summaryrefslogtreecommitdiff
path: root/httemplate/search/log.html
blob: 9a61a71e1dcb97b84dda1e071524a26967ce34cf (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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
<& elements/search.html, 
  'title'         => 'System Log',
  'name_singular' => 'event',
  'menubar'       => \@menubar,
  '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  => scalar($cgi->param('beginning')),
    } &>
  </TD>
  <TD>To 
    <& /elements/input-date-field.html, {
      name   => 'ending',
      value  => scalar($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 => scalar($cgi->param('min_level')),
    &>
     to
    <& /elements/select.html,
      field      => 'max_level',
      options    => [ 0..7 ],
      labels     => { map {$_ => $FS::Log::LEVELS[$_]} 0..7 },
      curr_value => scalar($cgi->param('max_level')),
    &>
  </TD>
  <TD>
    Context
    <& /elements/select.html,
      field  => 'context',
      options => \@contexts,
      labels => { map {$_, $_} @contexts },
      curr_value => ($cgi->param('context') || ''),
    &>
    <BR><& /elements/checkbox.html,
      'field' => 'context_height',
      'postfix' => 'Only match most specific context',
      'value' => 1,
      'curr_value' => scalar($cgi->param('context_height')),
    &>
  </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 = '&#8627;';
  foreach (map encode_entities($_), @context, $log->message) {
    $html .= "<DIV>$pre$_</DIV>";
    $pre = '&nbsp;&nbsp;&nbsp;'.$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' ]);

my @menubar = ();
push @menubar, qq(<A HREF="${fsurl}browse/log_email.html" STYLE="text-decoration: underline;">Configure conditions for sending email when logging</A>),

$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 context_height 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>