diff --git a/lib/WebGUI/Asset/Event.pm b/lib/WebGUI/Asset/Event.pm index f205f533b..ef041918f 100644 --- a/lib/WebGUI/Asset/Event.pm +++ b/lib/WebGUI/Asset/Event.pm @@ -45,88 +45,87 @@ use WebGUI::DateTime; #################################################################### sub definition { - my $class = shift; - my $session = shift; - my $definition = shift; - - my $i18n = WebGUI::International->new($session, 'Asset_Event'); - - my $dt = WebGUI::DateTime->new($session, time); - - ### Set up list options ### - - - - ### Build properties hash ### - my %properties; - tie %properties, 'Tie::IxHash'; - %properties = ( - - ##### DEFAULTS ##### - 'description' => { - fieldType => "HTMLArea", - defaultValue => "", - }, - 'startDate' => { - fieldType => "Date", - defaultValue => $dt->toMysqlDate, - }, - 'endDate' => { - fieldType => "Date", - defaultValue => $dt->toMysqlDate, - }, - 'startTime' => { - fieldType => "TimeField", - defaultValue => $dt->toMysqlTime, - }, - 'endTime' => { - fieldType => "TimeField", - defaultValue => $dt->toMysqlTime, - }, - - 'recurId' => { - fieldType => "Text", - defaultValue => undef, - }, - - 'relatedLinks' => { - fieldType => "Textarea", - defaultValue => undef, - }, - 'location' => { - fieldType => "Text", - defaultValue => undef, - }, - 'feedId' => { - fieldType => "Text", - defaultValue => undef, - }, - 'feedUid' => { - fieldType => "Text", - defaultValue => undef, - }, - ); - - - ### Add user defined fields - for my $num (1..5) - { - $properties{"UserDefined".$num} = { - fieldType => "text", - defaultValue => "", - }; - } - - - push(@{$definition}, { - assetName =>$i18n->get('assetName'), - icon =>'calendar.gif', - tableName =>'Event', - className =>'WebGUI::Asset::Event', - properties =>\%properties - }); - - return $class->SUPER::definition($session, $definition); + my $class = shift; + my $session = shift; + my $definition = shift; + + my $i18n = WebGUI::International->new($session, 'Asset_Event'); + + my $dt = WebGUI::DateTime->new($session, time); + + ### Set up list options ### + + + + ### Build properties hash ### + my %properties; + tie %properties, 'Tie::IxHash'; + %properties = ( + + ##### DEFAULTS ##### + 'description' => { + fieldType => "HTMLArea", + defaultValue => "", + }, + 'startDate' => { + fieldType => "Date", + defaultValue => $dt->toMysqlDate, + }, + 'endDate' => { + fieldType => "Date", + defaultValue => $dt->toMysqlDate, + }, + 'startTime' => { + fieldType => "TimeField", + defaultValue => $dt->toMysqlTime, + }, + 'endTime' => { + fieldType => "TimeField", + defaultValue => $dt->toMysqlTime, + }, + + 'recurId' => { + fieldType => "Text", + defaultValue => undef, + }, + + 'relatedLinks' => { + fieldType => "Textarea", + defaultValue => undef, + }, + 'location' => { + fieldType => "Text", + defaultValue => undef, + }, + 'feedId' => { + fieldType => "Text", + defaultValue => undef, + }, + 'feedUid' => { + fieldType => "Text", + defaultValue => undef, + }, + ); + + + ### Add user defined fields + for my $num (1..5) { + $properties{"UserDefined".$num} = { + fieldType => "text", + defaultValue => "", + }; + } + + + push(@{$definition}, { + assetName => $i18n->get('assetName'), + icon => 'calendar.gif', + tableName => 'Event', + className => 'WebGUI::Asset::Event', + properties => \%properties + }); + + return $class->SUPER::definition($session, $definition); } @@ -138,16 +137,13 @@ sub definition { Returns true if a user can add this asset. - - =cut -sub canAdd -{ - my $self = shift; - my $session = shift; - - return $session->user->isInGroup($self->getParent->get("groupIdEventEdit")); +sub canAdd { + my $self = shift; + my $session = shift; + + return $session->user->isInGroup($self->getParent->get("groupIdEventEdit")); } @@ -163,12 +159,11 @@ Returns true if a user can edit this asset. =cut -sub canEdit -{ - my $self = shift; - my $session = $self->session; - - return $session->user->isInGroup($self->getParent->get("groupIdEventEdit")); +sub canEdit { + my $self = shift; + my $session = $self->session; + + return $session->user->isInGroup($self->getParent->get("groupIdEventEdit")); } @@ -191,51 +186,50 @@ used for generating future occurrences of events that don't end. =cut -sub generateRecurringEvents -{ - my $self = shift; - my $recur = shift; - my $parent = $self->getParent; - my $id; - - if ($recur) - { - $id = $self->setRecurrence($recur); - return () unless $id; - } - else - { - $id = $self->get("recurId"); - $recur = {$self->getRecurrence}; - } - - my $properties = {%{$self->get}}; - $properties->{recurId} = $id; - - # Get the distance between the event startDate and endDate - my $duration_days = 0; - - my $event_start = WebGUI::DateTime->new($self->session, delete($properties->{startDate})." 00:00:00"); - my $event_end = WebGUI::DateTime->new($self->session, delete($properties->{endDate})." 00:00:00"); - $duration_days = $event_end->subtract_datetime($event_start)->days; - - my @dates = $self->getRecurrenceDates($recur); - - for my $date (@dates) - { - my $dt = WebGUI::DateTime->new($self->session, $date." 00:00:00"); - - ### TODO: Only generate if the recurId does not exist on this day - $properties->{startDate} = $dt->strftime('%F'); - $properties->{endDate} = $dt->clone->add(days => $duration_days)->strftime('%F'); - - - my $newEvent = $parent->addChild($properties); - $newEvent->requestAutoCommit; - - } - - return 1; +sub generateRecurringEvents { + my $self = shift; + my $recur = shift; + my $parent = $self->getParent; + my $id; + + if ($recur) { + $id = $self->setRecurrence($recur); + return () unless $id; + } + else { + $id = $self->get("recurId"); + $recur = {$self->getRecurrence}; + } + + my $properties = {%{$self->get}}; + $properties->{recurId} = $id; + + # Get the distance between the event startDate and endDate + # Only days, since event recurrence only changes the Date the event occurs, not + # the time. + my $duration_days = 0; + + my $event_start + = WebGUI::DateTime->new($self->session, delete($properties->{startDate})." 00:00:00"); + my $event_end + = WebGUI::DateTime->new($self->session, delete($properties->{endDate})." 00:00:00"); + $duration_days + = $event_end->subtract_datetime($event_start)->days; + + my @dates = $self->getRecurrenceDates($recur); + + for my $date (@dates) { + my $dt = WebGUI::DateTime->new($self->session, $date." 00:00:00"); + + ### TODO: Only generate if the recurId does not exist on this day + $properties->{startDate} = $dt->strftime('%F'); + $properties->{endDate} = $dt->clone->add(days => $duration_days)->strftime('%F'); + + my $newEvent = $parent->addChild($properties); + $newEvent->requestAutoCommit; + } + + return 1; } @@ -252,8 +246,8 @@ By specifying this method, you activate this feature. =cut sub getAutoCommitWorkflowId { - my $self = shift; - return "pbworkflow000000000003"; + my $self = shift; + return "pbworkflow000000000003"; } @@ -272,32 +266,27 @@ adjusted. =cut -sub getDateTimeStart -{ - my $self = shift; - my $date = $self->get("startDate"); - my $time = $self->get("startTime"); - my $tz = $self->session->user->profileField("timeZone"); - - #$self->session->errorHandler->warn($self->getId.":: Date: $date -- Time: $time"); - unless ($date) - { - $self->session->errorHandler->warn("This event (".$self->get("assetId").") has no date."); - return; - } - - - if ($time) - { - my $dt = WebGUI::DateTime->new($self->session, $date." ".$time); - $dt->set_time_zone($tz); - return $dt; - } - else - { - my $dt = WebGUI::DateTime->new($self->session, $date." 00:00:00"); - return $dt; - } +sub getDateTimeStart { + my $self = shift; + my $date = $self->get("startDate"); + my $time = $self->get("startTime"); + my $tz = $self->session->user->profileField("timeZone"); + + #$self->session->errorHandler->warn($self->getId.":: Date: $date -- Time: $time"); + if (!$date) { + $self->session->errorHandler->warn("This event (".$self->get("assetId").") has no date."); + return; + } + + if ($time) { + my $dt = WebGUI::DateTime->new($self->session, $date." ".$time); + $dt->set_time_zone($tz); + return $dt; + } + else { + my $dt = WebGUI::DateTime->new($self->session, $date." 00:00:00"); + return $dt; + } } @@ -316,32 +305,28 @@ adjusted. =cut -sub getDateTimeEnd -{ - my $self = shift; - my $date = $self->get("endDate"); - my $time = $self->get("endTime"); - my $tz = $self->session->user->profileField("timeZone"); - - #$self->session->errorHandler->warn($self->getId.":: Date: $date -- Time: $time"); - unless ($date) - { - $self->session->errorHandler->warn("This event (".$self->get("assetId").") has no date."); - return; - } - - - if ($time) - { - my $dt = WebGUI::DateTime->new($self->session, $date." ".$time); - $dt->set_time_zone($tz); - return $dt; - } - else - { - my $dt = WebGUI::DateTime->new($self->session, $date." 23:59:59"); - return $dt; - } +sub getDateTimeEnd { + my $self = shift; + my $date = $self->get("endDate"); + my $time = $self->get("endTime"); + my $tz = $self->session->user->profileField("timeZone"); + + #$self->session->errorHandler->warn($self->getId.":: Date: $date -- Time: $time"); + if (!$date) { + $self->session->errorHandler->warn("This event (".$self->get("assetId").") has no date."); + return; + } + + + if ($time) { + my $dt = WebGUI::DateTime->new($self->session, $date." ".$time); + $dt->set_time_zone($tz); + return $dt; + } + else { + my $dt = WebGUI::DateTime->new($self->session, $date." 23:59:59"); + return $dt; + } } @@ -357,40 +342,48 @@ Event object. =cut -sub getEventNext -{ - my $self = shift; - my $db = $self->session->db; - - my $where = 'Event.startDate > "'.$self->get("startDate").'" || (Event.startDate = "'.$self->get("startDate").'" && '; - - # All day events must either look for null time or greater than 00:00:00 - if ($self->isAllDay) - { - $where .= "(Event.startTime IS NULL " - . "&& assetData.title > ".$db->quote($self->get("title")).") " - . "|| Event.startTime >= '00:00:00'"; - } - # Non all-day events must look for greater than time - else - { - $where .= "(Event.startTime = '".$self->get("startTime")."' " - . "&& assetData.title > ".$db->quote($self->get("title")).")" - . "|| Event.startTime > '".$self->get("startTime")."'"; - } - $where .= ")"; - - my $events = $self->getLineage(['siblings'], - { - #returnObjects => 1, - includeOnlyClasses => ['WebGUI::Asset::Event'], - joinClass => 'WebGUI::Asset::Event', - orderByClause => 'Event.startDate, Event.startTime, Event.endDate, Event.endDate, assetData.title, assetData.assetId', - whereClause => $where, - limit => 1, - }); - - return WebGUI::Asset->newByDynamicClass($self->session,$events->[0]); +sub getEventNext { + my $self = shift; + my $db = $self->session->db; + + my $where = 'Event.startDate > "'.$self->get("startDate").'"' + . '|| (Event.startDate = "'.$self->get("startDate").'" && '; + + # All day events must either look for null time or greater than 00:00:00 + if ($self->isAllDay) { + $where .= "(Event.startTime IS NULL " + . "&& assetData.title > ".$db->quote($self->get("title")).") " + . "|| Event.startTime >= '00:00:00'"; + } + # Non all-day events must look for greater than time + else + { + $where .= "(Event.startTime = '".$self->get("startTime")."' " + . "&& assetData.title > ".$db->quote($self->get("title")).")" + . "|| Event.startTime > '".$self->get("startTime")."'"; + } + $where .= ")"; + + + my @orderByColumns = ( + 'Event.startDate', + 'Event.startTime', + 'Event.endDate', + 'Event.endDate', + 'assetData.title', + 'assetData.assetId', + ); + + my $events = $self->getLineage(['siblings'], { + #returnObjects => 1, + includeOnlyClasses => ['WebGUI::Asset::Event'], + joinClass => 'WebGUI::Asset::Event', + orderByClause => join(",", @orderByColumns), + whereClause => $where, + limit => 1, + }); + + return WebGUI::Asset->newByDynamicClass($self->session,$events->[0]); } @@ -407,39 +400,45 @@ object. =cut -sub getEventPrev -{ - my $self = shift; - my $db = $self->session->db; - - my $where = 'Event.startDate < "'.$self->get("startDate").'" || (Event.startDate = "'.$self->get("startDate").'" && '; - - # All day events must either look for null time or greater than 00:00:00 - if ($self->isAllDay) - { - $where .= "(Event.startTime IS NULL " - . "&& assetData.title < ".$db->quote($self->get("title")).")"; - } - # Non all-day events must look for greater than time - else - { - $where .= "(Event.startTime = '".$self->get("startTime")."' " - . "&& assetData.title < ".$db->quote($self->get("title")).")" - . "|| Event.startTime < '".$self->get("startTime")."'"; - } - $where .= ")"; - - my $events = $self->getLineage(['siblings'], - { - #returnObjects => 1, - includeOnlyClasses => ['WebGUI::Asset::Event'], - joinClass => 'WebGUI::Asset::Event', - orderByClause => 'Event.startDate DESC, Event.startTime DESC, Event.endDate DESC, Event.endDate DESC, assetData.title DESC, assetData.assetId DESC', - whereClause => $where, - limit => 1, - }); - - return WebGUI::Asset->newByDynamicClass($self->session,$events->[0]); +sub getEventPrev { + my $self = shift; + my $db = $self->session->db; + + my $where = 'Event.startDate < "'.$self->get("startDate").'"' + . '|| (Event.startDate = "'.$self->get("startDate").'" && '; + + # All day events must either look for null time or greater than 00:00:00 + if ($self->isAllDay) { + $where .= "(Event.startTime IS NULL " + . "&& assetData.title < ".$db->quote($self->get("title")).")"; + } + # Non all-day events must look for greater than time + else { + $where .= "(Event.startTime = '".$self->get("startTime")."' " + . "&& assetData.title < ".$db->quote($self->get("title")).")" + . "|| Event.startTime < '".$self->get("startTime")."'"; + } + $where .= ")"; + + my @orderByColumns = ( + 'Event.startDate DESC', + 'Event.startTime DESC', + 'Event.endDate DESC', + 'Event.endDate DESC', + 'assetData.title DESC', + 'assetData.assetId DESC', + ); + + my $events = $self->getLineage(['siblings'], { + #returnObjects => 1, + includeOnlyClasses => ['WebGUI::Asset::Event'], + joinClass => 'WebGUI::Asset::Event', + orderByClause => join(",",@orderByColumns), + whereClause => $where, + limit => 1, + }); + + return WebGUI::Asset->newByDynamicClass($self->session,$events->[0]); } @@ -457,26 +456,23 @@ Otherwise returns an iCalendar Date/Time string in the UTC time zone. =cut -sub getIcalStart -{ - my $self = shift; - - if ($self->isAllDay) - { - my $date = $self->get("startDate"); - $date =~ s/\D//g; - return $date; - } - else - { - my $date = $self->get("startDate"); - my $time = $self->get("startTime"); - - $date =~ s/\D//g; - $time =~ s/\D//g; - - return $date."T".$time."Z"; - } +sub getIcalStart { + my $self = shift; + + if ($self->isAllDay) { + my $date = $self->get("startDate"); + $date =~ s/\D//g; + return $date; + } + else { + my $date = $self->get("startDate"); + my $time = $self->get("startTime"); + + $date =~ s/\D//g; + $time =~ s/\D//g; + + return $date."T".$time."Z"; + } } @@ -494,26 +490,23 @@ Otherwise returns an iCalendar Date/Time string in the UTC time zone. =cut -sub getIcalEnd -{ - my $self = shift; - - if ($self->isAllDay) - { - my $date = $self->get("endDate"); - $date =~ s/\D//g; - return $date; - } - else - { - my $date = $self->get("endDate"); - my $time = $self->get("endTime"); - - $date =~ s/\D//g; - $time =~ s/\D//g; - - return $date."T".$time."Z"; - } +sub getIcalEnd { + my $self = shift; + + if ($self->isAllDay) { + my $date = $self->get("endDate"); + $date =~ s/\D//g; + return $date; + } + else { + my $date = $self->get("endDate"); + my $time = $self->get("endTime"); + + $date =~ s/\D//g; + $time =~ s/\D//g; + + return $date."T".$time."Z"; + } } @@ -560,13 +553,13 @@ The number of (days, weeks, months, years) between each recurrence. A list of day names that this event recurs on. - u - Sunday - m - Monday - t - Tuesday - w - Wednesday - r - Thursday - f - Friday - s - Saturday + u - Sunday + m - Monday + t - Tuesday + w - Wednesday + r - Thursday + f - Friday + s - Saturday =item dayNumber @@ -586,95 +579,91 @@ A list of weeks that this event recurs on A list of months that this event recurs on - jan - January - feb - February - mar - March - apr - April - may - May - jun - June - jul - July - aug - August - sep - September - oct - October - nov - November - dec - December + jan - January + feb - February + mar - March + apr - April + may - May + jun - June + jul - July + aug - August + sep - September + oct - October + nov - November + dec - December =back =cut -sub getRecurrence -{ - my $self = shift; - use Data::Dumper; - #$self->session->errorHandler->warn("recurId: ".$self->get("recurId")); - return () unless $self->get("recurId"); - - my %data = $self->session->db->quickHash("select * from Event_recur where recurId=?",[$self->get("recurId")]); - my %recurrence = ( - recurType => $data{recurType}, - ); - - - # We do not need the recurId, and in fact will screw up our later comparisons - delete $data{"recurId"}; - - my $type = lc $data{"recurType"}; - if ($type eq "daily" || $type eq "weekday") - { - $recurrence{every} = $data{pattern}; - } - elsif ($type eq "weekly") - { - #(\d+) ([umtwrfs]+) - $data{pattern} =~ /(\d+) ([umtwrfs]+)/; - $recurrence{every} = $1; - $recurrence{dayNames} = [split //, $2]; - } - elsif ($type eq "monthweek") - { - #(\d+) (first,second,third,fourth,last) ([umtwrfs]+) - $data{pattern} =~ /(\d+) ([a-z,]+) ([umtwrfs]+)/; - $recurrence{every} = $1; - $recurrence{weeks} = [split /,/, $2]; - $recurrence{dayNames} = [split //, $3]; - } - elsif ($type eq "monthday") - { - #(\d+) on (\d+) - $data{pattern} =~ /(\d+) (\d+)/; - $recurrence{every} = $1; - $recurrence{dayNumber} = $2; - } - elsif ($type eq "yearweek") - { - #(\d+) (first,second,third,fourth,last) ([umtwrfs]+)? (jan,feb,mar,apr,may,jun,jul,aug,sep,oct,nov,dec) - $data{pattern} =~ /(\d+) ([a-z,]+) ([umtwrfs]+) ([a-z,]+)/; - $recurrence{every} = $1; - $recurrence{weeks} = [split /,/, $2]; - $recurrence{dayNames} = [split //, $3]; - $recurrence{months} = [split /,/, $4]; - } - elsif ($type eq "yearday") - { - #(\d+) on (\d+) (jan,feb,mar,apr,may,jun,jul,aug,sep,oct,nov,dec) - $data{pattern} =~ /(\d+) (\d+) ([a-z,]+)/; - $recurrence{every} = $1; - $recurrence{dayNumber} = $2; - $recurrence{months} = [split /,/, $3]; - } - - $recurrence{startDate} = $data{startDate}; - if ($data{endDate} && $data{endDate} =~ /^after (\d+)/i) - { - $recurrence{endAfter} = $1; - } - elsif ($data{endDate}) - { - $recurrence{endDate} = $data{endDate}; - } - - return %recurrence; +sub getRecurrence { + my $self = shift; + #use Data::Dumper; + #$self->session->errorHandler->warn("recurId: ".$self->get("recurId")); + return () unless $self->get("recurId"); + + my %data + = $self->session->db->quickHash( + "select * from Event_recur where recurId=?", + [$self->get("recurId")] + ); + + my %recurrence = ( + recurType => $data{recurType}, + ); + + + # We do not need the recurId, and in fact will screw up our later comparisons + delete $data{"recurId"}; + + my $type = lc $data{"recurType"}; + if ($type eq "daily" || $type eq "weekday") { + $recurrence{every} = $data{pattern}; + } + elsif ($type eq "weekly") { + #(\d+) ([umtwrfs]+) + $data{pattern} =~ /(\d+) ([umtwrfs]+)/; + $recurrence{every} = $1; + $recurrence{dayNames} = [split //, $2]; + } + elsif ($type eq "monthweek") { + #(\d+) (first,second,third,fourth,last) ([umtwrfs]+) + $data{pattern} =~ /(\d+) ([a-z,]+) ([umtwrfs]+)/; + $recurrence{every} = $1; + $recurrence{weeks} = [split /,/, $2]; + $recurrence{dayNames} = [split //, $3]; + } + elsif ($type eq "monthday") { + #(\d+) on (\d+) + $data{pattern} =~ /(\d+) (\d+)/; + $recurrence{every} = $1; + $recurrence{dayNumber} = $2; + } + elsif ($type eq "yearweek") { + #(\d+) (first,second,third,fourth,last) ([umtwrfs]+)? (jan,feb,mar,apr,may,jun,jul,aug,sep,oct,nov,dec) + $data{pattern} =~ /(\d+) ([a-z,]+) ([umtwrfs]+) ([a-z,]+)/; + $recurrence{every} = $1; + $recurrence{weeks} = [split /,/, $2]; + $recurrence{dayNames} = [split //, $3]; + $recurrence{months} = [split /,/, $4]; + } + elsif ($type eq "yearday") { + #(\d+) on (\d+) (jan,feb,mar,apr,may,jun,jul,aug,sep,oct,nov,dec) + $data{pattern} =~ /(\d+) (\d+) ([a-z,]+)/; + $recurrence{every} = $1; + $recurrence{dayNumber} = $2; + $recurrence{months} = [split /,/, $3]; + } + + $recurrence{startDate} = $data{startDate}; + if ($data{endDate} && $data{endDate} =~ /^after (\d+)/i) { + $recurrence{endAfter} = $1; + } + elsif ($data{endDate}) { + $recurrence{endDate} = $data{endDate}; + } + + return %recurrence; } @@ -692,396 +681,399 @@ DateTime::Event::ICal instead. =cut -sub getRecurrenceDates -{ - my $self = shift; - my $recur = shift; - - my %date; - - return undef unless $recur->{recurType}; - - my %dayNames = ( - monday => "m", - tuesday => "t", - wednesday => "w", - thursday => "r", - friday => "f", - saturday => "s", - sunday => "u", - ); - my %weeks = ( - 0 => "first", - 1 => "second", - 2 => "third", - 3 => "fourth", - 4 => "fifth", - ); - - - my $dt = WebGUI::DateTime->new($self->session, $recur->{startDate}." 00:00:00"); - my $dt_start = $dt->clone; # Keep track of the initial start date - my $dt_end = WebGUI::DateTime->new($self->session, $recur->{endDate}." 00:00:00") - if $recur->{endDate}; - # Set an end for events with no end - #!!! TODO !!! - Get the appropriate configuration - $dt_end = $dt->clone->add(years=>2) - if (!$recur->{endDate} && !$recur->{endAfter}); - - - RECURRENCE: while (1) - { - ####### daily - if ($recur->{recurType} eq "daily") - { - ### Add date - $date{$dt->strftime('%F')}++; - - # Add interval - $dt->add(days => $recur->{every}); - - # Test for quit - if (($recur->{endAfter} && keys %date >= $recur->{endAfter}) || ($dt_end && $dt > $dt_end)) - { - last RECURRENCE; - } - - # Next - next RECURRENCE; - } - ####### weekday - elsif ($recur->{recurType} eq "weekday") - { - my $today = $dt->day_name; - - # If today is not a weekday - unless (grep /$today/i,qw(monday tuesday wednesday thursday friday)) - { - # Add a day - $dt->add(days => 1); - - # Test for quit - if (($recur->{endAfter} && keys %date >= $recur->{endAfter}) || ($dt_end && $dt > $dt_end)) - { - last RECURRENCE; - } - - # next - next RECURRENCE; - } - else - { - ### Add date - $date{$dt->strftime('%F')}++; - - $dt->add(days => $recur->{every}); - - # Test for quit - if (($recur->{endAfter} && keys %date >= $recur->{endAfter}) || ($dt_end && $dt > $dt_end)) - { - last RECURRENCE; - } - - # Next - next RECURRENCE; - } - } - ####### weekly - elsif ($recur->{recurType} eq "weekly") - { - for (0..6) # Work through the week - { - my $dt_day = $dt->clone->add(days => $_); - - # If today is past the endDate, quit. - last RECURRENCE - if ($recur->{endDate} && $dt_day > $dt_end); - - my $today = $dayNames{lc $dt_day->day_name}; - - if (grep /$today/i, @{$recur->{dayNames}}) - { - ### Add date - $date{$dt_day->strftime('%F')}++; - } - - # If occurrences is past the endAfter, quit - last RECURRENCE - if ($recur->{endAfter} && keys %date >= $recur->{endAfter}); - } - - # Add interval - $dt->add(weeks => $recur->{every}); - - # Test for quit - if (($recur->{endAfter} && keys %date >= $recur->{endAfter}) || ($dt_end && $dt > $dt_end)) - { - last RECURRENCE; - } - - # Next - next RECURRENCE; - - } - ####### monthday - elsif ($recur->{recurType} eq "monthDay") - { - # Pick out the correct day - my $startDate = $dt->year."-".$dt->month."-".$recur->{dayNumber}; - - my $dt_day = WebGUI::DateTime->new($self->session, $startDate." 00:00:00"); - - # Only if today is not before the recurrence start - if ($dt_day->clone->truncate(to => "day") >= $dt_start->clone->truncate(to=>"day")) - { - # If today is past the endDate, quit. - last RECURRENCE - if ($recur->{endDate} && $dt_day > $dt_end); - - ### Add date - $date{$dt_day->strftime('%F')}++; - } - - # Add interval - $dt->add(months => $recur->{every})->truncate(to => "month"); - - # Test for quit - if (($recur->{endAfter} && keys %date >= $recur->{endAfter}) || ($dt_end && $dt > $dt_end)) - { - last RECURRENCE; - } - - # Next - next RECURRENCE; - } - ###### monthweek - elsif ($recur->{recurType} eq "monthWeek") - { - # For each week remaining in this month - my $dt_week = $dt->clone; - while ($dt->month eq $dt_week->month) - { - my $week = int($dt_week->day_of_month / 7); - - if (grep /$weeks{$week}/i, @{$recur->{weeks}}) - { - # Pick out the correct days - for (0..6) # Work through the week - { - my $dt_day = $dt_week->clone->add(days => $_); - - # If today is past the endDate, quit. - last RECURRENCE - if ($recur->{endDate} && $dt_day > $dt_end); - - # If today isn't in the month, stop looking - last if ($dt_day->month ne $dt->month); - - my $today = $dayNames{lc $dt_day->day_name}; - - if (grep /$today/i, @{$recur->{dayNames}}) - { - ### Add date - $date{$dt_day->strftime('%F')}++; - } - - # If occurrences is past the endAfter, quit - last RECURRENCE - if ($recur->{endAfter} && keys %date >= $recur->{endAfter}); - } - } - - # Add a week - $dt_week->add(days => 7); - } - - ### If last is selected - if (grep /last/, @{$recur->{weeks}}) - { - my $dt_last = $dt->clone->truncate(to => "month") - ->add(months => 1)->subtract(days => 1); - - for (0..6) - { - my $dt_day = $dt_last->clone->subtract(days => $_); - - # If today is before the startDate, don't even bother - last if ($dt_day < $dt_start); - # If today is past the endDate, try the next one - next if ($recur->{endDate} && $dt_day > $dt_end); - - my $today = $dayNames{lc $dt_day->day_name}; - - if (grep /$today/i, @{$recur->{dayNames}}) - { - ### Add date - $date{$dt_day->strftime('%F')}++; - - } - - # If occurrences is past the endAfter, quit - last RECURRENCE - if ($recur->{endAfter} && keys %date >= $recur->{endAfter}); - } - } - - - # Add interval - $dt->add(months => $recur->{every})->truncate(to => "month"); - - # Test for quit - if (($recur->{endAfter} && keys %date >= $recur->{endAfter}) || ($dt_end && $dt > $dt_end)) - { - last RECURRENCE; - } - - # Next - next RECURRENCE; - } - ####### yearday - elsif ($recur->{recurType} eq "yearDay") - { - # For each month - my $dt_month = $dt->clone; - while ($dt->year eq $dt_month->year) - { - my $mon = $dt_month->month_abbr; - if (grep /$mon/i, @{$recur->{months}}) - { - # Pick out the correct day - my $startDate = $dt_month->year."-".$dt_month->month."-".$recur->{dayNumber}; - - my $dt_day = WebGUI::DateTime->new($self->session, $startDate." 00:00:00"); - - # Only if today is not before the recurrence start - if ($dt_day->clone->truncate(to => "day") >= $dt_start->clone->truncate(to=>"day")) - { - # If today is past the endDate, quit. - last RECURRENCE - if ($recur->{endDate} && $dt_day > $dt_end); - - ### Add date - $date{$dt_day->strftime('%F')}++; - - } - - # If occurrences is past the endAfter, quit - last RECURRENCE - if ($recur->{endAfter} && keys %date >= $recur->{endAfter}); - } - - $dt_month->add(months=>1); - } - - # Add interval - $dt->add(years => $recur->{every})->truncate(to => "year"); - - # Test for quit - if (($recur->{endAfter} && keys %date >= $recur->{endAfter}) || ($dt_end && $dt > $dt_end)) - { - last RECURRENCE; - } - - # Next - next RECURRENCE; - } - ####### yearweek - elsif ($recur->{recurType} eq "yearWeek") - { - # For each month - my $dt_month = $dt->clone; - while ($dt->year eq $dt_month->year) - { - my $mon = $dt_month->month_abbr; - if (grep /$mon/i, @{$recur->{months}}) - { - # For each week remaining in this month - my $dt_week = $dt_month->clone; - while ($dt_month->month eq $dt_week->month) - { - my $week = int($dt_week->day_of_month / 7); - - if (grep /$weeks{$week}/i, @{$recur->{weeks}}) - { - for (0..6) # Work through the week - { - my $dt_day = $dt_week->clone->add(days => $_); - - # If today is past the endDate, quit. - last RECURRENCE - if ($recur->{endDate} && $dt_day > $dt_end); - - # If today isn't in the month, stop looking - last if ($dt_day->month ne $dt_month->month); - - my $today = $dayNames{lc $dt_day->day_name}; - - if (grep /$today/i, @{$recur->{dayNames}}) - { - ### Add date - $date{$dt_day->strftime('%F')}++; - } - - # If occurrences is past the endAfter, quit - last RECURRENCE - if ($recur->{endAfter} && keys %date >= $recur->{endAfter}); - } - } - - # Next week - $dt_week->add(days => 7); - } - - ### If last is selected - if (grep /last/, @{$recur->{weeks}}) - { - my $dt_last = $dt_month->clone->add(months => 1)->subtract(days => 1); - - for (0..6) - { - my $dt_day = $dt_last->clone->subtract(days => $_); - - # If today is past the endDate, try the next one - next - if ($recur->{endDate} && $dt_day > $dt_end); - - my $today = $dayNames{lc $dt_day->day_name}; - - if (grep /$today/i, @{$recur->{dayNames}}) - { - ### Add date - $date{$dt_day->strftime('%F')}++; - - } - - # If occurrences is past the endAfter, quit - last RECURRENCE - if ($recur->{endAfter} && keys %date >= $recur->{endAfter}); - } - } - - } - - # Next month - $dt_month->add(months=>1); - } - - # Add interval - $dt->add(years => $recur->{every})->truncate(to => "year"); - - # Test for quit - if (($recur->{endAfter} && keys %date >= $recur->{endAfter}) || ($dt_end && $dt > $dt_end)) - { - last RECURRENCE; - } - - # Next - next RECURRENCE; - } - } - - - return sort keys %date; +sub getRecurrenceDates { + my $self = shift; + my $recur = shift; + + my %date; + + return undef unless $recur->{recurType}; + + my %dayNames = ( + monday => "m", + tuesday => "t", + wednesday => "w", + thursday => "r", + friday => "f", + saturday => "s", + sunday => "u", + ); + + my %weeks = ( + 0 => "first", + 1 => "second", + 2 => "third", + 3 => "fourth", + 4 => "fifth", + ); + + + my $dt = WebGUI::DateTime->new($self->session, $recur->{startDate}." 00:00:00"); + my $dt_start = $dt->clone; # Keep track of the initial start date + my $dt_end; + if ($recur->{endDate}) { + $dt_end = WebGUI::DateTime->new($self->session, $recur->{endDate}." 00:00:00"); + } + # Set an end for events with no end + #!!! TODO !!! - Get the appropriate configuration + elsif (!$recur->{endDate} && !$recur->{endAfter}) { + $dt_end = $dt->clone->add(years=>2); + } + + + RECURRENCE: while (1) + { + ####### daily + if ($recur->{recurType} eq "daily") + { + ### Add date + $date{$dt->strftime('%F')}++; + + # Add interval + $dt->add(days => $recur->{every}); + + # Test for quit + if (($recur->{endAfter} && keys %date >= $recur->{endAfter}) || ($dt_end && $dt > $dt_end)) + { + last RECURRENCE; + } + + # Next + next RECURRENCE; + } + ####### weekday + elsif ($recur->{recurType} eq "weekday") + { + my $today = $dt->day_name; + + # If today is not a weekday + unless (grep /$today/i,qw(monday tuesday wednesday thursday friday)) + { + # Add a day + $dt->add(days => 1); + + # Test for quit + if (($recur->{endAfter} && keys %date >= $recur->{endAfter}) || ($dt_end && $dt > $dt_end)) + { + last RECURRENCE; + } + + # next + next RECURRENCE; + } + else + { + ### Add date + $date{$dt->strftime('%F')}++; + + $dt->add(days => $recur->{every}); + + # Test for quit + if (($recur->{endAfter} && keys %date >= $recur->{endAfter}) || ($dt_end && $dt > $dt_end)) + { + last RECURRENCE; + } + + # Next + next RECURRENCE; + } + } + ####### weekly + elsif ($recur->{recurType} eq "weekly") + { + for (0..6) # Work through the week + { + my $dt_day = $dt->clone->add(days => $_); + + # If today is past the endDate, quit. + last RECURRENCE + if ($recur->{endDate} && $dt_day > $dt_end); + + my $today = $dayNames{lc $dt_day->day_name}; + + if (grep /$today/i, @{$recur->{dayNames}}) + { + ### Add date + $date{$dt_day->strftime('%F')}++; + } + + # If occurrences is past the endAfter, quit + last RECURRENCE + if ($recur->{endAfter} && keys %date >= $recur->{endAfter}); + } + + # Add interval + $dt->add(weeks => $recur->{every}); + + # Test for quit + if (($recur->{endAfter} && keys %date >= $recur->{endAfter}) || ($dt_end && $dt > $dt_end)) + { + last RECURRENCE; + } + + # Next + next RECURRENCE; + + } + ####### monthday + elsif ($recur->{recurType} eq "monthDay") + { + # Pick out the correct day + my $startDate = $dt->year."-".$dt->month."-".$recur->{dayNumber}; + + my $dt_day = WebGUI::DateTime->new($self->session, $startDate." 00:00:00"); + + # Only if today is not before the recurrence start + if ($dt_day->clone->truncate(to => "day") >= $dt_start->clone->truncate(to=>"day")) + { + # If today is past the endDate, quit. + last RECURRENCE + if ($recur->{endDate} && $dt_day > $dt_end); + + ### Add date + $date{$dt_day->strftime('%F')}++; + } + + # Add interval + $dt->add(months => $recur->{every})->truncate(to => "month"); + + # Test for quit + if (($recur->{endAfter} && keys %date >= $recur->{endAfter}) || ($dt_end && $dt > $dt_end)) + { + last RECURRENCE; + } + + # Next + next RECURRENCE; + } + ###### monthweek + elsif ($recur->{recurType} eq "monthWeek") + { + # For each week remaining in this month + my $dt_week = $dt->clone; + while ($dt->month eq $dt_week->month) + { + my $week = int($dt_week->day_of_month / 7); + + if (grep /$weeks{$week}/i, @{$recur->{weeks}}) + { + # Pick out the correct days + for (0..6) # Work through the week + { + my $dt_day = $dt_week->clone->add(days => $_); + + # If today is past the endDate, quit. + last RECURRENCE + if ($recur->{endDate} && $dt_day > $dt_end); + + # If today isn't in the month, stop looking + last if ($dt_day->month ne $dt->month); + + my $today = $dayNames{lc $dt_day->day_name}; + + if (grep /$today/i, @{$recur->{dayNames}}) + { + ### Add date + $date{$dt_day->strftime('%F')}++; + } + + # If occurrences is past the endAfter, quit + last RECURRENCE + if ($recur->{endAfter} && keys %date >= $recur->{endAfter}); + } + } + + # Add a week + $dt_week->add(days => 7); + } + + ### If last is selected + if (grep /last/, @{$recur->{weeks}}) + { + my $dt_last = $dt->clone->truncate(to => "month") + ->add(months => 1)->subtract(days => 1); + + for (0..6) + { + my $dt_day = $dt_last->clone->subtract(days => $_); + + # If today is before the startDate, don't even bother + last if ($dt_day < $dt_start); + # If today is past the endDate, try the next one + next if ($recur->{endDate} && $dt_day > $dt_end); + + my $today = $dayNames{lc $dt_day->day_name}; + + if (grep /$today/i, @{$recur->{dayNames}}) + { + ### Add date + $date{$dt_day->strftime('%F')}++; + + } + + # If occurrences is past the endAfter, quit + last RECURRENCE + if ($recur->{endAfter} && keys %date >= $recur->{endAfter}); + } + } + + + # Add interval + $dt->add(months => $recur->{every})->truncate(to => "month"); + + # Test for quit + if (($recur->{endAfter} && keys %date >= $recur->{endAfter}) || ($dt_end && $dt > $dt_end)) + { + last RECURRENCE; + } + + # Next + next RECURRENCE; + } + ####### yearday + elsif ($recur->{recurType} eq "yearDay") + { + # For each month + my $dt_month = $dt->clone; + while ($dt->year eq $dt_month->year) + { + my $mon = $dt_month->month_abbr; + if (grep /$mon/i, @{$recur->{months}}) + { + # Pick out the correct day + my $startDate = $dt_month->year."-".$dt_month->month."-".$recur->{dayNumber}; + + my $dt_day = WebGUI::DateTime->new($self->session, $startDate." 00:00:00"); + + # Only if today is not before the recurrence start + if ($dt_day->clone->truncate(to => "day") >= $dt_start->clone->truncate(to=>"day")) + { + # If today is past the endDate, quit. + last RECURRENCE + if ($recur->{endDate} && $dt_day > $dt_end); + + ### Add date + $date{$dt_day->strftime('%F')}++; + + } + + # If occurrences is past the endAfter, quit + last RECURRENCE + if ($recur->{endAfter} && keys %date >= $recur->{endAfter}); + } + + $dt_month->add(months=>1); + } + + # Add interval + $dt->add(years => $recur->{every})->truncate(to => "year"); + + # Test for quit + if (($recur->{endAfter} && keys %date >= $recur->{endAfter}) || ($dt_end && $dt > $dt_end)) + { + last RECURRENCE; + } + + # Next + next RECURRENCE; + } + ####### yearweek + elsif ($recur->{recurType} eq "yearWeek") + { + # For each month + my $dt_month = $dt->clone; + while ($dt->year eq $dt_month->year) + { + my $mon = $dt_month->month_abbr; + if (grep /$mon/i, @{$recur->{months}}) + { + # For each week remaining in this month + my $dt_week = $dt_month->clone; + while ($dt_month->month eq $dt_week->month) + { + my $week = int($dt_week->day_of_month / 7); + + if (grep /$weeks{$week}/i, @{$recur->{weeks}}) + { + for (0..6) # Work through the week + { + my $dt_day = $dt_week->clone->add(days => $_); + + # If today is past the endDate, quit. + last RECURRENCE + if ($recur->{endDate} && $dt_day > $dt_end); + + # If today isn't in the month, stop looking + last if ($dt_day->month ne $dt_month->month); + + my $today = $dayNames{lc $dt_day->day_name}; + + if (grep /$today/i, @{$recur->{dayNames}}) + { + ### Add date + $date{$dt_day->strftime('%F')}++; + } + + # If occurrences is past the endAfter, quit + last RECURRENCE + if ($recur->{endAfter} && keys %date >= $recur->{endAfter}); + } + } + + # Next week + $dt_week->add(days => 7); + } + + ### If last is selected + if (grep /last/, @{$recur->{weeks}}) + { + my $dt_last = $dt_month->clone->add(months => 1)->subtract(days => 1); + + for (0..6) + { + my $dt_day = $dt_last->clone->subtract(days => $_); + + # If today is past the endDate, try the next one + next + if ($recur->{endDate} && $dt_day > $dt_end); + + my $today = $dayNames{lc $dt_day->day_name}; + + if (grep /$today/i, @{$recur->{dayNames}}) + { + ### Add date + $date{$dt_day->strftime('%F')}++; + + } + + # If occurrences is past the endAfter, quit + last RECURRENCE + if ($recur->{endAfter} && keys %date >= $recur->{endAfter}); + } + } + + } + + # Next month + $dt_month->add(months=>1); + } + + # Add interval + $dt->add(years => $recur->{every})->truncate(to => "year"); + + # Test for quit + if (($recur->{endAfter} && keys %date >= $recur->{endAfter}) || ($dt_end && $dt > $dt_end)) + { + last RECURRENCE; + } + + # Next + next RECURRENCE; + } + } + + + return sort keys %date; } @@ -1098,83 +1090,82 @@ The hash keys are the same as getRecurrence. =cut -sub getRecurrenceFromForm -{ - my $self = shift; - my $form = $self->session->form; - - my %recurrence = (); - my $type = lc $form->param("recurType"); - - return () unless ($type && $type !~ /none/i); - - if ($type eq "daily") - { - if (lc($form->param("recurSubType")) eq "weekday") - { - $recurrence{recurType} = "weekday"; - } - else - { - $recurrence{recurType} = "daily"; - } - - $recurrence{every} = $form->param("recurDay"); - } - elsif ($type eq "weekly") - { - $recurrence{recurType} = "weekly"; - $recurrence{dayNames} = [$form->param("recurWeekDay")]; - $recurrence{every} = $form->param("recurWeek"); - } - elsif ($type eq "monthly") - { - if (lc($form->param("recurSubType")) eq "monthweek") - { - $recurrence{recurType} = "monthWeek"; - $recurrence{weeks} = [$form->param("recurMonthWeekNumber")]; - $recurrence{dayNames} = [$form->param("recurMonthWeekDay")]; - } - elsif (lc($form->param("recurSubType")) eq "monthday") - { - $recurrence{recurType} = "monthDay"; - $recurrence{dayNumber} = $form->param("recurMonthDay"); - } - - $recurrence{every} = $form->param("recurMonth"); - } - elsif ($type eq "yearly") - { - if (lc($form->param("recurSubType")) eq "yearweek") - { - $recurrence{recurType} = "yearWeek"; - $recurrence{weeks} = [$form->param("recurYearWeekNumber")]; - $recurrence{dayNames} = [$form->param("recurYearWeekDay")]; - $recurrence{months} = [$form->param("recurYearWeekMonth")]; - } - elsif (lc($form->param("recurSubType")) eq "yearday") - { - $recurrence{recurType} = "yearDay"; - $recurrence{dayNumber} = $form->param("recurYearDay"); - $recurrence{months} = [$form->param("recurYearDayMonth")]; - } - - $recurrence{every} = $form->param("recurYear"); - } - - $recurrence{every} ||= 1; - $recurrence{startDate} = $form->param("recurStart"); - - if (lc $form->param("recurEndType") eq "date") - { - $recurrence{endDate} = $form->param("recurEndDate"); - } - elsif (lc $form->param("recurEndType") eq "after") - { - $recurrence{endAfter} = $form->param("recurEndAfter"); - } - - return %recurrence; +sub getRecurrenceFromForm { + my $self = shift; + my $form = $self->session->form; + + my %recurrence = (); + my $type = lc $form->param("recurType"); + + return () unless ($type && $type !~ /none/i); + + if ($type eq "daily") + { + if (lc($form->param("recurSubType")) eq "weekday") + { + $recurrence{recurType} = "weekday"; + } + else + { + $recurrence{recurType} = "daily"; + } + + $recurrence{every} = $form->param("recurDay"); + } + elsif ($type eq "weekly") + { + $recurrence{recurType} = "weekly"; + $recurrence{dayNames} = [$form->param("recurWeekDay")]; + $recurrence{every} = $form->param("recurWeek"); + } + elsif ($type eq "monthly") + { + if (lc($form->param("recurSubType")) eq "monthweek") + { + $recurrence{recurType} = "monthWeek"; + $recurrence{weeks} = [$form->param("recurMonthWeekNumber")]; + $recurrence{dayNames} = [$form->param("recurMonthWeekDay")]; + } + elsif (lc($form->param("recurSubType")) eq "monthday") + { + $recurrence{recurType} = "monthDay"; + $recurrence{dayNumber} = $form->param("recurMonthDay"); + } + + $recurrence{every} = $form->param("recurMonth"); + } + elsif ($type eq "yearly") + { + if (lc($form->param("recurSubType")) eq "yearweek") + { + $recurrence{recurType} = "yearWeek"; + $recurrence{weeks} = [$form->param("recurYearWeekNumber")]; + $recurrence{dayNames} = [$form->param("recurYearWeekDay")]; + $recurrence{months} = [$form->param("recurYearWeekMonth")]; + } + elsif (lc($form->param("recurSubType")) eq "yearday") + { + $recurrence{recurType} = "yearDay"; + $recurrence{dayNumber} = $form->param("recurYearDay"); + $recurrence{months} = [$form->param("recurYearDayMonth")]; + } + + $recurrence{every} = $form->param("recurYear"); + } + + $recurrence{every} ||= 1; + $recurrence{startDate} = $form->param("recurStart"); + + if (lc $form->param("recurEndType") eq "date") + { + $recurrence{endDate} = $form->param("recurEndDate"); + } + elsif (lc $form->param("recurEndType") eq "after") + { + $recurrence{endAfter} = $form->param("recurEndAfter"); + } + + return %recurrence; } @@ -1191,9 +1182,9 @@ Gets the related links. sub getRelatedLinks { - my $self = shift; - return () unless $self->get("relatedLinks"); - return split /\n+/, $self->get("relatedLinks"); + my $self = shift; + return () unless $self->get("relatedLinks"); + return split /\n+/, $self->get("relatedLinks"); } @@ -1211,96 +1202,95 @@ Uses the current user's locale and timezone. =cut -sub getTemplateVars -{ - my $self = shift; - my $i18n = WebGUI::International->new($self->session,"Asset_Event"); - my %var; - - # Some miscellaneous stuff - $var{"isPublic"} = 1 - if $self->get("groupIdView") eq "7"; - $var{"groupToView"} = $self->get("groupIdView"); # Todo: Remove this? - - # Start date/time - my $dtStart = $self->getDateTimeStart; - $dtStart->set_locale($i18n->get("locale") || "en_US"); - - $var{"startDateSecond"} = sprintf "%02d", $dtStart->second; - $var{"startDateMinute"} = sprintf "%02d", $dtStart->minute; - $var{"startDateHour24"} = $dtStart->hour; - $var{"startDateHour"} = $dtStart->hour_12; - $var{"startDateM"} = ( $dtStart->hour < 12 ? "AM" : "PM" ); - $var{"startDateDayName"} = $dtStart->day_name; - $var{"startDateDayAbbr"} = $dtStart->day_abbr; - $var{"startDateDayOfMonth"} = $dtStart->day_of_month; - $var{"startDateDayOfWeek"} = $dtStart->day_of_week; - $var{"startDateMonthName"} = $dtStart->month_name; - $var{"startDateMonthAbbr"} = $dtStart->month_abbr; - $var{"startDateYear"} = $dtStart->year; - $var{"startDateYmd"} = $dtStart->ymd; - $var{"startDateMdy"} = $dtStart->mdy; - $var{"startDateDmy"} = $dtStart->dmy; - $var{"startDateHms"} = $dtStart->hms; - $var{"startDateEpoch"} = $dtStart->epoch; - - # End date/time - my $dtEnd = $self->getDateTimeEnd; - $dtEnd->set_locale($i18n->get("locale") || "en_US"); - - $var{"endDateSecond"} = sprintf "%02d", $dtEnd->second; - $var{"endDateMinute"} = sprintf "%02d", $dtEnd->minute; - $var{"endDateHour24"} = $dtEnd->hour; - $var{"endDateHour"} = $dtEnd->hour_12; - $var{"endDateM"} = ( $dtEnd->hour < 12 ? "AM" : "PM" ); - $var{"endDateDayName"} = $dtEnd->day_name; - $var{"endDateDayAbbr"} = $dtEnd->day_abbr; - $var{"endDateDayOfMonth"} = $dtEnd->day_of_month; - $var{"endDateDayOfWeek"} = $dtEnd->day_of_week; - $var{"endDateMonthName"} = $dtEnd->month_name; - $var{"endDateMonthAbbr"} = $dtEnd->month_abbr; - $var{"endDateYear"} = $dtEnd->year; - $var{"endDateYmd"} = $dtEnd->ymd; - $var{"endDateMdy"} = $dtEnd->mdy; - $var{"endDateDmy"} = $dtEnd->dmy; - $var{"endDateHms"} = $dtEnd->hms; - $var{"endDateEpoch"} = $dtEnd->epoch; - - - - $var{isAllDay} = $self->isAllDay; - $var{isOneDay} = 1 if ($var{isAllDay} && $var{startDateDmy} eq $var{endDateDmy}); - - - # Make a Friendly date span - $var{dateSpan} = $var{startDateDayName}.", " - . $var{startDateMonthName}." " - . $var{startDateDayOfMonth}." " - . ( !$var{isAllDay} ? $var{startDateHour}.":".$var{startDateMinute}." ".$var{startDateM} : "" ) - . ( !$var{isOneDay} ? - ' • ' - . $var{endDateDayName}.", " - .$var{endDateMonthName}." " - .$var{endDateDayOfMonth}." " - . ( !$var{isAllDay} ? $var{endDateHour}.":".$var{endDateMinute}." ".$var{endDateM} : "") - : ""); - - # Make some friendly URLs +sub getTemplateVars { + my $self = shift; + my $i18n = WebGUI::International->new($self->session,"Asset_Event"); + my %var; + + # Some miscellaneous stuff + $var{"isPublic"} = 1 + if $self->get("groupIdView") eq "7"; + $var{"groupToView"} = $self->get("groupIdView"); # Todo: Remove this? + + # Start date/time + my $dtStart = $self->getDateTimeStart; + $dtStart->set_locale($i18n->get("locale") || "en_US"); + + $var{"startDateSecond"} = sprintf "%02d", $dtStart->second; + $var{"startDateMinute"} = sprintf "%02d", $dtStart->minute; + $var{"startDateHour24"} = $dtStart->hour; + $var{"startDateHour"} = $dtStart->hour_12; + $var{"startDateM"} = ( $dtStart->hour < 12 ? "AM" : "PM" ); + $var{"startDateDayName"} = $dtStart->day_name; + $var{"startDateDayAbbr"} = $dtStart->day_abbr; + $var{"startDateDayOfMonth"} = $dtStart->day_of_month; + $var{"startDateDayOfWeek"} = $dtStart->day_of_week; + $var{"startDateMonthName"} = $dtStart->month_name; + $var{"startDateMonthAbbr"} = $dtStart->month_abbr; + $var{"startDateYear"} = $dtStart->year; + $var{"startDateYmd"} = $dtStart->ymd; + $var{"startDateMdy"} = $dtStart->mdy; + $var{"startDateDmy"} = $dtStart->dmy; + $var{"startDateHms"} = $dtStart->hms; + $var{"startDateEpoch"} = $dtStart->epoch; + + # End date/time + my $dtEnd = $self->getDateTimeEnd; + $dtEnd->set_locale($i18n->get("locale") || "en_US"); + + $var{"endDateSecond"} = sprintf "%02d", $dtEnd->second; + $var{"endDateMinute"} = sprintf "%02d", $dtEnd->minute; + $var{"endDateHour24"} = $dtEnd->hour; + $var{"endDateHour"} = $dtEnd->hour_12; + $var{"endDateM"} = ( $dtEnd->hour < 12 ? "AM" : "PM" ); + $var{"endDateDayName"} = $dtEnd->day_name; + $var{"endDateDayAbbr"} = $dtEnd->day_abbr; + $var{"endDateDayOfMonth"} = $dtEnd->day_of_month; + $var{"endDateDayOfWeek"} = $dtEnd->day_of_week; + $var{"endDateMonthName"} = $dtEnd->month_name; + $var{"endDateMonthAbbr"} = $dtEnd->month_abbr; + $var{"endDateYear"} = $dtEnd->year; + $var{"endDateYmd"} = $dtEnd->ymd; + $var{"endDateMdy"} = $dtEnd->mdy; + $var{"endDateDmy"} = $dtEnd->dmy; + $var{"endDateHms"} = $dtEnd->hms; + $var{"endDateEpoch"} = $dtEnd->epoch; + + + + $var{isAllDay} = $self->isAllDay; + $var{isOneDay} = 1 if ($var{isAllDay} && $var{startDateDmy} eq $var{endDateDmy}); + + + # Make a Friendly date span + $var{dateSpan} = $var{startDateDayName}.", " + . $var{startDateMonthName}." " + . $var{startDateDayOfMonth}." " + . ( !$var{isAllDay} ? $var{startDateHour}.":".$var{startDateMinute}." ".$var{startDateM} : "" ) + . ( !$var{isOneDay} ? + ' • ' + . $var{endDateDayName}.", " + .$var{endDateMonthName}." " + .$var{endDateDayOfMonth}." " + . ( !$var{isAllDay} ? $var{endDateHour}.":".$var{endDateMinute}." ".$var{endDateM} : "") + : ""); + + # Make some friendly URLs $var{"url"} = $self->getUrl; $dtStart->truncate(to=>"day"); - $var{"urlDay"} = $self->getParent->getUrl("type=day;start=".$dtStart->toMysql); - $var{"urlWeek"} = $self->getParent->getUrl("type=week;start=".$dtStart->toMysql); - $var{"urlMonth"} = $self->getParent->getUrl("type=month;start=".$dtStart->toMysql); - $var{"urlParent"} = $self->getParent->getUrl; - - - # Related links - $var{"relatedLinks"} = []; - push @{$var{"relatedLinks"}}, { "linkUrl" => $_ } - for ($self->getRelatedLinks); - - - return %var; + $var{"urlDay"} = $self->getParent->getUrl("type=day;start=".$dtStart->toMysql); + $var{"urlWeek"} = $self->getParent->getUrl("type=week;start=".$dtStart->toMysql); + $var{"urlMonth"} = $self->getParent->getUrl("type=month;start=".$dtStart->toMysql); + $var{"urlParent"} = $self->getParent->getUrl; + + + # Related links + $var{"relatedLinks"} = []; + push @{$var{"relatedLinks"}}, { "linkUrl" => $_ } + for ($self->getRelatedLinks); + + + return %var; } @@ -1315,10 +1305,10 @@ Returns true if this event is an all day event. =cut -sub isAllDay -{ - return 1 unless ($_[0]->get("startTime") || $_[0]->get("endTime")); - return 0; +sub isAllDay { + my $self = shift; + return 1 unless ($self->get("startTime") || $self->get("endTime")); + return 0; } @@ -1338,31 +1328,31 @@ If the "print" form parameter is set, will prepare the print template. sub prepareView { - my $self = shift; - my $parent = $self->getParent; - my $templateId; - - if ($parent) - { - if ($self->session->form->param("print")) - { - $templateId = $parent->get("templateIdPrintEvent"); - $self->session->style->makePrintable(1); - } - else - { - $templateId = $parent->get("templateIdEvent"); - } - } - else - { - $templateId = "CalendarEvent000000001"; - } - - my $template = WebGUI::Asset::Template->new($self->session,$templateId); - $template->prepare; - - $self->{_viewTemplate} = $template; + my $self = shift; + my $parent = $self->getParent; + my $templateId; + + if ($parent) + { + if ($self->session->form->param("print")) + { + $templateId = $parent->get("templateIdPrintEvent"); + $self->session->style->makePrintable(1); + } + else + { + $templateId = $parent->get("templateIdEvent"); + } + } + else + { + $templateId = "CalendarEvent000000001"; + } + + my $template = WebGUI::Asset::Template->new($self->session,$templateId); + $template->prepare; + + $self->{_viewTemplate} = $template; } @@ -1390,120 +1380,136 @@ Requests that the events be committed =cut -sub processPropertiesFromFormPost -{ - my $self = shift; - $self->SUPER::processPropertiesFromFormPost; # Updates the event - my $session = $self->session; - my $form = $self->session->form; - - ### Verify the form was filled out correctly... - # The end must be after the start - if (!$form->param("allday") - && $self->get("startDate") gt $self->get("endDate") - || ($self->get("startDate") eq $self->get("endDate") && $self->get("startTime") gt $self->get("endTime"))) - { - return ["The event end must be after the event start."]; - } - - - ### Form is verified - # Events are always hidden from navigation - $self->update({ isHidden => 1 }); - - # Fix times according to input (allday, timezone) - if ($self->session->form->param("allday")) - { - $self->update({ startTime => undef, - endTime => undef, - }); - } - else - { - # Convert timezone - my $tz = $self->session->user->profileField("timeZone"); - - my ($startDate,$startTime) = split / /, WebGUI::DateTime->new($self->session, mysql => $self->get("startDate")." ".$self->get("startTime"), time_zone => $tz) - ->set_time_zone("UTC")->toMysql; - - my ($endDate,$endTime) = split / /, WebGUI::DateTime->new($self->session, mysql => $self->get("endDate")." ".$self->get("endTime"), time_zone => $tz) - ->set_time_zone("UTC")->toMysql; - - $self->update({ startDate => $startDate, - startTime => $startTime, - endDate => $endDate, - endTime => $endTime, - }); - } - - - # Determine if the pattern has changed - if ($form->param("recurType")) - { - # Create the new recurrence hash - my %recurrence_new = $self->getRecurrenceFromForm; - # Get the old recurrence hash and range - my %recurrence_old = $self->getRecurrence; - - - # Set storable to canonical so that we can compare data structures - $Storable::canonical = 1; - - # Pattern keys - if (nfreeze(\%recurrence_new) ne nfreeze(\%recurrence_old)) - { - # Delete all old events and create new ones - my $old_id = $self->get("recurId"); - - return ["There's something wrong with your recurrence pattern."] - unless $self->generateRecurringEvents(\%recurrence_new); - - - ## Delete old events - my $events = $self->getLineage(["siblings"], - { - returnObjects => 1, - includeOnlyClasses => ['WebGUI::Asset::Event'], - joinClass => 'WebGUI::Asset::Event', - whereClause => 'Event.recurId = "'.$old_id.'"', - }); - - $_->purge for @$events; - } - # Include / exclude keys - #elsif () - #{ - # # Delete / create necessary events - # - #} - # No change - else - { - # Just update related events - my %properties = %{ $self->get }; - delete $properties{startDate}; - delete $properties{endDate}; - - my $events = $self->getLineage(["siblings"], - { - returnObjects => 1, - includeOnlyClasses => ['WebGUI::Asset::Event'], - joinClass => 'WebGUI::Asset::Event', - whereClause => 'Event.recurId = "'.$self->get("recurId").'"', - }); - - for my $event (@$events) - { - # Add a revision - $properties{startDate} = $event->get("startDate"); - $properties{endDate} = $event->get("endDate"); - - $event->addRevision(\%properties); - $event->requestAutoCommit; - } - } - } - $self->requestAutoCommit; +sub processPropertiesFromFormPost { + my $self = shift; + $self->SUPER::processPropertiesFromFormPost; # Updates the event + my $session = $self->session; + my $form = $self->session->form; + + ### Verify the form was filled out correctly... + my @errors; + # If the start date is after the end date + if ($self->get("startDate") gt $self->get("endDate")) { + push @errors, "The event end date must be after the event start date."; + } + + # If the dates are the same and the start time is after the end time + if ($self->get("startDate") eq $self->get("endDate") + && $self->get("startTime") gt $self->get("endTime") + ) { + push @errors, "The event end time must be after the event start time."; + } + + if (@errors) { + return \@errors; + } + + + ### Form is verified + # Events are always hidden from navigation + $self->update({ isHidden => 1 }); + + # Fix times according to input (allday, timezone) + if ($form->param("allday")) { + $self->update({ + startTime => undef, + endTime => undef, + }); + } + else { + # Convert timezone + my $tz = $self->session->user->profileField("timeZone"); + + my $dtStart + = WebGUI::DateTime->new($session, + mysql => $self->get("startDate") . " " . $self->get("startTime"), + time_zone => $tz, + ); + + my $dtEnd + = WebGUI::DateTime->new($session, + mysql => $self->get("endDate") . " " . $self->get("endTime"), + time_zone => $tz, + ); + + $self->update({ + startDate => $dtStart->toDatabaseDate, + startTime => $dtStart->toDatabaseTime, + endDate => $dtEnd->toDatabaseDate, + endTime => $dtEnd->toDatabaseTime, + }); + } + + + # Determine if the pattern has changed + if ($form->param("recurType")) { + # Create the new recurrence hash + my %recurrence_new = $self->getRecurrenceFromForm; + # Get the old recurrence hash and range + my %recurrence_old = $self->getRecurrence; + + + # Set storable to canonical so that we can compare data structures + $Storable::canonical = 1; + + # Pattern keys + if (nfreeze(\%recurrence_new) ne nfreeze(\%recurrence_old)) { + # Delete all old events and create new ones + my $old_id = $self->get("recurId"); + + return ["There's something wrong with your recurrence pattern."] + unless $self->generateRecurringEvents(\%recurrence_new); + + + ## Delete old events + my $events = $self->getLineage(["siblings"], { + returnObjects => 1, + includeOnlyClasses => ['WebGUI::Asset::Event'], + joinClass => 'WebGUI::Asset::Event', + whereClause => qq{Event.recurId = "$old_id"}, + }); + + $_->purge for @$events; + } + # Include / exclude keys + #elsif () + #{ + # # Delete / create necessary events + # + #} + # No change + else { + # Just update related events + my %properties = %{ $self->get }; + delete $properties{startDate}; + delete $properties{endDate}; + delete $properties{url}; # addRevision will create a new url for us + + my $events = $self->getLineage(["siblings"], { + #returnObjects => 1, + includeOnlyClasses => ['WebGUI::Asset::Event'], + joinClass => 'WebGUI::Asset::Event', + whereClause => q{Event.recurId = "}.$self->get("recurId").q{"}, + }); + + for my $eventId (@{$events}) { + my $event = WebGUI::Asset->newByDynamicClass($session,$eventId); + + # Add a revision + $properties{startDate} = $event->get("startDate"); + $properties{endDate} = $event->get("endDate"); + + # addRevision returns the new revision + $event = $event->addRevision(\%properties); + $event->requestAutoCommit(); + } + } + } + + # Finally, commit this event + $self->requestAutoCommit; + + return; } @@ -1524,72 +1530,72 @@ Returns the ID of the row if success, otherwise returns 0. sub setRecurrence { - my $self = shift; - my $vars = shift; - - my $type = $vars->{recurType} || return; - my $pattern; - - if ($type eq "daily" || $type eq "weekday") - { - return 0 unless ($vars->{every}); - #(\d+) - $pattern = $vars->{every}; - } - elsif ($type eq "weekly") - { - return 0 unless ($vars->{every} && $vars->{dayNames}); - #(\d+) ([umtwrfs]+) - $pattern = $vars->{every}." ".join("",@{$vars->{dayNames}}); - } - elsif ($type eq "monthWeek") - { - return 0 unless ($vars->{every} && $vars->{weeks} && $vars->{dayNames}); - #(\d+) (first,second,third,fourth,last) ([umtwrfs]+) - $pattern = $vars->{every}." ".join(",",@{$vars->{weeks}})." ".join("",@{$vars->{dayNames}}); - } - elsif ($type eq "monthDay") - { - return 0 unless ($vars->{every} && $vars->{dayNumber}); - #(\d+) on (\d+) - $pattern = $vars->{every}." ".$vars->{dayNumber}; - } - elsif ($type eq "yearWeek") - { - 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) - $pattern = $vars->{every}." ".join(",",@{$vars->{weeks}})." ".join("",@{$vars->{dayNames}})." ".join(",",@{$vars->{months}}); - } - elsif ($type eq "yearDay") - { - return 0 unless ($vars->{every} && $vars->{dayNumber} && $vars->{months}); - #(\d+) on (\d+) (jan,feb,mar,apr,may,jun,jul,aug,sep,oct,nov,dec) - $pattern = $vars->{every}." ".$vars->{dayNumber}." ".join(",",@{$vars->{months}}); - } - - - my $end = undef; - if ($vars->{endAfter}) - { - $end = "after ".$vars->{endAfter}; - } - elsif ($vars->{endDate}) - { - $end = $vars->{endDate}; - } - - - my $data = { - recurId => "new", - recurType => $type, - pattern => $pattern, - startDate => $vars->{startDate}, - endDate => $end, - }; - - ## Set to the database - ## Return the new recurId - return $self->session->db->setRow("Event_recur","recurId",$data); + my $self = shift; + my $vars = shift; + + my $type = $vars->{recurType} || return; + my $pattern; + + if ($type eq "daily" || $type eq "weekday") + { + return 0 unless ($vars->{every}); + #(\d+) + $pattern = $vars->{every}; + } + elsif ($type eq "weekly") + { + return 0 unless ($vars->{every} && $vars->{dayNames}); + #(\d+) ([umtwrfs]+) + $pattern = $vars->{every}." ".join("",@{$vars->{dayNames}}); + } + elsif ($type eq "monthWeek") + { + return 0 unless ($vars->{every} && $vars->{weeks} && $vars->{dayNames}); + #(\d+) (first,second,third,fourth,last) ([umtwrfs]+) + $pattern = $vars->{every}." ".join(",",@{$vars->{weeks}})." ".join("",@{$vars->{dayNames}}); + } + elsif ($type eq "monthDay") + { + return 0 unless ($vars->{every} && $vars->{dayNumber}); + #(\d+) on (\d+) + $pattern = $vars->{every}." ".$vars->{dayNumber}; + } + elsif ($type eq "yearWeek") + { + 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) + $pattern = $vars->{every}." ".join(",",@{$vars->{weeks}})." ".join("",@{$vars->{dayNames}})." ".join(",",@{$vars->{months}}); + } + elsif ($type eq "yearDay") + { + return 0 unless ($vars->{every} && $vars->{dayNumber} && $vars->{months}); + #(\d+) on (\d+) (jan,feb,mar,apr,may,jun,jul,aug,sep,oct,nov,dec) + $pattern = $vars->{every}." ".$vars->{dayNumber}." ".join(",",@{$vars->{months}}); + } + + + my $end = undef; + if ($vars->{endAfter}) + { + $end = "after ".$vars->{endAfter}; + } + elsif ($vars->{endDate}) + { + $end = $vars->{endDate}; + } + + + my $data = { + recurId => "new", + recurType => $type, + pattern => $pattern, + startDate => $vars->{startDate}, + endDate => $end, + }; + + ## Set to the database + ## Return the new recurId + return $self->session->db->setRow("Event_recur","recurId",$data); } @@ -1606,12 +1612,12 @@ Sets the event's related links. sub setRelatedLinks { - my $self = shift; - my @links = @_; - - $self->update({ - relatedLinks => join("\n", @links), - }); + my $self = shift; + my @links = @_; + + $self->update({ + relatedLinks => join("\n", @links), + }); } @@ -1628,29 +1634,29 @@ Returns the template to be viewed. sub view { - my $self = shift; - my $session = $self->session; - - # Get, of course, the event data - my $var = $self->get; - - - - # Get some more template vars - my %dates = $self->getTemplateVars; - $var->{$_} = $dates{$_} for keys %dates; - - # Next and previous events - my $next = $self->getEventNext; - $var->{"nextUrl"} = $next->getUrl - if ($next); - - my $prev = $self->getEventPrev; - $var->{"prevUrl"} = $prev->getUrl - if ($prev); - - - return $self->processTemplate($var, undef, $self->{_viewTemplate}); + my $self = shift; + my $session = $self->session; + + # Get, of course, the event data + my $var = $self->get; + + + + # Get some more template vars + my %dates = $self->getTemplateVars; + $var->{$_} = $dates{$_} for keys %dates; + + # Next and previous events + my $next = $self->getEventNext; + $var->{"nextUrl"} = $next->getUrl + if ($next); + + my $prev = $self->getEventPrev; + $var->{"prevUrl"} = $prev->getUrl + if ($prev); + + + return $self->processTemplate($var, undef, $self->{_viewTemplate}); } @@ -1667,413 +1673,412 @@ Edit the event. sub www_edit { - my $self = shift; - my $session = $self->session; - my $form = $self->session->form; - my $tz = $session->user->profileField("timeZone"); - my $func = lc $session->form->param("func"); - my $var = {}; + my $self = shift; + my $session = $self->session; + my $form = $self->session->form; + my $tz = $session->user->profileField("timeZone"); + my $func = lc $session->form->param("func"); + my $var = {}; - return $self->session->privilege->noAccess() unless $self->getParent->canAddEvent(); - - if ($func eq "add" || $form->param("assetId") eq "new") - { - $var->{"formHeader"} = WebGUI::Form::formHeader($session, - { - action => $self->getParent->getUrl, - }) - . WebGUI::Form::hidden($self->session, - { - name =>"assetId", - value =>"new", - }) - . WebGUI::Form::hidden($self->session, - { - name =>"class", - value =>$self->session->form->process("class","className") - }); - } - else - { - $var->{"formHeader"} = WebGUI::Form::formHeader($session, - { - action => $self->getUrl, - }); - } - - $var->{"formHeader"} .= WebGUI::Form::hidden($self->session, - { - name => "func", - value => "editSave" - }) - . WebGUI::Form::hidden($self->session, - { - name => "recurId", - value => $self->get("recurId"), - }); - - $var->{"formFooter"} = WebGUI::Form::formFooter($session); - - - ###### Event Tab - # title AS long title - $var->{"formTitle"} = WebGUI::Form::text($session, - { - name => "title", - value => $form->process("title") || $self->get("title"), - }); - - # menu title AS short title - $var->{"formMenuTitle"} = WebGUI::Form::text($session, - { - name => "menuTitle", - value => $form->process("menuTitle") || $self->get("menuTitle"), - maxlength => 15, - size => 16, - }); - - # location - $var->{"formLocation"} = WebGUI::Form::text($session, - { - name => "location", - value => $form->process("location") || $self->get("location"), - }); - - # description - $var->{"formDescription"}= WebGUI::Form::HTMLArea($session, - { - name => "description", - value => $form->process("description") || $self->get("description"), - }); - - # start date - my $default_start = WebGUI::DateTime->new($self->session, $session->form->param("start") || time) - ->set_time_zone($tz); - my ($startDate,$startTime) = split / /, $self->getDateTimeStart->toUserTimeZone - unless $func eq "add" || $self->get("assetId") eq "new"; - - $var->{"formStartDate"}= WebGUI::Form::date($session, - { - name => "startDate", - value => $form->process("startDate") || $startDate, - defaultValue => $default_start->toUserTimeZoneDate, - }); - $var->{"formStartTime"} = WebGUI::Form::timeField($session, - { - name => "startTime", - value => $form->process("startTime") || $startTime, - defaultValue => $default_start->toUserTimeZoneTime, - }); - - # end date - $default_start->add(hours => 1); - my ($endDate,$endTime) = split / /, $self->getDateTimeEnd->toUserTimeZone - unless $func eq "add" || $self->get("assetId") eq "new"; - $var->{"formEndDate"} = WebGUI::Form::date($session, - { - name => "endDate", - value => $form->process("endDate") || $endDate, - defaultValue => $default_start->toUserTimeZoneDate, - }); - $var->{"formEndTime"} = WebGUI::Form::timeField($session, - { - name => "endTime", - value => $form->process("endTime") || $endTime, - defaultValue => $default_start->toUserTimeZoneTime, - }); - - # time - my $allday = ($form->param("allday") eq "yes" ? 1 : $self->isAllDay); - $var->{"formTime"} = - q| - -
- - -
-
| - .q|Start: |.$var->{"formStartTime"} - .q|
End: |.$var->{"formEndTime"} - .q|
|; - - # related links - $var->{"formRelatedLinks"} = WebGUI::Form::textarea($session, - { - name => "relatedLinks", - value => $form->process("relatedLinks") || $self->get("relatedLinks"), - }); - - - - ###### Recurrence tab - # Pattern - my %recur = $self->getRecurrenceFromForm || $self->getRecurrence; - $recur{every} ||= 1; - - $var->{"formRecurPattern"} = - q| -
-

-

- - -

-

-
- Every
- -
- - -
- - -

-

-
- Every week(s) on
- -
- -
- -
- -
- -
- -
- -
-
- - -

-

-
-

Every month(s) on

-

- -

- -

- - week on - -

-
- - -

-

-
-

Every years(s) on

-

- - - -

- -

- - - of - -

-
-
- |; - - - # Start - $var->{"formRecurStart"} = WebGUI::Form::date($session, - { - name => "recurStart", - value => $recur{startDate}, - defaultValue => $self->get("startDate"), - }); - - # End - $var->{"formRecurEnd"} = q| -
-
- - - | - . WebGUI::Form::date($session,{ name => "recurEndDate", value => $recur{endDate}, defaultValue => $recur{endDate} }) - . q| -
- - - - - occurences. -
- |; - - - # Include - - # Exclude - - - - - # Add button - $var->{"formSave"} = WebGUI::Form::submit($session, - { - name => "save", - value => "save", - }); - # Cancel button - $var->{"formCancel"} = WebGUI::Form::button($session, - { - name => "cancel", - value => "cancel", - extras => 'onClick="window.history.go(-1)"', - }); - - - $var->{"formFooter"} .= <<'ENDJS'; - + function toggleRecur() + { + document.getElementById("recurPattern_daily").style.display = "none"; + document.getElementById("recurPattern_weekly").style.display = "none"; + document.getElementById("recurPattern_monthly").style.display = "none"; + document.getElementById("recurPattern_yearly").style.display = "none"; + + if (document.getElementById("recurType_daily").checked) + { + document.getElementById("recurPattern_daily").style.display = "block"; + } + else if (document.getElementById("recurType_weekly").checked) + { + document.getElementById("recurPattern_weekly").style.display = "block"; + } + else if (document.getElementById("recurType_monthly").checked) + { + document.getElementById("recurPattern_monthly").style.display = "block"; + } + else if (document.getElementById("recurType_yearly").checked) + { + document.getElementById("recurPattern_yearly").style.display = "block"; + } + } + YAHOO.util.Event.onAvailable("recurPattern",function(e) { toggleRecur(); }); + ENDJS - - - - ### Show any errors if necessary - if ($self->session->stow->get("editFormErrors")) - { - my $errors = $self->session->stow->get("editFormErrors"); - push @{$var->{"formErrors"}}, { message => $_ } - for @{$errors}; - } - - - - ### Load the template - my $parent = $self->getParent; - my $template; - if ($parent) - { - $template = WebGUI::Asset::Template->new($session,$parent->get("templateIdEventEdit")); - } - else - { - $template = WebGUI::Asset::Template->new($session,"CalendarEventEdit00001"); - } - - - - ### Show the processed template - $session->http->sendHeader; - my $style = $session->style->process("~~~",$self->getParent->get("styleTemplateId")); - my ($head, $foot) = split("~~~",$style); - $self->session->output->print($head, 1); - $self->session->output->print($self->processTemplate($var, undef, $template)); - $self->session->output->print($foot, 1); - return "chunked"; + + + + ### Show any errors if necessary + if ($self->session->stow->get("editFormErrors")) + { + my $errors = $self->session->stow->get("editFormErrors"); + push @{$var->{"formErrors"}}, { message => $_ } + for @{$errors}; + } + + + + ### Load the template + my $parent = $self->getParent; + my $template; + if ($parent) + { + $template = WebGUI::Asset::Template->new($session,$parent->get("templateIdEventEdit")); + } + else + { + $template = WebGUI::Asset::Template->new($session,"CalendarEventEdit00001"); + } + + + + ### Show the processed template + $session->http->sendHeader; + my $style = $session->style->process("~~~",$self->getParent->get("styleTemplateId")); + my ($head, $foot) = split("~~~",$style); + $self->session->output->print($head, 1); + $self->session->output->print($self->processTemplate($var, undef, $template)); + $self->session->output->print($foot, 1); + return "chunked"; } @@ -2100,10 +2105,10 @@ If true, will show the printable version of the event sub www_view { my $self = shift; - return $self->session->privilege->noAccess() unless $self->canView; - my $check = $self->checkView; - return $check if (defined $check); - $self->session->http->setCacheControl($self->get("visitorCacheTimeout")) if ($self->session->user->userId eq "1"); + return $self->session->privilege->noAccess() unless $self->canView; + my $check = $self->checkView; + return $check if (defined $check); + $self->session->http->setCacheControl($self->get("visitorCacheTimeout")) if ($self->session->user->userId eq "1"); $self->session->http->sendHeader; $self->prepareView; my $style = $self->getParent->processStyle("~~~"); diff --git a/lib/WebGUI/AssetExportHtml.pm b/lib/WebGUI/AssetExportHtml.pm index f7ae2a8d6..bbd924064 100644 --- a/lib/WebGUI/AssetExportHtml.pm +++ b/lib/WebGUI/AssetExportHtml.pm @@ -41,15 +41,17 @@ These methods are available from this class: =head2 checkExportPath ( ) -Returns a descriptive error message (HTML) if the export path is not writable, does not exist, or is not specified in the per-domain WebGUI config file. +Returns a descriptive error message (HTML) if the export path is not +writable, does not exist, or is not specified in the per-domain WebGUI +config file. =cut sub checkExportPath { my $self = shift; my $error; - if(defined $self->session->config->get("exportPath")) { - if(-d $self->session->config->get("exportPath")) { + if (defined $self->session->config->get("exportPath")) { + if (-d $self->session->config->get("exportPath")) { unless (-w $self->session->config->get("exportPath")) { $error .= 'Error: The export path '.$self->session->config->get("exportPath").' is not writable.
Make sure that the webserver has permissions to write to that directory'; @@ -76,22 +78,22 @@ sub checkExportPath { # further sub _exportAsHtml { - my $self = shift; - my $quiet = shift; - my $userId = shift; - my $index = shift; + my $self = shift; + my $quiet = shift; + my $userId = shift; + my $index = shift; my $extrasUploadsAction = shift; - my $rootUrlAction = shift; - my $startTime = $self->session->datetime->time(); + my $rootUrlAction = shift; + my $startTime = $self->session->datetime->time(); - my $exportPathError = $self->checkExportPath(); + my $exportPathError = $self->checkExportPath(); if ($exportPathError) { return (0, $exportPathError); } - my $exportPath = $self->session->config->get('exportPath'); - my $defaultAssetId = $self->session->setting->get('defaultPage'); - my $defaultAssetPath = undef; + my $exportPath = $self->session->config->get('exportPath'); + my $defaultAssetId = $self->session->setting->get('defaultPage'); + my $defaultAssetPath = undef; my $i18n = WebGUI::International->new($self->session, 'Asset'); @@ -99,14 +101,15 @@ sub _exportAsHtml { $tempSession->user({userId=>$userId}); my $newSelf = WebGUI::Asset->new($tempSession, $self->getId, $self->get("className"), $self->get("revisionDate")); - my $assetIds = $newSelf->getLineage(["self","descendants"],{endingLineageLength=>$newSelf->getLineageLength+$self->session->form->process("depth")}); - $tempSession->var->end; - $tempSession->close; + # Get a list of the asset IDs we need, reverse sorted by URL + my $assetIds + = $newSelf->getLineage(["self","descendants"],{ + endingLineageLength => $newSelf->getLineageLength+$self->session->form->process("depth") + }); + # We're going to walk up the URL branch, making the deepest paths first foreach my $assetId (@{$assetIds}) { - my $assetSession = WebGUI::Session->open($self->session->config->getWebguiRoot, $self->session->config->getFilename); - $assetSession->user({userId => $userId}); - my $asset = WebGUI::Asset->newByDynamicClass($assetSession, $assetId); + my $asset = WebGUI::Asset->newByDynamicClass($tempSession, $assetId); my $url = $asset->get("url"); $self->session->output->print(sprintf($i18n->get('exporting page'), $url)) unless $quiet; @@ -121,8 +124,8 @@ sub _exportAsHtml { return (0, $error); } - my $path = $pathData->{'path'}; - my $filename = $pathData->{'filename'}; + my $path = $pathData->{'path'}; + my $filename = $pathData->{'filename'}; my $fullPath = (length($path)? "$path/" : "").$filename; if ($asset->getId eq $defaultAssetId) { @@ -156,7 +159,12 @@ sub _exportAsHtml { $self->session->output->print($i18n->get('done')) unless $quiet; } - if ($extrasUploadsAction eq 'symlink') { + # We're done with the export sessions + $tempSession->var->end; + $tempSession->close; + + + if ($extrasUploadsAction eq 'symlink') { my ($extrasPath, $uploadsPath) = ($self->session->config->get('extrasPath'), $self->session->config->get('uploadsPath')); my ($extrasUrl, $uploadsUrl) = ($self->session->config->get('extrasURL'), $self->session->config->get('uploadsURL')); s#^/*## for ($extrasUrl, $uploadsUrl); @@ -218,48 +226,33 @@ index filename passed in from the UI =cut sub _translateUrlToPath { - my $self = shift; - my $url = shift; - my $index = shift; + my $self = shift; + my $url = shift; + my $index = shift; my $dataRef; - if ($url !~ m{\.}) { # If there is not a dot in the URL, this is easy - $dataRef->{'path'} = $url; - $dataRef->{'filename'} = $index; + # If there is not a dot in the URL, this is easy + if ($url !~ m{[.]}) { + $dataRef->{'path' } = $url; + $dataRef->{'filename' } = $index; } - elsif ($url =~ /^(.*)\/(.*)$/) { # If there is a dot and a slash in the url - my $dotCounter = 0; # Track how many dots we found - my $preSlash = $1; - my $postSlash = $2; + # There is a dot + else { + # The last part after a slash is the "name" + my ($path,$name) = $url =~ m{(.*) /? ([^/]+) $}x; # NOTE: Might be more efficient to use index() and substr() - if ($preSlash =~ /\./) { # webgui url index.html/foo becomes folder foo, filename index user specified - $dotCounter++; - $dataRef->{'path'} = $postSlash; - $dataRef->{'filename'} = $index; - } - - if ($postSlash =~ /\./) { # webgui url foo/page.html becomes folder foo, filename page.html - $dotCounter++; - $dataRef->{'path'} = $preSlash; - $dataRef->{'filename'} = $postSlash; - } - - if ($postSlash eq "") { # webgui url foo.html/ becomes no path, filename foo.html - $dataRef->{'path'} = undef; - $dataRef->{'filename'} = $preSlash; - } - - if ($dotCounter == 2) { # webgui url foo.html/page.html becomes an error because this is non-sensical - $self->session->errorHandler->error("Cannot generate path for url $url. Ambiguious."); - $dataRef->{'path'} = undef; - $dataRef->{'filename'} = undef; - $dataRef->{'error'} = "Cannot generate path for url $url. Ambiguious."; - } - } - else { # Dots in the url but no slash - $dataRef->{'path'} = undef; - $dataRef->{'filename'} = $url; # webgui url foo.html becomes no path, filename foo.html - } + # If it ends in a known file type handled by apache, use that + if ($name =~ m{[.](?:html|htm|txt)$}) { + $dataRef->{'path' } = $path; + $dataRef->{'filename' } = $name; + } + else { + # It doesn't end in a known file type + # Make a directory for it + $dataRef->{'path' } = $url; + $dataRef->{'filename' } = $index; + } + } return $dataRef; } diff --git a/lib/WebGUI/AssetVersioning.pm b/lib/WebGUI/AssetVersioning.pm index 651a9d411..671ddd9f1 100644 --- a/lib/WebGUI/AssetVersioning.pm +++ b/lib/WebGUI/AssetVersioning.pm @@ -31,6 +31,11 @@ This is a mixin package for WebGUI::Asset that contains all versioning related f use WebGUI::Asset; + my $newAsset = $asset->addRevision(\%properties); + my $newAsset = $asset->addRevision(\%properties, $revisionDate, \%options); + + # TODO: Add usage for all methods available from this class + =head1 METHODS These methods are available from this class: @@ -42,7 +47,11 @@ These methods are available from this class: =head2 addRevision ( properties [ , revisionDate, options ] ) -Adds a revision of an existing asset. Note that programmers should almost never call this method directly, but rather use the update() method instead. +Creates a new revision of an existing asset. Returns the new revision of +the asset. + +Note that programmers should almost never call this method directly, but +rather use the update() method instead. =head3 properties @@ -63,30 +72,46 @@ If this is set to 1 then assets that would normally autocommit their workflow (l =cut sub addRevision { - my $self = shift; - my $properties = shift; - my $now = shift ||$self->session->datetime->time(); - my $options = shift; - my $autoCommitId = $self->getAutoCommitWorkflowId() unless ($options->{skipAutoCommitWorkflows}); - my $workingTag = ($autoCommitId) ? WebGUI::VersionTag->create($self->session, {groupToUse=>'12', workflowId=>$autoCommitId}) : WebGUI::VersionTag->getWorking($self->session); + my $self = shift; + my $properties = shift; + my $now = shift || $self->session->datetime->time(); + my $options = shift; + + my $autoCommitId = $self->getAutoCommitWorkflowId() unless ($options->{skipAutoCommitWorkflows}); + my $workingTag + = ($autoCommitId) + ? WebGUI::VersionTag->create($self->session, {groupToUse=>'12', workflowId=>$autoCommitId}) + : WebGUI::VersionTag->getWorking($self->session) + ; + $self->session->db->beginTransaction; - $self->session->db->write("insert into assetData (assetId, revisionDate, revisedBy, tagId, status, url, - ownerUserId, groupIdEdit, groupIdView) values (?, ?, ?, ?, 'pending', ?, '3','3','7')", - [$self->getId, $now, $self->session->user->userId, $workingTag->getId, $self->getId] ); - foreach my $definition (@{$self->definition($self->session)}) { - unless ($definition->{tableName} eq "assetData") { - $self->session->db->write("insert into ".$definition->{tableName}." (assetId,revisionDate) values (?,?)", [$self->getId, $now]); - } + $self->session->db->write( + "insert into assetData " + . "(assetId, revisionDate, revisedBy, tagId, status, url, ownerUserId, groupIdEdit, groupIdView) " + . "values (?, ?, ?, ?, 'pending', ?, '3','3','7')", + [$self->getId, $now, $self->session->user->userId, $workingTag->getId, $self->getId] + ); + + foreach my $definition (@{$self->definition($self->session)}) { + unless ($definition->{tableName} eq "assetData") { + $self->session->db->write( + "insert into ".$definition->{tableName}." (assetId,revisionDate) values (?,?)", + [$self->getId, $now] + ); } - $self->session->db->commit; - my $newVersion = WebGUI::Asset->new($self->session,$self->getId, $self->get("className"), $now); - $newVersion->updateHistory("created revision"); - $newVersion->update($self->get); - $newVersion->setVersionLock; - $properties->{status} = 'pending'; - $newVersion->update($properties); - $newVersion->setAutoCommitTag($workingTag) if (defined $autoCommitId); - return $newVersion; + } + + $self->session->db->commit; + + my $newVersion = WebGUI::Asset->new($self->session,$self->getId, $self->get("className"), $now); + $newVersion->updateHistory("created revision"); + $newVersion->update($self->get); + $newVersion->setVersionLock; + $properties->{status} = 'pending'; + $newVersion->update($properties); + $newVersion->setAutoCommitTag($workingTag) if (defined $autoCommitId); + + return $newVersion; } diff --git a/lib/WebGUI/DateTime.pm b/lib/WebGUI/DateTime.pm index 363d3f687..bf4dd6bec 100755 --- a/lib/WebGUI/DateTime.pm +++ b/lib/WebGUI/DateTime.pm @@ -49,17 +49,27 @@ WebGUI::DateTime - DateTime subclass with additional WebGUI methods my $dt = WebGUI::DateTime->new( year => 2006, month => 11, day => 6 ); - my $mysql = $dt->toMysql; # Make a MySQL date/time string - my $mysqlDate = $dt->toMysqlDate; # Make a MySQL date string - my $mysqlTime = $dt->toMysqlTime; # Make a MySQL time string + # Get a string to give to MySQL + my $mysqlDatetime = $dt->toDatabase; + my $mysqlDate = $dt->toDatabaseDate; + my $mysqlTime = $dt->toDatabaseTime + + # Get a string for WebGUI::Form elements + my $userDatetime = $dt->toUserTimeZone; + my $userDate = $dt->toUserTimeZoneDate; + my $userTime = $dt->toUserTimeZoneTime; + # Get strings to be used for iCalendar feeds + my $ical = $dt->toIcal; + my $icalDate = $dt->toIcalDate; + my $icalTime = $dt->toIcalTime; - my $ical = $dt->toIcal; # Make an iCal date/time string - my $icalDate = $dt->toIcalDate; # Make an iCal date string - my $icalTime = $dt->toIcalTime; # Make an iCal time string - - my $webguiDate = $dt->webguiDate($webguiFormat) #return the date based on WebGUI's date format string - + # Get a string based on the user's preferred date/time format in the user's + # time zone. + my $webguiDate = $dt->webguiDate; + + # Get a string based on a passed WebGUI date/time format + my $webguiDate = $dt->webguiDate($webguiFormat); ### See perldoc DateTime for additional methods ### @@ -209,13 +219,17 @@ sub cloneToUserTimeZone { Handle copying all WebGUI::DateTime specific data. This is a class method. +This method overrides the from_object in DateTime to keep WebGUI::DateTime +specific information being passed between object instances. Most DateTime +math actually creates new objects. + =cut sub from_object { - my $class = shift; - my %args = @_; + my $class = shift; + my %args = @_; my $session = $args{object}->session; - my $copy = $class->SUPER::from_object(@_); + my $copy = $class->SUPER::from_object(@_); $copy->session($session); return $copy; } @@ -239,7 +253,7 @@ sub toDatabase { =head2 toDatabaseDate Returns a MySQL Date string. Any time data stored by this object will be -ignored. Is not adjusted for time zone. +ignored. Is adjusted to the UTC time zone. =cut diff --git a/lib/WebGUI/Help/Asset_Calendar.pm b/lib/WebGUI/Help/Asset_Calendar.pm index 5caee5b3c..bb6332ac6 100644 --- a/lib/WebGUI/Help/Asset_Calendar.pm +++ b/lib/WebGUI/Help/Asset_Calendar.pm @@ -1,5 +1,108 @@ package WebGUI::Help::Asset_Calendar; +our $HELP = {}; + +#### Edit Calendar Page +$editPage = $HELP->{'calendar add/edit'} = {}; + +$editPage->{ title } = 'help add/edit title'; +$editPage->{ body } = 'help add/edit body'; + +push @{$editPage->{ isa }}, { + tag => 'asset fields', + namespace => 'Asset', + }, + ; + +push @{$editPage->{ fields }}, + { + title => "defaultView label", + description => "defaultView description", + namespace => "Asset_Calendar", + }, + { + title => "defaultDate label", + description => "defaultDate description", + namespace => "Asset_Calendar", + }, + { + title => "groupIdEventEdit label", + description => "groupIdEventEdit description", + namespace => "Asset_Calendar", + }, + { + title => "templateIdMonth label", + description => "templateIdMonth description", + namespace => "Asset_Calendar", + }, + { + title => "templateIdWeek label", + description => "templateIdWeek description", + namespace => "Asset_Calendar", + }, + { + title => "templateIdDay label", + description => "templateIdDay description", + namespace => "Asset_Calendar", + }, + { + title => "templateIdEvent label", + description => "templateIdEvent description", + namespace => "Asset_Calendar", + }, + { + title => "templateIdEventEdit label", + description => "templateIdEventEdit description", + namespace => "Asset_Calendar", + }, + { + title => "templateIdSearch label", + description => "templateIdSearch description", + namespace => "Asset_Calendar", + }, + { + title => "templateIdPrintMonth label", + description => "templateIdPrintMonth description", + namespace => "Asset_Calendar", + }, + { + title => "templateIdPrintWeek label", + description => "templateIdPrintWeek description", + namespace => "Asset_Calendar", + }, + { + title => "templateIdPrintDay label", + description => "templateIdPrintDay description", + namespace => "Asset_Calendar", + }, + { + title => "templateIdPrintEvent label", + description => "templateIdPrintEvent description", + namespace => "Asset_Calendar", + }, + ; + +push @{$editPage->{ related }}, + "", + "", + ; + +#### View Calendar Page + +#### Search Calendar Page + +#### ICal Calendar Page + + +#### View Month Template + +#### View Week Template + +#### View Day Template + +#### Search Template + + our $HELP = { 'calendar add/edit' => { title => 'add/edit title', diff --git a/lib/WebGUI/i18n/English/Asset_Calendar.pm b/lib/WebGUI/i18n/English/Asset_Calendar.pm index 2fba62ef0..e44b4222e 100755 --- a/lib/WebGUI/i18n/English/Asset_Calendar.pm +++ b/lib/WebGUI/i18n/English/Asset_Calendar.pm @@ -276,13 +276,10 @@ our $I18N = { context => q{Description of what the Calendar Update Feeds workflow activity does}, }, -#################### ASSET NAME #################### - 'assetName' => { - message => q{Calendar}, - lastUpdated => 1131394072, - }, - 'add/edit title' => { +#################### HELP PAGES #################### + + 'add/edit title' => { message => q|Calendar, Add/Edit|, lastUpdated => 1165878391, }, @@ -292,6 +289,13 @@ our $I18N = { lastUpdated => 1165878391, }, + + +#################### ASSET NAME #################### + 'assetName' => { + message => q{Calendar}, + lastUpdated => 1131394072, + }, }; 1;