#!/usr/bin/perl -wT ###################################################################################### # Travel Email Form for CnK # By Tim Reynolds # 11/28/2001 ###################################################################################### #### # To Do: # # IMPORTANT!!!!!!!!!!! # - Add hidden fields to every section with a for loop in order to save state for the data # use the for loop in the confirm routine of the html code as an example. #### ######################################## # Configuration Area # ####################################### #### # CGI.pm config #### use CGI qw (:standard); use CGI::Carp qw(fatalsToBrowser); $q = new CGI; # set path for links in lib file $pathL2 = '/travel-destinations'; $baseHREF = 'http://www.coxandkingsusa.com/new/travel-destinations'; #$baseHREF = 'http://macbook.local/cnk/new/travel-destinations'; #### #### # Field Configuration #### ## This array is the names of the fields that you want in your database. @fields = ( "travellers_first_name", "travellers_last_name", "trav2fn", "trav2ln", "trav3fn", "trav3ln", "africa", "asia", "middleeast", "indian_ocean", "latinamerica", "escorted_group", "private_travel", "family_travel", "signaturesafaris", "signaturefamilysafaris", "comments", "emailnews", "brochure_first_name", "brochure_last_name", "brochure_address", "brochure_city", "brochure_zip", "brochure", "brochure_companion_first_name", "brochure_companion_last_name", "brochure_companion_address", "brochure_companion_city", "brochure_companion_zip", "companion_brochure", "phone_number", "email", "brochure_state", "brochure_companion_state", 'hear', 'india_beyond' ); # field count should be 33 $field_count = @fields; ## This array holds the name of each field (Rendered HTML) that appears next to the field @field_names = ("First Name", "Last Name", "First Name", "Last Name", "First Name", "Last Name", "Africa", "Asia & Pacific", "Arabia & Northern Africa", "Indian Ocean", "Latin America", "Escorted/Group Travel", "Private Travel", "Family Travel", "Signature Safari & Travel Journeys", "Signature Family Safaris", "Comments", "Email Newsletter", "First Name", "Last Name", "Street Address", "City", "Zip", "Select a Brochure", "First Name", "Last Name", "Street Address", "City", "Zip", "Select a Brochure", "Phone Number", "Email", "State", "State", "HowĘdid you hear about Cox & Kings?", "India & Beyond" ); #### # Import all variables #### import_names('IN'); #### # Field Values # # these are the values that are processed after the user inputs information #### @fields_vals = ( "$IN::travellers_first_name", "$IN::travellers_last_name", "$IN::trav2fn", "$IN::trav2ln", "$IN::trav3fn", "$IN::trav3ln", "$IN::africa", "$IN::asia", "$IN::middleeast", "$IN::indian_ocean", "$IN::latinamerica", "$IN::escorted_group", "$IN::private_travel", "$IN::family_travel", "$IN::specialescortedtravel", "$IN::privatetravelsafaris", "$IN::comments", "$IN::emailnews", "$IN::brochure_first_name", "$IN::brochure_last_name", "$IN::brochure_address", "$IN::brochure_city", "$IN::brochure_zip", "$IN::brochure", "$IN::brochure_companion_first_name", "$IN::brochure_companion_last_name", "$IN::brochure_companion_address", "$IN::brochure_companion_city", "$IN::brochure_companion_zip", "$IN::companion_brochure", "$IN::phone_number", "$IN::email", "$IN::brochure_state", "$IN::brochure_companion_state", "$IN::hear", "$IN::india_beyond" ); #### ## sets fields that are required ## this array is used in check_missing and print_warning ## will check the variables to se if they are empty #### #### # My blurb about the mess below # # OK @REQUIRED starts out as a basic set of parameters # then it hits the if statement for the first brochure which sets @REQ # if anything in it's block is true # however in the next set of if's @REQ will be overwritten if it is true # which means if the second brochure contains data in any of it's fields # it's a top down modification of @REQ #### # triggers valid reponse in html if user fills out any incomplete information in # brochure sections # # triggerred when set to "y" in if else statements below # &print_warning then check to see if x="y" $x="n"; @REQUIRED = qw/travellers_first_name travellers_last_name phone_number email/; if ($IN::brochure_first_name || $IN::brochure_last_name || $IN::brochure_address || $IN::brochure_city || $IN::brochure_state || $IN::brochure_zip) { $x="y"; if ($IN::brochure_first_name && $IN::brochure_last_name && $IN::brochure_address && $IN::brochure_city && $IN::brochure_state && $IN::brochure_zip) { if ($IN::brochure_companion_first_name || $IN::brochure_companion_last_name || $IN::brochure_companion_address || $IN::brochure_companion_city || $IN::brochure_companion_state || $IN::brochure_companion_zip ) { @REQUIRED = qw/travellers_first_name travellers_last_name phone_number email brochure_companion_first_name brochure_companion_last_name brochure_companion_address brochure_companion_city brochure_companion_state brochure_companion_zip/; } } else { $x="y"; @REQUIRED = qw/travellers_first_name travellers_last_name phone_number email brochure_first_name brochure_last_name brochure_address brochure_city brochure_state brochure_zip/; } } ### end of first check ### start of check for second brochure if ($IN::brochure_companion_first_name || $IN::brochure_companion_last_name || $IN::brochure_companion_address || $IN::brochure_companion_city || $IN::brochure_companion_state || $IN::brochure_companion_zip ) { $x="y"; if ($IN::brochure_first_name || $IN::brochure_last_name || $IN::brochure_address || $IN::brochure_city || $IN::brochure_state || $IN::brochure_zip ) { $x="y"; @REQUIRED = qw/travellers_first_name travellers_last_name phone_number email brochure_first_name brochure_last_name brochure_address brochure_city brochure_state brochure_zip brochure_companion_first_name brochure_companion_last_name brochure_companion_address brochure_companion_city brochure_companion_state brochure_companion_zip/; } else { $x="y"; @REQUIRED = qw/travellers_first_name travellers_last_name phone_number email brochure_companion_first_name brochure_companion_last_name brochure_companion_address brochure_companion_city brochure_companion_state brochure_companion_zip/; } } #### end of check for second brochure #### end of field configuration #### # HTML Library File # # html for form which includes user input -- confirmation pages and initial page #### require "/u/web/coxan2/cgi-local/travel_form/travel_form_html_n.lib"; require "/u/web/coxan2/cgi-local/subr/fullPage_n.lib"; #require "/Library/WebServer/CGI-Executables/travel_form/travel_form_html_n.lib"; #require "/Library/WebServer/CGI-Executables/subr/fullPage_n.lib"; ### # Sendmail Config # # location of sendmail #### # set path for sendmail # needed in order to run with -T $ENV{PATH} = "/bin:/usr/lib"; # path # live path $mail_loc = "/usr/lib/sendmail -t"; # #### local setting - make to change back to live setting #### # # #$mail_loc = "/usr/sbin/sendmail -t"; ##### # Variable Configuration ##### # main variable config $to = "tours\@coxandkingsusa.com"; #$to = "tim\@cdmusicpage.com, susan\@mcreative.com"; $from = "tours\@coxandkingsusa.com"; # used in travel_form_html.lib to set form action url $script = "http://www.coxandkingsusa.com/cgi-local/travel_form/travel_form.cgi"; #$script = "http://192.168.1.101/cgi-local/travel_form/travel_form_n.cgi"; # sets font size and face for all form fields $font = ""; # sets font size and face for all main text that appears above the form $main_text_font = ""; # variable for actions $action = $q->param("action"); ### end of variable config #### # Date and Time config #### use POSIX 'strftime'; my $date = strftime('%D', localtime); my $str_time = strftime('%T', localtime); #### #### # DO I NEED TO print this header? # already have this in subroutine html code? #### print $q->header; #### Call checkbox_state so boxes save state always &checkbox_state; ####################################################################### # end of config area # ####################################################################### ### #### # Actions #### if($action =~ /submit/i){ # Add the record passed from the add record page &top_html; &check_print; &response_form; &bottom_html; } elsif($action =~ /confirm/i){ # Add record and display final page ✓ } else { &top_html; &first_form; &bottom_html; } exit; #### end of actions #### # Subroutines #### #### # Checkbox State # # checks to see what the value is for each checkbox # then prints out the proper html checkbox code # (check or unchecked) #### sub checkbox_state { ### make sure to write code for yes no radio button ### check for yes and no if ($fields_vals[6] eq "") { $field_val7 = ""; } else { $field_val6 = "checked"; } if ($fields_vals[7] eq "") { $field_val7 = ""; } else { $field_val7 = "checked"; } if ($fields_vals[8] eq "") { $field_val8 = ""; } else { $field_val8 = "checked"; } if ($fields_vals[9] eq "") { $field_val9 = ""; } else { $field_val9 = "checked"; } if ($fields_vals[10] eq "") { $field_val10 = ""; } else { $field_val10 = "checked"; } if ($fields_vals[11] eq "") { $field_val11 = ""; } else { $field_val11 = "checked"; } if ($fields_vals[12] eq "") { $field_val12 = ""; } else { $field_val12 = "checked"; } if ($fields_vals[13] eq "") { $field_val13 = ""; } else { $field_val13 = "checked"; } if ($fields_vals[14] eq "") { $field_val14 = ""; } else { $field_val14 = "checked"; } if ($fields_vals[15] eq "") { $field_val15 = ""; } else { $field_val15 = "checked"; } if ($fields_vals[17] eq "No") { $field_val17 = qq[yes | no ]; } else { $field_val17 = qq[yes | no ]; } # adding new checkbox if ($fields_vals[35] eq "") { $field_val35 = ""; } else { $field_val35 = "checked"; } } #### end of checkbox state #### # Check # # checks to see if any parameters are missing # then fills @_ or doesn't and then this is checked # in the confirm action #### sub check { my @missing = check_missing(param()); # this may also work !$scalar(@array) if (@missing == 0) { &mail; &top_html; &confirm_form; &bottom_html; } else { &top_html; &check_print; &response_form; &bottom_html; } } #### end of check #### # Check Print #### sub check_print { my @missing = check_missing(param()); if (@missing) { print "
"; print_warning(@missing); print "
"; return undef; } } #### end of check print sub check_missing { my (%p); grep (param($_) ne '' && $p{$_}++,@_); return grep(!$p{$_},@REQUIRED); } #### end of check missing #### # Mail #### sub mail { # Mail Label label is the file handle # the location of the send mail library open (MAIL, "| $mail_loc"); print MAIL "To: $to\n"; #print MAIL "Bcc: tim\@mcreative.com\n"; print MAIL "From: $from\n"; print MAIL "Subject: Travel Form Contact \n\n"; print MAIL "Names of the Travellers in party: \n"; print MAIL "------------------------------------\n"; print MAIL "1.Name: $fields_vals[0] $fields_vals[1] \n"; print MAIL "2.Name: $fields_vals[2] $fields_vals[3] \n"; print MAIL "3.Name: $fields_vals[4] $fields_vals[5] \n"; print MAIL "\n"; print MAIL "Contact Information: \n"; print MAIL "------------------------------------\n"; print MAIL "Phone Number: $fields_vals[30] \n"; print MAIL "Email: $fields_vals[31] \n"; print MAIL "\n"; print MAIL "Destinations of interest: \n"; print MAIL "------------------------------------\n"; print MAIL "$fields_vals[6]\n"; print MAIL "$fields_vals[7]\n"; print MAIL "$fields_vals[8]\n"; print MAIL "$fields_vals[9]\n"; print MAIL "$fields_vals[10]\n"; # adding India Beyond print MAIL "$fields_vals[35]\n"; print MAIL "\n\n"; print MAIL "Preferred Type of Travel: \n"; print MAIL "------------------------------------\n"; print MAIL "$fields_vals[11]\n"; print MAIL "$fields_vals[12]\n"; print MAIL "$fields_vals[13]\n"; # removing checkboxes not needed #print MAIL "$fields_vals[14]\n"; #print MAIL "$fields_vals[15]\n"; print MAIL "\n\n"; # adding new How did you hear print MAIL "How did you hear about Cox & Kings?: \n"; print MAIL "------------------------------------\n"; print MAIL "$fields_vals[34] \n"; print MAIL "\n\n"; print MAIL "Comments: \n"; print MAIL "------------------------------------\n"; print MAIL "$fields_vals[16] \n"; print MAIL "\n"; print MAIL "\n"; print MAIL "Email Newsletter: $fields_vals[17] \n"; print MAIL "------------------------------------\n"; print MAIL "\n"; print MAIL "\n"; print MAIL "Brochure Information: \n"; print MAIL "------------------------------------\n"; print MAIL "Name: $fields_vals[18] $fields_vals[19]\n"; print MAIL "Street Address: $fields_vals[20]\n"; print MAIL "City: $fields_vals[21]\n"; print MAIL "State: $fields_vals[32]\n"; print MAIL "Zip: $fields_vals[22]\n"; # removing brochure #print MAIL "Brochure: $fields_vals[23]\n"; print MAIL "\n"; print MAIL "Companion Brochure Information: \n"; print MAIL "------------------------------------\n"; print MAIL "Name: $fields_vals[24] $fields_vals[25]\n"; print MAIL "Street Address: $fields_vals[26]\n"; print MAIL "City: $fields_vals[27]\n"; print MAIL "State: $fields_vals[33]\n"; print MAIL "Zip: $fields_vals[28]\n"; # removing companion brochure #print MAIL "Brochure: $fields_vals[29]\n"; close (MAIL); } #### end of mail #### # Print Warning #### sub print_warning { # removes underscores from parameter names foreach $item (@_) { $item =~ s|_| |gs; } $both_brochure = "Are you interested in a brochure? It appears you have entered information into some of the fields in either the 'Request a Brochure' or 'Send a Brochure to a Companion' sections. Please fill out the rest of the fields in these section. If you are not interested in receiving a brochure then please remove your entries from these sections.

"; if ($x eq "y") { print "$both_brochure\n"; } print font({-color=>'red'}, 'You must enter information into the following field(s): ', ); print font({-color=>'black'}, em(join(', ',@_)), ); } #### end of print warning