<!--#include file = "Startup.asp"-->
<!-- #include file="Function.asp" -->
<%
call adminer()
call Header()
Call ComeUrl()
%>
<script language="JavaScript">
<!--
if(navigator.appName == "Microsoft Internet Explorer")
{
    isIE=true;
}
else
{
    isIE=false;
}
function AddText(NewCode) 
{
    if(document.all){
        insertAtCaret(document.myform.Content, NewCode);
        document.myform.Content.focus();
    }
    else
    {
        document.myform.Content.value += NewCode;
        document.myform.Content.focus();
    }
}

function insertAtCaret (textEl, text){
    if (textEl.createTextRange && textEl.caretPos)
    {
        var caretPos = textEl.caretPos;
        caretPos.text += caretPos.text.charAt(caretPos.text.length - 2) == ' ' ? text + ' ' : text;
    }
    else if(textEl)
    {
        textEl.value += text;
    }
    else
    {
        textEl.value = text;
    }
}

 //-->
</script>
<%
Dim Action,FoundErr,ErrMsg
Dim Id,ComName,ComUrl,ComKEY,ComAdd,LanXiRen,ComCode,ComTel,ComFax,ComMail

Action=Trim(Request("Action"))
if Action="" Or Action="Manage" then
	call Main()
elseif Action="AddAnnounce" then
	call AddAnnounce()
elseif Action="AddSaveAnnounce" then
	call AddSaveAnnounce()
elseif Action="ModifyAnnounce" then
	call ModifyAnnounce()
elseif Action="ModifySaveAnnounce" then
	call ModifySaveAnnounce()
elseif Action="DelAnnounce" then
	call DelAnnounce()
Else
	FoundErr=True
	ErrMsg=ErrMsg & "<br><li>参数错误！</li>"
end if

if founderr=true then
	call WriteErrMsg()
End if
%>
<%
Sub AddAnnounce()
%>
<Script Language=JavaScript>
function doSubmit(){
	if (document.myform.Title.value==""){
		alert("站点标题不能为空！");
		return false;
	}
		// getHTML()为eWebEditor自带的接口函数，功能为取编辑区的内容
		if (document.myform.Content.value==""){
			alert("站点内容不能为空！");
			return false;
		}
}
</Script>
<table width="100%"  border="0" cellpadding="3" cellspacing="1" bgcolor="#DEDFDE">
  <form name="myform" method="post" action="WapUrl.asp?Action=AddSaveAnnounce">
    <tr> 
      <td colspan="2" bgcolor="#f7f7f7"><div align="center"> <strong>链 接 添 加</strong></div></td>
    </tr>
    <tr> 
      <td bgcolor="#FFFFFF">网站名称：</td>
      <td bgcolor="#FFFFFF"><input name="SiteName" type="text" class="input_text" id="SiteName" size="50"></td>
    </tr>
    <tr> 
      <td width="120" bgcolor="#FFFFFF">网站地址 </td>
      <td bgcolor="#FFFFFF"><input name="Url" type="text" class="input_text" id="Content" value="http://" size="90"></td>
    </tr>
    <tr> 
      <td width="120" bgcolor="#FFFFFF">所属类别</td>
      <td bgcolor="#FFFFFF"><input name="Type" type="text" id="Type" value="1"></td>
    </tr>
    <tr> 
      <td colspan="2" bgcolor="#FFFFFF"><%ShowSiteType%></td>
    </tr>
    <tr> 
      <td height="19" colspan="2" bgcolor="#FFFFFF"><div align="center"> 
          <input type="submit" name="Submit" value=" 提　交 " class="input_submit" onClick="return doSubmit()">
          　　　　　 
          <input type="reset" name="Submit" value=" 重　置 " class="input_submit">
        </div></td>
    </tr>
  </form>
</table>

<%
End Sub
%>


<%
Sub ModifyAnnounce()

dim AnnID,Title,Content
AnnID=trim(Request("AnnID"))
if AnnID="" then
	FoundErr=True
	ErrMsg=ErrMsg & "<br><li>请选择要编辑的站点！</li>"
	exit sub
else
	AnnID=CLng(AnnID)
end if
sSql="Select * From WapUrlList Where ID="&AnnID
oRs.Open sSql,oConn,1,1
If oRs.Eof Then
	FoundErr=True
	ErrMsg=ErrMsg & "<br><li>无此站点！</li>"
	exit sub
Else
	SiteName=oRs("SiteName")
	SiteUrl=oRs("WapUrl")
    SiteType=oRs("TypeId")
End If
oRs.Close

%>
<Script Language=JavaScript>
function doSubmit(){
	if (document.myform.Title.value==""){
		alert("站点标题不能为空！");
		return false;
	}
		// getHTML()为eWebEditor自带的接口函数，功能为取编辑区的内容
		if (document.myform.Content.value==""){
			alert("站点内容不能为空！");
			return false;
		}
}
</Script>
<table width="100%"  border="0" cellpadding="3" cellspacing="1" bgcolor="#DEDFDE">
  <form name="myform" method="post" action="WapUrl.asp?Action=ModifySaveAnnounce&AnnID=<%=AnnID%>">
    <tr> 
      <td width="120" colspan="2" bgcolor="#f7f7f7"><div align="center"> <strong> 
          站 点 编 辑</strong></div></td>
    </tr>
    <tr> 
      <td bgcolor="#FFFFFF">网站名称：</td>
      <td bgcolor="#FFFFFF"><input name="SiteName" type="text" class="input_text" id="SiteName" value="<%=SiteName%>" size="50"></td>
    </tr>
    <tr> 
      <td bgcolor="#FFFFFF">网站地址 </td>
      <td bgcolor="#FFFFFF"><input name="Url" type="text" class="input_text" id="Content" value="<%=SiteUrl%>" size="90"></td>
    </tr>
    <tr> 
      <td bgcolor="#FFFFFF">所属类别</td>
      <td bgcolor="#FFFFFF"><input name="Type" type="text" id="Type" value="<%=SiteType%>"></td>
    </tr>
    <tr> 
      <td colspan="2" bgcolor="#FFFFFF">
        <%ShowSiteType%>
      </td>
    </tr>
    <tr> 
      <td height="40" colspan="2" bgcolor="#FFFFFF"><div align="center"> 
          <input type="submit" name="Submit" value=" 提　交 " class="input_submit" onClick="return doSubmit()">
          　　　　　 
          <input type="reset" name="Submit" value=" 重　置 " class="input_submit">
        </div></td>
    </tr>
  </form>
</table>

<%
End Sub
%>




<%
Sub Main
%>
<SCRIPT language=javascript>
function unselectall()
{
    if(document.myform.chkAll.checked){
	document.myform.chkAll.checked = document.myform.chkAll.checked&0;
    } 	
}

function CheckAll(form)
  {
  for (var i=0;i<form.elements.length;i++)
    {
    var e = form.elements[i];
    if (e.Name != "chkAll"&&e.disabled==false)
       e.checked = form.chkAll.checked;
    }
  }
  

function ConfirmDel()
{
	if(document.myform.Action.value=="Del")
	{
		if(confirm("确定要删除选中的站点吗？一但删除将无法恢复！"))
		    return true;
		else
			return false;
	}
}
</SCRIPT>
<table width="100%"  border="0" cellpadding="3" cellspacing="1" bgcolor="#DEDFDE">
  <form name="myform" method="post" action="WapUrl.asp?Action=DelAnnounce" onsubmit="return ConfirmDel();"><tr>
    <td width="40" bgcolor="#F7F7F7"><div align="center"><strong>选中</strong>
      
      
    </div></td>
    <td bgcolor="#F7F7F7"><div align="center"><strong>站点名称</strong></div></td>
      <td bgcolor="#F7F7F7"><div align="center"><strong>网站地址</strong> </div>
        <div align="center"></div></td>
    <td bgcolor="#F7F7F7"><div align="center"><strong>网站类型</strong></div></td>
    <td bgcolor="#F7F7F7"><div align="center"><strong>修改</strong></div></td>
    <td bgcolor="#F7F7F7"><div align="center"><strong>删除</strong></div></td>
  </tr>
  
<%
sSql="Select * From WapUrlList Order By ID Desc"
oRs.Open sSql,oConn,1,3
If oRs.Eof Then
	Response.Write "<tr><td colspan='6' bgcolor='#FFFFFF'><div align='center'>暂无站点信息！</div></td></tr></form></table>"
Else

const MaxPerPage=15   '单独页最大记录数 const 用来申明常量
dim totalPut   '总记录
dim CurrentPage  '当前页次
dim TotalPages   '总页数
dim i



'!-- 分页功能代码块,可独立使用
if not ors.eof then
  ors.MoveFirst  '注意放到前面来,否则到任何页总是在第一个记录上
  end if
  ors.pagesize=MaxPerPage  '设置每页最多显示多少条记录
  If trim(Request("Page"))<>"" then  '如果请求的页次不为空
	CurrentPage= CLng(request("Page"))   'clng是转换成长整型数据类型,并赋值到当前页次上
	If CurrentPage> ors.PageCount then  '如果当前页次大于总页数,则将最大页次赋值到当前页次上
		CurrentPage = ors.PageCount 
	End If 
Else 
	CurrentPage= 1 '一切条件不成立,将当前页设为第一页
End If 

 totalPut=ors.recordcount '将总记录赋值于TOTALPUT
	if CurrentPage<>1 then '如果当前页数不等于第一页
		if (currentPage-1)*MaxPerPage<totalPut then  '如果当前页减一乘以每页最大的记录数小于总记录的话
			ors.move(currentPage-1)*MaxPerPage  '相对当前记录数向后移动
			dim bookmark  '定义书签变量
			bookmark=ors.bookmark '将当前记录的标签赋于变量BOOKMARK上
		end if 
	end if

	dim n,k
	if (totalPut mod MaxPerPage)=0 then  '总记录数与每页最大记录数求余的结果为零时,则N返回整数页次,否则再加一.
		n= totalPut \ MaxPerPage
	else  
		n= totalPut \ MaxPerPage + 1  
	end if

	Do While Not oRs.Eof and i<maxperpage
%>  
  <tr>
    <td width="40" bgcolor="#FFFFFF"><div align="center">
      <input name="AnnID" type="checkbox" onClick="unselectall()" id="AnnID" value="<%=oRs("ID")%>">
    </div></td>
    <td bgcolor="#FFFFFF"><a href="WapUrl.asp?Action=ModifyAnnounce&AnnID=<%=oRs("ID")%>" tilte="<%=oRs("SiteName")%>"><%=gotTopic(oRs("SiteName"),50)%></a></td>
    <td bgcolor="#FFFFFF"><div align="center"><%=oRs("WapUrl")%></div></td>    
    <td bgcolor="#FFFFFF"><div align="center"><%=oRs("TypeId")%></div></td>
    <td bgcolor="#FFFFFF"><div align="center">[<a href="WapUrl.asp?Action=ModifyAnnounce&AnnID=<%=oRs("ID")%>">修改</a>]</div></td>
    <td bgcolor="#FFFFFF"><div align="center"><%If session("userclass")=1 Then%>[<span onClick='return ConfirmDel()'><a href="WapUrl.asp?Action=DelAnnounce&AnnID=<%=oRs("ID")%>">删除</a></span>]<%End If%></div></td>
  </tr>
  
  <%
  oRs.MoveNext
  i=i+1
  Loop
  %>
  
  <tr>
    <td colspan="6" bgcolor="#FFFFFF"><table width="100%"  border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="40"><div align="center">
            <input name="chkAll" type="checkbox" id="chkAll" onclick=CheckAll(this.form) value="checkbox">
        </div></td>
            <td>选中本页显示的所有站点</td>
        <td><div align="right">
		<input name="Action" type="hidden" id="Action2" value="Del">
        <input type="submit" name="Submit1" value=" 删　除 " onClick="document.myform.Action.value='Del'" class="input_submit">
&nbsp;&nbsp; </div></td>
      </tr>
    </table></td>
  </tr></form>
</table>

<table width="100%"  border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td height="30"><div align="center">
        <%
	Response.Write "共 <font color='#FF0000'>"&totalPut&"</font> 条站点　" 
          k=currentPage
		if k<>1 then
			response.write "[<b>"+"<a href='WapUrl.asp?page=1'>首页</a></b>] "
			response.write "[<b>"+"<a href='WapUrl.asp?page="&cstr(k-1)&"'>上一页</a></b>] "
		else
			Response.Write "[首页] [上一页]"
		end if
		if k<>n then
			response.write "[<b>"+"<a href='WapUrl.asp?page="&cstr(k+1)&"'>下一页</a></b>] "
			response.write "[<b>"+"<a href='WapUrl.asp?page="&cstr(n)&"'>尾页</a></b>] "
		else
			Response.Write "[下一页] [尾页]"
		end if	
		Response.Write "　页次：<font color='#ff0000'>"&currentpage&"</font>/"&n&"页　15条站点/页"
		%>
　转到：
<select name="select" onchange="javascript:window.location='WapUrl.asp?page='+this.options[this.selectedIndex].value;">
<option>跳转页</option>
<%
Dim z
For z=1 To n%>
  <option value="<%=z%>">第<%=z%>页</option>
<%
Next
%> 
</select>
        </div></td>
  </tr></table>
<%
End If
End Sub
%>


<%
Sub AddSaveAnnounce()
SiteName=Trim(Request.Form("SiteName"))
SiteUrl = Trim(Request.Form("Url"))
SiteType=Request.Form("Type")	
if SiteName="" then
	founderr=true
	errmsg=ErrMsg & "<br><li>网站名称不能为空！</li>"
end if
if SiteUrl="http://" or SiteUrl="" then
	founderr=true
	errmsg=errmsg & "<br><li>网站链接不能为空！</li>"
end if
if FoundErr=True then
	exit sub
end if

sSql="Select * From WapUrlList Where ID=0"
oRs.Open sSql,oConn,1,3
oRs.AddNew
oRs("SiteName")=SiteName
oRs("WapUrl")=SiteUrl
oRs("TypeId")=SiteType
oRs.Update
Response.Write "<p align=center>站点添加成功，3秒后自动返回站点管理页！<script>window.setTimeout(""location.href='WapUrl.asp?Action=Manage'"",3000);</script></p>"
End Sub
%>



<%
Sub ModifySaveAnnounce()
Dim Title,Content,i,AnnID
AnnID=trim(Request("AnnID"))
SiteName=Trim(Request.Form("SiteName"))
SiteUrl=Trim(Request.Form("Url"))
SiteType=Trim(Request.Form("Type"))
if AnnID="" then
	FoundErr=True
	ErrMsg=ErrMsg & "<br><li>请选择要修改的站点！</li>"
	exit sub
else
	AnnID=CLng(AnnID)
end if
if SiteName="" then
	founderr=true
	errmsg=ErrMsg & "<br><li>站点名称不能为空！</li>"
end if
if SiteUrl="" then
	founderr=true
	errmsg=errmsg & "<br><li>网站地址不能为空！</li>"
end if
if SiteType="" then
	founderr=true
	errmsg=errmsg & "<br><li>网站类型不能为空！</li>"
end if
if FoundErr=True then
	exit sub
end if

sSql="Select * From WapUrlList Where ID="&AnnID
oRs.Open sSql,oConn,1,3
If Not oRs.Eof Then
oRs("SiteName")=SiteName
oRs("WapUrl")=SiteUrl
oRs("TypeId")=SiteType
oRs.Update
Response.Write "<p align=center>站点修改成功，3秒后自动返回站点管理页！<script>window.setTimeout(""location.href='WapUrl.asp?Action=Manage'"",3000);</script></p>"
Else
	FoundErr=True
	ErrMsg=ErrMsg & "<br><li>无此站点！</li>"
	exit sub
End If
End Sub
%>




<%
Sub DelAnnounce()

dim AnnID
AnnID=trim(Request("AnnID"))
if AnnID="" then
	FoundErr=True
	ErrMsg=ErrMsg & "<br><li>参数不足</li>"
	exit sub
end if
sSql="Select * From WapUrlListWhere ID In ("&AnnID&")"
oRs.Open sSql,oConn,1,1
If oRs.Eof Then
	FoundErr=True
	ErrMsg=ErrMsg & "<br><li>无此站点！</li>"
	exit sub
End If
oRs.Close
sSql = "DELETE FROM WapUrlList WHERE ID In ("&AnnID&")"
oConn.Execute sSql
	
Response.Write "<p align=center>站点删除成功，3秒后自动返回站点管理页！<script>window.setTimeout(""location.href='WapUrl.asp'"",3000);</script></p>"

End Sub
%>
<%
Sub ShowSiteType
Response.Write "<b>类别参考:</b>"
sSql="Select * From WapUrlType"
oRs.Open sSql,oConn,1,1
For I=0 To oRs.RecordCount-1
	if i MOd 10=0 then '每三项换行。
	    Response.Write "<br/>"
	Else
	    Response.Write" | "
	end if
Response.Write ORs("TypeId") &  "." & ORs("TypeName") 
oRs.MoveNext
Next
 End Sub
%>