<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;"># Copyright 2002-2006, Fred Steinberg, Brown Bear Software

# Display/Approve/Delete tentative events

package ApproveEvents;
use strict;

use CGI;
use Calendar::Date;
use Calendar::Footer;
use Calendar::Header;
use Calendar::ListView;
use Calendar::Name;
use Calendar::Title;
use Operation::ShowIt;

use vars ('@ISA');
@ISA = ('ShowIt');              # primarily to get cssDefaults

sub perform {
    my $self = shift;

    if ($self-&gt;getParams ('ApproveIt')) {

        $self-&gt;{form_saved}++;
        $self-&gt;{audit_ids} = {};

        # Get event ids
        while (my ($name, $val) = each %{$self-&gt;{params}}) {
            next if ($val =~ /pending/i);
            next unless ($name =~ /Approve-(\d+)-(.*)/);
            my ($id, $calName) = ($1, $2);
            my $action = $val; # 'approve', 'delete', 'pending'
            my $db;
            if (defined $calName and $calName ne '') {
                $db = Database-&gt;new ($calName);
            } else {
                $db = $self-&gt;db;
            }
            my ($event, $date) = $db-&gt;getEventById ($id);
            next unless $event;
            if ($action =~ /approve/i) {
                $event-&gt;isTentative (0);
                $db-&gt;replaceEvent ($event, $date);
            } elsif ($action =~ /delete/i) {
                $db-&gt;deleteEvent ($date, $id, 'all');
            }
            $self-&gt;{audit_ids}-&gt;{$id} = [$action, $date, $event-&gt;text];
        }

        # If no tentative events left, go back to cal
        my $eventHash = $self-&gt;db-&gt;getTentativeEvents;
        $self-&gt;db-&gt;addIncludedTentativeEvents ($self-&gt;getUsername, $eventHash);
        if (!keys %$eventHash) {
            print $self-&gt;redir ($self-&gt;makeURL ({Op =&gt; 'ShowIt'}));
            return;
        }
    }

    my $prefs = $self-&gt;prefs;
    my @page = (Name-&gt;new      ($prefs),
                Title-&gt;new     ($self, 'ignored', 'Approval'),
                ListView-&gt;new  ($self, Date-&gt;new, Date-&gt;new,
                                {mode =&gt; 'Approval'}),
                Footer-&gt;new    ($prefs),
                SubFooter-&gt;new ($prefs));

    # Get each piece's CSS
    $self-&gt;{_childrenCSS} = '';
    foreach (@page) {
        next unless defined;
        $self-&gt;{_childrenCSS} .= $_-&gt;cssDefaults ($prefs)
            if $_-&gt;can ('cssDefaults');
    }

    # Do Header *after* getting each ones CSS
    unshift @page, Header-&gt;new (op     =&gt; $self,
                                title  =&gt; $prefs-&gt;Description);

    foreach (@page) {
        next unless defined;
        my $html = ($_-&gt;getHTML || '');
        print "$html \n";
    }
    my $cgi = CGI-&gt;new ('');
    print $cgi-&gt;end_html
        unless (($ENV{SERVER_PROTOCOL} || '') eq 'INCLUDED');

    return;
}

sub auditString {
    my ($self, $short) = @_;
    return unless $self-&gt;{form_saved};
    my $line = $self-&gt;SUPER::auditString ($short);

    if ($short) {
        $line .= ' ';
        while (my ($id, $info) = each %{$self-&gt;{audit_ids}}) {
            $line .= "$id: $info-&gt;[0],";
        }
        chop $line;
        return $line;
    }

    my $message = "These tentative events on the '" . $self-&gt;calendarName .
                  "' Calendar were processed:\n\n";

    my $text = '';
    while (my ($id, $info) = each %{$self-&gt;{audit_ids}}) {
        $text .= ' ' . sprintf ("%7s", $info-&gt;[0]) . "d - $info-&gt;[1] - " .
                "$info-&gt;[2]\n";
    }
    $text ||= '    -no events processed-';
    $message .= $text;

    return "$line\n\n$message\n";
}

sub cssDefaults {
    my ($self, $prefs) = @_;
    my $css = $self-&gt;SUPER::cssDefaults;
    $css .= Operation-&gt;cssString ('.EventTag',
                                  {bg    =&gt; 'gray',
                                   color =&gt; 'darkred'});
    $css;
}

1;
</pre></body></html>