<%@ page contentType="text/html;charset=GBK" %>
<%@ page import="gbase.html.*,gbase.init.*,gbase.db.*,java.sql.*"%>
<%@ include file="../checkLogin.jsp" %>
<%
	
	String message="操作失败";
	String url="web_public_sum.jsp";
        boolean flag=true;
      try{
        DBOperation theDBOperation=new DBOperation();
        String sql ="select * from bar_menu where web_account='"+web_account+"'";
        ResultSet rs=null;
        rs =theDBOperation.getResultSet(sql);
        while(rs.next())
        {
        int page_size=rs.getInt("page_size");
        int row_size=rs.getInt("row_size");
        
        String id=rs.getString("id");
        String name=rs.getString("name");
        String menu_type=rs.getString("menu_type");
        String content_type=rs.getString("content_type");
        String web_template_id=rs.getString("web_template_id");
        String web_template_id2=rs.getString("web_template_id2");
        
        WebConfig theWebConfig=new WebConfig();
        WebInfo webInfo=theWebConfig.getWebInfo(web_account);
        String web_title=webInfo.getWeb_name()+":"+name;
        String httpUrl="";
        //非列表栏目页
        if((!content_type.equals("2")) && (!content_type.equals("3"))){  
        httpUrl=cms_url+web_account+"/template/"+web_template_id+".jsp?bar_id="+id+"&web_account="+web_account+"&bar_name="+name+"&web_title="+web_title;
        String htmlFilePath="";
        String htmlFileName="";
        if(menu_type.equals("3"))
          htmlFileName="index.html";
        else
          {
          htmlFilePath="/bar"+id;
          htmlFileName="index.html";
          }
          HtmlGenerater theHtmlGenerater=new HtmlGenerater();
          flag=theHtmlGenerater.geneHtmlFile(web_account,httpUrl,htmlFilePath,htmlFileName); 
        }
        
        //列表栏目页以及内容页
        else
        {
        String sql1 ="";
        ResultSet rs1=null;
        if(content_type.equals("2"))
          sql1= "select * from web_titleinfo where web_account='"+web_account+"' and bar_id="+id+"";
        else if(content_type.equals("3"))
          sql1= "select * from web_imageinfo where  web_account='"+web_account+"' and bar_id="+id+"";
        rs1 =theDBOperation.getResultSet(sql1);
        //列表页
        rs1.last();
        int sum_count=rs1.getRow();
        int need_page = 1;
        int sum_page=0;
        if(content_type.equals("3"))
         sum_page=(sum_count-1)/(page_size*row_size)+1;
        else
         sum_page=(sum_count-1)/page_size+1;
        for(int i=0;i<sum_page;i++)
        {
          httpUrl=cms_url+web_account+"/template/"+web_template_id+".jsp?bar_id="+id+"&web_account="+web_account+"&bar_name="+name+"&web_title="+web_title+"&need_page="+need_page+"&sum_page="+sum_page+"&page_size="+page_size+"&row_size="+row_size;
          String htmlFilePath="/bar"+id+"_"+need_page;
          String htmlFileName="index.html";
          HtmlGenerater theHtmlGenerater=new HtmlGenerater();
          flag=theHtmlGenerater.geneHtmlFile(web_account,httpUrl,htmlFilePath,htmlFileName); 
          need_page++;
        }
        //内容页
        rs1.beforeFirst();
        while(rs1.next())
        {
          web_title=rs1.getString("title")+"("+webInfo.getWeb_name()+":"+name+")";
          httpUrl=cms_url+web_account+"/template/"+web_template_id2+".jsp?bar_id="+id+"&content_id="+rs1.getString("id")+"&web_account="+web_account+"&bar_name="+name+"&web_title="+web_title;
          String htmlFilePath="/"+id;
          String htmlFileName="content"+rs1.getString("id")+".html";
          HtmlGenerater theHtmlGenerater=new HtmlGenerater();
          flag=theHtmlGenerater.geneHtmlFile(web_account,httpUrl,htmlFilePath,htmlFileName); 
        }
        
        String htmlFilePath1="";
        String htmlFileName1="bar"+id+".xml";
        XmlGenerater theXmlGenerater=new XmlGenerater();
        flag=theXmlGenerater.geneXmlFile(web_account,id,htmlFilePath1,htmlFileName1); 
        }
        
        }
        
        if(flag)
          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>