<?php

class User_login_model extends Model{

	function User_login_model(){
		parent::Model();
				$this->load->helper('url');	
		$this->load->helper('form');
		$this->load->library('session');
	}
	
	function verifyUser($username,$password){
    $q = $this->db->query("SELECT * FROM d_users WHERE user_username='$username' AND user_password='$password' AND user_state='1' ");
    if($q->num_rows() > 0) {
        foreach ($q->result() as $row) {
	$udata = array(
                   'username'  => $row->user_username,
                   'id'     => $row->user_id,
                   'logged_in' => TRUE
               );

		$this->session->set_userdata($udata);
		            $data[] = $row;   
			}
    return $data;
	return TRUE;
  						  }
	else 
    return FALSE;
}


	function checkUser($str){
    $q = $this->db->query("SELECT * FROM d_users WHERE user_username='$str' ");
    if($q->num_rows() > 0) {
        foreach ($q->result() as $row) {
            $data[] = $row;   
			}
    return $data;
	return TRUE;
  						  }
	else 
    return FALSE;
}

	function checkMail($str){
    $q = $this->db->query("SELECT * FROM d_users WHERE user_email='$str' ");
    if($q->num_rows() > 0) {
        foreach ($q->result() as $row) {
            $data[] = $row;   
			}
    return $data;
	return TRUE;
  						  }
	else 
    return FALSE;
}
 
function log_state($username,$password)
{
$t=time();
$this->db->query("update d_users set log_state='1',time_log='$t' where user_username='$username' and user_password='$password'");

return true;

}
function log_out_state($id)
{
$this->db->query("update d_users set log_state='0'  where user_id='$id'");

return true;

}

}
?>