Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Overview: Demonstrate your ability to instantiate classes from text files and th

ID: 3594743 • Letter: O

Question

Overview: Demonstrate your ability to instantiate classes from text files and then display the content. Instructions:

1. You have been provided with a PHP file (Chapter10-project03.php) that includes all the necessary markup. You have also been provided with two text files, customers.txt and orders.txt, that contain information on customers and their orders.

2. Define classes to encapsulate the data of a Customer and an Order. Each line in the file contains the following information: customer id, first name, last name, email, university, address, city, state, country, zip/postal, phone. Each line in the orders file contains the following data: order id, customer id, book ISBN, book title, book category.

3. Read the data in customers.txt and for each line in that file create a new instance of Customer in an array, and then display the customer data in a table.

4. Each customer name must be a link back to Chapter10-project03.php but with the customer id data as a query string.

5. When the user clicks on the customer name (i.e., makes a request to the same page but with the customer id passed as a query string), then read the data in orders.txt into an array of Order objects, and then display any matching order data for that customer. Be sure to display a message when there is no order information for the requested customer. Test: Test the page in the browser. Verify the correct orders are displayed for different customers. Also note that the customer name is displayed in the panel heading for the orders.

NOTE: Sample output is provided in the next page. Try to run the code before you start working to see what the page looks like. At the top of the php file, add a comment including your name, section, and student id. The assignment should be completed individually. You should write the php code yourself and not by using any tools.

customer.txt

-------------------

order.txt

-----------

1,4,0133360903,Building Java Programs,Computer Science
2,6,0321836995,Mathematics All Around,Mathematics
3,24,0321825721,Mathematics for Elementary Teachers with Activity Manual,Mathematics
4,10,0133011208,Business Math,Business
5,10,0321836960,Elementary Statistics,Statistics
6,15,0321838696,Business Statistics: A First Course,Statistics
7,19,0133485102,Managing Engineering and Technology,Engineering
8,2,0133128911,Basics of Web Design: HTML5 & CSS3,Computer Science
9,2,0133068307,Introduction to JavaScript Programming with XML and PHP,Computer Science
10,3,0133251241,Horngren's Financial & Managerial Accounting,Business
11,18,0132948850,Survey of Economics,Economics
12,18,0132948869,Microeconomics,Economics
13,18,0132991330,Macroeconomics,Economics
14,18,0132992795,Macroeconomics, 2/e,Economics
15,16,0132730359,E-Commerce 2013,Business
16,29,0132993341,Fundamentals of Futures and Options Markets,Business
17,21,0132991306,Modern Systems Analysis and Design,Business
18,25,0321836960,Elementary Statistics,Statistics
19,25,0321838696,Business Statistics: A First Course,Statistics
20,5,0133255433,Horngren's Financial & Managerial Accounting, The Managerial Chapters,Business
21,5,0133255573,Horngren's Financial & Managerial Accounting. The Financial Chapters,Business
22,11,0205890962,Mosaics: Reading and Writing Essays 6e,Student Success
23,30,013335671X,Machine Design,Engineering
24,23,0136015727,Reliability Engineering,Engineering
25,23,0132832887,Aerodynamics for Engineers,Engineering
26,23,0321899970,Technical Communication,English

Chapter10-project03.php

--------------------------------------------

<?php

/* include 'book-utilities.php'; */


?>

<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<title>Book Template</title>

<link rel="shortcut icon" href="../../assets/ico/favicon.png">

<!-- Google fonts used in this theme -->
<link href="http://fonts.googleapis.com/css?family=Roboto+Slab:400,700" rel='stylesheet' type='text/css'>
<link href="http://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600,700,300italic,400italic,600italic,700italic" rel='stylesheet' type='text/css'>  

<!-- Bootstrap core CSS -->
<link href="bootstrap3_bookTheme/dist/css/bootstrap.min.css" rel="stylesheet">
<!-- Bootstrap theme CSS -->
<link href="bootstrap3_bookTheme/theme.css" rel="stylesheet">


<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="bootstrap3_bookTheme/assets/js/html5shiv.js"></script>
<script src="bootstrap3_bookTheme/assets/js/respond.min.js"></script>
<![endif]-->
</head>

<body>

<?php include 'book-header.inc.php'; ?>

<div class="container">
<div class="row"> <!-- start main content row -->

<div class="col-md-2"> <!-- start left navigation rail column -->
<?php include 'book-left-nav.inc.php'; ?>
</div> <!-- end left navigation rail -->

<div class="col-md-10"> <!-- start main content column -->
  
<!-- Customer panel -->
<div class="panel panel-danger spaceabove">
<div class="panel-heading"><h4>My Customers</h4></div>
<table class="table">
<tr>
<th>Name</th>
<th>Email</th>
<th>University</th>
<th>Address</th>
<th>City</th>
<th>State</th>
<th>Country</th>
<th>Zip/Postal</th>
<th>Phone</th>
</tr>
<?php  

foreach ($customers as $cust) {
echo '<tr>';
echo '<td><a href="chapter10-project03.php?customer="></a></td>';
echo '<td>' . '</td>';
echo '<td>' . '</td>';
echo '<td>' . '</td>';
echo '<td>' . '</td>';
echo '<td>' . '</td>';  
echo '<td>' . '</td>';
echo '<td>' . '</td>';
echo '<td>' . '</td>';
echo '</tr> ';   
}
?>
</table>
</div>

<?php
if ($_SERVER['REQUEST_METHOD'] == 'GET') {
if ( isset($_GET['customer']) ) {  
  
$requestedCustomer = $customers[$_GET['customer']];
  
$orders = readOrders( $_GET['customer'], 'orders.txt' );
if ( is_null($orders) ) {
echo '<div class="well">No orders for that customer</div>';
} else {
?>   
<div class="panel panel-danger">
<div class="panel-heading"><h4>Orders for <strong></strong></h4></div>
<table class="table">
<tr>
<th></th>
<th>ISBN</th>
<th>Title</th>
<th>Category</th>
</tr>

<?php foreach ($orders as $ord) {

echo '<tr>';
echo '<td><img src="images/book/tinysquare/.jpg"></td>';
echo '<td>' . '</td>';
echo '<td><a href="chapter10-project03.php?isbn"></td>';
echo '<td>' . '</td>';
echo '</tr> ';  

} ?>
</table>
</div>
<?php
}
}
} ?>
</div>


</div> <!-- end main content column -->
</div> <!-- end main content row -->
</div> <!-- end container -->




<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="bootstrap3_bookTheme/assets/js/jquery.js"></script>
<script src="bootstrap3_bookTheme/dist/js/bootstrap.min.js"></script>
<script src="bootstrap3_bookTheme/assets/js/holder.js"></script>
</body>
</html>

2 2 5 2 1 145 +37 2 01a 121g 7 4400 1 5709B7 0 (41426 P30 R12t 271t u u 4 d 6 1 P 2 J aN5 +ac5 XIirN t1 ,e44.1 a 9 IraiW sEei 1 t-, o / u R t ssra a9t r6Sauut -:a 8 e e 6 b v9vT/ 4 1 0 la 0ear1 1 it-c ierii,o erGnnen ni-, r V n a a n 1 eph iet ^ gi kht y, I t y@ a e for.J 3 r,mcrhevd 1erWb.y c 1 as e-, o i d a n e ^- LBFF ^ ^ ^678923 p3 4 5 6 7 1 1 1 1 2 2

Explanation / Answer

Done exact output as your screenshot I also tested in the browser.

chapter08-project02.php

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Chapter 8</title>
<!-- Bootstrap core CSS -->
<link href="bootstrap3_defaultTheme/dist/css/bootstrap.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="chapter08-project02.css" rel="stylesheet">
<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="bootstrap3_defaultTheme/assets/js/html5shiv.js"></script>
<script src="bootstrap3_defaultTheme/assets/js/respond.min.js"></script>
<![endif]-->
</head>
<body>
<?php include "art-header.inc.php";
include "art-data.php";
function outputCartRow($file, $product, $quantity, $price)
{
   $amount=$quantity * $price;
   $img_file='<img class="img-thumbnail" src="images/art/tiny/'.$file.'" alt="...">';
   echo ' <tr>
           <td>'.$img_file.'</td>
<td>'.$product.'</td>
           <td>'.$quantity.'</td>
           <td>$'.number_format($price,2).'</td>
           <td>$'.$amount.'</td>
</tr>';          
}
?>
<div class="container">
<div class="page-header">
<h2>View Cart</h2>
</div>

<table class="table table-condensed">
<tr>
<th>Image</th>
<th>Product</th>
<th>Quantity</th>
<th>Price</th>
<th>Amount</th>
</tr>
<?php
           outputCartRow($file1, $product1, $quantity1, $price1);
           outputCartRow($file2, $product2, $quantity2, $price2);
           $total=($quantity1*$price1) + ($quantity2*$price2);
           $tax=$total *0.1;
           if($total >2000){
               $shipping=0;
           }
           else
           {
               $shipping=100;
           }
           echo '<tr class="success strong">
<td colspan="4" class="moveRight">Subtotal</td>
<td >$'.$total.'</td>
</tr>';
echo '<tr class="active strong">
<td colspan="4" class="moveRight">Tax</td>
<td>$'.$tax.'</td>
</tr> ';
         
echo '<tr class="strong">
<td colspan="4" class="moveRight">Shipping</td>
<td>$'.$shipping.'</td>
</tr>
<tr class="warning strong text-danger">
<td colspan="4" class="moveRight">Grand Total</td>
<td>$1970</td>
</tr> ';
       ?>

<tr >
<td colspan="4" class="moveRight"><button type="button" class="btn btn-primary" >Continue Shopping</button></td>
<td><button type="button" class="btn btn-success" >Checkout</button></td>
</tr>
</table>   
</div> <!-- end container -->
<?php include "art-footer.inc.php"?>

<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="bootstrap3_defaultTheme/assets/js/jquery.js"></script>
<script src="bootstrap3_defaultTheme/dist/js/bootstrap.min.js"></script>
</body>
</html>

art-header.inc.php

<header>
<div id="topHeaderRow" >
<div class="container">
<nav class="navbar navbar-inverse " role="navigation">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<p class="navbar-text">Welcome to <strong>Art Store</strong>, <a href="#" class="navbar-link">Login</a> or <a href="#" class="navbar-link">Create new account</a></p>
</div>
<div class="collapse navbar-collapse navbar-ex1-collapse pull-right">
<ul class="nav navbar-nav">
<li><a href="#"><span class="glyphicon glyphicon-user"></span> My Account</a></li>
<li><a href="#"><span class="glyphicon glyphicon-gift"></span> Wish List</a></li>
<li><a href="#"><span class="glyphicon glyphicon-shopping-cart"></span> Shopping Cart</a></li>
<li><a href="#"><span class="glyphicon glyphicon-arrow-right"></span> Checkout</a></li>
</ul>
</div>
</nav>
</div>
</div>   

<div id="logoRow" >
<div class="container">
<div class="row">
<div class="col-md-8">
<h1>Art Store</h1>
</div>
  
<div class="col-md-4">
<form class="form-inline" role="search">
<div class="input-group">
<label class="sr-only" for="search">Search</label>
<input type="text" class="form-control" placeholder="Search" name="search">
<span class="input-group-btn">
<button class="btn btn-default" type="submit"><span class="glyphicon glyphicon-search"></span></button>
</span>
</div>
</form>
</div>
  
</div>

  
</div>
</div>

<div id="mainNavigationRow" >
<div class="container">
<nav class="navbar navbar-default" role="navigation">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<div class="collapse navbar-collapse navbar-ex1-collapse">
<ul class="nav navbar-nav">
<li class="active"><a href="#">Home</a></li>
<li><a href="#">About Us</a></li>
<li><a href="#">Art Works</a></li>
<li><a href="#">Artists</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Specials <b class="caret"></b></a>
<ul class="dropdown-menu">
<?php
for ($i=0; $i < 5; $i++) {
$extra = $i + 1;
echo '<li><a href="#">Special ' . $extra . '</a></li>';
}
?>
</ul>
</li>
</ul>
</div>
</nav>
</div> <!-- end container -->
</div> <!-- end mainNavigationRow -->

</header>

art-footer.inc.php

<footer>
<div class="container">
<div class="row">
<div class="col-md-3">
<h4><span class="glyphicon glyphicon-info-sign"></span> About Us</h4>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s.</p>
</div>
<div class="col-md-3">
<h4><span class="glyphicon glyphicon-earphone"></span> Customer Service</h4>
<ul class="nav nav-stacked">
<li><a href="#">Delivery Information</a></li>
<li><a href="#">Privacy Policy</a></li>
<li><a href="#">Shipping</a></li>
<li><a href="#">Terms and Conditions</a></li>
</ul>   
</div>
<div class="col-md-3">
<h4><span class="glyphicon glyphicon-shopping-cart"></span> Just Ordered</h4>
<div class="media">
<a class="pull-left" href="#">
<img class="media-object" src="images/art/tiny/099110.jpg" alt="...">
</a>
<div class="media-body">
<p class="media-heading similarTitle"><a href="#">The Veiled Woman</a></p>
<em>5 minutes ago</em>
</div>
</div>
<div class="media">
<a class="pull-left" href="#">
<img class="media-object" src="images/art/tiny/116010.jpg" alt="...">
</a>
<div class="media-body">
<p class="media-heading similarTitle"><a href="#">Artist Holding a Thistle</a></p>
<em>11 minutes ago</em>
</div>
</div>   
<div class="media">
<a class="pull-left" href="#">
<img class="media-object" src="images/art/tiny/113010.jpg" alt="...">
</a>
<div class="media-body">
<p class="media-heading similarTitle"><a href="#">Self-portrait in a Straw Hat</a></p>
<em>23 minutes ago</em>
</div>
</div>
</div>   
<div class="col-md-3">
<h4><span class="glyphicon glyphicon-envelope"></span> Contact us</h4>
<form role="form">
<div class="form-group tight-form-group">
<label class="sr-only" for="name">Name</label>
<input type="text" class="form-control" name="email" placeholder="Enter name ...">
</div>
<div class="form-group tight-form-group">
<label class="sr-only" for="email">Email</label>
<input type="email" class="form-control" name="email" placeholder="Enter email ...">
</div>
<div class="form-group tight-form-group">
<label class="sr-only" for="email">Email</label>
<textarea class="form-control" rows="3" placeholder="Enter message ..."></textarea>
</div>   
<button type="submit" class="btn btn-primary btn-block">Submit</button>
</form>
</div>

</div>
</div>

<div id="copyrightRow">
<div class="container">
<div class="row">
<p class="text-muted">All images are copyright to their owners. This is just a hypothetical site
<span class="pull-right">&copy; 2014 Copyright Art Store</span></p>
</div>
</div>
</div>
</footer>

art-data.php

<?php
$file1 = '116010.jpg';
$product1 = 'Artist Holding a Thistle';
$quantity1 = 3;
$price1 = 500;

$file2 = '113010.jpg';
$product2 = 'Self-portrait in a Straw Hat';
$quantity2 = 1;
$price2 = 700;
?>