-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgestion_notes_matiere.php
More file actions
256 lines (229 loc) · 10 KB
/
gestion_notes_matiere.php
File metadata and controls
256 lines (229 loc) · 10 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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
<?php
session_start();
require_once "auth_check.php";
require_once "config/database.php";
require_once "models/Note.php";
require_once "models/Etudiant.php";
require_once "models/Matiere.php";
require_once "models/User.php";
$database = new Database();
$db = $database->getConnection();
$note = new Note($db);
$etudiant = new Etudiant($db);
$matiere = new Matiere($db);
$user = new User($db);
// Récupérer la liste des matières selon le type d'utilisateur
if ($_SESSION['user_type'] === 'professeur') {
// Pour un professeur, récupérer uniquement ses matières assignées
$liste_matieres = $user->getProfessorSubjects($_SESSION['user_id']);
} else {
// Pour un admin, récupérer toutes les matières
$matieres = $matiere->read();
$liste_matieres = [];
while ($row = $matieres->fetch(PDO::FETCH_ASSOC)) {
$liste_matieres[] = $row;
}
}
// Vérifier que le professeur a accès à la matière sélectionnée
if ($_SESSION['user_type'] === 'professeur' && $selected_matiere) {
$authorized_subjects = array_column($liste_matieres, 'nom');
if (!in_array($selected_matiere, $authorized_subjects)) {
header("Location: gestion_notes_matiere.php");
exit();
}
}
// Traitement de la mise à jour des notes
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['notes'])) {
try {
$db->beginTransaction();
foreach ($_POST['notes'] as $etudiant_id => $note_data) {
if (!empty($note_data['cc'])) {
$note->etudiant_id = $etudiant_id;
$note->matiere = $selected_matiere;
$note->note = $note_data['cc'];
$note->type_note = 'cc';
$note->date_examen = date('Y-m-d');
if ($note->exists()) {
if (!$note->update()) {
throw new Exception("Erreur lors de la mise à jour de la note CC");
}
} else {
if (!$note->create()) {
throw new Exception("Erreur lors de l'ajout de la note CC");
}
}
}
if (!empty($note_data['sn'])) {
$note->etudiant_id = $etudiant_id;
$note->matiere = $selected_matiere;
$note->note = $note_data['sn'];
$note->type_note = 'sn';
$note->date_examen = date('Y-m-d');
if ($note->exists()) {
if (!$note->update()) {
throw new Exception("Erreur lors de la mise à jour de la note SN");
}
} else {
if (!$note->create()) {
throw new Exception("Erreur lors de l'ajout de la note SN");
}
}
}
$note_finale = (0.7 * $note_data['sn'] + 0.3 * $note_data['cc']);
$note->etudiant_id = $etudiant_id;
$note->matiere = $selected_matiere;
$note->note = $note_finale;
$note->type_note = 'finale'; // Enregistrer comme note finale
$note->date_examen = date('Y-m-d');
if ($note->exists()) {
if (!$note->update()) {
throw new Exception("Erreur lors de la mise à jour de la note finale");
}
} else {
if (!$note->create()) {
throw new Exception("Erreur lors de l'ajout de la note finale");
}
}
}
$db->commit();
$message = "Les notes ont été enregistrées avec succès.";
$message_type = "success";
} catch (Exception $e) {
$db->rollBack();
$message = $e->getMessage();
$message_type = "danger";
$success = false;
}
}
// Récupérer la liste des classes
$classes = $etudiant->getClasses();
// Récupérer la matière et la classe sélectionnées
$selected_matiere = isset($_GET['matiere']) ? $_GET['matiere'] : '';
$selected_class = isset($_GET['classe']) ? $_GET['classe'] : '';
$etab = $_SESSION['etab'] ?? '';
?>
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<title>Gestion des Notes par Matière</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
<style>
.edit-mode td input {
display: block;
}
.edit-mode td span {
display: none;
}
td input {
display: none;
}
</style>
</head>
<body>
<?php include 'header.php'; ?>
<div class="container mt-4">
<h1 class="mb-4">Gestion des Notes par Matière</h1>
<form method="GET" class="row g-3 mb-4">
<div class="col-md-4">
<label for="matiere" class="form-label">Matière</label>
<select name="matiere" id="matiere" class="form-select" required>
<option value="">Sélectionner une matière</option>
<?php foreach ($liste_matieres as $mat): ?>
<option value="<?php echo htmlspecialchars($mat['nom']); ?>" <?php echo $selected_matiere == $mat['nom'] ? 'selected' : ''; ?>>
<?php echo htmlspecialchars($mat['nom']); ?>
</option>
<?php endforeach; ?>
</select>
</div>
<div class="col-md-4">
<label for="classe" class="form-label">Classe</label>
<select name="classe" id="classe" class="form-select" required>
<option value="">Sélectionner une classe</option>
<?php foreach ($classes as $classe): ?>
<option value="<?php echo htmlspecialchars($classe); ?>" <?php echo $selected_class === $classe ? 'selected' : ''; ?>>
<?php echo htmlspecialchars($classe); ?>
</option>
<?php endforeach; ?>
</select>
</div>
<div class="col-md-4">
<label class="form-label"> </label>
<button type="submit" class="btn btn-primary d-block">Afficher</button>
</div>
</form>
<?php if ($selected_matiere && $selected_class):
// Récupérer les étudiants et leurs notes
$etudiants = $etudiant->readByClasse($selected_class, $etab);
?>
<div class="table-responsive">
<table class="table table-bordered">
<thead>
<tr>
<th>Étudiant</th>
<th>Session Normale(SN)</th>
<th>Contrôle Continu(CC)</th>
<th>Note Finale</th>
</tr>
</thead>
<tbody id="studentTable">
<?php while ($row = $etudiants->fetch(PDO::FETCH_ASSOC)):
// Récupérer les notes existantes
$notes = $note->getNotesByEtudiantMatiere($row['id'], $selected_matiere);
$note_cc = $notes['note_cc'];
$note_sn = $notes['note_sn'];
$note_finale = floatval($note_sn) * 0.7 + floatval($note_cc) * 0.3;
echo "<tr data-id='{$row['id']}'>";
echo "<td>{$row['nom']}</td>";
echo "<td><span>{$notes['note_sn']}</span><input type='text' value='{$notes['note_sn']}'></td>";
echo "<td><span>{$notes['note_cc']}</span><input type='text' value='{$notes['note_cc']}'></td>";
echo "<td><span>{$note_finale}</span></td>";
echo "</tr>";
endwhile; ?>
</tbody>
</table>
</div>
<button id="editBtn" class="btn btn-primary mt-3">Modifier les notes</button>
<button id="saveBtn" class="btn btn-primary mt-3" style="display: none;">Enregistrer les notes</button>
<?php endif; ?>
</div>
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script src ="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
<script>
$(document).ready(function() {
$('#editBtn').click(function() {
if (confirm("Êtes-vous sûr de vouloir modifier les notes?")) {
$('#studentTable').addClass('edit-mode');
$('#editBtn').hide();
$('#saveBtn').show();
}
});
$('#saveBtn').click(function() {
$('#studentTable').removeClass('edit-mode');
var notes = {};
$('#studentTable tr').each(function() {
var id = $(this).data('id');
var note_sn = parseFloat($(this).find('td:eq(1) input').val());
var note_cc = parseFloat($(this).find('td:eq(2) input').val());
var note_finale = (note_sn * 0.7 + note_cc * 0.3).toFixed(2);
notes[id] = { sn: note_sn, cc: note_cc, finale: note_finale };
$(this).find('td:eq(1) span').text(note_sn);
$(this).find('td:eq(2) span').text(note_cc);
$(this).find('td:eq(3) span').text(note_finale);
});
$.ajax({
url: 'gestion_notes_matiere.php',
type: 'POST',
data: { notes: notes },
success: function(response) {
alert("Enregistré avec succès !");
}
});
$('#saveBtn').hide();
$('#editBtn').show();
});
});
</script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>