<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
	class Dashboard_model extends CI_Model
	{
		function __construct()
		{
			parent::__construct();
		}
		
		function notif_count(){
			$this->db->from('ptsp_pengunjung');
			$this->db->where('waktu_jawab',NULL);
			$query = $this->db->get();
            return $query->num_rows();
		}
		
		function antrian_pengunjung($tanggal){
			$query = $this->db->query("SELECT A.*,B.alamat,B.file_ktp FROM ptsp_pengunjung A LEFT JOIN pengguna B ON A.p_id=B.id where date(waktu_hubungi)='$tanggal' AND waktu_jawab IS NULL ORDER BY waktu_hubungi ASC ");
            if ($query->num_rows() > 0) {
                return $query->result();
				}else{
				return $query->result();
			}
		}
		
		function pengaturan(){
			return $this->db->query("SELECT * FROM pengaturan WHERE id = '2' ")->row();
		}
		
		function update_pengaturan($id, $data)
		{
			$this->db->where('id', $id);
			$this->db->update('pengaturan', $data);
		}
		
		function update_user($id, $data)
		{
			$this->db->where('id', $id);
			$this->db->update('user', $data);
		}
		
		function update_jam_layanan($id, $data)
		{
			$this->db->where('id', $id);
			$this->db->update('jam_layanan', $data);
		}
		
		function update_ptsp_hubungi($id, $data)
		{
			$this->db->where('id', $id);
			$this->db->update('ptsp_hubungi', $data);
		}
		
		function update_ptsp_hubungi_kesekretariatan($id, $data)
		{
			$this->db->where('id', $id);
			$this->db->update('ptsp_hubungi_kesekretariatan', $data);
		}
		
		function pengunjung(){
			return $this->db->query("SELECT A.*,B.alamat,B.file_ktp FROM ptsp_pengunjung A LEFT JOIN pengguna B ON A.p_id=B.id ORDER BY waktu DESC")->result();
		}
		
		function jenis_layanan($id_jenis_layanan){
			return $this->db->query("SELECT * FROM ptsp_layanan WHERE id_jenis_layanan='$id_jenis_layanan' ")->row();
		}
		
		function data_layanan($id_jenis_layanan){
			return $this->db->query("SELECT * FROM ptsp_layanan WHERE id_jenis_layanan='$id_jenis_layanan' ")->result();
		}
		
		function insert($data)
		{
			$this->db->insert('ptsp_pengunjung', $data);
		}
		
		
		
		function get_layanan_id($id,$p_id){
			return $this->db->query("SELECT * FROM ptsp_pengunjung WHERE md5(id) = '$id' AND p_id = '$p_id' ")->row();
		}
		
		function ptsp_pengunjung_id($id,$p_id){
			return $this->db->query("SELECT * FROM ptsp_pengunjung WHERE id = '$id' AND p_id = '$p_id' ")->row();
		}
		
		function ptsp_hubungi_id($bantuan){
			return $this->db->query("SELECT * FROM ptsp_hubungi WHERE id = '$bantuan'")->row();
		}
		
	}
