<?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">JUMLAH KD SEMESTER <?= $setting['semester'] ?></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>MAPEL</th>
                                                    <th>KELAS</th>
													 <th>GURU PENGAMPU</th>
													 <th>JML KD</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' ORDER BY id DESC"); 
											  else:
											  $query = mysqli_query($koneksi, "SELECT * FROM jadwal_rapor WHERE kurikulum='K-2013' AND idguru='$user[id_user]' ORDER BY id DESC"); 
											endif;
											  while ($data = mysqli_fetch_array($query)) :
											 
											   $peg = fetch($koneksi,'users',['id_user'=>$data['idguru']]);
											$no++;
											   ?>
                                                <tr>
                                                    <td><?= $no; ?></td>
                                                    <td><?= $data['kodemap'] ?></td>
                                                     <td>
													  <?php
														$dataArray = unserialize($data['kelas']);
														foreach ($dataArray as $key => $value) :
															echo $value . ", ";
														endforeach;
														?>
													 </td>
													  <td><?= $peg['nama'] ?></td>
													  <td>
													  <?php if($data['jumkd']==0): ?>
													  <h5><span class="badge badge-danger"><?= $data['jumkd'] ?></span></h5>
													  <?php else: ?>
													   <h5><span class="badge badge-dark"><?= $data['jumkd'] ?></span></h5>
													  <?php endif; ?>
													  </td>
											             <td>
														 <a href="?pg=jumkd&id=<?= $data['id'] ?>" class="btn btn-sm btn-primary" data-bs-toggle="tooltip" data-bs-placement="top" title="Input Jumlah KD"><i class="material-icons">edit</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-primary" type="button" disabled>
										<span class="spinner-grow spinner-grow-sm" role="status" aria-hidden="true"></span>
										 JUMLAH KD SEMESTER <?= $setting['semester'] ?>
									</button>
											</div>
									<form id='formkd' class="row g-1">    
                                <?php
								$id = $_GET['id'];
								$jadwal = fetch($koneksi,'jadwal_rapor',['id'=>$id]);
                               ?>		
                             <input	type="hidden" name="id" value="<?= $id ?>" >						   
                               <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="<?= $jadwal['tingkat'] ?>"><?= $jadwal['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="<?= $jadwal['kodemap'] ?>"><?= $jadwal['kodemap'] ?></option>	
									 </select>
							</div>
							 
							 <div class="col-md-12">
								<label class="form-label bold">Jumlah KD</label>
								<input type="number" name="jumkd" class="form-control" required="true">
								</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>
						$('#formkd').submit(function(e) {
								e.preventDefault();
								var data = new FormData(this);
								$.ajax({
									type: 'POST',
									 url: 'cbtserver_rapor/tdeskrip.php?pg=jumkd',
									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>

	
					  <?php endif ?>
					  
	