<?php
defined('APK') or exit('Anda tidak dizinkan mengakses langsung script ini!');
?>
    <div class='row'>
        <div class='col-md-12'>
             <div class="card">
             <div class="card-header">
                  <h5 class='card-title'><i class="fas fa-pengawas"></i> Tata Tertib</h5></div>    
			 
						<div class="row">
						<div class='col-md-8'>
            <div class="panel panel-default">		
                <div class='card-body'>
                <div class='table-responsive'>
                    <table id='example1' style="font-size: 12px" class='table'>
                        <thead>
                            <tr>
                                <th width='5px'>#</th>
                               
                                <th>Nama</th>
                              
                                <th width="60px"></th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php $guruku = mysqli_query($koneksi, "SELECT * FROM tartib"); ?>
                            <?php while ($t = mysqli_fetch_array($guruku)) : ?>
                                <?php $no++; ?>
                                <tr>
                                    <td><?= $no ?></td>
                                    
                                    <td><?= $t['isi'] ?></td>
                                   
                                    <td style="text-align:center">
                                        <div class=''>
                                            <a href="?pg=<?= $pg ?>&ac=edit&id=<?= $t['nomor'] ?>"> <button class='btn btn-sm btn-outline-success'><i class='fa fa-edit'></i></button></a>
                                        
                                        </div>
                                    </td>
                                </tr>
                            <?php endwhile ?>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
	 
    <div class='col-md-4'>
        <?php if ($ac == '') : ?>
           
           
        <?php elseif ($ac == 'edit') : ?>
            <?php
            $id = $_GET['id'];
            $value = mysqli_fetch_array(mysqli_query($koneksi, "SELECT * FROM tartib WHERE nomor='$id'"));
            if (isset($_POST['submit'])) {
               
                $isi = $_POST['isi'];
                $isi = str_replace("'", "&#39;", $isi);
               
                        $exec = mysqli_query($koneksi, "UPDATE tartib SET isi='$isi' WHERE nomor='$id'");
                    
                (!$exec) ? $info = info("Gagal menyimpan!", "NO") : jump("?pg=$pg");
            }
            ?>
            <form action='' method='post'>
                <div class="card">
             <div class="card-header">
                        <h5 class='card-title'>Edit</h5>
                        <div class='right '>
                            <button type='submit' name='submit' class='btn btn-sm btn-outline-success'><i class='fa fa-check'></i>Simpan</button>
                            <a href='?pg=<?= $pg ?>' class='btn btn-sm btn-outline-danger'><i class='fa fa-times'></i>Back</a>
                        </div>
                    </div>
                    <div class='card-body'>
                        <?= $info ?>
                        <div class='form-group-sm'>
                            <label>Tata Tertib</label>
                            <textarea name="isi" class='form-control' rows="8" required='true' /><?= $value['isi'] ?></textarea>
                        </div>
                        
                            </div>
                        </div>
                    </div>
                </div>
            </form>
        
        <?php endif ?>
    </div>
</div>
