<?php
class Model_squrity extends CI_model
{

	public function getsqurity()
	{
		$mst_petugas_id = $this->session->userdata('mst_petugas_id');
		if (empty($mst_petugas_id)) {
			$this->session->sess_destroy();
			redirect('');
		}
	}

	public function cekmenu($mst_menu_link)
	{
		$mst_petugas_id = $this->session->userdata('mst_petugas_id');
		$sql = $this->db->query("SELECT mst_menu_link FROM tbl_mst_menu,tbl_mst_akses,tbl_mst_petugas WHERE 
						mst_akses_menu_id=mst_menu_id AND mst_akses_petugas_id='$mst_petugas_id' and 
						mst_menu_link='$mst_menu_link' group by mst_menu_link");

		if ($sql->num_rows() <= 0) {
			redirect('aksesgagal/error');
			echo "<script>
			 	toastr.error('Anda tidak memiliki akses ke halaman ini');
			</script>";
			exit;
		} else {
			return true;
		}
	}

	public function cekmenu_saldo($mst_menu_link)
	{
		$mst_petugas_id = $this->session->userdata('mst_petugas_id');
		$sql = $this->db->query("SELECT mst_menu_link FROM tbl_mst_menu,tbl_mst_akses,tbl_mst_petugas WHERE 
						mst_akses_menu_id=mst_menu_id AND mst_akses_petugas_id='$mst_petugas_id' and 
						mst_menu_link='$mst_menu_link' group by mst_menu_link");

		if ($sql->num_rows() <= 0) {
			return false;
			exit;
		} else {
			return true;
		}
	}
}
