<%@ page contentType="text/html;charset=GBK" %>
<%@ include file="../checkLogin.jsp" %>
<%@ page import="java.sql.*,gbase.db.*,java.util.*,gbase.util.*"%>
<%
	
	String message="操作失败";
	String action = request.getParameter("action")==null?"":request.getParameter("action");
	String url="web_css_list.jsp";
	
	String id=request.getParameter("id")==null?"":request.getParameter("id");
        String title=request.getParameter("title")==null?"":request.getParameter("title");
        String web_project_id=request.getParameter("web_project_id")==null?"":request.getParameter("web_project_id");
	String content=request.getParameter("content")==null?"":request.getParameter("content");
	String flag=request.getParameter("flag")==null?"":request.getParameter("flag");
	String old_content=content;
	ConvertSql theConvertSql=new ConvertSql();
        content=theConvertSql.convertSqlValue(content);
        String sql="";
        DBOperation theDBOperation = new DBOperation();
        
	if(action.equals("update"))
	  { 
	  sql="update web_css set web_project_id="+web_project_id+",title='"+title+"',content='"+content+"' where id="+id+" and web_account='"+web_account+"'";
	  }
	else if(action.equals("delete"))
	  sql="delete from web_css  where id="+id+"";
	else if(action.equals("set"))
	  {
	  theDBOperation.executeSql("update web_css set flag=1  where web_account='"+web_account+"'");
	  sql="update web_css set flag=0  where id="+id+"  and web_account='"+web_account+"'";
	  }
	else
	  {
	  SeqIdGenerater theSeqIdGenerater=new SeqIdGenerater();
	  int seqId=theSeqIdGenerater.generatorKey("web_css");
	  id=Integer.toString(seqId);
	  sql="insert into web_css(id,web_project_id,title,content,web_account) values("+seqId+","+web_project_id+",'"+title+"','"+content+"','"+web_account+"')";
	  }
	//out.println(sql);
	
        try {
        int i=theDBOperation.executeSql(sql);
        if(i>0)
          {
          if(action.equals("set") || flag.equals("0")){
           sql = "select * from web_css  where id="+id+"";
           ResultSet rs =theDBOperation.getResultSet(sql);
           String newContent="";
           if(rs.next())
           {
           newContent=rs.getString("content")==null?"":rs.getString("content");
           }
           ContentToFile theContentToFile=new ContentToFile();
           theContentToFile.geneCssFile(web_account,newContent,"/css");
           
           WebConfig theWebConfig=WebConfig.getInstance();
           String root_path=theWebConfig.getManagerWebDir();
           String from_file=root_path+"/"+web_account+"/css/css.css";
           String to_file=root_path+"/"+web_account+"/"+web_account+"/css/css.css";
           Copys theCopys=new Copys();
           theCopys.copy(from_file,to_file);   
          } 
          message = "操作成功!";
          }
        else
          message = "操作失败!";
      }
      catch (Exception ex) {
        message = "操作失败!";
      }
	
%>
<script language="javascript">
	function process ( message,url){
		alert(message);
		self.location = url;
	}
</script>
<html>
	<head>
		<title></title>
	</head>
	<body onload="javascript: process('<%=message%>','<%=url%>');">
	</body>
</html>