2 $Month => (localtime)[4]
3 $Year => (localtime)[5] + 1900
17 <& /Elements/Header, Title => $title &>
22 % if ( $date->month == $end->month ) {
23 % $title = $rtdate->GetMonth( $date->month -1 ). ' '.
24 % $date->day. '-'. $end->day. ', '. $date->year;
25 % } elsif ( $date->year == $end->year ) {
27 % $rtdate->GetMonth( $date->month -1 ). ' '. $date->day. ' - '.
28 % $rtdate->GetMonth( $end->month -1 ). ' '. $end->day. ', '. $end->year;
31 % $rtdate->GetMonth( $date->month -1 ). ' '.$date->day. ', '. $date->year.
33 % $rtdate->GetMonth( $end->month -1 ). ' '.$end->day. ', '. $end->year;
36 % $title = $rtdate->GetMonth($Month) . " $Year"
38 <&| /Widgets/TitleBox,
39 title => loc('Calendar for '). $title,
40 title_class=> 'inverse',
43 % my($PMonth, $PYear, $NMonth, $NYear);
44 % unless ( $WeekDay ) {
49 % ($PMonth, $PYear) = ($Month - 1, $Year);
54 <a href="<%$RT::WebPath%>/Search/Calendar.html?Month=<%$PMonth%>&Year=<%$PYear%>&<%$QueryString%>">«<%$rtdate->GetMonth($PMonth)%></a>
57 <font size="+1"><% $rtdate->GetMonth($Month). " $Year" %></font>
60 % ($NMonth, $NYear) = ($Month + 1, $Year);
65 <a href="<%$RT::WebPath%>/Search/Calendar.html?Month=<%$NMonth%>&Year=<%$NYear%>&<%$QueryString%>"><%$rtdate->GetMonth($NMonth)%>»</a>
71 <table class="rtxcalendar">
75 <td class="labels" colspan=<% $WeekDay ? 2 : 1 %>></td>
76 % for ( @{$week{$weekstart}} ) {
77 <th width="14%"><%$rtdate->GetWeekday($_)%></th>
86 <td class="controls" rowspan=<% $rowspan+1 %> valign="middle">
87 <& week_collapse, date=>$date, Month=>$OrigMonth, Year=>$OrigYear, QueryString=>$QueryString &>
91 <& td_week_expand, date=>$date, Month=>$Month, Year=>$Year, QueryString=>$QueryString &>
96 <td class="labels"></td>
99 % while ($date <= $end) {
101 % my $is_today = (DateTime->compare($today, $date) == 0);
102 % my $is_yesterday = (DateTime->compare($yesterday, $date) == 0);
103 % my $is_aweekago = (DateTime->compare($aweekago, $date) == 0);
105 <td class="<% $is_today ? 'today'
106 : $is_yesterday ? 'yesterday'
107 : $is_aweekago ? 'aweekago'
111 <div class="<% $is_today ? 'todays'
114 ><% $rtdate->GetMonth($date->month-1). ' '. $date->day %></div>
118 % $date = $set->next($date);
119 % if ( $date->day_of_week == $startday_of_week ) {
121 % if ( $date <= $end ) { #a second week? not going to work for week view yet
123 <td class="controls" rowspan=<% $rowspan + 1 %> valign="middle">
124 <& week_collapse, date=>$date, Month=>$OrigMonth, Year=>$OrigYear, QueryString=>$QueryString &>
129 % } #while ($date <= $end)
131 % foreach my $row ( @week_rows ) {
136 % while ($date <= $end) {
138 % my $is_today = (DateTime->compare($today, $date) == 0);
139 % my $is_yesterday = (DateTime->compare($yesterday, $date) == 0);
140 % my $is_aweekago = (DateTime->compare($aweekago, $date) == 0);
142 <td class="<% $is_today ? 'today'
143 : $is_yesterday ? 'yesterday'
144 : $is_aweekago ? 'aweekago'
149 % #XXX display these in a time aware fashion
151 %#% for my $t ( @{ $Tickets{$date->strftime("%F")} } ) {
153 %# <& /Elements/CalendarEvent, Object => $t, Date => $date, DateTypes => \%DateTypes &>
155 %# <% ($sp>0) ? '<BR>'x$sp : '' |n %>
159 % $date = $set->next($date);
160 % if ( $date->day_of_week == $startday_of_week ) {
162 % if ( $date <= $end ) { #a second week? not going to work for week view yet
164 <td class="controls" rowspan=<% $rowspan + 1 %> valign="middle">
165 <& week_collapse, date=>$date, Month=>$OrigMonth, Year=>$OrigYear, QueryString=>$QueryString &>
170 % } #while ($date <= $end)
171 % } #foreach my $row ( @week_rows )
175 % while ($date <= $end) {
177 % my $offmonth = !$WeekDay && $date->month != ($Month + 1);
178 % my $is_today = (DateTime->compare($today, $date) == 0);
179 % my $is_yesterday = (DateTime->compare($yesterday, $date) == 0);
180 % my $is_aweekago = (DateTime->compare($aweekago, $date) == 0);
182 <td class="<% $offmonth ? 'offmonth'
183 : $is_today ? 'today'
184 : $is_yesterday ? 'yesterday'
185 : $is_aweekago ? 'aweekago'
189 <div class="<% $is_today ? 'todays'
190 : $offmonth ? 'offmonth'
193 ><% $date->day %></div>
196 % for my $t ( @{ $Tickets{$date->strftime("%F")} } ) {
198 <& /Elements/CalendarEvent, Object => $t, Date => $date, DateTypes => \%DateTypes &>
200 <% ($sp>0) ? '<BR>'x$sp : '' |n %>
204 % $date = $set->next($date);
205 % if ( $date->day_of_week == $startday_of_week ) {
207 % if ( $date <= $end ) {
209 <& td_week_expand, date=>$date, Month=>$Month, Year=>$Year, QueryString=>$QueryString &>
213 % } #while ($date <= $end)
219 % unless ( $WeekDay ) {
224 <a href="<%$RT::WebPath%>/Search/Calendar.html?Month=<%$PMonth%>&Year=<%$PYear%>&<%$QueryString%>">«<%$rtdate->GetMonth($PMonth)%></a>
227 <td valign="top" align="center">
228 <form action="<%$RT::WebPath%>/Search/Calendar.html?<%$QueryString%>" method="post">
230 <select name="Month">
232 <option value="<%$_%>" <% $_ == $Month ? 'selected' : ''%> ><%$rtdate->GetMonth($_)%></option>
236 % my $year = (localtime)[5] + 1900;
238 % for ( ($year-5) .. ($year+5)) {
239 <option value="<%$_%>" <% $_ == $Year ? 'selected' : ''%>><%$_%></option>
243 %# <& /Elements/Submit&>
244 <input type="submit" value="<% loc('Submit') %>" class="button" />
250 <a href="<%$RT::WebPath%>/Search/Calendar.html?Month=<%$NMonth%>&Year=<%$NYear%>&<%$QueryString%>"><%$rtdate->GetMonth($NMonth)%>»</a>
257 % #XXX an option to turn off "Calendar Preferences and Help" for embedded
258 % # (and weekly?) use
262 <td valign="top" rowspan=9>
264 <a href="<%$RT::WebPath%>/Prefs/Calendar.html">Calendar Preferences and Help</a>
267 % foreach my $legend (keys %legend) {
270 <img src="<%$RT::WebImagesURL%>/<%$legend%>.png" />
274 % foreach ( @{$legend{$legend}} ) {
275 <% $more++ ? ', ' : '' %>
289 'created' => ['Created'],
291 'resolved' => ['Resolved'],
292 'updated' => ['Last Updated'],
293 'created_due' => ['Created','Due'],
294 'reminder' => ['Reminders'],
295 'started' => ['Started'],
296 'starts_due' => ['Starts','Due'],
299 my $stime = 480; #8am
300 my $etime = 1080; #6pm
301 my $timestep = 30; #1/2h
302 #my $timestep = 120; #2h
303 my $rowspan = ($etime-$stime) / $timestep;
307 while ( $wt < $etime ) { push @week_rows, $wt; $wt+=$timestep }
311 use RTx::Calendar qw(FirstDay LastDay LastDayOfWeek);
313 my $title = loc("Calendar");
315 my @DateTypes = qw/Created Starts Started Due LastUpdated Resolved/;
317 my $rtdate = RT::Date->new($session{'CurrentUser'});
319 my $time_zone = $session{'CurrentUser'}->UserObj->Timezone
320 || RT->Config->Get('Timezone');
322 my $weekstart = 'Sunday'; #RT::SiteConfig? user pref?
324 'Saturday' => [6,0..5],
326 'Monday' => [1..6,0],
328 my $startday_of_week = ${$week{$weekstart}}[0] || 7;
329 my $endday_of_week = ${$week{$weekstart}}[-1] || 7;
331 my $today = DateTime->today( time_zone=>$time_zone );
332 my $yesterday = $today->clone->subtract( days=>1 );
333 my $aweekago = $today->clone->subtract( days=>7 );
337 $start = DateTime->new( year => $WeekYear,
338 month => $WeekMonth+1,
340 time_zone => $time_zone,
342 $end = LastDayOfWeek( $WeekYear, $WeekMonth+1, $WeekDay, $endday_of_week );
344 $start = FirstDay($Year, $Month + 1, $startday_of_week );
345 $end = LastDay ($Year, $Month + 1, $endday_of_week );
349 # use this to loop over days until $end
350 my $set = DateTime::Set->from_recurrence(
351 next => sub { $_[0]->truncate( to => 'day' )->add( days => 1 ) }
356 '/Elements/QueryString',
365 $QueryString ||= 'NewQuery=1';
367 # Default Query and Format
368 my $TempFormat = "__Starts__ __Due__";
369 my $TempQuery = "( Status = 'new' OR Status = 'open' OR Status = 'stalled')
370 AND ( Owner = '" . $session{CurrentUser}->Id ."' OR Owner = 'Nobody' )
371 AND ( Type = 'reminder' OR 'Type' = 'ticket' )";
373 if ( my $Search = RTx::Calendar::SearchDefaultCalendar($session{CurrentUser}) ) {
374 $TempFormat = $Search->SubValue('Format');
375 $TempQuery = $Search->SubValue('Query');
378 # we overide them if needed
379 $TempQuery = $Query if $Query;
380 $TempFormat = $Format if $Format;
382 # we search all date types in Format string
383 my @Dates = grep { $TempFormat =~ m/__${_}(Relative)?__/ } @DateTypes;
385 # used to display or not a date in Element/CalendarEvent
386 my %DateTypes = map { $_ => 1 } @Dates;
388 $TempQuery .= RTx::Calendar::DatesClauses(\@Dates, $date->strftime("%F"), $end->strftime("%F"));
390 # print STDERR ("-" x 30), "\n", $TempQuery, "\n";
392 my %Tickets = RTx::Calendar::FindTickets($session{'CurrentUser'}, $TempQuery, \@Dates, $date->strftime("%F"), $end->strftime("%F"));
395 <%def td_week_expand>
400 $QueryString => undef
402 <td class="controls">
403 <a href="<%$RT::WebPath%>/Search/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>
412 $QueryString => undef
414 <a href="<%$RT::WebPath%>/Search/Calendar.html?Month=<% $Month %>&Year=<% $Year %>&<%$QueryString%>"><img src="<%$RT::WebPath%>/NoAuth/images/week-collapse.gif" STYLE="height:384px;width:11px"></a>
418 % my( $min ) = shift;
419 <td class="labels"><% pretty_time($min) |n %></td>
424 return 'Midnight' if $t == 0 || $t == 1440;
425 return 'Noon' if $t == 720;
427 my $h = int( $t / 60 );
431 if ( $h == 0 || $h == 24 ) { $h = 12; }
432 elsif ( $h == 12 ) { $ap = 'PM'; }
433 elsif ( $h > 12 ) { $ap = 'PM'; $h -= 12; }
435 sprintf('%02d:%02d '.$ap, $h, $m);