<!--#include file="sdcms_check.asp"-->
<%
set sdcms=new Sdcms_Admin
sdcms.Check_admin
sdcms.Check_lever 3
set sdcms=nothing
select case action
case "add":title="添加公告"
case "edit":title="修改公告"
case else:stype="main":title="公告管理"
end select
sd_table="sd_notice"
sd_table01="sd_count"
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><%if stype<>"main" then%><li class="unsub"><a href="javascript:void(0)" onclick="$('upfiles').style.visibility='inherit'">附件上传</a></li><%end if%>
</ul><div style="visibility:hidden;position:absolute;margin:0 0 0 88px;*margin:-27px 0 0 88px;border:1px solid #FCBA72;background:#fff;padding:5px 10px;width:300px;" id="upfiles"><img src="images/close.gif"  style="position:absolute;margin:10px 0 0 242px;cursor:pointer;" onclick="$('upfiles').style.visibility='hidden'" alt="关闭" /><%admin_upfile 3,"280","30",1%></div>
<div id="sdcms_right_b">
<%
select case action
case "add":add
case "edit":edit
case "save":save
case "makehtml":makehtml
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 width="300" class="title_bg">标题</td>
      <td class="title_bg">日期</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,adddate,hits,"
	if Is_sql=0 then
		sql=sql&"(iif(isurl=0,'否','是'))"
	else
		sql=sql&"(case isurl when 0 then'否' else '是' end)"
	end if
	sql=sql&" from "&sd_table&" order by id 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>
	 <%for i=0 to 4%>
      <td <%if i<>1 then%>align="center"<%end if%>><%if i=1 then%><a href="../notice/<%=rs(0)%><%=sdcms_filetxt%>" target="_blank"><%=rs(i)%></a><%else%><%=rs(i)%><%end if%></td>
      <%next%>
      <td align="center"><a href="?action=makehtml&id=<%=rs(0)%>">生成</a> <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="7" 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="makehtml">生成 </option>
			  <option value="del">删除</option>
			  </select> 
             
      <input type="submit" class="bnt01" value="执行">

</td>
    </tr>
	<%if rcount>0 then%>
	<tr>
      <td colspan="7" 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="100" 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" value="<%=sdcms_adminname%>" type="text" class="input" id="t1" size="40"></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;$('c').style.display='block';this.form.t4.disabled=false;  checked value='0' >否 <input name='t2' type='radio' onClick=$('flag').style.display='block';this.form.t3.disabled=false;$('c').style.display='none';this.form.t4.disabled=true; value='1' >是</td>
    </tr>
    <tr  class="tdbg dis" id='flag'>
      <td  width="100" align="center">连接地址：</td>
      <td><input name="t3" type="text" disabled="disabled" class="input" id="t3" size="40"> <span>请填写完整路径 如：http://www.sdcms.cn</span></td>
    </tr>
   <tr class="tdbg" id="c">
      <td  width="100" align="center">公告内容：</td>
      <td><%if sdcms_editor_type=0 then%><span id="loadedit" style="font-size:12px"><img src='../editor/loading.gif' align='absbottom'> 正在载入编辑器...</span><%elseif sdcms_editor_type=1 then
	  set sdcms=new Sdcms_Function
	sdcms.ewebEditor "t4","600","300"
	set sdcms=nothing
	 end if%><textarea name="t4" id="t4" style="display:none"></textarea><br><input name="t5" id="t5" type="checkbox" value="1" /><label for="t5">保存远程图片</label><%all_set="生成首页|生成分类|生成信息":all_set=split(all_set,"|"):for i=0 to ubound(all_set)%><input name="up<%=i+1%>" type="checkbox" value="1" <%if instr(", "&sdcms_create_set&", ",", "&i+1&", ")>0 then echo "checked"%> id="up<%=i+1%>"><label for="up<%=i+1%>"><%=all_set(i)%></label>
	  <%next%></td>
    </tr>
    <tr class="tdbg">
	  <td>&nbsp;</td>
      <td><input name="Submit" type="submit" class="bnt" value="添 加">
        <input type="button" onClick="history.go(-1)" class="bnt" value="返 回"> <%if sdcms_editor_type=1 then%><input type="button" onClick="eWebEditor1.insertHTML('$show_page$')" class="bnt" value="插入分页"><%end if%></td>
    </tr>
	</form>
  </table>
<%
if sdcms_editor_type=0 then
	set sdcms=new Sdcms_Function
	sdcms.HtmlEditor 1,"t4","600","260",0
	set sdcms=nothing
end if
end sub
sub edit
set rs=conn.execute("select id,title,author,isurl,url,content from "&sd_table&" where id="&id&"")
if rs.eof then
echo "请勿非法提交参数":Died
end if
check_info
set sdcms_f=new Sdcms_Function
%>
  <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" 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"></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;$('c').style.display='block';this.form.t4.disabled=false;  <%=w_check(rs(3),0)%> value='0' >否 <input name='t2' type='radio' onClick=$('flag').style.display='block';this.form.t3.disabled=false;$('c').style.display='none';this.form.t4.disabled=true; 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" <%if rs(3)=0 then%>disabled="disabled"<%end if%> value="<%=rs(4)%>" class="input" id="t3" size="40"> <span>请填写完整路径 如：http://www.sdcms.cn</span></td>
    </tr>
   <tr class="tdbg<%if rs(3)=1 then%> dis<%end if%>" id="c">
      <td align="center">公告内容：</td>
      <td><%if sdcms_editor_type=0 then%><span id="loadedit" style="font-size:12px"><img src='../editor/loading.gif' align='absbottom'> 正在载入编辑器...</span><%elseif sdcms_editor_type=1 then
	sdcms_f.ewebEditor "t4","600","300"
	 end if%><textarea name="t4" id="t4" <%if rs(3)=1 then%>disabled="disabled"<%end if%> style="display:none"><%if rs(3)=0 then echo sdcms_f.TempEncode(rs(5)) end if%></textarea>
	  <br><input name="t5" id="t5" type="checkbox" value="1" /><label for="t5">保存远程图片</label><%all_set="生成首页|生成分类|生成信息":all_set=split(all_set,"|"):for i=0 to ubound(all_set)%><input name="up<%=i+1%>" type="checkbox" value="1" <%if instr(", "&sdcms_create_set&", ",", "&i+1&", ")>0 then echo "checked"%> id="up<%=i+1%>"><label for="up<%=i+1%>"><%=all_set(i)%></label><%next%></td>
    </tr>
    <tr class="tdbg">
	  <td>&nbsp;</td>
      <td><input name="Submit" type="submit" class="bnt" value="保 存">
        <input type="button" onClick="history.go(-1)" class="bnt" value="返 回"> <%if sdcms_editor_type=1 then%><input type="button" onClick="eWebEditor1.insertHTML('$show_page$')" class="bnt" value="插入分页"><%end if%></td>
    </tr>
	</form>
  </table>
<%
if sdcms_editor_type=0 then
	sdcms_f.HtmlEditor 1,"t4","600","260",0
end if
set sdcms_f=nothing
end sub
sub save
t0=trim(request("t0"))
t1=trim(request("t1"))
t2=trim(request("t2"))
t3=trim(request("t3"))
t4=trim(request("t4"))
t5=trim(request("t5"))
up1=trim(request("up1"))
up2=trim(request("up2"))
up3=trim(request("up3"))
if t5<>"" then t4=ReplaceRemoteUrl(t4)
set rs=server.CreateObject("adodb.recordset")
sql="select title,author,isurl,url,content,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,255)
rs(1)=left(t1,50)
rs(2)=t2
if t2=1 then
rs(3)=left(t3,255)
else
rs(4)=t4
end if
rs.update
id=rs(5)
if act="add" then
conn.execute("update "&sd_table01&" set notice_num=notice_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&up2&up3)>0 then
	set sdcms_c=new sdcms_create
	if len(up3)>0 then sdcms_c.Create_notice_show id
	if len(up2)>0 then sdcms_c.Create_n_list
	if len(up1)>0 then sdcms_c.Create_index
	set sdcms_f=nothing
end if
echo "信息保存成功"
end sub
sub del
if id<>"" then
conn.execute("Insert into sd_log (sdcms_name,ip,content) values('"&sdcms_adminname&"','"&sdcms_adminip&"','删除公告：编号为"&id&"')")
   if instr(id,", ")>0 then
	id=split(id,", ")
		for i=0 to ubound(id)
			set sdcms=new sdcms_function
			sdcms.DelHtml "../notice/"&id(i)&sdcms_filetxt
			set sdcms=nothing
			conn.execute("update "&sd_table01&" set notice_num=notice_num-1 where id=1")
			conn.execute("delete from "&sd_table&" where id="&id(i)&"")
		Next
			set sdcms_c=new sdcms_create
			sdcms_c.Create_n_list:sdcms_c.Create_index
			set sdcms_c=nothing
	 
	Else
		set sdcms=new sdcms_function
		sdcms.DelHtml "../notice/"&id&sdcms_filetxt
		set sdcms=nothing
		conn.execute("update "&sd_table01&" set notice_num=notice_num-1 where id=1")
		conn.execute("delete from "&sd_table&" where id="&id&"")
		set sdcms_c=new sdcms_create
		sdcms_c.Create_n_list:sdcms_c.Create_index
		set sdcms_c=nothing		  
	End if
		    
else
  response.Redirect("?")
end if
end sub

sub makehtml
if id<>"" then
conn.execute("Insert into sd_log (sdcms_name,ip,content) values('"&sdcms_adminname&"','"&sdcms_adminip&"','生成公告：编号为"&id&"')")
	if instr(id,", ")>0 then
	id=split(id,", ")
		for i=0 to ubound(id)
		  set sdcms=new sdcms_create
		  sdcms.Create_notice_show id(i)
		  set sdcms=nothing
		Next
	Else
		set sdcms=new sdcms_create
		sdcms.Create_notice_show id
		set sdcms=nothing
	End if
else
  response.Redirect("?")
end if
end sub

sub check_info
with response
.write("	<script>")
.write("	function checkadd()")
if sdcms_editor_type=0 then
.write("	{document.add.elements.t4.value =oEdit1.getHTMLBody();")
elseif sdcms_editor_type=1 then
.write("	{document.add.elements.t4.value =eWebEditor1.getHTML();")
end if
.write("	if (document.add.t0.value=='')")
.write("	{")
.write("	alert('公告标题不能为空');")
.write("	document.add.t0.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("	if (!document.add.t4.disabled && document.add.elements.t4.value =='')")
.write("	{")
.write("	alert('内容不能为空');")
.write("	document.add.t4.focus;")
.write("	return false")
.write("	}")

.write("	}")
.write("	</script>")
end with
end sub
%>  
</div>
</body>
</html>