<%@ page contentType="text/html;charset=GBK" %>
<%@ page import="java.sql.*,gbase.db.*,gbase.init.*,java.util.*,gbase.init.*,gbase.util.*,java.text.*,java.io.*,gbase.init.*,gbase.html.*,org.apache.log4j.MDC"%>
<%
	WebConfig theWebConfig=WebConfig.getInstance();
        String new_web_url=theWebConfig.getWeb_url();
        String new_web_ip=theWebConfig.getIp();
	SeqIdGenerater theSeqIdGenerater=new SeqIdGenerater();
	ConvertSql theConvertSql=new ConvertSql();
	DBOperation theDBOperation = new DBOperation();
        ResultSet rs=null;
	String message="该网站帐号已存在，请申请别的网站帐号!";
	String action = request.getParameter("action")==null?"":request.getParameter("action");
	
	String web_id=request.getParameter("web_id")==null?"":request.getParameter("web_id");
	String web_account=request.getParameter("web_account")==null?"":request.getParameter("web_account");
        String web_name=request.getParameter("web_name")==null?"":request.getParameter("web_name");
        String old_web_url="http://"+web_account+new_web_url;
        String web_url=request.getParameter("web_url")==null?old_web_url:request.getParameter("web_url").trim();
        if(web_url.equals(""))web_url=old_web_url;
        String web_type=request.getParameter("web_type")==null?"":request.getParameter("web_type");
        String web_keywords=request.getParameter("web_keywords")==null?"":request.getParameter("web_keywords");
        String web_description=request.getParameter("web_description")==null?"":request.getParameter("web_description");
        String web_user_type=request.getParameter("web_user_type")==null?"":request.getParameter("web_user_type");
        String web_enterprise_name=request.getParameter("web_enterprise_name")==null?"":request.getParameter("web_enterprise_name");
        String web_enterprise_address=request.getParameter("web_enterprise_address")==null?"":request.getParameter("web_enterprise_address");
        String web_contacter_name=request.getParameter("web_contacter_name")==null?"":request.getParameter("web_contacter_name");
        String web_contacter_telno=request.getParameter("web_contacter_telno")==null?"":request.getParameter("web_contacter_telno");
        String web_contacter_email=request.getParameter("web_contacter_email")==null?"":request.getParameter("web_contacter_email");
        String web_contacter_qq=request.getParameter("web_contacter_qq")==null?"":request.getParameter("web_contacter_qq");
        String web_jive_flag=request.getParameter("web_jive_flag")==null?"":request.getParameter("web_jive_flag");
	String web_jive_desc=request.getParameter("web_jive_desc")==null?"":request.getParameter("web_jive_desc");
	String real_url=request.getParameter("real_url")==null?"":request.getParameter("real_url");
	if(real_url.equals(""))real_url="/my_cms_images/logo.jpg";
        String password=request.getParameter("password")==null?"":request.getParameter("password");
        String project_account=request.getParameter("project_account")==null?"":request.getParameter("project_account");
        String project_id=request.getParameter("project_id")==null?"":request.getParameter("project_id");
	
	SimpleDateFormat timeformat = new SimpleDateFormat("yyyy-MM-dd");
        java.util.Date date = Calendar.getInstance().getTime();
        String create_date = timeformat.format(date).toString();
        
	String url="register_complete.jsp?web_account="+web_account+"&password="+password;
	
	String sql="";
	int url_update_flag=1;
	if(!web_url.equals(""))
	{
        sql = "select web_account from web_info  where web_url='"+web_url+"' and web_account!='"+web_account+"'";
        rs =theDBOperation.getResultSet(sql);
        if(rs.next())
          url_update_flag=0;
        }
   if(web_url.equals("") || url_update_flag==1){
   
	String sqls[]=new String[2];
	if(action.equals("update"))
	{ 
	  sqls[0]="update web_info set web_url='"+web_url+"',web_name='"+web_name+"',web_type='"+web_type+"',web_keywords='"+web_keywords+"',web_description='"+web_description+"',web_user_type='"+web_user_type+"',web_enterprise_name='"+web_enterprise_name+"',web_enterprise_address='"+web_enterprise_address+"',web_contacter_telno='"+web_contacter_telno+"',web_contacter_email='"+web_contacter_email+"',web_contacter_qq='"+web_contacter_qq+"',web_jive_flag='"+web_jive_flag+"',web_jive_desc='"+web_jive_desc+"',real_url='"+real_url+"',project_account='"+project_account+"',project_id="+project_id+"  where web_account='"+web_account+"'";
	  sqls[1]="update web_user set password='"+password+"' where user_account='admin' and web_account='"+web_account+"'";
	}
	else if(action.equals("delete"))
	 {
	  sqls[0]="delete from web_info  where web_account='"+web_account+"'";
	  sqls[1]="delete from web_user  where web_account='"+web_account+"'";
	 } 
	else
	  {
	  int seqId=theSeqIdGenerater.generatorKey("web_info");
	  web_id=Integer.toString(seqId);
	  int user_id=theSeqIdGenerater.generatorKey("web_user");
	  sqls[0]="insert into web_info(web_id,web_account,web_url,web_name,web_type,web_keywords,web_description,web_user_type,web_enterprise_name,web_enterprise_address,web_contacter_telno,web_contacter_email,web_contacter_qq,create_date,web_jive_flag,web_jive_desc,real_url,project_account,project_id) values("+seqId+",'"+web_account+"','"+web_url+"','"+web_name+"','"+web_type+"','"+web_keywords+"','"+web_description+"','"+web_user_type+"','"+web_enterprise_name+"','"+web_enterprise_address+"','"+web_contacter_telno+"','"+web_contacter_email+"','"+web_contacter_qq+"','"+create_date+"','"+web_jive_flag+"','"+web_jive_desc+"','"+real_url+"','"+project_account+"',"+project_id+")";
	  sqls[1]="insert into web_user(user_id,web_account,user_account,password,user_name,telno,address,duty,bir_add)  values("+user_id+",'"+web_account+"','admin','"+password+"','超级管理员','','','','')";
	  }
	
        try {
        int i=theDBOperation.executeSqls(sqls);
        if(i>0)
          {
          DataProcess theDataProcess=new DataProcess();
          theDataProcess.webInfoSave(project_id,project_account,web_account,web_url,action);
          message = "操作成功!";
          }
        else
          message = "该网站帐号已存在，请申请别的网站帐号!";
      }
      catch (Exception ex) {
        message = "该网站帐号已存在，请申请别的网站帐号!";
        //ex.printStackTrace();
      }
    }
    else
    {
     message="域名"+web_url+"已经被别人使用了，如果域名"+web_url+"是你的，请把域名"+web_url+"解析到111.111.111.111并发邮件到xiantianyou@163.com，请管理员进行确认。";
    }		
%>
<script language="javascript">
	function process ( message,url){
	        if(message=='操作成功!')
	        {
	        self.location=url;
	        }
	        else
	        {
		alert(message);
		self.location = "register.jsp";
		}
	}
</script>
<html>
	<head>
		<title></title>
	</head>
	<body onload="javascript: process('<%=message%>','<%=url%>');">
	</body>
</html>