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

//=============================================================================
class Module extends CommonClass
{
    //构造函数
    function execute()
    {
      global $action;
      switch($this->input['action']) {
        //
        case 'forumArticle':
            $this->forumArticle();
            break;
        case 'delWithDate':
            $this->doAdminOrder("你确定要对此版块进行帖子删除？");
            break;
        case 'delWithDate2':
            $this->delWithDate();
            break;
        case 'delWithNum':
            $this->doAdminOrder("你确定要对此版块进行帖子删除？");
            break;
        case 'delWithNum2':
            $this->delWithNum();
            break;
        case 'delArticle':
		    $this->inputCheck("main.php?mod=forumarticle&action=forumArticle");
            $this->doAdminOrder("你确定要将此人的帖子全部删除吗？");
            break;
        case 'delArticle2':
            $this->delArticle();
            break;
        //
        default:
            $this->forumArticle();
            break;
      }
    } // end func

//-----------------------------------------------------------------------------
//---1、论坛版块排序。------作者：险情
//---2、
//---3、
//-----------------------------------------------------------------------------

//=============================================================================
//显示论坛帖子信息
    function forumArticle()
    {

		//格式化用户输入数据
		if(!$this->input){
            $userTopicNum = 0;
            eval("\$this->outPut(\"".$this->getTemplate("forumArticle")."\");");
		}
		if ($this->input['searchName'] and !$this->getIdFromName($this->input['searchName'])){
			unset($this->input['searchName']);
            $this->adminShowWrong("main.php?mod=forumarticle&action=forumArticle","没有这个注册用户。");
		}

        //获取论坛分类列表
		$forumId = $this->input['forumId'];
		$mode = $this->input['mode'];
		$searchName = $this->input['searchName'];
        $optionLine = $this->getForumLine($forumId);
        $userTopicNum = 0;
		$searchTime = 96400*$this->input['searchDay'];
		$getNowTime = time();
		//
		//exit();

		//
		if ($forumId=="all" or !$forumId) {
			$msg = "查看论坛所有版块";
			//显示所有论坛帖子总计
			$this->file = "../".$this->set[dataPath]."/forums.php";
			$forumLines = $this->read_file();
			foreach ($forumLines as $forumLine) {
				$forum = $this->make_array($forumLine);
				if ($forum[1] == "forum") {
					$forumid = $forum[2];

					$this->file =  "../".$this->set[dataPath]."/".$forumid."/list.php";
					$lines = $this->read_file();
					for ($i=0; $i<count($lines);$i++ ) {
						$lineInfo = $this->make_array($lines[$i]);
						if ($mode == "before"){
							if ($lineInfo[2] == $searchName and ($getNowTime-$lineInfo[3])>$searchTime){
								$userTopicNum++;
							}
						}
						elseif($mode == "after"){
							//exit($lineInfo[3]);
							if ($lineInfo[2] == $searchName and ($getNowTime-$lineInfo[3])<$searchTime){
								$userTopicNum++;

								//$nameXianqing = $lineInfo[2];
							    //exit($nameXianqing);

							}
						}
					}//end for
				}
			}//end foreach
			$topicNum = "以下为<b>$searchName</b>共发表主题";
		//显示单个论坛帖子总计
		}
		else{
            $msg = $this->getForumName($forumId);
			$this->file =  "../".$this->set[dataPath]."/".$forumId."/list.php";
			$lines = $this->read_file();
			for ($i=0; $i<count($lines);$i++ ) {
				$lineInfo = $this->make_array($lines[$i]);
				if ($mode == "before"){
					if ($lineInfo[2] == $searchName and ($getNowTime-$lineInfo[3])>$searchTime){
						$userTopicNum++;
					}
				}
				elseif($mode == "after"){
					//exit($lineInfo[3]);
					if ($lineInfo[2] == $searchName and ($getNowTime-$lineInfo[3])<$searchTime){
						$userTopicNum++;

						//$nameXianqing = $lineInfo[2];
						//exit($nameXianqing);

					}
				}
			}//end for
		$topicNum = "以下为<b><font color=red>$searchName</font></b>共发表主题";

		}


      eval("\$this->outPut(\"".$this->getTemplate("forumArticle")."\");");
    } // end func

//=============================================================================
//按照日期条件进行删除
    function delWithDate()
    {
        if($this->input[forumId] > 1000 and $this->input[forumId]!="all"){
            $this->adminShowMsg("./main.php?mod=forumarticle","请您选择子版块");

		}
		if(!ereg ("^[0-9]$",$this->input[searchDay])){
            $this->adminShowMsg("./main.php?mod=forumarticle","请您选择删除条件");
		}
		$getNowTime = time();
		$searchTime = 86400*$this->input['searchDay'];
        $getDelNum = 0;
		$getPostCount = 0;


        if(!$this->input[forumId] or $this->input[forumId]=="all"){
			$this->file = '../'.$this->set[dataPath]."/forums.php";
			$forums = $this->openfile();
			foreach ($forums as $this->forum) {
				$forumDelNum = 0;
		        $getPostCount = 0;
				if ($this->forum[1] == "forum" and file_exists('../'.$this->set[dataPath]."/".$this->forum[2]."/list.php")) {
					//获的list.php文件主题
					$this->file = '../'.$this->set[dataPath]."/".$this->forum[2]."/list.php";
					$listInfo = $this->openfile();
					for($i=0; $i<count($listInfo); $i++){
						$getTopicTime = intval($listInfo[$i][3]);
						if(($getNowTime-$getTopicTime) > $searchTime){
							$this->file = '../'.$this->set[dataPath]."/".$this->forum[2]."/list.php";
							$this->delete2("1",$listInfo[$i][1]);
							$this->file = '../'.$this->set[dataPath]."/".$this->forum[2].'/'.$listInfo[$i][1].'.php';
							$getPostCount += $this->getlines();
							@unlink('../'.$this->set[dataPath]."/".$this->forum[2].'/'.$listInfo[$i][1].'.php');
							@unlink('../'.$this->set[dataPath]."/".$this->forum[2].'/'.$listInfo[$i][1].'_.php');
							@unlink('../'.$this->set[dataPath]."/".$this->forum[2].'/'.$listInfo[$i][1].'.php4');
							$forumDelNum++;
						}
					}//end for
				//更新版块信息
				$this->file = '../'.$this->set[dataPath]."/".$this->forum[2]."/list.php";
				$getListMaxId = $this->get_max_value("1");
				$this->file = '../'.$this->set[dataPath]."/".$this->forum[2]."/status.php";
				$line = $this->get();

				$line[1] = $line[1]-$forumDelNum;
				$line[2] = $line[2]-$getPostCount;
				$line[3] = $getListMaxId;

				$this->overwrite($line);

				//
				$getDelNum += $forumDelNum;
				}
			}//end foreach
		}//
		else{

			$this->file = '../'.$this->set[dataPath]."/".$this->input[forumId]."/list.php";
			$listInfo = $this->openfile();
			for($i=0; $i<count($listInfo); $i++){
				$getTopicTime = intval($listInfo[$i][3]);
				if(($getNowTime-$getTopicTime) > $searchTime){
			        $this->file = '../'.$this->set[dataPath]."/".$this->input[forumId]."/list.php";
                    $this->delete2("1",$listInfo[$i][1]);
					$this->file = '../'.$this->set[dataPath]."/".$this->input[forumId].'/'.$listInfo[$i][1].'.php';
					$getPostCount += $this->getlines();
					@unlink('../'.$this->set[dataPath]."/".$this->input[forumId].'/'.$listInfo[$i][1].'.php');
					@unlink('../'.$this->set[dataPath]."/".$this->input[forumId].'/'.$listInfo[$i][1].'_.php');
					@unlink('../'.$this->set[dataPath]."/".$this->input[forumId].'/'.$listInfo[$i][1].'.php4');
					$getDelNum++;
				}
			}//end for
			//更新版块信息
			$this->file = '../'.$this->set[dataPath]."/".$this->input[forumId]."/list.php";
			$getListMaxId = $this->get_max_value("1");
			$this->file = '../'.$this->set[dataPath]."/".$this->input[forumId]."/status.php";
			$line = $this->get();

			$line[1] = $line[1]-$getDelNum;
			$line[2] = $line[2]-$getPostCount;
			$line[3] = $getListMaxId;

			$this->overwrite($line);

		}
        $this->adminShowMsg("./main.php?mod=forumarticle","您已经成功按照日期删除了所有符合条件的帖子记录：<font color=red><b>$getDelNum</b></font>");
    } // end func

//=============================================================================
//按照日期条件进行删除
    function delWithNum()
    {
        //
        if($this->input[forumId] > 1000 and $this->input[forumId]!="all"){
            $this->adminShowMsg("./main.php?mod=forumarticle","请您选择子版块");

		}
		if(!ereg ("^[0-9]$",$this->input[searchNum])){
            $this->adminShowMsg("./main.php?mod=forumarticle","请您选择删除条件");
		}
		$searchNum = $this->input['searchNum'];
        $getDelNum = 0;
		$getPostCount = 0;



        if(!$this->input[forumId] or $this->input[forumId]=="all"){
			$this->file = '../'.$this->set[dataPath]."/forums.php";
			$forums = $this->openfile();
			foreach ($forums as $this->forum) {
				$forumDelNum = 0;
		        $getPostCount = 0;
				if ($this->forum[1] == "forum" and file_exists('../'.$this->set[dataPath]."/".$this->forum[2]."/list.php")) {
					//获的list.php文件主题
					$this->file = '../'.$this->set[dataPath]."/".$this->forum[2]."/list.php";
					$listInfo = $this->openfile();
					$this->null_write("");
					for($i=0; $i<count($listInfo); $i++){
						if($i<$searchNum){
						   $this->file = '../'.$this->set[dataPath]."/".$this->forum[2]."/list.php";
						   $this->add_line($listInfo[$i],0);
						}
						else{

							$this->file = '../'.$this->set[dataPath]."/".$this->forum[2]."/list.php";
							$this->delete2("1",$listInfo[$i][1]);
							$this->file = '../'.$this->set[dataPath]."/".$this->forum[2].'/'.$listInfo[$i][1].'.php';
							$getPostCount += $this->getlines();
							@unlink('../'.$this->set[dataPath]."/".$this->forum[2].'/'.$listInfo[$i][1].'.php');
							@unlink('../'.$this->set[dataPath]."/".$this->forum[2].'/'.$listInfo[$i][1].'_.php');
							@unlink('../'.$this->set[dataPath]."/".$this->forum[2].'/'.$listInfo[$i][1].'.php4');
							$forumDelNum++;

						}
					}//end for
					//更新版块信息
					$this->file = '../'.$this->set[dataPath]."/".$this->forum[2]."/list.php";
					$getListMaxId = $this->get_max_value("1");
					$this->file = '../'.$this->set[dataPath]."/".$this->forum[2]."/status.php";
					$line = $this->get();

					$line[1] = $line[1]-$forumDelNum;
					$line[2] = $line[2]-$getPostCount;
					$line[3] = $getListMaxId;

					$this->overwrite($line);

					$getDelNum += $forumDelNum;
				}
			}//end foreach
		}//
		else{


			$this->file = '../'.$this->set[dataPath]."/".$this->input[forumId]."/list.php";
			$listInfo = $this->openfile();
            $this->null_write("");
			for($i=0; $i<count($listInfo); $i++){
				if($i<$searchNum){
			       $this->file = '../'.$this->set[dataPath]."/".$this->input[forumId]."/list.php";
                   $this->add_line($listInfo[$i],0);
				}
				else{

					$this->file = '../'.$this->set[dataPath]."/".$this->input[forumId]."/list.php";
					$this->delete2("1",$listInfo[$i][1]);
					$this->file = '../'.$this->set[dataPath]."/".$this->input[forumId].'/'.$listInfo[$i][1].'.php';
					$getPostCount += $this->getlines();
					@unlink('../'.$this->set[dataPath]."/".$this->input[forumId].'/'.$listInfo[$i][1].'.php');
					@unlink('../'.$this->set[dataPath]."/".$this->input[forumId].'/'.$listInfo[$i][1].'_.php');
					@unlink('../'.$this->set[dataPath]."/".$this->input[forumId].'/'.$listInfo[$i][1].'.php4');
					$getDelNum++;

				}
			}//end for
			//更新版块信息
			$this->file = '../'.$this->set[dataPath]."/".$this->input[forumId]."/list.php";
			$getListMaxId = $this->get_max_value("1");
			$this->file = '../'.$this->set[dataPath]."/".$this->input[forumId]."/status.php";
			$line = $this->get();

			$line[1] = $line[1]-$getDelNum;
			$line[2] = $line[2]-$getPostCount;
			$line[3] = $getListMaxId;

			$this->overwrite($line);

		}
        $this->adminShowMsg("./main.php?mod=forumarticle","您已经成功按照数量删除了所有符合条件的帖子记录：<font color=red><b>$getDelNum</b></font>");
    } // end func


//=============================================================================
//删除一个用户的所有帖子
    function delArticle()
    {

		//格式化用户输入数据
		if ($this->input['id'] and !$this->getIdFromName($this->input['id'])){
            $this->adminShowWrong("main.php?mod=forumarticle&action=forumArticle","没有这个注册用户。");
		}

        //获取论坛分类列表
		$forumId = $this->input['forumId'];
		$mode = $this->input['searchMode'];
		$searchName = $this->input['id'];
        $optionLine = $this->getForumLine($forumId);
        $userTopicNum = 0;
		$searchTime = 96400*$this->input['searchDay'];
		$getNowTime = time();


		$getDelNum = 0;
		$getPostCount = 0;

		//
//        echo $forumId."-".$mode."-".$searchName."-".$searchTime."-".$getNowTime;
		//exit();

		//
		if ($forumId=="all" or !$forumId) {
			$msg = "查看论坛所有版块";
			//显示所有论坛帖子总计
			$this->file = "../".$this->set[dataPath]."/forums.php";
			$forumLines = $this->read_file();
			foreach ($forumLines as $forumLine) {
				$forumDelNum = 0;
		        $getPostCount = 0;
				$forum = $this->make_array($forumLine);
				if ($forum[1] == "forum" and file_exists("../".$this->set[dataPath]."/".$forum[2]."/list.php")) {
					$forumId = $forum[2];

					$this->file =  "../".$this->set[dataPath]."/".$forumId."/list.php";
					$lines = $this->read_file();
					for ($i=0; $i<count($lines);$i++ ) {
						$lineInfo = $this->make_array($lines[$i]);
							if ($mode == "before"){
								if ($lineInfo[2] == $searchName and ($getNowTime-$lineInfo[3])>$searchTime){

									$this->file = '../'.$this->set[dataPath]."/".$forumId."/list.php";
									$this->delete2("1",$lineInfo[1]);
									$this->file = '../'.$this->set[dataPath]."/".$forumId.'/'.$lineInfo[1].'.php';
									$getPostCount += $this->getlines();
									@unlink('../'.$this->set[dataPath]."/".$forumId.'/'.$lineInfo[1].'.php');
									@unlink('../'.$this->set[dataPath]."/".$forumId.'/'.$lineInfo[1].'_.php');
									@unlink('../'.$this->set[dataPath]."/".$forumId.'/'.$lineInfo[1].'.php4');

									$forumDelNum++;
								}
							}
							elseif($mode == "after"){
								//exit($lineInfo[3]);
								if ($lineInfo[2] == $searchName and ($getNowTime-$lineInfo[3])<$searchTime){

									$this->file = '../'.$this->set[dataPath]."/".$forumId."/list.php";
									$this->delete2("1",$lineInfo[1]);
									$this->file = '../'.$this->set[dataPath]."/".$forumId.'/'.$lineInfo[1].'.php';
									$getPostCount += $this->getlines();
									@unlink('../'.$this->set[dataPath]."/".$forumId.'/'.$lineInfo[1].'.php');
									@unlink('../'.$this->set[dataPath]."/".$forumId.'/'.$lineInfo[1].'_.php');
									@unlink('../'.$this->set[dataPath]."/".$forumId.'/'.$lineInfo[1].'.php4');

									$forumDelNum++;
								}
							}
						}//end for
						//更新版块信息
						$this->file = '../'.$this->set[dataPath]."/".$forumId."/list.php";
						$getListMaxId = $this->get_max_value("1");
						$this->file = '../'.$this->set[dataPath]."/".$forumId."/status.php";
						$line = $this->get();
						$line[1] = $line[1]-$forumDelNum;
						$line[2] = $line[2]-$getPostCount;
						$line[3] = $getListMaxId;

						$this->overwrite($line);
				}
			$getDelNum += $forumDelNum;

			}//end foreach
			$topicNum = "以下为<b>$searchName</b>共发表主题";
		//显示单个论坛帖子总计
		}

		else{
			$this->file =  "../".$this->set[dataPath]."/".$forumId."/list.php";
			$lines = $this->read_file();
			for ($i=0; $i<count($lines);$i++ ) {
				$lineInfo = $this->make_array($lines[$i]);
				if ($mode == "before"){
					if ($lineInfo[2] == $searchName and ($getNowTime-$lineInfo[3])>$searchTime){

					    $this->file = '../'.$this->set[dataPath]."/".$forumId."/list.php";
					    $this->delete2("1",$lineInfo[1]);
					    $this->file = '../'.$this->set[dataPath]."/".$forumId.'/'.$lineInfo[1].'.php';
					    $getPostCount += $this->getlines();
					    @unlink('../'.$this->set[dataPath]."/".$forumId.'/'.$lineInfo[1].'.php');
					    @unlink('../'.$this->set[dataPath]."/".$forumId.'/'.$lineInfo[1].'_.php');
					    @unlink('../'.$this->set[dataPath]."/".$forumId.'/'.$lineInfo[1].'.php4');

						$getDelNum++;
					}
				}
				elseif($mode == "after"){
					//exit($lineInfo[3]);
					if ($lineInfo[2] == $searchName and ($getNowTime-$lineInfo[3])<$searchTime){

						$this->file = '../'.$this->set[dataPath]."/".$forumId."/list.php";
					    $this->delete2("1",$lineInfo[1]);
					    $this->file = '../'.$this->set[dataPath]."/".$forumId.'/'.$lineInfo[1].'.php';
					    $getPostCount += $this->getlines();
					    @unlink('../'.$this->set[dataPath]."/".$forumId.'/'.$lineInfo[1].'.php');
					    @unlink('../'.$this->set[dataPath]."/".$forumId.'/'.$lineInfo[1].'_.php');
					    @unlink('../'.$this->set[dataPath]."/".$forumId.'/'.$lineInfo[1].'.php4');

						$getDelNum++;
					}
				}
			}//end for
				//更新版块信息
				$this->file = '../'.$this->set[dataPath]."/".$forumId."/list.php";
				$getListMaxId = $this->get_max_value("1");
				$this->file = '../'.$this->set[dataPath]."/".$forumId."/status.php";
				$line = $this->get();
                				$line[1] = $line[1]-$getDelNum;
				$line[2] = $line[2]-$getPostCount;
				$line[3] = $getListMaxId;

				$this->overwrite($line);
		$topicNum = "以下为<b><font color=red>$searchName</font></b>共发表主题";

		}


        $this->adminShowMsg("./main.php?mod=forumarticle","您已经成功按照数量删除了所有符合条件的帖子记录：<font color=red><b>$getDelNum</b></font>");
    } // end func

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