MIF_E31211879/application/core/Controller.php

74 lines
1.8 KiB
PHP

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Controller extends CI_Controller {
/**
* @author Fendrik Nurul Jadid <fendrik1311@gmail.com>
* @since v.1.0
**/
public function __construct()
{
parent::__construct();
// $this->load->library('Pdf');
//Codeigniter : Write Less Do More
// $akses = false;
// $link = $this->uri->segment(1)."/".$this->uri->segment(2);
// // $role = json_decode($_SESSION['role']);
// $data = $this->db->where_in("id_menu",$role)->get("menu")->result();
// foreach ($data as $value) {
// if ($value->url==$link) {
// $akses = true;
// }
// }
// if ($link=='/') {
// $akses=true;
// }
// // die(var_dump($link));
// if (!$akses) {
// // redirect(base_url()."permission/denied");
// }
$menu_utama = $this->Core->get_menu();
// die(var_dump($menu_utama));
// echo "<pre>";
// print_r($menu_utama);
// echo "</pre>";
// die();
$akses = false;
$link = strtolower($this->uri->segment(1));
$link2 = strtolower($this->uri->segment(2));
// $link3 = strtolower($this->uri->segment(3));
if ($link2!='') {
$link.="/".$link2;
}
if (!isset($_SESSION['iduser'])) {
redirect('user/login');
}
$data_user = $this->db->where("iduser",$_SESSION['iduser'])->get("user")->row();
$roles = json_decode($data_user->roles);
// die($roles);
$data = $this->db->where_in("idmenu",$roles)->get("menu")->result();
// die(var_dump($link));
foreach ($data as $value) {
if (strtolower($value->roles)==$link) {
$akses = true;
}
}
if ($link=='' || $link==null || empty($link)) {
$akses=true;
}
// die(var_dump($link));
if (!$akses) {
// redirect(base_url()."permission/denied");
}
}
}