-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmin_dashboard.php
More file actions
212 lines (195 loc) · 7.59 KB
/
admin_dashboard.php
File metadata and controls
212 lines (195 loc) · 7.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
<?php
session_start();
require_once 'db.php';
/*Redirection si l'utilisateur n'est pas connecté ou n'est pas administrateur
if (!isset($_SESSION['user_id']) || $_SESSION['role'] !== 'admin') {
header('Location: login.php');
exit;
}*/
// Message pour les actions
$message = '';
// Validation des notes en attente
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['validate_grades'])) {
$grade_id = $_POST['grade_id'];
// Récupération de la note en attente
$sql = "SELECT * FROM pending_grades WHERE id = :id";
$stmt = $pdo->prepare($sql);
$stmt->execute(['id' => $grade_id]);
$grade = $stmt->fetch();
if ($grade) {
// Insertion de la note dans la table grades
$sql_insert = "INSERT INTO grades (student_id, teacher_id, course, grade) VALUES (:student_id, :teacher_id, :course, :grade)";
$stmt_insert = $pdo->prepare($sql_insert);
$stmt_insert->execute([
'student_id' => $grade['student_id'],
'teacher_id' => $grade['teacher_id'],
'course' => $grade['course'],
'grade' => $grade['grade']
]);
// Suppression de la note de la table pending_grades
$sql_delete = "DELETE FROM pending_grades WHERE id = :id";
$stmt_delete = $pdo->prepare($sql_delete);
$stmt_delete->execute(['id' => $grade_id]);
$message = 'Note validée avec succès.';
} else {
$message = 'Erreur lors de la validation de la note.';
}
}
// Ajout d'un nouvel enseignant
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['add_teacher'])) {
$nom_prenom = $_POST['nom_prenom'];
$email = $_POST['email'];
$mdp = password_hash($_POST['mdp'], PASSWORD_DEFAULT);
$matiere = $_POST['matiere'];
// Insertion de l'enseignant dans la table teachers
$sql_insert = "INSERT INTO teachers (nom_prenom, email, mdp, matiere) VALUES (:nom_prenom, :email, :mdp, :matiere)";
$stmt_insert = $pdo->prepare($sql_insert);
$stmt_insert->execute([
'nom_prenom' => $nom_prenom,
'email' => $email,
'mdp' => $mdp,
'matiere' => $matiere
]);
$message = 'Enseignant ajouté avec succès.';
}
?>
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Tableau de bord Admin</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<style>
body {
background-color: #f8f9fa;
font-family: Arial, sans-serif;
}
.container {
margin-top: 50px;
}
h2 {
text-align: center;
margin-bottom: 20px;
}
.alert {
margin-top: 20px;
}
.form-group {
margin-bottom: 15px;
}
.btn-custom {
margin-top: 10px;
}
.nav-link {
margin-right: 15px;
}
.nav-link.active {
font-weight: bold;
color: #1abc9c;
}
</style>
</head>
<body>
<div class="container">
<h2>Tableau de bord Admin</h2>
<nav class="nav">
<a class="nav-link active" href="admin_dashboard.php">Tableau de bord</a>
<a class="nav-link" href="validate_grades.php">Valider les Notes</a>
<a class="nav-link" href="logout.php">Déconnexion</a>
</nav>
<?php if ($message): ?>
<div class="alert alert-info" role="alert">
<?= htmlspecialchars($message) ?>
</div>
<?php endif; ?>
<h3>Ajouter un Enseignant</h3>
<form method="POST">
<div class="form-group">
<label for="nom_prenom">Nom & Prénom</label>
<input type="text" class="form-control" id="nom_prenom" name="nom_prenom" required>
</div>
<div class="form-group">
<label for="email">Email</label>
<input type="email" class="form-control" id="email" name="email" required>
</div>
<div class="form-group">
<label for="mdp">Mot de passe</label>
<input type="password" class="form-control" id="mdp" name="mdp" required>
</div>
<div class="form-group">
<label for="matiere">Matière</label>
<input type="text" class="form-control" id="matiere" name="matiere" required>
</div>
<button type="submit" class="btn btn-primary" name="add_teacher">Ajouter l'Enseignant</button>
</form>
<h3 class="mt-5">Liste des Enseignants</h3>
<table class="table table-striped table-bordered">
<thead class="thead-dark">
<tr>
<th>ID</th>
<th>Nom & Prénom</th>
<th>Email</th>
<th>Matière</th>
</tr>
</thead>
<tbody>
<?php
// Récupérer la liste des enseignants
$sql = "SELECT * FROM teachers";
$stmt = $pdo->prepare($sql);
$stmt->execute();
$teachers = $stmt->fetchAll();
if ($teachers) {
foreach ($teachers as $teacher) {
echo "<tr>";
echo "<td>" . htmlspecialchars($teacher['id_enseignant']) . "</td>";
echo "<td>" . htmlspecialchars($teacher['nom_prenom']) . "</td>";
echo "<td>" . htmlspecialchars($teacher['email']) . "</td>";
echo "<td>" . htmlspecialchars($teacher['matiere']) . "</td>";
echo "</tr>";
}
} else {
echo "<tr><td colspan='4'>Aucun enseignant trouvé.</td></tr>";
}
?>
</tbody>
</table>
<h3 class="mt-5">Travail des Enseignants</h3>
<table class="table table-striped table-bordered">
<thead class="thead-dark">
<tr>
<th>ID Enseignant</th>
<th>Nom & Prénom</th>
<th>Cours</th>
<th>Notes Enregistrées</th>
</tr>
</thead>
<tbody>
<?php
// Récupérer le travail des enseignants
$sql = "SELECT teachers.id_enseignant, teachers.nom_prenom, grades.course, COUNT(grades.id) AS notes_enregistrees
FROM teachers
LEFT JOIN grades ON teachers.id_enseignant = grades.teacher_id
GROUP BY teachers.id_enseignant, teachers.nom_prenom, grades.course";
$stmt = $pdo->prepare($sql);
$stmt->execute();
$teacher_work = $stmt->fetchAll();
if ($teacher_work) {
foreach ($teacher_work as $work) {
echo "<tr>";
echo "<td>" . htmlspecialchars($work['id_enseignant']) . "</td>";
echo "<td>" . htmlspecialchars($work['nom_prenom']) . "</td>";
echo "<td>" . htmlspecialchars($work['course']) . "</td>";
echo "<td>" . htmlspecialchars($work['notes_enregistrees']) . "</td>";
echo "</tr>";
}
} else {
echo "<tr><td colspan='4'>Aucun travail trouvé pour les enseignants.</td></tr>";
}
?>
</tbody>
</table>
</div>
</body>
</html>