-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshopping_list.php
More file actions
72 lines (51 loc) · 1.82 KB
/
shopping_list.php
File metadata and controls
72 lines (51 loc) · 1.82 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
<?php
//this is a function to check if the user is an actual user or a visitor
require_once('src/authenticate/requiresLogin.php');
//it can relocate the user if they aren't signed in yet
requiresLogin();
require_once('src/templating/ViewGenerator.php');
require_once('src/model/foodListItem.php');
require_once('src/database_handler/DH_user.php');
require_once('src/model/user.php');
require_once('src/util/FileUploadHandler.php');
$DH = new DH_user();
$user = $DH->getUser($_SESSION["user_id"]);
//after clicking on add new item to the list function
if (isset($_POST["add"])) {
if($_POST["name"] != "" && $_POST["qty"] != ""){
$dest = "";
if(isset($_FILES["img_browse"])){
$uploadHelper = new FileUploadHandler();
$dest = $uploadHelper->handleFile($_FILES["img_browse"],"static/img/uploaded/"); //"static/img/uploaded/" . $_FILES["img_browse"]["name"];
}
$item = new FoodListItem();
$item->picture = $dest;
$item->name = $_POST["name"];
$item->amount = $_POST["qty"];
$user->addItem(0, $item);
$DH->updateUser($user);
}
}
//after clicking on remove button function
if (isset($_POST["delete"])) {
$user->removeItem(0, $_POST["delete"]);
$DH->updateUser($user);
}
//after clicking on modify button function
if (isset($_POST["edit"])) {
//TODO
}
//after clicking on modify button function
if (isset($_POST["toStock"])) {
$movingItem = new FoodListItem();
$movingItem = $user->getItem(0, $_POST["toStock"]);
$user->addItem(1, $movingItem);
$user->removeItem(0, $_POST["toStock"]);
$DH->updateUser($user);
}
if(!empty($_POST)){
header("Location: shopping_list.php");
}
$items = $user->shopping_list;
$generator = new ViewGenerator();
$generator->generate("shopping_list_view", $user->shopping_list);