<!--#include file="sdcms_check.asp"-->
<%
set sdcms=new Sdcms_Admin
sdcms.Check_admin
sdcms.Check_lever 2
set sdcms=nothing
select case action
case "add":title="添加链接"
case "edit":title="修改链接"
case else:title="链接管理"
end select
sd_table="sd_link"
sd_table01="sd_count"
ordnum=trim(request("ordnum"))
stype=trim(request("stype"))
if stype="" or not isnumeric(stype) then
stype=0
end if
select case t
case "0","1"
case else:t=0
end select
sdcms_head
%>

<div class="sdcms_notice"><span>管理操作：</span><a href="?action=add">添加链接</a>　┊　<a href="?">链接管理</a></div>
<br>
<ul id="sdcms_sub_title">
	<li class="<%if stype<>0 then echo "un" end if%>sub"><a<%if stype<>"" then%> href="?"<%end if%>><%=title%></a></li>
	<%if stype<>"" then%><li class="<%if stype<>1 then echo "un" end if%>sub"><a href="?stype=1">图片链接</a></li><li class="<%if stype<>2 then echo "un" end if%>sub"><a href="?stype=2">文字链接</a></li><li class="<%if stype<>3 then echo "un" end if%>sub"><a href="?stype=3">审核链接</a></li><%end if%>
</ul>
<div id="sdcms_right_b">
<%
select case action
case "add":add
case "edit":edit
case "save":save
case "del":del
case "up":up
case "down":down
case "pass":pass
case else:main
end select
closedb
sub main
%>
  <table border="0" align="center" cellpadding="3" cellspacing="1" class="table_b">
    <tr>
      <td width="50" class="title_bg">ID</td>
      <td class="title_bg">网站链接</td>
      <td width="100" class="title_bg">状态</td>
      <td width="100" class="title_bg">排序</td>
      <td width="200" class="title_bg">管理</td>
    </tr>
	<%
	sql="select id,title,url,pic,ispic,ordnum,"
	if Is_sql=0 then
	sql=sql&"(iif(ispass=0,'未验证','已验证'))"
	else
	sql=sql&"(case ispass when 0 then'未验证'else'已验证'end)"
	end if
	sql=sql&" from "&sd_table&" "
	select case stype
	case "1":sql=sql&"where ispic=1 and ispass=1"
	case "2":sql=sql&"where ispic=0 and ispass=1"
	case "3":sql=sql&"where ispass=0"
	case else:sql=sql&"where ispass=1"
	end select
	sql=sql&" order by ordnum desc"
	set rs=conn.execute(sql)
	while not rs.eof
	%>
    <tr onmouseover=this.bgColor='#EBFFDC'; onmouseout=this.bgColor='#ffffff';  bgcolor='#ffffff'>
      <td align="center"><%=rs(0)%></td>
	  <td height="33" align="center"><%if rs(4)=1 then%><a href="<%=rs(2)%>" target="_blank"><img src="<%=rs(3)%>" border="0" width="88" height="31"></a><%else%><a href="<%=rs(2)%>" target="_blank"><%=rs(1)%></a><%end if%></td>
	  <td align="center"><%=rs(6)%></td>
	  <td align="center"><a href="?action=up&id=<%=rs(0)%>&ordnum=<%=rs(5)%>&stype=<%=stype%>&t=<%=rs(4)%>">↑</a> <a href="?action=down&id=<%=rs(0)%>&ordnum=<%=rs(5)%>&stype=<%=stype%>&t=<%=rs(4)%>">↓</a></td>
      <td align="center"><%if stype=3 then%><a href="?action=pass&id=<%=rs(0)%>&t=1&stype=<%=stype%>">通过验证</a><%else%><a href="?action=pass&id=<%=rs(0)%>&t=0&stype=<%=stype%>">取消验证</a><%end if%> <a href="?action=edit&id=<%=rs(0)%>">编辑</a> <a href="?action=del&id=<%=rs(0)%>&stype=<%=stype%>" onclick='return confirm("真的要删除?不可恢复!");'>删除</a></td>
    </tr>
	<%rs.movenext
	wend%>
  </table>
  
<%
end sub
sub add
check_info
%>
  <table width="98%" border="0" align="center" cellpadding="3" cellspacing="1">
  <form name="add" method="post" action="?action=save&act=add" onSubmit='return checkadd()'>
    <tr>
      <td width="9%" align="center" class="tdbg">网站名称：      </td>
      <td width="91%" class="tdbg"><input name="t0" type="text" class="input" id="t0" size="40"></td>
    </tr>
    <tr class="tdbg">
      <td align="center">网站域名：      </td>
      <td><input name="t1" type="text" class="input" id="t1" size="40"> <span>请填写完整路径 如：http://www.sdcms.cn</span></td>
    </tr>
    <tr class="tdbg">
      <td align="center">链接类别：</td>
      <td><input name='t2' type='radio' onClick=$('flag').style.display='none';this.form.t3.disabled=true;  value='0' >文字链接 <input name='t2' type='radio' onClick=$('flag').style.display='block';this.form.t3.disabled=false; value='1' checked >图片链接</td>
    </tr>
    <tr class="tdbg" id='flag'>
      <td align="center">图片地址：</td>
      <td><input name="t3" type="text" class="input" id="t3" size="40"></td>
    </tr>
	<tr class="tdbg">
      <td align="center">是否验证：      </td>
      <td><input name="t4" type="radio" value="0">未验证 <input name="t4" type="radio" value="1" checked>已验证　<input name="up1" id="up1" type="checkbox" value="1" /><label for="up1">生成首页</label></td>
    </tr>
    <tr class="tdbg">
	  <td>&nbsp;</td>
      <td><input name="Submit" type="submit" class="bnt" value="添 加">
        <input name="Submit23" type="button" onClick="history.go(-1)" class="bnt" value="返 回"></td>
    </tr>
	</form>
  </table>
<%
end sub
sub edit
set rs=conn.execute("select id,title,url,ispic,pic,ispass from "&sd_table&" where id="&id&"")
if rs.eof then
echo "请勿非法提交参数":Died
end if
check_info
%>
  <table width="98%" border="0" align="center" cellpadding="3" cellspacing="1">
  <form name="add" method="post" action="?action=save&act=save&id=<%=id%>" onSubmit='return checkadd()'>
    <tr>
      <td width="9%" align="center" class="tdbg">网站名称：      </td>
      <td width="91%" class="tdbg"><input name="t0" type="text" class="input" value="<%=rs(1)%>" id="t0" size="30"></td>
    </tr>
    <tr class="tdbg">
      <td align="center">网站域名：      </td>
      <td><input name="t1" type="text" class="input" value="<%=rs(2)%>" id="t1" size="30"> <span>请填写完整路径 如：http://www.sdcms.cn</span></td>
    </tr>
    <tr class="tdbg">
      <td align="center">链接类别：</td>
      <td><input name='t2' type='radio' onClick=$('flag').style.display='none';this.form.t3.disabled=true; value='0' <%=w_check(rs(3),0)%>>文字链接 <input name='t2' type='radio' onClick=$('flag').style.display='block';this.form.t3.disabled=false; value='1' <%=w_check(rs(3),1)%>>图片链接</td>
    </tr>
	  <tr class="tdbg <%if rs(3)=0 then%>dis<%end if%>" id='flag' >
      <td align="center">图片地址：</td>
      <td><input name="t3" type="text" value="<%=rs(4)%>" class="input" id="t3" size="40"  <%if rs(3)=0 then%>disabled<%end if%>></td>
    </tr>
	<tr class="tdbg">
      <td align="center">是否验证：      </td>
      <td><input name="t4" type="radio" value="0" <%=w_check(rs(5),0)%>>未验证 <input name="t4" type="radio" value="1" <%=w_check(rs(5),1)%>>已验证 　<input name="up1" id="up1" type="checkbox" value="1" /><label for="up1">生成首页</label></td>
    </tr>
    <tr class="tdbg">
	  <td>&nbsp;</td>
      <td><input name="Submit" type="submit" class="bnt" value="保 存">
        <input name="Submit232" type="button" onClick="history.go(-1)" class="bnt" value="返 回"></td>
    </tr>
	</form>
  </table>
<%
end sub

sub save
t0=trim(request("t0"))
t1=trim(request("t1"))
t2=trim(request("t2"))
t3=trim(request("t3"))
t4=trim(request("t4"))
up1=trim(request("up1"))
if act="add" then
	set rs=conn.execute("select max(ordnum) from ["&sd_table&"] where ispic="&t2&"")
	if rs.eof then
		t5=1
	else
		if rs(0)<>"" then t5=cint(rs(0))+1 else t5=1 end if
	end if
end if

set rs=server.CreateObject("adodb.recordset")
sql="select title,url,ispic,pic,ispass,ordnum from "&sd_table&""
if act="save" then 
 sql=sql&" where id="&id&""
end if
rs.open sql,conn,1,3
if act="add" then 
  rs.addnew
else
  rs.update
end if
rs(0)=left(t0,255)
rs(1)=left(t1,255)
rs(2)=left(t2,255)
rs(3)=left(t3,255)
rs(4)=left(t4,255)
if act="add" then rs(5)=t5
rs.update
if act="add" then
conn.execute("update "&sd_table01&" set link_num=link_num+1 where id=1")
conn.execute("Insert into sd_log (sdcms_name,ip,content) values('"&sdcms_adminname&"','"&sdcms_adminip&"','添加链接："&rs(0)&"')")
else
conn.execute("Insert into sd_log (sdcms_name,ip,content) values('"&sdcms_adminname&"','"&sdcms_adminip&"','修改链接："&rs(0)&"')")
end if
if len(up1)>0 then
	set sdcms_c=new sdcms_create
	sdcms_c.Create_index
	set sdcms_f=nothing
end if
response.Redirect("?")
end sub

sub del
   conn.execute("update "&sd_table01&" set link_num=link_num-1 where id=1")
   conn.execute("Insert into sd_log (sdcms_name,ip,content) values('"&sdcms_adminname&"','"&sdcms_adminip&"','删除链接："&conn.execute("select title from "&sd_table&" where id="&id&"")(0)&"')")
  conn.execute("delete from "&sd_table&" where id="&id&"")
  set sdcms_c=new sdcms_create
  sdcms_c.Create_index
  set sdcms_f=nothing
  response.Redirect("?stype="&stype&"") 
end sub

sub pass
  conn.execute("update   "&sd_table&" set ispass="&t&" where id="&id&"")
  conn.execute("Insert into sd_log (sdcms_name,ip,content) values('"&sdcms_adminname&"','"&sdcms_adminip&"','审核链接："&conn.execute("select title from "&sd_table&" where id="&id&"")(0)&"')")
  set sdcms_c=new sdcms_create
  sdcms_c.Create_index
  set sdcms_f=nothing
  response.Redirect("?stype="&stype&"") 
end sub

sub up
	set rs=conn.execute("select top 1 id,ordnum from ["&sd_table&"] where ordnum>"&ordnum&" and ispic="&t&" order by ordnum  ")
	if not rs.eof then
	 conn.execute("update  ["&sd_table&"] set ordnum="&rs(1)&" where id="&id&"")
	 conn.execute("update  ["&sd_table&"] set ordnum="&ordnum&" where id="&rs(0)&"")
	end if
	set sdcms_c=new sdcms_create
	sdcms_c.Create_index
	set sdcms_f=nothing
	response.redirect("?stype="&stype&"") 
end sub

sub down
	set rs=conn.execute("select top 1 id,ordnum from ["&sd_table&"] where ordnum<"&ordnum&" and ispic="&t&" order by ordnum desc")
	if not rs.eof then
	 conn.execute("update  ["&sd_table&"] set ordnum="&rs(1)&" where id="&id&"")
	 conn.execute("update ["&sd_table&"] set ordnum="&ordnum&" where id="&rs(0)&"")
	end if
	set sdcms_c=new sdcms_create
	sdcms_c.Create_index
	set sdcms_f=nothing
	response.redirect("?stype="&stype&"") 
end sub

sub check_info
with response
.write("	<script>")
.write("	function checkadd()")
.write("	{")
.write("	if (document.add.t0.value=='')")
.write("	{")
.write("	alert('网站名称不能为空');")
.write("	document.add.t0.focus();")
.write("	return false")
.write("	}")
.write("	if (document.add.t1.value=='')")
.write("	{")
.write("	alert('网站域名不能为空');")
.write("	document.add.t1.focus();")
.write("	return false")
.write("	}")
.write("	if (!document.add.t3.disabled && document.add.t3.value=='')")
.write("	{")
.write("	alert('图片地址不能为空');")
.write("	document.add.t3.focus();")
.write("	return false")
.write("	}")
.write("	}")
.write("	</script>")
end with
end sub
%>  
</div>
</body>
</html>