<?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 'editCat':
            $this->editCat();
            break;
        case 'doEditCat':
            $this->doEditCat();
            break;
        case 'forumEditShow':
            $this->forumEditShow();
            break;
        case 'forumEditSave':
            $this->forumEditSave();
            break;

        //
      }    
    } // end func

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

//=============================================================================
//显示等待处理论坛分类函数
    function editCat()
    {   
		
	  $forumId = $this->input[forumId];

      $this->site_title .= $this->set[ctbTitle]." - 首页";
      $this->file = "../".$this->set[dataPath]."/forums.php";
      $forumCode = $this->select_line("2", $forumId);
      //显示等待修改版快信息
      $forumName = $forumCode[3];
      $forumInfo = $forumCode[4];
     eval("\$this->outPut(\"".$this->getTemplate("forumEditCat")."\");");
    } // end func

//=============================================================================
//处理论坛分类函数
    function doEditCat()
    {
		$this->inputCheck("main.php?mod=forumedit&action=editCat");

		  $this->file = "../". $this->set[dataPath]."/forums.php";
		  $line = $this->select_line(2,$this->input[forumId]);
		  $line[3]=$this->input[forumName];
		  $line[4]=$this->input[forumInfo];
		  $this->update2("2",$this->input[forumId],$line);    
        
        //显示提示信息
       $this->adminShowMsg("main.php?mod=forumedit&action=editCat&forumId={$this->input[forumId]}","您已经成功修改了论坛分类.");
    } // end func

//=============================================================================
//显示等待处理版块函数
    
	function forumEditShow()
    {   
      $this->site_title .= $this->set[ctbTitle]." - 首页";
      $this->file = "../".$this->set[dataPath]."/forums.php";
      $forumCode = $this->select_line("2", $this->input[forumId]);
      //显示等待修改版快信息
      $forumName = $forumCode[3];
      $forumInfo = $forumCode[4];
      //获取论坛模式
      if ($forumCode[5] == "1") {
        $forumLimit="<option value=\"0\">普通版块</option><option value=\"1\">加密版块</option><option value=\"2\" selected>精华版块</option>";
      }elseif ($forumCode[6] == "1") {
        $forumLimit = "<option value=\"0\">普通版块</option><option value=\"1\" selected>加密版块</option><option value=\"2\" >精华版块</option>";
      }else {
        $forumLimit = "<option value=\"0\" selected>普通版块</option><option value=\"1\" >加密版块</option><option value=\"2\" >精华版块</option>";
      }
      //
      if ($forumCode[7]=="1") {
        $forumMode="<option value=\"0\">访客访问</option><option value=\"1\" selected>注册访问</option>";
      }else {
        $forumMode="<option value=\"0\" selected>访客访问</option><option value=\"1\" >注册访问</option>";
      }
      //获取论坛帖子信息
      $this->file = "../".$this->set[dataPath]."/".$this->input[forumId]."/status.php";
      $newStatus = $this->get();
      $topicNum = $newStatus[1];
      $postNum = $newStatus[2]-$newStatus[1];
      //显示斑竹
      if ($forumCode[8] != "") {
        $moderators = explode("|",$forumCode[8]);
        $moderCount = count($moderators);
        for ($i=0;$i<=$moderCount;$i++) {
            if ($moderators[$i] != "") {
              $modInfo = explode(",",$moderators[$i]);
              $modUserid = $modInfo[0];
              $modUsername = $modInfo[1];

              $modListArray[] = $modUsername; 
            }
        }
		$modList = join("|",$modListArray);
      } else {
        $modList = "";
      }
      //获取论坛会员
      $this->file = "../".$this->set[dataPath]."/".$this->input[forumId]."/member.php";
      @$limitUsers = $this->get();
	  $limitUsersArray = array();
      for ($i=1;$i<count($limitUsers);$i++) {
        $this->file = "../".$this->set[dataPath]."/users/".$limitUsers[$i].".php";
        @$limitUserName = $this->get();
		
		$limitUsersArray[] = $limitUserName[3];
      } 
	  $limitUsersList = join("|",$limitUsersArray);
	  eval("\$this->outPut(\"".$this->getTemplate("forumEditShow")."\");");
    } // end func

//=============================================================================
//版块处理操作函数
    function forumEditSave()   {

	  //输入数据简单验证
      if (!$this->input[forumName] or !$this->input[forumInfo])
      $this->adminShowWrong("main.php?mod=forumedit&action=forumEditShow&forumId={$this->input[forumId]}","论坛修改错误，请不要留空。");
      
      $this->input = $this->adminSafeChars($this->input);
        //获取新的版块数组
      $forumId = $this->input[forumId];
      $forumName = $this->input[forumName];
      $forumInfo = $this->input[forumInfo];
      $forumModerator = $this->input[forumModerator];
      $forumMode = $this->input[forumMode];
      $forumLimitUser = $this->input[forumLimitUser];
    //判断论坛模式
    if ($this->input[forumLimit] == "0") {
      $forumGood = "0";
      $forumLimit = "0";
    }
    if ($this->input[forumLimit] == "1") {
      $forumGood = "0";
      $forumLimit = "1";  
    }
    if ($this->input[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);

    //更新forums.php文件
    $this->file = "../".$this->set[dataPath]."/forums.php";
    $updateArray=array($this->code,"forum",$forumId,$forumName,$forumInfo,$forumGood,$forumLimit,$forumMode,$modList,"","\n");
    $this->update2("2",$forumId,$updateArray);
    
    //更新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]."/".$forumId."/member.php";
    $this->overwrite($limitList);
    //显示提示信息
    $this->adminShowMsg("main.php?mod=forumedit&action=forumEditShow&forumId={$this->input[forumId]}","您已经成功修改此版快的信息.");

    }

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