<?php
include "../../inc/config.php";
$json_response = array();
$msg = "";
$values = "";
//param here
$param = array();
$token = get_token();
$url = get_service_url('rest');
 //dump($token);

if (isset($_GET["ask"])=="jumlah") {
    //truncate jurusan
    $db->fetch_custom("truncate jurusan");
    $data_dic = array(
      'act' => 'GetCountProdi',
      'token' => $token,
      'filter' => "",
    );
    $results = json_decode(run($data_dic,$url));
    //dump($results);
    if ($results->data>0) {
       $json_response["jumlah"] = $results->data;
    } else {
      $json_response["jumlah"] = 0;
    }
    echo json_encode($json_response);
} else {
    if ($_POST["total_data"]<1) {
        $msg =  "<div class=\"alert alert-warning \" role=\"alert\">
            <font color=\"#3c763d\">Tidak ada data berhasil di Download</font><br />
            </div>";

        $jumlah["last_notif"] = $msg;
        array_push($json_response, $jumlah);

        echo json_encode($json_response);
        exit();
    }

    $offset = $_POST["offset"];

    $jumlah["offset"] = $offset;

    $par_get = array(
        "offset" => $offset
    );


    $data_rec = array();
            $data_param = [
                  'act' => 'GetProdi',
                    'token' => $token,
                    'filter' => "",
                    'order' => 'id_prodi desc',
                    'limit' => 11,
                    'offset' => $offset

                ];

            $datas = json_decode(run($data_param,$url));

            //print_r($datas);


            foreach ($datas->data as $key) {
                       $insert_jurusan[] = array(
                            "id_sms" => $key->id_prodi,
  							"nama_jurusan" => $db->trimmer($key->nama_program_studi),
  							"kode_jurusan" => $key->kode_program_studi,
  							"status" => $key->status,
  							"id_jenj_didik" => $key->id_jenjang_pendidikan,
                            "jenjang" => $db->trimmer($key->nama_jenjang_pendidikan),
                            "CreatedDate" => date('Y-m-d H:i:s')
                        );     
              }
            if (!empty($insert_jurusan)) {
              $db->insertMulti("jurusan",$insert_jurusan);
            }

    if ($_POST["last"]=="yes") {
        //echo "<pre>";

    $msg =  "<div class=\"alert alert-warning \" role=\"alert\">
            <font color=\"#3c763d\">".$_POST["total_data"]." Data jurusan berhasil di Unduh</font><br />";
            $msg .= "</div>
            </div>";

            $jumlah["last_notif"] = $msg;
    }



    array_push($json_response, $jumlah);

    echo json_encode($json_response);
    exit();
}
?>
