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_fakultas(){ $q = "SELECT * FROM fakultas"; $this->rhlib->jsonFromQueryWLimit($q); } function get_pt(){ $q = "SELECT kdpt, nmpt FROM pt"; $query = $this->db->query($q); $data = array(); $build_array = array ("success"=>false,"results"=>0,"data"=>array(),"msg"=>"no data"); if ($query->num_rows() > 0) { $data = $query->result(); $ttl = count($data); if($ttl > 0){ $build_array["success"]=true; $build_array["results"]=$ttl; $build_array["data"]=$data; $build_array["msg"]= ""; } } echo json_encode($build_array); } function insert_fakultas(){ $dataArray = $this->getFieldsAndValues(); $ret = $this->rhlib->insertRecord('fakultas',$dataArray); $this->rhlib->insertRecordPublic('fakultas',$dataArray); return $ret; } function update_fakultas(){ $dataArray = $this->getFieldsAndValues(); //UPDATE $where['kdfakultas'] = $_POST['kdfakultas']; $this->db->where('kdfakultas', $_POST['kdfakultas']); $this->db->update('fakultas', $dataArray); if($this->db->affected_rows()){ $ret["success"]=true; $ret["msg"]='Update Data Berhasil'; $this->rhlib->updateRecordPublic('fakultas',$dataArray,$where); }else{ $ret["success"]=false; $ret["msg"]= 'Update Data Gagal'; } return $ret; } function delete_fakultas(){ $where['kdfakultas'] = $_POST['kdfakultas']; $ret = $this->rhlib->deleteRecord('fakultas',$where); $this->rhlib->deleteRecordPublic('fakultas',$where); return $ret; } function getFieldsAndValues(){ $dataArray = array( 'kdpt'=> $_POST['kdpt'], 'kdfakultas'=> $_POST['kdfakultas'], 'nmfakultas'=> $_POST['nmfakultas'], 'nmfakultasskt'=> $_POST['nmfakultasskt'], 'deskripsi'=> $_POST['deskripsi'], ); return $dataArray; } } ?>