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


<div class='row'>
        <div class='col-md-8'>
          <div class="card">
             <div class="card-header">
			  <h5 class='card-title'>PENGATURAN TINDAKAN</h5>
			  </div>    
			 
						<div class="card-body">
                   <div class='table-responsive'>
                        <table  id='datatable1' class='table  table-hover'>
                            <thead>
                            <tr >                             
                             <th width='5%'>NO</th>								                                 
                              <th>TINDAKAN</th>	
							  <th width='5%'>MIN POIN</th>
							  <th width='5%'>MAX POIN</th>
								<th>KETENTUAN</th>								  
						       <th width='5%'></th>
                            </tr>							
                        </thead>
                        <tbody>
                            <?php
                            $query = mysqli_query($koneksi, "select * from bk_tindakan");
                            $no = 0;
                            while ($bk = mysqli_fetch_array($query)) {							
                                $no++;                             
                                ?>
                                <tr>
                                    <td><?= $no; ?></td>
                                    <td><h5><span class="badge badge-primary"><?= $bk['tindakan'] ?></span></h5></td>
									<td><h5><span class="badge badge-secondary"><?= $bk['minpoin'] ?></span></h5></td>
									<td><h5><span class="badge badge-danger"><?= $bk['maxpoin'] ?></span></h5></td>
									<td><?= $bk['ketentuan'] ?></td>									
								   <td>	
									<a href="?pg=tindakan&&id=<?= $bk['id'] ?>" class="btn btn-sm btn-success"><i class="material-icons">edit</i></a>								   
									
									</td>
									</tr>
									<?php } ?>
                        </tbody>
                    </table>
				
            </div>
        </div>
    </div>
</div>
	
	<?php
			$id = $_GET['id'];
            $bks = mysqli_fetch_array(mysqli_query($koneksi, "SELECT * FROM bk_tindakan WHERE id='$id'"));
			
            if (isset($_POST['submit'])) {
				$tind = $_POST['tindakan'];
				$keten = $_POST['ketentuan'];
				$min = $_POST['minpoin'];
				$max = $_POST['maxpoin'];
				 $exec = mysqli_query($koneksi, "UPDATE bk_tindakan SET tindakan='$tind',ketentuan='$keten',minpoin='$min',maxpoin='$max' WHERE id='$id'");
				 if($exec){
					 echo"
					 <script type='text/javascript'>
		           
					 setTimeout(function() {
                    window.location.replace('?pg=tindakan');
                }, 2000);
				</script>";
				 }
			} 
			?>		
	 <div class='col-md-4'>
            <div class="card">
             <div class="card-header">
			 <h5 class='card-title'>PENGATURAN TINDAKAN</h5>
			   </div>														 
				<div class='card-body'>
				 <form  action=''  method='post'  enctype='multipart/form-data'>  
                    				                       						
						     <div class="form-group">
							<label class="bold">Tindakan</label>
							  <select name='tindakan' class='form-select' required='true'>
                              <option value="<?= $bks['tindakan'] ?>"><?= $bks['tindakan'] ?></option>
							  
                                              </select> 
                                            </div>
						           
							 <div class="form-group">
							<label class="bold">Ketentuan</label>
							   <textarea name='ketentuan' class='form-control' rows="5" required='true' /><?= $bks['ketentuan'] ?></textarea>
                                            </div>
						   
							 <div class="form-group">
							<label class="bold">Min Poin</label>
							
							   <input type="number" name='minpoin' value="<?= $bks['minpoin'] ?>" class='form-control'  required='true' />
                                            </div>
						       
							 <div class="form-group">
							<label class="bold">Max Poin</label>
							   <input type="number" name='maxpoin' value="<?= $bks['maxpoin'] ?>" class='form-control'  required='true' />
                                            </div>
						         
									<p>
							 <div class='kanan'>
				   		 <button type='submit' name="submit" id="blockui-3" class='btn btn-primary'>Simpan</button>		
							</div>
							</form>
							 </div>
						</div>
					</div>
				</div>
			</div>
