<!DOCTYPE html>
<html>
<head>
<title>Shop.com Shooping Application</title>
<style>
a           {color:white; background-color:blue; text-decoration:none; border:2px solid black; border-radius:10px}
table       {background-color:lightgray}
th          {color:white; background-color:black;}
table,th,td {border:2px solid black; border-collapse:collapse; vertical-align:top; padding:5px}
</style>
</head>
<body>
<h1 align=center>Shopping Application</h1>
<h2 align=center><a href="javascript:top.location.href='/~sultans/php/demo/5session/shop/shop.php'">  Shop.php  </a></h2>
<h3>This is a full shopping application with shopping cart capability.  It is written in PHP, and uses sessions and cookies.  
<br>Below is a list of components and their functions.</h3> 
<br>
<table>
<tr bgcolor=lightgray><th>Tables<th>Description and Keys
<tr>
<td><b>customer</td>
<td>This table holds customer registration/profile information such as user, password, name, address, etc.
<br><b>Primary key: </b>cust_id 
<tr>
<td><b>cust_cart</td>
<td>This table holds customer shopping cart content such as ice cream flavors, ice cream toppings, etc. 
<br><b>Primary key: </b> cart_id 
<br><b>Foreign key: </b> <i>cust_id</i>
<tr>
<td><b>cust_order</td>
<td>This table holds completed orders with data such as customer name & address, ice cream flavors, toppings, credit card, etc. 
<br><b>Primary key: </b> order_id 
<br><b>Foreign key: </b> <i>cust_id</i>

<tr bgcolor=lightgray><th>Session Variables<th>Purpose 
<tr>
<td><b>cust_id</td>
<td>This session variable is created once a user logs in successfully, and deleted once user logs out, or closes the browser.
<br><b>Purpose:  </b>This variable is validated in all subsequent pages. If no cust_id, the user is redirected to the log in page. 
<tr>
<td><b>cust_fname</td>
<td>This session variable is created once a user logs in successfully, and deleted once user logs out, or closes the browser.
<br><b>Purpose:  </b>To display the user's first name on subsequent pages to provide a more friendly user interface.
<tr>
<td><b>cart_id</td>
<td>This session variable is created once a user adds items to a shopping cart, and deleted once they complete their checkout process.
<br><b>Purpose:  </b>To ensure that the customer has an active shopping cart when checking out 

<tr bgcolor=lightgray><th>Cookies<th>Purpose and Duration
<tr>
<td><b>cust_user</td>
<td>This cookie is created once a user logs in successfully, and requested that the userid is saved for future login sessions. 
<br><b>Purpose:  </b>The purpose of the cookie is to enable the customer not to have to enter their userid when logging in.
<br><b>Duration: </b> <i>7 days</i> 

<tr bgcolor=lightgray><th>PHP Pages<th>Description and Functionality
<tr>
<td><b>Shop.php<td><ul>
<li>This is the login <b>entry point</b> to the application.
<li>Allows you to <b>login</b> or to <b>register</b>.
<li>The script also allows you to <b>log out.</b> (<i>This can also be done via a call from the other components</i>).
<li><u>If logging in</u>, the script retrieves your customer information from the <b>customer DB table</b>.
<li>A row must exist in the customer table, and the password must match what is entered.
<li>If login is successful, the cust_id and fname (<i>from the customer table</i>) are temporarily saved in a session, 
<br>and the script <b>redirects</b> you to the <b>shopCart page</b>.
<li>The temporary <b>cust_id session variable</b> is used in all other pages to ensure proper login.
<li>The temporary <b>fname session variable</b> is used to provide a friendlier user experience. 
<li>The script allows you to save your userid. If so, <b>User cookie</b> will be saved for 7 days.
<br>Next time you login, you only need to enter your password.
<li><u>If register</u>, the script <b>redirects</b> you to the <b>shopProf page</b>.
<li><u>If logging out</u>, your temporary cust_id and fname session variables are deleted.
<tr>
<td><b>ShopProf.php<td><ul>
<li>This script allows you to either <b>register</b> if a new user, or to <b>update your previous profile</b>.
<li>The script checks the temporary <b>cust_id session variable</b>.
<li>If the cust_id session variable does not exist, this means a new registration.
<li>If the cust_id session variable exists, this means it is an update to the customer previous profile information.
<li><u>If new registration</u>, the script allows you to enter a new userid, password, name, and other information.
<li>The entered userid is checked against the database to ensure that is it unique, and does not already exist.
<li>If OK, the data is inserted in the <b>customer DB table</b>, with a newly generated <b>cust_id</b> value.
<li>The cust_id and fname are saved as temporary session variables to facilitate further processing. 
<li><u>If update to profile</u>, the script allows you to update your registration profile within the customer DB table.
<li>The script does not allow you to change your userid, all other data can be changed.
<li>The script also allows you to delete your customer profile. (<i>This has been deactivated</i>).
<tr>
<td><b>ShopCart.php<td><ul>
<li>This script allows you to <b>shop</b>, and add items to your shopping cart.
<li>The script checks to see if there is a temporary <b>cust_id session variable</b>.
<li>If no cust_id session variable, the script <b>redirects</b> you to the login <b>shop.php page</b>.
<li>The script checks to see if there is already a <b>cart_id session variable</b>.
<li><u>If no cart_id session variable</u>, It must be a new cart.
<li>The user adds items to the shopping cart. 
<li>The script inserts data into the <b>cust_cart DB table</b>, and creates a <b>cart_id session variable</b>.
<li><u>If cart_id session variable exists</u>, It must be an update (or clear) of existing cart.
<li>If update, the script updates the content of the cust_cart table row. 
<li>If clear, the script deletes the row from the cust_cart table, and deletes the cart_id session variable.
<li>The user has the ability to checkout. If so, the script <b>redirects</b> to the <b>shopDBAdd.php page</b>.
<tr>
<td><b>ShopDBAdd.php<td><ul>
<li>This script allows you to <b>checkout</b> (add a new order) to the database.
<li>The script checks to see if there is a temporary <b>cust_id session variable</b>.
<li>If no cust_id session variable, the script <b>redirects</b> you to the login <b>shop.php page</b>.
<li>The script checks to see if there is already a <b>cart_id session variable</b>.
<li>If no cart_id session variable, the script <b>redirects</b> you to the <b>shopCart.php page</b>.
<li>The script retrieves data from the <b>customer DB table</b> and the <b>cust_cart DB table</b>.
<li>Data is displayed on the screen.
<li>Client has the ability to change information (including name/address and cart items).
<li>If client clicks on "Place Order" button, the script inserts data into <b>cust_order DB table</b>.
<li>The script also deletes row from the <b>cust_cart DB table</b>, as well as the <b>cart_id session variable</b>. 
<tr>
<td><b>ShopDBList.php<td><ul>
<li>This script <b>displays</b> a list of all processed orders.
<li>The script checks to see if there is a temporary <b>cust_id session variable</b>.
<li>If no cust_id session variable, the script <b>redirects</b> you to the login <b>shop.php page</b>.
<li>The script retrieved all rows from the <b>cust_order DB table</b> and displays a list on the screen.
<li>The client has the ability to <b>sort</b> (<i>ascending & descending</i>) by name, address, shopping items, etc.
<li>The client has the ability to click on a single order, and to either <b>update</b> or <b>delete</b> the order.
<li>If either update or delete, the scripts <b>redirects</b> you to <b>shopDBUpd.php page</b>.
<tr>
<td><b>ShopDBSrch.php<td><ul>
<li>This script <b>displays</b> all or some processed orders, and allows you to <b>search/filter</b> through the orders.
<li>The script checks to see if there is a temporary <b>cust_id session variable</b>.
<li>If no cust_id session variable, the script <b>redirects</b> you to the login <b>shop.php page</b>.
<li>The script retrieved all rows from the <b>cust_order DB table</b> and displays a list on the screen.
<li>The client has the ability to <b>search/filter</b> for a particular name, address, shopping items, etc.
<li>The client has the ability to <b>sort</b> (<i>ascending & descending</i>) by name, address, shopping items, etc.
<li>The client has the ability to click on a single order, and to either <b>update</b> or <b>delete</b> the order
<li>If either update or delete, the scripts <b>redirects</b> you to <b>shopDBUpd.php page</b>.
<tr>
<td><b>ShopDBUpd.php<td><ul>
<li>This script allows you to <b>update</b> or to <b>delete</b> an order.
<li>The script checks to see if there is a temporary <b>cust_id session variable</b>.
<li>If no cust_id session variable, the script <b>redirects</b> you to the login <b>shop.php page</b>.
<li>This script can only be called from within the <b>ShopDBList.php</b> or the <b>ShopDBSrch.php</b> pages.
<li>The script must have a <b>order_id</b> passed to it from the List of Search pages. 
<li>The script uses the order_id to retrieved the order row from the <b>cust_order DB table</b>.
<li>The order data is displayed on the screen.
<li>The client has the ability to either update or delete the order.
<li><u>If update</u>, the data is updated from within the cust_order DB table.
<li><u>If delete</u>, the order row is deleted from the cust_order DB table.
</table>
<br><br>
<body>
</html>