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 % RTx::Calendar::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, Tickets => $Tickets{$date->strftime("%F")},
270 DateTypes => \%DateTypes,
277 % for my $t ( @{ $Tickets{$date->strftime("%F")} } ) {
279 <& /Elements/CalendarEvent, Object => $t, Date => $date, DateTypes => \%DateTypes &>
281 <% ($sp>0) ? '<BR>'x$sp : '' |n %>
287 % $date = $set->next($date);
288 % if ( $date->day_of_week == $startday_of_week ) {
290 % if ( $date <= $end ) {
292 <& td_week_expand, date=>$date, Month=>$Month, Year=>$Year, QueryString=>$QueryString, Embed=>$Embed, &>
296 % } #while ($date <= $end)
302 % unless ( $WeekDay ) {
307 <a href="<%$RT::WebPath%>/Search/<%$Embed||'Calendar.html'%>?Month=<%$PMonth%>&Year=<%$PYear%>&<%$QueryString%>">«<%$rtdate->GetMonth($PMonth)%></a>
310 <td valign="top" align="center">
311 <form action="<%$RT::WebPath%>/Search/<%$Embed||'Calendar.html'%>?<%$QueryString%>" method="post">
313 <select name="Month">
315 <option value="<%$_%>" <% $_ == $Month ? 'selected' : ''%> ><%$rtdate->GetMonth($_)%></option>
319 % my $year = (localtime)[5] + 1900;
321 % for ( ($year-5) .. ($year+5)) {
322 <option value="<%$_%>" <% $_ == $Year ? 'selected' : ''%>><%$_%></option>
326 %# <& /Elements/Submit&>
327 <input type="submit" value="<% loc('Submit') %>" class="button" />
333 <a href="<%$RT::WebPath%>/Search/<%$Embed||'Calendar.html'%>?Month=<%$NMonth%>&Year=<%$NYear%>&<%$QueryString%>"><%$rtdate->GetMonth($NMonth)%>»</a>
340 % unless ( $Embed ) {
345 <td valign="top" rowspan=9>
347 <a href="<%$RT::WebPath%>/Prefs/Calendar.html">Calendar Preferences and Help</a>
350 % foreach my $legend (keys %legend) {
353 <img src="<%$RT::WebImagesURL%>/<%$legend%>.png" />
357 % foreach ( @{$legend{$legend}} ) {
358 <% $more++ ? ', ' : '' %>
374 'created' => ['Created'],
376 'resolved' => ['Resolved'],
377 'updated' => ['Last Updated'],
378 'created_due' => ['Created','Due'],
379 'reminder' => ['Reminders'],
380 'started' => ['Started'],
381 'starts_due' => ['Starts','Due'],
384 my $stime = RT->Config->Get('CalendarWeeklyStartMin');
385 $stime = 480 unless $stime =~ /^\d+$/; #8am
386 my $etime = RT->Config->Get('CalendarWeeklyEndMin');
387 $etime = 1080 unless $etime =~ /^\d+$/; #6pm
389 my $timestep = RT->Config->Get('CalendarWeeklySizeMin') || 30; #1/2h
390 my $rowspan = ($etime-$stime) / $timestep;
392 my $default_slots = RT->Config->Get('CalendarWeeklySlots') || 5;
396 while ( $wt < $etime ) { push @week_rows, $wt; $wt+=$timestep }
400 use RTx::Calendar qw(FirstDay LastDay LastDayOfWeek);
402 $Embed =~ /^[\w\.]*$/ or die 'xss';
404 my $title = loc("Calendar");
406 my @DateTypes = qw/Created Starts Started Due LastUpdated Resolved/;
408 my $rtdate = RT::Date->new($session{'CurrentUser'});
410 my $time_zone = $session{'CurrentUser'}->UserObj->Timezone
411 || RT->Config->Get('Timezone');
413 my $weekstart = 'Sunday'; #RT::SiteConfig? user pref?
415 'Saturday' => [6,0..5],
417 'Monday' => [1..6,0],
419 my $startday_of_week = ${$week{$weekstart}}[0] || 7;
420 my $endday_of_week = ${$week{$weekstart}}[-1] || 7;
422 my $today = DateTime->today( time_zone=>$time_zone );
423 my $yesterday = $today->clone->subtract( days=>1 );
424 my $aweekago = $today->clone->subtract( days=>7 );
428 $start = DateTime->new( year => $WeekYear,
429 month => $WeekMonth+1,
431 time_zone => $time_zone,
433 $end = LastDayOfWeek( $WeekYear, $WeekMonth+1, $WeekDay, $endday_of_week );
435 $start = FirstDay($Year, $Month + 1, $startday_of_week );
436 $end = LastDay ($Year, $Month + 1, $endday_of_week );
439 # use this to loop over days until $end
440 my $set = DateTime::Set->from_recurrence(
441 next => sub { $_[0]->truncate( to => 'day' )->add( days => 1 ) }
448 '/Elements/QueryString',
453 Rows => $RowsPerPage,
459 '/Elements/QueryString',
465 # Default Query and Format
466 my $TempFormat = "__Starts__ __Due__";
467 my $TempQuery = "( Status = 'new' OR Status = 'open' OR Status = 'stalled')
468 AND ( Owner = '" . $session{CurrentUser}->Id ."' OR Owner = 'Nobody' )
469 AND ( Type = 'reminder' OR 'Type' = 'ticket' )";
471 if ( my $Search = RTx::Calendar::SearchDefaultCalendar($session{CurrentUser}) ) {
472 $TempFormat = $Search->SubValue('Format');
473 $TempQuery = $Search->SubValue('Query');
476 # we overide them if needed
477 $TempQuery = $Query if $Query;
478 $TempFormat = $Format if $Format;
480 # we search all date types in Format string
481 my @Dates = grep { $TempFormat =~ m/__${_}(Relative)?__/ } @DateTypes;
483 # used to display or not a date in Element/CalendarEvent
484 my %DateTypes = map { $_ => 1 } @Dates;
486 $TempQuery .= RTx::Calendar::DatesClauses(\@Dates, $start->strftime("%F"), $end->strftime("%F"));
488 # print STDERR ("-" x 30), "\n", $TempQuery, "\n";
490 my %Tickets = RTx::Calendar::FindTickets($session{'CurrentUser'}, $TempQuery, \@Dates, $start->strftime("%F"), $end->strftime("%F"));
493 <%def td_week_expand>
498 $QueryString => undef
501 <td class="controls">
502 <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>
511 $QueryString => undef
514 <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>
518 % my( $min ) = shift;
519 <td class="labels"><% pretty_time($min) |n %></td>
524 return 'Midnight' if $t == 0 || $t == 1440;
525 return 'Noon' if $t == 720;
527 my $h = int( $t / 60 );
531 if ( $h == 0 || $h == 24 ) { $h = 12; }
532 elsif ( $h == 12 ) { $ap = 'PM'; }
533 elsif ( $h > 12 ) { $ap = 'PM'; $h -= 12; }
535 sprintf('%02d:%02d '.$ap, $h, $m);