-
Notifications
You must be signed in to change notification settings - Fork 0
/
NewThread.php
75 lines (58 loc) · 1.51 KB
/
NewThread.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
<?php
/**
* Created by PhpStorm.
* User: sinisterdeath
* Date: 8/6/2015
* Time: 10:32 PM
*/
require "/Model/ModelFacade.php";
//redirect if user not logged in
ModelFacade::redirectUnauthorised();
OnRequest();
function OnRequest()
{
ModelFacade::kickIfBannedOrDeleted();
$requestMethod = $_SERVER['REQUEST_METHOD'];
if ($requestMethod == "GET") {
newThreadGet();
} else {
//loginPost("", "");
newThreadPost();
}
$message = "test error";
}
function newThreadGet()
{
$subcategory = ModelFacade::getSubCategory($_GET["subcategory"]);
if ($subcategory == null) {
$message = "Sorry Subcategory with that id does not exist";
include_once('/Views/ErrorPage.html');
} else {
include_once('/Views/NewThread.html');
}
}
function newThreadPost()
{
$subcategory = $_GET["subcategory"];
$title = trim($_POST["title"]);
$content = trim($_POST["content"]);
if (empty($title) or empty($content)) {
checkEmptyValues($title, $content);
} else {
$postId = ModelFacade::insertThread($title, $content, $subcategory, ModelFacade::getLoggedInUser()->id);
header("location:Thread.php?id=" . $postId);
}
}
function checkEmptyValues($title, $content)
{
if (empty($title)) {
$titleReq = "has-warning has-feedback";
$message = true;
}
if (empty($content)) {
$contentReq = "has-warning has-feedback";
$message = true;
}
include_once('/Views/NewThread.html');
}
?>