#!/usr/bin/perl ############################################################################## # Weekly Holiday Home Booking Calendar Version 2.50 # # Copyright 2001 John Plaxton john@availcheck.com # # First Created June 2001 Last Modified 15 November 2003 # # Scripts Archive at: http://www.availcheck.com # ############################################################################## # COPYRIGHT NOTICE # # Copyright 2001 John H K Plaxton All Rights Reserved. # # # # Availcheck Weekly Availability Calendar may NOT be used or modified or # # changed by anyone without my expressed permission. The coding should # # remain intact and unchanged. # # # # Selling the code for this program without prior written consent is # # expressly forbidden. In other words, please ask first before you try and # # make money off my program. This coding has taken hundreds of man hours. # # # ############################################################################## use CGI qw(:standard);use CGI::Carp qw(fatalsToBrowser); use Time::localtime; use Time::Local; $q = new CGI; print $q->header; $VERSION = "v 2.50"; require "/home/gar10848/public_html/calendars/cal1/config.pl"; require "/home/gar10848/public_html/calendars/cal1/codebank.pl"; foreach $field ($q->param()) { ${$field} = $q->param($field); ${$field} =~ s/'\<\>//g; #print"$field - ${$field}
"; } $Bin = &getpath; my $self_url = $q->url; my $headerdata = &get_header_details(); my ($contactname,$propname,$userid,$pword,$propaddr,$proppostcode,$proptel,$propemail,$headertext,$curr,$currphrase,$lastupdated,$showhist,$pcounter,$showpricecol,$showavail,$deposit) = split(/\|/,$headerdata); my $link = &emaillink($propemail); $propaddr =~ s/¬/ /g; $headertext =~ s/¬/
/g; ###################################################################################### # If you are translating the calendars then change these lines to your chosen language my $contactline = "For Further Details ".$proptel.' '.$link; my $lastupdtext = &createlongdatestr($lastupdated,$lastupdated); $lastupdtext = "Calendar Last Updated ".$lastupdtext; $ret_menu_text = "
Return to Calendar
"; ###################################################################################### my %details_hash = ( 'xx--propname--xx' => $propname, 'xx--propaddr--xx' => $propaddr, 'xx--proptel--xx' => $proptel, 'xx--propemail--xx' => $propemail, 'xx--headertext--xx' => $headertext, 'xx--textcol--xx' => $textcol, 'xx--formcol--xx' => $formcol, 'xx--titlecolor--xx' => $titlecolor, 'xx--bordercolor--xx' =>$bordercolor, 'xx--availcol--xx' => $availcolors[0], 'xx--availwecol--xx' => $availcolors[1], 'xx--bookedcol--xx' => $availcolors[2], 'xx--URL--xx' => $self_url, 'xx--contactline--xx'=> $contactline, 'xx--lastupdtext--xx'=> $lastupdtext, 'xx--endaddtext--xx' => $endaddtext, 'xx--jsfile--xx' => $ancilldir."avail.js", 'xx--grid_main1--xx' => "", 'xx--grid_main2--xx' => "" ); if ($q->param('complete_enquiry')){ &send_client_email; &send_email_to_hr; if (-e $return_html) {send_html( $return_html, \%details_hash);} else {&print_no_access_screen("HTML File " . $return_html ." Not found ");} } elsif ($q->param('booking_enquiry')){ &printbookingpage($headerdata); } else {&printcalendar($headerdata); } sub printcalendar { my ($contactname,$propname,$userid,$pword,$propaddr,$proppostcode,$proptel,$propemail,$headertext,$curr,$currphrase,$lastupdated,$showhist,$pcounter,$showpricecol,$showavail,$deposit) = split(/\|/, shift); (my $menu_url = $self_url) =~ s/index.cgi/menu.cgi/g; if (!$showyear){$showyear = &getcurryear;} my $curryear = &getcurryear; my $nextyear = $curryear+1; my $twoyears = $curryear+2; my $grid_text = ""; $grid_text .= "
"; $grid_text .= &printgridcell('bgcolor='.$availcolors[0],$availwords[0],"align='center'","2"); $grid_text .= &printgridcell('bgcolor='.$availcolors[1],$availwords[1],"align='center'","2"); $grid_text .= &printgridcell('bgcolor='.$availcolors[2],$availwords[2],"align='center'","2"); $grid_text .= &printgridcell("","Update Calendar","align='center'","2"); if ($showpricecol ==1){$grid_text .= &printgridcell("",$currphrase,"align='center'","2");} $grid_text .= "
Calendar for $propname [ $showyear ]
"; $grid_text.= "
\n"; $grid_text .= "\n"; $grid_text .= ""; $grid_text .= &printgridtitle('class=gridtitles',''); for(my $x=1;$x<6;$x++){$grid_text .= &printgridtitle('class=gridtitles',"Week $x");}; &printcalendarrows($showpricecol,$showavail,$curr,$grid_text); } sub printcalendarrows { my $showpricecol = shift;my $showavail = shift; my $curr = shift;my $grid_text = shift;my ($cbstr, $year, $x, $pricestr);my $rowcount = 0;my $tempmon = -1;my $dopadding = 0;my $cbon=$ancilldir."chon.jpg"; open (DB,"<$datatable")|| &print_no_access_screen('Datafile not created or missing'); foreach (){ my ($aut,$date,$avail,$price,$paidfor) = split(/\|/, $_); if ($date > time){ $year = localtime($date)->year; $year+=1900; my $currmon = localtime($date)->mon; $cbstr = ""; if ($year == $showyear){ $rowcount++; my $mymon = localtime($date)->mon; my $mymday = localtime($date)->mday; my $dstr = (&adddateending($mymday).'-'.&adddateending(localtime($date+604800)->mday)); if ($showavail==0){$avail = 0;} if ($tempmon != $currmon){ $grid_text .= "";$grid_text .= &printgridtitle('class=gridtitles',$months[$currmon]); if ($dopadding == 0){ if ($mymday > 27){$grid_text .= "";} elsif ($mymday > 20){$grid_text .= "";} elsif ($mymday > 13){$grid_text .= "";} elsif ($mymday > 6){$grid_text .= "";} else {} $dopadding = 1; } if ($avail == 0){ $cbstr = ""; if($showpricecol == 1){$pricestr=&createpricestr($curr,$price);} else {$pricestr='';} $grid_text .= &printgridcell('class=availcol',($cbstr.' '.$dstr.' '.$pricestr),"align='left'","1"); } elsif ($avail == 1){$grid_text .= &printgridcell('class=availwecol',$dstr.' '.$availwords[$avail],"align='center'","1");} else {$grid_text .= &printgridcell('class=bookedcol',$dstr.' '.$availwords[$avail],"align='center'","1");} } else { if ($avail == 0){ $cbstr = ""; if($showpricecol ==1){$pricestr=&createpricestr($curr,$price);} $grid_text .= &printgridcell('class=availcol',($cbstr.' '.$dstr.' '.$pricestr),"align='left'","1"); } elsif ($avail == 1){$grid_text .= &printgridcell('class=availwecol',$dstr.' '.$availwords[$avail],"align='center'","1");} else {$grid_text .= &printgridcell('class=bookedcol',$dstr.' '.$availwords[$avail],"align='center'","1");} } $tempmon = $mymon; } # not correct year } # not after today } # foreach close (DB); if ($rowcount<=1){ $grid_text.= "
NO CALENDAR DATA FOUND FOR THIS YEAR
"; } else { $grid_text.= "

Click on the boxes for the dates you are interested in.
Then click on the "Make Booking Enquiry"button above.
© 2000-2003 Availcheck $VERSION
"; } $details_hash{'xx--grid_main1--xx'} = $grid_text; #################################################################################### # template header_html printed if (-e $header_html) {send_html( $header_html, \%details_hash);} else {print"HTML File " . $header_html ." Not found ";} #################################################################################### } # end print_yearly_calendarrows #################################################################################### sub send_client_email { my $todaysdate = &get_date; my @bookingrecs = &get_booking_records();my $pricec = 0;my $longdatestr; open(MAIL,"|$mailprog -t") or die "Error opening email gateway system file: $!\n"; print MAIL "To: $email\n"; print MAIL "From: $propemail\n"; print MAIL "Subject: Booking Enquiry for $propname\n\n"; print MAIL "Thank you for making a booking enquiry for $propname. It was submitted by\n"; print MAIL "$booker_name [ $email ] on $todaysdate\n"; print MAIL "-" x 80 . "\n\n"; print MAIL "Here are the details of Your booking enquiry\n"; print MAIL "\n"; print MAIL "Booking for: $propname\n"; print MAIL "Date\(s\) Interested In: \n"; if (! $showpricecol){ print MAIL "DATE(S)\n"; print MAIL "==============\n"; foreach my $row (@bookingrecs){ my ($aut,$date,$avail,$price,$paidfor) = split(/\|/, $row); $pricec = 0; my $tempd = &createlongdatestr($date); $longdatestr .= $tempd; print MAIL "$tempd \n"; } } else { print MAIL "DATE(S) PRICE(S)\n"; print MAIL "=================================================\n"; foreach my $row (@bookingrecs){ my ($aut,$date,$avail,$price,$paidfor) = split(/\|/, $row); $pricec += $price; my $tempp = &createpricestr($curr,$price); my $tempd = &createlongdatestr($date); $longdatestr .= $tempd; print MAIL "$tempd $tempp \n"; } my $temptot = &createpricestr($curr,$pricec); print MAIL "-" x 80 . "\n"; print MAIL "Total: $temptot\n\n\n"; } chomp($deposit); if ($deposit){ $dep = &calculate_deposit($deposit,$pricec); $dep_text = &createpricestr($curr,$dep); print MAIL "We require a deposit of $dep_text to secure this booking. If it is less than 1 month until the booking date then please send full payment.\n\n"; print MAIL "-" x 80 . "\n\n"; print MAIL "Please send cheques payable to:\n$contactname\n$propaddr\n$proppostcode\n\n"; if (-e "paypal_plugin.pl"){ require "paypal_plugin.pl"; my $prop_str = $propname . " " .$longdatestr;$prop_str =~ s/ /\%20/g; my $item_str = $propname . "/" . time; $item_str =~ s/ /\%20/g; $pricetot =~ s/$curr//g;chomp($deposit); $paypal_depositstr = &create_paypal_str_deposit($dep,$prop_str. "%20Deposit%20Payment",$item_str,$currphrase); $paypal_fullstr = &create_paypal_str_full($pricec,$prop_str. "%20Full%20Payment",$item_str,$currphrase); if ($deposit){print MAIL "$paypal_depositstr\n";} print MAIL "$paypal_fullstr\n"; } } else { print MAIL "We shall Try to contact you as soon as possible to confirm this booking.\n\n"; } print MAIL "No. Adults $no_adults\n"; print MAIL "No. Children $no_children\n"; print MAIL "For any further queries please ring us on $proptel\n\n"; print MAIL "-" x 80 . "\n\n"; print MAIL "Thank You. \n"; print MAIL "Availcheck Calendars http://www.availcheck.com\n"; print MAIL "-" x 80 . "\n\n"; close (MAIL); } # end send_email #################################################################################### sub send_email_to_hr { my $todaysdate = &get_date; my @bookingrecs = &get_booking_records(); my $startdate=0;my $enddate=0;my $datediff=0;my $atemp=0;my $init=1;$pricec=0;my $pricetot=0;my $datesstr; open(MAIL,"|$mailprog -t") or die "Error opening email gateway system file: $!\n"; print MAIL "To: $propemail\n"; print MAIL "From: $email\n"; print MAIL "Subject: Booking Enquiry for $propname\n\n"; print MAIL "You have received a booking enquiry from your website posted by\n"; print MAIL "$booker_name [ $email ] on $todaysdate\n"; print MAIL "-" x 80 . "\n\n"; print MAIL "Here are the details of the booking enquiry\n"; print MAIL "\n"; print MAIL "Booking for: $propname\n"; print MAIL "Date\(s\) Interested In: \n"; print MAIL "DATE(S) Availability\n"; print MAIL "=============================================\n"; if (! $showpricecol){ print MAIL "DATE(S)\n"; print MAIL "==============\n"; foreach my $row (@bookingrecs){ my ($aut,$date,$avail,$price,$paidfor) = split(/\|/, $row); my $tempd = &createlongdatestr($date); print MAIL "$tempd \n"; } } else { print MAIL "DATE(S) PRICE(S)\n"; print MAIL "=================================================\n"; foreach my $row (@bookingrecs){ my ($aut,$date,$avail,$price,$paidfor) = split(/\|/, $row); $pricec += $price; my $tempp = &createpricestr($curr,$price); my $tempd = &createlongdatestr($date); print MAIL "$tempd - $tempp \n"; } my $temptot = &createpricestr($curr,$pricec); print MAIL "-" x 80 . "\n"; print MAIL "Total: $temptot\n\n\n"; } (my $menu_url = $self_url) =~ s/index.cgi/menu.cgi/g; $postaddress =~ s/\r\n/ /g; print MAIL "=============================================\n\n"; print MAIL "Estimated time of arrival: $arrival_time\n\n"; if (($showprices)&&($pricetot > 0)){ $pricetot_text = &createpricestr($curr,$pricetot); print MAIL "Total Price for this booking: $pricetot_text\n";} chomp($deposit); if ($deposit){ $dep = &calculate_deposit($deposit,$pricec); $dep = &createpricestr($curr,$dep); print MAIL "An email has been sent to $booker_name requesting payment ( Deposit : $dep )\n\n"; } else {print MAIL "An email has been sent to $booker_name $email\n\n";} print MAIL "Address Details\n"; print MAIL "===============\n"; print MAIL "$booker_name\n"; print MAIL "$postaddress\n$country\n Tel: $phone\n\n"; print MAIL "No. Adults $no_adults\n"; print MAIL "No. Children $no_children\n"; print MAIL "Other requests: $enquiry\n\n"; ## # If you change your booking form elements then you can have the email send # these details back to you like so: # print MAIL "$name_of_form_element\n"; # noting the \$ sign at the start of the form name element. ## print MAIL "=============================================\n"; print MAIL "By clicking on the link below you can automatically update your calendar to make the dates in this booking taken. Only do this if these dates are now fully booked.\n"; my $urlstr = "?action=autoupdatecal&u=$userid&p=$pword"; foreach (@bookingrecs){ my ($aut,@a) = split(/\|/, $_); $urlstr .= "&aut|$aut=on"; } print MAIL "$menu_url$urlstr\n\n"; print MAIL "=============================================\n\n"; print MAIL "Availcheck Calendars http://www.availcheck.com\n"; print MAIL "-" x 80 . "\n\n"; close (MAIL); } # end send_email #################################################################################### sub printbookingpage { my $atemp=0;$init=1;my $allavail=0; my $grid_text = "";my $pricec = 0; my @bookingrecs = &get_booking_records();my $rowcount = @bookingrecs; foreach my $field ($q->param()) {if($field ne 'action'){$grid_text .= "\n";}} $grid_text .= "
Check dates and fill in your contact details
\n"; if ($showpricecol==1){$grid_text .= "\n";} else {$grid_text .= "\n";} if ($rowcount<1){$grid_text .= "";} elsif ($showpricecol==1){ $grid_text .= "\n"; $grid_text .= "\n"; $grid_text .= "\n\n";} else {$grid_text .= "";} foreach (@bookingrecs){ ($aut,$date,$avail,$price,$paidfor) = split(/\|/, $_); $tempd = &createlongdatestr($date); $tempp = &createpricestr($curr,$price); $atemp = $avail; if ($avail!=0){$allavail++;} $pricec += $price; if ($showpricecol==1){$grid_text .= "";} else {$grid_text .= "";} } # end foreach if ($allavail == 0){if ($rowcount > 1){ if ($showpricecol==1){$temptot = &createpricestr($curr,$pricec); $grid_text .= "\n"; $grid_text .= "";}}} $grid_text .= "\n"; if ($deposit =~ /\%/){$deposit = sprintf("%.2f", (($deposit * $pricec)/100));} $tempd = &createlongdatestr($startdate,$enddate); if ($pricec > 0){$pricec = &createpricestr($curr,$pricec);} else {$pricec = "---";} chomp($deposit); if ($deposit and ! $allavail and $rowcount){ $deposit = &createpricestr($curr,$deposit); $grid_text .= "\n"; $grid_text .= "\n"; } $grid_text .= "
Details
Details
PLEASE SELECT DATES BEFORE COMPLETING THIS FORM
DatesPriceAvailability
DatesAvailability
$tempd $tempp $availwords[$atemp]
$tempd $availwords[$atemp]
 
Total:$temptot
 
 
Total Deposit required to secure this booking:$deposit
\n"; # inserts details of selected dates into HASH which appears at top of booking form in xx--grid_main1--xx position $details_hash{'xx--grid_main1--xx'} = $grid_text; # inserts details of selected dates into HASH which appears at top of booking form in xx--grid_main1--xx position $grid_text = ""; $grid_text .= "
"; if (! $rowcount) {$grid_text .= "Please select dates you are interested in.
";} elsif ($allavail){$grid_text .= "Sorry, some of your select dates are taken. Please reselect.
";} if ($rowcount and ! $allavail){$grid_text .= "";} $grid_text .= "
"; #################################################################################### # inserts buttons and/or error message into HASH which appears at bottom of booking form in xx--grid_main2--xx position $details_hash{'xx--grid_main2--xx'} = $grid_text; # inserts buttons and/or error message into HASH which appears at bottom of booking form in xx--grid_main2--xx position #################################################################################### # template booking_form_html printed if (-e $booking_form_html) {send_html( $booking_form_html, \%details_hash);} else {print"HTML File " . $booking_form_html ." Not found ";} #################################################################################### } # end printbookingpage