Advertisement
Guest User

history

a guest
Sep 12th, 2017
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 8.30 KB | None | 0 0
  1. <?php
  2. session_start();
  3. include "../../lib/nusoap/nusoap.php";
  4.  
  5. include "../../inc/config.php";
  6.  
  7.  
  8. $json_response = array();
  9.  
  10. if ($_POST['total_data']>0) {
  11.  
  12. $config = $db->fetch_single_row('config_user','id',1);
  13.  
  14. if ($config->live=='Y') {
  15.   $url = 'http://'.$config->url.':'.$config->port.'/ws/live.php?wsdl'; // gunakan live
  16. } else {
  17.   $url = 'http://'.$config->url.':'.$config->port.'/ws/sandbox.php?wsdl'; // gunakan sandbox
  18. }
  19.  
  20. $client = new nusoap_client($url, true);
  21. $proxy = $client->getProxy();
  22.  
  23.  
  24.         # MENDAPATKAN TOKEN
  25.         $username = $config->username;
  26.         $password = $config->password;
  27.         $result = $proxy->GetToken($username, $password);
  28.         $token = $result;
  29.  
  30.  
  31.         $sukses_count = 0;
  32.    
  33.         $error_count = 0;
  34.         $error_count_in = 0;
  35.  
  36.         $error_msg = array();
  37.    
  38.         $array_id_pt = array();
  39.         $array_sms_asal = array();
  40.         $array_sks_diakui = array();
  41.         $error_pt_asal = "";
  42.         $error_nim = "";
  43.         $error_prodi_asal = "";
  44.  
  45.         $update_data = array();
  46.         $update_data_status = array();
  47.    
  48.         $update_data_er =array();
  49.         $update_data_er_status =array();
  50.         $error_mk = "";
  51.         $id_pt_asal = "";
  52.        
  53.  
  54.         $data_id_sukses = array();
  55.         $data_id_error= array();
  56.    
  57.         $all_errors = array();
  58.         $all_error = array();
  59.         $query_not_in = "";
  60.         $jurusan = "";
  61.  
  62.         $msg = "";
  63.  
  64.         $sem = "";
  65.         if ($_POST['sem']!='all') {
  66.             $sem = "and mulai_smt='".$_POST['sem']."'";
  67.         }
  68.        
  69.        
  70.  
  71.         if (!empty($_POST['all_id'])) {
  72.             $trim_data_id = rtrim($_POST['all_id'], ',');
  73.             $query_not_in = "and history_pendidikan.id not in(".$trim_data_id.")";
  74.  
  75.         }
  76.  
  77.         if ($_POST['jurusan']!='all') {
  78.             $jurusan = "and trim(jurusan.kode_jurusan)='".trim($_POST['jurusan'])."'";
  79.         } else {
  80.             if ($_SESSION['level']!=1) {
  81.                 $jurusan = "and trim(jurusan.kode_jurusan)='".$_SESSION['jurusan']."'";
  82.             }
  83.         }
  84.  
  85.  
  86.  
  87.         $data = $db->fetch_custom("select history_pendidikan.*,id_sms from history_pendidikan inner join jurusan on history_pendidikan.kode_jurusan=jurusan.kode_jurusan where history_pendidikan.id is not null $sem $jurusan and status_error!=1 and status_error!=1 $query_not_in limit 50");
  88.  
  89.  
  90.         foreach ($data as $value) {
  91.  
  92.             $id_reg_filter = "trim(p.nipd)='".trim($value->nipd)."' and p.id_sms='".$value->id_sms."' and p.mulai_smt='".$value->mulai_smt."'";
  93.             $id_reg_pd = $proxy->GetRecord($token,'mahasiswa_pt',$id_reg_filter);
  94.  
  95.  
  96.  
  97.         if (!empty($id_reg_pd['result'])) {
  98.            
  99.  
  100.  
  101.         if ($value->kode_pt_asal!='') {
  102.             $filter_satuan_pendidikan = "trim(p.npsn)='".trim($value->kode_pt_asal)."' and soft_delete='0'";
  103.             $id_pt_asal = $proxy->GetRecord($token,'satuan_pendidikan',$filter_satuan_pendidikan);
  104.  
  105.  
  106.                 if ($id_pt_asal['result']) {
  107.                     $id_pt_asals = $id_pt_asal['result']['id_sp'];
  108.                     $array_id_pt = array('id_pt_asal' => $id_pt_asals,'nm_pt_asal' => $id_pt_asal['result']['nm_lemb']);
  109.                     if ($value->kode_prodi_asal!='') {
  110.                         $kode_prodi_asal_data = trim($value->kode_prodi_asal);
  111.                        
  112.                         $filter_sms = "id_sp='".$id_pt_asals."' and trim(kode_prodi)='".$kode_prodi_asal_data."'";
  113.                    
  114.                         $temp_sms = $proxy->GetRecord($token,'sms',$filter_sms);
  115.                         if ($temp_sms['result']) {
  116.                             $array_sms_asal = array('id_prodi_asal' => $temp_sms['result']['id_sms'],'nm_prodi_asal' => $temp_sms['result']['nm_lemb']);
  117.                         } else {
  118.                             $error_prodi_asal = "Kode Prodi Asal Tidak Ditemukan di Feeder. Perbaiki atau kosongkan Saja";
  119.                         }
  120.                     }
  121.                    
  122.                 } else {
  123.                     $error_pt_asal = "Kode PT Asal tidak ditemukan di Feeder";
  124.                 }
  125.         }
  126.         if ($value->sks_diakui!='') {
  127.             $array_sks_diakui = array('sks_diakui' => $value->sks_diakui);
  128.         }
  129.  
  130.  
  131.     } else {
  132.            
  133.             $error_nim = "Nipd/NIm tidak ditemukan di feeder";
  134.     }
  135.  
  136.  
  137.         if ($error_nim=="" && $error_pt_asal=="" && $error_prodi_asal=="") {
  138.                     $data_ids[] = $value->id;
  139.                     $data_nim[$value->id] = $value->nipd;
  140.                     $temp_key = array(
  141.                     'id_reg_pd' => $id_reg_pd['result']['id_reg_pd'],
  142.                     'mulai_smt' => $value->mulai_smt
  143.                     );
  144.  
  145.                     $temp_data = array(
  146.                         'id_jns_daftar' => $value->id_jns_daftar,
  147.                         'id_jalur_masuk' => $value->id_jalur_masuk,
  148.                         'tgl_masuk_sp' => $value->tgl_masuk_sp
  149.                     );
  150.                     $temp_data = array_merge($temp_data,$array_id_pt);
  151.                     $temp_data = array_merge($temp_data,$array_sms_asal);
  152.                     $temp_data = array_merge($temp_data,$array_sks_diakui);
  153.  
  154.  
  155.                    
  156.                     $array_history[] = array('key'=>$temp_key,'data'=>$temp_data);
  157.  
  158.  
  159.         } else {
  160.  
  161.                     $error_msg[] = "Error $error_nim $error_pt_asal $error_prodi_asal";
  162.                     $update_data_er[] = "WHEN $value->id THEN 'Error, $error_nim $error_pt_asal $error_prodi_asal' ";
  163.                     $update_data_er_status[]= "WHEN $value->id THEN '2' ";
  164.                     $data_id_error[] = $value->id;
  165.                     $error_count++;
  166.         }
  167.  
  168.         $all_id[] = $value->id;
  169.  
  170.         $array_sms_asal = array();
  171.         $error_prodi_asal = "";
  172.         $error_pt_asal = "";
  173.         $error_nim = "";
  174.        
  175.     }
  176.  
  177. /*  echo "<pre>";
  178.     print_r($array_history);
  179.     print_r($value);
  180.     exit();*/
  181.         if (!empty($array_history)) {
  182.  
  183.             $result = $proxy->UpdateRecordset($token, 'mahasiswa_pt',json_encode($array_history));
  184.  
  185.                 foreach ($result['result'] as $key => $value) {
  186.  
  187.                     $value_data = $value['error_desc'];
  188.                     $data_key = $data_ids[$key];
  189.  
  190.                     if ($value_data!='') {
  191.                         //$db->update('kelas_kuliah',array('status_error' => 2,'keterangan' => $value),'id',$key);
  192.                         $error_msg[] = $data_nim[$data_key]." $value_data";
  193.                         $update_data_er[] = "WHEN $data_key THEN '".str_replace("'",'',$value_data)."'";
  194.                         $update_data_er_status[]= "WHEN $data_key THEN '2' ";
  195.                         $data_id_error[] = $data_key;
  196.                         $error_count++;
  197.                     } else {
  198.                         //$db->update('kelas_kuliah',array('status_error' => 1,'keterangan' => $value),'id',$key);
  199.                         $update_data[]= "WHEN $data_key THEN '' ";
  200.                         $update_data_status[]= "WHEN $data_key THEN '1' ";
  201.                         $data_id_sukses[] = $data_key;
  202.                         $sukses_count++;
  203.                     }
  204.  
  205.                 }
  206.                
  207.  
  208.         }
  209.    
  210.  
  211.     if ($error_count>0) {
  212.         $id_error_update = implode(",", $data_id_error);
  213.         $data_er_update = implode(" ", $update_data_er);
  214.         $data_er_update_status = implode(" ", $update_data_er_status);
  215.         $bulk_update_error = "UPDATE history_pendidikan
  216.                 SET keterangan = (CASE id
  217.                     $data_er_update
  218.                     END),status_error = (CASE id
  219.                     $data_er_update_status
  220.                     END)
  221.                 WHERE id IN($id_error_update);";
  222.                 //echo $bulk_update_error;
  223.                 $db->fetch_custom($bulk_update_error);
  224.     }
  225.     if ($sukses_count>0) {
  226.         $id_update = implode(",", $data_id_sukses);
  227.         $data_update = implode(" ", $update_data);
  228.         $data_update_status = implode(" ", $update_data_status);
  229.  
  230.         $bulk_update_sukses = "UPDATE history_pendidikan
  231.                 SET keterangan = (CASE id
  232.                     $data_update
  233.                     END),status_error = (CASE id
  234.                     $data_update_status
  235.                     END)
  236.                 WHERE id IN($id_update);";
  237.                 //echo $bulk_update_sukses;
  238.                 $db->fetch_custom($bulk_update_sukses);
  239.     }
  240.  
  241.     //$jumlah['not_in'] = $query_not_in;
  242.     $jumlah['all_id'] = $all_id;
  243.     $jumlah['jumlah_error'] = $error_count;
  244.     $jumlah['jumlah_sukses'] = $sukses_count;
  245.     $jumlah['error_msg'] = $error_msg;
  246.  
  247.  
  248.  
  249.     if (isset($_POST['id_data'])) {
  250.  
  251.         $jumlah_sukses = $_POST['jumlah_sukses']+$sukses_count;
  252.         $jumlah_error = $_POST['jumlah_error']+$error_count;
  253.  
  254.    
  255.         $msg =  "<div class=\"alert alert-warning \" role=\"alert\">
  256.         <font color=\"#3c763d\">".$jumlah_sukses." data History berhasil ditambah</font><br />
  257.         <font color=\"#ce4844\" >".$jumlah_error." data tidak bisa ditambahkan </font>";
  258.        
  259.         if (!$jumlah_error==0) {
  260.             $msg .= "<a data-toggle=\"collapse\" href=\"#collapseExample\" aria-expanded=\"false\" aria-controls=\"collapseExample\">Detail error</a>";
  261.             //pesan error
  262.  
  263.             if (!empty($_POST['error_msg'])) {
  264.                 $trim_error = rtrim($_POST['error_msg'], ',');
  265.            
  266.                 $all_error = explode(",", $trim_error);
  267.             }
  268.            
  269.  
  270.             $all_errors = array_merge($all_error,$error_msg);
  271.            
  272.         }
  273.         //echo "<br />Total: ".$i." baris data";
  274.         $msg .= "<div class=\"collapse\" id=\"collapseExample\">";
  275.                 $i=1;
  276.                 foreach ($all_errors as $pesan) {
  277.                         $msg .= "<div class=\"bs-callout bs-callout-danger\">".$i.". ".$pesan."</div><br />";
  278.                     $i++;
  279.                     }
  280.         $msg .= "</div>
  281.         </div>";
  282.  
  283.  
  284.         $jumlah['last_notif'] = $msg;
  285.     }
  286.  
  287.  
  288. } else {
  289.     $msg =  "Tidak ada data yang bisa diproses<p>";
  290.         $jumlah['last_notif'] = $msg;
  291. }
  292.  
  293. array_push($json_response, $jumlah);
  294. echo json_encode($json_response);
  295. //echo convert(memory_get_usage(true)); // 123 kb
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement