load->library('session');
$this->load->library('phpexcelreader');
//$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(){
$token = $this->proxy->GetToken($this->username, $this->password);
return $token;
}
function upload_excel()
{
$fileName = $_FILES['excelmahasiswa']['name'];
$tmpName = $_FILES['excelmahasiswa']['tmp_name'];
$fileSize = $_FILES['excelmahasiswa']['size'];
$fileType = $_FILES['excelmahasiswa']['type'];
if (strpos($fileName,'.xls') !== false) {
//upload
$config['upload_path'] = './uploads/';
//$config['allowed_types'] = 'xls|xlsx';
$config['allowed_types'] = '*';
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload('excelmahasiswa'))
{
print_r($this->upload->display_errors());
$errors = implode('
', $this->upload->display_errors());
$return = array(
'success' => false,
'message' => 'terjadi kesalahan.
'.$errors,
'data' => array(),
);
echo json_encode($return);
die;
}
else{
$content = array('upload_data' => $this->upload->data());
$full_path = './uploads/'.$content['upload_data']['file_name'];
$this->phpexcelreader->read($full_path);
$sheets = $this->phpexcelreader->sheets;
$sheet = $sheets[0];
$cells = $sheet['cells'];
$data = array();
if(!empty($cells))
{
$token = $this->_get_token();
foreach($cells as $idx => $cell)
{
if($idx <= 7) continue;
//get mahasiswa pt
$id_pd = '';
$id_reg_pd = '';
$check_nim = $this->proxy->GetRecord($token, 'mahasiswa_pt', "'".$cell[2]."' = trim(both ' ' from nipd)");
if(!empty($check_nim['result']['id_reg_pd'])){
$id_pd = $check_nim['result']['id_pd'];
$id_reg_pd = $check_nim['result']['id_reg_pd'];
}
//status mahasiswa
$status = strtoupper($cell[5]);
/*
1: LULUS
2: MUTASI
3: DIKELUARKAN
4: MENGUNDURKAN DIRI
5: PUTUS SEKOLAH
6: WAFAT
7: HILANG
8: ALIH FUNGSI
9: PENSIUN
Z: LAINNYA
A: AKTIF
*/
switch($status)
{
case 'LULUS': $kdstatus = '1'; break;
case 'MUTASI': $kdstatus = '2'; break;
case 'DIKELUARKAN': $kdstatus = '3'; break;
case 'MENGUNDURKAN DIRI': $kdstatus = '4'; break;
case 'PUTUS SEKOLAH': $kdstatus = '5'; break;
case 'WAFAT': $kdstatus = '6'; break;
case 'HILANG': $kdstatus = '7'; break;
case 'ALIH FUNGSI': $kdstatus = '8'; break;
case 'PENSIUN': $kdstatus = '9'; break;
case 'LAINNYA': $kdstatus = 'Z'; break;
case 'AKTIF': $kdstatus = 'A'; break;
}
$j_masuk = $cell[6];
switch($j_masuk)
{
case 'Peserta didik baru': $kd_masuk = '1'; break;
case 'Pindahan': $kd_masuk = '2'; break;
case 'Naik kelas': $kd_masuk = '3'; break;
case 'Akselerasi': $kd_masuk = '4'; break;
case 'Mengulang': $kd_masuk = '5'; break;
case 'Lanjutan semester': $kd_masuk = '6'; break;
case 'Pindahan Alih Bentuk': $kd_masuk = '8'; break;
}
$dt = array(
'no' => $cell[1],
'nim' => $cell[2],
'nama' => $cell[3],
'prodi' => $cell[4],
'status' => $kdstatus,
'jenis_masuk' => $kd_masuk,
'jk' => $cell[7],
'ttl' => $cell[8],
'agama' => $cell[9],
'id_pd' => $id_pd,
'id_reg_pd' => $id_reg_pd,
);
$data[] = $dt;
}
}
$return = array(
'success' => true,
'message' => '',
'data' => $data,
);
echo json_encode($return);
die;
}
}
}
function export_to_feeder()
{
$data = $this->input->post('json_mahasiswa');
if(empty($data)){
$return = array(
'success' => false,
'message' => 'data yang dimasukkan kosong',
);
echo json_encode($return);
die;
}
$data = json_decode($data);
$success_all = true;
$errors = array();
if(!empty($data))
{
$token = $this->_get_token();
foreach($data as $idx => $dt)
{
if($dt->status == 'A') continue;
$update = array(
'key' => array('id_reg_pd' => $dt->id_reg_pd),
'data' => array('id_jns_keluar' => $dt->status),
);
$updated_mahasiswa_pt = $this->proxy->UpdateRecord($token, 'mahasiswa_pt', json_encode($update));
if(isset($updated_mahasiswa_pt['result']['error_desc']) && !empty($updated_mahasiswa_pt['result']['error_desc'])){
$success_all = false;
$errors[] = $updated_mahasiswa_pt['result']['error_desc'];
}
}
}
$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;
}
}
?>