<?php include("conn.php");
$page='Bar Menu Management';?>
<!DOCTYPE html>
<html lang="en">
<?php include("common/head.php")?>
<body>

    <?php include("common/menu.php")?>
<!---side nav bar end-->
<?php include("common/tittle.php")?>
            <!--Main body Start-->
           
            <!--Nav menu end-->
            <!--Main body Start-->
            <div style="overflow:scroll; height:100vh;" id="accordions" class="col-sm-12 mt-1">
            <?php
              $sql1="select * from menu where itemlocation='Bar' ";
              $result1 = mysqli_query($conn,$sql1)or die( mysqli_error($conn));
               $total_menu = mysqli_num_rows($result1) ;
              ?>

      <hr class="bg-success">
                <!--search section end-->
                <!--Orders start-->

                <!--order-items-->
                <!--order-items-one-->
               <div  id="collapseOne" class="  col-sm-12  " data-parent="#accordions">         
                    <h5 class="text-center">Menu Management</h5>
                    <!-- Button trigger modal -->
<button type="button" class="btn btn-primary m-2 btn-sm" data-toggle="modal" data-target="#exampleModal">
   Add Menu
  </button>
  
 <!-- Modal -->
 <div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
    <div class="modal-dialog" role="document">
      <div class="modal-content">
        <div class="modal-header">
          <h5 class="modal-title text-center text-dark" id="exampleModalLabel">Add menu</h5>
          <button type="button" class="close" data-dismiss="modal" aria-label="Close">
            <span aria-hidden="true">&times;</span>
          </button>
        </div>
        <div class="modal-body">
            <form  method="post" enctype="multipart/form-data" class="text-dark">
                <div class="form-group">
                  <label for="exampleFormControlInput1">Menu Name</label>
                  <input type="text" name="name" class="form-control" id="exampleFormControlInput1" placeholder="Enter menu name" required>
                </div>
                <div class="form-group">
                    <label class="form-label" for="form6Example2">Item Image</label>
                    <input type="file" class="form-control-file border" name="image">
                </div> 
                
                <div class="form-group">
                  <label for="exampleFormControlSelect1">Menu Category</label>
                 
                  <select name="cat" class="form-control" id="exampleFormControlSelect1">
                  <option value="nan">Select</option>
        
                     <option>Local Dish</option>
                     <option>American Classics</option>
                     <option>Italian</option>
                     <option>General</option>
                  </select>
                </div>

                <div class="form-group">
                  <label for="exampleFormControlSelect1">Meal type</label>
                  <select name="meal_type" class="form-control" id="exampleFormControlSelect1">
                  <option value="nan">Select</option>
                  <option value="Breakfast">Breakfast</option>
                  <option value="Lunch">Lunch</option>
                  <option value="Dinner">Dinner</option>
                  <option value="Snack">Snack</option>
                  </select>
                </div>
                <div class="form-group">
                    <label for="exampleFormControlInput1">Menu Discription</label>
                    <input type="text" name="dis" class="form-control" id="exampleFormControlInput1" placeholder="Discription" >
                  </div>

                  <div class="form-group">
                    <label for="exampleFormControlInput1">Quantity</label>
                    <input type="number" name="qty" class="form-control" id="exampleFormControlInput1" placeholder="Input number" >
                  </div>

                  <div class="form-group">
                    <label for="exampleFormControlInput1">Menu Price</label>
                    <input type="number" name="price" class="form-control" id="exampleFormControlInput1" placeholder="Enter Price" required>
                  </div>



                  <input type="hidden" name="location" value="Bar">
                  <input type="hidden" name="by" value="<?php echo $id_user ?>">
                  <input type="hidden" name="date" value="<?php echo date("F j, Y") ?>">
                  <button type="submit"  name="submit" class="btn btn-primary btn-sm">Submit</button>
              </form>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
  
        </div>
      </div>
    </div>
  </div>


  <?php 


include('conn.php');


if(isset($_POST['submit'])){

  $filename = $_FILES['image']['name'];
  $name=addslashes($_POST['name']);
   $dis=$_POST['dis'];
  $cat=$_POST['cat'];
  $meal_type=$_POST['meal_type'];
   $qty=$_POST['qty'];
  $price=addslashes($_POST['price']);
  $location=$_POST['location'];
  $date=$_POST['date'];
  $by=$_POST['by'];



// Select file type
$imageFileType = strtolower(pathinfo($filename,PATHINFO_EXTENSION));

// valid file extensions
$extensions_arr = array("jpg","jpeg","png");

// Check extension
if( in_array($imageFileType,$extensions_arr) ){

// Upload files and store in database
if(move_uploaded_file($_FILES["image"]["tmp_name"],'image/'.$filename)){
  // Image db insert sql
  $sql = "INSERT INTO `menu`(`image`, `category`,`meal_type`, `name`, `discription`, `quantity`,`price`, `itemlocation`, `uploadby`, `date`) VALUES ('$filename','$cat','$meal_type','$name','$dis','$qty','$price','$location','$by','$date')";
  if(mysqli_query($conn,$sql)){
    echo"<script>alert('You Have Successfully added a new Itme'); window.location='bar_menu.php'</script>";
  }
  else{
    echo 'Error: '.mysqli_error($conn);
  }
}else{
  echo 'Error in uploading file - '.$_FILES['image']['name'].'<br/>';
}
	}
} 

?>






  <table id="example_table" class="table-customer table-striped table-hover  w-100 table-bordered">
                        <thead>
                            
                        <tr>
                            <th>id</th>
                            <th>Image</th>
                            <th>Category </th>
                            <th>Name</th>
                            <th>Qty added</th>
                            <th>Qty sold</th>
                            <th>Qty remaining</th>
                            <th>Status</th>
                            <th>Price</th>
                            <th>Action</th>
                        </tr>
                        </thead>
                        <tbody>
                        <?php

      

$sql="select * from menu where itemlocation='Bar' order by id desc";
$result = mysqli_query($conn,$sql)or die( mysqli_error($conn));
while ($row=mysqli_fetch_array($result)) {




 $data=$row['id'];
   $image=$row['image'];
   $category=$row['category'];
   $name=$row['name'];
   $discription=$row['discription'];
   $status=$row['status'];
   $price=$row['price'];
   
 


 $link="menu_edit.php?id=".urlencode(base64_encode($data));
 $edit_user="edit/edit_user.php?id=".urlencode(base64_encode($data));
 $update="edit/add_item.php?id=".urlencode(base64_encode($data));
 $dat=$data;


 $text='';





  include('item_data.php');

?>
                        <tr>
                            <td><?php echo $data ?></td>
                            <td><img style="width: 40px;" src="image/<?php echo $image ?>" alt="<?php echo $image ?>"></td>
                            <td><?php echo $category ?></td>
                            <td><?php echo $name ?></td>
                            <td><?php echo $qty ?></td>
                            <td class=""><?php echo $rqty ?></td>
                            <td class=" <?php echo $qty_color ?>"><?php echo $total_remaining_item ?></td>
                            <td> <input type="button" name="view" value="<?php echo $text ?>" id="<?php echo $row["id"]; ?>" class="btn   <?php echo $read ?> btn-sm " /></td>
                            <td ><?php echo $currency?><?php echo number_format($price)?></td>
                            <td>
  
                            <input  type="button" name="view" value="Add" id="<?php echo $row["id"]; ?>" class="btn  btn-primary btn-sm view_datas" />
                            <input  type="button" name="view" value="Edit" id="<?php echo $row["id"]; ?>" class="btn  btn-success btn-sm view_datase" />
                          </td>
                        </tr>
                        <?php } ?>
                        <thead>
                        <th>Id</th>
                            <th>Image</th>
                            <th>Category </th>
                            <th>Name</th>
                            <th>Qty added</th>
                            <th>Qty sold</th>
                            <th>Qty remaining</th>
                            <th>Status</th>
                            <th>Price</th>
                            <th>Action</th>
                            </thead>
                    </tbody>
                    </table>
    

                </div>

        


       

         
                <!--Order end-->
            </div>
            <!--Main body end-->

            <!--Customer massaging section-->
    
              

                

          

<!-- Small modal -->
<div id="dataModal"  class="modal fade bd-example-modal-sm" tabindex="-1" data-backdrop="static" data-keyboard="false" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true">
  <div class="modal-dialog modal-sm">
    <div id="employee_detail" class="modal-content text-dark">
     
    
    
    </div>
  </div>
</div>

<!-- Small modal -->
<div id="dataModals"  class="modal fade bd-example-modal-sm" tabindex="-1" data-backdrop="static" data-keyboard="false" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true">
  <div class="modal-dialog modal-sm">
    <div id="employee_details" class="modal-content text-dark">
     
    
    
    </div>
  </div>
</div>




      <!-- Small modal -->
<div id="dataModalse"  class="modal fade bd-example-modal-sm" tabindex="-1" data-backdrop="static" data-keyboard="false" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true">
  <div class="modal-dialog modal-sm">
    <div id="employee_detailse" class="modal-content text-dark">
     
    
    
    </div>
  </div>
</div>

       

   
    
  
  <!--  isotope plugin cdn  -->
  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.isotope/3.0.6/isotope.pkgd.min.js" integrity="sha256-CBrpuqrMhXwcLLUd5tvQ4euBHCdh7wGlDfNz8vbu/iI=" crossorigin="anonymous"></script>
    <script src="js/script.js"></script>
    <!--  isotope plugin cdn  -->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.isotope/3.0.6/isotope.pkgd.min.js" integrity="sha256-CBrpuqrMhXwcLLUd5tvQ4euBHCdh7wGlDfNz8vbu/iI=" crossorigin="anonymous"></script>
    <script src="js/script.js"></script>
     <!-- jQuery js-->
   <!-- jQuery Datatable js -->
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" ></script>
     <script src="https://cdn.datatables.net/2.0.5/js/dataTables.js"></script>
     <script src="https://cdn.datatables.net/buttons/3.0.2/js/dataTables.buttons.js"></script>
     <script src="https://cdn.datatables.net/buttons/3.0.2/js/buttons.dataTables.js"></script>
     <script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.10.1/jszip.min.js"></script>
     <script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.2.7/pdfmake.min.js"></script>
     <script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.2.7/vfs_fonts.js"></script>
     <script src="https://cdn.datatables.net/buttons/3.0.2/js/buttons.html5.min.js"></script>
     <script src="https://cdn.datatables.net/buttons/3.0.2/js/buttons.print.min.js"></script>

     <script>
      $(document).ready( function () {
        new DataTable('#example_table', {
            order:[[2,"asc"]],
            autoFill: true,
            pageLength : 100,
    lengthMenu: [[5, 10, 20, -1], [5, 10, 20, 'Todos']],
    layout: {
        topStart: {
            buttons: ['copy', 'csv', 'excel', 'pdf', 'print']
        }
    }
});
       } );
</script>
<script>
         $(document).ready(function(){  
      $('.view_data').click(function(){  
           var employee_id = $(this).attr("id");  
           $.ajax({  
                url:"menu_status.php",  
                method:"post",  
                data:{employee_id:employee_id},  
                success:function(data){  
                     $('#employee_detail').html(data);  
                     $('#dataModal').modal("show");  
                }  
           });  
      });  
 });  
     </script>

<script>
         $(document).ready(function(){  
      $('.view_datas').click(function(){  
           var employee_ids = $(this).attr("id");  
           $.ajax({  
                url:"bar_menu_add.php",  
                method:"post",  
                data:{employee_ids:employee_ids},  
                success:function(data){  
                     $('#employee_details').html(data);  
                     $('#dataModals').modal("show");  
                }  
           });  
      });  
 });  
     </script>

<script>
         $(document).ready(function(){  
      $('.view_datase').click(function(){  
           var employee_idse = $(this).attr("id");  
           $.ajax({  
                url:"menu_edit.php",  
                method:"post",  
                data:{employee_idse:employee_idse},  
                success:function(data){  
                     $('#employee_detailse').html(data);  
                     $('#dataModalse').modal("show");  
                }  
           });  
      });  
 });  
     </script>

</body>

</html>