forked from Nour-Dev-Paris/Projet-4_OCR
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
171 lines (159 loc) · 6.33 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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
<?php // Routeur - Gestion des requêtes - Appel du bon Controlleur
session_start();
require('..\Projet4\controller\frontend.php');
require('..\Projet4\controller\backend.php');
try
{
if(isset($_GET['action'])) {
if($_GET['action'] == 'loginAdmin') {
$adminLogin = new BackendController();
$admin = $adminLogin->loginAdmin();
return $admin;
}
elseif($_GET['action'] == 'post') {
if (isset($_GET['id']) && $_GET['id'] > 0) {
$postView = new FrontendController();
$viewPost = $postView->post();
return $viewPost;
}
else {
throw new Exception('Aucun identifiant de billet envoyé');
}
}
elseif ($_GET['action'] == 'postReportView') {
$postReportView = new FrontendController();
$reportView = $postReportView->postReportView();
return $reportView;
if(isset($_GET['id']) && $_GET['id'] > 0) {
$postReportView = new FrontendController();
$reportView = $postReportView->postReportView();
}
else
{
throw new Exception('Aucun identifiant de billet envoyé');
}
}
elseif ($_GET['action'] == 'homePage') {
$pageHome = new FrontendController();
$home = $pageHome->homePage();
return $home;
}
elseif($_GET['action'] == 'addComment') {
if (isset($_GET['id']) && $_GET['id'] > 0) {
if (!empty($_POST['author']) && !empty($_POST['comment'])) {
$addComment = new FrontendController();
$addComment->addComment($_GET['id'], $_POST['author'], $_POST['comment']);
}
else
{
throw new Exception('Tous les champs ne sont pas remplis !');
}
}
else
{
throw new Exception('Aucun identifiant de billet envoyé');
}
}
elseif ($_GET['action'] == 'report') {
$reportComment = new FrontendController();
$reportComment->postReport($_GET['id'], $_GET['comment_id']);
}
elseif (isset($_SESSION) && $_SESSION['id'] == '1') {
if($_GET['action'] == 'loginAdmin') {
$adminLogin = new BackendController();
$admin = $adminLogin->loginAdmin();
return $admin;
}
elseif($_GET['action'] == 'createPost') {
$postCreate = new BackendController();
$post = $postCreate->createPost();
return $post;
}
elseif($_GET['action'] == 'updateView') {
$updateView = new BackendController();
$adminUpdateView = $updateView->UpdateView();
return $adminUpdateView;
}
elseif($_GET['action'] == 'updatePostView') {
if(isset($_GET['id']) && $_GET['id'] > 0) {
$updatePostView = new BackendController();
$viewUpdatePost = $updatePostView->submitUpdateView();
}
else
{
throw new Exception('Aucun identifiant de billet envoyé');
}
}
elseif($_GET['action'] == 'updatePost') {
$updatePost = new BackendController();
$updated = $updatePost->submitUpdate($_POST['title'], $_POST['content'], $_GET['id']);
return $updated;
}
elseif($_GET['action'] == 'deletePost') {
$removePost = new BackendController();
$postDelete = $removePost->deletePost($_GET['id']);
return $postDelete;
}
elseif($_GET['action'] == 'adminView') {
$adminReturn = new BackendController();
$return = $adminReturn->adminView();
return $return;
}
elseif ($_GET['action'] == 'postAdmin') {
if (!empty($_POST['title']) && !empty($_POST['content'])) {
$submitPostAdmin = new BackendController();
$submitPostAdmin->newPost($_POST['title'], $_POST['content']);
}
else
{
throw new Exception('Tous les champs ne sont pas remplis !');
}
}
elseif($_GET['action'] == 'commentManageView') {
$commentViewManage = new BackendController();
$commentView = $commentViewManage->commentManageView();
return $commentView;
}
elseif($_GET['action'] == 'commentManage') {
if(isset($_GET['id']) && $_GET['id'] > 0) {
$updateReportView = new BackendController();
$viewUpdateReport = $updateReportView->submitReportView();
}
else
{
throw new Exception('Aucun identifiant de commentaire envoyé');
}
}
elseif($_GET['action'] == 'updateReport') {
$updateReport = new BackendController();
$reportUpdated = $updateReport->reportUpdate($_POST['title'], $_POST['content'], $_GET['id']);
return $reportUpdated;
}
elseif($_GET['action'] == 'deleteComment') {
$removeComment = new BackendController();
$commentDelete = $removeComment->deleteComment($_GET['id']);
return $commentDelete;
}
elseif($_GET['action'] == 'sessionStop') {
$removeSession = new BackendController();
$sessionStop = $removeSession->sessionStop();
return $sessionStop;
}
}
elseif ($_GET['action'] == 'listPosts') {
$listPost = new FrontendController();
$posts = $listPost->listPosts();
return $posts;
}
}
else
{
$pageHome = new FrontendController();
$home = $pageHome->homePage();
return $home;
}
}
catch(Exception $e)
{
echo 'Erreur : ' . $e->getMessage();
}