6353abbdb1e30e770a109f73e0a560c8f09d20d9
[freeside.git] / rt / share / html / RTx / Statistics / DayOfWeek / index.html
1 <& /Elements/Header, Title =>loc('Tickets by Day Of Week in Queue:' . $QueueObj->Name()) &>
2 <& /RTx/Statistics/Elements/Tabs, Title =>loc('Trends in ticket status by Day Of Week in Queue:' . $QueueObj->Name()) &>
3
4 <h3>Description</h3>
5 <p>The purpose of this page is to show historical trends for each day of the week. 
6 It displays details of number of tickets created in your
7 selected queue for each day. It also hows how many of those created tickets were Resolved or Deleted</p>
8
9 <form method="POST" action="index.html">
10
11
12 %my $title = "Ticket counts by day of week in " . $QueueObj->Name();
13 <&|/Elements/TitleBox, 
14         title => $title,
15         title_href => "/RTx/Statistics/DayOfWeek/index.html?$QueryString" &>
16 <TABLE BORDER=0 cellspacing=0 cellpadding=1 WIDTH=100%>
17 % if ($ShowHeader) {
18 <& /RTx/Statistics/Elements/CollectionAsTable/Header, 
19     Format => \@Format, 
20     FormatString => $Format,
21     AllowSorting => $AllowSorting, 
22     Order => $Order, 
23     Query => undef,
24     Rows => $Rows,
25     Page => $Page,
26     OrderBy => $OrderBy , 
27     BaseURL => $BaseURL,
28     maxitems => $maxitems &> 
29 % }
30 % my $line = 1;
31 % for my $d (0..$#days) {
32 %     my $x = 1;
33 %     $values{Statistics_Date} = $days[$d];
34 %# NOTE Show all status values???
35 %     $values{Statistics_Created_Count} = $counts[$d]{new};
36 %     $values{Statistics_Resolved_Count} = $counts[$d]{resolved};
37 %     $values{Statistics_Deleted_Count} = $counts[$d]{deleted};
38 <&   /RTx/Statistics/Elements/CollectionAsTable/Row, Format => \@Format, i => $line, record => $record, maxitems => $maxitems &>
39 %    $line++;
40 % }
41 % $values {Statistics_Date} = "Totals";
42 % $values {Statistics_Created_Count} = $Totals{new};
43 % $values {Statistics_Resolved_Count} = $Totals{resolved};
44 % $values {Statistics_Deleted_Count} = $Totals{deleted};
45 <&   /RTx/Statistics/Elements/CollectionAsTable/Row, Format => \@BoldFormat, i => $line, record => $record, maxitems => $maxitems &>
46 </table>
47 </&>
48
49 <%perl>
50 my $url = 'Elements/Chart?&x_labels=';
51 for (0..$#days) {
52   $url .= $days[$_] . "," ;
53 }
54 chop $url;
55 $url .= "&";
56
57 my @things = qw(new resolved deleted);
58 for my $th (0..$#things) {
59   $url .= "data".(1+$th)."=".(join ",", map { $counts[$_]{$things[$th]} } (0..6))."&";
60 }
61 chop $url;
62 $url .= '&set_legend=Created,Resolved,Deleted';
63 </%perl>
64
65 <& /RTx/Statistics/Elements/GraphBox, GraphURL => $url &>
66
67 % Statistics::DebugLog("queue name=" . $QueueObj->Id() . "\n");
68
69 <& /RTx/Statistics/Elements/ControlsAsTable/ControlBox, 
70          Title => "Change Queue", 
71          ShowSingleQueue => 1, Queue => $QueueObj->Id()
72  &>
73
74 </form>
75
76 % Statistics::DebugInit( $m );
77
78 <%ARGS>
79 $Queue => $Statistics::DayOfWeekQueue
80
81 $AllowSorting => undef
82 $Order => undef
83 $OrderBy => undef
84 $ShowNavigation => 1
85 $ShowHeader => 1
86 $Rows => 50
87 $Page => 1
88 $BaseURL => undef
89 </%ARGS>
90
91 <%INIT>
92 use GD::Graph;
93 use RTx::Statistics;
94 my @days = qw(Sun Mon Tue Wed Thu Fri Sat);
95 my $n = 0;
96 my @data = ([]);
97 my @msgs;
98 my @counts;
99 my %Totals = (
100   resolved => 0,
101   deleted => 0,
102   new => 0
103 );
104 my $QueryString = "Queue=$Queue";
105 my $maxitems = 4;
106 my %record;
107 my %values;
108 my $record = \%record;
109
110 $record{values} = \%values;
111
112 my $Format = qq{ Statistics_Date, 
113                  '__Statistics_Created_Count__/STYLE:text-align:right;', 
114                  '__Statistics_Resolved_Count__/STYLE:text-align:right;', 
115                  '__Statistics_Deleted_Count__/STYLE:text-align:right;' };
116 my $BoldFormat = qq{ '<B>__Statistics_Date__</B>', 
117                      '<B>__Statistics_Created_Count__</B>/STYLE:text-align:right;',
118                      '<B>__Statistics_Resolved_Count__</B>/STYLE:text-align:right;',
119                      '<B>__Statistics_Deleted_Count__</B>/STYLE:text-align:right;' };
120 my (@Format) = $m->comp('/RTx/Statistics/Elements/CollectionAsTable/ParseFormat', Format => $Format);
121 my (@BoldFormat) = $m->comp('/RTx/Statistics/Elements/CollectionAsTable/ParseFormat', Format => $BoldFormat);
122
123 my $QueueObj = new RT::Queue($session{'CurrentUser'});
124 $QueueObj->Load($Queue);
125 $RT::Logger->warning("Loaded queue $Queue, name=". $QueueObj->Name());
126
127 my $tix = new RT::Tickets($session{'CurrentUser'});
128 $tix->LimitQueue (VALUE => $Queue);
129 $tix->UnLimit;
130 if ($tix->Count) {
131     # Initialize the counters to zero, so that all the cells show up
132     foreach my $day (0..@days) {
133         $counts[$day]{resolved} = 0;
134         $counts[$day]{deleted} = 0;
135         $counts[$day]{new} = 0;
136     }
137     while (my $t = $tix->RT::SearchBuilder::Next) {  # BLOODY HACK
138         if($t->Status eq "resolved") {
139           $counts[(localtime($t->ResolvedObj->Unix))[6]]{resolved}++;
140           $Totals{resolved}++;
141         }
142         if($t->Status eq "deleted") {
143           $counts[(localtime($t->LastUpdatedObj->Unix))[6]]{deleted}++;
144           $Totals{deleted}++;
145         }
146         $counts[(localtime($t->CreatedObj->Unix))[6]]{new}++;
147         $Totals{new}++;
148     }
149 }
150 </%INIT>