98 lines
4.1 KiB
PHP
98 lines
4.1 KiB
PHP
<?php
|
|
require_once '../includes/header.php';
|
|
require_once '../db/config.php';
|
|
|
|
// Handle POST requests for creating/deleting packages
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
if (isset($_POST['add_package'])) {
|
|
// Simplified for brevity, will be expanded in edit-package.php
|
|
$name = $_POST['name'];
|
|
$price = $_POST['price'];
|
|
$coach_id = $_POST['coach_id'];
|
|
|
|
$stmt = db()->prepare('INSERT INTO service_packages (name, price, coach_id) VALUES (?, ?, ?)');
|
|
$stmt->execute([$name, $price, $coach_id]);
|
|
header('Location: manage-packages.php');
|
|
exit;
|
|
} elseif (isset($_POST['delete_package'])) {
|
|
$id = $_POST['id'];
|
|
$stmt = db()->prepare('DELETE FROM service_packages WHERE id = ?');
|
|
$stmt->execute([$id]);
|
|
header('Location: manage-packages.php');
|
|
exit;
|
|
}
|
|
}
|
|
|
|
// Fetch all packages
|
|
$packages = db()->query('SELECT sp.*, c.name as coach_name FROM service_packages sp JOIN coaches c ON sp.coach_id = c.id ORDER BY sp.created_at DESC')->fetchAll();
|
|
$coaches = db()->query('SELECT * FROM coaches')->fetchAll();
|
|
|
|
?>
|
|
|
|
<div class="container">
|
|
<h1 class="text-center my-4">Manage Service Packages</h1>
|
|
|
|
<!-- Add Package Form -->
|
|
<div class="card mb-4">
|
|
<div class="card-header">Add New Package</div>
|
|
<div class="card-body">
|
|
<form method="POST">
|
|
<div class="form-group">
|
|
<label for="name">Package Name</label>
|
|
<input type="text" class="form-control" id="name" name="name" required>
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="price">Price</label>
|
|
<input type="number" step="0.01" class="form-control" id="price" name="price" required>
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="coach_id">Coach</label>
|
|
<select class="form-control" id="coach_id" name="coach_id" required>
|
|
<?php foreach ($coaches as $coach): ?>
|
|
<option value="<?= $coach['id'] ?>"><?= htmlspecialchars($coach['name']) ?></option>
|
|
<?php endforeach; ?>
|
|
</select>
|
|
</div>
|
|
<button type="submit" name="add_package" class="btn btn-primary">Add Package</button>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Packages Table -->
|
|
<div class="card">
|
|
<div class="card-header">Existing Packages</div>
|
|
<div class="card-body">
|
|
<table class="table table-bordered">
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Coach</th>
|
|
<th>Price</th>
|
|
<th>Payment Type</th>
|
|
<th>Actions</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php foreach ($packages as $package): ?>
|
|
<tr>
|
|
<td><?= htmlspecialchars($package['name']) ?></td>
|
|
<td><?= htmlspecialchars($package['coach_name']) ?></td>
|
|
<td>$<?= htmlspecialchars($package['price']) ?></td>
|
|
<td><?= htmlspecialchars(ucfirst(str_replace('_', ' ', $package['payment_type']))) ?></td>
|
|
<td>
|
|
<a href="edit-package.php?id=<?= $package['id'] ?>" class="btn btn-sm btn-info">Edit</a>
|
|
<form method="POST" class="d-inline">
|
|
<input type="hidden" name="id" value="<?= $package['id'] ?>">
|
|
<button type="submit" name="delete_package" class="btn btn-sm btn-danger" onclick="return confirm('Are you sure?')">Delete</button>
|
|
</form>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<?php require_once '../includes/footer.php'; ?>
|