improve handling of internal errors from US Census geocoding, #39549
[freeside.git] / httemplate / search / log.html
1 <& elements/search.html, 
2   'title'         => 'System Log',
3   'name_singular' => 'event',
4   'menubar'       => \@menubar,
5   'html_init'     => include('.head'),
6   'query'         => $query,
7   'count_query'   => $count_query,
8   'header'        => [ #'#', # lognum, probably not useful
9                        'Date',
10                        'Level',
11                        'Context',
12                        'Applies To',
13                        'Message',
14                      ],
15   'fields'        => [ #'lognum',
16                        $date_sub,
17                        $level_sub,
18                        $context_sub,
19                        $object_sub,
20                        $message_sub,
21                      ],
22   'sort_fields'   => [
23                        '_date',
24                        'level',
25                        '',
26                        'tablename,tablenum',
27                        'message',
28                      ],
29   'links'         => [
30                        '', #date
31                        '', #level
32                        '', #context
33                        $object_link_sub,
34                        '', #message
35                      ],
36   'tooltips'      => [
37                        '', #date
38                        '', #level
39                        $tt_sub,
40                        '', #object
41                        $tt_sub,
42                      ],
43   'color'         => [
44                        $color_sub,
45                        $color_sub,
46                        '',
47                        '',
48                        '',
49                      ],
50   # aligns
51   'download_label' => 'Download this log',
52 &>\
53 <%def .head>
54 <STYLE type="text/css">
55 a:link    {text-decoration: none}
56 a:visited {text-decoration: none}
57 .tooltip {
58   background-color: #ffffff;
59   font-size: 100%;
60   font-weight: bold;
61 }
62 </STYLE>
63 <FORM ACTION="<%$p%>search/log.html" METHOD="GET">
64 <TABLE CELLSPACING="10">
65 <TR>
66   <TD>From 
67     <& /elements/input-date-field.html, {
68       name => 'beginning',
69       value => $cgi->param('beginning'),
70     } &>
71   </TD>
72   <TD>To 
73     <& /elements/input-date-field.html, {
74       name => 'ending',
75       value => $cgi->param('ending') || '',
76       noinit => 1,
77     } &>
78   </TD>
79 </TR>
80 <TR>
81   <TD>Level
82     <& /elements/select.html,
83       field => 'min_level',
84       options => [ 0..7 ],
85       labels => { map {$_ => $FS::Log::LEVELS[$_]} 0..7 },
86       curr_value => $cgi->param('min_level'),
87     &>
88      to
89     <& /elements/select.html,
90       field => 'max_level',
91       options => [ 0..7 ],
92       labels => { map {$_ => $FS::Log::LEVELS[$_]} 0..7 },
93       curr_value => $cgi->param('max_level'),
94     &>
95   </TD>
96   <TD>
97     Context
98     <& /elements/select.html,
99       field  => 'context',
100       options => \@contexts,
101       labels => { map {$_, $_} @contexts },
102       curr_value => ($cgi->param('context') || ''),
103     &>
104   </TD>
105 </TR>
106 <TR>
107   <TD COLSPAN=2>
108     Containing text
109       <& /elements/input-text.html,
110         field => 'message',
111         size => 30,
112         size => 30,
113         curr_value => ($cgi->param('message') || ''),
114       &>
115     <DIV STYLE="display:inline; float:right">
116       <INPUT TYPE="submit" VALUE="Refresh">
117     </DIV>
118   </TD>
119 </TR>
120 </TABLE>
121 </%def>
122 <%once>
123 my $date_sub = sub { time2str('%Y-%m-%d %T', $_[0]->_date) };
124
125 my $level_sub = sub { $FS::Log::LEVELS[$_[0]->level] };
126
127 my $context_sub = sub {
128   my $log = shift;
129   ($log->context)[-1] . (scalar($log->context) > 1 ? '...' : '') ;
130   # XXX find a way to make this use less space (dropdown?)
131 };
132
133 my $tt_sub = sub {
134   my $log = shift;
135   my @context = $log->context;
136   # don't create a tooltip if there's only one context entry and the 
137   # message isn't cut off
138   return '' if @context == 1 and length($log->message) <= 60;
139   my $html = '<DIV CLASS="tooltip">'.(shift @context).'</DIV>';
140   my $pre = '&#8627;';
141   foreach (map encode_entities($_), @context, $log->message) {
142     $html .= "<DIV>$pre$_</DIV>";
143     $pre = '&nbsp;&nbsp;&nbsp;'.$pre;
144   }
145   $html;
146 };
147
148 my $object_sub = sub {
149   my $log = shift;
150   return '' unless $log->tablename;
151   # this is a sysadmin log; anyone reading it should be able to understand
152   # 'cust_main #2319' with no trouble.
153   $log->tablename . ' #' . $log->tablenum;
154 };
155
156 my $message_sub = sub {
157   my $log = shift;
158   my $message = $log->message;
159   if ( length($message) > 60 ) { # pretty arbitrary
160     $message = substr($message, 0, 57) . '...';
161   }
162   $message;
163 };
164
165 my $object_link_sub = sub {
166   my $log = shift;
167   my $table = $log->tablename or return;
168   # sigh
169   if ( grep {$_ eq $table} (qw( cust_bill cust_main cust_pkg cust_svc ))
170        or $table =~ /^svc_/ )
171   {
172
173     return [ $fsurl.'view/'.$table.'.cgi?'. $log->tablenum ];
174
175   } elsif ( grep {$_ eq $table} (qw( cust_msg cust_pay cust_pay_void 
176                                      cust_refund cust_statement )) )
177   {
178
179     return [ $fsurl.'view/'.$table.'.html?', $log->tablenum ];
180
181   } else { # you're on your own
182
183     return '';
184
185   }
186 };
187
188 my @colors = (
189   '404040', #debug
190   '0000aa', #info
191   '00aa00', #notice
192   'aa0066', #warning
193   '000000', #error
194   'aa0000', #critical
195   'ff0000', #alert
196   'ff0000', #emergency
197 );
198
199 my $color_sub = sub { $colors[ $_[0]->level ]; };
200
201 my @contexts = ('', sort FS::log_context->contexts);
202 </%once>
203 <%init>
204 my $curuser = $FS::CurrentUser::CurrentUser;
205 die "access denied"
206   unless $curuser->access_right([ 'View system logs', 'Configuration' ]);
207
208 my @menubar = ();
209 push @menubar, qq(<A HREF="${fsurl}browse/log_email.html" STYLE="text-decoration: underline;">Configure conditions for sending email when logging</A>),
210
211 $cgi->param('min_level', 0) unless defined($cgi->param('min_level'));
212 $cgi->param('max_level', 7) unless defined($cgi->param('max_level'));
213
214 my %search = ();
215 $search{'date'} = [ FS::UI::Web::parse_beginning_ending($cgi) ];
216 $search{'level'} = [ $cgi->param('min_level'), $cgi->param('max_level') ];
217 foreach my $param (qw(agentnum context tablename tablenum custnum message)) {
218   if ( $cgi->param($param) ) {
219     $search{$param} = $cgi->param($param);
220   }
221 }
222 my $query = FS::log->search(\%search); # validates everything
223 my $count_query = delete $query->{'count_query'};
224
225 </%init>