add RTx::Calendar 0.07
[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 <td align="center">
32 <a href="<%$RT::WebPath%>/Prefs/Calendar.html">Calendar Preferences and Help</a>
33 </td>
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 <thead>
47 <tr>
48 <th></th>
49 % for (1 .. 6, 0) {
50 <th width="14%"><%$rtdate->GetWeekday($_)%></th>
51 % }
52 </tr>
53 </thead>
54 <tbody>
55 <tr>
56 % while ($date <= $end) {
57 %   if ( $date->day_of_week == 1) {
58 <th><% $date->week_number %></th>
59 %   }
60 <td class="<% $date->month != ($Month + 1) ? 'oddline' : '' %>"
61     style="width:14%;<%  DateTime->compare($today, $date) == 0 ? 'background:#f6f7f8;' : '' %>"
62 >
63 <p class="date"><%$date->day%></p>
64 % for my $t ( @{ $Tickets{$date->strftime("%F")} } ) {
65 <& /Elements/CalendarEvent, Object => $t, Date => $date, DateTypes => \%DateTypes &>
66 % }
67 </td>
68 % $date = $set->next($date);
69 % if ( $date->day_of_week == 1) {
70 </tr><tr>
71 % }
72 % }
73 </tr>
74 </tbody>
75 </table>
76
77 <table width="100%">
78 <tr>
79 <td align="left">
80 <a href="<%$RT::WebPath%>/Search/Calendar.html?Month=<%$PMonth%>&Year=<%$PYear%>&<%$QueryString%>">«<%$rtdate->GetMonth($PMonth)%></a>
81 </td>
82 <td align="right">
83 <a href="<%$RT::WebPath%>/Search/Calendar.html?Month=<%$NMonth%>&Year=<%$NYear%>&<%$QueryString%>"><%$rtdate->GetMonth($NMonth)%>»</a>
84 </td>
85 </tr>
86 </table>
87
88
89 <table width="100%">
90 <tr>
91 <td valign="top" align="center" width="80%">
92 <form action="<%$RT::WebPath%>/Search/Calendar.html?<%$QueryString%>" method="post">
93
94 <select name="Month">
95 % for (0..11) {
96 <option value="<%$_%>" <% $_ == $Month ? 'selected' : ''%> ><%$rtdate->GetMonth($_)%></option>
97 % }
98 </select>
99 % my $year = (localtime)[5] + 1900;
100 <select name="Year">
101 % for ( ($year-5) .. ($year+5)) {
102 <option value="<%$_%>" <% $_ == $Year ? 'selected' : ''%>><%$_%></option>
103 % }
104 </select>
105
106 <& /Elements/Submit&>
107 </form>
108 </td>
109 <td valign="top" width="50%" align="right">
110 <img src="<%$RT::WebImagesURL%>/created.png" /> : <&|/l&>Created</&><br />
111 <img src="<%$RT::WebImagesURL%>/due.png" /> : <&|/l&>Due</&><br />
112 <img src="<%$RT::WebImagesURL%>/resolved.png" /> : <&|/l&>Resolved</&><br />
113 <img src="<%$RT::WebImagesURL%>/updated.png" /> : <&|/l&>Last Updated</&><br />
114 <img src="<%$RT::WebImagesURL%>/created_due.png" /> : <&|/l&>Created</&>, <&|/l&>Due</&><br />
115 <img src="<%$RT::WebImagesURL%>/reminder.png" /> : <&|/l&>Reminders</&><br />
116 <img src="<%$RT::WebImagesURL%>/starts.png" /> : <&|/l&>Starts</&><br />
117 <img src="<%$RT::WebImagesURL%>/started.png" /> : <&|/l&>Started</&><br />
118 <img src="<%$RT::WebImagesURL%>/starts_due.png" /> : <&|/l&>Starts</&>, <&|/l&>Due</&><br />
119
120
121 </td>
122 </table>
123
124 </&>
125
126 </html>
127 <%INIT>
128 use RTx::Calendar;
129
130 my $title = loc("Calendar");
131
132 my @DateTypes = qw/Created Starts Started Due LastUpdated Resolved/;
133
134 my $rtdate = RT::Date->new($session{'CurrentUser'});
135
136 my $today = DateTime->today;
137 my $date  = RTx::Calendar::FirstMonday($Year, $Month + 1);
138 my $end   = RTx::Calendar::LastSunday($Year, $Month + 1);
139
140 # use this to loop over days until $end
141 my $set = DateTime::Set->from_recurrence(
142     next => sub { $_[0]->truncate( to => 'day' )->add( days => 1 ) }
143 );
144
145 my $QueryString = 
146       $m->comp(
147         '/Elements/QueryString',
148         Query   => $Query,
149         Format  => $Format,
150         Order   => $Order,
151         OrderBy => $OrderBy,
152         Rows    => $RowsPerPage
153       )
154       if ($Query);
155
156 $QueryString ||= 'NewQuery=1';
157
158 # Default Query and Format
159 my $TempFormat = "__Starts__ __Due__";
160 my $TempQuery = "( Status = 'new' OR Status = 'open' OR Status = 'stalled')
161  AND ( Owner = '" . $session{CurrentUser}->Id ."' OR Owner = 'Nobody'  )
162  AND ( Type = 'reminder' OR 'Type' = 'ticket' )"; 
163
164 if ( my $Search = RTx::Calendar::SearchDefaultCalendar($session{CurrentUser}) ) {
165   $TempFormat = $Search->SubValue('Format');
166   $TempQuery = $Search->SubValue('Query');
167 }
168
169 # we overide them if needed
170 $TempQuery  = $Query  if $Query;
171 $TempFormat = $Format if $Format;
172
173 # we search all date types in Format string
174 my @Dates = grep { $TempFormat =~ m/__${_}(Relative)?__/ } @DateTypes;
175
176 # used to display or not a date in Element/CalendarEvent
177 my %DateTypes = map { $_ => 1 } @Dates;
178
179 $TempQuery .= RTx::Calendar::DatesClauses(\@Dates, $date->strftime("%F"), $end->strftime("%F"));
180
181 # print STDERR ("-" x 30), "\n", $TempQuery, "\n";
182
183 my %Tickets = RTx::Calendar::FindTickets($session{'CurrentUser'}, $TempQuery, \@Dates, $date->strftime("%F"), $end->strftime("%F"));
184
185 </%INIT>