<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class users_model extends CI_Model {
 
    public function __construct()
    {
        parent::__construct();
        $this->load->database();
    }
 
 	// get all employes
	public function get_users() {
	    $condition = "user_type_id=1 or user_type_id=4";
        $this->db->select('*');
		$this->db->from('users');
		$this->db->where($condition);
		return $this->db->get();
	}
	
	// Function to add record in table
	public function add($data){
		$this->db->insert('users', $data);
		if ($this->db->affected_rows() > 0) {
			return true;
		} else {
			return false;
		}
	}
	
	 public function read_user_information($id) {
	     
		$condition = "id =" . "'" . $id . "' ";
		$this->db->select('*');
		$this->db->from('users');
		$this->db->where($condition);
		$this->db->limit(1);
		$query = $this->db->get();
		
		if ($query->num_rows() == 1) {
			return $query->result();
		} else {
			return false;
		}
	}
	
	
		// Function to update record in table > change_password
	public function change_password($data, $id){
		
		$condition = "id =" . "'" . $id . "' ";
		$this->db->where($condition);
		if( $this->db->update('users',$data)) {
			return true;
		} else {
			return false;
		}		
	}
	
	public function user_info($data, $id){
		$condition = "id =" . "'" . $id . "' ";
		$this->db->where($condition);
		if( $this->db->update('users',$data)) {
			return true;
		} else {
			return false;
		}		
	}
	
	// Function to update record in table > basic_info
	public function basic_info($data, $id){
		$condition = "id =" . "'" . $id . "' ";
		$this->db->where($condition);
		if( $this->db->update('users',$data)) {
			return true;
		} else {
			return false;
		}		
	}
	
	
	public function read_employee_information($id) {
		$condition = "id =" . "'" . $id . "' ";
		$this->db->select('*');
		$this->db->from('users');
		$this->db->where($condition);
		$this->db->limit(1);
		$query = $this->db->get();
		
		if ($query->num_rows() == 1) {
			return $query->result();
		} else {
			return false;
		}
	}
	
	
	// Function to update record in table > profile picture
	public function profile_picture($data, $id){
		
		$condition = "id =" . "'" . $id . "' ";
		$this->db->where($condition);
		if( $this->db->update('users',$data)) {
			return true;
		} else {
			return false;
		}		
	}
	
	public function delete_record($id){
		$condition = "id =" . "'" . $id . "' ";
		$this->db->where($condition);
		if($this->db->delete('users')) {
			return true;
		} else {
			return false;
		}
	}
	
	
}