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

class UseraccessDetails extends CI_Model{
	
	public function UseraccessDetails_id($id){
		$this->db->select('user_module_access_details.*');
		$this->db->select('module.description');
		$this->db->where('userID', $id);
		$this->db->from('user_module_access_details');
		$this->db->join('module', 'module.ID = user_module_access_details.moduleID');
		$query = $this->db->get();
		if($query->num_rows() >= 1){
			return $query->result();
		}else{
			return false;
		}
	}
	
	public function UseraccessDetails_id_code($menuCode){
		$this->db->select('user_module_access_details.*');
		$this->db->where('userID', element('role', $this->session->userdata('logged_in')));
		$this->db->where('companyID', element('compID', $this->session->userdata('logged_in')));
		$this->db->where('menuCode', $menuCode);
		$this->db->where('accessRight', 1);
		$this->db->from('user_module_access_details');
		$query = $this->db->get();
		return true;
		if($query->num_rows() >= 1){
			return $query->result();
		}else{
			return false;
		}
	}
	
	function UseraccessDetails_update(){
		$this->db->select('a.*');
		$this->db->where('a.companyID', $this->input->post('companyID'));
		$this->db->where('a.userID', $this->input->post('fldid'));
		$this->db->where('a.menuCode', $this->input->post('menuCode'));
		$this->db->from('user_module_access_details a');
		$query = $this->db->get();
		if($query->num_rows() >= 1){
			$data = $query->result();
			$dataupdate = array (
				'accessRight' => $this->input->post('accessRight'),
				'updatedBy' => element('role', $this->session->userdata('logged_in'))
			);
			$this->db->flush_cache();
			$this->db->where('ID', $data[0]->ID);
			$query1 = $this->db->update('user_module_access_details', $dataupdate); 
			if($query1 === TRUE){
				return TRUE;
			} else {
				return FALSE;
			}
		}else{
			$dataupdate = array (
				'companyID' => $this->input->post('companyID'),
				'userID' => $this->input->post('fldid'),
				'menuCode' => $this->input->post('menuCode'),
				'accessRight' => $this->input->post('accessRight'),
				'createdBy' => element('role', $this->session->userdata('logged_in'))
			);
			$query1 = $this->db->insert('user_module_access_details', $dataupdate); 
			if($query1 === TRUE){
				return TRUE;
			} else {
				return FALSE;
			}
		}
	}
	function UseraccessDetails_update2(){
		$dataupdate = array (
			'accessRight' => $this->input->post('accessRight'),
			'updatedBy' => element('role', $this->session->userdata('logged_in'))
		);
		$this->db->where('ID', $data[0]->ID);
		$query1 = $this->db->update('user_module_access_details', $dataupdate); 
		if($query1 === TRUE){
			return TRUE;
		} else {
			return FALSE;
		}
	}
}
/* End of file UseraccessDetailsDetails.php */
/* Location: ./application/models/UseraccessDetailsDetails.php */
/* Created By : Yahaya Abdollah */
