<%@ 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 web_template_type_id=request.getParameter("web_template_type_id")==null?"":request.getParameter("web_template_type_id");
	String web_project_id=request.getParameter("web_project_id")==null?"":request.getParameter("web_project_id");
        String web_project_name=request.getParameter("web_project_name")==null?"":request.getParameter("web_project_name");
	String file_name=request.getParameter("file_name")==null?"page_top":request.getParameter("file_name");
        String page_name=request.getParameter("page_name")==null?"网页头部修改":request.getParameter("page_name");

	String url="page_top_content.jsp?file_name="+file_name+"&page_name="+page_name+"&web_template_type_id="+web_template_type_id;
	
	String id=request.getParameter("id")==null?"":request.getParameter("id");
        String title=request.getParameter("title")==null?"":request.getParameter("title");
        String title_desc=request.getParameter("title_desc")==null?"":request.getParameter("title_desc");
        ConvertSql theConvertSql=new ConvertSql();
        title_desc=theConvertSql.convertSqlValue(title_desc);
        String test_desc=request.getParameter("test_desc")==null?"":request.getParameter("test_desc");
        
	String content=request.getParameter("content")==null?"":request.getParameter("content");
	String flag=request.getParameter("flag")==null?"":request.getParameter("flag");
	String old_content=content;
	
        content=theConvertSql.convertSqlValue(content);
        String sql="";
        DBOperation theDBOperation = new DBOperation();
        
	if(action.equals("update"))
	  { 
	  sql="update web_template set title_desc='"+title_desc+"',test_desc='"+test_desc+"',web_project_id="+web_project_id+",web_template_type_id="+web_template_type_id+",title='"+title+"',content='"+content+"' where id="+id+" and web_account='"+web_account+"'";
	  }
	else if(action.equals("delete"))
	  sql="delete from web_template  where id="+id+" and web_account='"+web_account+"'";
	else if(action.equals("set"))
	  {
	  theDBOperation.executeSql("update web_template set flag=1 where web_template_type_id="+web_template_type_id+" and web_account='"+web_account+"'");
	  sql="update web_template set flag=0  where id="+id+" and web_account='"+web_account+"'";
	  }
	else
	  {
	  SeqIdGenerater theSeqIdGenerater=new SeqIdGenerater();
	  int seqId=theSeqIdGenerater.generatorKey("web_template");
	  id=Integer.toString(seqId);
	  sql="insert into web_template(id,web_project_id,web_template_type_id,title,title_desc,test_desc,content,web_account) values("+seqId+","+web_project_id+","+web_template_type_id+",'"+title+"','"+title_desc+"','"+test_desc+"','"+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_template  where id="+id+" and web_account='"+web_account+"'";
           ResultSet rs =theDBOperation.getResultSet(sql);
           if(rs.next())
           {
           old_content=rs.getString("content")==null?"":rs.getString("content");
           }
          ContentToFile theContentToFile=new ContentToFile();
         if(file_name.equals("page_top") || file_name.equals("page_bottom"))
            theContentToFile.geneTemplateTopBottomFile(web_account,old_content,"/template",file_name+".jsp");
          else
            theContentToFile.geneTemplateFile(web_account,old_content,"/template",file_name+".jsp");
          
          }
         /*
          else
          {
          ContentToFile theContentToFile=new ContentToFile();
          theContentToFile.geneTemplateFile(web_account,old_content,"/template",id+".jsp");
          }
         */
          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>