129 lines
4.3 KiB
PHP
129 lines
4.3 KiB
PHP
<?php
|
|
class M_laboratorium extends CI_Model {
|
|
|
|
function index() {
|
|
$query = $this->db->get('master_laboratorium');
|
|
return $query->result();
|
|
}
|
|
|
|
function status() {
|
|
$this->db->where('ml_status', 1);
|
|
$query = $this->db->get('master_laboratorium');
|
|
return $query->result();
|
|
}
|
|
|
|
function statusdetail() {
|
|
$this->db->join('master_laboratorium', 'master_laboratorium.ml_id = master_laboratorium_detail.mld_ml_id','left');
|
|
$this->db->order_by('ml_nama', 'ASC');
|
|
$this->db->order_by('mld_nama', 'ASC');
|
|
$this->db->where('mld_status', 1);
|
|
$query = $this->db->get('master_laboratorium_detail');
|
|
return $query->result();
|
|
}
|
|
|
|
function insert() {
|
|
$insert = array(
|
|
'ml_nama' => $this->input->post('nama'),
|
|
'ml_keterangan' => $this->input->post('keterangan'),
|
|
'ml_status' => 1,
|
|
);
|
|
$insert = $this->db->insert('master_laboratorium', $insert);
|
|
$id = $this->db->insert_id();
|
|
|
|
$status = $_POST['statusdetail'];$num=0;
|
|
foreach($status as $key =>$datanya)
|
|
{
|
|
$insert_data = array(
|
|
'mld_nama' => $_POST['detail'][$num],
|
|
'mld_keterangan' => $_POST['ket'][$num],
|
|
'mld_status' => $_POST['statusdetail'][$num],
|
|
'mld_ml_id' => $id,
|
|
);
|
|
$insert = $this->db->insert('master_laboratorium_detail', $insert_data);
|
|
|
|
$num++;
|
|
}
|
|
}
|
|
|
|
function edit($id) {
|
|
$this->db->where('ml_id', $id);
|
|
$query = $this->db->get('master_laboratorium');
|
|
return $query;
|
|
}
|
|
|
|
function editdetail($id) {
|
|
$this->db->where('mld_ml_id', $id);
|
|
$query = $this->db->get('master_laboratorium_detail');
|
|
return $query->result();
|
|
}
|
|
|
|
function prosesedit() {
|
|
$update = array(
|
|
'ml_nama' => $this->input->post('nama'),
|
|
'ml_keterangan' => $this->input->post('keterangan'),
|
|
);
|
|
$id = $this->input->post('id');
|
|
$this->db->where('ml_id', $id);
|
|
$this->db->update('master_laboratorium', $update);
|
|
|
|
$status = $_POST['statusdetail'];$num=0;
|
|
foreach($status as $key =>$datanya)
|
|
{
|
|
$data = array(
|
|
'mld_nama' => $_POST['detail'][$num],
|
|
'mld_keterangan' => $_POST['ket'][$num],
|
|
'mld_status' => $_POST['statusdetail'][$num],
|
|
'mld_ml_id' => $id,
|
|
);
|
|
if($_POST['baru'][$num]=="2"){
|
|
$this->db->where('mld_id', $_POST['iddetail'][$num]);
|
|
$this->db->update('master_laboratorium_detail', $data);
|
|
}else{
|
|
$insert = $this->db->insert('master_laboratorium_detail', $data);
|
|
}
|
|
$num++;
|
|
}
|
|
}
|
|
|
|
function delete($id) {
|
|
$this->db->where('ml_id', $id);
|
|
$this->db->delete('master_laboratorium');
|
|
|
|
$this->db->where('mld_ml_id', $id);
|
|
$this->db->delete('master_laboratorium_detail');
|
|
}
|
|
|
|
function deletedetail($id) {
|
|
$this->db->where('mld_id', $id);
|
|
$this->db->delete('master_laboratorium_detail');
|
|
}
|
|
|
|
function disabled($id) {
|
|
$update_data = array(
|
|
'ml_status' => 0,
|
|
);
|
|
$this->db->where('ml_id', $id);
|
|
$this->db->update('master_laboratorium', $update_data);
|
|
|
|
$update_data_detail = array(
|
|
'mld_status' => 0,
|
|
);
|
|
$this->db->where('mld_ml_id', $id);
|
|
$this->db->update('master_laboratorium_detail', $update_data_detail);
|
|
}
|
|
|
|
function aktif($id) {
|
|
$update_data = array(
|
|
'ml_status' => 1,
|
|
);
|
|
$this->db->where('ml_id', $id);
|
|
$this->db->update('master_laboratorium', $update_data);
|
|
|
|
$update_data_detail = array(
|
|
'mld_status' => 1,
|
|
);
|
|
$this->db->where('mld_ml_id', $id);
|
|
$this->db->update('master_laboratorium_detail', $update_data_detail);
|
|
}
|
|
}
|
|
?>
|