Question

In: Computer Science

PHP A local client needs to take his static web page for ordering organic vegetables and...

PHP

A local client needs to take his static web page for ordering organic vegetables and build a dynamic page. He doesn't have much money to spend, so we are going to write orders to a flat file. He is also going to need a page that he can go to that will display his orders.

He has already met with Sharron, so we've got a specification already assembled. Here are the details:

The customer will go to a form page where they can enter an order for vegetables. The file will be called orderVegetables.php. Here are products a customer can order:

  • 5 lb Potatoes, $6.00 each
  • 3 lb Carrots, $3.75 each
  • 1 Cauliflower, $4.00 each

The customer should be able choose a quantity of items beside any of the vegetable options. Only allow orders where there is at least one thing ordered. Also, if the total price is over $50 then they qualify for free delivery, otherwise delivery cost is $5.00. (You can apply the delivery fee after tax, or before). Be sure to also capture the customers name, email and phone number on the form so the client can contact them to setup delivery. Make sure each order has the date and time of the order as well. Don't forget to use \r\n for a new line at the end of each record.

When the user clicks 'submit,' a POST request is made to processVeggies.php where the order is written to the file veggie-orders.txt. The text file should be simply a storage place in lieu of using a proper database. Some would call it a 'flat-file' storage system. Make sure to lock the file before appending, and to unlock it afterwards. Display a thank you message to the client and print their order details to the screen. Let them know that they will be contacted within the next business day.

Of course the client would like a page to view all the orders. This file will be called viewOrders.php. The client would like a link on this page to reset the orders (reset the veggie-orders.txt file) called Reset Orders. This link will call a file resetOrders.php. The client will typically print off a days worth of orders and then reset the form for the next day. Don't worry about locking the file on your reset page.

Good luck! We need this prototype soon!

- Ima Plant

Senior Consultant,
Acme International Inc.

====

The order form also needs to capture customer name, phone number, and email.

What to expects

1. The input page (named orderVegetables.php) needs to have the following fields:

a. Select drop-down fields should be used to allow users to choose a quantity for each item. Limit the options to 0-30.

b.We also need fields for name, email, and phone number.

2. Look and Feel: Use bootstrap or not, your choice. The header of each page should contain a masthead/header image that would befit an upscale veggie shop. Please use GIMP, MS PAINT or some other editor to create this header image for the top of your page. Or better yet, set your header text using <h1> or <h2> and set the image you create as a background-image in your CSS. As well, all formatting should be done using CSS in an external stylesheet. Please use a div with an id of 'container' to hold your content. Ensure that this simple theme is present for ALL of your pages!

3. The processing page (named processVeggies.php) needs to include the following:

a. Order details gathered from input form.

b. Whether or not delivery is free - display a message to the user one way or the other (include dollar sign and two decimal places - that is, format for currency)

c. Assume a provincial tax rate of 15%

d. Calculate and display the details of their order, net amount before tax, tax amount, delivery amount, and total amount.

e. Include the time, date, and year (for Atlantic Canada) that the order was processed.

f. Ensure that there is some type of validation on the processing page. If someone tried to run it without accessing the form page first, it should give the user a link back to the order page.

4. The processing page (processVeggies.php) should also write this order to a file.

a .Ensure file is accessible to your script, but hidden from public browsing. Please note that veggie-orders.txt MUST be stored one directory behind your publishing directory. "$DOCUMENT_ROOT/../veggie-orders.txt" would be an example.

b. Orders file should be delimited by a "\t" or some other delimiter. " \r\n" at the end of each line.

5. The viewOrders.php page should open the file for reading only and display, in html, all of the pending orders for the day. The look and feel of this page should follow the store's theme. Though this page would be used only by administrators of the site, we will not lock it down. For now, assume it will be live for all to view. Please create a table to hold all of the pending orders. Each line of the order file could be a table row. You can keep this simple, no need to use explode() or list() if you don't want to. As well on this page, create a hyperlink to resetOrders.php (see below). If there are no pending orders, ensure there is a message to the user stating the fact.

6. Create another page called resetOrders.php. This page should reset the orders file (delete the file contents), give the user confirmation that the file has been cleared and give them a link/instructions on what to do next.

7. All pages should be accessible via links. So there should be some sort of menu.  I DON'T need a link to process orders as that would be silly. Remember menus should go at the top of your pages.

8.Comments, Code Formatting, Submission Packaging (variable naming, page naming).

Solutions

Expert Solution

header.php

<!DOCTYPE html>
<html>
<title>Vegetable App </title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
<style>
body {font-family: "Times New Roman", Georgia, Serif;}
h1, h2, h3, h4, h5, h6 {
font-family: "Playfair Display";
letter-spacing: 5px;
}
</style>
<body>

<div class="w3-top">
<div class="w3-bar w3-white w3-padding w3-card" style="letter-spacing:4px;">
<a href="#home" class="w3-bar-item w3-button">Vegetable App</a>
<div class="w3-right w3-hide-small">
<a href="orderVegetables.php" class="w3-bar-item w3-button">Order Vegetables</a>
<a href="viewOrders.php" class="w3-bar-item w3-button">View Orders</a>
</div>
</div>
</div>

footer.php

<!-- Footer -->
<footer class="w3-center w3-light-grey w3-padding-32">
</footer>

</body>
</html>

index.php

<?php require_once 'header.php'; ?>
<!-- Contact Section -->
<h1 style="margin: 2em">Welcome to Vegetable Ordering App </h1>

<!-- End page content -->
</div>

<?php require_once 'footer.php'; ?>

orderVegetables.php

<?php require_once 'header.php'; ?>
<!-- Contact Section -->
<?php
$option = "";
$err_msg = "";
for ($i = 0; $i < 30; $i++) {
$option .= "<option value='$i'>$i</option>";
}
$msg = "";
$error = 0;
if (!empty($_POST)) {
$potatoes = doubleval($_POST["potatoes"]) * 6.00;
$carrots = doubleval($_POST["carrots"]) * 6.00;
$coli = doubleval($_POST["coli"]) * 6.00;

$total = $potatoes + $carrots + $coli;
if ($total <= 0) {
$error = 1;
$err_msg = "Select Atleast One Order";
}
if (!$error) {
$insert = $_POST["name"] . "," . $_POST["email"] . "," . $_POST["number"] . "," . $_POST["potatoes"] . "," . $_POST["carrots"] . "," . $_POST["coli"] . "," . date("Y/m/d") . "," . date("h:i:sa") . "\r\n";
file_put_contents(dirname(__FILE__) . "/../veggie-orders.txt", $insert, FILE_APPEND | LOCK_EX);
$delivery = ($total > 50) ? 0 : 5;
$msg = "Net Amount= $ $total, Tax Amount= $ " . (15 * $total / 100) . ",Delivery $ $delivery"
. ", Total Amount is $ " . ($total + (15 * $total / 100) + $delivery);
}
}
?>
<div class="w3-container w3-padding-64" id="contact">
<?php
if (empty($_POST) || !empty($err_msg)) {
echo "<p>$err_msg</p>";
?>
<h1>Order Vegetable</h1><br>
<form action="" target="_blank" method="post">
<p><input class="w3-input w3-padding-16" type="text" placeholder="Name" required name="name"></p>
<p><input class="w3-input w3-padding-16" type="email" placeholder="Email" required name="email"></p>
<p><input class="w3-input w3-padding-16" type="text" placeholder="Number" required name="number"></p>
<p><label>5 lb Potatoes, $6.00 each</label><select class="w3-input w3-padding-16" required name="potatoes">
<?php echo $option ?>
</select></p>
<p><label>3 lb Carrots, $3.75 each</label><select class="w3-input w3-padding-16" required name="carrots">
<?php echo $option ?>
</select></p>
<p><label>1 Cauliflower, $4.00 each</label><select class="w3-input w3-padding-16" required name="coli">
<?php echo $option ?>
</select></p>


<p><button class="w3-button w3-light-grey w3-section" type="submit">ORDER</button></p>
</form>
<?php
} else {
echo "<h1 style='margin: 2em'>$msg</h1>";
}
?>
</div>

<!-- End page content -->
</div>

<?php require_once 'footer.php'; ?>

viewOrders.php

<?php require_once 'header.php'; ?>
<!-- Contact Section -->
<div class="w3-container w3-padding-64" id="contact">

<h1>Orders</h1><br>
<table>
<tr>
<th>Name</th>
<th>Email</th>
<th>Number</th>
<th>Potatoes</th>
<th>Carrots</th>
<th>Cauliflower</th>
<th>Date</th>
<th>Time</th>
</tr>
<?php
$conetents = explode("\r\n", file_get_contents(dirname(__FILE__) . "/../veggie-orders.txt"));
foreach ($conetents as $val) {
$arr = explode(",", $val);
if (count($arr) > 1) {
if (strtotime($arr[6]) == strtotime(date("Y/m/d")))
echo"<tr>";
echo"<td>$arr[0]</td>";
echo"<td>$arr[1]</td>";
echo"<td>$arr[2]</td>";
echo"<td>$arr[3]</td>";
echo"<td>$arr[4]</td>";
echo"<td>$arr[5]</td>";
echo"<td>$arr[6]</td>";
echo"<td>$arr[7]</td>";


echo"</tr>";
}
}
?>
</table>
<a href="resetOrders.php">Reset Orders</a>

</div>

<!-- End page content -->
</div>

<?php require_once 'footer.php'; ?>

resetOrders.php

<?php require_once 'header.php'; ?>
<!-- Contact Section -->
<div class="w3-container w3-padding-64" id="contact">


<?php
if (!empty(file_get_contents(dirname(__FILE__) . "/../veggie-orders.txt"))) {
file_put_contents(dirname(__FILE__) . "/../veggie-orders.txt", "");
echo"<h1 style='margin: 2em'>All Orders are reset </h1>";
} else {
echo"<h1 style='margin: 2em'>There are no pending orders </h1>";
}
?>


</div>

<!-- End page content -->
</div>

<?php require_once 'footer.php'; ?>


Related Solutions

Create a web page using PHP that allows the users to create an account (a username...
Create a web page using PHP that allows the users to create an account (a username and a password). There should be a login page that allows users to create an account by entering their preferred username and password. The same page should also let users login if they already have an account. If a user is logged in successfully , they should be able to enter a comment and also read the comments entered by others previously.
Create a web page using PHP and HTML that contains a list of movie names available...
Create a web page using PHP and HTML that contains a list of movie names available for rent (at least 10 movies), so that each time you visit the home page, you see a different order of movies in the list. The movie names are required. 2) The rental price for each movie ranges between $1.99 to $7.99. • Create an associative array with a code for the movie as the key (e.g., movie1, movie2, etc.) and the associated rental...
Julio Fernandez runs a small business specializing in delivering organic fruit and vegetables to the local...
Julio Fernandez runs a small business specializing in delivering organic fruit and vegetables to the local area. He buys from local farms and packages these together in boxes and delivers them locally. Each box is sold for $12. He has the following costs:  Direct wages are $9 per hour (30 minutes per box on average) Fruit and vegetables are $4 per box  Other fixed costs incurred each year for this business are as follows: o Rent of Delivery...
Web Programming: Explain how a session actually works in PHP, including how the client and server...
Web Programming: Explain how a session actually works in PHP, including how the client and server use the session ID to identify the session Then, compare and contrast cookies and sessions as a means of storing state information for a given user. Thank you
Using a combination of HTML/PHP, implement a web page where the users can upload a text...
Using a combination of HTML/PHP, implement a web page where the users can upload a text file, exclusively in .txt format, which contains a string of 400 numbers, such as: 71636269561882670428 85861560789112949495 65727333001053367881 52584907711670556013 53697817977846174064 83972241375657056057 82166370484403199890 96983520312774506326 12540698747158523863 66896648950445244523 05886116467109405077 16427171479924442928 17866458359124566529 24219022671055626321 07198403850962455444 84580156166097919133 62229893423380308135 73167176531330624919 30358907296290491560 70172427121883998797 Your code should contain a PHP function that, accepting the string of 400 numbers in input, is able to find the greatest product of four adjacent numbers in all the...
Great Oaks Farm grows organic vegetables and sells them to local restaurants after processing. The farm’s...
Great Oaks Farm grows organic vegetables and sells them to local restaurants after processing. The farm’s leading product is Salad-in-a-Bag, which is a mixture of organic green salad ingredients prepared and ready to serve. The company sells a large bag to restaurants for $25. It calculates the variable cost per bag at $19 (including $1 for local delivery), and the average total cost per bag is $22. Because the vegetables are perishable and Great Oaks Farm is experiencing a large...
Special Order Great Oaks Farm grows organic vegetables and sells them to local restaurants after processing....
Special Order Great Oaks Farm grows organic vegetables and sells them to local restaurants after processing. The farm’s leading product is Salad-in-a-Bag, which is a mixture of organic green salad ingredients prepared and ready to serve. The company sells a large bag to restaurants for $25. It calculates the variable cost per bag at $19 (including $1 for local delivery), and the average total cost per bag is $22. Because the vegetables are perishable and Great Oaks Farm is experiencing...
1. Describe the difference between a static web page and a dynamic one. 2.Briefly explain the...
1. Describe the difference between a static web page and a dynamic one. 2.Briefly explain the benefit of using a templating engine when developing a web app. 3.How does the express.js package make it easier to write a web application? 4.Describe how callbacks and promises help with asynchronous programming. 5.What is the difference between a GET and a POST request? When would you use each? 6.Explain what adding the body-parser plugin to your app allows you to do with express.
Using JavaScript, create a simple web page that will take orders for Chess Org. Chess Org...
Using JavaScript, create a simple web page that will take orders for Chess Org. Chess Org sells yearly membership for $30 each. Discounts are given for buying in bulk (see Table 1 and example below). Table 1 – Discounts Quantity Purchased Discount 1 – 29 0% 30 - 59 10% 60 + 15% Example: If a customer purchases 40 family membership, their total price (CTotal) would be: COriginalPrice = 30*40=1200 DMainDiscount = 1200*0.1=120 CTotalPrice = COriginalPrice - DMainDiscount= 1200-120 =...
Your client was born on Nov 28, 1945. This client must take his first required minimum...
Your client was born on Nov 28, 1945. This client must take his first required minimum distribution from an IRA no later than   a. April 1, 2017 b. April 1, 2016 c. May 28, 2016 d. November 28, 2016 Look on the 2017 Form 1040 (in Ch 3 of the textbook). Alimony received is included in the income section of the return. Alimony paid is included in the Adjusted Gross Income portion of the return. Which statement is true regarding...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT