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

class User extends MY_Controller {
	
	function __construct()
	{
		//$this->auth->auth_main();
		parent::__construct();		
		
		$this->modul='user';
		$this->title='USER';
		
		$this->username=$this->session->userdata('username');		
		$this->kd_cmpy=$this->session->userdata('kd_cmpy');
		
		$this->load->model($this->modul.'_mdl','mdl');
	}
	
	public function index()
	{		
		$data = array(
			'content' 	=> 	$this->modul.'/'.$this->modul,			
			't'			=>	$this->session->userdata('t'),
			'u'			=>	$this->session->userdata('u'),
			'h'			=>	$this->session->userdata('h')
			);		
		$this->load('tpl',$data['content'], $data);
		$this->load->view($this->modul.'/'.$this->modul.'_cjs');
		$this->load->view($this->modul.'/'.$this->modul.'_mjs');
		
	}
	
	function getPage(){
		$page = isset($_POST['page']) ? intval($_POST['page']) : 1;
		$rows = isset($_POST['rows']) ? intval($_POST['rows']) : 100;	
		$key = $_REQUEST["q"];
		$rs = $this->mdl->getPage($page,$rows,$key);
		
		echo json_encode($rs);
	}
	
	function getform($cmd){
		$form_data = $this->input->post();
		$id=$form_data['id'];
		
		$form_data['pass']=$this->encrypt->encode($form_data['pass']);
		// $form_data['grup']='admin';
		
		unset($form_data['id']);
		if ($cmd=="add"){	
			$this->add($form_data);	
		} else {
			$this->edit($form_data,$id);
		}
	}
	
	function aksi($cmd)
	{
		ini_set('memory_limit', '-1');
		
		$page = isset($_REQUEST['page']) ? intval($_REQUEST['page']) : 1;
		$rows = isset($_REQUEST['rows']) ? intval($_REQUEST['rows']) : 100;	
		$key = $_REQUEST["q"];
		
		$data = array(
			'rs' 	=> 	$this->mdl->getPage($page,$rows,$key)
		);
		
		if ($cmd=='xls'){
			$filename =$this->modul.".xls";
			header('Content-type: application/ms-excel');
			header('Content-Disposition: attachment; filename='.$filename);
		}
		$this->load->view($this->modul.'/print',$data);
	}
	public function hakakses() {
		// // add breadcrumbs
		// $this->breadcrumbs->push('<i class="fa fa-dashboard"></i> Home', '/');
		// $this->breadcrumbs->push($this->title, '/' . $this->modul);
		// $this->breadcrumbs->push('Hak Akses', '/' . $this->modul.'/hakakses');
		$group_id = $this->uri->segment(3, 0);
		$group_name = urldecode($this->uri->segment(4, 0));
		$data = array(
			'smodul' => $this->modul,
			'name' => $this->session->userdata('name'),
			'content' => $this->modul . '/hakakses_frm',
			'title' => 'Hak Akses ' . $group_name,
			'group_id' => $group_id,
			'group_name' => $group_name
		);
		$this->load('tpl', $data['content'], $data);
		$this->load->view($this->modul . '/hakakses_frm_cjs');
		$this->load->view($this->modul . '/hakakses_frm_mjs');
	}
	function gridHakAkses($nm_opr) {
		$rs = $this->mdl->getHakAkses2($nm_opr);
		echo json_encode($rs);
	}
	function simpan() {
		$form_data = $this->input->post();
		$rs = $this->mdl->setHakAkses($form_data);
		echo json_encode($rs);
	}
}