2 $Month => (localtime)[4]
3 $Year => (localtime)[5] + 1900
18 $slots => $default_slots
24 % if ( $start->month == $end->month ) {
25 % $title = $rtdate->GetMonth( $start->month -1 ). ' '.
26 % $start->day. '-'. $end->day. ', '. $start->year;
27 % } elsif ( $start->year == $end->year ) {
29 % $rtdate->GetMonth( $start->month -1 ). ' '. $start->day. ' - '.
30 % $rtdate->GetMonth( $end->month -1 ). ' '. $end->day. ', '. $end->year;
33 % $rtdate->GetMonth( $start->month -1 ).' '.$start->day.', '.$start->year.
35 % $rtdate->GetMonth( $end->month -1 ). ' '.$end->day. ', '. $end->year;
38 % $title = $rtdate->GetMonth($Month) . " $Year"
43 <& /Elements/Header, Title => $title &>
48 <&| /Widgets/TitleBox,
49 title => loc('Calendar for '). $title,
50 title_class=> 'inverse',
53 % my($PMonth, $PYear, $NMonth, $NYear);
54 % unless ( $WeekDay ) {
59 % ($PMonth, $PYear) = ($Month - 1, $Year);
64 <a href="<%$RT::WebPath%>/Search/<%$Embed||'Calendar.html'%>?Month=<%$PMonth%>&Year=<%$PYear%>&<%$QueryString%>">«<%$rtdate->GetMonth($PMonth)%></a>
67 <font size="+1"><% $rtdate->GetMonth($Month). " $Year" %></font>
70 % ($NMonth, $NYear) = ($Month + 1, $Year);
75 <a href="<%$RT::WebPath%>/Search/<%$Embed||'Calendar.html'%>?Month=<%$NMonth%>&Year=<%$NYear%>&<%$QueryString%>"><%$rtdate->GetMonth($NMonth)%>»</a>
81 <table class="<% $WeekDay ? 'rtxweeklycalendar' : 'rtxcalendar' %>">
85 % unless ( $WeekDay ) {
88 <td class="labels" colspan=<% $WeekDay ? 2 : 1 %>></td>
89 % for ( @{$week{$weekstart}} ) {
90 <th colspan=<% $WeekDay ? $slots : 1 %>><%$rtdate->GetWeekday($_)%></th>
100 % unless ( $WeekDay ) {
101 <& td_week_expand, date=>$start, Month=>$Month, Year=>$Year, QueryString=>$QueryString, Embed=>$Embed, &>
106 <td class="labels" colspan=2></td>
110 % while ($date <= $end) {
112 % my $is_today = (DateTime->compare($today, $date) == 0);
113 % my $is_yesterday = (DateTime->compare($yesterday, $date) == 0);
114 % my $is_aweekago = (DateTime->compare($aweekago, $date) == 0);
116 <th colspan=<%$slots%>
118 %# <% $is_today ? 'today'
119 %# : $is_yesterday ? 'yesterday'
120 %# : $is_aweekago ? 'aweekago'
123 %# <div class="<% $is_today ? 'todays'
126 ><% $rtdate->GetWeekday( $week{$weekstart}->[$sday++] ). ' '.
127 $rtdate->GetMonth($date->month-1). ' '.
132 % $date = $set->next($date);
133 % if ( $date->day_of_week == $startday_of_week ) {
135 % if ( $date <= $end ) { #a second week? not going to work for week view yet
137 <td class="controls" rowspan=<% $rowspan + 2 %> valign="middle">
138 <& week_collapse, date=>$date, Month=>$OrigMonth, Year=>$OrigYear, QueryString=>$QueryString, Embed=>$Embed, &>
143 % } #while ($date <= $end)
152 <td class="controls" rowspan=<% $rowspan+1 %> valign="middle">
153 <& week_collapse, date=>$start, Month=>$OrigMonth, Year=>$OrigYear, QueryString=>$QueryString, Embed=>$Embed, &>
156 % #slot header callback
157 % if ( defined($Display) && $Display =~ /^(\w+)$/ ) {
159 % my $el = "/Elements/CalendarSlotHeader$1";
160 <td class="labels"></td>
162 <& $el, Date => $date,
163 DateTypes => \%DateTypes,
171 % foreach my $row ( @week_rows ) {
178 % while ($date <= $end) {
180 % my $is_today = (DateTime->compare($today, $date) == 0);
181 % my $is_yesterday = (DateTime->compare($yesterday, $date) == 0);
182 % my $is_aweekago = (DateTime->compare($aweekago, $date) == 0);
185 % if ( defined($Display) && $Display =~ /^(\w+)$/ ) {
186 % my $el = "/Elements/CalendarSlot$1";
187 <& $el, Date => $date,
188 DateTypes => \%DateTypes,
189 Tickets => $Tickets{$date->strftime("%F")} || [],
193 timestep => $timestep,
198 % #just display the normal events for this day?
199 <td class="weekly" colspan="<%$slots%>">
200 % for my $Ticket ( @{ $Tickets{$date->strftime("%F")} } ) {
204 % my $meth = $_.'Obj';
206 % my($m, $h) = ($Ticket->$meth->Localtime('user'))[1,2];
207 % my $tod = $h*60 + $m;
209 % LocalDate($Ticket->$meth->Unix) eq $date->strftime('%F') #today
210 % && $tod >= $row && $tod < ($row+$timestep); #and in timeslot
212 % next unless keys %dt;
213 <& /Elements/CalendarEvent,
218 % unless ( $Ticket eq ${ $Tickets{$date->strftime("%F")} }[-1] ) { #hmm, no.. not with "next unless $dt" :/
226 % $date = $set->next($date);
227 % if ( $date->day_of_week == $startday_of_week ) {
229 % if ( $date <= $end ) { #a second week? not going to work for week view yet
231 <td class="controls" rowspan=<% $rowspan + 2 %> valign="middle">
232 <& week_collapse, date=>$date, Month=>$OrigMonth, Year=>$OrigYear, QueryString=>$QueryString, Embed=>$Embed, &>
238 % } #while ($date <= $end)
240 % } #foreach my $row ( @week_rows )
245 % while ($date <= $end) {
247 % my $offmonth = !$WeekDay && $date->month != ($Month + 1);
248 % my $is_today = (DateTime->compare($today, $date) == 0);
249 % my $is_yesterday = (DateTime->compare($yesterday, $date) == 0);
250 % my $is_aweekago = (DateTime->compare($aweekago, $date) == 0);
252 % my $past = $DimPast && DateTime->compare($today, $date) == 1;
255 class="<% $past ? 'past' : '' %><% $offmonth ? 'offmonth' : '' %><%
257 : $is_yesterday ? ' yesterday'
258 : $is_aweekago ? ' aweekago'
262 <div class="<% $is_today ? 'todays'
263 : ( $past ? 'past' : ''). ($offmonth ? 'offmonth' : '' )
265 ><% $date->day %></div>
267 % if ( defined($Display) && $Display =~ /^(\w+)$/ ) {
269 % my $el = "/Elements/CalendarDay$1";
270 <& $el, CurrentUser => $session{CurrentUser},
271 Tickets => $Tickets{$date->strftime("%F")},
274 DateTypes => \%DateTypes,
281 % for my $t ( @{ $Tickets{$date->strftime("%F")} } ) {
283 <& /Elements/CalendarEvent, Object => $t, Date => $date, DateTypes => \%DateTypes &>
285 <% ($sp>0) ? '<BR>'x$sp : '' |n %>
291 % $date = $set->next($date);
292 % if ( $date->day_of_week == $startday_of_week ) {
294 % if ( $date <= $end ) {
296 <& td_week_expand, date=>$date, Month=>$Month, Year=>$Year, QueryString=>$QueryString, Embed=>$Embed, &>
300 % } #while ($date <= $end)
306 % unless ( $WeekDay ) {
311 <a href="<%$RT::WebPath%>/Search/<%$Embed||'Calendar.html'%>?Month=<%$PMonth%>&Year=<%$PYear%>&<%$QueryString%>">«<%$rtdate->GetMonth($PMonth)%></a>
314 <td valign="top" align="center">
315 <form action="<%$RT::WebPath%>/Search/<%$Embed||'Calendar.html'%>?<%$QueryString%>" method="post">
317 <select name="Month">
319 <option value="<%$_%>" <% $_ == $Month ? 'selected' : ''%> ><%$rtdate->GetMonth($_)%></option>
323 % my $year = (localtime)[5] + 1900;
325 % for ( ($year-5) .. ($year+5)) {
326 <option value="<%$_%>" <% $_ == $Year ? 'selected' : ''%>><%$_%></option>
330 %# <& /Elements/Submit&>
331 <input type="submit" value="<% loc('Submit') %>" class="button" />
337 <a href="<%$RT::WebPath%>/Search/<%$Embed||'Calendar.html'%>?Month=<%$NMonth%>&Year=<%$NYear%>&<%$QueryString%>"><%$rtdate->GetMonth($NMonth)%>»</a>
344 % unless ( $Embed ) {
349 <td valign="top" rowspan=9>
351 <a href="<%$RT::WebPath%>/Prefs/Calendar.html">Calendar Preferences and Help</a>
354 % foreach my $legend (keys %legend) {
357 <img src="<%$RT::WebImagesURL%>/<%$legend%>.png" />
361 % foreach ( @{$legend{$legend}} ) {
362 <% $more++ ? ', ' : '' %>
378 'created' => ['Created'],
380 'resolved' => ['Resolved'],
381 'updated' => ['Last Updated'],
382 'created_due' => ['Created','Due'],
383 'reminder' => ['Reminders'],
384 'started' => ['Started'],
385 'starts_due' => ['Starts','Due'],
388 my $stime = RT->Config->Get('CalendarWeeklyStartMin');
389 $stime = 480 unless $stime =~ /^\d+$/; #8am
390 my $etime = RT->Config->Get('CalendarWeeklyEndMin');
391 $etime = 1080 unless $etime =~ /^\d+$/; #6pm
393 my $timestep = RT->Config->Get('CalendarWeeklySizeMin') || 30; #1/2h
394 my $rowspan = ($etime-$stime) / $timestep;
396 my $default_slots = RT->Config->Get('CalendarWeeklySlots') || 5;
400 while ( $wt < $etime ) { push @week_rows, $wt; $wt+=$timestep }
404 use RTx::Calendar qw( FirstDay LastDay LastDayOfWeek DatesClauses LocalDate
405 SearchDefaultCalendar FindTickets );
407 $Embed =~ /^[\w\.]*$/ or die 'xss';
409 my $title = loc("Calendar");
411 my @DateTypes = qw/Created Starts Started Due LastUpdated Resolved/;
413 my $rtdate = RT::Date->new($session{'CurrentUser'});
415 my $time_zone = $session{'CurrentUser'}->UserObj->Timezone
416 || RT->Config->Get('Timezone');
418 my $weekstart = 'Sunday'; #RT::SiteConfig? user pref?
420 'Saturday' => [6,0..5],
422 'Monday' => [1..6,0],
424 my $startday_of_week = ${$week{$weekstart}}[0] || 7;
425 my $endday_of_week = ${$week{$weekstart}}[-1] || 7;
427 my $today = DateTime->today( time_zone=>$time_zone );
428 my $yesterday = $today->clone->subtract( days=>1 );
429 my $aweekago = $today->clone->subtract( days=>7 );
433 $start = DateTime->new( year => $WeekYear,
434 month => $WeekMonth+1,
436 time_zone => $time_zone,
438 $end = LastDayOfWeek( $WeekYear, $WeekMonth+1, $WeekDay, $endday_of_week );
440 $start = FirstDay($Year, $Month + 1, $startday_of_week );
441 $end = LastDay ($Year, $Month + 1, $endday_of_week );
444 # use this to loop over days until $end
445 my $set = DateTime::Set->from_recurrence(
446 next => sub { $_[0]->truncate( to => 'day' )->add( days => 1 ) }
453 '/Elements/QueryString',
458 Rows => $RowsPerPage,
464 '/Elements/QueryString',
470 # Default Query and Format
471 my $TempFormat = "__Starts__ __Due__";
472 my $TempQuery = "( Status = 'new' OR Status = 'open' OR Status = 'stalled')
473 AND ( Owner = '" . $session{CurrentUser}->Id ."' OR Owner = 'Nobody' )
474 AND ( Type = 'reminder' OR 'Type' = 'ticket' )";
476 if ( my $Search = SearchDefaultCalendar($session{CurrentUser}) ) {
477 $TempFormat = $Search->SubValue('Format');
478 $TempQuery = $Search->SubValue('Query');
481 # we overide them if needed
482 $TempQuery = $Query if $Query;
483 $TempFormat = $Format if $Format;
485 # we search all date types in Format string
486 my @Dates = grep { $TempFormat =~ m/__${_}(Relative)?__/ } @DateTypes;
488 # used to display or not a date in Element/CalendarEvent
489 my %DateTypes = map { $_ => 1 } @Dates;
491 $TempQuery .= DatesClauses(\@Dates, $start->strftime("%F"), $end->strftime("%F"));
493 # print STDERR ("-" x 30), "\n", $TempQuery, "\n";
495 my %Tickets = FindTickets($session{'CurrentUser'}, $TempQuery, \@Dates, $start->strftime("%F"), $end->strftime("%F"));
498 <%def td_week_expand>
503 $QueryString => undef
506 <td class="controls">
507 <a href="<%$RT::WebPath%>/Search/<%$Embed||'Calendar.html'%>?WeekDay=<% $date->day %>&WeekMonth=<% $date->month -1 %>&WeekYear=<% $date->year %>&OrigMonth=<% $Month %>&OrigYear=<% $Year %>&<%$QueryString%>"><img src="<%$RT::WebPath%>/NoAuth/images/week-expand.gif"></a>
516 $QueryString => undef
519 <a href="<%$RT::WebPath%>/Search/<%$Embed||'Calendar.html'%>?Month=<% $Month %>&Year=<% $Year %>&<%$QueryString%>"><img src="<%$RT::WebPath%>/NoAuth/images/week-collapse.gif" STYLE="height:384px;width:11px;border:none"></a>
523 % my( $min ) = shift;
524 <td class="labels"><% pretty_time($min) |n %></td>
529 return 'Midnight' if $t == 0 || $t == 1440;
530 return 'Noon' if $t == 720;
532 my $h = int( $t / 60 );
536 if ( $h == 0 || $h == 24 ) { $h = 12; }
537 elsif ( $h == 12 ) { $ap = 'PM'; }
538 elsif ( $h > 12 ) { $ap = 'PM'; $h -= 12; }
540 sprintf('%02d:%02d '.$ap, $h, $m);