<?php
defined('APK') or exit('Anda tidak dizinkan mengakses langsung script ini!');
?>
<?php if ($ac == '') { ?>
    <div class='row'>
	<div class='col-md-12'>
             <div class='panel panel-default'>
               <div class="panel-heading" style="height:45px">
                    <div class='box-tools pull-right '>
					 
                    </div>
					<h4 class='box-title'><i class="fas fa-graduation-cap"></i> Asesmen Sumatif</h4>
                </div>
				<div class='box-header with-border '>
			   <div class='box-tools pull-right '>
			   <table>
			   <tr>
			   <td>
			   <div class="form-group-sm">
			  <select name='jenjang' class='form-control' >
              <option value=""><?= $setting['sekolah'] ?></option>
               </select>
			   </div>
				</td>
			   <td>
			   <div class="form-group-sm">
			  <select name='jenjang' class='form-control' >
              <option value=""><?= $setting['jenjang'] ?></option>
               </select>
			   </div>
				</td>
				<td>
				<div class="form-group-sm">
			  <select name='jenjang' class='form-control'>
               <option value=""><?= $setting['kota'] ?></option>
               </select>
			   </div>
				</td>
				<td>
				<div class="form-group-sm">
			  <select name='jenjang' class='form-control' >
               <option value=""><?= $setting['kecamatan'] ?></option>
               </select>
			   </div>
				</td>
				</tr>					
			</table>
			</div>
			 <h4 class='box-title'></h4>
			  </div>
			  <div class="box-body">
                    <ul class="nav nav-tabs">
                        <li class="active"><a href="#tab_1" data-toggle="tab" aria-expanded="true" >Sumatif</a></li>
                    </ul>
					<div class="tab-content">
                    <div class="tab-pane active" id="tab_1" >
				<div class="panel panel-default">
				 <div class='box-body'>      
          
        <div class='col-md-7'>
           <div class="panel panel-default">
                <div class='box-header with-border '>
                    <h4 class='box-title'>Lingkup Materi</h4>
                    <div class='box-tools pull-right'>
					
					  
                    </div>
                </div>
				
                <div class='box-body'>
                    <div class='table-responsive'>
                        <table style="font-size: 11px" id='example' class='table table-bordered table-hover'>
                            <thead >
                                <tr>
                                    <th width='3px' class="hidden-xs">No</th>
									  <th>Kelas</th>
                                    <th>Mapel</th>  
                                        <th>Lingkup Materi</th>									  
									
										</tr>
									</thead>							
							<tbody>							
                                <?php
								$no = 0;
								
								 $query = mysqli_query($koneksi, "select * from lingkup
								 JOIN pengawas ON pengawas.id_pengawas=lingkup.idguru");
                            while ($tjn = mysqli_fetch_array($query)) {
							
                                $no++;
                            ?>
							 <tr>
                                    <td class="hidden-xs"><?= $no; ?></td>
							        <td><?= $tjn['kelas'] ?></td>
									<td ><?= $tjn['kodemap'] ?></td>
									<td><?= $tjn['materi'] ?></td>
                                   
							       </tr>
                            <?php } ?>
                        </tbody>
                        </table>
                    </div>
                    </div>
					</div>
                    </div>
					
                     <div class='col-md-5'>
           <div class="panel panel-default">
                <div class='box-header'> 
                    <h5 class='box-title'>Asesmen Sumatif Akhir Semester</h5>
					<form method="POST" action="?pg=akhirsumatif&ac=nilai" enctype="multipart/form-data">
                    <div class='box-tools pull-right'>
					 
					   
                    </div>
                </div>
				
									 <div class='box-body'>
									 <div class='row'>
									<div class="col-md-4">
                                        <div class='form-group-sm'>
                                                   <label>Kelas</label>
                                                    <select name='kelas' class='form-control' required='true'>
                                                        <option value=''></option>
                                                         <?php $quem = mysqli_query($koneksi, "SELECT * FROM jadwal_mapel WHERE guru='$_SESSION[id_pengawas]' GROUP BY kelas"); ?>
                                                <?php while ($m = mysqli_fetch_array($quem)) : ?>
                                                    <option value="<?= $m['kelas'] ?>"><?= $m['kelas'] ?></option>
                                                <?php endwhile ?>
                                                    </select>
                                                </div>
												</div>
												<div class="col-md-8">
                                          <div class='form-group-sm'>
                                                   <label>Mapel</label>
                                                   <select name='mapel' class='form-control' style='width:100%' required>
                                                   <option value=''></option>
                                                <?php $quem = mysqli_query($koneksi, "SELECT * FROM jadwal_mapel JOIN mata_pelajaran ON mata_pelajaran.kode_mapel=jadwal_mapel.kode WHERE guru='$_SESSION[id_pengawas]' GROUP BY kode "); ?>
                                                <?php while ($m = mysqli_fetch_array($quem)) : ?>
                                                    <option value="<?= $m['kode'] ?>"><?= $m['nama_mapel'] ?> </option>
                                                <?php endwhile ?>
                                            </select>
                                                </div>
												</div>
												
												<div class="col-md-12">
											   <div class='form-group-sm'>
                                                   <label>Guru Mapel</label>
                                                    <select name='guru' class='form-control' required='true'>
													 
													 <?php
                                                        $kelasQ = mysqli_query($koneksi, "SELECT * FROM pengawas WHERE id_pengawas='$_SESSION[id_pengawas]' ");
                                                        while ($ekstra = mysqli_fetch_array($kelasQ)) {
                                                            echo "<option value='$ekstra[id_pengawas]'>$ekstra[nama]</option>";
                                                        }
                                                        ?>
													
                                                    </select>
                                                </div>
												</div>
											</div>
											
                                                <div class='modal-footer' >
                                            <div class='box-tools pull-right btn-group' >
                                             <button type='submit' class='btn btn-sm btn-success'><i class='fa fa-check'></i> Simpan</button>
                                            </div>
                                        </div>
										
                                    </form>
                               
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
<?php } elseif ($ac == 'nilai') { ?>
<?php
$kelas=$_POST['kelas'];
$kode=$_POST['mapel'];
$guru=$_POST['guru'];

?>
<div class='row'>
        <div class='col-md-12'>
            <div class="panel panel-default">
			<div class="panel-heading" style="height:45px">
                    <div class='box-tools pull-right '>
					 
                    </div>
					<h4 class='box-title'><i class="fas fa-graduation-cap"></i> Asesmen Sumatif Akhir Semester</h4>
                </div>
			
                <div class='box-header with-border '>
			   <div class='box-tools pull-right '>
			   <table>
			   <tr>
			   <td>
			   <div class="form-group-sm">
			  <select name='jenjang' class='form-control' >
              <option value=""><?= $setting['sekolah'] ?></option>
               </select>
			   </div>
				</td>
			   <td>
			   <div class="form-group-sm">
			  <select name='jenjang' class='form-control' >
              <option value=""><?= $setting['jenjang'] ?></option>
               </select>
			   </div>
				</td>
				<td>
				<div class="form-group-sm">
			  <select name='jenjang' class='form-control'>
               <option value=""><?= $setting['kota'] ?></option>
               </select>
			   </div>
				</td>
				<td>
				<div class="form-group-sm">
			  <select name='jenjang' class='form-control' >
               <option value=""><?= $setting['kecamatan'] ?></option>
               </select>
			   </div>
				</td>
				</tr>					
			</table>
			</div>
			 <h4 class='box-title'></h4>
			  </div>
			  <div class="box-body">
                    <ul class="nav nav-tabs">
                        <li class="active"><a href="#tab_1" data-toggle="tab" aria-expanded="true" >E-Rapor</a></li>
                    </ul>
					<div class="tab-content">
                    <div class="tab-pane active" id="tab_1" >
				<div class="panel panel-default">
				 <div class='box-body'> 
        <div class='col-md-12'>
            <div class='box box-solid'>
                <div class='box-header with-border '>
                    <h4 class='box-title'>Asesmen Sumatif Akhir Semester</h4>
                    <div class='box-tools pull-right'>
				      <a data-toggle='modal' data-backdrop="static" data-target='#upload' class='btn btn-sm btn-primary'><i class='fas fa-upload'></i> <span class='hidden-xs'> Upload</span></a>
								 <a href="m_proto/prosessumatifsemester.php?kelas=<?= $kelas ?>&mapel=<?= $kode ?>&guru=<?= $guru ?>" class='btn btn-sm btn-success' type="button" data-placement="top" data-toggle="tooltip" data-original-title="Download Format"><i class="fa fa-download"></i></a>
                              <a href="?pg=akhirsumatif&ac=hapus&kelas=<?= $kelas ?>&mapel=<?= $kode ?>&khp=SAS" class='btn btn-danger btn-sm' type="button" data-placement="top" data-toggle="tooltip" data-original-title="Reset"><i class="fa fa-trash"></i> Reset</button></a>
							 
							  
							  </div>
					  </div>
				<div class="panel-body">
                    </div>
					<p>Asesmen Sumatif Akhir Semester tidak wajib untuk dilakukan, kewenangan diserahkan pada sekolah. Jika Sekolah melaksanakan maka silahkan input nilai</p>
					<a class="btn btn-sm">
                      <i class="fa fa-home"></i>  Kelas : <?= $kelas ?>
                    </a>
					<a class="btn btn-sm">
                      <i class="fa fa-th-large"></i> Kode Mapel : <?= $kode ?>
                    </a>
					<a class="btn btn-sm">
					<b>Isi Nilai Akhir Semester</b>
					 </a>
                <div class='box-body'>
                    <div class='table-responsive'>
                        <table style="font-size: 11px" id='example' class='table table-bordered table-striped'>
                            <thead >
                                <tr>
                                    <th width='3px' class="hidden-xs">No</th>
									  <th>Nama</th>
									 <th width='5%'>Nilai</th>
									 
										</tr>
									</thead>							
							<tbody>							
							 <?php
									  $no=0;
									$query = mysqli_query($koneksi,"select * from siswa WHERE id_kelas='$kelas' ");
									  while ($siswa = mysqli_fetch_array($query)) {
										
										  $no++;
									?>
									<tr>
									<td class="hidden-xs"><?= $no; ?></td>
									 <td><?= $siswa['nama'] ?></td>
									  <?php
									  
									$queryX = mysqli_query($koneksi,"select * from nilai_sumatif WHERE idsiswa='$siswa[id_siswa]' AND mapel='$kode' AND khp='SAS' GROUP BY ket ");
									  while ($Q = mysqli_fetch_array($queryX)) {
										  
									?>
									<td style="text-align:center"> <?= $Q['nilai'] ?></td>
									 <?php } ?>
							       </tr>
                            <?php } ?>
							 </tbody>
                        </table>
                    </div>
                    </div>
					</div>
                    </div>
					
			       <div class='modal fade' id='upload' style='display: none;'>
                        <div class='modal-dialog'>
                            <div class='modal-content'>
                                <div class='modal-header'>
                                    <button class='close' data-dismiss='modal'><span aria-hidden='true'><i class='glyphicon glyphicon-remove'></i></span></button>
                                    <h4 class='modal-title'>Upload Nilai Sumatif Akhir Semester</h4>
                                </div>
                                
                                  <form id="form-import" action=''>
									 <div class='modal-body'>
									 <div class='row'>
									<div class="col-md-12">
                                        <div class='form-group'>
                                                   <label>Upload</label>
                                                     <input type="file" class="form-control" name="file" id="file" placeholder="" aria-describedby="helpfile" required>
                                                      <small id="helpfile" class="form-text text-muted">File harus .xlsx</small>
													  <input type="hidden" name="kelas" value="<?= $kelas ?>"  >
													   <input type="hidden" name="mapel" value="<?= $kode ?>"  >
													    <input type="hidden" name="guru" value="<?= $guru ?>"  >
                                                </div>
												</div>											
												</div>
												<p style="color: red">Saat Upload File Cukup Satu Kali Kik Tombol Simpan, Tunggu Bebarapa Saat Sampai Data Tersimpan, Terima Kasih</p>
                                                <div class='modal-footer' >
                                            <div class='box-tools pull-right btn-group' >
                                                <button type='submit' name='submit' class='btn btn-sm btn-success'><i class='fa fa-check'></i> Simpan</button>
                                             
                                            </div>
                                        </div>
										
                                    </form>
                               
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>                  
					
	<script>
  
    $('#form-import').on('submit', function(e) {
        e.preventDefault();
        $.ajax({
            type: 'post',
            url: 'm_proto/crud_akhirsumatif.php',
            data: new FormData(this),
            processData: false,
            contentType: false,
            cache: false,
            beforeSend: function() {
                $('form button').on("click", function(e) {
                    e.preventDefault();
                });
            },
            success: function(data) {

                $('#importdata').modal('hide');
                iziToast.success({
                    title: 'Sukses!',
                    message: data,
                    position: 'topRight'
                });
                setTimeout(function() {
                    window.location.reload();
                }, 2000);


            }
        });
    });
   
</script>			

<?php } elseif ($ac == 'hapus') { ?>
<?php

$exec = delete($koneksi,'nilai_sumatif',['kelas'=>$_GET['kelas'], 'mapel'=>$_GET['mapel'], 'khp'=>$_GET['khp']]);
	echo "
	  <script type='text/javascript'>
		setTimeout(function () { 	
			swal({
				title: 'Sukses',
				text:  'Nilai Berhasil dihapus',
				type: 'success',
				timer: 1000,
				showConfirmButton: true
			});		
		},10);	
		window.setTimeout(function(){ 
			window.location.replace('?pg=akhirsumatif');
		} ,1000);	
	  </script>";
	
	?>
<?php } ?>
	