week view on calendars from Sunday -> Saturday
[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 ( @{$week{$weekstart}} ) {
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 == $startday_of_week ) {
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 == $startday_of_week ) {
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 qw(FirstDay LastDay);
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 $weekstart = 'Sunday'; #RT::SiteConfig?  user pref?
137 my %week = (
138   'Saturday' => [6,0..5],
139   'Sunday'   => [0..6],
140   'Monday'   => [1..6,0],
141 );
142 my $startday_of_week = ${$week{$weekstart}}[0]  || 7;
143 my $endday_of_week   = ${$week{$weekstart}}[-1] || 7;
144
145 my $today = DateTime->today;
146 my $date = FirstDay($Year, $Month + 1, $startday_of_week );
147 my $end  = LastDay ($Year, $Month + 1, $endday_of_week );
148
149 # use this to loop over days until $end
150 my $set = DateTime::Set->from_recurrence(
151     next => sub { $_[0]->truncate( to => 'day' )->add( days => 1 ) }
152 );
153
154 my $QueryString = 
155       $m->comp(
156         '/Elements/QueryString',
157         Query   => $Query,
158         Format  => $Format,
159         Order   => $Order,
160         OrderBy => $OrderBy,
161         Rows    => $RowsPerPage
162       )
163       if ($Query);
164
165 $QueryString ||= 'NewQuery=1';
166
167 # Default Query and Format
168 my $TempFormat = "__Starts__ __Due__";
169 my $TempQuery = "( Status = 'new' OR Status = 'open' OR Status = 'stalled')
170  AND ( Owner = '" . $session{CurrentUser}->Id ."' OR Owner = 'Nobody'  )
171  AND ( Type = 'reminder' OR 'Type' = 'ticket' )"; 
172
173 if ( my $Search = RTx::Calendar::SearchDefaultCalendar($session{CurrentUser}) ) {
174   $TempFormat = $Search->SubValue('Format');
175   $TempQuery = $Search->SubValue('Query');
176 }
177
178 # we overide them if needed
179 $TempQuery  = $Query  if $Query;
180 $TempFormat = $Format if $Format;
181
182 # we search all date types in Format string
183 my @Dates = grep { $TempFormat =~ m/__${_}(Relative)?__/ } @DateTypes;
184
185 # used to display or not a date in Element/CalendarEvent
186 my %DateTypes = map { $_ => 1 } @Dates;
187
188 $TempQuery .= RTx::Calendar::DatesClauses(\@Dates, $date->strftime("%F"), $end->strftime("%F"));
189
190 # print STDERR ("-" x 30), "\n", $TempQuery, "\n";
191
192 my %Tickets = RTx::Calendar::FindTickets($session{'CurrentUser'}, $TempQuery, \@Dates, $date->strftime("%F"), $end->strftime("%F"));
193
194 </%INIT>