-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
executable file
·147 lines (125 loc) · 6.25 KB
/
index.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
<?php
session_start();
require_once('controller/controll.php');
require_once('controller/adminControll.php');
try {
//VARIABLE PGE => ROOT SHEET
if (isset($_GET['pge'])){
//HOME PAGE WITH 5 RECENT ARTICLES
if ($_GET['pge'] === "home"){
$openCtrl = new controll();
if (isset($_POST['numberLoad'])) {
$openCtrl->indexPostView($_POST['numberLoad']);
} else {
$openCtrl->indexPostView();
}
// ABOUT THIS WEBSITE AND LEGAL MENTIONS
} else if ($_GET['pge'] === "about"){
$openCtrl = new controll();
$openCtrl->aboutPge();
//ARTICLE WITH COMMENTS
} else if ($_GET['pge'] === "article"){
$openCtrl = new controll();
if (isset($_GET['idPost']) && isset($_GET['action']) && $_GET['action'] === 'show'){
$idPost = $_GET['idPost'];
//USER ADD A NEW COMMENT ON ARTICLE
if(isset($_POST['comment']) && !empty($_POST['comment'])){
$newComment = htmlspecialchars($_POST['comment']);
$openCtrl->userPublishComment($idPost, $_POST['pseudo'], $newComment);
}
$openCtrl->onePostView($idPost);
//SIGNAL A COMMENT
} else if (isset($_GET['action']) && $_GET['action'] === 'signal') {
$openCtrl = new controll();
if (isset($_GET['idComm']) && isset($_GET['idPost'])){
$openCtrl->userSignalComment($_GET['idPost'], $_GET['idComm']);
} else {
throw new Exception('Erreur, numéro de commentaire ou de billet introuvable');
}
} else {
throw new Exception('Erreur, numéro d\'article ou action introuvable');
}
//ADMINISTRATION PART
} else if ($_GET['pge'] === "admin"){
$adminCtrl = new adminControll();
if (isset($_SESSION['id'])){
if (isset($_GET['action'])){
//CREATE ARTICLE
if ($_GET['action'] === "edit"){
require_once('view/adminPostEdit.php');
//PUBLISH
if (isset($_POST['textEdit']) && !empty($_POST['textEdit'])){
//UPDATE AN EXISTING ARTICLE
if (isset($_GET['idPost']) && isset($_SESSION['wantModify']) && $_SESSION['wantModify'] === true){
$idPost = htmlspecialchars($_GET['idPost']);
$postText = $_POST['textEdit'];
$postTitle = $_POST['titlePostEdit'];
$adminCtrl->adminUpdate($idPost, $postText, $postTitle);
//POST A NEW ARTICLE
}else{
$_SESSION['wantModify'] = false;
$postTitle = $_POST['titlePostEdit'];
$postText = $_POST['textEdit'];
$adminCtrl->adminEdit($postTitle, $postText);
}
}
//CREATE ARTICLE
} else if ($_GET['action'] === "createArticle"){
$_SESSION['wantModify'] = false;
header('Location: index.php?pge=admin&action=edit');
//UPDATE ARTICLE
} else if($_GET['action'] === "updatePost" && isset($_GET['idPost'])){
$adminCtrl->updateArticle($_GET['idPost']);
//DELETE ARTICLE
} else if($_GET['action'] === "delete"){
if(isset($_GET['idPost'])){
$adminCtrl->adminDelPost($_GET['idPost']);
}else{
throw new Exception('Mauvais numéro de billet.');
}
//DELETE COMMENT
} else if($_GET['action'] === "deleteComm"){
if(isset($_GET['idComm']) && isset($_GET['idPost'])){
if (isset($_GET['from'])) {
$from = htmlspecialchars($_GET['from']);
}
$adminCtrl->adminDelComm($_GET['idComm'], $_GET['idPost'], $from);
}else{
throw new Exception('Mauvais numéro de commentaire.');
}
//VIEW SIGNALEMENTS
} else if ($_GET['action'] === "viewSignalement"){
$adminCtrl->viewSignalement();
//VALIDE THE COMMENTS AFTER ADMIN READ
} else if ($_GET['action'] === "validComm"){
if (isset($_GET['idComm'])){
$adminCtrl->validCommSignaled($_GET['idComm']);
}
//LOGOUT THE ADMIN
}else if($_GET['action'] === "logout"){
$adminCtrl->adminLogOut();
}
//WELCOME ADMIN PAGE
} else {
$adminCtrl->indexAdmin();
}
//IF THE LOGIN FORM ARE COMPLETE -> TEST THE IDs
} else if (isset($_POST['idAdmin']) && isset($_POST['pass'])){
$adminCtrl->adminIdRequest($_POST['idAdmin'], $_POST['pass']);
//ADMIN LOGIN FORM
}else{
require('view/login.php');
}
}else{
throw new Exception('Page inconnue :\'(');
}
//HOME PAGE WITH 5 RECENT ARTICLES
} else {
$openCtrl = new controll();
$openCtrl->indexPostView();
}
//ERRORS
} catch (Exception $e) {
$messageError = $e->getMessage();
require("view/errorView.php");
}