<?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 Semester</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 Semester <b>tidak wajib</b> untuk dilakukan, kewenangan diserahkan pada sekolah. 
                 Jika dilaksanakan , silahkan isi nilai dibawah ini				  
							   	</span>
                            </div>
                                </div>
                <div class="table-responsive">
                     <table style="font-size: 12px" id='mapel' class='table'>
                        <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='SAS' "));		
                                $no++;
                              
                            ?>
							
                                <tr>
                                    <td><?= $no; ?></td>
                                    <td><?= $jadwal['mapel'] ?></td>
									 <td><?= $jadwal['kelas'] ?></td>
                                   
                                    <td>
									<?php if($jml==0){ ?>
									<a href="?pg=nilaisas&ac=input3&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>
									<?php }else{ ?>
									<button class="btn btn-sm btn-default" disabled><i class="fas fa-lock"></i></button>
									<?php } ?>
									<a href="?pg=nilaisas&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>
									
									</td>
									
									  
										 
										 
																</tr>
																<?php }
																?>
															</tbody>
														</table>
														

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


<?php } elseif ($ac == 'input3') { ?>
<?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 Semester - <?= $jadwal['kode'] ?>/<?= $jadwal['kelas'] ?></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 Semester <b>tidak wajib</b> untuk dilakukan, kewenangan diserahkan pada sekolah. 
                 Jika dilaksanakan , silahkan isi nilai dibawah ini				  
							   </span>
                            </div>
                                </div>
			<form id="formnilai" action="" >			
		  <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>Nilai</th>
                            </tr>
						
                        </thead>
                        <tbody>									
						<?php
					$query = mysqli_query($koneksi, "select * from siswa WHERE id_kelas='$jadwal[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 $jadwal['kelas'] ?>">
									<input type="hidden" name="mapel[]" value="<?php echo $jadwal['kode'] ?>">
									<input type="hidden" name="ket[]" value="LMAS">
									<input type="hidden" name="khp[]" value="SAS">
									 </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();
        $.ajax({
            type: 'POST',
            url: 'sandik_ikm/crud_nilaisumatif.php?pg=tambah_sas',
            data: $(this).serialize(),
            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=nilaisas');
                    }, 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_sas&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 Semester - <?= $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='SAS' 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 
			
			WHERE nilai_sumatif.idsiswa='$siswa[id_siswa]' AND nilai_sumatif.khp='SAS' 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 } ?>