RT# 81692 Update use of deprecated widgets in RT
[freeside.git] / rt / share / html / RTx / Statistics / CallsMultiQueue / index.html
1 <& /Elements/Header, Title => loc('Tickets per day in Multiple queues') &>
2 <& /RTx/Statistics/Elements/Tabs, Title => loc('Tickets per day in Multiple Queues by status') &>
3
4 <h3>Description</h3>
5 <p>This chart shows details of tickets per day by their status. You can select multiple queues to display at the same time, but only one status. You can chose any of the defined status values. 
6 There is also the option to display all available queues at the same time.
7 The default display shows tickets resolved in your default queue (General unless altered locally).
8 The line chart below shows the same information in a graphical form.
9
10 <br />
11
12 <form method="POST" action="index.html">
13
14 %# Build Legend
15 % my @legend;
16 % for (sort keys %queues_to_show) {
17 %   push @legend, $_;
18 % }
19
20 %my $title = "Tickets with Status $status in " . join(', ', @queues) . ", per day from " .
21 %         Statistics::FormatDate($Statistics::PerDayDateFormat, $dates[0]) . " through " .
22 %         Statistics::FormatDate($Statistics::PerDayDateFormat, $dates[$#dates-1]);
23
24 <& /Widgets/TitleBoxStart, title => $title, title_href => $RT::WebPath."/RTx/Statistics/OpenStalled/index.html?$QueryString"&>
25 <TABLE BORDER=0 cellspacing=0 cellpadding=1 WIDTH="100%">
26 % if ($ShowHeader) {
27 <& /RTx/Statistics/Elements/CollectionAsTable/Header, 
28     Format => \@RowFormat, 
29     FormatString => $RowFormat,
30     AllowSorting => $AllowSorting, 
31     Order => $Order, 
32     Query => undef,
33     Rows => $Rows,
34     Page => $Page,
35     OrderBy => $OrderBy , 
36     BaseURL => $BaseURL,
37     maxitems => $maxitems &> 
38 % }
39 % my $line = 0;
40 % LINE: for my $d (0..$#dates) {
41 %   if ($d == $#dates ){
42 %     next LINE;
43 %   }
44 %   $line++;
45 %   my $x = 1;
46 %   $values{Statistics_Date} = Statistics::FormatDate($dateformat, $dates[$d]);
47 %   my $row_total=0;
48 %   foreach my $q (sort keys %queues_to_show) {
49 %     my $tix = new RT::Tickets($session{'CurrentUser'});
50 %     if ($status eq "resolved") {
51 %       $tix->LimitStatus(VALUE => $status);
52 %       $tix->LimitResolved(VALUE => $dates[$d]->ISO, OPERATOR => ">=");
53 %       if ($dates[$d+1]) {
54 %         $tix->LimitResolved(VALUE => $dates[$d+1]->ISO, OPERATOR => "<=");
55 %       }
56 %     } 
57 %     elsif ($status eq "new") {
58 %       $tix->LimitCreated(VALUE => $dates[$d]->ISO, OPERATOR => ">=");
59 %       if ($dates[$d+1]) {
60 %         $tix->LimitCreated(VALUE => $dates[$d+1]->ISO, OPERATOR => "<=");
61 %       }
62 %     } 
63 %     elsif ($status eq "deleted") {
64 %       $tix->LimitStatus(VALUE => $status);
65 %       $tix->LimitLastUpdated(VALUE => $dates[$d]->ISO, OPERATOR => ">=");
66 %       if ($dates[$d+1]) {
67 %         $tix->LimitLastUpdated(VALUE => $dates[$d+1]->ISO, OPERATOR => "<=");
68 %       }
69 %     }
70 %     elsif ($status eq "stalled") {
71 %       $tix->LimitStatus(VALUE => $status);
72 %       $tix->LimitLastUpdated(VALUE => $dates[$d]->ISO, OPERATOR => ">=");
73 %       if ($dates[$d+1]) {
74 %         $tix->LimitLastUpdated(VALUE => $dates[$d+1]->ISO, OPERATOR => "<=");
75 %       }
76 %     }
77 %     elsif ($status eq "open") {
78 %       $tix->LimitStatus(VALUE => $status);
79 %       $tix->LimitLastUpdated(VALUE => $dates[$d]->ISO, OPERATOR => ">=");
80 %       if ($dates[$d+1]) {
81 %         $tix->LimitLastUpdated(VALUE => $dates[$d+1]->ISO, OPERATOR => "<=");
82 %       }
83 %     }
84 %     elsif ($status eq "rejected") {
85 %       $tix->LimitStatus(VALUE => $status);
86 %       $tix->LimitLastUpdated(VALUE => $dates[$d]->ISO, OPERATOR => ">=");
87 %       if ($dates[$d+1]) {
88 %         $tix->LimitLastUpdated(VALUE => $dates[$d+1]->ISO, OPERATOR => "<=");
89 %       }
90 %     }
91 %     $tix->LimitQueue (VALUE => $q);
92 %     $values{$q} = $tix->Count;
93 %     $row_total += $tix->Count;
94 %     $data[$x++][$d] = $tix->Count;
95 %   }
96 %   $values{Statistics_Totals} = $row_total;
97 <&  /RTx/Statistics/Elements/CollectionAsTable/Row, Format => \@RowFormat, i => $line, record => $record, maxitems => $maxitems &>
98 % }
99 </table>
100 <& /Widgets/TitleBoxEnd&>
101
102 <!--    <td>Show:</td>
103     <td COLSPAN=2><SELECT NAME="status">
104 % for (qw(resolved new deleted stalled rejected open)) {
105     <OPTION VALUE="<% $_ %>" <% $_ eq $status && "SELECTED" %>>
106     <% loc($_) %></OPTION>
107 % }
108 --!>
109
110 <%perl>
111 # Create the graph URL
112 my $url = 'Elements/Chart?x_labels=';
113 #$url .= join ",", @{ shift @data } . "&";
114 for (0..$max) {
115      $url .=  $m->interp->apply_escapes($data[0][$_],'u') . ",";
116 }
117 chop $url;
118 $url .= "&";
119 shift @data;
120 $url .=  'set_legend='.(join ",", @legend)."&";
121 for (0..$#data) {
122   $url .= "data".(1+$_)."=". (join ",", @{$data[$_]})."&";
123 }
124 chop $url;
125 </%perl>
126
127 <& /RTx/Statistics/Elements/GraphBox, GraphURL => $url &>
128
129 <& /RTx/Statistics/Elements/ControlsAsTable/ControlBox, 
130          Title => "Change Status, Queues or Dates", 
131          ShowDates => 1, sMonth => \$sMonth, sDay => \$sDay, sYear => \$sYear,
132                          eMonth => \$eMonth, eDay => \$eDay, eYear => \$eYear,
133                          weekends => $weekends,
134          ShowMultiQueues => 1, queues_ref => \@queues,
135          ShowStatus => 1, Status => $status
136  &>
137
138 </form>
139
140 <a href="<%$RT::WebPath%>/RTx/Statistics/CallsMultiQueue/index.html?<% $QueryString %>"><&|/l&>Bookmarkable link</&></a>
141 %# | <a href="<%$RT::WebPath%>/RTx/Statistics/CallsMultiQueue/Results.tsv?<%$QueryString%>"><&|/l&>spreadsheet</&></a>
142 <BR>
143 <BR>
144
145 <%ARGS>
146 $status => $Statistics::MultiQueueStatus
147 $max => $Statistics::MultiQueueMaxRows
148 @queues => @Statistics::MultiQueueQueueList
149 $weekends => $Statistics::PerDayWeekends;
150 $sMonth=>undef
151 $sDay=>undef
152 $sYear=>undef
153 $eMonth=>undef
154 $eDay=>undef
155 $eYear=>undef
156 $days=>undef
157 $dateformat => $Statistics::MultiQueueDateFormat
158 $currentMonth=>undef
159
160 $AllowSorting => undef
161 $Order => undef
162 $OrderBy => undef
163 $ShowNavigation => 1
164 $ShowHeader => 1
165 $Rows => 50
166 $Page => 1
167 $BaseURL => undef
168 $AddAllCheck => undef
169 </%ARGS>
170
171 <%INIT>
172
173 use RTx::Statistics;
174 use Time::Local;
175 my $n = 0;
176 my @data = ([]);
177 my @dates;
178 my @msgs;
179 my $selected;
180 my $diff;
181 my %queues_to_show;
182 my $secsPerDay=86400;
183 my $sEpoch;
184 my $eEpoch;
185 my $QueryString;
186 my $maxitems;
187 my $RowFormat;
188 my $BoldRowFormat;
189 my %record;
190 my %values;
191 my $record = \%record;
192
193 $record{values} = \%values;
194
195 Statistics::DebugClear();
196 Statistics::DebugLog("CallsQueueDay/index.html ARGS:\n");
197 for my $key (keys %ARGS) {
198   Statistics::DebugLog("ARG{ $key }=" . $ARGS{$key} . "\n");
199 }
200
201
202   # Handle the Add All Checkbox
203   if($AddAllCheck eq "on") {
204     $AddAllCheck = undef;
205     undef (@queues);
206     my $q=new RT::Queues($session{'CurrentUser'});
207     $q->UnLimit;
208     while (my $queue=$q->Next) {
209       next if !$queue->CurrentUserHasRight('SeeQueue');
210       push @queues, $queue->Name;
211     }
212   }
213
214   # If the user has the right to see the queue, put it into the map
215   for my $q (@queues) {
216       my $Queueobj = new RT::Queue($session{'CurrentUser'});
217       $Queueobj->Load($q);
218       next if !$Queueobj->CurrentUserHasRight('SeeQueue');
219       $queues_to_show{$q} = 1;
220   }
221
222   $maxitems = (scalar @queues) + 2;
223
224   # Build the format strings
225   $RowFormat = "'__Statistics_Date__'";
226   $BoldRowFormat = "'<B>__Statistics_Date__</B>'";
227   for my $q (@queues) {
228       $RowFormat .= ",'__Statistics_Dynamic__/KEY:$q/TITLE:$q/STYLE:text-align:right;'";
229       $BoldRowFormat .= ",'<B>__Statistics_Dynamic__</B>/KEY:$q/TITLE:$q/STYLE:text-align:right;'";
230   }
231   $RowFormat .= ",'<B>__Statistics_Totals__</B>/STYLE:text-align:right;'";
232   $BoldRowFormat .= ",'<B>__Statistics_Totals__</B>/STYLE:text-align:right;'";
233   # Parse the formats into structures.
234   my (@RowFormat) = $m->comp('/RTx/Statistics/Elements/CollectionAsTable/ParseFormat', Format => $RowFormat);
235   my (@BoldRowFormat) = $m->comp('/RTx/Statistics/Elements/CollectionAsTable/ParseFormat', Format => $BoldRowFormat);
236
237 if ($sDay > $Statistics::monthsMaxDay{$sMonth}) {
238   $sDay = $Statistics::monthsMaxDay{$sMonth};
239 }
240
241 if ($eDay > $Statistics::monthsMaxDay{$eMonth}) {
242   $eDay = $Statistics::monthsMaxDay{$eMonth};
243 }
244
245 if ($sYear){
246         $sEpoch = timelocal(0, 0, 0, $sDay, $sMonth, $sYear-1900);
247 }
248 if ($eYear){
249 Statistics::DebugLog("eMonth = " . $eMonth . "\n");
250         $eEpoch = timelocal(0, 0, 0, $eDay, $eMonth, $eYear-1900);
251 } else {
252         # This case happens when the page is first loaded
253         my @local = localtime(time);
254         ($eDay, $eMonth, $eYear) = ($local[3], $local[4], $local[5]);
255         $eYear += 1900; 
256         $eEpoch = timelocal(0, 0, 0, $local[3], $local[4], $local[5], $local[6], $local[7], $local[8]);
257 Statistics::DebugLog("Setting eEpoch=$eEpoch from current time.\n");
258 }
259
260 if (($eEpoch < $sEpoch) || ($sEpoch == 0)) {
261     # We have an end, but not a start, or, overlapping.
262     
263     # if $currentMonth is set, just set the day to 1
264     if($currentMonth) {
265       # set start vars from end, but with day set to 1
266       (undef, undef, undef, $sDay, $sMonth, $sYear) = localtime($eEpoch);
267       $sDay=1;
268       $sEpoch = timelocal(0, 0, 0, $sDay, $sMonth, $sYear);
269     } else {
270       # If the user has specified how many days back to go, use that,
271       # If not, set start to configured default period before end
272       if(defined $days) {
273         $sEpoch = $eEpoch - ($days * $Statistics::secsPerDay);
274       } else {
275         $sEpoch = $eEpoch - ($Statistics::PerDayPeriod * $Statistics::secsPerDay);
276       }
277       (undef, undef, undef, $sDay, $sMonth, $sYear) = localtime($sEpoch);
278     }
279     $sYear += 1900;
280 }
281
282 # Compute days to chart.
283 # The +1 is because we need to generate one more date. If the user
284 # selected a 10 day range, we need to generate 11 days.
285 $diff = int(($eEpoch - $sEpoch + $Statistics::secsPerDay - 1) / $Statistics::secsPerDay)+1;
286 Statistics::DebugLog("Setting diff=$diff\n");
287
288 Statistics::DebugLog("sEpoch=$sEpoch, components=" . join(',', localtime($sEpoch)) . "\n");
289 Statistics::DebugLog("eEpoch=$eEpoch, components=" . join(',', localtime($eEpoch)) . "\n");
290
291 # Build the new query string
292 $QueryString = "queues=" . join("&queues=", @queues);
293 $QueryString .= "&sDay=$sDay&sMonth=$sMonth&sYear=$sYear&eDay=$eDay&eMonth=$eMonth&eYear=$eYear&weekends=$weekends";
294
295
296
297
298 # Set up the end date to be midnight(morning) of the date after the one the user wanted.
299 my $endRange = $eEpoch + $Statistics::secsPerDay;
300 $n = 0;
301 until ($#dates == $diff) {
302     my $date = new RT::Date($session{CurrentUser});
303     $date->Set(Value=>$endRange - $n, Format => 'unix');
304     # Note: we used to adjust the time to local midnight, but
305     # none of the other date entry fields in RT seem to adjust, so we've stopped.
306     #Statistics::DebugLog("Before adjust to midnight date " . Statistics::FormatDate("%c", $date) . "\n");
307     $n+= $Statistics::secsPerDay;
308     # If we aren't showing weekends and this is one, decrement the number
309     # of days to show and skip to the next date.
310     if(!$weekends and Statistics::RTDateIsWeekend($date)) {$diff--; next;}
311     unshift @dates, $date;
312 Statistics::DebugLog("pushing date " . Statistics::FormatDate("%c", $date) . "\n");
313     unshift @{ $data[0] }, Statistics::FormatDate($Statistics::PerDayLabelDateFormat, $date);
314 }
315
316 # We put an extra day into the lists to cover up till midnight of the next day,
317 # But we don't want that to appear in the labels, so pop it off.
318 pop( @{ $data[0] } );
319
320 my $queue = new RT::Queues($session{CurrentUser});
321 $queue->UnLimit;
322
323 my $QueueObj = new RT::Queue($session{'CurrentUser'});
324 $QueueObj->Load($queue);
325 </%INIT>