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_klsmhs(){ $q = "SELECT a.*,b.nmjnskls,c.nmstatus FROM klsmhs a LEFT JOIN jkls b ON b.idjnskls=a.idjnskls LEFT JOIN status c ON c.idstatus=a.idstatus"; $this->rhlib->jsonFromQueryWLimit($q); } function insert_klsmhs(){ $dataArray = $this->getFieldsAndValues(); $ret = $this->rhlib->insertRecord('klsmhs',$dataArray); $this->rhlib->insertRecordPublic('klsmhs',$dataArray); return $ret; } function update_klsmhs(){ $fieldsAndValues = $this->getFieldsAndValues(); unset($fieldsAndValues['idklsmhs']); //UPDATE $where['idklsmhs'] = $_POST['idklsmhs']; $this->db->where('idklsmhs', $_POST['idklsmhs']); $this->db->update('klsmhs', $fieldsAndValues); if($this->db->affected_rows()){ $ret["success"]=true; $ret["msg"]='Update Data Berhasil'; $this->rhlib->updateRecordPublic('klsmhs',$fieldsAndValues,$where); }else{ $ret["success"]=false; $ret["msg"]= 'Update Data Gagal'; } return $ret; } function delete_klsmhs(){ $where['idklsmhs'] = $_POST['idklsmhs']; $ret = $this->rhlib->deleteRecord('klsmhs',$where); $this->rhlib->deleteRecordPublic('klsmhs',$where); return $ret; } function getFieldsAndValues(){ $dataArray = array( 'idklsmhs'=> $this->autoNumber('idklsmhs','klsmhs'), 'kdklsmhs'=> $_POST['kdklsmhs'], 'nmklsmhs'=> $_POST['nmklsmhs'], 'deskripsi'=> $_POST['deskripsi'], 'idjnskls'=> $_POST['idjnskls'], 'idstatus'=> $_POST['idstatus'] ); return $dataArray; } } ?>