<?php
defined('APK') or exit('Anda tidak dizinkan mengakses langsung script ini!');

?>           <?php if ($ac == '') : ?>
	        <div class="alert alert-dark" role="alert">
                  Asesmen Sumatif Akhir Semester <b>tidak wajib</b> untuk dilakukan, kewenangan diserahkan pada sekolah. 
                 Jika dilaksanakan , silahkan isi nilai dibawah ini	
				<?php
	if (empty($_GET['level'])) {
        $tingkat = "";
    } else {
        $tingkat = $_GET['level'];
    }			
    if (empty($_GET['kelas'])) {
        $kelas = "";
    } else {
        $kelas = $_GET['kelas'];
    }
     if (empty($_GET['mapel'])) {
        $mapel = "";
    } else {
        $mapel = $_GET['mapel'];
    }
	  if (empty($_GET['guru'])) {
        $guru = "";
    } else {
        $guru = $_GET['guru'];
    }
	
    ?>
	 <?php include"cbtserver_rapor/radio.php"; ?>
				   </div>	
                   <div class="row">
                          <div class="col-md-8">
                                <div class="card">
                                    <div class="card-header">
                                        <h5 class="bold"> SUMATIF AKHIR SEMESTER <span class="badge badge-secondary"><?= $mapel ?> <?= $kelas ?></span></h5>
										<div class="pull-right">
										<?php if($kelas<>''): ?>
										
										<button type="button" class="btn btn-sm btn-success" data-bs-toggle="modal" data-bs-target="#example"><i class="material-icons">upload</i>Upload</button>
                                    
									<?php endif; ?>
									<a href="erapor" class="btn btn-sm btn-dark">Back</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%;font-size:12px">
                                            <thead>
                                                <tr>
                                                    <th width="5%">NO</th> 
													<th>NIS</th>													                           
                                                    <th>NAMA SISWA</th>
													 <th>SAS</th>
													
													 
                                                </tr>
                                            </thead>
                                            <tbody>
											<?php
											$no=0;
											
											$query = mysqli_query($koneksi, "SELECT * FROM siswa WHERE kelas='$kelas'"); 				
											  while ($data = mysqli_fetch_array($query)) :
											$sas = mysqli_fetch_array(mysqli_query($koneksi, "SELECT * FROM nilai_sumatif WHERE nis='$data[nis]' AND kode='$mapel' AND khp='SAS'"));
											$no++;
											   ?>
                                                <tr>
                                                    <td><?= $no; ?></td>
                                                     <td><?= $data['nis'] ?></td>
                                                      <td><?= $data['nama'] ?></td>
													  <td><?= $sas['nilai'] ?></td>
                                                </tr>
												<?php endwhile; ?>
												</tbody>
                                                </table>
												 </div>
												 <div class="modal fade" id="example" tabindex="-1" aria-labelledby="example" aria-hidden="true">
                                                    <div class="modal-dialog modal-lg">
                                                        <div class="modal-content">
                                                            <div class="modal-header">
                                                                <h5>NILAI SUMATIF <span class="badge badge-secondary"><?= $mapel ?> <?= $kelas ?></span></h5>
                                                                 <a href="cbtserver_rapor/kurmer/prosessas.php?m=<?= $mapel ?>&k=<?= $kelas ?>" class="btn-link"><i class='material-icons'>download</i> <b>Download Format</b></a>
                                                            </div>
                                                            <div class="modal-body">
													 <div class="alert alert-dark" role="alert">                   
													  Asesmen Sumatif Akhir Semester <b>tidak wajib</b> untuk dilakukan, kewenangan diserahkan pada sekolah. 
														Jika dilaksanakan , silahkan isi nilai dibawah ini	
													  </div>
											          <form id="form-import" action=''>
								                     <input type="hidden" name="guru" value="<?= $guru ?>" >
													<input type="hidden" name="mapel" value="<?= $mapel ?>" >
														<input type="hidden" name="level" value="<?= $tingkat ?>" >
													<div class='col-md-12'>
														<label>Pilih File</label>
														<input type='file' name='file' class='form-control' required='true' />
														
													</div>
													
                                                            </div>
                                                            <div class="modal-footer">
                                                                <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">BATAL</button>
                                                                <button type="submit" class="btn btn-primary" id="blockui-2">SIMPAN</button>
                                                            </div>
															 </form>
                                                        </div>
                                                    </div>
                                                </div>
											</div>
										</div>
										
									</div>
									
					       <div class="col-md-4">
                     
                                <div class="card widget widget-payment-request">
                                    <div class="card-header">
                                  
                                    </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/user.png" alt="">
                                                </div>
                                                <div class="widget-payment-request-author-info">
                                                    <span class="widget-payment-request-author-name"><?= strtoupper($user['nama']) ?></span>
                                                    <span class="widget-payment-request-author-about"><?= $setting['sekolah'] ?></span>
                                               
											   </div>
                                            </div>
											
									<div class="widget-payment-request-info m-t-md">
									 <div class="d-grid gap-2">
									<button class="btn btn-primary" type="button" disabled>
										<span class="spinner-grow spinner-grow-sm" role="status" aria-hidden="true"></span>
										 SUMATIF AKHIR SEMESTER
									</button>
											</div>
								
                               <div class="col-md-12">
								<label class="form-label bold">Tingkat</label>
								<select name='level' id='level' class='form-select level' required='true' style="width: 100%">
								    <option value="">Pilih Tingkat</option>
                                       <?php
										if($user['level']=='admin'):
											$query = mysqli_query($koneksi, "SELECT * FROM jadwal_rapor WHERE kurikulum='K-Merdeka' GROUP BY tingkat"); 
											else:
											$query = mysqli_query($koneksi, "SELECT * FROM jadwal_rapor WHERE kurikulum='K-Merdeka' AND idguru='$user[id_user]' GROUP BY tingkat"); 	
										  endif;
										while ($tkt = mysqli_fetch_array($query)) {										
										echo "<option value='$tkt[tingkat]'>$tkt[tingkat]</option>";
													}
													?>						
									 </select>
							     </div>	
							    <div class="col-md-12">
								<label class="form-label bold">Pilih Rombel</label>
								<select name='kelas' id='kelas' class='form-select kelas' required='true' style="width: 100%">         
								
								 </select>
							     </div>
							<div class="col-md-12">
								<label class="form-label bold">Mata Pelajaran</label>
								<select name='mapel' id='mapel' class='form-select mapel' required='true' style="width: 100%">
								  <?php
										if($user['level']=='admin'):
											$query = mysqli_query($koneksi, "SELECT * FROM jadwal_rapor WHERE kurikulum='K-Merdeka'"); 
											else:
											$query = mysqli_query($koneksi, "SELECT * FROM jadwal_rapor WHERE kurikulum='K-Merdeka' AND idguru='$user[id_user]'"); 	
										  endif;
										while ($mpl = mysqli_fetch_array($query)) {										
										echo "<option value='$mpl[kodemap]'>$mpl[kodemap]</option>";
													}
													?>						
									 </select>
									
							</div>
							
								 <div class="col-md-12">
								<label class="form-label bold">Guru Pengampu</label>
								<select name="guru" class='form-select guru' required='true' style="width: 100%" >
										 <?php
										if($user['level']=='admin'):
											$query = mysqli_query($koneksi, "SELECT * FROM jadwal_rapor WHERE kurikulum='K-Merdeka'"); 
											else:
											$query = mysqli_query($koneksi, "SELECT * FROM jadwal_rapor WHERE kurikulum='K-Merdeka' AND idguru='$user[id_user]'"); 	
										  endif;
										while ($guru = mysqli_fetch_array($query)) {
                                          $peg = mysqli_fetch_array(mysqli_query($koneksi, "SELECT * FROM users  WHERE id_user='$guru[idguru]'"));											
										echo "<option value='$guru[idguru]'>$peg[nama]</option>";
													}
													?>	
												</select>
							          </div><p>
									  
								           <div class="d-grid gap-2">
                                         <button  class="btn btn-primary flex-grow-1 m-l-xxs" id="cari"> PILIH</button>
                                          <script type="text/javascript">
                                $('#cari').click(function() {
									 var level = $('.level').val();
                                    var kelas = $('.kelas').val();
                                    var mapel = $('.mapel').val();
									 var guru = $('.guru').val();
                                    location.replace("?pg=sas&level=" + level + "&kelas=" + kelas + "&mapel=" + mapel + "&guru=" + guru);
                                }); 
                            </script>
                                            </div>
									
										</div>
									 </div>
					            </div>
								</div>
							</div>
						</div>
					</div>
				</div>
							<script>
						$('#form-import').submit(function(e) {
								e.preventDefault();
								var data = new FormData(this);
								$.ajax({
									type: 'POST',
									 url: 'cbtserver_rapor/kurmer/crud_sas.php',
									enctype: 'multipart/form-data',
									data: data,
									cache: false,
									contentType: false,
									processData: false,
									beforeSend: function() {},
									success: function(data) {
									   
										setTimeout(function() {
											window.location.reload();
										}, 1500);
									}
								})
								return false;
							});
							</script>
							<script>	
		$("#level").change(function() {
		var level = $(this).val();
		console.log(level);
		$.ajax({
		type: "POST",
		url: "cbtserver_rapor/kurmer/tnilai.php?pg=kelas", 
		data: "level=" + level, 
	    success: function(response) { 
		$("#kelas").html(response);
		
				}
			});
		});</script>
							
             <?php elseif ($ac == 'edit'): ?>
			 <?php
			 $idl = $_GET['idl'];
			 $lingkup = fetch($koneksi,'lingkup',['idl'=>$idl]);
			 ?>
	                <div class="col-md-4">
                     
                                <div class="card widget widget-payment-request">
                                    <div class="card-header">
                                  
                                    </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/user.png" alt="">
                                                </div>
                                                <div class="widget-payment-request-author-info">
                                                    <span class="widget-payment-request-author-name"><?= strtoupper($user['nama']) ?></span>
                                                    <span class="widget-payment-request-author-about"><?= $setting['sekolah'] ?></span>
                                               
											   </div>
                                            </div>
											
									<div class="widget-payment-request-info m-t-md">
									 <div class="d-grid gap-2">
									<button class="btn btn-primary" type="button" disabled>
										<span class="spinner-grow spinner-grow-sm" role="status" aria-hidden="true"></span>
										 EDIT LINGKUP MATERI
									</button>
											</div>
										
									<form id='formedit' class="row g-1"> 
									
                                    <input type="hidden" name="idl" value="<?= $idl ?>" >
									
                               <div class="col-md-12">
								<label class="form-label bold">Tingkat</label>
								<select name='level' id='level' class='form-select' required='true' style="width: 100%">
								    <option value="<?= $lingkup['tingkat'] ?>"><?= $lingkup['tingkat'] ?></option>
                                       					
									 </select>
							     </div>	
							             
								
							<div class="col-md-12">
								<label class="form-label bold">Mata Pelajaran</label>
								<select name='mapel' id='mapel' class='form-select' required='true' style="width: 100%">
								  <option value="<?= $lingkup['kodemap'] ?>"><?= $lingkup['kodemap'] ?></option>
									 </select>
							</div>
							 <div class="col-md-12">
								<label class="form-label bold">Materi</label>
							   <textarea name="materi" class="form-control" rows="5" required="true" maxlength="200" ><?= $lingkup['materi'] ?></textarea>							   
							   </div>
							   <div id="count">
								<span id="current_count">0</span>
								<span id="maximum_count">/ 200</span>
							</div>
							<script type="text/javascript">
							$('textarea').keyup(function() {    
								var characterCount = $(this).val().length,
									current_count = $('#current_count'),
									maximum_count = $('#maximum_count'),
									count = $('#count');    
									current_count.text(characterCount);        
							});
							</script>
								<p>
									  
								           <div class="d-grid gap-2">
                                       
										 
                                         <button type="submit" class="btn btn-primary flex-grow-1 m-l-xxs" id="blockui-2">Simpan</button>
                                          
                                            </div>
										</form>
										
										</div>
									 </div>
					            </div>
								</div>
							</div>
						</div>
					</div>
				</div>
							<script>
						$('#formedit').submit(function(e) {
								e.preventDefault();
								var data = new FormData(this);
								$.ajax({
									type: 'POST',
									 url: 'cbtserver_rapor/kurmer/tkurmer.php?pg=edit',
									enctype: 'multipart/form-data',
									data: data,
									cache: false,
									contentType: false,
									processData: false,
									beforeSend: function() {},
									success: function(data) {
									   
										setTimeout(function() {
											window.location.replace('?pg=lingkup');
										}, 1500);
									}
								})
								return false;
							});
							</script>
							
							   
					  <?php endif ?>
					  
					  
					  
					  	  
					  
					  
					