load->library('session'); $this->load->library('rhlib'); require_once(APPPATH.'libraries/nusoap/nusoap.php'); //includes nusoap require_once(APPPATH.'libraries/nusoap/class.wsdlcache.php'); //includes nusoap $this->client = new nusoap_client($this->url, true); $this->proxy = $this->client->getProxy(); set_time_limit(0); } function _get_token(){ if(!empty($this->token)) return $this->token; $token = $this->proxy->GetToken($this->username, $this->password); $this->token = $token; return $token; } //process data from uploaded excel to grid function upload_excel() { $fileName = $_FILES['excelnilai']['name']; $tmpName = $_FILES['excelnilai']['tmp_name']; $fileSize = $_FILES['excelnilai']['size']; $fileType = $_FILES['excelnilai']['type']; if (strpos($fileName,'.xls') === false){ $return = array( 'success' => false, 'message' => 'sistem hanya menerima file berekstensi .xls', 'data' => array(), ); echo json_encode($return); die; } $fp = fopen($tmpName, 'r'); $content = fread($fp, filesize($tmpName)); fclose($fp); $rows = explode("\n", $content); //split whole data to row array $token = $this->_get_token(); $errors = array(); $data = array(); foreach($rows as $idx => $row) { if($idx == 0) continue; //skip the header $fields = explode("\t", $row); //split row to field data /* [0] => kdprodi [1] => kdstsemester [2] => nmkelas [3] => kode mata kuliah [4] => NIM [5] => nilai angka [6] => nilai huruf [7] => nilai indeks */ if(!empty($fields[0])){ // if data is not empty $param = array( 'kdprodi' => $fields[0], 'kdstsemester' => $fields[1], 'nmkelas' => $fields[2], 'kdmk' => $fields[3], 'nim' => str_replace("'", "", $fields[4]), 'nilai_angka' => $fields[5], 'nilai_huruf' => $fields[6], 'nilai_indeks' => $fields[7], ); $do_upload = $this->do_upload($param); if($do_upload['success']){ $data[] = $do_upload['data']; }else{ $errors[] = $do_upload['message']; } } } $return = array( 'success' => true, 'message' => 'data berhasil di export', 'data' => $data, 'errors' => $errors, ); echo json_encode($return); die; } //process insert data from grid to feeder function export_to_feeder() { $data = $this->input->post('json_nilai'); if(empty($data)){ $return = array( 'success' => false, 'message' => 'data yang dimasukkan kosong', ); echo json_encode($return); die; } $data = json_decode($data); //get id satuan pendidikan $token = $this->_get_token(); $success_all = true; $errors = array(); foreach($data as $idx => $d){ $dt = (array) $d; if($dt['is_update']){ //update the current nilai $data_input = array( 'nilai_angka' => $dt['nilai_angka'], 'nilai_huruf' => $dt['nilai_huruf'], 'nilai_indeks' => $dt['nilai_indeks'], ); $key = array( 'id_kls' => $dt['id_kls'], 'id_reg_pd' => $dt['id_reg_pd'], ); $update = array( 'key' => $key, 'data' => $data_input, ); $updated_nilai = $this->proxy->UpdateRecord($token, 'nilai', json_encode($update)); if(isset($updated_nilai['result']['error_desc']) && !empty($updated_nilai['result']['error_desc'])){ $errors[] = "gagal input nilai mahasiswa '".$dt['nm_mhs']."' : ".$updated_nilai['result']['error_desc']; $success_all = false; } } else { //insert the current nilai $insert_nilai = array( 'nilai_angka' => $dt['nilai_angka'], 'nilai_huruf' => $dt['nilai_huruf'], 'nilai_indeks' => $dt['nilai_indeks'], 'id_kls' => $dt['id_kls'], 'id_kls' => $dt['id_kls'], 'id_reg_pd' => $dt['id_reg_pd'], 'asal_data' => 9, ); $inserted_nilai = $this->proxy->InsertRecord($token, 'nilai', json_encode($insert_nilai)); if(isset($inserted_nilai['result']['error_desc']) && !empty($inserted_nilai['result']['error_desc'])){ $errors[] = "gagal input nilai mahasiswa '".$dt['nm_mhs']."' : ".$inserted_nilai['result']['error_desc']; $success_all = false; } } } $message = ""; if(!empty($errors)){ $message .= "Terjadi kesalahan :
"; foreach($errors as $idx => $error) { $message .= ($idx+1).'. '.$error.'
'; } } $return = array( 'success' => $success_all, 'message' => $message, ); echo json_encode($return); die; } function view(){ $mk = $this->_get_mk($sms['result']['id_sms'], $kdmk); print_r($mk); echo $kdmk; } //process each row of excel to row of grid function do_upload($param = array()) { extract($param); if(!isset($kdprodi) || empty($kdprodi)){ return false; } $token = $this->_get_token(); $return_data = array(); $return_data['nilai_angka'] = $nilai_angka; $return_data['nilai_huruf'] = $nilai_huruf; $return_data['nilai_indeks'] = $nilai_indeks; //get id_sms (id prodi in feeder) $sms = $this->_get_sms($kdprodi); if(!isset($sms['result']['id_sms'])){ return array('success' => false, 'data' => array(), 'message' => array('Kode Prodi '.$kdprodi.' tidak dikenali')); }else{ $return_data['id_sms'] = $sms['result']['id_sms']; } //get id_smt (id semester in feeder) $semester = $this->_get_semester($kdstsemester); if(!isset($semester['result']['id_smt'])){ return array('success' => false,'data' => array(), 'message' => array('Kode Semester '.$kdstsemester.' tidak dikenali')); }else{ $return_data['id_smt'] = $semester['result']['id_smt']; } //get id_mk (id mata kuliah in feeder) $mk = $this->_get_mk($kdmk); if(!isset($mk['result']['id_mk'])){ return array('success' => false,'data' => array(), 'message' => array('Kode Mata kuliah '.$kdmk.' tidak dikenali')); }else{ $return_data['id_mk'] = $mk['result']['id_mk']; $return_data['kd_mk'] = $kdmk; $return_data['nm_mk'] = $mk['result']['nm_mk']; } //get id_reg_pd (id mahasiswa in feeder) $mahasiswa_pt = $this->_get_mahasiswa_pt($sms['result']['id_sms'], $nim); //$sms['result']['id_sms'], if(!isset($mahasiswa_pt['result']['id_reg_pd'])){ return array('success' => false,'data' => array(), 'message' => array('Mahasiswa dengan NIM '.$nim.' tidak dikenali')); }else{ $return_data['id_reg_pd'] = $mahasiswa_pt['result']['id_reg_pd']; $return_data['nim'] = $mahasiswa_pt['result']['nipd']; $return_data['nm_mhs'] = $mahasiswa_pt['result']['nm_pd']; } //get idkelas from siak (which is namakelas in feeder) $get_idkelas = $this->db->get_where('kelas', array('kdprodi' => $kdprodi, 'idkelas' => $nmkelas))->row_array(); //get id_kls (id kelas in feeder) $kelas_kuliah = $this->_get_kelas_kuliah($get_idkelas['idkelas'], $sms['result']['id_sms'], $semester['result']['id_smt'], $mk['result']['id_mk']); if(!isset($kelas_kuliah['result']['id_kls'])){ return array('success' => false,'data' => array(), 'message' => array('Kelas Kuliah '.$nmkelas.' tidak dikenali')); }else{ $return_data['id_kls'] = $kelas_kuliah['result']['id_kls']; $return_data['nm_kelas'] = $nmkelas; } //get nilai (if any), then update if. if nilai is not exist then add new one. $filter_nilai = "p.id_kls = '".$kelas_kuliah['result']['id_kls']."' and p.id_reg_pd = '".$mahasiswa_pt['result']['id_reg_pd']."'"; $nilai = $this->proxy->GetRecord($token, 'nilai', $filter_nilai); if(!isset($nilai['result']['id_kls'])){ $return_data['is_update'] = false; }else{ $return_data['is_update'] = true; } return array('success' => true,'data' => $return_data, 'message' => ''); } function _get_sms($kdprodi = '') { $token = $this->_get_token(); if(isset($this->sms[$kdprodi])){ return $this->sms[$kdprodi]; } $filter_prodi = "kode_prodi = '".$kdprodi."' and id_sp = '".$this->id_sp."'"; //and id_sp = '".$this->id_sp."' $sms = $this->proxy->GetRecord($token, 'sms', $filter_prodi); $this->sms[$kdprodi] = $sms; return $sms; } function _get_semester($kdstsemester){ $token = $this->_get_token(); if(isset($this->semester[$kdstsemester])){ return $this->semester[$kdstsemester]; } $filter_semester = "id_smt = '".$kdstsemester."'"; $semester = $this->proxy->GetRecord($token, 'semester', $filter_semester); $this->semester[$kdstsemester] = $semester; return $semester; } function _get_mk($kdmk){ $token = $this->_get_token(); foreach($this->mk as $idx => $matakuliah){ if($matakuliah['id_sms'] == $id_sms && $matakuliah['kdmk'] == $kdmk){ return $this->mk[$idx]['data']; } } //$filter_mk = "id_sms = '".$id_sms."' and kode_mk = '".$kdmk."'"; $filter_mk = "kode_mk = '".$kdmk."'"; $mk = $this->proxy->GetRecord($token, 'mata_kuliah', $filter_mk); $this->mk[] = array( 'id_sms' => $id_sms, 'kdmk' => $kdmk, 'data' => $mk, ); return $mk; } function _get_mahasiswa_pt($id_sms, $nim){ $token = $this->_get_token(); foreach($this->mahasiswa_pt as $idx => $mahasiswa_pt){ if($mahasiswa_pt['id_sms'] == $id_sms && $mahasiswa_pt['nim'] == $nim){ return $this->mahasiswa_pt[$idx]['data']; } } $filter_mahasiswa_pt = "p.id_sms = '".$id_sms."' and trim(nipd) = '".$nim."'"; $mahasiswa_pt = $this->proxy->GetRecord($token, 'mahasiswa_pt', $filter_mahasiswa_pt); $this->mahasiswa_pt[] = array( 'id_sms' => $id_sms, 'nim' => $nim, 'data' => $mahasiswa_pt, ); return $mahasiswa_pt; } function _get_kelas_kuliah($idkelas, $id_sms, $id_smt, $id_mk){ $token = $this->_get_token(); foreach($this->kelas_kuliah as $idx => $kelas_kuliah){ if($kelas_kuliah['idkelas'] == $idkelas && $kelas_kuliah['id_sms'] == $id_sms && $kelas_kuliah['id_smt'] == $id_smt && $kelas_kuliah['id_mk'] == $id_mk){ return $this->kelas_kuliah[$idx]['data']; } } $filter_kelas_kuliah = "trim(nm_kls) = '".$idkelas."' and p.id_sms = '".$id_sms."' and p.id_smt = '".$id_smt."' and p.id_mk= '".$id_mk."'"; $kelas_kuliah = $this->proxy->GetRecord($token, 'kelas_kuliah', $filter_kelas_kuliah); $this->kelas_kuliah[] = array( 'idkelas' => $idkelas, 'id_sms' => $id_sms, 'id_smt' => $id_smt, 'id_mk' => $id_mk, 'data' => $kelas_kuliah, ); return $kelas_kuliah; } } ?>