fix: Event userDefined fields now work properly.
This commit is contained in:
parent
2124f58231
commit
b75ecdaa5e
2 changed files with 296 additions and 400 deletions
|
|
@ -4,6 +4,7 @@
|
||||||
- fix: SQL Report: Paginate After (Still) (William McKee / Knowmad
|
- fix: SQL Report: Paginate After (Still) (William McKee / Knowmad
|
||||||
Technologies)
|
Technologies)
|
||||||
- fix: Bug in thumbnailer.pl
|
- fix: Bug in thumbnailer.pl
|
||||||
|
- fix: Events userDefined fields now work.
|
||||||
|
|
||||||
|
|
||||||
7.3.12
|
7.3.12
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ $VERSION = "0.0.0";
|
||||||
use strict;
|
use strict;
|
||||||
|
|
||||||
use Tie::IxHash;
|
use Tie::IxHash;
|
||||||
|
use Carp qw(cluck confess);
|
||||||
use Storable qw(nfreeze thaw);
|
use Storable qw(nfreeze thaw);
|
||||||
|
|
||||||
use WebGUI::International;
|
use WebGUI::International;
|
||||||
|
|
@ -49,7 +50,6 @@ sub definition {
|
||||||
my $definition = shift;
|
my $definition = shift;
|
||||||
|
|
||||||
my $i18n = WebGUI::International->new($session, 'Asset_Event');
|
my $i18n = WebGUI::International->new($session, 'Asset_Event');
|
||||||
|
|
||||||
my $dt = WebGUI::DateTime->new($session, time);
|
my $dt = WebGUI::DateTime->new($session, time);
|
||||||
|
|
||||||
### Set up list options ###
|
### Set up list options ###
|
||||||
|
|
@ -109,7 +109,7 @@ sub definition {
|
||||||
|
|
||||||
### Add user defined fields
|
### Add user defined fields
|
||||||
for my $num (1..5) {
|
for my $num (1..5) {
|
||||||
$properties{"UserDefined".$num} = {
|
$properties{"userDefined".$num} = {
|
||||||
fieldType => "text",
|
fieldType => "text",
|
||||||
defaultValue => "",
|
defaultValue => "",
|
||||||
};
|
};
|
||||||
|
|
@ -173,65 +173,45 @@ sub canEdit {
|
||||||
|
|
||||||
####################################################################
|
####################################################################
|
||||||
|
|
||||||
=head2 generateRecurringEvents ( [ \%recurrence_data ] )
|
=head2 generateRecurringEvents ( )
|
||||||
|
|
||||||
Generate a series of events.
|
Generates Events according to this Event's recurrence pattern.
|
||||||
|
|
||||||
If given a hashref of recurrence data, will create a new recurrence row in the
|
Will croak on failure.
|
||||||
database and set the event to this new recurrence pattern. Will return undef if
|
|
||||||
there is an error creating the recurrence pattern.
|
|
||||||
|
|
||||||
If not given recurrence data, will use the event's existing recurrence. This is
|
|
||||||
used for generating future occurrences of events that don't end.
|
|
||||||
|
|
||||||
Returns the new recurrence pattern's ID, or undef if failure. (NOTE: This
|
|
||||||
should probably use croak instead)
|
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
sub generateRecurringEvents {
|
sub generateRecurringEvents {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my $recur = shift;
|
|
||||||
my $parent = $self->getParent;
|
my $parent = $self->getParent;
|
||||||
my $session = $self->session;
|
my $session = $self->session;
|
||||||
my $recurId;
|
|
||||||
|
|
||||||
if ($recur) {
|
my $properties = $self->get;
|
||||||
$recurId = $self->setRecurrence($recur);
|
my $recurId = $self->get("recurId");
|
||||||
return () unless $recurId;
|
my $recur = {$self->getRecurrence};
|
||||||
}
|
|
||||||
else {
|
|
||||||
$recurId = $self->get("recurId");
|
|
||||||
$recur = {$self->getRecurrence};
|
|
||||||
}
|
|
||||||
|
|
||||||
$self->update({ recurId => $recurId });
|
# This method only works on events that have recurrence patterns
|
||||||
my $properties = {%{$self->get}};
|
if (!$recurId) {
|
||||||
$properties->{recurId} = $recurId;
|
croak("Cannot generate recurring events: Event has no recurrence pattern.");
|
||||||
|
}
|
||||||
|
|
||||||
# Get the distance between the event startDate and endDate
|
# Get the distance between the event startDate and endDate
|
||||||
# Only days, since event recurrence only changes the Date the event occurs, not
|
# Only days, since event recurrence only changes the Date the event occurs, not
|
||||||
# the time.
|
# the time.
|
||||||
|
# TODO: Allow recurrence patterns of less than a single day.
|
||||||
my $duration_days = 0;
|
my $duration_days = 0;
|
||||||
|
|
||||||
my $event_start
|
my $event_start
|
||||||
= WebGUI::DateTime->new($self->session, delete($properties->{startDate})." 00:00:00");
|
= WebGUI::DateTime->new($session, $properties->{startDate}." 00:00:00");
|
||||||
my $event_end
|
my $event_end
|
||||||
= WebGUI::DateTime->new($self->session, delete($properties->{endDate})." 00:00:00");
|
= WebGUI::DateTime->new($session, $properties->{endDate}." 00:00:00");
|
||||||
$duration_days
|
$duration_days
|
||||||
= $event_end->subtract_datetime($event_start)->days;
|
= $event_end->subtract_datetime($event_start)->days;
|
||||||
|
|
||||||
my @dates = $self->getRecurrenceDates($recur);
|
my @dates = $self->getRecurrenceDates;
|
||||||
|
|
||||||
for my $date (@dates) {
|
for my $date (@dates) {
|
||||||
# Only generate if the recurId does not exist on this day
|
# Only generate if the recurId does not exist on this day
|
||||||
use Data::Dumper;
|
|
||||||
warn "COMPARING $date TO $properties->{startDate}";
|
|
||||||
warn Dumper $session->db->quickArray(
|
|
||||||
"select count(*) from Event where recurId=? and startDate=?",
|
|
||||||
[$properties->{recurId}, $date],
|
|
||||||
);
|
|
||||||
|
|
||||||
my ($exists)
|
my ($exists)
|
||||||
= $session->db->quickArray(
|
= $session->db->quickArray(
|
||||||
"select count(*) from Event where recurId=? and startDate=?",
|
"select count(*) from Event where recurId=? and startDate=?",
|
||||||
|
|
@ -239,11 +219,11 @@ sub generateRecurringEvents {
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!$exists) {
|
if (!$exists) {
|
||||||
warn "Making event on $date";
|
|
||||||
my $dt = WebGUI::DateTime->new($self->session, $date." 00:00:00");
|
my $dt = WebGUI::DateTime->new($self->session, $date." 00:00:00");
|
||||||
|
|
||||||
$properties->{startDate} = $dt->toDatabaseDate;
|
$properties->{startDate} = $dt->toDatabaseDate;
|
||||||
$properties->{endDate} = $dt->clone->add(days => $duration_days)->toDatabaseDate;
|
$properties->{endDate}
|
||||||
|
= $dt->clone->add(days => $duration_days)->toDatabaseDate;
|
||||||
|
|
||||||
my $newEvent = $parent->addChild($properties);
|
my $newEvent = $parent->addChild($properties);
|
||||||
$newEvent->requestAutoCommit;
|
$newEvent->requestAutoCommit;
|
||||||
|
|
@ -295,7 +275,7 @@ sub getDateTimeStart {
|
||||||
|
|
||||||
#$self->session->errorHandler->warn($self->getId.":: Date: $date -- Time: $time");
|
#$self->session->errorHandler->warn($self->getId.":: Date: $date -- Time: $time");
|
||||||
if (!$date) {
|
if (!$date) {
|
||||||
$self->session->errorHandler->warn("This event (".$self->get("assetId").") has no date.");
|
$self->session->errorHandler->warn("Event::getDateTimeStart -- This event (".$self->get("assetId").") has no start date.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -334,11 +314,10 @@ sub getDateTimeEnd {
|
||||||
|
|
||||||
#$self->session->errorHandler->warn($self->getId.":: Date: $date -- Time: $time");
|
#$self->session->errorHandler->warn($self->getId.":: Date: $date -- Time: $time");
|
||||||
if (!$date) {
|
if (!$date) {
|
||||||
$self->session->errorHandler->warn("This event (".$self->get("assetId").") has no date.");
|
$self->session->errorHandler->warn("Event::getDateTimeEnd -- This event (".$self->get("assetId").") has no end date.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if ($time) {
|
if ($time) {
|
||||||
my $dt = WebGUI::DateTime->new($self->session, $date." ".$time);
|
my $dt = WebGUI::DateTime->new($self->session, $date." ".$time);
|
||||||
$dt->set_time_zone($tz);
|
$dt->set_time_zone($tz);
|
||||||
|
|
@ -377,8 +356,7 @@ sub getEventNext {
|
||||||
. "|| Event.startTime >= '00:00:00')";
|
. "|| Event.startTime >= '00:00:00')";
|
||||||
}
|
}
|
||||||
# Non all-day events must look for greater than time
|
# Non all-day events must look for greater than time
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
$where .= "((Event.startTime = '".$self->get("startTime")."' "
|
$where .= "((Event.startTime = '".$self->get("startTime")."' "
|
||||||
. "&& assetData.title > ".$db->quote($self->get("title")).")"
|
. "&& assetData.title > ".$db->quote($self->get("title")).")"
|
||||||
. "|| Event.startTime > '".$self->get("startTime")."')";
|
. "|| Event.startTime > '".$self->get("startTime")."')";
|
||||||
|
|
@ -693,21 +671,21 @@ sub getRecurrence {
|
||||||
|
|
||||||
####################################################################
|
####################################################################
|
||||||
|
|
||||||
=head2 getRecurrenceDates
|
=head2 getRecurrenceDates ( endDate )
|
||||||
|
|
||||||
Gets a series of dates in the specified recurrence pattern.
|
Gets a series of dates in this event's recurrence pattern, up to the
|
||||||
|
calendar's configured "maintainRecurrenceOffset".
|
||||||
|
|
||||||
This is quite possibly the worst algorithm I've ever created. We should be using
|
This is quite possibly the worst algorithm I've ever created. We should be
|
||||||
DateTime::Event::ICal instead.
|
using DateTime::Event::ICal instead.
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
sub getRecurrenceDates {
|
sub getRecurrenceDates {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my $recur = shift;
|
|
||||||
|
|
||||||
my %date;
|
my %date;
|
||||||
|
my $recur = {$self->getRecurrence};
|
||||||
return undef unless $recur->{recurType};
|
return undef unless $recur->{recurType};
|
||||||
|
|
||||||
my %dayNames = (
|
my %dayNames = (
|
||||||
|
|
@ -736,17 +714,15 @@ sub getRecurrenceDates {
|
||||||
$dt_end = WebGUI::DateTime->new($self->session, $recur->{endDate}." 00:00:00");
|
$dt_end = WebGUI::DateTime->new($self->session, $recur->{endDate}." 00:00:00");
|
||||||
}
|
}
|
||||||
# Set an end for events with no end
|
# Set an end for events with no end
|
||||||
#!!! TODO !!! - Get the appropriate configuration
|
# TODO: Get the maintainRecurrenceOffset value
|
||||||
elsif (!$recur->{endDate} && !$recur->{endAfter}) {
|
elsif (!$recur->{endDate} && !$recur->{endAfter}) {
|
||||||
$dt_end = $dt->clone->add(years=>2);
|
$dt_end = $dt->clone->add(years=>2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
RECURRENCE: while (1)
|
RECURRENCE: while (1) {
|
||||||
{
|
|
||||||
####### daily
|
####### daily
|
||||||
if ($recur->{recurType} eq "daily")
|
if ($recur->{recurType} eq "daily") {
|
||||||
{
|
|
||||||
### Add date
|
### Add date
|
||||||
$date{$dt->strftime('%F')}++;
|
$date{$dt->strftime('%F')}++;
|
||||||
|
|
||||||
|
|
@ -754,8 +730,7 @@ sub getRecurrenceDates {
|
||||||
$dt->add(days => $recur->{every});
|
$dt->add(days => $recur->{every});
|
||||||
|
|
||||||
# Test for quit
|
# Test for quit
|
||||||
if (($recur->{endAfter} && keys %date >= $recur->{endAfter}) || ($dt_end && $dt > $dt_end))
|
if (($recur->{endAfter} && keys %date >= $recur->{endAfter}) || ($dt_end && $dt > $dt_end)) {
|
||||||
{
|
|
||||||
last RECURRENCE;
|
last RECURRENCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -763,35 +738,30 @@ sub getRecurrenceDates {
|
||||||
next RECURRENCE;
|
next RECURRENCE;
|
||||||
}
|
}
|
||||||
####### weekday
|
####### weekday
|
||||||
elsif ($recur->{recurType} eq "weekday")
|
elsif ($recur->{recurType} eq "weekday") {
|
||||||
{
|
|
||||||
my $today = $dt->day_name;
|
my $today = $dt->day_name;
|
||||||
|
|
||||||
# If today is not a weekday
|
# If today is not a weekday
|
||||||
unless (grep /$today/i,qw(monday tuesday wednesday thursday friday))
|
unless (grep /$today/i,qw(monday tuesday wednesday thursday friday)) {
|
||||||
{
|
|
||||||
# Add a day
|
# Add a day
|
||||||
$dt->add(days => 1);
|
$dt->add(days => 1);
|
||||||
|
|
||||||
# Test for quit
|
# Test for quit
|
||||||
if (($recur->{endAfter} && keys %date >= $recur->{endAfter}) || ($dt_end && $dt > $dt_end))
|
if (($recur->{endAfter} && keys %date >= $recur->{endAfter}) || ($dt_end && $dt > $dt_end)) {
|
||||||
{
|
|
||||||
last RECURRENCE;
|
last RECURRENCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
# next
|
# next
|
||||||
next RECURRENCE;
|
next RECURRENCE;
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
### Add date
|
### Add date
|
||||||
$date{$dt->strftime('%F')}++;
|
$date{$dt->strftime('%F')}++;
|
||||||
|
|
||||||
$dt->add(days => $recur->{every});
|
$dt->add(days => $recur->{every});
|
||||||
|
|
||||||
# Test for quit
|
# Test for quit
|
||||||
if (($recur->{endAfter} && keys %date >= $recur->{endAfter}) || ($dt_end && $dt > $dt_end))
|
if (($recur->{endAfter} && keys %date >= $recur->{endAfter}) || ($dt_end && $dt > $dt_end)) {
|
||||||
{
|
|
||||||
last RECURRENCE;
|
last RECURRENCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -800,10 +770,8 @@ sub getRecurrenceDates {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
####### weekly
|
####### weekly
|
||||||
elsif ($recur->{recurType} eq "weekly")
|
elsif ($recur->{recurType} eq "weekly") {
|
||||||
{
|
for (0..6) { # Work through the week
|
||||||
for (0..6) # Work through the week
|
|
||||||
{
|
|
||||||
my $dt_day = $dt->clone->add(days => $_);
|
my $dt_day = $dt->clone->add(days => $_);
|
||||||
|
|
||||||
# If today is past the endDate, quit.
|
# If today is past the endDate, quit.
|
||||||
|
|
@ -812,8 +780,7 @@ sub getRecurrenceDates {
|
||||||
|
|
||||||
my $today = $dayNames{lc $dt_day->day_name};
|
my $today = $dayNames{lc $dt_day->day_name};
|
||||||
|
|
||||||
if (grep /$today/i, @{$recur->{dayNames}})
|
if (grep /$today/i, @{$recur->{dayNames}}) {
|
||||||
{
|
|
||||||
### Add date
|
### Add date
|
||||||
$date{$dt_day->strftime('%F')}++;
|
$date{$dt_day->strftime('%F')}++;
|
||||||
}
|
}
|
||||||
|
|
@ -827,8 +794,7 @@ sub getRecurrenceDates {
|
||||||
$dt->add(weeks => $recur->{every});
|
$dt->add(weeks => $recur->{every});
|
||||||
|
|
||||||
# Test for quit
|
# Test for quit
|
||||||
if (($recur->{endAfter} && keys %date >= $recur->{endAfter}) || ($dt_end && $dt > $dt_end))
|
if (($recur->{endAfter} && keys %date >= $recur->{endAfter}) || ($dt_end && $dt > $dt_end)) {
|
||||||
{
|
|
||||||
last RECURRENCE;
|
last RECURRENCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -837,16 +803,14 @@ sub getRecurrenceDates {
|
||||||
|
|
||||||
}
|
}
|
||||||
####### monthday
|
####### monthday
|
||||||
elsif ($recur->{recurType} eq "monthDay")
|
elsif ($recur->{recurType} eq "monthDay") {
|
||||||
{
|
|
||||||
# Pick out the correct day
|
# Pick out the correct day
|
||||||
my $startDate = $dt->year."-".$dt->month."-".$recur->{dayNumber};
|
my $startDate = $dt->year."-".$dt->month."-".$recur->{dayNumber};
|
||||||
|
|
||||||
my $dt_day = WebGUI::DateTime->new($self->session, $startDate." 00:00:00");
|
my $dt_day = WebGUI::DateTime->new($self->session, $startDate." 00:00:00");
|
||||||
|
|
||||||
# Only if today is not before the recurrence start
|
# Only if today is not before the recurrence start
|
||||||
if ($dt_day->clone->truncate(to => "day") >= $dt_start->clone->truncate(to=>"day"))
|
if ($dt_day->clone->truncate(to => "day") >= $dt_start->clone->truncate(to=>"day")) {
|
||||||
{
|
|
||||||
# If today is past the endDate, quit.
|
# If today is past the endDate, quit.
|
||||||
last RECURRENCE
|
last RECURRENCE
|
||||||
if ($recur->{endDate} && $dt_day > $dt_end);
|
if ($recur->{endDate} && $dt_day > $dt_end);
|
||||||
|
|
@ -859,8 +823,7 @@ sub getRecurrenceDates {
|
||||||
$dt->add(months => $recur->{every})->truncate(to => "month");
|
$dt->add(months => $recur->{every})->truncate(to => "month");
|
||||||
|
|
||||||
# Test for quit
|
# Test for quit
|
||||||
if (($recur->{endAfter} && keys %date >= $recur->{endAfter}) || ($dt_end && $dt > $dt_end))
|
if (($recur->{endAfter} && keys %date >= $recur->{endAfter}) || ($dt_end && $dt > $dt_end)) {
|
||||||
{
|
|
||||||
last RECURRENCE;
|
last RECURRENCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -868,19 +831,15 @@ sub getRecurrenceDates {
|
||||||
next RECURRENCE;
|
next RECURRENCE;
|
||||||
}
|
}
|
||||||
###### monthweek
|
###### monthweek
|
||||||
elsif ($recur->{recurType} eq "monthWeek")
|
elsif ($recur->{recurType} eq "monthWeek") {
|
||||||
{
|
|
||||||
# For each week remaining in this month
|
# For each week remaining in this month
|
||||||
my $dt_week = $dt->clone;
|
my $dt_week = $dt->clone;
|
||||||
while ($dt->month eq $dt_week->month)
|
while ($dt->month eq $dt_week->month) {
|
||||||
{
|
|
||||||
my $week = int($dt_week->day_of_month / 7);
|
my $week = int($dt_week->day_of_month / 7);
|
||||||
|
|
||||||
if (grep /$weeks{$week}/i, @{$recur->{weeks}})
|
if (grep /$weeks{$week}/i, @{$recur->{weeks}}) {
|
||||||
{
|
|
||||||
# Pick out the correct days
|
# Pick out the correct days
|
||||||
for (0..6) # Work through the week
|
for (0..6) { # Work through the week
|
||||||
{
|
|
||||||
my $dt_day = $dt_week->clone->add(days => $_);
|
my $dt_day = $dt_week->clone->add(days => $_);
|
||||||
|
|
||||||
# If today is past the endDate, quit.
|
# If today is past the endDate, quit.
|
||||||
|
|
@ -909,13 +868,11 @@ sub getRecurrenceDates {
|
||||||
}
|
}
|
||||||
|
|
||||||
### If last is selected
|
### If last is selected
|
||||||
if (grep /last/, @{$recur->{weeks}})
|
if (grep /last/, @{$recur->{weeks}}) {
|
||||||
{
|
|
||||||
my $dt_last = $dt->clone->truncate(to => "month")
|
my $dt_last = $dt->clone->truncate(to => "month")
|
||||||
->add(months => 1)->subtract(days => 1);
|
->add(months => 1)->subtract(days => 1);
|
||||||
|
|
||||||
for (0..6)
|
for (0..6) {
|
||||||
{
|
|
||||||
my $dt_day = $dt_last->clone->subtract(days => $_);
|
my $dt_day = $dt_last->clone->subtract(days => $_);
|
||||||
|
|
||||||
# If today is before the startDate, don't even bother
|
# If today is before the startDate, don't even bother
|
||||||
|
|
@ -925,11 +882,9 @@ sub getRecurrenceDates {
|
||||||
|
|
||||||
my $today = $dayNames{lc $dt_day->day_name};
|
my $today = $dayNames{lc $dt_day->day_name};
|
||||||
|
|
||||||
if (grep /$today/i, @{$recur->{dayNames}})
|
if (grep /$today/i, @{$recur->{dayNames}}) {
|
||||||
{
|
|
||||||
### Add date
|
### Add date
|
||||||
$date{$dt_day->strftime('%F')}++;
|
$date{$dt_day->strftime('%F')}++;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# If occurrences is past the endAfter, quit
|
# If occurrences is past the endAfter, quit
|
||||||
|
|
@ -943,8 +898,7 @@ sub getRecurrenceDates {
|
||||||
$dt->add(months => $recur->{every})->truncate(to => "month");
|
$dt->add(months => $recur->{every})->truncate(to => "month");
|
||||||
|
|
||||||
# Test for quit
|
# Test for quit
|
||||||
if (($recur->{endAfter} && keys %date >= $recur->{endAfter}) || ($dt_end && $dt > $dt_end))
|
if (($recur->{endAfter} && keys %date >= $recur->{endAfter}) || ($dt_end && $dt > $dt_end)) {
|
||||||
{
|
|
||||||
last RECURRENCE;
|
last RECURRENCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -952,23 +906,19 @@ sub getRecurrenceDates {
|
||||||
next RECURRENCE;
|
next RECURRENCE;
|
||||||
}
|
}
|
||||||
####### yearday
|
####### yearday
|
||||||
elsif ($recur->{recurType} eq "yearDay")
|
elsif ($recur->{recurType} eq "yearDay") {
|
||||||
{
|
|
||||||
# For each month
|
# For each month
|
||||||
my $dt_month = $dt->clone;
|
my $dt_month = $dt->clone;
|
||||||
while ($dt->year eq $dt_month->year)
|
while ($dt->year eq $dt_month->year) {
|
||||||
{
|
|
||||||
my $mon = $dt_month->month_abbr;
|
my $mon = $dt_month->month_abbr;
|
||||||
if (grep /$mon/i, @{$recur->{months}})
|
if (grep /$mon/i, @{$recur->{months}}) {
|
||||||
{
|
|
||||||
# Pick out the correct day
|
# Pick out the correct day
|
||||||
my $startDate = $dt_month->year."-".$dt_month->month."-".$recur->{dayNumber};
|
my $startDate = $dt_month->year."-".$dt_month->month."-".$recur->{dayNumber};
|
||||||
|
|
||||||
my $dt_day = WebGUI::DateTime->new($self->session, $startDate." 00:00:00");
|
my $dt_day = WebGUI::DateTime->new($self->session, $startDate." 00:00:00");
|
||||||
|
|
||||||
# Only if today is not before the recurrence start
|
# Only if today is not before the recurrence start
|
||||||
if ($dt_day->clone->truncate(to => "day") >= $dt_start->clone->truncate(to=>"day"))
|
if ($dt_day->clone->truncate(to => "day") >= $dt_start->clone->truncate(to=>"day")) {
|
||||||
{
|
|
||||||
# If today is past the endDate, quit.
|
# If today is past the endDate, quit.
|
||||||
last RECURRENCE
|
last RECURRENCE
|
||||||
if ($recur->{endDate} && $dt_day > $dt_end);
|
if ($recur->{endDate} && $dt_day > $dt_end);
|
||||||
|
|
@ -990,8 +940,7 @@ sub getRecurrenceDates {
|
||||||
$dt->add(years => $recur->{every})->truncate(to => "year");
|
$dt->add(years => $recur->{every})->truncate(to => "year");
|
||||||
|
|
||||||
# Test for quit
|
# Test for quit
|
||||||
if (($recur->{endAfter} && keys %date >= $recur->{endAfter}) || ($dt_end && $dt > $dt_end))
|
if (($recur->{endAfter} && keys %date >= $recur->{endAfter}) || ($dt_end && $dt > $dt_end)) {
|
||||||
{
|
|
||||||
last RECURRENCE;
|
last RECURRENCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -999,25 +948,19 @@ sub getRecurrenceDates {
|
||||||
next RECURRENCE;
|
next RECURRENCE;
|
||||||
}
|
}
|
||||||
####### yearweek
|
####### yearweek
|
||||||
elsif ($recur->{recurType} eq "yearWeek")
|
elsif ($recur->{recurType} eq "yearWeek") {
|
||||||
{
|
|
||||||
# For each month
|
# For each month
|
||||||
my $dt_month = $dt->clone;
|
my $dt_month = $dt->clone;
|
||||||
while ($dt->year eq $dt_month->year)
|
while ($dt->year eq $dt_month->year) {
|
||||||
{
|
|
||||||
my $mon = $dt_month->month_abbr;
|
my $mon = $dt_month->month_abbr;
|
||||||
if (grep /$mon/i, @{$recur->{months}})
|
if (grep /$mon/i, @{$recur->{months}}) {
|
||||||
{
|
|
||||||
# For each week remaining in this month
|
# For each week remaining in this month
|
||||||
my $dt_week = $dt_month->clone;
|
my $dt_week = $dt_month->clone;
|
||||||
while ($dt_month->month eq $dt_week->month)
|
while ($dt_month->month eq $dt_week->month) {
|
||||||
{
|
|
||||||
my $week = int($dt_week->day_of_month / 7);
|
my $week = int($dt_week->day_of_month / 7);
|
||||||
|
|
||||||
if (grep /$weeks{$week}/i, @{$recur->{weeks}})
|
if (grep /$weeks{$week}/i, @{$recur->{weeks}}) {
|
||||||
{
|
for (0..6) { # Work through the week
|
||||||
for (0..6) # Work through the week
|
|
||||||
{
|
|
||||||
my $dt_day = $dt_week->clone->add(days => $_);
|
my $dt_day = $dt_week->clone->add(days => $_);
|
||||||
|
|
||||||
# If today is past the endDate, quit.
|
# If today is past the endDate, quit.
|
||||||
|
|
@ -1029,8 +972,7 @@ sub getRecurrenceDates {
|
||||||
|
|
||||||
my $today = $dayNames{lc $dt_day->day_name};
|
my $today = $dayNames{lc $dt_day->day_name};
|
||||||
|
|
||||||
if (grep /$today/i, @{$recur->{dayNames}})
|
if (grep /$today/i, @{$recur->{dayNames}}) {
|
||||||
{
|
|
||||||
### Add date
|
### Add date
|
||||||
$date{$dt_day->strftime('%F')}++;
|
$date{$dt_day->strftime('%F')}++;
|
||||||
}
|
}
|
||||||
|
|
@ -1046,12 +988,10 @@ sub getRecurrenceDates {
|
||||||
}
|
}
|
||||||
|
|
||||||
### If last is selected
|
### If last is selected
|
||||||
if (grep /last/, @{$recur->{weeks}})
|
if (grep /last/, @{$recur->{weeks}}) {
|
||||||
{
|
|
||||||
my $dt_last = $dt_month->clone->add(months => 1)->subtract(days => 1);
|
my $dt_last = $dt_month->clone->add(months => 1)->subtract(days => 1);
|
||||||
|
|
||||||
for (0..6)
|
for (0..6) {
|
||||||
{
|
|
||||||
my $dt_day = $dt_last->clone->subtract(days => $_);
|
my $dt_day = $dt_last->clone->subtract(days => $_);
|
||||||
|
|
||||||
# If today is past the endDate, try the next one
|
# If today is past the endDate, try the next one
|
||||||
|
|
@ -1060,11 +1000,9 @@ sub getRecurrenceDates {
|
||||||
|
|
||||||
my $today = $dayNames{lc $dt_day->day_name};
|
my $today = $dayNames{lc $dt_day->day_name};
|
||||||
|
|
||||||
if (grep /$today/i, @{$recur->{dayNames}})
|
if (grep /$today/i, @{$recur->{dayNames}}) {
|
||||||
{
|
|
||||||
### Add date
|
### Add date
|
||||||
$date{$dt_day->strftime('%F')}++;
|
$date{$dt_day->strftime('%F')}++;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# If occurrences is past the endAfter, quit
|
# If occurrences is past the endAfter, quit
|
||||||
|
|
@ -1083,8 +1021,7 @@ sub getRecurrenceDates {
|
||||||
$dt->add(years => $recur->{every})->truncate(to => "year");
|
$dt->add(years => $recur->{every})->truncate(to => "year");
|
||||||
|
|
||||||
# Test for quit
|
# Test for quit
|
||||||
if (($recur->{endAfter} && keys %date >= $recur->{endAfter}) || ($dt_end && $dt > $dt_end))
|
if (($recur->{endAfter} && keys %date >= $recur->{endAfter}) || ($dt_end && $dt > $dt_end)) {
|
||||||
{
|
|
||||||
last RECURRENCE;
|
last RECURRENCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1120,52 +1057,42 @@ sub getRecurrenceFromForm {
|
||||||
|
|
||||||
return () unless ($type && $type !~ /none/i);
|
return () unless ($type && $type !~ /none/i);
|
||||||
|
|
||||||
if ($type eq "daily")
|
if ($type eq "daily") {
|
||||||
{
|
if (lc($form->param("recurSubType")) eq "weekday") {
|
||||||
if (lc($form->param("recurSubType")) eq "weekday")
|
|
||||||
{
|
|
||||||
$recurrence{recurType} = "weekday";
|
$recurrence{recurType} = "weekday";
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
$recurrence{recurType} = "daily";
|
$recurrence{recurType} = "daily";
|
||||||
}
|
}
|
||||||
|
|
||||||
$recurrence{every} = $form->param("recurDay");
|
$recurrence{every} = $form->param("recurDay");
|
||||||
}
|
}
|
||||||
elsif ($type eq "weekly")
|
elsif ($type eq "weekly") {
|
||||||
{
|
|
||||||
$recurrence{recurType} = "weekly";
|
$recurrence{recurType} = "weekly";
|
||||||
$recurrence{dayNames} = [$form->param("recurWeekDay")];
|
$recurrence{dayNames} = [$form->param("recurWeekDay")];
|
||||||
$recurrence{every} = $form->param("recurWeek");
|
$recurrence{every} = $form->param("recurWeek");
|
||||||
}
|
}
|
||||||
elsif ($type eq "monthly")
|
elsif ($type eq "monthly") {
|
||||||
{
|
if (lc($form->param("recurSubType")) eq "monthweek") {
|
||||||
if (lc($form->param("recurSubType")) eq "monthweek")
|
|
||||||
{
|
|
||||||
$recurrence{recurType} = "monthWeek";
|
$recurrence{recurType} = "monthWeek";
|
||||||
$recurrence{weeks} = [$form->param("recurMonthWeekNumber")];
|
$recurrence{weeks} = [$form->param("recurMonthWeekNumber")];
|
||||||
$recurrence{dayNames} = [$form->param("recurMonthWeekDay")];
|
$recurrence{dayNames} = [$form->param("recurMonthWeekDay")];
|
||||||
}
|
}
|
||||||
elsif (lc($form->param("recurSubType")) eq "monthday")
|
elsif (lc($form->param("recurSubType")) eq "monthday") {
|
||||||
{
|
|
||||||
$recurrence{recurType} = "monthDay";
|
$recurrence{recurType} = "monthDay";
|
||||||
$recurrence{dayNumber} = $form->param("recurMonthDay");
|
$recurrence{dayNumber} = $form->param("recurMonthDay");
|
||||||
}
|
}
|
||||||
|
|
||||||
$recurrence{every} = $form->param("recurMonth");
|
$recurrence{every} = $form->param("recurMonth");
|
||||||
}
|
}
|
||||||
elsif ($type eq "yearly")
|
elsif ($type eq "yearly") {
|
||||||
{
|
if (lc($form->param("recurSubType")) eq "yearweek") {
|
||||||
if (lc($form->param("recurSubType")) eq "yearweek")
|
|
||||||
{
|
|
||||||
$recurrence{recurType} = "yearWeek";
|
$recurrence{recurType} = "yearWeek";
|
||||||
$recurrence{weeks} = [$form->param("recurYearWeekNumber")];
|
$recurrence{weeks} = [$form->param("recurYearWeekNumber")];
|
||||||
$recurrence{dayNames} = [$form->param("recurYearWeekDay")];
|
$recurrence{dayNames} = [$form->param("recurYearWeekDay")];
|
||||||
$recurrence{months} = [$form->param("recurYearWeekMonth")];
|
$recurrence{months} = [$form->param("recurYearWeekMonth")];
|
||||||
}
|
}
|
||||||
elsif (lc($form->param("recurSubType")) eq "yearday")
|
elsif (lc($form->param("recurSubType")) eq "yearday") {
|
||||||
{
|
|
||||||
$recurrence{recurType} = "yearDay";
|
$recurrence{recurType} = "yearDay";
|
||||||
$recurrence{dayNumber} = $form->param("recurYearDay");
|
$recurrence{dayNumber} = $form->param("recurYearDay");
|
||||||
$recurrence{months} = [$form->param("recurYearDayMonth")];
|
$recurrence{months} = [$form->param("recurYearDayMonth")];
|
||||||
|
|
@ -1177,12 +1104,10 @@ sub getRecurrenceFromForm {
|
||||||
$recurrence{every} ||= 1;
|
$recurrence{every} ||= 1;
|
||||||
$recurrence{startDate} = $form->param("recurStart");
|
$recurrence{startDate} = $form->param("recurStart");
|
||||||
|
|
||||||
if (lc $form->param("recurEndType") eq "date")
|
if (lc $form->param("recurEndType") eq "date") {
|
||||||
{
|
|
||||||
$recurrence{endDate} = $form->param("recurEndDate");
|
$recurrence{endDate} = $form->param("recurEndDate");
|
||||||
}
|
}
|
||||||
elsif (lc $form->param("recurEndType") eq "after")
|
elsif (lc $form->param("recurEndType") eq "after") {
|
||||||
{
|
|
||||||
$recurrence{endAfter} = $form->param("recurEndAfter");
|
$recurrence{endAfter} = $form->param("recurEndAfter");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1201,8 +1126,7 @@ Gets the related links.
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
sub getRelatedLinks
|
sub getRelatedLinks {
|
||||||
{
|
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
return () unless $self->get("relatedLinks");
|
return () unless $self->get("relatedLinks");
|
||||||
return split /\n+/, $self->get("relatedLinks");
|
return split /\n+/, $self->get("relatedLinks");
|
||||||
|
|
@ -1235,7 +1159,6 @@ sub getTemplateVars {
|
||||||
|
|
||||||
# Start date/time
|
# Start date/time
|
||||||
my $dtStart = $self->getDateTimeStart;
|
my $dtStart = $self->getDateTimeStart;
|
||||||
$dtStart->set_locale($i18n->get("locale") || "en_US");
|
|
||||||
|
|
||||||
$var{ "startDateSecond" } = sprintf "%02d", $dtStart->second;
|
$var{ "startDateSecond" } = sprintf "%02d", $dtStart->second;
|
||||||
$var{ "startDateMinute" } = sprintf "%02d", $dtStart->minute;
|
$var{ "startDateMinute" } = sprintf "%02d", $dtStart->minute;
|
||||||
|
|
@ -1257,7 +1180,6 @@ sub getTemplateVars {
|
||||||
|
|
||||||
# End date/time
|
# End date/time
|
||||||
my $dtEnd = $self->getDateTimeEnd;
|
my $dtEnd = $self->getDateTimeEnd;
|
||||||
$dtEnd->set_locale($i18n->get("locale") || "en_US");
|
|
||||||
|
|
||||||
$var{ "endDateSecond" } = sprintf "%02d", $dtEnd->second;
|
$var{ "endDateSecond" } = sprintf "%02d", $dtEnd->second;
|
||||||
$var{ "endDateMinute" } = sprintf "%02d", $dtEnd->minute;
|
$var{ "endDateMinute" } = sprintf "%02d", $dtEnd->minute;
|
||||||
|
|
@ -1277,14 +1199,14 @@ sub getTemplateVars {
|
||||||
$var{ "endDateHms" } = $dtEnd->hms;
|
$var{ "endDateHms" } = $dtEnd->hms;
|
||||||
$var{ "endDateEpoch" } = $dtEnd->epoch;
|
$var{ "endDateEpoch" } = $dtEnd->epoch;
|
||||||
|
|
||||||
|
$var{ "isAllDay" } = $self->isAllDay;
|
||||||
|
$var{ "isOneDay" } = $var{isAllDay} && $var{startDateDmy} eq $var{endDateDmy}
|
||||||
$var{isAllDay} = $self->isAllDay;
|
? 1 : 0
|
||||||
$var{isOneDay} = 1 if ($var{isAllDay} && $var{startDateDmy} eq $var{endDateDmy});
|
;
|
||||||
|
|
||||||
|
|
||||||
# Make a Friendly date span
|
# Make a Friendly date span
|
||||||
$var{dateSpan} = $var{startDateDayName}.", "
|
$var{dateSpan}
|
||||||
|
= $var{startDateDayName}.", "
|
||||||
. $var{startDateMonthName}." "
|
. $var{startDateMonthName}." "
|
||||||
. $var{startDateDayOfMonth}." "
|
. $var{startDateDayOfMonth}." "
|
||||||
. ( !$var{isAllDay} ? $var{startDateHour}.":".$var{startDateMinute}." ".$var{startDateM} : "" )
|
. ( !$var{isAllDay} ? $var{startDateHour}.":".$var{startDateMinute}." ".$var{startDateM} : "" )
|
||||||
|
|
@ -1297,11 +1219,11 @@ sub getTemplateVars {
|
||||||
: "");
|
: "");
|
||||||
|
|
||||||
# Make some friendly URLs
|
# Make some friendly URLs
|
||||||
|
my $urlStartParam = $dtStart->cloneToUserTimeZone->truncate(to => "day");
|
||||||
$var{ "url" } = $self->getUrl;
|
$var{ "url" } = $self->getUrl;
|
||||||
$dtStart->truncate(to=>"day");
|
$var{ "urlDay" } = $self->getParent->getUrl("type=day;start=".$urlStartParam);
|
||||||
$var{"urlDay"} = $self->getParent->getUrl("type=day;start=".$dtStart->toMysql);
|
$var{ "urlWeek" } = $self->getParent->getUrl("type=week;start=".$urlStartParam);
|
||||||
$var{"urlWeek"} = $self->getParent->getUrl("type=week;start=".$dtStart->toMysql);
|
$var{ "urlMonth" } = $self->getParent->getUrl("type=month;start=".$urlStartParam);
|
||||||
$var{"urlMonth"} = $self->getParent->getUrl("type=month;start=".$dtStart->toMysql);
|
|
||||||
$var{ "urlParent" } = $self->getParent->getUrl;
|
$var{ "urlParent" } = $self->getParent->getUrl;
|
||||||
$var{"urlSearch"} = $self->getParent->getSearchUrl;
|
$var{"urlSearch"} = $self->getParent->getSearchUrl;
|
||||||
|
|
||||||
|
|
@ -1348,26 +1270,21 @@ If the "print" form parameter is set, will prepare the print template.
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
sub prepareView
|
sub prepareView {
|
||||||
{
|
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my $parent = $self->getParent;
|
my $parent = $self->getParent;
|
||||||
my $templateId;
|
my $templateId;
|
||||||
|
|
||||||
if ($parent)
|
if ($parent) {
|
||||||
{
|
if ($self->session->form->param("print")) {
|
||||||
if ($self->session->form->param("print"))
|
|
||||||
{
|
|
||||||
$templateId = $parent->get("templateIdPrintEvent");
|
$templateId = $parent->get("templateIdPrintEvent");
|
||||||
$self->session->style->makePrintable(1);
|
$self->session->style->makePrintable(1);
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
$templateId = $parent->get("templateIdEvent");
|
$templateId = $parent->get("templateIdEvent");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
$templateId = "CalendarEvent000000001";
|
$templateId = "CalendarEvent000000001";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1427,7 +1344,7 @@ sub processPropertiesFromFormPost {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
### Form is verified, fix properties
|
### Form is verified
|
||||||
# Events are always hidden from navigation
|
# Events are always hidden from navigation
|
||||||
$self->update({ isHidden => 1 });
|
$self->update({ isHidden => 1 });
|
||||||
|
|
||||||
|
|
@ -1448,14 +1365,15 @@ sub processPropertiesFromFormPost {
|
||||||
}
|
}
|
||||||
|
|
||||||
# Fix times according to input (allday, timezone)
|
# Fix times according to input (allday, timezone)
|
||||||
|
# All day events have no time
|
||||||
if ($form->param("allday")) {
|
if ($form->param("allday")) {
|
||||||
$self->update({
|
$self->update({
|
||||||
startTime => undef,
|
startTime => undef,
|
||||||
endTime => undef,
|
endTime => undef,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
# Non-allday events need timezone conversion
|
||||||
else {
|
else {
|
||||||
# Convert timezone
|
|
||||||
my $tz = $self->session->user->profileField("timeZone");
|
my $tz = $self->session->user->profileField("timeZone");
|
||||||
|
|
||||||
my $dtStart
|
my $dtStart
|
||||||
|
|
@ -1495,11 +1413,15 @@ sub processPropertiesFromFormPost {
|
||||||
# Delete all old events and create new ones
|
# Delete all old events and create new ones
|
||||||
my $old_id = $self->get("recurId");
|
my $old_id = $self->get("recurId");
|
||||||
|
|
||||||
my $new_id = $self->generateRecurringEvents(\%recurrence_new);
|
# Set the new recurrence pattern
|
||||||
|
my $new_id = $self->setRecurrence(\%recurrence_new);
|
||||||
return ["There is something wrong with your recurrence pattern."]
|
return ["There is something wrong with your recurrence pattern."]
|
||||||
unless $new_id;
|
unless $new_id;
|
||||||
|
|
||||||
## Delete old events
|
# Generate the new recurring events
|
||||||
|
$self->generateRecurringEvents();
|
||||||
|
|
||||||
|
# Delete old events
|
||||||
my $events = $self->getLineage(["siblings"], {
|
my $events = $self->getLineage(["siblings"], {
|
||||||
returnObjects => 1,
|
returnObjects => 1,
|
||||||
includeOnlyClasses => ['WebGUI::Asset::Event'],
|
includeOnlyClasses => ['WebGUI::Asset::Event'],
|
||||||
|
|
@ -1509,14 +1431,10 @@ sub processPropertiesFromFormPost {
|
||||||
|
|
||||||
$_->purge for @$events;
|
$_->purge for @$events;
|
||||||
}
|
}
|
||||||
# Include / exclude keys
|
|
||||||
#elsif ()
|
|
||||||
#{
|
|
||||||
# # Delete / create necessary events
|
|
||||||
#
|
|
||||||
#}
|
|
||||||
# No change
|
|
||||||
else {
|
else {
|
||||||
|
# TODO: Give users a form property to decide what events to update
|
||||||
|
# TODO: Make a workflow activity to do this, so that updating
|
||||||
|
# 1 million events doesn't kill the server.
|
||||||
# Just update related events
|
# Just update related events
|
||||||
my %properties = %{ $self->get };
|
my %properties = %{ $self->get };
|
||||||
delete $properties{startDate};
|
delete $properties{startDate};
|
||||||
|
|
@ -1566,46 +1484,39 @@ Returns the ID of the row if success, otherwise returns 0.
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
sub setRecurrence
|
sub setRecurrence {
|
||||||
{
|
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my $vars = shift;
|
my $vars = shift;
|
||||||
|
|
||||||
my $type = $vars->{recurType} || return;
|
my $type = $vars->{recurType} || return;
|
||||||
my $pattern;
|
my $pattern;
|
||||||
|
|
||||||
if ($type eq "daily" || $type eq "weekday")
|
if ($type eq "daily" || $type eq "weekday") {
|
||||||
{
|
|
||||||
return 0 unless ($vars->{every});
|
return 0 unless ($vars->{every});
|
||||||
#(\d+)
|
#(\d+)
|
||||||
$pattern = $vars->{every};
|
$pattern = $vars->{every};
|
||||||
}
|
}
|
||||||
elsif ($type eq "weekly")
|
elsif ($type eq "weekly") {
|
||||||
{
|
|
||||||
return 0 unless ($vars->{every} && $vars->{dayNames});
|
return 0 unless ($vars->{every} && $vars->{dayNames});
|
||||||
#(\d+) ([umtwrfs]+)
|
#(\d+) ([umtwrfs]+)
|
||||||
$pattern = $vars->{every}." ".join("",@{$vars->{dayNames}});
|
$pattern = $vars->{every}." ".join("",@{$vars->{dayNames}});
|
||||||
}
|
}
|
||||||
elsif ($type eq "monthWeek")
|
elsif ($type eq "monthWeek") {
|
||||||
{
|
|
||||||
return 0 unless ($vars->{every} && $vars->{weeks} && $vars->{dayNames});
|
return 0 unless ($vars->{every} && $vars->{weeks} && $vars->{dayNames});
|
||||||
#(\d+) (first,second,third,fourth,last) ([umtwrfs]+)
|
#(\d+) (first,second,third,fourth,last) ([umtwrfs]+)
|
||||||
$pattern = $vars->{every}." ".join(",",@{$vars->{weeks}})." ".join("",@{$vars->{dayNames}});
|
$pattern = $vars->{every}." ".join(",",@{$vars->{weeks}})." ".join("",@{$vars->{dayNames}});
|
||||||
}
|
}
|
||||||
elsif ($type eq "monthDay")
|
elsif ($type eq "monthDay") {
|
||||||
{
|
|
||||||
return 0 unless ($vars->{every} && $vars->{dayNumber});
|
return 0 unless ($vars->{every} && $vars->{dayNumber});
|
||||||
#(\d+) on (\d+)
|
#(\d+) on (\d+)
|
||||||
$pattern = $vars->{every}." ".$vars->{dayNumber};
|
$pattern = $vars->{every}." ".$vars->{dayNumber};
|
||||||
}
|
}
|
||||||
elsif ($type eq "yearWeek")
|
elsif ($type eq "yearWeek") {
|
||||||
{
|
|
||||||
return 0 unless ($vars->{every} && $vars->{weeks} && $vars->{dayNames} && $vars->{months});
|
return 0 unless ($vars->{every} && $vars->{weeks} && $vars->{dayNames} && $vars->{months});
|
||||||
#(\d+) (first,second,third,fourth,last) ([umtwrfs]+)? (jan,feb,mar,apr,may,jun,jul,aug,sep,oct,nov,dec)
|
#(\d+) (first,second,third,fourth,last) ([umtwrfs]+)? (jan,feb,mar,apr,may,jun,jul,aug,sep,oct,nov,dec)
|
||||||
$pattern = $vars->{every}." ".join(",",@{$vars->{weeks}})." ".join("",@{$vars->{dayNames}})." ".join(",",@{$vars->{months}});
|
$pattern = $vars->{every}." ".join(",",@{$vars->{weeks}})." ".join("",@{$vars->{dayNames}})." ".join(",",@{$vars->{months}});
|
||||||
}
|
}
|
||||||
elsif ($type eq "yearDay")
|
elsif ($type eq "yearDay") {
|
||||||
{
|
|
||||||
return 0 unless ($vars->{every} && $vars->{dayNumber} && $vars->{months});
|
return 0 unless ($vars->{every} && $vars->{dayNumber} && $vars->{months});
|
||||||
#(\d+) on (\d+) (jan,feb,mar,apr,may,jun,jul,aug,sep,oct,nov,dec)
|
#(\d+) on (\d+) (jan,feb,mar,apr,may,jun,jul,aug,sep,oct,nov,dec)
|
||||||
$pattern = $vars->{every}." ".$vars->{dayNumber}." ".join(",",@{$vars->{months}});
|
$pattern = $vars->{every}." ".$vars->{dayNumber}." ".join(",",@{$vars->{months}});
|
||||||
|
|
@ -1613,12 +1524,10 @@ sub setRecurrence
|
||||||
|
|
||||||
|
|
||||||
my $end = undef;
|
my $end = undef;
|
||||||
if ($vars->{endAfter})
|
if ($vars->{endAfter}) {
|
||||||
{
|
|
||||||
$end = "after ".$vars->{endAfter};
|
$end = "after ".$vars->{endAfter};
|
||||||
}
|
}
|
||||||
elsif ($vars->{endDate})
|
elsif ($vars->{endDate}) {
|
||||||
{
|
|
||||||
$end = $vars->{endDate};
|
$end = $vars->{endDate};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1648,8 +1557,7 @@ Sets the event's related links.
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
sub setRelatedLinks
|
sub setRelatedLinks {
|
||||||
{
|
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my @links = @_;
|
my @links = @_;
|
||||||
|
|
||||||
|
|
@ -1670,8 +1578,7 @@ Returns the template to be viewed.
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
sub view
|
sub view {
|
||||||
{
|
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my $session = $self->session;
|
my $session = $self->session;
|
||||||
|
|
||||||
|
|
@ -1710,8 +1617,7 @@ Edit the event.
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
# Author's note: This sub is ugly and should be reformatted according to PBP
|
# Author's note: This sub is ugly and should be reformatted according to PBP
|
||||||
sub www_edit
|
sub www_edit {
|
||||||
{
|
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my $session = $self->session;
|
my $session = $self->session;
|
||||||
my $form = $self->session->form;
|
my $form = $self->session->form;
|
||||||
|
|
@ -1721,21 +1627,18 @@ sub www_edit
|
||||||
|
|
||||||
return $self->session->privilege->noAccess() unless $self->getParent->canAddEvent();
|
return $self->session->privilege->noAccess() unless $self->getParent->canAddEvent();
|
||||||
|
|
||||||
if ($func eq "add" || $form->param("assetId") eq "new")
|
if ($func eq "add" || $form->param("assetId") eq "new") {
|
||||||
{
|
$var->{"formHeader"}
|
||||||
$var->{"formHeader"} = WebGUI::Form::formHeader($session,
|
= WebGUI::Form::formHeader($session, {
|
||||||
{
|
|
||||||
action => $self->getParent->getUrl,
|
action => $self->getParent->getUrl,
|
||||||
})
|
})
|
||||||
. WebGUI::Form::hidden($self->session,
|
. WebGUI::Form::hidden($self->session, {
|
||||||
{
|
|
||||||
name => "assetId",
|
name => "assetId",
|
||||||
value => "new",
|
value => "new",
|
||||||
})
|
})
|
||||||
. WebGUI::Form::hidden($self->session,
|
. WebGUI::Form::hidden($self->session, {
|
||||||
{
|
|
||||||
name => "class",
|
name => "class",
|
||||||
value =>$self->session->form->process("class","className")
|
value => $self->session->form->process("class","className"),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
@ -1745,13 +1648,12 @@ sub www_edit
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
$var->{"formHeader"} .= WebGUI::Form::hidden($self->session,
|
$var->{"formHeader"}
|
||||||
{
|
.= WebGUI::Form::hidden($self->session, {
|
||||||
name => "func",
|
name => "func",
|
||||||
value => "editSave"
|
value => "editSave"
|
||||||
})
|
})
|
||||||
. WebGUI::Form::hidden($self->session,
|
. WebGUI::Form::hidden($self->session, {
|
||||||
{
|
|
||||||
name => "recurId",
|
name => "recurId",
|
||||||
value => $self->get("recurId"),
|
value => $self->get("recurId"),
|
||||||
});
|
});
|
||||||
|
|
@ -1761,8 +1663,8 @@ sub www_edit
|
||||||
|
|
||||||
###### Event Tab
|
###### Event Tab
|
||||||
# title AS long title
|
# title AS long title
|
||||||
$var->{"formTitle"} = WebGUI::Form::text($session,
|
$var->{"formTitle"}
|
||||||
{
|
= WebGUI::Form::text($session, {
|
||||||
name => "title",
|
name => "title",
|
||||||
value => $form->process("title") || $self->get("title"),
|
value => $form->process("title") || $self->get("title"),
|
||||||
});
|
});
|
||||||
|
|
@ -1784,8 +1686,8 @@ sub www_edit
|
||||||
});
|
});
|
||||||
|
|
||||||
# description
|
# description
|
||||||
$var->{"formDescription"}= WebGUI::Form::HTMLArea($session,
|
$var->{"formDescription"}
|
||||||
{
|
= WebGUI::Form::HTMLArea($session, {
|
||||||
name => "description",
|
name => "description",
|
||||||
value => $form->process("description") || $self->get("description"),
|
value => $form->process("description") || $self->get("description"),
|
||||||
});
|
});
|
||||||
|
|
@ -1865,8 +1767,8 @@ sub www_edit
|
||||||
: $self->isAllDay
|
: $self->isAllDay
|
||||||
;
|
;
|
||||||
|
|
||||||
$var->{"formTime"} =
|
$var->{"formTime"}
|
||||||
q|<input id="allday_yes" type="radio" name="allday" value="yes" |
|
= q|<input id="allday_yes" type="radio" name="allday" value="yes" |
|
||||||
. ($allday ? 'checked="checked"' : '')
|
. ($allday ? 'checked="checked"' : '')
|
||||||
. q| />
|
. q| />
|
||||||
<label for="allday_yes">No specific time (All day event)</label>
|
<label for="allday_yes">No specific time (All day event)</label>
|
||||||
|
|
@ -1882,8 +1784,8 @@ sub www_edit
|
||||||
. q|</div>|;
|
. q|</div>|;
|
||||||
|
|
||||||
# related links
|
# related links
|
||||||
$var->{"formRelatedLinks"} = WebGUI::Form::textarea($session,
|
$var->{"formRelatedLinks"}
|
||||||
{
|
= WebGUI::Form::textarea($session, {
|
||||||
name => "relatedLinks",
|
name => "relatedLinks",
|
||||||
value => $form->process("relatedLinks") || $self->get("relatedLinks"),
|
value => $form->process("relatedLinks") || $self->get("relatedLinks"),
|
||||||
});
|
});
|
||||||
|
|
@ -1895,8 +1797,8 @@ sub www_edit
|
||||||
my %recur = $self->getRecurrenceFromForm || $self->getRecurrence;
|
my %recur = $self->getRecurrenceFromForm || $self->getRecurrence;
|
||||||
$recur{every} ||= 1;
|
$recur{every} ||= 1;
|
||||||
|
|
||||||
$var->{"formRecurPattern"} =
|
$var->{"formRecurPattern"}
|
||||||
q|
|
= q|
|
||||||
<div id="recurPattern">
|
<div id="recurPattern">
|
||||||
<p><input type="radio" name="recurType" id="recurType_none" value="none" onclick="toggleRecur()" />
|
<p><input type="radio" name="recurType" id="recurType_none" value="none" onclick="toggleRecur()" />
|
||||||
<label for="recurType_none">None</label></p>
|
<label for="recurType_none">None</label></p>
|
||||||
|
|
@ -2026,15 +1928,16 @@ sub www_edit
|
||||||
|
|
||||||
|
|
||||||
# Start
|
# Start
|
||||||
$var->{"formRecurStart"} = WebGUI::Form::date($session,
|
$var->{"formRecurStart"}
|
||||||
{
|
= WebGUI::Form::date($session, {
|
||||||
name => "recurStart",
|
name => "recurStart",
|
||||||
value => $recur{startDate},
|
value => $recur{startDate},
|
||||||
defaultValue => $self->get("startDate"),
|
defaultValue => $self->get("startDate"),
|
||||||
});
|
});
|
||||||
|
|
||||||
# End
|
# End
|
||||||
$var->{"formRecurEnd"} = q|
|
$var->{"formRecurEnd"}
|
||||||
|
= q|
|
||||||
<div><input type="radio" name="recurEndType" id="recurEndType_none" value="none" |.(!$recur{endDate} && !$recur{endAfter} ? 'checked="checked"' : '').q|/>
|
<div><input type="radio" name="recurEndType" id="recurEndType_none" value="none" |.(!$recur{endDate} && !$recur{endAfter} ? 'checked="checked"' : '').q|/>
|
||||||
<label for="recurEndType_none">No end</label><br />
|
<label for="recurEndType_none">No end</label><br />
|
||||||
|
|
||||||
|
|
@ -2060,14 +1963,15 @@ sub www_edit
|
||||||
|
|
||||||
|
|
||||||
# Add button
|
# Add button
|
||||||
$var->{"formSave"} = WebGUI::Form::submit($session,
|
$var->{"formSave"}
|
||||||
{
|
= WebGUI::Form::submit($session, {
|
||||||
name => "save",
|
name => "save",
|
||||||
value => "save",
|
value => "save",
|
||||||
});
|
});
|
||||||
|
|
||||||
# Cancel button
|
# Cancel button
|
||||||
$var->{"formCancel"} = WebGUI::Form::button($session,
|
$var->{"formCancel"}
|
||||||
{
|
= WebGUI::Form::button($session, {
|
||||||
name => "cancel",
|
name => "cancel",
|
||||||
value => "cancel",
|
value => "cancel",
|
||||||
extras => 'onClick="window.history.go(-1)"',
|
extras => 'onClick="window.history.go(-1)"',
|
||||||
|
|
@ -2076,14 +1980,11 @@ sub www_edit
|
||||||
|
|
||||||
$var->{"formFooter"} .= <<'ENDJS';
|
$var->{"formFooter"} .= <<'ENDJS';
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
function toggleTimes()
|
function toggleTimes() {
|
||||||
{
|
if (document.getElementById("allday_no").checked) {
|
||||||
if (document.getElementById("allday_no").checked)
|
|
||||||
{
|
|
||||||
document.getElementById("times").style.display = "block";
|
document.getElementById("times").style.display = "block";
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
document.getElementById("times").style.display = "none";
|
document.getElementById("times").style.display = "none";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -2093,27 +1994,22 @@ sub www_edit
|
||||||
YAHOO.util.Event.on("allday_yes",'click',function(e) { toggleTimes(); });
|
YAHOO.util.Event.on("allday_yes",'click',function(e) { toggleTimes(); });
|
||||||
|
|
||||||
|
|
||||||
function toggleRecur()
|
function toggleRecur() {
|
||||||
{
|
|
||||||
document.getElementById("recurPattern_daily").style.display = "none";
|
document.getElementById("recurPattern_daily").style.display = "none";
|
||||||
document.getElementById("recurPattern_weekly").style.display = "none";
|
document.getElementById("recurPattern_weekly").style.display = "none";
|
||||||
document.getElementById("recurPattern_monthly").style.display = "none";
|
document.getElementById("recurPattern_monthly").style.display = "none";
|
||||||
document.getElementById("recurPattern_yearly").style.display = "none";
|
document.getElementById("recurPattern_yearly").style.display = "none";
|
||||||
|
|
||||||
if (document.getElementById("recurType_daily").checked)
|
if (document.getElementById("recurType_daily").checked) {
|
||||||
{
|
|
||||||
document.getElementById("recurPattern_daily").style.display = "block";
|
document.getElementById("recurPattern_daily").style.display = "block";
|
||||||
}
|
}
|
||||||
else if (document.getElementById("recurType_weekly").checked)
|
else if (document.getElementById("recurType_weekly").checked) {
|
||||||
{
|
|
||||||
document.getElementById("recurPattern_weekly").style.display = "block";
|
document.getElementById("recurPattern_weekly").style.display = "block";
|
||||||
}
|
}
|
||||||
else if (document.getElementById("recurType_monthly").checked)
|
else if (document.getElementById("recurType_monthly").checked) {
|
||||||
{
|
|
||||||
document.getElementById("recurPattern_monthly").style.display = "block";
|
document.getElementById("recurPattern_monthly").style.display = "block";
|
||||||
}
|
}
|
||||||
else if (document.getElementById("recurType_yearly").checked)
|
else if (document.getElementById("recurType_yearly").checked) {
|
||||||
{
|
|
||||||
document.getElementById("recurPattern_yearly").style.display = "block";
|
document.getElementById("recurPattern_yearly").style.display = "block";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -2124,8 +2020,7 @@ ENDJS
|
||||||
|
|
||||||
|
|
||||||
### Show any errors if necessary
|
### Show any errors if necessary
|
||||||
if ($self->session->stow->get("editFormErrors"))
|
if ($self->session->stow->get("editFormErrors")) {
|
||||||
{
|
|
||||||
my $errors = $self->session->stow->get("editFormErrors");
|
my $errors = $self->session->stow->get("editFormErrors");
|
||||||
push @{$var->{"formErrors"}}, { message => $_ }
|
push @{$var->{"formErrors"}}, { message => $_ }
|
||||||
for @{$errors};
|
for @{$errors};
|
||||||
|
|
@ -2136,13 +2031,13 @@ ENDJS
|
||||||
### Load the template
|
### Load the template
|
||||||
my $parent = $self->getParent;
|
my $parent = $self->getParent;
|
||||||
my $template;
|
my $template;
|
||||||
if ($parent)
|
if ($parent) {
|
||||||
{
|
$template
|
||||||
$template = WebGUI::Asset::Template->new($session,$parent->get("templateIdEventEdit"));
|
= WebGUI::Asset::Template->new($session,$parent->get("templateIdEventEdit"));
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
$template
|
||||||
$template = WebGUI::Asset::Template->new($session,"CalendarEventEdit00001");
|
= WebGUI::Asset::Template->new($session,"CalendarEventEdit00001");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue