-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathorder.php
More file actions
244 lines (207 loc) · 9.31 KB
/
order.php
File metadata and controls
244 lines (207 loc) · 9.31 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
<?php
//If Form is Submitted
if(isset($_POST['submit'])){
//Form Variables
$name = $_POST['name'];
$email = $_POST['emailAddress'];
$phone = $_POST['phoneNumber'];
$food = $_POST['foodType'];
$quantity = $_POST['quantity'];
$notes = $_POST['notes'];
$time = $_POST['pickupTime'];
//Add Order
$append = $name . "," . $email . "," . $phone . "," . $food . "," . $quantity . "," . $notes . "," . $time . "\n";
date_default_timezone_set('America/New_York');
$target_txt = "orders/" . date("d") . ".txt";
$html = "";
$tab = " ";
//HTML Order
$brokenAppend = explode(",", rtrim($append, "\n"));
$htmlAppend = $tab . "<tr>\nATTRIBUTES" . $tab . "</tr>\n";
$attributes = "";
foreach($brokenAppend as $attribute){
$attributes .= $tab . " <td>" . $attribute . "</td>\n";
}
$htmlAppend = str_replace("ATTRIBUTES", $attributes, $htmlAppend);
//Make A New Order File For A New Day
if(!file_exists(($target_txt))){
$orders = fopen($target_txt, "w");
fwrite($orders, $append);
fclose($orders);
$html .= $htmlAppend;
}
else{
$orderFile = fopen($target_txt, "r");
$orders = fread($orderFile, filesize($target_txt));
fclose($orderFile);
//Write New Order
$orderFile = fopen($target_txt, "w");
//Compare Times
function compareTime($timeX, $timeY) {
$timeX = intval(substr($timeX, 0, 2)) * 100 + intval(substr($timeX, 3));
$timeY = intval(substr($timeY, 0, 2)) * 100 + intval(substr($timeY, 3));
return $timeX < $timeY;
}
$wrote = false;
$ordersList = explode("\n", $orders);
//Loop Through Orders
foreach ($ordersList as $order) {
if ($order === '') {
if(!$wrote){
fwrite($orderFile, $append);
$html .= $htmlAppend;
}
fclose($orderFile);
break;
}
//Store Order Before Breaking Into Array
$preOrder = $order . "\n";
$order = explode(",", $order);
//Make HTML Tag
$htmlOrder = $tab . "<tr>\nATTRIBUTES" . $tab . "</tr>\n";
$attributes = "";
foreach($order as $attribute){
$attributes .= $tab . " <td>" . $attribute . "</td>\n";
}
$currTime = $order[count($order) - 1];
//If Order Time Is Less, Then Add the Order
if(!$wrote && compareTime($time, $currTime)) {
fwrite($orderFile, $append);
$html .= $htmlAppend;
$wrote = true;
}
//Add the Order
fwrite($orderFile, $preOrder);
$html .= str_replace("ATTRIBUTES", $attributes, $htmlOrder);
}
}
//Remove Last Skip Line(To make code look nicer)
$html = rtrim($html, "\n");
//Read HTML Template And Add New Orders
$orderHTML = fopen("orders.txt", "r");
$htmlContent = fread($orderHTML, filesize("orders.txt"));
fclose($orderHTML);
$htmlContent = str_replace("REPLACE", $html, $htmlContent);
//Write the HTML Template on the HTML Page
$orderHTML = fopen("orders.html", "w");
fwrite($orderHTML, $htmlContent);
fclose($orderHTML);
//Redirect Page To Prevent Reloads
header("Location: success.html");
exit();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<!-- 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://cdn.jsdelivr.net/npm/bootstrap@4.3.1/dist/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/5.0.1/css/bootstrap.min.css">
<!-- 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://cdn.jsdelivr.net/npm/popper.js@1.14.7/dist/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.3.1/dist/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/5.0.1/js/bootstrap.bundle.min.js"></script>
<!--Google Fonts-->
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Volkhov:wght@700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="style.css" type="text/css">
<title>Order</title>
</head>
<body>
<!--Navigation Bar: Referenced from GetBootstrap.com-->
<nav class="navbar navbar-expand-lg navbar-dark bg-dark fixed-top" class="navigationBar"> <!--Color of NavBar and calling navbar class in bootstrap-->
<div class="container">
<a class="navbar-brand" href="#">ISpeedFood</a> <!--The Header of the Navbar-->
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<!--Dropdown button of the ul's when display screen is at a certain size-->
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<!--Links in the Navigation Bar-->
<ul class="navbar-nav ms-auto">
<li class="nav-item">
<a class="nav-link" href="home.html">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="home.html#aboutUs">About Us</a>
</li>
<li class="nav-item">
<a class="nav-link" href="menu.php">Menu</a>
</li>
<li class="nav-item">
<a class="nav-link" href="order.php">Order</a>
</li>
<li class="nav-item">
<a class="nav-link" href="contactUs.html">Contact Us</a>
</li>
</ul>
</div>
</div>
</nav>
<div class="beginning">
<h1 class="header">Order</h1>
</div>
<!--Forms: Referenced from GetBootstrap.com-->
<form class="forms" id="orderFood" method="post" enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF'];?>">
<!--Name-->
<div class="form-group">
<label for="name">Name:</label>
<input type="text" class="form-control forms" id="name" name="name" required>
<!--type text allows the user to input text-->
</div>
<!--Email Address-->
<div class="form-group">
<label for="emailAddress">Email address:</label>
<input type="email" class="form-control forms" id="emailAddress" name="emailAddress" placeholder="name@gmail.com" required>
<!--type email checks if the user inputs a valid email address-->
</div>
<!--Phone Number-->
<div class="form-group">
<label for="phoneNumber">Phone Number:</label>
<input type="tel" class="form-control forms" id="phoneNumber" name="phoneNumber" pattern="[0-9]{3}-[0-9]{3}-[0-9]{4}" placeholder="999-999-9999" required>
<!--type tel with the pattern is the format to only accept inputs with XXX-XXX-XXXX phone number-->
</div>
<!--Food Type-->
<div class="form-group">
<label for="foodType">Select Food Item:</label>
<select class="form-select forms" id="foodType" name="foodType" required>
<option></option>
<!--Menu List-->
<?php
$itemList = fopen("itemList.txt", "r");
// Reading and displaying each option
while(!feof($itemList)) {
$option = explode(",", fgets($itemList));
echo "<option>" . $option[1] . ": " . $option[2] . "</option>\n";
if(!feof($itemList)){
echo " ";
}
}
fclose($itemList);
?>
</select>
</div>
<!--Quantity-->
<div class="form-group">
<label for="quantity">Quantity:</label>
<input type="number" class="form-control forms" id="quantity" name="quantity" min="1" max="10" placeholder="1-10" required>
</div>
<div class="form-group">
<label for="appt">Pick Up Time:</label> (<small>Open between 9am to 6pm</small>) <br/>
<input type="time" id="pickupTime" name="pickupTime" min="09:00" max="18:00" required> <br/>
</div>
<!--Prefernces-->
<div class="form-group">
<label for="notes">Preferences/Notes</label>
<textarea class="form-control forms" id="notes" name="notes" rows="3" placeholder="Make it spicy!"></textarea>
</div>
<button type="submit" name="submit" class="btn btn-primary submitButton">Submit</button>
</form>
<br/>
</body>
</html>