summaryrefslogtreecommitdiff
path: root/httemplate/search/access_user_log.html
blob: 75bfa13efc0a029b5d28020809ff1100065c01d5 (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
<& elements/search.html,
                 'title'       => 'Access Log',
                 'name'        => 'entries',
                 'query'       => $query,
                 'count_query' => $count_query,
                 'header'      => [ 
                                    'Path',
                                    '#',
                                    'Avg time',
                                  ],
                 'fields'      => [ sub { shift->pretty_path },
                                    sub { shift->num_entries },
                                    sub { shift->avg_render_seconds },
                                  ],
                 'sort_fields' => [qw( pretty_path num_entries avg_render_seconds )],
             
&>
<%init>

die "access denied"
  unless $FS::CurrentUser::CurrentUser->access_right('Employee Reports');

my %hashref = ();
my @extra_sql = ();

my($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi);
push @extra_sql, "_date >= $beginning" if $beginning;
push @extra_sql, "_date <= $ending"    if $ending;

my $count_hr = '';
if ( $cgi->param('usernum') =~ /^\d+$/ ) {
  $hashref{usernum} = $cgi->param('usernum');
  $count_hr = "WHERE usernum = ".$hashref{usernum}; 
}

if ( $cgi->param('skip_components') ) {
  push @extra_sql, "path NOT IN ( '". join("','", 
                                        map "/var/www/html/freeside/$_", qw(
                                          view/REAL_logo.cgi
                                          misc/jsrsServer.html
                                          misc/xmlhttp-reason-hint.html
                                          config/config-image.cgi
                                          misc/xmlhttp-part_pkg_taxproduct.html
                                          misc/progress-popup.html
                                          misc/file-upload.html
                                          misc/confirm-censustract.html
                                          misc/xmlhttp-address_standardize.html
                                          misc/confirm-address_standardize.html
                                          misc/xmlhttp-part_pkg_usageprice.html
                                        )
                                      ).
                             "' )";
}

my $extra_sql = '';
$extra_sql .=  (keys(%hashref) ? ' AND ' : ' WHERE ' ). join(' AND ', @extra_sql)
  if @extra_sql;
my $count_extra = $extra_sql;
$extra_sql .= ' GROUP BY pretty_path '
  if $cgi->param('group_by') eq 'path';

my $query = {
  'select'    => join(' , ',
                   "regexp_replace(path, '^/var/www/(html/)?freeside/', '') as pretty_path",
                   'COUNT(*) AS num_entries',
                   'ROUND(AVG(COALESCE(render_seconds,0)),1) '.
                           ' AS avg_render_seconds',
                 ),
  'table'     => 'access_user_log',
  'hashref'   => \%hashref,
  'extra_sql' => $extra_sql,
};

my $count_query = "SELECT COUNT(DISTINCT path) FROM access_user_log $count_hr $count_extra";

</%init>