81 lines
1.8 KiB
PHP
81 lines
1.8 KiB
PHP
<?php
|
|
defined('BASEPATH') or exit('No direct script access allowed');
|
|
|
|
class ManageKurir extends CI_Controller
|
|
{
|
|
function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->load->model('ModelKurir', 'MK');
|
|
$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()
|
|
{
|
|
|
|
$datKurir = $this->MK->getDataKurir();
|
|
|
|
$data = [
|
|
'sidebar' => "data master license",
|
|
'navChild' => "data master kurir",
|
|
'kurir' => $datKurir
|
|
];
|
|
|
|
$this->load->view('master/Kurir', $data);
|
|
}
|
|
|
|
public function save()
|
|
{
|
|
$method = $this->input->post('method');
|
|
$id_kurir = $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_KURIR' => $nama
|
|
|
|
];
|
|
|
|
if ($method === 'add') {
|
|
$action = $this->MK->create('kurir', $input);
|
|
} else if ($method === 'edit') {
|
|
$action = $this->MK->update('kurir', $input, 'ID_KURIR', $id_kurir);
|
|
}
|
|
|
|
if ($action) {
|
|
$this->session->set_flashdata('flash', 'ditambah');
|
|
redirect('ManageKurir');
|
|
} else {
|
|
$this->session->set_flashdata('flashgagal', 'ditambah');
|
|
redirect('ManageKurir');
|
|
}
|
|
}
|
|
}
|
|
|
|
public function hapus()
|
|
{
|
|
$id = $this->input->post('id');
|
|
if ($this->MK->delete('kurir', $id, 'ID_KURIR')) {
|
|
$this->session->set_flashdata('flash', 'dihapus');
|
|
redirect('ManageKurir');
|
|
}
|
|
}
|
|
|
|
}
|