<?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="card">
             <div class="card-header">
                  <h5 class='card-title'><i class="fas fa-graduation-cap"></i> Asesmen Sumatif Akhir Lingkup Materi</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">
                  Asesmen Sumatif Akhir Lingkup Materi bertujuan untuk mengevaluasi hasil belajar siswa pada tiap lingkup materi. Hasil Asesmen Sumatif Akhir Lingkup Materi digunakan
                      <b>Untuk Pengolahan Nilai pada Laporan Hasil Belajar Siswa (Rapor).</b>          
							</span>
                            </div>
                                </div>
                <div class="table-responsive">
                     <table style="font-size: 12px" id='mapel' class='table table-bordered'>
                        <thead>
						
                            <tr>
                                <th width='5px'>
                                    #
                                </th>
                                <th>Mapel</th>
								<th width="20%">Kelas</th>
                                <th width="20%">Action</th>
                                
                            </tr>
						
                        </thead>
                        <tbody>
						
                            <?php
							
							$tg=date('Y-m-d');
                             $query = mysqli_query($koneksi, "select * from jadwal_mapel 
							JOIN kelas ON kelas.id_kelas=jadwal_mapel.kelas  WHERE jadwal_mapel.guru='$user[id_user]' AND kelas.kurikulum='Merdeka'");
                            $no = 0; ?>
                           <?php while ($jadwal = mysqli_fetch_array($query)) {
							$jml = mysqli_num_rows(mysqli_query($koneksi, "SELECT * FROM nilai_sumatif 
                            WHERE kelas='$jadwal[kelas]' AND mapel='$jadwal[kode]' AND khp='SAM' "));	
                                $no++;
                              
                            ?>
							
                                <tr>
                                    <td><?= $no; ?></td>
                                    <td><?= $jadwal['mapel'] ?></td>
									 <td><?= $jadwal['kelas'] ?></td>
                                   
                                    <td>
									
									<a href="?pg=nilaisumatif&ac=input&idj=<?= $jadwal['id_jadwal'] ?>" class="btn-sm btn btn-outline-success" data-bs-placement="top" data-bs-toggle="tooltip" title="Input Nilai Sumatif"><i class="fas fa-plus-circle"></i></a>
									
									<a href="?pg=nilaisumatif&ac=lihat3&idj=<?= $jadwal['id_jadwal'] ?>" class="btn-sm btn btn-outline-primary" data-bs-placement="top" data-bs-toggle="tooltip" title="Lihat Nilai"><i class="fas fa-check-circle"></i></a>
									<?php if($jml==0){ ?>
									<a href="?pg=nilaisumatif&ac=upload&idj=<?= $jadwal['id_jadwal'] ?>" class="btn btn-sm btn-outline-info" data-bs-placement="top" data-bs-toggle="tooltip" title="Upload Nilai"><i class="fas fa-upload"></i></a>
									<?php }else{ ?>
									<button class="btn btn-sm btn-default" disabled><i class="fas fa-lock"></i></button>
									<?php } ?>
									</td>
									
									  
										 
										 
																</tr>
																<?php }
																?>
															</tbody>
														</table>
														

													</div>
												</div>
						
						</div>
						
		 
           			

<?php } elseif ($ac == 'input') { ?>
<?php 
$jadwal=fetch($koneksi,'jadwal_mapel',['id_jadwal'=>$_GET['idj']]); 
?>
 <div class='row'>
 <div class='col-md-12'>
  <div class="card">
             <div class="card-header">
                  <h5 class='card-title'><i class="fas fa-graduation-cap"></i> Asesmen Sumatif Akhir Lingkup Materi - <?= $jadwal['kode'] ?></h5>
                </div>
			
            <div class='card-body'>
			<form id="formtujuan" action="?pg=nilaisumatif&ac=input3" method="POST">
		  <div class="table-responsive">
							
                     <table style="font-size: 12px" id='mapel' class='table table-bordered'>
                        <thead>
						
                            <tr>
                                <th width='5px'>
                                    #
                                </th>
                                <th>Nama</th>
								<th width="5%">Kelas</th>
                              <th width="15%">Pilih LM</th>
                                 <th>Nilai</th>
                            </tr>
						
                        </thead>
                        <tbody>
						 
                                <tr>
                                    <td>1</td>
                                    <td><?= $jadwal['mapel'] ?>
									<input type="hidden" name="mapel" value="<?= $jadwal['kode'] ?>" >
									</td>									
									 <td><?= $jadwal['kelas'] ?>
									 <input type="hidden" name="kelas" value="<?= $jadwal['kelas'] ?>" >
									 </td>
                                    <td>
									<select  name="lm"  class="form-select"  style="width:100px;" required="true">     
									 <?php 
									   $sql=mysqli_query($koneksi,"SELECT * FROM  lingkup WHERE idjadwal='$jadwal[id_jadwal]'  ");
									   while ($data=mysqli_fetch_array($sql)) {
										echo '<option value="'.$data['lm'].'">'.$data['lm'].'</option> ';
									   }
									  ?>
									</select>	
									</td>
                                    <td>
                                    <button type='submit'  class='btn btn-sm btn-outline-success'><i class='fa fa-plus-circle'></i></button>
									   </td>
											 
																</tr>
																
																
															</tbody>
															
														</table>
												
															 </form>	

													</div>
												</div>
											</div>
											
									</div>
<?php } elseif ($ac == 'input3') { ?>

 <div class='row'>
 <div class='col-md-12'>
 <div class="card">
             <div class="card-header">
                  <h5 class='card-title'><i class="fas fa-graduation-cap"></i> Asesmen Sumatif Akhir Lingkup Materi - <?= $_POST['mapel'] ?>/<?= $_POST['kelas'] ?>/<?= $_POST['lm'] ?></h5>
                </div>
			
            <div class='card-body'>
			<form id="formnilai" action="" >			
		  <div class="table-responsive">							
                     <table style="font-size: 12px" id='mapel' class='table table-hover'>
                        <thead>						
                            <tr>
                                <th width='5px'>
                                    #
                                </th>
                                <th>Nama</th>
								<th width="5%">Kelas</th>
                                 <th>Nilai</th>
                            </tr>
						
                        </thead>
                        <tbody>									
						<?php
					$query = mysqli_query($koneksi, "select * from siswa WHERE id_kelas='$_POST[kelas]'");
                            $no = 0; ?>
                           <?php while ($siswa = mysqli_fetch_array($query)) {								
                                $no++;                              
                            ?>
                          <tr>
                                    <td><?= $no; ?></td>
                                    <td><?= $siswa['nama'] ?></td>
									 <td><?= $siswa['id_kelas'] ?>
									 <input type="hidden" name="ids[]" value="<?php echo $siswa['id_siswa'] ?>">
									<input type="hidden" name="kelas[]" value="<?php echo $_POST['kelas'] ?>">
									<input type="hidden" name="mapel[]" value="<?php echo $_POST['mapel'] ?>">
									<input type="hidden" name="ket[]" value="<?php echo $_POST['lm'] ?>">
									<input type="hidden" name="khp[]" value="SAM">
									 </td>
									 <td><input type="number" name="nilai[]" class="form-control" value="0" ></td>
									</tr>
																<?php } ?>
																
															</tbody>
														</table>
														
										<div class='right '>
													<button type='submit'  class='btn  btn-success'><i class='fa fa-check-circle'></i> Simpan</button>
																</div>
															 </form>
													</div>
												</div>
						
						</div>
						
		<script>
       $('#formnilai').submit(function(e) {
         e.preventDefault();
        var data = new FormData(this);
        $.ajax({
            type: 'POST',
            url: 'sandik_ikm/crud_nilaisumatif.php?pg=tambah',
             data: data,
            cache: false,
            contentType: false,
            processData: false,
            success: function(data) {
               iziToast.info(
				{
				title: 'Sukses!',
				message: 'Data berhasil disimpan',
				titleColor: '#FFFF00',
				messageColor: '#fff',
				backgroundColor: 'rgba(0, 0, 0, 0.5)',
			   progressBarColor: '#FFFF00',
				 position: 'topRight'
				});
                setTimeout(function() {
                    window.location.replace('?pg=nilaisumatif');
                }, 2000);

            }
        });
        return false;
    });
    </script>										
						

<?php } elseif ($ac == 'lihat3') { ?>
 <?php 
$jadwal=fetch($koneksi,'jadwal_mapel',['id_jadwal'=>$_GET['idj']]); 
?>
 <di
 <div class='row'>
 <div class='col-md-12'>
  <div class="card">
             <div class="card-header">
                 
                    <div class='right '>
					<a href="?pg=hapus_sumatif&kelas=<?= $jadwal['kelas'] ?>&mapel=<?= $jadwal['kode'] ?>" class="btn btn-sm btn-outline-danger"><i class="fas fa-trash"></i> Hapus</a>				 
                    </div>
					 <h5 class='card-title'><i class="fas fa-graduation-cap"></i> Asessmen Sumatif Akhir Lingkup Materi - <?= $jadwal['kode'] ?>/<?= $jadwal['kelas'] ?></h5>
                </div>
				
			  <div class="card-body">
   <div class="table-responsive">							
      <table id="test_table" style="font-size: 12px" class="table table-bordered">
	 <thead>
      <tr>
	<th width='2%' style="text-align: center;">No</th>
	<th>Nama Siswa</th>
	<th width='15%'>Mapel</th>
	<th width='10%'>Kelas</th>
	 <?php
			$querys = mysqli_query($koneksi,"select * from nilai_sumatif 
			WHERE khp='SAM' AND mapel='$jadwal[kode]' AND kelas='$jadwal[kelas]'   GROUP BY ket");
              while ($kd = mysqli_fetch_array($querys)) {
			?>
			<th width='5%' style="text-align: center;"><?= $kd['ket'] ?></th>
			  <?php } ?>
			  
	</tr>
	 </thead>	
				<?php
	       $no=0;
			$query = mysqli_query($koneksi,"select * from siswa WHERE id_kelas='$jadwal[kelas]'");
              while ($siswa = mysqli_fetch_array($query)) {
				 
				  $no++;
			?>
     <tbody>
	
	         <tr>
	        <td><?= $no ?></td>
			<td><?= ucwords(strtolower($siswa['nama'])) ?></td>
			<td><?= $jadwal['kode'] ?></td>
			<td><?= $jadwal['kelas'] ?></td>
	       <?php
			$queryxx = mysqli_query($koneksi,"select AVG(nilai) AS nkd from nilai_sumatif 
			JOIN lingkup ON lingkup.lm=nilai_sumatif.ket
			WHERE nilai_sumatif.idsiswa='$siswa[id_siswa]' AND nilai_sumatif.khp='SAM' AND nilai_sumatif.mapel='$jadwal[kode]'  AND nilai_sumatif.kelas='$jadwal[kelas]' GROUP  BY nilai_sumatif.ket ");
              while ($nilai = mysqli_fetch_array($queryxx)) {
		 
		 
			?>
	
     	<td style="text-align: center;"><?= round($nilai['nkd'],2) ?></td>
			 <?php } ?>
			 </tr>
			
			  <?php   } ?>
	
	  
	 </tbody>
	</table>	
					
			</div>
</div>
</div>
</div>			
<?php } elseif ($ac == 'upload') { ?>
<?php 
$jadwal=fetch($koneksi,'jadwal_mapel',['id_jadwal'=>$_GET['idj']]); 
?>
<div class='row'>
    <div class='col-md-12'>
       <div class="card">
             <div class="card-header">
                  <h5 class='card-title'><i class="fas fa-users-cog"></i> Import Nilai Sumatif Akhir Lingkup Materi</h4>
				  </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">
                  Asesmen Sumatif Akhir Lingkup Materi bertujuan untuk mengevaluasi hasil belajar siswa pada tiap lingkup materi. Hasil Asesmen Sumatif Akhir Lingkup Materi digunakan
                      <b>Untuk Pengolahan Nilai pada Laporan Hasil Belajar Siswa (Rapor).</b>          
						</span>
                            </div>
                                </div>
                                <div class='card-body'>
                                <form id="form-import" action=''>
								<input type="hidden" name="kelas" value="<?= $jadwal['tingkat'] ?>" >
									<input type="hidden" name="mapel" value="<?= $jadwal['kode'] ?>" >
										<input type="hidden" name="guru" value="<?= $jadwal['idguru'] ?>" >
                                    <div class='col-md-4'>
                                        <label>Pilih File</label>
                                        <input type='file' name='file' class='form-control' required='true' />
										
                                    </div>
                                    <div class='col-md-4'>
                                        <label>&nbsp;</label><br>
                                        <button type='submit' name='submit' class='btn btn-sm btn-success right'><i class='fa fa-upload'></i> Import</button>
                                    </div>
                                </form>
                            </div>
                       
						<div class='row'>
						<div class='col-md-1'>
						 </div>
						 <div class='col-md-8'>
						 <a href="sandik_ikm/prosessumatif.php?kelas=<?= $jadwal['kelas'] ?>&mapel=<?= $jadwal['kode'] ?>" class="btn-link"><i class='fa fa-download'></i> <b>Download Format</b></a>
						 </div>
                        <?= $info ?>
                        
                        <div id='progressbox'></div>
                        <div id='hasilimport'></div>
                    </div>
                </div>
            </div>
           
        </div>
    </div>
</div>
<script>
    $('#form-import').on('submit', function(e) {
        e.preventDefault();
        $.ajax({
            type: 'post',
            url: 'sandik_ikm/crud_sumatif.php',
            data: new FormData(this),
            processData: false,
            contentType: false,
            cache: false,
            beforeSend: function() {
                $('#progressbox').html('<div><img src="<?= $homeurl ?>/dist/img/animasi1.gif" style="margin-left:100px"></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.replace('?pg=nilaisumatif');
                    }, 2000);
                }, 2000);
            }
        });
    });
</script>
						<?php } ?>