36735-vm/delete_training_session.php
Flatlogic Bot d076708932 feat: Implement new design and features for the main page
- Redesigned the main page with a modern look and feel.
- Added search and filtering functionality for drills.
- Implemented pagination for browsing drills.
- Added the ability for users to mark drills as favorites.
2025-12-07 18:15:23 +00:00

34 lines
979 B
PHP

<?php
require_once __DIR__ . '/auth.php'; // Corrected path
// Require login
if (!is_logged_in()) {
header('Location: login.php');
exit();
}
$session_id = filter_input(INPUT_GET, 'id', FILTER_VALIDATE_INT);
if (!$session_id) {
header('Location: training_sessions.php');
exit();
}
$coach_id = get_user_id();
require_once __DIR__ . '/db/config.php'; // Ensure db() is available
$pdo = db();
// Verify the session belongs to the current coach before deleting
$stmt = $pdo->prepare("SELECT id FROM training_sessions WHERE id = ? AND coach_id = ?");
$stmt->execute([$session_id, $coach_id]);
$session = $stmt->fetch();
if ($session) {
// The ON DELETE CASCADE on the training_session_drills table will handle deleting the links.
$stmt = $pdo->prepare("DELETE FROM training_sessions WHERE id = ?");
$stmt->execute([$session_id]);
}
// Redirect back to the list with a status message
header('Location: training_sessions.php?status=deleted');
exit();
?>