KGRKJGETMRETU895U-589TY5MIGM5JGB5SDFESFREWTGR54TY
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/Calendar/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /domains/compasssysweb/calendar/CalciumDir39/upgrades/Calendar/BottomBars.pm
# Copyright 1999-2003, Fred Steinberg, Brown Bear Software

# This guy is for the selection bars at the bottom of the screen

package BottomBars;
use strict;
use CGI (':standard');
use Calendar::Defines;
use Calendar::Javascript;

# Pass op, date
sub new {
    my $class = shift;
    my $self = {};
    bless $self, $class;
    my ($operation, $date) = @_;

    my ($amount, $navType, $type) = $operation->ParseDisplaySpecs;
    my ($displayTable, $navTable, $calTable, $optsTable, $baseHref, $href);

    my $prefs    = $operation->prefs;
    my $username = $operation->getUsername;

    # See which menus, if any, we want
    my $whichMenus = $prefs->BottomBars || '';
    return unless ($whichMenus or $username);

    my $i18n = $operation->I18N;

    my ($face, $size) = $prefs->font ('BottomBars');

    # OK, make the Display, Navigation, and Calendar menus

    my (%theHash, @order);

    # Display menu
    if ($whichMenus =~ /display/i) {
        my @amountValues = qw /Day Week Month Quarter Year/;

        my $showFiscal = $prefs->MenuItemFiscal || 'always';
        if ($showFiscal !~ /never/i) {
            push @amountValues, qw /FPeriod FQuarter FYear/;
        }

        # if currently in planner view, only allow Day and Week
        if ($type =~ /planner/i) {
            @amountValues = qw /Week Day/;
        } elsif ($type =~ /timeplan/i) { # time plan only up to month
            @amountValues = qw /Day Week Month/;
        }

        my @typeValues = qw /Block List Condensed TimePlan/;
        # if any included cals, maybe add planner view
        if ($prefs->getIncludedCalendarNames) {
            my $showPlanner = $prefs->MenuItemPlanner || 'always';
            if ($showPlanner !~ /never/i
                and $showPlanner =~ /always/i
                or ($showPlanner =~ /add/i and
                    $operation->permission->permitted ($username, 'Add'))
                or ($showPlanner =~ /admin/i and
                    $operation->permission->permitted ($username, 'Admin'))) {
                push @typeValues, 'Planner';
            }
        }

        my $bg = $prefs->color ('BottomBarBG') || '';
        my $fg = $prefs->color ('BottomBarFG') || '';

        if (0) {    # OLD STYLE; no popups, just links
            my %theHash;
            my $baseHref = $operation->makeURL ({Op      => 'ShowIt',
                                                 Date    => $date,
                                                 Amount  => undef,
                                                 Type    => undef,
                                                 NavType => $navType});
            foreach (@amountValues) {
                $theHash{$_} = $baseHref . "&Amount=$_&Type=$type";
            }
            foreach (@typeValues) {
                $theHash{$_} = $baseHref . "&Amount=$amount&Type=$_";
            }
            $theHash{' '} = undef;

            my @order = (@amountValues, ' ', @typeValues);

            $displayTable = $self->_bottomBarTable (\@order,
                                                    \%theHash,
                                                    $i18n,
                                                    $prefs, $size, $face,
                                                    ($amount, $type));
        } else {                # popup menu version
            # Be careful w/quoting; older versions of CGI.pm don't autoescape
            # in forms, so "BBDisplay" won't work.
            my $onChangeJS = "document.forms['BBDisplay'].submit()";

            my %amountLabels = (Year     => $i18n->get ('Year'),
                                Quarter  => $i18n->get ('Quarter'),
                                Month    => $i18n->get ('Month'),
                                Week     => $i18n->get ('Week'),
                                Day      => $i18n->get ('Day'),
                                FYear    => $i18n->get ('Fiscal Year'),
                                FQuarter => $i18n->get ('Fiscal Quarter'),
                                FPeriod  => $i18n->get ('Fiscal Period'));

            my $amt = popup_menu (-name     => 'Amount',
                                  -override => 1,
                                  -default  => $amount,
                                  -style    => "color: $fg; " .
                                               "background-color: $bg",
                                  -onchange => $onChangeJS,
                                  -values   => \@amountValues,
                                  -labels   => \%amountLabels);
            my %typeLabels = (Block     => $i18n->get ('Block'),
                              List      => $i18n->get ('List'),
                              Condensed => $i18n->get ('Condensed'),
                              TimePlan  => $i18n->get ('Time Plan'),
                              Planner   => $i18n->get ('Planner'));
            my $typ = popup_menu (-name     => 'Type',
                                  -override => 1,
                                  -default  => $type,
                                  -style    => "color: $fg; " .
                                               "background-color: $bg",
                                  -onchange => $onChangeJS,
                                  -values   => \@typeValues,
                                  -labels   => \%typeLabels);

            my $goButton = '<noscript>' . submit (-name => 'Go') .
                           '</noscript>';
            $displayTable  = startform (-name => 'BBDisplay');
            $displayTable .= table (Tr (td ($amt), td ($typ), td ($goButton)));
            $displayTable .= hidden (-name  => 'CalendarName',
                                     -value => $operation->calendarName);
            delete $operation->{params}->{CookieParams};
            delete $operation->{params}->{IsPopup};
            $displayTable .= $operation->hiddenDisplaySpecs;
            $displayTable .= endform;
        }
    }

    # Navigation Bar menu (but don't display if no nav bar displayed)
    if ($whichMenus =~ /navbar/i and $prefs->NavBarSite !~ /neither/i) {
        $baseHref = $operation->makeURL ({Op      => 'ShowIt',
                                          CookieParams => undef,
                                          IsPopup      => undef,
                                          Date    => $date,
                                          Amount  => $amount,
                                          NavType => undef,
                                          Type    => $type});
        %theHash = ('Absolute' => $baseHref . "&NavType=Absolute",
                    'Relative' => $baseHref . "&NavType=Relative",
                    'Both'     => $baseHref . "&NavType=Both",
                    'Neither'  => $baseHref . "&NavType=Neither");
        @order = (qw (Absolute Relative Both Neither));
        $navTable = $self->_bottomBarTable (\@order, \%theHash, $i18n, $prefs,
                                            $size, $face, ($navType));
    }

    # Calendar menu
    if ($whichMenus =~ /cal/i) {
#         $self->{'html'}  = Javascript->SearchCalendar ($operation);
#         $self->{'html'} .= Javascript->TextFilter     ($operation);
#         $self->{'html'} .= Javascript->EventFilter    ($operation);

        $self->{html} .= Javascript->MakePopupFunction
                            ($operation->makeURL ({Op => 'AdminPageUser'}),
                             'UserOptions', 500, 450);
        $self->{html} .= Javascript->MakePopupFunction
                            ($operation->makeURL ({Op => 'PrintView'}),
                             'Print', 500, 450);

        my $miniName = 'MiniCal_' . $operation->calendarName;
        $self->{html} .= Javascript->MakePopupFunction
                            ($operation->makeURL ({Op => 'MiniCal'}),
                             $miniName, 400, 250);

        my $showDay = $operation->makeURL ({Op => 'ShowDay',
                                            Date => $date});

        %theHash = (#'Search'       => 'JavaScript:SearchCalendar()',
                    #'Text Filter'  => 'JavaScript:TextFilter()',
                    #'Event Filter' => 'JavaScript:EventFilter()',
                    'Print' => $operation->makeURL ({Op => 'PrintView'}),

                    'Approve Events' =>
                                $operation->makeURL ({Op => 'ApproveEvents'}),
                    'Settings'   => $operation->makeURL ({Op => 'AdminPage'}),
                    'Options'    => $operation->makeURL ({Op =>
                                                          'AdminPageUser'}),
                    'MiniCal'    => $operation->makeURL ({Op => 'MiniCal'}),
                    'Add'        => $showDay,
                    'Add/Edit'   => $showDay);

#        my %JSLink = (Options => 'JavaScript:UserOptionsPopup()');
        my %JSLink = (Options => 'JavaScript:UserOptionsPopup()',
                      Print   => 'JavaScript:PrintPopup()',
                      MiniCal => "JavaScript:${miniName}Popup()",
                     );
        $theHash{JSLinks} = \%JSLink;

#        @order = ('Search', 'Text Filter', 'Event Filter');
        @order = ('Options', 'MiniCal');
        push @order, 'Settings'
            if ($operation->permission->permitted ($username, 'Admin'));
        if ($operation->permission->permitted ($username, 'Edit')) {
            unshift @order, 'Add/Edit';
            if ($prefs->TentativeSubmit) {
                push @order, 'Approve Events';
            }
        } elsif ($operation->permission->permitted ($username, 'Add')) {
            unshift @order, 'Add';
        }
        unshift @order, 'Print' if (@order < 3);
        $calTable = $self->_bottomBarTable (\@order, \%theHash, $i18n, $prefs,
                                            $size, $face);
    }

    # System Options menu
    if ($whichMenus =~ /sys/i) {
        $self->{'html'} .= Javascript->SelectCalendar ($operation);
        %theHash = ();
        @order = ();
        my $showHome = $prefs->MenuItemHome || 'always';
        if ($showHome !~ /never/i and
            ($showHome =~ /always/i
             or ($showHome =~ /add/i and
                 $operation->permission->permitted ($username, 'Add'))
             or ($showHome =~ /admin/i and
                 $operation->permission->permitted ($username, 'Admin')))) {
            %theHash = ('Home' => $operation->makeURL ({PlainURL => 1,
                                                      CalendarName => undef}));
            @order = ('Home');
        }
        my $admin = 'Administer';
        if (Defines->multiCals) {
            $admin = 'Admin';
            $theHash{'Select Calendar'} = $operation->makeURL
                                                    ({Op => 'SelectCalendar'});
#            $theHash{'Select Calendar'} = 'JavaScript:SelectCalendar()';
            $theHash{JSLinks} = {'Select Calendar'=>
                                               'JavaScript:SelectCalendar()'};
            push @order, 'Select Calendar';
        }
        if (Permissions->new(MasterDB->new)->permitted ($username, 'Admin')) {
            push @order, $admin;
            $theHash{$admin} = $operation->makeURL ({Op => 'SysAdminPage',
                                                     CalendarName => undef});
        }
        if ($username) {
            if ($operation->getUser->internallyAuthenticated) {
                push @order, 'Logout';
                $theHash{'Logout'} = $operation->makeURL({Op => 'UserLogout'});
            }
        } else {
            push @order, 'Login';
            my $params = $operation->mungeParams (CalendarName =>
                                                  $operation->calendarName);
            $theHash{'Login'} = $operation->makeURL ({Op        => 'UserLogin',
                                                      DesiredParams => $params,
                                                      DesiredOp =>
                                                          $operation->opName});
        }
        $optsTable = $self->_bottomBarTable (\@order, \%theHash, $i18n, $prefs,
                                             $size, $face);
    }

    my $userlink;
    if ($username) {
        if ($operation->getUser->internallyAuthenticated) {
            my $url = $operation->makeURL ({Op     => 'UserOptions',
                                            NextOp => 'ShowIt'});
            $userlink = a ({href => $url}, "$username");
        } else {
            $userlink = $username;
        }
    }

#    my $color = $prefs->color ('BottomBarFG') || '';
    my $color = $prefs->color ('MainPageFG') || '';

    my @menus;
    foreach ($displayTable, $navTable, $calTable, $optsTable) {
        push @menus, $_ if $_;
    }

    my @labels;
    push @labels, 'Display'        if $displayTable;
    push @labels, 'Navigation Bar' if $navTable;
    push @labels, 'This Calendar'  if $calTable;
    push @labels, 'System Options' if $optsTable;

    my @corners;
    foreach my $label (@labels) {
        push @corners, td ({-align => 'right'},
                            b (font ({color => $color,
                                      face  => $face,
                                      size  => $size},
                                     $i18n->get ($label) . ':')));
        push @corners, td ({-align => 'left'}, shift @menus);
    }

    my $offset = $prefs->Timezone || '0';
    my $offString = '';
    if ($offset) {
        my $hours = $offset == 1 ? 'hour' : 'hours';
        $offString = small ($i18n->get ('Time offset') .
                            ": $offset " . $i18n->get ($hours));
    }
    if ($username) {
        my $usertd = td ({-colspan => 2},
                         [small (i ($i18n->get ("Current User:"))) . ' ' .
                          small ($userlink) .
                          "&nbsp;&nbsp;$offString"
                         ]);
        push @corners, $usertd;
    } elsif (defined $prefs->Timezone) {
        push @corners, td ({-colspan => 2}, $offString);
    }

    $self->{'html'} .= table ({-align => 'center'},
                              Tr ($corners[0] || '', $corners[1] || '',
                                  $corners[2] || '', $corners[3] || ''),
                              Tr ($corners[4] || '', $corners[5] || '',
                                  $corners[6] || '', $corners[7] || ''),
                              Tr ($corners[8] || ''));

# Uncomment following (and comment above) for 1 menu per line.
#     $self->{'html'} .= table (#{-width => (@labels > 1) ? '100%' : ''},
#                           {-align => 'center'},
#                               Tr ($corners[0] || '', $corners[1] || ''),
#                               Tr ($corners[2] || '', $corners[3] || ''),
#                               Tr ($corners[4] || '', $corners[5] || ''),
#                               Tr ($corners[6] || '', $corners[7] || ''),
#                               Tr ($corners[8] || ''));

    $self;
}

sub getHTML {
  my $self = shift;
  "\n$self->{'html'}\n";
}

# Pass a hash with (link text => link) pairs, and a list of which items are
# currently selected (and thus aren't links and a diff. color)
sub _bottomBarTable {
    my $self = shift;
    my ($order, $linkHash, $i18n, $prefs, $size, $face, @selected) = @_;

    my $html;

    my $tableBG    = $prefs->color ('BottomBarBG') || '';
    my $colorFG    = $prefs->color ('BottomBarFG') || '';
    my $selectedBG = $prefs->color ('BottomBarSelectedBG') || '';
    my $selectedFG = $prefs->color ('BottomBarSelectedFG') || '';
    my $tds;

    my $JSLink = $linkHash->{JSLinks} || {};

    foreach my $linkText (@$order) {
        my $selected = grep /$linkText/i, @selected;
        my $space    = $linkText eq '&nbsp;';
        my $text18  = $i18n->get ($linkText);
        my $stuff;
        if ($selected) {
            $stuff = font ({color => $selectedFG,
                            face  => $face,
                            size  => $size},
                           $text18);
        } else {
            if ($space) {
                $stuff = font ({size => -1}, $text18);
            } else {
                my $theLink = font ({size  => $size,
                                     face  => $face,
                                     color => $colorFG},
                                    $text18);
                if (!$JSLink->{$linkText}) {
                    $stuff = a ({-href => $linkHash->{$linkText}},
                                $theLink);
                } else {
                    $stuff = "\n" . qq (<script language="javascript">
                                 document.write (
                                '<a href="$JSLink->{$linkText}">$theLink</a>')
                                 </script>);
                    $stuff .= "\n";
                    $stuff .= qq (<noscript>
                                  <a href="$linkHash->{$linkText}">$theLink</a>
                                  </noscript>);
                    $stuff .= "\n";
                }
            }
        }

        $tds .= td ({-bgcolor => ($selected ? $selectedBG : $tableBG),
                     -align   => 'center'},
                    $stuff);
    }

    $html = table ({width       => '100%',
                    border      => 0,
                    cellpadding => 6,
                    cellspacing => 0},
                   Tr ($tds));
    $html;
}

1;

Anon7 - 2021