<!--#include file="../../fy.Function.asp"-->
<!--#include file="../../../fy_inc/cls_pageview.asp"-->
<!doctype html>
<html>
<head>
<meta charset="gb2312">
<title>友情链接系统管理</title>
<link rel="stylesheet" type="text/css" href="../../css/base.css">
<link rel="stylesheet" type="text/css" href="../../css/content.css">
</head>
<body>
<div class="content"> 
	<div class="breadnav">当前位置：<a href="#">后台首页</a> >> 链接系统管理</div>
    <div class="opers">
		<a href="?" class="btn <%If request("Action")="" Then echo " btn_primary" %>">管理首页</a>
		<a href="?Action=Add" class="btn<%If request("Action")="Add" Then echo " btn_primary" %>">新增友情类别</a>
		<a href="Linksh_fy.asp" class="btn">链接审核</a>
    </div>
    <% 
	Dim ShowErr,Action
	If Not fycms.fycms_QXYZ(0,"yqlj_fy","") Then   Call fycms.Alert("对不起，你没有操作权限！","") 
	Action = Request("Action")
	Select Case Action
			Case "Edit","Add"
				Call Edit()
			Case "SaveAdd"
				Call SaveAdd
			Case "SaveEdit"
				Call SaveEdit
			Case "del"
				Call Del()
			Case Else
				Call Main()
	End Select
	
	Sub SaveAdd()
		Dim ClassLinkName,Description,SQL,rs,id
		ClassLinkName = Trim(Request.Form("ClassLinkName"))
		Description = RSQL(Request.Form("Description"))
		IF 	ClassLinkName = "" Then 
 			Call fycms.ActErr("类别名称不能为空","","")
 			Response.End
		End IF
		SQL = "Select * From ClassLink_fy Where ClassLinkName='"&ClassLinkName&"'"
		Set Rs=Server.CreateObject("Adodb.RecordSet")
		Rs.Open SQL,Conn,1,3
		IF Not (Rs.Eof And Rs.Bof) Then
 			Call fycms.ActErr("数据库中已经存在此类别名称","","")
 			Response.End
		End IF
		Rs.addnew
		Rs("ClassLinkName")		= ClassLinkName
		Rs("Description")	    = Description
		Rs.update
		Rs.Close:Set Rs=Nothing
  		Call fycms.ActErr("添加新类别成功","sys_fy/link/Index.asp","")
		Response.End
	End Sub	
		
	Sub SaveEdit()
		Dim ClassLinkName,Description,SQL,rs,id
		ClassLinkName = Trim(Request.Form("ClassLinkName"))
		Description = RSQL(Request.Form("Description"))
		ID = ChkNumeric(Request("ID"))
		IF 	ClassLinkName = "" Then 
 			Call fycms.ActErr("类别名称不能为空","","")
 			Response.End
		End IF
		IF 	ClassLinkName = "" Then 
		 	 Call fycms.ActErr("类别名称不能为空","","")
 			Response.End
		End IF
		SQL = "Select * From ClassLink_fy Where ID="&ID
		Set Rs=Server.CreateObject("Adodb.RecordSet")
		Rs.Open SQL,Conn,1,3
		IF Not (Rs.Eof And Rs.Bof) Then
			Rs("ClassLinkName")		= ClassLinkName
			Rs("Description")	    = Description
			Rs.update
		Else
  			Call fycms.ActErr("无此类别，参数传递出错","","")
			Response.End
		End IF
		Rs.Close:Set Rs=Nothing
 		Call fycms.ActErr("类别修改成功","sys_fy/link/Index.asp","")
 	End Sub	
	Sub Del()
		Conn.Execute ("Delete from ClassLink_fy Where ID=" & ChkNumeric(Request.QueryString("ID")))
		Conn.Execute ("Delete from Link_fy Where ClassLinkID=" & ChkNumeric(Request.QueryString("ID")))		
		Set conn=nothing
		ShowErr = "<li>类别删除成功！</li>"
		Call fycms.ActErr("类别删除成功","sys_fy/link/Index.asp","")
   		Response.End
    End Sub
		
 Sub Main
	Dim strLocalUrl
	strLocalUrl = request.ServerVariables("SCRIPT_NAME")
	Dim intPageNow
	intPageNow = request.QueryString("page")
	Dim intPageSize, strPageInfo
	intPageSize = 30
	Dim arrinfo, i
	Dim sql, sqlCount
	sql = "SELECT [ID], [ClassLinkName], [Description], [AddDate]" & _
		" FROM [ClassLink_fy]" & _
		"ORDER BY [ID] ASC"
	sqlCount = "SELECT Count([ID])" & _
			" FROM [ClassLink_fy]"

		Dim clsRecordInfo
		Set clsRecordInfo = New Cls_PageView
			clsRecordInfo.intRecordCount = 2816
			clsRecordInfo.strSqlCount = sqlCount
			clsRecordInfo.strSql = sql
			clsRecordInfo.intPageSize = intPageSize
			clsRecordInfo.intPageNow = intPageNow
			clsRecordInfo.strPageUrl = strLocalUrl
			clsRecordInfo.strPageVar = "page"
		clsRecordInfo.objConn = Conn		
		arrinfo = clsRecordInfo.arrinfo
		strPageInfo = clsRecordInfo.strPageInfo
		Set clsRecordInfo = nothing
 %><table width="100%" border="0" cellspacing="0" cellpadding="0">
    <thead>
      <tr>
      <th>ID</th>
	  <th>链接类别名称</th>
	  <th>链接类别简介</th>
	  <th>管理操作</th>
	  </tr>
    </thead>
      <%
		Dim bgColor
		If IsArray(arrinfo) Then
			For i = 0 to UBound(arrinfo, 2)
	%>
    <tr >
      <td><%= arrinfo(0,i) %></td>
      <td>
	  <a href="?Action=Edit&ID=<%=arrinfo(0,i)  %>">
	  <%=arrinfo(1,i)%></a></td>
      <td><%= arrinfo(2,i) %></td>
      <td><a href="?Action=Edit&ID=<%=arrinfo(0,i)  %>">修改</a>┆
          <a href="?Action=del&ID=<%= arrinfo(0,i) %>" onClick="return confirm('确认删除此类别吗?同时也删除改类别下的所以链接!')">删除</a>┆
    <A href="Link_fy.asp?action=List&classlinkid=<%= arrinfo(0,i) %>">列出所有链接</A>
	<a href="Link_fy.asp?Action=Add&classlinkid=<%= arrinfo(0,i) %>">添加链接</a></td></tr>
	<% 
	Next
	End If
	%>
    </table>
    <div class="pagelist">
    	<%= strPageInfo%>
   </div>
 
<% 
 End Sub
sub edit()
	Dim ID,Rs,ClassLinkName,Description,frmAction
	IF Action = "Edit" Then
		ID = ChkNumeric(Request("ID"))
		IF ID = 0 Then echo "请指定要修改的类别":Response.End
		Set Rs=Conn.Execute("Select * from ClassLink_fy Where ID=" & ID)
			if Rs.Bof And Rs.EOF then
				 echo "不存在此类别！"
				Exit Sub
			End IF	
		ClassLinkName = Rs("ClassLinkName")	
		Description = Rs("Description")
		frmAction		= "Edit"
	Else
		ClassLinkName = ""	
		Description = ""
		frmAction		= "Add"
	End IF
  %>


 <form name="form1" method="post" action="?">  <tr>
    <div class="divtable"> 
        <dl>
            <dt>类别名称：</dt>
            <dd>
               <input name="ClassLinkName" type="text" id="ClassLinkName" value="<%= ClassLinkName %>">   
            </dd>
         </dl>
        
        <dl>
            <dt>简要说明：</dt>
            <dd>
               <textarea name="Description" cols="50" rows="8" id="Description"><%= Description %></textarea>
             </dd>
         </dl>
        
 
            <dl>
             <dd>
			<input name="ID" type="hidden" value="<%=ID%>">
			<input name="Action" type="hidden" id="Action" value="Save<%=frmAction%>">
			<input type="submit"  onclick=CheckInfo()  class="btn btn_primary" name="Submit" value=" 保 存 "> 
			<input type="reset" class="btn"  name="Submit2" value=" 取 消 " />
            </dd>
         </dl>
        
    </div>
    </form>








<SCRIPT language=javascript>
		function CheckInfo()
		{
		  if(document.form1.ClassLinkName.value=="")
			{
			  alert("类别不能为空！");
			  document.form1.ClassLinkName.focus();
			  return false;
			}
	    form1.submit();
        return true;
		}
		</script>
<%
 
 end sub
 CloseConn %>
<br>
</div>
</body>
</html>
