<!--#include file="conn.asp"-->
<!--#include file="config.asp"-->
<%
if session("admin")="" then
  response.redirect "admin_login.asp"
end if

'06 友情链接管理
if not checkflag("06") then
  call mb("对不起，您没有管理友情链接的权限！","",0)
end if


dim action
dim totalpage,maxperpage,totalrecords,i,currentpage
action=request("action")
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>友情链接管理相关</title>
<script language=javascript src="mouse_up.js"></script>
<link href="admin.css" rel="stylesheet" type="text/css">
</head>

<body leftmargin="5" topmargin="0">
<table width="100%" border="0" align="center" cellpadding="2" cellspacing="0" bgcolor="#000000" vspace="0" hspace="0">
  <tr bgcolor="#EFEBEF"> 
    <td height="27"><table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr> 
          <td width="86%"><font color="#FF3000">.:: 您可以在这里进行[友情链接管理]相关操作</font></td>
          <td width="14%" height="20" align="center"><a href="javascript:this.location.reload()"><img src="images/refresh.gif" alt="刷新" width="40" height="12" border="0"></a></td>
        </tr>
      </table></td>
  </tr>
  <tr > 
    <td height="1" bgcolor="#000000"></td>
  </tr>
</table>
<%
select case action
  case "add"
    call add() 
  case "addsave"
    call addsave()
  case "edit"
    call edit()
  case "editsave"
    call editsave()
  case "del"
    call del()
  case else
    call main()
end select

sub add()

%>
<br>
<form action="?action=addsave" method="post" name="add" id="add">
  <table width="500" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
    <tr align="center" bgcolor="#EFEBEF" > 
      <td height="25" colspan="2"><font color="#000000">友情链接 - 添加</font></td>
    </tr>
    <tr bgcolor="#FFFFFF"> 
      <td width="23%" height="25" align="center">网站名称：</td>
      <td width="77%" height="25">&nbsp; 
        <input name="sitename" type="text" class="input" id="sitename" size="40"></td>
    </tr>
    <tr bgcolor="#FFFFFF"> 
      <td height="25" align="center">网站地址：</td>
      <td height="25">&nbsp; 
        <input name="siteurl" type="text" class="input" id="siteurl" value="http://" size="40"></td>
    </tr>
    <tr bgcolor="#FFFFFF"> 
      <td height="25" align="center">Logo地址：</td>
      <td height="25">&nbsp; 
        <input name="logourl" type="text" class="input" id="logourl" value="http://" size="40"></td>
    </tr>
    <tr bgcolor="#FFFFFF"> 
      <td height="25" align="center">链接类型：</td>
      <td height="25">&nbsp; 
        <select name="ltype" size="1" class="input" id="ltype">
          <option value="0">文字链接</option>
          <option value="1" selected>Logo链接</option>
          <option value="2">合作伙伴</option>
        </select></td>
    </tr>
    <tr bgcolor="#FFFFFF"> 
      <td height="25" align="center">网站说明：</td>
      <td height="25">&nbsp; 
        <textarea name="remark" cols="45" rows="10" class="input" id="remark"></textarea></td>
    </tr>
    <tr bgcolor="#FFFFFF"> 
      <td height="30" colspan="2" align="center"> 
        <input name="Submit" type="submit" class="button" value=" 确定添加 ">
        　 
        <input name="Submit2" type="reset" class="button" value=" 重新填写 "> </td>
    </tr>
  </table>
</form>
<%
end sub

sub addsave()

dim sitename,siteurl,logourl,remark,ltype
sitename=checkstr(trim(request.form("sitename")))
siteurl=checkstr(trim(request.form("siteurl")))
logourl=checkstr(trim(request.form("logourl")))
remark=checkstr(trim(request.form("remark")))
ltype=request("ltype")

if not isinteger(ltype) then
  ltype=0
end if

if sitename="" or strlength(sitename)>50 then
  call mb("站点名称不能为空，或大于25个字符！","",0)
end if

if siteurl="" or siteurl="http://" then
  call mb("网站网址不能为空！","",0)
end if

if ltype>0 and (logourl="" or logourl="http://") then
  call mb("请输入Logo链接地址！","",0)
end if

if remark="" then
  call mb("网站说明不能为空！","",0)
end if

set rs=server.createobject("adodb.recordset")
sql="select * from link where id is null"
rs.open sql,conn,1,3

rs.addnew()
rs("sitename")=sitename
rs("siteurl")=siteurl
rs("logourl")=logourl
rs("remark")=remark
rs("ltype")=ltype
rs("passed")=true
rs.update

rs.close
call mb("添加友情链接成功！","admin_link.asp?action=add",1)

end sub

sub edit()

dim id

id=request("id")
if not isinteger(id) then
  call mb("对不起，请指定要编辑的友情链接！","",0)
end if

set rs=conn.execute("select * from link where id="&id)
if rs.bof and rs.eof then
  call mb("找不到友情链接！","",0)
end if
%>
<br>
<form action="?action=editsave" method="post" name="edit" id="edit">
  <table width="500" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
    <tr align="center" bgcolor="#EFEBEF" > 
      <td height="25" colspan="2"><font color="#000000">友情链接 - 编辑</font></td>
    </tr>
    <tr bgcolor="#FFFFFF"> 
      <td width="23%" height="25" align="center">网站名称：</td>
      <td width="77%" height="25">&nbsp; 
        <input name="sitename" type="text" class="input" id="sitename" value="<%=rs("sitename")%>" size="40"></td>
    </tr>
    <tr bgcolor="#FFFFFF"> 
      <td height="25" align="center">网站地址：</td>
      <td height="25">&nbsp; 
        <input name="siteurl" type="text" class="input" id="siteurl" value="<%=rs("siteurl")%>" size="40"></td>
    </tr>
    <tr bgcolor="#FFFFFF"> 
      <td height="25" align="center">Logo地址：</td>
      <td height="25"> &nbsp; 
        <input name="logourl" type="text" class="input" id="logourl" value="<%=rs("logourl")%>" size="40"></td>
    </tr>
    <tr bgcolor="#FFFFFF"> 
      <td height="25" align="center">链接类型：</td>
      <td height="25">&nbsp; 
        <select name="ltype" size="1" class="input" id="ltype">
          <option value="0" <%if rs("ltype")=0 then response.write " selected"%>>文字链接</option>
          <option value="1" <%if rs("ltype")=1 then response.write " selected"%>>Logo链接</option>
          <option value="2" <%if rs("ltype")=2 then response.write " selected"%>>合作伙伴</option>
        </select></td>
    </tr>
    <tr bgcolor="#FFFFFF"> 
      <td height="25" align="center">网站说明：</td>
      <td height="25">&nbsp; 
        <textarea name="remark" cols="45" rows="10" class="input" id="remark"><%=rs("remark")%></textarea></td>
    </tr>
    <tr bgcolor="#FFFFFF"> 
      <td height="30" colspan="2" align="center"> 
        <input name="Submit" type="submit" class="button" value=" 确定编辑 ">
        　 
        <input name="Submit2" type="reset" class="button" value=" 重新填写 ">
        <input name="id" type="hidden" id="id" value="<%=id%>"> </td>
    </tr>
  </table>
</form>
<%
rs.close
set rs=nothing
end sub

sub editsave()

dim id:id=request("id")
if not isinteger(id) then
  call mb("对不起，请指定要编辑的友情链接！","",0)
end if

dim sitename,siteurl,logourl,remark,ltype
sitename=checkstr(trim(request.form("sitename")))
siteurl=checkstr(trim(request.form("siteurl")))
logourl=checkstr(trim(request.form("logourl")))
remark=checkstr(trim(request.form("remark")))
ltype=request("ltype")

if not isinteger(ltype) then
  ltype=0
end if

if sitename="" or strlength(sitename)>50 then
  call mb("站点名称不能为空，或大于25个字符！","",0)
end if

if siteurl="" then
  call mb("网站网址不能为空！","",0)
end if

if ltype>0 and logourl="" then
  call mb("请输入Logo链接地址！","",0)
end if

if remark="" then
  call mb("Flash说明不能为空！","",0)
end if

set rs=server.createobject("adodb.recordset")
sql="select * from link where id="&id
rs.open sql,conn,1,3

if rs.bof and rs.eof then
  call mb("找不到要编辑的友情链接！","",0)
else
 rs("sitename")=sitename
 rs("siteurl")=siteurl
 rs("logourl")=logourl
 rs("remark")=remark
 rs("ltype")=ltype
 rs("passed")=true
 rs.update
end if

rs.close
set rs=nothing
call mb("编辑友情链接成功！","admin_link.asp",1)

end sub


sub main()

response.expires=0
currentpage=request("page")
if not isinteger(currentpage) then
  currentpage=1
else
  currentpage=clng(currentpage)
end if

maxperpage=15
totalrecords=0
totalpage=1
i=1

set rs=server.createobject("adodb.recordset")
sql="select * from link order by id desc"
rs.open sql,conn,1,1

if not(rs.bof and rs.eof) then
  rs.pagesize=maxperpage
  rs.absolutepage=currentpage
  totalpage=rs.pagecount
  totalrecords=rs.recordcount
end if
%>
<br>
<br>

<table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
  <tr align="center" bgcolor="#EFEBEF"> 
    <td width="5%" height="23"><font color="#000000">ID</font></td>
    <td width="30%" height="23"><font color="#000000">网站名称</font></td>
    <td width="25%" height="23"><font color="#000000">网　　址</font></td>
    <td width="10%" height="23"><font color="#000000">链接类型</font></td>
    <td width="16%" height="23"><font color="#000000">加入日期</font></td>
    <td width="14%" height="23"><font color="#000000">操　作</font></td>
  </tr>
  <%do until rs.eof or i>maxperpage%>
  <tr bgcolor="#FFFFFF"> 
    <td height="23">&nbsp;<%=rs("id")%></td>
    <td height="23">&nbsp;<a href="<%=rs("siteurl")%>" title="访问该网站..." target=_blank><%=rs("sitename")%></a></td>
    <td height="23">&nbsp;<%=rs("siteurl")%></td>
    <td height="23">&nbsp; 
      <%
	select case rs("ltype")
	  case 1
	    response.write "Logo"
	  case 2
	    response.write "合作伙伴"
	  case else
	    response.write "文字链接"
	end select
   %>
    </td>
    <td height="23">&nbsp;<%=rs("dateandtime")%></td>
    <td height="23" align="center"> <a href="?action=edit&id=<%=rs("id")%>" title="编辑">编辑</a> 
      <a href="?action=del&id=<%=rs("id")%>" title="删除友情链接..." onclick="javascript:if(confirm('是否真的要删除友情链接吗？\n\n系统提示：删除后不可恢复！')){return true;}else{return false;}">删除</a></td>
  </tr>
  <%rs.movenext
   i=i+1
   loop
  %>
  <tr bgcolor="#FFFFFF"> 
    <td height="23" colspan="6"> 
      <%if totalrecords>0 then call showpage("admin_link.asp",totalrecords,maxperpage,true,true,"个友情链接")%>
    </td>
  </tr>
</table>
<%
rs.close
set rs=nothing
end sub

sub del()

dim id:id=request("id")

if not isinteger(id) then
 call mb("请指定要删除的链接！","",0)
end if

conn.execute("delete from link where id="&id)

call mb("删除友情链接成功！","admin_link.asp",1)

end sub
%>
</body>
</html>
