<?php
session_start();
include "../../inc/config.php";
$json_response = array();

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();
}

$url = get_service_url('url_rest');

$data_rec = array();
$final = array();
$id_reg_pd_smt = array();
$offset = $_POST['offset'];
$token = $_POST['token'];

$jumlah['offset'] = $offset;
$jumlah['token'] = $_POST['token'];

$no = $offset;

if ($offset==0) {

$token = $db->get_token();


    $jumlah['token'] = get_token();
}

        if ($_POST['total_data']<=11) {
            $limit = $_POST['total_data'];
        } else {
            $limit = 11;
        }

    $temp_data_akm = [
      'act' => 'GetProdi',
        'token' => $token,
        'filter' => "status='A'",
        'order' => 'id_prodi desc',
        'limit' => $limit,
        'offset' => $offset

    ];

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


            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') {

$msg =  "<div class=\"alert alert-warning \" role=\"alert\">
        <font color=\"#3c763d\">".$_POST['total_data']." data Jurusan berhasil di Download</font><br />";
        $msg .= "</div>
        </div>";
        $jumlah['last_notif'] = $msg;
}



array_push($json_response, $jumlah);

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