156 lines
6.7 KiB
PHP
156 lines
6.7 KiB
PHP
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Admin - Manage Restaurants</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.3/font/bootstrap-icons.min.css">
|
|
<link rel="preconnect" href="https://fonts.googleapis.com">
|
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
|
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600;700&display=swap" rel="stylesheet">
|
|
<style>
|
|
body {
|
|
font-family: 'Poppins', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
|
|
background-color: #F8F9FA;
|
|
color: #212529;
|
|
}
|
|
.btn-primary {
|
|
background-color: #FF6347;
|
|
border-color: #FF6347;
|
|
}
|
|
.btn-primary:hover {
|
|
background-color: #E5533D;
|
|
border-color: #E5533D;
|
|
}
|
|
.table {
|
|
background-color: #FFFFFF;
|
|
border-radius: 0.5rem;
|
|
box-shadow: 0 0.125rem 0.25rem rgba(0,0,0,0.075);
|
|
}
|
|
.card {
|
|
border-radius: 0.5rem;
|
|
}
|
|
.modal-content {
|
|
border-radius: 0.5rem;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
|
|
<div class="container mt-5">
|
|
<div class="d-flex justify-content-between align-items-center mb-4">
|
|
<h1>Manage Restaurants</h1>
|
|
<button class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#addRestaurantModal">
|
|
<i class="bi bi-plus-lg"></i> Add New Restaurant
|
|
</button>
|
|
</div>
|
|
|
|
<div class="card">
|
|
<div class="card-body">
|
|
<table class="table table-hover">
|
|
<thead>
|
|
<tr>
|
|
<th>ID</th>
|
|
<th>Name</th>
|
|
<th>Address</th>
|
|
<th>Phone</th>
|
|
<th>Email</th>
|
|
<th>Actions</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php
|
|
require_once 'db/config.php';
|
|
try {
|
|
$pdo = db();
|
|
$stmt = $pdo->query("SELECT * FROM restaurants ORDER BY id DESC");
|
|
$restaurants = $stmt->fetchAll();
|
|
foreach ($restaurants as $restaurant) {
|
|
echo "<tr>";
|
|
echo "<td>" . htmlspecialchars($restaurant['id']) . "</td>";
|
|
echo "<td>" . htmlspecialchars($restaurant['name']) . "</td>";
|
|
echo "<td>" . htmlspecialchars($restaurant['address']) . "</td>";
|
|
echo "<td>" . htmlspecialchars($restaurant['phone']) . "</td>";
|
|
echo "<td>" . htmlspecialchars($restaurant['email']) . "</td>";
|
|
echo '<td>
|
|
<button class="btn btn-sm btn-secondary"><i class="bi bi-pencil"></i></button>
|
|
<button class="btn btn-sm btn-danger"><i class="bi bi-trash"></i></button>
|
|
</td>';
|
|
echo "</tr>";
|
|
}
|
|
} catch (PDOException $e) {
|
|
echo "<tr><td colspan='6'>Error: " . $e->getMessage() . "</td></tr>";
|
|
}
|
|
?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Add Restaurant Modal -->
|
|
<div class="modal fade" id="addRestaurantModal" tabindex="-1" aria-labelledby="addRestaurantModalLabel" aria-hidden="true">
|
|
<div class="modal-dialog">
|
|
<div class="modal-content">
|
|
<div class="modal-header">
|
|
<h5 class="modal-title" id="addRestaurantModalLabel">Add New Restaurant</h5>
|
|
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
|
</div>
|
|
<div class="modal-body">
|
|
<form id="addRestaurantForm">
|
|
<div class="mb-3">
|
|
<label for="name" class="form-label">Restaurant Name</label>
|
|
<input type="text" class="form-control" id="name" name="name" required>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="address" class="form-label">Address</label>
|
|
<textarea class="form-control" id="address" name="address" rows="3" required></textarea>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="phone" class="form-label">Phone Number</label>
|
|
<input type="text" class="form-control" id="phone" name="phone" required>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="email" class="form-label">Contact Email</label>
|
|
<input type="email" class="form-control" id="email" name="email" required>
|
|
</div>
|
|
<button type="submit" class="btn btn-primary">Save Restaurant</button>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
|
<script>
|
|
document.getElementById('addRestaurantForm').addEventListener('submit', function(e) {
|
|
e.preventDefault();
|
|
|
|
const formData = new FormData(this);
|
|
const data = Object.fromEntries(formData.entries());
|
|
|
|
fetch('api/restaurants.php?action=create', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
},
|
|
body: JSON.stringify(data),
|
|
})
|
|
.then(response => response.json())
|
|
.then(result => {
|
|
if (result.success) {
|
|
location.reload();
|
|
} else {
|
|
alert('Error: ' + result.error);
|
|
}
|
|
})
|
|
.catch(error => {
|
|
console.error('Error:', error);
|
|
alert('An unexpected error occurred.');
|
|
});
|
|
});
|
|
</script>
|
|
|
|
</body>
|
|
</html>
|