<?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">SIKAP SOSIAL KI-2</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>GURU PENGAMPU</th>
													 
													  <th></th>
                                                </tr>
                                            </thead>
                                            <tbody>
											<?php
											$no=0;
											if($user['level']=='admin'):
											$query = mysqli_query($koneksi, "SELECT * FROM jadwal_rapor JOIN mapel_rapor ON mapel_rapor.kode=jadwal_rapor.kodemap WHERE jadwal_rapor.kurikulum='K-2013' AND mapel_rapor.sikap='2' GROUP BY mapel_rapor.tingkat"); 
											else:
											$query = mysqli_query($koneksi, "SELECT * FROM jadwal_rapor JOIN mapel_rapor ON mapel_rapor.kode=jadwal_rapor.kodemap WHERE jadwal_rapor.kurikulum='K-2013' AND jadwal_rapor.idguru='$user[id_user]' AND mapel_rapor.sikap='2' GROUP BY mapel_rapor.tingkat"); 
											endif;
											  while ($data = mysqli_fetch_array($query)) :
											 $mapel = fetch($koneksi,'mata_pelajaran',['kode'=>$data['kodemap']]);
											  $peg = fetch($koneksi,'users',['id_user'=>$data['idguru']]);
											 $kur = mysqli_fetch_array(mysqli_query($koneksi, "SELECT * FROM kelas  WHERE level='$data[tingkat]' GROUP BY level"));
											$no++;
											   ?>
                                                <tr>
                                                    <td><?= $no; ?></td>
                                                     <td><?= $data['tingkat'] ?></td>
                                                      
													   <td><?= $mapel['nama_mapel'] ?></td>
													  <td><?= $peg['nama'] ?></td>
													   
													  <td>
											<?php if($kur['model_rapor']==1): ?>
											<a href="?pg=sosial&idj=<?= $data['id'] ?>" class="btn btn-sm btn-primary" data-bs-toggle="tooltip" data-bs-placement="top" title="Nilai Spiritual"><i class="material-icons">add</i> </a>
											<?php else: ?>
											Tidak ada sikap Sosial
											<?php endif; ?>
											</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-primary" type="button" disabled>
										<span class="spinner-grow spinner-grow-sm" role="status" aria-hidden="true"></span>
										 INPUT NILAI SIKAP KI-1
									</button>
											</div>
											
									                        
                               <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 class='form-select kelas' required='true' style="width: 100%">
								
								                <?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 mapel' 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 guru' 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 id="cari_nilai" class="btn btn-primary"><i class='material-icons'>search</i> Cari Nilai</button>
                            <script type="text/javascript">
                                $('#cari_nilai').click(function() {
                                    var kelas = $('.kelas').val();
                                    var mapel = $('.mapel').val();
									var guru = $('.guru').val();
                                    location.replace("?pg=sosial&ac=input&kelas=" + kelas + "&mapel=" + mapel + "&guru=" + guru);
                                }); 
                            </script>
                                            </div>
									
										</div>
									 </div>
					            </div>
								</div>
							</div>
						</div>
					</div>
				</div>
				<?php elseif ($ac == 'input'): ?>	
						<?php 
						$kelas = $_GET['kelas']; 	
						
						$guru = $_GET['guru']; 
						$modrap = fetch($koneksi,'kelas',['kelas'=>$kelas]); 
						?>
						 <div class="row">
                          <div class="col-md-12">
                                <div class="card">
                                    <div class="card-header">
                                        <h5 class="bold">NILAI SIKAP <span class="badge badge-secondary">SPIRITUAL  <?= $kelas ?></span></h5>
										 <a href="?pg=sosial" 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">
									<?php if($modrap['model_rapor']==1): ?>
									<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>NAMA SISWA</th>
													
													   <th>SELALU DILAKUKAN</th>
													    <th>MULAI MENINGKAT</th>
														<th width="5%">PRED</th>
														<th width="5%"></th>
                                                </tr>
                                            </thead>
                                            <tbody>
											<?php
											$no=0;
											
											$query = mysqli_query($koneksi, "SELECT * FROM siswa WHERE kelas='$kelas'"); 	
											  while ($siswa = mysqli_fetch_array($query)) :
											$niss = mysqli_num_rows(mysqli_query($koneksi, "SELECT * FROM sosial WHERE nis='$siswa[nis]'"));
											$spi =fetch($koneksi,'sosial',['nis'=>$siswa['nis']]);
											$no++;
											   ?>
											   	
                                                <tr>
                                                    <td><?= $no; ?></td>                                              
													   <td><?= $siswa['nama'] ?></td>
                                                       
													    <td><?= $spi['ket1'] ?></td>
													<td><?= $spi['ket2'] ?></td>
													<td><?= $spi['predikat'] ?></td>
													 <td>
													 <?php if($niss==1): ?>
													 <button data-id="<?= $spi['id'] ?>" class="delet btn btn-sm btn-danger" ><i class="material-icons">delete</i></button>
													 <?php else : ?>
													 <a href="?pg=sosial&ac=inputsos&ids=<?= $siswa['id_siswa'] ?>"  class="btn btn-sm btn-primary"><i class="material-icons">edit</i></a>
												<?php endif; ?>
												</td>
                                                </tr>
												<?php endwhile; ?>
                                                </table>
												 </div>
												 <?php else: ?>
												 TIDAK ADA SIKAP SOSIAL
												 <?php endif; ?>
											</div>
										</div>
										
									
								</div>
							</div>
						</div>
					 <script>
									$('#datatable1').on('click', '.delet', function() {
									var id = $(this).data('id');
									console.log(id);
									swal({
											  title: 'Yakin hapus data?',
											  text: "You won't be able to revert this!",
											  type: 'warning',
											  showCancelButton: true,
											  confirmButtonColor: '#3085d6',
											  cancelButtonColor: '#d33',
											  confirmButtonText: 'Ya, Hapus!',
											  cancelButtonText: "Batal"				  
									}).then((result) => {
										if (result.value) {
											$.ajax({
											   url: 'cbtserver_rapor/crud_spi.php?pg=hapussos',
												method: "POST",
												data: 'id=' + id,
												success: function(data) {
													  iziToast.info(
										{
											 title: 'Sukses!',
											message: 'Data berhasil dihapus',
											titleColor: '#FFFF00',
											messageColor: '#fff',
											backgroundColor: 'rgba(0, 0, 0, 0.5)',
											 progressBarColor: '#FFFF00',
											  position: 'topRight'				  
											});
													setTimeout(function() {
														window.location.reload();
													}, 2000);
												}
											});
										}
										return false;
									})

								});

							</script>    
				
				 <?php elseif ($ac == 'inputsos'): ?>	
				 <?php include"cbtserver_rapor/radio.php"; ?>
				<?php 
				$siswa=fetch($koneksi,'siswa',['id_siswa'=>$_GET['ids']]); 
				$kelas=$siswa['kelas'];
				?>	
				<div class="row">
                          <div class="col-md-8">
                                <div class="card">
                                    <div class="card-header">
                                        <h5 class="bold">NILAI KI-1 <span class="badge badge-secondary">  <?= $siswa['nama'] ?></span></h5>
										
                                    </div>
                                    <div class="card-body">
				                    <form id='formspi'  >
									<input type="hidden" name="nis" value="<?= $siswa['nis']; ?>" required>
									<input type="hidden" name="kelas" value="<?= $siswa['kelas']; ?>" required>
									 <div class="row mb-2">
											<label  class="col-md-3 bold">Selalu Dilakukan</label>
											<div class="col-sm-9">
								<label class="checkbox"><input class='hidden radio-label' type='checkbox' name="ket1[]" value="jujur" /> 
								<span class="check"></span>jujur</label>
								<label class="checkbox"><input class='hidden radio-label' type='checkbox' name="ket1[]" value="disiplin" /> 
								<span class="check"></span>disiplin</label>
								<label class="checkbox"><input class='hidden radio-label' type='checkbox' name="ket1[]" value="tanggung jawab" /> 
								<span class="check"></span>tanggung jawab</label>
								<label class="checkbox"><input class='hidden radio-label' type='checkbox' name="ket1[]" value="santun" /> 
								<span class="check"></span>santun</label>			
								<label class="checkbox"><input class='hidden radio-label' type='checkbox' name="ket1[]" value="percaya diri" /> 
								<span class="check"></span>percaya diri</label>
								<label class="checkbox"><input class='hidden radio-label' type='checkbox' name="ket1[]" value="peduli" /> 
								<span class="check"></span>peduli</label>	
								<label class="checkbox"><input class='hidden radio-label' type='checkbox' name="ket1[]" value="toleransi" /> 
								<span class="check"></span>toleransi</label>	
									
													   </div>
													</div>
									<div class="row mb-2">
							<label  class="col-md-3 bold">Mulai Meningkat</label>
							<div class="col-sm-9">
							 <select name='ket2'  class='form-select' required='true' style="width:100%;">
							 <option value=''>Pilih Sikap</option>
							  <option value='jujur'>Jujur</option>
										   <option value='disiplin'>Disiplin</option>
										    <option value='tanggung jawab'>Tanggung jawab</option>
											 <option value='santun'>Santun</option>
											  <option value='percaya diri'>Percaya diri</option>
											   <option value='peduli'>Peduli</option>
											    <option value='toleransi'>Toleransi</option>
                                                    </select>
                                                    
                                       </div>
						            </div>
									<div class="row mb-2">
									<label  class="col-md-3 bold">Predikat</label>
							<div class="col-sm-9">
							 <select name='pred' id="pred" class='form-select' required='true' style="width:100%;">
							 <option value=''>Pilih Predikat</option>
							  <option value='A'>Sangat Baik</option>
                                <option value='B'>Baik</option>
								 <option value='C'>Cukup</option>
                                                    </select>
                                                    
                                       </div>
						            </div>
									<div class="row mb-2">
									<label  class="col-md-3 bold"></label>
							<div class="col-sm-9">
							 <button type='submit' name='submit' id="blockui-2" class='btn btn-success kanan'> Simpan</button>    
							 </div>
						         </div>
								</form>
								 </div>
									</div>
										</div>
						         
							 <div class="col-md-4">
                     
                                <div class="card widget widget-payment-request">
                                    <div class="card-header">
                                   <h5 class="bold">NILAI KI-1 <span class="badge badge-secondary">  <?= $siswa['nama'] ?></span></h5>
                                    </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>
								
									</div>
								</div>	
							 </div>	
						</div>
				 <script>
		 $('#formspi').submit(function(e) {
        e.preventDefault();
        $.ajax({
            type: 'POST',
            url: 'cbtserver_rapor/crud_spi.php?pg=tambah_sos',
            data: $(this).serialize(),
            beforeSend: function() {
                $('form button').on("click", function(e) {
                    e.preventDefault();
                });
            },
            success: function(data) {
                console.log(data);
                if (data == 'OK') {
                   
                    setTimeout(function() {
                        window.location.replace('?pg=sosial&ac=input&kelas=<?= $kelas?>');
                    }, 2000);
                } else {
                    iziToast.error({
                        title: 'Gagal!',
                        message: 'Pilihan Sikap tidak Boleh Sama',
						titleColor: '#FFFF00',
						messageColor: '#fff',
						backgroundColor: 'rgba(0, 0, 0, 0.5)',
						 progressBarColor: '#FFFF00',
                        position: 'topRight'
                    });
					setTimeout(function() {
                        window.location.reload();
                    }, 2000);
                }

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