<?php if ($ac == '') { ?>


<div class="section-header">
    <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> Deskripsi Pengetahuan (KI-3)</h5>
                </div>
				
            <div class='card-body'>
                   <div class='table-responsive'>
                        <table style="font-size: 11px" id='example1' class='table table-hover'>
                            <thead>
                            <tr>
                             <th width="5%" class="text-center">
                                    #
                                </th>
                                <th width="10%">Kelas</th>
                                 <th>Nama Mapel</th>
							<th width="25%" style="text-align:center;">Action</th>
							
                            </tr>
                        </thead>
                        <tbody>
                            <?php
                            $query = mysqli_query($koneksi, "select * FROM jadwal_mapel JOIN kelas ON kelas.id_kelas=jadwal_mapel.kelas					
							WHERE guru='$_SESSION[id_user]' AND kelas.kurikulum='K-13'");
                            $no = 0;
                            while ($mapel = mysqli_fetch_array($query)) {
								$jumlah = mysqli_num_rows(mysqli_query($koneksi, "SELECT * FROM deskripsi 
								WHERE mapel='$mapel[kode]' AND kelas='$mapel[kelas]' AND smt='$setting[semester]' AND ki='KI3' "));
                                $no++;
                            ?>
                                <tr>
                                    <td><?= $no; ?></td>
									<td><?= $mapel['kelas'] ?></td>
                                    <td><?= $mapel['mapel'] ?></td>
                                  
                                    <td style="text-align:center;">
									<a href="?pg=deskrip3&ac=input&mapel=<?= $mapel['kode'] ?>&kelas=<?= $mapel['kelas'] ?>&smt=<?= $setting['semester'] ?>" class="btn btn-sm btn-outline-primary" >
                                          <i class="fas fa-plus" data-bs-placement="top" data-bs-toggle="tooltip" title="Input Manual"></i></button></a>
									<?php if($jumlah==0){ ?>
									<a href="sandik_rapor/prosesd3.php?id=<?= $mapel['id_jadwal'] ?>" class="btn btn-sm btn-outline-warning" >
                                          <i class="fas fa-download" data-bs-placement="top" data-bs-toggle="tooltip" title="Download Format"></i></button></a>
										<?php }else{ ?>
										 <button type="button" class="btn btn-sm btn-default" disabled>
                                          <i class="fas fa-lock" ></i>
                                        </button>
										<?php } ?>
                                        <?php if($jumlah==0){ ?>
                                       <a href="?pg=deskrip3&ac=upload&mapel=<?= $mapel['kode'] ?>&kelas=<?= $mapel['kelas'] ?>&smt=<?= $setting['semester'] ?>" class="btn btn-sm btn-outline-success" >
                                          <i class="fas fa-upload" data-bs-placement="top" data-bs-toggle="tooltip" title="Upload"></i></button></a>
									
										<?php }else{ ?>
										 <button type="button" class="btn btn-sm btn-default" disabled>
                                          <i class="fas fa-lock" ></i>
                                        </button>
										<?php } ?>
										  <a href="?pg=deskrip3&ac=view3&mapel=<?= $mapel['kode'] ?>&kelas=<?= $mapel['kelas'] ?>&smt=<?= $setting['semester'] ?>" class="btn btn-sm btn-outline-info" >
                                          <i class="fas fa-search" data-bs-placement="top" data-bs-toggle="tooltip" title="Lihat Hasil"></i></button></a>
									
										</td>
										   
                                </tr>
								
                            <?php }
                            ?>

                        </tbody>
                    </table>
                </div>
            </div>
			
            </div>
        </div>
    </div>
</div>
<?php } elseif ($ac == 'upload') { ?>
<div class='row'>
    <div class='col-md-12'>
        <div class="card">
             <div class="card-header">
                  <h5 class='card-title'><i class="fas fa-users-cog"></i> Import Deskripsi <?= $_GET['mapel'] ?> (KI-3)</h5>
				  </div>   
   		  
                    <div class='card-body'>
                        <div class='form-group'>
                            <div class='row'>
                                <form id='formsiswa' enctype='multipart/form-data'>
                                    <div class='col-md-4'>
                                        <label>Pilih File</label>
                                        <input type='file' name='file' class='form-control' required='true' />
                                    </div>
                                    <div class='col-md-4'>
                                        <label>&nbsp;</label><br>
                                        <button type='submit' name='submit' class='btn btn-success right'><i class='fa fa-upload'></i> Import</button>
                                    </div>
                                </form>
                            </div>
                        </div>
						<br>
						 
						
                        <?= $info ?>
                        
                        <div id='progressbox'></div>
                        <div id='hasilimport'></div>
                    </div>
                </div>
            </div>
           
        </div>
    </div>
</div>
<script>
    $('#formsiswa').on('submit', function(e) {
        e.preventDefault();
        $.ajax({
            type: 'post',
            url: 'sandik_rapor/crud_deskrip3.php',
            data: new FormData(this),
            processData: false,
            contentType: false,
            cache: false,
            beforeSend: function() {
                $('#progressbox').html('<div><img src="<?= $homeurl ?>/dist/img/animasi1.gif" style="margin-left:100px"></div>');
                $('.progress-bar').animate({
                    width: "30%"
                }, 100);
            },
            success: function(response) {
                setTimeout(function() {
                    $('.progress-bar').css({
                        width: "100%"
                    });
                    setTimeout(function() {
                        $('#hasilimport').html(response);
						});
						setTimeout(function() {
                    window.location.replace('?pg=deskrip3');
                    }, 2000);
                }, 2000);
            }
        });
    });
</script>
<?php } elseif ($ac == 'view3') { ?>
<?php
$mapel=$_GET['mapel'];
$kelas=$_GET['kelas'];
?>
<div class="section-header">
    <div class='row'>
        <div class='col-md-12'>
              <div class="card">
                       <div class="card-header">
					<h5 class='card-title'><i class="fas fa-rss"></i> Deskripsi KI-3 <?= $mapel ?> - <?= $kelas ?></h5>
                </div>
				
			  <div class="card-body">
                   <div class='table-responsive'>
                        <table style="font-size: 11px" id='example1' class='table table-hover'>
                            <thead>
                            <tr>
                             <th width="5%" class="text-center">
                                    #
                                </th>
                                <th>Deskripsi</th>
							<th width="20%">Action</th>
							
                            </tr>
                        </thead>
                        <tbody>
                            <?php
                            $query = mysqli_query($koneksi, "select * FROM deskripsi  WHERE mapel='$mapel' AND kelas='$kelas' AND smt='$setting[semester]' AND ki='KI3' ");
                            $no = 0;
                            while ($des = mysqli_fetch_array($query)) {
                                $no++;
                            ?>
                                <tr>
                                    <td><?= $no; ?></td>
                                    <td><?= $des['deskripsi'] ?></td>
                                    <td>
                                       <button type="button" class="btn btn-sm btn-outline-success" data-bs-toggle="modal" data-bs-target="#modal-des<?= $no ?>">
                                          <i class="fas fa-edit"></i>
                                        </button>
										  
									 <button data-id="<?= $des['id'] ?>" class="hapus btn-sm btn btn-outline-danger"><i class="fas fa-trash"></i></button>
										</td>
										   
                                </tr>
								
							<div class="modal fade" id="modal-des<?= $no ?>" tabindex="-1" role="dialog" aria-labelledby="modelTitleId" aria-hidden="true">
                                            <div class="modal-dialog" role="document">
                                                <div class="modal-content">
                                                    
                                                        <div class="modal-header">
                                                            <h5 class="modal-title">Edit Deskripsi</h5>
                                                            <button type="button" class="close" data-bs-dismiss="modal" aria-label="Close">
                                                                <span aria-hidden="true">&times;</span>
                                                            </button>
                                                        </div>
														<form id="form-des<?= $no ?>" >
                                                        <div class="modal-body">
                                                            <input type="hidden" value="<?= $des['id'] ?>" name="id" class="form-control" >
                                                            <div class="form-group">
                                                                <label>Deskripsi</label>
                                                                <textarea name='deskripsi' style='height:100px' class='form-control' required><?= $des['deskripsi'] ?></textarea>
                                                            </div>
                                                        <p>
													   <div class='right'>
														  <button type='submit' class='btn btn-outline-success'><i class='fa fa-check-circle'></i>Simpan</button>
														
																 </div>
                                                                </form>	
																  </div>
																	</div>
																	  </div>
                                <script>
                                    $('#form-des<?= $no ?>').submit(function(e) {
                                        e.preventDefault();
                                        $.ajax({
                                            type: 'POST',
                                            url: 'sandik_rapor/crud_deskripsi.php?pg=ubah3',
                                            data: $(this).serialize(),
                                            success: function(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.reload();
                                                    }, 2000);
                                                    $('#modal-edit<?= $no ?>').modal('hide');
                                                } else {
                                                    iziToast.error({
                                                        title: 'Maaf!',
                                                        message: 'Data Gagal diperbarui',
                                                        position: 'topRight'
                                                    });
                                                }
                                                //$('#bodyreset').load(location.href + ' #bodyreset');
                                            }
                                        });
                                        return false;
                                    });
                                </script>
                            <?php }
                            ?>


                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    $('#example1').on('click', '.hapus', function() {
       var id = $(this).data('id');
        console.log(id);
        swal({
            title: 'Are you sure?',
            text: 'Akan menghapus data ini!',
            showCancelButton: true,
			type: 'warning',
            confirmButtonColor: '#3085d6',
            cancelButtonColor: '#d33',
            confirmButtonText: 'iya, hapus'
        }).then((result) => {
            if (result.value) {
                $.ajax({
                    url: 'sandik_rapor/crud_deskripsi.php?pg=hapus3',
                    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);
                    }
                });
            }
        })

    });
   
</script>
<?php } elseif ($ac == 'input') { ?>
<div class='row'>
    <div class='col-md-5'>
         <div class="card">
             <div class="card-header">
					<h5 class='card-title'><i class="fas fa-users-cog"></i> Input Deskripsi <?= $_GET['mapel'] ?> (KI-3)</h5></div>   
						<div class="card-body">
                           <form id='menu'  method='post'>
							<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">TP</label>
							<div class="col-sm-9">
						   <input type="text" value="<?= $setting['tp']  ?>" class="form-control" readonly>
							</div>
		                    </div>
							<div class="row mb-2">
							<label  class="col-md-3 col-form-label bold">Kode Mapel</label>
							<div class="col-sm-9">
						   <input type="text" name="mapel" value="<?= $_GET['mapel']  ?>" class="form-control" readonly>
							</div>
		                    </div>
							<div class="row mb-2">
							<label  class="col-md-3 col-form-label bold">Kelas</label>
							<div class="col-sm-9">
						   <input type="text" name="kelas" value="<?= $_GET['kelas']  ?>" class="form-control" readonly>
							</div>
		                    </div>
							<div class="row mb-2">
							<label  class="col-md-3 col-form-label bold">Deskripsi</label>
							<div class="col-sm-9">
						   <textarea name="deskrip"  class="form-control" rows="5"></textarea>
							</div>
		                    </div>
							<div class="right">
					   <button type='submit' name='submit' class='btn btn-outline-primary'><i class='fa fa-check-circle' ></i>Simpan</button>
                       <a href="?pg=deskrip3" class="btn btn-outline-danger"><i class="fa fa-times-circle"></i>Back</a>           
					 </div>
					  </form>
                        </div>
					    </div>
						</div>
						<div class='col-md-7'>
					 <div class="card">
                       <div class="card-header"></div>	
                   <div class='card-body'>
                   <div class='table-responsive'>
                        <table style="font-size: 11px" id='example1' class='table  table-hover'>
                            <thead>
                            <tr>
                             <th width="5%" class="text-center">
                                    #
                                </th>
                                <th>Deskripsi</th>
							<th width="25%">Action</th>
							
                            </tr>
                        </thead>
                        <tbody>
                            <?php
                            $query = mysqli_query($koneksi, "select * FROM deskripsi  WHERE mapel='$_GET[mapel]' AND kelas='$_GET[kelas]' AND smt='$setting[semester]' AND ki='KI3' ");
                            $no = 0;
                            while ($des = mysqli_fetch_array($query)) {
                                $no++;
                            ?>
                                <tr>
                                    <td><?= $no; ?></td>
                                    <td><?= $des['deskripsi'] ?></td>
                                    <td>
                                       <button type="button" class="btn btn-sm btn-outline-success" data-bs-toggle="modal" data-bs-target="#modal-des<?= $no ?>">
                                          <i class="fas fa-edit"></i>
                                        </button>
										  
									 <button data-id="<?= $des['id'] ?>" class="hapus btn-sm btn btn-outline-danger"><i class="fas fa-trash"></i></button>
										</td>
										   
                                </tr>
								
							<div class="modal fade" id="modal-des<?= $no ?>" tabindex="-1" role="dialog" aria-labelledby="modelTitleId" aria-hidden="true">
                                            <div class="modal-dialog" role="document">
                                                <div class="modal-content">
                                                    
                                                        <div class="modal-header">
                                                            <h5 class="modal-title">Edit Deskripsi</h5>
                                                            <button type="button" class="close" data-bs-dismiss="modal" aria-label="Close">
                                                                <span aria-hidden="true">&times;</span>
                                                            </button>
                                                        </div>
														 <div class="modal-body">
														<form id="form-des<?= $no ?>" >                                                      
                                                            <input type="hidden" value="<?= $des['id'] ?>" name="id" class="form-control" >
                                                            <div class="form-group">
                                                                <label class="bold">Deskripsi</label>
                                                                <textarea name='deskripsi' style='height:100px' class='form-control' required><?= $des['deskripsi'] ?></textarea>
                                                            </div>
                                                       <p>
													   <div class='right'>
														  <button type='submit' class='btn btn-success'><i class='fa fa-check-circle'></i> Simpan</button>
															 
																 </div>
                                                                </form>	
																  </div>
																	</div>
																	  </div>
                                <script>
                                    $('#form-des<?= $no ?>').submit(function(e) {
                                         e.preventDefault();
                                         var data = new FormData(this);
                                        $.ajax({
                                            type: 'POST',
                                            url: 'sandik_rapor/crud_deskripsi.php?pg=ubah3',
                                             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 }
                            ?>


                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    $('#example1').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_deskripsi.php?pg=hapus3',
                    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);
                    }
                });
            }
        })

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