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 % unless ( $WeekDay ) {
87 <td class="labels" colspan=<% $WeekDay ? 2 : 1 %>></td>
88 % for ( @{$week{$weekstart}} ) {
89 <th colspan=<% $WeekDay ? $slots : 1 %>><%$rtdate->GetWeekday($_)%></th>
99 % unless ( $WeekDay ) {
100 <& td_week_expand, date=>$start, Month=>$Month, Year=>$Year, QueryString=>$QueryString, Embed=>$Embed, &>
105 <td class="labels" colspan=2></td>
109 % while ($date <= $end) {
111 % my $is_today = (DateTime->compare($today, $date) == 0);
112 % my $is_yesterday = (DateTime->compare($yesterday, $date) == 0);
113 % my $is_aweekago = (DateTime->compare($aweekago, $date) == 0);
115 <th colspan=<%$slots%>
117 %# <% $is_today ? 'today'
118 %# : $is_yesterday ? 'yesterday'
119 %# : $is_aweekago ? 'aweekago'
122 %# <div class="<% $is_today ? 'todays'
125 ><% $rtdate->GetWeekday( $week{$weekstart}->[$sday++] ). ' '.
126 $rtdate->GetMonth($date->month-1). ' '.
131 % $date = $set->next($date);
132 % if ( $date->day_of_week == $startday_of_week ) {
134 % if ( $date <= $end ) { #a second week? not going to work for week view yet
136 <td class="controls" rowspan=<% $rowspan + 2 %> valign="middle">
137 <& week_collapse, date=>$date, Month=>$OrigMonth, Year=>$OrigYear, QueryString=>$QueryString, Embed=>$Embed, &>
142 % } #while ($date <= $end)
151 <td class="controls" rowspan=<% $rowspan+1 %> valign="middle">
152 <& week_collapse, date=>$start, Month=>$OrigMonth, Year=>$OrigYear, QueryString=>$QueryString, Embed=>$Embed, &>
155 % #slot header callback
156 % if ( defined($Display) && $Display =~ /^(\w+)$/ ) {
158 % my $el = "/Elements/CalendarSlotHeader$1";
159 <td class="labels"></td>
161 <& $el, Date => $date,
162 DateTypes => \%DateTypes,
170 % foreach my $row ( @week_rows ) {
177 % while ($date <= $end) {
179 % my $is_today = (DateTime->compare($today, $date) == 0);
180 % my $is_yesterday = (DateTime->compare($yesterday, $date) == 0);
181 % my $is_aweekago = (DateTime->compare($aweekago, $date) == 0);
184 % if ( defined($Display) && $Display =~ /^(\w+)$/ ) {
185 % my $el = "/Elements/CalendarSlot$1";
186 <& $el, Date => $date,
187 DateTypes => \%DateTypes,
188 Tickets => $Tickets{$date->strftime("%F")} || [],
192 timestep => $timestep,
197 % #just display the normal events for this day?
198 <td class="weekly" colspan="<%$slots%>">
199 % for my $Ticket ( @{ $Tickets{$date->strftime("%F")} } ) {
203 % my $meth = $_.'Obj';
205 % my($m, $h) = ($Ticket->$meth->Localtime('user'))[1,2];
206 % my $tod = $h*60 + $m;
208 % LocalDate($Ticket->$meth->Unix) eq $date->strftime('%F') #today
209 % && $tod >= $row && $tod < ($row+$timestep); #and in timeslot
211 % next unless keys %dt;
212 <& /Elements/CalendarEvent,
217 % unless ( $Ticket eq ${ $Tickets{$date->strftime("%F")} }[-1] ) { #hmm, no.. not with "next unless $dt" :/
225 % $date = $set->next($date);
226 % if ( $date->day_of_week == $startday_of_week ) {
228 % if ( $date <= $end ) { #a second week? not going to work for week view yet
230 <td class="controls" rowspan=<% $rowspan + 2 %> valign="middle">
231 <& week_collapse, date=>$date, Month=>$OrigMonth, Year=>$OrigYear, QueryString=>$QueryString, Embed=>$Embed, &>
237 % } #while ($date <= $end)
239 % } #foreach my $row ( @week_rows )
244 % while ($date <= $end) {
246 % my $offmonth = !$WeekDay && $date->month != ($Month + 1);
247 % my $is_today = (DateTime->compare($today, $date) == 0);
248 % my $is_yesterday = (DateTime->compare($yesterday, $date) == 0);
249 % my $is_aweekago = (DateTime->compare($aweekago, $date) == 0);
252 class="<% $offmonth ? 'offmonth'
253 : $is_today ? 'today'
254 : $is_yesterday ? 'yesterday'
255 : $is_aweekago ? 'aweekago'
259 <div class="<% $is_today ? 'todays'
260 : $offmonth ? 'offmonth'
263 ><% $date->day %></div>
265 % if ( defined($Display) && $Display =~ /^(\w+)$/ ) {
267 % my $el = "/Elements/CalendarDay$1";
268 <& $el, CurrentUser => $session{CurrentUser},
269 Tickets => $Tickets{$date->strftime("%F")},
271 DateTypes => \%DateTypes,
278 % for my $t ( @{ $Tickets{$date->strftime("%F")} } ) {
280 <& /Elements/CalendarEvent, Object => $t, Date => $date, DateTypes => \%DateTypes &>
282 <% ($sp>0) ? '<BR>'x$sp : '' |n %>
288 % $date = $set->next($date);
289 % if ( $date->day_of_week == $startday_of_week ) {
291 % if ( $date <= $end ) {
293 <& td_week_expand, date=>$date, Month=>$Month, Year=>$Year, QueryString=>$QueryString, Embed=>$Embed, &>
297 % } #while ($date <= $end)
303 % unless ( $WeekDay ) {
308 <a href="<%$RT::WebPath%>/Search/<%$Embed||'Calendar.html'%>?Month=<%$PMonth%>&Year=<%$PYear%>&<%$QueryString%>">«<%$rtdate->GetMonth($PMonth)%></a>
311 <td valign="top" align="center">
312 <form action="<%$RT::WebPath%>/Search/<%$Embed||'Calendar.html'%>?<%$QueryString%>" method="post">
314 <select name="Month">
316 <option value="<%$_%>" <% $_ == $Month ? 'selected' : ''%> ><%$rtdate->GetMonth($_)%></option>
320 % my $year = (localtime)[5] + 1900;
322 % for ( ($year-5) .. ($year+5)) {
323 <option value="<%$_%>" <% $_ == $Year ? 'selected' : ''%>><%$_%></option>
327 %# <& /Elements/Submit&>
328 <input type="submit" value="<% loc('Submit') %>" class="button" />
334 <a href="<%$RT::WebPath%>/Search/<%$Embed||'Calendar.html'%>?Month=<%$NMonth%>&Year=<%$NYear%>&<%$QueryString%>"><%$rtdate->GetMonth($NMonth)%>»</a>
341 % unless ( $Embed ) {
346 <td valign="top" rowspan=9>
348 <a href="<%$RT::WebPath%>/Prefs/Calendar.html">Calendar Preferences and Help</a>
351 % foreach my $legend (keys %legend) {
354 <img src="<%$RT::WebImagesURL%>/<%$legend%>.png" />
358 % foreach ( @{$legend{$legend}} ) {
359 <% $more++ ? ', ' : '' %>
375 'created' => ['Created'],
377 'resolved' => ['Resolved'],
378 'updated' => ['Last Updated'],
379 'created_due' => ['Created','Due'],
380 'reminder' => ['Reminders'],
381 'started' => ['Started'],
382 'starts_due' => ['Starts','Due'],
385 my $stime = RT->Config->Get('CalendarWeeklyStartMin');
386 $stime = 480 unless $stime =~ /^\d+$/; #8am
387 my $etime = RT->Config->Get('CalendarWeeklyEndMin');
388 $etime = 1080 unless $etime =~ /^\d+$/; #6pm
390 my $timestep = RT->Config->Get('CalendarWeeklySizeMin') || 30; #1/2h
391 my $rowspan = ($etime-$stime) / $timestep;
393 my $default_slots = RT->Config->Get('CalendarWeeklySlots') || 5;
397 while ( $wt < $etime ) { push @week_rows, $wt; $wt+=$timestep }
401 use RTx::Calendar qw( FirstDay LastDay LastDayOfWeek DatesClauses LocalDate
402 SearchDefaultCalendar FindTickets );
404 $Embed =~ /^[\w\.]*$/ or die 'xss';
406 my $title = loc("Calendar");
408 my @DateTypes = qw/Created Starts Started Due LastUpdated Resolved/;
410 my $rtdate = RT::Date->new($session{'CurrentUser'});
412 my $time_zone = $session{'CurrentUser'}->UserObj->Timezone
413 || RT->Config->Get('Timezone');
415 my $weekstart = 'Sunday'; #RT::SiteConfig? user pref?
417 'Saturday' => [6,0..5],
419 'Monday' => [1..6,0],
421 my $startday_of_week = ${$week{$weekstart}}[0] || 7;
422 my $endday_of_week = ${$week{$weekstart}}[-1] || 7;
424 my $today = DateTime->today( time_zone=>$time_zone );
425 my $yesterday = $today->clone->subtract( days=>1 );
426 my $aweekago = $today->clone->subtract( days=>7 );
430 $start = DateTime->new( year => $WeekYear,
431 month => $WeekMonth+1,
433 time_zone => $time_zone,
435 $end = LastDayOfWeek( $WeekYear, $WeekMonth+1, $WeekDay, $endday_of_week );
437 $start = FirstDay($Year, $Month + 1, $startday_of_week );
438 $end = LastDay ($Year, $Month + 1, $endday_of_week );
441 # use this to loop over days until $end
442 my $set = DateTime::Set->from_recurrence(
443 next => sub { $_[0]->truncate( to => 'day' )->add( days => 1 ) }
450 '/Elements/QueryString',
455 Rows => $RowsPerPage,
461 '/Elements/QueryString',
467 # Default Query and Format
468 my $TempFormat = "__Starts__ __Due__";
469 my $TempQuery = "( Status = 'new' OR Status = 'open' OR Status = 'stalled')
470 AND ( Owner = '" . $session{CurrentUser}->Id ."' OR Owner = 'Nobody' )
471 AND ( Type = 'reminder' OR 'Type' = 'ticket' )";
473 if ( my $Search = SearchDefaultCalendar($session{CurrentUser}) ) {
474 $TempFormat = $Search->SubValue('Format');
475 $TempQuery = $Search->SubValue('Query');
478 # we overide them if needed
479 $TempQuery = $Query if $Query;
480 $TempFormat = $Format if $Format;
482 # we search all date types in Format string
483 my @Dates = grep { $TempFormat =~ m/__${_}(Relative)?__/ } @DateTypes;
485 # used to display or not a date in Element/CalendarEvent
486 my %DateTypes = map { $_ => 1 } @Dates;
488 $TempQuery .= DatesClauses(\@Dates, $start->strftime("%F"), $end->strftime("%F"));
490 # print STDERR ("-" x 30), "\n", $TempQuery, "\n";
492 my %Tickets = FindTickets($session{'CurrentUser'}, $TempQuery, \@Dates, $start->strftime("%F"), $end->strftime("%F"));
495 <%def td_week_expand>
500 $QueryString => undef
503 <td class="controls">
504 <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>
513 $QueryString => undef
516 <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>
520 % my( $min ) = shift;
521 <td class="labels"><% pretty_time($min) |n %></td>
526 return 'Midnight' if $t == 0 || $t == 1440;
527 return 'Noon' if $t == 720;
529 my $h = int( $t / 60 );
533 if ( $h == 0 || $h == 24 ) { $h = 12; }
534 elsif ( $h == 12 ) { $ap = 'PM'; }
535 elsif ( $h > 12 ) { $ap = 'PM'; $h -= 12; }
537 sprintf('%02d:%02d '.$ap, $h, $m);