0fb5414aa0c295c71a057add549371f79762d682
[freeside.git] / rt / share / html / Search / Calendar.html
1 <%args>
2 $Month => (localtime)[4]
3 $Year => (localtime)[5] + 1900
4 $Query => undef
5 $Format => undef
6 $Order => undef
7 $OrderBy => undef
8 $RowsPerPage => undef
9 $NewQuery => 0
10 </%args>
11
12 <& /Elements/Header, Title => $title &>
13 <& /Ticket/Elements/Tabs, 
14     current_tab => "Search/Calendar.html?$QueryString",
15     Title => $title &>
16 <&| /Widgets/TitleBox,
17      title => loc('Calendar for ') . $rtdate->GetMonth($Month) . " $Year" ,
18      title_class=> 'inverse',
19      color => "#993333" &>
20
21 <table width="100%">
22 <tr>
23 <td align="left">
24 % my ($PMonth, $PYear) = ($Month - 1, $Year);
25 % if ($PMonth < 0) {
26 %    $PYear--;
27 %    $PMonth = 11;
28 % }
29 <a href="<%$RT::WebPath%>/Search/Calendar.html?Month=<%$PMonth%>&Year=<%$PYear%>&<%$QueryString%>">«<%$rtdate->GetMonth($PMonth)%></a>
30 </td>
31 <th align="center">
32   <font size="+1"><% $rtdate->GetMonth($Month). " $Year" %></font>
33 </th>
34 <td align="right">
35 % my ($NMonth, $NYear) = ($Month + 1, $Year);
36 % if ($NMonth > 11) {
37 %    $NYear++;
38 %    $NMonth = 0;
39 % }
40 <a href="<%$RT::WebPath%>/Search/Calendar.html?Month=<%$NMonth%>&Year=<%$NYear%>&<%$QueryString%>"><%$rtdate->GetMonth($NMonth)%>»</a>
41 </td>
42 </tr>
43 </table>
44
45 <table class="rtxcalendar">
46
47 <thead>
48 <tr>
49 % for ( @{$week{$weekstart}} ) {
50 <th width="14%"><%$rtdate->GetWeekday($_)%></th>
51 % }
52 </tr>
53 </thead>
54
55 <tbody>
56 <tr>
57 % while ($date <= $end) {
58 %
59 %   my $offmonth = $date->month != ($Month + 1);
60 %   my $is_today     = (DateTime->compare($today,     $date) == 0);
61 %   my $is_yesterday = (DateTime->compare($yesterday, $date) == 0);
62 %   my $is_aweekago  = (DateTime->compare($aweekago,  $date) == 0);
63
64     <td class="<% $offmonth ? 'offmonth'
65                     : $is_today     ? 'today'
66                     : $is_yesterday ? 'yesterday'
67                     : $is_aweekago  ? 'aweekago'
68                     : ''
69                %>"
70     >
71       <div class="<% $is_today ? 'todays'
72                        : $offmonth ? 'offmonth'
73                        :'' %>date"
74       ><%$date->day%></div>
75
76 %     my $sp = 3;
77 %     for my $t ( @{ $Tickets{$date->strftime("%F")} } ) {
78 %       $sp--;
79         <& /Elements/CalendarEvent, Object => $t, Date => $date, DateTypes => \%DateTypes &>
80 %     }
81       <% ($sp>0) ? '<BR>'x$sp : '' |n %>
82
83     </td>
84
85 %   $date = $set->next($date);
86 %   if ( $date->day_of_week == $startday_of_week ) {
87       </tr><tr>
88 %   }
89
90 % }
91 </tr>
92 </tbody>
93 </table>
94
95 <table width="100%">
96 <tr>
97 <td align="left">
98 <a href="<%$RT::WebPath%>/Search/Calendar.html?Month=<%$PMonth%>&Year=<%$PYear%>&<%$QueryString%>">«<%$rtdate->GetMonth($PMonth)%></a>
99 </td>
100
101 <td valign="top" align="center">
102 <form action="<%$RT::WebPath%>/Search/Calendar.html?<%$QueryString%>" method="post">
103
104 <select name="Month">
105 % for (0..11) {
106 <option value="<%$_%>" <% $_ == $Month ? 'selected' : ''%> ><%$rtdate->GetMonth($_)%></option>
107 % }
108 </select>
109 % my $year = (localtime)[5] + 1900;
110 <select name="Year">
111 % for ( ($year-5) .. ($year+5)) {
112 <option value="<%$_%>" <% $_ == $Year ? 'selected' : ''%>><%$_%></option>
113 % }
114 </select>
115
116 %# <& /Elements/Submit&>
117 <input type="submit" value="<% loc('Submit') %>" class="button" />
118
119 </form>
120 </td>
121
122 <td align="right">
123 <a href="<%$RT::WebPath%>/Search/Calendar.html?Month=<%$NMonth%>&Year=<%$NYear%>&<%$QueryString%>"><%$rtdate->GetMonth($NMonth)%>»</a>
124 </td>
125 </tr>
126 </table>
127
128 <table width="100%">
129 <tr>
130
131 <td valign="top" rowspan=9>
132   <BR>
133   <a href="<%$RT::WebPath%>/Prefs/Calendar.html">Calendar Preferences and Help</a>
134 </td>
135
136 % foreach my $legend (keys %legend) {
137     <tr>
138       <td align="right">
139         <img src="<%$RT::WebImagesURL%>/<%$legend%>.png" />
140       </td>
141       <td align="left">
142 %       my $more = 0;
143 %       foreach ( @{$legend{$legend}} ) {
144           <% $more++ ? ', ' : '' %>
145           <&|/l&><% $_ %></&>
146 %       }
147       </td>
148     </tr>
149 % }
150
151 </table>
152
153 </&>
154
155 <%ONCE>
156
157 my %legend = (
158   'created'     => ['Created'],
159   'due'         => ['Due'],
160   'resolved'    => ['Resolved'],
161   'updated'     => ['Last Updated'],
162   'created_due' => ['Created','Due'],
163   'reminder'    => ['Reminders'],
164   'started'     => ['Started'],
165   'starts_due'  => ['Starts','Due'],
166 );
167
168 </%ONCE>
169 <%INIT>
170 use RTx::Calendar qw(FirstDay LastDay);
171
172 my $title = loc("Calendar");
173
174 my @DateTypes = qw/Created Starts Started Due LastUpdated Resolved/;
175
176 my $rtdate = RT::Date->new($session{'CurrentUser'});
177
178 my $weekstart = 'Sunday'; #RT::SiteConfig?  user pref?
179 my %week = (
180   'Saturday' => [6,0..5],
181   'Sunday'   => [0..6],
182   'Monday'   => [1..6,0],
183 );
184 my $startday_of_week = ${$week{$weekstart}}[0]  || 7;
185 my $endday_of_week   = ${$week{$weekstart}}[-1] || 7;
186
187 my $today = DateTime->today;
188 my $yesterday = $today->clone->subtract( days=>1 );
189 my $aweekago  = $today->clone->subtract( days=>7 );
190 my $date = FirstDay($Year, $Month + 1, $startday_of_week );
191 my $end  = LastDay ($Year, $Month + 1, $endday_of_week );
192
193 # use this to loop over days until $end
194 my $set = DateTime::Set->from_recurrence(
195     next => sub { $_[0]->truncate( to => 'day' )->add( days => 1 ) }
196 );
197
198 my $QueryString = 
199       $m->comp(
200         '/Elements/QueryString',
201         Query   => $Query,
202         Format  => $Format,
203         Order   => $Order,
204         OrderBy => $OrderBy,
205         Rows    => $RowsPerPage
206       )
207       if ($Query);
208
209 $QueryString ||= 'NewQuery=1';
210
211 # Default Query and Format
212 my $TempFormat = "__Starts__ __Due__";
213 my $TempQuery = "( Status = 'new' OR Status = 'open' OR Status = 'stalled')
214  AND ( Owner = '" . $session{CurrentUser}->Id ."' OR Owner = 'Nobody'  )
215  AND ( Type = 'reminder' OR 'Type' = 'ticket' )"; 
216
217 if ( my $Search = RTx::Calendar::SearchDefaultCalendar($session{CurrentUser}) ) {
218   $TempFormat = $Search->SubValue('Format');
219   $TempQuery = $Search->SubValue('Query');
220 }
221
222 # we overide them if needed
223 $TempQuery  = $Query  if $Query;
224 $TempFormat = $Format if $Format;
225
226 # we search all date types in Format string
227 my @Dates = grep { $TempFormat =~ m/__${_}(Relative)?__/ } @DateTypes;
228
229 # used to display or not a date in Element/CalendarEvent
230 my %DateTypes = map { $_ => 1 } @Dates;
231
232 $TempQuery .= RTx::Calendar::DatesClauses(\@Dates, $date->strftime("%F"), $end->strftime("%F"));
233
234 # print STDERR ("-" x 30), "\n", $TempQuery, "\n";
235
236 my %Tickets = RTx::Calendar::FindTickets($session{'CurrentUser'}, $TempQuery, \@Dates, $date->strftime("%F"), $end->strftime("%F"));
237
238 </%INIT>