Chris Pollett > Old Classes > PIC40 ( Print View ) Lecture Notes-PDF Spring '01 Ad: Enrollment info Course Info:
Practice Exams: PIC: |
HW#5 --- last modified January 16 2019 00:35:22..Due date: noon Mar. 7 ========= Files to be submitted: p40hw5file1.php (put in directory ~/public_html/hw5 ====================== under Unix and also in a directory \SUBMIT under NT. HW5 Purpose: (1) To gain experience with connecting to a database in PHP ============ (2) To use hidden fields with forms. (3) To use cookies to maintain past sessions. Specification: ============== For this assignment you will complete a partially finished script that is supposed to produce forms to allow a user to create a travel itinerary using the airtransportation database. Here is the partially finished script. You will need to write the function Intro($MSG), CKAirport(), Itinerary(), SetCookies(), Connect(), FreeCursor(), Close(), Prepare($query), FetchRow($cursor). The partially finished script contains comments as to what these functions do. Below is a description of what the whole script does. The main block of the script is essentially just be a switch statement on the value of the field State. Depending on this value the appropriate page drawing function is called. All forms on pages in this assignment should use the POST method. If State is undefined then the intro page function is called with a blank message to draw the intro page. This page has two submit buttons (only the one that is clicked will have it's value passed, if you want you can have these in two forms on the same page). The title of this page is: Travel Planner. If there had been a message it would have been printed next in a blue h3 heading. Travel Planner is then also printed at the top of page in a h1 heading. Beneath this should appear Previous itinerary: [Fetch Now] [Fetch Now] is a submit button with name State and value Fetch Now. There should then be a horizontal rule followed by: Departure City or Airport: [ ] Destination City or Airport: [ ] Departure Date: [ ] YYYY-MM-DD [Reset] [Show Flights] This is the end of the second form of this page. The [ ]'s indicate textfields, [Reset] resets this form, and [Show Flights] is a submit button with name State and value Show Flights. The airtransportation database only has flights stored in it from between August 1-4, 2001. The airports stoed in it are LAX, BOSTON, Charle de Gaulle, Orly, Halifax. If [Show Flights] is clicked, it calls the CKAirport() function which first checks if the three fields have been filled out. If not, CKAirport() returns the the message "Sorry, you did not give me enough data. Please fill in the starred fields." In the main switch the Intro function gets called with this message. Since there was a message passed to intro it draws, each field that was not filled in now has a * after it. Use the OutStar function to draw the *'s. If all fields were filled out, CKAirport() then queries the Airport table of the airtransportation database to see if it contains either an airport code or a city for both the departure and destination specified. If not it returns the message, "Sorry we do not service, name_of_city" (it does this twice if can't match either city.) then the switch in the main menu will reprint the intro screen. If there were two airports that match either the departure city or destination city, it goes to a new page which has a form that uses selection gadgets (done using the <select> tag look at DrawSelect function) to allow the user to specify the airport and continue with the request. Otherwise, (and also when this latter form was filled out) CKAirport returns("done"). This causes the main switch to call the Flight() function which outputs a page saying, "Select a flight:" then has a selection gadget so that the user can select a flight from among the flights list in the Flight table in the airtransportation database between the departure and destination airport on that day. It then has three buttons Main Menu, Continue. Clicking Main Menu goes to the intro page, Continue goes to a page which lists in a selection gadget all non-booked seats on this flight together with whether the seat is a window or aisle and if it is first or economy class. Flight() has already been written for you, but this is what it does if you'd like to understand the code. The page to select a seat is draw by the SelectSeat() function. Again, this page has Main Menu, Previous and Continue buttons. These works as before however, the Continue button this time causes the Itinerary("unsaved") function to be called. It generates a page which prints out the itinerary so far followed by three buttons: [Main Menu], [Previous], [Save itinerary]. The first two buttons do as before. Clicking [Save itinerary] causes SetCookies() to be called. This function writes cookies to the client machine with all the data of the itinerary. It then returns to the intro page but with "Itinerary saved" printed before the Travel Planner heading. If on the intro page the [Fetch Now] button is clicked the Itinerary("saved") functions is called. The cookie variable is looked at and the stored itinerary is regenerated and displayed. If no cookie was stored it calls the Intro function with the messafe "No previous itinerary." followed by the rest of the intro page. Some links ========== 1. airtransportation database schema 2. An example PHP program to list out airport table. 3. An example PERL DBI program to list out airport table. Point Breakdown for HW5 ======================= Code documentation.....................1pt Intro page prints as described.........1pt The previous itinerary button works....1pt Error handling for each page generated by script works as described..........................1pt Specify an airport page shows up if needed and works as described.........1pt Select a flight page works as described.............................1pt Select a seat page works as described.............................1pt Save itinerary works using cookies.....1pt Total..................................8pts Additional Bonus Problem: 3pts ======================== File to submit: p40hw5bon1.plx =============== put in same places as the main assignment. Will discuss Monday, March 5 after class necessary Tk to do this. Due date: same as HW6 ========= Specification: ============== Rewrite the above assignment as a stand-alone (not using browser) program using Perl/Tk and DBI. |