<?php 
class User_model extends CI_Model {
	public function _consruct(){
		parent::_construct();
 	}
		
 	function getAdminData($user_id = ''){
 		if(empty($user_id)){
 			return 0;
 		}
 		$this->db->select("users.*,pos.profile_photo");
 		$this->db->join("pos","(pos.pos_id = users.profile_id AND users.user_type='3')");
		$query = $this->db->get_where('users',array('users.id'=>$user_id));
		//pr($this->db->last_query());
		if($query->num_rows() > 0 && !empty($query)){
			$result = $query->row();
            return $result;
		}
		return 0;
	}

 	function updateUser($user_id = '',$user_data = array()){
 		if(empty($user_id) || empty($user_data)){
 			return 0;
 		}
		if(isset($user_data['profile_image']) && !empty($user_data['profile_image'])){
			$profile_photo = $user_data['profile_image'];
			unset($user_data['profile_image']);
		}
		
		$this->db->update('users',$user_data,array('id'=>$user_id));
		$pos_id = $this->session->userdata('pos_id');

		if(isset($profile_photo) && !empty($profile_photo)){
			$this->db->update('pos',array('profile_photo'=>$profile_photo),array('pos_id'=>$pos_id));
		}
		
		if(!empty($user_data)){
			 $sess_array = array(
			    'id' => $user_id,
			    'username' => $user_data['username'],
			   'user_type'=> 3			    
			     );
			$this->session->set_userdata('logged_pos',$sess_array);
		}
		return 1;
	}
 	
}
?>