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_jkelas(){ $q = "SELECT * FROM jkls ORDER BY kdjnskls"; $this->rhlib->jsonFromQueryWLimit($q); } function insert_jkelas(){ $dataArray = $this->getFieldsAndValues(); $ret = $this->rhlib->insertRecord('jkls',$dataArray); $this->rhlib->insertRecordPublic('jkls',$dataArray); return $ret; } function update_jkelas(){ $fieldsAndValues = $this->getFieldsAndValues(); //UPDATE $where['idjnskls'] = $_POST['idjnskls']; $this->db->where('idjnskls', $_POST['idjnskls']); $this->db->update('jkls', $fieldsAndValues); if($this->db->affected_rows()){ $ret["success"]=true; $ret["msg"]='Update Data Berhasil'; $this->rhlib->updateRecordPublic('jkls',$fieldsAndValues,$where); }else{ $ret["success"]=false; $ret["msg"]= 'Update Data Gagal'; } return $ret; } function delete_jkelas(){ $where['idjnskls'] = $_POST['idjnskls']; $ret = $this->rhlib->deleteRecord('jkls',$where); $this->rhlib->deleteRecordPublic('jkls',$where); return $ret; } function getFieldsAndValues(){ $dataArray = array( 'idjnskls'=> $this->autoNumber('idjnskls','jkls'), 'kdjnskls'=> $_POST['kdjnskls'], 'nmjnskls'=> $_POST['nmjnskls'], 'deskripsi'=> $_POST['deskripsi'] ); return $dataArray; } } ?>