
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!--#include file="../inc/Conn.asp"-->
<!--#include file="Inc/Admin.Asp"-->
<!--#include file="Inc/Function.asp"-->
<%
dim strFileName
const MaxPerPage=10
dim totalPut,CurrentPage,TotalPages
dim sql,rs,ID,LinkType
dim Action
Action=trim(request("Action"))
ID=Trim(Request("ID"))
LinkType=trim(request("LinkType"))
strFileName="Admin_FriendLinks.asp?LinkType=" & LinkType

if request("page")<>"" then
    currentPage=cint(request("page"))
else
	currentPage=1
end if

if ID<>"" then
	if Action="Del" then
		conn.execute "Delete From Dream_FriendLinks Where ID=" & CLng(ID)
	end if
end if
if Action="Add" then
stext="添加"
elseif Action="Modify" then
stext="修改"
else
stext=""
end if
%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>修改产品</title>
<link href="css/adminstyle.css" rel="stylesheet" type="text/css">
<script LANGUAGE="javascript">
function Check() {
if (document.AddLink.SiteName.value=="")
	{
	  alert("请输入网站名称！")
	  document.AddLink.SiteName.focus()
	  return false
	 }
if (document.AddLink.SiteUrl.value=="")
	{
	  alert("请输入网站地址！")
	  document.AddLink.SiteUrl.focus()
	  return false
	 }
}
function ConfirmDel()
{
   if(confirm("确定要删除此友情链接站点吗？"))
     return true;
   else
     return false;
}
</script>
</head>

<body>
<div class="container">
	<div class="local"><h3>您现在的位置：<a href="admin_Index_Main.asp">管理首页</a> >> 友情链接管理</h3></div>
	<table width="100%" border="0" cellpadding="10" cellspacing="0" class="border" style="margin-top:10px;">
		<tr>
			<td>
			<div class="page_content">
				<div class="r_title"><h3><img src="images/xiao.jpg" /> <%=stext%>友情链接</h3> <div style="float:right; padding-right:10px;"><input name="" onclick="javascript:location.href='Admin_FriendLinks.asp?Action=Add';" type="button" value="添加友情链接" /> <input name="" onclick="javascript:location.href='Admin_FriendLinks.asp';" type="button" value="所有链接" /></div></div>
				<div class="contents">
	<%
	if Action="Add" then
		call Add()
	elseif Action="SaveAdd" then
		call SaveAdd()
	elseif Action="Modify" then
		call Modify()
	elseif Action="SaveModify" then
		call SaveModify()
	else
		call main()
	end if
	if FoundErr=True then
		call WriteErrMsg()
	end if
	call CloseConn()
	
	sub main()
		sql="select * from Dream_FriendLinks "
		sql=sql & "order by id desc"
		set rs=server.createobject("adodb.recordset")
		rs.open sql,conn,1,1
		
		if rs.eof and rs.bof then
			response.write "目前共有 0 个友情链接"
		else
			totalPut=rs.recordcount
			if currentpage<1 then
				currentpage=1
			end if
			if (currentpage-1)*MaxPerPage>totalput then
				if (totalPut mod MaxPerPage)=0 then
					currentpage= totalPut \ MaxPerPage
				else
					currentpage= totalPut \ MaxPerPage + 1
				end if
	
			end if
			if currentPage=1 then
				showContent
				showpage strFileName,totalput,MaxPerPage,true,true,"个站点"
			else
				if (currentPage-1)*MaxPerPage<totalPut then
					rs.move  (currentPage-1)*MaxPerPage
					dim bookmark
					bookmark=rs.bookmark
					showContent
					showpage strFileName,totalput,MaxPerPage,true,true,"个站点"
				else
					currentPage=1
					showContent
					showpage strFileName,totalput,MaxPerPage,true,true,"个站点"
				end if
			end if
		end if
		rs.close
		set rs=nothing
	end sub
	
	sub showContent
		dim i
		i=0
	%>  
<table width="100%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#F8E9EA" style="margin-top:10px;">
  <tr> 
    <th width="5%">编号</th>
    <th width="30%">网站名称</th>
    <th width="30%">网站简介</th>
    <th width="20%">站长</th>
    <th width="15%">操作</th>
  </tr>
<%
do while not rs.eof
%>
    
  <tr bgcolor="#FFFFFF" class="tdbg"> 
    <td align="center" height="22"><%=rs("id")%></td>
    <td><a href="<%=rs("SiteUrl")%>" target='blank' title="<%=rs("SiteUrl")%>"><%=rs("SiteName")%></a></td>
    <td><%=rs("SiteIntro")%></td>
    <td align="center"><a href="mailto:<%=rs("Email")%>"><%=rs("SiteAdmin")%></a></td>
    <td align="center"> 
     <a href='Admin_FriendLinks.asp?Action=Modify&ID=<%=rs("id")%>'>修改</a>&nbsp;|&nbsp;<a href='Admin_FriendLinks.asp?Action=Del&ID=<%=rs("id")%>' onclick='return ConfirmDel();'>删除</a></td>
  </tr>
    <%
	i=i+1
	if i>=MaxPerPage then exit do
	rs.movenext
loop
%>
</table>
<%
end sub

sub Add()
%>
<form method="post" name="AddLink" onSubmit="return Check()" action="Admin_FriendLinks.asp">
  <table width="100%" border="0" align="center" cellpadding="2" cellspacing="1" style="margin-top:10px;">
    <tr> 
      <td width="100" height="25" align="right" valign="middle">网站名称：</td>
      <td> 
        <input name="SiteName" size="30"  maxlength="20" title="这里请输入您的网站名称，最多为20个汉字"> 
        <font color="#FF0000"> *</font></td>
    </tr>
    <tr> 
      <td height="25" align="right">网站地址：</td>
      <td height="25"> 
        <input name="SiteUrl" size="40"  maxlength="100" type="text"  value="http://" title="这里请输入您的网站地址，最多为50个字符，前面必须带http://"> 
        <font color="#FF0000">*</font></td>
    </tr>
    <tr> 
      <td height="25" align="right">站长姓名：</td>
      <td height="25"> 
        <input name="SiteAdmin" size="15"  maxlength="20" type="text"  title="这里请输入您的大名了，不然我知道您是谁啊。最多为20个字符"></td>
    </tr>
    <tr class="tdbg"> 
      <td height="25" align="right">电子邮件：</td>
      <td height="25"> 
        <input name="Email" size="30"  maxlength="30" type="text"  value="@" title="这里请输入联系电子邮件，最多为30个字符"></td>
    </tr>
    <tr> 
      <td align="right">网站简介：</td>
      <td valign="middle"> 
        <textarea name="SiteIntro"  style="width:99%" rows="5" id="SiteIntro" title="这里请输入网站的简单介绍"></textarea></td>
    </tr>
    <tr> 
      <td height="40" colspan="2" align="center"> 
        <input name="Action" type="hidden" id="Action" value="SaveAdd"> 
        <input type="submit" value=" 确 定 " name="cmdOk"> &nbsp; <input type="reset" value=" 重 填 " name="cmdReset"></td>
    </tr>
  </table>
</form>
<%
end sub

sub Modify()
	if ID="" then
		FoundErr=True
		ErrMsg=ErrMsg & "<br><li>请指定友情站点ID</li>"
		exit sub
	else
		ID=Clng(ID)
	end if
	dim sqlLink,rsLink
	sqlLink="select * from Dream_FriendLinks where ID=" & ID
	set rsLink=Server.CreateObject("Adodb.RecordSet")
	rsLink.open sqlLink,conn,1,3
	if rsLink.bof and rsLink.eof then
		FoundErr=True
		ErrMsg=ErrMsg & "<br><li>找不到站点！</li>"
		rsLink.close
		set rsLink=nothing
		exit sub
	end if

%>
<form method="post" name="AddLink" onSubmit="return Check()" action="Admin_FriendLinks.asp">
  <table width="100%" border="0" align="center" cellpadding="2" cellspacing="1" style="margin-top:10px;">
	<tr> 
      <td width="100" height="25" align="right" valign="middle">网站名称：</td>
      <td> 
        <input name="SiteName" size="30"  maxlength="20" value="<%=rsLink("SiteName")%>"> 
        <font color="#FF0000"> *</font></td>
    </tr>
    <tr> 
      <td height="25" align="right">网站地址：</td>
      <td height="25"> 
        <input name="SiteUrl" size="40"  maxlength="100" type="text"  value="<%=rsLink("SiteUrl")%>"> 
        <font color="#FF0000">*</font></td>
    </tr>
    <tr> 
      <td height="25" align="right">站长姓名：</td>
      <td height="25"> 
        <input name="SiteAdmin" size="15"  maxlength="20" type="text" value="<%=rsLink("SiteAdmin")%>"></td>
    </tr>
    <tr class="tdbg"> 
      <td height="25" align="right">电子邮件：</td>
      <td height="25"> 
        <input name="Email" size="30"  maxlength="30" type="text" value="<%=rsLink("Email")%>"></td>
    </tr>
    <tr> 
      <td align="right">网站简介：</td>
      <td valign="middle"> 
        <textarea name="SiteIntro" style="width:99%" rows="5" id="SiteIntro" title="这里请输入网站的简单介绍"><%=ReHTMLEncode(rsLink("SiteIntro"))%></textarea></td>
    </tr>
    <tr bgcolor="#FFFFFF" class="tdbg"> 
      <td height="40" colspan="2" align="center"> 
        <input name="ID" type="hidden" id="ID" value="<%=rsLink("ID")%>"> 
        <input name="Action" type="hidden" id="Action" value="SaveModify"> <input type="submit" value=" 确 定 " name="cmdOk"></td>
    </tr>
  </table>
</form>
<%
	rsLink.close
	set rsLink=nothing
end sub
%>
<%
sub SaveAdd()
	
	dim LinkType,LinkSiteName,LinkSiteUrl,LinkLogoUrl,LinkSiteAdmin,LinkEmail,LinkSitePassword,LinkSitePwdConfirm,LinkSiteIntro,LinkIsGood,LinkIsOK
	LinkSiteName=trim(request("SiteName"))
	LinkSiteUrl=trim(request("SiteUrl"))
	LinkSiteAdmin=trim(request("SiteAdmin"))
	LinkEmail=trim(request("Email"))
	LInkSiteIntro=trim(request("SiteIntro"))
	LinkLogoUrl=trim(request("LogoUrl"))
	if LinkSiteName="" then
		FoundErr=True
		ErrMsg=ErrMsg & "<br><li>网站名称不能为空！</li>"
	end if
	if LinkSiteUrl="" then
		FoundErr=True
		ErrMsg=ErrMsg & "<br><li>网站地址不能为空！</li>"
	end if
	if FoundErr<>True then
	
		dim sqlLink,rsLink
		sqlLink="select * from Dream_FriendLinks where SiteName='" & LinkSiteName & "' and SiteUrl='" & LinkSiteUrl & "'"
		set rs=Server.CreateObject("Adodb.RecordSet")
		rs.open sqlLink,conn,1,1
		if not (rs.bof and rs.eof) then
			FoundErr=True
			ErrMsg=ErrMsg & "<br><li>你要添加的网站已经存在！</li>"			
		else
			
		    set rsLink=Server.CreateObject("Adodb.RecordSet")
		   	sql="select * from Dream_FriendLinks where (id is null)"
		    rsLink.open sql,conn,1,3		   
			rsLink.Addnew
			rsLink("SiteName")=LinkSiteName
			rsLink("SiteUrl")=LinkSiteUrl
			rsLink("SiteAdmin")=LinkSiteAdmin
			rsLink("Email")=LinkEmail		
			rsLink("SiteIntro")=HTMLEncode(LinkSiteIntro)
			rsLink.update
			rsLink.close
			set rsLink=nothing
			call CloseConn()
			Response.Redirect "Admin_FriendLinks.asp"
		end if
		rs.close
		set rs=nothing
	end if
end sub

sub SaveModify()
	if ID="" then
		FoundErr=True
		ErrMsg=ErrMsg & "<br><li>请指定友情站点ID</li>"
		exit sub
	else
		ID=Clng(ID)
	end if
	dim LinkType,LinkSiteName,LinkSiteUrl,LinkLogoUrl,LinkSiteAdmin,LinkEmail,LinkSitePassword,LinkSitePwdConfirm,LinkSiteIntro,LinkIsGood,LinkIsOK
	LinkSiteName=trim(request("SiteName"))
	LinkSiteUrl=trim(request("SiteUrl"))
	LinkSiteAdmin=trim(request("SiteAdmin"))
	LinkEmail=trim(request("Email"))
	LInkSiteIntro=trim(request("SiteIntro"))
	if LinkSiteName="" then
		FoundErr=True
		ErrMsg=ErrMsg & "<br><li>网站名称不能为空！</li>"
	end if
	if LinkSiteUrl="" then
		FoundErr=True
		ErrMsg=ErrMsg & "<br><li>网站地址不能为空！</li>"
	end if
	if FoundErr=True then
		exit sub
	end if
	dim sqlLink,rsLink
	sqlLink="select * from Dream_FriendLinks where ID=" & ID
	set rsLink=Server.CreateObject("Adodb.RecordSet")
	rsLink.open sqlLink,conn,1,3
	if rsLink.bof and rsLink.eof then
		FoundErr=True
		ErrMsg=ErrMsg & "<br><li>找不到站点！</li>"
	else
		rsLink("SiteName")=LinkSiteName
		rsLink("SiteUrl")=LinkSiteUrl
		rsLink("SiteAdmin")=LinkSiteAdmin
		rsLink("Email")=dLinkEmail	
		rsLink("SiteIntro")=HTMLEncode(LinkSiteIntro)
		rsLink.update
		rsLink.close
		set rsLink=nothing
		call CloseConn()
		Response.Redirect "Admin_FriendLinks.asp"
	end if
	rsLink.close
	set rsLink=nothing
end sub
%>
	</div>				
			</div>
			</td>
		</tr>
  </table>
</div>
</body>
</html>