<?php include("conn.php");
$page='Restaurant 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-->
            <div id="accordions" class="col-sm-12 mt-2">
            <?php
              $sql1="select * from menu where itemlocation='Restaurant' ";
              $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 style="overflow: scroll;height:100vh;" 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="false" aria-modal="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="Restaurant">
                  <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='restaurant_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   w-100 table-bordered">
                        <thead >
                            
                        <tr >
                            <th>Id</th>
                            <th>Image</th>
                            <th>Category </th>
                            <th>Item Name</th>
                            <th>Description</th>
                            <th>Status</th>
                            <th>Price</th>
                            <th>Action</th>
                        </tr>
                        </thead>
                        <tbody>
                        <?php

      

$sql3="select * from menu where itemlocation='Restaurant' ";
$result3 = mysqli_query($conn,$sql3)or die( mysqli_error($conn));
while ($row3=mysqli_fetch_array($result3)) {
 $data=$row3['id'];
   $image=$row3['image'];
   $category=$row3['category'];
   $name=$row3['name'];
   $discription=$row3['discription'];
   $quantity=$row3['quantity'];
   $status=$row3['status'];
   $price=$row3['price'];
   

 $link="delete/del_blog.php?id=".urlencode(base64_encode($data));
 $edit_user="edit/edit_user.php?id=".urlencode(base64_encode($data));
 $activate="edit/user_status.php?id=".urlencode(base64_encode($data));
 $dat=$data;


 $text='';

 if ($status==='1') {
   $text='Active';
   $read='btn-success';
   $de='deactivate';
   $sta=0;
 }
                            else {
   $text='Inactive';
   $read='btn-danger';
  $de='activate';
  $sta=1;
 }

 if ($quantity<10) {
   
    $qty_color='text-danger';

  }

?>
                        <tr>
                            <td><?php echo $data ?></td>
                            <td><img style="width: 70px;" src="image/<?php echo $image ?>" alt=""></td>
                            <td><?php echo $category ?></td>
                            <td><?php echo $name ?></td>
                            <td><?php echo $discription ?></td>
                            <td> <input type="button" name="view" value="<?php echo $text ?>" id="<?php echo $row3["id"]; ?>" class="btn   <?php echo $read ?> btn-sm view_data" /></td>
                            <td ><?php echo $currency?><?php echo number_format($price)?></td>
                            <td>  <input  type="button" name="view" value="Delete" id="<?php echo $row3["id"]; ?>" class="btn  btn-danger btn-sm view_datas" />
                            <input  type="button" name="view" value="Edit" id="<?php echo $row3["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>Description</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" role="dialog" aria-labelledby="mySmallModalLabel"  data-backdrop="static" data-keyboard="false" aria-hidden="false" aria-modal="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" role="dialog" aria-labelledby="mySmallModalLabel"  data-backdrop="static" data-keyboard="false" aria-hidden="false" aria-modal="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" role="dialog" aria-labelledby="mySmallModalLabel"  data-backdrop="static" data-keyboard="false" aria-hidden="false" aria-modal="true">
  <div class="modal-dialog modal-sm">
    <div id="employee_detailse" class="modal-content text-dark">
     
    
    
    </div>
  </div>
</div>




      
       


     <!-- jQuery js-->
   <!-- jQuery Datatable js -->
  
     <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:"menu_del.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>

<script>
    google.charts.load('current', {'packages':['corechart']});
    google.charts.setOnLoadCallback(drawChart);
    
    function drawChart() {
    
    // Set Data
    const data = google.visualization.arrayToDataTable([
      ['Menu', 'Mhl'],
      ['Pizza',54.8],
      ['Burger',48.6],
      ['Local Dish',44.4],
      ['Flires',23.9],
      ['Kebab',14.5]
    ]);
    
    // Set Options
    const options = {
      title:'Menu Performance',
      is3D:true
    };
    
    // Draw
    const chart = new google.visualization.PieChart(document.getElementById('myChart'));
    chart.draw(data, options);
    
    }
    </script>

<script>
    google.charts.load('current', {'packages':['corechart']});
    google.charts.setOnLoadCallback(drawChart);
    
    function drawChart() {
    
    // Set Data
    const data = google.visualization.arrayToDataTable([
      ['Revenue', 'GHC'],
      ['Monday',5500],
      ['Tuesday',4900],
      ['Wednesday',4400],
      ['Thursday',2400],
      ['Friday',1500]
    ]);
    
    // Set Options
    const options = {
      title:'Daily  Revenue'
    };
    
    // Draw
    const chart = new google.visualization.BarChart(document.getElementById('myChart2'));
    chart.draw(data, options);
    
    }
    </script>

</body>

</html>