<?php 
/**
* @用户信息函数类
*/
class getuser extends hon6mysql {
		public function __construct($path =''){
				parent::mysql_link();
		}
		/**/
		public function getmemberlevel($credits,$type = "title"){
				$credits = isset($credits)?intval($credits):0;
				$this->groupdate = $this->query_object("select honorid,caption,maxscore from ".JIEQI_DB_PREFIX."_system_honors where minscore<=".$credits." and maxscore>".$credits);
					if($type == "title"){
							return $this->groupdate->caption;
					}elseif($type == "level"){
							return $this->groupdate->honorid;
					}elseif($type == "nextlevelscore"){
							if($this->groupdate->maxscore!=0){
									return $this->groupdate->maxscore;
							}else{
									return "MAX";
							}
					}
		}
		public function getmembergroup($groupid,$type = "name"){
				$this->groupdate = $this->query_object("select name,description from ".JIEQI_DB_PREFIX."_system_groups where groupid = ".$groupid);
					if($type == "name"){
							return $this->groupdate->name;
					}elseif($type == "description"){
							return $this->groupdate->description;
					}
		}
		public function getuserdate($date,$uid){
				 $this->sqldate = $this->query_field("select ".$date." from ".JIEQI_DB_PREFIX."_system_users where uid=".$uid);
				 return $this->sqldate;
		}
		public function checklogin($str){
				if($str == "" or $str == 0 or $str == null){
						$url = array(
								"backurl" => urlencode("?".$_SERVER['QUERY_STRING']),
						);
						header("location:".URL_user_login($url));	
				}
		}
		public function getmsg($str){
				if($str == "" or $str == 0){
						return 0;	
				}else{
						$this->msgnum = $this->query_num("select messageid from ".JIEQI_DB_PREFIX."_system_message where isread=0 and toid=".$str);
						return $this->msgnum;
				}
		}
		public function getip(){
				if(@$_SERVER["HTTP_X_FORWARDED_FOR"]){  
						$ip = $_SERVER["HTTP_X_FORWARDED_FOR"];  
				}elseif(@$_SERVER["HTTP_CLIENT_IP"]){  
						$ip = $_SERVER["HTTP_CLIENT_IP"];  
				}elseif(@$_SERVER["REMOTE_ADDR"]){
						$ip = $_SERVER["REMOTE_ADDR"];  
				}elseif(getenv("HTTP_X_FORWARDED_FOR")){  
						$ip = getenv("HTTP_X_FORWARDED_FOR");  
				}elseif(getenv("HTTP_CLIENT_IP")){
						$ip = getenv("HTTP_CLIENT_IP");  
				}elseif(getenv("REMOTE_ADDR")){
						$ip = getenv("REMOTE_ADDR");  
				}else{
						$ip = "Unknown";
				}
				return $ip;  
		}
		public function getuserfile($userid){
				$userid = isset($userid)?intval($userid):0;
				$this->userdir = HON6_ROOT."./user_temp/".$userid."/";
				if(is_dir($this->userdir)){
						if($this->handle = opendir($this->userdir)){
								$this->i = 0;
								/*扫描用户文件个数并返回文件名*/
       					while(($this->file = readdir($this->handle)) !== false){
         						if($this->file!="." && $this->file!=".."){
         								$this->filename = $this->file;
         								$this->i = $this->i + 1;
         						}
       					}
       					if($this->i == 1){
       							/*当用户数据文件为一个时，即正常*/
       							return $this->userdir.$this->filename;
       					}else{
       							/*发现有多个用户数据文件全部删除*/
       							if($this->handles = opendir($this->userdir)){
       									while(($this->files = readdir($this->handles)) !== false){
    												if($this->files!="." && $this->files!=".."){
     														$this->fullpath=$this->userdir.$this->files;
																unlink($this->fullpath);
   													}
  											}
  									}
										return false;
       					}
       					closedir($this->handle);
						}else{
									return false;	
						}
				}else{
						return false;	
				}
		}
}
?>