-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontroller.php
More file actions
319 lines (260 loc) · 7.91 KB
/
controller.php
File metadata and controls
319 lines (260 loc) · 7.91 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
<?php
class Controller
{
private $post,
$get,
$session,
$server,
$files;
private $connect;
public function __construct(array $post, array $get, array $session, array $files, array $server)
{
$this->post = $post;
$this->get = $get;
$this->session = $session;
$this->files = $files;
$this->server = $server;
$this->connect = (isset($this->session['pseudo'])) ? true : false;
}
public function __destruct() {
$_SESSION = array_merge($_SESSION, $this->session);
}
public function accueilAction()
{
/***************************************
Récupération des informations nécéssaires pour l'affichage de la page.
***************************************/
$forum = new Forum();
$categories = $forum->getCategories();
$topics = $forum->getTopics();
$stats = $forum->getStats();
/***************************************
Récupération des nouveaux sujets/messages.
***************************************/
foreach ($topics as $i => $topic) {
if ($this->connect) {
$topics[$i]['view'] = (bool)$forum->userRequestViewTopic($this->session['id'], $topic['id']);
}
else {
$topics[$i]['view'] = true;
}
}
/***************************************
Affichage de la page
***************************************/
$title = 'forum';
$content = 'accueil.phtml';
include __ROOT_DIR__ . '/views/index.phtml';
}
public function inscriptionAction()
{
if (!$this->connect) {
$title = 'Inscription';
$content = 'inscription.phtml';
include __ROOT_DIR__ . '/views/index.phtml';
}
else {
$this->session['informationUser'][] = 'Vous êtes déja inscrit ...';
$this->accueilAction();
}
}
public function membresAction()
{
$forum = new Forum();
if ($this->connect) {
$title = 'Membres';
$content = 'membres.phtml';
$membres = $forum->getMembres();
include __ROOT_DIR__ . '/views/index.phtml';
}
else {
$this->session['informationUser'][] = 'Vous devez être connecté pour accéder à cette page.';
$this->accueilAction();
}
}
public function disconnectAction()
{
$connection = new Connection();
$title = 'Disconnect';
$content = 'disconnect.phtml';
$connection->disconnect();
$this->session = array();
$this->connect = (isset($this->session['pseudo'])) ? true : false;
$this->session['informationUser'][] = 'Vous êtes bien déconnecté.';
$this->accueilAction();
}
public function profileAction()
{
if ($this->connect) {
$title = 'Mon profil';
$content = 'profile.phtml';
include __ROOT_DIR__ . '/views/index.phtml';
}
else {
$this->session['informationUser'][] = 'Vous devez être connecté pour accéder à cette page.';
$this->accueilAction();
}
}
public function handlingConnectAction()
{
$connection = new Connection();
$connection->connect($this->post);
$this->session = array_merge($this->session, $_SESSION);
if (isset($this->session['pseudo'])) {
$this->connect = true;
$this->session['informationUser'][] = 'Connexion reussi. Bienvenue '. $this->session['pseudo'] . '.';
}
else {
$this->connect = false;
$this->session['informationUser'][] = 'Echec connection.';
}
$this->accueilAction();
}
public function handlingInscriptionAction()
{
$inscription = new Inscription();
// On test si le formulaire est complet !
$errorMessages = $inscription->formulaireCompleted($this->post);
if (count($errorMessages) > 0) {
// Il y'a des erreurs !
$this->session['informationUser'] = $errorMessages;
$this->inscriptionAction();
}
else {
// On test si l'inscription est possible, pas de doublon présent.
$errorMessages = $inscription->inscriptionFactory($this->post);
if (count($errorMessages) > 0) {
// Il y a des doublons :(
$this->session['informationUser'] = $errorMessages;
$this->inscriptionAction();
}
else {
// On enregistre notre nouveau client/utilisateur.
$inscription->createUser($this->post);
$this->session['informationUser'][] = 'Bravo vous voila inscrit, vous pouvez vous connecter dès à présent.';
$this->accueilAction();
}
}
}
public function topicAction()
{
$forum = new Forum();
if ($this->connect) {
/***************************************
On enregistre le fait que l'utilisateur à vu le topic
***************************************/
$forum->userViewTopic($this->session['id'], $this->get['topicId']);
/***************************************
Affichage de la page
***************************************/
$title = 'Topic';
$content = 'topic.phtml';
$topic = $forum->getTopic($this->get['topicId']);
$messages = $forum->getMessagesTopic($this->get['topicId']);
include __ROOT_DIR__ . '/views/index.phtml';
}
else {
$this->session['informationUser'][] = 'Vous devez être connecté pour accéder à cette page.';
$this->accueilAction();
}
}
public function messageReplyAction()
{
$forum = new Forum();
if ($this->connect) {
/********************************************
Méthodes de réponse aux topics
********************************************/
$topic = $forum->getTopic($this->get['topicId']);
$messages = $forum->getMessagesTopic($this->get['topicId']);
// Test du message
if ($forum->testReply($this->post)) {
// On enregistre le message
if ($forum->createReply($this->post, $this->session['id'], $topic['id'])) {
$this->session['informationUser'][] = 'Votre message à bien été envoyé.';
}
else {
$this->session['informationUser'][] = 'Vous ne pouvez poster qu\'une seule fois votre message.';
}
}
else {
$this->session['informationUser'][] = 'A quoi sert une réponse si celle ci est vide ?';
}
$this->topicAction();
}
else {
$this->session['informationUser'][] = 'Vous devez être connecté pour accéder à cette page.';
$this->accueilAction();
}
}
public function newTopicAction()
{
if ($this->connect) {
$title = 'Nouveau sujet';
$content = 'createTopic.phtml';
$catId = $this->get['categorieId'];
include __ROOT_DIR__ . '/views/index.phtml';
}
else {
$this->session['informationUser'][] = 'Vous devez être connecté pour accéder à cette page.';
$this->accueilAction();
}
}
public function handlingTopicAction()
{
$forum = new Forum();
if ($this->connect) {
if ($forum->testTopic($this->post)) {
// On enregistre le sujet
if ($forum->createTopic($this->post, $this->session['id'], $this->get['categorieId'])) {
$this->session['informationUser'][] = 'Votre sujet à bien été envoyé.';
}
else {
$this->session['informationUser'][] = 'Vous ne pouvez poster qu\'une seule fois votre sujet.';
}
$this->accueilAction();
}
else {
$this->session['informationUser'][] = 'Merci de remplir un titre ainsi qu\'un sujet';
$this->newTopicAction();
}
}
else {
$this->session['informationUser'][] = 'Vous devez être connecté pour accéder à cette page.';
$this->accueilAction();
}
}
public function handlingDeleteMessageAction()
{
$forum = new Forum();
if ($this->connect) {
$forum->deleteMessage($this->get['messageId']);
$this->session['informationUser'][] = 'Message supprimé ...';
$this->topicAction();
}
else {
$this->session['informationUser'][] = 'Vous devez être connecté pour accéder à cette page.';
$this->accueilAction();
}
}
public function uploadAvatarAction()
{
$forum = new Forum();
if ($this->connect) {
if (empty($this->file['avatar'])) {
if (($avatar = $forum->uploadAvatar($this->files['avatar'], $this->session['id'])) !== false) {
$this->session['informationUser'][] = 'Avatar modifié.';
$this->session['avatar'] = $avatar;
}
else {
$this->session['informationUser'][] = 'Erreur lors de l\'upload.';
}
}
$this->profileAction();
}
else {
$this->session['informationUser'][] = 'Vous devez être connecté pour accéder à cette page.';
$this->accueilAction();
}
}
}