%args>
$Month => (localtime)[4]
$Year => (localtime)[5] + 1900
$Query => undef
$Format => undef
$Order => undef
$OrderBy => undef
$RowsPerPage => undef
$NewQuery => 0
$WeekDay => undef
$WeekMonth => undef
$WeekYear => undef
$OrigMonth => undef
$OrigYear => undef
%args>
<& /Elements/Header, Title => $title &>
<& /Elements/Tabs &>
<&| /Widgets/TitleBox,
title => loc('Calendar for ') . $rtdate->GetMonth($Month) . " $Year" ,
title_class=> 'inverse',
color => "#993333" &>
% my($PMonth, $PYear, $NMonth, $NYear);
% unless ( $WeekDay ) {
% }
|
% for ( @{$week{$weekstart}} ) {
<%$rtdate->GetWeekday($_)%> |
% }
% if ( $WeekDay ) {
<& td_week_collapse, date=>$date, Month=>$OrigMonth, Year=>$OrigYear, QueryString=>$QueryString &>
% } else {
<& td_week_expand, date=>$date, Month=>$Month, Year=>$Year, QueryString=>$QueryString &>
% }
% while ($date <= $end) {
%
% my $offmonth = $date->month != ($Month + 1);
% my $is_today = (DateTime->compare($today, $date) == 0);
% my $is_yesterday = (DateTime->compare($yesterday, $date) == 0);
% my $is_aweekago = (DateTime->compare($aweekago, $date) == 0);
<% ( $WeekDay ? $rtdate->GetMonth($date->month). ' ' : '' ).
$date->day
%>
% my $sp = 3;
% for my $t ( @{ $Tickets{$date->strftime("%F")} } ) {
% $sp--;
<& /Elements/CalendarEvent, Object => $t, Date => $date, DateTypes => \%DateTypes &>
% }
<% ($sp>0) ? ' 'x$sp : '' |n %>
|
% $date = $set->next($date);
% if ( $date->day_of_week == $startday_of_week ) {
% if ( $date <= $end ) {
% if ( $WeekDay ) {
<& td_week_collapse, date=>$date, Month=>$OrigMonth, Year=>$OrigYear, QueryString=>$QueryString &>
% } else {
<& td_week_expand, date=>$date, Month=>$Month, Year=>$Year, QueryString=>$QueryString &>
% }
% }
% }
% }
% unless ( $WeekDay ) {
% }
% #XXX an option to turn off "Calendar Preferences and Help" for embedded
% # (and weekly?) use
Calendar Preferences and Help
|
% foreach my $legend (keys %legend) {
|
% my $more = 0;
% foreach ( @{$legend{$legend}} ) {
<% $more++ ? ', ' : '' %>
<&|/l&><% $_ %>&>
% }
|
% }
&>
<%ONCE>
my %legend = (
'created' => ['Created'],
'due' => ['Due'],
'resolved' => ['Resolved'],
'updated' => ['Last Updated'],
'created_due' => ['Created','Due'],
'reminder' => ['Reminders'],
'started' => ['Started'],
'starts_due' => ['Starts','Due'],
);
%ONCE>
<%INIT>
use RTx::Calendar qw(FirstDay LastDay LastDayOfWeek);
my $title = loc("Calendar");
my @DateTypes = qw/Created Starts Started Due LastUpdated Resolved/;
my $rtdate = RT::Date->new($session{'CurrentUser'});
my $weekstart = 'Sunday'; #RT::SiteConfig? user pref?
my %week = (
'Saturday' => [6,0..5],
'Sunday' => [0..6],
'Monday' => [1..6,0],
);
my $startday_of_week = ${$week{$weekstart}}[0] || 7;
my $endday_of_week = ${$week{$weekstart}}[-1] || 7;
my $today = DateTime->today;
my $yesterday = $today->clone->subtract( days=>1 );
my $aweekago = $today->clone->subtract( days=>7 );
my( $date, $end);
if ( $WeekDay ) {
$date = DateTime->new( year=>$WeekYear, month=>$WeekMonth, day=>$WeekDay );
$end = LastDayOfWeek( $WeekYear, $WeekMonth, $WeekDay, $endday_of_week );
} else {
$date = FirstDay($Year, $Month + 1, $startday_of_week );
$end = LastDay ($Year, $Month + 1, $endday_of_week );
}
# use this to loop over days until $end
my $set = DateTime::Set->from_recurrence(
next => sub { $_[0]->truncate( to => 'day' )->add( days => 1 ) }
);
my $QueryString =
$m->comp(
'/Elements/QueryString',
Query => $Query,
Format => $Format,
Order => $Order,
OrderBy => $OrderBy,
Rows => $RowsPerPage
)
if ($Query);
$QueryString ||= 'NewQuery=1';
# Default Query and Format
my $TempFormat = "__Starts__ __Due__";
my $TempQuery = "( Status = 'new' OR Status = 'open' OR Status = 'stalled')
AND ( Owner = '" . $session{CurrentUser}->Id ."' OR Owner = 'Nobody' )
AND ( Type = 'reminder' OR 'Type' = 'ticket' )";
if ( my $Search = RTx::Calendar::SearchDefaultCalendar($session{CurrentUser}) ) {
$TempFormat = $Search->SubValue('Format');
$TempQuery = $Search->SubValue('Query');
}
# we overide them if needed
$TempQuery = $Query if $Query;
$TempFormat = $Format if $Format;
# we search all date types in Format string
my @Dates = grep { $TempFormat =~ m/__${_}(Relative)?__/ } @DateTypes;
# used to display or not a date in Element/CalendarEvent
my %DateTypes = map { $_ => 1 } @Dates;
$TempQuery .= RTx::Calendar::DatesClauses(\@Dates, $date->strftime("%F"), $end->strftime("%F"));
# print STDERR ("-" x 30), "\n", $TempQuery, "\n";
my %Tickets = RTx::Calendar::FindTickets($session{'CurrentUser'}, $TempQuery, \@Dates, $date->strftime("%F"), $end->strftime("%F"));
%INIT>
<%def td_week_expand>
<%args>
$date => undef
$Month => undef
$Year => undef
$QueryString => undef
%args>
|
%def>
<%def td_week_collapse>
<%args>
$date => undef
$Month => undef
$Year => undef
$QueryString => undef
%args>
|
%def>