copy dari repo om Irfan
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
defined('BASEPATH') or exit('No direct script access allowed');
|
||||
|
||||
class ManageTeknisi extends CI_Controller
|
||||
{
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->load->model('ModelTeknisi', 'MT');
|
||||
$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("Authority");
|
||||
} elseif ($jabatan != "ADMIN") {
|
||||
redirect("Authority");
|
||||
}
|
||||
|
||||
$datTeknisi = $this->MT->getDataTeknisi();
|
||||
|
||||
$data = [
|
||||
'sidebar' => "data master service",
|
||||
'navChild' => "data master teknisi",
|
||||
'teknisi' => $datTeknisi
|
||||
];
|
||||
|
||||
$this->load->view('master/Teknisi', $data);
|
||||
}
|
||||
|
||||
public function save()
|
||||
{
|
||||
$method = $this->input->post('method');
|
||||
$id_teknisi = $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_TEKNISI' => $nama
|
||||
|
||||
];
|
||||
|
||||
if ($method === 'add') {
|
||||
$action = $this->MT->create('teknisi', $input);
|
||||
} else if ($method === 'edit') {
|
||||
$action = $this->MT->update('teknisi', $input, 'ID_TEKNISI', $id_teknisi);
|
||||
}
|
||||
|
||||
if ($action) {
|
||||
$this->session->set_flashdata('flash', 'ditambah');
|
||||
redirect('ManageTeknisi');
|
||||
} else {
|
||||
$this->session->set_flashdata('flashgagal', 'ditambah');
|
||||
redirect('ManageTeknisi');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function hapus()
|
||||
{
|
||||
$id = $this->input->post('id');
|
||||
if ($this->MT->delete('teknisi', $id, 'ID_TEKNISI')) {
|
||||
$this->session->set_flashdata('flash', 'dihapus');
|
||||
redirect('ManageTeknisi');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user