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

class Usertype_model extends CI_Model {

	public function getlist()
	{
		$data=array();
		$this->db->select('*');
		$this->db->from('tbl_user_type');
		$this->db->where('user_type_id!=',1);
		$q=$this->db->get();
		//echo $this->db->last_query();exit;
		if($q->num_rows()>0){
			foreach($q->result_array() as $result){
				$data[]=$result;
			}
		}
		
		return $data;
	}

	public function insert_usertype($insert_array)
	{
		$insert=$this->db->insert('tbl_user_type',$insert_array);

		if($insert)
		{
			
			$this->utility->setMsg('Data added successfully.','SUCCESS');
			$return=1;
		}
		else
		{
			$this->utility->setMsg('Failed to insert data. Please try again.','ERROR');
			$return=0;
		}
		return $return;
	}

	public function getusertype($id)
	{
		$data=array();
		$this->db->where('user_type_id',$id);
		$q=$this->db->get('tbl_user_type');
		//echo $this->db->last_query();exit;
		if($q->num_rows()>0)
		{
			foreach($q->result_array() as $result)
			{
				$data[]=$result;
			}
		}
		return $data;
	}

	public function update_usertype($update_array,$id)
	{
		$this->db->where('user_type_id',$id);
		$update=$this->db->update('tbl_user_type',$update_array);
		
		if($update)
		{
			
			$this->utility->setMsg('Data added successfully.','SUCCESS');
			$return=1;
		}
		else
		{
			$this->utility->setMsg('Failed to update data. Please try again.','ERROR');
			$return=0;
		}
		return $return;
	}

	public function delete_usertype($id)
	{

		$this->db->where('user_type_id',$id);
		$delete=$this->db->delete('tbl_user_type');
		if($delete)
		{
			
			$this->utility->setMsg('SUCCESS');
			$return=1;
		}
		else
		{
			$this->utility->setMsg('FAILURE');
			$return=0;
		}
		return $return;
	}

	public function userpermission($id)
	{
		$this->db->where('user_type_id',$id);
		$q=$this->db->get('user_permissions');
		//echo $this->db->last_query();exit;
		if($q->num_rows()>0)
		{
			return $q->row_array();
		}
		
	}

	public function gettype($usertype)
 {
    $this->db->where('user_type_name',$usertype);
    $ut_existance = $this->db->get('tbl_user_type');
    if($ut_existance->num_rows()>0){
        
        return $ut_existance;
        
    }
 }
}