Skip to content
Snippets Groups Projects
Commit 7e5e77e6 authored by ZHANG David's avatar ZHANG David
Browse files

Upload New File

parent 11095a5c
No related branches found
No related tags found
No related merge requests found
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
include 'config.php';
session_start();
// Vérification de connexion et rôle
if (!isset($_SESSION['user']) || $_SESSION['user']['role'] !== 'admin') {
header('Location: login.php');
exit;
}
$user = $_SESSION['user'];
// Supprimer une session si une requête POST est envoyée (uniquement si autorisé)
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['delete_session_id'])) {
$session_id = $conn->real_escape_string($_POST['delete_session_id']);
// Supprimer les étudiants liés à cette session
$delete_students = $conn->prepare("DELETE FROM SessionStudent WHERE session_id = ?");
$delete_students->bind_param("i", $session_id);
$delete_students->execute();
// Supprimer la session elle-même
$delete_session = $conn->prepare("DELETE FROM Session WHERE id = ?");
$delete_session->bind_param("i", $session_id);
if ($delete_session->execute()) {
$success = "Session deleted successfully!";
} else {
$error = "Error deleting session: " . $conn->error;
}
$delete_students->close();
$delete_session->close();
}
// Récupérer toutes les sessions avec le nombre d'étudiants inscrits
$sessions = [];
$sql = "
SELECT s.id, s.subject, s.start_time, s.end_time, s.tutor_id,
COUNT(ss.student_id) AS student_count
FROM Session s
LEFT JOIN SessionStudent ss ON s.id = ss.session_id
GROUP BY s.id, s.subject, s.start_time, s.end_time, s.tutor_id
";
$stmt = $conn->prepare($sql);
$stmt->execute();
$result = $stmt->get_result();
while ($row = $result->fetch_assoc()) {
$sessions[] = $row;
}
$stmt->close();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>View All Sessions</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<?php include 'sidebar.php'; ?>
<div class="main-content">
<div class="manage-sessions-admin">
<h1>Toutes les sessions </h1>
<?php if (isset($success)): ?>
<p class="success"><?= htmlspecialchars($success) ?></p>
<?php endif; ?>
<?php if (isset($error)): ?>
<p class="error"><?= htmlspecialchars($error) ?></p>
<?php endif; ?>
<div class="table-container">
<?php if (!empty($sessions)): ?>
<table>
<thead>
<tr>
<th>Subject</th>
<th>Start Time</th>
<th>End Time</th>
<th>Number of Students</th>
<th>Tutor ID</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php foreach ($sessions as $session): ?>
<tr>
<td><?= htmlspecialchars($session['subject']) ?></td>
<td><?= htmlspecialchars(date('d/m/Y H:i', strtotime($session['start_time']))) ?></td>
<td><?= htmlspecialchars(date('H:i', strtotime($session['end_time']))) ?></td>
<td><?= htmlspecialchars($session['student_count']) ?></td>
<td><?= htmlspecialchars($session['tutor_id']) ?></td>
<td>
<form method="POST" style="display:inline;">
<input type="hidden" name="delete_session_id" value="<?= htmlspecialchars($session['id']) ?>">
<button type="submit" onclick="return confirm('Are you sure you want to delete this session?')">Delete</button>
</form>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php else: ?>
<p>No sessions available.</p>
<?php endif; ?>
</div>
<br>
</div>
</body>
</html>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment