Files
shopee-apps/application/delete/controllers/ManageBarangBackup.php
T
2026-06-13 16:02:07 +10:00

160 lines
4.7 KiB
PHP

<?php
defined('BASEPATH') or exit('No direct script access allowed');
class ManageBarang extends CI_Controller
{
function __construct()
{
parent::__construct();
$this->load->model('ModelBarang', 'MBarang');
$this->load->model('ModelType', 'MType');
$this->load->model('ModelProcessor', 'MProcessor');
$this->load->model('ModelRam', 'MRam');
$this->load->model('ModelHarddisk', 'MHarddisk');
$this->load->model('ModelSsd', 'MSsd');
$this->load->model('ModelOs', 'MOs');
$this->load->model('ModelVga', 'MVga');
$this->load->model('ModelMonitor', 'MMonitor');
$this->load->model('ModelWarna', 'MWarna');
$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");
}
$datBarang = $this->MBarang->getNamaBarang();
$data = [
'sidebar' => "data list 3",
'navChild' => "data list barang",
'barang' => $datBarang
];
$this->load->view('barang/table-barang', $data);
}
public function add()
{
$username = $this->session->userdata('username');
if ($username == null) {
redirect("Login");
}
$datBarang = $this->MBarang->getDataBarang();
$datType = $this->MType->getDataType();
$datProcessor = $this->MProcessor->getDataProcessor();
$datRam = $this->MRam->getDataRam();
$datHarddisk = $this->MHarddisk->getDataHarddisk();
$datSsd = $this->MSsd->getDataSsd();
$datOs = $this->MOs->getDataOs();
$datVga = $this->MVga->getDataVga();
$datMonitor = $this->MMonitor->getDataMonitor();
$datWarna = $this->MWarna->getDataWarna();
$data = [
'sidebar' => "data list 3",
'navChild' => "data list barang",
'barang' => $datBarang,
'type' => $datType,
'processor' => $datProcessor,
'ram' => $datRam,
'hdd' => $datHarddisk,
'ssd' => $datSsd,
'os' => $datOs,
'vga' => $datVga,
'monitor' => $datMonitor,
'warna' => $datWarna
];
//var_dump($data);
$this->load->view('barang/barang-tambah', $data);
}
public function save()
{
$method = $this->input->post('method');
$id_barang = $this->input->post('id');
$type = $this->input->post('TYPE');
$processor = $this->input->post('PROCESSOR');
$ram = $this->input->post('RAM');
$hdd = $this->input->post('HDD');
$ssd = $this->input->post('SSD');
$os = $this->input->post('OS');
$vga = $this->input->post('VGA');
$monitor = $this->input->post('MONITOR');
$warna = $this->input->post('WARNA');
$this->form_validation->set_rules('TYPE', 'Pilih Type', 'required');
$this->form_validation->set_rules('PROCESSOR', 'Pilih Processor', 'required');
$this->form_validation->set_rules('RAM', 'Pilih RAM', 'required');
$this->form_validation->set_rules('HDD', 'Pilih HDD', 'required');
$this->form_validation->set_rules('SSD', 'Pilih SSD', 'required');
$this->form_validation->set_rules('OS', 'Pilih OS', 'required');
$this->form_validation->set_rules('VGA', 'Pilih VGA', 'required');
$this->form_validation->set_rules('MONITOR', 'Pilih Monitor', 'required');
$this->form_validation->set_rules('WARNA', 'Pilih Warna', 'required');
if ($this->form_validation->run() == FALSE) {
$data = [
'status' => false,
'errors' => [
'TYPE' => form_error('TYPE'),
'PROCESSOR' => form_error('PROCESSOR'),
'RAM' => form_error('RAM'),
'HDD' => form_error('HDD'),
'SSD' => form_error('SSD'),
'OS' => form_error('OS'),
'VGA' => form_error('VGA'),
'MONITOR' => form_error('MONITOR'),
'WARNA' => form_error('WARNA')
]
];
$this->output_json($data);
} else {
$input = [
'ID_TYPE' => $type,
'ID_PROCESSOR' => $processor,
'ID_RAM' => $ram,
'ID_HDD' => $hdd,
'ID_SSD' => $ssd,
'ID_OS' => $os,
'ID_VGA' => $vga,
'ID_MONITOR' => $monitor,
'ID_WARNA' => $warna
];
$action = $this->MBarang->create('barang', $input);
if ($action) {
$this->session->set_flashdata('flash', 'ditambah');
//$this->output_json(['status' => true]);
redirect('ManageBarang');
} else {
$this->session->set_flashdata('flashgagal', 'ditambah');
//$this->output_json(['status' => true]);
redirect('ManageBarang');
}
}
}
public function hapus()
{
$id = $this->input->post('id');
if ($this->MBarang->delete('barang', $id, 'ID_BARANG')) {
$this->session->set_flashdata('flash', 'dihapus');
redirect('ManageBarang');
}
}
}