<?php
/*
\* ===========================================
\* 项目: CTB文本论坛
\* 版本: 1.3
\* 团队: 实易数码
\* 小组: CTB文本论坛小组
\* 作者: windnets，16hot，险情
\* 功能: 用户模块
\* ===========================================
\* Copyright (c) 2002 
\* 团队主页: http://www.16hot.com
\* 团队信箱: --------------------
\* 创建日期: 2002.6
\* 修改日期: 2003-4-10
\* 修改说明: 代码整理/优化
\* 版权声明: 这个程序是免费软件.
\* ===========================================
*/


class Module extends CommonClass
{
    
    /**
     *构造函数
     *
     */
    function execute()
    {
        switch ($this->input['action']) {
            case "writereg":
                $this->writeRegister();
                break;
            case "emailRegister":
                $this->emailRegister();
                break;
            case "login":
            	$this->showLogin();
            	break;
            case "logined":
            	$this->logined();
            	break;
            case "logout":
            	$this->logout();
            	break;
            case "list":
            	$this->memberList();
            	break;
            case "profile":
            	$this->showProfile();
            	break;
            case "modPass":
            	$this->modifyPass();
            	break;
            case "modProfile":
            	$this->moddifyProfile();
            	break;
            case "info":
            	$this->showInfo();
            	break;
            case "sentUser":
            	$this->sentUser();
            	break;
            case "doSent":
            	$this->doSent();
            	break;
            case "getPassWord":
            	$this->getPassWord();
            	break;
            case "sentPassWord":
            	$this->sentPassWord();
            	break;
            case "seeuserface":
            	$this->seeUserFace();
            	break;
            case "seeUserTopic":
            	$this->seeUserTopic();
            	break;
            default:
                $this->showRegister();
                break;
        }
    } // end func

	
	/**
	 *显示注册界面
	 *2002-4-26
	 */
	function showRegister()
	{
		if ($this->set[allowRegister] == "N") {
		   $this->showmsg("本论坛现在已经临时停止注册新用户。","./index.php");
		}
		$registerTime = time();
		if ($registerTime-$HTTP_COOKIE_VARS['last_register'] < $this->set['registerLimitTime']){
            $this->showmsg("管理员已经限制了同一ip注册用户时间，请耐心等待。","./index.php");
		}
		if ($this->set['registerSentPass'] == "Y" and $this->set['registerEmailSubmit'] == "email"){
            $registerMode = "注册用户需要进行邮件确认，以便击活帐户。";
		}
		elseif ($this->set['registerSentPass'] == "Y" and $this->set['registerEmailSubmit'] == "admin"){
            $registerMode = "注册用户需要管理员进行检验通过。";
		}
		else {
            $registerMode = "注册用户注册后马上生效。";
		}
		//
        $this->BAN = " &gt; 用户注册";
		$header = $this->header("用户注册");
		eval("\$this->outPut(\"".$this->getTemplate("register")."\");");
	} // end func
	

	
	/**
	 *写入用户注册信息
	 *2002-4-26
	 */
	function writeRegister()
	{        
		$this->file = $this->set[dataPath]."/users/list.php";
		if (!$this->input['ulogin'] || !$this->input['uname'] || !$this->input['upass'] || !$this->input['upass2'] || !$this->input['umail']) {
		    $this->showMsg("请输入必填的信息");
		} elseif ($this->input['upass'] != $this->input['upass2']) {
		    $this->showMsg("前后密码不一致!");
		} elseif (!$this->checkEmail($this->input['umail'])){
		    $this->showMsg("您的信箱地址不合法!");
		
		//
		} elseif ($this->select_line(2, $this->input['ulogin'])) {
		    $this->showMsg("您输入的登陆ID已经有人使用!");
		} elseif ($this->select_line(4, $this->input['uname'])) {
		    $this->showMsg("您输入的用户名已经有人使用!");
		} elseif ($this->checkRegister() == "4") {
		    $this->showMsg("您输入的信箱已经有人使用!");
		//
		} elseif ( (ereg("&nbsp;",$this->input['ulogin'])) || ( ereg("<",$this->input['ulogin'])) || (ereg(">",$this->input['ulogin'])) || (ereg("^ ",$this->input['ulogin'])) || (ereg(" $",$this->input['ulogin'])) ) {
		    $this->showMsg("您输入的登录名非法!");
		} elseif ( (ereg("&nbsp;",$this->input['uname'])) || ( ereg("<",$this->input['uname'])) || (ereg(">",$this->input['uname'])) || (ereg("^ ",$this->input['uname'])) || (ereg(" $",$this->input['uname'])) ) {
		    $this->showMsg("您输入的显示名非法!");
		} elseif (strlen($this->input['uname']) > 16) { 
			$this->showMsg("您填写的显示名字太长了"); 
		}

		$this->file = $this->set[dataPath]."/bluser.php";
		$holdUser = $this->get();
		for ($i=0;$i<count($holdUser);$i++){
            if ($holdUser[$i] == $this->input['uname']){
                $this->showMsg("此用户名被禁止使用，请更换一个"); 
            }
		}
			$userMd5Pass = md5($this->input['upass']);
			$userLoginName = $this->safeChars($this->input['ulogin']);
            $userShowName = $this->safeChars($this->input['uname']);
            $userShowEmail = $this->safeChars($this->input['umail']);
        if ($this->set[registerSentPass] == "N") {
			$this->file = $this->set[dataPath]."/member.php";
			$user = $this->get();
			$user[2] = $user[2]+1;			
			$user[3] = $user[3]+1;				
			$userId = $user[3];		
			$user[4] = $this->input['uname'];
			$this->overwrite($user);
			@chmod($this->file,0777);
			
			$this->file = $this->set[dataPath]."/users/list.php";
			$userList = array(stripslashes($this->code),$userId,$userLoginName,$userMd5Pass,$userShowName,"1","");
			$this->add_line($userList);
			@chmod($this->file,0777);
			
			$this->file = $this->set[dataPath]."/users/".$userId.".php";
			$member = array(stripslashes($this->code),$userId,$userLoginName,$userShowName,"2",$userShowEmail,"","","","","",time(),time(),"0","no_portait.gif","","新手上路","pips1.gif","0","","","","","","","");
			$this->add_line($member);
			@chmod($this->file,0777);
		}else{
			$this->file = $this->set[dataPath]."/users/listtemp.php";
            if ($this->select_line(1, $this->input['ulogin'])){
                $this->showMsg("您输入的登陆名已经有人使用!");
			}
            if ($this->select_line(2, $this->input['uname'])){
                $this->showMsg("您输入的显示名已经有人使用!");
			}
            if ($this->select_line(4, $this->input['umail'])){
                $this->showMsg("您输入的信箱已经有人使用!");
			} 
			$emailSubmitPass = rand(100000,999999);
			$emailTime = time();
			$this->file = $this->set[dataPath]."/users/listtemp.php";
			$userList = array(stripslashes($this->code),$userLoginName,$userShowName,$userMd5Pass,$userShowEmail,$userLoginName.$emailSubmitPass,$emailTime,"");
			$this->add_line($userList);
			@chmod($this->file,0777);
			if ($this->set[registerEmailSubmit] == "email") {
				$subject = "您在 ".$this->set['ctbTitle']." 的注册确认信";
				$message = "您已经成功注册为{$this->set['ctbTitle']}的会员；下面是您的密码；\n{$this->input['upass']			}\n请点击下面的地址进行确认，以便击活您的帐户；\n{$this->set['webPath']}/index.php?mods=member&action=emailRegister&emailPass=$userLoginName$emailSubmitPass\n\n";
				$msg = "亲爱的{$this->input['uname']} 您好！\n______________________________________________\n\n".    $message;
				$emailFrom = $this->set['ctbTitle']."的邮件<".$this->set['emailAdmin'].">";
				$this->sendSmallEmail($userShowEmail,$subject, $msg,"text",$emailFrom);
            $this->showMsg("谢谢您的注册,一封确认信已经发送到您的信箱，请进行确认以便击活您的帐号!","./index.php");
			}
			else 
            $this->showMsg("谢谢您的注册,请耐心等待管理员的确认!","./index.php");

		}
		$registerTime = time();
		$registerTimeLimit = $registerTime+3153600;
		if($this->set[registerLimitIp] == "Y") {
			setCookie('last_register', $registerTime, $registerTimeLimit);
		}
		$this->showMsg("谢谢您的注册!","./index.php?mods=member&action=login");
	} // end func

	/**
	 *邮件注册确认函数
	 *2002-12-26
	 */
	function emailRegister()
	{
		$this->file = $this->set[dataPath]."/users/listtemp.php";
        $userEmailInfo = $this->select_line(5, $this->input['emailPass']);
		if (!$userEmailInfo){
			$this->showMsg("此用户资料不存在!","./index.php");
		}
			$this->file = $this->set[dataPath]."/member.php";
			$user = $this->get();
			$user[2] = $user[2]+1;		
			$user[3] = $user[3]+1;				
			$userId = $user[3];		
			$user[4] = $userEmailInfo[2];
			$this->overwrite($user);
			@chmod($this->file,0777);
			
			$this->file = $this->set[dataPath]."/users/list.php";
			$userList = array(stripslashes($this->code),$userId,$userEmailInfo[1],$userEmailInfo[3],$userEmailInfo[2],"1","");
			$this->add_line($userList);
			@chmod($this->file,0777);
			
			$this->file = $this->set[dataPath]."/users/".$userId.".php";
			$member = array(stripslashes($this->code),$userId,$userEmailInfo[1],$userEmailInfo[2],"2",$userEmailInfo[4],"","","","","",time(),time(),"0","no_portait.gif","","新手上路","pips1.gif","0","","","","","","","");
			$this->add_line($member);
			@chmod($this->file,0777);
	 $this->file = $this->set[dataPath]."/users/listtemp.php";
	 $this->delete2(5,$this->input['emailPass']);	$this->showMsg("您的注册信息已经成功通过了确认，请您登陆!","./index.php?mods=member&action=login");
	} // end func	
	
	/**
	 *显示登陆界面
	 *2002-4-26
	 */
	function showLogin()
	{
		$this_input_jump_back = $this->input['jump_back'];
		if ($_SERVER['HTTP_REFERER']) {
			$jump_back = $_SERVER['HTTP_REFERER'];
		} elseif ($this->input['jump_back']) {
			$jump_back = str_replace('~~~~', '&', str_replace('^^^^', '=', $this->input['jump_back']));
		}
        $this->BAN = " &gt; 用户登陆";
		$header = $this->header("用户登陆");

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

	
	/**
	 *登陆
	 *2002-4-26
	 *2002-4-29修改
	 */
	function logined()
	{
		if (!$this->input['ulogon'] || !$this->input['upass']) {
			unset($this->input['jump_back']);
		    $this->showMsg("请填写您的登录名和密码!");
		} elseif ( (ereg("&nbsp;",$this->input['ulogon'])) || ( ereg("<",$this->input['ulogon'])) || (ereg(">",$this->input['ulogon'])) || (ereg("^ ",$this->input['ulogon'])) || (ereg(" $",$this->input['ulogon'])) ) {
			unset($this->input['jump_back']);
		    $this->showMsg("非法登录名!");
		}

		$this->file = $this->set[dataPath]."/users/list.php";
		$check = $this->select_line("2",addslashes($this->input['ulogon']));
			
		if ($check == 0) {
			unset($this->input['jump_back']);
			$this->userLoginLog($this->input['ulogon']."->输入了非法的登陆名");
		    $this->showMsg("对不起，您输入的登录名不存在!");
		} elseif ($check[3] == md5($this->input['upass'])) {
   			$this->file = $this->set[dataPath]."/users/".$check[1].".php";
			$thisMember = $this->get();
   			$_SESSION['sess_uid'] = $check[1];
			$_SESSION['sess_ulogin'] = $check[2];
			$_SESSION['sess_upass'] = md5($this->input['upass']);
			$_SESSION['sess_uname'] = $thisMember[3];
			$_SESSION['sess_ugrade'] = $thisMember[4];
			$_SESSION['sess_last_login'] = $thisMember[12];
			$_SESSION['sess_limit_user'] = $check[5];
			$_SESSION['sess_login_mode'] = $this->input['loginMode'];
			$thisMember[12] = time();
			$this->overwrite($thisMember);

			$this->file = $this->set[dataPath]."/online.php";
			$this->delete2('1',getenv("REMOTE_ADDR"));

			if (isset($this->input['jump_back'])) {
				$this->userLoginLog();
				$this->showMsg("谢谢 {$thisMember[3]} 登陆，欢迎您的回来!",$this->input['jump_back']);
			} elseif (isset($this->sess['sess_url'])) {
				$this->userLoginLog();
				$this->showMsg("谢谢 {$thisMember[3]} 登陆，欢迎您的回来!",$this->sess['sess_url']);
			} else {
				$this->userLoginLog();

				$this->showMsg("谢谢 {$thisMember[3]} 登陆，欢迎您的回来!","./index.php");
			}
		} else {
			$this->userLoginLog($this->input['ulogon']."->输入了非法的密码：".$this->input['upass']);
			unset($this->input['jump_back']);  // added by cx
			$this->showMsg("对不起，您输入的密码错误!");
		}
			
	} // end func

	
	/**
	 *退出登陆
	 *2002-4-30
	 */
	function logout()
	{
        if ($_SESSION['sess_uid']) { 
	        $this->file = $this->set[dataPath]."/online.php";
			$this->delete2("1",$this->sess['sess_uid']);
			$this->file = $this->set[dataPath]."/users/".$this->sess['sess_uid'].".php";
			$thisMember = $this->get();
			$thisMember[12] = time();
			$this->overwrite($thisMember);

			session_unset();
			session_destroy();
			$this->showMsg("已经清空您的登陆记录!","./index.php");
		}else {
		    $this->showMsg("您还没有登陆呢!");
		}
	} // end func

	
	/**
	 *检查用户名和信箱
	 *2002-4-29
	 */
	function checkRegister()
	{
		$this->file = $this->set[dataPath]."/member.php";
		$userNum = $this->get();
		for ($i=1;$i<=$userNum[3];$i++ ) {
			$this->file = $this->set[dataPath]."/users/".$i.".php";
			if (file_exists($this->file)) {
			    $check = $this->get();
				if ($check[2] == $this->input['ulogin']) {
				    return 2;
					break;
				}
				if ($check[3] == $this->input['uname']) {
				    return 3;
					break;
				}
				if ($check[5] == $this->input['umail']) {
				    return 4;
					break;
				}
			}
		}
		return 1;
	} // end func



	/**
	 *显示用户列表
	 *2002-5-6
	 */
	function memberList()
	{
        $this->BAN = " &gt; 用户列表";
		$header = $this->header("用户列表");
        if($this->input['orderby']!="regtime" && $this->input['orderby'] && $this->input['orderby']!="showAdmin" && $this->input['orderby']!="showOnline"){
            if($this->input['orderby']=="posts"){
				$this->openLimit();
                $listLine  = $this->orderUser(13) ;
			    $showMgs=">按照发帖排序";
			}
		    if($this->input['orderby']=="rate"){
				$this->openLimit();
                $listLine  = $this->orderUser(18) ;
			    $showMgs=">按照评分排序";
			}
		}
		elseif ($this->input['orderby']=="showAdmin") {
		$this->openLimit();
	    $listLine = $this->showAdmin();
		$showMgs=">显示论坛管理团队";

		}
		elseif ($this->input['orderby']=="showOnline") {
        $this->openLimit();
	    $listLine = $this->showOnline();	
		$showMgs=">显示论坛在线会员";
		}
		elseif($this->input['searchUserKey']){
            $listLine = $this->newSearchUser($this->input['searchUserKey'],$this->input['searchMode']);
		    $show_mgs="快速定位到单个会员";
		}
		else{
            $this->file = $this->set[dataPath]."/users/list.php";
            $listLine = $this->read_file();
		}
		$totalFile = count($listLine);
		if ($this->input['shumu'] and $this->input['shumu']<250) {
            $recnum = $this->input['shumu'];
        }else {
            $recnum = $this->set[userList];
        }
        $listNum = $this->set[userPage];
		$totalNum = ($totalFile % $recnum) == "0" ? intval(($totalFile)/$recnum) : intval(($totalFile)/$recnum)+1;

        $p = $this->input['p'];
		if ( !$p ) { $p = 1; } 
		for( $i = ($totalFile - ($p-1)*$recnum); $i > ($totalFile - $p*$recnum);$i--) { 
			$getUserId = $this->make_array($listLine[$i]);
			$num = $i+1;
			$this->file = $this->set[dataPath]."/users/".$getUserId[1].".php";
			if (file_exists($this->file)) {
			    $memberInfo = $this->get();
				$memberName = htmlspecialchars(stripslashes($memberInfo[3]));
				$memberHomePage = htmlspecialchars(stripslashes($memberInfo[6]));
				if (!empty($memberHomePage)) {
					$memberHomePage = "<a href=".$memberHomePage." target='_blank'><img src='{$this->tplPath}/images/system/home.gif' border=0></a>";
				} else {
					$memberHomePage = "没有";
				}
				$memberRegisterTime = date($this->set[dateformat],$memberInfo[11]);
				$id = $memberInfo[1];
				$memberPostNum = $memberInfo[13];
				$memberGrade = $memberInfo[18];
				if (!trim($memberGrade)) {
    				$memberGrade = "0";
                }
				$memberMgs = "<a href='./index.php?mods=usermgs&action=sentmgs_htm&mgsSentTo=$memberName' target='_blank'><img src='{$this->tplPath}/images/system/userlist_message.gif' border=0></a>";
                
				$memberLever = $memberInfo[16]; 
				eval ("\$memberList .= \"".$this->getTemplate("memberListBit")."\";");
			}
		}
		$page = $this->getPage("./index.php?mods={$this->input['mods']}&action=list&orderby={$this->input['orderby']}",$totalNum);

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


	
	/**
	 *显示用户档案界面
	 *2002-5-7
	 *create by 16hotcom
	 */
	function showProfile()
	{
		if (!$this->sess['sess_uid'] || !$this->sess['sess_uname'] || !$this->sess['sess_upass']) {
		    $this->showMsg("注册用户才可以修改，请先登陆/注册!","index.php?mods=member&action=login");
		}		

        $this->BAN = " &gt; 用户档案";
		$header = $this->header("用户档案");
		$this->file = $this->set[dataPath]."/users/".$this->sess['sess_uid'].".php";
		$userInfo = $this->get();
		$oldMail = $userInfo[5];
		$oldHome = $userInfo[6];
		$oldLocal = $userInfo[7];
		$oldQQ = $userInfo[8];
		$oldMsn = $userInfo[9];
		$oldIcq = $userInfo[10];
		$oldSig = str_replace("<br>","\n",stripslashes($userInfo[15]));
		if (empty($userInfo[14])) {
			$oldtx = "";     
		} else {
			$postFaceInfo = explode("|",$userInfo[14]);
			$oldtx = $postFaceInfo[0];
		}
		if ($postFaceInfo[2] == "1"){
			$faceModeChecked_0 = "";
			$faceModeChecked_1 = "checked";
		}
		else {
			$faceModeChecked_0 = "checked";
			$faceModeChecked_1 = "";
		}
		if (empty($postFaceInfo[1]))
            $showMyFace = "<IFRAME frameBorder=0 height=40 name=ad scrolling=no src=\"{$this->tplPath}/uploadFace.htm\" width=400>";
		else 
            $showMyFace = "<IFRAME frameBorder=0 height=40 name=ad scrolling=no src=\"{$this->tplPath}/uploadFaceAfter.htm\" width=400>";
        //        
        $faceDir = opendir($this->tplPath."/images/face");
        while ($imageFile = readdir($faceDir)) {
			if (($imageFile != ".") && ($imageFile != "..") && ($imageFile != "")  &&($imageFile != "xq.jpg")) {
				$userPictrue .= "<option value=".$imageFile.">".$imageFile."</option>\n";
			}
		}
        closedir($faceDir);
		$uploadFaceLimit = $this->set[uploadPhotoSize]/1000;
		//<<
		eval("\$this->outPut(\"".$this->getTemplate("memberProfile")."\");");
	    
	} // end func


	
	/**
	 *修改密码
	 *2002-5-7
	 *16hotcom
	 */
	function modifyPass()
	{
		if (!$this->sess['sess_uid'] || !$this->sess['sess_uname'] || !$this->sess['sess_upass']) {
		    $this->showMsg("注册用户才可以修改，请先登陆/注册!","index.php?mods=member&action=login");
		}		
		if (!trim($this->input['oldPass'])) {
		    $this->showMsg("请输入您的旧密码!");
		} elseif (!trim($this->input['newPass']) || !trim($this->input['newPass2'])) {
		    $this->showMsg("请输入您的新密码!");
		} elseif ($this->input['newPass'] != $this->input['newPass2']) {
		    $this->showMsg("您输入的新密码前后不一致!");
		}

		$this->file = $this->set[dataPath]."/users/list.php";
		$pass = $this->select_line("1",$this->sess['sess_uid']);
		if (md5($this->input['oldPass']) != $pass[3]) {
		    $this->showMsg("您输入的旧密码正确!");
		}
		$pass[3] = md5($this->input['newPass']);
		$this->update2("1",$this->sess['sess_uid'],$pass);
        @chmod($this->file,0777);
		$this->showMsg("修改密码完成,请重新登陆并且记住您的新密码!","./index.php?mods=member&action=login");
		
	} // end func


	/**
	 *修改用户资料
	 *2002-5-7
	 *create by 16hotcom
	 */
	function moddifyProfile()
	{
		if (!$this->sess['sess_uid'] || !$this->sess['sess_uname'] || !$this->sess['sess_upass']) {
		    $this->showMsg("注册用户才可以修改，请先登陆/注册!","index.php?mods=member&action=login");
		}		

		if (!trim($this->input['umail'])) {
		    $this->showMsg("请输入您的信箱地址!");
		} elseif (!$this->checkEmail($this->input['umail'])){
		    $this->showMsg("您的信箱地址不合法!");
		} 
		
		$this->file = $this->set[dataPath]."/users/".$this->sess['sess_uid'].".php";
		$userInfo = $this->get();
		$userInfo[5] = $this->safeChars($this->input['umail']);
		$userInfo[6] = $this->safeChars($this->input['uhome']);
		$userInfo[7] = $this->safeChars($this->input['ulocal']);
		$userInfo[8] = $this->safeChars($this->input['uqq']);
		$userInfo[9] = $this->safeChars($this->input['umsn']);
		$userInfo[10] = $this->safeChars($this->input['uicq']);
		$userInfo[15] = $this->safeChars($this->input['signature']);
		$userInfo[15] = $this->set[replaceWhenPost] == 'Y' ? $this->replaceBadWord($userInfo[15]) : $userInfo[15];
		
		$userFaceInfo = explode("|",$userInfo[14]);
		if (trim($this->input['userIcon'])){
            $userFaceInfo[0] = $this->input['userIcon']; 
        }
        $userFaceInfo[2] = $this->input['faceMode']; 
		$userInfo[14] = implode("|",$userFaceInfo);
		
		$this->overwrite($userInfo);
        @chmod($this->file,0777);
	    $this->showMsg("修改资料完成!","./index.php"); //?mods=member&action=profile");  changed by cx
	} // end func


	
	/**
	 *显示用户资料
	 *2002-5-8
	 * by 16hotcom
	 */
	function showInfo()
	{
		$this->file = $this->set[dataPath]."/users/".$this->input['id'].".php";

		if (!file_exists($this->file)) {
		    $this->showMsg("对不起，这个用户的资料不存在!");
		}
		$userInfo = $this->get();
		$memberName = htmlspecialchars(stripslashes($userInfo[3]));
		$memberHome = $userInfo[6];
		$memberLocal = $userInfo[7];
		$memberQQ = $userInfo[8];
		$memberMsn = $userInfo[9];
		$memberIcq = $userInfo[10];
		$memberrTime = date($this->set[dateformat],$userInfo[11]);
		$memberPostNumber = $userInfo[13];
	    $memberLastVisit = date($this->set[dateformat],$userInfo[12]);
	    $memberGrade = $userInfo[16];
	    $memberReview = $userInfo[18];
		if ($userInfo[20] == "") {
		    $memberpost = "未发表过任何帖子";
			$memberPostTime = "未知";
		} else {
			$userInfo[21] = $this->set[replaceWhenPost] == 'Y' ? $userInfo[21] : $this->replaceBadWord($userInfo[21]);
			$memberLastPost = "<a href='./index.php?mods=topicdisplay&forumid=".$userInfo[19]."&postid=".$userInfo[20]."' target=blank>".$userInfo[21]."</a>";
			$memberPostTime = date($this->set[dateformat],$userInfo[22]);
		}		
		if (empty($userInfo[14])) {
			$memberFace = "{$this->tplPath}/images/face/no_portait.gif";     
		} else {
				$postFaceInfo = explode("|",$userInfo[14]);
				if ($postFaceInfo[2] == "1"){
					$memberFace = $this->set[dataPath]."/upface/".$postFaceInfo[1];
				}
				else 
					$memberFace = "{$this->tplPath}/images/face/".$postFaceInfo[0];
		}
		$oldSig = str_replace("<br />","\n",stripslashes($userInfo[15]));  
		$oldSig = str_replace("<br>","\n",stripslashes($oldSig));          
		$oldSig = str_replace("&lt;", "<", $oldSig);                       
		$oldSig = str_replace("&gt;", ">", $oldSig);
		$oldSig = str_replace("&amp;", "&", $oldSig);
		$oldSig = str_replace("</textarea", "&lt;/textarea", $oldSig); 	
		$memberTitle = $userInfo[23];
		        $this->BAN = " &gt; <a href=\"./index.php?mods=member&action=list\">用户资料</a>&gt; $memberName";
		$header = $this->header("用户资料");

		eval("\$this->outPut(\"".$this->getTemplate("memberInfo")."\");");

	} // end func

	/**
	 *显示用户的自定义头像
	 *2002-12-26
	 */
	function seeUserFace()
	{
		$this->file = $this->set[dataPath]."/users/".$this->sess['sess_uid'].".php";

		if (!file_exists($this->file)) {
		    $this->showMsg("对不起，这个用户的资料不存在!");
		}
		$userInfo = $this->get();
		if (empty($userInfo[14])) {
			$memberFace = "{$this->tplPath}/images/face/no_portait.gif";     
		} else {
				$postFaceInfo = explode("|",$userInfo[14]);
				if ($postFaceInfo[2] == "1"){
					$memberFace = $this->set[dataPath]."/upface/".$postFaceInfo[1];
				}
				else 
					$memberFace = "{$this->tplPath}/images/face/".$postFaceInfo[0];
		}
        header("location:$memberFace");  
	}//end func 
    /**
     *将用户排序
     *2002-8-26
     */
	function orderUser($columnSort){

        $this->file = $this->set[dataPath]."/users/list.php";
        $lines = file($this->file);
        for ($i=0;$i<=count($lines);$i++) {
            $getUserId = explode("\x0E",$lines[$i]);
		    $this->file = $this->set[dataPath]."/users/".$getUserId[1].".php";
			if (file_exists($this->file)) {
                $getUserOrder = $this->get();
                $linesOrder[$lines[$i]] = $getUserOrder[$columnSort];
		    }
        }
        @asort($linesOrder);
        @reset($linesOrder);

        for ($j=0; $j<count($linesOrder); $j++) {
            $listLine[] = key($linesOrder);
            next($linesOrder);
        }
        return $listLine;
	}//end function

	/**
	 *只显示管理员用户
	 *2002-8-26
	 */
		function showAdmin(){

		   $this->file = $this->set[dataPath]."/users/list.php";
		   $tlines = file($this->file);
		   for ($i=0;$i<=count($tlines);$i++) {
			    $getUserId = explode("\x0E",$tlines[$i]);
		        $this->file = $this->set[dataPath]."/users/".$getUserId[1].".php";
				if (file_exists($this->file)) {
		        $getUserOrder = $this->get();
				    if ($getUserOrder[4]=="1" or $getUserOrder[4]=="3") {
			        $linesOrder[$tlines[$i]] = $getUserOrder[4];				        
				    }

		       }
		   }
		   @arsort($linesOrder);
		   @reset($linesOrder);

		   for ($j=0; $j<count($linesOrder); $j++) {
               $listLine[]=key($linesOrder);
               next($linesOrder);
			    }
		  return $listLine;
		}//end function

	/**
	 *只显示在线用户
	 *2002-8-26
	 */
		function showOnline(){

		   $this->file = $this->set[dataPath]."/online.php";
		   $tlines = file($this->file);
		   for ($i=0;$i<count($tlines);$i++) {
			    $getUserId = explode("\x0E",$tlines[$i]);
				if ($getUserId[2]!="0") {
                $listLine[] = "<?die();?>\x0E".$getUserId[1];				    
				}
		   }
		  return $listLine;
		}//end function

	/**
	 *用户搜索
	 *2002-8-26
	 */
    function newSearchUser($searchUserKey,$searchMode) {
	  
        $this->file = $this->set[dataPath]."/users/list.php";
	    $userCode = $this->read_file();
		for ($i=0;$i<count($userCode);$i++) {
            $userLine = explode("\x0E",$userCode[$i]);
			if ($searchMode == "1"){
				if($searchUserKey == $userLine[4]) {
				$this->file = $this->set[dataPath]."/users/".$userLine[1].".php";
				$userInfo = $this->read_file();
				$listLine[] = $userCode[$i];
			    }
			}
			elseif ($searchMode == "0"){
				if(eregi($searchUserKey, $userLine[4])) {
				$this->file = $this->set[dataPath]."/users/".$userLine[1].".php";
				$userInfo = $this->read_file();
				$listLine[] = $userCode[$i];
			    }
			}
		}
		return $listLine;
    } //end func

	function sentUser()
	{
		if (!$this->sess['sess_uid'] || !$this->sess['sess_uname'] || !$this->sess['sess_upass']) {
		    $this->showMsg("注册用户才可以发送，请先登陆/注册!","index.php?mods=member&action=login");
		}		

		$this->file = $this->set[dataPath]."/users/".$this->input['id'].".php";

		if (!file_exists($this->file)) {
		    $this->showMsg("对不起，这个用户的资料不存在!");
		}
		$userInfo = $this->get();
		$memberName = htmlspecialchars(stripslashes($userInfo[3]));

		$emailTopic = $memberName.":你好";
        $emailComment = "\n".$memberName.":\n      你好,";
		//
        $this->BAN = "&gt; <a href=\"./index.php?mods=member&action=list\">用户资料</a>&gt; <a href=\"./index.php?mods=member&action=info&id={$this->input[id]}\">$memberName</a>&gt; 发送邮件";
        $header = $this->header("发送邮件");
        eval("\$this->outPut(\"".$this->getTemplate("sentUser")."\");");
    }
	/**
	 *将文章发送到指定信箱
	 *
	 */
	function doSent()
	{
		if (!$this->sess['sess_uid'] || !$this->sess['sess_uname'] || !$this->sess['sess_upass']) {
		    $this->showMsg("注册用户才可以发送，请先登陆/注册!","index.php?mods=member&action=login");
		}		
		$message;
		if (!$this->input['emailMode'] || !$this->input['subject'] || !$this->input['message']){
		    $this->showMsg("请您将资料填写完整");//,"./index.php?mods=member&action=sent_user&id=$id"
        }
		$this->file = $this->set[dataPath]."/users/".$this->input['id'].".php";
		if (!file_exists($this->file)) {
		    $this->showMsg("对不起，这个用户的资料不存在!");
		}
		$userInfo = $this->get();
		$toMemberName = htmlspecialchars(stripslashes($userInfo[3]));
		$this->file = $this->set[dataPath]."/users/".$this->sess['sess_uid'].".php";
		$sendInfo = $this->get();
		if ($this->set[replaceWhenPost] == 'Y') {
			$$this->input['subject'] = $this->replaceBadWord($$this->input['subject']);
			$$this->input['message'] = $this->replaceBadWord($$this->input['message']);
		}

		$subject = htmlspecialchars($this->input['subject']);
		$emailFrom = $this->sess['sess_uname']."的邮件<".$sendInfo[5].">";
		$this->sendSmallEmail($userInfo[5], $subject, $this->input['message'],$this->input['emailMode'],$emailFrom); //$sendInfo[5]

        $postShowMsg = "您已经成功将文章发送到指定信箱<br><br>
            <li><a href=\"index.php?mods=member&action=info&id={$this->input['id']}\">继续查看资料</a><br>
            </li>
            <li><a href=\"index.php?mods=member&action=list\">返回用户列表</a><br>
            </li>
            <li><a href=\"index.php\">返回论坛首页</a></ul>";
        $this->showMsg($postShowMsg,"./index.php");//?mods=member&action=sent_user&id=$id
          		  
    }
	/**
	 *显示取回密码界面
	 *2002-4-26
	 */
	function getPassWord()
	{
        $this->BAN = " &gt; 取回用户密码";
		$header = $this->header("取回用户密码");

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

	/**
	 *执行发送密码操作
	 *2002-8-26
     *整理说明：这个函数还没有具体整理，还要麻烦老三来整理。2002-12-1 by 16hot
	 */
    function sentPassWord()
	{

		if (!$this->input['ulogin'] || !$this->input['uname']){
		    $this->showMsg("请您将资料填写完整");
        }

		$this->file = $this->set[dataPath]."/users/list.php";
		$userInfo= $this->select_line("2",addslashes($this->input['ulogin']));
        if (!$userInfo[1]) {
            $this->showMsg("不存在此用户");
        }

		$this->file = $this->set[dataPath]."/users/".$userInfo[1].".php";
		$thisMember = $this->get();

		if($this->input['uname'] != $thisMember[3]){
            $this->showMsg("登陆id和显示名称不匹配");
        }
        $newPass = rand(100000,999999);
        $userId = $thisMember[1];
		$this->file = $this->set[dataPath]."/users/list.php";
		$pass = $this->select_line("1",$userId);
		$pass[3] = md5($newPass);
		$this->update2("1",$userId,$pass);
        @chmod($this->file,0777);

        $subject = "您在 ".$this->set['ctbTitle']." 的密码";
		$message = $this->input['uname']."：您在 ".$this->set[ctbTitle]." 的密码为：".$newPass."，请牢记！\n\n";
		$msg = "亲爱的{$this->input['uname']} 您好！\n______________________________________________\n\n".    $message;
		$emailFrom = $this->set['ctbTitle']."的邮件<".$this->set['emailAdmin'].">";
		$this->sendSmallEmail($thisMember[5],$subject, $msg,"text",$emailFrom); //$this->set['ctbTitle'],
        $this->showMsg("您已经成功将密码发送到您的信箱","./index.php");
          		  
    }

	/**
	 *显示用户发表的所有主题
	 *2002-12-26
	 */
	function seeUserTopic()
	{
		if ($this->input['noSessName'])
			$seachName = $this->input['noSessName'];
		else 
            $seachName = $this->sess['sess_uname'];
        $this->BAN = " &gt; <a href=\"./index.php?mods=search&action=search\">文章搜索</a> &gt; 显示 $seachName 的全部主题";
        $header = $this->header("显示 $seachName 的全部主题");
        $this->file = $this->set[dataPath]."/forums.php";
        $forumLines = $this->read_file();
        $optionLine = "";
        foreach ($forumLines as $forumLine) {
            $forum = $this->make_array($forumLine);
            if ($forum[1] == "cat") {
                $optionLine .= "<option value=\"no\">╋".$forum[3]."</option>";
                }
            if ($forum[1] == "forum") {
                $forumid = $forum[2];
                $optionLine .= "<option value=".$forum[2].">　|-".$forum[3]."</option>";

                $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 ($lineInfo[2] == $seachName and $lineInfo[2]!=""){
                    $userAllTopic[]=$lines[$i]."\x0E".$forumid."\x0E".$forum[3];
					}
                }
            }
        }
        $forumList = "<select name='forumid' class='input5' onchange=\"window.location=('./index.php?mods=forumdisplay&forumid='+this.options[this.selectedIndex].value+'');\">".$optionLine."</select>";  // changed by cx
        $totalFile = count($userAllTopic);
		$lines = $this->orderTopic3($userAllTopic,3,$totalFile);

        $recnum = $this->set[topicList];
        $totalNum = ($totalFile % $recnum) == "0" ? intval(($totalFile)/$recnum) : intval(($totalFile)/$recnum)+1;
        $p = $this->input['p'];
        if ( !$p ) { $p = 1; }
        for( $i = ($p-1) * $recnum; $i < $p*$recnum ;$i++) {   
                $forumNew = $this->make_array($lines[$i]);
                if ($forumNew[12] and $forumNew[13]){
                    $forumId = $forumNew[12];
                    $forumName = $forumNew[13];
				}
				else {
				    $forumId = $forumNew[7];
                    $forumName = $forumNew[8];
				}
                $this->file = $this->set[dataPath]."/".$forumId."/".$forumNew[1]."_.php";
                if (file_exists($this->file)) {
                    $line = $this->get();
                    $postTitle = str_replace($this->input['keyword'],"<font color=red>".$this->input['keyword']."</font>",$line[2]);
					$postTitle = $this->set[replaceWhenPost] == 'Y' ? $postTitle : $this->replaceBadWord($postTitle);
                    $id = $line[1];
                    $clickNum = $line[4];
                    $topicNum = $line[3];
                    $reUserName = $line[5];
                    $lastTime = date($this->set[dateformat],$line[6]);
                    $topicPic = $line[7];
                    $forumid = $forumNew[12];
                    $topicAuthor = str_replace($this->input['keyword'],"<font color=red>".$this->input['keyword']."</font>",$forumNew[2]);
                    if (empty($topicPic)) {
                        $topicPic = "smileyface.gif";
                    }
                    if (($this->sesss['sess_last_login'] != "") && ($line[6] > $this->sesss['sess_last_login'])) {
                        $newMode = "<img src='{$this->tplPath}/images/system/newtopic.gif'>";
                    } else {
                        $newMode = "";
                    }
                    if ($topicCode[5] == "1" && $topicCode[4] != "1"){
                        $newFlag = "foldertop.gif";
                    }elseif ($topicCode[4] == "1" && $topicCode[5] == "1"){
                        $newFlag = "folder_lock_top.gif";
                    }elseif ($topicCode[4] == "1" && $topicCode[5] != "1"){
                        $newFlag = "folderlock.gif";
                    }elseif ($topicNum >= 10 && $topicNum <20){
                        $newFlag = "folderhot.gif";
                    }elseif ($topicNum >= 20){
                        $newFlag = "folderhot1.gif";
                    }else{
                        $newFlag = "folder.gif";
                    }

					$countFile = $line[3];
                    $pageNum = ($countFile % $this->set[topicList]) == "0" ? intval(($countFile)/$this->set[topicList]) : intval(($countFile)/$this->set[topicList])+1;
                    if ($pageNum < 2) {
                        $lastPage = "";
                    } else {
                        $lastPage = "&#171; <a href=./index.php?mods=topicdisplay&forumid=$forumid&postid=$id&p=$pageNum>$pageNum</a> &#187;";
                    }
                    eval ("\$postList .= \"".$this->getTemplate("searchPost")."\";");
                }
        }

        $page = $this->getPage("$PHP_SELF?mods=member&action=seeUserTopic&noSessName=$seachName",$totalNum);
        eval("\$this->outPut(\"".$this->getTemplate("seeUserTopic")."\");");
	} // end func

} // end class

?>