copy dari repo om Irfan
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
defined('BASEPATH') or exit('No direct script access allowed');
|
||||
|
||||
class ManageJabatan extends CI_Controller
|
||||
{
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->load->model('JabatanModel', 'JabatanM');
|
||||
$this->load->library(['datatables', 'form_validation']);
|
||||
$this->form_validation->set_error_delimiters('', '');
|
||||
}
|
||||
public function output_json($data, $encode = true)
|
||||
{
|
||||
if ($encode) $data = json_encode($data);
|
||||
$this->output->set_content_type('application/json')->set_output($data);
|
||||
}
|
||||
public function index()
|
||||
{
|
||||
$username = $this->session->userdata('username');
|
||||
$jabatan = $this->session->userdata('jabatan');
|
||||
if ($username == null) {
|
||||
redirect("Action");
|
||||
} elseif ($jabatan != "ADMIN") {
|
||||
redirect("Action");
|
||||
}
|
||||
|
||||
$datJabatan = $this->JabatanM->getDataJabatan();
|
||||
|
||||
$data = [
|
||||
'sidebar' => "data master",
|
||||
'navChild' => "data jabatan",
|
||||
'jabatan' => $datJabatan
|
||||
];
|
||||
|
||||
$this->load->view('karyawan/table-jabatan', $data);
|
||||
}
|
||||
|
||||
public function save()
|
||||
{
|
||||
$method = $this->input->post('method');
|
||||
$id_jabatan = $this->input->post('id');
|
||||
$nama = $this->input->post('nama');
|
||||
|
||||
$this->form_validation->set_rules('nama', 'Nama', 'required');
|
||||
if ($this->form_validation->run() == FALSE) {
|
||||
$data = [
|
||||
'status' => false,
|
||||
'errors' => [
|
||||
'nama' => form_error('nama')
|
||||
|
||||
]
|
||||
];
|
||||
$this->output_json($data);
|
||||
} else {
|
||||
|
||||
$input = [
|
||||
'NAMA_JABATAN' => $nama
|
||||
|
||||
];
|
||||
|
||||
if ($method === 'add') {
|
||||
$action = $this->JabatanM->create('jabatan', $input);
|
||||
} else if ($method === 'edit') {
|
||||
$action = $this->JabatanM->update('jabatan', $input, 'ID_JABATAN', $id_jabatan);
|
||||
}
|
||||
|
||||
if ($action) {
|
||||
if ($method === 'add') {
|
||||
$this->output_json(['status' => true]);
|
||||
} else if ($method === 'edit') {
|
||||
redirect('ManageJabatan');
|
||||
}
|
||||
} else {
|
||||
$this->output_json(['status' => false]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function hapus()
|
||||
{
|
||||
$id = $this->input->post('id');
|
||||
if ($this->JabatanM->delete('jabatan', $id, 'ID_jabatan')) {
|
||||
redirect('ManageJabatan');
|
||||
}
|
||||
}
|
||||
|
||||
// public function add(){
|
||||
// $username = $this->session->userdata('username');
|
||||
// if ($username == null){
|
||||
// redirect("Action");
|
||||
// }
|
||||
|
||||
// $this->load->view('tambah-user');
|
||||
// }
|
||||
}
|
||||
Reference in New Issue
Block a user