<?php
#------------------------------------------------------#
#               本程序为zChain.net提供                 #
#                zChain论坛(ZBB)v2.00                  #
#------------------------------------------------------#
# INPUT[$FORM{}] : $action,$mid,$f_title,$f_body;

require_once('bin/config.php');
require_once('bin/common.php');

require_once('core/class_forum_base.php');
CForumBase::setFileBase("$filepath");
require_once('core/base_array_file.php');
require_once('core/class_news.php');

#--- Validate user ---
if($sv_user != $admname){errorview("只有系统管理员可以管理公告！");}

#--- Action branch ---
switch($action){
 case 'add_form': addForm();exit;
 case 'add_submit': addSubmit();exit;
 case 'remove': removeMessage($mid);exit;
}

#--- Display mailbox ---
$oNws=new CNews;
$oNws->load();
$size=$oNws->itemCount();

page_header("公告管理");
print "<CENTER>";
$posText=getRootText()." >> 公告管理";
menu_bar($posText,'');

print <<<EOT
<BR><table width=600 cellspacing=1 class=forumLine cellpadding=3>
<tr>
 <td align=center colspan=2 class=rowCaption> 公告列表 </td>
</tr>
<tr>
 <td class=row1>总共有<EM> $size </EM>条公告</td>
 <td width=100 class=row1 align=center><a href=?action=add_form>发布新公告</a></td>
</tr>
</table>
EOT;

for($i=0; $i<$size; $i++) {
 $oNws->moveTo($i);

 print <<<EOT
<BR>
<TABLE cellSpacing=1 cellPadding=3 border=0 width=600 class=forumLine>
<TR>
 <TD align=center width=100 class=rowCaption>发布人 </TD>
 <TD align=center class=rowCaption>公告内容</TD>
</TR>
<TR>
 <TD vAlign=top width=100 rowSpan=2 class=row1>$oNws->user</TD>
 <TD vAlign=top class=row1>
 <TABLE cellSpacing=0 cellPadding=0 width=100% border=0>
 <TR> 
  <TD><IMG height=16 src=$imgurl/lytu.gif border=0> 发布时间: $oNws->time</TD>
  <TD width=25 align=right>
  <a href="?action=remove&mid=$oNws->id"><IMG height=16 alt=删除该公告 src=$imgurl/del.gif border=0></a></TD>
 </TR>
 </TABLE>
 <HR size=1><B>$oNws->title</B><BR>$oNws->body</TD>
<TR>
 <TD align=right class=row1><IMG height=16 src=$imgurl/pro.gif border=0>
  <a href='viewuser.php?user=$oNws->user'>查看 {$oNws->user} 的个人资料</a></TD>
</TR>
</TABLE>
EOT;
}

print "<br><a href=javascript:history.back();><IMG src=$imgurl/back.gif border=0></a></CENTER>";

page_footer();
exit;

function addForm()
{
 global $imgurl;

 page_header('发布新公告');
 print "<CENTER>";
 $posText=getRootText()." >> <a href=affichemgr.php>公告管理</a> >>发布新公告";
 menu_bar($posText,'');

 print <<<EOT
<BR>
<SCRIPT>
var i=0;
function check(theForm) {
if(theForm.f_title.value == ""){alert("标题不能为空！");return false;}
if(theForm.f_title.value.length > 100){
 alert("标题不能超过 100 个字节！");
 return false;
}
if(theForm.f_body.value.length > 1000){
 alert("内容不能超过 1000 个字节！");
 return false;
}
i++;
if (i>1) {alert('公告正在发出，请耐心等待！'); return false;}
}
function confirm_reset(){
 if (confirm("该项操作要清除全部的内容，您确定要清除吗?")){return true;}
 return false;
}
function presskey(eventobject){if(event.ctrlKey && window.event.keyCode==13){this.document.form.submit();}}
</SCRIPT>
<center>
<form name=form action=affichemgr.php method=post>
<input type=hidden name=action value="add_submit">
<TABLE cellSpacing=1 cellPadding=4 border=0 width=500 class=forumLine>
<TR><TD colspan=2 class=rowCaption>新公告</TD></TR>
<TR><TD class=row2></TD>
 <TD vAlign=top class=row2> 注意：以下<em> * </em>星号标出的项目必需填写.</TD>
</TR>
<TR>
 <TD align=middle class=row1><em>*</em> 公告标题:</TD>
 <TD class=row1>
 <INPUT name=f_title size=40 onkeydown=presskey() class=plain></TD>
</TR>
<TR>
 <TD vAlign=top align=middle class=row2><em>*</em> 公告内容:</TD>
 <TD class="row2">
 <TEXTAREA name=f_body rows=6 cols=40 onkeydown=presskey() class=plain></TEXTAREA></TD>
</TR>
<TR>
 <TD class=row1>&nbsp;</TD>
 <TD class=row1>注意：HTML 功能允许。</TD>
</TR>
<TR align=center>
 <TD class=row2 colspan=2>
 <input onClick="return check(this.form)" type=submit value="  确 定 发 布  " name=SUBMIT>
 <input onClick="return confirm_reset()" type=reset value="  清 除 内 容  " name=RESET>
 </TD>
</TR>
</TABLE>
</FORM>
<br><a href=javascript:history.back();><IMG src=$imgurl/back.gif border=0></a>
</CENTER>
EOT;

 page_footer();
}

function addSubmit()
{
 global $istime,$stime,$sv_user,$f_title,$f_body;

 $oNws=new CNews;
 $oNws->load();

 if(strlen($f_title) > 100){errorview("您的讯息不能大于1000个字符！");}
 if(strlen($f_body) > 1000){errorview("您的讯息不能大于1000个字符！");}

 $oNws->insertNew();
 $oNws->id=$istime; $oNws->user=$sv_user;
 $oNws->time=$stime; $oNws->title=cleanText($f_title); $oNws->body=cleanHtml($f_body);
 $oNws->update();
 $oNws->store();

 print "<META HTTP-EQUIV=Refresh CONTENT='0;url=affichemgr.php'>";
}

function removeMessage($mid)
{
 $oNws=new CNews;
 $oNws->load();
 if($oNws->find($mid)){$oNws->delete();}
 $oNws->store();

 print "<META HTTP-EQUIV=Refresh CONTENT='0;url=affichemgr.php'>";
}

?>