<?php
defined('APK') or exit('Anda tidak dizinkan mengakses langsung script ini!');
$jumsiswa = mysqli_num_rows(mysqli_query($koneksi, "SELECT * FROM siswa"));

?>           
          
	<div class="row">                   			
           <div class="col-xl-8">	
                  <div class="card widget widget-list">
                      <div class="card-header">
                           <h5 class="card-title">SETTING KURIKULUM</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>TK</th>													                                                   
                                                    <th>KURIKULUM</th>
													 <th>MODEL RAPOR</th>
													 
                                                </tr>
                                            </thead>
                                            <tbody>
                                            <?php
											$no=0;
											$query = mysqli_query($koneksi, "SELECT * FROM kelas GROUP BY level"); 
											  while ($data = mysqli_fetch_array($query)) :
											  $mdr =fetch($koneksi,'mode_rapor',['model'=>$data['model_rapor']]);
											$no++;
											   ?>
											  <tr> 
											   <td><?= $no; ?> </td>
											     <td><?= $data['level'] ?> </td>
												   <td><?= $data['kurikulum'] ?> </td>
												     <td><?= $mdr['ket'] ?> </td>
													
											</tr>
									
										 <?php endwhile; ?>
										 </tbody>
										 </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>
										 SETTING KURIKULUM
									</button>
											</div>
									<form id='formkuri' 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="">Pilih Tingkat</option>									
									  <?php
													
										$tkt = mysqli_query($koneksi, "SELECT * FROM kelas GROUP BY level");
										while ($tingkat = mysqli_fetch_array($tkt)) {										
										echo "<option value='$tingkat[level]'>$tingkat[level]</option>";
													}
													?>
									 </select>
							     </div>	
							      <div class="col-md-12">
								<label class="form-label bold">Kurikulum</label>
								<select name='kuri' id='kuri' class='form-select mapel' 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 class="col-md-12">
								<label class="form-label bold">Model Rapor</label>
								<select name='model' id='model' class='form-select mapel' required='true' style="width: 100%">
								  
									 </select>
							</div>
							
								<p>
									  
								           <div class="d-grid gap-2">
                                       <button type="submit" class="btn btn-primary" id="blockui-2">SIMPAN</button>
                           
                                            </div>
									</form>
										</div>
									 </div>
					            </div>
								</div>
							</div>
						</div>
					</div>
                           
										<script>
										$('#formkuri').submit(function(e){
											e.preventDefault();
											var data = new FormData(this);
											$.ajax(
											{
												type: 'POST',
												 url: 'cbtserver_rapor/tkuri.php?pg=editkuri',
												 enctype: 'multipart/form-data',
												data: data,
												cache: false,
												contentType: false,
												processData: false,
												success: function(data){   		
												setTimeout(function()
													{
													window.location.reload();
															}, 2000);
																		  
															}
														});
													return false;
												});
											</script>							 
	                                      <script>
									$("#kuri").change(function() {
									var kuri = $(this).val();
									console.log(kuri);
									$.ajax({
									type: "POST",
									url: "cbtserver_rapor/tkuri.php?pg=model", 
									data: "kuri=" + kuri, 
									success: function(response) { 
									$("#model").html(response);
											}
										});
									});
									</script>		