integrate RTx::Statistics package, part of merging spiritone RT changes (#1661)
[freeside.git] / rt / html / RTx / Statistics / OpenStalled / index.html
1 <& /Elements/Header, Title => loc('New, Open and Stalled tickets by Queue') &>
2 <& /RTx/Statistics/Elements/Tabs, Title => loc('New, Open and Stalled tickets by Queue') &>
3
4 <h3>Description</h3>
5 <p>The purpose of this page is to show a snapshot of the current status of tickets by Queue. You can multi select Queues from the dropdown
6 list or simply show all available queues. This will indicate how many tickets have not yet been viewed (New), how many have been at least
7 viewed once (Open) and how many have had their status changed to stalled.</p>
8
9 <form method="POST" action="index.html">
10
11 %my $tix = new RT::Tickets($session{'CurrentUser'});
12 %if ($queue) {
13 %        $tix->LimitQueue (VALUE => $queue);
14 %}
15
16
17 %my $title = "New, Open and Stalled Tickets in " . join(', ', @queues);
18 <& /Elements/TitleBoxStart, title => $title, title_href => "/RTx/Statistics/OpenStalled/index.html?$QueryString"&>
19 <TABLE BORDER=0 cellspacing=0 cellpadding=1 WIDTH="100%">
20 % if ($ShowHeader) {
21 <& /RTx/Statistics/Elements/CollectionAsTable/Header, 
22     Format => \@RowFormat, 
23     FormatString => $RowFormat,
24     AllowSorting => $AllowSorting, 
25     Order => $Order, 
26     Query => undef,
27     Rows => $Rows,
28     Page => $Page,
29     OrderBy => $OrderBy , 
30     BaseURL => $BaseURL,
31     maxitems => $maxitems &> 
32 % }
33
34 %    for ( sort keys %queues_to_show) {
35 %        push @data, $_;
36 %    }
37 %    my @legend;
38 %    my $total = 0;
39 %    my $line = 0;
40 %# NOTE need to handle all status values (see share/html/Elements/SelectStatus).
41 %    foreach my $s (qw(new open stalled)) {
42 %      $line++;
43 %      push @legend, $s;
44 %      $total=0;
45 %      foreach my $q (sort keys %queues_to_show)  {
46 %        $tix = new RT::Tickets($session{'CurrentUser'});
47 %        $tix->LimitQueue(VALUE => "$q");
48 %        $tix->LimitStatus(VALUE => "$s");
49 %        push @data, $tix->Count;
50 %        $totals{$q} += $tix->Count; # Add up columns for each queue
51 %        $total += $tix->Count;
52 %        $values{$q} = $tix->Count;
53 %      }
54 %      $totals{"Totals"} += $total;
55 %      $values{Statistics_Status} = $s;
56 %      $values{Statistics_Totals} = $total;
57 <&     /RTx/Statistics/Elements/CollectionAsTable/Row, Format => \@RowFormat, i => $line, record => $record, maxitems => $maxitems &>
58 %    }
59 %    $values{Statistics_Status} = "Totals";
60 %    foreach my $q (sort keys %queues_to_show) {
61 %      $values{$q} = $totals{$q};
62 %    }
63 %    $values{Statistics_Totals} = $totals{"Totals"};
64 <&   /RTx/Statistics/Elements/CollectionAsTable/Row, Format => \@BoldRowFormat, i => $line+1, record => $record, maxitems => $maxitems &>
65 </table>
66 <& /Elements/TitleBoxEnd&>
67
68 <hr>
69
70 <BR />
71 <BR />
72
73 % use Data::Dumper;
74 % Statistics::DebugLog("Dump of data array is " . Dumper(@data) . "\n");
75 %  my $url = 'Elements/Chart?x_labels=';
76 %  for (1..(scalar keys %queues_to_show)) {
77 %    $url .=  $m->interp->apply_escapes((shift @data),'u')  . ',';
78 %  }
79 %  chop $url;
80 %  $url .= '&data1=' ;
81 %  for (1..(scalar keys %queues_to_show)) {
82 %    $url .=  $m->interp->apply_escapes((shift @data),'u') . ',';
83 %  }
84 %  chop $url;
85 %  $url .= '&data2=' ;
86 %  for (1..(scalar keys %queues_to_show)) {
87 %    $url .=  $m->interp->apply_escapes((shift @data),'u') . ',';
88 %  }
89 %  chop $url;
90 %  $url .= '&data3=' ;
91 %  for (1..(scalar keys %queues_to_show)) {
92 %    $url .=  $m->interp->apply_escapes((shift @data),'u') . ',';
93 %  }
94 %  $url .= '&set_legend='.(join ",", @legend);
95
96
97 <& /RTx/Statistics/Elements/GraphBox, GraphURL => $url &>
98
99 <& /RTx/Statistics/Elements/ControlsAsTable/ControlBox, Title => "Select Queues", ShowMultiQueues => 1, queues_ref => \@queues &>
100
101 <a href="<%$RT::WebPath%>/RTx/Statistics/OpenStalled/index.html?<% $QueryString %>"><&|/l&>Bookmarkable link</&></a>
102 %# | <a href="<%$RT::WebPath%>/RTx/Statistics/OpenStalled/Results.tsv?<%$QueryString%>"><&|/l&>spreadsheet</&></a>
103 <BR>
104 <BR>
105
106 </FORM>
107
108 % Statistics::DebugInit( $m );
109
110 <%ARGS>
111 @queues => @Statistics::OpenStalledQueueList
112 $AllowSorting => undef
113 $Order => undef
114 $OrderBy => undef
115 $ShowNavigation => 1
116 $ShowHeader => 1
117 $Rows => 50
118 $Page => 1
119 $BaseURL => undef
120 $AddAllCheck => undef
121 </%ARGS>
122
123 <%INIT>
124   use RTx::Statistics;
125
126   my $n = 0;
127   my @data; 
128   my @msgs;
129   my %totals;
130   my $QueryString;
131   my %queues_to_show;
132   my $maxitems;
133   my $RowFormat;
134   my $BoldRowFormat;
135   my %record;
136   my %values;
137   my $record = \%record;
138
139   $record{values} = \%values;
140
141   Statistics::DebugClear();
142
143   # Handle the Add All Checkbox
144   if($AddAllCheck eq "on") {
145     $AddAllCheck = undef;
146     undef (@queues);
147     my $q=new RT::Queues($session{'CurrentUser'});
148     $q->UnLimit;
149     while (my $queue=$q->Next) {
150       next if !$queue->CurrentUserHasRight('SeeQueue');
151       push @queues, $queue->Name;
152     }
153   }
154
155   # If the user has the right to see the queue, put it into the map
156   for my $q (@queues) {
157       my $Queueobj = new RT::Queue($session{'CurrentUser'});
158       $Queueobj->Load($q);
159       next if !$Queueobj->CurrentUserHasRight('SeeQueue');
160       $queues_to_show{$q} = 1;
161   }
162
163   $maxitems = (scalar @queues) + 2;
164
165   # Build the new query string
166   $QueryString = "queues=" . join("&queues=", @queues);
167
168   # Build the format strings
169   $RowFormat = "'__Statistics_Status__'";
170   $BoldRowFormat = "'<B>__Statistics_Status__</B>'";
171   for my $q (@queues) {
172       $RowFormat .= ",'__Statistics_Dynamic__/KEY:$q/TITLE:$q/STYLE:text-align:right;'";
173       $BoldRowFormat .= ",'<B>__Statistics_Dynamic__</B>/KEY:$q/TITLE:$q/STYLE:text-align:right;'";
174   }
175   $RowFormat .= ",'<B>__Statistics_Totals__</B>/STYLE:text-align:right;'";
176   $BoldRowFormat .= ",'<B>__Statistics_Totals__</B>/STYLE:text-align:right;'";
177   # Parse the formats into structures.
178   my (@RowFormat) = $m->comp('/RTx/Statistics/Elements/CollectionAsTable/ParseFormat', Format => $RowFormat);
179   my (@BoldRowFormat) = $m->comp('/RTx/Statistics/Elements/CollectionAsTable/ParseFormat', Format => $BoldRowFormat);
180
181
182   my $queue = new RT::Queues($session{CurrentUser});
183   $queue->UnLimit;
184
185   my $QueueObj = new RT::Queue($session{'CurrentUser'});
186   $QueueObj->Load($queue);
187
188 </%INIT>