id=$infoAry['user_id']; $this->fname=$infoAry['first_name']; $this->lname=$infoAry['last_name']; $this->situation=$infoAry['situation']; $this->email=$infoAry['email']; $this->tel=$infoAry['telephone']; $this->mobile=$infoAry['mobile']; $this->group=serialize(new Group($infoAry['grp_id'])); $infoAry=null; } public function get_id(){ return $this->id; } public function get_fname(){ return $this->fname; } public function get_lname(){ return $this->lname; } public function get_situation(){ return $this->situation; } public function get_email(){ return $this->email; } public function get_tel(){ return ($this->tel==null)?'Nil':$this->tel; } public function get_mobile(){ return ($this->mobile==null)?'Nil':$this->mobile; } public function get_group(){ return unserialize($this->group); } public function set_group($id){ return $this->group=serialize(new Group($id)); } public function get_address(){ if($result=dbController::get_user_info($this->id,false,false,true)) return $result['address']; } public function get_all_info(){ return array('id'=>$this->id, 'fname'=>$this->fname, 'lname'=>$this->lname, 'situation'=>$this->situation, 'email'=>$this->email, 'tel'=>$this->tel, 'mobile'=>$this->mobile, 'group'=>$this->group); } public function change_my_info($fname, $lname, $situation, $address, $email, $group, $tel=null, $mobile=null){ $fname=trim($fname); $lname=trim($lname); $situation=trim($situation); $address=trim($address); $email=trim($email); $tel=trim($tel); $mobile=trim($mobile); $group=trim($group); $isFill=(CoreFunc::check_blank($fname))?true:false; $ifFill=($isFill)?CoreFunc::check_blank($lname):false; $ifFill=($isFill)?CoreFunc::check_blank($situation):false; $ifFill=($isFill)?CoreFunc::check_blank($address):false; $ifFill=($isFill)?CoreFunc::check_blank($email):false; $ifFill=($isFill)?CoreFunc::check_blank($group):false; if($isFill) if(dbController::change_user_info($this->id, $fname, $lname, $situation, $address, $email, $group, $tel, $mobile)){ $this->fname=$fname; $this->lname=$lname; $this->situation=$situation; $this->email=$email; $this->group=serialize(new Group($grpInfo['grp_id'])); $this->tel=$tel; $this->mobile=$mobile; return true; } return false; } public function change_my_pwd($original_pwd, $new_pwd){ //Return true if change password successful. Otherwise, return false. $original_pwd=trim($original_pwd); $new_pwd=trim($new_pwd); $isFill=(CoreFunc::check_blank($original_pwd))?true:false; $ifFill=($isFill)?CoreFunc::check_blank($new_pwd):false; if($isFill) return dbController::change_user_pwd($this->id, $new_pwd, $original_pwd); return false; } public function logout(){ //Clear the session when user logout. $_SESSION['userObj']=null; } //Static functions----------------------------------------------------------------------------------------------- public static function login($id, $password){ //If login success, the user info store in Session and return true. $_SESSION['userObj']=null; //Clear session before create new user object $result=false; $id=strtolower(trim($id)); $password=trim($password); if(!CoreFunc::check_blank($id) && !CoreFunc::check_blank($password)) return $result; $result=dbController::user_login($id, $password); if($result!=false){ $_SESSION['userObj']=serialize(new User($result['user_id'])); $result=true; } return $result; } public static function create_user($id, $fname, $lname, $situation, $address, $password, $email, $group, $tel=null, $mobile=null){ //If create User success, return true. Otherwise return the error message; $id=strtolower(trim($id)); $fname=trim($fname); $lname=trim($lname); $situation=trim($situation); $address=trim($address); $password=trim($password); $email=trim($email); $tel=($tel=='')?null:trim($tel); $mobile=($mobile=='')?null:trim($mobile); $group=trim($group); $isFill=(CoreFunc::check_blank($id))?true:false; $isFill=($isFill)?CoreFunc::check_blank($fname):false; $ifFill=($isFill)?CoreFunc::check_blank($lname):false; $ifFill=($isFill)?CoreFunc::check_blank($situation):false; $ifFill=($isFill)?CoreFunc::check_blank($address):false; $ifFill=($isFill)?CoreFunc::check_blank($password):false; $ifFill=($isFill)?CoreFunc::check_blank($email):false; $ifFill=($isFill)?CoreFunc::check_blank($group):false; if($isFill) return dbController::create_user($id, $fname, $lname, $situation, $address, $password, $email, $group, $tel, $mobile); return false; } public static function drop_user($id){ //For staff only. //If drop user success, return true. Otherwise, return false. if(CoreFunc::is_staff()){ $isFill=(CoreFunc::check_blank($id))?true:false; if($isFill) if(dbController::drop_user($id)){ if($id==$this->id) $this->logout(); return true; } } return false; } public static function change_user_info($id, $fname, $lname, $situation, $address, $email, $group, $tel=null, $mobile=null){ //For staff only. if(CoreFunc::is_staff()){ $id=strtolower(trim($id)); $fname=trim($fname); $lname=trim($lname); $situation=trim($situation); $address=trim($address); $email=trim($email); $tel=trim($tel); $mobile=trim($mobile); $group=trim($group); $isFill=(CoreFunc::check_blank($id))?true:false; $isFill=($isFill)?CoreFunc::check_blank($fname):false; $ifFill=($isFill)?CoreFunc::check_blank($lname):false; $ifFill=($isFill)?CoreFunc::check_blank($situation):false; $ifFill=($isFill)?CoreFunc::check_blank($address):false; $ifFill=($isFill)?CoreFunc::check_blank($email):false; $ifFill=($isFill)?CoreFunc::check_blank($group):false; if($isFill) return dbController::change_user_info($id, $fname, $lname, $situation, $address, $email, $group, $tel, $mobile); } return false; } public static function multi_search_user_info($id=false, $fname=false, $lname=false, $situation=false, $address=false, $email=false, $group=false, $tel=false, $mobile=false){ //For staff only. if(CoreFunc::is_staff()){ $id=($id && CoreFunc::check_blank($id))?strtolower(trim($id)):false; $fname=($fname && CoreFunc::check_blank($fname))?trim($fname):false; $lname=($lname && CoreFunc::check_blank($lname))?trim($lname):false; $situation=($situation && CoreFunc::check_blank($situation))?trim($situation):false; $address=($address && CoreFunc::check_blank($address))?trim($address):false; $email=($email && CoreFunc::check_blank($email))?trim($email):false; $group=($group && CoreFunc::check_blank($group))?trim($group):false; $tel=($tel && CoreFunc::check_blank($tel))?trim($tel):false; $mobile=($mobile && CoreFunc::check_blank($mobile))?trim($mobile):false; return dbController::multi_search_user_info($id,$fname,$lname,$situation,$address,$email,$group,$tel,$mobile); } return false; } public static function get_user_info($id){ //For staff only. if(CoreFunc::is_staff()){ $isFill=(CoreFunc::check_blank($id))?true:false; if($isFill) return dbController::get_user_info($id); } return false; } public static function reset_user_pwd($id, $new_pwd){ //For staff only. if(CoreFUnc::is_staff()){ $id=strtolower(trim($id)); $new_pwd=trim($new_pwd); $isFill=(CoreFunc::check_blank($id))?true:false; $ifFill=($isFill)?CoreFunc::check_blank($new_pwd):false; if($isFill) return dbController::change_user_pwd($id,$new_pwd); } return false; } public static function count_user(){ //For staff only. return (CoreFUnc::is_staff())?dbController::count_record('User', 'user_id'):false; } public static function login_state(){ return @is_object(unserialize($_SESSION['userObj'])); } public static function get_current_user(){ return (@is_object(unserialize($_SESSION['userObj'])))?unserialize($_SESSION['userObj']):false; } } ?>