load->library('session'); $this->load->library('rhlib'); } function autoNumber($column,$tbl){ $q = "SELECT max(".$column.")+1 as max FROM ".$tbl."" ; $query = $this->db->query($q); $max = ''; if ($query->num_rows() != 0) { $row = $query->row(); $max=$row->max; } if ($max == null){ $max=0; } return $max; } function retValOrNull($val){ //especially for combo & looukup with no item selected $val = ($val=='')? null : $val; return $val; } function get_bebanstudi(){ $q = "SELECT * FROM bebanstudi ORDER BY ipmin"; $this->rhlib->jsonFromQueryWLimit($q); } function insert_bebanstudi(){ $dataArray = $this->getFieldsAndValues(); $ret = $this->rhlib->insertRecord('bebanstudi',$dataArray); return $ret; } function update_bebanstudi(){ $fieldsAndValues = $this->getFieldsAndValues(); //UPDATE $this->db->where('idbebanstudi', $_POST['idbebanstudi']); $this->db->update('bebanstudi', $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_bebanstudi(){ $where['idbebanstudi'] = $_POST['idbebanstudi']; $ret = $this->rhlib->deleteRecord('bebanstudi',$where); return $ret; } function getFieldsAndValues(){ $dataArray = array( 'idbebanstudi'=> ($_POST['idbebanstudi']) ? $_POST['idbebanstudi']:$this->autoNumber('idbebanstudi','bebanstudi'), 'ipmin'=> $_POST['ipmin'], 'ipmax'=> $_POST['ipmax'], 'sksmin'=> $_POST['sksmin'], 'sksmax'=> $_POST['sksmax'] ); return $dataArray; } } ?>