<?php include('../conn.php');
if (isset($_GET['id'])) {
$id=mysqli_real_escape_string($conn, $_GET['id']);
$id2=base64_decode($id); }
?>
<?php include("../common/head.php");?>


  
  <!-- Modal -->
                  <?php 
$sql = "SELECT * FROM menu WHERE id='$id2' ";
$result=mysqli_query($conn,$sql);
    $row=mysqli_fetch_array($result);
        $name=$row['name'];
        $id=$row['id'];
          $status=$row['status'];
          $price=$row['price'];
          $itemlocation=$row['itemlocation'];
          $text='';
?>
    <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 Item</h5>
          <a href="../bar" class="close" data-dismiss="modal" aria-label="Close">
            <span aria-hidden="true">&times;</span>
          </a>
        </div>
        <div class="modal-body">


     
            <form  method="post" action="#"  class="text-dark">
                <div class="form-group">
                  <label for="exampleFormControlInput1">Item Name</label>
                  <input type="text"  class="form-control" id="exampleFormControlInput1" value="<?php echo $name?>" disabled>
				  <input type="hidden" name="name" class="form-control" id="exampleFormControlInput1" value="<?php echo $name?>" >
                </div> 
               
                

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


                  <input type="hidden" name="location" value="<?php echo $itemlocation ?>">
                  <input type="hidden" name="id" value="<?php echo $id ?>">
                  <input type="hidden" name="by" value="<?php echo $id_user ?>">
            	      <input type="hidden" name="date" value="<?php echo date("F j, Y") ?>">
                    <input type="hidden" name="time" value="<?php echo date("h:ia") ?>">
                  <button type="submit"  name="submit" class="btn btn-primary btn-sm">Submit</button>
              </form>
        </div>
        <div class="modal-footer">
          <a href="../bar" class="btn btn-secondary" data-dismiss="modal">Close</a>
  
        </div>
      </div>
    </div>

	<?php
	
	if(isset($_POST['submit'])){

		
		$name=$_POST['name'];
		 $qty=$_POST['qty'];
		$id=$_POST['id'];
		$location=$_POST['location'];
		$date=$_POST['date'];
    $time=$_POST['time'];
		$by=$_POST['by'];
	
	
	
		
			// Image db insert sql
			$sql = "INSERT INTO `bar_inventory`(`item_id`, `name`,`quantity` , `uploadby`,`date`,`time`) VALUES ('$id','$name','$qty','$by','$date','$time')";
			if(mysqli_query($conn,$sql)){
        echo"<script>alert('Item added succesfully'); window.location.href='../bar'</script>";
			}
			else{
			  echo 'Error: '.mysqli_error($conn);
			}
		}
		
	
	
	
	?>