<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class home_model extends CI_Model 
{

	function __construct()
    {
        parent::__construct();
        
    }
    function check_auth($username,$vPassword){
        //check if password is working or not 
        $this->db->select('id');
        $this->db->from('user');
        $this->db->where('username', $username);
        $this->db->where('pwd', $vPassword);
        $query = $this->db->get();
        $ApExists = $query->row_array();

        if(count($ApExists) > 0 ){
            //check if user is active or not 
            $this->db->select('id,name,pics');
            $this->db->from('user');
            $this->db->where('username', $username);
            $this->db->where('pwd', $vPassword);
            $this->db->where('status', '1');
            $this->db->where('is_delete', '0');
            $query = $this->db->get();
            $AaExists = $query->row_array();
            if(count($AaExists) > 0){
                $AaExists["id"] = $AaExists['id'];
                $AaExists["name"] = $AaExists['name'];
                $AaExists["pics"] = $AaExists['pics'];
                $AaExists['logged_in'] = TRUE;
                return $AaExists;
            }else{
                $AaExists["msg"]="Sorry, Your Account has been deactive , contact to administrator";
                $AaExists['logged_in'] = FALSE;
                return $AaExists;
            }

        }else{
            //tell user that your password is wrong here.
            $AaExists["msg"]="Sorry, your password is wrong , contact to administrator";
            $AaExists['logged_in'] = FALSE;
            return $AaExists;
        }
    }
    function user_details($userid){ 
        $this->db->select('*');
        $this->db->from('user');
        $this->db->where('status','1');
        $this->db->where('is_delete','0');
        $this->db->where("id", $userid);
        $query=$this->db->get();
        return $query->row_array();
    }
       
}
?>
