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


<div class='row'>
        <div class='col-md-7'>
          <div class="card">
             <div class="card-header">
			  <h5 class='card-title'><i class="fas fa-tools"></i> Master <small>Tindakan</small></h5>
			  </div>    
			 
						<div class="card-body">
                   <div class='table-responsive'>
                        <table style="font-size: 12px" id='example1' 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%'>Action</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 style="color:blue"><b><?= $bk['tindakan'] ?></b></td>
									<td style="color:red"><b><?= $bk['minpoin'] ?></b></td>
									<td style="color:red"><b><?= $bk['maxpoin'] ?></b></td>
									<td><?= $bk['ketentuan'] ?></td>									
								   <td>	
									<a href="?pg=tindakan&ac=edit&id=<?= $bk['id'] ?>" class="btn btn-sm btn-outline-success"><i class="fas fa-edit"></i></a>								   
									
									</td>
									</tr>
									<?php } ?>
                        </tbody>
                    </table>
				
            </div>
        </div>
    </div>
</div>

<?php if ($ac == ''): ?>
  
<?php elseif($ac == 'edit'): ?>				
	<?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 () { 	
			  iziToast.info(
					{
					title: 'Sukses!',
					message: 'Data berhasil disimpan',
					titleColor: '#FFFF00',
					messageColor: '#fff',
					backgroundColor: 'rgba(0, 0, 0, 0.5)',
				    progressBarColor: '#FFFF00',
					 position: 'topRight'				  
						});
		   },100);	
					 setTimeout(function() {
                    window.location.replace('?pg=tindakan');
                }, 2000);
				</script>";
				 }
			} 
			?>		
	 <div class='col-md-5'>
            <div class="card">
             <div class="card-header">
			  <h5 class='card-title'> Edit <small>Pengaturan Tindakan</small></h5>
			   </div>														 
				<div class='card-body'>
				 <form  action=''  method='post' class="form-horizontal" enctype='multipart/form-data'>  
                    				                       						
						     <div class="form-group">
							<label class="bold">Tindakan</label>
							<div class="col-sm-9">
							  <select name='tindakan' class='form-control' 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>
							<div class="col-sm-9">
							   <input type="number" name='minpoin' value="<?= $bks['minpoin'] ?>" class='form-control'  required='true' />
                                            </div>
						            </div>
						
							 <div class="form-group">
							<label class="bold">Max Poin</label>
							<div class="col-sm-9">
							   <input type="number" name='maxpoin' value="<?= $bks['maxpoin'] ?>" class='form-control'  required='true' />
                                            </div>
						            </div>
									<p>
							 <div class='right'>
				   		 <button type='submit' name="submit"  class='btn btn-sm btn-success pull-right'><i class='fa fa-check' ></i><span> Simpan</span></button>		
							</div>
							</form>
							 </div>
						</div>
					</div>
				</div>
			</div>
<?php endif; ?>