This commit is contained in:
Flatlogic Bot 2025-10-29 10:45:26 +00:00
parent 9584826cb1
commit 1b9afa40ef
6 changed files with 282 additions and 98 deletions

View File

@ -20,7 +20,7 @@ body {
left: 0; left: 0;
right: 0; right: 0;
bottom: 0; bottom: 0;
background: linear-gradient(45deg, rgba(0, 123, 255, 0.8), rgba(40, 167, 69, 0.8)); background: linear-gradient(45deg, rgba(32, 222, 110, 0.8), rgba(40, 167, 69, 0.8));
} }
.hero-section .container { .hero-section .container {
@ -37,16 +37,16 @@ body {
} }
.btn-primary { .btn-primary {
background-color: #007BFF; background-color: #20de6e;
border-color: #007BFF; border-color: #20de6e;
padding: 0.75rem 1.5rem; padding: 0.75rem 1.5rem;
border-radius: 0.5rem; border-radius: 0.5rem;
font-weight: 600; font-weight: 600;
} }
.btn-primary:hover { .btn-primary:hover {
background-color: #0056b3; background-color: #18b35a;
border-color: #0056b3; border-color: #18b35a;
} }
.how-it-works { .how-it-works {
@ -55,7 +55,7 @@ body {
.step-icon { .step-icon {
font-size: 3rem; font-size: 3rem;
color: #007BFF; color: #20de6e;
} }
/* Auth pages styling */ /* Auth pages styling */
@ -67,3 +67,24 @@ body {
transform: translateY(-5px); transform: translateY(-5px);
box-shadow: 0 12px 40px rgba(0,0,0,0.12) !important; box-shadow: 0 12px 40px rgba(0,0,0,0.12) !important;
} }
.text-primary {
color: #20de6e !important;
}
.btn-outline-primary {
--bs-btn-color: #20de6e;
--bs-btn-border-color: #20de6e;
--bs-btn-hover-color: #fff;
--bs-btn-hover-bg: #20de6e;
--bs-btn-hover-border-color: #20de6e;
--bs-btn-active-color: #fff;
--bs-btn-active-bg: #20de6e;
--bs-btn-active-border-color: #20de6e;
--bs-btn-disabled-color: #20de6e;
--bs-btn-disabled-bg: transparent;
}
.navbar-toggler-icon {
background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 30 30'%3e%3cpath stroke='rgba(32, 222, 110, 1)' stroke-linecap='round' stroke-miterlimit='10' stroke-width='2' d='M4 7h22M4 15h22M4 23h22'/%3e%3c/svg%3e");
}

View File

@ -0,0 +1 @@
ALTER TABLE `users` ADD `location` VARCHAR(255) NULL DEFAULT NULL AFTER `user_type`;

View File

@ -1,14 +1,5 @@
<?php <?php
require_once 'db/config.php'; require_once 'db/config.php';
// Fetch categories for the search form
try {
$pdo = db();
$categories_stmt = $pdo->query("SELECT * FROM service_categories ORDER BY name");
$search_categories = $categories_stmt->fetchAll();
} catch (PDOException $e) {
$search_categories = [];
}
?> ?>
<!DOCTYPE html> <!DOCTYPE html>
<html lang="it"> <html lang="it">
@ -68,12 +59,10 @@ try {
</div> </div>
</div> </div>
<div class="col-lg-4"> <div class="col-lg-4">
<select class="form-select border-0" name="category"> <div class="input-group">
<option value="">Tutte le categorie</option> <span class="input-group-text bg-transparent border-0"><i class="bi bi-geo-alt"></i></span>
<?php foreach ($search_categories as $category): ?> <input type="text" class="form-control border-0" name="location" placeholder="Comune">
<option value="<?= $category['id'] ?>"><?= htmlspecialchars($category['name']) ?></option> </div>
<?php endforeach; ?>
</select>
</div> </div>
<div class="col-lg-2"> <div class="col-lg-2">
<button type="submit" class="btn btn-primary w-100">Cerca</button> <button type="submit" class="btn btn-primary w-100">Cerca</button>

View File

@ -9,6 +9,7 @@ $success = null;
if ($_SERVER["REQUEST_METHOD"] == "POST") { if ($_SERVER["REQUEST_METHOD"] == "POST") {
$name = trim($_POST['name'] ?? ''); $name = trim($_POST['name'] ?? '');
$email = trim($_POST['email'] ?? ''); $email = trim($_POST['email'] ?? '');
$location = trim($_POST['location'] ?? '');
$password = $_POST['password'] ?? ''; $password = $_POST['password'] ?? '';
$confirm_password = $_POST['confirm_password'] ?? ''; $confirm_password = $_POST['confirm_password'] ?? '';
@ -17,7 +18,7 @@ if ($_SERVER["REQUEST_METHOD"] == "POST") {
$first_name = $name_parts[0]; $first_name = $name_parts[0];
$last_name = $name_parts[1] ?? ''; $last_name = $name_parts[1] ?? '';
if (empty($first_name) || empty($email) || empty($password)) { if (empty($first_name) || empty($email) || empty($password) || empty($location)) {
$error = "Tutti i campi sono obbligatori."; $error = "Tutti i campi sono obbligatori.";
} elseif ($password !== $confirm_password) { } elseif ($password !== $confirm_password) {
$error = "Le password non coincidono."; $error = "Le password non coincidono.";
@ -37,9 +38,9 @@ if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Insert the new user // Insert the new user
$insert_stmt = $pdo->prepare( $insert_stmt = $pdo->prepare(
"INSERT INTO users (first_name, last_name, email, password, user_type) VALUES (?, ?, ?, ?, 'provider')" "INSERT INTO users (first_name, last_name, email, password, user_type, location) VALUES (?, ?, ?, ?, 'provider', ?)"
); );
if ($insert_stmt->execute([$first_name, $last_name, $email, $hashed_password])) { if ($insert_stmt->execute([$first_name, $last_name, $email, $hashed_password, $location])) {
$success = "Registrazione completata! Ora puoi effettuare il login."; $success = "Registrazione completata! Ora puoi effettuare il login.";
} else { } else {
$error = "Si è verificato un errore durante la registrazione. Riprova."; $error = "Si è verificato un errore durante la registrazione. Riprova.";
@ -95,6 +96,10 @@ if ($_SERVER["REQUEST_METHOD"] == "POST") {
<label for="email" class="form-label">Indirizzo Email</label> <label for="email" class="form-label">Indirizzo Email</label>
<input type="email" class="form-control" id="email" name="email" required value="<?= htmlspecialchars($email ?? '') ?>"> <input type="email" class="form-control" id="email" name="email" required value="<?= htmlspecialchars($email ?? '') ?>">
</div> </div>
<div class="mb-3">
<label for="location" class="form-label">Comune</label>
<input type="text" class="form-control" id="location" name="location" required value="<?= htmlspecialchars($location ?? '') ?>">
</div>
<div class="mb-3"> <div class="mb-3">
<label for="password" class="form-label">Password</label> <label for="password" class="form-label">Password</label>
<input type="password" class="form-control" id="password" name="password" required> <input type="password" class="form-control" id="password" name="password" required>

View File

@ -1,89 +1,120 @@
<?php <?php
require_once 'db/config.php'; require_once 'db/config.php';
$q = trim($_GET['q'] ?? ''); $query = $_GET['q'] ?? '';
$category_id = $_GET['category'] ?? null; $location = $_GET['location'] ?? '';
$pageTitle = "Risultati della ricerca";
$pageDescription = "Servizi trovati per la tua ricerca.";
$results = []; $results = [];
$error = null;
try { if (!empty($query) || !empty($location)) {
$pdo = db(); try {
$sql = "SELECT s.*, u.first_name, u.last_name, sc.name as category_name $pdo = db();
$sql = "
SELECT
s.id,
s.name,
s.description,
s.price,
c.name as category_name,
u.first_name,
u.last_name,
u.location
FROM services s FROM services s
JOIN users u ON s.provider_id = u.id JOIN users u ON s.provider_id = u.id
JOIN service_categories sc ON s.category_id = sc.id JOIN service_categories c ON s.category_id = c.id
WHERE u.user_type = 'provider'"; WHERE u.user_type = 'provider'
";
$params = []; $params = [];
if (!empty($q)) { if (!empty($query)) {
$sql .= " AND (s.name LIKE ? OR s.description LIKE ?)"; $sql .= " AND (s.name LIKE :query OR s.description LIKE :query)";
$params[] = "%$q%"; $params[':query'] = '%' . $query . '%';
$params[] = "%$q%"; }
if (!empty($location)) {
$sql .= " AND u.location LIKE :location";
$params[':location'] = '%' . $location . '%';
}
$stmt = $pdo->prepare($sql);
$stmt->execute($params);
$results = $stmt->fetchAll();
} catch (PDOException $e) {
// In a real app, you would log this error.
$error_message = "Si è verificato un errore durante la ricerca. Riprova più tardi.";
} }
if (!empty($category_id)) {
$sql .= " AND s.category_id = ?";
$params[] = $category_id;
}
$stmt = $pdo->prepare($sql);
$stmt->execute($params);
$results = $stmt->fetchAll();
} catch (PDOException $e) {
$error = "Errore del database: " . $e->getMessage();
} }
require_once '_header.php';
?> ?>
<main class="container my-5"> <!DOCTYPE html>
<h1 class="mb-4">Ricerca servizi</h1> <html lang="it">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Risultati della Ricerca - MeToo</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.1/font/bootstrap-icons.css">
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
</head>
<body>
<div class="card mb-4"> <?php include __DIR__ . '/_header.php'; ?>
<div class="card-body">
<form action="search.php" method="GET" class="row g-3"> <main class="container my-5">
<div class="col-md-8"> <h1 class="mb-4">Risultati della ricerca</h1>
<input type="text" class="form-control" name="q" placeholder="Cosa stai cercando?" value="<?= htmlspecialchars($q) ?>">
</div> <div class="row mb-4">
<div class="col-md-4"> <div class="col">
<button type="submit" class="btn btn-primary w-100">Cerca di nuovo</button> <form action="search.php" method="GET" class="row g-3">
</div> <div class="col-md-6">
</form> <input type="text" class="form-control" name="q" placeholder="Che servizio cerchi?" value="<?= htmlspecialchars($query) ?>">
</div>
<div class="col-md-4">
<input type="text" class="form-control" name="location" placeholder="Comune" value="<?= htmlspecialchars($location) ?>">
</div>
<div class="col-md-2">
<button type="submit" class="btn btn-primary w-100">Cerca</button>
</div>
</form>
</div>
</div> </div>
</div>
<?php if ($error): ?> <?php if (isset($error_message)): ?>
<div class="alert alert-danger"><?= htmlspecialchars($error) ?></div> <div class="alert alert-danger"><?= $error_message ?></div>
<?php elseif (empty($results)): ?> <?php elseif (empty($results)): ?>
<div class="alert alert-info">Nessun servizio trovato per la tua ricerca.</div> <div class="alert alert-info">
<?php else: ?> Nessun servizio trovato per "<?= htmlspecialchars($query) ?>" <?= !empty($location) ? 'a ' . htmlspecialchars($location) : '' ?>. Prova a modificare i criteri di ricerca.
<p class="text-muted">Trovati <?= count($results) ?> risultati.</p> </div>
<div class="row g-4"> <?php else: ?>
<?php foreach ($results as $service): ?> <p class="text-muted">Trovati <?= count($results) ?> risultati.</p>
<div class="col-md-6 col-lg-4"> <div class="row row-cols-1 row-cols-md-2 row-cols-lg-3 g-4">
<div class="card h-100"> <?php foreach ($results as $service): ?>
<div class="card-body d-flex flex-column"> <div class="col">
<h5 class="card-title"><?= htmlspecialchars($service['name']) ?></h5> <div class="card h-100">
<h6 class="card-subtitle mb-2 text-muted"><?= htmlspecialchars($service['category_name']) ?></h6> <div class="card-body">
<p class="card-text flex-grow-1"><?= nl2br(htmlspecialchars(substr($service['description'], 0, 100))) . (strlen($service['description']) > 100 ? '...' : '') ?></p> <h5 class="card-title"><?= htmlspecialchars($service['name']) ?></h5>
<p class="fs-5 fw-bold text-end mb-3"> <?= htmlspecialchars(number_format($service['price'], 2, ',', '.')) ?></p> <h6 class="card-subtitle mb-2 text-muted"><?= htmlspecialchars($service['category_name']) ?></h6>
<div class="mt-auto"> <p class="card-text"><?= htmlspecialchars(substr($service['description'], 0, 100)) ?>...</p>
<p class="mb-1"><small>Offerto da: <?= htmlspecialchars($service['first_name'] . ' ' . $service['last_name']) ?></small></p> <p class="card-text">
<a href="#" class="btn btn-primary w-100 disabled">Vedi Dettagli</a> <strong>Prezzo:</strong> <?= htmlspecialchars(number_format($service['price'], 2, ',', '.')) ?><br>
<strong>Fornitore:</strong> <?= htmlspecialchars($service['first_name'] . ' ' . $service['last_name']) ?><br>
<strong>Comune:</strong> <?= htmlspecialchars($service['location']) ?>
</p>
<a href="service.php?id=<?= $service['id'] ?>" class="btn btn-primary">Vedi Dettagli</a>
</div> </div>
</div> </div>
</div> </div>
</div> <?php endforeach; ?>
<?php endforeach; ?> </div>
</div> <?php endif; ?>
<?php endif; ?>
</main> </main>
<?php
require_once '_footer.php'; <?php include __DIR__ . '/_footer.php'; ?>
?>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
<script src="assets/js/main.js?v=<?php echo time(); ?>"></script>
</body>
</html>

137
service.php Normal file
View File

@ -0,0 +1,137 @@
<?php
require_once 'db/config.php';
$service_id = $_GET['id'] ?? null;
if (!$service_id) {
header("Location: index.php");
exit;
}
$service = null;
$other_providers = [];
$error_message = null;
try {
$pdo = db();
// Fetch the main service details
$sql = "
SELECT
s.id,
s.name,
s.description,
s.price,
c.name as category_name,
u.first_name,
u.last_name,
u.location
FROM services s
JOIN users u ON s.provider_id = u.id
JOIN service_categories c ON s.category_id = c.id
WHERE s.id = :service_id AND u.user_type = 'provider'
";
$stmt = $pdo->prepare($sql);
$stmt->execute([':service_id' => $service_id]);
$service = $stmt->fetch();
if ($service) {
// Fetch other providers offering a service with the same name in the same location
$sql_others = "
SELECT
u.first_name,
u.last_name,
u.location,
s.price
FROM services s
JOIN users u ON s.provider_id = u.id
WHERE s.name = :service_name
AND u.location = :location
AND s.id != :service_id
AND u.user_type = 'provider'
ORDER BY s.price ASC
";
$stmt_others = $pdo->prepare($sql_others);
$stmt_others->execute([
':service_name' => $service['name'],
':location' => $service['location'],
':service_id' => $service_id
]);
$other_providers = $stmt_others->fetchAll();
}
} catch (PDOException $e) {
$error_message = "Si è verificato un errore. Riprova più tardi.";
// In a real app, you would log this error: error_log($e->getMessage());
}
$pageTitle = $service ? htmlspecialchars($service['name']) : "Servizio non trovato";
$pageDescription = $service ? htmlspecialchars(substr($service['description'], 0, 155)) : "";
?>
<!DOCTYPE html>
<html lang="it">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><?= $pageTitle ?> - MeToo</title>
<meta name="description" content="<?= $pageDescription ?>">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.1/font/bootstrap-icons.css">
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
</head>
<body>
<?php include __DIR__ . '/_header.php'; ?>
<main class="container my-5">
<?php if ($error_message): ?>
<div class="alert alert-danger"><?= $error_message ?></div>
<?php elseif (!$service): ?>
<div class="alert alert-warning">Servizio non trovato.</div>
<?php else: ?>
<div class="row">
<div class="col-lg-8">
<div class="card">
<div class="card-body">
<h1 class="card-title h2"><?= htmlspecialchars($service['name']) ?></h1>
<h6 class="card-subtitle mb-3 text-muted"><?= htmlspecialchars($service['category_name']) ?></h6>
<p class="lead"><?= htmlspecialchars($service['description']) ?></p>
<hr>
<p>
<strong>Prezzo:</strong> <?= htmlspecialchars(number_format($service['price'], 2, ',', '.')) ?><br>
<strong>Fornitore:</strong> <?= htmlspecialchars($service['first_name'] . ' ' . $service['last_name']) ?><br>
<strong>Comune:</strong> <?= htmlspecialchars($service['location']) ?>
</p>
</div>
</div>
</div>
<div class="col-lg-4">
<div class="card">
<div class="card-body">
<h5 class="card-title">Migliori fornitori in zona</h5>
<?php if (empty($other_providers)): ?>
<p class="text-muted">Nessun altro fornitore trovato in questa zona per questo servizio.</p>
<?php else: ?>
<ul class="list-group list-group-flush">
<?php foreach ($other_providers as $provider): ?>
<li class="list-group-item d-flex justify-content-between align-items-center">
<?= htmlspecialchars($provider['first_name'] . ' ' . $provider['last_name']) ?>
<span class="badge bg-primary rounded-pill"> <?= htmlspecialchars(number_format($provider['price'], 2, ',', '.')) ?></span>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</div>
</div>
</div>
</div>
<?php endif; ?>
</main>
<?php include __DIR__ . '/_footer.php'; ?>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
<script src="assets/js/main.js?v=<?php echo time(); ?>"></script>
</body>
</html>