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

class Menus_list extends CI_Controller {
	function index(){
		if ($this->session->userdata('idgroup')){
			if($this->session->userdata('idgroup')>2){
				redirect('login');
			}else{
				$this->showData();
			}
		}else{
			redirect('login');
		}
	}

	function showData(){
		if($this->session->userdata('is_logged_in')==FALSE){
			redirect('login');
		}

		if ($this->session->userdata('idgroup')){
			if($this->session->userdata('idgroup')>2){
				redirect('login');
			}
		}else{
			redirect('login');
		}

		$data['pkpu'] 	 = '';
		$data['phi'] 	 = '';
		$data['hki'] 	 = '';
		$data['ham'] 	 = '';
		$data['ikan'] 	 = '';
		$data['tipikor'] = '';
		$data['antrian']	 = '';
		$this->load->model('sistem/db_menu','menu');
		$status = $this->menu->get_status_menu();
		if($status!=''){
			if($status->num_rows>0){
				foreach ($status->result() as $row) {
					if($row->id==149)
						$data['pkpu'] = $row->st;
					elseif($row->id==148)
						$data['phi'] = $row->st;
					elseif($row->id==151)
						$data['hki'] = $row->st;
					elseif($row->id==156)
						$data['ham'] = $row->st;
					elseif($row->id==155)
						$data['ikan'] = $row->st;
					elseif($row->id==154)
						$data['tipikor'] = $row->st;
					elseif($row->id==6000)
						$data['antrian'] = $row->st;
				}
			}
		}
		$data['page_title'] = 'MANAJEMEN MENU';
		$data['main_body'] = 'sistem/menu_list';
		$data['page_url'] = 'perkara_kasasi_list';	
		$this->load->vars($data);
		$this->load->view('header');
		$this->load->view('body/body_new');
	}

	function activated(){
		if(empty($_POST)){
			show_404();
		}
		if($this->session->userdata('is_logged_in')==FALSE){
			echo json_encode(array('st'=>0,'msg'=>'Please Refresh Your Page'));
			return;
		}
		if ($this->session->userdata('idgroup')){
			if($this->session->userdata('idgroup')>2){
				echo json_encode(array('st'=>0,'msg'=>'Maaf Anda Tidak Diizinkan Melakukan Perubahan'));
				return;
			}
		}else{
			echo json_encode(array('st'=>0,'msg'=>'Maaf Anda Tidak Diizinkan Melakukan Perubahan'));
			return;
		}
		$id = trim($this->input->post('id'));
		if(intval($id)<0 AND intval($id)>7){
			echo json_encode(array('st'=>0,'msg'=>'Error:<br /> Value Not Found'));
			return;
		}
		$id = intval($id);
		$this->load->model('sistem/db_menu','menu');
		if($id==1)
			$status = $this->menu->activated_menu('254,149,132');
		elseif($id==3)
			$status = $this->menu->activated_menu('257,134,148');
		elseif($id==2)
			$status = $this->menu->activated_menu('151,133,256');
		elseif($id==4)
			$status = $this->menu->activated_menu('260,142,156');
		elseif($id==5)
			$status = $this->menu->activated_menu('259,141,155');
		elseif($id==6)
			$status = $this->menu->activated_menu('140,258,154');
		elseif($id==7)
			$status = $this->menu->activated_menu('6000');

		if($status){
			echo json_encode(array('st'=>1,'msg'=>'Menu Telah Di Update. Silahkan Logout dan Login Kembali'));
			return;
		}
	}

	function deactivated(){
		if(empty($_POST)){
			show_404();
		}
		if($this->session->userdata('is_logged_in')==FALSE){
			echo json_encode(array('st'=>0,'msg'=>'Please Refresh Your Page'));
			return;
		}
		if ($this->session->userdata('idgroup')){
			if($this->session->userdata('idgroup')>2){
				echo json_encode(array('st'=>0,'msg'=>'Maaf Anda Tidak Diizinkan Melakukan Perubahan'));
				return;
			}
		}else{
			echo json_encode(array('st'=>0,'msg'=>'Maaf Anda Tidak Diizinkan Melakukan Perubahan'));
			return;
		}

		$id = trim($this->input->post('id'));
		if(intval($id)<0 AND intval($id)>7){
			echo json_encode(array('st'=>0,'msg'=>'Error:<br /> Value Not Found'));
			return;
		}
		$id = intval($id);
		$this->load->model('sistem/db_menu','menu');
		if($id==1)
			$status = $this->menu->deactivated_menu('254,149,132');
		elseif($id==3)
			$status = $this->menu->deactivated_menu('257,134,148');
		elseif($id==2)
			$status = $this->menu->deactivated_menu('151,133,256');
		elseif($id==4)
			$status = $this->menu->deactivated_menu('260,142,156');
		elseif($id==5)
			$status = $this->menu->deactivated_menu('259,141,155');
		elseif($id==6)
			$status = $this->menu->deactivated_menu('140,258,154');
		elseif($id==7)
			$status = $this->menu->deactivated_menu('6000');

		if($status){
			echo json_encode(array('st'=>1,'msg'=>'Menu Telah Di Update. Silahkan Logout dan Login Kembali'));
			return;
		}
	}
}
