2 $Month => (localtime)[4]
3 $Year => (localtime)[5] + 1900
18 $slots => $default_slots
23 % if ( $start->month == $end->month ) {
24 % $title = $rtdate->GetMonth( $start->month -1 ). ' '.
25 % $start->day. '-'. $end->day. ', '. $start->year;
26 % } elsif ( $start->year == $end->year ) {
28 % $rtdate->GetMonth( $start->month -1 ). ' '. $start->day. ' - '.
29 % $rtdate->GetMonth( $end->month -1 ). ' '. $end->day. ', '. $end->year;
32 % $rtdate->GetMonth( $start->month -1 ).' '.$start->day.', '.$start->year.
34 % $rtdate->GetMonth( $end->month -1 ). ' '.$end->day. ', '. $end->year;
37 % $title = $rtdate->GetMonth($Month) . " $Year"
42 <& /Elements/Header, Title => $title &>
47 <&| /Widgets/TitleBox,
48 title => loc('Calendar for '). $title,
49 title_class=> 'inverse',
52 % my($PMonth, $PYear, $NMonth, $NYear);
53 % unless ( $WeekDay ) {
58 % ($PMonth, $PYear) = ($Month - 1, $Year);
63 <a href="<%$RT::WebPath%>/Search/<%$Embed||'Calendar.html'%>?Month=<%$PMonth%>&Year=<%$PYear%>&<%$QueryString%>">«<%$rtdate->GetMonth($PMonth)%></a>
66 <font size="+1"><% $rtdate->GetMonth($Month). " $Year" %></font>
69 % ($NMonth, $NYear) = ($Month + 1, $Year);
74 <a href="<%$RT::WebPath%>/Search/<%$Embed||'Calendar.html'%>?Month=<%$NMonth%>&Year=<%$NYear%>&<%$QueryString%>"><%$rtdate->GetMonth($NMonth)%>»</a>
80 <table class="rtxcalendar">
84 <td class="labels" colspan=<% $WeekDay ? 2 : 1 %>></td>
85 % for ( @{$week{$weekstart}} ) {
86 <th colspan=<% $WeekDay ? $slots : 1 %>><%$rtdate->GetWeekday($_)%></th>
95 <td class="controls" rowspan=<% $rowspan+2 %> valign="middle">
96 <& week_collapse, date=>$start, Month=>$OrigMonth, Year=>$OrigYear, QueryString=>$QueryString, Embed=>$Embed, &>
100 <& td_week_expand, date=>$start, Month=>$Month, Year=>$Year, QueryString=>$QueryString, Embed=>$Embed, &>
105 <td class="labels"></td>
108 % while ($date <= $end) {
110 % my $is_today = (DateTime->compare($today, $date) == 0);
111 % my $is_yesterday = (DateTime->compare($yesterday, $date) == 0);
112 % my $is_aweekago = (DateTime->compare($aweekago, $date) == 0);
114 <td colspan=<%$slots%>
116 <% $is_today ? 'today'
117 : $is_yesterday ? 'yesterday'
118 : $is_aweekago ? 'aweekago'
122 <div class="<% $is_today ? 'todays'
125 ><% $rtdate->GetMonth($date->month-1). ' '. $date->day %></div>
129 % $date = $set->next($date);
130 % if ( $date->day_of_week == $startday_of_week ) {
132 % if ( $date <= $end ) { #a second week? not going to work for week view yet
134 <td class="controls" rowspan=<% $rowspan + 2 %> valign="middle">
135 <& week_collapse, date=>$date, Month=>$OrigMonth, Year=>$OrigYear, QueryString=>$QueryString, Embed=>$Embed, &>
140 % } #while ($date <= $end)
145 % #slot header callback
146 % if ( defined($Display) && $Display =~ /^(\w+)$/ ) {
148 % my $el = "/Elements/CalendarSlotHeader$1";
149 <td class="labels"></td>
151 <& $el, Date => $date,
152 DateTypes => \%DateTypes,
160 % foreach my $row ( @week_rows ) {
167 % while ($date <= $end) {
169 % my $is_today = (DateTime->compare($today, $date) == 0);
170 % my $is_yesterday = (DateTime->compare($yesterday, $date) == 0);
171 % my $is_aweekago = (DateTime->compare($aweekago, $date) == 0);
174 % if ( defined($Display) && $Display =~ /^(\w+)$/ ) {
175 % my $el = "/Elements/CalendarSlot$1";
176 <& $el, Date => $date,
177 DateTypes => \%DateTypes,
178 Tickets => $Tickets{$date->strftime("%F")} || [],
182 timestep => $timestep,
187 % #just display the normal events for this day?
188 <td class="weekly" colspan="<%$slots%>">
189 % for my $Ticket ( @{ $Tickets{$date->strftime("%F")} } ) {
193 % my $meth = $_.'Obj';
195 % #XXX off by 1h on daylight savings boundaries.. 2 sundays a year
196 % my $tod = ( $Ticket->$meth->Unix
197 % - $Ticket->$meth->SetToMidnight(Timezone=>'user')
200 % RTx::Calendar::LocalDate($Ticket->$meth->Unix) eq $date->strftime('%F') #today
201 % && $tod >= $row && $tod < ($row+$timestep); #and in timeslot
203 % next unless keys %dt;
204 <& /Elements/CalendarEvent,
209 % unless ( $Ticket eq ${ $Tickets{$date->strftime("%F")} }[-1] ) { #hmm, no.. not with "next unless $dt" :/
217 % $date = $set->next($date);
218 % if ( $date->day_of_week == $startday_of_week ) {
220 % if ( $date <= $end ) { #a second week? not going to work for week view yet
222 <td class="controls" rowspan=<% $rowspan + 2 %> valign="middle">
223 <& week_collapse, date=>$date, Month=>$OrigMonth, Year=>$OrigYear, QueryString=>$QueryString, Embed=>$Embed, &>
229 % } #while ($date <= $end)
231 % } #foreach my $row ( @week_rows )
236 % while ($date <= $end) {
238 % my $offmonth = !$WeekDay && $date->month != ($Month + 1);
239 % my $is_today = (DateTime->compare($today, $date) == 0);
240 % my $is_yesterday = (DateTime->compare($yesterday, $date) == 0);
241 % my $is_aweekago = (DateTime->compare($aweekago, $date) == 0);
244 class="<% $offmonth ? 'offmonth'
245 : $is_today ? 'today'
246 : $is_yesterday ? 'yesterday'
247 : $is_aweekago ? 'aweekago'
251 <div class="<% $is_today ? 'todays'
252 : $offmonth ? 'offmonth'
255 ><% $date->day %></div>
257 % if ( defined($Display) && $Display =~ /^(\w+)$/ ) {
259 % my $el = "/Elements/CalendarDay$1";
260 <& $el, Tickets => $Tickets{$date->strftime("%F")},
262 DateTypes => \%DateTypes,
269 % for my $t ( @{ $Tickets{$date->strftime("%F")} } ) {
271 <& /Elements/CalendarEvent, Object => $t, Date => $date, DateTypes => \%DateTypes &>
273 <% ($sp>0) ? '<BR>'x$sp : '' |n %>
279 % $date = $set->next($date);
280 % if ( $date->day_of_week == $startday_of_week ) {
282 % if ( $date <= $end ) {
284 <& td_week_expand, date=>$date, Month=>$Month, Year=>$Year, QueryString=>$QueryString, Embed=>$Embed, &>
288 % } #while ($date <= $end)
294 % unless ( $WeekDay ) {
299 <a href="<%$RT::WebPath%>/Search/<%$Embed||'Calendar.html'%>?Month=<%$PMonth%>&Year=<%$PYear%>&<%$QueryString%>">«<%$rtdate->GetMonth($PMonth)%></a>
302 <td valign="top" align="center">
303 <form action="<%$RT::WebPath%>/Search/<%$Embed||'Calendar.html'%>?<%$QueryString%>" method="post">
305 <select name="Month">
307 <option value="<%$_%>" <% $_ == $Month ? 'selected' : ''%> ><%$rtdate->GetMonth($_)%></option>
311 % my $year = (localtime)[5] + 1900;
313 % for ( ($year-5) .. ($year+5)) {
314 <option value="<%$_%>" <% $_ == $Year ? 'selected' : ''%>><%$_%></option>
318 %# <& /Elements/Submit&>
319 <input type="submit" value="<% loc('Submit') %>" class="button" />
325 <a href="<%$RT::WebPath%>/Search/<%$Embed||'Calendar.html'%>?Month=<%$NMonth%>&Year=<%$NYear%>&<%$QueryString%>"><%$rtdate->GetMonth($NMonth)%>»</a>
332 % unless ( $Embed ) {
337 <td valign="top" rowspan=9>
339 <a href="<%$RT::WebPath%>/Prefs/Calendar.html">Calendar Preferences and Help</a>
342 % foreach my $legend (keys %legend) {
345 <img src="<%$RT::WebImagesURL%>/<%$legend%>.png" />
349 % foreach ( @{$legend{$legend}} ) {
350 <% $more++ ? ', ' : '' %>
366 'created' => ['Created'],
368 'resolved' => ['Resolved'],
369 'updated' => ['Last Updated'],
370 'created_due' => ['Created','Due'],
371 'reminder' => ['Reminders'],
372 'started' => ['Started'],
373 'starts_due' => ['Starts','Due'],
376 my $stime = RT->Config->Get('CalendarWeeklyStartMin');
377 $stime = 480 unless $stime =~ /^\d+$/; #8am
378 my $etime = RT->Config->Get('CalendarWeeklyEndMin');
379 $etime = 1080 unless $etime =~ /^\d+$/; #6pm
381 my $timestep = RT->Config->Get('CalendarWeeklySizeMin') || 30; #1/2h
382 my $rowspan = ($etime-$stime) / $timestep;
384 my $default_slots = RT->Config->Get('CalendarWeeklySlots') || 5;
388 while ( $wt < $etime ) { push @week_rows, $wt; $wt+=$timestep }
392 use RTx::Calendar qw(FirstDay LastDay LastDayOfWeek);
394 $Embed =~ /^[\w\.]*$/ or die 'xss';
396 my $title = loc("Calendar");
398 my @DateTypes = qw/Created Starts Started Due LastUpdated Resolved/;
400 my $rtdate = RT::Date->new($session{'CurrentUser'});
402 my $time_zone = $session{'CurrentUser'}->UserObj->Timezone
403 || RT->Config->Get('Timezone');
405 my $weekstart = 'Sunday'; #RT::SiteConfig? user pref?
407 'Saturday' => [6,0..5],
409 'Monday' => [1..6,0],
411 my $startday_of_week = ${$week{$weekstart}}[0] || 7;
412 my $endday_of_week = ${$week{$weekstart}}[-1] || 7;
414 my $today = DateTime->today( time_zone=>$time_zone );
415 my $yesterday = $today->clone->subtract( days=>1 );
416 my $aweekago = $today->clone->subtract( days=>7 );
420 $start = DateTime->new( year => $WeekYear,
421 month => $WeekMonth+1,
423 time_zone => $time_zone,
425 $end = LastDayOfWeek( $WeekYear, $WeekMonth+1, $WeekDay, $endday_of_week );
427 $start = FirstDay($Year, $Month + 1, $startday_of_week );
428 $end = LastDay ($Year, $Month + 1, $endday_of_week );
431 # use this to loop over days until $end
432 my $set = DateTime::Set->from_recurrence(
433 next => sub { $_[0]->truncate( to => 'day' )->add( days => 1 ) }
440 '/Elements/QueryString',
445 Rows => $RowsPerPage,
451 '/Elements/QueryString',
457 # Default Query and Format
458 my $TempFormat = "__Starts__ __Due__";
459 my $TempQuery = "( Status = 'new' OR Status = 'open' OR Status = 'stalled')
460 AND ( Owner = '" . $session{CurrentUser}->Id ."' OR Owner = 'Nobody' )
461 AND ( Type = 'reminder' OR 'Type' = 'ticket' )";
463 if ( my $Search = RTx::Calendar::SearchDefaultCalendar($session{CurrentUser}) ) {
464 $TempFormat = $Search->SubValue('Format');
465 $TempQuery = $Search->SubValue('Query');
468 # we overide them if needed
469 $TempQuery = $Query if $Query;
470 $TempFormat = $Format if $Format;
472 # we search all date types in Format string
473 my @Dates = grep { $TempFormat =~ m/__${_}(Relative)?__/ } @DateTypes;
475 # used to display or not a date in Element/CalendarEvent
476 my %DateTypes = map { $_ => 1 } @Dates;
478 $TempQuery .= RTx::Calendar::DatesClauses(\@Dates, $start->strftime("%F"), $end->strftime("%F"));
480 # print STDERR ("-" x 30), "\n", $TempQuery, "\n";
482 my %Tickets = RTx::Calendar::FindTickets($session{'CurrentUser'}, $TempQuery, \@Dates, $start->strftime("%F"), $end->strftime("%F"));
485 <%def td_week_expand>
490 $QueryString => undef
493 <td class="controls">
494 <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>
503 $QueryString => undef
506 <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"></a>
510 % my( $min ) = shift;
511 <td class="labels"><% pretty_time($min) |n %></td>
516 return 'Midnight' if $t == 0 || $t == 1440;
517 return 'Noon' if $t == 720;
519 my $h = int( $t / 60 );
523 if ( $h == 0 || $h == 24 ) { $h = 12; }
524 elsif ( $h == 12 ) { $ap = 'PM'; }
525 elsif ( $h > 12 ) { $ap = 'PM'; $h -= 12; }
527 sprintf('%02d:%02d '.$ap, $h, $m);