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;
right: 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 {
@ -37,16 +37,16 @@ body {
}
.btn-primary {
background-color: #007BFF;
border-color: #007BFF;
background-color: #20de6e;
border-color: #20de6e;
padding: 0.75rem 1.5rem;
border-radius: 0.5rem;
font-weight: 600;
}
.btn-primary:hover {
background-color: #0056b3;
border-color: #0056b3;
background-color: #18b35a;
border-color: #18b35a;
}
.how-it-works {
@ -55,7 +55,7 @@ body {
.step-icon {
font-size: 3rem;
color: #007BFF;
color: #20de6e;
}
/* Auth pages styling */
@ -67,3 +67,24 @@ body {
transform: translateY(-5px);
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
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>
<html lang="it">
@ -68,12 +59,10 @@ try {
</div>
</div>
<div class="col-lg-4">
<select class="form-select border-0" name="category">
<option value="">Tutte le categorie</option>
<?php foreach ($search_categories as $category): ?>
<option value="<?= $category['id'] ?>"><?= htmlspecialchars($category['name']) ?></option>
<?php endforeach; ?>
</select>
<div class="input-group">
<span class="input-group-text bg-transparent border-0"><i class="bi bi-geo-alt"></i></span>
<input type="text" class="form-control border-0" name="location" placeholder="Comune">
</div>
</div>
<div class="col-lg-2">
<button type="submit" class="btn btn-primary w-100">Cerca</button>

View File

@ -9,6 +9,7 @@ $success = null;
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$name = trim($_POST['name'] ?? '');
$email = trim($_POST['email'] ?? '');
$location = trim($_POST['location'] ?? '');
$password = $_POST['password'] ?? '';
$confirm_password = $_POST['confirm_password'] ?? '';
@ -17,7 +18,7 @@ if ($_SERVER["REQUEST_METHOD"] == "POST") {
$first_name = $name_parts[0];
$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.";
} elseif ($password !== $confirm_password) {
$error = "Le password non coincidono.";
@ -37,9 +38,9 @@ if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Insert the new user
$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.";
} else {
$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>
<input type="email" class="form-control" id="email" name="email" required value="<?= htmlspecialchars($email ?? '') ?>">
</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">
<label for="password" class="form-label">Password</label>
<input type="password" class="form-control" id="password" name="password" required>

View File

@ -1,81 +1,108 @@
<?php
require_once 'db/config.php';
$q = trim($_GET['q'] ?? '');
$category_id = $_GET['category'] ?? null;
$pageTitle = "Risultati della ricerca";
$pageDescription = "Servizi trovati per la tua ricerca.";
$query = $_GET['q'] ?? '';
$location = $_GET['location'] ?? '';
$results = [];
$error = null;
try {
if (!empty($query) || !empty($location)) {
try {
$pdo = db();
$sql = "SELECT s.*, u.first_name, u.last_name, sc.name as category_name
$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 sc ON s.category_id = sc.id
WHERE u.user_type = 'provider'";
JOIN service_categories c ON s.category_id = c.id
WHERE u.user_type = 'provider'
";
$params = [];
if (!empty($q)) {
$sql .= " AND (s.name LIKE ? OR s.description LIKE ?)";
$params[] = "%$q%";
$params[] = "%$q%";
if (!empty($query)) {
$sql .= " AND (s.name LIKE :query OR s.description LIKE :query)";
$params[':query'] = '%' . $query . '%';
}
if (!empty($category_id)) {
$sql .= " AND s.category_id = ?";
$params[] = $category_id;
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) {
$error = "Errore del database: " . $e->getMessage();
} catch (PDOException $e) {
// In a real app, you would log this error.
$error_message = "Si è verificato un errore durante la ricerca. Riprova più tardi.";
}
}
require_once '_header.php';
?>
<main class="container my-5">
<h1 class="mb-4">Ricerca servizi</h1>
<!DOCTYPE html>
<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">
<div class="card-body">
<?php include __DIR__ . '/_header.php'; ?>
<main class="container my-5">
<h1 class="mb-4">Risultati della ricerca</h1>
<div class="row mb-4">
<div class="col">
<form action="search.php" method="GET" class="row g-3">
<div class="col-md-8">
<input type="text" class="form-control" name="q" placeholder="Cosa stai cercando?" value="<?= htmlspecialchars($q) ?>">
<div class="col-md-6">
<input type="text" class="form-control" name="q" placeholder="Che servizio cerchi?" value="<?= htmlspecialchars($query) ?>">
</div>
<div class="col-md-4">
<button type="submit" class="btn btn-primary w-100">Cerca di nuovo</button>
<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>
<?php if ($error): ?>
<div class="alert alert-danger"><?= htmlspecialchars($error) ?></div>
<?php if (isset($error_message)): ?>
<div class="alert alert-danger"><?= $error_message ?></div>
<?php elseif (empty($results)): ?>
<div class="alert alert-info">Nessun servizio trovato per la tua ricerca.</div>
<div class="alert alert-info">
Nessun servizio trovato per "<?= htmlspecialchars($query) ?>" <?= !empty($location) ? 'a ' . htmlspecialchars($location) : '' ?>. Prova a modificare i criteri di ricerca.
</div>
<?php else: ?>
<p class="text-muted">Trovati <?= count($results) ?> risultati.</p>
<div class="row g-4">
<div class="row row-cols-1 row-cols-md-2 row-cols-lg-3 g-4">
<?php foreach ($results as $service): ?>
<div class="col-md-6 col-lg-4">
<div class="col">
<div class="card h-100">
<div class="card-body d-flex flex-column">
<div class="card-body">
<h5 class="card-title"><?= htmlspecialchars($service['name']) ?></h5>
<h6 class="card-subtitle mb-2 text-muted"><?= htmlspecialchars($service['category_name']) ?></h6>
<p class="card-text flex-grow-1"><?= nl2br(htmlspecialchars(substr($service['description'], 0, 100))) . (strlen($service['description']) > 100 ? '...' : '') ?></p>
<p class="fs-5 fw-bold text-end mb-3"> <?= htmlspecialchars(number_format($service['price'], 2, ',', '.')) ?></p>
<div class="mt-auto">
<p class="mb-1"><small>Offerto da: <?= htmlspecialchars($service['first_name'] . ' ' . $service['last_name']) ?></small></p>
<a href="#" class="btn btn-primary w-100 disabled">Vedi Dettagli</a>
</div>
<p class="card-text"><?= htmlspecialchars(substr($service['description'], 0, 100)) ?>...</p>
<p class="card-text">
<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>
@ -83,7 +110,11 @@ require_once '_header.php';
</div>
<?php endif; ?>
</main>
<?php
require_once '_footer.php';
?>
</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>

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>