9be0b7d0a542343d437613ad125097b008c2cde2
[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  => scalar($cgi->param('beginning')),
70     } &>
71   </TD>
72   <TD>To 
73     <& /elements/input-date-field.html, {
74       name   => 'ending',
75       value  => scalar($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    => [ &FS::Log::levelnums ],
85       labels     => { &FS::Log::levelmap },
86       curr_value => scalar($cgi->param('min_level')),
87     &>
88      to
89     <& /elements/select.html,
90       field      => 'max_level',
91       options    => [ &FS::Log::levelnums ],
92       labels     => { &FS::Log::levelmap },
93       curr_value => scalar($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     <BR><& /elements/checkbox.html,
105       'field' => 'context_height',
106       'postfix' => 'Only match most specific context',
107       'value' => 1,
108       'curr_value' => scalar($cgi->param('context_height')),
109     &>
110   </TD>
111 </TR>
112 <TR>
113   <TD COLSPAN=2>
114     Containing text
115       <& /elements/input-text.html,
116         field => 'message',
117         size => 30,
118         size => 30,
119         curr_value => ($cgi->param('message') || ''),
120       &>
121     <DIV STYLE="display:inline; float:right">
122       <INPUT TYPE="submit" VALUE="Refresh">
123     </DIV>
124   </TD>
125 </TR>
126 </TABLE>
127 </%def>
128 <%once>
129 my $date_sub = sub { time2str('%Y-%m-%d %T', $_[0]->_date) };
130
131 my $level_sub = sub { $FS::Log::LEVELS{$_[0]->level} };
132
133 my $context_sub = sub {
134   my $log = shift;
135   ($log->context)[-1] . (scalar($log->context) > 1 ? '...' : '') ;
136   # XXX find a way to make this use less space (dropdown?)
137 };
138
139 my $tt_sub = sub {
140   my $log = shift;
141   my @context = $log->context;
142   # don't create a tooltip if there's only one context entry and the 
143   # message isn't cut off
144   return '' if @context == 1 and length($log->message) <= 60;
145   my $html = '<DIV CLASS="tooltip">'.(shift @context).'</DIV>';
146   my $pre = '&#8627;';
147   foreach (map encode_entities($_), @context, $log->message) {
148     $html .= "<DIV>$pre$_</DIV>";
149     $pre = '&nbsp;&nbsp;&nbsp;'.$pre;
150   }
151   $html;
152 };
153
154 my $object_sub = sub {
155   my $log = shift;
156   return '' unless $log->tablename;
157   # this is a sysadmin log; anyone reading it should be able to understand
158   # 'cust_main #2319' with no trouble.
159   $log->tablename . ' #' . $log->tablenum;
160 };
161
162 my $message_sub = sub {
163   my $log = shift;
164   my $message = $log->message;
165   if ( length($message) > 60 ) { # pretty arbitrary
166     $message = substr($message, 0, 57) . '...';
167   }
168   $message;
169 };
170
171 my $object_link_sub = sub {
172   my $log = shift;
173   my $table = $log->tablename or return;
174   # sigh
175   if ( grep {$_ eq $table} (qw( cust_bill cust_main cust_pkg cust_svc ))
176        or $table =~ /^svc_/ )
177   {
178
179     return [ $fsurl.'view/'.$table.'.cgi?'. $log->tablenum ];
180
181   } elsif ( grep {$_ eq $table} (qw( cust_msg cust_pay cust_pay_void 
182                                      cust_refund cust_statement )) )
183   {
184
185     return [ $fsurl.'view/'.$table.'.html?', $log->tablenum ];
186
187   } else { # you're on your own
188
189     return '';
190
191   }
192 };
193
194 my %colors = (
195   0 => '404040', #debug, gray
196   1 => '000000', #info, black
197   3 => '0000aa', #warning, blue
198   4 => 'aa0066', #error, purple
199   5 => 'ff0000', #critical, red
200 );
201
202 my $color_sub = sub { $colors{ $_[0]->level }; };
203
204 my @contexts = ('', FS::log_context->contexts);
205 </%once>
206 <%init>
207 my $curuser = $FS::CurrentUser::CurrentUser;
208 die "access denied"
209   unless $curuser->access_right([ 'View system logs', 'Configuration' ]);
210
211 my @menubar = ();
212 push @menubar, qq(<A HREF="${fsurl}browse/log_email.html" STYLE="text-decoration: underline;">Configure conditions for sending email when logging</A>);
213
214 $cgi->param('min_level', 0) unless defined($cgi->param('min_level'));
215 $cgi->param('max_level', 5) unless defined($cgi->param('max_level'));
216
217 my %search = ();
218 $search{'date'} = [ FS::UI::Web::parse_beginning_ending($cgi) ];
219 $search{'level'} = [ $cgi->param('min_level'), $cgi->param('max_level') ];
220 foreach my $param (qw(agentnum context context_height tablename tablenum custnum message)) {
221   if ( $cgi->param($param) ) {
222     $search{$param} = $cgi->param($param);
223   }
224 }
225 my $query = FS::log->search(\%search); # validates everything
226 my $count_query = delete $query->{'count_query'};
227
228 </%init>