<!--#Include File="../Inc/Const.Asp"-->
<!--#Include File="Inc/Class_Sitelink.Asp"-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>站内链接管理</title>
<link href="Images/Style.Css" rel="stylesheet" type="text/css" />
</head>
<body>
<%

Call ChkLogin("sitelink")

Dim U
Set U = New Cls_SiteLink

Dim Rs,Sql,Style
Dim ID
    ID = Request("ID")
Dim Key
    Key = Request("Key")
Dim Page
    Page = Request("Page")
Dim Orders
    Orders = Request("Orders")
Dim DFieldKey
    DFieldKey = Request("DFieldKey")
Dim DFieldOrders
    DFieldOrders = Request("DFieldOrders")
If len(ID) > 0 And Not IsNumeric(ID) Then : Response.Write "编号只能是数字!" : Conn.Close : Set Conn = Nothing : Set U = Nothing : Response.End '// 检测ID
If Len(Page) = 0 Or Not IsNumeric(ID) Then Page = 1
If Page < 1 Then Page = 1
If LCase(Orders) <> "asc" Then Orders = "Desc"
If Len(DFieldKey) = 0 Then DFieldKey = "Order"
If Len(DFieldOrders) = 0 Then DFieldOrders = "Order"
If Instr("[id],[text],[link],[order],[replace],[target],[state]" , "[" & Lcase(DFieldKey) & "]") = 0 Then Key = ""
If Instr("[id],[text],[link],[order],[replace],[target],[state]" , "[" & Lcase(DFieldOrders) & "]") = 0 Then DFieldOrders = "ID"
Page = Int(Page) : Key = Replace(Key,"'","")
Dim JumpUrl
    JumpUrl = "&Key=" & Server.UrlENCode(Key) & "&DFieldKey=" & DFieldKey & "&Orders=" & Orders & "&DFieldOrders=" & DFieldOrders

Select Case Request("Act")
Case "Guide"
	If Len(ID) = 0 Then
		Call U.Initialize()
		Call Main_Guide(0)
	Else
		U.vID = ID
		Call U.SetValue()
		Call Main_Guide(1)
	End If
Case "UpDate"
	If U.GetValue() Then
		If Len(ID) = 0 Then
			If Not U.Create() Then
				Alert U.LastError,"manage_sitelink.Asp?Page=" & Page & JumpUrl
			Else
				Alert "","manage_sitelink.Asp?Page=" & Page & JumpUrl
			End If
		Else
			U.vID = ID
			If Not U.Modify() Then
				Alert U.LastError,"manage_sitelink.Asp?Page=" & Page & JumpUrl
			Else
				Alert "","manage_sitelink.Asp?Page=" & Page & JumpUrl
			End If
		End If
	Else
		Alert U.LastError,"manage_sitelink.Asp?Page=" & Page & JumpUrl
	End If
Case "Delete"
	If Len(ID) > 0 Then
		U.vID = ID
		If Not U.Delete() Then
			Alert U.LastError,"manage_sitelink.Asp?Page=" & Page & JumpUrl
		Else
			Alert "","manage_sitelink.Asp?Page=" & Page & JumpUrl
		End If
	Else
		Call Main()
	End If
Case "Change"
	If Len(ID) > 0 Then
		U.vID = ID
		If Not U.Change() Then
			Alert U.LastError,""
		End If
	End If
	Call Main()
Case Else
	Call Main()
End Select
Set U = Nothing
If IsObject(Conn) Then Conn.Close : Set Conn = Nothing

Sub Main()
	Sql = "Select [ID],[Text],[Link],[Order],[Replace],[Target],[State] From [{pre}Sitelink]"
	If Len(Key) > 0 Then
		If Instr(",ID,Order,Replace,Target,State,","," & DFieldKey & ",") > 0 Then
			If Len(Key) > 0 And IsNumeric(Key) Then
				Sql = Sql & " Where [" & DFieldKey & "]=" & Key & ""
			End If
		Else
			Sql = Sql & " Where [" & DFieldKey & "] Like '%" & Key & "%'"
		End If
	End If
	Sql = Sql & " Order By [" & DFieldOrders & "] " & Orders & ""
	Set Rs = DB(Sql,2)
	%>
	<table width=100% border=0 cellpadding=3 cellspacing=1 class=css_table bgcolor='#E1E1E1'>
	  <tr class=css_menu>
	    <td colspan=8><table width=100% border=0 cellpadding=4 cellspacing=0 class=css_main_table>
	        <form name=frmSearch method=post action=manage_sitelink.Asp>
	          <tr>
	            <td class=css_main><a href=manage_sitelink.Asp?Page=<%=Page%><%=JumpUrl%>>站内链接管理</a> <a href=manage_sitelink.Asp?Act=Guide&Page=<%=Page%><%=JumpUrl%>>添加站内链接</a></td>
	            <td class=css_search><select name=DFieldKey id=DFieldKey>
	              <option value="ID" <%If Lcase(DFieldKey) = "id" Then Response.Write "selected='selecte'" %>>编号</option><option value="Text" <%If Lcase(DFieldKey) = "text" Then Response.Write "selected='selected'" %>>链接文字</option><option value="Link" <%If Lcase(DFieldKey) = "link" Then Response.Write "selected='selected'" %>>链接地址</option><option value="Order" <%If Lcase(DFieldKey) = "order" Then Response.Write "selected='selected'" %>>优先级别</option><option value="Replace" <%If Lcase(DFieldKey) = "replace" Then Response.Write "selected='selected'" %>>替换次数</option><option value="Target" <%If Lcase(DFieldKey) = "target" Then Response.Write "selected='selected'" %>>打开方式</option><option value="State" <%If Lcase(DFieldKey) = "state" Then Response.Write "selected='selected'" %>>状态</option>
	              </select>
	              <input name=Key type=text id=Key size=10 value="<%=Key%>">
	              <input type=submit name=Submit value=搜>
	            </td>
	          </tr>
	        </form>
	      </table></td>
	  </tr>
	  <tr>
	    <td class='css_top'>编号</td>
	    <td class='css_top'>链接文字</td>
	    <td class='css_top'>链接地址</td>
	    <td class='css_top'><a href='manage_sitelink.Asp?Page=<%=Page%>&DFieldOrders=Order&Orders=<%If Lcase(DFieldOrders) = Lcase("Order") And Orders = "Desc" Then Response.Write "Asc" Else Response.Write "Desc" %>'>优先级别</a></td>
	    <td class='css_top'><a href='manage_sitelink.Asp?Page=<%=Page%>&DFieldOrders=Replace&Orders=<%If Lcase(DFieldOrders) = Lcase("Replace") And Orders = "Desc" Then Response.Write "Asc" Else Response.Write "Desc" %>'>替换次数</a></td>
	    <td class='css_top'><a href='manage_sitelink.Asp?Page=<%=Page%>&DFieldOrders=Target&Orders=<%If Lcase(DFieldOrders) = Lcase("Target") And Orders = "Desc" Then Response.Write "Asc" Else Response.Write "Desc" %>'>打开方式</a></td>
	    <td class='css_top'><a href='manage_sitelink.Asp?Page=<%=Page%>&DFieldOrders=State&Orders=<%If Lcase(DFieldOrders) = Lcase("State") And Orders = "Desc" Then Response.Write "Asc" Else Response.Write "Desc" %>'>状态</a></td>
	    <td class='css_top'>管理</td>
	  </tr>
	  <%
	  If Rs.Eof Then
	  %>
	  <tr class=css_norecord>
	    <td colspan=8>没有任何记录！</td>
	  </tr>
	  <%
	  Else
	  Dim i
	  Rs.PageSize = 15
	  Rs.AbsolutePage = Page
	  For i = 1 To Rs.PageSize
	  If Rs.Eof Then Exit For
	  %>
	  <tr  bgcolor="#fbfbfb" onMouseMove="javascript:this.bgColor='#cedcf0';" onMouseOut="javascript:this.bgColor='#FBFBFB';">
	    <td width=35 class='css_list'><%=Rs("ID")%></td>
	    <td width=100 class='css_list'><%=Rs("Text")%></td>
	    <td class='css_list'><%=Rs("Link")%></td>
	    <td width=70 class='css_list'><%=Rs("Order")%></td>
	    <td width=70 class='css_list'><%If Rs("Replace") = 0 Then Response.Write "不限" Else Response.Write Rs("Replace")%></td>
	    <td width=70 class='css_list'><%
	    Select Case Cstr(LCase(Rs("Target")))
	    Case "0"
	    	Response.Write "<a href='manage_sitelink.Asp?Act=Change&Field=Target&ID=" & Rs("ID") & "&Page=" & Page & "" & JumpUrl & "'>原窗口</a>"
	    Case "1"
	    	Response.Write "<a href='manage_sitelink.Asp?Act=Change&Field=Target&ID=" & Rs("ID") & "&Page=" & Page & "" & JumpUrl & "'>新窗口</a>"
	    Case Else
	    	Response.Write Rs("Target")
	    End Select
	    %></td>
	    <td width=45 class='css_list'><%
	    Select Case Cstr(LCase(Rs("State")))
	    Case "0"
	    	Response.Write "<a href='manage_sitelink.Asp?Act=Change&Field=State&ID=" & Rs("ID") & "&Page=" & Page & "" & JumpUrl & "'>禁用</a>"
	    Case "1"
	    	Response.Write "<a href='manage_sitelink.Asp?Act=Change&Field=State&ID=" & Rs("ID") & "&Page=" & Page & "" & JumpUrl & "'>启用</a>"
	    Case Else
	    	Response.Write Rs("State")
	    End Select
	    %></td>
	    <td width=100 class='css_list'>
	    <input name=modify type=button onclick="location.href='manage_sitelink.Asp?Act=Guide&ID=<%=Rs("ID")%>&Page=<%=Page%><%=JumpUrl%>';" value=修改>
	    <input name=delete type=button onclick="if(confirm('您确定要删除这条记录吗?')){location.href='manage_sitelink.Asp?Act=Delete&ID=<%=Rs("ID")%>&Page=<%=Page%><%=JumpUrl%>';}" value=删除>
	    </td>
	  </tr>
	  <%
	  Rs.MoveNext
	  Next
	  End If
	  %>
	  <tr class=css_page_list>
	    <td colspan=8><%=PageList(Rs.PageCount,Page,Rs.RecordCount,15,"manage_sitelink.Asp?Page={p}&Key=" & Server.UrlENCode(Key) & "&DFieldKey=" & DFieldKey & "&Orders=" & Orders & "&DFieldOrders=" & DFieldOrders)%></td>
	  </tr>
	</table>
	<%
	Rs.Close
End Sub

Sub Main_Guide(T)
	%>
	<table width=100% border=0 cellpadding=3 cellspacing=1 class=css_table bgcolor='#E1E1E1'>
	  <tr class=css_menu>
	    <td colspan=2><table width=100% border=0 cellpadding=4 cellspacing=0 class=css_main_table>
	        <tr>
	          <td class=css_main><a href=manage_sitelink.Asp?Page=<%=Page%><%=JumpUrl%>>站内链接管理</a></td>
	        </tr>
	      </table></td>
	  </tr>
	  <form name='frm' method='post' action='manage_sitelink.Asp?Act=UpDate&ID=<%=ID%>&Page=<%=Page%><%=JumpUrl%>'>
	    <%If T = 0 Then Style="" Else Style=""%>
	    <tr<%=Style%>>
	      <td class=css_col12>链接文字：<div id='hText' style="color:#ccc;letter-spacing: 0px;font-size:13px;">需要替换的文本,必填&nbsp;</div></td>
	      <td class=css_col22>
	      <input class='css_input' name="oText" type="text" id="oText" onfocus="hText.style.color='red';" onblur="hText.style.color='#ccc';" value="<%=U.vText%>" size=50 >
	      </td>
	    </tr>
	    <%If T = 0 Then Style="" Else Style=""%>
	    <tr<%=Style%>>
	      <td class=css_col11>链接描述：<div id='hDescription' style="color:#ccc;letter-spacing: 0px;font-size:13px;">链接的描述内容,留空则使用链接文字,随机选择描述请用|分隔不同的描述&nbsp;</div></td>
	      <td class=css_col21>
	      <input class='css_input' name="oDescription" type="text" id="oDescription" onfocus="hDescription.style.color='red';" onblur="hDescription.style.color='#ccc';" value="<%=U.vDescription%>" size=50 >
	      </td>
	    </tr>
	    <%If T = 0 Then Style="" Else Style=""%>
	    <tr<%=Style%>>
	      <td class=css_col12>链接地址：<div id='hLink' style="color:#ccc;letter-spacing: 0px;font-size:13px;">该文本对应的链接地址,推荐以http://形式开头&nbsp;</div></td>
	      <td class=css_col22>
	      <input class='css_input' name="oLink" type="text" id="oLink" onfocus="hLink.style.color='red';" onblur="hLink.style.color='#ccc';" value="<%=U.vLink%>" size=50 >
	      </td>
	    </tr>
	    <%If T = 0 Then Style="" Else Style=""%>
	    <tr<%=Style%>>
	      <td class=css_col11>优先级别：<div id='hOrder' style="color:#ccc;letter-spacing: 0px;font-size:13px;">数字越大,越优先替换&nbsp;</div></td>
	      <td class=css_col21>
	      <input class='css_input' name="oOrder" type="text" id="oOrder" onfocus="hOrder.style.color='red';" onblur="hOrder.style.color='#ccc';" value="<%=U.vOrder%>" size=10 >
	      </td>
	    </tr>
	    <%If T = 0 Then Style="" Else Style=""%>
	    <tr<%=Style%>>
	      <td class=css_col12>替换次数：<div id='hReplace' style="color:#ccc;letter-spacing: 0px;font-size:13px;">替换链接的次数，为0时则替换全部&nbsp;</div></td>
	      <td class=css_col22>
	      <input name="oReplace" type="text" class="css_input" id="oReplace" onfocus="hReplace.style.color='red';" onblur="hReplace.style.color='#ccc';" value="<%=U.vReplace%>" size="10" >
	      </td>
	    </tr>
	    <%If T = 0 Then Style="" Else Style=""%>
	    <tr<%=Style%>>
	      <td class=css_col11>打开方式：<span id='hTarget' style="color:#ccc;letter-spacing: 0px;font-size:13px;"></span></td>
	      <td class=css_col21>
	      <%If IsNull(U.vTarget) Then U.vTarget=""%>
	      <span style="width: 100px;"><input <%If  U.vTarget = 0 Then Response.Write "checked='checked'"%> class='css_input' name="oTarget" type="radio" id="oTarget" onfocus="hTarget.style.color='red';" onblur="hTarget.style.color='#ccc';" value="0"  >原窗口</span>
	      <span style="width: 100px;"><input <%If  U.vTarget = 1 Then Response.Write "checked='checked'"%> class='css_input' name="oTarget" type="radio" id="oTarget" onfocus="hTarget.style.color='red';" onblur="hTarget.style.color='#ccc';" value="1"  >新窗口</span>
	      </td>
	    </tr>
	    <%If T = 0 Then Style="" Else Style=""%>
	    <tr<%=Style%>>
	      <td class=css_col12>状态：<span id='hState' style="color:#ccc;letter-spacing: 0px;font-size:13px;"></span></td>
	      <td class=css_col22>
	      <%If IsNull(U.vState) Then U.vState=""%>
	      <span style="width: 100px;"><input <%If  U.vState = 0 Then Response.Write "checked='checked'"%> class='css_input' name="oState" type="radio" id="oState" onfocus="hState.style.color='red';" onblur="hState.style.color='#ccc';" value="0"  >禁用</span>
	      <span style="width: 100px;"><input <%If  U.vState = 1 Then Response.Write "checked='checked'"%> class='css_input' name="oState" type="radio" id="oState" onfocus="hState.style.color='red';" onblur="hState.style.color='#ccc';" value="1"  >启用</span>
	      </td>
	    </tr>
	    <tr class=css_page_list>
	      <td colspan=2><input type='submit' name='Submit' value='保存'></td>
	    </tr>
	  </form>
	</table>
	<%
End Sub
%>
</body>
</html>