|
Server : Apache/2.4.62 System : FreeBSD fbsdweb2.web.rcn.net 14.1-RELEASE FreeBSD 14.1-RELEASE releng/14.1-n267679-10e31f0946d8 GENERIC amd64 User : www ( 80) PHP Version : 8.3.8 Disable Function : NONE Directory : /domains/compasssysweb/calendar/CalciumDir39/upgrades/Operation/ |
Upload File : |
# Copyright 2003, Fred Steinberg, Brown Bear Software
# Display 'thumbnail' calendar, and 1 days worth of events.
package MiniCal;
use strict;
use CGI;
use vars ('@ISA');
@ISA = ('Operation');
sub perform {
my $self = shift;
my $i18n = $self->I18N;
my $calName = $self->calendarName;
my $cgi = CGI->new;
my $refresh = 0; # set to 0 or undef to never refresh
unless (defined $calName) {
print $self->redir ($self->makeURL ({Op => 'Splash'}));
return;
}
# Get colors
my $prefs = $self->prefs;
my %colors = (bg => $prefs->color ('MainPageBG'),
fg => $prefs->color ('MainPageFG'),
link => $prefs->color ('LinkFG'),
vlink => $prefs->color ('VLinkFG'),
dayFG => $prefs->color ('EventFG'),
dayBG => $prefs->color ('EventBG'),
todayFG => $prefs->color ('TodayFG'),
todayBG => $prefs->color ('TodayBG'),
tailBG => $prefs->color ('MonthTailBG'),
tailFG => $prefs->color ('MonthTailFG'),
dowFG => $prefs->color ('WeekHeaderFG'),
dowBG => $prefs->color ('WeekHeaderBG'),
);
$self->{colors} = \%colors;
# Fonts - each is [face, size]
$self->{fonts} = {day => [$prefs->font ('BlockDayDate')],
name => [$prefs->font ('BlockDayOfWeek')],
event => [$prefs->font ('BlockEvent')],
time => [$prefs->font ('BlockEventTime')]};
$self->{fonts}->{day}->[1]--;
$self->{fonts}->{name}->[1]--;
my ($theDate, $theMonth, $theYear, $fullScreen) =
$self->getParams (qw/Date TheMonth TheYear FullScreen/);
$self->clearParams ('IsPopup'); # we don't actually want cookie info
$theDate = Date->new ($theDate); # if undef, it's today
my ($year, $month, $day) = $theDate->ymd;
# params from form above cal
if ($theMonth or $theYear) {
$year = $theYear;
$month = $theMonth;
$theDate = Date->new ($year, $month, $day);
}
my $whichFrame = $self->getParams ('WhichFrame') || 'Main';
if ($whichFrame eq 'Main') {
my $url = $self->makeURL ({Op => $self->opName,
FullScreen => $fullScreen,
Date => $theDate});
print $cgi->header;
print qq {<html><head><title>Calcium - $calName</title></head>};
print qq {<frameset border=0 cols = "225,*">
<frame src="$url&WhichFrame=MiniCalendar"
name="MiniCalendar"/>
<frame src="$url&WhichFrame=MiniEvents"
name="MiniEvents"/>
</frameset>};
print qq {</html>};
return;
}
print $cgi->header ($refresh ? {-Refresh => $refresh} : {});
print $cgi->start_html (-title => "Calcium - $calName",
-bgcolor => $colors{bg},
-text => $colors{fg},
-link => $colors{link});
if ($whichFrame =~ 'Calendar') {
print "<center>$calName</center>";
my $header = $self->monthHeader ($cgi, $theDate);
my $calendar = $self->thumbTable ($cgi, $theDate);
print $header;
print $calendar;
print '<p><center>';
if (!$fullScreen) {
print $cgi->a ({-href => $self->makeURL ({Op => 'ShowIt',
Date => $theDate}),
-target => 'CalciumMain'},
'Display Calendar');
} else {
require Calendar::Javascript;
my $url = $self->makeURL ({Op => $self->opName});
print Javascript->MakePopupFunction ($url, 'MiniCal', 400, 250);
print $cgi->a ({-href => 'Javascript:MiniCalPopup()'},
'Display as a Popup Window');
}
print '</center></p>';
print $cgi->end_html;
return;
}
if ($whichFrame =~ /Events/) {
print $self->dailyEvents ($cgi, $theDate);
print $cgi->end_html;
return;
}
}
sub thumbTable {
my ($self, $cgi, $date) = @_;
my $weekStart = $self->prefs->StartWeekOn || 7;
# Day of week initials
my @tds = map {$cgi->font ({-color => $self->{colors}->{dowFG},
-face => $self->{fonts}->{name}->[0],
-size => $self->{fonts}->{name}->[1]},
$_)}
qw (S M T W T F S);
if ($weekStart != 7) {
foreach (1..$weekStart) {
push @tds, (shift @tds);
}
}
my @trs = $cgi->Tr ({-align => 'center'},
$cgi->td ({-bgcolor => $self->{colors}->{dowBG}},
[@tds]));
# For first week of month, find what day of the week the 1st is, spit
# out some blank cells
my $theDate = $date->firstOfMonth;
my $weekStartDate = $theDate->firstOfWeek ($weekStart);
my $delta = $weekStartDate->deltaDays ($theDate);
@tds = ();
my $tailBG = {-bgcolor => $self->{colors}->{tailBG}};
my $tailFG = { -color => $self->{colors}->{tailFG},
-size => -1};
for (my $i=0; $i<$delta; $i++) {
if ($i == 0) {
my $lastMonth = Date->new ($date)->addMonths (-1);
my $lastURL = $self->makeURL ({Date => $lastMonth,
Op => $self->opName});
push @tds, $cgi->td ($tailBG,
$cgi->a ({-href => $lastURL,
-target => '_top'},
$cgi->font ($tailFG, '<')));
} else {
push @tds, $cgi->td ($tailBG, $cgi->font ($tailFG, ' '));
}
}
my $today = Date->new;
for (my $i=$delta; $i<7; $i++) {
my $fgcolor = $self->{colors}->{dayFG};
my $bgcolor = $self->{colors}->{dayBG};
if ($theDate == $today) {
$fgcolor = $self->{colors}->{todayFG};
$bgcolor = $self->{colors}->{todayBG};
}
my $url = $self->makeURL ({Date => $theDate,
WhichFrame => 'MiniEvents',
Op => $self->opName});
push @tds, $cgi->td ({-bgcolor => $bgcolor},
$cgi->a ({-href => $url,
-target => 'MiniEvents'},
$cgi->font ({-color => $fgcolor,
-face =>
$self->{fonts}->{day}->[0],
-size =>
$self->{fonts}->{day}->[1]},
$theDate->day)));
$theDate++;
}
push @trs, $cgi->Tr ({-align => 'center'}, @tds);
# And remaining weeks
my $daysInMonth = $theDate->daysInMonth;
@tds = ();
my $day = $theDate->day;
while ($day++ <= $daysInMonth) {
if ($theDate->dayOfWeek == $weekStart) {
push @trs, $cgi->Tr ({-align => 'center'}, @tds) if @tds;
@tds = ();
}
my $fgcolor = $self->{colors}->{dayFG};
my $bgcolor = $self->{colors}->{dayBG};
if ($theDate == $today) {
$fgcolor = $self->{colors}->{todayFG};
$bgcolor = $self->{colors}->{todayBG};
}
my $url = $self->makeURL ({Date => $theDate,
WhichFrame => 'MiniEvents',
Op => $self->opName});
push @tds, $cgi->td ({-bgcolor => $bgcolor},
$cgi->a ({-href => $url,
-target => 'MiniEvents'},
$cgi->font ({-color => $fgcolor,
-face =>
$self->{fonts}->{day}->[0],
-size =>
$self->{fonts}->{day}->[1]},
$theDate->day)));
$theDate++;
}
# And maybe last week
for (my $i=@tds; $i<7; $i++) {
if ($i == 6) {
my $nextMonth = Date->new ($date)->addMonths (1);
my $nextURL = $self->makeURL ({Date => $nextMonth,
Op => $self->opName});
push @tds, $cgi->td ($tailBG,
$cgi->a ({-href => $nextURL,
-target => '_top'},
$cgi->font ($tailFG, '>')));
} else {
push @tds, $cgi->td ($tailBG, $cgi->font ($tailFG, ' '));
}
}
push @trs, $cgi->Tr ({-align => 'center'}, @tds) if @tds;
my $html = $cgi->table ({-border => 0,
-align => 'center',
-cellpadding => 2,
-cellspacing => 1,
-bgcolor => '#336699'},
@trs);
# $html = $cgi->table ({-border => 1, -align => 'center'}, $cgi->Tr ($cgi->td ($html)));
return $html;
}
sub monthHeader {
my ($self, $cgi, $date) = @_;
my $onChangeJS = "document.forms[0].submit()";
my $html = $cgi->start_form;
my %monthNames = (1 => 'January',
2 => 'February',
3 => 'March',
4 => 'April',
5 => 'May',
6 => 'June',
7 => 'July',
8 => 'August',
9 => 'September',
10 => 'October',
11 => 'November',
12 => 'December');
$html .= '<center>';
$html .= $cgi->popup_menu (-name => 'TheMonth',
-values => [1..12],
-default => $date->month,
-onchange => $onChangeJS,
-labels => \%monthNames);
my $thisYear = $date->year;
$html .= $cgi->popup_menu (-name => 'TheYear',
-values => [map {$thisYear + $_} -2..2],
-onchange => $onChangeJS,
-default => $thisYear);
$html .= $cgi->hidden (-name => 'Op', -value => $self->opName);
$html .= $cgi->hidden (-name => 'CalendarName',
-value => $self->calendarName);
$html .= $cgi->hidden (-name => 'WhichFrame', -value => 'MiniCalendar');
$html .= $cgi->end_form;
$html .= '</center>';
return $html;
}
# Display list of events for the specified day
sub dailyEvents {
my ($self, $cgi, $date) = @_;
my @events = $self->db->getApplicableEvents ($date, $self->prefs);
my $html = '<center>' . $date->pretty ($self->I18N) .
'</center>';
@events = Event->sort (\@events, $self->prefs->EventSorting);
if (@events) {
my $face = $self->{fonts}->{event}->[0];
my $timeFace = $self->{fonts}->{time}->[0];
require Calendar::Javascript;
$html .= Javascript->PopupWindow ($self);
$html .= '<ul>';
foreach (@events) {
my $x = $_->getHTML ({op => $self,
calName => $self->calendarName,
date => $date,
prefs => $self->prefs,
i18n => $self->I18N,
eventFace => $face,
timeFace => $timeFace,
timeSize => -1});
# kludge to make links come up in new window
if ($_->link) {
$x =~ s/<a /<a target="_blank" /;
}
$html .= "<li>$x</li>";
}
# $html .= '<ul>' . join "\n",
# map {'<li>' .
# $_->getHTML ($self->calendarName, $date, $self->prefs,
# $self->I18N, undef, $face, undef,
# $timeFace, -1)
# . '</li>'} @events;
$html .= '</ul>';
} else {
$html .= '<center><p><i>no events</i></p></center>';
}
return $html;
}
# just use default auditing
#sub auditString {
#}
1;