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

class Complaint_Model extends CI_Model {


    public function get_new_msg_users() {
        return $this->db->select('guard_name')->where('deleted_DT IS NULL')->where('admin_view_flag', 0)->group_by('guard_name')->get('mst_complaint')->result();
    }

	
	public function fetch_data()
	{
        return $this->db->where('deleted_DT IS NULL')->get('mst_guard')->result();
	}
	
	public function get_chat_by_userid($userid) {
	    $data['userdetails'] = $this->db->where('id', $userid)->get('mst_guard')->row(); 
	    $data['chat'] = $this->db->where('deleted_DT IS NULL')
	                    ->where('guard_name', $userid)->order_by('comp_id', 'ASC')->get('mst_complaint')->result();

        return $data;
	}
	
	
	public function save_chat_msg($userid) {
	    if(!empty($_POST['msg'])) {
    	    $data['guard_name'] = $userid;
    	    $data['admin_msg'] = 1;
    	    
    	    $data['complaint_desc'] = !empty($_POST['msg']) ? $_POST['msg'] : '';
    	    $data['inserted_by'] = $this->session->userdata('name');
    	    $data['inserted_SI'] = $this->session->userdata('id');
    	    $data['inserted_DT'] = date('Y-m-d H:i:s');
    	    $this->db->insert('mst_complaint', $data);
	    }
	}

	public function display_recordsById($id)
	{
		/*$query=$this->db->query("select * from mst_complaint where comp_id='".$id."'");
		return $query->row();*/
		
		//echo $id;
		
	    $query=$this->db->select('mst_complaint.*,mst_guard.name,id');
	 	$this->db->where('mst_complaint.deleted_DT',NULL);
	 	$this->db->where('comp_id',$id);
		$this->db->from('mst_complaint');
		$this->db->join('mst_guard','mst_guard.id=mst_complaint.guard_name','left');
		$query=$this->db->get();
		return $query->row();
		
		
	}

	public function update($id)
	{
		
		$n=$this->input->post('name');
		$a=$this->input->post('address');
		$e=$this->input->post('emailid');
		$c=$this->input->post('contact');
		$DOB=$this->input->post('DOB');
		$DOJ=$this->input->post('DOJ');
		$username=$this->input->post('username');
		$password=$this->input->post('password');
		$query=$this->db->query("update mst_guard SET name='$n',address='$a',email='$e',contact='$c',
		DOB='$DOB',DOJ='DOJ',username='username', password='password' where id='".$id."'");

	}


	

	
}
