employee statistics: omit common components
[freeside.git] / httemplate / search / access_user_log.html
1 <& elements/search.html,
2                  'title'       => 'Access Log',
3                  'name'        => 'entries',
4                  'query'       => $query,
5                  'count_query' => $count_query,
6                  'header'      => [ 
7                                     'Path',
8                                     '#',
9                                     'Avg time',
10                                   ],
11                  'fields'      => [ sub { shift->pretty_path },
12                                     sub { shift->num_entries },
13                                     sub { shift->avg_render_seconds },
14                                   ],
15                  'sort_fields' => [qw( pretty_path num_entries avg_render_seconds )],
16              
17 &>
18 <%init>
19
20 die "access denied"
21   unless $FS::CurrentUser::CurrentUser->access_right('Employee Reports');
22
23 my %hashref = ();
24 my @extra_sql = ();
25
26 my($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi);
27 push @extra_sql, "_date >= $beginning" if $beginning;
28 push @extra_sql, "_date <= $ending"    if $ending;
29
30 my $count_hr = '';
31 if ( $cgi->param('usernum') =~ /^\d+$/ ) {
32   $hashref{usernum} = $cgi->param('usernum');
33   $count_hr = "WHERE usernum = ".$hashref{usernum}; 
34 }
35
36 if ( $cgi->param('skip_components') ) {
37   push @extra_sql, "path NOT IN ( '". join("','", 
38                                         map "/var/www/html/freeside/$_", qw(
39                                           view/REAL_logo.cgi
40                                           misc/jsrsServer.html
41                                           misc/xmlhttp-reason-hint.html
42                                           config/config-image.cgi
43                                           misc/xmlhttp-part_pkg_taxproduct.html
44                                           misc/progress-popup.html
45                                           misc/file-upload.html
46                                           misc/confirm-censustract.html
47                                           misc/xmlhttp-address_standardize.html
48                                           misc/confirm-address_standardize.html
49                                           misc/xmlhttp-part_pkg_usageprice.html
50                                         )
51                                       ).
52                              "' )";
53 }
54
55 my $extra_sql = '';
56 $extra_sql .=  (keys(%hashref) ? ' AND ' : ' WHERE ' ). join(' AND ', @extra_sql)
57   if @extra_sql;
58 my $count_extra = $extra_sql;
59 $extra_sql .= ' GROUP BY pretty_path '
60   if $cgi->param('group_by') eq 'path';
61
62 my $query = {
63   'select'    => join(' , ',
64                    "regexp_replace(path, '^/var/www/(html/)?freeside/', '') as pretty_path",
65                    'COUNT(*) AS num_entries',
66                    'ROUND(AVG(COALESCE(render_seconds,0)),1) '.
67                            ' AS avg_render_seconds',
68                  ),
69   'table'     => 'access_user_log',
70   'hashref'   => \%hashref,
71   'extra_sql' => $extra_sql,
72 };
73
74 my $count_query = "SELECT COUNT(DISTINCT path) FROM access_user_log $count_hr $count_extra";
75
76 </%init>