summaryrefslogtreecommitdiff
path: root/rt/share/html/Search/Calendar.html
blob: 9d2b6f5466b114503b16fc654d464d78571d6896 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
<%args>
$Month => (localtime)[4]
$Year => (localtime)[5] + 1900
$Query => undef
$Format => undef
$Order => undef
$OrderBy => undef
$RowsPerPage => undef
$NewQuery => 0
</%args>

<& /Elements/Header, Title => $title &>
<& /Ticket/Elements/Tabs, 
    current_tab => "Search/Calendar.html?$QueryString",
    Title => $title &>
<&| /Widgets/TitleBox,
     title => loc('Calendar for ') . $rtdate->GetMonth($Month) . " $Year" ,
     title_class=> 'inverse',
     color => "#993333" &>

<table width="100%">
<tr>
<td align="left">
% my ($PMonth, $PYear) = ($Month - 1, $Year);
% if ($PMonth < 0) {
%    $PYear--;
%    $PMonth = 11;
% }
<a href="<%$RT::WebPath%>/Search/Calendar.html?Month=<%$PMonth%>&Year=<%$PYear%>&<%$QueryString%>">«<%$rtdate->GetMonth($PMonth)%></a>
</td>
<th align="center">
  <font size="+1"><% $rtdate->GetMonth($Month). " $Year" %></font>
</th>
<td align="right">
% my ($NMonth, $NYear) = ($Month + 1, $Year);
% if ($NMonth > 11) {
%    $NYear++;
%    $NMonth = 0;
% }
<a href="<%$RT::WebPath%>/Search/Calendar.html?Month=<%$NMonth%>&Year=<%$NYear%>&<%$QueryString%>"><%$rtdate->GetMonth($NMonth)%>»</a>
</td>
</tr>
</table>

<table class="rtxcalendar">

<thead>
<tr>
% for ( @{$week{$weekstart}} ) {
<th width="14%"><%$rtdate->GetWeekday($_)%></th>
% }
</tr>
</thead>

<tbody>
<tr>
% while ($date <= $end) {
%
%   my $offmonth = $date->month != ($Month + 1);
%   my $is_today     = (DateTime->compare($today,     $date) == 0);
%   my $is_yesterday = (DateTime->compare($yesterday, $date) == 0);
%   my $is_aweekago  = (DateTime->compare($aweekago,  $date) == 0);

    <td class="<% $offmonth ? 'offmonth'
                    : $is_today     ? 'today'
                    : $is_yesterday ? 'yesterday'
                    : $is_aweekago  ? 'aweekago'
                    : ''
               %>"
    >
      <div class="<% $is_today ? 'todays'
                       : $offmonth ? 'offmonth'
                       :'' %>calendardate"
      ><%$date->day%></div>

%     my $sp = 3;
%     for my $t ( @{ $Tickets{$date->strftime("%F")} } ) {
%       $sp--;
        <& /Elements/CalendarEvent, Object => $t, Date => $date, DateTypes => \%DateTypes &>
%     }
      <% ($sp>0) ? '<BR>'x$sp : '' |n %>

    </td>

%   $date = $set->next($date);
%   if ( $date->day_of_week == $startday_of_week ) {
      </tr><tr>
%   }

% }
</tr>
</tbody>
</table>

<table width="100%">
<tr>
<td align="left">
<a href="<%$RT::WebPath%>/Search/Calendar.html?Month=<%$PMonth%>&Year=<%$PYear%>&<%$QueryString%>">«<%$rtdate->GetMonth($PMonth)%></a>
</td>

<td valign="top" align="center">
<form action="<%$RT::WebPath%>/Search/Calendar.html?<%$QueryString%>" method="post">

<select name="Month">
% for (0..11) {
<option value="<%$_%>" <% $_ == $Month ? 'selected' : ''%> ><%$rtdate->GetMonth($_)%></option>
% }
</select>
% my $year = (localtime)[5] + 1900;
<select name="Year">
% for ( ($year-5) .. ($year+5)) {
<option value="<%$_%>" <% $_ == $Year ? 'selected' : ''%>><%$_%></option>
% }
</select>

%# <& /Elements/Submit&>
<input type="submit" value="<% loc('Submit') %>" class="button" />

</form>
</td>

<td align="right">
<a href="<%$RT::WebPath%>/Search/Calendar.html?Month=<%$NMonth%>&Year=<%$NYear%>&<%$QueryString%>"><%$rtdate->GetMonth($NMonth)%>»</a>
</td>
</tr>
</table>

<table width="100%">
<tr>

<td valign="top" rowspan=9>
  <BR>
  <a href="<%$RT::WebPath%>/Prefs/Calendar.html">Calendar Preferences and Help</a>
</td>

% foreach my $legend (keys %legend) {
    <tr>
      <td align="right">
        <img src="<%$RT::WebImagesURL%>/<%$legend%>.png" />
      </td>
      <td align="left">
%       my $more = 0;
%       foreach ( @{$legend{$legend}} ) {
          <% $more++ ? ', ' : '' %>
          <&|/l&><% $_ %></&>
%       }
      </td>
    </tr>
% }

</table>

</&>

<%ONCE>

my %legend = (
  'created'     => ['Created'],
  'due'         => ['Due'],
  'resolved'    => ['Resolved'],
  'updated'     => ['Last Updated'],
  'created_due' => ['Created','Due'],
  'reminder'    => ['Reminders'],
  'started'     => ['Started'],
  'starts_due'  => ['Starts','Due'],
);

</%ONCE>
<%INIT>
use RTx::Calendar qw(FirstDay LastDay);

my $title = loc("Calendar");

my @DateTypes = qw/Created Starts Started Due LastUpdated Resolved/;

my $rtdate = RT::Date->new($session{'CurrentUser'});

my $weekstart = 'Sunday'; #RT::SiteConfig?  user pref?
my %week = (
  'Saturday' => [6,0..5],
  'Sunday'   => [0..6],
  'Monday'   => [1..6,0],
);
my $startday_of_week = ${$week{$weekstart}}[0]  || 7;
my $endday_of_week   = ${$week{$weekstart}}[-1] || 7;

my $today = DateTime->today;
my $yesterday = $today->clone->subtract( days=>1 );
my $aweekago  = $today->clone->subtract( days=>7 );
my $date = FirstDay($Year, $Month + 1, $startday_of_week );
my $end  = LastDay ($Year, $Month + 1, $endday_of_week );

# use this to loop over days until $end
my $set = DateTime::Set->from_recurrence(
    next => sub { $_[0]->truncate( to => 'day' )->add( days => 1 ) }
);

my $QueryString = 
      $m->comp(
        '/Elements/QueryString',
        Query   => $Query,
        Format  => $Format,
        Order   => $Order,
        OrderBy => $OrderBy,
        Rows    => $RowsPerPage
      )
      if ($Query);

$QueryString ||= 'NewQuery=1';

# Default Query and Format
my $TempFormat = "__Starts__ __Due__";
my $TempQuery = "( Status = 'new' OR Status = 'open' OR Status = 'stalled')
 AND ( Owner = '" . $session{CurrentUser}->Id ."' OR Owner = 'Nobody'  )
 AND ( Type = 'reminder' OR 'Type' = 'ticket' )"; 

if ( my $Search = RTx::Calendar::SearchDefaultCalendar($session{CurrentUser}) ) {
  $TempFormat = $Search->SubValue('Format');
  $TempQuery = $Search->SubValue('Query');
}

# we overide them if needed
$TempQuery  = $Query  if $Query;
$TempFormat = $Format if $Format;

# we search all date types in Format string
my @Dates = grep { $TempFormat =~ m/__${_}(Relative)?__/ } @DateTypes;

# used to display or not a date in Element/CalendarEvent
my %DateTypes = map { $_ => 1 } @Dates;

$TempQuery .= RTx::Calendar::DatesClauses(\@Dates, $date->strftime("%F"), $end->strftime("%F"));

# print STDERR ("-" x 30), "\n", $TempQuery, "\n";

my %Tickets = RTx::Calendar::FindTickets($session{'CurrentUser'}, $TempQuery, \@Dates, $date->strftime("%F"), $end->strftime("%F"));

</%INIT>