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

class Jabatan extends MX_Controller {
	
	
	public function __construct(){
		parent::__construct();
		
		$this->page->use_directory();
		$this->load->model('model_jabatan');	
	}

	public function index() {		
		$this->page->view('jabatan_index', array(
			'add'			=> $this->page->base_url('/add'),
			'grid'			=> $this->model_jabatan->get_jabatan(),
		));
	}
	
	private function form($action = 'insert', $id = ''){
		$this->page->view('jabatan_form', array (
			'back'			=> $this->agent->referrer(),
			'action'		=> $this->page->base_url("/{$action}/{$id}"),
			'jabatan'		=> $this->model_jabatan->by_id_jabatan($id),
		));
	}
	
	public function add(){
		$this->form();
	}
	
	public function edit($id){
		$this->form('update', $id);
	}
	
	public function insert(){
		$data = array(
			'id' => $this->input->post('id'),
			'nama' => $this->input->post('nama'),
			'aktif' => $this->input->post('aktif'),
		);
		$this->db->insert('jabatan', $data);
		
		redirect($this->page->base_url());
	}
	
	public function update($id){
		$data = array(
			'nama' => $this->input->post('nama'),
			'aktif' => $this->input->post('aktif'),			
		);
		$this->db->where('id', $id);
		$this->db->update('jabatan', $data);
		
		redirect($this->page->base_url());
	}
	
	public function delete($id){
		$this->db->delete('jabatan', array('id' => $id));
		redirect($this->agent->referrer());
	}
	
	public function options_jabatan($id){
		$jabatan = $this->db->order_by('nama')->get('jabatan');
		return options($jabatan, 'id', $id, 'nama');
	}
	
}

/* End of file Jabatan.php */
/* Location: ./application/modules/master_data/controllers/Jabatan.php */