<?php
defined('APK') or exit('Anda tidak dizinkan mengakses langsung script ini!');
$jsiswa = mysqli_num_rows(mysqli_query($koneksi, "SELECT * FROM siswa"));
$jsisL = mysqli_num_rows(mysqli_query($koneksi, "SELECT * FROM siswa WHERE jk='L'"));
$jsisP = mysqli_num_rows(mysqli_query($koneksi, "SELECT * FROM siswa WHERE jk='P'"));

$jpesL = mysqli_num_rows(mysqli_query($koneksi, "SELECT * FROM siswa WHERE jk='L' AND username<>''"));
$jpesP = mysqli_num_rows(mysqli_query($koneksi, "SELECT * FROM siswa WHERE jk='P' AND username<>''"));
$jpeserta = mysqli_num_rows(mysqli_query($koneksi, "SELECT * FROM siswa WHERE username<>''"));

$jum = $jpesL + $jpesP;
?>           
			<?php if ($ac == '') : ?>
			<div class="row">
                            <div class="col-xl-4">
                                <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">
                                                <i class="material-icons-outlined">storage</i>
                                            </div>
                                            <div class="widget-stats-content flex-fill">
                                                <span class="widget-stats-title">PESERTA LAKI-LAKI</span>
                                                <span class="widget-stats-amount"><?= $jpesL; ?></span>
                                                <span class="widget-stats-info" style="color:blue;">dari <?= $jsiswa ?> Siswa</span>
                                            </div>
                                           
                                        </div>
										 <div class="progress">
                                            <div class="progress-bar"  role="progressbar" style="width: <?= round(($jpesL/$jsiswa)*100); ?>%;" aria-valuenow="<?= ($jpesL/$jsiswa)*100; ?>" aria-valuemin="0" aria-valuemax="100"></div>
                                              </div>
                                    </div>
                                </div>
								
                            </div>
                            <div class="col-xl-4">
                                <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">
                                                <i class="material-icons-outlined">memory</i>
                                            </div>
                                            <div class="widget-stats-content flex-fill">
                                                <span class="widget-stats-title">PESERTA PEREMPUAN</span>
                                                <span class="widget-stats-amount"><?= $jpesP; ?></span>
                                                <span class="widget-stats-info" style="color:blue;">dari <?= $jsiswa ?> Siswa</span>
                                            </div>
                                            
                                        </div>
										 <div class="progress">
                                            <div class="progress-bar bg-danger"  role="progressbar" style="width: <?= round(($jpesP/$jsiswa)*100); ?>%;" aria-valuenow="<?= ($jpesP/$jsiswa)*100; ?>" aria-valuemin="0" aria-valuemax="100"></div>
                                              </div>
                                    </div>
                                </div>
                            </div>
                            <div class="col-xl-4">
                                <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-success">
                                                <i class="material-icons-outlined">people</i>
                                            </div>
                                            <div class="widget-stats-content flex-fill">
                                                <span class="widget-stats-title">TOTAL PESERTA</span>
                                                <span class="widget-stats-amount"><?= $jpeserta ?></span>
                                                <span class="widget-stats-info">dari <?= $jsiswa ?> Siswa</span>
                                            </div>
                                           
                                        </div>
										<div class="progress">
                                            <div class="progress-bar bg-success"  role="progressbar" style="width: <?= round(($jum/$jsiswa)*100); ?>%;" aria-valuenow="<?= ($jum/$jsiswa)*100; ?>" aria-valuemin="0" aria-valuemax="100"></div>
                                              </div>
                                    </div>
                                </div>
                            </div>
                        </div>
					<div class="row">
                          <div class="col">
                                <div class="card">
                                    <div class="card-header">
                                        <h5 class="card-title">Peserta Asesmen</h5>
										<div class="pull-right">
										<a href="?pg=peserta&ac=update" class="btn btn-primary"><i class="material-icons">upload</i>Update</a>   
                                    
									</div>
									</div>
                                    <div class="card-body">
									<div class="card-box table-responsive">
                                         <table id="datatable1" class="table table-bordered table-hover" style="width:100%">
                                            <thead>
                                                <tr>
                                                    <th>NO</th>
                                                    <th>NO PESERTA</th>
                                                    <th>NAMA PESERTA</th>
                                                    <th>ROMBEL</th>
                                                    <th>USERNAME</th>
                                                    <th>PASSWORD</th>
                                                </tr>
                                            </thead>
                                            <tbody>
                                               <?php
											$no=0;
											$query = mysqli_query($koneksi, "SELECT * FROM siswa WHERE username<>''"); 
											  while ($data = mysqli_fetch_array($query)) :
											$no++;
											   ?>
                                                <tr>
                                                    <td><?= $no; ?></td>
                                                    <td><?= $data['no_peserta'] ?></td>
                                                     <td><?= $data['nama'] ?></td>
                                                    <td><?= $data['kelas'] ?></td>
                                                    <td><?= $data['username'] ?></td>
                                                  <td><?= $data['password'] ?></td>
                                                </tr>
												<?php endwhile; ?>
                                                </table>
												 </div>
											</div>
										</div>
									</div>
								</div>		
		 <?php elseif ($ac == 'update') : ?>
		            <div class="row">
                        <div class="col-xl-4">
                                <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">
                                                <i class="material-icons-outlined">storage</i>
                                            </div>
                                            <div class="widget-stats-content flex-fill">
                                                <span class="widget-stats-title">PESERTA LAKI-LAKI</span>
                                                <span class="widget-stats-amount"><?= $jpesL; ?></span>
                                                <span class="widget-stats-info" style="color:blue;">dari <?= $jsiswa ?> Siswa</span>
                                            </div>
                                           
                                        </div>
										 <div class="progress">
                                            <div class="progress-bar"  role="progressbar" style="width: <?= round(($jpesL/$jsiswa)*100); ?>%;" aria-valuenow="<?= round(($jpesL/$jsiswa)*100); ?>" aria-valuemin="0" aria-valuemax="100"></div>
                                              </div>
                                    </div>
                                </div>
								
                            </div>
                            <div class="col-xl-4">
                                <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">
                                                <i class="material-icons-outlined">memory</i>
                                            </div>
                                            <div class="widget-stats-content flex-fill">
                                                <span class="widget-stats-title">PESERTA PEREMPUAN</span>
                                                <span class="widget-stats-amount"><?= $jpesP; ?></span>
                                                <span class="widget-stats-info" style="color:blue;">dari <?= $jsiswa ?> Siswa</span>
                                            </div>
                                            
                                        </div>
										 <div class="progress">
                                            <div class="progress-bar bg-warning"  role="progressbar" style="width: <?= round(($jpesP/$jsiswa)*100); ?>%;" aria-valuenow="<?= round(($jpesP/$jsiswa)*100); ?>" aria-valuemin="0" aria-valuemax="100"></div>
                                              </div>
                                    </div>
                                </div>
                            </div>
                            <div class="col-xl-4">
                                <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-success">
                                                <i class="material-icons-outlined">people</i>
                                            </div>
                                            <div class="widget-stats-content flex-fill">
                                                <span class="widget-stats-title">TOTAL PESERTA</span>
                                                <span class="widget-stats-amount"><?= $jpeserta ?></span>
                                                <span class="widget-stats-info">dari <?= $jsiswa ?> Siswa</span>
                                            </div>
                                           
                                        </div>
										<div class="progress">
                                            <div class="progress-bar bg-success"  role="progressbar" style="width: <?= ($jum/$jsiswa)*100; ?>%;" aria-valuenow="<?= ($jum/$jsiswa)*100; ?>" aria-valuemin="0" aria-valuemax="100"></div>
                                              </div>
                                    </div>
                                </div>
                            </div>
                        </div>
					<div class="row">
                          <div class="col-md-4">
                                
                                <div class="card widget widget-payment-request">
                                    <div class="card-header">
                                        <h5 class="card-title"><?= $setting['sekolah'] ?></h5>
                                    </div>
                                    <div class="card-body">
                                        <div class="widget-payment-request-container">
                                            <div class="widget-payment-request-author">
                                                <div class="avatar m-r-sm">
                                                    <img src="<?= $homeurl ?>/images/guru.png" alt="">
                                                </div>
                                                <div class="widget-payment-request-author-info">
                                                    <span class="widget-payment-request-author-name">KEPALA SEKOLAH</span>
                                                    <span class="widget-payment-request-author-about"><?= $setting['sekolah'] ?></span>
                                                </div>
                                            </div>
                                            
                                            <div class="widget-payment-request-info m-t-md">
                                                <div class="widget-payment-request-info-item">
                                                    <span class="widget-payment-request-info-title d-block">
                                                      Penanggung Jawab Kegiatan
                                                    </span>
                                                    <span class="text-muted d-block"><?= $setting['kepsek'] ?><br>NIP. <?= $setting['nip'] ?></span>
                                                </div>
                                                
                                            </div>
                                             </div>
                                        </div>
                                    </div>
                                </div>
                           
				
				<div class='col-md-8'>

					<div class="card">
                        <div class="card-header">
                                        <h5 class="card-title">Update Peserta Asesmen</h5>
										<div class="pull-right">
										<a href="asesmen/cbtserver_siswa/proses.php" id="blockui-2" class="btn btn-success"><i class="material-icons">download</i>Format</a>   
                                   
									</div>
									</div>
                              <div class="card-body">
							   <form id='formsiswa' >	
                                      <label>Pilih File Excel</label>
									  <div class="input-group mb-3">
                                       <input type='file' name='file' class='form-control' required='true' />
									    <span class="input-group-text">
											<button type="submit" id="blockui-3" class="btn btn-primary"><i class="material-icons">upload</i></button>
										</span>
                                        </div>	
								</form>
							</div>		
					     
						</div>
					</div>
				</div>	
<script>
    $('#formsiswa').submit(function(e){
		e.preventDefault();
		var data = new FormData(this);
		$.ajax(
		{
			type: 'POST',
             url: 'asesmen/cbtserver_siswa/import_siswa.php',
            data: data,
			cache: false,
			contentType: false,
			processData: false,
			success: function(data){   		
			setTimeout(function()
				{
				window.location.replace('?pg=peserta');
						}, 1500);
									  
						}
					});
				return false;
			});
		</script>	
        <?php endif; ?>		 