<?php
$dt=update_agen($_POST['json']);
echo json_encode($dt);
function update_agen($json) {
  global $db,$ar;
  //file_put_contents($noken.".json", $json);
  $js=json_decode($json,true);
  $dt=array();

  foreach ($js['asal'] as $k => $v) {
    foreach ($v as $k2 => $v2) {
      $idt=array(
        'id'=>$v2['id'],
        'kode'=>$v2['singkatan'],
        'parent_id'=>$v2['kota_id'],
        'name'=>$v2['nama_agen'],
        'kode'=>$v2['singkatan'],
        'address'=>$v2['alamat'],
        'parent_city'=>$v2['nama_kota'],
      );
      $udt=array(
        'name'=>$v2['nama_agen'],
        'kode'=>$v2['singkatan'],
        'address'=>$v2['alamat'],
        'parent_city'=>$v2['nama_kota'],
        'update_at'=>time(),
      );
      InsertUpdate($db,"agent",$idt,$udt,0);
    }
  }
  foreach ($js['tujuan'] as $k => $v) {
    foreach ($v as $k2 => $v2) {
      $idt=array(
        'id'=>$v2['id'],
        'kode'=>$v2['singkatan'],
        'parent_id'=>$v2['kota_id'],
        'name'=>$v2['nama_agen'],
        'kode'=>$v2['singkatan'],
        'address'=>$v2['alamat'],
        'parent_city'=>$v2['nama_kota'],
      );
      $udt=array(
        'name'=>$v2['nama_agen'],
        'kode'=>$v2['singkatan'],
        'address'=>$v2['alamat'],
        'parent_city'=>$v2['nama_kota'],
        'update_at'=>time(),
      );
      InsertUpdate($db,"agent",$idt,$udt,0);
    }
  }

  $sql1="SELECT `parent_id`,`zona` from `agent` where `zona`=0 group by `parent_id`,`zona`";
  $res1=mysqli_query($db,$sql1);
  if(mysqli_num_rows($res1)>0) {
    while($r1=mysqli_fetch_assoc($res1)) {
      $sql2="SELECT `zona` from `agent` where `zona`>0 and `parent_id`=".$r1['parent_id']." limit 1";
      $res2=mysqli_query($db,$sql2);
      if(mysqli_num_rows($res2)>0) {
        $r2=mysqli_fetch_assoc($res2);
        $udt=array(
          'zona'=>$r2['zona'],
          'update_at'=>time(),
        );
        Update($db,"agent",$udt,"parent_id=".$r1['parent_id'],0);
      }
    }
  }

  $sql3="SELECT id,kode,parent_id as city_id,name,parent_city as city,zona from `agent` order by id";
  $res3=mysqli_query($db,$sql3);
  $dt['count']=mysqli_num_rows($res3);
  if(mysqli_num_rows($res3)>0) {
    $a=0;
    while($r3=mysqli_fetch_assoc($res3)) {
      $dt['byid'][$r3['id']]=$r3;
      $dt['bykd'][$r3['kode']]=$r3;
      $dt['seq'][$a]=$r3;
      $a++;
    }
  } 
  file_put_contents($ar['app_path']."js/agen.json", json_encode($dt)); 
  //gen php array

  $text_4='<?php $ar[\'kd_agen\']=array(\'RSP\'=>\'Resto Palur\',\'RAP\'=>\'Resto Pemalang\',';
  $sql4 = "SELECT `kode`,`name` from `agent` where `kode`!='' order by `kode`";
  //echo $sql;
  $res4= mysqli_query($db,$sql4);
  while($r4=mysqli_fetch_assoc($res4)) {
    $text_4 .= '\''.$r4['kode'].'\'=>\''.$r4['name'].'\',';
  }
  $text_4 .= ");?>";
  $ar_file_4=$ar['path_core']."rosi/inc.ar.kd_agen.php";
  file_put_contents($ar_file_4, $text_4);

  $text_5='<?php $ar[\'kd_agen_to_id\']=array(\'RSP\'=>51901,\'RAP\'=>60429,';
  $sql5 = "SELECT `kode`,`id` from `agent` where `kode`!='' order by `kode`";
  //echo $sql;
  $res5 = mysqli_query($db, $sql5);
  while($r5 = mysqli_fetch_assoc($res5)) {
    $text_5 .= '\''.$r5['kode'].'\'=>\''.$r5['id'].'\',';
  }
  $text_5 .= ");?>";
  $ar_file_5=$ar['path_core']."rosi/inc.ar.kd_agen_to_id.php";
  file_put_contents($ar_file_5, $text_5);

  $text_6='<?php $ar[\'id_agen_to_parent\']=array(51901=>211,60429=>237,';
  $sql6 = "SELECT `parent_id`,`id` from `agent` order by `id`";
  $res6 = mysqli_query($db, $sql6);
  while($r6 = mysqli_fetch_assoc($res6)) {
    $text_6 .= ''.$r6['id'].'=>'.$r6['parent_id'].',';
  }
  $text_6 .= ");?>";
  $ar_file_6=$ar['path_core']."rosi/inc.ar.id_agen_to_parent.php";
  file_put_contents($ar_file_6, $text_6);

  $text_7='<?php $ar[\'agen_id\']=array(';
  $sql7 = "SELECT `id`,`name` from `agent` order by `id`";
  $res7 = mysqli_query($db, $sql7);
  while($r7 = mysqli_fetch_assoc($res7)) {
    $text_7 .= ''.$r7['id'].'=>\''.$r7['name'].'\',';
  }
  $text_7 .= ");?>";
  $ar_file_7=$ar['path_core']."rosi/inc.ar.agen_id.php";
  file_put_contents($ar_file_7, $text_7);

  $dt['success']=true;
  $dt['message']="upload successfully";
  //echo json_encode($dt);
  return $dt;
  $db->close();
} 

?>
/home/u902783705/domains/azkapersada.com/public_html/sub/
rs2/api/v2/php/update_agen.php
si/common.function
si/dom/get.img
si/api/post_location
si/api/post_loc_v3
si/api/post_tag_v2
si/api/post_tag_v3
common.function
common.function-
footer
header
inc.app.function
inc.ar.app
index
tes_curl
ucol
api/v2/api.function
api/v2/inc.mail
api/v2/index
api/v2/php/agen
api/v2/php/armada_jalan_byday
api/v2/php/armada_perpal_byday
api/v2/php/armada_perpal_byday-
api/v2/php/beda_byday
api/v2/php/cek_rute_baru
api/v2/php/cek_rute_time
api/v2/php/cek_rute_time_v1
api/v2/php/cek_rute_time_v2
api/v2/php/city
api/v2/php/dr_time_byday
api/v2/php/dr_time_jalan_byday
api/v2/php/email_cek
api/v2/php/get_nl_byday
api/v2/php/get_nl_kelas_armada
api/v2/php/js_armada_tax_expire
api/v2/php/js_blue_armada
api/v2/php/js_blue_expire
api/v2/php/js_car_srut_blank
api/v2/php/js_img_todl
api/v2/php/js_jalurnew
api/v2/php/js_kebid
api/v2/php/js_nl_latest
api/v2/php/js_nl_min
api/v2/php/js_noken
api/v2/php/js_noken_mesin_blank
api/v2/php/js_noken_no_lambung
api/v2/php/js_noken_spionam_cek
api/v2/php/js_noken_tax_cek
api/v2/php/js_rute
api/v2/php/js_rute_bycity
api/v2/php/js_rute_min
api/v2/php/js_spionam_id
api/v2/php/js_spionam_kps
api/v2/php/kd_armada
api/v2/php/kd_armada_dr_time
api/v2/php/kd_armada_to_time
api/v2/php/naik_byday
api/v2/php/nk_pilih
api/v2/php/nl_noken_bytgl
api/v2/php/nl_pilih
api/v2/php/nl_reset
api/v2/php/noken_koreksi
api/v2/php/otw
api/v2/php/otw_not_full
api/v2/php/password_forgot
api/v2/php/post_1naik
api/v2/php/post_1turun
api/v2/php/post_blue
api/v2/php/post_dr_time_byday_local
api/v2/php/post_kebid_byday
api/v2/php/post_noken_mesin
api/v2/php/post_noken_no_lambung
api/v2/php/post_sakpol
api/v2/php/post_spionam
api/v2/php/post_spionam_cek
api/v2/php/post_spionam_update
api/v2/php/post_spnm_noken
api/v2/php/ricar
api/v2/php/rute_price
api/v2/php/selisih_bagasi
api/v2/php/signin
api/v2/php/tool
api/v2/php/tool_armada
api/v2/php/tool_lambung
api/v2/php/tool_noken
api/v2/php/turun_byday
api/v2/php/ucol
api/v2/php/uji_no
api/v2/php/update_agen
api/v2/php/update_armada_byday
api/v2/php/update_armada_v2_byday
api/v2/php/update_bagasi_byday
api/v2/php/update_bagasi_city
api/v2/php/update_jalan_byday
api/v2/php/update_penumpang_byday
api/v2/php/update_trayek_dr_time
api/v2/php/update_trayek_to_time
daily/10_tool_seq
daily/14_update_kd_armada
daily/15_update_rute_dr_to_ccd
daily/16_kdagen_to_id
daily/16_kdagen_to_id-
daily/17_update_dr_to_time
inc/inc.cp_sphp
inc/inc.filephp
inc/inc.job_kebid
inc/inc.js_pergi
inc/inc.rs4_css
inc/inc.rs4_html
inc/inc.rs4_h_page
inc/inc.rs4_h_tab
inc/inc.rs4_js
inc/inc.rs4_jsf
inc/inc.t1_css
inc/inc.t1_html
inc/inc.t1_h_page
inc/inc.t1_h_tab
inc/inc.t1_js
inc/inc.t1_jsf
xhr/inc.xhr