-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbasket.php
50 lines (37 loc) · 1.26 KB
/
basket.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
<?php
/// This must come first when we need access to the current session
session_start();;
require("classes/components.php");
require("classes/utils.php");
require("classes/basket.php");
/// Redirect user from this page if they're already logged in
if(!isset($_SESSION["loggedIn"])){
header("Location: " . Utils::$projectFilePath . "/login.php");
}
/**
* Process the POST request to perform actions like removing, increasing, or decreasing quantity of items in the basket.
*/
if($_SERVER["REQUEST_METHOD"] === "POST" &&
isset($_GET["id"]) &&
is_numeric($_GET["id"]) &&
isset($_GET["action"])){
switch ($_GET["action"]){
case "remove":
Basket::remove($_GET["id"]);
break;
case "increase":
Basket::increaseQuantity($_GET["id"]);
break;
case "decrease":
Basket::decreaseQuantity($_GET["id"]);
break;
}
header("Location: " . $_SERVER["PHP_SELF"]);
}
Components::pageHeader($_SESSION["username"] . "'s basket", ["style"], ["mobile-nav"]);
?>
<h2>Basket</h2>
<?php
Components::basketTable(Basket::getFullBasketArray());
Components::pageFooter();
?>