<%@ page contentType="text/html;charset=GBK" %>
<%@ include file="../checkLogin.jsp" %>
<%@ page import="java.sql.*,gbase.db.*,java.util.*,gbase.util.*,java.text.*,gbase.html.*"%>
<%
	
	String message="操作失败";
	String action = request.getParameter("action")==null?"":request.getParameter("action");
	String url="web_link_list.jsp";
	
	String id=request.getParameter("id")==null?"":request.getParameter("id");
        String link_name=request.getParameter("link_name")==null?"":request.getParameter("link_name");
        String link_url=request.getParameter("link_url")==null?"":request.getParameter("link_url");
        String link_desc=request.getParameter("link_desc")==null?"":request.getParameter("link_desc");
        String start_date=request.getParameter("start_date")==null?"":request.getParameter("start_date");
        String end_date=request.getParameter("end_date")==null?"":request.getParameter("end_date");
        String link_order=request.getParameter("link_order")==null?"1":request.getParameter("link_order");
        String open_method=request.getParameter("open_method")==null?"":request.getParameter("open_method");
        String dis_location=request.getParameter("dis_location")==null?"":request.getParameter("dis_location");
        String link_state=request.getParameter("link_state")==null?"":request.getParameter("link_state");
        
	ConvertSql theConvertSql=new ConvertSql();
        link_desc=theConvertSql.convertSqlValue(link_desc);
        
        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_link set link_order=link_order+1  where link_order>="+link_order+"";
	  theDBOperation.executeSql(sql);
	  sql="update web_link set link_name='"+link_name+"',link_url='"+link_url+"',link_desc='"+link_desc+"',start_date='"+start_date+"',end_date='"+end_date+"',link_order="+link_order+",open_method='"+open_method+"',dis_location='"+dis_location+"',link_state='"+link_state+"' where id="+id+"";
	  }
	else if(action.equals("delete"))
	  sql="delete from web_link  where id="+id+"";
	else
	  {
	  sql="update web_link set link_order=link_order+1  where link_order>="+link_order+"";
	  theDBOperation.executeSql(sql);
	  SeqIdGenerater theSeqIdGenerater=new SeqIdGenerater();
	  int seqId=theSeqIdGenerater.generatorKey("web_link");
	  sql="insert into web_link(id,link_name,link_url,link_desc,start_date,end_date,link_order,open_method,dis_location,link_state,web_account,create_date) values("+seqId+",'"+link_name+"','"+link_url+"','"+link_desc+"','"+start_date+"','"+end_date+"',"+link_order+",'"+open_method+"','"+dis_location+"','"+link_state+"','"+web_account+"','"+create_date+"')";
	  }
	//out.println(sql);
	
        try {
        int i=theDBOperation.executeSql(sql);
        if(i>0)
          {
          String htmlFilePath="friend_link";
          String htmlFileName="index.html";
          HtmlGenerater theHtmlGenerater=new HtmlGenerater();
          String httpUrl=cms_url+web_account+"/template/friend_link.jsp?web_account="+web_account+"&web_title=友情链接";
          boolean flag=theHtmlGenerater.geneHtmlFile(web_account,httpUrl,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>