<?php include 'koneksi.php'; ?>
<?php include 'common/header.php'; ?>

<h3><span class="glyphicon glyphicon-shopping-cart"></span>  Daftar Menu </h3>
<button style="margin-bottom:20px" data-toggle="modal" data-target="#myModal" class="btn btn-warning col-md-2"><span class="glyphicon glyphicon-plus"></span>Tambah Menu</button>
<br/>
<br/>

<?php
$per_hal = 10;
$jumlah_record = mysqli_query($GLOBALS["___mysqli_ston"], "SELECT * from menu");
$jum = mysqli_num_rows($jumlah_record);
$halaman = ceil($jum / $per_hal);
$page = (isset($_GET['page'])) ? (int) $_GET['page'] : 1;
$start = ($page - 1) * $per_hal;
?>
<div class="col-md-12">
    <table class="col-md-2">
        <tr>
            <td>Jumlah Record</td>		
            <td><?php echo $jum; ?></td>
        </tr>
        <tr>
            <td>Jumlah Halaman</td>	
            <td><?php echo $halaman; ?></td>
        </tr>
    </table>
</div>
<form action="cari.php" method="get">
    <div class="input-group col-md-5 col-md-offset-7">
        <span class="input-group-addon" id="basic-addon1"><span class="glyphicon glyphicon-search"></span></span>
        <input type="text" class="form-control" placeholder="Cari menu di sini .." aria-describedby="basic-addon1" name="cari">	
    </div>
</form>
<br/>
<table class="table table-hover">
    <tr>
        <th class="col-md-1">No</th>
        <th class="col-md-3">Gambar</th>
        <th class="col-md-2">Nama Barang</th>
        <th class="col-md-2">Harga</th>
        <th class="col-md-2"> Kategori </th>
        <!-- <th class="col-md-1">Sisa</th>		 -->
        <th class="col-md-3">Opsi</th>
    </tr>
    <?php
    if (isset($_GET['cari'])) {
        $cari = mysqli_real_escape_string($GLOBALS["___mysqli_ston"], $_GET['cari']);
        $menu = mysqli_query($GLOBALS["___mysqli_ston"], "select * from menu where nama like '$cari' or kategori_id like '$cari'");
    } else {
        $menu = mysqli_query($GLOBALS["___mysqli_ston"], "select * from menu limit $start, $per_hal");
    }
    $no = 1;
    while ($b = mysqli_fetch_array($menu)) {
        ?>
        <tr>
            <td><?php echo $no++ ?></td>
            <td> 
                <img class="img-responsive" src="picture/<?php echo $b['gambar']; ?>" width="150" height="100">
            </td>
            <td><?php echo $b['nama'] ?></td>
            <td>Rp.<?php echo number_format($b['harga']) ?>,-</td>
            <td><?php
                if ($b['kategori_id'] == 1) {
                    echo 'Makanan';
                } else if ($b['kategori_id'] == 2) {
                    echo 'Minuman';
                }
                ?>
            </td>
            <td>
                <a href="edit.php?id=<?php echo $b['id_menu']; ?>" class="btn btn-info"><span class="glyphicon glyphicon-edit"></span></a>
                <a onclick="if (confirm('Apakah anda yakin ingin menghapus data ini ??')) {
                            location.href = 'delete.php?id=<?php echo $b['id_menu']; ?>'
                        }" class="btn btn-danger"><span class="glyphicon glyphicon-remove"></span></a>
            </td>
        </tr>		
        <?php
    }
    ?>

</table>
<ul class="pagination">			
    <?php
    for ($x = 1; $x <= $halaman; $x++) {
        ?>
        <li><a href="?page=<?php echo $x ?>"><?php echo $x ?></a></li>
        <?php
    }
    ?>						
</ul>
<!-- modal input -->
<div id="myModal" class="modal fade">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">Tambah Menu</h4>
            </div>
            <div class="modal-body">
                <form action="tambah_proses.php" method="post" enctype="multipart/form-data">


                    <div class="form-group">
                        <label> Gambar </label>
                        <input type="file" name="gambar" class="form-control">
                    </div>   

                    <div class="form-group">
                        <label>Nama</label>
                        <input name="nama" type="text" class="form-control" placeholder="Nama Menu .."/>
                    </div>

                    <div class="form-group">
                        <label>Harga</label>
                        <input name="harga" type="text" class="form-control" placeholder="Harga Jual per porsi"/>
                    </div>
                    <div class="form-groups">
                        <label>Kategori</label>
                        <input name="kategori" type="radio" value="1"> Makanan
                        <input name="kategori" type="radio" value="2"> Minuman
                    </div>

            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Batal</button>
                <input type="submit" class="btn btn-primary" value="Simpan">
            </div>
            </form>
        </div>
    </div>
</div>

<?php
include 'common/footer.php';
?>