<?php
defined('APK') or exit('Anda tidak dizinkan mengakses langsung script ini!');
if (empty($_GET['kelas'])) {
        $kelas = "";
    } else {
        $kelas = $_GET['kelas'];
    }
$jumsiswa = mysqli_num_rows(mysqli_query($koneksi, "SELECT * FROM siswa WHERE kelas='$kelas'"));
?>


<?php if ($ac == '') { ?>
  <div class="row">
  <div class="col-md-8">
      <div class="card">
         <div class="card-header">
         <h5 class="card-title">CATATAN PROSES <?= $kelas ?></h5>
			<a href="projek" class="btn btn-light pull-right">BACK</a>							
           </div>
             <div class="card-body">
                    <div class='table-responsive'>
                        <table style="font-size: 13px" id='datatable1' class='table table-hover'>
                            <thead >
                                <tr>
                                    <th width='3px' class="hidden-xs">No</th>
									    <th> Proyek</th>
                                    <th>Judul Proyek</th>  
									
                               		<th width="5%">Jml Dimensi</th> 
                                    <th>Sdh Dinilai</th>  
									<th>Blm Dinilai</th>  									
									<th width='7%'>Action</th>
										</tr>
									</thead>							
							<tbody>							
                                <?php
								$no = 0;
								
								 $query = mysqli_query($koneksi, "select * FROM m_proyek WHERE kelas='$kelas'");
                            while ($tjn = mysqli_fetch_array($query)) {
							$nilai = mysqli_num_rows(mysqli_query($koneksi, "SELECT * FROM m_proyek WHERE kelas='$tjn[kelas]'"));
                            $dimensi = mysqli_num_rows(mysqli_query($koneksi, "SELECT * FROM proyek WHERE kelas='$tjn[kelas]' AND p_proyek='$tjn[id]'"));
							$isi = mysqli_num_rows(mysqli_query($koneksi, "SELECT * FROM nilai_proses WHERE kelas='$kelas' AND proyek_ke='$tjn[ke]' GROUP BY idsiswa"));
                           $belum = $jumsiswa - $isi;
							$no++;
                            ?>
							 <tr>
                                    <td><?= $no; ?></td>
									<td><h5><span class="badge badge-danger"><?= $tjn['ke'] ?></span></h5></td>
									<td ><?= $tjn['judul'] ?></td>
									
									<td><h5><span class="badge badge-dark"><?= $dimensi ?></span></h5></b></td>
									<td><h5><span class="badge badge-primary"><?= $isi; ?></span></h5> siswa</td>
									<td><h5><span class="badge badge-secondary"><?= $belum; ?></span></h5> siswa</td>
                                   <td style="text-align:center">
								   <?php if($dimensi<>5): ?>
								   <button type="button" class="btn btn-sm btn-secondary" disabled>
                                          <i class="material-icons" >lock</i></button>
								   <?php else: ?>
								   
                                      <a href="?pg=catatanproses&ac=input&id=<?= $tjn['id'] ?>" class='btn btn-success btn-sm' data-bs-placement="top" data-bs-toggle="tooltip" title="Pilih Proyek" ><i class="material-icons">add</i></a>
								   
								   <?php endif; ?>
                                   </td>
								  
							       </tr>
                            <?php } ?>
                        </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>
										 CATATAN PROSES
									</button>
											</div>
								
                               <div class="col-md-12">
								<label class="form-label bold">Rombel</label>
								<select name="kelas" class='form-select kelas' required='true' style="width: 100%">
								    
                                       <?php
										if($user['level']=='admin'):
											$query = mysqli_query($koneksi, "SELECT * FROM kelas WHERE kurikulum='K-Merdeka'");
											echo "<option value=''>Pilih Rombel</option>";											
											else:
											$query = mysqli_query($koneksi, "SELECT * FROM kelas WHERE kelas='$user[walas]' AND kurikulum='K-Merdeka'"); 	
										  endif;
										while ($tkt = mysqli_fetch_array($query)) {										
										echo "<option value='$tkt[kelas]'>$tkt[kelas]</option>";
													}
													?>						
									 </select>
							     </div>	
							
									  <p>
									  
								           <div class="d-grid gap-2">
                                           <button id="cari" class="btn btn-primary">SIMPAN</button>
                            <script type="text/javascript">
                                $('#cari').click(function() {
                                    var kelas = $('.kelas').val();
                                   
                                    location.replace("?pg=catatanproses&kelas=" + kelas);
                                }); 
                            </script>
                                            </div>
									    
										</div>
									 </div>
					            </div>
								</div>
							</div>
						</div>
					</div>
				</div>
	<?php } elseif ($ac == 'input') { ?>
	
<?php
$id=$_GET['id'];
$proyek=fetch($koneksi,'m_proyek',['id'=>$id]);
?>
<div class="row">
  <div class="col-md-1"></div>
  <div class="col-md-10">
      <div class="card">
         <div class="card-header">
         <h5 class="card-title">CATATAN PROSES <?= $kelas ?></h5>
										
           </div>
             <div class="card-body">
						<form id="formtujuan" class="form-horizontal" action=''  class="form-horizontal" >
								<input type="hidden" name="proyek" value="<?= $_GET['id'] ?>" >	
						    <div class="row mb-3">
							<label  class="col-sm-3 control-label">Kelas</label>
							<div class="col-sm-9">
							<select name='kelas' class='form-control' style="width:30%;" >
                             <option value="<?= $proyek['kelas'] ?>"><?= $proyek['kelas'] ?></option>
                               
                                                </select>
                                            </div>
                                        </div>
							 <div class="row mb-3">
							<label  class="col-sm-3 control-label">Fase</label>
							<div class="col-sm-9">
							<select name='fase' class='form-control' style="width:30%;" >
                             <option value="<?= $proyek['fase'] ?>"><?= $proyek['fase'] ?></option>
                               
                                                </select>
                                            </div>
                                        </div>
							 <div class="row mb-3">
							<label  class="col-sm-3 control-label">Judul</label>
							<div class="col-sm-9">
							    <input type='text' name='judul' value="<?= $proyek['judul'] ?>" class='form-control' style="width:100%;" readonly />
                                            </div>
						            </div>
							 <div class="row mb-3">
							<label  class="col-sm-3 control-label">Deskripsi</label>
							<div class="col-sm-9">
							    <input type='text' name='deskripsi' value="<?= $proyek['deskripsi'] ?>" class='form-control' style="width:100%;" readonly />
                                            </div>
						            </div>	
							
							 <div class="row mb-3">
							<label  class="col-sm-3 control-label">Proyek</label>
							<div class="col-sm-9">
							 <select name='proyek'  class='form-control' required='true' style="width:100%;">
							 <option value="<?= $proyek['ke'] ?>"><?= $proyek['ke'] ?></option>
							  
                                
                                                    </select>
                                                    
                                       </div>
						            </div>
								 <div class="row mb-3">
							<label  class="col-sm-3 control-label">Nama Siswa</label>
							<div class="col-sm-9">
							 <select name='ids'  class='form-select' required='true' style="width:100%;">
							 <option value=''>--Pilih Siswa--</option>
							  <?php $query = mysqli_query($koneksi, "select id_siswa,nama,kelas FROM siswa 
                            WHERE kelas='$proyek[kelas]' AND NOT EXISTS 
							(SELECT * 
							 FROM nilai_proses 
							 WHERE siswa.id_siswa = nilai_proses.idsiswa AND nilai_proses.proyek_ke='$proyek[ke]')"); ?>
                                     <?php while ($m = mysqli_fetch_array($query)) : ?>
                                         <option value="<?= $m['id_siswa'] ?>"><?= $m['nama'] ?></option>
                                                <?php endwhile ?>
                                                    </select>
                                       </div>
						            </div>
								 <div class="row mb-3">
							<label  class="col-sm-3 control-label">Catatan Proses</label>
							<div class="col-sm-9">
							 <textarea name="catatan" class="form-control" rows="4" required='true'></textarea>
                                       </div>
						            </div>
									 <div class="kanan">
							
					   <button type='submit' name='submit' class='btn btn-success kanan'><i class='fa fa-check-circle' ></i> Simpan</button>                                  
					 </div>
									    </form>
								            </div>
											</div>
											</div>
											
								          </div>
                                        </div>
                                    </div>
                                </div>

	<script>
	 $('#formtujuan').submit(function(e) {
        e.preventDefault();
        var data = new FormData(this);
        $.ajax({
            type: 'POST',
            url: 'cbtserver_projek/crud_proyek.php?pg=tambah_catatan',
            enctype: 'multipart/form-data',
            data: data,
            cache: false,
            contentType: false,
            processData: false,
            success: function(data) {
                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.reload();
                }, 2000);

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