<?php
defined('APK') or exit('Anda tidak dizinkan mengakses langsung script ini!');
$jmap = mysqli_num_rows(mysqli_query($koneksi, "SELECT * FROM mata_pelajaran"));
$jmapU = mysqli_num_rows(mysqli_query($koneksi, "SELECT * FROM mata_pelajaran WHERE pk='Umum'"));
$jmapJ = mysqli_num_rows(mysqli_query($koneksi, "SELECT * FROM mata_pelajaran WHERE pk<>'Umum'"));

?>           
			   
					<div class="row">
                          <div class="col-md-8">
                                <div class="card">
                                    <div class="card-header">
                                        <h5 class="card-title">Mata Pelajaran</h5>
										<div class="pull-right">
										<button id="confirm"  class="hapus btn btn-danger" data-bs-toggle="tooltip" data-bs-placement="top" title="Reset Mata Pelajaran"><i class="material-icons">delete</i></button>
                                 
									</div>
                                    </div>
                                    <div class="card-body">
									<br>
									<div class="card-box table-responsive">
                                        <table id="datatable1" class="table table-bordered table-hover" style="width:100%">
                                            <thead>
                                                <tr>
                                                    <th width="5%">NO</th>                                               
                                                    <th>KODE</th>
                                                   <th>MATA PELAJARAN</th>
												    <th>JURUSAN</th>
                                                </tr>
                                            </thead>
                                            <tbody>
											<?php
											$no=0;
											$query = mysqli_query($koneksi, "SELECT * FROM mata_pelajaran"); 
											  while ($data = mysqli_fetch_array($query)) :
											$no++;
											   ?>
                                                <tr>
                                                    <td><?= $no; ?></td>
                                                    <td><?= $data['kode'] ?></td>
                                                    <td><?= $data['nama_mapel'] ?></td>
													 <td><?= $data['pk'] ?></td>
                                                </tr>
												<?php endwhile; ?>
                                                </table>
												 </div>
											</div>
										</div>
									</div>
									
					       <div class="col-md-4">
                       <div class="card" id="blockui-card-1">
                                <div class="card widget widget-payment-request">
                                    <div class="card-header">
                                        <h5 class="card-title">Upload</h5>
										<a href="cbtserver_master/M_MAPEL.xlsx" class="btn btn-link pull-right"><i class="material-icons">download</i>Download Format</a>   
                                    </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="../images/buku.png" alt="">
                                                </div>
                                                <div class="widget-payment-request-author-info">
                                                    <span class="widget-payment-request-author-name">Mata Pelajaran</span>
                                                    <span class="widget-payment-request-author-about"><?= $setting['sekolah'] ?></span>
                                                </div>
                                            </div>
									<div class="widget-payment-request-info m-t-md">
									<form id='formmapel' >	
                                      <label>Pilih File</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-1" class="btn btn-primary"><i class="material-icons">upload</i></button>
										</span>
                                        </div>	
										</form>
									 </div>
					            </div>
								</div>
							</div>
						</div>
					
					<script>
    $('#formmapel').submit(function(e){
		e.preventDefault();
		var data = new FormData(this);
		$.ajax(
		{
			type: 'POST',
             url: 'cbtserver_master/import_mapel.php',
            data: data,
			cache: false,
			contentType: false,
			processData: false,
			success: function(data){   		
			setTimeout(function()
				{
				window.location.reload();
						}, 1500);
									  
						}
					});
				return false;
			});
		</script>	
                        
                                <div class="card widget widget-list">
                                    
                                    <div class="card-body">
                                       
                                        <ul class="widget-list-content list-unstyled">
                                            <li class="widget-list-item widget-list-item-green">
                                                <span class="widget-list-item-icon"><i class="material-icons-outlined">article</i></span>
                                                <span class="widget-list-item-description">
                                                    <a href="#" class="widget-list-item-description-title">
                                                      <?= $jmapU ?> Mapel Umum 
                                                    </a>
                                                    <span class="widget-list-item-description-progress">
                                                        <div class="progress">
                                                            <div class="progress-bar bg-success" role="progressbar" style="width: <?= round(($jmapU/$jmap)*100) ?>%;" aria-valuenow="<?= round(($jmapU/$jmap)*100) ?>" aria-valuemin="0" aria-valuemax="100"></div>
                                                        </div>
                                                    </span>
                                                </span>
                                            </li>
                                            <li class="widget-list-item widget-list-item-blue">
                                                <span class="widget-list-item-icon"><i class="material-icons-outlined">verified_user</i></span>
                                                <span class="widget-list-item-description">
                                                    <a href="#" class="widget-list-item-description-title">
                                                       <?= $jmapJ ?> Mapel Kejuruan 
                                                    </a>
                                                    <span class="widget-list-item-description-progress">
                                                        <div class="progress">
                                                            <div class="progress-bar" role="progressbar" style="width: <?= round(($jmapJ/$jmap)*100) ?>%;" aria-valuenow="<?= round(($jmapJ/$jmap)*100) ?>" aria-valuemin="0" aria-valuemax="100"></div>
                                                        </div>
                                                    </span>
                                                </span>
                                            </li>
                                           
                                        </ul>
                                    </div>
                                </div>
							</div>									
		
         <script>
				$("#confirm").click(function(){
		    	Swal.fire({
				  title: 'Reset Data Mata Pelajaran',
				  text: "Data Siswa akan dikosongkan !",
				  type: 'warning',
				  showCancelButton: true,
				  confirmButtonColor: '#3085d6',
				  cancelButtonColor: '#d33',
				  confirmButtonText: 'Yes, Reset!'
				}).then((result) => {
				  if (result.value) {
					$.ajax({
					url: 'cbtserver_master/tsiswa.php?pg=reset_mapel',
					success: function(data) {
						 Swal.fire(
				      'Deleted!',
				      'Your file has been deleted.',
				      'success'
				    )
				   setTimeout(function() {
					window.location.reload();
					}, 1000);
						}
					});
					}
					return false;
						})

						});
					</script>	