<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Login_model extends CI_Model{
	public function check_login_test($data) { 
		$this->db->where('u_username', $this->input->post('username'));
        $this->db->where('u_password', md5($this->input->post('password')));
        $query = $this->db->get("login");
		if ($query->num_rows() >= 1) {
			return $query->row_array();
			} else {
			return false;
			}
	} 
	public function check_login($data){ 
		if($this->input->post('organization_code')){					
			$this->db->select('*');
			$this->db->from('login');
			$this->db->join('organization', 'organization.org_id= login.organization_id');
			$this->db->where('login.u_username',$this->input->post('username'));
			$this->db->where('login.u_password', md5($this->input->post('password')));
			$this->db->where('organization.org_code',$this->input->post('organization_code')); 
			$query = $this->db->get();
			
		}else{
			$this->db->where('organization_id','0');
			$this->db->where('u_username', $this->input->post('username'));
			$this->db->where('u_password', md5($this->input->post('password')));
			$query = $this->db->get("login");
		}      
		if ($query->num_rows() >= 1) {
			return $query->row_array();
			} else {
			return false;
			}
	} 
    public function userroles($u_id) { 
     $userroles = $this->db->select('*')->from('login_roles')->where('lr_u_id',$u_id)->get()->result_array();
       if(!empty($userroles)) {
       		return $userroles[0];
       } else{
       		return array();
       }
    }
} 