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

?>           
	<?php if ($ac == '') : ?>
                 
				 <div class="row">
                          <div class="col-md-8">
                                <div class="card">
                                    <div class="card-header">
                                        <h5 class="card-title">NILAI HARIAN</h5>
										
                                    </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>TANGGAL</th>
													<th>ROMBEL</th>													                           
                                                    <th>MAPEL</th>
													 <th>GURU PENGAMPU</th>
													  <th></th>
													
                                                </tr>
                                            </thead>
                                            <tbody>
											<?php
											$no=0;
											if($user['level']=='admin'):
											$query = mysqli_query($koneksi, "SELECT * FROM nilai_harian GROUP BY tanggal"); 
											else:
											$query = mysqli_query($koneksi, "SELECT * FROM nilai_harian WHERE guru='$user[id_user]' GROUP BY tanggal"); 	
											endif;
											  while ($data = mysqli_fetch_array($query)) :
											 $peg = fetch($koneksi,'users',['id_user'=>$data['guru']]);
											$no++;
											   ?>
                                                <tr>
                                                    <td><?= $no; ?></td>
                                                     <td><?= $data['tanggal'] ?></td>
                                                      <td><?= $data['kelas'] ?></td>										   
													  <td><?= $data['mapel'] ?></td>
													   <td><?= $peg['nama'] ?></td>
													  <td>
													  <a href="cbtserver_ptm/cetaknilai.php?t=<?= $data['tanggal'] ?>&k=<?= $data['kelas'] ?>&m=<?= $data['mapel'] ?>&g=<?= $data['guru'] ?>" target="_blank" class="btn btn-sm btn-danger"><i class="material-icons">print</i></a>
													  </td>
                                                </tr>
												<?php endwhile; ?>
                                                </table>
												 </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-dark" type="button" disabled>
										<span class="spinner-grow spinner-grow-sm" role="status" aria-hidden="true"></span>
										 NILAI HARIAN
									</button>
											</div>
										
									<form method="POST" action="?pg=nilai&ac=input" class="row g-1"  enctype='multipart/form-data'>
									 <div class="col-md-12">
								<label class="form-label bold">Tanggal</label>
								<input type="text" name="tanggal" class="datepicker form-control" required="true" autocomplete="off">
							     </div>
								<div class="col-md-12">
								<label class="form-label bold">Jenis</label>
								<select name='kode'  class='form-select' required='true' style="width: 100%">
								    <option value="">Pilih Jenis</option>
                                        <option value="UH">UH</option>	
										<option value="PR">TUGAS</option>										
									 </select>
							     </div>									 
                               <div class="col-md-12">
								<label class="form-label bold">Rombel</label>
								<select name='kelas' id='kelas' class='form-select' required='true' style="width: 100%">
								    <option value="">Pilih Rombel</option>
                                       <?php									
											$query = mysqli_query($koneksi, "SELECT * FROM kelas"); 
										while ($tkt = mysqli_fetch_array($query)) {										
										echo "<option value='$tkt[kelas]'>$tkt[kelas]</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=''>Pilih Mapel</option>
								<?php
										
											$query = mysqli_query($koneksi, "SELECT * FROM mata_pelajaran"); 	
										  
										while ($mpl = mysqli_fetch_array($query)) {										
										echo "<option value='$mpl[kode]'>$mpl[nama_mapel]</option>";
													}
													?>						
									 </select>
									
							</div>
							<div class="col-md-12">
								<label class="form-label bold">Kurikulum</label>
								<select name='kuri' id='kuri' class='form-select' required='true' style="width: 100%">
								  	<option value=''>Pilih Kurikulum</option>
									<option value='K-2013'>K-2013</option>
									<option value='K-Merdeka'>K-Merdeka</option>
									 </select>
									
							</div>
							<div id="kd" style="display: none;">
							<div class='col-md-12'>
                                     <label class="bold">No KI/KD</label>
                                   <input type="text" name="kd"  class="form-control" autocomplete='off' >
                                  </div>
																							
								 </div>		
                                     <div id="lingkup" style="display: none;">
									
											<div class='col-md-12'>
                                        <label class="bold">Tujuan Pembelajaran Ke</label>
                                          <input type="number" name="tp"  class="form-control" autocomplete='off' >
                                                </div> 
								           </div>	
								 <div class="col-md-12">
								<label class="form-label bold">Guru Pengampu</label>
								<select name="guru" class='form-select' required='true' style="width: 100%" >
										 <?php
										if($user['level']=='admin'):
											$query = mysqli_query($koneksi, "SELECT * FROM users where level='guru'"); 
											else:
											$query = mysqli_query($koneksi, "SELECT * FROM users where id_user='$user[id_user]'"); 	
										  endif;
										while ($guru = mysqli_fetch_array($query)) {
                                         
										echo "<option value='$guru[id_user]'>$guru[nama]</option>";
													}
													?>	
												</select>
							          </div><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 type="text/javascript">
    $(function () {
        $("#kuri").change(function () {
            if ($(this).val() == "K-2013") {
                $("#kd").show();             
				 $("#lingkup").hide();
				
            } else {
                $("#kd").hide();
				 $("#lingkup").show();
				
            }
        });
    });
</script>						
							
             <?php elseif ($ac == 'input'): ?>
			 <?php
			 $tgl = $_POST['tanggal'];
			  $kode = $_POST['kode'];
			  $kelas = $_POST['kelas'];
			  $mapel = $_POST['mapel'];
			 $kuri = $_POST['kuri'];
			 $kd = $_POST['kd'];
			 $tp = $_POST['tp'];
			 $guru = $_POST['guru'];
			 ?>
			 <div class="row">
                          <div class="col-md-8">
                                <div class="card">
                                    <div class="card-header">
                                        <h5 class="card-title">NILAI HARIAN | <?= $mapel ?> | <?= $kelas ?> | <?= $kode ?></h5>
										
                                    </div>
                                    <div class="card-body">
									<form id="formnilai" action="" >
									<div class="card-box table-responsive">
                                        <table id="datata" class="table table-bordered table-hover" style="width:100%;font-size:12px">
                                            <thead>
                                                <tr>
                                                    <th width="5%">NO</th> 
																										                           
                                                    <th>NIS</th>
													 <th>NAMA</th>
													  <th>NILAI</th>
													
                                                </tr>
                                            </thead>
                                            <tbody>
											<?php
											$no=0;
											
											$query = mysqli_query($koneksi, "SELECT * FROM siswa WHERE kelas='$kelas'"); 
											
											  while ($data = mysqli_fetch_array($query)) :
											 
											$no++;
											   ?>
                                                <tr>
                                                    <td><?= $no; ?></td>
                                                     <td><?= $data['nis'] ?></td>
                                                      <td><?= $data['nama'] ?></td>										   
													  <td>
													  <input type="number" name="nilai[]" value="0" class="form-control" required="true" >
													  <input type="hidden" name="ids[]" value="<?= $data['id_siswa'] ?>" class="form-control"  >
													   <input type="hidden" name="tgl[]" value="<?= $tgl ?>" class="form-control"  >
													   <input type="hidden" name="kode[]" value="<?= $kode ?>" class="form-control"  >
													  <input type="hidden" name="kd[]" value="<?= $kd ?>" class="form-control"  >
													  <input type="hidden" name="tp[]" value="<?= $tp ?>" class="form-control"  >
													  <input type="hidden" name="kelas[]" value="<?= $kelas ?>" class="form-control"  >
													  <input type="hidden" name="mapel[]" value="<?= $mapel ?>" class="form-control"  >
													  <input type="hidden" name="guru[]" value="<?= $guru ?>" class="form-control"  >
													   <input type="hidden" name="kuri[]" value="<?= $kuri ?>" class="form-control"  >
													  
													  
													  </td>
													  
                                                </tr>
												<?php endwhile; ?>
                                                </table>
												 </div>
												 <div class='kanan'>
													<button type='submit'  class='btn  btn-primary' id="blockui-3"> Simpan</button>
																</div>
															 </form>
											</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>
										NILAI HARIAN
									</button>
											</div>
										
									
									
                                   
									
                               <div class="col-md-12">
								<label class="form-label bold">Kelas</label>
								<input type="text" class="form-control" value="<?= $kelas ?>" readonly>
							     </div>	
							             
								
							<div class="col-md-12">
								<label class="form-label bold">Mapel</label>
								<input type="text" class="form-control" value="<?= $mapel ?>" readonly>
							</div>
							 
							
								
										</div>
									 </div>
					            </div>
								</div>
							</div>
						</div>
					</div>
				</div>
								<script>
       $('#formnilai').submit(function(e) {
        e.preventDefault();
        var data = new FormData(this);
        $.ajax({
            type: 'POST',
            url: 'cbtserver_ptm/crud_nilai.php?pg=tambah',
           enctype: 'multipart/form-data',
            data: data,
            cache: false,
            contentType: false,
            processData: false,
            success: function(data) {
               
                setTimeout(function() {
                    window.location.replace('?pg=nilai');
                }, 2000);

            }
        });
        return false;
    });
   </script>
							   
					  <?php endif ?>
					  
					  
					  
					  	  
					  
					  
					