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