Solved

Adding locaton to form

Posted on 2002-07-29
4
204 Views
Last Modified: 2010-03-05
Please see this previously question, answered by maneshr:

http://www.experts-exchange.com/perl/Q_20252319.html

We would like to add the following drop down menu to the form which is currently on this page:

http://www.laxautopark.com/content/reservations.html

Select location:
LAX
Phoenix

If the person selects LAX the reservation is made at the LAX parking lot location.  The email would be sent to service@laxautoparks.com  A confirmation email is sent to the customer.  The appropriate thank you page would be displayed, and the appropriate database is modified.   (Phoenix and LAX has a different Thank You Page and a different confirmation email.)

If the person selects Phoenix the reservation is made at the Phoenix  parking lot location.  The email would be sent to service@oxautoparks.com  The appropriate thank you page would be displayed, the appropriate database is modified.    (Phoenix and LAX has a different Thank You Page and a different confirmation email.)

Feel free to test the live form as much as you like.    Just use the word "TEST" as your first or last name.

Here is the current perl script working online for the LAX site:

#!/usr/bin/perl

$|++;

print "Content-type: text/html\n\n";

use CGI;
use Time::Local;

##     Full path to the sendmail file.
#$mailprog ="/usr/sbin/sendmail";
$mailprog ="/usr/sbin/sendmail";

###  Full path to the dates file
$date_file="/tmp/date.txt";

if (-e $date_file){
    ##     Read the entire list of blocked dates.
    open(DF,$date_file) || die $!;
    flock(DF, 1) || die $!;     ##     Open the file in a shared, read-only mode.
    while(<DF>){
         chomp;
         $line{$_}++;
    }
    close(DF);
}

##     Required for date validations
%mon2num=('JAN' => 0,
'FEB' => 1,
'MAR' => 2,
'APR' => 3,
'MAY' => 4,
'JUN' => 5,
'JUL' => 6,
'AUG' => 7,
'SEP' => 8,
'OCT' => 9,
'NOV' => 10,
'DEC' => 11
);

##     Full path to the comma-delimited output file.
$out_file='/tmp/comma_out';

##     Full path to the counter file.
$ctr_file='/tmp/ctr';

##     Hard-coded from email id
$from='service@laxautopark.com';
#$from='manrao@cisco.com';

##     Hard-coded of the Rental company
$cc='service@laxautopark.com';
#$cc='manrao@cisco.com';

##     Create a new CGI object
$query=new CGI;

##     Read the incoming HTML form elements.
foreach ($query->param){
    $$_=$query->param($_);

    ##     Remove leading & trailing whites spaces
    $$_=~ s/^\s+//;
    $$_=~ s/\s+$//;
    ##     Squeeze multiple white spaces into a single space.
    $$_=~ s/\s+/ /g;
}

##     Set default value for Corporate Code
$TACode='None' if (!($TACode));

##     Placeholder for doing all data validations here
my($error_flag)=0;

if (!($FirstName) && length($FirstName)<=0){     ##     Empty!!
    print "<B>Please use your back button to go back and enter your first name. </B><P>\n";
    ++$error_flag;
}

if (!($LastName) && length($LastName)<=0){     ##     Empty!!
    print "<B>Please use your back button to go back and enter your last name.</B><P>\n";
    ++$error_flag;
}

if (!($DepartMonth) && length($DepartMonth)<=0){     ##     Empty!!
    print "<B>Please use your back button to go back and select the month you will be leaving your car.</B><P>\n";
    ++$error_flag;
}

if (!($DepartDay) && length($DepartDay)<=0){     ##     Empty!!
    print "<B>Please use your back button to go back and select the day you will be leaving your car.</B><P>\n";
    ++$error_flag;
}

if (!($yeardropoff) && length($yeardropoff)<=0){     ##     Empty!!
    print "<B>Please use your back button to go back and select a year for departure.</B><P>\n";
    ++$error_flag;
}

if (!($DepartHour) && length($DepartHour)<=0){     ##     Empty!!
    print "<B>Please use your back button to go back and select the hour you will be leaving your car.</B><P>\n";
    ++$error_flag;
}

if (!($ReturnMonth) && length($ReturnMonth)<=0){     ##     Empty!!
    print "<B>Please use your back button to go back and select the month you you be picking up your car.</B><P>\n";
    ++$error_flag;
}

if (!($ReturnDay) && length($ReturnDay)<=0){     ##     Empty!!
    print "<B>Please use your back button to go back and select the day you will be picking up your car.</B><P>\n";
    ++$error_flag;
}

if (!($yearreturn) && length($yearreturn)<=0){     ##     Empty!!
    print "<B>Please use your back button to go back and select a year for Return</B><P>\n";
    ++$error_flag;
}

if (!($ReturnHour) && length($ReturnHour)<=0){     ##     Empty!!
    print "<B>Please use your back button to go back and enter the hour you will be picking up your car.</B><P>\n";
    ++$error_flag;
}

if (!($Email) && length($Email)<=0){     ##     Empty!!
    print "<B>Please use your back button to go back and enter your Email address.</B><P>\n";
    ++$error_flag;
}

exit if $error_flag;  ##  Stop!! We have errors.

##     Do advanced date validations here.
$yeardropoff-=1900;     ##     Remove 1900 from the year.
$CMONTH=$mon2num{uc($DepartMonth)};
$Time1 = timelocal(0,0,$DepartHour,$DepartDay,$CMONTH,$yeardropoff);
$Depart_Time1 = timelocal(0,0,0,$DepartDay,$CMONTH,$yeardropoff);

$yearreturn-=1900;     ##     Remove 1900 from the year.
$DMONTH=$mon2num{uc($ReturnMonth)};
$Time2 = timelocal(0,0,$ReturnHour,$ReturnDay,$DMONTH,$yearreturn);

if ($Time1 >= $Time2){ ##     Stop!! Departure date cannot be after Return date.
    print "<B>You entered a date to pick up your car that is before the date you are dropping off your car. Please use your back button to correct the date(s).</B><P>\n";
    ++$error_flag;
}

##     Now get the current date time.
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =localtime(time);
$Time_now=timelocal(0,0,$hour,$mday,$mon,$year);

if (($Time1 - (10 *60)) <= $Time_now){ ##     Stop!! Departure date must be at least 30 mins difference after current date-time.
    print "<B>You entered a date or time that has already past.  Please use your back button to choose another date and or time.</B><P>\n";
    ++$error_flag;
}

exit if $error_flag;     ##     Stop!! We have errors.

print "<!--Departure time = $Depart_Time1-->\n";

##     Now check if the Start date has been blocked.
if ($line{$Depart_Time1}){     ##     Blocked!!

    print qq{
    We are sorry but the departure date that you selected ($DepartMonth/$DepartDay/},($yeardropoff+1900),qq{) is completely booked.
    <P>
    Click <A HREF="javascript:history.go(-1)"><B>here</B></A> to select a different Departure date!!
    };
    exit ;     ##     Stop!! We have a blocked date!!
}

##     End of placeholder for doing all data validations here


##     Now that data validation is completed, successfully, we will increment the counter.
##     Check if the counter file exists.
if (open(CTR,$ctr_file)){     ##     Exists. Use it!!
##     Open the file with a shared lock, to prevent simultaneous access.
flock(CTR,1) || die $!;
$counter=<CTR>;     ##     Read the counter.
chomp($counter);     ##     Remove the newline character.
}else{     ##     Does not exist. Create one!!
$counter=1000;     ##     Lets start from this number.
}

close(CTR);

##     Increment the counter.
$counter++;

##     Now write this new value back to the file.
open(CTR,"> $ctr_file")|| die $!;
##     But remember to lock this file for exculsive use, to prevent simultaneous access.
flock(CTR,2) || die $!;
print CTR     $counter."\n";
close(CTR);

##     Now write this new record to the comma-delimited file.
open(DELIM,">> $out_file")|| die $!;
##     But remember to lock this file for exculsive use, to prevent simultaneous access.
flock(DELIM,2) || die $!;

print DELIM join(',',$counter,$FirstName,$LastName,$DepartMonth,$DepartDay,$DepartHour.':'.$DepartMinute.' '.$DepartDT,$ReturnMonth,$ReturnDay,$ReturnHour.':'.$ReturnMinute.' '.$ReturnDT,$Email,$Zip,$bestphone,$vehiclemake,$vehiclecolor,$comments)."\n";

close(DELIM);

##     Start sending out the emails!!
open(MAIL, "| $mailprog -t ") || die $!;
print MAIL "To: $Email\n";
print MAIL "From: $from\n";
print MAIL "Subject: Confirmation e-mail from LAX Auto Park (# $counter)\n";
print MAIL qq{

Thank You for your Reservation at Fox LAX Parking

Please print this email for your reference.   (Note:  0.00 is 12 AM)

CONFIRMATION NUMBER: $counter

Name: $FirstName $LastName

Departure date: $DepartMonth $DepartDay,}.($yeardropoff+1900).qq{, $DepartHour:$DepartMinute $DepartDT

Return date: $ReturnMonth $ReturnDay,}. ($yeardropoff+1900).qq{, $ReturnHour:$ReturnMinute $ReturnDT

Email address: $Email

Zip code: $Zip

Phone Number: $bestphone

Corporate code (if any): $TACode

Comments: $comments

Fox LAX Parking
http://www.laxautopark.com
10611 South La Cienega Boulevard, Los Angeles 90045
310-645-9300


};

close(MAIL);

### rowby added below

##     Start sending out the emails!!
open(MAIL, "| $mailprog -t ") || die $!;
print MAIL "To: service\@laxautopark.com\n";
print MAIL "From: $from\n";
print MAIL "Subject: To LAX Reservation Dept (# $counter)\n";
print MAIL qq{

A reservation has been made on the LAXAUTOPARK Website.

CONFIRMATION NUMBER: $counter

Name: $FirstName $LastName

Departure date: $DepartMonth $DepartDay,}.($yeardropoff+1900).qq{, $DepartHour:$DepartMinute $DepartDT

Return date: $ReturnMonth $ReturnDay,}. ($yeardropoff+1900).qq{, $ReturnHour:$ReturnMinute $ReturnDT

Email address: $Email

Zip code: $Zip

Phone Number: $bestphone

Corporate code (if any): $TACode

Vehicle make (if included): $vehiclemake

Vehicle color: (if included): $vehiclecolor

Comments: $comments
};

close(MAIL);
###  end of rowby

##     Now that we have sent the email out, lets print the HTML page.
print qq{
<center><img src="http://www.laxautopark.com/images/an-min-logo-new1.gif" width="121" height="62"></center>
<p align="center"><font face="Arial, Helvetica, sans-serif" size="3"><b>Thank
You for your Reservation at FOX LAX Parking</b></font>
<p align="left"><font face="Arial, Helvetica, sans-serif" size="3">We
have emailed a confirmation to the email address you provided.  (Note: 0:00 is 12AM.)</font>
<p align="left">

<p align="left">
<p align="left">
<p align="left">
<p align="left">
<p align="left">
<p align="left">
<p align="left">
<p align="left"><b><font face="Arial, Helvetica, sans-serif">CONFIRMATION
NUMBER: $counter</font></b>
<p align="left">
<p align="left">
<p align="left">
<p align="left">
<p align="left">
<p align="left">
<p align="left">
<p align="left"><font face="Arial, Helvetica, sans-serif" size="2">Name:
$FirstName $LastName</font>
<p align="left"><font face="Arial, Helvetica, sans-serif" size="2">Departure  date: $DepartMonth $DepartDay,

}. ($yeardropoff+1900).qq{, $DepartHour:$DepartMinute $DepartDT</font>
<p align="left"><font face="Arial, Helvetica, sans-serif" size="2">Return date: $ReturnMonth $ReturnDay,

}. ($yearreturn+1900).qq{, $ReturnHour:$ReturnMinute $ReturnDT</font>
<p align="left"><font face="Arial, Helvetica, sans-serif" size="2">Email
address: $Email</font>
<p align="left"><font face="Arial, Helvetica, sans-serif" size="2">Zip
code: $Zip</font>
<p align="left"><font face="Arial, Helvetica, sans-serif" size="2">Corporate
code (if any): $TACode</font>
<p align="left"><font face="Arial, Helvetica, sans-serif" size="2">Phone Number: $bestphone</font>
<p align="left"><font face="Arial, Helvetica, sans-serif" size="2">Comments: $comments
<p align="left">
<p align="left">
 Click <a href="http://www.laxautopark.com/content/map.shtml">HERE</a>
        for Map &amp; Directions</p>
Click <a href="http://www.laxautopark.com">HERE</a>
        to return to our home page.</p>
<p align="left">
<B><FONT SIZE="3">We look forward to providing you with excellent service. <p>
FOX LAX Parking<br>
10611 South Boulevard (3 blocks south of Century Boulevard) <bR>Los Angeles 90045<bR>
If you have any questions please phone us at 310-645-9300.  We are happy to answer any questions.
<p align="center"><br>
</p>
};
0
Comment
Question by:Rowby Goren
  • 3
4 Comments
 
LVL 9

Author Comment

by:Rowby Goren
ID: 7191066
Hmmm.  No respnses so far.  I've increased the points to 350.  Will that help?

Thanks

Rowby
0
 

Accepted Solution

by:
celere earned 350 total points
ID: 7191387
Without reading and writing all of your code :) I'd try:

In your form:
<SELECT NAME="location">
<OPTION VALUE = "LAX">LAX
<OPTION VALUE ="Phoenix">Phoenix</option>

and in your script:

##Start sending out the emails!!
...
A reservation has been made on the $location AUTOPARK Website.
....

##Now that we have sent the email out, lets print the HTML page
...
b>Thank
You for your Reservation at $location LAX Parking</b>
....

You can also create other variables, such as lengthier messages, based on the $location:

if ($location eq "LAX"){
$loc_address = "10611 South Boulevard (3 blocks south of Century Boulevard) <bR>Los Angeles 90045<bR>";
}

Hope this helps.
0
 
LVL 9

Author Comment

by:Rowby Goren
ID: 7713626
THanks you!
0
 
LVL 9

Author Comment

by:Rowby Goren
ID: 8230837
THanks. Sorry for the extreme delay in awarding the points!
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now