-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadministration.php
More file actions
350 lines (270 loc) · 9.65 KB
/
administration.php
File metadata and controls
350 lines (270 loc) · 9.65 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
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
<?php
session_start();
if (isset($_SESSION['account']) && $_SESSION['account']['admin'] == 'oui') {
include('include/display_art_min.php');
include ('include/try_catch.php');
$bdd->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
if (isset($_GET['id']) && !empty($_GET['id'] && isset($_GET['delete'])))
{
if (filter_var($_GET['id'],FILTER_VALIDATE_INT)) {
$supprimer = $bdd->prepare("DELETE FROM articles WHERE id=?");
$supprimer->execute(array(
filter_var($_GET['id'],FILTER_VALIDATE_INT )));
$supprimer->closeCursor();
$errors[] ='<div class="alert alert-success"><strong>L\'article a bien été supprimé</strong></div>';
header('administration.php');
}
}
if (isset($_GET['id']) && !empty($_GET['id']) && isset($_GET['deleteuser']))
{
if (filter_var($_GET['id'],FILTER_VALIDATE_INT)) {
$supprimer = $bdd->prepare("DELETE FROM user WHERE id=?");
$supprimer->execute(array(
filter_var($_GET['id'],FILTER_VALIDATE_INT )));
$supprimer->closeCursor();
$errors[] ='<div class="alert alert-success"><strong>L\'utilisateur a bien été supprimé</strong></div>';
header('administration.php');
}
}
if (isset($_GET['admin']) && isset($_GET['id']) && !empty($_GET['id']))
{
if (filter_var($_GET['id'],FILTER_VALIDATE_INT)) {
$modifier = $bdd->prepare("UPDATE user SET admin=:admin WHERE id=:id");
$modifier->bindParam(":admin", $_GET['admin']);
$modifier->bindParam(":id", $_GET['id']);
$modifier->execute();
$modifier->closeCursor();
$errors[] ='<div class="alert alert-success"><strong>Le status de l\'utilisateur a bien été modifié</strong></div>';
header('administration.php');
}
}
$response = $bdd->query('SELECT * FROM articles ORDER BY id');
$articles = $response->fetchAll(PDO::FETCH_ASSOC);
$response2 = $bdd->query('SELECT * FROM user ORDER BY id');
$users = $response2->fetchAll(PDO::FETCH_ASSOC);
//AJOUT d'ARTICLES
include('include/upload_file.php');
if(!empty($_POST)) // Si les données du formulaire ne sont pas vides
{
if(isset($_POST['title']) AND !empty($_POST['title'])){
// Vérification que le champ TITRE soit conforme à la regex
if(!preg_match('#^[a-z \'\-áàâäãåçéèêëíìîïñóòôöõúùûüýÿæœÁÀÂÄÃÅÇÉÈÊËÍÌÎÏÑÓÒÔÖÕÚÙÛÜÝŸÆŒ0-9]{5,30}$#i', $_POST['title'])){
// Si le champ n'est pas conforme, on créer une erreur dans l'array $errors
$errors[] = '<div class="alert alert-danger"><strong>Titre de l\'artice non valide</strong></div>';
}
} else {
// Si le champ n'existe pas ou est vide, on créer une erreur dans l'array $errors
$errors[] = '<div class="alert alert-warning"><strong>Veuillez renseigner le titre de l\'article</strong></div>';
}
if(isset($_POST['content']) AND !empty($_POST['content'])){
// Vérification que le champ TITRE soit conforme à la regex
} else {
// Si le champ n'existe pas ou est vide, on créer une erreur dans l'array $errors
$errors[] = '<div class="alert alert-warning"><strong>Veuillez renseigner le contenu de l\'article</strong></div>';
}
if(isset($_POST['author']) AND !empty($_POST['author'])){
// Vérification que le champ TITRE soit conforme à la regex
if(!preg_match('#^[a-z \'\-áàâäãåçéèêëíìîïñóòôöõúùûüýÿæœÁÀÂÄÃÅÇÉÈÊËÍÌÎÏÑÓÒÔÖÕÚÙÛÜÝŸÆŒ0-9]{3,30}$#i', $_POST['author'])){
// Si le champ n'est pas conforme, on créer une erreur dans l'array $errors
$errors[] = '<div class="alert alert-danger"><strong>Nom d\'autheur non valide </strong></div>';
}
} else {
// Si le champ n'existe pas ou est vide, on créer une erreur dans l'array $errors
$errors[] = '<div class="alert alert-warning"><strong>Veuillez renseigner le nom de l\'autheur</strong></div>';
}
if((isset($_POST['title']) && !empty($_POST['title'])) && ($_POST['content'] && !empty($_POST['content'])) && ($_POST['author'] && !empty($_POST['author'])) && (isset($_POST['monFichier']) && !empty($_POST['monFichier'])))
{
if(!isset($errors)) // Connexion à la base de donnée avec un prepare et sécurisation des données contre les failles XSS
{
include ('include/try_catch.php');
$bdd->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$response = $bdd->prepare("INSERT INTO articles(title, content, posted, author, picture) VALUES(?,?,?,?,?)");
$response->execute(array(
$_POST['title'],
$_POST['content'],
date("d-m-Y"),
$_POST['author'],
$_POST['monFichier'],
));
$success[] = 'Votre article a bien été ajouté.';
}
else
{
$errors[] = 'Il y a eu un problème durant l\'envoi de l\'article.';
}
}
else
{
$errors[] = "Merci de remplir tous les champs.";
}
}
?>
<!DOCTYPE HTML>
<!--
Future Imperfect by HTML5 UP
html5up.net | @ajlkn
Free for personal and commercial use under the CCA 3.0 license (html5up.net/license)
-->
<html>
<head>
<title>Je suis une bobo</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<!--[if lte IE 8]><script src="assets/js/ie/html5shiv.js"></script><![endif]-->
<link rel="stylesheet" href="assets/css/main.css" />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css">
<!--[if lte IE 9]><link rel="stylesheet" href="assets/css/ie9.css" /><![endif]-->
<!--[if lte IE 8]><link rel="stylesheet" href="assets/css/ie8.css" /><![endif]-->
</head>
<body class="single">
<!-- Wrapper -->
<div id="wrapper">
<!-- Header -->
<header id="header">
<h1><a href="index.php">BLOG D'UNE BOBO</a></h1>
<?php
include ('include/menu.php')
?>
<nav class="main">
<ul>
<li class="menu">
<a class="fa-bars" href="#menu">Menu</a>
</li>
</ul>
</nav>
</header>
<!-- Menu -->
<section id="menu">
<!-- Links -->
<section>
<?php display_articles_min(); ?>
</section>
<!-- Actions -->
<section>
<ul class="actions vertical">
<li><a href="connexion.php" class="button big fit">Se connecter</a></li>
</ul>
</section>
</section>
<!-- Main -->
<section>
<?php
if (isset($alertSuccess)) {
echo $alertSuccess;
}
?>
<h2>Liste des articles</h2>
<table class="table">
<thead>
<tr>
<th>Titre</th>
<th>Contenu</th>
<th>Date de création</th>
<th>Image à la une</th>
<th>Autheur</th>
</tr>
</thead>
<?php
foreach( $articles as $data )
{
?>
<tbody>
<tr>
<th><?php echo htmlspecialchars($data['title']);?></th>
<th><?php echo htmlspecialchars($data['content']);?></th>
<th><?php echo htmlspecialchars($data['posted']);?></th>
<th><?php echo htmlspecialchars($data['picture']);?></th>
<th><?php echo htmlspecialchars($data['author']);?></th>
<th><a href="administration.php?id=<?php echo htmlspecialchars($data['id']);?>&delete=1" onclick="return" class="btn btn-danger">SUPPRIMER</a></th>
</tr>
<?php
}
$response->closeCursor();
?>
</tbody>
</table>
<h2>Liste des utilisateurs</h2>
<table class="table">
<thead>
<tr>
<th>Pseudo</th>
<th>Email</th>
<th>Admin</th>
<th>Supprimer compte</th>
<th>Modification des droits</th>
</tr>
</thead>
<?php
foreach( $users as $data )
{
?>
<tbody>
<tr>
<th><?php echo htmlspecialchars($data['uname']);?></th>
<th><?php echo htmlspecialchars($data['email']);?></th>
<th><?php echo htmlspecialchars($data['admin']);?></th>
<th><a href="administration.php?id=<?php echo htmlspecialchars($data['id']);?>&deleteuser=1" onclick="return" class="btn btn-danger">SUPPRIMER</a></th>
<th>
<a href="administration.php?id=<?php echo htmlspecialchars($data['id']);?>&admin=non" name="simplemember" class="btn btn-warning">Simple membre</a>
<a href="administration.php?id=<?php echo htmlspecialchars($data['id']);?>&admin=oui" name="administrator" class="btn btn-warning">Administrateur</a>
</th>
</tr>
<?php
}
$response->closeCursor();
?>
</tbody>
</table>
<h2>Ajout d'un article</h2>
<?php
if (isset($success)) {
foreach ($success as $success) {
echo $success;
}
}
if (isset($errors)) {
foreach ($errors as $errors) {
echo $errors;
}
}
?>
<form method="post" action="administration.php">
<div class="row uniform">
<div class="6u">
<input type="text" name="title" placeholder="Titre" />
</div>
<div class="6u">
<input type="text" name="content" placeholder="Contenu" />
</div>
<div class="6u">
<input type="text" name="author" placeholder="Autheur" />
</div>
<!-- File Button -->
<div class="form-group">
<label class="col-md-4 control-label" for="filebutton" ></label>
<div class="col-md-4">
<input id="filebutton" name="monFichier" class="input-file" type="file">
</div>
</div>
<ul class="actions">
<li><input type="submit" value="Envoyer" /></li>
<li><input type="reset" value="Reset" /></li>
</ul>
</div>
</form>
</section>
<!-- Footer -->
</div>
<!-- Scripts -->
<script src="assets/js/jquery.min.js"></script>
<script src="assets/js/skel.min.js"></script>
<script src="assets/js/util.js"></script>
<!--[if lte IE 8]><script src="assets/js/ie/respond.min.js"></script><![endif]-->
<script src="assets/js/main.js"></script>
</body>
</html>
<?php }
else
{
echo "Vous n'etes pas connecter ou pas administrateur !";
} ?>