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 ManageSp extends CI_Controller
|
||||
{
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->load->model('ModelSp', 'MSp');
|
||||
$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");
|
||||
}
|
||||
|
||||
$datSp = $this->MSp->getDataSp();
|
||||
|
||||
$data = [
|
||||
'sidebar' => "data master sku",
|
||||
'navChild' => "data master sp",
|
||||
'sp' => $datSp
|
||||
];
|
||||
|
||||
$this->load->view('master/SerialParalel', $data);
|
||||
}
|
||||
|
||||
public function save()
|
||||
{
|
||||
$method = $this->input->post('method');
|
||||
$id_sp = $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_SP' => $nama
|
||||
|
||||
];
|
||||
|
||||
if ($method === 'add') {
|
||||
$action = $this->MSp->create('sp', $input);
|
||||
} else if ($method === 'edit') {
|
||||
$action = $this->MSp->update('sp', $input, 'ID_SP', $id_sp);
|
||||
}
|
||||
|
||||
if ($action) {
|
||||
$this->session->set_flashdata('flash', 'ditambah');
|
||||
redirect('ManageSp');
|
||||
} else {
|
||||
$this->session->set_flashdata('flashgagal', 'ditambah');
|
||||
redirect('ManageSp');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function hapus()
|
||||
{
|
||||
$id = $this->input->post('id');
|
||||
if ($this->MSp->delete('sp', $id, 'ID_SP')) {
|
||||
$this->session->set_flashdata('flash', 'dihapus');
|
||||
redirect('ManageSp');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user