-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathetudiant_controller.php
More file actions
237 lines (203 loc) · 8.45 KB
/
Copy pathetudiant_controller.php
File metadata and controls
237 lines (203 loc) · 8.45 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
<?php
include ('dbconfig.php');
session_start();
if (isset($_POST['modiferEtudiant'])) {
$etudiant_id = $_SESSION['EtudiantID'];
$etudiant_nom = $_POST['etudiant_nom'];
$etudiant_prenom = $_POST['etudiant_prenom'];
$cin = $_POST['CIN'];
$email = $_POST['email'];
$tele = $_POST['tele'];
$adresse = $_POST['adresse'];
$niveau_etude = $_POST['niveau_etude'];
$serie_bac = $_POST['serie_bac'];
$annee_bac = $_POST['annee_bac'];
$intitule_diplome = $_POST['intitule_diplome'];
$annee_diplome = $_POST['annee_diplome'];
$specialite = $_POST['specialite'];
$parcours_souhaite = $_POST['parcours_souhaite'];
$mois_stage = $_POST['mois_stage'];
$experience = $_POST['experience'];
$mot_de_passe = $_POST['ancien_mot_de_passe'];
$nouveau_mot_de_passe = $_POST['nouveau_mot_de_passe'];
if (!empty($mot_de_passe) && !empty($nouveau_mot_de_passe)) {
$query = "SELECT * FROM etudiants WHERE EtudiantID = $etudiant_id AND Password = '$mot_de_passe'";
$query_run = mysqli_query($connection, $query);
if (mysqli_num_rows($query_run) > 0) {
$query = "UPDATE etudiants SET Password = '$nouveau_mot_de_passe' WHERE EtudiantID = $etudiant_id";
$query_run = mysqli_query($connection, $query);
} else {
$_SESSION['status'] = "Mot de passe incorrect";
header('location: etudiant_espace.php');
exit;
}
}
$filename = $_FILES['image']['name'];
if (!empty($filename)) {
$tmp_name = $_FILES['image']['tmp_name'];
$destination = 'upload/images/' . $filename;
$imageFileType = strtolower(pathinfo($destination, PATHINFO_EXTENSION));
if ($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg") {
$_SESSION['status'] = "Le fichier doit être une image";
header('location: etudiant_espace.php');
exit;
} else if ($_FILES['image']['size'] > 6 * 1024 * 1024) {
$_SESSION['status'] = "Le fichier doit être moins de 6 Mo";
header('location: etudiant_espace.php');
exit;
} else {
// Vérification si le fichier existe déjà
if (!file_exists($destination)) {
// Déplacer le fichier vers sa destination avec le nouveau nom
move_uploaded_file($tmp_name, $destination);
$query = "UPDATE etudiants SET Image = '$filename' WHERE EtudiantID = $etudiant_id";
$query_run = mysqli_query($connection, $query);
} else {
// Renommer le fichier avec un nom unique
$new_filename = uniqid() . '_' . $filename;
$destination = 'upload/images/' . $new_filename;
move_uploaded_file($tmp_name, $destination);
$query = "UPDATE etudiants SET Image = '$new_filename' WHERE EtudiantID = $etudiant_id";
$query_run = mysqli_query($connection, $query);
}
}
}
//print all inputs
// foreach ($_POST as $key => $value) {
// echo $key . " : " . $value . "<br>";
// }
if (!empty($etudiant_nom) && !empty($etudiant_prenom) && !empty($cin) && !empty($tele)){
$query = "UPDATE etudiants SET
Etudiant_name = '$etudiant_nom',
Etudiant_prenom = '$etudiant_prenom',
CIN = '$cin',
Email = '$email',
Tele = '$tele',
Adresse = '$adresse',
niveau_etude = '$niveau_etude',
serie_bac = '$serie_bac',
annee_bac = '$annee_bac',
intitule_diplome = '$intitule_diplome',
annee_diplome = '$annee_diplome',
Specialite = '$specialite',
parcours_souhaite = '$parcours_souhaite',
mois_stage = '$mois_stage',
experience = '$experience'
WHERE EtudiantID = $etudiant_id";
$query_run = mysqli_query($connection, $query);
if ($query_run) {
$_SESSION['success'] = "Vos informations ont été mises à jour avec succès.";
header('location: etudiant_espace.php');
} else {
$_SESSION['status'] = "Erreur lors de la mise à jour des informations : " . mysqli_error($connection);
header('location: etudiant_espace.php');
}
} else {
$_SESSION['status'] = "Veuillez remplir tous les champs.";
header('location: etudiant_espace.php');
}
}
if (isset ($_POST['AjouterFichier'])) {
$user_id = $_SESSION['EtudiantID'];
$file_name = $_FILES['file']['name'];
$file_size = $_FILES['file']['size'];
$file_tmp = $_FILES['file']['tmp_name'];
$file_type = strtolower(pathinfo($file_name, PATHINFO_EXTENSION));
$upload_folder = 'upload/diplomes/';
if (empty ($_FILES['file']['name'])) {
$_SESSION['status'] = "Aucun fichier sélectionné";
header('location: etudiant_fichiers.php');
exit;
}
// Check file size and type
if ($file_type !== 'pdf') {
$_SESSION['status'] = "Le fichier doit être un PDF";
header('location: etudiant_fichiers.php');
exit;
}
if ($file_size > 6 * 1024 * 1024) {
$_SESSION['status'] = "Le fichier doit être moins de 6 Mo";
header('location: etudiant_fichiers.php');
exit;
}
// Generate a unique file name
$uniq_file_name = uniqid() . '_' . $file_name;
$path = $upload_folder . $uniq_file_name;
$query = "INSERT INTO fichiers (path, name, userID, uploadDateTime) VALUES ('$path', '$file_name', $user_id, NOW())";
$query_run = mysqli_query($connection, $query);
if ($query_run) {
if (move_uploaded_file($file_tmp, $upload_folder . $uniq_file_name)) {
$_SESSION['success'] = "Le fichier a été ajouté avec succès";
header('location: etudiant_fichiers.php');
} else {
// File not saved
$_SESSION['status'] = "Une erreur s'est produite lors de l'enregistrement du fichier";
header('location: etudiant_fichiers.php');
}
} else {
$_SESSION['status'] = "Une erreur s'est produite lors de l'ajout du fichier";
header('location: etudiant_fichiers.php');
}
}
if (isset ($_POST['supprimerFichier'])) {
$file_id = $_POST['fichierID'];
$file_path = $_POST['fichierPath'];
$query = "DELETE FROM fichiers WHERE fileID = $file_id";
$query_run = mysqli_query($connection, $query);
if ($query_run) {
if (unlink($file_path)) {
$_SESSION['success'] = "Le fichier a été supprimé avec succès";
header('location: etudiant_fichiers.php');
} else {
$_SESSION['status'] = "Une erreur s'est produite lors de la suppression du fichier";
header('location: etudiant_fichiers.php');
}
} else {
$_SESSION['status'] = "Une erreur s'est produite lors de la suppression du fichier";
header('location: etudiant_fichiers.php');
}
}
if (isset ($_POST['downloadFichier'])) {
$file_id = $_POST['fichierID'];
$file_path = $_POST['fichierPath'];
if (file_exists($file_path)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="' . basename($file_path) . '"');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file_path));
readfile($file_path);
exit;
} else {
$_SESSION['status'] = "Le fichier n'existe pas";
header('location: etudiant_fichiers.php');
}
}
// login
if (isset ($_POST['login_btn'])) {
$cin = $_POST['cin'];
$password = $_POST['password'];
$query = "SELECT * FROM etudiants WHERE CIN = '$cin' AND Password = '$password'";
$query_run = mysqli_query($connection, $query);
if (mysqli_num_rows($query_run) > 0) {
// valid
$row = mysqli_fetch_assoc($query_run);
$_SESSION['EtudiantID'] = $row['EtudiantID'];
$_SESSION['Etudiant_name'] = $row['Etudiant_name'];
header('location: etudiant_espace.php');
} else {
// invalid
$_SESSION['status'] = "CIN ou mot de passe incorrect";
header('location: etudiant_log.php');
}
}
// logout
if (isset ($_POST['logout_btn'])) {
session_destroy();
unset($_SESSION['EtudiantID']);
unset($_SESSION['Etudiant_name']);
header('location: etudiant_log.php');
}
?>