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

# Auditing Options
package AdminAuditing;
use strict;

use CGI (':standard');
use Calendar::GetHTML;
use Operation::MultiCal;

use vars ('@ISA');
@ISA = ('Operation::MultiCal');

sub perform {
    my $self = shift;
    my $i18n = $self-&gt;I18N;

    my ($save, $cancel, $sysset) = $self-&gt;getParams (qw (Save Cancel SysSet));

    my $db  = $self-&gt;db;
    my $cgi = new CGI;

    if ($cancel) {
        my $op = $self-&gt;isSystemOp ? 'SysAdminPage' : 'AdminPage';
        print $self-&gt;redir ($self-&gt;makeURL ({Op =&gt; $op}));
        return;
    }

    my ($calendars, $preferences) = $self-&gt;getCalsAndPrefs;
    $db = $self-&gt;dbByName ($calendars-&gt;[0])
        if ($self-&gt;isMultiCal and $calendars-&gt;[0]);

    my @opTypes = qw (View Add AddTentative Edit Admin);
    if (Defines-&gt;mailEnabled) {
        push @opTypes, 'Subscribe';     # for user subscription requests
    }

    if ($self-&gt;isSystemOp and $sysset) {
        @opTypes = qw (SysAdmin UserLogin UserOptions);
    }

    my $override = 1;
    my $message = $self-&gt;adminChecks;

    if (!$message and $save) {
    CHECK_ERRORS: {
        $override = 0;

        my @changed;

        my (@setEmail, $setEmail);
        my $mailToggle = $self-&gt;getOnChangeName ('EmailAddresses');
        if (!$self-&gt;isMultiCal or
            ($self-&gt;{params}-&gt;{$mailToggle} eq 'change')) {
            push @changed, 'Email Address';
            $setEmail = 1;
            my $newEmail = $cgi-&gt;param ('EmailAddresses');
            $newEmail =~ s/,/ /g;
            $newEmail =~ s/\s+/ /g;
            @setEmail = split /\s/, $newEmail;
            push @setEmail, '' if (!@setEmail);
        }

        my $filename;
        my $filenameToggle = $self-&gt;getOnChangeName ('Filename');
        if (!$self-&gt;isMultiCal or
            ($self-&gt;{params}-&gt;{$filenameToggle} eq 'change')) {
            push @changed, 'Filename';
            $filename = $cgi-&gt;param ('Filename') || '';
            $filename =~ s/^\s+//;
            $filename =~ s/\s+$//;
            my $blah = $filename;
            $blah =~ s{[-\\/\.:]}{}g;
            if ($blah =~ /\W/) {
                $message = 'Error: only letters, digits, underscores, '
                         . 'periods, colons, and slashes '
                         . 'are allowed in the filename.';
                $filename = undef;
                last CHECK_ERRORS;
            } else {
                $filename ||= 'CalciumAuditLog';
            }
        }

        my (%setAuditing, %ignoreOp);
        foreach my $op (@opTypes) {
            my $name = "Checks-$op";
            my @boxes = $cgi-&gt;param ($name);
            my $theOp = ($op eq 'SysAdmin' ? 'Admin' : $op);
            $setAuditing{$theOp} = \@boxes;
            if ($self-&gt;isMultiCal) {
                my $togName = $self-&gt;getOnChangeName ($op);
                $ignoreOp{$op} = ($self-&gt;{params}-&gt;{$togName} eq 'ignore');
                push (@changed, $op) unless $ignoreOp{$op};
            } else {
                push (@changed, $theOp);
            }
        }

        $message = $self-&gt;getModifyMessage (cals =&gt; $calendars,
                                            mods =&gt; \@changed);

        last CHECK_ERRORS if (!@changed);

        # Save everything
        $self-&gt;{audit_formsaved}++;
        foreach (@$calendars) {
            my %orig;       # for auditing this op
            my $db = $self-&gt;dbByName ($_);

            if ($setEmail) {
                $orig{email} = [$db-&gt;auditingEmail];
                $db-&gt;auditingEmail (@setEmail);
            }
            if (defined $filename) {
                $orig{filename} = $db-&gt;auditingFile;
                $db-&gt;auditingFile ($filename);
            }

            foreach my $op (@opTypes) {
                my $theOp = ($op eq 'SysAdmin' ? 'Admin' : $op);
                next if $ignoreOp{$theOp};
                $orig{"type_$theOp"} = [$db-&gt;getAuditing ($theOp)];
                $db-&gt;setAuditing ($theOp, @{$setAuditing{$theOp}});
            }
            $self-&gt;{audit_info}-&gt;{defined ($_) ? $_ : ' MASTER '} = \%orig;
        }
    }
    }

    print GetHTML-&gt;startHTML (title =&gt; $i18n-&gt;get ('Auditing'),
                              op    =&gt; $self);

    print '&lt;center&gt;';
    if (!$self-&gt;isSystemOp) {
        print GetHTML-&gt;AdminHeader (I18N    =&gt; $i18n,
                                    cal     =&gt; $self-&gt;calendarName || '',
                                    goob    =&gt; $self-&gt;goobLabel    || '',
                                    group   =&gt; $self-&gt;groupName    || '',
                                    section =&gt; 'Auditing');
    } else {
        print GetHTML-&gt;SysAdminHeader ($i18n, 'Auditing', $sysset ? 1 : undef);
    }

    print $cgi-&gt;h3 ($message) if $message;
    print '&lt;br&gt;';
    print '&lt;/center&gt;';

    print startform;

    # If group, allow selecting any calendar we have Admin permission for
    my %onChange = ();
    if ($self-&gt;isMultiCal) {
        my ($calSelector, $message) = $self-&gt;calendarSelector;
        print $message if $message;

        foreach (qw /View Add AddTentative Edit Admin Subscribe
                     EmailAddresses Filename/) {
            $onChange{$_} = $self-&gt;getOnChange ($_);
        }
        print $calSelector if $calSelector;
    }



    my %opLabels = (View         =&gt; 'View Calendar',
                    Add          =&gt; 'Add Events',
                    AddTentative =&gt; 'Add Tentative Events',
                    Edit         =&gt; 'Edit/Delete Events',
                    Admin        =&gt; 'Calendar Administration',
                    Subscribe    =&gt; 'User Subscription Requests',
                    SysAdmin     =&gt; 'System Administration',
                    UserLogin    =&gt; 'User Login and Logout',
                    UserOptions  =&gt; 'User Options');

    my @checkValues = qw (file email);
    my %checkLabels = (file  =&gt; $i18n-&gt;get ('Log to File'),
                       email =&gt; $i18n-&gt;get ('Send Email'));

    my @rows;
    foreach my $op (@opTypes) {
        my $storedOp = ($op eq 'SysAdmin' ? 'Admin' : $op);
        my @types = $db-&gt;getAuditing ($storedOp);

        push @rows, Tr ($self-&gt;groupToggle (name =&gt; $op),
                        td ('&amp;nbsp;'),
                        td ($i18n-&gt;get ($opLabels{$op})),
                        td ('&amp;nbsp;'),
                        td (checkbox_group (-name   =&gt; "Checks-$op",
                                            -onChange =&gt; $onChange{$op},
                                            -override =&gt; $override,
                                            -Values =&gt; \@checkValues,
                                            -labels =&gt; \%checkLabels,
                                            -default =&gt; \@types)));
    }

    print table (@rows);

    my $filename = $db-&gt;auditingFile || 'CalciumAuditLog';
    my $mailRow = '';
    my $emailAddrs = join ' ', ($db-&gt;auditingEmail || '');
    $mailRow = Tr ($self-&gt;groupToggle (name =&gt; 'EmailAddresses'),
                   td ('&amp;nbsp;'),
                   td (b ($i18n-&gt;get ('Email to') . ': ')),
                   td (textfield (-name =&gt; 'EmailAddresses',
                                  -default =&gt; $emailAddrs,
                                  -onChange =&gt; $onChange{EmailAddresses},
                                  -override =&gt; $override,
                                  -columns =&gt; 60)),
                   td ('&lt;small&gt;' .
                       $i18n-&gt;get ('Separate multiple addresses with ' .
                                   'spaces or commas.') .
                       '&lt;/small&gt;'));

    print table (Tr ($self-&gt;groupToggle (name =&gt; 'Filename'),
                     td ('&amp;nbsp;'),
                     td (b ($i18n-&gt;get ('Filename') . ': ')),
                     td (textfield (-name =&gt; 'Filename',
                                    -default =&gt; $filename,
                                    -onChange =&gt; $onChange{Filename},
                                    -override =&gt; $override,
                                    -columns =&gt; 60)),
                     td ('&lt;small&gt;' .
                         'Unless it specifies a full path, ' .
                         $i18n-&gt;get ('the file will be located in') . ' "' .
                         Defines-&gt;baseDirectory . '/data"&lt;/small&gt;')),
                 $mailRow);

    my ($setAlljs, $setAllRow) = $self-&gt;setAllJavascript;
    print $setAlljs;
    print $setAllRow;

    print '&lt;hr&gt;';
    print submit (-name =&gt; 'Save',   -value =&gt; $i18n-&gt;get ('Save'));
    print '&amp;nbsp;';
    print submit (-name =&gt; 'Cancel', -value =&gt; $i18n-&gt;get ('Done'));
    print '&amp;nbsp;';
    print reset  (-value =&gt; 'Reset');

    print $self-&gt;hiddenParams;
    print hidden (-name =&gt; 'SysSet', -value =&gt; 1) if $sysset;

    print endform;
    print $self-&gt;helpNotes;
    print $cgi-&gt;end_html;
}

sub auditString {
    my ($self, $short) = @_;
    return unless $self-&gt;{audit_formsaved};
    my $line = $self-&gt;basicAuditString ($short);
    my $i18n = $self-&gt;I18N;

    my $cal = $self-&gt;currentCal;
    my $old = $self-&gt;{audit_info}-&gt;{defined $cal ? $cal : ' MASTER '};
    my $db  = $self-&gt;dbByName ($cal);

    my $info = '';

    my $oldFile = $old-&gt;{filename}  || '[]';
    my $newFile = $db-&gt;auditingFile || '[]';

    if ($oldFile ne $newFile) {
        $info .= "\n" unless $short;
        $info .= $i18n-&gt;get ('Filename') . ': ' . "$oldFile -&gt; $newFile";
    }

    my $oldMail = $old-&gt;{email} || [];
    my @newMail = $db-&gt;auditingEmail;
    my $newMail = join ',', @newMail;
       $oldMail = join ',', @$oldMail;
    if ($oldMail ne $newMail) {
        $info .= "\n" unless $short;
        $info .= $i18n-&gt;get (' Email') . ': ' . "$oldMail -&gt; $newMail";
    }

    foreach my $op (qw (View Add AddTentative Edit Admin Subscribe
                        SysAdmin UserLogin UserOptions)) {
        my $orig = join (',', @{$old-&gt;{"type_$op"} || []}) || 'none';
        my $new  = join (',', $db-&gt;getAuditing ($op))      || 'none';
        next if ($orig eq $new);
        $info .= "\n" unless $short;
        $info .= " [$op: $orig -&gt; $new ] ";
    }

    return unless $info;
    return "$line $info";
}

sub cssDefaults {
    my $self = shift;
    my $css = $self-&gt;SUPER::cssDefaults;
    $css .= GetHTML-&gt;AdminCSS ($self);
    return $css;
}

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