-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathorders.php
169 lines (166 loc) · 6.19 KB
/
orders.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
<?php require 'config.php' ?>
<?php require 'nav.php' ?>
<?php
if(!isset($_SESSION['username']))
{
if(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on')
$url = "https://";
else
$url = "http://";
$url.= $_SERVER['HTTP_HOST'];
$url.= $_SERVER['REQUEST_URI'];
$_SESSION['back']=$url;
header('Location:'.'signin.php');
}
$accountid=$_SESSION['accountid'];
$sql="select car.id as prodid,car.date as date,cat.name as name,cat.price as price,cat.imagename as img,car.id as id,car.qty as qty,car.total as total from orders as car left join grocerycatalog as cat on car.productid=cat.id and car.custid=$accountid where car.orderfrom='direct' and page='grocery' and car.custid=$accountid;";
$result=$conn->query($sql);
$sql="select car.id as prodid,car.date as date,cat.name as name,cat.price as price,cat.imagename as img,car.id as id,car.qty as qty,car.total as total from orders as car left join grocerycart as cart on car.productid=cart.id left join grocerycatalog as cat on cart.productid=cat.id and car.custid=$accountid where car.orderfrom='cart' and page='grocery' and car.custid=$accountid;";
$result2=$conn->query($sql);
$noitems=$result->num_rows+$result2->num_rows;
?>
<html>
<head>
<link rel="stylesheet" href="css/cart.css" type="text/css" />
</head>
<body onload="calcTotal()">
<div class="allitems">
<?php
while($row = $result->fetch_assoc())
{
$name=$row['name'];
$img=$row['img'];
$date=$row['date'];
$id=$row['id'];
$prodid=$row['id'];
$price=$row['price'];
$qty=$row['qty'];
$total=$row['total'];
$prodid=$row['prodid'];
$idq=$id."qty";
$idp=$id."price";
$idd=$id."dprice";
$idprod=$id."prod";
print <<< END
<div class="item">
<div class="left">
<img src="images/products/$img">
</div>
<div id="$idprod" hidden>$prodid</div>
<div class="right">
<div class="row">
<div class="name">$name</div>
<label class="name">$date</label>
</div>
<div id="$idp" hidden>$price</div>
<div class="row">
<div class="price">$<label id="$idd" class="dprice">$total</label></div>
<div class="qtydiv">
<div class="qty">
<input type="number" name="qty" value="$qty" id="$idq" readonly>
</div>
</div>
</div>
</div>
</div>
END;
}
while($row = $result2->fetch_assoc())
{
$name=$row['name'];
$date=$row['date'];
$img=$row['img'];
$id=$row['id'];
$prodid=$row['id'];
$price=$row['price'];
$qty=$row['qty'];
$total=$row['total'];
$prodid=$row['prodid'];
$idq=$id."qty";
$idp=$id."price";
$idd=$id."dprice";
$idprod=$id."prod";
print <<< END
<div class="item">
<div class="left">
<img src="images/products/$img">
</div>
<div id="$idprod" hidden>$prodid</div>
<div class="right">
<div class="row">
<div class="name">$name</div>
<label class="name">$date</label>
</div>
<div id="$idp" hidden>$price</div>
<div class="row">
<div class="price">$<label id="$idd" class="dprice">$total</label></div>
<div class="qtydiv">
<div class="qty">
<input type="number" name="qty" value="$qty" id="$idq" readonly>
</div>
</div>
</div>
</div>
</div>
END;
}
?>
</div>
<div class="totaldiv">
<div class="row">
<div class="noitems">Number of Items: <label><?php echo $noitems; ?></label></div>
</div>
<div class="row">
<div class="grandtotal">Grand Total: <label>$</label><label id="gtotal"></label></div>
</div>
</div>
</body>
<script type="text/javascript">
function addQty(id)
{
var qty=parseInt(document.getElementById(id+"qty").value);
document.getElementById(id+"qty").value=qty+1;
var price=parseFloat(document.getElementById(id+"price").innerHTML);
document.getElementById(id+"dprice").innerHTML=(qty+1)*price;
calcTotal();
pid=document.getElementById(id+"prod").innerHTML;
window.location.replace("addcart.php?id="+pid+"&qty=1");
}
function subQty(id)
{
var qty=parseInt(document.getElementById(id+"qty").value);
if(qty<=1)
{
return;
}
document.getElementById(id+"qty").value=qty-1;
var price=parseFloat(document.getElementById(id+"price").innerHTML);
document.getElementById(id+"dprice").innerHTML=(qty-1)*price;
calcTotal();
pid=document.getElementById(id+"prod").innerHTML;
window.location.replace("removecart.php?pid="+pid+"&qty="+(qty-1));
}
function calcTotal()
{
var x = document.getElementsByClassName("dprice");
var i;
var total=0;
for (i = 0; i < x.length; i++) {
total+=parseFloat(x[i].innerHTML);
}
document.getElementById("gtotal").innerHTML=total;
}
function buy(id)
{
window.location.replace("buyitemfromcart.php?id="+id);
}
function buyall()
{
window.location.replace("buycart.php");
}
function deleteCart(pid)
{
window.location.replace("deletecart.php?id="+pid);
}
</script>
</html>