<?php
ini_set('max_execution_time', 300); 
require "../../config/koneksi.php";
require "../../config/function.php";

$datetime = date('Y-m-d H:i:s');
if ($koneksi) {
    
    $data = isset($_POST['datasinkron']) ? $_POST['datasinkron'] : '';
    $token = $_POST['tokenapi'];
    if ($token <> '' and $data <> '') {
        mysqli_query($koneksi, "UPDATE aplikasi set token_api='$token' where id_aplikasi='1'");
        foreach ($data as $data) {
            $gagal = $gagal2 = $gagal3 = $gagal4 = $gagal5 = $gagal6 = $gagal7 = $gagal8 = $gagal9 = 0;
            $masuk1 = $masuk2 = $masuk3 = $masuk4 = $masuk5 = $masuk6 = $masuk7 = $masuk8 = $masuk9 = 0;
            if ($data == 'siswa') {
                $datax = http_request($setting['url_host'] . "/syncsiswa.php?token=" . $token .  "&server=" . $setting['id_server']);
                $r = json_decode($datax, TRUE);
                if ($r <> null) {
                    //if ($r['token'] == 'tokenx') {
                    $sql = mysqli_query($koneksi, "truncate table siswa");
                    $i = 1;
                    foreach ($r['siswa'] as $r) {
                        $sql = mysqli_query($koneksi, "insert into siswa
                            (id_siswa,id_kelas,idpk,nisn,no_peserta,nama,level,ruang,sesi,username,password,foto,server,agama,jenis_kelamin) values 			
                            ('$r[id_siswa]','$r[id_kelas]','$r[idpk]','$r[nisn]','$r[no_peserta]','" . addslashes($r['nama']) . "','$r[level]','$r[ruang]','$r[sesi]','$r[username]','$r[password]','$r[foto]','$r[server]','$r[agama]','$r[jenis_kelamin]')");

                        $qkelas = mysqli_query($koneksi, "SELECT id_kelas FROM kelas WHERE id_kelas='$r[id_kelas]'");
                        $cekkelas = mysqli_num_rows($qkelas);
                        if (!$cekkelas <> 0) {
                            $exec = mysqli_query($koneksi, "INSERT INTO kelas (id_kelas,level,nama)VALUES('$r[id_kelas]','$r[level]','$r[id_kelas]')");
                        }
                        if ($setting['jenjang'] == 'SMK') {

                            $qpk = mysqli_query($koneksi, "SELECT id_pk FROM pk WHERE id_pk='$r[idpk]'");
                            $cekpk = mysqli_num_rows($qpk);
                            if (!$cekpk <> 0) {
                                $exec = mysqli_query($koneksi, "INSERT INTO pk (id_pk,program_keahlian)VALUES('$r[idpk]','$r[idpk]')");
                            }
                        }
                        $qlevel = mysqli_query($koneksi, "SELECT kode_level FROM level WHERE kode_level='$r[level]'");
                        $ceklevel = mysqli_num_rows($qlevel);
                        if (!$ceklevel <> 0) {
                            $exec = mysqli_query($koneksi, "INSERT INTO level (kode_level,keterangan)VALUES('$r[level]','$r[level]')");
                        }
                        $qruang = mysqli_query($koneksi, "SELECT kode_ruang FROM ruang WHERE kode_ruang='$r[ruang]'");
                        $cekruang = mysqli_num_rows($qruang);
                        if (!$cekruang <> 0) {
                            $exec = mysqli_query($koneksi, "INSERT INTO ruang (kode_ruang,keterangan)VALUES('$r[ruang]','$r[ruang]')");
                        }
                        $qsesi = mysqli_query($koneksi, "SELECT kode_sesi FROM sesi WHERE kode_sesi='$r[sesi]'");
                        $ceksesi = mysqli_num_rows($qsesi);
                        if (!$ceksesi <> 0) {
                            $exec = mysqli_query($koneksi, "INSERT INTO sesi (kode_sesi,nama_sesi)VALUES('$r[sesi]','$r[sesi]')");
                        }
                        $qserver = mysqli_query($koneksi, "SELECT kode_server FROM server WHERE kode_server='$r[server]'");
                        $cekserver = mysqli_num_rows($qserver);
                         if (!$cekserver <> 0) {
                       $exec = mysqli_query($koneksi, "INSERT INTO server (kode_server,nama_server,status)VALUES('$r[server]','$r[server]','aktif')");
                         }
                        if (!$sql) {
                            $gagal++;
                        } else {
                            $masuk1++;
                        }
                    }

                    $exec = mysqli_query($koneksi, "update sinkron set jumlah='$masuk1', status_sinkron='1', tanggal='$datetime' where nama_data='DATA1'");
                   
                    echo "
                                    <div class='row'>
                                        <div class='col-md-12'>
                                            <div class='box box-solid'>
                                                <div class='box-header with-border'>
                                                <h5 class='box-title'>Data Masuk</h5>
                                                </div>
                                                <div class='box-body'>
                                                <table class='table table-striped'>
                                                        <th>Nama Data</th><th>Data Berhasil Masuk</th><th>Data Gagal</th>
                                                        <tr><td>Peserta Ujian</td><td><i class='fa fa-check text-green'></i> $masuk1</td><td><i class='fa fa-times text-red'></i> $gagal</td></tr>
                                                        
                                                    </table>
                                                
                                                </div><!-- /.box-body -->
                                            </div><!-- /.box -->
                                        </div>
                                    </div>";
                } else {
                    echo '<div class="alert alert-danger alert-dismissible">
        <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
        <h4><i class="icon fa fa-ban"></i> Sinkron Data Siswa Gagal!</h4>
        Silahkan periksa koneksi internet dan token
      </div>';
                }
            }
            if ($data == 'soal') {


                $syncdata = http_request($setting['url_host'] . "/syncsoal.php?token=" . $token);

                $sync = json_decode($syncdata, TRUE);

                if ($sync <> null) {
                    $sql = mysqli_query($koneksi, "truncate table mapel");
                    $sql = mysqli_query($koneksi, "truncate table soal");

                    foreach ($sync['bank'] as $banksoal) {
                       
                        if ($banksoal['status'] == 1) {
                            $sql = mysqli_query($koneksi, "insert into banksoal
                            (id_bank,kode,idpk,idguru,nama,jml_soal,jml_esai,jml_multi,jml_bs,jml_urut,tampil_pg,tampil_esai,tampil_multi,tampil_bs,tampil_urut,opsi,level,groupsoal,bobot_pg,bobot_esai,bobot_bs,bobot_multi,bobot_urut,kelas,date,status,sts,kkm,soal_agama) values 			
                            ('$banksoal[id_bank]','$banksoal[kode]','$banksoal[idpk]','$banksoal[idguru]','$banksoal[nama]','$banksoal[jml_soal]','$banksoal[jml_esai]','$banksoal[jml_multi]','$banksoal[jml_bs]','$banksoal[jml_urut]',
							'$banksoal[tampil_pg]','$banksoal[tampil_esai]','$banksoal[tampil_multi]','$banksoal[tampil_bs]','$banksoal[tampil_urut]','$banksoal[opsi]','$banksoal[level]','$banksoal[groupsoal]','$banksoal[bobot_pg]','$banksoal[bobot_esai]','$banksoal[bobot_bs]','$banksoal[bobot_multi]','$banksoal[bobot_urut]',
							'$banksoal[kelas]','$banksoal[date]','$banksoal[status]','$banksoal[sts]','$banksoal[kkm]','$banksoal[soal_agama]')");
                            if (!$sql) {
                                $gagal2++;
                            } else {
                                $masuk2++;
                            }

                            foreach ($sync['soal'] as $soal) {
                                if ($soal['id_bank'] == $banksoal['id_bank']) {
                                    $soalx = addslashes($soal['soal']);
                                    $pilA = addslashes($soal['pilA']);
                                    $pilB = addslashes($soal['pilB']);
                                    $pilC = addslashes($soal['pilC']);
                                    $pilD = addslashes($soal['pilD']);
                                    $pilE = addslashes($soal['pilE']);
									$perA = addslashes($soal['perA']);
                                    $perB = addslashes($soal['perB']);
                                    $perC = addslashes($soal['perC']);
                                    $perD = addslashes($soal['perD']);
                                    $perE = addslashes($soal['perE']);
                                    $sqlsoal = mysqli_query($koneksi, "insert into soal
                    (id_soal,id_bank,nomor,soal,jenis,kode,opsi,pilA,pilB,pilC,pilD,pilE,perA,perB,perC,perD,perE,jawaban,file,file1,fileA,fileB,fileC,fileD,fileE,ket,sts,groupsoal,pembahasan) values 			
                    ('$soal[id_soal]','$soal[id_bank]','$soal[nomor]','$soalx','$soal[jenis]','$soal[kode]','$soal[opsi]','$pilA','$pilB','$pilC','$pilD','$pilE','$perA','$perB','$perC','$perD','$perE','$soal[jawaban]','$soal[file]','$soal[file1]','$soal[fileA]','$soal[fileB]','$soal[fileC]','$soal[fileD]','$soal[fileE]','$soal[ket]','$soal[sts]','$soal[groupsoal]','$soal[pembahasan]')");
                            $sqlfile = mysqli_query($koneksi, "insert into file_pendukung(id_bank,nama_file) VALUES('$soal[id_bank]','$soal[file]')");    
								     
								if (!$sqlsoal) {
                                        $gagal3++;
                                    } else {
                                        $masuk3++;
                                    }
                                }
                            }

                            $urls = [];
                            $i = 0;
                            foreach ($sync['file'] as $file) {

                                if ($file['id_bank'] == $banksoal['id_bank']) {
                                    $urls[$i] = $setting['web'] . "/files/" . $file['nama_file'];
                                    $i++;
                                }
                            }
                            multiple_download($urls);
                            // }
                        }
                    }
                    $exec = mysqli_query($koneksi, "update sinkron set jumlah='$masuk2', status_sinkron='1',tanggal='$datetime'  where nama_data='DATA2'");
                    $exec = mysqli_query($koneksi, "update sinkron set jumlah='$masuk3', status_sinkron='1',tanggal='$datetime' where nama_data='DATA3'");

                    echo "
                                    <div class='row'>
                                        <div class='col-md-12'>
                                            <div class='box box-solid'>
                                                <div class='box-header with-border'>
                                                <h5 class='box-title'>DATA SOAL YANG MASUK KE LOKAL</h5>
                                                </div>
                                                <div class='box-body'>
                                                <table class='table table-striped'>
                                                        <th>Nama Data</th><th>Data Berhasil Masuk</th><th>Data Gagal</th>
                                                        <tr><td>Bank Soal</td><td><i class='fa fa-check text-green'></i> $masuk2</td><td><i class='fa fa-times text-red'></i> $gagal2</td></tr>
                                                        <tr><td>Data Soal</td><td><i class='fa fa-check text-green'></i> $masuk3</td><td><i class='fa fa-times text-red'></i> $gagal3</td></tr>
                                                       
                                                    </table>
                                                
                                                </div><!-- /.box-body -->
                                            </div><!-- /.box -->
                                        </div>
                                    </div>";
                } else {
                    echo '<div class="alert alert-danger alert-dismissible">
        <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
        <h4><i class="icon fa fa-ban"></i> Sinkron Data Soal Gagal!</h4>
        Silahkan periksa koneksi internet dan token
      </div>';
                }
            }
            if ($data == 'jadwal') {
                $syncdata = http_request($setting['url_host'] . "/syncsoal.php?token=" . $token);

                $sync = json_decode($syncdata, TRUE);

                if ($sync <> null) {

                    $sql = mysqli_query($koneksi, "truncate table ujian");
                    foreach ($sync['jadwal'] as $jadwal) {
                      
                        $sqljadwal = mysqli_query($koneksi, "insert into ujian
                                (id_ujian,kode_nama,id_pk,id_guru,id_bank,kode_ujian,nama,groupsoal,jml_soal,jml_esai,jml_multi,jml_bs,jml_urut,opsi,tampil_bs,tampil_urut,tampil_pg,tampil_esai,tampil_multi,lama_ujian,tgl_ujian,tgl_selesai,waktu_ujian,selesai_ujian,level,kelas,sesi,acak,token,status,hasil,kkm,ulang,soal_agama,reset,pelanggaran,btnselesai) values 			
                                ('$jadwal[id_ujian]','$jadwal[kode_nama]','$jadwal[id_pk]','$jadwal[id_guru]','$jadwal[id_bank]','$jadwal[kode_ujian]','$jadwal[nama]','$jadwal[groupsoal]','$jadwal[jml_soal]','$jadwal[jml_esai]','$jadwal[jml_multi]',
								'$jadwal[jml_bs]','$jadwal[jml_urut]','$jadwal[opsi]','$jadwal[tampil_bs]','$jadwal[tampil_urut]','$jadwal[tampil_pg]','$jadwal[tampil_esai]','$jadwal[tampil_multi]',
                                '$jadwal[lama_ujian]','$jadwal[tgl_ujian]','$jadwal[tgl_selesai]','$jadwal[waktu_ujian]','$jadwal[selesai_ujian]','$jadwal[level]','$jadwal[kelas]','$jadwal[sesi]','$jadwal[acak]','$jadwal[token]','$jadwal[status]','$jadwal[hasil]','$jadwal[kkm]','$jadwal[ulang]','$jadwal[soal_agama]','$jadwal[reset]','$jadwal[pelanggaran]','$jadwal[btnselesai]')");
                        if (!$sqljadwal) {
                            $gagal4++;
                        } else {
                            $masuk4++;
                        }
                    }
					
                    $exec = mysqli_query($koneksi, "update sinkron set jumlah='$masuk4', status_sinkron='1',tanggal='$datetime' where nama_data='DATA4'");
                    echo "
                                    <div class='row'>
                                        <div class='col-md-12'>
                                            <div class='box box-solid'>
                                                <div class='box-header with-border'>
                                                <h5 class='box-title'>DATA JADWAL YANG MASUK KE LOKAL</h5>
                                                </div>
                                                <div class='box-body'>
                                                <table class='table table-striped'>
                                                <th>Nama Data</th><th>Data Berhasil Masuk</th><th>Data Gagal</th>
                                                        <tr><td>Jadwal Ujian</td><td><i class='fa fa-check text-green'></i> $masuk4</td><td><i class='fa fa-times text-red'></i> $gagal4</td></tr>
                                                    </table>
                                                
                                                </div><!-- /.box-body -->
                                            </div><!-- /.box -->
                                        </div>
                                    </div>";
                } else {
                    echo '<div class="alert alert-danger alert-dismissible">
        <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
        <h4><i class="icon fa fa-ban"></i> Sinkron Data Jadwal Gagal!</h4>
        Silahkan periksa koneksi internet dan token
      </div>';
                }
            }
			
			  if ($data == 'jenis') {
                $syncdata = http_request($setting['url_host'] . "/syncsoal.php?token=" . $token);

                $sync = json_decode($syncdata, TRUE);

                if ($sync <> null) {
                
                    $sql = mysqli_query($koneksi, "truncate table jenis");
                    foreach ($sync['jenis'] as $jenis) {
                      
                        $sqljenis = mysqli_query($koneksi, "insert into jenis
                                (id_jenis,nama,status) values 			
                                ('$jenis[id_jenis]','$jenis[nama]','$jenis[status]')");
                        if (!$sqljenis) {
                            $gagal5++;
                        } else {
                            $masuk5++;
                        }
					}
					
                    $exec = mysqli_query($koneksi, "update sinkron set jumlah='$masuk5', status_sinkron='1',tanggal='$datetime' where nama_data='DATA5'");
                    echo "
                                    <div class='row'>
                                        <div class='col-md-12'>
                                            <div class='box box-solid'>
                                                <div class='box-header with-border'>
                                                <h5 class='box-title'>DATA JENIS UJIAN YANG MASUK KE LOKAL</h5>
                                                </div>
                                                <div class='box-body'>
                                                <table class='table table-striped'>
                                                <th>Nama Data</th><th>Data Berhasil Masuk</th><th>Data Gagal</th>
                                                        <tr><td>JENIS UJIAN</td><td><i class='fa fa-check text-green'></i> $masuk5</td><td><i class='fa fa-times text-red'></i> $gagal5</td></tr>
                                                    </table>
                                                
                                                </div><!-- /.box-body -->
                                            </div><!-- /.box -->
                                        </div>
                                    </div>";
                 } else {
                    echo '<div class="alert alert-danger alert-dismissible">
        <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
        <h4><i class="icon fa fa-ban"></i> Sinkron Data Materi Gagal!</h4>
        Silahkan periksa koneksi internet dan token
      </div>';
                }
            }
			
			if ($data == 'menu') {
                $syncdata = http_request($setting['url_host'] . "/syncsoal.php?token=" . $token);

                $sync = json_decode($syncdata, TRUE);

                if ($sync <> null) {
                
                    $sql = mysqli_query($koneksi, "truncate table menu");
                    foreach ($sync['menu'] as $menu) {
                      
                        $sqlmenu = mysqli_query($koneksi, "insert into menu
                                (id_menu,ujian,ulangi,kirim,tarik,soal,pindah,opsi,aplikasi) values 			
                                ('$menu[id_menu]','$menu[ujian]','$menu[ulangi]','$menu[kirim]','$menu[tarik]','$menu[soal]','$menu[pindah]','$menu[opsi]','$menu[aplikasi]')");
                        if (!$sqlmenu) {
                            $gagal7++;
                        } else {
                            $masuk7++;
                        }
					}
                
                    $exec = mysqli_query($koneksi, "update sinkron set jumlah='$masuk7', status_sinkron='1',tanggal='$datetime' where nama_data='DATA7'");
                    echo "
                                    <div class='row'>
                                        <div class='col-md-12'>
                                            <div class='box box-solid'>
                                                <div class='box-header with-border'>
                                                <h5 class='box-title'>DATA MENU YANG MASUK KE LOKAL</h5>
                                                </div>
                                                <div class='box-body'>
                                                <table class='table table-striped'>
                                                <th>Nama Data</th><th>Data Berhasil Masuk</th><th>Data Gagal</th>
                                                        <tr><td>Menu Ujian</td><td><i class='fa fa-check text-green'></i> $masuk7</td><td><i class='fa fa-times text-red'></i> $gagal7</td></tr>
                                                    </table>
                                                
                                                </div><!-- /.box-body -->
                                            </div><!-- /.box -->
                                        </div>
                                    </div>";
                 } else {
                    echo '<div class="alert alert-danger alert-dismissible">
        <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
        <h4><i class="icon fa fa-ban"></i> Sinkron Data Tugas Gagal!</h4>
        Silahkan periksa koneksi internet dan token
      </div>';
                }
            }
			
			
			 if ($data == 'quiz') {
                $syncdata = http_request($setting['url_host'] . "/syncsoal.php?token=" . $token);

                $sync = json_decode($syncdata, TRUE);

                if ($sync <> null) {
                
                    $sql = mysqli_query($koneksi, "truncate table soal_quiz");
                    foreach ($sync['quiz'] as $quiz) {
                      
                        $sqlquiz = mysqli_query($koneksi, "insert into soal_quiz
                                (id_bank,idmateri,nomor,kode,soal,pilA,pilB,pilC,pilD,pilE,jawaban) values 			
                                ('$quiz[id_bank]','$quiz[idmateri]','$quiz[nomor]','$quiz[kode]','$quiz[soal]','$quiz[pilA]','$quiz[pilB]','$quiz[pilC]','$quiz[pilD]','$quiz[pilE]','$quiz[jawaban]')");
                        if (!$sqlquiz) {
                            $gagal6++;
                        } else {
                            $masuk6++;
                        }
					}
                 
                    $exec = mysqli_query($koneksi, "update sinkron set jumlah='$masuk6', status_sinkron='1',tanggal='$datetime' where nama_data='DATA6'");
                    echo "
                                    <div class='row'>
                                        <div class='col-md-12'>
                                            <div class='box box-solid'>
                                                <div class='box-header with-border'>
                                                <h5 class='box-title'>DATA SOAL QUIZ YANG MASUK KE LOKAL</h5>
                                                </div>
                                                <div class='box-body'>
                                                <table class='table table-striped'>
                                                <th>Nama Data</th><th>Data Berhasil Masuk</th><th>Data Gagal</th>
                                                        <tr><td>Quiz Belajar</td><td><i class='fa fa-check text-green'></i> $masuk6</td><td><i class='fa fa-times text-red'></i> $gagal6</td></tr>
                                                    </table>
                                                
                                                </div><!-- /.box-body -->
                                            </div><!-- /.box -->
                                        </div>
                                    </div>";
                 } else {
                    echo '<div class="alert alert-danger alert-dismissible">
        <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
        <h4><i class="icon fa fa-ban"></i> Sinkron Data Quiz Gagal!</h4>
        Silahkan periksa koneksi internet dan token
      </div>';
                }
            }
			if ($data == 'pengumuman') {
                $syncdata = http_request($setting['url_host'] . "/syncsoal.php?token=" . $token);

                $sync = json_decode($syncdata, TRUE);

                if ($sync <> null) {
                
                    $sql = mysqli_query($koneksi, "truncate table pengumuman");
                    foreach ($sync['pengumuman'] as $pengumuman) {
                      
                        $sqlpengumuman = mysqli_query($koneksi, "insert into pengumuman
                                (type,judul,user,text,date) values 			
                                ('$pengumuman[type]','$pengumuman[judul]','$pengumuman[user]','$pengumuman[text]','$pengumuman[date]')");
                        if (!$sqlpengumuman) {
                            $gagal8++;
                        } else {
                            $masuk8++;
                        }
					}
                 
                    $exec = mysqli_query($koneksi, "update sinkron set jumlah='$masuk8', status_sinkron='1',tanggal='$datetime' where nama_data='DATA8'");
                    echo "
                                    <div class='row'>
                                        <div class='col-md-12'>
                                            <div class='box box-solid'>
                                                <div class='box-header with-border'>
                                                <h5 class='box-title'>DATA PENGUMUMAN YANG MASUK KE LOKAL</h5>
                                                </div>
                                                <div class='box-body'>
                                                <table class='table table-striped'>
                                                <th>Nama Data</th><th>Data Berhasil Masuk</th><th>Data Gagal</th>
                                                        <tr><td>Pengumuman</td><td><i class='fa fa-check text-green'></i> $masuk8</td><td><i class='fa fa-times text-red'></i> $gagal8</td></tr>
                                                    </table>
                                                
                                                </div><!-- /.box-body -->
                                            </div><!-- /.box -->
                                        </div>
                                    </div>";
                 } else {
                    echo '<div class="alert alert-danger alert-dismissible">
        <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
        <h4><i class="icon fa fa-ban"></i> Sinkron Data pengumuman Gagal!</h4>
        Silahkan periksa koneksi internet dan token
      </div>';
                }
            }
			
			if ($data == 'pel') {
                $syncdata = http_request($setting['url_host'] . "/syncsoal.php?token=" . $token);

                $sync = json_decode($syncdata, TRUE);

                if ($sync <> null) {
                
                    $sql = mysqli_query($koneksi, "truncate table mata_pelajaran");
                    foreach ($sync['pel'] as $pel) {
                      
                        $sqlpel = mysqli_query($koneksi, "insert into mata_pelajaran
                                (kode_mapel,nama_mapel) values 			
                                ('$pel[kode_mapel]','$pel[nama_mapel]')");
                        if (!$sqlpel) {
                            $gagal9++;
                        } else {
                            $masuk9++;
                        }
					}
                 
                    $exec = mysqli_query($koneksi, "update sinkron set jumlah='$masuk9', status_sinkron='1',tanggal='$datetime' where nama_data='DATA9'");
                    echo "
                                    <div class='row'>
                                        <div class='col-md-12'>
                                            <div class='box box-solid'>
                                                <div class='box-header with-border'>
                                                <h5 class='box-title'>DATA MAPEL YANG MASUK KE LOKAL</h5>
                                                </div>
                                                <div class='box-body'>
                                                <table class='table table-striped'>
                                                <th>Nama Data</th><th>Data Berhasil Masuk</th><th>Data Gagal</th>
                                                        <tr><td>Mata Pelajaran</td><td><i class='fa fa-check text-green'></i> $masuk9</td><td><i class='fa fa-times text-red'></i> $gagal9</td></tr>
                                                    </table>
                                                
                                                </div><!-- /.box-body -->
                                            </div><!-- /.box -->
                                        </div>
                                    </div>";
									
									   echo "<script>
	
	window.setTimeout(function(){ 
			window.location.replace('ujian');
		} ,1000);	
    </script>";
									
                 } else {
                    echo '<div class="alert alert-danger alert-dismissible">
        <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
        <h4><i class="icon fa fa-ban"></i> Sinkron Data Pengaturan Gagal!</h4>
        Silahkan periksa koneksi internet dan token
      </div>';
                }
            }
			
			
			
        }
    } else {
        echo '<div class="alert alert-danger alert-dismissible">
        <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
        <h4><i class="icon fa fa-ban"></i> Sinkron Gagal!</h4>
        Silahkan memilih data sinkron dan mengisi token dengan benar
      </div>';
    }
   

} else {
    echo "
								<div class='row'>
									<div class='col-md-12'>
										<div class='box box-solid'>
											<div class='box-header with-border bg-red'>
											<h5 class='box-title'>SINKRONISASI GAGAL</h5>
											</div>
											<div class='box-body'>
											<ul>
											<li>Periksa Koneksi Internet</li>
											<li>Periksa Pengaturan Jaringan</li>
											<li>Pastikan Server dalam kondisi AKTIF</li>
											</ul>
											</div><!-- /.box-body -->
										</div><!-- /.box -->
									</div>
								</div>";
}

