load->library('session'); $this->load->library('rhlib'); } function retValOrNull($val){ //especially for combo & looukup with no item selected $val = ($val=='')? null : $val; return $val; } function get_ruangan(){ $q = "SELECT * FROM v_ruangan"; $this->rhlib->jsonFromQueryWLimit($q); } function insert_ruangan(){ $dataArray = $this->getFieldsAndValues(); $ret = $this->rhlib->insertRecord('ruangan',$dataArray); return $ret; } function update_ruangan(){ $fieldsAndValues = $this->getFieldsAndValues(); //UPDATE $this->db->where('idruangan', $_POST['idruangan']); $this->db->update('ruangan', $fieldsAndValues); if($this->db->affected_rows()){ $ret["success"]=true; $ret["msg"]='Update Data Berhasil'; }else{ $ret["success"]=false; $ret["msg"]= 'Update Data Gagal'; } return $ret; } function delete_ruangan(){ $where['idruangan'] = $_POST['idruangan']; $ret = $this->rhlib->deleteRecord('ruangan',$where); return $ret; } function getFieldsAndValues(){ $dataArray = array( 'kdruangan'=> $_POST['kdruangan'], 'nmruangan'=> $_POST['nmruangan'], 'deskripsi'=> $_POST['deskripsi'], 'idjnsruangan'=> $this->retValOrNull($_POST['idjnsruangan']), 'idtiperuangan'=> $this->retValOrNull($_POST['idtiperuangan']), 'rua_idruangan'=> $this->retValOrNull($_POST['idsubruangan']), 'kapasitas'=> $_POST['kapasitas'], 'idstatus'=> $this->retValOrNull($_POST['idstatus']), 'idklpruangan'=> $this->retValOrNull($_POST['idklpruangan']), ); return $dataArray; } } ?>