90 lines
2.1 KiB
PHP
90 lines
2.1 KiB
PHP
<?php
|
|
defined('BASEPATH') or exit('No direct script access allowed');
|
|
|
|
class ManageOperator extends CI_Controller
|
|
{
|
|
function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->load->model('ModelOperator', 'MO');
|
|
$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()
|
|
{
|
|
|
|
$datOperator = $this->MO->getDataOperator();
|
|
|
|
$data = [
|
|
'sidebar' => "data master service",
|
|
'navChild' => "data master operator",
|
|
'operator' => $datOperator
|
|
];
|
|
|
|
$this->load->view('master/Operator', $data);
|
|
}
|
|
|
|
public function save()
|
|
{
|
|
$method = $this->input->post('method');
|
|
$id_operator = $this->input->post('id');
|
|
$id_teknisi = $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_OPERATOR' => $nama
|
|
|
|
];
|
|
|
|
$inputteknisi = [
|
|
'NAMA_TEKNISI' => $nama
|
|
|
|
];
|
|
|
|
if ($method === 'add') {
|
|
$action = $this->MO->create('operator', $input);
|
|
$actionteknisi = $this->MO->create('teknisi', $inputteknisi);
|
|
} else if ($method === 'edit') {
|
|
$action = $this->MO->update('operator', $input, 'ID_OPERATOR', $id_operator);
|
|
$actionteknisi = $this->MO->update('teknisi', $inputteknisi, 'ID_TEKNISI', $id_teknisi);
|
|
}
|
|
|
|
if ($action) {
|
|
$this->session->set_flashdata('flash', 'ditambah');
|
|
redirect('ManageOperator');
|
|
} else {
|
|
$this->session->set_flashdata('flashgagal', 'ditambah');
|
|
redirect('ManageOperator');
|
|
}
|
|
}
|
|
}
|
|
|
|
public function hapus()
|
|
{
|
|
$id = $this->input->post('id');
|
|
if ($this->MO->delete('operator', $id, 'ID_OPERATOR')) {
|
|
$action = $this ->MO->delete('teknisi',$id,'ID_TEKNISI');
|
|
$this->session->set_flashdata('flash', 'dihapus');
|
|
redirect('ManageOperator');
|
|
}
|
|
}
|
|
|
|
}
|