97 lines
2.3 KiB
PHP
97 lines
2.3 KiB
PHP
<?php
|
|
defined('BASEPATH') or exit('No direct script access allowed');
|
|
|
|
class ManageDistributor extends CI_Controller
|
|
{
|
|
function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->load->model('ModelDistributor','MDistributor');
|
|
$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");
|
|
}
|
|
|
|
$datDistributor = $this->MDistributor->getDataDistributor();
|
|
|
|
$data = [
|
|
'sidebar' => "data list 2",
|
|
'navChild' => "data list distributor",
|
|
'distributor' => $datDistributor
|
|
];
|
|
|
|
$this->load->view('list/table-listdistributor', $data);
|
|
}
|
|
|
|
public function save()
|
|
{
|
|
$method = $this->input->post('method');
|
|
$id_distributor = $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_DISTRIBUTOR' => $nama
|
|
|
|
];
|
|
|
|
if ($method === 'add') {
|
|
$action = $this->MDistributor->create('distributor', $input);
|
|
} else if ($method === 'edit') {
|
|
$action = $this->MDistributor->update('distributor', $input, 'ID_DISTRIBUTOR', $id_distributor);
|
|
}
|
|
|
|
if ($action) {
|
|
if ($method === 'add') {
|
|
$this->output_json(['status' => true]);
|
|
} else if ($method === 'edit') {
|
|
redirect('ManageDistributor');
|
|
}
|
|
} else {
|
|
$this->output_json(['status' => false]);
|
|
}
|
|
}
|
|
}
|
|
|
|
public function hapus()
|
|
{
|
|
$id = $this->input->post('id');
|
|
if ($this->MDistributor->delete('distributor', $id, 'ID_DISTRIBUTOR')) {
|
|
redirect('ManageDistributor');
|
|
}
|
|
}
|
|
|
|
// public function add(){
|
|
// $username = $this->session->userdata('username');
|
|
// if ($username == null){
|
|
// redirect("Action");
|
|
// }
|
|
|
|
// $this->load->view('tambah-user');
|
|
// }
|
|
}
|