-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathitem.php
180 lines (155 loc) · 8.48 KB
/
item.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
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
<?php
session_start();
require_once("dbcontroller.php");
$db_handle = new DBController();
$itemListing = $db_handle->runQuery("SELECT * FROM tree WHERE Code='" . $_GET["Code"] . "'");
if (!empty($_GET["action"])) {
switch ($_GET["action"]) {
case "add":
if (!empty($_POST["quantity"])) {
$productByCode = $db_handle->runQuery("SELECT * FROM tree WHERE Code='" . $_GET["Code"] . "'");
$itemArray = array($productByCode[0]["Code"] => array('Name' => $productByCode[0]["Name"], 'Code' => $productByCode[0]["Code"], 'quantity' => $_POST["quantity"], 'Price' => $productByCode[0]["Price"], 'Image' => $productByCode[0]["Image"]));
if (!empty($_SESSION["cart_item"])) {
if (in_array($productByCode[0]["Code"], array_keys($_SESSION["cart_item"]))) {
foreach ($_SESSION["cart_item"] as $k => $v) {
if ($productByCode[0]["Code"] == $k) {
if (empty($_SESSION["cart_item"][$k]["quantity"])) {
$_SESSION["cart_item"][$k]["quantity"] = 0;
}
$_SESSION["cart_item"][$k]["quantity"] += $_POST["quantity"];
}
}
} else {
$_SESSION["cart_item"] = array_merge($_SESSION["cart_item"], $itemArray);
}
} else {
$_SESSION["cart_item"] = $itemArray;
}
}
break;
}
}
?>
<!doctype html>
<html lang="en">
<head>
<title>Plant a Tree</title>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<script src="https://kit.fontawesome.com/a7d4a476f6.js" crossorigin="anonymous"></script>
<link rel="stylesheet" href="styles/custom-styles.css">
</head>
<body>
<!-- Banner starts -->
<?php include("banner.php"); ?>
<!-- Banner ends -->
<!-- Navbar starts -->
<?php include("nav.php"); ?>
<!-- Navbar ends -->
<div class="row mt-5 ml-5 mr-5">
<div class="col-lg">
<img class="img-thumbnail" src="images/<?php echo $itemListing[0]["Image"]; ?> " />
</div>
<div class="col-lg">
<h1>
<?php
if (!isset($itemListing[0]["Name"])) {
echo "Null item";
} else {
echo $itemListing[0]["Name"];
}
?>
</h1>
<div class="row">
<div class="col mb-3">
<h2>$<?php echo $itemListing[0]["Price"] ?></h2>
</div>
<div class="col align-self-center text-right">
<p>Stock: <?php echo $itemListing[0]["Stock"] ?></p>
</div>
</div>
<nav>
<div class="nav nav-tabs mb-3" id="nav-tab" role="tablist">
<a class="nav-item nav-link active" id="nav-product-tab" data-toggle="tab" href="#nav-product" role="tab" aria-controls="nav-product" aria-selected="true">Product Details</a>
<a class="nav-item nav-link" id="nav-maintenance-tab" data-toggle="tab" href="#nav-maintenance" role="tab" aria-controls="nav-maintenance" aria-selected="false">Maintenance</a>
</div>
</nav>
<div class="tab-content" id="nav-tabContent">
<div class="tab-pane fade show active" id="nav-product" role="tabpanel" aria-labelledby="nav-product-tab">
<h2>Product Details</h2>
<p>
<?php
if ($itemListing[0]["Description"] == null) {
echo "No description has been set for this item.";
} else { ?>
<br><b>Category:</b> <?php echo $itemListing[0]["Category"] ?>
<br><b>Soil Drainage:</b> <?php echo $itemListing[0]["Soil_Drain"] ?>
<br><b>Sun Requirement:</b> <?php echo $itemListing[0]["Sun_Requirement"] ?>
<br><b>Maintenance:</b> <?php echo $itemListing[0]["Maintenance"] ?>
<br><b>Max Height:</b> <?php echo $itemListing[0]["Max_Height"] ?> meters
<br><b>Growth Rate:</b> <?php echo $itemListing[0]["Growth_Rate"] ?>
<br><br>
<b>Description:</b><br>
<?php
echo $itemListing[0]["Description"];
}
?>
</p>
</div>
<div class="tab-pane fade" id="nav-maintenance" role="tabpanel" aria-labelledby="nav-maintenance-tab">
<h2>Maintenance</h2>
<p><br>
<?php
if ($itemListing[0]["Maintenance_Info"] == null) {
echo "No maintenance information has been set for this item.";
} else {
echo $itemListing[0]["Maintenance_Info"];
}
?></p>
</div>
</div>
</div>
</div>
<?php
$product_array = $db_handle->runQuery("SELECT * FROM tree WHERE Code = '" . $_GET["Code"] . "'");
if (!empty($product_array)) {
foreach ($product_array as $key => $value) {
?>
<div class="row mt-5 ml-5 mr-5">
<div class="col-lg">
<!-- Empty space below item image -->
</div>
<div class="col-lg text-center">
<form method="post" action="item.php?action=add&Code=<?php echo $product_array[$key]["Code"]; ?>">
<div class="quantity-panel btn-group">
<button type="button" id="decrease" onclick="decreaseValue()" autocomplete="off" class="btn btn-secondary btn-lg">-</button>
<input type="text" class="btn btn-secondary btn-lg" maxlength="2" size="2" id="number" value="1" Name="quantity">
<button type="button" id="increase" onclick="increaseValue()" autocomplete="off" class="btn btn-secondary btn-lg">+</button>
</div>
<div class="cart-panel mt-3">
<input type="submit" value="Add to Wheelbarrow" class="btnAddAction btn btn-lg btn-primary btn-block mr-1 ml-1"></button>
<button type="button" class="btn btn-primary btn-block btn-lg mr-1 ml-1" onclick="location.href = 'cart.php';">Go to Checkout</button>
</div>
</div>
</div>
</form>
<?php
}
}
?>
<!-- Footer starts here -->
<?php
include("footer.php");
?>
<!-- Footer ends -->
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
<script type="text/javascript" src="counter.js"></script>
</body>
</html>