enable CardFortress in test database, #71513
[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->path },
12                                     sub { shift->num_entries },
13                                     sub { shift->avg_render_seconds },
14                                   ],
15                  'sort_fields' => [qw( path num_entries avg_render_seconds )],
16              
17 &>
18 <%init>
19
20 die "access denied"
21   unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
22
23 my %hashref = ();
24 my @extra_sql = ();
25
26 my($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi, '_date');
27 push @extra_sql, "_date >= $beginning" if $beginning;
28 push @extra_sql, "_date <= $ending"    if $ending;
29
30 $hashref{usernum} = $cgi->param('usernum') if $cgi->param('usernum') =~ /^\d+$/;
31
32 my $extra_sql = '';
33 $extra_sql .=  (keys(%hashref) ? ' AND ' : ' WHERE ' ). join(' AND ', @extra_sql)
34   if @extra_sql;
35 $extra_sql .= ' GROUP BY path '
36   if $cgi->param('group_by') eq 'path';
37 warn $extra_sql;
38
39 my $query = {
40   'select'    => join(' , ',
41                    'path',
42                    'COUNT(*) AS num_entries',
43                    'ROUND(AVG(COALESCE(render_seconds,0)),1) '.
44                            ' AS avg_render_seconds',
45                  ),
46   'table'     => 'access_user_log',
47   'hashref'   => \%hashref,
48   'extra_sql' => $extra_sql,
49 };
50
51 #uuh, no, need dates and usernum too, but whatever for now
52 my $count_query = 'SELECT COUNT(DISTINCT path) FROM access_user_log';
53
54 </%init>