#!/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
# The "use Cwd" method would be nice, but it doesn't work with
# some versions of IIS/ActivePerl
#use Cwd;
#$path = cwd;
if ($path ne "") {
chdir $path;
push @INC,$path;
}
# finished discovering name
#use Data::Dumper;
# some global variables (more further down)
local $plans_version = "7.9.3"; # version
local $debug_info;
local %options;
local $perl_version = (sprintf ("%vd",$^V));
#local $options{data_storage_mode};
local $fatal_error = 0; # fatal errors cause plans to abort and print an error message to the browser
local $error_info = "";
local $html_output;
local $script_url = "";
local $messages = ""; # formatted in plain text with newlines. Converted to html at display time.
local $template_html;
local $local_template_file = 0; # tells whether the template was loaded via a filesystem open or through a http request.
local $event_details_template;
local $list_item_template;
local $calendar_item_template;
local $upcoming_item_template;
local %calendars;
local %current_calendar;
local %latest_calendar;
local %new_calendars;
local $normalized_timezone = 0;
local $normalized_timezone_pending_events = 0;
# used when adding new entries
local $max_cal_id = 0;
local $max_event_id = 0;
local $max_series_id = 0;
local $max_user_id = 0;
local $max_action_id = 0;
# used to protect against refreshes
local $latest_cal_id = 0;
local $latest_event_id = 0;
local $latest_new_cal_id = 0;
local $latest_new_event_id = 0;
local $session;
local %users;
my $profile;
local $logged_in = 0;
local $logged_in_as_root = 0;
local $logged_in_as_current_cal_user = 0;
local $logged_in_as_current_cal_admin = 0;
local $lg_name = "";
local $lg_password = "";
local %events;
local %new_events;
local @pending_events_to_display;
local %text;
local %cookie_parms;
local $cookie_text = "";
local $cookie_header_text = "";
local $max_remote_event_id = 0;
local $options{default_template_path} = "";
local $theme_url = "";
local $options{choose_themes} = "";
local $graphics_url = "";
local $icons_url = "";
local $input_cal_id_valid = 0;
local $options{right_click_menus_enabled} = 0;
local %cal_options;
local $rightnow;
local @months;
local @months_abv;
local @day_names;
local $loaded_all_events; # flag used to avoid calling load_events("all") twice
# not needed for calendars (we always load all calendars)
local @disabled_tabs;
# check for required modules.
my $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 (-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/Session") {
$module_found=1;}
}
if ($options{sessions} eq "1") {
if ($module_found == 0) {
$fatal_error = 1;
$error_info .= "unable to locate required module CGI::Session!\n";
} else {
require CGI::Session;}
}
$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 (-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";}
# multi-language stuff
if (defined $options{language_files}) {
my @language_files = split(',', $options{language_files});
# pull in language files
foreach $language_file (@language_files) {
$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;}
}
# create a javascript file with language strings
open (FH, "$options{default_theme_path}/$options{js_language_file}") || {$debug_info.= "unable to open file $options{default_theme_path}/$options{js_language_file}\n"};
flock FH,2;
my $first_lang_line=;
close FH;
if ($options{generate_js_lang} eq "1" || $first_lang_line !~ /$plans_version/) {
my $lang_string = "";
$lang_string .= "//$plans_version\n";
$lang_string .= "var plans_lang = new Array();\n";
# generate %lang keys
foreach $lang_key (keys %lang) {
if (ref $lang{$lang_key} eq "ARRAY") {
$lang_string .= "plans_lang['$lang_key']=new Array(";
my $first = 1;
foreach $key (@{$lang{$lang_key}}) {
if (!$first) {$lang_string .= ',';}
if ($first) {$first = 0;}
my $lang_val = &js_string($key);
$lang_string .= "'$lang_val'";
}
$lang_string .= ");\n";
} else {
my $lang_val = &js_string($lang{$lang_key});
$lang_string .= "plans_lang['$lang_key']='$lang_val';\n"
}
}
open (FH, ">$options{default_theme_path}/$options{js_language_file}") || {$debug_info .= "unable to open file $options{default_theme_path}/$options{js_language_file} for writing!\n"};
flock FH,2;
print FH $lang_string;
close FH;
}
} else {
$fatal_error=1;
$error_info .= "No language files defined in plans.config!\n";
}
# check for perl version
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 ($fatal_error == 1) { # print error and bail out
&fatal_error();
}
# init cgi stuff
$q = new CGI;
if ($options{calendar_url} ne "") {
$script_url = $options{calendar_url};
} else {
$script_url = $q->url(-path_info>=1);
}
$script_url =~ /(.*)\//; # remove trailing / and all text after
$script_url = $1; # remove trailing / and all text after
%cookie_parms = %{&extract_cookie_parms()};
# check if data files or tables are present
&check_data();
# fatal error? Print error and bail out
if ($fatal_error == 1) {
&fatal_error();}
if ($theme_url eq "") { # not defined in config file
$theme_url = "$script_url/theme";
}
if ($options{choose_themes}) {
$chosen_url = $q->param('theme_url');
$chosen_url = $cookie_parms{'theme_url'} if ($chosen_url eq "");
$theme_url = $chosen_url if ($chosen_url ne "");
}
$graphics_url ="$theme_url/graphics"; # where misc. graphics are
$icons_url = "$theme_url/icons"; # where icons are
$css_path = "$theme_url/plans.css"; # css file
# globals from http parameters
my $active_tab = $q->param('active_tab') + 0; # +0 ensures numericity
$active_tab = 0 if ($active_tab > scalar @{$lang{tab_text}} - 1);
my $api_output_format = $q->param('output_format');
my $api_command = $q->param('api_command');
my $add_edit_cal_action = $q->param('add_edit_cal_action');
$add_edit_cal_action = "" if (!&contains(["add", "edit", "view_pending"],$add_edit_cal_action)); # validate
my $add_edit_event = $q->param('add_edit_event');
$add_edit_event = "" if (!&contains(["add", "edit"],$add_edit_event)); # validate
local $current_event_id = $q->param('evt_id');
$current_event_id = "" if ($current_event_id !~ /^R?\d+$/); # validate
local $pending_event_id = $q->param('pending_event_id');
$pending_event_id = "" if ($pending_event_id !~ /^R?\d+$/); # validate
local $cal_start_month = $q->param('cal_start_month') + 0; # +0 ensures numericity
local $cal_start_year = $q->param('cal_start_year') + 0; # +0 ensures numericity
local $cal_num_months = $q->param('cal_num_months') + 0; # +0 ensures numericity
# if view parameters not supplied in http request, check cookie
$cal_start_month = $cookie_parms{'cal_start_month'} if ($q->param('cal_start_month') eq "");
$cal_start_year = $cookie_parms{'cal_start_year'} if ($cal_start_year == 0);
$cal_num_months = $cookie_parms{'cal_num_months'} if ($cal_num_months == 0);
my $special_action = $q->param('special_action'); # needs no validation - never used in output
local $display_type = $q->param('display_type') + 0; # +0 ensures numericity
$display_type = $cookie_parms{'display_type'} if ($q->param('display_type') eq "");
$messages = $q->param('messages') if ($q->param('messages') ne "");
# other globals
my $event_start_date;
my $event_start_timestamp;
my $event_days;
my $start_mday;
my $start_mon;
my $start_year;
my @timestamp_array;
my $prev_month_link = "";
my $next_month_link = "";
# load calendar data
&load_calendars();
&load_users();
&load_actions();
local $current_cal_id = 0;
if ($q->param('cal_id') eq "") {
$current_cal_id = $cookie_parms{'cal_id'} if ($current_cal_id == 0);
} else {
$current_cal_id = $q->param('cal_id');
}
$current_cal_id += 0; # +0 ensures numericity
# if calendar id not supplied, but evt_id is supplied (like when viewing an event) use that event's calendar as the current calendar
#if ($current_event_id ne "")
#{
# &load_event($current_event_id);
#
# my %temp_current_event = %{$events{$current_event_id}};
# if ($current_cal_id eq "")
# {
# $current_cal_id = $temp_current_event{cal_ids}[0];
# }
#}
foreach $cal_id (keys %calendars) {
if ($cal_id eq $current_cal_id) {
$input_cal_id_valid = 1;}
}
if ($current_cal_id eq "") {
$input_cal_id_valid = 0;}
if ($current_cal_id =~ /\D/) {
$input_cal_id_valid = 0;}
$current_cal_id = 0 if ($current_event_id eq "" && !$input_cal_id_valid);
# make all calendars selectable by default
foreach $cal_id (keys %calendars) {
$default_cal{selectable_calendars}{$cal_id} = 1;}
%current_calendar = %{$calendars{$current_cal_id}};
# time-related globals
$rightnow = time() + 3600 * $current_calendar{gmtime_diff};
@rightnow_array = gmtime $rightnow;
$rightnow_year = $rightnow_array[5]+1900;
$rightnow_month = $rightnow_array[4];
$rightnow_mday = $rightnow_array[3];
$next_year = $rightnow_year+1;
$rightnow_description = formatted_time($rightnow, "hh:mm:ss mn md yy");
@weekday_sequence = @day_names;
# session stuff
if ($options{sessions} eq "1") {
#$lg_name = $q->param('lg_name');
$lg_name = $current_cal_id;
$lg_password = $q->param('cal_password');
&delete_old_sessions(1); # in days
#$debug_info .= "plans_sid (cookie): ".$q->cookie("plans_sid")."\n";
my $current_session_id = $q->cookie("plans_sid") || undef;
$session = new CGI::Session(undef, $current_session_id, {Directory=>$options{sessions_directory}});
$session->expire("+1d");
#$debug_info .= "current_session_id: $current_session_id\n";
# log out?
if ($q->param('logout') eq "1") {
$session->delete();
$cookie_text .= "Set-Cookie; plans_sid=deleted; path=/;\n";
}
# try to match session with user id. (If this fails, it's not really a session.)
my $results = &init_session($q, $session);
$profile = $session->param("~profile");
if (defined $profile->{calendar_permissions}) {
$logged_in = 1;
$cookie_text .= "Set-Cookie: plans_sid=".$session->id."; path=/;\n";
}
}
if ($options{sessions} eq "1") {
$logged_in_as_root = ($profile->{calendar_permissions}->{0}->{admin} eq "1") ? 1:0;
$logged_in_as_current_cal_user = ($profile->{calendar_permissions}->{$current_cal_id}->{user} ne "") ? 1:0;
$logged_in_as_current_cal_admin = ($profile->{calendar_permissions}->{$current_cal_id}->{admin} ne "") ? 1:0;
} elsif ($q->param('cal_password') ne "") {
$logged_in_as_root = ($calendars{0}{password} eq crypt($q->param('cal_password'), $options{salt})) ? 1:0;
$logged_in_as_current_cal_admin = ($current_calendar{password} eq crypt($q->param('cal_password'), $options{salt})) ? 1:0;
foreach $user_id (keys %users) {
my %user = %{$users{$user_id}};
my %user_calendars = %{$user{calendars}};
foreach $user_cal_id (keys %user_calendars) {
if ($user_cal_id eq $current_cal_id && $user{calendars}{$user_cal_id}{edit_events} eq "1" &&
$user{password} eq crypt($q->param('cal_password'), $options{salt})) {
$logged_in_as_current_cal_user = 1;
last;
}
last if ($logged_in_as_current_cal_user == 1);
}
last if ($logged_in_as_current_cal_user == 1);
}
}
$logged_in_as_current_cal_user = 0 if (!$options{users}) ;
#$debug_info .= "init_session results: $results\n";
#$debug_info .= "logged-in: ".$session->param("~logged-in")."\n";
#$debug_info .= "session id: ".$session->id."\n";
#$debug_info .= "profile user_id: ".$profile->{calendar_permissions}->{$current_cal_id}."\n";
#$debug_info .= "options{sessions}: $options{sessions}\n";
#$debug_info .= "logged_in_as_root: $logged_in_as_root\n";
#$debug_info .= "logged_in_as_current_cal_user: $logged_in_as_current_cal_user\n";
#$debug_info .= "logged_in_as_current_cal_admin: $logged_in_as_current_cal_admin\n";
#$debug_info .= "current_calendar{password}: $current_calendar{password}\n";
#$debug_info .= ($profile->{calendar_permissions}->{$current_cal_id}->{admin})."\n";
# custom stylesheet?
if ($current_calendar{custom_stylesheet} ne "") {
$css_path = "http://$current_calendar{custom_stylesheet}";
}
# if this is a custom calendar request, shoehorn the request parameters in
if ($q->param('custom_calendar') eq "1") {
$current_cal_id = $q->param('custom_calendar_calendar') + 0;
@custom_calendar_backgound_calendars = $q->param('custom_calendar_background_calendars');
foreach $local_background_calendar (keys %{$calendars{$current_cal_id}{local_background_calendars}}) {
delete $calendars{$current_cal_id}{local_background_calendars}{$local_background_calendar};}
foreach $local_background_calendar (@custom_calendar_backgound_calendars) {
$calendars{$current_cal_id}{local_background_calendars}{$local_background_calendar} = 1;}
%current_calendar = %{$calendars{$current_cal_id}};
}
# make sure we can select the current calendar
#$current_calendar{selectable_calendars}{$current_cal_id} = 1;
# set info window height & width
$current_calendar{info_window_size} ="400x400" if ($current_calendar{info_window_size} eq ""); # default
my ($info_window_width, $info_window_height) = split("x", $current_calendar{info_window_size});
# rotate weekday_sequence by the offset defined in the week start day.
for ($l1=0;$l1 < $current_calendar{week_start_day};$l1++) {
push @weekday_sequence, (shift @weekday_sequence);}
# load background_colors
my @temp_lines = split ("\n", $event_background_colors);
foreach $temp_line (@temp_lines) {
next if ($temp_line !~ /\w/); # skip any blank lines
$temp_line =~ s/^\s+//;
my ($hex_color, $hex_color_title) = split (/,*\s+/, $temp_line, 2);
$hex_color_title = " " if ($hex_color_title eq "");
push @event_bgcolors, {color => $hex_color, title => $hex_color_title};
}
#evaluate browser type and version
$_ = $ENV{HTTP_USER_AGENT};
if (/Mozilla/) {
if (/Opera.([0-9\.]+)/) { $browser_type = 'Opera'; $browser_version=$1;} elsif (/MSIE.([0-9.]+)/) { $browser_type = 'IE'; $browser_version = $1;} elsif (/Mozilla\/([0-9\.]+)/) {$browser_type = 'Mozilla'; $browser_version=$1;
if (($browser_version<5) || (/Netscape/)) {$browser_type = "Netscape";} }
if (/\)[^0-9.]+[0-9]*[\/\ ]([0-9.]+)/) {$browser_version=$1;}
} elsif (/(\w+)\/([0-9\.]+)/) {$browser_type = $1; $browser_version = $2}
#evaluate, transform, tweak, adjust, modify input values
#$debug_info .= "browser type: $browser_type
";
#if no month is selected, use the current month
if ($cal_start_month eq "" && $q->param('cal_start_month') eq "") {
$cal_start_month = $rightnow_month;
#$cal_start_month = 2;
}
#if the input year is out of range use the current year
if (($cal_start_year+0) < 1902 || ($cal_start_year+0)> 2037) {
$cal_start_year = $rightnow_year;
}
$cal_num_months = $current_calendar{default_number_of_months} if ($cal_num_months < 1);
$cal_num_months = $current_calendar{default_number_of_months} if ($cal_num_months > $current_calendar{max_number_of_months});
$cal_num_months = 1 if ($cal_num_months > $current_calendar{max_number_of_months});
$cal_num_months = 1 if ($cal_num_months == 0);
#calculate calendar end month and year
$cal_end_month = $cal_start_month;
$cal_end_year = $cal_start_year;
for ($l1=1;$l1<$cal_num_months;$l1++) {
$cal_end_month++;
if ($cal_end_month == 12) {
$cal_end_month=0;
$cal_end_year++;
}
}
#check to make sure num_months+cal_start_date doesn't go out of bounds
if ($cal_end_year < 1902 || $cal_end_year> 2037) {
$cal_end_year = $cal_start_year;
$cal_end_month = $cal_start_month;
$cal_num_months = 1;
}
# time window for loading events
my $cal_start_timestamp = timegm(0,0,0,1,$cal_start_month,$cal_start_year) - 2592000;
my $cal_end_timestamp = timegm(0,0,0,1,$cal_end_month,$cal_end_year) + 5184000;
if ($q->param('cal_start_timestamp') ne "" && $q->param('cal_start_timestamp') !~ /\D/) {
$cal_start_timestamp = $q->param('cal_start_timestamp');}
if ($q->param('cal_end_timestamp') ne "" && $q->param('cal_end_timestamp') !~ /\D/) {
$cal_end_timestamp = $q->param('cal_end_timestamp');}
#$debug_info .="start: $cal_start_timestamp\nend: $cal_end_timestamp\nrightnow: $rightnow\n";
# load event data, for main calendar and its background calendars
my @temp_calendars = ($current_cal_id);
foreach $local_background_calendar (keys %{$current_calendar{local_background_calendars}}) {
push @temp_calendars, $local_background_calendar;}
my $initial_load_events = 1;
$initial_load_events = 0 if ($q->param('get_upcoming_events') eq "1");
&load_events($cal_start_timestamp, $cal_end_timestamp, \@temp_calendars) if ($initial_load_events == 1);
if ($current_event_id ne "") {
&load_event($current_event_id);
}
# load events from remote background calendars
if (scalar keys %{$current_calendar{remote_background_calendars}} > 0) {
$remote_calendars_status="";
my $temp = scalar keys %{$current_calendar{remote_background_calendars}};
foreach $remote_calendar_id (keys %{$current_calendar{remote_background_calendars}}) {
# pull in remote calendar name
my $remote_calendar_url = $current_calendar{remote_background_calendars}{$remote_calendar_id}{url};
$remote_calendar_complete_url = $remote_calendar_url;
#$debug_info .= "remote calendar: $remote_calendar_complete_url\n";
$remote_calendar_complete_url .= "?remote_calendar_request=1&cal_id=$current_calendar{remote_background_calendars}{$remote_calendar_id}{remote_id}&cal_start_year=$cal_start_year&cal_start_month=$cal_start_month&num_months=$cal_num_months";
#$debug_info .= "remote calendar url: $remote_calendar_complete_url\n";
my $xml_results = &get_remote_file($remote_calendar_complete_url);
if ($xml_results =~ //) {
$xml_results =~ s/</g;
$xml_results =~ s/>/>/g;
#$debug_info .= "Error fetching remote calendar: $xml_results\n";
} else {
my %remote_calendar = %{&xml2hash($xml_results)};
my $remote_cal_title = $remote_calendar{'xml'}{calendar}{title};
my $remote_cal_gmtime_diff = $remote_calendar{'xml'}{calendar}{gmtime_diff};
#$debug_info .= "remote_cal_gmtime_diff: $remote_cal_gmtime_diff\n";
#my $temp = $xml_results;
#$temp=~ s/>/>/g;
#$temp=~ s/</g;
#$debug_info .= "xml results: $temp\n";
&load_remote_events($xml_results, $remote_calendar_id, $remote_cal_gmtime_diff);
}
}
}
# this should be done after all $current_cal_id is calculated and events are loaded.
&normalize_timezone();
&normalize_timezone_pending_events();
# calculate previous X months range.
my $previous_cal_start_month = $cal_start_month - $cal_num_months;
my $previous_cal_start_year = $cal_start_year;
if ($previous_cal_start_month < 0) {
$previous_cal_start_year = $cal_start_year - 1 - int(abs($cal_num_months - $cal_start_month) / 12);
$previous_cal_start_month = 12 - abs($previous_cal_start_month) % 12;
}
# for the case when num_months = 12 and start_month=0
if ($previous_cal_start_month == 12) {
$previous_cal_start_month=0;
$previous_cal_start_year++;
}
# singular or plural?
if ($cal_num_months > 1) {
$prev_string = $lang{previous_months};
$prev_string =~ s/###num###/$cal_num_months/;
} else {
$prev_string = $lang{previous_month};
}
# calculate next X months range.
my $next_cal_start_month = $cal_start_month + $cal_num_months;
my $next_cal_start_year = $cal_start_year;
if ($next_cal_start_month > 11) {
$next_cal_start_year = $cal_start_year + int(abs($cal_num_months + $cal_start_month) / 12);
$next_cal_start_month = abs($cal_start_month + $cal_num_months) % 12;
}
# singular or plural?
if ($cal_num_months > 1) {
$next_string = $lang{next_months};
$next_string =~ s/###num###/$cal_num_months/;
} else {
$next_string = $lang{next_month};
}
if ($q->param('diagnostic_mode') eq "1") {
my $diagnostic_results = &diagnostic_info;
$html_output = <
Diagnostic mode
Plans Diagnostic information
$diagnostic_results
Debug info:
$debug_info
p1
print $html_output;
exit(0);
}
if ($q->param('detect_remote_calendars') eq "1") {
&detect_remote_calendars();
exit(0);
}
if ($q->param('remote_calendar_request') eq "1") {
&remote_calendar_request();
exit(0);
}
if ($q->param('add_edit_user') eq "1") {
&add_edit_user();
exit(0);
}
if ($q->param('add_new_ical') eq "1") {
&add_new_ical();
exit(0);
}
if ($q->param('js_login') eq "1") {
&js_login();
exit(0);
}
if ($q->param('manage_pending_events') eq "1") {
&manage_pending_events();
exit(0);
}
if ($q->param('export_calendar') eq "1") {
if ($q->param('export_type') eq "ascii_text") {
&ascii_text_cal($cal_start_month, $cal_start_year, $cal_end_month, $cal_end_year);
exit(0);
} elsif ($q->param('export_type') eq "csv_file") {
&csv_file($cal_start_month, $cal_start_year, $cal_end_month, $cal_end_year);
exit(0);
} elsif ($q->param('export_type') eq "csv_file_palm") {
&csv_file_palm($cal_start_month, $cal_start_year, $cal_end_month, $cal_end_year);
exit(0);
} elsif ($q->param('export_type') eq "vcalendar") {
&vcalendar_export_cal($cal_start_month, $cal_start_year, $cal_end_month, $cal_end_year);
exit(0);
} elsif ($q->param('export_type') eq "icalendar") {
&icalendar_export_cal($cal_start_month, $cal_start_year, $cal_end_month, $cal_end_year);
exit(0);
}
}
if ($q->param('export_event') eq "1") {
if ($q->param('export_type') eq "ascii_text") {
&ascii_text_event();
exit(0);
} elsif ($q->param('export_type') eq "icalendar") {
&icalendar_export_event();
exit(0);
} elsif ($q->param('export_type') eq "vcalendar") {
&vcalendar_export_event();
exit(0);
}
} elsif ($q->param('get_upcoming_events') eq "1") {
&get_upcoming_events();
exit(0);
} elsif ($api_command ne "") {
if ($api_command eq "delete_event") {
&api_add_delete_events();
exit(0);
}
} elsif ($q->param('view_event') eq "1") {
&load_templates();
&view_event();
exit(0);
} elsif ($q->param('view_pending_event') eq "1") {
&load_templates();
my %pending_event = %{$new_events{$pending_event_id}};
&view_pending_event(\%pending_event);
exit(0);
} elsif ($q->param('email_reminder') eq "1") {
&load_templates();
&email_reminder_prompt();
exit(0);
} elsif ($q->param('email_reminder_confirm') eq "1") {
&load_templates();
&email_reminder_confirm();
exit(0);
} elsif ($special_action eq "preview_event") {
&load_templates();
&preview_event();
exit(0);
} elsif ($special_action eq "preview_date") {
&load_templates();
&preview_date();
exit(0);
} elsif ($q->param('validate_event') eq "1") {
&validate_event();
exit(0);
}
#load templates
&load_templates();
# ssi-style includes in the template
if ($local_template_file) {
my $new_html = $template_html;
$template_html =~ s/###include\s+(.+)###/&load_file($1)/ge;
#while ($new_html =~ s/###include\s+(.+)###//g)
if(0) {
my $include_file=$1;
if (-e $include_file) {
open (FH, "$include_file") || ($debug_info .="
unable to open include file $include_file for reading
");
flock FH,2;
my @include_lines=;
close FH;
$include_html = join "", @include_lines;
}
$template_html =~ s/###include\s+(.+)###/$include_html/;
}
}
if($options{choose_themes}) {
my $theme_file="choose_theme.html";
my $theme_html="";
if (-e $theme_file) {
open (FH, "$theme_file") || ($debug_info .="
unable to open theme file $theme_file for reading
");
flock FH,2;
my @theme_lines=;
close FH;
$theme_html = join "", @theme_lines;
}
$template_html =~ s/###choose theme###/$theme_html/;
} else {
$template_html =~ s/###choose theme###//;
}
my $view_cookie = &xml_store($cal_start_month, "cal_start_month");
$view_cookie .= &xml_store($cal_start_year, "cal_start_year");
$view_cookie .= &xml_store($cal_num_months, "cal_num_months");
$view_cookie .= &xml_store($current_cal_id, "cal_id");
$view_cookie .= &xml_store($display_type, "display_type");
$cookie_text .= "Set-Cookie: plans_view=$view_cookie; path=/;\n";
$cookie_header_text = $cookie_text;
#$debug_info .= "cookie: $cookie_header_text\n";
$html_output .=<
p1
chomp $insert_text;
$html_output =~ s/###javascript stuff###/$insert_text/;
# sneak in the color select javascript before all other javascript.
my $temp =<
p1
$html_output =~ s/(