<?php if ($ac == '') { ?>	
<div class='row'>
        <div class='col-md-12'>
             <div class="card">
             <div class="card-header">
                  <h5 class='card-title'><i class="fas fa-graduation-cap"></i> Input Nilai Sikap PTS -
					<?php if($setting['semester']=='1'){ ?> PAS <?php }else{ ?> PAT <?php } ?> </h5>
                </div>
				
            <div class='card-body'>
                   <div class='table-responsive'>
                        <table style="font-size: 12px" id='datatable1' class='table table-hover'>
                            <thead>
                            <tr>
                             <th width="5%" class="text-center">
                                    #
                                </th>
                                <th width="5%">Kelas</th>
                                 <th>Nama Mapel</th>
								 <th width="8%">Input</th>
							
							
                            </tr>
                        </thead>
                        <tbody>
                            <?php
							$tahun=date('Y');
                            $query = mysqli_query($koneksi, "select * FROM jadwal_mapel	JOIN kelas ON kelas.id_kelas=jadwal_mapel.kelas					
							WHERE guru='$_SESSION[id_user]' AND agama='1' AND kelas.model_rapor='2'");
                            $no = 0;
                            while ($mapel = mysqli_fetch_array($query)) {
							
                                $no++;
                            ?>
                                <tr>
                                    <td><?= $no; ?></td>
									<td><?= $mapel['kelas'] ?></td>
                                    <td><?= $mapel['mapel'] ?></td>
									
									
                                    <td>
									
									<a href="?pg=sikapbaru&ac=input&kelas=<?= $mapel['kelas'] ?>" class="btn btn-sm btn-outline-success" >
                                          <i class="fas fa-edit"></i></a>
										
										</td>
										   
                                </tr>
                            <?php }
                            ?>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>

<?php } elseif ($ac == 'input') { ?>
<div class='row'>
        <div class='col-md-12'>
             <div class="card">
             <div class="card-header">
                  <h5 class='card-title'><i class="fas fa-graduation-cap"></i> Input Nilai Sikap PTS -
					<?php if($setting['semester']=='1'){ ?> PAS <?php }else{ ?> PAT <?php } ?></h5>
                </div>
				
            <div class='card-body'>
			<table id='tabelsikap' class='table table-hover'>
                            <thead>
                            <tr>
                                <th width="2%" class="text-center">
                                    #
                                </th>
                                <th width="7%">Nis</th>
                                <th>Nama Siswa</th>
								<th>Dimensi</th>
								<th>Keterangan</th>
								
							<th width="20%">Action</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php
                            $query = mysqli_query($koneksi, "select * from siswa WHERE id_kelas='$_GET[kelas]' ");
                            $no = 0;
                            while ($siswa = mysqli_fetch_array($query)) {
							$niss = mysqli_num_rows(mysqli_query($koneksi, "SELECT * FROM barusikap WHERE nis='$siswa[nis]'"));
							
                                $no++;
                            ?>
                                <tr>
                                    <td><?= $no; ?></td>
                                    <td><?= $siswa['nis'] ?></td>
                                    <td><?= $siswa['nama'] ?></td>
									<td><?= $niss ?> dimensi</td>
									<td>
									<?php if($niss==6): ?>
									<b>Lengkap</b>
									<?php else: ?>
									<b style="color:red" class="siskolah">Kurang <?= 6 - $niss ?> dimensi</b>
									<?php endif; ?>
								</td>
                                     <td>
									 <?php if($niss==6){ ?>
										<button type="button" class="btn btn-sm btn-default" disabled>
                                         <i class="fas fa-lock"></i>
                                        </button>
									 <?php }else{ ?>
									 <a href="?pg=sikapbaru&ac=inputspi&id=<?= $siswa['id_siswa'] ?>" class="btn btn-sm btn-outline-success" >
                                          <i class="fas fa-plus-circle" ></i></button></a>
									 <?php } ?>
									 <a href="?pg=sikapbaru&ac=lihat&nis=<?= $siswa['nis'] ?>" class="btn btn-sm btn-outline-primary" >
                                          <i class="fas fa-check-circle" ></i></button></a>
										</td>
										<?php
														}
														?>
															</tr>
													</tbody>
												</table>
												</div>
												   </div>
												    </div>
												      </div>
													</div>
												      </div>
                                        
		
	   <script>
  $('#tabelsikap').on('click', '.hapus', function() {
       var id = $(this).data('id');
        console.log(id);
        swal({
            title: 'Are you sure?',
            text: 'Akan menghapus data ini!',
            showCancelButton: true,
            confirmButtonColor: '#3085d6',
            cancelButtonColor: '#d33',
            confirmButtonText: 'iya, hapus'
        }).then((result) => {
            if (result.value) {
                $.ajax({
                    url: 'sandik_rapor/crud_spi.php?pg=hapusspi',
                    method: "POST",
                    data: 'id=' + id,
                    success: function(data) {
                        iziToast.success({
                            title: 'Sukses!',
                            message: 'Data Berhasil dihapus',
                            position: 'topRight'
                        });
                        setTimeout(function() {
                            window.location.reload();
                        }, 2000);
                    }
                });
            }
            return false;
        })

    });
	</script>
          
<?php } elseif ($ac == 'inputspi') { ?>

<?php 
$siswa=fetch($koneksi,'siswa',['id_siswa'=>$_GET['id']]); 
$kelas=$siswa['id_kelas'];
?>
<div class='row'>
        <div class='col-md-12'>
             <div class="card">
             <div class="card-header">
                  <h5 class='card-title'><i class="fas fa-graduation-cap fa-fw"></i> Input Nilai Sikap
					<?php if($setting['semester']=='1'){ ?> PAS <?php }else{ ?> PAT <?php } ?> </h5>
				  
				  </div>    
			 
						<div class="card-body">
                    <form id='menu'  class="form-horizontal">
					 <input type="hidden" name="id" value="<?= $siswa['nis'] ?>"> 
							<div class="row mb-2">
							<label  class="col-md-3 col-form-label bold">Semester</label>
							<div class="col-sm-5">
						   <select name="smt" id="smt" class="form-control" style="width: 100%;" readonly>
                               <option value="<?= $setting['semester']  ?>">Semester <?= $setting['semester']  ?></option>
							      
                                  </select>
							</div>
		                    </div>
							<div class="row mb-2">
							<label  class="col-md-3 col-form-label bold">N I S</label>
							<div class="col-sm-5">
						   <input type="text" name="nis" value="<?= $siswa['nis']  ?>" class="form-control" readonly>
							</div>
		                    </div>
							<div class="row mb-2">
							<label  class="col-md-3 col-form-label bold">Nama Siswa</label>
							<div class="col-sm-9">
						   <input type="text" value="<?= $siswa['nama']  ?>" class="form-control" readonly>
							</div>
		                    </div>
							<div class="row mb-2">
							<label  class="col-md-3 col-form-label bold">Dimensi</label>
							<div class="col-sm-9">
							 <select name='dimensi' id="dimensi" class='form-select' required='true' style="width:100%;">
							 <option value=''>--Pilih Dimensi--</option>
							  
                                 <?php $quem = mysqli_query($koneksi, "SELECT * FROM m_dimensi"); ?>
                                     <?php while ($m = mysqli_fetch_array($quem)) : ?>
                                         <option value="<?= $m['id_dimensi'] ?>"><?= $m['dimensi'] ?></option>
                                                <?php endwhile ?>
                                                    </select>
                                                    
                                       </div>
						            </div>
								<div class="row mb-2">
							<label  class="col-md-3 col-form-label bold">Elemen</label>
							<div class="col-sm-9">
							 <select name='elemen' id="elemen" class='form-select' required='true' style="width:100%;">
							 <option value=''>--Pilih Elemen--</option>
							  
                                </select>
								  
                                       </div>
						            </div>
								<div class="row mb-2">
							<label  class="col-md-3 col-form-label bold">Sub Elemen</label>
							<div class="col-sm-9">
							 <select name='sub_elemen' id="sub_elemen" class='form-select' required='true' style="width:100%;">
							 <option value=''>--Pilih Sub Elemen--</option>
							  
                                </select>
                                       </div>
						            </div>
								
							<div class="right">
					   <button type='submit' name='submit' class='btn btn-success'><i class='fa fa-check-circle' ></i> Simpan</button>                                  
					 </div>
					  </form>
                        </div>
					 </div>
                        </div>
					<script>
				  $("#dimensi").change(function() {
					var dimensi = $(this).val();
					console.log(dimensi);
					$.ajax({
						type: "POST", 
						url: "sandik_rapor/crud_sikapbaru.php?pg=ambil_elemen", 
						data: "dimensi=" + dimensi, 
						success: function(response) { 
							$("#elemen").html(response);
						}
					});
				});						
			</script>	
           <script>
				  $("#elemen").change(function() {
					var elemen = $(this).val();
					console.log(elemen);
					$.ajax({
						type: "POST", 
						url: "sandik_rapor/crud_sikapbaru.php?pg=ambil_sub_elemen", 
						data: "elemen=" + elemen, 
						success: function(response) { 
							$("#sub_elemen").html(response);
						}
					});
				});						
			</script>		
			
			 <script>
		 $('#menu').submit(function(e) {
        e.preventDefault();
        $.ajax({
            type: 'POST',
            url: 'sandik_rapor/crud_sikapbaru.php?pg=tambah',
            data: $(this).serialize(),
            beforeSend: function() {
                $('form button').on("click", function(e) {
                    e.preventDefault();
                });
            },
            success: function(data) {
                console.log(data);
                if (data == 'OK') {
                    iziToast.info(
            {
                title: 'Sukses!',
                message: 'Data berasil disimpan',
				titleColor: '#FFFF00',
				messageColor: '#fff',
				backgroundColor: 'rgba(0, 0, 0, 0.5)',
				 progressBarColor: '#FFFF00',
                  position: 'topRight'			  
                });
                    setTimeout(function() {
                        window.location.replace('?pg=sikapbaru&ac=input&kelas=<?= $kelas?>');
                    }, 2000);
                } else {
                    iziToast.error({
                        title: 'Gagal!',
                        message: 'Dimensi Sudah tercatat',
                        position: 'topRight'
                    });
					setTimeout(function() {
                        window.location.reload();
                    }, 2000);
                }

            }
        });
        return false;
    });
</script>
	 		
<?php } elseif ($ac == 'lihat') { ?>
<?php $siswa=fetch($koneksi,'siswa',['nis'=>$_GET['nis']]); ?>
<div class='row'>
        <div class='col-md-12'>
             <div class="card">
             <div class="card-header">									
                    <div class='right '>
					 <a href="?pg=sikapbaru&ac=input&kelas=<?= $siswa['id_kelas'] ?>" class="btn btn-sm btn-outline-danger" ><i class="fas fa-times-circle">Back</i></a>
                    </div>
					  <h5 class="card-title"><i class="fas fa-graduation-cap"></i> Input Nilai Sikap
					<?php if($setting['semester']=='1'){ ?> PAS <?php }else{ ?> PAT <?php } ?></h5>
					<h4 class='card-title text-center'><?= $siswa['nama'] ?> <br>Kelas <?= $siswa['id_kelas'] ?> NIS <?= $siswa['nis'] ?></h4>
                </div>
			
            <div class='card-body'>
			<table id='tabelsikap' class='table table-bordered table-hover'>
                            <thead>
                            <tr>
                                <th width="2%" class="text-center">
                                    #
                                </th>
								<th>Dimensi</th>
								<th>Penjelasan</th>
								
							<th width="5%">Action</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php
							$siswa=fetch($koneksi,'siswa',['nis'=>$_GET['nis']]);
                            $query = mysqli_query($koneksi, "select * from barusikap WHERE nis='$_GET[nis]' ORDER BY p_dimensi ASC");
                            $no = 0;
                            while ($sikap = mysqli_fetch_array($query)) {
							$dm=fetch($koneksi,'m_dimensi',['id_dimensi'=>$sikap['p_dimensi']]);
							$des=fetch($koneksi,'m_sub_elemen',['id_sub'=>$sikap['p_sub']]);
							$fase=$siswa['fase'];
							
							
                                $no++;
                            ?>
                                <tr>
                                    <td><?= $no; ?></td>
                                    <td><?= $dm['dimensi'] ?></td>
									<td>
									<?php if($fase=='A'){ ?>
									<?= $siswa['nama']?> <?= $des['A'] ?>
									<?php }elseif($fase=='B'){ ?>
									<?= $siswa['nama']?> <?= $des['B'] ?>
									<?php }elseif($fase=='C'){ ?>
									<?= $siswa['nama']?> <?= $des['C'] ?>
									<?php }elseif($fase=='D'){ ?>
									<?= $siswa['nama']?> <?= $des['D'] ?>
									<?php }elseif($fase=='E'){ ?>
									<?= $siswa['nama']?> <?= $des['E'] ?>
									<?php } ?>
								     </td>
                                     <td>
									 <button data-id="<?= $sikap['idp'] ?>" class="hapus btn-sm btn btn-outline-danger"><i class="fas fa-trash"></i></button>
                                  
										</td>
										<?php
														}
														?>
															</tr>
													</tbody>
												</table>
												</div>
												   </div>
												    </div>
												      </div>
													</div>
												      </div>
                                        
		
	   <script>
  $('#tabelsikap').on('click', '.hapus', function() {
       var id = $(this).data('id');
        console.log(id);
        swal({
            title: 'Are you sure?',
            text: 'Akan menghapus data ini!',
			 type: 'warning',
            showCancelButton: true,
            confirmButtonColor: '#3085d6',
            cancelButtonColor: '#d33',
            confirmButtonText: 'iya, hapus'
        }).then((result) => {
            if (result.value) {
                $.ajax({
                    url: 'sandik_rapor/crud_sikapbaru.php?pg=hapusspi',
                    method: "POST",
                    data: 'id=' + id,
                    success: function(data) {
                       iziToast.info(
            {
                title: 'Sukses!',
                message: 'Data berasil 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 } ?>