We help IT Professionals succeed at work.

Integrating perl scripts

Rowby Goren
Rowby Goren asked
on
HI,

I attempted to award the points on the last question, but upon submission the experts exchange server resulted in a server error.

I'll attempt to do the award later today.

In the meantime, we need to integrate the reservation with the calendar script.

No hurry at all.  If it takes a week that's okay.

I'm offering 200 points for this. If that's not enough let me know.

Rowby
Comment
Watch Question

CERTIFIED EXPERT

Commented:
rowby,

"..we need to integrate the reservation with the calendar script...."

Please post the latest version of your Admin script-calendar file & reservation script - reservation HTML form.

Also, pl. explain what exactly you would like by way of integration. This will help all other users understand your requirements & attempt an answer.

Author

Commented:
This question is to integrate 2 perl scripts along with an HTML script for a parking lot web site.  The public visits a web page where they reserve a start and end date for their parking reservation.  If the parking lot is already filled up for the start date (only the start date) then when they push the submit button they will get a message suggesting they select another start date because that date is filled up.

On the admin side, the parking lot employee is able to block out certain dates, via a javascript calendar.  Using the same javascript calendar they are able to UNblock a date.

In previous recent questions, in this Experts-Exchange Perl Section,  drafts of the perl, javascript and HTML portions have been worked on.  Now we are going to put them all together!

Here is the URL where the public visits:

http://www.laxautopark.com/content/booking.htm  (not live yet)

Here is the URL where the parking lot employee visits (Later will be in a password protected page.

http://www.laxautopark.com/content/calendar.shtml

Below are the latest versions of the two perl scripts:

================== 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";

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

print "\$$_ = >",$$_,"<<BR>\n";
}

##     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>First name cannot be empty</B><P>\n";
++$error_flag;
}

if (!($LastName) && length($LastName)<=0){  ##  Empty!!
print "<B>Last name cannot be empty</B><P>\n";
++$error_flag;
}

if (!($DepartMonth) && length($DepartMonth)<=0){  ##  Empty!!
print "<B>Please select a month for departure</B><P>\n";
++$error_flag;
}

if (!($DepartDay) && length($DepartDay)<=0){  ##  Empty!!
print "<B>Please select a day for departure</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 enter hour of departure</B><P>\n";
++$error_flag;
}

if (!($ReturnMonth) && length($ReturnMonth)<=0){  ##  Empty!!
print "<B>Please select a month for Return</B><P>\n";
++$error_flag;
}

if (!($ReturnDay) && length($ReturnDay)<=0){  ##  Empty!!
print "<B>Please select a day for Return</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 (!($Email) && length($Email)<=0){  ##  Empty!!
 print "<B>Please enter an Email id.</B><P>\n";
 ++$error_flag;
}

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

if (!($Email) && length($Email)<=0){  ##  Empty!!
print "<B>Please enter an Email id.</B><P>\n";
++$error_flag;
}

##  Do advanced date validations here.
$yeardropoff-=1900; ##  Remove 1900 from the year.
$CMONTH=$mon2num{uc($DepartMonth)};
$Time1 = timelocal(0,0,$DepartHour,$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.

##     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, $DepartHour:$DepartMinute $DepartDT

Return date: $ReturnMonth $ReturnDay, $yeardropoff, $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, $DepartHour:$DepartMinute $DepartDT

Return date: $ReturnMonth $ReturnDay, $yeardropoff, $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, $DepartHour:$DepartMinute $DepartDT</font>
<p align="left"><font face="Arial, Helvetica, sans-serif" size="3">Return
date: $ReturnMonth $ReturnDay, $yeardropoff, $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>
};

================== calendar.cgi ======================

#!/usr/bin/perl

$|++;

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

use CGI;
use Time::Local;

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

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

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

if (!($dateField) && length($dateField)<=0){     ##     Empty!!
    print "<B>Date cannot be empty</B><P>\n";
    ++$error_flag;
}

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

($CMONTH,$DepartDay,$yeardropoff)=split(/\//,$dateField);
$CMONTH--;  ##  The month rages from 0 to 11, where 0 is January & 11 is December.

##     Do advanced date validations here.
$yeardropoff-=1900;     ##     Remove 1900 from the year.
$Time = timelocal(0,0,$DepartHour,$DepartDay,$CMONTH,$yeardropoff);
##  End of placeholder for doing all data validations here

if (-e $date_file){
    open(DF,$date_file) || die $!;
    while(<DF>){
         chomp;
         $line{$_}++;
    }
    close(DF);
}

print "<!--\$dateField = >",$dateField,"<\n";
print "\$Time = >",$Time,"<-->\n";

if ($action=~ /^Block$/){
    ##     Append the data to the blocked dates file.
    $mess="$dateField has been blocked!!<BR>\n";
    $line{$Time}++;
}else{
    ##     Remove the data from the blocked dates file.
    $mess="$dateField has been unblocked!!<BR>\n";
    delete $line{$Time};
}

open(DF,">$date_file") || die $!;
foreach (sort keys %line){
    print DF $_."\n";
}
close (DF);

print "<B>$mess</B><P>\n";

print "Click <A HREF=http://www.laxautopark.com/content/calendar.shtml>HERE</A> for another date<P>\n";


=====================  booking.shtml ====================

<HTML>

<HEAD>

<TITLE>A-Z Javascript Calendar</TITLE>

<META NAME="keywords" CONTENT="javascript,calendar">

</HEAD>

<BODY>
<script language="JavaScript">


<!--
//Form button calendar (author Manesh Rao)

function setDate(str) {


if (str == "   ") {

 return;

}



mnth1 = document.forms[0].month.value;

mnth = mnth1;

mnth++;

year = document.forms[0].year.value;

dateStr = mnth+"/"+str+"/"+year;



dateStr = trim(dateStr);



document.forms[1].dateField.value = dateStr;





}//setDate()



/**

* The function removes spaces from the selected date.

*/



function trim(str) {



res="";



for(var i=0; i< str.length; i++) {

  if (str.charAt(i) != " ") {

    res +=str.charAt(i);

 }

}

 

return res;



}//trim()



/**

* The method to get the Month name given the Month number of the year.

*/



function getMonthName(mnth) {



if (mnth == 0) {

 name = "January";

}else if(mnth==1) {

 name = "February";

}else if(mnth==2) {

 name = "March";

}else if(mnth==3) {

 name = "April";

}else if(mnth==4) {

 name = "May";

} else if(mnth==5) {

 name = "June";

} else if(mnth==6) {

 name = "July";

} else if(mnth==7) {

 name = "August";

} else if(mnth==8) {

 name = "September";

} else if(mnth==9) {

 name = "October";

} else if(mnth==10) {

 name = "November";

} else if(mnth==11) {

 name = "December";

}



return name;



}//getMonthName()



/**

* Get the number of days in the month based on the year.

*/



function getNoOfDaysInMnth(mnth,yr) {



rem = yr % 4;



if(rem ==0) {

  leap = 1;

} else {

 leap = 0;

}



noDays=0;



if ( (mnth == 1) || (mnth == 3) || (mnth == 5) ||

     (mnth == 7) || (mnth == 8) || (mnth == 10) ||

     (mnth == 12)) {

 noDays=31;

} else if (mnth == 2) {

          noDays=28+leap;

       } else {

          noDays=30;

}



//alert(noDays);

return noDays;



     

}//getNoOfDaysInMnth()

 

/**

* The function to reset the date values in the buttons of the

* slots.

*/



function fillDates(dayOfWeek1,noOfDaysInmnth) {



for(var i=1; i<43; i++) {

  str = "s"+i;

  document.forms[0].elements[str].value="   ";

}





startSlotIndx = dayOfWeek1;

slotIndx = startSlotIndx;



for(var i=1; i<(noOfDaysInmnth+1); i++) {

 slotName = "s"+slotIndx;



 val="";

 if (i<10) {

   val = " "+i+" ";

 } else {

   val = i;

 }



 document.forms[0].elements[slotName].value = val;

 slotIndx++;

}

 

}//fillDates()





/**

* The function that is called at the time of loading the page.

* This function displays Today's date and also displays the

* the calendar of the current month.

*/



function thisMonth() {



 dt = new Date();

 mnth  = dt.getMonth(); /* 0-11*/

 dayOfMnth = dt.getDate(); /* 1-31*/

 dayOfWeek = dt.getDay(); /*0-6*/

 yr = dt.getFullYear(); /*4-digit year*/



 
//alert("month:"+(mnth+1)+":dayofMnth:"+dayOfMnth+":dayofweek:"+dayOfWeek+":year:"+yr);



 mnthName = getMonthName(mnth)+ " ";

 document.forms[0].month.value = mnth;

 document.forms[0].year.value = yr;

 document.forms[0].currMonth.value = mnth;

 document.forms[0].currYear.value = yr;

 

 document.forms[0].monthYear.value = mnthName+yr;

 document.forms[1].dateField.value = (mnth+1)+"/"+dayOfMnth+"/"+yr;



 startStr = (mnth+1)+"/1/"+yr;

 dt1 = new Date(startStr);

 dayOfWeek1 = dt1.getDay(); /*0-6*/



 noOfDaysInMnth = getNoOfDaysInMnth(mnth+1,yr);

 fillDates(dayOfWeek1+1,noOfDaysInMnth);





}//thisMonth()



/**

* The function that will be used to display the calendar of the next month.

*/



function nextMonth() {



var currMnth = document.forms[0].month.value;

currYr = document.forms[0].year.value;



if (currMnth == "11") {

   nextMnth = 0;

   nextYr = currYr;

   nextYr++;

} else {

  nextMnth=currMnth;

  nextMnth++;

  nextYr = currYr;

}



mnthName = getMonthName(nextMnth);

document.forms[0].month.value=nextMnth;

document.forms[0].year.value=nextYr;

document.forms[0].monthYear.value= mnthName+" "+nextYr;



str = (nextMnth+1)+"/1/"+nextYr;

dt = new Date(str);

dayOfWeek = dt.getDay();



noOfDays = getNoOfDaysInMnth(nextMnth+1,nextYr);



fillDates(dayOfWeek+1,noOfDays);





}//nextMonth()



/**

* The method to display the calendar of the previous month.

*/



function prevMonth() {



var currMnth = document.forms[0].month.value;

currYr = document.forms[0].year.value;



if (currMnth == "0") {

   prevMnth = 11;

   prevYr = currYr;

   prevYr--;

} else {

  prevMnth=currMnth;

  prevMnth--;

  prevYr = currYr;

}



str = (prevMnth+1)+"/1/"+prevYr;

dt = new Date(str);

dayOfWeek = dt.getDay();



/***********************************************

 * Remove the comment if do not want the user to

 * go to any previous month than this current month.

 ***********************************************/



/*



runningMonth = document.forms[0].currMonth.value;

rMonth=runningMonth;

rMonth++;

runningYear = document.forms[0].currYear.value;

rYear=runningYear;



str = (rMonth)+"/1/"+rYear;

dt1 = new Date(str);



if (dt.valueOf() < dt1.valueOf()) {

  alert('Cannot Go Before Current Month');

  return;

}



*/



/**************************************************

* End of comment

**************************************************/



mnthName = getMonthName(prevMnth);

document.forms[0].month.value=prevMnth;

document.forms[0].year.value=prevYr;

document.forms[0].monthYear.value= mnthName+" "+prevYr;



noOfDays = getNoOfDaysInMnth(prevMnth+1,prevYr);

fillDates(dayOfWeek+1,noOfDays);



}//prevMonth()


//-->

</script>

</head>





<body onload="thisMonth()">

<form>
<table border=1 bgcolor="#BAA0A0" align=center>

<tr>

<td>


   <!-- Hidden fields --->

   <input type=hidden name=month value="">

   <input type=hidden name=year value="">

   <input type=hidden name=currMonth value="">

   <input type=hidden name=currYear value="">

   <!-- End of Hidden fields --->

   <p>

    <input type="button" name="prev" onclick="prevMonth()"

    value="<<">
    <input type="text" size="15" name="monthYear" value="" onFocus="this.blur();">

    <input type="button" name="next" onclick="nextMonth()" value=">>">

  </p>

   

   <table bgcolor="#D4D4D4" align=center border="1" cellpadding="0" cellspacing="0"

   width="150">

       <tr bgcolor="#ffffff">

           <td width="14%"><font size="1"><strong>SUN</strong></font></td>

           <td width="14%"><font size="1"><strong>MON</strong></font></td>

           <td width="14%"><font size="1"><strong>TUE</strong></font></td>

           <td width="14%"><font size="1"><strong>WED</strong></font></td>

           <td width="14%"><font size="1"><strong>THU</strong></font></td>

           <td width="15%"><font size="1"><strong>FRI</strong></font></td>

           <td width="15%"><font size="1"><strong>SAT</strong></font></td>

       </tr>

       <tr>

           <td align="center" width="14%"><input type="button"

           onclick="setDate(this.value);"

           name="s1" value=" 1 "></td>

           <td align="center" width="14%"><input type="button"

           onclick="setDate(this.value);"

           name="s2" value=" 2 "></td>

           <td align="center" width="14%"><input type="button"

           onclick="setDate(this.value);"

           name="s3" value=" 3 "></td>

           <td align="center" width="14%"><input type="button"

           onclick="setDate(this.value);"

           name="s4" value=" 4 "></td>

           <td align="center" width="14%"><input type="button"

           onclick="setDate(this.value);"

           name="s5" value=" 5 "></td>

           <td align="center" width="15%"><input type="button"

           onclick="setDate(this.value);"

           name="s6" value=" 6 "></td>

           <td align="center" width="15%"><input type="button"

           onclick="setDate(this.value);"

           name="s7" value=" 7 "></td>

       </tr>

       <tr>

           <td align="center" width="14%"><input type="button"

           onclick="setDate(this.value);"

           name="s8" value=" 8 "></td>

           <td align="center" width="14%"><input type="button"

           onclick="setDate(this.value);"

           name="s9" value=" 9 "></td>

           <td align="center" width="14%"><input type="button"

           onclick="setDate(this.value);"

           name="s10" value="10"></td>

           <td align="center" width="14%"><input type="button"

           onclick="setDate(this.value);"

           name="s11" value="11"></td>

           <td align="center" width="14%"><input type="button"

           onclick="setDate(this.value);"

           name="s12" value="12"></td>

           <td align="center" width="15%"><input type="button"

           onclick="setDate(this.value);"

           name="s13" value="13"></td>

           <td align="center" width="15%"><input type="button"

           onclick="setDate(this.value);"

           name="s14" value="14"></td>

       </tr>

       <tr>

           <td align="center" width="14%"><input type="button"

           onclick="setDate(this.value);"

           name="s15" value="15"></td>

           <td align="center" width="14%"><input type="button"

           onclick="setDate(this.value);"

           name="s16" value="16"></td>

           <td align="center" width="14%"><input type="button"

           onclick="setDate(this.value);"

           name="s17" value="17"></td>

           <td align="center" width="14%"><input type="button"

           onclick="setDate(this.value);"

           name="s18" value="18"></td>

           <td align="center" width="14%"><input type="button"

           onclick="setDate(this.value);"

           name="s19" value="19"></td>

           <td align="center" width="15%"><input type="button"

           onclick="setDate(this.value);"

           name="s20" value="20"></td>

           <td align="center" width="15%"><input type="button"

           onclick="setDate(this.value);"

           name="s21" value="21"></td>

       </tr>

       <tr>

           <td align="center" width="14%"><input type="button"

           onclick="setDate(this.value);"

           name="s22" value="22"></td>

           <td align="center" width="14%"><input type="button"

           onclick="setDate(this.value);"

           name="s23" value="23"></td>

           <td align="center" width="14%"><input type="button"

           onclick="setDate(this.value);"

           name="s24" value="24"></td>

           <td align="center" width="14%"><input type="button"

           onclick="setDate(this.value);"

           name="s25" value="25"></td>

           <td align="center" width="14%"><input type="button"

           onclick="setDate(this.value);"

           name="s26" value="26"></td>

           <td align="center" width="15%"><input type="button"

           onclick="setDate(this.value);"

           name="s27" value="27"></td>

           <td align="center" width="15%"><input type="button"

           onclick="setDate(this.value);"

           name="s28" value="28"></td>

       </tr>

       <tr>

           <td align="center"><input type="button" name="s29"

           onclick="setDate(this.value);"

           value="29"></td>

           <td align="center"><input type="button" name="s30"

           onclick="setDate(this.value);"

           value="30"></td>

           <td align="center"><input type="button" name="s31"

           onclick="setDate(this.value);"

           value="   "></td>

           <td align="center"><input type="button" name="s32"

           onclick="setDate(this.value);"

           value="   "></td>

           <td align="center"><input type="button" name="s33"

           onclick="setDate(this.value);"

           value="   "></td>

           <td align="center"><input type="button" name="s34"

           onclick="setDate(this.value);"

           value="   "></td>

           <td align="center"><input type="button" name="s35"

           onclick="setDate(this.value);"

           value="   "></td>

       </tr>

       <tr>

           <td align="center"><input type="button" name="s36"

           onclick="setDate(this.value);"

           value="   "></td>

           <td align="center"><input type="button" name="s37"

           onclick="setDate(this.value);"

           value="   "></td>

           <td align="center"><input type="button" name="s38"

           onclick="setDate(this.value);"

           value="   "></td>

           <td align="center"><input type="button" name="s39"

           onclick="setDate(this.value);"

           value="   "></td>

           <td align="center"><input type="button" name="s40"

           onclick="setDate(this.value);"

           value="   "></td>

           <td align="center"><input type="button" name="s41"

           onclick="setDate(this.value);"

           value="   "></td>

           <td align="center"><input type="button" name="s42"

           onclick="setDate(this.value);"

           value="   "></td>

       </tr>

   </table>

</form>

<form METHOD=POST ACTION="/cgi-bin/calendar.cgi">

 <table border=0 cellspacing=1 cellpadding=1>

 <tr>

 <td>

 <b>Selected:</b>

 </td>

 <td align=center>

 <input type=text size="12" name=dateField  onFocus="this.blur();">

 </td>

 <tr>
 <tr>
 <tr>
 <tr>

 <td align=center>

<INPUT TYPE=SUBMIT Name="action" Value="Block">
 </TD>

 <td align=center>

<INPUT TYPE=SUBMIT Name="action" Value="Un-block">
 </TD>

 </table>

</form>

</td>

</tr>

</table>

</BODY>

</HTML>



CERTIFIED EXPERT

Commented:
rowby,

"..The public visits a web page where they reserve a start and end date for their parking reservation.
If the parking lot is already filled up for the start date (only the start date) then when they push
the submit button they will get a message suggesting they select another start date because that date
is filled up."

Let me explain what i have understood so far.

You want the reservation script to lookup in the date.txt & see if the start date (that the user entered from the reservation form) matches with any date in the date.txt file.

If it does, then you want to show an error message and stop any further processing.

Let me know if this is correct.

Author

Commented:
"You want the reservation script to lookup in the date.txt & see if the start date (that the user entered
from the reservation form) matches with any date in the date.txt file.     ...If it does, then you want to show an error message and stop any further processing."

Yes.  The error message should be nicely formatted, along with a button that says CLICK HERE to return to the reservation page, and select a different date.

Thanks


Rowby

Author

Commented:
"You want the reservation script to lookup in the date.txt & see if the start date (that the user entered
from the reservation form) matches with any date in the date.txt file.     ...If it does, then you want to show an error message and stop any further processing."

Yes.  The error message should be nicely formatted, along with a button that says CLICK HERE to return to the reservation page, and select a different date.

Thanks


Rowby

Author

Commented:
"You want the reservation script to lookup in the date.txt & see if the start date (that the user entered
from the reservation form) matches with any date in the date.txt file.     ...If it does, then you want to show an error message and stop any further processing."

Yes.  The error message should be nicely formatted, along with a button that says CLICK HERE to return to the reservation page, and select a different date.

Thanks


Rowby
CERTIFIED EXPERT

Commented:
rowby,

"...Yes.  The error message should be nicely formatted, along with a button that says CLICK HERE to return
to the reservation page, and select a different date..."

So is it accurate to say that the "CLICK HERE: link/button works like the "Back" button of the browser?

Let me know.

Author

Commented:
Yes, the button it should work like the back button of a browser.  I suggest that it be a hard coded link, rather than a javascript-based button.

Rowby

CERTIFIED EXPERT

Commented:
rowby,

"..I suggest that it be a hard coded link, rather than a javascript-based button..."
On the contrary, it will have to javascript based.

Meanwhile, given that your clients will take some more time to decide on the DB, i would suggest you go ahead and close or delete the following question.

http://www.experts-exchange.com/jsp/qShow.jsp?ta=perl&qid=20246919

Author

Commented:
okay javascript it is.  I have deleted the 20246919 question.

Thanks!
CERTIFIED EXPERT

Commented:
rowby,

"..okay javascript it is..."

That is a good choice. i will start work on the integration today.

"..I have deleted the 20246919 question..."

Excellent!! Now please go ahead & close....

http://www.experts-exchange.com/jsp/qShow.jsp?ta=perl&qid=20245842
CERTIFIED EXPERT

Commented:
rowby,

'..Now please go ahead & close....

                     http://www.experts-exchange.com/jsp/qShow.jsp?ta=perl&qid=20245842 ..."

Thanks for closing the question.

Please find below the updated calendar.pl & reservation.cgi scripts.

i tested it a bit by blocking dates, making reservation on that blocked date, unblocking the date and then retrying reservation. Each step worked as expected.

However, i am looking to you to do the comprehensive testing, based on any use cases you might have.

===================calendar.pl
#!/usr/local/bin/perl

$|++;

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

use CGI;
use Time::Local;

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

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

}

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

if (!($dateField) && length($dateField)<=0){      ##      Empty!!
      print "<B>Date cannot be empty</B><P>\n";
      ++$error_flag;
}

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

($CMONTH,$DepartDay,$yeardropoff)=split(/\//,$dateField);

$CMONTH--;      ##      The month rages from 0 to 11, where 0 is January & 11 is December.

##      Do advanced date validations here.
$yeardropoff-=1900;      ##      Remove 1900 from the year.
$Time = timelocal(0,0,0,$DepartDay,$CMONTH,$yeardropoff);
##  End of placeholder for doing all data validations here

if (-e $date_file){
      open(DF,$date_file) || die $!;
      while(<DF>){
            chomp;
            $line{$_}++;
      }
      close(DF);
}

print "<!--\$dateField = >",$dateField,"<\n";
print "\$Time = >",$Time,"<-->\n";

if ($action=~ /^Block$/){
      ##      Append the data to the blocked dates file.
      $mess="$dateField has been blocked!!<BR>\n";
      $line{$Time}++;
}else{
      ##      Remove the data from the blocked dates file.
      $mess="$dateField has been unblocked!!<BR>\n";
      delete $line{$Time};
}

open(DF,">$date_file") || die $!;
foreach (sort keys %line){
      print DF $_."\n";
}
close (DF);

print "<B>$mess</B><P>\n";

print "Click <A HREF=/webtraining/calendar.html>HERE</A> for another date<P>\n";

===============================reservation.cgi
#!/usr/local/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>First name cannot be empty</B><P>\n";
      ++$error_flag;
}

if (!($LastName) && length($LastName)<=0){      ##      Empty!!
      print "<B>Last name cannot be empty</B><P>\n";
      ++$error_flag;
}

if (!($DepartMonth) && length($DepartMonth)<=0){      ##      Empty!!
      print "<B>Please select a month for departure</B><P>\n";
      ++$error_flag;
}

if (!($DepartDay) && length($DepartDay)<=0){      ##      Empty!!
      print "<B>Please select a day for departure</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 enter hour of departure</B><P>\n";
      ++$error_flag;
}

if (!($ReturnMonth) && length($ReturnMonth)<=0){      ##      Empty!!
      print "<B>Please select a month for Return</B><P>\n";
      ++$error_flag;
}

if (!($ReturnDay) && length($ReturnDay)<=0){      ##      Empty!!
      print "<B>Please select a day for Return</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 hour of Return</B><P>\n";
      ++$error_flag;
}

if (!($Email) && length($Email)<=0){      ##      Empty!!
      print "<B>Please enter an Email id.</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

Author

Commented:
Will test the new scripts etc on Wednesday.  

Thanks!

Rowby
CERTIFIED EXPERT

Commented:
rowby,

"..Will test the new scripts etc on Wednesday.  ..."

Sure. Let me know how it goes.

Author

Commented:
Hi  

The date blocking works.   However if the reservation is successful it does not send to a comfirmation page and does not send out an email.  

I assume that is part of the script that needs to be redone?  

Take a look:

http://www.laxautopark.com/content/booking.htm 

Thanks
CERTIFIED EXPERT

Commented:
rowby,

"..I assume that is part of the script that needs to be redone?  .."

No. Actually that part is not affected in any way. it should work like normal.

You might want to check the script again to ensure the problem is not caused by something else (non-functional sendmail?)

Let me know.

Author

Commented:
I'll check a little later today.
CERTIFIED EXPERT

Commented:
rowby,

"..I'll check a little later today. ..."

Did you get a chance to look at the script? Did it work properly?

Let me know.

Author

Commented:
Hi didn't have a chance.  Will check it later today (10 am in Calif right now.  Will check it in a couple of hours -- when arrive at client.

ROwby
CERTIFIED EXPERT

Commented:
rowby,

"..Will check it later today (10 am in Calif right now.  Will check it in a couple  of hours -- when arrive at client...."

Sure. Let me know. I am on PST time too.

Happy holidays!!

Author

Commented:
Nope, still not working.  

I put up two new test pages:

http://www.laxautopark.com/content/booking-calling-old-reservation-cgi.htm  calls "old-reservation.cgi", which I posted at the beginning of this question.  IT results in a the approprite confirmation page (but does not have the lock-out date feature incorporated by the calendar.cgi script.

and
http://www.laxautopark.com/content/booking-calling-reservation-cgi.htm  which calls the newest script "reservation.cgi", which incorporates the lock-out date feature incorporated by calendar.cgi  But a successful submission results in a blank page.

================== Below are copy and pastes of both scripts  Both scripts have 755 permissions.

first what I am calling "old-calendar.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";

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

print "\$$_ = >",$$_,"<<BR>\n";
}

##     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>First name cannot be empty</B><P>\n";
++$error_flag;
}

if (!($LastName) && length($LastName)<=0){  ##  Empty!!
print "<B>Last name cannot be empty</B><P>\n";
++$error_flag;
}

if (!($DepartMonth) && length($DepartMonth)<=0){  ##  Empty!!
print "<B>Please select a month for departure</B><P>\n";
++$error_flag;
}

if (!($DepartDay) && length($DepartDay)<=0){  ##  Empty!!
print "<B>Please select a day for departure</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 enter hour of departure</B><P>\n";
++$error_flag;
}

if (!($ReturnMonth) && length($ReturnMonth)<=0){  ##  Empty!!
print "<B>Please select a month for Return</B><P>\n";
++$error_flag;
}

if (!($ReturnDay) && length($ReturnDay)<=0){  ##  Empty!!
print "<B>Please select a day for Return</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 (!($Email) && length($Email)<=0){  ##  Empty!!
print "<B>Please enter an Email id.</B><P>\n";
++$error_flag;
}

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

if (!($Email) && length($Email)<=0){  ##  Empty!!
print "<B>Please enter an Email id.</B><P>\n";
++$error_flag;
}

##  Do advanced date validations here.
$yeardropoff-=1900; ##  Remove 1900 from the year.
$CMONTH=$mon2num{uc($DepartMonth)};
$Time1 = timelocal(0,0,$DepartHour,$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.

##     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, $DepartHour:$DepartMinute $DepartDT

Return date: $ReturnMonth $ReturnDay, $yeardropoff, $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, $DepartHour:$DepartMinute $DepartDT

Return date: $ReturnMonth $ReturnDay, $yeardropoff, $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, $DepartHour:$DepartMinute $DepartDT</font>
<p align="left"><font face="Arial, Helvetica, sans-serif" size="3">Return
date: $ReturnMonth $ReturnDay, $yeardropoff, $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>
};

======================= and now the latest reservation.cgi script: (which results in a blank page):
'#!/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>First name cannot be empty</B><P>\n";
     ++$error_flag;
}

if (!($LastName) && length($LastName)<=0){     ##     Empty!!
     print "<B>Last name cannot be empty</B><P>\n";
     ++$error_flag;
}

if (!($DepartMonth) && length($DepartMonth)<=0){     ##     Empty!!
     print "<B>Please select a month for departure</B><P>\n";
     ++$error_flag;
}

if (!($DepartDay) && length($DepartDay)<=0){     ##     Empty!!
     print "<B>Please select a day for departure</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 enter hour of departure</B><P>\n";
     ++$error_flag;
}

if (!($ReturnMonth) && length($ReturnMonth)<=0){     ##     Empty!!
     print "<B>Please select a month for Return</B><P>\n";
     ++$error_flag;
}

if (!($ReturnDay) && length($ReturnDay)<=0){     ##     Empty!!
     print "<B>Please select a day for Return</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 hour of Return</B><P>\n";
     ++$error_flag;
}

if (!($Email) && length($Email)<=0){     ##     Empty!!
     print "<B>Please enter an Email id.</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

Author

Commented:
P.s. NO hurry, probably the soonest these scripts will go live will be December 28-29

Rowby
CERTIFIED EXPERT

Commented:
rowby,

"..and now the latest reservation.cgi script: (which results in a blank page):..."

Oh no!!! No..No.....

The reservation.cgi script that you have is partial. i was under the impression that you would merge the version that i posted (with blocking & un blocking checks) with the larger code.

Anyway, you need to APPEND the following lines of code

##     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, $DepartHour:$DepartMinute $DepartDT

Return date: $ReturnMonth $ReturnDay, $yeardropoff, $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, $DepartHour:$DepartMinute $DepartDT

Return date: $ReturnMonth $ReturnDay, $yeardropoff, $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, $DepartHour:$DepartMinute $DepartDT</font>
<p align="left"><font face="Arial, Helvetica, sans-serif" size="3">Return
date: $ReturnMonth $ReturnDay, $yeardropoff, $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>
};


AFTER....

##     End of placeholder for doing all data validations here


Let me know how the script works after you have made this change.

Author

Commented:
Hi,

The script works (of course).  Let me know if you need to do anything else, otherwise I'll award the points.

Thanks again!

Rowby

Author

Commented:
(Here's the link to the latest working script)

http://www.laxautopark.com/content/booking-calling-reservation-cgi.htm
ozo
CERTIFIED EXPERT
Most Valuable Expert 2014
Top Expert 2015

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

Author

Commented:
Hmmmm. I don't get that error.  Can you do it again and try to reproduce the error.  Or tell me what you did that resulted in the error?  

Rowby

Author

Commented:
Also, Ozo, did you use the latest test link:



http://www.laxautopark.com/content/booking-calling-reservation-cgi.htm 

Thanks

Rowby
CERTIFIED EXPERT

Commented:
rowby,

"..http://www.laxautopark.com/content/booking-calling-reservation-cgi.htm .."

here is the page that i receieved when i tried the above URL....

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: 1064

Name: k k

Departure date: Jan 1, 102, 10:00:00:00

Return date: Jan 18, 102, 23:00:00:00

Email address: m@my.com

Zip code: sfdsdf

Corporate code: sfd

Author

Commented:
Yes that should be fine.

I don't know how Ozo got that error message.  As I recall this issue that Ozo reported:

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

....was resolved in an earlier fix of the script.

Rowby
CERTIFIED EXPERT

Commented:
rowby,

".102, 23:00:00:00 .."

However, i can see a small problem.

The year is shown as 102. All that you need to do is add 1900 to the variable (for year) & then display it.

Hope that helps.

Author

Commented:
"The year is shown as 102. All that you need to do is add 1900 to the variable (for year) & then display
it"

Hi

Not sure where I would make that change or how to do it.(And would it also correct the emails):

Is it this section?

Departure date: $DepartMonth $DepartDay, $yeardropoff, $DepartHour:$DepartMinute $DepartDT

Return date: $ReturnMonth $ReturnDay, $yeardropoff, $ReturnHour:$ReturnMinute $ReturnDT

Author

Commented:
"The year is shown as 102. All that you need to do is add 1900 to the variable (for year) & then display
it"

Hi

Not sure where I would make that change or how to do it.(And would it also correct the emails):

Is it this section?

Departure date: $DepartMonth $DepartDay, $yeardropoff, $DepartHour:$DepartMinute $DepartDT

Return date: $ReturnMonth $ReturnDay, $yeardropoff, $ReturnHour:$ReturnMinute $ReturnDT
CERTIFIED EXPERT

Commented:
rowby,

"..Not sure where I would make that change or how to do it.(And would it also correct the emails):

                     Is it this section?."

Yes. i think this is it.

To fix the problem, pl. REPLACE...

Departure date: $DepartMonth $DepartDay, $yeardropoff, $DepartHour:$DepartMinute $DepartDT

Return date: $ReturnMonth $ReturnDay, $yeardropoff, $ReturnHour:$ReturnMinute $ReturnDT

WITH...

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

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


Let me know how it goes.

Author

Commented:
HI,

Did the replacement and got an internal server error. Just to be sure I reuploaded the pervious version of the script and did NOT get the internal service error.

 Here is a copy and paste from that section of the script:

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).{, $ReturnHour:$ReturnMinute $ReturnDT

Email address: $Email

Zip code: $Zip

Corporate code: $TACode
};
CERTIFIED EXPERT

Commented:
rowby,

"..Just to be sure I reuploaded the pervious version  of the script and did NOT get the internal service error. "

Can you please post the exact script, after the changes here?

Let me know.

Author

Commented:
I downloaded the current scriopt back to my local computer.  It follows below:

#!/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>First name cannot be empty</B><P>\n";
     ++$error_flag;
}

if (!($LastName) && length($LastName)<=0){     ##     Empty!!
     print "<B>Last name cannot be empty</B><P>\n";
     ++$error_flag;
}

if (!($DepartMonth) && length($DepartMonth)<=0){     ##     Empty!!
     print "<B>Please select a month for departure</B><P>\n";
     ++$error_flag;
}

if (!($DepartDay) && length($DepartDay)<=0){     ##     Empty!!
     print "<B>Please select a day for departure</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 enter hour of departure</B><P>\n";
     ++$error_flag;
}

if (!($ReturnMonth) && length($ReturnMonth)<=0){     ##     Empty!!
     print "<B>Please select a month for Return</B><P>\n";
     ++$error_flag;
}

if (!($ReturnDay) && length($ReturnDay)<=0){     ##     Empty!!
     print "<B>Please select a day for Return</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 hour of Return</B><P>\n";
     ++$error_flag;
}

if (!($Email) && length($Email)<=0){     ##     Empty!!
     print "<B>Please enter an Email id.</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, $DepartHour:$DepartMinute $DepartDT

Return date: $ReturnMonth $ReturnDay, $yeardropoff, $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).{, $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, $DepartHour:$DepartMinute $DepartDT</font>
<p align="left"><font face="Arial, Helvetica, sans-serif" size="3">Return
date: $ReturnMonth $ReturnDay, $yeardropoff, $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>
};
CERTIFIED EXPERT

Commented:
rowby,

i am not sure why you have added the sending out email part twice??

Let me know.

Author

Commented:
Because I wanted a slighlty different message in the body going to the people at fox than from the vistor.

I haven't changed that message (to the people at fox) yet -- in the script.

Rowby

Author

Commented:
Because I wanted a slighlty different message in the body going to the people at fox than from the vistor.

I haven't changed that message (to the people at fox) yet -- in the script.

Rowby
CERTIFIED EXPERT

Commented:
rowby,

"..
                     I haven't changed that message (to the people at fox) yet -- in the script..."

In your code, you need to REPLACE...

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

WITH...

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

i hope this will not just fix the source of the problem, but will also provide you with a fully functional script.
CERTIFIED EXPERT

Commented:
rowby,

Did you get a chance to try the above solution?

Let me know.

Author

Commented:
Will test in a few minutes.

And report back

ROwby
CERTIFIED EXPERT

Commented:
rowby,

"..Will test in a few minutes.

                     And report back..."

Excellent!!

Hope we have this nailed down this time round.

Author

Commented:
Hmmmm.    NO error, but it still gives the date as "102".

Below is a copy and paste of the exact script being called at:

http://www.laxautopark.com/content/booking-calling-reservation-cgi.htm

===============
#!/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>First name cannot be empty</B><P>\n";
     ++$error_flag;
}

if (!($LastName) && length($LastName)<=0){     ##     Empty!!
     print "<B>Last name cannot be empty</B><P>\n";
     ++$error_flag;
}

if (!($DepartMonth) && length($DepartMonth)<=0){     ##     Empty!!
     print "<B>Please select a month for departure</B><P>\n";
     ++$error_flag;
}

if (!($DepartDay) && length($DepartDay)<=0){     ##     Empty!!
     print "<B>Please select a day for departure</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 enter hour of departure</B><P>\n";
     ++$error_flag;
}

if (!($ReturnMonth) && length($ReturnMonth)<=0){     ##     Empty!!
     print "<B>Please select a month for Return</B><P>\n";
     ++$error_flag;
}

if (!($ReturnDay) && length($ReturnDay)<=0){     ##     Empty!!
     print "<B>Please select a day for Return</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 hour of Return</B><P>\n";
     ++$error_flag;
}

if (!($Email) && length($Email)<=0){     ##     Empty!!
     print "<B>Please enter an Email id.</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, $DepartHour:$DepartMinute $DepartDT

Return date: $ReturnMonth $ReturnDay, $yeardropoff, $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, $DepartHour:$DepartMinute $DepartDT</font>
<p align="left"><font face="Arial, Helvetica, sans-serif" size="3">Return
date: $ReturnMonth $ReturnDay, $yeardropoff, $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>
};


CERTIFIED EXPERT
Commented:
rowby,

".. NO error, but it still gives the date as "102"...."

As expected. Remember you have the same code in three places (2 emails & one HTML output). So you need to make this same change in all these places.

Based on the change you made to one email, i am sure you can replicate this same change in the other email.

Meanwhile, for the HTML part, you need to REPLACE....

<p align="left"><font face="Arial, Helvetica, sans-serif" size="3">Departure
                     date: $DepartMonth $DepartDay, $yeardropoff, $DepartHour:$DepartMinute $DepartDT</font>
                     <p align="left"><font face="Arial, Helvetica, sans-serif" size="3">Return
                     date: $ReturnMonth $ReturnDay, $yeardropoff, $ReturnHour:$ReturnMinute $ReturnDT</font>

WITH...

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


Let me know after you have made the changes.

Author

Commented:
I made your corrections and it works fine.

Thanks for your work and patience!

I'll put this on line probably on Friday.

Rowby
CERTIFIED EXPERT

Commented:
rowby,

"..I made your corrections and it works fine.

                     Thanks for your work and patience!

                     I'll put this on line probably on Friday...."

Yessss!!!! Glad to know you got the solution you were looking for.

Meanwhile, let me know the progress on the other question (http://www.experts-exchange.com/jsp/qShow.jsp?ta=perl&qid=20249186) that you have opened.

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