-
Notifications
You must be signed in to change notification settings - Fork 0
/
add.php
113 lines (100 loc) · 2.84 KB
/
add.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
<?php
session_start();
$seperator = "{||}";
/*-------------------------
Methods to Add products to the order.
--------------------------*/
if(isset($_SESSION["Plants"]) && $_SESSION["Plants"] != ""){
$plants = $_SESSION["Plants"];
$numbers = $_SESSION["Number"];
$cartPrice = $_SESSION["CartPrice"];
$cartNum = (int)$_SESSION["CartNum"];
$arrPlants = array();
$arrPlants = explode($seperator,$plants);
$arrNums = array();
$arrNums = explode($seperator,$numbers);
$count = 0;
$match = "false";
/*-------------------------
Loops for a plant match.
If it matches it increments the plants count by 1.
--------------------------*/
while($count < count($arrPlants)){
if((int)$arrPlants[$count] == (int)$id){
$arrNums[$count] = (int)$arrNums[$count];
$arrNums[$count]++;
$match = "true";
}
}
/*-------------------------
If no match then append new plant on end of both arrays.
--------------------------*/
if($match == "false"){
$num = count($arrPlants) + 1;
$arrPlants[$num] .= $seperator . $id;
$arrNums[$num] .= $seperator . "1";
}
include("php/dblogin.php");
$sql = "select * from plants";
$parse = oci_parse($connect,$sql);
if(!$parse){
echo "Error Parsing SQL statement";
exit;
}
oci_execute($parse);
$plantID = $_POST["id"];
while(oci_fetch_array($parse)){
$id = oci_result($parse,"ID");
$plantPrice = oci_result($parse,"PRICE");
if($plantID == $id){
$cartPrice += $plantPrice;
$cartNum += 1;
break;
}
}
oci_close($connect);
/*-------------------------
Turn arrays back into strings then set the SESSION variables.
--------------------------*/
$plants = implode($seperator,$arrPlants);
$numbers = implode($seperator,$arrNums);
$_SESSION["Plants"] = $plants;
$_SESSION["Number"] = $numbers;
$_SESSION["CartPrice"] = $cartPrice;
$_SESSION["CartNum"] = $cartNum;
}
else{
/*-------------------------
If Plants SESSION variable is not set.
--------------------------*/
include("php/dblogin.php");
$sql = "select * from plants";
$parse = oci_parse($connect,$sql);
if(!$parse){
echo "Error Parsing SQL statement";
exit;
}
oci_execute($parse);
$plantID = $_POST["id"];
while(oci_fetch_array($parse)){
$id = oci_result($parse,"ID");
$plantPrice = oci_result($parse,"PRICE");
if($plantID == $id){
$price = $plantPrice;
break;
}
}
oci_close($connect);
$_SESSION["Plants"] = "";
$_SESSION["Number"] = "";
$_SESSION["CartPrice"] = 0;
$_SESSION["CartNum"] = 0;
$_SESSION["Plants"] = "$plantID";
$_SESSION["Number"] = "1";
$_SESSION["CartPrice"] = $price;
$_SESSION["CartNum"] = 1;
}
/*-------------------------
Comment layout
--------------------------*/
?>