diff options
author | Mark Wells <mark@freeside.biz> | 2012-12-11 14:38:07 -0800 |
---|---|---|
committer | Mark Wells <mark@freeside.biz> | 2012-12-11 14:38:07 -0800 |
commit | 913bd0405d6eb0db41b9944dfd42eb1f97d18ca9 (patch) | |
tree | ce51c6db058fe65de6f37ec5ce047dc75007cfa3 /httemplate | |
parent | bda74e13569c8531e77e8dcd01d9da9038f3c4d0 (diff) |
system log, #18333
Diffstat (limited to 'httemplate')
-rw-r--r-- | httemplate/elements/menu.html | 12 | ||||
-rw-r--r-- | httemplate/search/elements/search-html.html | 18 | ||||
-rw-r--r-- | httemplate/search/log.html | 221 |
3 files changed, 248 insertions, 3 deletions
diff --git a/httemplate/elements/menu.html b/httemplate/elements/menu.html index bfbc179b9..66e8bf669 100644 --- a/httemplate/elements/menu.html +++ b/httemplate/elements/menu.html @@ -346,6 +346,14 @@ if($curuser->access_right('Financial reports')) { } # else $report_financial contains nothing. +tie my %report_logs, 'Tie::IxHash'; + $report_logs{'System log'} = [ $fsurl.'search/log.html', 'View system events and debugging information.' ], + if $curuser->access_right('View system logs') + || $curuser->access_right('Configuration'); + $report_logs{'Outgoing messages'} = [ $fsurl.'search/cust_msg.html', 'View outgoing message log' ] + if $curuser->access_right('View email logs') + || $curuser->access_right('Configuration'); + tie my %report_menu, 'Tie::IxHash'; $report_menu{'Prospects'} = [ \%report_prospects, 'Prospect reports' ] if $curuser->access_right('List prospects'); @@ -375,6 +383,8 @@ $report_menu{'Billing events'} = [ \%report_bill_event, 'Billing events' ] $report_menu{'Financial'} = [ \%report_financial, 'Financial reports' ] if $curuser->access_right('Financial reports') or $curuser->access_right('Receivables report'); +$report_menu{'Logs'} = [ \%report_logs, 'System and email logs' ] + if (keys %report_logs); # empty if the user has no rights to it $report_menu{'SQL Query'} = [ $fsurl.'search/report_sql.html', 'SQL Query' ] if $curuser->access_right('Raw SQL'); @@ -440,8 +450,6 @@ $tools_menu{'Time Queue'} = [ $fsurl.'search/report_timeworked.html', 'View pen if $curuser->access_right('Time queue'); $tools_menu{'Attachments'} = [ $fsurl.'browse/cust_attachment.html', 'View customer attachments' ] if !$conf->config('disable_cust_attachment') and $curuser->access_right('View attachments') and $curuser->access_right('Browse attachments'); -$tools_menu{'Outgoing messages'} = [ $fsurl.'search/cust_msg.html', 'View outgoing message log' ] #shouldn't this be in the reports menu? - if $curuser->access_right('View email logs'); $tools_menu{'Importing'} = [ \%tools_importing, 'Import tools' ] if $curuser->access_right('Import'); $tools_menu{'Exporting'} = [ \%tools_exporting, 'Export tools' ] diff --git a/httemplate/search/elements/search-html.html b/httemplate/search/elements/search-html.html index 5c8001fad..7ccf356ea 100644 --- a/httemplate/search/elements/search-html.html +++ b/httemplate/search/elements/search-html.html @@ -259,6 +259,7 @@ % % my $links = $opt{'links'} ? [ @{$opt{'links'}} ] : ''; % my $onclicks = $opt{'link_onclicks'} ? [ @{$opt{'link_onclicks'}} ] : []; +% my $tooltips = $opt{'tooltips'} ? [ @{$opt{'tooltips'}} ] : []; % my $aligns = $opt{'align'} ? [ @{$opt{'align'}} ] : ''; % my $colors = $opt{'color'} ? [ @{$opt{'color'}} ] : []; % my $sizes = $opt{'size'} ? [ @{$opt{'size'}} ] : []; @@ -360,6 +361,7 @@ % if ( $links ) { % my $link = shift @$links; % my $onclick = shift @$onclicks; +% my $tooltip = shift @$tooltips; % % if ( ! $opt{'agent_virt'} % || ( $null_link && ! $row->agentnum ) @@ -374,6 +376,14 @@ % if ref($onclick) eq 'CODE'; % $onclick = qq( onClick="$onclick") if $onclick; % +% $tooltip = &{$tooltip}($row) +% if ref($tooltip) eq 'CODE'; +% $tooltip = qq! id="a$id" !. +% qq! onmouseover="return overlib(!. +% $m->interp->apply_escapes($tooltip, 'h', 'js_string'). +% qq!, FGCLASS, 'tooltip', REF, 'a$id', !. +% qq!REFC, 'LL', REFP, 'UL')"! if $tooltip; +% % if ( $link ) { % my( $url, $method ) = @{$link}; % if ( ref($method) eq 'CODE' ) { @@ -381,11 +391,16 @@ % } else { % $a = $url. $row->$method(); % } -% $a = qq(<A HREF="$a"$onclick>); +% $a = qq(<A HREF="$a"$onclick$tooltip>); % } % elsif ( $onclick ) { % $a = qq(<A HREF="javascript:void(0);"$onclick>); % } +% elsif ( $tooltip ) { +% $a = qq(<A $tooltip>); +% } +% $id++; + % } % % } @@ -499,4 +514,5 @@ $count_sth->execute my $count_arrayref = $count_sth->fetchrow_arrayref; my $total = $count_arrayref->[0]; +my $id = 0; </%init> diff --git a/httemplate/search/log.html b/httemplate/search/log.html new file mode 100644 index 000000000..d1bfb6cc9 --- /dev/null +++ b/httemplate/search/log.html @@ -0,0 +1,221 @@ +<& elements/search.html, + 'title' => 'System Log', + 'name_singular' => 'event', + 'html_init' => include('.head'), + 'query' => $query, + 'count_query' => $count_query, + 'header' => [ #'#', # lognum, probably not useful + 'Date', + 'Level', + 'Context', + 'Applies To', + 'Message', + ], + 'fields' => [ #'lognum', + $date_sub, + $level_sub, + $context_sub, + $object_sub, + $message_sub, + ], + 'sort_fields' => [ + '_date', + 'level', + '', + 'tablename,tablenum', + 'message', + ], + 'links' => [ + '', #date + '', #level + '', #context + $object_link_sub, + '', #message + ], + 'tooltips' => [ + '', #date + '', #level + $tt_sub, + '', #object + $tt_sub, + ], + 'color' => [ + $color_sub, + $color_sub, + '', + '', + '', + ], + # aligns + 'download_label' => 'Download this log', +&>\ +<%def .head> +<STYLE type="text/css"> +a:link {text-decoration: none} +a:visited {text-decoration: none} +.tooltip { + background-color: #ffffff; + font-size: 100%; + font-weight: bold; +} +</STYLE> +<FORM ACTION="<%$p%>search/log.html" METHOD="GET"> +<TABLE CELLSPACING="10"> +<TR> + <TD>From + <& /elements/input-date-field.html, { + name => 'beginning', + value => $cgi->param('beginning'), + } &> + </TD> + <TD>To + <& /elements/input-date-field.html, { + name => 'ending', + value => $cgi->param('ending') || '', + noinit => 1, + } &> + </TD> +</TR> +<TR> + <TD>Level + <& /elements/select.html, + field => 'min_level', + options => [ 0..7 ], + labels => { map {$_ => $FS::Log::LEVELS[$_]} 0..7 }, + curr_value => $cgi->param('min_level'), + &> + to + <& /elements/select.html, + field => 'max_level', + options => [ 0..7 ], + labels => { map {$_ => $FS::Log::LEVELS[$_]} 0..7 }, + curr_value => $cgi->param('max_level'), + &> + </TD> + <TD> + Context + <& /elements/select.html, + field => 'context', + options => \@contexts, + labels => { map {$_, $_} @contexts }, + curr_value => ($cgi->param('context') || ''), + &> + </TD> +</TR> +<TR> + <TD COLSPAN=2> + Containing text + <& /elements/input-text.html, + field => 'message', + size => 30, + size => 30, + curr_value => ($cgi->param('message') || ''), + &> + <DIV STYLE="display:inline; float:right"> + <INPUT TYPE="submit" VALUE="Refresh"> + </DIV> + </TD> +</TR> +</TABLE> +</%def> +<%once> +my $date_sub = sub { time2str('%Y-%m-%d %T', $_[0]->_date) }; + +my $level_sub = sub { $FS::Log::LEVELS[$_[0]->level] }; + +my $context_sub = sub { + my $log = shift; + ($log->context)[-1] . (scalar($log->context) > 1 ? '...' : '') ; + # XXX find a way to make this use less space (dropdown?) +}; + +my $tt_sub = sub { + my $log = shift; + my @context = $log->context; + # don't create a tooltip if there's only one context entry and the + # message isn't cut off + return '' if @context == 1 and length($log->message) <= 60; + my $html = '<DIV CLASS="tooltip">'.(shift @context).'</DIV>'; + my $pre = '↳'; + foreach (@context, $log->message) { + $html .= "<DIV>$pre$_</DIV>"; + $pre = ' '.$pre; + } + $html; +}; + +my $object_sub = sub { + my $log = shift; + return '' unless $log->tablename; + # this is a sysadmin log; anyone reading it should be able to understand + # 'cust_main #2319' with no trouble. + $log->tablename . ' #' . $log->tablenum; +}; + +my $message_sub = sub { + my $log = shift; + my $message = $log->message; + if ( length($message) > 60 ) { # pretty arbitrary + $message = substr($message, 0, 57) . '...'; + } + $message; +}; + +my $object_link_sub = sub { + my $log = shift; + my $table = $log->tablename or return; + # sigh + if ( grep {$_ eq $table} (qw( cust_bill cust_main cust_pkg cust_svc )) + or $table =~ /^svc_/ ) + { + + return [ $fsurl.'view/'.$table.'.cgi?'. $log->tablenum ]; + + } elsif ( grep {$_ eq $table} (qw( cust_msg cust_pay cust_pay_void + cust_refund cust_statement )) ) + { + + return [ $fsurl.'view/'.$table.'.html?', $log->tablenum ]; + + } else { # you're on your own + + return ''; + + } +}; + +my @colors = ( + '404040', #debug + '0000aa', #info + '00aa00', #notice + 'aa0066', #warning + '000000', #error + 'aa0000', #critical + 'ff0000', #alert + 'ff0000', #emergency +); + +my $color_sub = sub { $colors[ $_[0]->level ]; }; + +my @contexts = ('', sort FS::log_context->contexts); +</%once> +<%init> +my $curuser = $FS::CurrentUser::CurrentUser; +die "access denied" + unless $curuser->access_right([ 'View system logs', 'Configuration' ]); + +$cgi->param('min_level', 0) unless defined($cgi->param('min_level')); +$cgi->param('max_level', 7) unless defined($cgi->param('max_level')); + +my %search = (); +$search{'date'} = [ FS::UI::Web::parse_beginning_ending($cgi) ]; +$search{'level'} = [ $cgi->param('min_level'), $cgi->param('max_level') ]; +foreach my $param (qw(agentnum context tablename tablenum custnum message)) { + if ( $cgi->param($param) ) { + $search{$param} = $cgi->param($param); + } +} +my $query = FS::log->search(\%search); # validates everything +my $count_query = delete $query->{'count_query'}; + +</%init> |