-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeleteitem.php
executable file
·63 lines (50 loc) · 2.78 KB
/
deleteitem.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
<?php
include "./config.php"; // Import the configuration library.
include "./authentication.php"; // Import the authentication library.
include "./database.php"; // Import the database library.
include "./utils.php"; // Import the utils library.
// Process any GET information submitted.
// Collect any information from the form that may have been submitted.
$location = $_GET["location"]; // This is the location the item is in.
$space = $_GET["space"]; // This is the space the item is in.
$container = $_GET["container"]; // This is the container the item is in.
$item = $_GET["item"]; // This is the name of the item.
$confirm = $_GET["confirm"]; // This is the deletion confirmation.
if ($confirm == "true") {
unset($item_database[$username]["locations"][$location]["spaces"][$space]["containers"][$container]["items"][$item]); // Remove the item from the database.
if (sizeof($item_database[$username]["locations"][$location]["spaces"][$space]["containers"][$container]["items"]) == 0) { // Check to see if this container is now empty.
unset($item_database[$username]["locations"][$location]["spaces"][$space]["containers"][$container]); // Remove the empty container.
}
if (sizeof($item_database[$username]["locations"][$location]["spaces"][$space]["containers"]) == 0) { // Check to see if this space is now empty.
unset($item_database[$username]["locations"][$location]["spaces"][$space]); // Remove the empty space.
}
if (sizeof($item_database[$username]["locations"][$location]["spaces"]) == 0) { // Check to see if this location is now empty.
unset($item_database[$username]["locations"][$location]); // Remove the empty location.
}
save_database($config["database_location"], $item_database, $config); // Save database changes to the disk.
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Home Index</title>
<link rel="stylesheet" type="text/css" href="./styles/main.css">
<link rel="stylesheet" type="text/css" href="./styles/themes/<?php echo $config["theme"]; ?>.css">
</head>
<body>
<main>
<?php
if ($confirm == "true") {
echo "<p>Item deleted</h3>";
echo "<a class='button' href='./index.php'>Back</a>";
} else {
echo "<p>Are you sure you want to delete this item?</h3>";
echo "<a class='button' href='./deleteitem.php?confirm=true&location=" . $location . "&space=" . $space . "&container=" . $container . "&item=" . $item . "'>Confirm</a>";
echo "<a class='button' href='./index.php'>Cancel</a>";
}
?>
</main>
</body>
</html>