<?php
class users_model extends CI_Model {
	public function check_users($username,$password){
		$this->db->where('username',$username);
        $this->db->where('password',$password);
		$result = $this->db->get('users');
		if($result->num_rows() == 1){
			$data = array("id"=>$result->row(0)->id,"username"=>$result->row(0)->username,"fullname"=>$result->row(0)->full_name,"expire"=>$result->row(0)->expire,"per"=>$result->row(0)->permision,"intper"=>$result->row(0)->internal_permision);
		return $data;
		}else{
			return "not_find";
		}
	}
	public function is_password_currect($id,$password){
		$this->db->where('id',$id);
        $this->db->where('password',$password);
		$result = $this->db->get('users');
		if($result->num_rows() == 1){
			return true;
		}else{
			return false;
		}
	}
	public function update_users($id,$data){
		$this->db->where('id',$id);
    $this->db->update('users', $data);
	}
	public function set_password($id,$password){
		$this->db->where("id",$id);
		$this->db->update('users', array("password"=>md5($password)));
	}
	public function users_list($number="null",$offset="null",$search = "null"){
        if($number=="null" && $offset == "null"){
             if($search == "null"){
			$result = $this->db->get('users');	
			 }else{
				$this->db->like('full_name',$search);
			$result = $this->db->get('users');		
			 }
			 
			 
        return count($result->result());   
        }else{
			if($search != "null"){
			$this->db->like('full_name',$search);
		}
        $this->db->limit($number,$offset);
		
        $result = $this->db->get('users');
        return $result->result();
        }
    }
	public function get_doctors(){
		$this->db->where('permision',4);
		 $result = $this->db->get('users');
        return $result->result();
	}
	public function insert_user($data){
		$this->db->insert('users', $data);

	}

     function getLastInserted() {
$query = $this->db->query("SELECT *
  FROM users
 ORDER
    BY Id DESC
 LIMIT 1");
$query = $query->result();
return $query[0]->id;
       }

	public function delete_users($id){
		 $this->db->where('id', $id);
		 $this->db->delete('users');
	}
	public function get_user_by_id($id){
		$this->db->where('id', $id);
		$result = $this->db->get('users');
        return $result->result();
	}

}
?>