121 lines
4.7 KiB
PHP
121 lines
4.7 KiB
PHP
<?php
|
|
require_once 'db/config.php';
|
|
|
|
$errorMessage = null;
|
|
$successMessage = null;
|
|
|
|
$venue_id = filter_input(INPUT_GET, 'id', FILTER_VALIDATE_INT);
|
|
if (!$venue_id) {
|
|
header("Location: venues.php");
|
|
exit;
|
|
}
|
|
|
|
// Handle form submission for editing the venue
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['edit_venue'])) {
|
|
$name = trim($_POST['name'] ?? '');
|
|
$description = trim($_POST['description'] ?? '');
|
|
$capacity = filter_input(INPUT_POST, 'capacity', FILTER_VALIDATE_INT);
|
|
$features = trim($_POST['features'] ?? '');
|
|
|
|
if (empty($name) || $capacity === false || $capacity <= 0) {
|
|
$errorMessage = "Error: Venue name and a valid capacity are required.";
|
|
} else {
|
|
try {
|
|
$pdo = db();
|
|
$stmt = $pdo->prepare('UPDATE venues SET name = ?, description = ?, capacity = ?, features = ? WHERE id = ?');
|
|
$stmt->execute([$name, $description, $capacity, $features, $venue_id]);
|
|
header("Location: venues.php?success=3");
|
|
exit;
|
|
} catch (PDOException $e) {
|
|
$errorMessage = "Error: Could not update the venue. " . $e->getMessage();
|
|
}
|
|
}
|
|
}
|
|
|
|
// Fetch the venue to edit
|
|
$venue = null;
|
|
try {
|
|
$pdo = db();
|
|
$stmt = $pdo->prepare('SELECT * FROM venues WHERE id = ?');
|
|
$stmt->execute([$venue_id]);
|
|
$venue = $stmt->fetch(PDO::FETCH_ASSOC);
|
|
} catch (PDOException $e) {
|
|
$errorMessage = "Error: Could not fetch venue details.";
|
|
}
|
|
|
|
if (!$venue) {
|
|
header("Location: venues.php");
|
|
exit;
|
|
}
|
|
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Edit Venue - The Best Events</title>
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
<link rel="stylesheet" href="assets/css/custom.css">
|
|
</head>
|
|
<body>
|
|
|
|
<nav class="navbar navbar-expand-lg navbar-light bg-light">
|
|
<div class="container-fluid">
|
|
<a class="navbar-brand" href="index.php">The Best Events</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">
|
|
<li class="nav-item">
|
|
<a class="nav-link" href="index.php">Home</a>
|
|
</li>
|
|
<li class="nav-item">
|
|
<a class="nav-link" href="venues.php">Venues</a>
|
|
</li>
|
|
<li class="nav-item">
|
|
<a class="nav-link" href="vendors.php">Vendors</a>
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
</nav>
|
|
|
|
<main class="container mt-4">
|
|
<h1 class="mb-4">Edit Venue</h1>
|
|
|
|
<?php if ($errorMessage): ?>
|
|
<div class="alert alert-danger">
|
|
<?= htmlspecialchars($errorMessage) ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<form action="edit-venue.php?id=<?= $venue_id ?>" method="POST">
|
|
<input type="hidden" name="edit_venue" value="1">
|
|
<div class="mb-3">
|
|
<label for="name" class="form-label">Venue Name</label>
|
|
<input type="text" class="form-control" id="name" name="name" value="<?= htmlspecialchars($venue['name']) ?>" required>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="description" class="form-label">Description</label>
|
|
<textarea class="form-control" id="description" name="description" rows="3"><?= htmlspecialchars($venue['description']) ?></textarea>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="capacity" class="form-label">Capacity</label>
|
|
<input type="number" class="form-control" id="capacity" name="capacity" value="<?= htmlspecialchars($venue['capacity']) ?>" required>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="features" class="form-label">Features</label>
|
|
<input type="text" class="form-control" id="features" name="features" value="<?= htmlspecialchars($venue['features']) ?>" placeholder="e.g., WiFi, Projector, Catering Available">
|
|
</div>
|
|
<button type="submit" class="btn btn-success">Save Changes</button>
|
|
<a href="venues.php" class="btn btn-secondary">Cancel</a>
|
|
</form>
|
|
|
|
</main>
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
|
|
</body>
|
|
</html>
|