<?php
class front_model extends CI_Model
{
	function __construct()
	{
		parent::__construct();
	}
	
	function chk_permission($where)
	{
		$this->db->select('pre.file_name');
		$this->db->from('kp_admin ad');
		$this->db->join('kp_group gr','gr.group_id=ad.group_id','inner');
		$this->db->join('kp_assigne_privilege_group apg','gr.group_id=apg.group_id','inner');
		$this->db->join('kp_privileges pre','apg.privilege_id = pre.privilege_id','inner');
		$this->db->where($where);
		$query = $this->db->get();
		$return_permission = array();
		if($query->num_rows > 0){			
			$return = $query->result();
			foreach($return as $row)
			{
				$return_permission[$row->file_name] = $row->file_name;
			}
		}
		return $return_permission;
	}
	
	function create_urls($where)
	{
		$this->db->select('pre.privilege_name,pre.file_name');
		$this->db->from('kp_admin ad');
		$this->db->join('kp_group gr','gr.group_id=ad.group_id','inner');
		$this->db->join('kp_assigne_privilege_group apg','gr.group_id=apg.group_id','inner');
		$this->db->join('kp_privileges pre','apg.privilege_id = pre.privilege_id','inner');
		$this->db->where($where);
		$query = $this->db->get();
		if($query->num_rows > 0){			
			return $query->result();
		}
	}
	
	function get_where($table,$where=NULL)
	{
		if($where != NULL){
			$this->db->where($where);
		}
		$query = $this->db->get($table);
		if($query->num_rows > 0){
			return $query->result();
		}
	}
	
	function get_single($table , $where , $show)
	{
		$this->db->where($where);
		$query = $this->db->get($table);
		if($query->num_rows > 0){
			$return = $query->row();
			return $return->$show;
		}
	}
	
	function single_rec($table , $where)
	{
		$this->db->where($where);
		$query = $this->db->get($table);
		if($query->num_rows > 0){
			return $query->row();
		}
	}
	
	function join_two_result($table1,$table2,$relation,$group=NULL,$where=NULL)
	{
		$this->db->select('*');
		$this->db->from($table1);
		$this->db->join($table2,$relation,'inner');
		if($group != NULL){
			$this->db->group_by($group);
		}
		if($where != NULL){
			$this->db->where($where);
		}
		$query = $this->db->get();
		if($query->num_rows > 0){
			
			return $query->result();
		
		}
	}
	
	function join_two_row($table1,$table2,$relation,$where)
	{
		$this->db->select('*');
		$this->db->from($table1);
		$this->db->join($table2,$relation,'inner');
		$this->db->where($where);
		$query = $this->db->get();
		if($query->num_rows > 0){
			
			return $query->row();
			
		}
	}
	
	function insert_data($table,$data)
	{
		$query = $this->db->insert($table,$data);
		if($query){
			return true;
		}else{
			return false;
		}
	}
	//Regestraion code
	//add webuer code
public function insert_webuser_record($var)
{
$query=$this->db->insert('njobn_webusers',$var);
if($query)
{
return true;
}
else
{
return false;
}
}
	function update_data($table,$data,$where)
	{
		$query = $this->db->update($table,$data,$where);
		if($query){
			return true;
		}else{
			return false;
		}
	}
	
	function del_rec($table , $where)
	{
		$query = $this->db->delete($table,$where);
		if($query){
			return true;
		}else{
			return false;
		}
	}
	
	/*function get_privileges_groups($where)
	{
		$this->db->select('*');
		$this->db->from('kp_group gr');
		$this->db->join('kp_assigne_privilege_group apg','gr.group_id=apg.group_id','inner');
		$this->db->join('kp_privileges pre','pre.privilege_id=apg.privilege_id','inner');
		$this->db->where($where);
		$query = $this->db->get();
		if($query->num_rows > 0){
			
			return $query->result();
		
		}
	}*/
}

?>