<?php
defined('APK') or exit('Anda tidak dizinkan mengakses langsung script ini!');
?>
<?php
$link = 'template/pesertaujian.xlsx';
$prp = mysqli_num_rows(mysqli_query($koneksi, "SELECT * FROM siswa WHERE jenis_kelamin='Perempuan'"));
$lk = mysqli_num_rows(mysqli_query($koneksi, "SELECT * FROM siswa WHERE jenis_kelamin='Laki-laki'"));
$total = mysqli_num_rows(mysqli_query($koneksi, "SELECT * FROM siswa"));
?>
<div class="row">
   <div class="col-md-8">
	<div class="card">
      <div class="card-header">									
         <h5 class="card-title">Impor Data Siswa</h5>
			</div>
                <div class="card-body">
				<div class="alert alert-custom" role="alert">
                    <div class="custom-alert-icon icon-dark"><i class="fa fa-check fa-2x"></i></div>
                          <div class="alert-content">
                       <span class="alert-text" style="text-align:justify"> Untuk Level atau Tingkat harap diisi denan <b>Angka</b> Contoh 7, 8, 9, 10, 11, 12 Untuk kelas boleh Bebas bisa Romawi maupun Angka. Karena level akan digenerate otomatis menjadi FASE yang digunakan pada Kurikulum Merdeka. Untuk Nomor Peserta, Username dan Password akan otomatis digenerate oleh Sistem</span>
                                                    </div>
                                                </div>
				<div class="row">
                        <div class='form-group'>
                            <div class='row'>
                                <form id='formsiswa' enctype='multipart/form-data'>
                                    <div class='col-md-8'>
                                        <label>Pilih File</label>
                                        <input type='file' name='file' class='form-control' required='true' />
                                    </div>
                                    <div class='col-md-8'>
                                        <label>&nbsp;</label><br>
                                        <button type='submit' name='submit' class='btn btn-sm btn-outline-primary right'><i class='fa fa-upload'></i> Import</button>
                                    </div>
                                </form>
                            </div>
                        </div>
                        <span>Import harus xlsx</span>
						<p>
						<a href='<?= $link ?>' class="btn btn-sm btn-link"> <i class='fa fa-sync'></i><b> Download Format</b></a>
						<hr>
                       
								<div id='progressbox'></div>
								<div id='hasilimport'></div>
								<p>
								</div>
							</div>
						</div>
					 </div>
	 
                            <div class="col-md-4">
							 <div class="row">
                                <div class="card widget widget-stats">
                                    <div class="card-body">
                                        <div class="widget-stats-container d-flex">
                                            <div class="widget-stats-icon widget-stats-icon-primary">
                                                <img src="<?= $homeurl ?>/dist/img/laki.png" width="50px"></i>
                                            </div>
                                            <div class="widget-stats-content flex-fill">
                                                <span class="widget-stats-title">LAKI-LAKI</span>
                                                <span class="widget-stats-amount"><?= $lk ?></span>
                                                <span class="widget-stats-info">Active Users</span>
                                            </div>
                                            <div class="widget-stats-indicator widget-stats-indicator-positive align-self-start">
                                                <i class="fa fa-chevron-down"></i> <?= round(($lk/$total)*100) ?>%
                                            </div>
                                        </div>
                                    </div>
                                </div>
                             
                                <div class="card widget widget-stats">
                                    <div class="card-body">
                                        <div class="widget-stats-container d-flex">
                                            <div class="widget-stats-icon widget-stats-icon-warning">
                                                  <img src="<?= $homeurl ?>/dist/img/prp.png" width="50px"></i>
                                            </div>
                                            <div class="widget-stats-content flex-fill">
                                                <span class="widget-stats-title">PEREMPUAN</span>
                                                <span class="widget-stats-amount"><?= $prp ?></span>
                                                <span class="widget-stats-info">Active Users</span>
                                            </div>
                                            <div class="widget-stats-indicator widget-stats-indicator-negative align-self-start">
                                                <i class="fa fa-chevron-down"></i> <?= round(($prp/$total)*100) ?>%
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
<script>
    $('#formsiswa').on('submit', function(e) {
        e.preventDefault();
        $.ajax({
            type: 'post',
            url: 'sandik_master/import_master.php',
            data: new FormData(this),
            processData: false,
            contentType: false,
            cache: false,
            beforeSend: function() {
                $('#progressbox').html('<div><label class="sandik" style="color:blue">Data sedang di proses</label>&nbsp;&nbsp;&nbsp;<img src="<?= $homeurl ?>/dist/img/animasi1.gif" style="margin-left:100px;width:50px"></div>');
                $('.progress-bar').animate({
                    width: "30%"
                }, 100);
            },
            success: function(response) {
                setTimeout(function() {
                    $('.progress-bar').css({
                        width: "100%"
                    });
                    setTimeout(function() {
                        $('#hasilimport').html(response);
                    });
						setTimeout(function() {
                    window.location.reload();
                    }, 2000);
                }, 2000);
            }
        });
    });
</script>