<?php
defined('APK') or exit('Anda tidak dizinkan mengakses langsung script ini!');
?>


<?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 Catatan Proses</h5>
                </div>
				<div class='card-body'>
             <div class="alert alert-custom" role="alert">
               <div class="custom-alert-icon icon-dark"><i class="fa fa-check fa-2x"></i></div>
                 <div class="alert-content">
                  <span class="alert-text" style="text-align:justify">
                 Jika input master Proyek tiap kelas <b>belum memenuhi 3 Proyek,</b> <b style="color:red"> maka tombol input nilai tidak muncul</b>         
							 </span>
                            </div>
                                </div>
                                <div class='card-body'>
                    <div class='table-responsive'>
                        <table style="font-size: 11px" id='example1' class='table table-hover'>
                            <thead >
                                <tr>
                                    <th width='3px' class="hidden-xs">No</th>
									  <th width='5%'>Kelas</th>
									   <th width='5px'>Fase</th>
									    <th width='10%'> Proyek</th>
                                    <th>Judul Proyek</th>  
									<th>Deskripsi</th>  
                               		<th width="5%">Jml Dimensi</th>  					  
									<th width='7%'>Action</th>
										</tr>
									</thead>							
							<tbody>							
                                <?php
								$no = 0;
								
								 $query = mysqli_query($koneksi, "select * FROM m_proyek");
                            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]'"));
							$no++;
                            ?>
							 <tr>
                                    <td><?= $no; ?></td>
							        <td><?= $tjn['kelas'] ?></td>
									<td ><?= $tjn['fase'] ?></td>
									<td><b style="color:blue;"><?= $tjn['ke'] ?></b></td>
									<td ><?= $tjn['judul'] ?></td>
									<td><?= $tjn['deskripsi'] ?></td>
									<td><b style="color:blue;"><?= $dimensi ?></b></td>
                                   <td style="text-align:center">
								   <?php if($dimensi<>5): ?>
								   <button type="button" class="btn btn-sm btn-default btn-rounded" disabled>
                                          <i class="fas fa-lock" ></i></button>
								   <?php else: ?>
								   <?php if($nilai==3){ ?>
                                      <a href="?pg=catatanproses&ac=input&id=<?= $tjn['id'] ?>" class='btn btn-outline-success btn-sm' data-bs-placement="top" data-bs-toggle="tooltip" title="Pilih Proyek" ><i class="fa fa-plus-circle"></i></a>
								   <?php }else{  ?>
									<b style="color:red;">Belum 3 proyek</b>
								   <?php } ?>
								   <?php endif; ?>
                                   </td>
								  
							       </tr>
                            <?php } ?>
                        </tbody>
                        </table>
                    </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-12'>
             <div class="card">
             <div class="card-header">
                  <h5 class='card-title'><i class="fas fa-school"></i> Input Catatan Proses</h5>
				  </div>    
			 
						<div class="card-body">
						<form id="formtujuan" action=''  class="form-horizontal" >
								<input type="hidden" name="proyek" value="<?= $_GET['id'] ?>" >	
						   <div class="row mb-2">
							<label  class="col-md-3 col-form-label bold">Kelas</label>
							<div class="col-sm-9">
							<select name='kelas' class='form-select' style="width:30%;" >
                             <option value="<?= $proyek['kelas'] ?>"><?= $proyek['kelas'] ?></option>
                               
                                                </select>
                                            </div>
                                        </div>
							<div class="row mb-2">
							<label  class="col-md-3 col-form-label bold">Fase</label>
							<div class="col-sm-9">
							<select name='fase' class='form-select' style="width:30%;" >
                             <option value="<?= $proyek['fase'] ?>"><?= $proyek['fase'] ?></option>
                               
                                                </select>
                                            </div>
                                        </div>
							<div class="row mb-2">
							<label  class="col-md-3 col-form-label bold">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-2">
							<label  class="col-md-3 col-form-label bold">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-2">
							<label  class="col-md-3 col-form-label bold">Proyek</label>
							<div class="col-sm-9">
							 <select name='proyek'  class='form-select' required='true' style="width:100%;">
							 <option value="<?= $proyek['ke'] ?>"><?= $proyek['ke'] ?></option>
							  
                                
                                                    </select>
                                                    
                                       </div>
						            </div>
								<div class="row mb-2">
							<label  class="col-md-3 col-form-label bold">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,id_kelas FROM siswa 
                            WHERE id_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-2">
							<label  class="col-md-3 col-form-label bold">Catatan Proses</label>
							<div class="col-sm-9">
							 <textarea name="catatan" class="form-control" rows="4" required='true'></textarea>
                                       </div>
						            </div>
									<p>
								<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>
											
								          </div>
                                        </div>
                                    </div>
                                </div>

	<script>
	 $('#formtujuan').submit(function(e) {
        e.preventDefault();
        var data = new FormData(this);
        $.ajax({
            type: 'POST',
            url: 'sandik_proyek/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 } ?>