<%@ page contentType="text/html;charset=GBK" %>
<%@ include file="../checkLogin.jsp" %>
<%@ page import="gbase.db.*,java.util.*,gbase.util.*,java.text.*"%>
<%@ page import="gbase.html.*,gbase.init.*,gbase.db.*,java.sql.*"%>
<%
	
	String message="操作失败";
	String action = request.getParameter("action")==null?"":request.getParameter("action");
	String url="web_imageinfo_list.jsp";
	
	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");
        String image_url=request.getParameter("real_url")==null?"":request.getParameter("real_url");
        System.out.println("image_url:"+image_url);
        String bar_id=request.getParameter("bar_id")==null?"0":request.getParameter("bar_id");
        String special_id=(request.getParameter("special_id")==null || request.getParameter("special_id").equals(""))?"0":request.getParameter("special_id");
	String content=request.getParameter("content")==null?"":request.getParameter("content");
	ConvertSql theConvertSql=new ConvertSql();
        content=theConvertSql.convertSqlValue(content);
        
        SimpleDateFormat timeformat = new SimpleDateFormat("yyyy-MM-dd");
        java.util.Date date = Calendar.getInstance().getTime();
        String create_date = timeformat.format(date).toString();
        
        String sql="";
        DBOperation theDBOperation = new DBOperation();
        
	if(action.equals("update"))
	  { 
	  sql="update web_imageinfo set title='"+title+"',image_url='"+image_url+"',title_desc='"+title_desc+"',bar_id="+bar_id+",special_id="+special_id+",content='"+content+"',create_date='"+create_date+"' where  web_account='"+web_account+"' and id="+id+"";
	  }
	else if(action.equals("delete"))
	  sql="delete from web_imageinfo  where  web_account='"+web_account+"' and id="+id+"";
	else
	  {
	  SeqIdGenerater theSeqIdGenerater=new SeqIdGenerater();
	  int seqId=theSeqIdGenerater.generatorKey("web_imageinfo");
	  id=Integer.toString(seqId);
	  sql="insert into web_imageinfo(id,title,image_url,title_desc,bar_id,special_id,content,create_date,web_account,user_account) values("+seqId+",'"+title+"','"+image_url+"','"+title_desc+"',"+bar_id+","+special_id+",'"+content+"','"+create_date+"','"+web_account+"','"+user_account+"')";
	  }
	//out.println(sql);
	
        try {
        int ii=theDBOperation.executeSql(sql);
        if(ii>0)
          {
          
          WebConfig theWebConfig=new WebConfig();
          WebInfo webInfo=theWebConfig.getWebInfo(web_account);
          String web_name=webInfo.getWeb_name();
          
          boolean flag=false;
          
          String index_url="index.jsp";
          String web_title=web_name;
          String httpUrl="";
          String bar_name="首页广告图片";
          
          
          //首页
          httpUrl=cms_url+web_account+"/template/"+index_url+"?web_account="+web_account+"&web_title="+web_title;
          String htmlFilePath="";
          String htmlFileName="";
          htmlFileName="index.html";
          HtmlGenerater theHtmlGenerater=new HtmlGenerater();
          flag=theHtmlGenerater.geneHtmlFile(web_account,httpUrl,htmlFilePath,htmlFileName); 
          
          
          //列表页
          web_title=web_name+":首页广告图片";
          int need_page = 1;
          int sum_page=1;
          int page_size=10;
          int row_size=1;
          
          for(int i=0;i<sum_page;i++)
          {
            httpUrl=cms_url+web_account+"/template/bar_image_list.jsp?bar_id="+bar_id+"&web_account="+web_account+"&bar_name=首页广告图片&web_title="+web_title+"&need_page="+need_page+"&sum_page="+sum_page+"&page_size="+page_size+"&row_size="+row_size;
            htmlFilePath="/bar"+bar_id+"_"+need_page;
            htmlFileName="index.html";
            theHtmlGenerater=new HtmlGenerater();
            flag=theHtmlGenerater.geneHtmlFile(web_account,httpUrl,htmlFilePath,htmlFileName); 
            need_page++;
            if(!flag)break;
          }
          if(!action.equals("delete")){
          //内容  
          web_title=title+" ("+web_name+":"+bar_name+")";
          httpUrl=cms_url+web_account+"/template/bar_image_content.jsp?bar_id="+bar_id+"&content_id="+id+"&web_account="+web_account+"&bar_name="+bar_name+"&web_title="+web_title;
          htmlFilePath="/"+bar_id;
          htmlFileName="content"+id+".html";
          theHtmlGenerater=new HtmlGenerater();
          flag=theHtmlGenerater.geneHtmlFile(web_account,httpUrl,htmlFilePath,htmlFileName); 
          }
          //生成RSS XML
          /*
          htmlFilePath="";
          htmlFileName="bar"+bar_id+".xml";
          XmlGenerater theXmlGenerater=new XmlGenerater();
          flag=theXmlGenerater.geneXmlFile(web_account,bar_id,htmlFilePath,htmlFileName); 
          */
          
          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>