-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathitem.php
More file actions
118 lines (99 loc) · 4.13 KB
/
Copy pathitem.php
File metadata and controls
118 lines (99 loc) · 4.13 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
<?php
session_start();
require_once 'bootstrap.php';
//use OWG\Weggeefwinkel\Business\UserService;
//use OWG\Weggeefwinkel\Business\CityService;
use OWG\Weggeefwinkel\Business\ItemService;
use OWG\Weggeefwinkel\Business\SectionService;
use OWG\Weggeefwinkel\Business\UserService;
use OWG\Weggeefwinkel\Business\MessageService;
use OWG\Weggeefwinkel\Entities\Item;
use OWG\Weggeefwinkel\Business\PhotoService;
if (!isset($_SESSION["username"])) {
header("location: login.php");
exit(0);
}
$sectionSvc = new SectionService();
$sectionList = $sectionSvc->getAll();
$itemSvc = new ItemService();
$userSvc = new UserService();
$item = null;
if (isset($_GET["id"])) {
$item = $itemSvc->getById($_GET["id"]);
}
$itemErrors = array();
if (isset($_GET["action"])) {
if ($_GET["action"] == "add") {
if (isset($_POST["addItem"])) {
if (!(isset($_POST["title"]) && isset($_POST["description"])) || $_POST["title"] == "" || $_POST["description"] == "") {
$error = "Titel en omschrijving zijn verplicht";
array_push($itemErrors, $error);
}
if (strlen($_POST["title"]) > 50) {
$error = "Titel mag maximaal 50 karakters bevatten";
array_push($itemErrors, $error);
}
if (strlen($_POST["description"]) > 500) {
$error = "Omschrijving mag maximaal 500 karakters bevatten";
array_push($itemErrors, $error);
}
if (strlen($_FILES["img"]["name"]) > 200) {
$error = "Bestandsnaam mag maximaal 200 karakters bevatten";
array_push($itemErrors, $error);
}
if (sizeof($itemErrors) == 0) {
if (!empty($_FILES["img"]["name"])) {
$photoSvc = new PhotoService();
$photoName = $photoSvc->handlePhoto($_FILES["img"]);
} else {
$photoName = "no-image.png";
}
$user = $userSvc->getByUsername($_SESSION["username"]);
$itemSvc->addItem($_POST["title"], $_POST["description"], $photoName, $_POST["section"], $user->getId());
//header("location: items.php");
//exit(0);
}
}
$view = $twig->render("addItem.twig", array("sectionList" => $sectionList, "username" => $_SESSION["username"], "itemErrors" => $itemErrors));
print($view);
}
//print_r($item);
elseif ($_GET["action"] == "edit") {
if (isset($_POST["submit"])) {
if ($item->getUser()->getUsername() == $_SESSION["username"]) {
if(isset($_POST["imgRemove"])){
$photoName = "no-image.png";
}
elseif (!empty($_FILES["img"]["name"])) {
$photoSvc = new PhotoService();
$photoName = $photoSvc->handlePhoto($_FILES["img"]);
} else {
$photoName = "no-image.png";
}
$itemSvc->updateItem($_GET["id"], $_POST["title"], $_POST["description"], $photoName, $_POST["section"]);
header("location: items.php");
exit(0);
} else {
print "ni van u eh";
}
}
$view = $twig->render("editItem.twig", array("item" => $item, "sectionList" => $sectionList, "username" => $_SESSION["username"]));
print($view);
} elseif ($_GET["action"] == "delete") {
$itemSvc->deleteItem($_GET["id"]);
header("location: items.php");
} elseif ($_GET["action"] == "show") {
if (isset($_POST['send'])) {
//print ("jaja");
$messageSvc = new MessageService();
$messageSvc->writeMessage($_POST['title'], $_POST['text'], $item->getUser(), null);
}
$view = $twig->render("showItem.twig", array("item" => $item, "sectionList" => $sectionList, "username" => $_SESSION["username"]));
print($view);
}
}
//print "jeuj: " . $_SESSION["username"];
else {
$view = $twig->render("showItem.twig", array("item" => $item, "username" => $_SESSION["username"]));
print($view);
}