<%@ 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="sys_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 sys_web_css set web_project_id="+web_project_id+",title='"+title+"',content='"+content+"' where id="+id+"";
	  }
	else if(action.equals("delete"))
	  {
	  sql="delete from sys_web_css  where id="+id+"";
	  }
	else if(action.equals("set"))
	  {
	  theDBOperation.executeSql("update sys_web_css set flag=1");
	  sql="update sys_web_css set flag=0  where id="+id+"";
	  }
	else
	  {
	  SeqIdGenerater theSeqIdGenerater=new SeqIdGenerater();
	  int seqId=theSeqIdGenerater.generatorKey("web_css");
	  id=Integer.toString(seqId);
	  sql="insert into sys_web_css(id,web_project_id,title,content) values("+seqId+","+web_project_id+",'"+title+"','"+content+"')";
	  }
        //out.println(sql);
	
        try {
        int i=theDBOperation.executeSql(sql);
        if(i>0)
        {
         if(action.equals("set")  || flag.equals("0"))
          {
           sql = "select * from sys_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("",newContent,"/css");
          } 
         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>