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

//=============================================================================

class Module extends CommonClass
{
    function execute()
    {
        switch($this->input['action']) {
			//
            case 'showAll':
                $this->showAll();
                break;
            case 'editUser':
                $this->editUser();
                break;
            case 'saveUser':
                $this->saveUser();
                break;
            case 'delUser':
                $this->doAdminOrder("你确定要此注册用户删除？");
                break;
            case 'delUser2':
                $this->delUser();
                break;
			//
        }
    } // end func

//-----------------------------------------------------------------------------
//---1、显示所有论坛用户------作者：险情
//---2、
//---3、
//-----------------------------------------------------------------------------

//=============================================================================
    function showAll()
    {

		$p = $this->input[p];
		if ( !$p ) { $p = 1; } 
        
        //显示列表
        $this->file = "../".$this->set[dataPath]."/users/list.php";
        $listline = $this->openfile();
        //    
        $totalFile = count($listline);
        $recnum = 20;//$userlist;
        $totalnum = ($totalFile % $recnum) == "0" ? intval(($totalFile)/$recnum) : intval(($totalFile)/$recnum)+1;
        //显示列表
		$num=0;
    	for( $i = ($totalFile - ($p-1)*$recnum); $i > ($totalFile - $p*$recnum);$i--)  { 
            $this->file = "../".$this->set[dataPath]."/users/".$listline[$i][1].".php";
        	if (file_exists($this->file) and $listline[$i]) {
            	if ($listline[$i][5]=="0") 
					$userMode="<font color=red>禁止</font>";
                else 
					$userMode="正常";
                $memberInfo = $this->get();
                $memName = htmlspecialchars($memberInfo[3]);
                $memTime = date("Y-m-d H:i:s",$memberInfo[11]);
                $userId = $memberInfo[1];
                $memPnum=$memberInfo[13];
                $memGrade=$memberInfo[18];
            	if (empty($mem_grade))
                    $memGrade="0";
                $memJb=$memberInfo[16];

				$num = $i+1;
            	eval ("\$member_list .= \"".$this->getTemplate("userShowLine")."\";");
            }
		}
        $page = $this->getPage("$PHP_SELF?mod=user&action=showAll",$totalnum);
    	eval("\$this->outPut(\"".$this->getTemplate("userShowAll")."\");");
    } // end func

//=============================================================================
//编辑一个选中会员
    function editUser()
    {
        
        //获取投降存储地址
		$getImageDir = ".".$this->set[facePath];
        $userId = $this->input['userId'];
        //获取用户文件
        $this->file = "../".$this->set[dataPath]."/users/".$this->input['userId'].".php";
        $userInfo = $this->openfile();
        //将用户资料进行付值
        $userLoginId=$userInfo[0][2];
        $userName=$userInfo[0][3];
        //-----------
        $userEmail=$userInfo[0][5];
        $userHomepage=$userInfo[0][6];
        $userForm=$userInfo[0][7];
        $userQq=$userInfo[0][8];
        $userMsn=$userInfo[0][9];
        $userIcq=$userInfo[0][10];
        $userTime=date("Y-m-d H:i:s",$userInfo[0][11]);
        $userLastTime=date("Y-m-d H:i:s",$userInfo[0][12]);
        $userSign= str_replace("<br>","",$userInfo[0][15]);
        //-----------
		$userGroup=$userInfo[0][4];
        $userGroupName=$userInfo[0][16];
        $userGroupPic=$userInfo[0][17];
        //-----------
        $userPostAll=$userInfo[0][13];
        $userGrade=$userInfo[0][18];
        $userPostForum=$userInfo[0][19];
        $userPostId=$userInfo[0][20];
        $userPostTime=date("Y-m-d H:i:s",$userInfo[0][22]);
        $userPostTopic=$userInfo[0][21];
        //-----------
			$userPicUp=$userInfo[0][36];
			$memberTitle = $userInfo[0][23];
			
			$userPic=$userInfo[0][14];
        
		
		
		$userMoney = $userInfo[0][34];
		if ($userInfo[0][26] == "man"){
			$gender_0 = "checked";
			$gender_1 = "";
			$gender_2 = "";

		}
		elseif ($userInfo[0][26] == "woman") {
			$gender_0 = "";
			$gender_1 = "checked";
			$gender_2 = "";
		}
		else{
			$gender_0 = "";
			$gender_1 = "";
			$gender_2 = "checked";
		}
		//
		if ($userInfo[0][37] == "1"){
			$faceModeChecked_0 = "";
			$faceModeChecked_2 = "";
			$faceModeChecked_1 = "checked";
		}
		elseif ($userInfo[0][37] == "2"){
			$faceModeChecked_0 = "";
			$faceModeChecked_1 = "";

			$faceModeChecked_2 = "checked";
		}
		else {
			$faceModeChecked_2 = "";

			$faceModeChecked_0 = "checked";
			$faceModeChecked_1 = "";
		}
		$userBirthday = $userInfo[0][27];
		$faceDesign = $userInfo[0][35];
	    $oldIntroduce = $userInfo[0][33];
        //-----------
        $dh=opendir(".".$this->set[facePath]);
        while ($imagefile=readdir($dh)) {
            if (($imagefile!=".") && ($imagefile!="..") && ($imagefile!="")  &&($imagefile!="xq.jpg")) 
            $userPic_1.="<option value=".$imagefile.">".$imagefile."</option>";
        }
        closedir($dh);
        
		eval("\$this->outPut(\"".$this->getTemplate("userEdit")."\");");
    }

//=============================================================================
//存储一个修改会员
    function saveUser()
    {
		//输入数据简单格式化
        $this->input = $this->adminSafeChars($this->input);
		//
        $this->file ="../".$this->set[dataPath]."/users/".$this->input['userId'].".php";
        $userInfo = $this->select("1",$this->input['userId']);
        //////修改密码
        $this->file ="../".$this->set[dataPath]."/users/list.php";
        $userNewLogin = $this->select("1",$this->input['userId']);
    	if ($userNewLogin[0][3]!=md5($this->input[userNewpass]) and !empty($this->input[userNewpass])) {
            $userNewLogin[0][3]=md5($this->input[userNewpass]);
            $this->update("1",$this->input['userId'],$userNewLogin[0]);
        }
        //////修改资料
        //$userInfo[0][2]= $this->adminSafeChars($user_loginid);
        //$userInfo[0][3]= $this->adminSafeChars($user_name);
        //////
        $userInfo[0][5]= $this->input[userEmail];
        $userInfo[0][6]= $this->input[userHomepage];
        $userInfo[0][7]= $this->input[userForm];
        $userInfo[0][8]= $this->input[userQq];
        $userInfo[0][9]= $this->input[userMsn];
        $userInfo[0][10]= $this->input[userIcq];
        //将输入的时间格式化
        $userTimeNews = explode(" ",$this->input[userTime]);
        $userTimeNews_1=explode("-",$userTimeNews[0]);
        $userTimeNews_2=explode(":",$userTimeNews[1]);
        $userTimeNew=mktime($userTimeNews_2[0],$userTimeNews_2[1],$userTimeNews_2[2],$userTimeNews_1[1],$userTimeNews_1[2],$userTimeNews_1[0]);

		$userLastTimeNews = explode(" ",$this->input[userLastTime]);
        $userLastTime_1=explode("-",$userLastTimeNews[0]);
        $userLastTime_2=explode(":",$userLastTimeNews[1]);
        $userLastTimeNew=mktime($userLastTime_2[0],$userLastTime_2[1],$userLastTime_2[2],$userLastTime_1[1],$userLastTime_1[2],$userLastTime_1[0]);

        $userPostTimeNews = explode(" ",$this->input[userPostTime]);
        $userPostTime_1=explode("-",$userPostTimeNews[0]);
        $userPostTime_2=explode(":",$userPostTimeNews[1]);
        $userPostTimeNew=mktime($userPostTime_2[0],$userPostTime_2[1],$userPostTime_2[2],$userPostTime_1[1],$userPostTime_1[2],$userPostTime_1[0]);

        //
		$userInfo[0][11]= $userTimeNew;
        $userInfo[0][12]= $userLastTimeNew;
        $userInfo[0][22]= $userPostTimeNew;

        //
        $userInfo[0][15]= $this->input[userSign];
        $userInfo[0][4]= $this->input[userGroup];
        $userInfo[0][16]= $this->input[userGroupName];
        $userInfo[0][17]= $this->input[userGroupPic];
        //////
        $userInfo[0][13]= $this->input[userPostAll];
        $userInfo[0][18]= $this->input[userGrade];
        $userInfo[0][19]= $this->input[userPostForum];
        $userInfo[0][20]= $this->input[userPostId];
        $userInfo[0][21]= $this->input[userPostTopic];
        $userInfo[0][23]= $this->input[memberTitle];
        ///////
		if($this->input[usericon]) {
			$userInfo[0][14] = $this->input[usericon];
		}
		$userInfo[0][33]= $this->input[oldIntroduce];
		$userInfo[0][26]= $this->input[gender];
		$userInfo[0][27]= $this->input[userBirthday];
		$userInfo[0][34]= $this->input[userMoney];
		$userInfo[0][35]= $this->input[faceDesign];
		$userInfo[0][36]= $this->input[userPicUp];
		$userInfo[0][37]= $this->input[faceMode];


        $userInfo[0] = $this->adminSafeChars($userInfo[0]);
        $this->file ="../".$this->set[dataPath]."/users/".$this->input['userId'].".php";
        $this->update("1",$this->input['userId'],$userInfo[0]);
        $this->adminShowMsg("./main.php?mod=user&action=showAll","您已经成功修改该会员信息");
    }

//=============================================================================
//删除一个选中会员
    function delUser()
    {
        //删除会员列表中的记录
        $this->file = "../".$this->set[dataPath]."/users/list.php";
        $this->delete("1",$this->input['id']);
        //会员文件
    	if (file_exists("../".$this->set[dataPath]."/users/".$this->input['id'].".php")) {
            unlink("../".$this->set[dataPath]."/users/".$this->input['id'].".php");
        }

    	if (file_exists("../".$this->set[dataPath]."/users/".$this->input['id']."old.php")) {
            unlink("../".$this->set[dataPath]."/users/".$this->input['id']."old.php");
        }
    	if (file_exists("../".$this->set[dataPath]."/users/".$this->input['id']."new.php")) {
            unlink("../".$this->set[dataPath]."/users/".$this->input['id']."new.php");
        }
    	if (file_exists("../".$this->set[dataPath]."/users/".$this->input['id']."read.php")) {
            unlink("../".$this->set[dataPath]."/users/".$this->input['id']."read.php");
        }
        $this->file ="../".$this->set[dataPath]."/member.php";
        $line = $this->get();
        $line[2]--;
        $this->overwrite($line);

        $this->adminShowMsg("./main.php?mod=user&action=showAll","您已经成功删除该注册会员");
    }



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