36953-vm/admin_exercises.php
2025-12-15 02:05:58 +00:00

172 lines
5.6 KiB
PHP

<?php
require_once 'db/config.php';
// Handle form submission for creating a new exercise
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['create_exercise'])) {
$name = $_POST['name'];
$description = $_POST['description'];
$video_url = $_POST['video_url'];
$muscle_group = $_POST['muscle_group'];
if (!empty($name)) {
$stmt = db()->prepare("INSERT INTO exercises (name, description, video_url, muscle_group) VALUES (?, ?, ?, ?)");
$stmt->execute([$name, $description, $video_url, $muscle_group]);
}
header("Location: admin_exercises.php");
exit;
}
// Handle deletion of an exercise
if (isset($_GET['delete'])) {
$id = $_GET['delete'];
$stmt = db()->prepare("DELETE FROM exercises WHERE id = ?");
$stmt->execute([$id]);
header("Location: admin_exercises.php");
exit;
}
// Fetch all exercises
$stmt = db()->query("SELECT * FROM exercises ORDER BY created_at DESC");
$exercises = $stmt->fetchAll();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Exercise Management</title>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="assets/css/custom.css">
<style>
body {
font-family: 'Inter', sans-serif;
background-color: #f8fafc;
color: #0f172a;
}
.container {
max-width: 1024px;
margin: 0 auto;
padding: 2rem;
}
h1 {
font-size: 2.25rem;
font-weight: 700;
margin-bottom: 2rem;
}
.card {
background-color: #ffffff;
border-radius: 0.5rem;
box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
padding: 2rem;
margin-bottom: 2rem;
}
.form-group {
margin-bottom: 1.5rem;
}
.form-group label {
display: block;
font-weight: 500;
margin-bottom: 0.5rem;
}
.form-group input,
.form-group textarea {
width: 100%;
padding: 0.75rem;
border: 1px solid #e2e8f0;
border-radius: 0.375rem;
}
.btn {
background-color: #14b8a6;
color: #ffffff;
padding: 0.75rem 1.5rem;
border: none;
border-radius: 0.375rem;
font-weight: 600;
cursor: pointer;
transition: background-color 0.3s;
}
.btn:hover {
background-color: #0d9488;
}
.table-container {
overflow-x: auto;
}
table {
width: 100%;
border-collapse: collapse;
}
th, td {
padding: 1rem;
text-align: left;
border-bottom: 1px solid #e2e8f0;
}
th {
background-color: #f1f5f9;
}
.actions a {
color: #f97316;
text-decoration: none;
margin-right: 1rem;
}
.actions a:hover {
text-decoration: underline;
}
</style>
</head>
<body>
<div class="container">
<h1>Exercise Management</h1>
<div class="card">
<h2>Add New Exercise</h2>
<form action="admin_exercises.php" method="POST">
<div class="form-group">
<label for="name">Exercise Name</label>
<input type="text" id="name" name="name" required>
</div>
<div class="form-group">
<label for="description">Description</label>
<textarea id="description" name="description" rows="4"></textarea>
</div>
<div class="form-group">
<label for="video_url">Video URL</label>
<input type="text" id="video_url" name="video_url">
</div>
<div class="form-group">
<label for="muscle_group">Muscle Group</label>
<input type="text" id="muscle_group" name="muscle_group">
</div>
<button type="submit" name="create_exercise" class="btn">Add Exercise</button>
</form>
</div>
<div class="card">
<h2>Exercise Library</h2>
<div class="table-container">
<table>
<thead>
<tr>
<th>Name</th>
<th>Muscle Group</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php foreach ($exercises as $exercise): ?>
<tr>
<td><?php echo htmlspecialchars($exercise['name']); ?></td>
<td><?php echo htmlspecialchars($exercise['muscle_group']); ?></td>
<td class="actions">
<a href="admin_edit_exercise.php?id=<?php echo $exercise['id']; ?>">Edit</a>
<a href="admin_exercises.php?delete=<?php echo $exercise['id']; ?>" onclick="return confirm('Are you sure you want to delete this exercise?');">Delete</a>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
</div>
</body>
</html>