<?php
/*
\* ===========================================
\* 项目: CTB文本论坛
\* 版本: 1.0
\* 团队: 实易数码
\* 小组: 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 'forumJoin':
            $this->forumJoin();
            break;
        case 'doForumJoin':
                $this->doAdminOrder("你确定要将此2个版块合并吗？");
            break;

        case 'doForumJoin2':
            $this->doForumJoin();
            break;
        //
      }    
    } // end func

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

//=============================================================================
//将论坛版块合并
    function forumJoin()
    {
        //获取论坛分类列表
        $optionLine = $this->getForumLine();

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

//=============================================================================
//将论坛版块合并操作
    function doForumJoin()
    {
        //:::将A中的所有帖子放到B中:::
		$joinForumA=$this->input[joinForumA]; 
		$joinForumB=$this->input[joinForumB];
        if ($joinForumA == $joinForumB){
            $this->adminShowWrong("main.php?mod=forumjoin&action=forumJoin","合并成功 ：）嘻嘻");

		}
        if (!is_dir('../'.$this->set[dataPath]."/".$joinForumA) or !is_dir('../'.$this->set[dataPath]."/".$joinForumB)) {
            $this->adminShowWrong("./main.php?mod=forumstat","请您选择子论坛");
		}
		//取出原论坛列表/主题信息,删除主题列表中的主题
        if (file_exists("../".$this->set[dataPath]."/".$joinForumA."/list.php")){
			$this->file = "../".$this->set[dataPath]."/".$joinForumA."/list.php";
			$copyList = $this->openFile();
        }else{
            $this->adminShowWrong("main.php?mod=forumjoin&action=forumJoin","合并版块没有帖子");

		}
        //获得新主题的id 
        if (file_exists( "../".$this->set[dataPath]."/".$joinForumB."/list.php")) {
			$this->file = "../".$this->set[dataPath]."/".$joinForumB."/list.php";
            $newPostId = $this->get_max_value("1")+1;
        }else{
            $newPostId = 1;
		}

		$getCopyNum = count($copyList);
        $getAllNum = 0;
        for($i=0;$i<$getCopyNum;$i++){
        //更新新论坛列表信息
		    //写入帖子php
			$this->file = "../".$this->set[dataPath]."/".$joinForumA."/".$copyList[$i][1]."_.php";
			$copyPhp3 = $this->get();
			$copyPhp3[1] = $newPostId;
			$this->file = "../".$this->set[dataPath]."/".$joinForumB."/".$newPostId."_.php";
			$this->overwrite($copyPhp3);
			$getAllNum = $getAllNum+$copyPhp3[3];
			//写入帖子php_
			$this->file = "../".$this->set[dataPath]."/".$joinForumA."/".$copyList[$i][1].".php";
			$fp = @fopen($this->file,"r");
			flock($fp,LOCK_SH);
			$copyPhp = fread($fp, filesize($this->file));
			fclose($fp);
			//
			$this->file = "../".$this->set[dataPath]."/".$joinForumB."/".$newPostId.".php";
			$fp = @fopen($this->file,"w");
			flock($fp,LOCK_EX);
			fwrite($fp,$copyPhp);
			fclose($fp);
			//写入list列表
			$copyList[$i][1] = $newPostId;
		    $this->file = "../".$this->set[dataPath]."/".$joinForumB."/list.php";
			$this->insertTop($this->file,$copyList[$i]);			
			//
			if($i==($getCopyNum-1)){
			    $pageNum = $this->getlines();
			}

			$newPostId++;
		}
        //更新论坛状态文件
        $this->file = "../".$this->set[dataPath]."/".$joinForumB."/status.php";
        $newStatus = $this->get();
        $newStatus[1] = $newStatus[1]+$getCopyNum;
        $newStatus[2] = $newStatus[2]+$getAllNum;
        $newStatus[3] = $newPostId;
        $this->overwrite($newStatus);

        //删除原论坛所有数据
		$this->file = "../". $this->set[dataPath]."/forums.php";
		$line = $this->delete2(2,$joinForumA);
		$this->file = "../". $this->set[dataPath]."/".$joinForumA;
		if (file_exists($this->file)) {
		  $delmgs=$this->delFileValue($this->file);
		}
      
	  
	  $this->adminShowMsg("./main.php?mod=forumjoin&action=forumJoin","您已经成功进行了版块合并");
    } // end func


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