Carleton University 
School of Computer Science 
Assignment 3 -- 95.205 C/D, Winter 2001

It is important to note that: Print a copy of the answer sheet and use it to hand in your answers to this assignment.

In this assignment, assume that each item for sale has a unique six digit id that is not shown to the user. The scripts in this assignment use these ids to reference the floral items or CDs (whichever you implemented in your second assignment), e.g., the floral item "Roses, Red, Longstemmed, $40.00" has the id 100001. You can assign the ids as you wish.

Note: For this assignment you will need to install the DBI and DBD::CSV modules as per instructions in class.

Question 1: Creating the Databases

Write a script named createShopDatabase.cgi that will create a database for storing information about
shopping carts and orders. Use the DBI module to create a CSV database named shop.

Create a table shoppingCart with the following columns:

userId, itemId, quantity
Note that this is the first script the TA will call when marking your assignment to ensure that the database is created before the shopping application is called. It should create a fresh copy of the database.

Question 2: Changes to the Shop205Home.cgi Script

If the request for the Shop205Home.cgi script is not accompanied by a cookie, the script creates a unique user id and sets a cookie with this id. The script then passes the newly created id to other scripts via a hidden field.

The web page displayed by this script has the following buttons:

Question 2: Changes to the Shop205DisplayCategories.cgi Script

Case 1

If the Shop205DisplayCategories.cgi script is called via the "Show Selected Categories" button, the script displays the selected categories as in assignment 2.

Case 2

If the Shop205DisplayCategories.cgi script is called via the "Show Shopping Cart" button, the script uses the user's id to search the shopping cart table for all items belonging to the user.

The script displays all items in the shopping cart in the the appropriate categories. The items should already be selected. To remove an item from the shopping cart, the user can deselect the appropriate item.

If no items were found in the shopping cart, the script displays the same page as in Case 1.

Buttons

This script has two buttons, labeled "Save Shopping Cart" and "Place Order" respectively, and clicking on either button calls the Shop205Order.cgi script.

Question 3: Changes to the Shop205Order.cgi Script

Case 1

If the Shop205Order.cgi script is called from the "Save Shopping Cart" button, the script saves the shopping cart in the appropriate table and displays a  page indicating that the shopping cart was saved.

In order to continue shopping the user needs to invoke the Shop205Home.cgi script again. Typically the user will log out at this point, only to revisit the shop's web site at another time.

Case 2

If the Shop205Order.cgi script is called from the "Place Order" button, the script displays the order information as in assignment 2, but the displayed page also includes a form that asks the user for their name and address.

The displayed page also contains two buttons labeled "Order" and "Cancel" respectively. If the user clicks the "Cancel" button, the script displays a page that thanks the user for visiting the site.

If the user clicks the "Order" button, the script

Question 4: Changes to the Shop205Home.cgi Script

The Shop205Home.cgi script needs to be changed to accommodate the presence of cookies.

If the script request is accompanied by a cookie that stores the user id, the script calls the Shop205DisplayCategories.cgi script to show the contents of the shopping cart.

This should have the same effect as if  "Show Shopping Cart" had been selected on the shop's home page

Note: One script can call another script by redirecting the browser to the location of the other script. If parameters need to be passed to the other script, they must be included in the URL.