%
require "SimpleDateFormat.pm";
$screenTitle="Schedule Event";
$config = $main::Config;
unless ($event) {
$event_id = $main::in{'EVENT_id'};
$db_events = new DBFile($main::events_db);
$event = $db_events->getRecord( {'event_id'=>$event_id} );
}
$db_schedule = new DBFile($main::schedule_db);
$schedule = $db_schedule->getRecord( {'event_id'=>$event->{'id'}} );
$_static_dates_range = "dates";
if ($schedule) {
#foreach $key (sort keys %$schedule) { print "$key = $schedule->{$key}
\n"; }
if ($schedule->{'recurrence_type'} eq "") {
my (@dates);
my ($occurences) = $db_schedule->getRecords( {'event_id'=>$event->{'id'}} );
if ($#{$occurences} > 0) {
# More than one occurrence
foreach $occurence (@$occurences) {
push(@dates,&SimpleDateFormat::formatDate($occurence->{'start'},$config->get("date_format")));
}
$_static_dates_range = "dates";
$_static_dates = join(",",@dates);
}
else {
# Only one!
if ($schedule->{'start'} == $schedule->{'end'}) {
$_static_dates_range = "dates";
$_static_dates = &SimpleDateFormat::formatDate($schedule->{'start'},$config->get("date_format"));
}
else {
$_static_dates_range = "range";
$_static_start_date = &SimpleDateFormat::formatDate($schedule->{'start'},$config->get("date_format"));
$_static_end_date = &SimpleDateFormat::formatDate($schedule->{'end'},$config->get("date_format"));
}
}
}
}
if (!$schedule) {
$schedule = {};
}
else {
if ($schedule->{'all_day'}) {
$_all_day = "CHECKED";
$schedule->{'start_time'} = "";
$schedule->{'end_time'} = "";
}
}
$time_format = $config->get("time_format");
$week_start_day = $config->get("week_start_day");
if ($main::in{'SCHEDULE_type'} eq "recurring") { # Coming from Recurring screen
$_start_hh = $main::in{'SCHEDULE_start_time_hh'};
$_start_mm = $main::in{'SCHEDULE_start_time_mm'};
if($main::in{'SCHEDULE_start_time_ampm'} eq "am") { $_start_am="SELECTED"; }
if($main::in{'SCHEDULE_start_time_ampm'} eq "pm") { $_start_pm="SELECTED"; }
$_end_hh = $main::in{'SCHEDULE_end_time_hh'};
$_end_mm = $main::in{'SCHEDULE_end_time_mm'};
if($main::in{'SCHEDULE_end_time_ampm'} eq "am") { $_end_am="SELECTED"; }
if($main::in{'SCHEDULE_end_time_ampm'} eq "pm") { $_end_pm="SELECTED"; }
if ($main::in{'SCHEDULE_all_day'}) { $_all_day="CHECKED"; }
}
else { # Coming from Add/Edit screen
($_start_hh,$_start_mm) = ($schedule->{'start_time'} =~ /(\d\d)(\d\d)/);
($_end_hh,$_end_mm) = ($schedule->{'end_time'} =~ /(\d\d)(\d\d)/);
if ($time_format eq "12") {
if ($_start_hh eq "00") { $_start_hh = "12"; $_start_am="SELECTED"; }
elsif ($_start_hh > 12) { $_start_hh -= 12; $_start_pm="SELECTED"; }
elsif ($_start_hh == 12) { $_start_pm="SELECTED"; }
else { $_start_am="SELECTED"; }
if ($_end_hh eq "00") { $_end_hh = "12"; $_start_am="SELECTED"; }
elsif ($_end_hh > 12) { $_end_hh -= 12; $_end_pm="SELECTED"; }
elsif ($_end_hh == 12) { $_end_pm="SELECTED"; }
else { $_end_am="SELECTED"; }
}
}
$monthnames = $config->get("month_names");
$daynames = $config->get("day_names");
$dayabbreviations = $config->get("day_abbreviations");
%>