#!/usr/bin/perl use strict; # avoids unintentional variable declarations use warnings; use CGI qw(:all *table *Tr *td); # 'standard' allows most of CGI.pm methods to be used as functions # '*table' allows use of start_table() and end_table() functions # '*Tr' allows use of start_Tr() and end_Tr() functions use CGI::Carp "fatalsToBrowser"; use DBI; require "CCvalidate.inc"; # PRODUCT INFORMATION: my $dbh = do_connect(); my $productID = "".param("productID"); my $query = "select product_name, product_price, product_image from product"; my $sth = $dbh->prepare($query); $sth->execute(); # these variables hold information about the products selected by the customer my ($productName, $price, $productImage); ($productName, $price, $productImage) = $sth->fetchrow_array; my $quantity = param("quantity"); my $subtotal = $quantity * $price; my $GST = sprintf ('%.2f', $subtotal * 0.07); my $PST = sprintf ('%.2f', $subtotal * 0.08); my $total= $subtotal + $GST + $PST; # CUSTOMER INFORMATION: # these variables hold the personal information entered by the customer my $name = param("name"); my $email = param("email"); my $phone = param("phone"); my $address1 = param("address1"); my $address2 = param("address2"); my $city = param("city"); my $province = param("province"); my $postalCode = param("postalCode"); my $creditCardType = param("creditCardType"); my $creditCardNumber = param("creditCardNumber"); my $creditCardExpiry = param("creditCardExpiry"); my $creditCardName = param("creditCardName"); my $confirmationNumber; my $password; my $userID; # ERROR FLAGS: my $quantityError = 0; my $nameError = 0; my $emailError = 0; my $phoneError = 0; my $addressError = 0; my $cityError = 0; my $provinceError = 0; my $postalCodeError = 0; my $creditCardError = 0; my $creditCardNameError = 0; # MAIN SECTION: # create the html header print header(); # determines the correct page to display if(param("page") eq "catalogue") { checkQuantity(); if ($quantityError) { catalogue(); } else { calculations(); } } elsif(param("page") eq "goToCreateAccount") { personalInfo(); } elsif(param("page") eq "personalInfo") { validatePersonalInfo(); if ( $nameError || $emailError || $phoneError || $addressError || $cityError || $provinceError || $postalCodeError || $creditCardError || $creditCardNameError ) { personalInfo(); } else { confirmation(); } } elsif(param("page") eq "helpWindow"){helpWindow();} else{catalogue();} print end_html(); # SUBROUTINES: # Student Assignment Submission Form as required by assignment specifications sub submissionForm { print hr(), "", h3("Student Assignment Submission Form"), span ({-class=>"fineprint"}, "I declare that the attached assignment is wholly my 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)"), br, br, span ({-class=>"fineprint"},"Meledy Ang"), br, span ({-class=>"fineprint"},"Student# 016 518 029"), br, span ({-class=>"fineprint"},"April 8, 2003"), br, br; } # end of submissionForm() # CREATES THE MAIN CATALOGUE PAGE sub catalogue { print start_html( { -title=>"The Catalogue Page", -style=>{-src=>"./mymanager1.css"} } ); #pagetop(); print h2("Welcome to our company!"); print br, "Please select one of our remarcable products:", br, br, br, br; print start_form( { -action=>"index.cgi", -method=>"get" } ), start_table({-align=>"center"}); my $startRow; my $rowNumber; if(param("rowNumber") eq "") { $startRow = 0; } else { $startRow = param("row"); } print start_Tr(); my $dbh = do_connect(); my $query = "select product_id, product_name, product_desc, product_price, product_image from product where product_notforsale = '0' order by product_id LIMIT $startRow , 3;"; my $sth = $dbh->prepare($query); $sth->execute(); my ($product_id, $product_name, $product_desc, $product_price, $product_image); while(($product_id, $product_name, $product_desc, $product_price, $product_image) = $sth->fetchrow_array) { print td( {-align=>"center"}, img( { -src=>$product_image, -height=>"87", -width=>"80", -alt=>$product_name } ), br, "", br, span ( {-class=>"fineprint"}, $product_name, br, '$', $product_price ) ); } print end_Tr(); print start_Tr(), start_td({-align=>"center", -colspan=>'3'}); if(param("rowNumber") eq "") { $rowNumber = getNumberOfRows("select * from product where product_notforsale = '0';"); } else { $rowNumber = param("rowNumber"); } if($rowNumber != 0) { my $previous = ($startRow - 3) >= 0 ? ($startRow - 3) : 0; my $next = ($startRow + 3) < $rowNumber ? ($startRow + 3) : $5; print "
[<< Previous]";
	       print '     ';
	       print "[Next >>]
"; } print end_td(), end_Tr(); if ($quantityError == 1) # for product or quantity errors { print Tr( td( {-align=>"center", -colspan=>'3'}, comment("this cell only appears if any invalid product or quantity is selected"), span( {-class=>"invalid"}, "Please select a product and quantity." ) ) ); } print Tr( td( {-align=>"center", -colspan=>'3'}, "Quantity", popup_menu( -name=>"quantity", -values=>["--","0","1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","23","22","23","24","25"], -default=>"--" ) ) ); print Tr( td( {-align=>"center",-colspan=>"3"}, hr ) ), Tr( ### button row ### td({-align=>"center",-colspan=>"3",-valign=>"middle"}, comment(" this cell contains all the buttons "), comment(" submit button to choose product and quantity"), # submit button q(), ' ', comment(" clear form button"), # clear form button q(), ' ', comment(" Manager Options button "), # mangaer options button a( {-href=>"manager.cgi"}, img( { -src=>"./images/manager_mode.jpg", -height=>"40", -width=>"125", -alt=>"Manager Mode", -border=>"0" } ) ), ' ', br ) # end td ), # end of Tr end_table(), comment(" hidden fields to pass along necessary variables "), hidden(-name=>'page',-default=>'catalogue', -override=>'catalog'), # this names the page currently displayed end_form; submissionForm(); } # end of catalogue() # CREATES THE PRODUCT CALCULATIONS PAGE sub calculations { print start_html( { -title=>"Product Calculations", -style=>{-src=>"./mymanager1.css"} } ); #pagetop(); print h2("Your Order Information"), br, comment("This table shows the costs for the product the customer wants to purchase"), start_table({-align=>"center"}), Tr( td({-align=>"right",-valign=>"middle"}, 'Product :',br, 'Quantity:',br, 'Price :',br, 'Subtotal:',br, 'GST :',br, 'PST :',br, 'Total:' ), # end of td td({-align=>"left"}, $productName, br, $quantity, br, '$',$price, br, '$',$subtotal, br, '$',$GST, br, '$',$PST, br, '$',$total ), # end of td td({-valign=>"top",-valign=>"middle"}, img( { -src=>$productImage, -height=>"289", -width=>"266", -alt=>$productName } ) ) ), # end of Tr Tr( td( {-align=>"center",-colspan=>"3"}, hr ) ), Tr( ### button row ### td({-align=>"center",-valign=>"middle",-colspan=>"3"}, comment(" this cell contains all the buttons "), br, # submit button to order, customer already has account comment("submit button to order, customer already has account"), a( {-href=>"index.cgi?page=goToAccountLogin"}, img( { -src=>"./images/haveAccount.jpg", -height=>"40", -width=>"125", -alt=>"Place order, already have account", -border=>"0" } ) ), '  ', # submit button to order, customer needs to create account comment("submit button to order, customer needs to create account"), a( {-href=>"index.cgi?page=goToCreateAccount"}, img( { -src=>"./images/createAccount.jpg", -height=>"40", -width=>"125", -alt=>"Place order, do not already have account", -border=>"0" } ) ), '  ', # cancel order button, return to catalogue comment("cancel order button, return to catalogue"), a( {-href=>"index.cgi?page=cancel"}, img( { -src=>"./images/cancel.jpg", -height=>"35", -width=>"125", -alt=>"Cancel and Return to Catalogue", -border=>"0" } ) ), br, br ) # end of td ), # end of Tr end_table(); # end of product info table } # end of submissionForm() # CREATES THE PERSONAL INFORMATION ENTRY PAGE sub personalInfo { print start_html( { -title=>"Customer Information", -style=>{-src=>"./mymanager1.css"} } ); #pagetop(); print h2("Your Order Information"), "If the product information displayed here is correct,", br, "please fill in the form below so that we can process your order.", br, br, comment("This table is for the customer to fill in their shipping and payment info."), start_form({ -action=>"index.cgi", -method=>"get"}), start_table({-align=>"center", -border=>"2"}); if ($nameError) { print Tr( td({-align=>"center", -valign=>"bottom", -colspan=>"2"}, comment("this cell only appears if the name entered is invalid"), span({-class=>"invalid"}, "Invalid name! Please re-enter. Click on Help button for more information." ) ) ); } print Tr( td({-align=>"right"},"Full Name"), td({-align=>"left"}, textfield( { -name=>"name", -size=>"40", -maxlength=>"40" } ) ) ); if ($emailError) { print Tr( td({-align=>"center", -valign=>"bottom", -colspan=>"2"}, comment("this cell only appears if the email entered is invalid"), span({-class=>"invalid"}, "Invalid email address! Please re-enter. Click on Help button for more information." ) ) ); } print Tr( td({-align=>"right"},"Email Address"), td({-align=>"left"}, textfield( { -name=>"email", -size=>"40" } ) ) ); if ($phoneError) { print Tr( td({-align=>"center", -valign=>"bottom", -colspan=>"2"}, comment("this cell only appears if the phone number entered is invalid"), span({-class=>"invalid"}, "Invalid telephone number! Please re-enter. Click on Help button for more information." ) ) ); } print Tr(td({-align=>"right"},"Phone Number"), td({-align=>"left"}, textfield( { -name=>"phone", -size=>"15" } ) ) ); if ($addressError) { print Tr( td({-align=>"center", -valign=>"bottom", -colspan=>"2"}, comment("this cell only appears if the address entered is invalid"), span({-class=>"invalid"}, "Invalid address! Please re-enter. Click on Help button for more information." ) ) ); } print Tr( td({-align=>"right"},"Address"), td({-align=>"left"}, textfield( { -name=>"address1", -size=>"40", -maxlength=>"40" } ), br, textfield( { -name=>"address2", -size=>"40", -maxlength=>"40" } ) ) ); if ($cityError) { print Tr( td({-align=>"center", -valign=>"bottom", -colspan=>"2"}, comment("this cell only appears if the city entered is invalid"), span({-class=>"invalid"}, "Invalid city! Please re-enter. Click on Help button for more information." ) ) ); } print Tr( td({-align=>"right"},"City"), td({-align=>"left"}, textfield( { -name=>"city", -size=>"40", -maxlength=>"40" } ) ) ); if ($provinceError) { print Tr( td({-align=>"center", -valign=>"bottom", -colspan=>"2"}, comment("this cell only appears if the province entered is invalid"), span({-class=>"invalid"}, "Invalid province! Please re-select. Click on Help button for more information." ) ) ); } print Tr( td({-align=>"right"},"Province"), td({-align=>"left"}, popup_menu( -name=>"province", -values=>["---","AB","BC","MB","NB","NF","NS","NT","ON","PE","QC","SK","YT"], -default=>"---" ), "       ", "      ", "Postal Code  ", textfield( { -name=>"postalCode", -size=>"7", -maxlength=>"7" } ), ) ), Tr( td({-align=>"center",-colspan=>"2"}, "  ") ); if ($creditCardError) { print Tr( td({-align=>"center", -valign=>"bottom", -colspan=>"2"}, comment("this cell only appears if the credit card info entered is invalid"), span({-class=>"invalid"}, "Invalid credit card! Please re-enter. Click on Help button for more information." ) ) ); } print Tr( td({-align=>"right"},"Credit Card"), td({-align=>"left"}, radio_group( -name=>"creditCardType", -values=>["VISA", "MasterCard", "AmericanExpress"], -default=>"noSelection", -rows=>"1", -columns=>"3" ) ) ), Tr( td({-align=>"right"},"Credit Card Number"), td({-align=>"left"}, textfield( { -name=>"creditCardNumber", -size=>"16", -maxlength=>"16" } ), "      ", "Expiry Date  ", textfield( { -name=>"creditCardExpiry", -size=>"5", -maxlength=>"5" } ), ) ); if ($creditCardNameError) { print Tr( td( {-align=>"center", -valign=>"bottom", -colspan=>"2"}, comment("this cell only appears if the card holder name entered is invalid"), span({-class=>"invalid"}, "Invalid name! Please re-enter. Click on Help button for more information." ) ) ); } print Tr( td({-align=>"right"}, "Card Holder's Name", br, span({-class=>"fineprint"},"(required only if", br, "different from above)") ), td({-align=>"left"}, textfield( { -name=>"creditCardName", -size=>"40", -maxlength=>"40" } ) ) ), Tr( td({-align=>"center",-colspan=>"2"}, "  ") ), Tr( ### button row ### td( {-align=>"center",-colspan=>"2",-valign=>"middle"}, comment(" this cell contains all the buttons "), comment(" submit button to place order"), # submit button to place order q(), '  ', comment(" clear form button"), # clear form button q(), '  ', comment(" cancel order, return to catalogue/home button "), # cancel button a( {-href=>"index.cgi"}, img( { -src=>"./images/cancel.jpg", -height=>"40", -width=>"125", -alt=>"Cancel and Return to Catalogue", -border=>"0" } ) ), '  ', comment("clicking this button creates a new window displaying the validation rules for the customer's personal information"), q(Help), br, '  ' ) # end of td ), # end of Tr end_table(), # end of customer info table comment(" hidden fields to pass along necessary variables "), hidden( -name=>'page', -default=>'personalInfo', -override=>'personalInfo' ), # this names the page currently displayed hidden(-name=>'productID',-default=>$productID), hidden(-name=>'quantity',-default=>$quantity), end_form(); } # end of personalInfo() # CREATES THE ORDER CONFIRMATION PAGE sub confirmation { open DICT, "/usr/share/dict/words"; # Get all the 4-6 letter words (no capitals!) my @dictionary=grep(/^[a-z]{4,6}$/, ); # Chomp off the \n at the end of the lines chomp @dictionary; # Pick two words (actually, pick two numbers) my $word1=int(rand(scalar(@dictionary))); my $word2=int(rand(scalar(@dictionary))); my $password = $dictionary[$word1] . " " . $dictionary[$word2]; # writes order information into database my $dbh = do_connect(); my $query = "insert into user values(','$email','$password','$name','','$phone','$address1','$address2','$city','$province','$postalCode','$creditCardType','$creditCardNumber','$creditCardExpiry','$creditCardName');"; my $sth = $dbh->prepare($query); $sth->execute(); $sth->finish; $dbh->disconnect; $dbh = do_connect(); $query = "select user_id from user where user_password = '$password';"; $sth = $dbh->prepare($query); $sth->execute(); ($userID) = $sth->fetchrow_array; $sth->finish; $dbh->disconnect; $dbh = do_connect(); $query = "insert into history values('', '$productID', '$userID', '$quantity', sysdate(), '$total');"; $sth = $dbh->prepare($query); $sth->execute(); $sth->finish; $dbh->disconnect; print start_html( { -title=>"Order Confirmation", -style=>{-src=>"./mymanager1.css"} } ); #pagetop(); print h2("Thank You for Your Order."); print br, "Your order has been placed sucessfully.", br, "A confirmation number has been issued for this order and you have been given a password.", br, "A copy of this information will be sent to the email address you specified.", br, br, br, start_table({-align=>"center", -style=>'background-color: #99ccff;'}), Tr( td({-align=>"center",-colspan=>'4'}, "Your confirmation number is:  ", $confirmationNumber, br, "Your password is:  ", $password ) # end of td ), # end of Tr Tr( td({-align=>"center",-valign=>"top",-colspan=>'2'}, img( { -src=>$productImage, -height=>"87", -width=>"80", -alt=>$productName } ),br, ), # end of td td({-align=>"right",-valign=>"middle",-rowspan=>'2'}, 'Name :', br, 'Email :', br, 'Phone :', br, 'Address:',br,br, 'City :', br, 'Province:', br, 'PostalCode:', br, 'Credit Card:', br, 'Credit Card Number:', br, 'Credit Card Expiry:', br, 'Cardholder Name:' ), # end of td td({-align=>"left",-valign=>"middle",-rowspan=>'2'}, $name, br, $email, br, $phone, br, $address1,br,$address2, br, $city, br, $province, br, $postalCode, br, $creditCardType, br, $creditCardNumber, br, $creditCardExpiry, br, $creditCardName ) # end of td ), # end of Tr Tr( td({-align=>"right",-valign=>"middle"}, 'Product :',br, 'Quantity:',br, 'Price :',br, 'Subtotal:',br, 'GST :',br, 'PST :',br, 'Total:' ), # end of td td({-align=>"left"}, $productName, br, $quantity, br, '$',$price, br, '$',$subtotal, br, '$',$GST, br, '$',$PST, br, '$',$total ) # end of td ), # end of Tr Tr( td({-align=>"center", -colspan=>"4"}, comment("return to catalogue/home button"), # home button a( {-href=>"index.cgi"}, img( { -src=>"./images/copyOK.jpg", -height=>"35", -width=>"125", -alt=>"Return to Catalogue", -border=>"0" } ) ), ) # end of td ), # end of Tr end_table(); # this send the confirmation email to the customer open EMAIL, qq(|mail -s "INT322D i3222d12" $email) or die("can't send email"); print EMAIL "Meledy Ang\ni3222d12\nmang1\@learn.senecac.on.ca\nhttp://zenit.senecac.on.ca/~i3222d12/assign3/index.cgi\n \n\nThis is the information you have given to us:\n\nName :$name\nEmail :$email\nPhone :$phone\nAddress:$address1\n$address2\nCity :$city\nProvince:$province\n PostalCode:$postalCode\n\nCredit Card:$creditCardType\nCredit Card Number:$creditCardNumber\nCredit Card Expiry:$creditCardExpiry\nCardholder Name:$creditCardName\n\n\nThis is your confirmation number: $confirmationNumber\n Your password is:$password\n\n\nProduct Order Detail:\n\nProduct :$productName\nQuantity:$quantity\nPrice :$price \nSubtotal:$subtotal\nGST :$GST\nPST :$PST\nTotal:$total\n\n"; # email text close EMAIL; } # end of confirmation() # CREATES HELP PAGE SHOWING THE VALIDATION RULES FOR CUSTOMER'S PERSONAL INFO sub helpWindow { print start_html( { -title=>"Personal Information Help", -style=>{-src=>"./mymanager1.css"} } ), # CSS validation sticker "", a( {-href=>"http://jigsaw.w3.org/css-validator/validator-uri.html"}, img( { -src=>"http://jigsaw.w3.org/css-validator/images/vcss", -height=>"31", -width=>"88", -align=>"right", -alt=>"Valid CSS!", -border=>"0" } ) ), # XHTML validation sticker "", a( {-href=>"http://validator.w3.org"}, img( { -src=>"http://www.w3.org/Icons/valid-xhtml10", -height=>"31", -width=>"88", -align=>"right", -alt=>"Valid XHTML 1.0!", -border=>"0" } ) ), h2("How to enter valid personal information"), br, start_table({-align=>"center", -style=>'background-color: #99ccff;'}), Tr( td([b("Field"),b("Valid Values and Format"),b("Additional Information")]), ), Tr( td({-style=>'font-size:13px;'},[b("Full Name"),"2-40 letters (can also include dashes,periods, and internal spaces)","Required"]), ), Tr( td({-style=>'font-size:13px;'},b("Email")), td({-style=>'font-size:13px;'}, "Must be in one of the following formats:", br, "user\@wherever", br, "user\@wherever (Human Readable Name)", br, "Human Readable Name <user\@wherever>", br, br, "The \"user\" portion must be 1-20 characters long, have no spaces and can consist of letters, digit, underscores, dashes, and periods.", br, "The \"wherever\" portion must be a a host or domain name consisting of at least two groups of characters spearated by a period. These groups must be at least 2 characters long, start with a letter, and can contain only letters, digits, and underscores.", br, "The \"Human Readable Name\" can composed of 0-40 printable characters not including <, >, \(, or \)" ), td({-style=>'font-size:13px;'},"Required"), ), Tr( td({-style=>'font-size:13px;'},b("Phone Number")), td({-style=>'font-size:13px;'},"10 digits in the following format:", br, "(416) 555-5555", br, "Any characters other than numbers will be ignored. You don't have to worry about getting the parenthesis and dashes correct, we will format that for you."), td({-style=>'font-size:13px;'},"Required"), ), Tr( td({-style=>'font-size:13px;'},[b("Address"),"The first line must be at least 3 printable characters long. You can continue onto the second line if necessary. Each line can contain a maximum of 40 characters. ","Required"]), ), Tr( td({-style=>'font-size:13px;'},[b("City"),"Must be 2-40 prinitable characters, beginning with a capital letter","Required"]), ), Tr( td({-style=>'font-size:13px;'},[b("Province"),"Must be 2 uppercase letters. Select from AB, BC, MB, NB, NF, NS, NT, ON, PE, QC, SK, YT.", "Required"]), ), Tr( td({-style=>'font-size:13px;'},b("Postal Code")), td({-style=>'font-size:13px;'}, "Must be a valid postal code recognized by Canada Post. It must consist of 2 groups of 3 characters separated by a space in this format:", br, "Q9Q 9Q9", br, "where \'Q\' is any uppercase letter and \9\'is any digit.", br, "If you forget to insert the space of if use lowercase letters, we will correct this for you.", br, "The initial letter must agree with the province according to this list:", br, comment(" Table of Postal Codes "), table( Tr({-align=>'center'}, [ td({-style=>'font-size:13px;'},[' AB ',' T ',"      ",' NT ',' X ']), td({-style=>'font-size:13px;'},[' BC ',' V ',"      ",' ON ','K,L,M,M, or P']), td({-style=>'font-size:13px;'},[' MB ',' R ',"      ",' PE ',' C ']), td({-style=>'font-size:13px;'},[' NB ',' E ',"      ",' QC ','G,H,J, or K']), td({-style=>'font-size:13px;'},[' NF ',' A ',"      ",' SK ',' S ']), td({-style=>'font-size:13px;'},[' NS ',' B ',"      ",' YT ',' Y ']) ] ) ), comment(" end of inner table ") ), td({-style=>'font-size:13px;'},"Required"), ), Tr( td({-style=>'font-size:13px;'},[b("Credit Card"),"Must select one from those shown.","Required"]), ), Tr( td({-style=>'font-size:13px;'},b("Credit Card Number")), td({-style=>'font-size:13px;'},"13-16 digits, depending on type of card. No spaces!"), td({-style=>'font-size:13px;'},"Required"), ), Tr( td({-style=>'font-size:13px;'},b("Expiry Date")), td({-style=>'font-size:13px;'},"In the format YY/DD. Don't forget the /."), td({-style=>'font-size:13px;'},"Required"), ), Tr( td({-style=>'font-size:13px;'},b("Card Holder's Name")), td({-style=>'font-size:13px;'}, "2-40 letters (can also include dashes,periods, and internal spaces)", br, "If left blank, the customer's name will be used." ), td({-style=>'font-size:13px;'},"Optional"), ), Tr( td({-style=>'font-size:13px;'},[b("Special Instructions"),"No validation is done on this.","Optional"]), ), Tr( td({-style=>'font-size:13px;'},[b("Offer Code"),"If used, must be 5 digits (this includes a valid check digit).","Optional"]), ), Tr( td( {-align=>"center", -colspan=>"3"}, br,br, button( { -name=>"Close Window", -onclick=>"window.close();" } ) ) ), end_table(), br,br; } # end of helpWindow() # VALIDATION SUBROUTINES: sub validatePersonalInfo { checkName(); checkEmail(); checkPhone(); checkAddress(); checkCity(); checkProvince(); checkPostalCode(); my $validCard = CCvalidate($creditCardType, $creditCardNumber, $creditCardExpiry); $validCard = time(); if ($validCard == 0) { $creditCardError = 1; } else { $confirmationNumber = $validCard; } checkCreditCardName(); } # toggles flag if error detected in Quantity sub checkQuantity { if ($quantity < 1 || $quantity > 25) { $quantityError = 1; } } # toggles flag if error detected in Full Name sub checkName { if(!($name =~m/^[A-Za-z,-\.][A-Za-z,-\. ]{0,38}[A-Za-z,-\.]$/)) { $nameError = 1; } } # toggles flag if error detected in Email sub checkEmail { my $user = '[A-Za-z][-A-Za-z0-9_\.]{0,19}'; my $fqdn = '[A-Za-z][A-Za-z0-9_]*([\.][A-Za-z][A-Za-z0-9_]*)+'; my $hrname1 = '[[:print:]]{0,40}'; my $hrname2 = '[^()<>]{0,40}'; if( # format 1: user@fqdn !($email =~ m/^$user\@$fqdn$/) && # format 2: user@fqdn (hrname) (!($email =~ m/^$user\@$fqdn \($hrname1\)$/) || !($email =~ m/^$user\@$fqdn \($hrname2\)$/)) && # format 3: hrname (!($email =~ m/^$hrname1 <$user\@$fqdn$>$/) || !($email =~ m/^$hrname2 <$user\@$fqdn$>$/)) ) { $emailError = 1; } } # toggles flag if error detected in Phone sub checkPhone { $phone =~ s/[^0-9]//g; if($phone =~ m/^[2-9][0-9]{9}$/) { $phone =~ s/^(...)(...)(....)$/\($1\) $2-$3/; } else { $phoneError = 1; } } # toggles flag if error detected in Address sub checkAddress { if(!($address1 =~ m/^[[:print:]]{3,40}$/) || !($address2 =~ m/^[[:print:]]{0,40}$/)) { $addressError = 1; } } # toggles flag if error detected in City sub checkCity { if(!($city =~ m/^[A-Z][[:print:]]{1,39}$/)) { $cityError = 1; } } # toggles flag if error detected in Province sub checkProvince { if(!($province =~ m/^(BC|AB|SK|MB|ON|QC|NB|NS|PE|NF|NT|YT)$/)) { $provinceError = 1; } } # toggles flag if error detected in Postal Code sub checkPostalCode { $postalCode = uc($postalCode); if ($postalCode =~ m/^([A-Z])\d[A-Z] ?\d[A-Z]\d$/) { if ( ($province eq 'NF' && $1 ne 'A') || ($province eq 'NS' && $1 ne 'B') || ($province eq 'PE' && $1 ne 'C') || ($province eq 'NB' && $1 ne 'E') || ($province eq 'QC' && ($1 =~ m/[^GHJK]/)) || ($province eq 'ON' && ($1 =~ m/[^KLMNP]/)) || ($province eq 'MB' && $1 ne 'R') || ($province eq 'SK' && $1 ne 'S') || ($province eq 'AB' && $1 ne 'T') || ($province eq 'BC' && $1 ne 'V') || ($province eq 'NT' && $1 ne 'X') || ($province eq 'YK' && $1 ne 'Y') ) { $postalCodeError = 1; } } else { $postalCodeError = 1; } } # toggles flag if error detected in Credit Card Name # If credit card name is blank, sets the credit card name to same as valid customer name sub checkCreditCardName { if ($creditCardName != "") { if(!($creditCardName =~m/^[A-Za-z,-\.][A-Za-z,-\. ]{0,38}[A-Za-z,-\.]$/)) { $creditCardNameError = 1; } } else { if ($nameError == 0) # see if customer name is valid { $creditCardName = $name; } } } sub do_connect { my $dbh = DBI->connect("DBI:mysql:database=i3222d12;zenit-db", "i3222d12", "94052026") or die"$DBI::errstr"; return $dbh; } sub getNumberOfRows { my $qry = shift; my $db = do_connect(); my $sth = $db->prepare($qry); $sth->execute(); return $sth->rows(); } #------------------------------------------------------------------------------ # creates top page block with company name and validation stickers #------------------------------------------------------------------------------ sub pagetop { # CSS validation sticker print "", a( {-href=>"http://jigsaw.w3.org/css-validator/validator-uri.html"}, img( { -src=>"http://jigsaw.w3.org/css-validator/images/vcss", -height=>"31", -width=>"88", -align=>"right", -alt=>"Valid CSS!", -border=>"0" } ) ); # XHTML validation sticker print "", a( {-href=>"http://validator.w3.org"}, img( { -src=>"http://www.w3.org/Icons/valid-xhtml10", -height=>"31", -width=>"88", -align=>"right", -alt=>"Valid XHTML 1.0!", -border=>"0" } ) ); print h1("Unique"); } # end of pagetop()