-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshop2.php
More file actions
386 lines (292 loc) · 8.48 KB
/
Copy pathshop2.php
File metadata and controls
386 lines (292 loc) · 8.48 KB
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
<!DOCTYPE html>
<!-- shopping.php
NEW UPDATE FIX POP-UP 05/19/2017
~~updated to fix bugs for ordering04/12/17 X
-->
<html>
<head><title>Order Process</title>
<!-- -->
<style>
body {
background-image: url("theme2.jpg")
}
/* My CSS stuff from previous index*/
h1{
color: #000;
font-style: bold;
}
p{
color: #000;
background-color: #ffe0cc;
}
.content.ui{
color: black;
display: block;
}
table{
font-family: arial, sans-serif;
border-collapse: collapse;
width: 50%;
background-color: #e6e6e6;
}
tr:nth-child(even) {
background-color: #ffe0cc;
}
td{
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}
td:hover{
background-color:#ff6600;
}
th:hover{
background-color:#ff6600;
}
th {
background-color:#ff6600;
color: white;
}
body{
background-repeat /*no-repeat; */
}
ul{
color: black;
display: block;
list-style-type: disc;
margin-top: 1em;
margin-bottom: 1 em;
margin-left: 0;
margin-right: 0;
padding-left: 40px;
}
hr{
width: 60%;
}
/*
*
*
*
*/
/* Rest of the CSS stuff*/
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #ff6600;
}
li {
float: left;
}
li a, .dropbtn {
display: inline-block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
li a:hover, .dropdown:hover .dropbtn {
background-color: #ffe0cc;
}
li.dropdown {
display: inline-block;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
}
.dropdown-content a {
color: #ff6600;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
.dropdown-content a:hover {background-color: #f1f1f1}
.dropdown:hover .dropdown-content {
display: block;
}
</style>
</head>
<body>
<ul>
<li><a class="active" href="dropdown.html">Home</a></li>
<li><a href="shop2.php">Shop</a></li>
<li style="float:right"><a href="signin.html">SignIn</a></li>
<li style="float:right"><a href="about.html">About</a></li> <li class="dropdown">
<a href="#" class="dropbtn">Products</a>
<div class="dropdown-content">
<a href="dropdown1.html">Viron Smartphone</a>
<a href="dropdown2.html">VironTab</a>
<a href="dropdown3.html">VironBook</a>
</div>
</li>
</ul>
<!--- --> <!--
<body bgcolor ="orange"> -->
<?php
$q1 = $_POST["quan1"];
$q2 = $_POST["quan2"];
$dvd1 = "Viron";
$dvd2 = "VironXL";
$q3 = $_POST["quan3"];
$q4 = $_POST["quan4"];
$dvd3 = "VironTab";
$dvd4 = "VironBook";
$file =fopen("inv.txt", "r");
//if file does not open
if($file == false){
echo "Error opening inventory file!";
exit();
}
$i= 0;
$total = 0.00;
/*create an array to hold the contents read off the file;
therefore we can manupulate them for processing.
So we keep reading the file as long as it is not the end,
which fgetscsv will know when there are no elements left*/
$data = array();
$i = 0;
while( feof($file) == false){
$data[$i] = fgetcsv($file);
$i = $i + 1;
}
/* Now we must close the file after we have obtained all the information
and then use such information and display it for the user in a table format
Also let the user know that you must reload the page by entering the
address again to show the updated stocks */
fclose($file);
echo '<br>';
echo '<h1>Current Inventory</h1>';
echo '<br>';
echo '<h3>Reload the page or enter the webaddress to see the stock update!</h3>';
echo "<h2>Tax is at 13%</h2>";
echo '<table>';
echo '<tr><th>Item Number</th>
<th>Item Name</th>
<th>Price</th>
<th>Stock</th></tr>';
$k = 1;
foreach($data as $side) {
echo('<tr>');
echo("<td>$k</td>");
echo('<td>');
echo(implode('</td><td>', $side));
echo('</td>');
echo('</tr>');
$k = $k + 1;
}
echo '</table>';
/* showing the values and taking out the "$" sign that was in the
txt file.
Then bulid a form for the user to enter in the values they want for
each item
at this juncture we build 3 arrays for each aspect of an item*/
$costsofitem = array();
$stockofitem = array();
$nameofitem = array();
$k = 0;
foreach ($data as $values){
$nameofitem[$k] = $values[0];
$costsofitem[$k] = str_replace("$", "", $values[1]);
$stockofitem[$k] = $values[2];
$k = $k + 1;
}
/* Submit table */
echo '<h3>Enter the amount you would like for each item</h3>';
echo '<form method=post>';
for ($k=0; $k < count($data)-1; $k++) {
echo "Item# ".($k+1).": <input type=\"text\" name=\"input[$k]\">" . '<br>';
}
echo '<input type="submit">';
echo '</form><br>';
/* Reciept and reply if ordering fails */
if($_SERVER['REQUEST_METHOD']=='POST'){
$k = 0;
$quantity = $_POST["input"];
$finalcost = array();
/* as the user goes thorugh their desired amount of prodcut
we msut also check if the amount they have entered is suffiecent
for ordering!
if It is not then we must check and let them know they have entered
the wrong amount.*/
foreach ($quantity as $amount){
if($amount > $stockofitem[$k]){
/* we check and let the user know they have enetered an insufficent amount of product and they must try again! */
echo "Sorry for the inconveince, but your order cannot be filled!, We only have:".$stockofitem[$k]."<br>
".$nameofitem[$k]." in stock"."<br>";
echo "The amount you ordered was: ".$amount." out of ".$nameofitem[$k];
exit();
} else if (ctype_digit($amount) == false && $amount != null) {
echo "ERROR!!!! Invalid order was placed!";
exit();
} else {
$finalcost[$k] = $amount * $costsofitem[$k];
$data[$k][2] -= $amount;
//alert("{$finalcost[$k]}");
/*echo "<script type='text/javascript'>alert('Total for $$finalcost[$k]');</script>";
*/
}
$k = $k + 1;
}
/*using the arrays $quantity, $finalcost, $nameofitem, $costsofitem,
values to to build the table */
echo '<h3>Reciept</h3>';
echo '<table>';
echo '<tr><th>Item:</th>
<th>Price:</th>
<th>Quantity</th>
<th>Amount</th></tr>';
//as you go thorugh print each's name, price, quantity and the total
for ($k=0; $k < count($quantity); $k++) {
echo '<tr>';
echo '<td>'.$nameofitem[$k].'</td>';
echo '<td>$'.$costsofitem[$k].'</td>';
echo '<td>'.$quantity[$k].'</td>';
echo '<td>$'.$finalcost[$k].'</td>';
echo '</tr>';
}
//printing variable for the popup
$x_2nd = array_sum($finalcost);
//update with tax
$x_2nd *= 1.13;
echo '<tr><td></td><td>Sub-Total</td>';
echo '<td>'.array_sum($quantity).'</td>';
echo '<td>$'.array_sum($finalcost).'</td>';
echo '</tr>';
echo '<tr><td></td><td>Tax</td>';
echo '<td></td><td>13%</td>';
echo '<tr><td></td><td>Total (with Tax)</td>';
echo '<td></td><td>$'.$x_2nd.'</td>';
//pop-up alret the user
echo "<script type='text/javascript'>alert('Your Order Total is: $$x_2nd. Reciept will be shown below!');
</script>";
/*add it up and show the costs of the items
and then update the file with the new stocks
that will be taken out
*/
//alert('array_sum($finalcost)');
$name_file = "inv.txt";
$file = fopen($name_file, "w");
for ($h=0; $h <count($data) ; $h++) {
$str = trim($nameofitem[$h]).", ".'$'.trim($costsofitem[$h]).", ".trim($data[$h][2]);
fwrite($file, $str);
if ($h != count($data)-1 ){
fwrite($file, "\n");
}
}
fclose($file);
//close the file after it is update
}
/* ALRET
-this will popup and tell the user the total
alert = $finalcost;
function alert($msg) {
echo "<script type='text/javascript'>alert('Total $:$msg');</script>";
*/
?>
</body></html>