-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbOffice - Users.php
361 lines (320 loc) · 12.8 KB
/
bOffice - Users.php
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
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
<?php
require "bOffice - header.php";
$time = getTimeForLog();
if(isset($_POST["cancelDelete"]) && isset($_SESSION["cancelDelete"])){
foreach ($_SESSION["cancelDelete"] as $key2 => $value2) {
if(!isset($column_name) && (!isset($valuesInserted))){
$columnName = $key2;
$valuesInserted = $value2;
}
elseif($value2 =="")
$value2 = Null;
elseif(is_numeric($value2)){
$columnName = $columnName.",".$key2;
$valuesInserted = $valuesInserted.",".$value2;
}
else{
$columnName = $columnName.",".$key2;
$valuesInserted = $valuesInserted.",'".$value2."'";
}
}
$connection = connectDB();
$query = $connection->prepare("INSERT INTO member(".$columnName.") VALUES(".$valuesInserted.")");
$query->execute();
$file = fopen('logDelete.txt', 'a+');
fwrite($file, $_SESSION["status"]." : ".$_SESSION["name"]." ".$_SESSION["firstName"]." a annulé la suppression du membre ".$_SESSION["cancelDelete"]["member_lastname"]." ".$_SESSION["cancelDelete"]["member_firstname"]." email : ".$_SESSION["cancelDelete"]["member_email"]." le : ".$time."\r\n");
fclose($file);
echo '<center><h2 class="succes">Action effectué : La suppression du membre '.$_SESSION["cancelDelete"]["member_lastname"].' '.$_SESSION["cancelDelete"]["member_firstname"].' a bien été annulé</h2';
unset($_SESSION["cancelDelete"]);
}
if(isset($_POST["emailOfUserDelete"])){
$connection = connectDB();
$query = $connection->prepare("SELECT * FROM member where member_email= :email");
$query->execute([
"email"=>$_POST["emailOfUserDelete"]
]);
$result = $query->fetch(PDO::FETCH_ASSOC);
if(!empty($result)){
$_SESSION["cancelDelete"] = $result;
$cancel = '<form method="POST"><input type="hidden" value="cancel" name="cancelDelete"><button type="submit" class="btn cancelButton">annuler</button></form>';
if($result["member_status"] != 2 && $_SESSION["admin"]){
$query = $connection->prepare("DELETE FROM member where member_email= :email");
$query->execute([
"email"=>$_POST["emailOfUserDelete"]
]);
$file = fopen('logDelete.txt', 'a+');
fwrite($file, $_SESSION["status"]." : ".$_SESSION["name"]." ".$_SESSION["firstName"]." a supprimé le membre ".$result["member_lastname"]." ".$result["member_firstname"]." email : ".$result["member_email"]." le : ".$time."\r\n");
fclose($file);
echo '<center><h2 class="succes">Action effectué : Le membre '.$result["member_lastname"].' '.$result["member_firstname"].' a bien été supprimé</h2>'.$cancel.'</center>';
}
else{
echo '<center><h2 class="erreur">Erreur: Vous n\'avez pas les droits pour effectuer cette action</h2></center>';
}
}
else{
if(isset($_SESSION["cancelDelete"]))
unset($_SESSION["cancelDelete"]);
echo '<center><h2 class="erreur">Erreur: Vous n\'avez pas les droits pour effectuer cette action</h2></center>';
}
}
if(isset($_POST["emailOfUserPromote"])){
$connection = connectDB();
$query = $connection->prepare("SELECT member_status,member_lastname,member_firstname,member_email FROM member where member_email= :email");
$query->execute([
"email"=>$_POST["emailOfUserPromote"]
]);
$result = $query->fetch(PDO::FETCH_ASSOC);
if($result["member_status"] == 0 && $_SESSION["admin"]){
$query = $connection->prepare("UPDATE member set member_status = 1 where member_email= :email");
$query->execute([
"email"=>$_POST["emailOfUserPromote"]
]);
$file = fopen('logPromotion.txt', 'a+');
fwrite($file, $_SESSION["status"]." : ".$_SESSION["name"]." ".$_SESSION["firstName"]." a promu le membre ".$result["member_lastname"]." ".$result["member_firstname"]." email : ".$result["member_email"]." le : ".$time."\r\n");
fclose($file);
echo '<center><h2 class="succes">Action effectué : Le membre '.$result["member_lastname"].' '.$result["member_firstname"].' à bien été promu Modérateur</h2></center>';
}
else{
?>
<center><h2 class="erreur">Erreur: Vous n'avez pas les droits pour effectuer cette action</h2></center>
<?php
}
}
if(isset($_POST["emailOfUserDemote"])){
$connection = connectDB();
$query = $connection->prepare("SELECT member_status,member_lastname,member_firstname,member_email FROM member where member_email= :email");
$query->execute([
"email"=>$_POST["emailOfUserDemote"]
]);
$result = $query->fetch(PDO::FETCH_ASSOC);
if($result["member_status"] == 1 && $_SESSION["admin"]){
$query = $connection->prepare("UPDATE member set member_status = 0 where member_email= :email");
$query->execute([
"email"=>$_POST["emailOfUserDemote"]
]);
$file = fopen('logPromotion.txt', 'a+');
fwrite($file, $_SESSION["status"]." : ".$_SESSION["name"]." ".$_SESSION["firstName"]." a déchu le membre ".$result["member_lastname"]." ".$result["member_firstname"]." email : ".$result["member_email"]." le : ".$time."\r\n");
fclose($file);
echo '<center><h2 class="succes">Action effectué : Le membre '.$result["member_lastname"].' '.$result["member_firstname"].' à bien été déchu Membre</h2></center>';
}
else{
?>
<center><h2 class="erreur">Erreur: Vous n'avez pas les droits pour effectuer cette action</h2></center>
<?php
}
}
if(isset($_POST["emailOfUserUnban"])){
$connection = connectDB();
$query = $connection->prepare("SELECT member_status,member_lastname,member_firstname,member_email FROM member where member_email= :email");
$query->execute([
"email"=>$_POST["emailOfUserUnban"]
]);
$result = $query->fetch(PDO::FETCH_ASSOC);
if($result["member_status"] == 3){
$query = $connection->prepare("UPDATE member set member_status=0 where member_email= :email");
$query->execute([
"email"=>$_POST["emailOfUserUnban"]
]);
$file = fopen('logBan.txt', 'a+');
fwrite($file, $_SESSION["status"]." : ".$_SESSION["name"]." ".$_SESSION["firstName"]." a débanni le membre ".$result["member_lastname"]." ".$result["member_firstname"]." email : ".$result["member_email"]." le : ".$time."\r\n");
fclose($file);
echo '<center><h2 class="succes">Action effectué : Le membre '.$result["member_lastname"].' '.$result["member_firstname"].' à bien été débanni</h2></center>';
}
else{
?>
<center><h2 class="erreur">Erreur: Vous n'avez pas les droits pour effectuer cette action</h2></center>
<?php
}
}
if(isset($_POST["emailOfUserBan"])){
$connection = connectDB();
$query = $connection->prepare("SELECT member_status,member_lastname,member_firstname,member_email FROM member where member_email= :email");
$query->execute([
"email"=>$_POST["emailOfUserBan"]
]);
$result = $query->fetch(PDO::FETCH_ASSOC);
if(($result["member_status"] != 2 && $_SESSION["admin"]) || ($_SESSION["moderateur"] && $result["member_status"] == 0)){
$query = $connection->prepare("UPDATE member set member_status=3 where member_email= :email");
$query->execute([
"email"=>$_POST["emailOfUserBan"]
]);
$file = fopen('logBan.txt', 'a+');
fwrite($file, $_SESSION["status"]." : ".$_SESSION["name"]." ".$_SESSION["firstName"]." a banni le membre ".$result["member_lastname"]." ".$result["member_firstname"]." email : ".$result["member_email"]." le : ".$time."\r\n");
fclose($file);
echo '<center><h2 class="succes">Action effectué : Le membre '.$result["member_lastname"].' '.$result["member_firstname"].' à bien été banni</h2></center>';
}
else{
?>
<center><h2 class="erreur">Erreur: Vous n'avez pas les droits pour effectuer cette action</h2></center>
<?php
}
}
?>
<div>
<table class="table table-striped">
<thead>
<tr>
<th>Nom de famille</th>
<th>Prénom</th>
<th>Email</th>
<th>Statut</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<tr class="notStrip">
<form method="POST">
<td>
<div class="container-fluid row">
<div>
<input type="text" class="form-control" id="searchLastname" placeholder="search" name="searchLastname" value="">
</div>
</div>
</td>
<td>
<div class="container-fluid row">
<div>
<input type="text" class="form-control" id="searchFirstname" placeholder="search" name="searchFirstname" value="">
</div>
</div>
</td>
<td>
<div class="container-fluid row">
<div>
<input type="text" class="form-control" id="searchEmail" placeholder="search" name="searchEmail" value="">
</div>
</div>
</td>
<td>
<div class="container-fluid row">
<div>
<select name="searchStatus" class="form-control">
<option value="All">Tous</option>
<option value="0">Membre</option>
<option value="1">Modérateur</option>
<option value="2">Administrateur</option>
<option value="3">Banni</option>
</select>
</div>
</div>
</td>
<td>
<div>
<div>
<button type="submit" class="btn btn-primary">Rechercher</button>
</div>
</div>
</td>
</form>
</tr>
<?php
if(isset($_POST["searchStatus"]) && $_POST["searchStatus"] == "All")
$_POST["searchStatus"] = Null;
if(empty($_POST["searchLastname"]) && empty($_POST["searchFirstname"]) && empty($_POST["searchEmail"]) && isset($_POST["searchStatus"])){
$connection = connectDB();
$query = $connection->prepare("SELECT member_lastname,member_firstname,member_email,member_status FROM member WHERE member_status = :status");
$query->execute([
"status"=>$_POST["searchStatus"]
]);
}
elseif(!empty($_POST["searchLastname"]) || !empty($_POST["searchFirstname"]) || !empty($_POST["searchEmail"]) || !empty($_POST["searchStatus"])){
$connection = connectDB();
$query = $connection->prepare("SELECT member_lastname,member_firstname,member_email,member_status FROM member WHERE member_lastname= :lastName OR member_firstname= :firstName OR member_email= :email OR member_status= :status");
$query->execute([
"lastName"=>$_POST["searchLastname"],
"firstName"=>$_POST["searchFirstname"],
"email"=>$_POST["searchEmail"],
"status"=>$_POST["searchStatus"]
]);
}
else{
$connection = connectDB();
$query = $connection->prepare("SELECT member_lastname,member_firstname,member_email,member_status FROM member");
$query->execute();
}
$result = $query->fetchAll(PDO::FETCH_ASSOC);
foreach ($result as $value){
echo "<tr>";
foreach ($value as $key => $value2){
if($key == "member_status"){
echo "<td>";
switch ($value2){
case 0:
echo "Membre";
break;
case 1:
echo "Modérateur";
break;
case 2:
echo "Administrateur";
break;
case 3:
echo "Banni";
break;
default:
echo "erreur - statut non existant";
}
echo "</td>";
$statusOfMember = $value2;
}
else{
echo "<td>".$value2."</td>";
}
if($key == "member_email"){
$emailOfMember = $value2;
}
}
$beginButton = '<td><div class="row">';
$endButton = '</div></td></tr>';
$eraseButton = ($_SESSION["admin"])? '<div class="actionButton">
<form method="POST">
<input type="hidden" name="emailOfUserDelete" value='.$emailOfMember.'>
<button type="submit" class="btn deleteButton">Supprimer</button>
</form>
</div>': "";
if(($_SESSION["moderateur"] && $statusOfMember != 1 && $statusOfMember != 3) || ($_SESSION["admin"] && $statusOfMember != 2 && $statusOfMember !=3)){
$banButton ='<div class="actionButton">
<form method="POST">
<input type="hidden" name="emailOfUserBan" value='.$emailOfMember.'>
<button type="submit" class="btn button">Bannir</button>
</form>
</div>';
}
elseif ($statusOfMember == 3) {
$banButton = '<div class="actionButton">
<form method="POST">
<input type="hidden" name="emailOfUserUnban" value='.$emailOfMember.'>
<button type="submit" class="btn button">Débannir</button>
</form>
</div>';
}
else{
$banButton = "";
}
if($statusOfMember == 0 && $_SESSION["admin"]){
$rankButton = '<div class="actionButton">
<form method="POST">
<input type="hidden" name="emailOfUserPromote" value='.$emailOfMember.'>
<button type="submit" class="btn button">Promouvoir</button>
</form>
</div>';
}
elseif($statusOfMember == 1 && $_SESSION["admin"]){
$rankButton = '<div class="actionButton">
<form method="POST">
<input type="hidden" name="emailOfUserDemote" value='.$emailOfMember.'>
<button type="submit" class="btn button">Destituer</button>
</form>
</div>';
}
else{
$rankButton ="";
}
echo ($statusOfMember==2)? "<td></td></tr>": $beginButton.$banButton.$rankButton.$eraseButton.$endButton;
}
?>
</tbody>
</table>
</div>
<?php
include "bOffice - footer.php" ?>