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

class Adm_tahun_ajaran extends CI_Controller {
	
	var $gparam = array();
	
	public function __construct() {
        parent::__construct();
		$this->gparam['controller'] = $this->router->fetch_class();
		$this->load->model('adm_tahun_ajaran_model', 'tahun_ajaran');
		$this->gparam['privilage'] = getPrivilage($this->gparam['controller']);
		$this->gparam['restrict'] = 'You Cannot Access This Menu';
    }
	
	public function index()
	{
		if ($this->gparam['privilage']->privilage_view == 'Y') {
			$gridopt = $this->input->get(array('psize', 'pnumber'));
			header('Content-Type: text/html');
			$create_button = '""';			
			$approve_button = '';
			
			if ($this->gparam['privilage']->privilage_create == 'Y') {
				//create button
				$create_button = '<a href="javascript:void(0)"  class="btn btn-primary btn-xs" onclick="create_view();" >
									<i class="fa fa-lg fa-fw fa-plus"></i>Create
								  </a>';

			}
			if ($this->gparam['privilage']->privilage_update == 'Y') {
				$approve_button = "<a href=\"javascript:void(0)\" onclick=\"approve_process('+row_id+','+tahun_ajaran+'); \" style=\"margin:4px;\" class=\"btn btn-success btn-xs\" group=\"\" data-toggle=\"tooltip\" title=\"Used\">\
								<i class=\"fa fa-check fa-lg\"></i>\
								</a>";
			}
			// pnumber, psize
			$data = array(
					'controller'	=> $this->gparam['controller'],
					'psize'  		=> (empty($gridopt['psize'])?10:$gridopt['psize']),
					'pnumber'  		=> (empty($gridopt['pnumber'])?1:$gridopt['pnumber']),
					'create' 		=> $create_button,
					'approve'		=> $approve_button
			);
			
			$this->load->view('tahun_ajaran_view',$data);
		} else {
			echo $this->gparam['restrict'];
		}
		
	}
	
	function crud() {
		if ($this->gparam['privilage']->privilage_view == 'Y') {
			$data = array(
				'controller'  => $this->gparam['controller']
			);
					
			$this->load->view('add_tahun_ajaran',$data);
		} else {
			echo $this->gparam['restrict'];
		}
	}
	
	function load_data() {
		header('Content-Type: application/jsonp');
        $list = $this->tahun_ajaran->get_list_data();
		
        echo json_encode($list);
	}
	
	function change_tahun_ajaran() {
		$row_id = $this->input->post('row_id');
		//$row_id = $this->uri->segment(3);
		$change = $this->tahun_ajaran->change_tahun_ajaran($row_id);			
		//header('Content-Type: application/jsonp');
		$json = true;
		echo json_encode($json);
		//reidrect('adm_tahun_ajaran');
		//$this->index();
		//echo 'Row Id = '.$row_id;
		
	}
	
	function cek_tahun_ajaran() {
		
		$tahun_ajaran = $this->input->post('tahun_ajaran');
		$cek = $this->tahun_ajaran->cek_tahun_ajaran($tahun_ajaran);
		
		if ($cek > 0) {
			$json = false;
		} else {
			$json = true;
		}
		
		echo json_encode($json);
	
	}
	
	function insert_data() {
		
		$data['sts_ppdb'] 		= 0;
		$data['status'] 		= $this->input->post('status');
		$data['tahun_ajaran'] 	= $this->input->post('tahun_ajaran');
		$data['keterangan']		= $this->input->post('keterangan');
		$data['created_date']	= date("Y-m-d H:i:s");
		$data['created_by']		= $this->session->userdata('username');
		
		$insert = $this->tahun_ajaran->insert_data($data);
		if ($insert) {
			$json = true;
			//redirect("home#".$this->gparam['controller'],"refresh");
		}
		echo json_encode($json);
	}
}
