<!--#include file="conn.asp"-->
<!--#include file="check.asp"-->

<% 
 '===========================================================================================
	'软件名称：126 cms 视频影视管理系统
	'程序版权：126电影               '咨询QQ：479025
	'开发作者：magicblack(479025)    '官方网站：http://www.126oo.com/
	'Copyright (C) 2009 - ... 126oo.com  All Rights Reserved.
	'郑重声明:
	'    1、免费版本请在程序首页保留版权信息，并做上本站LOGO友情连接,商业版本无此要求;
	'    2、任何个人或组织不得以盈利为目的发布,修改,本软件及其他副本上一切关于版权的信息；
	'    3、126电影保留此软件的法律追究权利；
'==========================================================================================
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
<HTML xmlns="http://www.w3.org/1999/xhtml">
<HEAD>
<TITLE>友情链接管理 - 后台管理中心 - 126电影程序CMS</TITLE>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<LINK href="images/css_body.css" type=text/css rel=stylesheet>
<script language="javascript" src="images/admin.js"></script>
</HEAD>
<BODY>
<DIV class=bodytitle>
<DIV class=bodytitleleft></DIV>
<DIV class=bodytitletxt>友情链接管理</DIV>
<DIV class=bodytitletxt2><a href="admin_link.asp?action=add">添加友情链接</a></DIV>
</DIV>

<%
response.Charset="GBK"
dim action
action = SafeData("RQ","action",0)

Select case action
	case "add" : add
	case "addsave" : addsave
	case "edit" : edit
	case "editsave" : editsave
	case "editall" : editall
	case "del" : del
	case "delall" : delAll
	case "last" : moveTolast
	case "next" : moveTonext
	case else : main
End Select

sub addsave
Dim L_Name : L_Name = SafeData("RF","L_Name",0)
Dim L_Type : L_Type = SafeData("RF","L_Type",0)
Dim L_Url : L_Url = SafeData("RF","L_Url",0)
Dim L_Sort : L_Sort = SafeData("RF","L_Sort",0)
Dim L_Logo : L_Logo = SafeData("RF","L_Logo",0)

if isN(L_Sort) then  L_Sort= Database.GetRecordBySQL("select max(l_sort) from Tbl_Link")(0)+1
if not isNum(L_Sort) then ErrMsg "友情链接","信息填写不完整，请检查!"
		

Dim result : result = DataBase.AddRecord("Tbl_Link",Array("L_Name:"&L_Name, "L_Type:"&L_Type, "L_Url:"&L_Url, "L_Sort:"&L_Sort, "L_Logo:"&L_Logo))   
If result<>0 Then  
    ShowMsg "添加友情链接成功！"  ,"admin_link.asp" 
End If  

end sub

sub editsave
Dim L_ID : L_ID = SafeData("RF","L_ID",0)
Dim L_Name : L_Name = SafeData("RF","L_Name",0)
Dim L_Type : L_Type = SafeData("RF","L_Type",0)
Dim L_Url : L_Url = SafeData("RF","L_Url",0)
Dim L_Sort : L_Sort = SafeData("RF","L_Sort",0)
Dim L_Logo : L_Logo = SafeData("RF","L_Logo",0)

if isN(L_Sort) then  L_Sort= Database.GetRecordBySQL("select max(l_sort) from Tbl_Link")(0)+1
if not isNum(L_Sort) then ErrMsg "友情链接","信息填写不完整，请检查!"
		
Dim result : result = DataBase.UpdateRecord("Tbl_Link","L_ID = "& L_ID ,Array("L_Name:"&L_Name, "L_Type:"&L_Type, "L_Url:"&L_Url, "L_Sort:"&L_Sort, "L_Logo:"&L_Logo))   
If result<>0 Then  
    ShowMsg "修改友情链接成功！" ,"admin_link.asp" 
End If  

end sub

sub editall
	dim ids,id,L_Name,L_Sort,L_Url
	ids = split(replace(SafeData("RF","L_ID",0)," ",""),",")
    
	For Each id In ids
		L_Name = SafeData("RF","L_Name" &id,0)
		L_Sort = SafeData("RF","L_Sort" &id,0) 
		L_Url = SafeData("RF","L_url" &id,0)
		
		if isN(L_Name)  then   ErrMsg "友情链接","信息填写不完整，请检查!"
		if isN(L_Url) then ErrMsg "友情链接","信息填写不完整，请检查!"
		
		if isN(L_Sort) then  L_Sort= Database.GetRecordBySQL("select max(l_sort) from Tbl_Link")(0)+1
		if not isNum(L_Sort) then ErrMsg "友情链接","信息填写不完整，请检查!"
		
			DataBase.UpdateRecord "Tbl_Link","L_ID = "& id ,Array("L_Name:"&L_Name,"L_Url:"&L_Url, "L_Sort:"&L_Sort)
		
	Next
	
	ShowMsg "批量修改完毕!","admin_link.asp" 
end sub


sub del
	Dim L_ID : L_ID = SafeData("RQ","L_ID",0)
	Dim result : result = Database.DeleteRecord("Tbl_Link", "L_ID:" & L_ID)   
	If result<>0 Then  
    ShowMsg "删除记录成功!" ,"admin_link.asp"  
	End If  
end sub

sub delall
	Dim L_ID : L_ID = SafeData("RF","L_ID",0)
	if isN(L_ID) then ShowMsg "没有选择任何数据!" ,"admin_link.asp"  
	Dim result : result = Database.DeleteRecord("Tbl_Link", "L_ID in (" & L_ID & ")")   
	If result<>0 Then  
    ShowMsg "批量删除记录成功!" ,"admin_link.asp"  
	End If 
end sub


sub moveToLast
	Dim L_ID : L_ID = SafeData("RQ","L_ID",0)
	Dim CurSort : CurSort = Database.GetRecordBySQL("select l_sort from Tbl_Link where L_ID = " & L_ID)(0)
	Dim Lessthan : Lessthan = Database.GetRecordBySQL("select count(*) from Tbl_Link where L_Sort < " & CurSort)(0)
	
	if Lessthan>0 then 
	 Dim L_Sort : L_Sort=Database.GetRecordBySQL("select top 1 L_sort from Tbl_Link  where L_sort<"&CurSort&" order by L_sort desc")(0)
		
	    DataBase.UpdateRecord "Tbl_Link","L_ID = "& L_ID ,Array( "L_Sort:"&L_Sort)
	else
		DataBase.UpdateRecord "Tbl_Link","L_ID = "& L_ID ,Array( "L_Sort:L_Sort-1")
	end if
	ShowMsg "上移成功!" ,"admin_link.asp"  
end sub 

sub moveToNext
	Dim L_ID : L_ID = SafeData("RQ","L_ID",0)
	Dim CurSort : CurSort = Database.GetRecordBySQL("select l_sort from Tbl_Link where L_ID = " & L_ID)(0)
	Dim Lessthan : Lessthan = Database.GetRecordBySQL("select count(*) from Tbl_Link where L_Sort > " & CurSort)(0)
	
	if Lessthan>0 then 
	 Dim L_Sort : L_Sort=Database.GetRecordBySQL("select top 1 L_sort from Tbl_Link  where L_sort>"&CurSort&" order by L_sort desc")(0)
		
	 DataBase.UpdateRecord "Tbl_Link","L_ID = "& L_ID ,Array( "L_Sort:"&L_Sort)
	else
		DataBase.UpdateRecord "Tbl_Link","L_ID = "& L_ID ,Array( "L_Sort:L_Sort+1")
	end if
	ShowMsg "下移成功!" ,"admin_link.asp"  
end sub 

sub main
Dim rs : Set rs = DataBase.GetPageRecord(0,Array("Tbl_Link:L_ID,L_Name,L_Type,L_Url,L_Sort","","L_Sort,L_ID Asc","L_ID")) 

Dim Page
 Page = DataBase.GetPager ("")

%>

<TABLE width="96%" border=0 align=center cellpadding="5" cellSpacing=1 class=tbtitle style="BACKGROUND: #cad9ea;">
<form action="" method="post" name="form1"> 
  <TBODY>
    <TR bgColor="#f5fafe">
	  <TD width="4%" align="center" >&nbsp;</TD>
      <TD align="center">友情链接名称</TD>
	  <TD width="20%" align="center">地址</TD>
      <TD width="15%" align="center">类型</TD>
	  <TD width="15%" align="center">排序</TD>
	  <TD width="25%" align="center">操作</TD>
    </TR>
	<%if not rs.eof then
		While Not rs.eof
	 %>
    <TR bgcolor="#FFFFFF">
	  <TD align="center"><input name="L_ID" type="checkbox" id="L_ID" value="<%=rs("L_ID")%>" /></TD>
      <TD><input type="text" name="l_name<%=rs("L_ID")%>" value="<%=rs("L_Name")%>" size="20"/></TD>
	  <TD><input name="l_url<%=rs("L_ID")%>" type="text" value="<%=rs("L_url")%>"  size="30"/></TD>
      <TD align="center"><% if rs("L_Type") ="font" then response.Write "文字链接" else response.Write "图片链接" end if %></TD>
	  <TD><input name="l_sort<%=rs("L_ID")%>" type="text" value="<%=rs("L_Sort")%>"  size="10"/></TD>
      <TD align="center">
	  <A href="admin_link.asp?action=last&L_ID=<%=rs("L_ID")%>">上移</a> | 
	  <A href="admin_link.asp?action=next&L_ID=<%=rs("L_ID")%>">下移</a> | 
	  <A href="admin_link.asp?action=edit&L_ID=<%=rs("L_ID")%>">修改</a> | 
	  <A href="admin_link.asp?action=del&L_ID=<%=rs("L_ID")%>" onClick="return confirm('确定要删除吗?');">删除</a></TD>
    </TR>
	<%rs.MoveNext
	Wend 
	end if%>
	<TR bgColor="#f5fafe">
	<td  colspan="6"><label>全选<input type="checkbox" name="chkall" id="chkall" class="checkbox" onClick="checkAll(this.checked,'input','L_ID')" /></label><label>反选<input type="checkbox" name="chkothers" id="chkothers" class="checkbox" onClick="checkOthers('input','L_ID')" /></label><input type="submit" value="批量删除" onClick="if(confirm('确定要删除吗')){form1.action='?action=delall';}else{return false}" class="btn"  />
	&nbsp;&nbsp;<input type="submit" value="批量修改选中" name="Submit"  class="btn"  onclick="form1.action='?action=editall';"/>
	</td></tr>
	
    <TR align="center" bgcolor="#f8fbfb">
      <TD colspan="6"><%=Page%></TD>
    </TR>
  </TBODY>
  </form>
</TABLE>

<%
Database.C(rs)
end sub

sub add
%>

<TABLE width="96%" border=0 align=center cellpadding="4" cellSpacing=1 class=tbtitle style="BACKGROUND: #cad9ea;">
<form action="?action=addsave" method="post">
  <TBODY>
    <TR>
      <TD vAlign=center width="20%" bgColor=#f5fafe>网站名称：</TD>
      <TD bgColor=#ffffff><INPUT id="L_Name" size=50 value="" name="L_Name" dataType="Require" msg="请填写友情链接标题">
	  </TD>
    </TR>
<TR>
     <TD vAlign=center width="20%" bgColor=#f5fafe>网站地址：</TD>
      <TD bgColor=#ffffff><INPUT id="L_Url" size=50 value="http://" name="L_Url" dataType="Require">
	  </TD>
    </TR>
	
     <TD vAlign=center width="20%" bgColor=#f5fafe>链接类型：</TD>
      <TD bgColor=#ffffff>
	  <select name="L_Type" >
	  <option value="font">文字链接</option>
	  <option value="pic">图片链接</option>
	  </select>
	  </TD>
    </TR>
	
     <TD vAlign=center width="20%" bgColor=#f5fafe>排序：</TD>
      <TD bgColor=#ffffff><INPUT id="L_Sort" size=5 value="" name="L_Sort" dataType="Require">
	  </TD>
    </TR>
	
    <TR align="center" bgcolor="#f8fbfb">
      <TD colspan="2"><INPUT class=inputbut type=submit value=添加 name=Submit>
      &nbsp;</TD>
    </TR>
  </TBODY>
  </form>
</TABLE>

<%
end sub

sub edit
Dim L_ID : L_ID = SafeData("RQ","L_ID",0)
Dim rs : Set rs = Database.GetRecordDetail("Tbl_Link","L_ID=" & L_ID)  

if rs.eof then ShowMsg "找不到此ID的友情链接!","admin_link.asp"

%>
<TABLE width="96%" border=0 align=center cellpadding="4" cellSpacing=1 class=tbtitle style="BACKGROUND: #cad9ea;">
<form action="?action=editsave" method="post">
<input name="L_ID" type="hidden" value="<%=rs("L_ID")%>">
  <TBODY>
    <TR>
      <TD vAlign=center width="20%" bgColor=#f5fafe>网站名称：</TD>
      <TD bgColor=#ffffff><INPUT id="L_Name" size=50 value="<%=rs("L_Name")%>" name="L_Name" dataType="Require" msg="请填写友情链接标题">
	  </TD>
    </TR>
<TR>
     <TD vAlign=center width="20%" bgColor=#f5fafe>网站地址：</TD>
      <TD bgColor=#ffffff><INPUT id="L_Url" size=50 value="<%=rs("L_Url")%>" name="L_Url" dataType="Require">
	  </TD>
    </TR>
	
     <TD vAlign=center width="20%" bgColor=#f5fafe>链接类型：</TD>
      <TD bgColor=#ffffff>
	  <select name="L_Type" >
	  <option value="font" <% if rs("L_Type") = "font" then response.Write "checked" %>>文字链接</option>
	  <option value="pic" <% if rs("L_Type") = "pic" then response.Write "checked" %>>图片链接</option>
	  </select>
	  </TD>
    </TR>
	
     <TD vAlign=center width="20%" bgColor=#f5fafe>排序：</TD>
      <TD bgColor=#ffffff><INPUT id="L_Sort" size=5 value="<%=rs("L_Sort")%>" name="L_Sort" dataType="Require">
	  </TD>
    </TR>
	
    <TR align="center" bgcolor="#f8fbfb">
      <TD colspan="2"><INPUT class=inputbut type=submit value=添加 name=Submit>
      &nbsp;</TD>
    </TR>
  </TBODY>
  </form>
</TABLE>
<%
Database.c(rs)
end sub
%>
</BODY>
</HTML>