2 $Month => (localtime)[4]
3 $Year => (localtime)[5] + 1900
17 <& /Elements/Header, Title => $title &>
20 <&| /Widgets/TitleBox,
21 title => loc('Calendar for ') . $rtdate->GetMonth($Month) . " $Year" ,
22 title_class=> 'inverse',
25 % my($PMonth, $PYear, $NMonth, $NYear);
26 % unless ( $WeekDay ) {
31 % ($PMonth, $PYear) = ($Month - 1, $Year);
36 <a href="<%$RT::WebPath%>/Search/Calendar.html?Month=<%$PMonth%>&Year=<%$PYear%>&<%$QueryString%>">«<%$rtdate->GetMonth($PMonth)%></a>
39 <font size="+1"><% $rtdate->GetMonth($Month). " $Year" %></font>
42 % ($NMonth, $NYear) = ($Month + 1, $Year);
47 <a href="<%$RT::WebPath%>/Search/Calendar.html?Month=<%$NMonth%>&Year=<%$NYear%>&<%$QueryString%>"><%$rtdate->GetMonth($NMonth)%>»</a>
53 <table class="rtxcalendar">
57 <td class="controls"></td>
58 % for ( @{$week{$weekstart}} ) {
59 <th width="14%"><%$rtdate->GetWeekday($_)%></th>
67 <& td_week_collapse, date=>$date, Month=>$OrigMonth, Year=>$OrigYear, QueryString=>$QueryString &>
69 <& td_week_expand, date=>$date, Month=>$Month, Year=>$Year, QueryString=>$QueryString &>
71 % while ($date <= $end) {
73 % my $offmonth = $date->month != ($Month + 1);
74 % my $is_today = (DateTime->compare($today, $date) == 0);
75 % my $is_yesterday = (DateTime->compare($yesterday, $date) == 0);
76 % my $is_aweekago = (DateTime->compare($aweekago, $date) == 0);
78 <td class="<% ($offmonth && !$WeekDay) ? 'offmonth'
80 : $is_yesterday ? 'yesterday'
81 : $is_aweekago ? 'aweekago'
85 <div class="<% $is_today ? 'todays'
86 : ($offmonth && !$WeekDay) ? 'offmonth'
88 ><% ( $WeekDay ? $rtdate->GetMonth($date->month). ' ' : '' ).
93 % for my $t ( @{ $Tickets{$date->strftime("%F")} } ) {
95 <& /Elements/CalendarEvent, Object => $t, Date => $date, DateTypes => \%DateTypes &>
97 <% ($sp>0) ? '<BR>'x$sp : '' |n %>
101 % $date = $set->next($date);
102 % if ( $date->day_of_week == $startday_of_week ) {
104 % if ( $date <= $end ) {
107 <& td_week_collapse, date=>$date, Month=>$OrigMonth, Year=>$OrigYear, QueryString=>$QueryString &>
109 <& td_week_expand, date=>$date, Month=>$Month, Year=>$Year, QueryString=>$QueryString &>
118 % unless ( $WeekDay ) {
123 <a href="<%$RT::WebPath%>/Search/Calendar.html?Month=<%$PMonth%>&Year=<%$PYear%>&<%$QueryString%>">«<%$rtdate->GetMonth($PMonth)%></a>
126 <td valign="top" align="center">
127 <form action="<%$RT::WebPath%>/Search/Calendar.html?<%$QueryString%>" method="post">
129 <select name="Month">
131 <option value="<%$_%>" <% $_ == $Month ? 'selected' : ''%> ><%$rtdate->GetMonth($_)%></option>
135 % my $year = (localtime)[5] + 1900;
137 % for ( ($year-5) .. ($year+5)) {
138 <option value="<%$_%>" <% $_ == $Year ? 'selected' : ''%>><%$_%></option>
142 %# <& /Elements/Submit&>
143 <input type="submit" value="<% loc('Submit') %>" class="button" />
149 <a href="<%$RT::WebPath%>/Search/Calendar.html?Month=<%$NMonth%>&Year=<%$NYear%>&<%$QueryString%>"><%$rtdate->GetMonth($NMonth)%>»</a>
156 % #XXX an option to turn off "Calendar Preferences and Help" for embedded
157 % # (and weekly?) use
161 <td valign="top" rowspan=9>
163 <a href="<%$RT::WebPath%>/Prefs/Calendar.html">Calendar Preferences and Help</a>
166 % foreach my $legend (keys %legend) {
169 <img src="<%$RT::WebImagesURL%>/<%$legend%>.png" />
173 % foreach ( @{$legend{$legend}} ) {
174 <% $more++ ? ', ' : '' %>
188 'created' => ['Created'],
190 'resolved' => ['Resolved'],
191 'updated' => ['Last Updated'],
192 'created_due' => ['Created','Due'],
193 'reminder' => ['Reminders'],
194 'started' => ['Started'],
195 'starts_due' => ['Starts','Due'],
200 use RTx::Calendar qw(FirstDay LastDay LastDayOfWeek);
202 my $title = loc("Calendar");
204 my @DateTypes = qw/Created Starts Started Due LastUpdated Resolved/;
206 my $rtdate = RT::Date->new($session{'CurrentUser'});
208 my $weekstart = 'Sunday'; #RT::SiteConfig? user pref?
210 'Saturday' => [6,0..5],
212 'Monday' => [1..6,0],
214 my $startday_of_week = ${$week{$weekstart}}[0] || 7;
215 my $endday_of_week = ${$week{$weekstart}}[-1] || 7;
217 my $today = DateTime->today;
218 my $yesterday = $today->clone->subtract( days=>1 );
219 my $aweekago = $today->clone->subtract( days=>7 );
223 $date = DateTime->new( year=>$WeekYear, month=>$WeekMonth, day=>$WeekDay );
224 $end = LastDayOfWeek( $WeekYear, $WeekMonth, $WeekDay, $endday_of_week );
226 $date = FirstDay($Year, $Month + 1, $startday_of_week );
227 $end = LastDay ($Year, $Month + 1, $endday_of_week );
230 # use this to loop over days until $end
231 my $set = DateTime::Set->from_recurrence(
232 next => sub { $_[0]->truncate( to => 'day' )->add( days => 1 ) }
237 '/Elements/QueryString',
246 $QueryString ||= 'NewQuery=1';
248 # Default Query and Format
249 my $TempFormat = "__Starts__ __Due__";
250 my $TempQuery = "( Status = 'new' OR Status = 'open' OR Status = 'stalled')
251 AND ( Owner = '" . $session{CurrentUser}->Id ."' OR Owner = 'Nobody' )
252 AND ( Type = 'reminder' OR 'Type' = 'ticket' )";
254 if ( my $Search = RTx::Calendar::SearchDefaultCalendar($session{CurrentUser}) ) {
255 $TempFormat = $Search->SubValue('Format');
256 $TempQuery = $Search->SubValue('Query');
259 # we overide them if needed
260 $TempQuery = $Query if $Query;
261 $TempFormat = $Format if $Format;
263 # we search all date types in Format string
264 my @Dates = grep { $TempFormat =~ m/__${_}(Relative)?__/ } @DateTypes;
266 # used to display or not a date in Element/CalendarEvent
267 my %DateTypes = map { $_ => 1 } @Dates;
269 $TempQuery .= RTx::Calendar::DatesClauses(\@Dates, $date->strftime("%F"), $end->strftime("%F"));
271 # print STDERR ("-" x 30), "\n", $TempQuery, "\n";
273 my %Tickets = RTx::Calendar::FindTickets($session{'CurrentUser'}, $TempQuery, \@Dates, $date->strftime("%F"), $end->strftime("%F"));
276 <%def td_week_expand>
281 $QueryString => undef
283 <td class="controls">
284 <a href="<%$RT::WebPath%>/Search/Calendar.html?WeekDay=<% $date->day %>&WeekMonth=<% $date->month %>&WeekYear=<% $date->year %>&OrigMonth=<% $Month %>&OrigYear=<% $Year %>&<%$QueryString%>"><img src="<%$RT::WebPath%>/NoAuth/images/week-expand.gif"></a>
288 <%def td_week_collapse>
293 $QueryString => undef
295 <td class="controls">
296 <a href="<%$RT::WebPath%>/Search/Calendar.html?Month=<% $Month %>&Year=<% $Year %>&<%$QueryString%>"><img src="<%$RT::WebPath%>/NoAuth/images/week-collapse.gif"></a>