<?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">INPUT NILAI RAPOR</h5>
										 <a href="erapor" class="btn btn-secondary kanan" data-bs-toggle="tooltip" data-bs-placement="top" title="Kembali"><i class="material-icons">arrow_back</i></a>						
                                    </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>TK</th>													
                                                   
                                                    <th>MATA PELAJARAN</th>
													 <th>KELAS</th>
													 <th>GURU PENGAMPU</th>
													  <th></th>
                                                </tr>
                                            </thead>
                                            <tbody>
											<?php
											$no=0;
											if($user['level']=='admin'):
											$query = mysqli_query($koneksi, "SELECT * FROM jadwal_rapor WHERE kurikulum='K-2013'"); 
											else:
											$query = mysqli_query($koneksi, "SELECT * FROM jadwal_rapor WHERE kurikulum='K-2013' AND idguru='$user[id_user]'"); 	
											endif;
											  while ($data = mysqli_fetch_array($query)) :
											 $mapel = fetch($koneksi,'mata_pelajaran',['kode'=>$data['kodemap']]);
											  $peg = fetch($koneksi,'users',['id_user'=>$data['idguru']]);
											  $jdes = mysqli_num_rows(mysqli_query($koneksi, "SELECT * FROM deskrip WHERE kodemap='$data[kodemap]' AND tingkat='$data[tingkat]' AND idguru='$data[idguru]' AND ket='KI3'"));
											$no++;
											   ?>
                                                <tr>
                                                    <td><?= $no; ?></td>
                                                     <td><?= $data['tingkat'] ?></td>
                                                      
													   <td><?= $mapel['nama_mapel'] ?></td>
													    <td>
													  <?php
														$dataArray = unserialize($data['kelas']);
														foreach ($dataArray as $key => $value) :
															echo $value . " ";
														endforeach;
														?>
													  <td><?= $peg['nama'] ?></td>
													  
													  <td>
											<a href="?pg=nilairapor&ac=view&id=<?= $data['id'] ?>" class="btn btn-sm btn-success" data-bs-toggle="tooltip" data-bs-placement="top" title="Lihat Data Nilai"><i class="material-icons">search</i> </a>
											<a href="?pg=nilairapor&idj=<?= $data['id'] ?>" class="btn btn-sm btn-primary" data-bs-toggle="tooltip" data-bs-placement="top" title="Input Nilai"><i class="material-icons">add</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>
											<?php $idj = $_GET['idj']; ?>
											<?php $desQ = fetch($koneksi,'jadwal_rapor',['id'=>$idj]); ?>
									<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>
										 PILIH MAPEL YANG AKAN DI INPUT
									</button>
											</div>
											<?php if($desQ['id']<>0): ?>
									<form method="POST" action="?pg=nilairapor&ac=upload" class="row g-1">                         
                               <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="<?= $desQ['tingkat'] ?>"><?= $desQ['tingkat'] ?></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
														$dataArray = unserialize($desQ['kelas']);
														foreach ($dataArray as $key => $value) :
															echo $value . " ";
															 echo "<option value='$value'>$value</option>";	
														endforeach;
														?>
								
								   								
									 </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="<?= $desQ['kodemap'] ?>"><?= $desQ['kodemap'] ?></option>	
									 </select>
							</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
													
										$guruku = mysqli_query($koneksi, "SELECT * FROM users where  id_user='$desQ[idguru]'");
										while ($guru = mysqli_fetch_array($guruku)) {										
										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>
										<?php else: ?>
										<div class="widget-payment-request-info m-t-md">
										 <div class="d-grid gap-2">
										<button class="btn btn-secondary" type="button" disabled>Pastikan Semua KD Mapel ini Sudah di isi</button>
										 </div>
										  </div>
										<?php endif; ?>
										</div>
									 </div>
					            </div>
								</div>
							</div>
						</div>
					</div>
				</div>
							
							
							
             <?php elseif ($ac == 'view'): ?>
			<?php $idj = $_GET['id']; ?>
			<?php $desQ = fetch($koneksi,'jadwal_rapor',['id'=>$idj]); ?>
	                <div class="row">
                          <div class="col-md-8">
                                <div class="card">
                                    <div class="card-header">
                                        <h5 class="card-title">NILAI RAPOR <?= $desQ['kodemap']; ?></h5>
										 <a href="?pg=nilairapor" class="btn btn-secondary pull-right" data-bs-toggle="tooltip" data-bs-placement="top" title="Kembali"><i class="material-icons">arrow_back</i></a>						
                                    </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>MATA PELAJARAN</th>
													 <th>KELAS</th>
													 <th>KI-3</th>
													   <th>KI-4</th>
                                                </tr>
                                            </thead>
                                            <tbody>
											<?php
											$no=0;
											$kelas= $_POST['kelas'];
											$kode= $_POST['mapel'];
											$guru= $_POST['guru'];
											$query = mysqli_query($koneksi, "SELECT * FROM nilai_rapor WHERE kelas='$kelas' AND kode='$kode' AND idguru='$guru'"); 	
											  while ($data = mysqli_fetch_array($query)) :
											
											$no++;
											   ?>
											   		<?php $siswa = fetch($koneksi,'siswa',['nis'=>$data['nis']]); ?>
                                                <tr>
                                                    <td><?= $no; ?></td>
                                                     <td><?= $data['nis'] ?></td>                                                  
													   <td><?= $siswa['nama'] ?></td>
														<td><?= $data['kelas'] ?></td>													   
													  <td><?= $data['nilai3'] ?></td>
													    <td><?= $data['nilai4'] ?></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>
										 PILIH MAPEL DAN KELAS
									</button>
											</div>
										
									<form method="POST" action="" class="row g-1">                         
                              
							          <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
														$dataArray = unserialize($desQ['kelas']);
														foreach ($dataArray as $key => $value) :
															echo $value . " ";
															 echo "<option value='$value'>$value</option>";	
														endforeach;
														?>
								
								   								
									 </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="<?= $desQ['kodemap'] ?>"><?= $desQ['kodemap'] ?></option>	
									 </select>
							</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
													
										$guruku = mysqli_query($koneksi, "SELECT * FROM users where  id_user='$desQ[idguru]'");
										while ($guru = mysqli_fetch_array($guruku)) {										
										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"><i class='material-icons'>search</i> Cari Nilai</button>
                                            </div>
										</form>
										
										</div>
									 </div>
					            </div>
								</div>
							</div>
						</div>
					</div>
				</div>
							
							
			<?php elseif ($ac == 'upload'): ?>
			 <?php
			 $mapel = $_POST['mapel'];
			 $kelas = $_POST['kelas'];
			  $guru = $_POST['guru'];
			 ?>
             <div class="row">
                          <div class="col-md-8">
                                <div class="card">
                                    <div class="card-header">
                                        <h5 class="bold">UPLOAD NILAI RAPOR <span class="badge badge-secondary"><?= $mapel ?> - <?= $kelas ?></span></h5>
										<a href="cbtserver_rapor/proses.php?k=<?= $kelas ?>&m=<?= $mapel ?>&g=<?= $guru ?>" class="btn btn-link pull-right"><i class="material-icons">download</i>Download Format</a>   
										 		
                                    </div>
                                    <div class="card-body">
									<br>
									<form id='formnilaisiswa'>	
                                      <label>Pilih File Excel</label>
									  <div class="input-group mb-3">
                                       <input type='file' name='file' class='form-control' required='true' />
									    <span class="input-group-text">
											<button type="submit" id="blockui-3" class="btn btn-primary"><i class="material-icons">upload</i></button>
										</span>
                                        </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-dark" type="button" disabled>
										<span class="spinner-grow spinner-grow-sm" role="status" aria-hidden="true"></span>
										NILAI <?= $mapel ?> - <?= $kelas ?>
									</button>
											</div>
											
										</div>
									 </div>
					            </div>
								</div>
							</div>
						</div>
					</div>
				</div>
			 <script>
    $('#formnilaisiswa').submit(function(e){
		e.preventDefault();
		var data = new FormData(this);
		$.ajax(
		{
			type: 'POST',
             url: 'cbtserver_rapor/import_nilai.php',
            data: data,
			cache: false,
			contentType: false,
			processData: false,
			success: function(data){   		
			setTimeout(function()
				{
				window.location.replace('?pg=nilairapor');
						}, 1500);
									  
						}
					});
				return false;
			});
		</script>	
					  <?php endif ?>
					  
					  
					  
					  	  
					  
					  
					