Hello class.
I need further modifications on the reservation script called by this page (it is not live on the site, so feel free to test:
http://www.laxautopark.com/reservations.shtml(note the years are now hidden fields, and I added two fields phone and comments which are not "live" yet.
First the easy part. I want the two time fields ("Time you will arrive to park your car:" and "Time you will be returning to pick up your car:*" to have the am and pm's built in, as on the following page (which IS live):
http://foxrentacar.com/rates_reservations.htmlAlso, for some reason if you make a reservation for a date EARLIER than today's date at:
http://www.laxautopark.com/reservations.shtml...you get the following message:
Can't locate object method "after" via package "current" at /home/sites/site24/web/cgi
-bin/reser
vation.cgi
line 151.
Now it *may* be I uploaded an earlier script but I doubt it. So please double check the script which I am posting at the end of this question.
Also if you put in your first name, last name and email address but do NOT enter a date and leave the rest of the form blank, you get the following message:
Day 'Day' out of range 1..31 at /home/sites/site24/web/cgi
-bin/reser
vation.cgi
line 134
I would rather a user friendly message appear.
Here is the script as is on the 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";
### Full path to the dates file
$date_file="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='rowby@rowby.com';
## Hard-coded of the Rental company
$cc='rowby@rowby.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 enter your first name. </B><P>\n";
++$error_flag;
}
if (!($LastName) && length($LastName)<=0){ ## Empty!!
print "<B>Please enter your last name.</B><P>\n";
++$error_flag;
}
if (!($DepartMonth) && length($DepartMonth)<=0){ ## Empty!!
print "<B>Please select the month you will be leaving your car.</B><P>\n";
++$error_flag;
}
if (!($DepartDay) && length($DepartDay)<=0){ ## Empty!!
print "<B>Please select the day you will be leaving your car.</B><P>\n";
++$error_flag;
}
if (!($yeardropoff) && length($yeardropoff)<=0){ ## Empty!!
print "<B>Please select a year for departure.</B><P>\n";
++$error_flag;
}
if (!($DepartHour) && length($DepartHour)<=0){ ## Empty!!
print "<B>Please select the hour you will be leaving your car.</B><P>\n";
++$error_flag;
}
if (!($ReturnMonth) && length($ReturnMonth)<=0){ ## Empty!!
print "<B>Please select the month you you be picking up your car.</B><P>\n";
++$error_flag;
}
if (!($ReturnDay) && length($ReturnDay)<=0){ ## Empty!!
print "<B>Please select the day you will be picking up your car.</B><P>\n";
++$error_flag;
}
if (!($yearreturn) && length($yearreturn)<=0){ ## Empty!!
print "<B>Please select a year for Return</B><P>\n";
++$error_flag;
}
if (!($ReturnHour) && length($ReturnHour)<=0){ ## Empty!!
print "<B>Please enter the hour you will be picking up your car.n</B><P>\n";
++$error_flag;
}
if (!($Email) && length($Email)<=0){ ## Empty!!
print "<B>Please enter an 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($Depar
tMonth)};
$Time1 = timelocal(0,0,$DepartHour,
$DepartDay
,$CMONTH,$
yeardropof
f);
$Depart_Time1 = timelocal(0,0,0,$DepartDay
,$CMONTH,$
yeardropof
f);
$yearreturn-=1900; ## Remove 1900 from the year.
$DMONTH=$mon2num{uc($Retur
nMonth)};
$Time2 = timelocal(0,0,$ReturnHour,
$ReturnDay
,$DMONTH,$
yearreturn
);
if ($Time1 >= $Time2){ ## Stop!! Departure date cannot be after Return date.
print "<B>Departure Date-time <U>MUST</U> be earlier than Return Date-Time</B><P>\n";
++$error_flag;
}
## Now get the current date time.
my ($sec,$min,$hour,$mday,$mo
n,$year,$w
day,$yday,
$isdst) =localtime(time);
$Time_now=timelocal(0,0,$h
our,$mday,
$mon,$year
);
if (($Time1 - (30 *60)) <= $Time_now){ ## Stop!! Departure date must be at least 30 mins difference
after current date-time.
print "<B>Departure Date-time <U>MUST</U> be at least 30 minutes after current date-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{
The Departure date that you selected ($DepartMonth/$DepartDay/}
,($yeardro
poff+1900)
,qq{) has been blocked.
<P>
Click <A HREF="javascript:history.g
o(-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,$FirstNa
me,$LastNa
me,$Depart
Month,$Dep
artDay,$De
partHour.'
:'.$Depart
Minute.'
'.$DepartDT,$ReturnMonth,$
ReturnDay,
$ReturnHou
r.':'.$Ret
urnMinute.
' '.$ReturnDT,$Email,$Zip)."
\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 Rowby (# $counter)!\n";
print MAIL qq{
Thank You for your Parking Reservation
Please print this page out for your reference.
We have emailed a confirmation email to the address you provided in your form.
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
Corporate code: $TACode
};
close(MAIL);
### rowby added below
## Start sending out the emails!!
open(MAIL, "| $mailprog -t ") || die $!;
print MAIL "To: rowby\@foxrentacar.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.
Please print this page out for your reference.
We have emailed a confirmation email to the address you provided in your form.
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
Corporate code: $TACode
};
close(MAIL);
### end of rowby
## Now that we have sent the email out, lets print the HTML page.
print qq{
<p align="center"><font face="Arial, Helvetica, sans-serif" size="3"><b>Thank
You for your Parking Reservation</b></font>
<p align="center"><font face="Arial, Helvetica, sans-serif" size="3">Please
print this page out for your reference.</font>
<p align="left"><font face="Arial, Helvetica, sans-serif" size="3">We
have emailed a confirmation email to the address you provided in
your form.</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="3">Name:
$FirstName $LastName</font>
<p align="left"><font face="Arial, Helvetica, sans-serif" size="3">Departure date: $DepartMonth $DepartDay,
}. ($yeardropoff+1900).qq{, $DepartHour:$DepartMinute $DepartDT</font>
<p align="left"><font face="Arial, Helvetica, sans-serif" size="3">Return date: $ReturnMonth $ReturnDay,
}. ($yearreturn+1900).qq{, $ReturnHour:$ReturnMinute $ReturnDT</font>
<p align="left"><font face="Arial, Helvetica, sans-serif" size="3">Email
address: $Email</font>
<p align="left"><font face="Arial, Helvetica, sans-serif" size="3">Zip
code: $Zip</font>
<p align="left"><font face="Arial, Helvetica, sans-serif" size="3">Corporate
code: $TACode</font>
<p align="left">
<p align="left">
<p align="left">
<p align="center"><br>
</p>
};