<?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
					<?php if($setting['semester']=='1'){ ?> PAS <?php }else{ ?> PAT <?php } ?> Spiritual (KI-1)</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='1'");
                            $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=sikap1&ac=input&kelas=<?= $mapel['kelas'] ?>" class="btn btn-sm btn-outline-success" >
                                          <i class="fas fa-plus-circle"></i></button></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
					<?php if($setting['semester']=='1'){ ?> PAS <?php }else{ ?> PAT <?php } ?> Spiritual (KI-1)</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>Selalu Dilakukan</th>
								<th>Mulai Berkembang</th>
								<th width="4%">Pred</th>
							<th width="15%">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)) {
							$spi=fetch($koneksi,'spiritual',['niss' =>$siswa['nis']]);
                                $no++;
                            ?>
                                <tr>
                                    <td><?= $no; ?></td>
                                    <td><?= $siswa['nis'] ?></td>
                                    <td><?= $siswa['nama'] ?></td>
									<td><?= $spi['keter'] ?> </td>
									<td><?= $spi['keter2'] ?></td>
									<td><?= $spi['pred'] ?></td>
                                     <td>
									 <?php if($spi['niss']<>''){ ?>
										<button type="button" class="btn btn-sm btn-default" disabled>
                                         <i class="fas fa-lock"></i>
                                        </button>
									 <?php }else{ ?>
									 <a href="?pg=sikap1&ac=inputspi&id=<?= $siswa['id_siswa'] ?>" class="btn btn-sm btn-outline-success" >
                                          <i class="fas fa-plus-circle" ></i></a>
									 <?php } ?>
										 <button data-id="<?= $spi['ids'] ?>" class="hapus btn-sm btn btn-outline-danger"> <i class="fas fa-times-circle"></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_spi.php?pg=hapusspi',
                    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 == '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
					<?php if($setting['semester']=='1'){ ?> PAS <?php }else{ ?> PAT <?php } ?> Spiritual (KI-1)</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">Yang Selalu dilakukan</label>
							<div class="col-sm-9">
						   <select name='ket1' class="form-select" style="width: 100%; height:36px;" required>
                             <option value=''></option>
                                <?php

                                  $edi=$koneksi->query("SELECT * FROM m_spiritual ORDER BY id ASC");
                                    while($p=mysqli_fetch_assoc($edi)){
                                            echo "<option value='$p[ket]'>$p[ket]</option>";
                                                 }
                                                    ?>
													</select>
							</div>
		                    </div>
							<div class="row mb-2">
							<label  class="col-md-3 col-form-label bold">Sedang Berkembang</label>
							<div class="col-sm-9">
						  <select name='ket2' class="form-select" style="width: 100%; height:36px;" required>
                                             <option value=''></option>
                                           <?php

                                           $edi3=$koneksi->query("SELECT * FROM m_spiritual ORDER BY id DESC");
                                            while($p3=mysqli_fetch_assoc($edi3)){
                                            echo "<option value='$p3[ket]'>$p3[ket]</option>";
                                                 }
                                                    ?>
												</select>
							</div>
		                    </div>
							<div class="row mb-2">
							<label  class="col-md-3 col-form-label bold">Predikat</label>
							<div class="col-sm-9">
							<select name='pred' class="form-select" style="width: 100%; height:36px;" required>
                                         
                                           <option value=''></option>
                                           <option value='A'>A</option>
									<option value='B'>B</option>
									<option value='C'>C</option>
									<option value='D'>D</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>
				  $('#menu').submit(function(e) {
        e.preventDefault();
        $.ajax({
            type: 'POST',
            url: 'sandik_rapor/crud_spi.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 berhasil disimpan',
				titleColor: '#FFFF00',
				messageColor: '#fff',
				backgroundColor: 'rgba(0, 0, 0, 0.5)',
			   progressBarColor: '#FFFF00',
				 position: 'topRight'
				});
                    setTimeout(function() {
                        window.location.replace('?pg=sikap1&ac=input&kelas=<?= $kelas?>');
                    }, 2000);
                } else {
                    iziToast.error({
                        title: 'Gagal!',
                        message: 'Yang sering dilakukan tidak boleh sama degan yang sedang berkembang',
                        position: 'topRight'
                    });
					setTimeout(function() {
                        window.location.reload();
                    }, 2000);
                }

            }
        });
        return false;
    });
</script>
						

<?php } ?>