copy dari repo om Irfan
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
defined('BASEPATH') or exit('No direct script access allowed');
|
||||
|
||||
class ManageMonitor extends CI_Controller
|
||||
{
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->load->model('ModelMonitor', 'MMonitor');
|
||||
$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");
|
||||
}
|
||||
|
||||
$datMonitor = $this->MMonitor->getDataMonitor();
|
||||
|
||||
$data = [
|
||||
'sidebar' => "data list",
|
||||
'navChild' => "data list monitor",
|
||||
'monitor' => $datMonitor
|
||||
];
|
||||
|
||||
$this->load->view('list/table-listmonitor', $data);
|
||||
}
|
||||
|
||||
public function save()
|
||||
{
|
||||
$method = $this->input->post('method');
|
||||
$id_processor = $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_MONITOR' => $nama
|
||||
|
||||
];
|
||||
|
||||
if ($method === 'add') {
|
||||
$action = $this->MMonitor->create('monitor', $input);
|
||||
} else if ($method === 'edit') {
|
||||
$action = $this->MMonitor->update('monitor', $input, 'ID_MONITOR', $id_monitor);
|
||||
}
|
||||
|
||||
if ($action) {
|
||||
if ($method === 'add') {
|
||||
$this->output_json(['status' => true]);
|
||||
} else if ($method === 'edit') {
|
||||
redirect('ManageMonitor');
|
||||
}
|
||||
} else {
|
||||
$this->output_json(['status' => false]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function hapus()
|
||||
{
|
||||
$id = $this->input->post('id');
|
||||
if ($this->MMonitor->delete('monitor', $id, 'ID_MONITOR')) {
|
||||
redirect('ManageMonitor');
|
||||
}
|
||||
}
|
||||
|
||||
// public function add(){
|
||||
// $username = $this->session->userdata('username');
|
||||
// if ($username == null){
|
||||
// redirect("Action");
|
||||
// }
|
||||
|
||||
// $this->load->view('tambah-user');
|
||||
// }
|
||||
}
|
||||
Reference in New Issue
Block a user