|
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/Calendar/ |
Upload File : |
# Copyright 1999-2003 Fred Steinberg, Brown Bear Software
# The NavigationBar is a string of http links. It comes in two styles:
# - Last Year, Jan, Feb, ..., Dec., Next Year
# or
# - <Year, <Month, <2 Weeks, <Week, Today, Week>, 2 Weeks>, Month>, Year>
#
# We call the first "absolute", the second "relative"
package NavigationBar;
use strict;
use CGI qw(:standard *table);
use Calendar::Date;
# Pass an operation obj and a date.
sub new {
my $class = shift;
my $self = {};
bless $self, $class;
my ($operation, $date, $location) = @_;
my ($amount, $style, $type) = $operation->ParseDisplaySpecs;
return if ($style =~ /neither/i);
my $prefs = $operation->prefs;
my $i18n = $operation->I18N;
return unless ($prefs->NavBarSite eq 'both' or
$prefs->NavBarSite eq $location);
my $hrefBase = $operation->makeURL ({Op => 'ShowIt',
Date => undef});
my $both = ($style =~ /both/i) ? 1 : 0;
my (@monthNames, @linkNames, @hrefs,
@absLinkNames, @absHrefs, @relLinkNames, @relHrefs);
@monthNames = map { $i18n->get (Date->monthName ($_, 'abbrev')) } (1..12);
# For Absolute, start with last year, stick on the months, add next year
if ($style =~ /absolute|both/i) {
if ($amount =~ /Day/i) {
my $startOn = $prefs->StartWeekOn || 7;
my $weekStart = $date->firstOfWeek ($startOn);
my $lastWeek = (Date->new ($date))->addWeeks (-1);
my $nextWeek = (Date->new ($date))->addWeeks (1);
my @dayNames = map {$i18n->get (Date->dayName ($_))} (1..7);
if ($startOn != 1) {
unshift @dayNames, pop @dayNames;
}
my $week = $i18n->get ('Week');
@linkNames = ("< $week", @dayNames, "$week >");
push @hrefs, $lastWeek;
for (my $i=0; $i<7; $i++) {
push @hrefs, $weekStart + $i;
}
push @hrefs, $nextWeek;
@absLinkNames = @linkNames;
@absHrefs = @hrefs;
}
elsif ($amount =~ /Week/i) {
for (my $i=-4; $i<=4; $i++) {
my $d = Date->new ($date)->addWeeks ($i);
push @hrefs, $i ? $d : undef;
push @absLinkNames, $d->pretty ($i18n, 'abbrev');
}
@absHrefs = @hrefs;
}
elsif ($amount =~ /Quarter/i) {
my $lastYear = (Date->new($date))->addYears(-1);
my $nextYear = (Date->new($date))->addYears(1);
my @qnames = map {$i18n->get ("$_ Quarter")}
qw /First Second Third Fourth/;
@linkNames = ($lastYear->year, @qnames, $nextYear->year);
push @hrefs, $lastYear;
for (my $i=1; $i<=4; $i++) {
push @hrefs, $date->startOfQuarter ($i);
}
push @hrefs, $nextYear;
@absLinkNames = @linkNames;
@absHrefs = @hrefs;
}
elsif ($amount =~ /FPeriod/i) {
my $lastYear = (Date->new($date))->addYears(-1);
my $nextYear = (Date->new($date))->addYears(1);
my @pnames = map {substr ($i18n->get ("Period"), 0, 1) . $_}
1..12;
@linkNames = ($lastYear->year, @pnames, $nextYear->year);
push @hrefs, $lastYear;
for (my $q=1; $q<=4; $q++) {
my $quart = $date->startOfQuarter ($q);
for (my $p=1; $p<=3; $p++) {
push @hrefs, $quart->startOfPeriod ($p);
}
}
push @hrefs, $nextYear;
@absLinkNames = @linkNames;
@absHrefs = @hrefs;
}
elsif ($amount !~ /Year/i) {
my ($lastYear, $nextYear);
$lastYear = (Date->new($date))->addYears(-1);
$nextYear = (Date->new($date))->addYears(1);
@linkNames = ($lastYear->year, @monthNames, $nextYear->year);
push @hrefs, $lastYear;
for (my $i=1; $i<=12; $i++) {
push @hrefs, Date->new ($date->year . "/$i/1");
}
push @hrefs, $nextYear;
@absLinkNames = @linkNames;
@absHrefs = @hrefs;
} else {
@absLinkNames = (($date->year - 5)..($date->year + 5));
foreach (@absLinkNames) {
push @absHrefs, $_ . "/1/1";
}
}
}
if ($style =~ /relative|both/i) {
my $year18 = $i18n->get ('Year');
my $years18 = $i18n->get ('Years');
my $week18 = $i18n->get ('Week');
my $weeks18 = $i18n->get ('Weeks');
my $month18 = $i18n->get ('Month');
my $q18 = $i18n->get ('Quarter');
my $qs18 = $i18n->get ('Quarters');
my $p18 = $i18n->get ('Period');
my $ps18 = $i18n->get ('Periods');
if ($amount =~ /Day/i) {
my $days = $i18n->get ('Days');
my $day = $i18n->get ('Day');
@linkNames = ("< $week18", "< 3 $days", "< 2 $days",
"< 1 $day",
$i18n->get ('Today'),
"1 $day >",
"2 $days >", "3 $days >", "$week18 >");
@hrefs = ($date - 7, $date - 3, $date - 2, $date - 1, $date->new,
$date + 1, $date + 2, $date + 3, $date + 7);
@relLinkNames = @linkNames;
@relHrefs = @hrefs;
}
elsif ($amount =~ /Quarter/i) {
@linkNames = ("< $year18", "< 3 $qs18", "< 2 $qs18",
"< $q18", $i18n->get('Today'), "$q18 >",
"2 $qs18 >", "3 $qs18 >", "$year18 >");
my $lastYear = $date->new ($date)->addYears (-1);
my $nextYear = $date->new ($date)->addYears (1);
my %qs;
# if ($date->isa ('Date::Fiscal')) {
foreach (-3..3) {
$qs{$_} = $date->new ($date)->addQuarters ($_);
}
# } else {
# }
@hrefs =($lastYear, $qs{-3}, $qs{-2}, $qs{-1},
Date->new(),
$qs{1}, $qs{2}, $qs{3},, $nextYear);
@relLinkNames = @linkNames;
@relHrefs = @hrefs;
}
elsif ($amount =~ /FPeriod/i) {
@linkNames = ("< $year18", "< $q18", "< 2 $ps18",
"< $p18", $i18n->get('Today'), "$p18 >",
"2 $ps18 >", "$q18 >", "$year18 >");
my $lastYear = ($date->new ($date))->addYears(-1);
my $nextYear = ($date->new ($date))->addYears(1);
my $lastq = $date->addPeriods (-3);
my $nextq = $date->addPeriods (3);
my $lastp2 = $date->addPeriods (-2);
my $lastp = $date->addPeriods (-1);
my $nextp = $date->addPeriods (1);
my $nextp2 = $date->addPeriods (2);
@hrefs =($lastYear, $lastq, $lastp2, $lastp,
Date->new(),
$nextp, $nextp2, $nextq, $nextYear);
@relLinkNames = @linkNames;
@relHrefs = @hrefs;
}
elsif ($amount !~ /Year/i) {
@linkNames = ("< $year18", "< $month18", "< 2 $weeks18",
"< $week18", $i18n->get('Today'), "$week18 >",
"2 $weeks18 >", "$month18 >", "$year18 >");
my ($lastYear, $lastMonth, $nextMonth, $nextYear);
$lastYear = ($date->new($date))->addYears(-1);
$lastMonth = ($date->new($date))->addMonths(-1);
$nextYear = ($date->new($date))->addYears(1);
$nextMonth = ($date->new($date))->addMonths(1);
@hrefs =($lastYear, $lastMonth, $date - 14, $date - 7,
Date->new(),
$date + 7, $date + 14, $nextMonth, $nextYear);
@relLinkNames = @linkNames;
@relHrefs = @hrefs;
} else {
my (@offsets) = (-10, -5, -1, 1, 5, 10);
@relLinkNames = ("< 10 $years18", "< 5 $years18",
"< 1 $year18",
$i18n->get ('This Year'),
"1 $year18 >", "5 $years18 >",
"10 $years18 >");
foreach (@offsets) {
push @relHrefs, Date->new($date)->addYears ($_);
}
splice @relHrefs, 3, 0, Date->new;
}
}
my ($navFace, $navSize) = $prefs->font ('NavLabel');
my ($relFace, $relSize) = $prefs->font ('NavRel');
my ($absFace, $absSize) = $prefs->font ('NavAbs');
my $navBG = $prefs->color ('NavLabelBG') || '';
my $navFG = $prefs->color ('NavLabelFG') || '';
my $linkBG = $prefs->color ('NavLinkBG') || '';
my $linkFG = $prefs->color ('NavLinkFG') || '';
my (@absTds, @relTds, $absTable, $relTable);
my ($tdParams) = {bgcolor => $linkBG, align => "center"};
foreach (@absLinkNames) {
my $startDate = (shift @absHrefs);
my $text = font ({-face => $absFace,
-size => $absSize,
-color => $linkFG},
$_);
if ($startDate) {
$startDate =~ s|/|%2F|g;
push @absTds, a ({href => "$hrefBase&Date=$startDate"}, $text);
} else {
push @absTds, "<b>$text</b>";
}
}
foreach (@relLinkNames) {
my $startDate = (shift @relHrefs);
$startDate =~ s|/|%2F|g;
push @relTds, a ({href => "$hrefBase&Date=$startDate"},
font ({-face => $relFace,
-size => $relSize,
color => $linkFG},
$_));
}
my $tableParams = {-width => '100%', -border => 0};
$absTable = table ($tableParams, Tr (td ($tdParams, \@absTds)));
$relTable = table ($tableParams, Tr (td ($tdParams, \@relTds)));
# ----
my @rows;
if ($both) {
push @rows, (Tr (td ($absTable)), Tr (td ($relTable)));
} else {
push @rows, Tr (td ($absTable)) if ($style =~ /absolute/i);
push @rows, Tr (td ($relTable)) if ($style =~ /relative/i);
}
# If a Day, put 1..31 links in, to boot.
if ($amount =~ /day/i) {
my $lastMonth = $date->firstOfMonth->addMonths(-1);
my $nextMonth = $date->firstOfMonth->addMonths(1);
my ($y, $m) = ($date->year, $date->month);
my $fnParams = {-color => $linkFG, -size => -1};
my @links = map {a ({-href => "$hrefBase&Date=$y%2F$m%2F$_"},
font ($fnParams, $_)) . ' '}
(1..$date->daysInMonth);
$links[$date->day - 1] = font ({-color => $linkFG}, b ($date->day));
my ($lastEscaped, $nextEscaped) = ("$lastMonth", "$nextMonth");
foreach ($lastEscaped, $nextEscaped) {
s|/|%2F|g;
}
my $tab = table ({-width => '100%',
-cellspacing => 0,
-border => 0},
Tr ({-bgcolor => $linkBG},
td (' ' .
a ({-href => "$hrefBase&Date=$lastEscaped"},
font ($fnParams,
$i18n->get ($lastMonth->monthName(1))))),
map {td ($_)} @links,
td (a ({-href => "$hrefBase&Date=$nextEscaped"},
font ($fnParams,
$i18n->get ($nextMonth->monthName (1))
)))));
push @rows, Tr (td ($tab));
}
my $navTable = table ({-width => '100%',
-cellspacing => 0}, @rows);
my $rowCount = @rows + 0;
$self->{html} = table ({-width => '100%',
-border => 0,
-cellspacing => 0,
-bgcolor => $navBG},
Tr (td ({-rowspan => $rowCount,
-align => 'center'},
font ({-color => $navFG,
-face => $navFace,
-size => $navSize},
b ($i18n->get('Navigate:')))),
td ($navTable)));
# ----
$self;
}
sub getHTML {
my $self = shift;
$self->{'html'};
}
1;