We help IT Professionals succeed at work.

Reservation script - further modifications

Rowby Goren
Rowby Goren asked
on
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.html

Also, 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/reservation.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/reservation.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($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>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,$mon,$year,$wday,$yday,$isdst) =localtime(time);
$Time_now=timelocal(0,0,$hour,$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/},($yeardropoff+1900),qq{) has been blocked.
     <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)."\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>
};


 

Comment
Watch Question

CERTIFIED EXPERT

Commented:
rowby,

"http://www.laxautopark.com/reservations.shtml"

Is there any particular reason you are using a shtml file, instead of a html file?

"..(note the years are now hidden fields, ..."

i visited the URL you posted & could see the year as hidden field.

Does this hidden field give you a problem?
Does the Perl script not receive the year at all?

"...and I added two fields phone and comments which are not "live" yet...."

Are these 2 fields mandatory? What, if any, are the validations for the mandatory fields?

".. 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):..."

Let me know if i have understood this correct.

You want to replace the current live list box, which has all the times (AM & PM) with a combination of a list box & radio buttons.

"..Also, for some reason if you make a reservation for a date EARLIER than today's date at:..."

Is this error shown with your orignial, unmodified HTML page & Perl script? What, if any, changes did you make to your HTML and/or Perl script?

"..I would rather a user friendly message appear...."

The error message in question should never be shown. This was the premise on which i have provided the solution.

This error is embedded inside Perl modules, that are called by the Perl scripts. Therefore, they cannot be modified.

Let me know.

Author

Commented:
Is there any particular reason you are using a shtml file, instead of a html file?

IF YOU PREFER THAT THAT PAGE NOT BE SHTML I WILL CHANGE IT.

"..(note the years are now hidden fields, ..."

i visited the URL you posted & could see the year as hidden field.

Does this hidden field give you a problem?

THE HIDDEN FIELD DOES NOT GIVE ME A PROBLEM.

Does the Perl script not receive the year at all?

YES IT RECEIVES THE YEAR AS YOU WILL SEE ON THE CONFIRMATION PAGE AND THE CONFIRMATIN EMAIL. So no problem there.

"...and I added two fields phone and comments which are not "live" yet...."

Are these 2 fields mandatory? What, if any, are the validations for the mandatory fields?

THEY ARE NOT MANDATORY

".. 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):..."

Let me know if i have understood this correct.

You want to replace the current live list box, which has all the times (AM & PM) with a combination
of a list box & radio buttons.

I WANT THE DROPDOWN TO LOOK LIKE THIS:
8 am
9 am
10 am
11 am
12 pm
1 pm
etc etc

NO RADIO BUTTIONS for AM & PM.  I will fix that on the HTML page when you tell me to.

"..Also, for some reason if you make a reservation for a date EARLIER than today's date at:..."

Is this error shown with your orignial, unmodified HTML page & Perl script? What, if any, changes did
you make to your HTML and/or Perl script?

I DON' THINK I MADE ANY CHANGES TO THE MODIFIED PERL. I AM 99 PERCENT SURE ITS THE EXACT SAME SCRIPT THAT WE FINALIZED.

"..I would rather a user friendly message appear...."

The error message in question should never be shown. This was the premise on which i have provided the
solution.

HMMM.... THEN I AM NOT SURE WHY THIS ERROR MESSAGE IS SHOWING.

This error is embedded inside Perl modules, that are called by the Perl scripts. Therefore, they cannot
be modified.

THEN IS IT POSSIBLE TO ADD SOME KIND OF VALIDATION THAT FOCES THE USER TO PUT IN AN ENTRY THAT WILL PREVENT THEM FROM GETTING THAT ERROR.  IF NOT I GUESS WE WILL HAVE TO LIVE WITH THAT PERL ERROR MESSAGE.
CERTIFIED EXPERT

Commented:
rowby,

"...IF YOU PREFER THAT THAT PAGE NOT BE SHTML I WILL CHANGE IT. "

If you are not using SSI's best to use html. this would save some parsing time on the server.

"..THE HIDDEN FIELD DOES NOT GIVE ME A PROBLEM..."

"...YES IT RECEIVES THE YEAR AS YOU WILL SEE ON THE CONFIRMATION PAGE AND THE CONFIRMATIN EMAIL. So no problem  there...."

Excellent!!

"..THEY ARE NOT MANDATORY..."

Excellent!! However, you want both these fields in the email that is sent to fox, right?

"..I WANT THE DROPDOWN TO LOOK LIKE THIS:..."

Correct me if i am wrong, but isnt this change in the HTML file than the Perl script?
Dont you just have to update the HTML file list box (<select> </select>) with the times?

Pl. let me know.

"..  IF NOT I GUESS WE WILL HAVE TO LIVE WITH THAT PERL ERROR MESSAGE. ..."

i dont think so. Since we want to, & i think we did, bury this message inside all the validations, we would never have to see it anyway. Can you pl. explain how i can reproduce this error at my end?

once i have been able to replicate the errror, i can then attempt to fix it.

Author

Commented:
I'll change the HTML to see if that will work with the AM & PM.

I'll change the page back to html instead of shtml.

Make a reservation using January 1 2001 as the pickup date and you will see one error.

Make a reservation with the first name and last name and email (no reservation dates selected) and you will see the second error.

Author

Commented:
P.S. I'll make the HTML page changes tomorrow (Tuesday) -- am putting out another fire now. :)

Rowby
CERTIFIED EXPERT

Commented:
rowby,

"..I'll change the HTML to see if that will work with the AM & PM.

I'll change the page back to html instead of shtml...."

Excellent!! 2 down 2 more to go.


"..Make a reservation using January 1 2001 as the pickup date and you will see one error.

Make a reservation with the first name and last name and email (no reservation dates selected) and you
will see the second error..."

What URL should i use?

http://www.laxautopark.com/reservations.shtml
OR
http://foxrentacar.com/rates_reservations.html
OR
it doesnt matter.

As soon as i know the URL to use, i will get that HTML file & the Perl script configured on my server. Next i will replicate that error on my server. That done, i will post the diagnosis & attempt a fix (if there is a problem).

".. I'll make the HTML page changes tomorrow (Tuesday) -- am putting out another fire now. :).."

No problem. As long as you are aware of the change & know what is to be done, i am fine with it

Author

Commented:
Use this page.  (If you still need user name and password for the server let me know.)

http://www.laxautopark.com/reservations.shtml
CERTIFIED EXPERT

Commented:
rowby,

"..Use this page.  .."

Ok Got the HTML file & the Perl script.

"..ou still need user name and password for the server let me know.)..."

Will let you know as soon as i need it.

Thanks
CERTIFIED EXPERT

Commented:
rowby,

"..Use this page.  .."

Just realized that this page has the radio buttons on it (AM/PM).

is this page on your list of pages to be updated (replace radio button with list box that has all times with AM/PM)?

if so, then i will wait till you have made those changes & then download the page.

Let me know.

Author

Commented:
I'll fix the html page first thing in the morning and report it here.
CERTIFIED EXPERT

Commented:
rowby,

"..'ll fix the html page first thing in the morning .."

... & i will take that file & start replicating the error.

Author

Commented:
Hi HEre's the new link.

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

Thanks

Rowby

Author

Commented:
Note the page is not live so you can test as much as you wish.
CERTIFIED EXPERT

Commented:
rowby,

"..Hi HEre's the new link...."

Got it. will work on it today & keep you posted on the progress

"..                     Note the page is not live so you can test as much as you wish. ..."

Since i have the HTML file & the Perl script with me, i will test it on my server first before handing it over to you for 2nd round of testing.

CERTIFIED EXPERT

Commented:
rowby,

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

i downloaded & installed this HTML file on my server. i then took your Perl code posted above & changed the email id to my id.

Next i added the phone & comment fields to both the emails that are sent out. The testing for this went fine.

"..Can't locate object method "after" via package "current" at /home/sites/site24/web/cgi-bin/reservation.cgi
line 151. ..."

This error is *not* due to the code, but due to the way in which you copied & pasted the code. The last time too we had this problem, such that when you copied and pasted the code from EE to your local machine, lines (which were supposed to a single line) were broken as 2. This is exactly what has happened on line 151. So you need to "join" lines 150 & 151.

i am looking at the 2nd error & i think i have found out another related error as well.

i will keep you posted on the "fix" if any.

CERTIFIED EXPERT

Commented:
rowby,

The source of the new error that i pointed is due to the change you have made to the HTML file.

If you look up the original HTML code, you will notice that the value for Month is empty.

in the URL you have posted above it has a value assinged to it.

You therefore need to REPLACE...

<option value="Month">Month</option>

WITH...

<option value="">Month</option>
CERTIFIED EXPERT

Commented:
rowby,

Another problem due to change in HTML code.

All the values for 12 AM must be 0 not 24

REPLACE..

<option value="24"><font color="#FF0000">12 AM</font></option>


WITH...

<option value="0"><font color="#FF0000">12 AM</font></option>

CERTIFIED EXPERT

Commented:
rowby,

"..Day 'Day' out of range 1..31 at /home/sites/site24/web/cgi-bin/reservation.cgi line 134 ..."

...& here's another example of how change to the HTML code can cause an error to appear.


REPLACE...

<option selected value="Day">Day</option>

WITH...

<option selected value=" ">Day</option>

NOTE: Please do not change any content in the HTML file, without being sure that the Perl script will bomb out all together. When i hand over the script to you, i test for as many situations as possible to ensure you get a working script.

Author

Commented:
Hi,

THanks for the testing.  I'll wait until you are finished and then make all the fixes to the html.

Rowby
CERTIFIED EXPERT

Commented:
rowby,

".. I'll wait until you are finished and then make all the fixes to the html...."

I have completed my testing & would like you to start making changes to the HTML file.
once you have done that & tested the code, pl let me know. Next, i will post the updated Perl code to take care of the phone # & comment fields.

once again you test & sign off.

Hope that helps.

Author

Commented:
Okay I'll will go to the client's office and make the changes to the HTML code there. ANd report back here.

Rowby

Author

Commented:
The changes have been made and the form seems to be working fine.  Unless you have further modifications we will make this page live today.

You can continue testing it, just put the word TEST in the name field(s).

Thanks

Rowby
CERTIFIED EXPERT
Commented:
rowby,

"..The changes have been made and the form seems to be working fine...."

Excellent!! Since you have tested the same, i will not do any further testing.

".. Unless you have further modifications  we will make this page live today..."

Yes. i have posted the Perl script that needs to go with the HTML file.

NOTE: i have emailed this same file to your personal account @rowby.com
===========reservation.cgi
#!/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($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>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,$mon,$year,$wday,$yday,$isdst) =localtime(time);
$Time_now=timelocal(0,0,$hour,$mday,$mon,$year);

##     Stop!! Departure date must be at least 30 mins difference after current date-time.
if (($Time1 - (30 *60)) <= $Time_now){
    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/},($yeardropoff+1900),qq{) has been
blocked.
    <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)."\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

Phone Number: $bestphone

Corporate code: $TACode

Comments: $textfield
};

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

Phone Number: $bestphone

Corporate code: $TACode

Comments: $textfield
};

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>
};

Author

Commented:
THank you as usual.  THe script is up and working perfectly.  It will be live on the site tomorrow morning.
CERTIFIED EXPERT

Commented:
rowby,

"..THank you as usual.  THe script is up and working perfectly.  It will be live on the site tomorrow morning. .."

You're welcome. Glad to know that you have the working solution with you.

if you dont mind, can you pl. post the URL once it has gone live? i will then do a quick test using the "TEST" name.

Thanks.

Author

Commented:
THank you as usual.  THe script is up and working perfectly.  It will be live on the site tomorrow morning.
ozo
CERTIFIED EXPERT
Most Valuable Expert 2014
Top Expert 2015

Commented:
                 ##     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);
This truncates the file before it is locked,
leaving a window where the read can find an empty file

Explore More ContentExplore courses, solutions, and other research materials related to this topic.