#!/usr/bin/perl -w # Add Content-type print "Content-type: text/html\n\n"; # print "pragma: no-cache\n\n"; #NEW Student Assignment Submission Form #======================================= #I/we declare that the attached assignment is my/our own work in accordance with #Seneca Academic Policy. No part of this assignment has been copied manually or #electronically from any other source (including web sites) or distributed to other #students. #Name(s) Student ID(s) #----------------------------------------------------------------------------------- # MELEDY ANG 016-518-029 i3222d12 #================= May 20,2002 ====================================== # # Read xhtml form variables submitted via the 'get' method # # This code supplied by the INT322 instructors # # Loop through all of the QUERY_STRING name/value pairs # foreach ( split( "\&" , $ENV{QUERY_STRING} ) ) { # # Split each pair into name and value # (my $name, my $value) = split("="); # # Replace each + with a space and decode # hex values into ASCII (e.g. '%40' to '@' etc..) # $value =~ tr/+/ / ; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg ; # # Place the decoded value into %form_element # $form_element{$name}=$value; } # To access form variables use $form_element{name} #==================================================================== # ---> assign the values into the variable #my $i; my $brand = $form_element{brand}; my $quantity = $form_element{quantity}; my %notebook_cost = ( "1" => "1399.00", "2" => "1459.00", "3" => "959.00", "4" => "1599.00"); my %notebook_name = ( "1" => "IBM Thinkpad T23", "2" => "SONY VAIO PCB-GRS 150", "3" => "HP Pavilion ze1230", "4" => "Fuijitsu Lifebook C21111"); # -----> xHTML HEADER ----------------------------------- #print <\n"; print "\n"; print "\n"; print "\n"; #EOF # -------------- HEADER TITLE FUNCTION ----------------------------------- sub xhtml_head_body { print " $_[0] Assignment\n"; # print "\n"; print "\n"; # ----> Prints the body for Page 1 print "\n"; print "
\n"; print "

Notebook $_[0]

\n"; print "
\n"; } # ------------------ HEADER TITLE FUNCTION ENDS HERE --------------------- # ----------------- XHTML VALIDATION FUNCTION ---------------------------- sub validator { print "

\n"; print "\n"; print "

\n"; } # ----------------- XHTML VALIDATION FUNCTION ENDS HERE ------------------ # ---------------- NaAVIGATION ------------------------------------------- # --------------- NAVIGATION ENDS HERE ----------------------------------- # ---------------- SHOW IMAGE FUNCTION ------------------------------------ sub showImage { $brand = $form_element{brand}; if ($brand == 1) { print "\"$notebook_name{$brand}\"\n"; } elsif ($brand == 2) { print "\"$notebook_name{$brand}\"\n"; } elsif ($brand == 3) { print "\"$notebook_name{$brand}\"\n"; } else { print "\"$notebook_name{$brand}\"\n"; } } # ----------------- SHOW IMAGE FUNCTION ENDS HERE ------------------------ # ------------------ FORM FUNCTION --------------------------------------- sub xhtml_form { # --> shows the correspnding picture print "
\n"; &showImage; print "
\n"; # --> Start of the form statement print "
\n"; print "\n"; # --> Choose the Notebook's Brand Name print "\n"; print "\n"; print "\n"; print "\n"; # --> Enter the Order Quantity print "\n"; print "\n"; print "\n"; print "\n"; # --> Submit Button print "\n"; print "\n"; print "\n"; print "
\n"; print "

Please select the Notebook brand you want to order:

\n"; print "
\n"; print "\n"; print "
\n"; print "

Please enter the quantity of the notebooks you want to order:

\n"; print "
\n"; print "\n"; print "
\n"; print "\n"; print "
\n"; print "
\n"; print "
\n"; } # ------------------ FORM FUNCTION ENDS HERE ----------------------------- # ------------------ BODY ENDER FUNCTION --------------------------------- sub xhtml_end_body { print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "
\n"; print " Home \n"; print "\n"; print " Page 1 \n"; print "
\n"; print "
\n"; print "
\n"; print "\n"; } # ------------------ BODY ENDER FUNCTION ENDS HERE ----------------------- # --------- PAGE ONE STARTS HERE ----------------------------------------- # ORDER FORM PAGE if (!$form_element{quantity}) { # --> Call the xhtml header tag function xhtml_head_body("Order Form"); &validator; print "
\n"; print "

WELCOME !

\n"; print "
\n"; # --> Call the form function &xhtml_form; # ---> assign the values into the variable $brand = $form_element{brand}; $quantity = $form_element{quantity}; # --> Call the xhtml ending tag function &xhtml_end_body; } # -------------------- END OF PAGE 1 -------------------------------- # -------- PAGE TWO STARTS HERE ------------------------------------- # ERROR MESSAGE PAGE elsif ($form_element{quantity} < 1 || $form_element{quantity} > 10) { # --> Call the xhtml header tag function xhtml_head_body("Error Page"); &validator; # --> Error Message print "

Transaction Terminated.

\n"; print "

You have entered an invalid number for quantity.

\n"; print "

Please enter a number between 1 and 10 only.

\n"; print "
\n"; # ---> Reshown the form by calling the xhtml form function &xhtml_form; # ---> assign the values into the variable $brand = $form_element{brand}; $quantity = $form_element{quantity}; # --> Call the xhtml ending tag function &xhtml_end_body; } # -------------------- END OF PAGE 2 -------------------------------- # -------- PAGE THREE STARTS HERE ----------------------------------- # RESULTS PAGE else { # --> Call the xhtml header tag function xhtml_head_body("Result Page"); &validator; print "

You have ordered the following product:

\n"; print "
\n"; # --> Enter the total cost of order my $subtotal = ($notebook_cost{$brand}) * $quantity; my $gst = $subtotal * 0.07; my $pst = $subtotal * 0.08; my $total = $subtotal + $gst + $pst; print "\n"; # --> Brand Name print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; # --> Quantity of Notebook Ordered print "\n"; print "\n"; print "\n"; print "\n"; # --> Unit Price print "\n"; print "\n"; print "\n"; print "\n"; # --> Extended Price print "\n"; print "\n"; print "\n"; print "\n"; # -- GST TAX print "\n"; print "\n"; print "\n"; print "\n"; # --> PST TAX (Provincial Tax = 8%) print "\n"; print "\n"; print "\n"; print "\n"; # --> Total Price of Product print "\n"; print "\n"; print "\n"; print "\n"; print "
\n"; &showImage; print "\n"; print "

Brand Name :

\n"; print "
\n"; printf ("

%s

\n", $notebook_name{$brand}); print "
\n"; print "

Quantity :

\n"; print "
\n"; printf ("

%d

\n", $quantity); print "
\n"; print "

Unit Price :

\n"; print "
\n"; printf ("

\$%.2f

\n", $notebook_cost{$brand}); print "
\n"; print "

Extended Price :

\n"; print "
\n"; printf ("

\$%.2f

\n", $subtotal); print "
\n"; print "

GST (7\%) :

\n"; print "
\n"; printf ("

\$%.2f

\n", $gst); print "
\n"; print "

PST (8\%) :

\n"; print "
\n"; printf ("

\$%.2f

\n", $pst); print "
\n"; print "

Total Price :

\n"; print "
\n"; printf ("

\$%.2f

\n", $total); print "
\n"; # --> Call the xhtml ending tag function &xhtml_end_body; } # -------------------- END OF PAGE 3 -------------------------------- print < EOF