<?php
/*
\* ===========================================
\* 项目: CTB文本论坛
\* 版本: 1.2
\* 团队: 实易数码
\* 小组: CTB文本论坛小组
\* 作者: 险情
\* 功能: 后台系统-公告处理程式
\* ===========================================
\* Copyright (c) 2002
\* 团队主页: http://www.11cn.org
\* 技术论坛: http://ctb.11cn.org
\* 创建日期: 2002/7/10
\* 修改日期: ------
\* 修改说明: ------
\* 版权声明: 这个程序是免费软件.
\* ===========================================
*/

//=============================================================================
class Module extends CommonClass
//系统管理模块子类
{
    function execute() {
        switch($this->input['action']) {
			//
            case 'showSay':
                $this->showSay();
                break;
            case 'addSay':
                $this->addSay();
                break;
            case 'deleteSay':
                $this->doAdminOrder("你是否确定删除本公告？");
                break;
            case 'deleteSay2':
                $this->deleteSay();
                break;
            case 'editSay':
                $this->editSay();
                break;
            case 'editSaySave':
                $this->editSaySave();
                break;
			//
        }
    } // end func

//-----------------------------------------------------------------------------
//---后台发布公告处理模块
//1---显示所有历史公告:showSay()
//2---添加一个历史公告:addSay()
//3---删除一个历史公告:deleteSay()
//4---显示等待修改历史公告:editSay()
//5---保存修改历史公告:editSaySave()
//---
//---
//-----------------------------------------------------------------------------
//1=============================================================================
//显示所有历史公告
function showSay()
//公告处理模块。
{

    if ($this->input['forumId']=="") $this->input['forumId'] = "all";   // Add by Felixsun

    //显示版块模块
	 $this->file = "../".$this->set[dataPath]."/forums.php";
	 $forums = $this->read_file();
		 $optionLine="<option value='all'>╋CTB论坛公告</option>\n";
		 $ShowForumName="<a href=\"main.php?mod=systemsay&action=showSay\" ><font color=white><b>CTB论坛公告</b></font></a>";
	     foreach ($forums as $line) {
		    $lineCode = $this->make_array($line);
			if ($lineCode[1] == "forum") {
				if ($lineCode[2]==$this->input['forumId']) {
				    $ShowForumName="<a href=\"main.php?mod=systemsay&action=showSay\" ><font color=white><b>CTB论坛公告</b></font></a>>><a href=\"main.php?mod=systemsay&action=showSay&forumId={$this->input['forumId']}\" ><font color=white><b>".$lineCode[3]."</b></font></a>";
				    $optionLine.="<option value='".$lineCode[2]."' selected>　|-".$lineCode[3]."</option>\n";
				  }
				else {
				    $optionLine.="<option value='".$lineCode[2]."'>　|-".$lineCode[3]."</option>\n";
				  }
			 }
		    }
	//显示本版块公告
	if ($this->input['forumId']=="all" or $this->input['forumId']=="")
		$this->file = "../".$this->set[dataPath]."/announce.php";
	else
		$this->file = "../".$this->set[dataPath]."/".$this->input['forumId']."/announce.php";
	if (file_exists($this->file)){
	   $sayinfo = $this->read_file();
	   $i=1;
	   foreach ($sayinfo as $sayline) {
	       $num=$i++;
	       $sayLineCode = $this->make_array($sayline);
	       $sayTime=date("Y-m-d H:i:s",$sayLineCode[1]);
	       $sayUser=$sayLineCode[5];
	       $sayTopic=$sayLineCode[2];
	       $sayWord = $this->ctbCode($sayLineCode[3]);
	       eval ("\$grade_body .= \"".$this->getTemplate("systemSayBody")."\";");
	    }
	}
	else eval ("\$grade_body .= \"".$this->getTemplate("systemSayBody2")."\";");
    eval("\$this->outPut(\"".$this->getTemplate("systemShowSay")."\");");
} // end func

//2----------------------------------------------------------------------------
//添加一个历史公告
function addSay()
{
    //简单格式化输入数据
	if(!$this->input['forumId']) $this->input['forumId']="all";
    $this->inputCheck("main.php?mod=systemsay&action=showSay&forumId={$this->input['forumId']}");
	//获取数据并将数据写入公告文件
	$sayUser=$this->sess['sess_adminname'];
	$sayUserId=$this->sess['sess_adminid'];
	$sayTime=time();
	$sayPic="thumbsup.gif";
	if ($this->input['forumId']=="all"){
	    $this->file = "../".$this->set[dataPath]."/announce.php";
	}else{
        $this->file = "../".$this->set[dataPath]."/".$this->input['forumId']."/announce.php";
	}
	$sayList = array(stripslashes($this->code),$sayTime,$this->input['sayTopic'],$this->input['sayBody'],$sayUserId,$sayUser,$sayPic,"0","0","\n");
	$this->insertTop($this->file,$sayList);
    $this->adminShowMsg("main.php?mod=systemsay&action=showSay&forumId={$this->input['forumId']}","您已经成功填加了论坛公告");

}

//3=============================================================================
//删除一个历史公告
function deleteSay()  {
	if ($this->input['forumId']=="all"){
	    $this->file = "../".$this->set[dataPath]."/announce.php";
	}else{
        $this->file = "../".$this->set[dataPath]."/".$this->input['forumId']."/announce.php";
	}
	if (($sayLines = $this->getlines())<2){
		unlink($this->file);
	}else{
	    $this->delete2("1",$this->input['id']);
	}
    $this->adminShowMsg("main.php?mod=systemsay&action=showSay&forumId={$this->input['forumId']}","您已经成功删除了论坛公告");
}

//4=============================================================================
//显示等待修改历史公告
function editSay()
{
	if ($this->input['forumId']=="all") {
	    $this->file = "../".$this->set[dataPath]."/announce.php";
        $forumName = "<a href=\"main.php?mod=systemsay&action=showSay\" ><font color=white><b>CTB论坛公告</b></font></a>";
	}else{

		$forumName .= "<a href=\"main.php?mod=systemsay&action=showSay\" ><font color=white><b>CTB论坛公告</b></font></a>>><a href=\"main.php?mod=systemsay&action=showSay&forumId={$this->input['forumId']}\" ><font color=white><b>".$this->getForumName($this->input['forumId'])."</b></font></a>";
        $this->file = "../".$this->set[dataPath]."/".$this->input['forumId']."/announce.php";
    }
    $sayLineCode = $this->select_line("1", $this->input['id']);
	$sayTopic=$sayLineCode[2];
	$sayBody = str_replace("<br>", "\n", $sayLineCode[3]);
    $sayUserId=$sayLineCode[4];
	$sayUser=$sayLineCode[5];
    eval("\$this->outPut(\"".$this->getTemplate("systemSayEdit")."\");");
}

//5=============================================================================
//保存修改历史公告
function editSaySave()
{
    //输入数据简单格式化
    $this->inputCheck("main.php?mod=systemsay&action=editSay&forumId={$this->input['forumId']}&id={$this->input['id']}");
	//
	if ($this->input['forumId']=="all"){
	    $this->file = "../".$this->set[dataPath]."/announce.php";
	}else{
        $this->file = "../".$this->set[dataPath]."/".$this->input['forumId']."/announce.php";
	}

	$saylist = $this->select_line("1",$this->input['id']);
	$saylist[2]= $this->input['sayTopic'];
	$editTime = date("Y-m-d H:i");
	$editInfor = "<br><br><div align=right><I>由 {$this->sess['sess_adminname']} 最后编辑于 $editTime</i></div>";
	$saylist[3]= $this->input['sayBody'].$editInfor;
	$this->update("1",$this->input['id'],$saylist);
    $this->adminShowMsg("main.php?mod=systemsay&action=showSay&forumId={$this->input['forumId']}","您已经成功修改了论坛公告");
}


//<<
//=============================================================================
} //end class