Chris Pollett > Old Classes > PIC40 ( Print View ) Lecture Notes-PDF Spring '01 Ad: Enrollment info Course Info:
Practice Exams: PIC: |
p40hw5file1.php --- last modified January 16 2019 00:35:22..<? if($State=="Save Itinerary"){SetCookies();} // // FileName: p40hw5file1.php (Travel Planner program) // // Purpose: This file accesses the airtransportation database to allow // user to make a travel itinerary based on the flight // information stored in this database. // ?> <html> <head> <title>Travel Planner</title> </head> <body bgcolor="#99FFCC"> <? // // Main Loop: // // $State variable is used to control which page is displayed switch($State) { case "Fetch Now": Itinerary("saved"); break; case "Save Itinerary": Intro("Itinerary Saved"); break; case "Show Flights": $MSG = CKAirport(); if($MSG == "Flight") {Flight();} else if($MSG != "done") {Intro($MSG);} break; case Previous: if($SEAT2) {Flight();} else {SelectSeat();} break; case Flight: Flight(); break; case "Continue": if($SEAT) {Itinerary("unsaved");} else {SelectSeat();} break; case "Main Menu": default: Intro(); } ?> </body> </html> <? // // Function: Intro // // Purpose: This function takes a message $MSG and if it exists // outputs in blue followed by the intro screen to // the Travel Planner program. If $MSG is false it // just outputs the intro screen. If $MSG has some value // then any of the form variables is not set it also // outputs a star by this element in the intro screen. // function Intro($MSG=false) { //your code here } // // Function:CKAirport // // Purpose: this function check if the three variables // $DEPCITY, $DESCITY, $DEPDATE all have values. // If not it returns the string "Sorry, you did not give // me enough data. Please fill in the starred fields." // Otheriwse, it looks at the Airport table of the airtransportation // database to see if $DEPCITY and $DESCITY are codes for // airports or are cities. If they are cities but there // is only one airport in that city the $DEPCITY or $DESCITY // is then set to the code of that airport. If at this // point both $DEPCITY and $DESCITY are codes of airports // then the value "Flight" is returned. If neither a code nor // a city could be found then "Sorry we not service $DEPCITY" // or "Sorry we nor service $DESCITY" or both is returned // by CKAirport. Finally, if there is more airport for $DESCITY // of $DEPCITY of both it produces a form with selection // selection gadgets to let the user pick between the possibilities. // after generating this form it returns the value "done". // function CKAirport() { // your code here } // // Function: Flight // // Purpose: produces the screen that allows the user to // select the from a list of available flights // between $DEPCITY and $DESCITY on $DEPDATE. // Queries the airtransportation database Flight // table to get this info. // function Flight() { GLOBAL $DEPCITY, $DESCITY, $DEPDATE; $dbh=Connect(); $cur=Prepare("select flightNo, airCraftName, dateTime from Flight where fromAirport='$DEPCITY' AND toAirport='$DESCITY' AND dateTime like '$DEPDATE%'"); ?> <h1>Travel Planner</h1> <hr> <form method="POST" action="p40hw5file1.php"> <table> <tr> <td> <h3>Please select a flight:</h3> </td> </tr> <tr> <td> <? DrawSelect($cur, "FLIGHT", 10); Close($dbh); ?> <td> </tr> <tr> <td> <? OutButton("hidden","DEPCITY",$DEPCITY); OutButton("hidden","DESCITY",$DESCITY); OutButton("hidden","DEPDATE",$DEPDATE); OutButton("submit","State","Main Menu"); OutButton("submit","State","Continue"); ?> </tr> </td> </table> </form> <?} // // Function: SetCookies // // Purpose: sets cookies to store the variables // $DEPCITY, $DESCITY, $DEPDATE, $FLIGHT, $SEAT // function SetCookies() { //your code here } // // Function: Itinerary // // Purpose: if $saved is equal to "saved". It copies the variables // stored in the cookies back into the variables // $DEPCITY, $DESCITY, $DEPDATE, $FLIGHT, $SEAT first. // In all cases, it then draws the itinerary that the // user has selected so far followed by the buttons // Main Menu, Previous, and Save Itinerary. // these either return to the Intro screen, select seat // screen or returns to Intro screen with saved info // message and where the first line of the program has been // execute to set the appropriate cookies. // function Itinerary($saved) { //your code here } // // Function: SelectSeat // // Purpose: This function draws the screen to allow the user to pick a // from the available seats on a given flight. // function SelectSeat() { GLOBAL $DEPCITY, $DESCITY, $DEPDATE, $FLIGHT; $flArray = split( "#", $FLIGHT); $flightNo = $flArray[0]; $aircraft = $flArray[1]; $dateTime = $flArray[2]; ?> <h1>Travel Planner</h1> <hr> <form method="POST" action="p40hw5file1.php"> <table> <tr> <td> <h3>Please select a seat:</h3> </td> </tr> <tr> <td> The information below is formatted as follows: </td> </tr> <tr> <td> Row#Seat#Aisle?#Window?#Class </td> </tr> <tr> <td> <? print "<select name=\"SEAT\" size=\"10\">\n"; $flag=true; $dbh=Connect(); // // Notice I open up two cursors at this point. I wouldn't // need to do this on a database // $cur=Prepare("select rowNo, seat,aisle,window, class from AircraftRow where airCraftName = '$aircraft'"); while($row = FetchRow($cur)) { $cur2=Prepare("select rowNo, seat from Bookings where flightNo='$flightNo' and dateTime='$dateTime' and rowNo='$row[0]' and seat='$row[1]' "); if(!FetchRow($cur2)) { OutOption($flag,$row); if($flag) {$flag=false;} } } Close($dbh); ?> </select> <td> </tr> <tr> <td> <? OutButton("hidden","DEPCITY",$DEPCITY); OutButton("hidden","DESCITY",$DESCITY); OutButton("hidden","DEPDATE",$DEPDATE); OutButton("hidden","FLIGHT",$FLIGHT); OutButton("hidden","SEAT2","true"); OutButton("submit","State","Main Menu"); OutButton("submit","State","Previous"); OutButton("submit","State","Continue"); ?> </tr> </td> </table> </form> <?} // // Function: OutButton // // Purpose: draws to screen a button of type $type with name $name // and with value $value. // function OutButton($type,$name,$value) { print "<input type=\"$type\" name=\"$name\" value =\"$value\" />"; } // // Function: OutText // // Purpose: draws to screen a textfield of type $type with name $name // and with value $value of size $size and max number of char's // maxlength. // function OutText($name,$value,$size,$maxLength) { print "<input type=\"text\" name=\"$name\" value =\"$value\""; print " size=\"$size\" maxlength=\"$maxLength\" />"; } // // Function: OutStar // // Purpose: draws a bold-face blue star // function OutStar() { print "<b style=\"color:blue\">*</b>\n"; } // // Function: OutOption // // Purpose: Writes out an option of a selection gadget // If $selected is true this will be a selected option // of the selection gadget. $row is the value of the option. // function OutOption($selected,$row) { if($selected) {print "<option selected=\"true\">"; $flag=false; } else {print "<option>";} foreach($row as $field) { print "$field#"; }?> </option> <?} // // Function: DeleteSharp // // Purpose: returns the substring of $string before the first # symbol // function DeleteSharp($string) { $row=split("#",$string); return $row[0]; } // // Function:DrawSelect // // Purpose: Draws a selection gadget with name $name where the options // are given by cycling over the rows returned by the database // cursor $cursor. // function DrawSelect($cursor, $name, $rowsVisible) { print "<select name=\"$name\" size=\"$rowsVisible\">\n"; $flag=true; while($row = FetchRow($cursor)) { OutOption($flag,$row); if($flag) { $flag=false;} }?> </select> <?} // // Function:Connect // // Purpose: connect to the database system. // function Connect() { //your code here } // // Function: FetchRow // // Purpose: // function FetchRow($cursor) { // your code here } // // Function:NumRows // // Purpose: returns the numbers of rows left in database cursor $cursor. // function NumRows($cursor) { return mysql_num_rows($cursor); } // // Function: Prepare // // Purpose: prepares an SQL query to be executed // function Prepare($query) { //your code here } // // Function:FreeCursor // // Purpose: frees a cursor // function FreeCursor($cursor) { //your code here } // // Function: Close // // Purpose: closes a database handle $dbhandle // function Close($dbhandle) { //your code here } ?> |