<?php
/*
\* ===========================================
\* 项目: CTB文本论坛
\* 版本: 1。3
\* 团队: 实易数码
\* 小组: CTB文本论坛小组
\* 作者: 险情
\* 功能: 帖子管理模块
\* ===========================================
\* Copyright (c) 2002 
\* 团队主页: http://www.11cn.org
\* 团队信箱: -------------------
\* 创建日期: 2002.6
\* 修改日期: 2003-4-10
\* 修改说明: 代码整理/优化
\* 版权声明: 这个程序是免费软件.
\* ===========================================
*/

class Module extends CommonClass
{

    /**
     *构造函数
     *
     */
	function execute()
    {

    	if (!isset($this->sess['sess_uid']) || $this->sess['sess_uid'] == "" || ($this->userCheck("7") == "0")) {
            $this->showMsg("对不起，只有作者,版主和管理员有管理权限!");
        }
        switch($this->input['action']) {
            case 'del':
                $this->showMsg("你确定要删除这个帖子吗？","ask");
                break;
            case 'del2':
                $this->mod_del2();
                break;
            case 'mode':
                $this->mode();
                break;
            case 'mode_save':
                $this->modeSave();
                break;
        }

    } // end func
    
    /**
     *删除主题或者帖子
     *
     */
	function mod_del2()
    {

    	if ($this->input['topicid'] == "1") {
            $this->file = $this->set[dataPath]."/".$this->input['forumid']."/".$this->input['postid']."_.php";
            $postNum = $this->get();
            
			$getUpload = trim($postNum[11]);
            if (!empty($getUpload)) {
				$downloadFile = explode("|",$postNum[11]);
				for ($j=0; $j<count($downloadFile)-1; $j++){
                    $downloadFileOne = explode("%",$downloadFile[$j]);
				    $getDownloadFileName = $downloadFileOne[3];
                    @unlink ($this->set[dataPath]."/upfile/".$getDownloadFileName);

				}
			}
            $this->file = $this->set[dataPath]."/".$this->input['forumid']."/status.php";
            $line = $this->get();
            $line[1]--;
            $line[2] = $line[2] - $postNum[3];
            $this->overwrite($line);        

        	if (file_exists($this->set[dataPath]."/".$this->input['forumid']."/".$this->input['postid'].".php")) {
            	unlink($this->set[dataPath]."/".$this->input['forumid']."/".$this->input['postid'].".php");
            }

        	if (file_exists($this->set[dataPath]."/".$this->input['forumid']."/".$this->input['postid']."_.php")) {
            	unlink($this->set[dataPath]."/".$this->input['forumid']."/".$this->input['postid']."_.php");
            }

            $this->file = $this->set[dataPath]."/".$this->input['forumid']."/list.php";
            $this->delete2("1",$this->input['postid']);
 		   
			$this->manageLog("删除主题：->".$postNum[2]);			
       
            $this->showMsg("已经删除该主题了!","./index.php?mods=forumdisplay&forumid={$this->input['forumid']}");
        } else {
            $this->file = $this->set[dataPath]."/".$this->input['forumid']."/status.php";
            $line = $this->get();
            $line[2]--;
            $this->overwrite($line);
            $this->file = $this->set[dataPath]."/".$this->input['forumid']."/".$this->input['postid'].".php";
            $this->delete("1",$this->input['topicid']);
            $this->file = $this->set[dataPath]."/".$this->input['forumid']."/".$this->input['postid']."_.php";
            $line = $this->get();
            $line[3]--;
            $this->overwrite($line);
            
		    $this->manageLog("删除回帖：->".$line[2]);			
            $this->showMsg("已经删除该回帖了!","./index.php?mods=forumdisplay&forumid={$this->input['forumid']}");
        }
        
    } // end func

    /**
     *显示等待编辑帖子信息
     *
     */
	function mode()
    {
		$this->file = $this->set[dataPath]."/forums.php";
        $this->forum = $this->select_line("2",$this->input['forumid']);
        $this->file = $this->set[dataPath]."/".$this->input['forumid']."/".$this->input['postid']."_.php";
        $postTitles = $this->get();
        $this->BAN = " &gt; <a href=\"index.php?mods=forumdisplay&forumid={$this->input['forumid']}\">".$this->forum[3]."</a> &gt; <a href=\"index.php?mods=topicdisplay&forumid={$this->input['forumid']}&postid={$this->input['postid']}\">".$postTitles[2]."</a> &gt; 编辑帖子";
		$header = $this->header("编辑帖子");

        $this->file = $this->set[dataPath]."/".$this->input['forumid']."/".$this->input['postid'].".php";
    	if (file_exists($this->file)) {
            $line = $this->select_line("1",$this->input['topicid']);
            $topicTitle = stripslashes($line[2]);            
            $topicBody = str_replace("<br />", "\n", stripslashes($line[3]));  // use <br /> for XHTML by cx
            $topicBody = str_replace("<br>", "\n", $topicBody);                // for older version
            $topicBody = str_replace("&lt;", "<", $topicBody);                 // change back...
            $topicBody = str_replace("&gt;", ">", $topicBody);
            $topicBody = str_replace("&amp;", "&", $topicBody);
            $topicBody = str_replace("</textarea", "&lt;/textarea", $topicBody);

            $codeChecked = ($line[9] == 1) ? "checked" : "";
            $urlChecked = ($line[10] == 1) ? "checked" : "";
            $fuhaoChecked = ($line[11] == 1) ? "checked" : "";
            $sigChecked = ($line[12] == 1) ? "checked" : "";

            $action2 = $this->input['action']."2";
            $actionModlue = "modetopic";
            $actionType = "mode_save";
        	eval("\$this->outPut(\"".$this->getTemplate("post")."\");");
        } else {
            $this->showMsg("对不起，您要修改的帖子不存在!");
        }

    } // end func
    
    /**
     *保存修改结果
     *
     */
	function modeSave()
    {

        if (!trim($this->input['topicTitle'])) {
            $this->showMsg("请填写主题");
        } elseif (!trim($this->input['topicBody'])) {
            $this->showMsg("请填写信息内容");
        }elseif (strlen($this->input['replyTitle']) > $this->set[postTopicWidth]) {
            $this->showMsg("您填写的标题太长了");
        }elseif (strlen($this->input['replyBody']) > $this->set[postCommonWidth]) {
            $this->showMsg("您填写的帖子内容太长了");
        }

        $this->file = $this->set[dataPath]."/".$this->input['forumid']."/".$this->input['postid'].".php";
        if (file_exists($this->file)) {
            $line = $this->select_line("1",$this->input['topicid']);
            $line[2] = $this->safeChars($this->input['topicTitle']);
			$line[2] = $this->set[replaceWhenPost] == 'Y' ? $this->replaceBadWord($line[2]) : $line[2];

			$editTime = date("Y-m-d H:i");
			$editInfo = "<br /><br /><div align=\"right\"><i>由 {$this->sess[sess_uname]} 最后编辑于 $editTime</i></div>";  // changed by cx
			$this->input['topicBody'] = str_replace('&lt;/textarea', '</textarea', $this->input['topicBody']);  // added by cx
            $line[3] = addslashes($this->safeChars($this->input['topicBody']));  // changed by cx. thank PaoPaoLong.
			$line[3] = $this->set[replaceWhenPost] == 'Y' ? $this->replaceBadWord($line[3]) : $line[3];
			$line[14] = $editInfo;

            $line[9]  = ($this->input['disableCtbCode'] == 1) ? "1" : "0";
            $line[10] = ($this->input['disableUrl'] == 1) ? "1" : "0";
            $line[11] = ($this->input['disableSymbol'] == 1) ? "1" : "0";
            $line[12] = ($this->input['disableSig'] == 1) ? "1" : "0";

            $this->update("1",$this->input['topicid'],$line);
            
			$this->manageLog("编辑帖子：->".$line[2]); 

			$this->showMsg("恭喜您，您修改的帖子已经成功保存!","./index.php?mods=topicdisplay&forumid={$this->input['forumid']}&postid={$this->input['postid']}");
        } else {
            $this->showMsg("对不起，您要修改的帖子不存在!");
        }
    } // end func
} // end class

?>