Advertisement
virbo

Import data Mahasiswa from Excel File

Nov 21st, 2015
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.25 KB | None | 0 0
  1. //echo "Import data mahasiswa";
  2. $objPHPExcel->setActiveSheetIndex(0);
  3. $cell_collection = $objPHPExcel->getActiveSheet()->getCellCollection();
  4. $jml_row = $objPHPExcel->getActiveSheet()->getHighestRow()-1;
  5. foreach ($cell_collection as $cell) {
  6.     $column = $objPHPExcel->getActiveSheet()->getCell($cell)->getColumn();
  7.     $row = $objPHPExcel->getActiveSheet()->getCell($cell)->getRow();
  8.     $data_value = $objPHPExcel->getActiveSheet()->getCell($cell)->getValue();
  9.                        
  10.     if ($row == 1) {
  11.         $header[$row][$column] = $data_value;
  12.     } else {
  13.         $arr_data[$row][$column] = $data_value;
  14.     }
  15. }
  16. if ($arr_data) {
  17.     $temp_data = array();
  18.     $sukses_count = 0;
  19.     $sukses_msg = '';
  20.     $error_count = 0;
  21.     $error_msg = array();
  22.     $sukses_msg = array();
  23.     //$i=0;
  24.     foreach ($arr_data as $key => $value) {
  25.         //++$i;
  26.         $nim = $value['B'];
  27.         $nm_mhs = $value['C'];
  28.         $tmp_lahir =$value['D'];
  29.         $tgl_lahir = date('Y-m-d', strtotime($value['E']));
  30.         $jk = trim($value['F']);
  31.         $agama = trim($value['G']);
  32.         $ds_kel = $value['H'];
  33.         $wilayah = trim($value['I']);
  34.         $nm_ibu = $value['J'];
  35.         $kode_prodi = trim($value['K']);
  36.         $tgl_masuk = date('Y-m-d', strtotime($value['L']));
  37.         $smt_awal = trim($value['M']);
  38.         $stat_mhs = trim($value['N']);
  39.         $stat_awal = trim($value['O']);
  40.         $sks_diakui = $value['P'];
  41.         $pt_asal = $value['Q'];
  42.         $prodi_asal = $value['R'];
  43.         $filter_sms = "kode_prodi='".$kode_prodi."' AND id_sp='".$this->session->userdata('id_sp')."'";
  44.         $temp_sms = $this->feeder->getrecord($this->session->userdata('token'),'sms',$filter_sms);
  45.         $id_sms = $temp_sms['result']?$temp_sms['result']['id_sms']:'';
  46.            
  47.         $temp_data['nm_pd'] = $nm_mhs;
  48.         $temp_data['jk'] = $jk;
  49.         $temp_data['tmpt_lahir'] = $tmp_lahir;
  50.         $temp_data['tgl_lahir'] = $tgl_lahir;
  51.         $temp_data['id_agama'] = $agama;
  52.         $temp_data['id_kk'] = 0;
  53.         $temp_data['id_sp'] = $this->session->userdata('id_sp');
  54.         $temp_data['ds_kel'] = $ds_kel;
  55.         $temp_data['id_wil'] = $wilayah;
  56.         $temp_data['a_terima_kps'] = 0;
  57.         $temp_data['stat_pd'] = $stat_mhs;
  58.         $temp_data['id_kebutuhan_khusus_ayah'] = 0;
  59.         $temp_data['nm_ibu_kandung'] = $nm_ibu;
  60.         $temp_data['id_kebutuhan_khusus_ibu'] = 0;
  61.         $temp_data['kewarganegaraan'] = 'ID';
  62.  
  63.         $temps_data['id_sms'] = $id_sms;
  64.         $temps_data['id_sp'] = $this->session->userdata('id_sp');
  65.         $temps_data['id_jns_daftar'] = $stat_awal;
  66.         $temps_data['nipd'] = $nim;
  67.         $temps_data['tgl_masuk_sp'] = $tgl_masuk;
  68.         $temps_data['a_pernah_paud'] = 0;
  69.         $temps_data['a_pernah_tk'] = 0;
  70.         $temps_data['mulai_smt'] = $smt_awal;
  71.         if ($stat_awal=='2') {
  72.             $temps_data['sks_diakui'] = $sks_diakui;
  73.             $temps_data['nm_pt_asal'] = $pt_asal;
  74.             $temps_data['nm_prodi_asal'] = $prodi_asal;
  75.         }
  76.         $temp_result = $this->feeder->insertrecord($this->session->userdata['token'], $this->table, $temp_data);
  77.                            
  78.         if ($temp_result['result']) {
  79.             //Error handle
  80.             if ($temp_result['result']['error_desc']==NULL) {
  81.                 ++$sukses_count;
  82.                 $temps_data['id_pd'] = $temp_result['result']['id_pd'];
  83.                 $temps_result = $this->feeder->insertrecord($this->session->userdata['token'], $this->table1, $temps_data);
  84.                 if ($temps_result['result']) {
  85.                     if ($temps_result['result']['error_desc']=='') {
  86.                         $sukses_msg[] = "<h4>Sukses</h4>Biodata dan histori pendidikan mahasiswa <strong>".$nm_mhs."</strong> / <strong>NIM: ".$nim."</strong> berhasil ditambahkan.";
  87.                     } else {
  88.                         ++$error_count;
  89.                         $error_msg[] = "<h4>Error ".$temps_result['result']['error_code']." (".$nm_mhs." / NIM: ".$nim.")</h4><strong>Histori pendidikan:</strong> ".$temps_result['result']['error_desc'];
  90.                     }
  91.                     if (($temps_result['result']['error_desc']!='') && ($temp_result['result']['error_desc']=='')) {
  92.                         $sukses_msg[] = "<h4>Sukses</h4>Biodata mahasiswa <strong>".$nm_mhs."</strong> berhasil ditambahkan.";
  93.                     }
  94.                 }
  95.                    
  96.             } else {
  97.                 if ($temp_result['result']['error_code']==200) {
  98.                     $filter_pd = "(nm_pd='".$nm_mhs."') AND (tmpt_lahir='".$tmp_lahir."') AND (tgl_lahir='".$tgl_lahir."') AND (nm_ibu_kandung='".$nm_ibu."') AND (p.id_sp='".$this->session->userdata('id_sp')."')";
  99.                     $temp_pd = $this->feeder->getrecord($this->session->userdata('token'),$this->table,$filter_pd);
  100.                     $temps_data['id_pd'] = $temp_pd['result']['id_pd'];
  101.                     $temps_result = $this->feeder->insertrecord($this->session->userdata['token'], $this->table1, $temps_data);
  102.                     if ($temps_result['result']) {
  103.                         if ($temps_result['result']['error_desc']==NULL) {
  104.                             ++$sukses_count;
  105.                             $sukses_msg[] = "<h4>Sukses</h4>Histori pendidikan mahasiswa <strong>".$nm_mhs."</strong> berhasil ditambahkan dengan <strong>NIM ".$nim."</strong>";
  106.                         } else {
  107.                             ++$error_count;
  108.                             $error_msg[] = "<h4>Error ".$temp_result['result']['error_code'].' / '.$temps_result['result']['error_code']." (".$nm_mhs." / NIM: ".$nim.")</h4><strong>Biodata:</strong> ".$temp_result['result']['error_desc']."<br /><strong>Histori pendidikan:</strong> ".$temps_result['result']['error_desc']."";
  109.                         }
  110.                     }
  111.                 }
  112.             }
  113.         } else {
  114.             $error_msg[] = "<h4>Error ".$temp_result['result']['error_code']."</h4>".$temp_result['result']['error_desc'];
  115.         }
  116.     }
  117.     $this->benchmark->mark('selesai');
  118.     $time_eks = $this->benchmark->elapsed_time('mulai', 'selesai');
  119.     if ((!$sukses_count==0) || (!$error_count==0)) {
  120.         echo "Waktu eksekusi ".$time_eks." detik<br />
  121.         Results (total ".$jml_row." baris data):<br />
  122.         <font color=\"#3c763d\">".$sukses_count." data Mahasiswa baru berhasil ditambah</font>";
  123.         if ($sukses_count!=0) {
  124.             echo "<a data-toggle=\"collapse\" href=\"#cols_sukses\" aria-expanded=\"false\" aria-controls=\"cols_sukses\"> Detail</a><br />";
  125.         } else { echo "<br />"; }
  126.         echo "<div class=\"collapse\" id=\"cols_sukses\">";
  127.             foreach ($sukses_msg as $pesan_sukses) {
  128.                 echo "<div class=\"bs-callout bs-callout-success\">".$pesan_sukses."</div><br />";
  129.             }
  130.             echo "</div>";
  131.  
  132.         echo "<font color=\"#ce4844\" >".$error_count." data tidak bisa ditambahkan </font>";
  133.         if ($error_count!=0) {
  134.             echo "<a data-toggle=\"collapse\" href=\"#cols_error\" aria-expanded=\"false\" aria-controls=\"cols_error\">Detail error</a>";
  135.         }
  136.         echo "<div class=\"collapse\" id=\"cols_error\">";
  137.             foreach ($error_msg as $pesan) {
  138.                 echo "<div class=\"bs-callout bs-callout-danger\">".$pesan."</div><br />";
  139.             }
  140.             echo "</div>";
  141.     }
  142. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement