This commit is contained in:
Flatlogic Bot 2025-09-23 16:52:21 +00:00
parent d627358851
commit 2fd5ee80aa
2 changed files with 102 additions and 10 deletions

View File

@ -52,8 +52,8 @@
<h1 class="display-3">Your Trusted Mechanic, <span class="golden-text">Just a Click Away.</span></h1>
<p class="lead">Find reliable mechanics and genuine spare parts instantly. Get back on the road faster.</p>
<div class="d-grid gap-2 d-sm-flex justify-content-sm-center">
<a href="search.php" class="btn btn-golden btn-lg px-4 gap-3">Find a Mechanic</a>
<a href="search.php" class="btn btn-outline-light btn-lg px-4">Find Spare Parts</a>
<a href="search.php?type=mechanic" class="btn btn-golden btn-lg px-4 gap-3">Find a Mechanic</a>
<a href="search.php?type=shop_owner" class="btn btn-outline-light btn-lg px-4">Find Spare Parts</a>
</div>
</div>
</header>

View File

@ -1,25 +1,117 @@
<?php
session_start();
require_once 'db/config.php';
// Determine the search type from the URL, default to 'mechanic'
$search_type = $_GET['type'] ?? 'mechanic';
if (!in_array($search_type, ['mechanic', 'shop_owner'])) {
$search_type = 'mechanic'; // Default to a safe value
}
// Set the page title and search placeholder based on the type
$page_title = ($search_type === 'mechanic') ? 'Find a Mechanic' : 'Find Spare Parts';
$search_label = ($search_type === 'mechanic') ? 'Search for a mechanic by location' : 'Search for a spare parts shop by location';
$search_placeholder = "Enter a city or area...";
$user_role_to_find = ($search_type === 'mechanic') ? 'mechanic' : 'shop_owner';
$results = [];
$search_location = '';
// Handle the search form submission
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$search_location = trim($_POST['location'] ?? '');
if (!empty($search_location)) {
$pdo = db_connect();
if ($pdo) {
// Query the database for users matching the role and location
$sql = "SELECT full_name, phone_number, location, garage_name FROM users WHERE user_role = :user_role AND location LIKE :location";
$stmt = $pdo->prepare($sql);
$stmt->execute([
'user_role' => $user_role_to_find,
'location' => '%' . $search_location . '%'
]);
$results = $stmt->fetchAll(PDO::FETCH_ASSOC);
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Search - MyMech</title>
<title><?php echo htmlspecialchars($page_title); ?> - MyMech</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;600;700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<nav class="navbar navbar-expand-lg navbar-dark bg-navy-blue-darker">
<div class="container">
<a class="navbar-brand" href="index.php"><span class="golden-text">MyMech</span></a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav ms-auto align-items-center">
<?php if (isset($_SESSION['user_id'])): ?>
<li class="nav-item"><a class="nav-link" href="<?php echo $_SESSION['user_role'] === 'admin' ? 'admin/dashboard.php' : '#'; ?>">Dashboard</a></li>
<li class="nav-item"><a class="nav-link" href="logout.php">Logout</a></li>
<?php else: ?>
<li class="nav-item mb-2 mb-lg-0 me-lg-2">
<a class="btn btn-outline-golden px-3" href="login.php">Login</a>
</li>
<li class="nav-item">
<a class="btn btn-golden px-3" href="register.php">Register</a>
</li>
<?php endif; ?>
</ul>
</div>
</div>
</nav>
<main class="container py-5 text-center">
<h2 class="golden-text">Search</h2>
<p>This page is under construction. The search functionality for mechanics and spare parts will be available here soon.</p>
<div class="text-center mt-4">
<a href="index.php" class="btn btn-golden">Go Back to Home</a>
<main class="container py-5">
<div class="row justify-content-center">
<div class="col-lg-8 col-md-10">
<div class="search-container p-4 rounded">
<h2 class="text-center golden-text mb-4"><?php echo htmlspecialchars($page_title); ?></h2>
<form action="search.php?type=<?php echo htmlspecialchars($search_type); ?>" method="POST">
<div class="mb-3">
<label for="location" class="form-label"><?php echo htmlspecialchars($search_label); ?></label>
<input type="text" class="form-control" id="location" name="location" placeholder="<?php echo htmlspecialchars($search_placeholder); ?>" value="<?php echo htmlspecialchars($search_location); ?>">
</div>
<div class="d-grid">
<button type="submit" class="btn btn-golden btn-lg">Search</button>
</div>
</form>
</div>
<?php if ($_SERVER["REQUEST_METHOD"] == "POST"): ?>
<div class="results-container mt-5">
<h3 class="golden-text mb-4">Search Results</h3>
<?php if (!empty($results)): ?>
<div class="row">
<?php foreach ($results as $result): ?>
<div class="col-md-6 mb-4">
<div class="card result-card h-100">
<div class="card-body">
<h5 class="card-title golden-text"><?php echo htmlspecialchars($result['garage_name'] ?: $result['full_name']); ?></h5>
<p class="card-text mb-1"><strong>Location:</strong> <?php echo htmlspecialchars($result['location']); ?></p>
<p class="card-text"><strong>Phone:</strong> <?php echo htmlspecialchars($result['phone_number']); ?></p>
</div>
</div>
</div>
<?php endforeach; ?>
</div>
<?php else: ?>
<div class="alert alert-warning" role="alert">
No results found for "<?php echo htmlspecialchars($search_location); ?>". Please try a different location.
</div>
<?php endif; ?>
</div>
<?php endif; ?>
</div>
</div>
</main>