<!--main-container-part-->
<div id="content">
    <!--breadcrumbs-->
    <div id="content-header">
        <div id="breadcrumb"> <a href="<?php echo site_url('admin'); ?>" title="Go to Home" class="tip-bottom"><i class="icon-home"></i> Home</a></div>
    </div>
    <!--End-breadcrumbs-->

    <!--Action boxes-->
    <div class="container-fluid">
        <div class="row-fluid">
            <div class="span12">
                <div class="widget-box">
                    <div class="widget-title"> <span class="icon"> <i class="icon-refresh"></i> </span>
                        <h5><?php echo $judul_halaman; ?></h5>
                    </div>
                    <div class="widget-content">
                        <!--<a href="#" class="btn btn-block btn-danger" id="doss_singcron">Singkronisai data Sekarang</a>-->
                        <hr/>
                        <button id="reset_data" type="button" class="btn btn-warning">RESET DATA</button>
                        <br/>
                        <br/>
                        <div class="alert warning">Operasi ini akan menghapus History Ujian!</div>
                        <br/>
                        <hr/>
                        <button id="update_1" type="button" class="btn btn-danger">Update Data Ke 1</button>
                        <h4>Data 1 <span id="header-1"></span></h4>
                        <!--Kelas-->
                        <div>
                            Status: <span id="keterangan-progress-1">-</span>
                        </div>
                        <div class="progress">
                            <div class="bar" style="width: 0%;" id="bar-sukses-1"></div>
                            <div class="bar bar-danger" style="width: 0%;" id="bar-gagal-1"></div>
                            <div id="persen-1" style="font-weight: bold">0%</div>
                        </div>
                        <hr/>
                        <button id="update_2" type="button" class="btn btn-danger" disabled="">Update Data Ke 2</button>
                        <h4>Data 2 <span id="header-2"></span></h4>
                        <!--Jurusan-->
                        <div>
                            Status: <span id="keterangan-progress-2">-</span>
                        </div>
                        <div class="progress">
                            <div class="bar" style="width: 0%;"id="bar-sukses-2"></div>
                            <div class="bar bar-danger" style="width: 0%;" id="bar-gagal-2"></div>
                            <div id="persen-2" style="font-weight: bold">0%</div>
                        </div>
                        <hr/>
                        <button id="update_3" type="button" class="btn btn-danger" disabled="">Update Data Ke 3</button>
                        <h4>Data 3 <span id="header-3"></span></h4>
                        <!--Pelajaran-->
                        <div>
                            Status: <span id="keterangan-progress-3">-</span>
                        </div>
                        <div class="progress">
                            <div class="bar" style="width: 0%;"id="bar-sukses-3"></div>
                            <div class="bar bar-danger" style="width: 0%;" id="bar-gagal-3"></div>
                            <div id="persen-3" style="font-weight: bold">0%</div>
                        </div>
                        <hr/>
                        <button id="update_4" type="button" class="btn btn-danger" disabled="">Update Data Ke 4</button>
                        <h4>Data 4 <span id="header-4"></span></h4>
                        <!--Materi Pelajaran-->
                        <div>
                            Status: <span id="keterangan-progress-4">-</span>
                        </div>
                        <div class="progress">
                            <div class="bar" style="width: 0%;"id="bar-sukses-4"></div>
                            <div class="bar bar-danger" style="width: 0%;" id="bar-gagal-4"></div>
                            <div id="persen-4" style="font-weight: bold">0%</div>
                        </div>
                        <hr/>
                        <button id="update_5" type="button" class="btn btn-danger" disabled="">Update Data Ke 5</button>
                        <h4>Data 5 <span id="header-5"></span></h4>
                        <!--jenis ujian-->
                        <div>
                            Status: <span id="keterangan-progress-5">-</span>
                        </div>
                        <div class="progress">
                            <div class="bar" style="width: 0%;"id="bar-sukses-5"></div>
                            <div class="bar bar-danger" style="width: 0%;" id="bar-gagal-5"></div>
                            <div id="persen-5" style="font-weight: bold">0%</div>
                        </div>
                        <hr/>
                        <button id="update_6" type="button" class="btn btn-danger" disabled="">Update Data Ke 6</button>
                        <h4>Data 6 <span id="header-6"></span></h4>
                        <!--Siswa-->
                        <div>
                            Status: <span id="keterangan-progress-6">-</span>
                        </div>
                        <div class="progress">
                            <div class="bar" style="width: 0%;"id="bar-sukses-6"></div>
                            <div class="bar bar-danger" style="width: 0%;" id="bar-gagal-6"></div>
                            <div id="persen-6" style="font-weight: bold">0%</div>
                        </div>
                        <hr/>
                        <button id="update_7" type="button" class="btn btn-danger" disabled="">Update Data Ke 7</button>
                        <h4>Data 7 <span id="header-7"></span></h4>
                        <!--Paket-->
                        <div>
                            Status: <span id="keterangan-progress-7">-</span>
                        </div>
                        <div class="progress">
                            <div class="bar" style="width: 0%;"id="bar-sukses-7"></div>
                            <div class="bar bar-danger" style="width: 0%;" id="bar-gagal-7"></div>
                            <div id="persen-7" style="font-weight: bold">0%</div>
                        </div>
                        <hr/>
                        <button id="update_8" type="button" class="btn btn-danger" disabled="">Update Data Ke 8</button>
                        <h4>Data 8 <span id="header-8"></span></h4>
                        <!--Soal-->
                        <div>
                            Status: <span id="keterangan-progress-8">-</span>
                        </div>
                        <div class="progress">
                            <div class="bar" style="width: 0%;"id="bar-sukses-8"></div>
                            <div class="bar bar-danger" style="width: 0%;" id="bar-gagal-8"></div>
                            <div id="persen-8" style="font-weight: bold">0%</div>
                        </div>
                        <hr/>
                        <button id="update_9" type="button" class="btn btn-danger" disabled="">Update Data Ke 9</button>
                        <h4>Data 9 <span id="header-9"></span></h4>
                        <!--Jadwal Ujian-->
                        <div>
                            Status: <span id="keterangan-progress-9">-</span>
                        </div>
                        <div class="progress">
                            <div class="bar" style="width: 0%;"id="bar-sukses-9"></div>
                            <div class="bar bar-danger" style="width: 0%;" id="bar-gagal-9"></div>
                            <div id="persen-9" style="font-weight: bold">0%</div>
                        </div>
                        <hr/>
                        <button id="update_10" type="button" class="btn btn-danger" disabled="">Update Data Ke 10</button>
                        <h4>Data 10 <span id="header-10"></span></h4>
                        <!--Jadwal Ujian-->
                        <div>
                            Status: <span id="keterangan-progress-10">-</span>
                        </div>
                        <div class="progress">
                            <div class="bar" style="width: 0%;"id="bar-sukses-10"></div>
                            <div class="bar bar-danger" style="width: 0%;" id="bar-gagal-10"></div>
                            <div id="persen-10" style="font-weight: bold">0%</div>
                        </div>
                        <hr/>
                        <button id="update_11" type="button" class="btn btn-danger" disabled="">Update Data Ke 11</button>
                        <h4>Data 11 <span id="header-11"></span></h4>
                        <!--Detail Paket-->
                        <div>
                            Status: <span id="keterangan-progress-11">-</span>
                        </div>
                        <div class="progress">
                            <div class="bar" style="width: 0%;"id="bar-sukses-11"></div>
                            <div class="bar bar-danger" style="width: 0%;" id="bar-gagal-11"></div>
                            <div id="persen-11" style="font-weight: bold">0%</div>
                        </div>
                        <hr/>
                        <button id="update_12" type="button" class="btn btn-danger" disabled="">Update Data Ke 12</button>
                        <h4>Data 12 <span id="header-12"></span></h4>
                        <!--Detail Paket-->
                        <div>
                            Status: <span id="keterangan-progress-12">-</span>
                        </div>
                        <div class="progress">
                            <div class="bar" style="width: 0%;"id="bar-sukses-12"></div>
                            <div class="bar bar-danger" style="width: 0%;" id="bar-gagal-12"></div>
                            <div id="persen-12" style="font-weight: bold">0%</div>
                        </div>
                        <hr/>
                        <button id="update_13" type="button" class="btn btn-danger" disabled="">Update Data Ke 13</button>
                        <h4>Data 13 <span id="header-13"></span></h4>
                        <!--File Audio-->
                        <div>
                            Status: <span id="keterangan-progress-13">-</span>
                        </div>
                        <div class="progress">
                            <div class="bar" style="width: 0%;"id="bar-sukses-13" disabled=""></div>
                            <div class="bar bar-danger" style="width: 0%;" id="bar-gagal-13"></div>
                            <div id="persen-13" style="font-weight: bold">0%</div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <hr/>
    </div>
</div>

<!--end-main-container-part-->
<script>
    $(document).ready(function () {
        $('#reset_data').click(function (e) {
            var r = confirm("Anda Yakin?");
            if (r === true) {
                $.ajax({
                    type: "GET",
                    crossDomain: true,
                    url: "<?php echo site_url('admin/reset_data/' . $status_cbt->token_cbt . '/'); ?>",
                    success: function (result) {
                        alert("RESET DATA BERHASIL");
                    }
                });
            }
        });
        var proses1 = false;
        $('#update_1').click(function (e) {
            if (proses1 === false) {
                proses1 = true;
                $('#update_1').addClass('disabled');
                $('#update_1').removeClass('btn-danger');
                $('#update_1').addClass('btn-success');
                $.ajax({
                    type: "GET",
                    crossDomain: true,
                    url: "<?php echo site_url('admin/trunc_data_1/' . $status_cbt->token_cbt . '/'); ?>",
                    success: function (result) {
                        $.ajax({
                            type: 'GET',
                            url: '<?php echo $status_cbt->alamat_server_cbt . '/home/sync_data_1/' . $status_cbt->token_cbt . '/' . $status_cbt->kode_unix; ?>',
                            dataType: 'json',
                            crossDomain: true,
                            success: function (ret_data) {
                                if (ret_data['error'] === "Server Off") {
                                    $('#header-1').html('[Server Off], tidak dapat melakukan syncronisasi');
                                } else {
                                    $('#header-1').html(' - Ditemukan ' + ret_data['jumlah_data'] + ' data');
                                    $('#keterangan-progress-1').html('Mengupdate data ...');
                                    var $berhasil = 0;
                                    var $gagal = 0;
                                    $.each(ret_data['data'], function (index, element) {
                                        //console.log(index + " = " + element['id_kelas']);
                                        $.ajax({
                                            type: "POST",
                                            crossDomain: true,
                                            url: "<?php echo site_url('admin/sync_data_1/' . $status_cbt->token_cbt . '/'); ?>",
                                            data: {
                                                'id': '' + element['id_kelas']
                                            },
                                            success: function (result) {
                                                if (result === 'OK') {
                                                    $berhasil++;
                                                    var prcn = Math.round(($berhasil / ret_data['jumlah_data']) * 100);
                                                    $('#bar-sukses-1').attr('style', 'width: ' + prcn + '%;');
                                                } else {
                                                    $gagal++;
                                                    var prcn = Math.round(($gagal / ret_data['jumlah_data']) * 100);
                                                    $('#bar-gagal-1').attr('style', 'width: ' + prcn + '%;');
                                                }

                                                $('#persen-1').html(prcn + '%');
                                                if (prcn > 98) {
                                                    $('#header-1').html(' - Ditemukan ' + ret_data['jumlah_data'] + ' data - PROSES SELESAI');
                                                    $('#keterangan-progress-1').html('Update data Selesai...');
                                                    $('#update_2').removeAttr("disabled");
                                                }
                                            }
                                        });
                                    });
                                }
                            },
                            error: function (jqXHR, textStatus, errorThrown) {
                                $('#keterangan-progress-1').html(textStatus + ' - ' + errorThrown);
                            }
                        });
                    }
                });
            }
        });
        var proses2 = false;
        $('#update_2').click(function (e) {
            if (proses2 === false) {
                proses2 = true;
                $('#update_2').addClass('disabled');
                $('#update_2').removeClass('btn-danger');
                $('#update_2').addClass('btn-success');
                $.ajax({
                    type: "GET",
                    url: "<?php echo site_url('admin/trunc_data_2/' . $status_cbt->token_cbt . '/'); ?>",
                    success: function (result) {
                        $.ajax({
                            type: 'GET',
                            url: '<?php echo $status_cbt->alamat_server_cbt . '/home/sync_data_2/' . $status_cbt->token_cbt . '/' . $status_cbt->kode_unix; ?>',
                            dataType: 'json',
                            success: function (ret_data) {
                                if (ret_data['error'] === "Server Off") {
                                    $('#header-2').html('[Server Off], tidak dapat melakukan syncronisasi');
                                } else {
                                    $('#header-2').html(' - Ditemukan ' + ret_data['jumlah_data'] + ' data');
                                    $('#keterangan-progress-2').html('Mengupdate data ...');

                                    var $berhasil = 0;
                                    var $gagal = 0;
                                    $.each(ret_data['data'], function (index, element) {
                                        //console.log(index + " = " + element['id_kelas']);
                                        $.ajax({
                                            type: "POST",
                                            url: "<?php echo site_url('admin/sync_data_2/' . $status_cbt->token_cbt . '/'); ?>",
                                            data: {
                                                'id': '' + element['id_jurusan']
                                            },
                                            success: function (result) {
                                                if (result === 'OK') {
                                                    $berhasil++;
                                                    var prcn = Math.round(($berhasil / ret_data['jumlah_data']) * 100);
                                                    $('#bar-sukses-2').attr('style', 'width: ' + prcn + '%;');
                                                } else {
                                                    $gagal++;
                                                    var prcn = Math.round(($gagal / ret_data['jumlah_data']) * 100);
                                                    $('#bar-gagal-2').attr('style', 'width: ' + prcn + '%;');
                                                }

                                                $('#persen-2').html(prcn + '%');
                                                if (prcn > 98) {
                                                    $('#header-2').html(' - Ditemukan ' + ret_data['jumlah_data'] + ' data - PROSES SELESAI');
                                                    $('#keterangan-progress-2').html('Update data Selesai...');
                                                    $('#update_3').removeAttr("disabled");
                                                }
                                            }
                                        });
                                    });
                                }
                            }
                            ,
                            error: function (jqXHR, textStatus, errorThrown) {
                                $('#keterangan-progress-2').html(textStatus + ' - ' + errorThrown);
                            }
                        });
                    }
                });
            }
        });
        var proses3 = false;
        $('#update_3').click(function (e) {
            if (proses3 === false) {
                proses3 = true;
                $('#update_3').addClass('disabled');
                $('#update_3').removeClass('btn-danger');
                $('#update_3').addClass('btn-success');
                $.ajax({
                    type: "GET",
                    url: "<?php echo site_url('admin/trunc_data_3/' . $status_cbt->token_cbt . '/'); ?>",
                    success: function (result) {
                        $.ajax({
                            type: 'GET',
                            url: '<?php echo $status_cbt->alamat_server_cbt . '/home/sync_data_3/' . $status_cbt->token_cbt . '/' . $status_cbt->kode_unix; ?>',
                            dataType: 'json',
                            success: function (ret_data) {
                                if (ret_data['error'] === "Server Off") {
                                    $('#header-3').html('[Server Off], tidak dapat melakukan syncronisasi');
                                } else {
                                    $('#header-3').html(' - Ditemukan ' + ret_data['jumlah_data'] + ' data');
                                    $('#keterangan-progress-3').html('Mengupdate data ...');
                                    var $berhasil = 0;
                                    var $gagal = 0;
                                    if (ret_data['jumlah_data'] > 0) {
                                        $.each(ret_data['data'], function (index, element) {
                                            //console.log(index + " = " + element['id_kelas']);
                                            $.ajax({
                                                type: "POST",
                                                url: "<?php echo site_url('admin/sync_data_3/' . $status_cbt->token_cbt . '/'); ?>",
                                                data: {
                                                    'id': '' + element['id_mata_pelajaran']
                                                },
                                                success: function (result) {
                                                    if (result === 'OK') {
                                                        $berhasil++;
                                                        var prcn = Math.round(($berhasil / ret_data['jumlah_data']) * 100);
                                                        $('#bar-sukses-3').attr('style', 'width: ' + prcn + '%;');
                                                    } else {
                                                        $gagal++;
                                                        var prcn = Math.round(($gagal / ret_data['jumlah_data']) * 100);
                                                        $('#bar-gagal-3').attr('style', 'width: ' + prcn + '%;');
                                                    }

                                                    $('#persen-3').html(prcn + '%');
                                                    if (prcn > 98) {
                                                        $('#header-3').html(' - Ditemukan ' + ret_data['jumlah_data'] + ' data - PROSES SELESAI');
                                                        $('#keterangan-progress-3').html('Update data Selesai...');
                                                        $('#update_4').removeAttr("disabled");
                                                    }
                                                }
                                            });
                                        });
                                    } else {
                                        $('#header-3').html(' - Ditemukan ' + ret_data['jumlah_data'] + ' data - PROSES SELESAI');
                                        $('#keterangan-progress-3').html('Update data Selesai...');
                                        $('#update_4').removeAttr("disabled");
                                    }
                                }
                            },
                            error: function (jqXHR, textStatus, errorThrown) {
                                $('#keterangan-progress-3').html(textStatus + ' - ' + errorThrown);
                            }
                        });
                    }
                });
            }
        });
        var proses4 = false;
        $('#update_4').click(function (e) {
            if (proses4 === false) {
                proses4 = true;
                $('#update_4').addClass('disabled');
                $('#update_4').removeClass('btn-danger');
                $('#update_4').addClass('btn-success');
                $.ajax({
                    type: "GET",
                    url: "<?php echo site_url('admin/trunc_data_4/' . $status_cbt->token_cbt . '/'); ?>",
                    success: function (result) {
                        $.ajax({
                            type: 'GET',
                            url: '<?php echo $status_cbt->alamat_server_cbt . '/home/sync_data_4/' . $status_cbt->token_cbt . '/' . $status_cbt->kode_unix; ?>',
                            dataType: 'json',
                            success: function (ret_data) {
                                if (ret_data['error'] === "Server Off") {
                                    $('#header-4').html('[Server Off], tidak dapat melakukan syncronisasi');
                                } else {
                                    $('#header-4').html(' - Ditemukan ' + ret_data['jumlah_data'] + ' data');
                                    $('#keterangan-progress-4').html('Mengupdate data ...');
                                    var $berhasil = 0;
                                    var $gagal = 0;
                                    $.each(ret_data['data'], function (index, element) {
                                        //console.log(index + " = " + element['id_kelas']);
                                        $.ajax({
                                            type: "POST",
                                            url: "<?php echo site_url('admin/sync_data_4/' . $status_cbt->token_cbt . '/'); ?>",
                                            data: {
                                                'id': '' + element['id_materi']
                                            },
                                            success: function (result) {
                                                if (result === 'OK') {
                                                    $berhasil++;
                                                    var prcn = Math.round(($berhasil / ret_data['jumlah_data']) * 100);
                                                    $('#bar-sukses-4').attr('style', 'width: ' + prcn + '%;');
                                                } else {
                                                    $gagal++;
                                                    var prcn = Math.round(($gagal / ret_data['jumlah_data']) * 100);
                                                    $('#bar-gagal-4').attr('style', 'width: ' + prcn + '%;');
                                                }

                                                $('#persen-4').html(prcn + '%');
                                                if (prcn > 98) {
                                                    $('#header-4').html(' - Ditemukan ' + ret_data['jumlah_data'] + ' data - PROSES SELESAI');
                                                    $('#keterangan-progress-4').html('Update data Selesai...');
                                                    $('#update_5').removeAttr("disabled");
                                                }
                                            }
                                        });
                                    });
                                }
                            },
                            error: function (jqXHR, textStatus, errorThrown) {
                                $('#keterangan-progress-4').html(textStatus + ' - ' + errorThrown);
                            }
                        });
                    }
                });
            }
        });
        var proses5 = false;
        $('#update_5').click(function (e) {
            if (proses5 === false) {
                proses5 = true;
                $('#update_5').addClass('disabled');
                $('#update_5').removeClass('btn-danger');
                $('#update_5').addClass('btn-success');
                $.ajax({
                    type: "GET",
                    url: "<?php echo site_url('admin/trunc_data_5/' . $status_cbt->token_cbt . '/'); ?>",
                    success: function (result) {
                        $.ajax({
                            type: 'GET',
                            url: '<?php echo $status_cbt->alamat_server_cbt . '/home/sync_data_5/' . $status_cbt->token_cbt . '/' . $status_cbt->kode_unix; ?>',
                            dataType: 'json',
                            success: function (ret_data) {
                                if (ret_data['error'] === "Server Off") {
                                    $('#header-5').html('[Server Off], tidak dapat melakukan syncronisasi');
                                } else {
                                    $('#header-5').html(' - Ditemukan ' + ret_data['jumlah_data'] + ' data - MEMPROSES');
                                    $('#keterangan-progress-5').html('Mengupdate data ...');
                                    var $berhasil = 0;
                                    var $gagal = 0;
                                    $.each(ret_data['data'], function (index, element) {
                                        $.ajax({
                                            type: "POST",
                                            url: "<?php echo site_url('admin/sync_data_5/' . $status_cbt->token_cbt . '/'); ?>",
                                            data: {
                                                'id': '' + element['id_jenis_ujian']
                                            },
                                            success: function (result) {
                                                if (result === 'OK') {
                                                    $berhasil++;
                                                    var prcn = Math.round(($berhasil / ret_data['jumlah_data']) * 100);
                                                    $('#bar-sukses-5').attr('style', 'width: ' + prcn + '%;');
                                                } else {
                                                    $gagal++;
                                                    var prcn = Math.round(($gagal / ret_data['jumlah_data']) * 100);
                                                    $('#bar-gagal-5').attr('style', 'width: ' + prcn + '%;');
                                                }

                                                $('#persen-5').html(prcn + '%');
                                                if (prcn > 98) {
                                                    $('#header-5').html(' - Ditemukan ' + ret_data['jumlah_data'] + ' data - PROSES SELESAI');
                                                    $('#keterangan-progress-5').html('Update data Selesai...');
                                                    $('#update_6').removeAttr("disabled");
                                                }
                                            }
                                        });
                                    });
                                }
                            },
                            error: function (jqXHR, textStatus, errorThrown) {
                                $('#keterangan-progress-5').html(textStatus + ' - ' + errorThrown);
                            }
                        });
                    }
                });
            }
        });
        var proses6 = false;
        $('#update_6').click(function (e) {
            if (proses6 === false) {
                proses6 = true;
                $('#update_6').addClass('disabled');
                $('#update_6').removeClass('btn-danger');
                $('#update_6').addClass('btn-success');
                $.ajax({
                    type: "GET",
                    url: "<?php echo site_url('admin/trunc_data_6/' . $status_cbt->token_cbt . '/'); ?>",
                    success: function (result) {
                        $.ajax({
                            type: 'GET',
                            url: '<?php echo site_url('admin/sync_data_6/' . $status_cbt->token_cbt . '/' . $status_cbt->id_server); ?>',
                            dataType: 'json',
                            success: function (ret_data) {
                                console.log(ret_data);
                                if (ret_data['status'] === "GAGAL") {
                                    $('#header-6').html('[Server Off], tidak dapat melakukan syncronisasi');
                                } else {
                                    $('#header-6').html(' - Ditemukan ' + ret_data['jumlah_data'] + ' data - MEMPROSES, JANGAN TUTUP HALAMAN INI');
                                    $('#keterangan-progress-6').html('Mengupdate data ...');
                                    if (ret_data['status'] === 'OK') {
                                        $('#header-6').html(' - PROSES SELESAI');
                                        $('#keterangan-progress-6').html('Update Selesai ...');
                                        $('#bar-sukses-6').attr('style', 'width: 100%;');
                                    } else {
                                        $('#keterangan-progress-6').html('Update Gagal ...');
                                        $('#bar-gagal-6').attr('style', 'width: 0%;');
                                    }
                                }

                                $('#update_7').removeAttr("disabled");
                            },
                            error: function (jqXHR, textStatus, errorThrown) {
                                $('#keterangan-progress-6').html(textStatus + ' - ' + errorThrown);
                            }
                        });
                    }
                });
            }
        });
        var proses7 = false;
        $('#update_7').click(function (e) {
            if (proses7 === false) {
                proses7 = true;
                $('#update_7').addClass('disabled');
                $('#update_7').removeClass('btn-danger');
                $('#update_7').addClass('btn-success');
                $.ajax({
                    type: "GET",
                    url: "<?php echo site_url('admin/trunc_data_7/' . $status_cbt->token_cbt . '/'); ?>",
                    success: function (result) {
                        $.ajax({
                            type: 'GET',
                            url: '<?php echo $status_cbt->alamat_server_cbt . '/home/sync_data_7/' . $status_cbt->token_cbt . '/' . $status_cbt->kode_unix; ?>',
                            dataType: 'json',
                            success: function (ret_data) {
                                if (ret_data['error'] === "Server Off") {
                                    $('#header-7').html('[Server Off], tidak dapat melakukan syncronisasi');
                                } else {
                                    $('#header-7').html(' - Ditemukan ' + ret_data['jumlah_data'] + ' data - MEMPROSES, JANGAN TUTUP HALAMAN INI');
                                    $('#keterangan-progress-7').html('Mengupdate data ...');
                                    var $berhasil = 0;
                                    var $gagal = 0;
                                    var jumlah = 0;
                                    if (ret_data['jumlah_data'] > 0) {
                                        $.each(ret_data['data'], function (index, element) {
                                            $.ajax({
                                                type: "POST",
                                                url: "<?php echo site_url('admin/sync_data_7/' . $status_cbt->token_cbt . '/'); ?>",
                                                data: {
                                                    'id': '' + element['id_paket_soal']
                                                },
                                                success: function (result) {
                                                    jumlah++;
                                                    if (result === 'OK') {
                                                        $berhasil++;
                                                        var prcn = Math.round(($berhasil / ret_data['jumlah_data']) * 100);
                                                        $('#bar-sukses-7').attr('style', 'width: ' + prcn + '%;');
                                                    } else {
                                                        $gagal++;
                                                        var prcn = Math.round(($gagal / ret_data['jumlah_data']) * 100);
                                                        $('#bar-gagal-7').attr('style', 'width: ' + prcn + '%;');
                                                    }

                                                    $('#persen-7').html(prcn + '%');
                                                    if (prcn > 98) {
                                                        $('#header-7').html(' - Ditemukan ' + ret_data['jumlah_data'] + ' data - PROSES SELESAI');
                                                        $('#keterangan-progress-7').html('Update data Selesai...');
                                                        $('#update_8').removeAttr("disabled");
                                                    }
                                                }
                                            });
                                        });
                                    } else {
                                        $('#header-7').html(' - Tidak ada data - PROSES SELESAI');
                                        $('#keterangan-progress-7').html('Update data Selesai...');
                                        $('#update_8').removeAttr("disabled");
                                    }
                                }
                            },
                            error: function (jqXHR, textStatus, errorThrown) {
                                $('#keterangan-progress-7').html(textStatus + ' - ' + errorThrown);
                            }
                        });
                    }
                });
            }
        });
        var proses8 = false;
        $('#update_8').click(function (e) {
            if (proses8 === false) {
                proses8 = true;
                $('#update_8').addClass('disabled');
                $('#update_8').removeClass('btn-danger');
                $('#update_8').addClass('btn-success');
                $.ajax({
                    type: "GET",
                    url: "<?php echo site_url('admin/trunc_data_8/' . $status_cbt->token_cbt . '/'); ?>",
                    success: function (result) {
                        $.ajax({
                            type: 'GET',
                            url: '<?php echo $status_cbt->alamat_server_cbt . '/home/sync_data_8/' . $status_cbt->token_cbt . '/' . $status_cbt->kode_unix; ?>',
                            dataType: 'json',
                            success: function (ret_data) {
                                if (ret_data['error'] === "Server Off") {
                                    $('#header-8').html('[Server Off], tidak dapat melakukan syncronisasi');
                                } else {
                                    $('#header-8').html(' - Ditemukan ' + ret_data['jumlah_data'] + ' data - MEMPROSES, JANGAN TUTUP HALAMAN INI');
                                    $('#keterangan-progress-8').html('Mengupdate data ...');
                                    var $berhasil = 0;
                                    var $gagal = 0;
                                    var jumlah = 0;
                                    var prcn = 0;

                                    var time = 500;

                                    $.each(ret_data['data'], function (index, element) {
                                        //console.log(index + " = " + element['id_kelas']);
                                        setTimeout(function () {
                                            $.ajax({
                                                type: "POST",
                                                url: "<?php echo site_url('admin/sync_data_8/' . $status_cbt->token_cbt); ?>/" + element['bank_soal'],
                                                success: function (result) {
                                                    jumlah++;
                                                    if (result === 'OK') {
                                                        $berhasil++;
                                                        prcn = Math.round(($berhasil / ret_data['jumlah_data']) * 100);
                                                        //$('#bar-sukses-8').attr('style', 'width: ' + prcn + '%;');
                                                    } else {
                                                        $gagal++;
                                                        //prcn = Math.round(($gagal / ret_data['jumlah_data']) * 100);
                                                        //$('#bar-gagal-8').attr('style', 'width: ' + prcn + '%;');
                                                    }

                                                    $('#persen-8').html(prcn + '%');
                                                    $('#bar-gagal-8').attr('style', 'width: ' + prcn + '%;');
                                                    if (prcn > 98) {
                                                        $('#header-8').html(' - Ditemukan ' + ret_data['jumlah_data'] + ' data - PROSES SELESAI');
                                                        $('#keterangan-progress-8').html('Update data Selesai...');
                                                        $('#update_9').removeAttr("disabled");
                                                    }
                                                }
                                            });
                                        }, time);
                                        time += 500;
                                    });
                                }
                            },
                            error: function (jqXHR, textStatus, errorThrown) {
                                $('#keterangan-progress-8').html(textStatus + ' - ' + errorThrown);
                            }
                        });
                    }
                });
            }
        });
        var proses9 = false;
        $('#update_9').click(function (e) {
            if (proses9 === false) {
                proses9 = true;
                $('#update_9').addClass('disabled');
                $('#update_9').removeClass('btn-danger');
                $('#update_9').addClass('btn-success');
                $.ajax({
                    type: "GET",
                    url: "<?php echo site_url('admin/trunc_data_9/' . $status_cbt->token_cbt . '/'); ?>",
                    success: function (result) {
                        $.ajax({
                            type: 'GET',
                            url: '<?php echo $status_cbt->alamat_server_cbt . '/home/sync_data_9/' . $status_cbt->token_cbt . '/' . $status_cbt->kode_unix; ?>',
                            dataType: 'json',
                            success: function (ret_data) {
                                if (ret_data['error'] === "Server Off") {
                                    $('#header-9').html('[Server Off], tidak dapat melakukan syncronisasi');
                                } else {
                                    $('#header-9').html(' - Ditemukan ' + ret_data['jumlah_data'] + ' data - MEMPROSES, JANGAN TUTUP HALAMAN INI');
                                    $('#keterangan-progress-9').html('Mengupdate data ...');
                                    var $berhasil = 0;
                                    var $gagal = 0;
                                    var jumlah = 0;
                                    $.each(ret_data['data'], function (index, element) {
                                        //console.log(index + " = " + element['id_kelas']);
                                        $.ajax({
                                            type: "POST",
                                            url: "<?php echo site_url('admin/sync_data_9/' . $status_cbt->token_cbt . '/'); ?>",
                                            data: {
                                                'id': '' + element['id_jadwal_ujian']
                                            },
                                            success: function (result) {
                                                jumlah++;
                                                if (result === 'OK') {
                                                    $berhasil++;
                                                    var prcn = Math.round(($berhasil / ret_data['jumlah_data']) * 100);
                                                    $('#bar-sukses-9').attr('style', 'width: ' + prcn + '%;');
                                                } else {
                                                    $gagal++;
                                                    var prcn = Math.round(($gagal / ret_data['jumlah_data']) * 100);
                                                    $('#bar-gagal-9').attr('style', 'width: ' + prcn + '%;');
                                                }

                                                $('#persen-9').html(prcn + '%');
                                                if (prcn > 98) {
                                                    $('#header-9').html(' - Ditemukan ' + ret_data['jumlah_data'] + ' data - PROSES SELESAI');
                                                    $('#keterangan-progress-9').html('Update data Selesai...');
                                                    $('#update_10').removeAttr("disabled");
                                                }
                                            }
                                        });
                                    });
                                }
                            },
                            error: function (jqXHR, textStatus, errorThrown) {
                                $('#keterangan-progress-9').html(textStatus + ' - ' + errorThrown);
                            }
                        });
                    }
                });
            }
        });
        var proses10 = false;
        $('#update_10').click(function (e) {
            if (proses10 === false) {
                proses10 = true;
                $('#update_10').addClass('disabled');
                $('#update_10').removeClass('btn-danger');
                $('#update_10').addClass('btn-success');
                $.ajax({
                    type: "GET",
                    url: "<?php echo site_url('admin/trunc_data_10/' . $status_cbt->token_cbt . '/'); ?>",
                    success: function (result) {
                        $.ajax({
                            type: 'GET',
                            url: '<?php echo $status_cbt->alamat_server_cbt . '/home/sync_data_10/' . $status_cbt->token_cbt . '/' . $status_cbt->kode_unix; ?>',
                            dataType: 'json',
                            success: function (ret_data) {
                                if (ret_data['error'] === "Server Off") {
                                    $('#header-10').html('[Server Off], tidak dapat melakukan syncronisasi');
                                } else {
                                    $('#header-10').html(' - Ditemukan ' + ret_data['jumlah_data'] + ' data - MEMPROSES, JANGAN TUTUP HALAMAN INI');
                                    $('#keterangan-progress-10').html('Mengupdate data ...');
                                    var $berhasil = 0;
                                    var $gagal = 0;
                                    var jumlah = 0;
                                    $.each(ret_data['data'], function (index, element) {
                                        //console.log(index + " = " + element['id_kelas']);
                                        $.ajax({
                                            type: "POST",
                                            url: "<?php echo site_url('admin/sync_data_10/' . $status_cbt->token_cbt . '/'); ?>",
                                            data: {
                                                'id': '' + element['id_detail_jadwal_ujian']
                                            },
                                            success: function (result) {
                                                jumlah++;
                                                if (result === 'OK') {
                                                    $berhasil++;
                                                    var prcn = Math.round(($berhasil / ret_data['jumlah_data']) * 100);
                                                    $('#bar-sukses-10').attr('style', 'width: ' + prcn + '%;');
                                                } else {
                                                    $gagal++;
                                                    var prcn = Math.round(($gagal / ret_data['jumlah_data']) * 100);
                                                    $('#bar-gagal-10').attr('style', 'width: ' + prcn + '%;');
                                                }


                                                $('#persen-10').html(prcn + '%');
                                                if (prcn > 98) {
                                                    $('#header-10').html(' - Ditemukan ' + ret_data['jumlah_data'] + ' data - PROSES SELESAI');
                                                    $('#keterangan-progress-10').html('Update data Selesai...');
                                                    $('#update_11').removeAttr("disabled");
                                                }
                                            }
                                        });
                                    });
                                }
                            },
                            error: function (jqXHR, textStatus, errorThrown) {
                                $('#keterangan-progress-10').html(textStatus + ' - ' + errorThrown);
                            }
                        });
                    }
                });
            }
        });
        var proses11 = false;
        $('#update_11').click(function (e) {
            if (proses11 === false) {
                proses11 = true;
                $('#update_11').addClass('disabled');
                $('#update_11').removeClass('btn-danger');
                $('#update_11').addClass('btn-success');
                $.ajax({
                    type: "GET",
                    url: "<?php echo site_url('admin/trunc_data_11/' . $status_cbt->token_cbt . '/'); ?>",
                    success: function (result) {
                        $.ajax({
                            type: 'GET',
                            url: '<?php echo $status_cbt->alamat_server_cbt . '/home/sync_data_11/' . $status_cbt->token_cbt . '/' . $status_cbt->kode_unix; ?>',
                            dataType: 'json',
                            success: function (ret_data) {
                                if (ret_data['error'] === "Server Off") {
                                    $('#header-11').html('[Server Off], tidak dapat melakukan syncronisasi');
                                } else {
                                    $('#header-11').html(' - Ditemukan ' + ret_data['jumlah_data'] + ' data - MEMPROSES, JANGAN TUTUP HALAMAN INI');
                                    $('#keterangan-progress-11').html('Mengupdate data ...');
                                    var $berhasil = 0;
                                    var $gagal = 0;
                                    var jumlah = 0;

                                    var time = 500;

                                    $.each(ret_data['data'], function (index, element) {
                                        //console.log(index + " = " + element['id_kelas']);
                                        setTimeout(function () {
                                            $.ajax({
                                                type: "POST",
                                                url: "<?php echo site_url('admin/sync_data_11/' . $status_cbt->token_cbt . '/'); ?>",
                                                data: {
                                                    'id': '' + element['id_detail_paket_soal']
                                                },
                                                success: function (result) {
                                                    jumlah++;
                                                    if (result === 'OK') {
                                                        $berhasil++;
                                                        var prcn = Math.round(($berhasil / ret_data['jumlah_data']) * 100);
                                                        $('#bar-sukses-11').attr('style', 'width: ' + prcn + '%;');
                                                    } else {
                                                        $gagal++;
                                                        var prcn = Math.round(($gagal / ret_data['jumlah_data']) * 100);
                                                        $('#bar-gagal-11').attr('style', 'width: ' + prcn + '%;');
                                                    }

                                                    $('#persen-11').html(prcn + '%');
                                                    if (prcn > 98) {
                                                        $('#header-11').html(' - Ditemukan ' + ret_data['jumlah_data'] + ' data - PROSES SELESAI');
                                                        $('#keterangan-progress-11').html('Update data Selesai...');
                                                        $('#update_12').removeAttr("disabled");
                                                    }
                                                }
                                            });
                                        }, time);
                                        time += 500;
                                    });
                                }
                            },
                            error: function (jqXHR, textStatus, errorThrown) {
                                $('#keterangan-progress-11').html(textStatus + ' - ' + errorThrown);
                            }
                        });
                    }
                });
            }
        });
        var proses12 = false;
        $('#update_12').click(function (e) {
            if (proses12 === false) {
                proses12 = true;
                $('#update_12').addClass('disabled');
                $('#update_12').removeClass('btn-danger');
                $('#update_12').addClass('btn-success');
                $.ajax({
                    type: "GET",
                    url: "<?php echo site_url('admin/trunc_data_12/' . $status_cbt->token_cbt . '/'); ?>",
                    success: function (result) {
                        $.ajax({
                            type: 'GET',
                            url: '<?php echo $status_cbt->alamat_server_cbt . '/home/sync_data_12/' . $status_cbt->token_cbt . '/' . $status_cbt->kode_unix; ?>',
                            dataType: 'json',
                            success: function (ret_data) {
                                if (ret_data['error'] === "Server Off") {
                                    $('#header-12').html('[Server Off], tidak dapat melakukan syncronisasi');
                                } else {
                                    $('#header-12').html(' - Ditemukan ' + ret_data['jumlah_data'] + ' data - MEMPROSES, JANGAN TUTUP HALAMAN INI');
                                    $('#keterangan-progress-12').html('Mengupdate data ...');
                                    var $berhasil = 0;
                                    var $gagal = 0;
                                    var jumlah = 0;
                                    $.each(ret_data['data'], function (index, element) {
                                        //console.log(index + " = " + element['id_kelas']);
                                        $.ajax({
                                            type: "POST",
                                            url: "<?php echo site_url('admin/sync_data_12/' . $status_cbt->token_cbt . '/'); ?>",
                                            data: {
                                                'id': '' + element['id_jenjang_pendidikan']
                                            },
                                            success: function (result) {
                                                jumlah++;
                                                if (result === 'OK') {
                                                    $berhasil++;
                                                    var prcn = Math.round(($berhasil / ret_data['jumlah_data']) * 100);
                                                    $('#bar-sukses-12').attr('style', 'width: ' + prcn + '%;');
                                                } else {
                                                    $gagal++;
                                                    var prcn = Math.round(($gagal / ret_data['jumlah_data']) * 100);
                                                    $('#bar-gagal-12').attr('style', 'width: ' + prcn + '%;');
                                                }

                                                $('#persen-12').html(prcn + '%');
                                                if (prcn > 98) {
                                                    $('#header-12').html(' - Ditemukan ' + ret_data['jumlah_data'] + ' data - PROSES SELESAI');
                                                    $('#keterangan-progress-12').html('Update data Selesai...');
                                                    $('#update_13').removeAttr("disabled");
                                                }
                                            }
                                        });
                                    });
                                }
                            },
                            error: function (jqXHR, textStatus, errorThrown) {
                                $('#keterangan-progress-12').html(textStatus + ' - ' + errorThrown);
                            }
                        });
                    }
                });
            }
        });
        var proses13 = false;
        $('#update_13').click(function (e) {
            if (proses13 === false) {
                proses13 = true;
                $('#update_13').addClass('disabled');
                $('#update_13').removeClass('btn-danger');
                $('#update_13').addClass('btn-success');
                $.ajax({
                    type: 'GET',
                    url: '<?php echo site_url('admin/sync_data_13/'); ?>',
                    dataType: 'json',
                    success: function (ret_data) {
                        if (ret_data['error'] === "Server Off") {
                            $('#header-1').html('[Server Off], tidak dapat melakukan syncronisasi');
                        } else {
                            if (ret_data['jumlah_data'] > 0) {
                                $('#header-13').html(' - Terdapat ' + ret_data['jumlah_data'] + ' file data Audio/Video - Mendownload DATA, JANGAN TUTUP HALAMAN INI');
                                $('#keterangan-progress-13').html('Mendownload data ...');
                                var $berhasil = 0;
                                var $gagal = 0;
                                var jumlah = 0;
                                $.each(ret_data['data'], function (index, element) {
                                    //console.log(index + " = " + element['id_kelas']);
                                    $.ajax({
                                        type: "POST",
                                        url: "<?php echo site_url('admin/download_file'); ?>/",
                                        data: {
                                            'id': '' + element['id_bank_soal']
                                        },
                                        success: function (result) {
                                            jumlah++;
                                            if (result === 'OK') {
                                                $berhasil++;
                                                var prcn = Math.round(($berhasil / ret_data['jumlah_data']) * 100);
                                                $('#bar-sukses-13').attr('style', 'width: ' + prcn + '%;');
                                            } else {
                                                $gagal++;
                                                var prcn = Math.round(($gagal / ret_data['jumlah_data']) * 100);
                                                $('#bar-gagal-13').attr('style', 'width: ' + prcn + '%;');
                                            }

                                            if (jumlah === ret_data['jumlah_data']) {
                                                $('#keterangan-progress-13').html('Download data Selesai...');
                                            }

                                            $('#persen-13').html(prcn + '%');
                                            if (prcn > 98) {
                                                $('#header-13').html(' - Ditemukan ' + ret_data['jumlah_data'] + ' data - PROSES SELESAI');
                                                $('#keterangan-progress-13').html('Update data Selesai...');
                                            }
                                        },
                                        error: function (jqXHR, textStatus, errorThrown) {
                                            $('#keterangan-progress-13').html(textStatus + ' - ' + errorThrown);
                                        }
                                    });
                                });
                            } else {
                                $('#header-13').html(' - Tidak ada ASSETS AUDIO/VIDEO');
                                $('#keterangan-progress-13').html('Download Selesai ...');
                            }
                        }
                    },
                    error: function (jqXHR, textStatus, errorThrown) {
                        $('#keterangan-progress-13').html(textStatus + ' - ' + errorThrown);
                    }
                });
            }
        });
    });
</script>



