<!--#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;
    }
}

function ubbFormat(what) 
{
    if (document.selection && document.selection.type == "Text")
    {
        var range = document.selection.createRange();
        range.text = "["+what+"]" + range.text + "[/"+what+"]";
    }
    else
    {
        txt=window.prompt("请输入内容","");     
        if (txt!=null) {           
                AddTxt="["+what+"]"+txt;
                AddText(AddTxt);
                AddText("[/"+what+"]");
        }       
    } 
}

function ubbInsert(what) 
{
    if (document.selection && document.selection.type == "Text")
    {
        var range = document.selection.createRange();
        range.text = "["+what+"]" + range.text + "[/"+what+"]";
    }
    else
    {
        txt=window.prompt("请输入内容","");     
        if (txt!=null) {           
                AddTxt="["+what+"]"+txt;
                AddText(AddTxt);
                AddText("[/"+what+"]");
        }       
    } 
}

function chsize(size) {
    if (document.selection && document.selection.type == "Text")
    {
        var range = document.selection.createRange();
        range.text = "[size=" + size + "]" + range.text + "[/size]";
    }
    else
    {                       
        txt=window.prompt("请输入内容",""); 
        if (txt!=null)
        {             
            AddTxt="[size="+size+"]"+txt;
            AddText(AddTxt);
            AddText("[/size]");
        }        
    }
}

function chfont(font) {
    if (document.selection && document.selection.type == "Text") {
    var range = document.selection.createRange();
    range.text = "" + range.text + "";
    }
    else
    {                  
        txt=window.prompt("请输入内容","");
        if (txt!=null)
        {             
            AddTxt=""+txt;
            AddText(AddTxt);
            AddText("");
        }        
    }  
}

function chcolor(color) {
    if (document.selection && document.selection.type == "Text") {
    var range = document.selection.createRange();
    range.text = "" + range.text + "";
    }
    else
    {  
    txt=window.prompt("请输入内容","");
        if(txt!=null) {
            AddTxt=""+txt;
            AddText(AddTxt);
            AddText("");
        }
    }
}

//-->
</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="SiteNew.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="Title" type="text" class="input_text" id="Title" size="50"></td>
    </tr>
    <tr> 
      <td width="120" rowspan="3" bgcolor="#FFFFFF"><p>新闻内容：</p>
        <p>换行请按<FONT color=#ff6600>Enter</FONT>，</p>
        <p>注意添加内容</p>
        <p>后要记得预览，</p>
        <p>以防分页函数</p>
        <p>将UBB的标记</p>
        <p>划隔为两页，</p>
        <p>这样会出现</p>
        <p>错误。</p></td>
      <td bgcolor="#FFFFFF"><img src="ubb/bold.gif" border="0" alt="粗体" onClick="ubbFormat('B')"><img src="ubb/italicize.gif" border="0" alt="斜体" onClick="ubbFormat('I')"><img src="ubb/underline.gif" border="0" alt="下划线" onClick="ubbFormat('U')"><img src="ubb/url.gif" alt="插入网址" width="23" height="22" border="0" onClick="ubbFormat('URL')"><img src="ubb/image.gif" border="0" alt="插入图片" onClick="ubbInsert('IMG')"> 
      </td>
    </tr>
    <tr> 
      <td bgcolor="#FFFFFF"><textarea name="Content" cols="90" rows="25"  class="input_text" id="Content"></textarea></td>
    </tr>
    <tr>
      <td bgcolor="#FFFFFF"><iframe name="Upload" frameborder="0" width="95%" height="80" scrolling="yes" src="uploadfile.asp"></iframe></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 ModifyAnnounce()

dim AnnID,Title,Content
AnnID=trim(Request("AnnID"))
Response.Write AnnID
if AnnID="" then
	FoundErr=True
	ErrMsg=ErrMsg & "<br><li>请选择要删除的新闻！</li>"
	exit sub
else
	AnnID=CLng(AnnID)
end if
sSql="Select * From SiteNew Where ID="&AnnID
oRs.Open sSql,oConn,1,1
If oRs.Eof Then
	FoundErr=True
	ErrMsg=ErrMsg & "<br><li>无此新闻！</li>"
	exit sub
Else
	Title=oRs("Title")
	Content=oRs("Content")
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="SiteNew.asp?Action=ModifySaveAnnounce&AnnID=<%=AnnID%>">
    <tr> 
      <td colspan="2" bgcolor="#f7f7f7"><div align="center"> <strong>新 闻 编 辑 </strong></div></td>
    </tr>
    <tr> 
      <td bgcolor="#FFFFFF">新闻标题：</td>
      <td bgcolor="#FFFFFF"><input name="Title" type="text" class="input_text" id="Title" size="50" value="<%=Title%>"></td>
    </tr>
    <tr> 
      <td width="120" rowspan="3" bgcolor="#FFFFFF"><p>新闻内容：</p>
        <p>换行请按<FONT color=#ff6600>Enter</FONT>，</p>
        <p>注意添加内容</p>
        <p>后要记得预览，</p>
        <p>以防分页函数</p>
        <p>将UBB的标记</p>
        <p>划隔为两页，</p>
        <p>这样会出现</p>
        <p>错误。</p></td>
      <td bgcolor="#FFFFFF"><img src="ubb/bold.gif" border="0" alt="粗体" onClick="ubbFormat('B')"><img src="ubb/italicize.gif" border="0" alt="斜体" onClick="ubbFormat('I')"><img src="ubb/underline.gif" border="0" alt="下划线" onClick="ubbFormat('U')"><img src="ubb/url.gif" alt="插入网址" width="23" height="22" border="0" onClick="ubbFormat('URL')"><img src="ubb/image.gif" border="0" alt="插入图片" onClick="ubbInsert('IMG')"> 
      </td>
    </tr>
    <tr> 
      <td bgcolor="#FFFFFF"><textarea name="Content" class="input_text"  rows="25" cols="90"><%=Content%></textarea></td>
    </tr>
    <tr>
      <td bgcolor="#FFFFFF"><iframe name="Upload" frameborder="0" width="95%" height="80" scrolling="yes" src="uploadfile.asp"></iframe></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="SiteNew.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></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 SiteNew 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="SiteNew.asp?Action=ModifyAnnounce&AnnID=<%=oRs("ID")%>" tilte="<%=oRs("Title")%>"><%=gotTopic(oRs("Title"),50)%></a></td>
    <td bgcolor="#FFFFFF"><div align="center"><%=oRs("PersonName")%></div></td>    
    <td bgcolor="#FFFFFF"><div align="center"><%=oRs("DateTime")%></div></td>
    <td bgcolor="#FFFFFF"><div align="center">[<a href="SiteNew.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="SiteNew.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='SiteNew.asp?page=1'>首页</a></b>] "
			response.write "[<b>"+"<a href='SiteNew.asp?page="&cstr(k-1)&"'>上一页</a></b>] "
		else
			Response.Write "[首页] [上一页]"
		end if
		if k<>n then
			response.write "[<b>"+"<a href='SiteNew.asp?page="&cstr(k+1)&"'>下一页</a></b>] "
			response.write "[<b>"+"<a href='SiteNew.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='SiteNew.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()
Dim Title,Content,i
Title=Trim(Request.Form("Title"))
Content = ""
For i = 1 To Request.Form("Content").Count
	Content = Content & Request.Form("Content")(i)
Next
	
if Title="" then
	founderr=true
	errmsg=ErrMsg & "<br><li>新闻标题不能为空！</li>"
end if
if Content="" then
	founderr=true
	errmsg=errmsg & "<br><li>新闻内容不能为空！</li>"
end if
if FoundErr=True then
	exit sub
end if

sSql="Select * From SiteNew Where ID=0"
oRs.Open sSql,oConn,1,3
oRs.AddNew
oRs("Title")=Title
oRs("Content")=Content
oRs("PersonName")=Session("username")
oRs.Update
Response.Write "<p align=center>新闻添加成功，3秒后自动返回新闻管理页！<script>window.setTimeout(""location.href='SiteNew.asp?Action=Manage'"",3000);</script></p>"
End Sub
%>



<%
Sub ModifySaveAnnounce()
Dim Title,Content,i,AnnID
AnnID=trim(Request("AnnID"))
Title=Trim(Request.Form("Title"))
Content = ""
For i = 1 To Request.Form("Content").Count
	Content = Content & Request.Form("Content")(i)
Next

if AnnID="" then
	FoundErr=True
	ErrMsg=ErrMsg & "<br><li>请选择要删除的新闻！</li>"
	exit sub
else
	AnnID=CLng(AnnID)
end if
if Title="" then
	founderr=true
	errmsg=ErrMsg & "<br><li>新闻标题不能为空！</li>"
end if
if Content="" then
	founderr=true
	errmsg=errmsg & "<br><li>新闻内容不能为空！</li>"
end if
if FoundErr=True then
	exit sub
end if

sSql="Select * From SiteNew Where ID="&AnnID
oRs.Open sSql,oConn,1,3
If Not oRs.Eof Then
oRs("Title")=Title
oRs("Content")=Content
oRs.Update
Response.Write "<p align=center>新闻修改成功，3秒后自动返回新闻管理页！<script>window.setTimeout(""location.href='SiteNew.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 SiteNew Where 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 SiteNew WHERE ID In ("&AnnID&")"
oConn.Execute sSql
	
Response.Write "<p align=center>新闻删除成功，3秒后自动返回新闻管理页！<script>window.setTimeout(""location.href='SiteNew.asp'"",3000);</script></p>"

End Sub
%>