<?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 'addCat':
            $this->addCat();
            break;
        case 'doAddCat':
            $this->doAddCat();
            break;
       case 'addForum':
            $this->addForum();
            break;
        case 'doAddForum':
            $this->doAddForum();
            break;
        //
      }    
    } // end func

//-----------------------------------------------------------------------------
//---1、添加一个版块类型。------作者：险情
//---2、
//---3、
//-----------------------------------------------------------------------------

//=============================================================================
//添加新论坛分类
    function addCat()
    {

      $forumList=$this->getForumList();
      eval("\$this->outPut(\"".$this->getTemplate("forumAddCat")."\");");
    } // end func

//=============================================================================
//执行添加新版块操作
    function doAddCat()
    {
        //输入数据简单格式化
		$this->inputCheck("main.php?mod=forumadd&action=addCat");
        
		//
        $this->file =  "../".$this->set[dataPath]."/forums.php";
        $forums = $this->openfile();
		$new = "";
        $this->null_write($new);
        $getMaxId=time();
        $newforumLine=array(stripslashes($this->code),"cat",$getMaxId,$this->input[catName],$this->input[catInfo],"","","","","");
        //重写整个forum文件
        $this->file =  "../".$this->set[dataPath]."/forums.php";
        foreach ($forums as $line) {
            $this->add_line($line,0);
            if ($line[2]==$this->input[forumListId]) 
				$this->add_line($newforumLine);
        }
		//第一次建立类型用
		if (count($forums) == 0){
			$this->add_line($newforumLine);
		}
        //显示提示信息
       $this->adminShowMsg("main.php?mod=forumadd&action=addCat","您已经成功添加了一个新的论坛分类.");
    } // end func

//=============================================================================
//添加新版块
    function addForum()
    {
        //获取论坛分类列表
        $forumList=$this->getForumList();
        eval("\$this->outPut(\"".$this->getTemplate("forumAddForum")."\");");
    } // end func

//============================================================================= 
//执行添加新版块操作
function doAddForum()
    {
	  //对输入数据进行简单格式化
      if (!$this->input[forumName] or !$this->input[forumInfo])
        $this->adminShowWrong("main.php?mod=forumadd&action=addForum","论坛添加错误，请不要留空。");
      $this->input = $this->adminSafeChars($this->input);
	  if (!$this->input[forumListId])
        $this->adminShowWrong("main.php?mod=forumadd&action=addForum","论坛添加错误，请先建立论坛类型。");

      //获取forum列表并清空并获取最大forumid
      $this->file =  "../".$this->set[dataPath]."/forums.php";
      $forums = $this->openfile();
	  $new = "";
      $this->null_write($new);
      foreach ($forums as $maxNum) {
          if($maxNum[2]<=10000 and $maxNum[2]>0)
             $getMaxNum[]=$maxNum[2];
      }
	  if (!$getMaxNum)
          $getMaxId = 1;
	  else 
          $getMaxId=max($getMaxNum)+1;

      //获取新的版块数组
      $forumName = $this->input[forumName];
      $forumInfo = $this->input[forumInfo];
      $forumModerator = $this->input[forumModerator];
      $forumLimit = $this->input[forumLimit];
      $forumMode = $this->input[forumMode];
      $forumLimitUser = $this->input[forumLimitUser];
    //判断论坛模式
    if ($forumLimit=="0") {
		$forumGood="0";
		$forumLimit="0";
    }
    elseif ($forumLimit=="1") {
		$forumGood="0";
		$forumLimit="1";  
    }
    elseif ($forumLimit=="2") {
		$forumGood="1";
		$forumLimit="0";  
    }
    //获取斑竹名字和id
    $modOne = explode("|",$forumModerator);
    $modNum = count($modOne);
    $modListArray = array();
    for($j=0;$j<$modNum;$j++){
        if (!empty($modOne[$j])) {
            if ($this->getIdFromName($modOne[$j])){  //此处判断是否有这个用户
			    $authorId = $this->getIdFromName($modOne[$j]);

                $modListArray[]=$authorId.",".$modOne[$j];
				//
                //改变用户级别
				$this->file = "../".$this->set[dataPath]."/users/".$authorId.".php";
				$userLine = $this->get();
				$userLine[4]="3";
				$this->update("1",$systemLine[0][1],$userLine); 


				//
			}
        } 

    }
	$modList = join("|",$modListArray);
    //
    $newforumLine=array(stripslashes($this->code),"forum",$getMaxId,$forumName,$forumInfo,$forumGood,$forumLimit,$forumMode,$modList,"");
        //重写整个forum文件
        $this->file =  "../".$this->set[dataPath]."/forums.php";
        foreach ($forums as $line) {
            $this->add_line($line,0);
            if ($line[2]==$this->input[forumListId])
			    $this->add_line($newforumLine);
        }
		//
        //建立版块目录
        $this->file =  "../".$this->set[dataPath]."/".$getMaxId;
        mkdir($this->file,0777);
        $this->file =  "../".$this->set[dataPath]."/".$getMaxId."/status.php";
        $newforumLine=array(stripslashes($this->code),"","","","","","","","","","0","0","0");
        $this->overwrite($newforumLine);
        //$this->file =  "../".$this->set[dataPath]."/".$getMaxId."/list.php";
        //$this->null_write("");
    
	//更新forumid下的member文件
    $limitOne = explode("|",$forumLimitUser);
    $limitNum = count($limitOne);
    $limitList[]= "<?die();?>";
    for($j=0;$j<$limitNum;$j++){
        if (!empty($limitOne[$j])) { //此处判断是否有这个用户
			if ($this->getIdFromName($limitOne[$j])){
			    $limitList[] = $this->getIdFromName($limitOne[$j]);
			}
        }//end if 
    }
    $this->file =  "../".$this->set[dataPath]."/".$getMaxId."/member.php";
    $this->overwrite($limitList);


       
	   $this->adminShowMsg("main.php?mod=forumadd&action=addForum","您已经成功添加了一个新的论坛版块.");
    } // end func




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