-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocessorder.php
More file actions
109 lines (95 loc) · 2.86 KB
/
processorder.php
File metadata and controls
109 lines (95 loc) · 2.86 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
<?php
/* Create short variable names */
$tireqty = $_POST[ 'tireqty' ];
$oilqty = $_POST[ 'oilqty' ];
$sparkqty = $_POST[ 'sparkplugs' ];
$find = $_POST[ 'find' ];
$address = $_POST[ 'address' ];
$DOCUMENT_ROOT = $_SERVER[ 'DOCUMENT_ROOT' ];
$date = date('H:i, jS F Y');
?>
<html>
<head>
<title>Bob 's Auto Parts - Order Results</title>
</head>
<body>
<h1>Bob 's Auto Parts</h1>
<h2>Order Results</h2>
<?php
echo '<p>Order processed at ' .$date. '</p>';
$totalqty = 0;
$totalqty = $tireqty + $oilqty + $sparkqty;
if ($totalqty == 0){
echo '<p style="color:red">';
echo 'You did not order anything on the preview page.';
echo '</p>';
exit;
} else{
echo '<p>Your order is as follows: </p>';
if ($tireqty > 0)
echo $tireqty. ' tires<br />';
if ($tireqty < 10)
$discount = 0.00;
elseif (($tireqty >= 10) && ($tireqty <= 49))
$discount = 5;
elseif (($tireqty >= 50) && ($tireqty <= 99))
$discount = 0.10;
elseif($tireqty >= 100)
$discount = 0.15;
if ($oilqty > 0)
echo $oilqty. ' bottles of oil<br />';
if ($sparkqty > 0)
echo $sparkqty. ' spark plugs<br />';
echo 'Items ordered: ' .$totalqty. '<br />';
}
$totalamount = 0.00;
define('TIREPRICE', 100);
define('OILPRICE', 10);
define('SPARKPRICE', 4);
$totalamount = $tireqty * TIREPRICE * $discount
+ $oilqty * OILPRICE
+ $sparkqty * SPARKPRICE;
echo 'Subtotal: $' .number_format($totalamount,2). '<br />';
$taxrate = 0.10; //local scales tax is 10%
$totalamount = $totalamount * (1 + $taxrate);
echo 'Total including tax: $' .number_format($totalamount,2). '<br />';
echo '<p>Address to the ship to is ' .$address. '</p>';
$outputstring= $date. "\t" .$tireqty. " tires \t" .$oilqty. " oil \t"
.$sparkqty. " spark plugs\t\$" .$totalamount. "\t" .$address. "\n";
//open file for appending
@ $fp = fopen("$DOCUMENT_ROOT/order.txt", 'ab');
flock($fp, LOCK_EX);
if (!$fp){
echo "<p><strong> Your order could not be processed at this time.
Please try again later.</strong></p></body></html>";
exit;
}
fwrite($fp, $outputstring, strlen($outputstring));
flock($fp, LOCK_UN);
fclose($fp);
echo "Order written.";
switch($find){
case "a" :
echo '<p>Regular customer.</p>';
break;
case "b" :
echo '<p>Customer referred by TV advert.</p>';
break;
case "c" :
echo '<p>Customer referred by phone directory.</p>';
break;
case "d" :
echo '<p>Customer referred by word of mouth.</p>';
break;
default :
echo '<p>We do not know how this customer found us.</p>';
break;
}
/* echo 'isset($tireqty):'.isset($tireqty). '<br />';
echo 'isset($nothere):'.isset($nothere). '<br />';
echo 'empty($tireqty):'.empty($tireqty). '<br />';
echo 'empty($nothere):'.empty($nothere). '<br />';
*/
?>
</body>
</html>