<%@ page contentType="text/html;charset=GBK" %>
<%@ include file="../checkLogin.jsp" %>
<%@ page import="gbase.db.*,java.util.*,gbase.util.*"%>
<%
	
	String message="操作失败";
	String action = request.getParameter("action")==null?"":request.getParameter("action");
	String url="sys_web_project_list.jsp";
	
	String id=request.getParameter("id")==null?"":request.getParameter("id");
        String title=request.getParameter("title")==null?"":request.getParameter("title");
        String project_desc=request.getParameter("project_desc")==null?"":request.getParameter("project_desc");
        ConvertSql theConvertSql=new ConvertSql();
        project_desc=theConvertSql.convertSqlValue(project_desc);
	String content=request.getParameter("content")==null?"":request.getParameter("content");
	content=theConvertSql.convertSqlValue(content);
        String sql="";
        DBOperation theDBOperation = new DBOperation();
        
	if(action.equals("update"))
	  { 
	  sql="update sys_web_project set title='"+title+"',project_desc='"+project_desc+"',content='"+content+"' where id="+id+"";
	  }
	else if(action.equals("delete"))
	  sql="delete from sys_web_project  where id="+id+"";
	else if(action.equals("set"))
	  {
	  theDBOperation.executeSql("update sys_web_project set flag=1");
	  sql="update sys_web_project set flag=0  where id="+id+"";
	  }
	else
	  {
	  SeqIdGenerater theSeqIdGenerater=new SeqIdGenerater();
	  int seqId=theSeqIdGenerater.generatorKey("sys_web_project");
	  sql="insert into sys_web_project(id,title,project_desc,content) values("+seqId+",'"+title+"','"+project_desc+"','"+content+"')";
	  }
	//out.println(sql);
	
        try {
        int i=theDBOperation.executeSql(sql);
        if(i>0)
          {
          if(action.equals("set"))
          {
           String newContent="";
           ResultSet rs=null;
           String file_name="";
           //风格
           theDBOperation.executeSql("update sys_web_css set flag=1");
           theDBOperation.executeSql("update sys_web_css set flag=0  where web_project_id="+id);
	   sql = "select * from sys_web_css  where web_project_id="+id;
           rs =theDBOperation.getResultSet(sql);
           if(rs.next())
           {
           newContent=rs.getString("content")==null?"":rs.getString("content");
           ContentToFile theContentToFile=new ContentToFile();
           theContentToFile.geneCssFile("",newContent,"/css");
           }
           
           //模版
           theDBOperation.executeSql("update sys_web_template set flag=1");
           theDBOperation.executeSql("update sys_web_template set flag=0  where web_project_id="+id);
	   sql = "select a.*,b.file_name from sys_web_template a,web_template_type b  where a.web_template_type_id=b.id and a.web_project_id="+id;
           rs =theDBOperation.getResultSet(sql);
           while(rs.next())
           {
           newContent=rs.getString("content")==null?"":rs.getString("content");
           file_name=rs.getString("file_name")==null?"":rs.getString("file_name");
           ContentToFile theContentToFile=new ContentToFile();
           if(file_name.equals("page_top") || file_name.equals("page_bottom"))
            theContentToFile.geneTemplateTopBottomFile("",newContent,"/template",file_name+".jsp");
          else
            theContentToFile.geneTemplateFile("",newContent,"/template",file_name+".jsp");
            
           }
          }
          else if(action.equals("delete"))
          {
           String[] delete_sql=new String[2];
           delete_sql[0]="delete from sys_web_css where web_project_id="+id+"";
           delete_sql[1]="delete from sys_web_template where web_project_id="+id+"";
           theDBOperation.executeSqls(delete_sql);
          }   
          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>