88 lines
2.0 KiB
PHP
88 lines
2.0 KiB
PHP
<?php
|
|
defined('BASEPATH') or exit('No direct script access allowed');
|
|
|
|
class ManageHarddisk extends CI_Controller
|
|
{
|
|
function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->load->model('ModelHarddisk', 'MHarddisk');
|
|
$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");
|
|
}
|
|
|
|
$datHarddisk = $this->MHarddisk->getDataHarddisk();
|
|
|
|
$data = [
|
|
'sidebar' => "data master sku",
|
|
'navChild' => "data master harddisk",
|
|
'hdd' => $datHarddisk
|
|
];
|
|
|
|
$this->load->view('master/Harddisk', $data);
|
|
}
|
|
|
|
public function save()
|
|
{
|
|
$method = $this->input->post('method');
|
|
$id_hdd = $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_HDD' => $nama
|
|
|
|
];
|
|
|
|
if ($method === 'add') {
|
|
$action = $this->MHarddisk->create('hdd', $input);
|
|
} else if ($method === 'edit') {
|
|
$action = $this->MHarddisk->update('hdd', $input, 'ID_HDD', $id_hdd);
|
|
}
|
|
|
|
if ($action) {
|
|
$this->session->set_flashdata('flash', 'ditambah');
|
|
redirect('ManageHarddisk');
|
|
} else {
|
|
$this->session->set_flashdata('flashgagal', 'ditambah');
|
|
redirect('ManageHarddisk');
|
|
}
|
|
}
|
|
}
|
|
|
|
public function hapus()
|
|
{
|
|
$id = $this->input->post('id');
|
|
if ($this->MHarddisk->delete('hdd', $id, 'ID_HDD')) {
|
|
$this->session->set_flashdata('flash', 'dihapus');
|
|
redirect('ManageHarddisk');
|
|
}
|
|
}
|
|
|
|
}
|