-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathitem.php
More file actions
89 lines (74 loc) · 3.02 KB
/
item.php
File metadata and controls
89 lines (74 loc) · 3.02 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
<?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();
if (isset($_GET["id"])) {
$item = $itemSvc->getById($_GET["id"]);
}
if (isset($_GET["action"])) {
if ($_GET["action"] == "add") {
if (isset($_POST["addItem"])) {
$photoSvc = new PhotoService();
$photoName = $photoSvc->handlePhoto($_FILES["img"]);
$user = $userSvc->getByUsername($_SESSION["username"]);
$itemSvc->addItem($_POST["title"], $_POST["description"], $photoName, $_POST["section"], $user->getId());
header("location: items.php");
exit(0);
} else {
$view = $twig->render("addItem.twig", array("sectionList" => $sectionList, "username" => $_SESSION["username"]));
print($view);
}
}
//print_r($item);
elseif ($_GET["action"] == "edit") {
if (isset($_POST["submit"])) {
if ($item->getUser()->getUsername() == $_SESSION["username"]) {
$photoSvc = new PhotoService();
//print_r($_FILES["img"]);
$photoName = $photoSvc->handlePhoto($_FILES["img"]);
$itemSvc->updateItem($_GET["id"], $_POST["title"], $_POST["description"], $photoName, $_POST["sectionId"]);
/* $itemSvc = new ItemService();
$item = $itemSvc->getById($_GET["id"]); */
header("location: items.php");
exit(0);
//print_r($item);
//$itemUser = $itemSvc->getUser($_GET["id"]);
} 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: account.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);
}