#!/usr/bin/perl # before anything else, the script needs to find out its own name # # some servers (notably IIS on windows) don't set the cwd to the script's # directory before executing it. So we get that information # from $0 (the full name & path of the script). BEGIN{($_=$0)=~s![\\/][^\\/]+$!!;push@INC,$_} $name = $0; $name =~ s/.+\/.+\///; # for unix $name =~ s/.+\\.+\\//; # for windows $path = $0; $path =~ s/(.+\/).+/$1/g; # for unix $path =~ s/(.+\\).+/$1/g; # for windows if ($path ne "") { chdir $path; push @INC,$path; } # finished discovering name # you'll need to replace the string below with the # actuao URL of your plans installation. #my $plans_url = "http://www.planscalendar.com/demo/plans.cgi"; #my $plans_url = "http://url.of.your/plans/installation/plans.cgi"; # check for required modules. my $module_found=0; foreach $temp_path (@INC) { if (-e "$temp_path/CGI") {$module_found=1;} } if ($module_found == 0) { $fatal_error=1; $error_info .= "unable to locate required module CGI!\n"; } else {use CGI;} $module_found=0; foreach $temp_path (@INC) { if (-e "$temp_path/CGI/Carp.pm") {$module_found=1;} } if ($module_found == 0) { $fatal_error=1; $error_info .= "unable to locate required module CGI::Carp!\n"; } else {use CGI::Carp qw/fatalsToBrowser/;} $module_found=0; foreach $temp_path (@INC) { if (-e "$temp_path/Time") {$module_found=1;} } if ($module_found == 0) { $fatal_error=1; $error_info .= "unable to locate required module Time.pm!\n"; } else {use Time::Local;} $module_found=0; foreach $temp_path (@INC) { if (-e "$temp_path/IO.pm") {$module_found=1;} } if ($module_found == 0) { $fatal_error=1; $error_info .= "unable to locate required module IO.pm!\n"; } else {use IO::Socket;} if ($fatal_error == 1) # print error and bail out { &fatal_error(); } $module_found=0; foreach $temp_path (@INC) { if (-e "$temp_path/plans_config.pl") {$module_found=1;} } if ($module_found == 0) { $fatal_error=1; $error_info .= "Unable to locate plans_config.pl! It should be in the same directory as plans.cgi!\n"; } else {require "plans_config.pl";} $module_found=0; foreach $temp_path (@INC) { if (-r "$temp_path/plans_lib.pl") {$module_found=1;} } if ($module_found == 0) { $fatal_error=1; $error_info .= "Unable to locate plans_lib.pl! It should be in the same directory as plans.cgi!\n"; } else {require "plans_lib.pl";} # get the language file, if one is defined if (defined $language_file) { $module_found=0; foreach $temp_path (@INC) { if (-r "$temp_path/$language_file") {$module_found=1;} } if ($module_found == 0) { $fatal_error=1; $error_info .= "Unable to locate language file $language_file! It should be in the same directory as plans.cgi!\n"; } else {require $language_file;} } else { $fatal_error=1; $error_info .= "No language file defined in plans.config!\n"; } # check for perl version local $perl_version = (sprintf ("%vd",$^V)); my $temp = substr($perl_version,0,3); if ($temp < 5.6) { $fatal_error=1; $error_info .= "Your version of perl ($perl_version) is too old! Plans requires perl version 5.6 or better.\n"; } if (!(-e "$temp_path/$config_file")) { $fatal_error=1; $error_info .= "Unable to locate email reminders data file $email_reminders_datafile! It should be in the same directory as email_reminders.cgi!\n"; } if ($fatal_error == 1) # print error and bail out { &fatal_error(); } # init cgi stuff #$q = new CGI; #$script_url = $q->url(-path_info>=1); #$script_url =~ /(.*)\//; # remove trailing / and all text after #$script_url = $1; # remove trailing / and all text after my $new_lines = ""; &load_calendars(); # load upcoming event data open (FH, "$email_reminders_datafile") || ($debug_info .="\nUnable to open file $email_reminders_datafile"); flock FH,2; my @lines=; close datafile; foreach $line (@lines) { if ($line !~ /\w/) {next}; # skip blank spaces my $temp_line = $line; $temp_line =~ s/<\/?email_reminder>//g; my ($evt_id) = &xml_quick_extract($temp_line, "evt_id"); my ($before) = &xml_quick_extract($temp_line, "before"); my ($script_url) = &xml_quick_extract($temp_line, "script_url"); $script_url = &decode($script_url); my ($extra_text) = &xml_quick_extract($temp_line, "extra_text"); $extra_text = &decode($extra_text); my ($to_address) = &xml_quick_extract($temp_line, "email_address"); $to_address = &decode($to_address); &load_event($evt_id); %current_event = %{$events{$evt_id}}; my $cal_id = $current_event{cal_id}; $rightnow = time() + 3600 * $calendars{$cal_id}{gmtime_diff}; my $event_time = $events{$evt_id}{start} + 3600 * $calendars{$cal_id}{gmtime_diff}; $date_string = &nice_date_range_format($current_event{start}, $current_event{end}, " - "); my $event_time = ""; if ($current_event{all_day_event} ne "1") { $event_time = &nice_time_range_format($current_event{start}, $current_event{end}); } my $reminder_text = $lang{email_reminder_text}; $reminder_text =~ s/###time###/$event_time/g; $reminder_text =~ s/###title###/$current_event{title}/g; $reminder_text =~ s/###date###/$date_string/g; $reminder_text =~ s/###details###/$current_event{details}/g; $reminder_text =~ s/###extra text###/$extra_text/g; $reminder_text =~ s/###link###/$script_url?view_event=1&evt_id=$current_event{id}/g; if (($event_time - $rightnow) < $before) { $test_reminder_results = &send_email_reminder(\%current_event, $to_address, $reminder_text); if ($test_reminder_results eq "1") { $results .= "Reminder for event $evt_id ($events{$evt_id}{title}) sent successfully to $to_address!\n"; #$results .= "$reminder_text\n"; } else { $results .= "Reminder not sent to $to_address:

($test_reminder_results)\n"; } } else { $new_lines .= $line; } } open (FH, ">$email_reminders_datafile") || ($debug_info .="\nUnable to open file $email_reminders_datafile for writing!"); flock FH,2; print FH $new_lines; close datafile; $results =~ s/\n/\n/g; $debug_info =~ s/\n/\n/g; print < $results $debug_info p1