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

<!DOCTYPE html>
<html lang="en">
  <?php $page='Edit Category';?> 
<?php include("../common/head.php")?>
<style>

 
    label{
        font-size:20px;

    }
    .edit-body{
        margin:100px;
    }

    input,select{
        background-color:rgba(0, 0, 0, 0) !important;
}
</style>
<body>
                 <!-- Modal -->
                 <?php 
$sql = "SELECT * FROM menu_cat WHERE id='$id2' ";
$result=mysqli_query($conn,$sql);
    $row=mysqli_fetch_array($result);
?>
        <div class="edit-header">
          <h3 class="edit-tittle text-center " id="exampleModalLabel">Edit Category</h3>
        </div>
        <div class="edit-body ">
        <form method="post"enctype="multipart/form-data"  class="text-dark">
                <div class="form-group">
                  <label for="exampleFormControlInput1">Item name</label>
                  <input type="text" class="form-control" name="name" id="exampleFormControlInput1" value="<?php echo $row['name']?>" >
                </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">
                <select class="form-control " name="location"  id="mySelect1" >
              <option value="<?php echo $row['location']?>"><?php echo $row['location']?></option>
              <option value="Bar">Bar</option>
              <option value="Restaurant">Restauranr</option>
         </select>
                </div> 
                
                <input type="hidden" name="date" value="<?php echo date("F j, Y") ?>">
                
                  <button class="btn btn-success btn-sm"  name="submit">Submit</button>
              </form>
        </div>
        <div class="modal-footer">
        </div>

        <?php 





if(isset($_POST['submit'])){
 
    $name=addslashes($_POST['name']);
    $location=$_POST['location'];
    $filename = $_FILES['image']['name'];
     $date=$_POST['date'];


	// Select file type
	$imageFileType = strtolower(pathinfo($filename,PATHINFO_EXTENSION));
	
	// valid file extensions
	$extensions_arr = array("jpg","jpeg","png","jfif");
 
	// Check extension
	if( in_array($imageFileType,$extensions_arr) ){
 
	// Upload files and store in database
	if(move_uploaded_file($_FILES["image"]["tmp_name"],'../image/'.$filename)){
     $sql = "UPDATE `menu_cat` SET`name`='$name',`image`='$filename',`location`='$location',`by`='$by' WHERE id='$id2'";
     $result = $conn->query($sql);
    
     if(mysqli_query($conn,$sql)){
      echo"<script>alert('You Have Successfully Updated Category'); window.location='../category'</script>";
		}
		else{
		  echo 'Error: '.mysqli_error($conn);
		}

}

else{
  echo 'Error in uploading file - '.$_FILES['image']['name'].'<br/>';
}
  }
}
?>

    </body>
</html>