<?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.*,express.image");
 		$this->db->join("express","(express.carrier_id = users.profile_id AND users.user_type='4')");
		$query = $this->db->get_where('users',array('users.id'=>$user_id));
		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));
		$exp_id = $this->session->userdata('exp_id');

		if(isset($profile_photo) && !empty($profile_photo)){
			$this->db->update('express',array('image'=>$profile_photo),array('carrier_id'=>$exp_id));
		}
		//pr($this->db->last_query());
		if(!empty($user_data)){
			 $sess_array = array(
			    'id' => $user_id,
			    'username' => $user_data['username'],
			   'user_type'=> 4			    
			     );
			$this->session->set_userdata('logged_exp',$sess_array);
		}
		return 1;
	}
 	
}
?>