|
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/Operation/ |
Upload File : |
# Copyright 1999-2003, Fred Steinberg, Brown Bear Software
# Replace an event; result of submitting the Edit Form
package EventReplace;
use strict;
use CGI;
use Calendar::Defines;
use Calendar::Date;
use Calendar::GetHTML;
use Calendar::ValidateDate;
use vars ('@ISA');
@ISA = ('Operation');
sub perform {
my $self = shift;
my ($date, $eventText, $popupText, $oldEventID, $allOrOne, $copyEvent,
$reminderTime, $reminderTime2, $reminderAddress,
$cancel, $ignoreConflict, $ignoreFuture, $displayCal, $isMulti,
$displayDate) =
$self->getParams (qw (Date EventText PopupText OldEventID
AllOrOne CopyEvent
MailReminder MailReminder2
ReminderAddress
Cancel
IgnoreTimeConflict
IgnoreFutureLimit DisplayCal
MultiCalDisplayed DisplayDate));
my $cgi = CGI->new;
if ($cancel) {
my $url = $self->makeURL ({Op => 'ShowDay',
Date => $displayDate || $date,
CalendarName => $displayCal});
print $self->redir ($url);
return;
}
$self->{audit_formsaved}++;
my ($isWarning, $errorMessage);
CHECK_ERRORS: {
# If multi-cal enabled, ensure at least 1 calendar selected
if ($isMulti and !$cgi->param ('WhichCalendars')) {
$errorMessage = $self->I18N->get ('You must select at least ' .
'one calendar') . '<br>';
$self->{audit_error} = 'no calendar specified';
last CHECK_ERRORS;
}
# Ensure it's not blank
$eventText =~ s/^\s+//; $eventText =~ s/\s+$//;
unless ($eventText) {
$errorMessage = $self->I18N->get ('You cannot create a blank ' .
'event') . '<br>';
$self->{audit_error} = 'blank event';
last CHECK_ERRORS;
}
# Ensure dates and times make sense...
my ($eventDate, $startTime, $endTime, $timePeriod, $endDate,
$dateChange);
($eventDate, $startTime, $endTime, $timePeriod, $endDate,
$dateChange, $errorMessage) =
ValidateDate->getAndValidateDateAndTimes ($self);
$self->{audit_error} = 'bad date or time';
last CHECK_ERRORS if $errorMessage;
# Make sure email address enteered if sending reminders
if (($reminderTime or $reminderTime2) and !$reminderAddress) {
$errorMessage = $self->I18N->get ('You must specify an email ' .
'address if Email Reminders ' .
'are specified.') . '<br>';
$self->{audit_error} = 'reminder w/no address';
last CHECK_ERRORS;
}
# Check time conflicts
my $tc = ValidateDate->timeConflict ($self->db,
$self->prefs,
$eventDate, $startTime,
$endTime, $oldEventID,
$ignoreConflict);
if ($tc->isBad) {
$errorMessage = $tc->conflictMessage ($self);
$isWarning = $tc->isWarning;
$self->{audit_error} = 'time conflict';
last CHECK_ERRORS;
}
# Check future limits
my $fc = ValidateDate->futureCheck ($self->prefs, $eventDate,
$endDate, $ignoreFuture);
if ($fc->isBad) {
$errorMessage = $fc->futureMessage ($self, $self->calendarName,
$self->I18N);
$isWarning = $fc->isWarning;
$self->{audit_error} = 'future limit';
last CHECK_ERRORS;
}
}
if ($errorMessage) {
my $title;
if (!$copyEvent) {
$title = ($isWarning ? 'Warning while Replacing Event'
: 'Error Replacing Event');
} else {
$title = ($isWarning ? 'Warning while Copying Event'
: 'Error Copying Event');
}
GetHTML->errorPage ($self->I18N,
header => $self->I18N->get ($title),
message => $errorMessage,
isWarning => $isWarning);
return;
}
delete $self->{audit_error};
# If we're modifying all instances (or all past/future instances) of a
# repeating event, we need to get and pass the exclusion list along.
my $exclusionString;
my $singleInstanceOfRepeater;
my $event;
if ($allOrOne !~ /^only/i) {
$event = $self->db->getEvent (undef, $oldEventID);
if ($event) {
my $exclusionList = $event->exclusionList;
foreach my $date (@$exclusionList) {
$exclusionString .= "$date ";
}
chop $exclusionString if $exclusionString;
}
} elsif ($allOrOne =~ /only/i) {
$singleInstanceOfRepeater = 1;
}
# If editing, need to get list of subscribers to pass along
my $subscribers;
if ($oldEventID) {
$event ||= $self->db->getEvent ($date, $oldEventID);
if ($event) {
$subscribers = $event->subscriptions;
}
}
my $params = $self->{params};
# If we're editing past/future instances of a repeating event, we need
# to create a new event for that, as well as the modify start or end
# date of the original event.
my $deletedText;
if ($allOrOne =~ /past|future/i) {
my $dateObj = Date->new ($date);
# If modifying past instances, set this event's start date
if (lc ($allOrOne) eq 'past') {
# Must Set Date param to event start date
$params->{Date} = "" . $event->repeatInfo->startDate; # stringify
$event->repeatInfo->startDate ($dateObj + 1);
}
if (lc ($allOrOne) eq 'future') {
$event->repeatInfo->endDate ($dateObj - 1);
}
$self->db->replaceEvent ($event);
# Delete event ID, so we actually get a new event in EventNew
delete $params->{OldEventID};
}
# Otherwise, delete the old version (or just one instance), unless
# we're copying an event.
elsif (!$copyEvent) {
if (!$isMulti or
grep {$self->calendarName eq $_} $cgi->param ('WhichCalendars')) {
$deletedText = $self->db->deleteEvent (Date->new ($date),
$oldEventID, $allOrOne,
'noSyncEntry');
}
}
# ...and create the new one. (Replace EventReplace Op w/EventNew.)
$params->{Op} = 'EventNew';
$params->{SingleRepeatingInstance} = $singleInstanceOfRepeater;
$params->{ExcludedDates} = $exclusionString if $exclusionString;
$params->{Subscribers} = $subscribers if $subscribers;
my $op = OperationFactory->create ('EventNew', $params, $self->getUser);
if ($op->authenticate) {
$op->perform;
$op->audit;
}
$self->{audit_copied_p} = $copyEvent;
$self->{audit_copiedText} = $eventText;
$self->{audit_deletedText} = $deletedText;
$self->{audit_eventDate} = $date;
}
sub auditString {
my ($self, $short) = @_;
return unless $self->{audit_formsaved};
my $summary = $self->SUPER::auditString ($short);
return ($summary . ' ERROR - ' . $self->{audit_error})
if $self->{audit_error};
return $summary if $short;
my $text;
$text = "Event Copied\n" if $self->{audit_copied_p};
$text .= $self->{audit_deletedText} || $self->{audit_copiedText};
$text = $self->{audit_eventDate} . "\n" . $text;
return $summary . "\n\n" . $text;
}
1;