<?php include("inc_header.php") ?>

<?php include ("dbconnect.php")?>
<?php
session_start();

//if(!isset($_SESSION['user']))
//{
//	header("Location: index.php");
//}

//$res=mysqli_query($con,"SELECT * FROM users WHERE user_id=".$_SESSION['user']);
//$userRow=mysqli_fetch_array($res);
//$saleslogin=$userRow['username'];
//$sales=$userRow['username'];
//$sukses = "";
//$katakunci = (isset($_GET['katakunci'])) ? $_GET['katakunci'] : "";


//$tp=mysqli_query($con,"SELECT * FROM stokopnameada2");
//$datatp=mysqli_fetch_array($tp);
//$tglposting=$datatp['tglposting'];


//$npl=$_SESSION['nomorpl'] ;


$friendname = (isset($_GET['friendname'])) ? $_GET['friendname'] : "";



?>
<title>Food Menu</title>
<p>
<h3>Please choose 1 food ...</h3>


<meta name="viewport" content ="width=device-width,initial-scale=1,user-scalable=yes" />
<p>
    <a href="index.php">
        <input type="button" class="btn btn-primary" value="Back" />
    </a>
</p>
<?php
if ($sukses) {
?>
    <div class="alert alert-primary" role="alert">
        <?php echo $sukses ?>
    </div>
<?php
}
?>
<form class="row g-3" method="get">
<div class="input-group">
    <input type="text" class="form-control" name="friendname" value="<?php echo $friendname; ?>"/></td>

   
    </div>
 <br>
just click the pic to choose   
    <div class="col-auto">
        <input type="text" class="form-control" placeholder="Food" name="katakunci" value="<?php echo $katakunci ?>" hidden/>
    </div>
    <div class="col-auto">
        <input type="submit" name="cari" value="Cari" class="btn btn-secondary" hidden/>
    </div>

    <p> 
    
 </p>   
</form>
<table class="table table-striped">
    <thead>
        <tr>
            <th class="col-1">#</th>
            <th>Code</th>
            <th>Food</th>
            <th>Images</th>
            

  
            
            
        </tr>
    </thead>
    <tbody>
        <?php
$sqltambahan = "";
$per_halaman = 20;

$sqltambahan    = " where jenis='FOOD' AND nama like '%" . $katakunci. "%' ";

$sql1   = "select * from tblMenu $sqltambahan";
$page   = isset($_GET['page'])?(int)$_GET['page']:1;
$mulai  = ($page > 1) ? ($page * $per_halaman) - $per_halaman : 0;
$q1     = mysqli_query($con,$sql1);
$total  = mysqli_num_rows($q1);
$pages  = ceil($total / $per_halaman);
$nomor  = $mulai + 1;
$sql1   = $sql1." order by nama asc limit $mulai,$per_halaman";

$q1     = mysqli_query($con, $sql1);
if(isset($_GET['page'])) {
    $halamanAktif = $_GET['page'];
}else {
    $halamanAktif = 1;

}

$jumlahlink = 2;
if ($halamanAktif>$jumlahlink){
$start_number = $halamanAktif-$jumlahlink;
} else {
   $start_number=1; 
}

if ($halamanAktif< ( $pages-$jumlahlink )){
    $end_number=$halamanAktif+$jumlahlink;
    //$start_number=

} else {
    $end_number=$pages;    
}

        while ($r1 = mysqli_fetch_array($q1)) {
        ?>
            <tr>
                <td><?php echo $nomor++ ?></td>
                <td><?php echo $r1['kode'] ?></td>
                <td><?php echo $r1['nama'] ?></td>
                <td><img src="images/food/<?php echo $r1['imagefile']?>" style="width:200px;height:200px;" /></td></tr>
               
                

     
                
 


                
            </tr>
        <?php
        }
        ?>

    </tbody>
</table>
<nav aria-label="Page navigation example">
    <ul class="pagination">

        <?php if ($halamanAktif>1) : ?>
            <li class="page-item">
                <a class="page-link" href="food_menu.php?katakunci=<?php echo $katakunci?>&friendname=<?php echo $friendname?>&cari=<?php echo $cari?>&page=<?php echo $halamanAktif-1 ?>" style="color:black" > 
            &laquo; </a>
        <?php endif; ?>


        <?php 
        $cari = isset($_GET['cari'])? $_GET['cari'] : "";
        for($i=$start_number; $i <= $end_number; $i++){
        
        //for($i=1; $i <= $pages; $i++){
            ?>
            <?php if($halamanAktif==$i): ?>
            <li class="page-item">
                <a class="page-link" href="food_menu.php?katakunci=<?php echo $katakunci?>&friendname=<?php echo $friendname?>&cari=<?php echo $cari?>&page=<?php echo $i ?>" style="color:red" ><?php echo $i ?> </a>
            </li>
            <?php else : ?>

                <li class="page-item">
                <a class="page-link" href="food_menu.php?katakunci=<?php echo $katakunci?>&friendname=<?php echo $friendname?>&cari=<?php echo $cari?>&page=<?php echo $i ?>"><?php echo $i ?></a>
            </li>
            <?php endif; ?>
            <?php
        }
        ?>
        <?php if ($halamanAktif<$pages) : ?>
            <li class="page-item">
                <a class="page-link" href="food_menu.php?katakunci=<?php echo $katakunci?>&friendname=<?php echo $friendname?>&cari=<?php echo $cari?>&page=<?php echo $halamanAktif+1 ?>" style="color:black" > 
            &raquo; </a>
        <?php endif; ?>

    </ul>
</nav>

