OPTIMAL DISTANCE AND TIME ENABLED
VOLATILE PRICING IN
FOOD DELIVERY SYSTEM
(Implementation and Coding)
DATABASE
CREATE TABLE `address` (
`address_id` int(11) NOT NULL,
`user_id` int(11) NOT NULL,
`state` varchar(255) NOT NULL,
`city` varchar(255) NOT NULL,
`street` varchar(255) NOT NULL,
`pincode` int(11) NOT NULL,
`latitude` decimal(10,8) NOT NULL,
`longitude` decimal(10,8) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
CREATE TABLE `drivers` (
`driver_id` int(11) NOT NULL,
`name` varchar(255) NOT NULL,
`phone` varchar(20) NOT NULL,
`location` varchar(255) NOT NULL,
`email` varchar(255) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
CREATE TABLE `feedback` (
`feedback_id` int(11) NOT NULL,
`order_id` int(11) NOT NULL,
`user_id` int(11) NOT NULL,
`restaurant_id` int(11) NOT NULL,
`rating` int(1) NOT NULL,
`comments` text DEFAULT NULL,
`categories` varchar(255) DEFAULT NULL,
`created_at` datetime NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
CREATE TABLE `menu` (
`menu_id` int(11) NOT NULL,
`restaurant_id` int(11) NOT NULL,
`item_name` varchar(255) NOT NULL,
`price` decimal(10,2) NOT NULL,
`img` varchar(255) NOT NULL,
`pricing_category_id` int(11) DEFAULT 1
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
CREATE TABLE `orders` (
`order_id` int(11) NOT NULL,
`user_id` int(11) NOT NULL,
`order_total` decimal(10,2) NOT NULL,
`delivery_status` varchar(20) NOT NULL,
`driver_id` int(11) NOT NULL,
`menu_id` int(11) NOT NULL,
`payment_status` varchar(20) DEFAULT 'pending',
`payment_method` varchar(50) DEFAULT NULL,
`transaction_id` varchar(100) DEFAULT NULL,
`payment_date` datetime DEFAULT NULL,
`delivery_distance` decimal(10,2) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
CREATE TABLE `payment` (
`payment_id` int(11) NOT NULL,
`order_id` int(11) NOT NULL,
`payment_method` varchar(20) NOT NULL,
`amount` decimal(10,2) NOT NULL,
`status` varchar(20) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
CREATE TABLE `rating` (
`rating_id` int(11) NOT NULL,
`user_id` int(11) NOT NULL,
`restaurant_id` int(11) NOT NULL,
`rating` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
CREATE TABLE `restaurants` (
`restaurant_id` int(11) NOT NULL,
`name` varchar(255) NOT NULL,
`address` varchar(255) NOT NULL,
`phone` varchar(20) NOT NULL,
`desp` varchar(300) NOT NULL,
`img` varchar(255) NOT NULL,
`latitude` decimal(10,8) NOT NULL,
`longitude` decimal(11,8) NOT NULL,
`rating` decimal(3,1) DEFAULT 0.0
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
CREATE TABLE `users` (
`user_id` int(11) NOT NULL,
`name` varchar(255) NOT NULL,
`email` varchar(255) NOT NULL,
`password` varchar(255) NOT NULL,
`phone` varchar(20) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
CODING
Login
<?php
session_start();
include './db_connect.php';
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="author" content="Kodinger">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Yummie Wheels</title>
<link rel="stylesheet"
href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9J
voRxT2MZw1T" crossorigin="anonymous">
<link rel="stylesheet" type="text/css" href="./css/my-login.css">
<link rel="stylesheet" href="./css/style.css">
</head>
<body class="my-login-page log">
<div class="nav">
<div class="menu-wrap">
<a href="./index.php">
<div class="logo">
Yummie Wheels
</div>
</a>
<div class="menu h-xs">
<a href="./index.php">
<div class="menu-item">
Home
</div>
</a>
<a href="./res.php">
<div class="menu-item">
Restaurants
</div>
</a>
<a href="./order.php">
<div class="menu-item">
Orders
</div>
</a>
<a href="./login.php">
<div class="menu-item active">
<?php
if(!isset($_SESSION['uid'])){
echo "Login";
}
else{
echo "Profile";
}
?>
</div>
</a>
</div>
<div class="right-menu">
<div class="cart-btn">
<i class='bx bx-cart-alt'></i>
</div>
</div>
</div>
</div>
<section class="h-100">
<div class="container h-100">
<div class="row justify-content-md-center h-100">
<div class="card-wrapper">
<div class="card-fat">
<div class="card-body">
<?php
if(!isset($_SESSION['uid'])){
echo<<<login
<h4 class="card-title">Login</h4>
<form method="POST" class="login-validate.php" action="./login-
validate.php">
<div class="form-group">
<label for="email">E-Mail Address</label>
<input id="email" type="email" class="form-control" name="email"
value="" required autofocus>
<div class="invalid-feedback">
Email is invalid
</div>
</div>
<div class="form-group">
<label for="password">Password
</label>
<input id="password" type="password" class="form-control"
name="password" required data-eye>
<div class="invalid-feedback">
Password is required
</div>
</div>
<div class="form-group m-0">
<button type="submit" class="btn btn-primary btn-block">
Login
</button>
</div>
<div class="mt-4 text-center">
Don't have an account? <a href="./register.php">Create One</a>
</div>
</form>
</div>
login;
}
else{
$user_id=$_SESSION['uid'];
$sql="select * from Users where user_id=$user_id";
$result=mysqli_query($conn, $sql);
$row=mysqli_fetch_assoc($result);
$name=$row["name"];
$email=$row["email"];
$ph=$row["phone"];
$sqla="SELECT * FROM `Address` where user_id=$user_id";
$addrow=mysqli_query($conn, $sqla);
$ar=mysqli_fetch_assoc($addrow);
$state=$ar["state"];
$city=$ar["city"];
$street=$ar["street"];
$pin=$ar["pincode"];
echo<<<in
<h2 style="text-align:center;">Welcome, $name</h2>
<br>
<h5><strong>Email:</strong>{$email}.</br>
<strong>Phone Number:</strong>{$ph}.</br>
<strong>Address:</strong>{$street}.</br><strong>City:</strong>{$city}</
br><strong>State:</strong>{$state}</br><strong>Pincode:</strong>{$pin}
</h5>
<form action="login.php" method="post">
<input type="submit" name="logout" value="logout"
style="background-color: #3D7065;border-radius: 1.5rem;border:none; color:
white;padding: 16px 32px;text-decoration: none;margin: 4px 2px;
cursor: pointer;display: block;width: 100px;margin: 0 auto;">
</form>
in;
if(isset($_POST['logout'])){
session_destroy();
header('Location: ./login.php');
}
}
?>
</div>
</div>
</div>
</div>
</body>
</html>
login-validate
<?php
session_start();
include 'db_connect.php';
$email=$_POST['email'];
$pass=$_POST['password'];
$sqlc="SELECT * FROM `Users` where email='$email' and password='$pass'";
$res=mysqli_query($conn, $sqlc);
if (mysqli_num_rows($res) > 0) {
$sqlu="select user_id from Users where email='$email'";
$result=mysqli_query($conn, $sqlu);
$row=mysqli_fetch_assoc($result);
$u_id=$row["user_id"];
$_SESSION['uid']=$u_id;
header('Location: ./login.php');
}
else{
header('Location: ./error.php?no=2');
}
echo $_SESSION['active'];
?>
Assign-pricing-categories
<?php
// Include necessary files
require_once 'db_connect.php';
require_once 'pricing-categories.php';
// Initialize pricing manager
$dbConnection = $conn;
$pricingManager = new PricingCategoryManager($dbConnection);
// Get all food items with their categories
$query = "SELECT menu_id, item_name, price, pricing_category_id FROM menu
ORDER BY price DESC";
$result = mysqli_query($dbConnection, $query);
echo "<h1>Debug Price Categories</h1>";
if (!$result) {
echo "<p>Error fetching menu items: " . mysqli_error($dbConnection) . "</p>";
exit;
}
echo "<table border='1' cellpadding='5'>
<tr>
<th>Item Name</th>
<th>Price</th>
<th>Category ID</th>
<th>Category Name</th>
</tr>";
$count = [
'1' => 0, // Regular
'2' => 0, // Premium
'3' => 0 // Budget
];
while ($item = mysqli_fetch_assoc($result)) {
$menuId = $item['menu_id'];
$price = (float)$item['price']; // cast to float
$name = $item['item_name'];
$categoryId = $item['pricing_category_id'];
if (isset($count["$categoryId"])) {
$count["$categoryId"]++;
}
$categoryName = $pricingManager->getCategoryName($categoryId);
echo "<tr>
<td>" . htmlspecialchars($name) . "</td>
<td>₹" . number_format($price, 2) . "</td>
<td>" . $categoryId . "</td>
<td>" . $categoryName . "</td>
</tr>";
}
echo "</table>";
echo "<h2>Summary:</h2>";
echo "<ul>
<li>Category ID 1 (Regular): {$count['1']}</li>
<li>Category ID 2 (Premium): {$count['2']}</li>
<li>Category ID 3 (Budget): {$count['3']}</li>
</ul>";
echo "<h1>Re-assign Price Categories</h1>";
// Reset pointer
mysqli_data_seek($result, 0);
echo "<table border='1' cellpadding='5'>
<tr>
<th>Item Name</th>
<th>Price</th>
<th>Should Be Category</th>
<th>New Category ID</th>
</tr>";
$fixCount = 0;
while ($item = mysqli_fetch_assoc($result)) {
$menuId = $item['menu_id'];
$price = (float)$item['price']; // cast to float
$name = $item['item_name'];
$currentCategoryId = $item['pricing_category_id'];
if ($price >= 200) {
$shouldBeCategoryId = PricingCategoryManager::CATEGORY_PREMIUM;
$shouldBeCategoryName = "Premium";
} elseif ($price <= 150) {
$shouldBeCategoryId = PricingCategoryManager::CATEGORY_BUDGET;
$shouldBeCategoryName = "Budget";
} else {
$shouldBeCategoryId = PricingCategoryManager::CATEGORY_REGULAR;
$shouldBeCategoryName = "Regular";
}
$needsFix = ($currentCategoryId != $shouldBeCategoryId);
if ($needsFix) {
$fixCount++;
$pricingManager->assignPricingCategory($menuId, $shouldBeCategoryId);
}
echo "<tr>
<td>" . htmlspecialchars($name) . "</td>
<td>₹" . number_format($price, 2) . "</td>
<td>" . $shouldBeCategoryName . " (" . $shouldBeCategoryId . ")</td>
<td>" . ($needsFix ? "<span style='color:red'>Fixed to " . $shouldBeCategoryId .
"</span>" : "Already correct") . "</td>
</tr>";
}
echo "</table>";
echo "<p>Fixed $fixCount items that had incorrect category assignments.</p>";
echo "<p><a href='display-pricing-ui.php'>View Menu</a></p>";
?>
budget-food-finder
<?php
include 'db_connect.php';
session_start();
// Function to filter foods by budget
function filterFoodsByBudget($conn, $budget) {
$sql = "SELECT item_name, price, restaurant_id FROM Menu WHERE price <=
$budget ORDER BY price ASC";
$result = mysqli_query($conn, $sql);
$foods = array();
if (mysqli_num_rows($result) > 0) {
while($row = mysqli_fetch_assoc($result)) {
// Get restaurant name
$resId = $row['restaurant_id'];
$resNameSql = "SELECT name FROM Restaurants WHERE restaurant_id =
$resId";
$resNameResult = mysqli_query($conn, $resNameSql);
$resNameRow = mysqli_fetch_assoc($resNameResult);
$foods[] = array(
'name' => $row['item_name'],
'price' => $row['price'],
'restaurant' => $resNameRow['name']
);
}
}
return $foods;
}
// Function to get top 3 cheapest items
function getTopCheapestItems($conn, $limit = 3) {
$sql = "SELECT item_name, price, restaurant_id FROM Menu ORDER BY price ASC
LIMIT $limit";
$result = mysqli_query($conn, $sql);
$foods = array();
if (mysqli_num_rows($result) > 0) {
while($row = mysqli_fetch_assoc($result)) {
// Get restaurant name
$resId = $row['restaurant_id'];
$resNameSql = "SELECT name FROM Restaurants WHERE restaurant_id =
$resId";
$resNameResult = mysqli_query($conn, $resNameSql);
$resNameRow = mysqli_fetch_assoc($resNameResult);
$foods[] = array(
'name' => $row['item_name'],
'price' => $row['price'],
'restaurant' => $resNameRow['name'],
'highlight' => true
);
}
}
return $foods;
}
// Function to filter foods by restaurant and budget (using restaurant as category)
function filterFoodsByRestaurantAndBudget($conn, $restaurantId, $budget) {
$sql = "SELECT item_name, price, restaurant_id FROM Menu
WHERE restaurant_id = $restaurantId AND price <= $budget
ORDER BY price ASC";
$result = mysqli_query($conn, $sql);
$foods = array();
if (mysqli_num_rows($result) > 0) {
while($row = mysqli_fetch_assoc($result)) {
// Get restaurant name
$resId = $row['restaurant_id'];
$resNameSql = "SELECT name FROM Restaurants WHERE restaurant_id =
$resId";
$resNameResult = mysqli_query($conn, $resNameSql);
$resNameRow = mysqli_fetch_assoc($resNameResult);
$foods[] = array(
'name' => $row['item_name'],
'price' => $row['price'],
'restaurant' => $resNameRow['name']
);
}
}
return $foods;
}
// Get all restaurants as categories
function getRestaurants($conn) {
$sql = "SELECT restaurant_id, name FROM Restaurants ORDER BY name";
$result = mysqli_query($conn, $sql);
$restaurants = array();
if (mysqli_num_rows($result) > 0) {
while($row = mysqli_fetch_assoc($result)) {
$restaurants[$row['restaurant_id']] = $row['name'];
}
}
return $restaurants;
}
// Handle form submissions
$budget = isset($_POST['budget']) ? (float)$_POST['budget'] : 0;
$restaurantId = isset($_POST['restaurant_id']) ? (int)$_POST['restaurant_id'] : 0;
$action = isset($_POST['action']) ? $_POST['action'] : '';
$filteredFoods = array();
$cheapestItems = array();
$categoryFoods = array();
$restaurants = array();
if ($action == 'filter_by_budget' && $budget > 0) {
$filteredFoods = filterFoodsByBudget($conn, $budget);
} elseif ($action == 'cheapest_items') {
$cheapestItems = getTopCheapestItems($conn);
} elseif ($action == 'filter_by_restaurant' && $restaurantId > 0 && $budget > 0) {
$categoryFoods = filterFoodsByRestaurantAndBudget($conn, $restaurantId, $budget);
}
// Get restaurants for dropdown
$restaurants = getRestaurants($conn);
// Find selected restaurant name
$selectedRestaurantName = '';
if ($restaurantId > 0 && isset($restaurants[$restaurantId])) {
$selectedRestaurantName = $restaurants[$restaurantId];
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Budget Food Finder - Yummie Wheels</title>
<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?
family=Poppins:wght@200;300;400;500;600;700;800;900&display=swap"
rel="stylesheet">
<link href='https://unpkg.com/[email protected]/css/boxicons.min.css' rel='stylesheet'>
<link rel="stylesheet" href="css/style.css">
<style>
.budget-container {
padding: 20px;
background-color: var(--secondary-color);
border-radius: 10px;
margin-bottom: 20px;
}
.budget-form {
display: flex;
flex-direction: column;
gap: 15px;
margin-bottom: 20px;
}
.input-group {
display: flex;
gap: 10px;
}
.budget-results {
background-color: rgba(255, 255, 255, 0.1);
padding: 15px;
border-radius: 8px;
}
.food-item-budget {
display: flex;
justify-content: space-between;
padding: 10px;
border-bottom: 1px solid rgba(255, 255, 255, 0.2);
}
.food-item-budget:last-child {
border-bottom: none;
}
.highlighted {
background-color: var(--third-color);
border-radius: 5px;
}
.activities-container {
display: flex;
flex-wrap: wrap;
gap: 20px;
margin-bottom: 20px;
}
.activity-card {
background-color: var(--secondary-color);
border-radius: 10px;
padding: 15px;
flex: 1;
min-width: 250px;
cursor: pointer;
transition: transform 0.3s;
}
.activity-card:hover {
transform: translateY(-5px);
}
.activity-card h3 {
color: var(--third-color);
margin-bottom: 10px;
}
select, input, button {
padding: 10px;
border: none;
border-radius: 5px;
}
button {
background-color: var(--third-color);
color: white;
cursor: pointer;
transition: background-color 0.3s;
}
button:hover {
background-color: #ff3b2f;
}
</style>
</head>
<body>
<!-- MOBILE NAV -->
<div class="mb-nav">
<div class="mb-move-item"></div>
<div class="mb-nav-item">
<a href="./index.php">
<i class="bx bxs-home"></i>
</a>
</div>
<div class="mb-nav-item">
<a href="./res.php">
<i class='bx bxs-wink-smile'></i>
</a>
</div>
<div class="mb-nav-item">
<a href="./order.php">
<i class='bx bxs-food-menu'></i>
</a>
</div>
<div class="mb-nav-item">
<a href="./login.php">
<i class='bx bxs-comment-detail'></i>
</a>
</div>
</div>
<!-- END MOBILE NAV -->
<!-- BACK TO TOP BTN -->
<a href="#" class="back-to-top">
<i class="bx bxs-to-top"></i>
</a>
<!-- END BACK TO TOP BTN -->
<!-- TOP NAVIGATION -->
<div class="nav">
<div class="menu-wrap">
<a href="./index.php">
<div class="logo">
Yummie Wheels
</div>
</a>
<div class="menu h-xs">
<a href="./index.php">
<div class="menu-item">
Home
</div>
</a>
<a href="./res.php">
<div class="menu-item">
Restaurants
</div>
</a>
<a href="./order.php">
<div class="menu-item">
Orders
</div>
</a>
<a href="./login.php">
<div class="menu-item">
<?php
if(!isset($_SESSION['uid'])){
echo "Login";
}
else{
echo "Profile";
}
?>
</div>
</a>
</div>
<div class="right-menu">
<div class="cart-btn">
<i class='bx bx-cart-alt'></i>
</div>
</div>
</div>
</div>
<!-- END TOP NAVIGATION -->
<!-- MAIN CONTENT -->
<section class="align-items-center bg-img bg-img-fixed" id="food-menu-section"
style="background-image: url(assets/katherine-chase-4MMK78S7eyk-unsplash.jpg);">
<div class="container">
<div class="food-menu">
<h1>Budget <span class="third-color">Food</span> Finder</h1>
<p>Find the best food options within your budget at Yummie Wheels</p>
<div class="activities-container">
<form method="post" class="activity-card" id="activity1">
<h3>Budget-Based Food Filtering</h3>
<p>Enter your budget and we'll show you all available options.</p>
<div class="budget-form">
<div class="input-group">
<input type="number" name="budget" placeholder="Enter your
budget (₹)" step="0.01" min="0" required>
<input type="hidden" name="action" value="filter_by_budget">
<button type="submit">Find Foods</button>
</div>
</div>
</form>
<form method="post" class="activity-card" id="activity2">
<h3>Sort and Highlight Cheapest Items</h3>
<p>Find the top 3 cheapest items across all restaurants.</p>
<div class="budget-form">
<div class="input-group">
<input type="hidden" name="action" value="cheapest_items">
<button type="submit">Show Cheapest Items</button>
</div>
</div>
</form>
<form method="post" class="activity-card" id="activity3">
<h3>Restaurant-Wise Cheap Foods</h3>
<p>Find budget-friendly options from your favorite restaurant.</p>
<div class="budget-form">
<div class="input-group">
<select name="restaurant_id" required style="width: 100%;">
<option value="">Select Restaurant</option>
<?php foreach($restaurants as $id => $name): ?>
<option value="<?php echo $id; ?>"><?php echo $name;
?></option>
<?php endforeach; ?>
</select>
</div>
<div class="input-group">
<input type="number" name="budget" placeholder="Enter your
budget (₹)" step="0.01" min="0" required>
<input type="hidden" name="action" value="filter_by_restaurant">
<button type="submit">Filter By Restaurant</button>
</div>
</div>
</form>
</div>
<?php if (!empty($filteredFoods)): ?>
<div class="budget-container">
<h2>Foods Under ₹<?php echo $budget; ?></h2>
<div class="budget-results">
<?php if (count($filteredFoods) > 0): ?>
<?php foreach($filteredFoods as $food): ?>
<div class="food-item-budget">
<div>
<strong><?php echo $food['name']; ?></strong>
<p>From: <?php echo $food['restaurant']; ?></p>
</div>
<div>
<strong>₹<?php echo $food['price']; ?></strong>
</div>
</div>
<?php endforeach; ?>
<?php else: ?>
<p>No foods found within your budget. Try increasing your
budget.</p>
<?php endif; ?>
</div>
</div>
<?php endif; ?>
<?php if (!empty($cheapestItems)): ?>
<div class="budget-container">
<h2>Top 3 Cheapest Items</h2>
<div class="budget-results">
<?php foreach($cheapestItems as $food): ?>
<div class="food-item-budget highlighted">
<div>
<strong><?php echo $food['name']; ?></strong>
<p>From: <?php echo $food['restaurant']; ?></p>
</div>
<div>
<strong>₹<?php echo $food['price']; ?></strong>
</div>
</div>
<?php endforeach; ?>
</div>
</div>
<?php endif; ?>
<?php if (!empty($categoryFoods)): ?>
<div class="budget-container">
<h2><?php echo $selectedRestaurantName; ?> Items Under ₹<?php echo
$budget; ?></h2>
<div class="budget-results">
<?php if (count($categoryFoods) > 0): ?>
<?php foreach($categoryFoods as $food): ?>
<div class="food-item-budget">
<div>
<strong><?php echo $food['name']; ?></strong>
</div>
<div>
<strong>₹<?php echo $food['price']; ?></strong>
</div>
</div>
<?php endforeach; ?>
<?php else: ?>
<p>No items found within your budget at this restaurant. Try
increasing your budget or selecting a different restaurant.</p>
<?php endif; ?>
</div>
</div>
<?php endif; ?>
</div>
</div>
</section>
<!-- END MAIN CONTENT -->
<!-- FOOTER SECTION -->
<section class="footer bg-img" style="background-color: var(--third-color);">
<div class="container">
<div class="row">
<div class="col-6 col-xs-12">
<h1>
Yummie Wheels
</h1>
<br>
<p>Yummie Wheels is a food delivery service that brings delicious meals to
your doorsteps in minutes.Whatever you are craving for pizza,pasta ,biriyani.</p>
<br>
<p>Email: <a
href="mailto:
[email protected]">
[email protected]</a></p>
<p>Phone: <a href="tel:+911234567890">+911234567890</a></p>
<p>Website: yummiefood.com</p>
</div>
<div class="col-2 col-xs-12">
<h1>
About us
</h1>
<br>
<p>
<a href="#">
Privacy policy
</a>
</p>
<p>
<a href="#">
Contact
</a>
</p>
<p>
<a href="#">
About
</a>
</p>
</div>
<div class="col-4 col-xs-12">
<h1>
Subscribe & media
</h1>
<br>
<p>Subscribe For official infromation and Discounts and more</p>
<div class="input-group" style="background-color: var(--secondary-color);">
<input required="text" placeholder="Enter your email">
<button onClick="window.location.href='./login.php';">
Subscribe
</button>
</div>
</div>
</div>
</div>
</section>
<!-- END FOOTER SECTION -->
<script src="js/main.js"></script>
</body>
</html>
Shortest path
<?php
include 'db_connect.php'; // Database connection
/**
* Creates a more realistic alternative path with multiple waypoints
* @param float $start_lat Starting latitude (restaurant)
* @param float $start_lon Starting longitude (restaurant)
* @param float $end_lat Ending latitude (customer)
* @param float $end_lon Ending longitude (customer)
* @return array Path information with waypoints
*/
function haversine($lat1, $lon1, $lat2, $lon2) {
$earth_radius = 6371; // Radius of the earth in km
$dLat = deg2rad($lat2 - $lat1);
$dLon = deg2rad($lon2 - $lon1);
$a = sin($dLat / 2) * sin($dLat / 2) +
cos(deg2rad($lat1)) * cos(deg2rad($lat2)) *
sin($dLon / 2) * sin($dLon / 2);
$c = 2 * atan2(sqrt($a), sqrt(1 - $a));
return $earth_radius * $c; // Distance in km
}
function dijkstra($graph, $start, $end) {
$distances = [];
$previous = [];
$queue = new SplPriorityQueue();
foreach ($graph as $node => $edges) {
$distances[$node] = INF;
$previous[$node] = null;
$queue->insert($node, INF);
}
$distances[$start] = 0;
$queue->insert($start, 0);
while (!$queue->isEmpty()) {
$current = $queue->extract();
if ($current === $end) {
break;
}
foreach ($graph[$current] as $neighbor => $cost) {
$alt = $distances[$current] + $cost;
if ($alt < $distances[$neighbor]) {
$distances[$neighbor] = $alt;
$previous[$neighbor] = $current;
$queue->insert($neighbor, $alt);
}
}
}
// Reconstruct shortest path
$path = [];
$node = $end;
while ($node !== null) {
array_unshift($path, $node);
$node = $previous[$node];
}
return [
'path' => $path,
'distance' => $distances[$end]
];
}
function alternativePath($start_lat, $start_lon, $end_lat, $end_lon) {
// Calculate the direct distance
$direct_distance = haversine($start_lat, $start_lon, $end_lat, $end_lon);
// Vector from start to end
$dx = $end_lat - $start_lat;
$dy = $end_lon - $start_lon;
// Generate 2-3 waypoints for a realistic alternative route
$waypoints = [];
// Calculate perpendicular offsets to create a curved path
// First waypoint - offset in one direction
$wp1_lat = $start_lat + ($dx * 0.3) + ($dy * 0.1);
$wp1_lon = $start_lon + ($dy * 0.3) - ($dx * 0.1);
$waypoints[] = ['lat' => $wp1_lat, 'lng' => $wp1_lon];
// Second waypoint - offset in the opposite direction
$wp2_lat = $start_lat + ($dx * 0.6) - ($dy * 0.1);
$wp2_lon = $start_lon + ($dy * 0.6) + ($dx * 0.1);
$waypoints[] = ['lat' => $wp2_lat, 'lng' => $wp2_lon];
// Calculate the total distance of this alternative path
$alt_distance = haversine($start_lat, $start_lon, $wp1_lat, $wp1_lon);
$alt_distance += haversine($wp1_lat, $wp1_lon, $wp2_lat, $wp2_lon);
$alt_distance += haversine($wp2_lat, $wp2_lon, $end_lat, $end_lon);
// Make the alternative slightly longer than the direct route (typically 10-20% longer)
$distance_ratio = $alt_distance / $direct_distance;
if ($distance_ratio < 1.1) {
// If our alternative isn't significantly longer, make it a bit longer
$alt_distance = $direct_distance * (1.1 + (mt_rand(5, 15) / 100));
}
return [
'path' => ['restaurant', 'waypoint1', 'waypoint2', 'user'],
'distance' => $alt_distance,
'waypoints' => [
'waypoint1' => ['lat' => $wp1_lat, 'lng' => $wp1_lon],
'waypoint2' => ['lat' => $wp2_lat, 'lng' => $wp2_lon]
]
];
}
// Debug information - log request parameters
error_log("shortest_path.php called with params: " . json_encode($_GET));
// Fetch restaurant and user locations
$restaurant_id = isset($_GET['restaurant_id']) ? intval($_GET['restaurant_id']) : 0;
$user_id = isset($_GET['user_id']) ? intval($_GET['user_id']) : 0;
// Handle direct coordinate input instead of IDs
if (isset($_GET['res_lat']) && isset($_GET['res_lng']) && isset($_GET['cust_lat']) &&
isset($_GET['cust_lng'])) {
$restaurant = [
'latitude' => floatval($_GET['res_lat']),
'longitude' => floatval($_GET['res_lng'])
];
$user = [
'latitude' => floatval($_GET['cust_lat']),
'longitude' => floatval($_GET['cust_lng'])
];
// Direct path graph
$graph = [
'restaurant' => ['user' => haversine($restaurant['latitude'], $restaurant['longitude'],
$user['latitude'], $user['longitude'])],
'user' => [] // End node
];
// Calculate shortest path
$shortest = dijkstra($graph, 'restaurant', 'user');
// Calculate alternative path
$alternative = alternativePath(
$restaurant['latitude'],
$restaurant['longitude'],
$user['latitude'],
$user['longitude']
);
// Return both paths and location data
echo json_encode([
'shortest_path' => $shortest['path'],
'shortest_distance' => $shortest['distance'],
'alternative_path' => $alternative['path'],
'alternative_distance' => $alternative['distance'],
'locations' => [
'restaurant' => ['lat' => $restaurant['latitude'], 'lng' => $restaurant['longitude']],
'user' => ['lat' => $user['latitude'], 'lng' => $user['longitude']],
'waypoint1' => $alternative['waypoints']['waypoint1'],
'waypoint2' => $alternative['waypoints']['waypoint2']
]
]);
exit;
}
// Regular database query flow
$query1 = $conn->query("SELECT latitude, longitude FROM restaurants WHERE
restaurant_id = $restaurant_id");
$query2 = $conn->query("SELECT latitude, longitude FROM address WHERE user_id =
$user_id");
// Log database query status
error_log("Restaurant query rows: " . ($query1 ? $query1->num_rows : "query failed"));
error_log("User query rows: " . ($query2 ? $query2->num_rows : "query failed"));
if ($query1 && $query2 && $query1->num_rows > 0 && $query2->num_rows > 0) {
$restaurant = $query1->fetch_assoc();
$user = $query2->fetch_assoc();
// Direct path graph
$graph = [
'restaurant' => ['user' => haversine($restaurant['latitude'], $restaurant['longitude'],
$user['latitude'], $user['longitude'])],
'user' => [] // End node
];
// Calculate shortest path
$shortest = dijkstra($graph, 'restaurant', 'user');
// Calculate alternative path
$alternative = alternativePath(
$restaurant['latitude'],
$restaurant['longitude'],
$user['latitude'],
$user['longitude']
);
// Return both paths and location data
echo json_encode([
'shortest_path' => $shortest['path'],
'shortest_distance' => $shortest['distance'],
'alternative_path' => $alternative['path'],
'alternative_distance' => $alternative['distance'],
'locations' => [
'restaurant' => ['lat' => $restaurant['latitude'], 'lng' => $restaurant['longitude']],
'user' => ['lat' => $user['latitude'], 'lng' => $user['longitude']],
'waypoint1' => $alternative['waypoints']['waypoint1'],
'waypoint2' => $alternative['waypoints']['waypoint2']
]
]);
} else {
// Return detailed error information
echo json_encode([
'error' => 'Could not retrieve location data',
'restaurant_id' => $restaurant_id,
'user_id' => $user_id,
'restaurant_query_success' => ($query1 !== false),
'user_query_success' => ($query2 !== false),
'restaurant_rows' => ($query1 ? $query1->num_rows : 0),
'user_rows' => ($query2 ? $query2->num_rows : 0)
]);
}
?>