<!--#include file="sdcms_check.asp"-->
<%
set sdcms=new Sdcms_Admin
sdcms.Check_admin
sdcms.Check_lever 15
set sdcms=nothing
select case action
case "add":title="添加内链"
case "edit":title="修改内链"
case else:title="内链管理"
end select
sd_table="sd_links"
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="sub"><%=title%></li> 
</ul>
<div id="sdcms_right_b">
<%
select case action
case "add":add
case "edit":edit
case "save":save
case "del":del
case else:main
end select
closedb
sub main
%>
  <table border="0" align="center" cellpadding="3" cellspacing="1" class="table_b">
    <form name="add" action="?" method="post"  onSubmit="return confirm('确定要执行选定的操作吗？');">
	<tr>
	  <td class="title_bg">选择</td>
      <td class="title_bg">I　D</td>
      <td class="title_bg" width="300">内链接</td>
      <td class="title_bg">窗口类别</td>
      <td class="title_bg">是否启用</td>
      <td class="title_bg">管理</td>
    </tr>
	<%
	page=request.querystring("page")
	if page="" or not isnumeric(page) then
	page=1
	end if
	pages = 20
	set rs=server.CreateObject("adodb.recordset")
	sql="select id,title,content,siteurl,linktype,ispass from "&sd_table&" order by ordnum desc"
	rs.open sql,conn,1,1	
	if rs.eof then
	else
	rs.pagesize = pages
	maxpagecount=rs.pagecount
	rs.absolutepage = page 
	rcount1=0
	pagestart=page-5
	pageend=page+5
	if pagestart<1 then
	pagestart=1
	end if
	if pageend>maxpagecount then
	pageend=maxpagecount
	end if
	rcount=rs.RecordCount
	do while not rs.eof and rcount1 <rs.pagesize  
	%>
    <tr onmouseover=this.bgColor='#EBFFDC'; onmouseout=this.bgColor='#ffffff';  bgcolor='#ffffff'>
	 <td align="center"><input name="id"  type="checkbox" onClick="unselectall()"   value="<%=rs(0)%>"></td>
      <td align="center"><%=rs(0)%></td>
	  <td align="center"><a href="<%=rs(3)%>" title="<%=rs(2)%>" target="_blank"><%=rs(1)%></a></td>
	  <td align="center"><%select case rs(4):case 1:echo "新窗口":case else:echo "原窗口":end select%></td>
	  <td align="center"><%select case rs(5):case 1:echo "是":case else:echo "否":end select%></td>
      <td align="center"><a href="?action=edit&id=<%=rs(0)%>">编辑</a> <a href="?action=del&id=<%=rs(0)%>" onclick='return confirm("真的要删除?不可恢复!");'>删除</a></td>
    </tr>
	<%
	rs.movenext
	rcount1=rcount1+1
	loop
	end if         
	%>
	<tr>
      <td colspan="6" class="tdbg" >
	  <span class="right">转到第
		 <select onChange="location.href='?page='+this.value+''">
		 <%for i=1 to maxpagecount%>
		 <option value="<%=i%>" <%if clng(page)=clng(i) then echo "selected" end if%>><%=i%></option>
		 <%next%>
		 </select>页</span>　<input name="chkAll" type="checkbox" id="chkAll" onclick=CheckAll(this.form) value="checkbox"> 全选 
              <select name="action">
			  <option>→操作</option>
			  <option value="del">删除</option>
			  </select> 
             
      <input type="submit" class="bnt01" value="执行">

</td>
    </tr>
	<%if rcount>0 then%>
	<tr>
      <td colspan="6" class="tdbg" align="center"><%
if page<>"1" then
echo "<a href=?page="&page-1&">上一页</a> "
else
echo "上一页 "
end if
for i=pagestart to pageend
if i=0 then 
i=1
end if
if i=clng(page) then
str="<font color=red><b>"&i&"</b></font>"
else
str=i
end if
strurl="[<a href=?page="&i&">"&str&"</a>]"
echo strurl
next
if page=maxpagecount then
echo " 下一页"
elseif  page<>""&maxpagecount&"" then
echo " <a href=?page="&page+1&"&stype="&stype&"&classid="&classid&">下一页</a>"
else
echo " 下一页"
end if
echo " 页次:"&page&"/"&maxpagecount&" 页   每页: "&pages&" 条  总数: "&rcount&" 条"
%></td>
	  </tr>
	  <%end if%>
	</form>
  </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="12%" align="center" class="tdbg">名 称：      </td>
      <td 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"></td>
    </tr>
	<tr class="tdbg">
      <td align="center">链 接：</td>
      <td><input name="t2" type="text" class="input" id="t2" size="40"> <span>请填写完整路径 如：http://www.sdcms.cn</span></td>
    </tr>
    <tr class="tdbg">
      <td align="center">优 先：</td>
      <td><input name="t3" type="text" class="input" id="t3" size="40" value="0" onKeyUp="value=value.replace(/[^\d]/g,'');"  onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''));"> <span>数字越大越优先</span></td>
    </tr>
	<tr class="tdbg">
      <td align="center">窗 口：</td>
      <td><input name="t5" type="radio" id="t5" value="0" checked="checked" />原窗<input name="t5" type="radio" id="t5" value="1" />新窗</td>
    </tr>
	<tr class="tdbg">
      <td align="center">状 态：</td>
      <td><input name="t6" type="radio" id="t6" value="1" checked="checked" />启用<input name="t6" type="radio" id="t6" value="0" />关闭</td>
    </tr>
    <tr class="tdbg">
	  <td>&nbsp;</td>
      <td><input name="Submit" type="submit" class="bnt" value="添 加">
        <input name="Submit2" type="button" onClick="history.go(-1)" class="bnt" value="返 回"></td>
    </tr>
	</form>
  </table>
<%

end sub
sub edit
set rs=conn.execute("select id,title,content,siteurl,ordnum,replacenum,linktype,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="12%" align="center" class="tdbg">名 称：      </td>
      <td class="tdbg"><input name="t0" type="text" class="input" id="t0" size="40" value="<%=rs(1)%>"></td>
    </tr>
    <tr class="tdbg">
      <td align="center">提 示：</td>
      <td><input name="t1" type="text" class="input" id="t1" size="40" value="<%=rs(2)%>"></td>
    </tr>
	<tr class="tdbg">
      <td align="center">链 接：</td>
      <td><input name="t2" type="text" class="input" id="t2" size="40" value="<%=rs(3)%>"> <span>请填写完整路径 如：http://www.sdcms.cn</span></td>
    </tr>
    <tr class="tdbg">
      <td align="center">优 先：</td>
      <td><input name="t3" type="text" class="input" id="t3" size="40" value="<%=rs(4)%>" onKeyUp="value=value.replace(/[^\d]/g,'');"  onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''));"> <span>数字越大越优先</span></td>
    </tr>
	<tr class="tdbg">
      <td align="center">窗 口：</td>
      <td><input name="t5" type="radio" id="t5" value="0" <%=w_check(rs(6),0)%> />原窗<input name="t5" type="radio" id="t5" value="1" <%=w_check(rs(6),1)%> />新窗</td>
    </tr>
	<tr class="tdbg">
      <td align="center">状 态：</td>
      <td><input name="t6" type="radio" id="t6" value="1" <%=w_check(rs(7),1)%> />启用<input name="t6" type="radio" id="t6" value="0" <%=w_check(rs(7),0)%> />关闭</td>
    </tr>
    <tr class="tdbg">
	  <td>&nbsp;</td>
      <td><input name="Submit" type="submit" class="bnt" value="保 存">
        <input name="Submit22" type="button" onClick="history.go(-1)" class="bnt" value="返 回"></td>
    </tr>
	</form>
  </table>
<%
end sub
sub save
set sdcms_f=new sdcms_function
t0=trim(request("t0"))
t1=trim(request("t1"))
t2=trim(request("t2"))
t3=sdcms_f.Requestint(trim(request("t3")))
t5=sdcms_f.Requestint(trim(request("t5")))
t6=sdcms_f.Requestint(trim(request("t6")))
set sdcms_f=nothing
set rs=server.CreateObject("adodb.recordset")
sql="select title,content,siteurl,ordnum,linktype,ispass,id 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,50)
rs(1)=left(t1,255)
rs(2)=left(t2,255)
rs(3)=left(t3,50)
rs(4)=left(t5,50)
rs(5)=left(t6,50)
rs.update
if act="add" then
conn.execute("Insert into sd_log (sdcms_name,ip,content) values('"&sdcms_adminname&"','"&sdcms_adminip&"','添加内链接："&t0&"')")
else
conn.execute("Insert into sd_log (sdcms_name,ip,content) values('"&sdcms_adminname&"','"&sdcms_adminip&"','修改内链接："&t0&"')")
end if
remove_app "site_links":remove_app "sitelinks"
response.Redirect("?") 
end sub

sub del
if id<>"" then
	if instr(id,", ")>0 then
	id=split(id,", ")
		for i=0 to ubound(id)
			conn.execute("Insert into sd_log (sdcms_name,ip,content) values('"&sdcms_adminname&"','"&sdcms_adminip&"','删除内链接：编号为"&id(i)&"')")
			conn.execute("delete from "&sd_table&" where id="&id(i)&"")
		Next
	Else
		conn.execute("Insert into sd_log (sdcms_name,ip,content) values('"&sdcms_adminname&"','"&sdcms_adminip&"','删除内链接：编号为"&id&"')")
		conn.execute("delete from "&sd_table&" where id="&id&"")
	End If
	remove_app "site_links":remove_app "sitelinks"
end if
	response.Redirect("?")
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.t2.value=='')")
.write("	{")
.write("	alert('链接不能为空');")
.write("	document.add.t2.focus();")
.write("	return false")
.write("	}")
.write("	}")
.write("	</script>")
end with
end sub
%>  
</div>
</body>
</html>