Location: PHPKode > projects > @1 File Store > libs/user.php
<?
class User
{
 var $userlevel;
 var $userid;
 var $user_data;
 function User()
 {
  	$this->userlevel=4096;
  	$this->user_data=array();
 }
 function identy($mysql)
 {
  	if(trim($this->userid))
  		return true;//ïðîâåðêà ñðàçó ïîñëå àâòîðèçàöèè
  	if(isset($_SESSION["user_id"]) && strlen($_SESSION["user_id"])>0)
	{
	  	$this->userid=$_SESSION["user_id"];
  		$mysql->query("SELECT * FROM ".DB_PREFIX."users WHERE id=".$this->userid);
  		if($mysql->num>0 && $mysql->errno==0)
	  	{
  			$this->userlevel=$mysql->field("level");
  			$this->user_data["login"]=$mysql->field("login");
	  		$this->user_data["email"]=$mysql->field("email");
	  		$this->user_data["confirm"]=$mysql->field("confirm");
	  		$this->user_data["allow_upload"]=$mysql->field("allow_upload");
  		}else
	  	 {
  		 	$this->failed();
  	 		return false;
	  	 }
	  }else
	   {
   		$this->failed();
	   	return false;
	   }
       return true;

 }
 function authorize($mysql, $login, $password)
 {
  	$login=AddSlashes(trim($login));
  	$password=AddSlashes(trim($password));
  	$SQL="SELECT * FROM ".DB_PREFIX."users WHERE login='".$login."' AND password='".$password."'";
  	$mysql->query($SQL);
  	if($mysql->num>0 && $mysql->errno==0)
  	{
  	 	$this->userid=$mysql->field("id");
  	 	$_SESSION["user_id"]=$this->userid;
  	 	$this->userlevel=$mysql->field("level");
		$this->user_data["login"]=$mysql->field("login");
		$this->user_data["email"]=$mysql->field("email");
		$this->user_data["confirm"]=$mysql->field("confirm");
  		$this->user_data["allow_upload"]=$mysql->field("allow_upload");
		return true;
  	}else
  	 {
  	 	$this->failed();
  	 	return false;
  	 }
 }
 function failed()
 {
 	
 	$_SESSION["user_id"]="";
 	$this->userlevel=4096;
 	$this->userid="";
 	$this->user_data=array();
 }
 function getlevel()
 {
 	return $this->userlevel;
 }
 function getaccess()
 {
 	if($this->user_data["confirm"]=="N")
 		return 0;
	switch($this->getlevel())
	{
	 case -2:
	 	return 0;
	 case -1:
	 	return 4; //admin
	 case  0:
	 	return 2; //sub admin
	 default:
	 	return 1;
	}
	return 0;
 }
 function getinfo()
 {
 	if(count($this->user_data)==0) 
 		return "not registred";
 	$STR=$this->user_data["login"];
 	return $STR;
 }

 function can_upload()
 {
  if($this->user_data["allow_upload"]=="Y")
  {
   return true;
  }
  return false;
 }
 function getemail()
 {
 	return $this->user_data["email"];
 }
 function getid()
 {
 	return $this->userid;
 }
}
?>
Return current item: @1 File Store