1 | <?php |
---|
2 | /***************************************************************************\ |
---|
3 | * eGroupWare - uilog * |
---|
4 | * http://www.egroupware.org * |
---|
5 | * Written by : jerry westrick [jerry@westrick.com] * |
---|
6 | * ------------------------------------------------- * |
---|
7 | * This program is free software; you can redistribute it and/or modify it * |
---|
8 | * under the terms of the GNU General Public License as published by the * |
---|
9 | * Free Software Foundation; either version 2 of the License, or (at your * |
---|
10 | * option) any later version. * |
---|
11 | \***************************************************************************/ |
---|
12 | |
---|
13 | |
---|
14 | class uilog |
---|
15 | { |
---|
16 | var $grants; |
---|
17 | var $cat_id; |
---|
18 | var $start; |
---|
19 | var $search; |
---|
20 | var $filter; |
---|
21 | |
---|
22 | var $public_functions = array( |
---|
23 | 'list_log' => True |
---|
24 | ); |
---|
25 | |
---|
26 | function uilog() |
---|
27 | { |
---|
28 | if ($GLOBALS['phpgw']->acl->check('error_log_access',1,'admin')) |
---|
29 | { |
---|
30 | $GLOBALS['phpgw']->redirect_link('/index.php'); |
---|
31 | } |
---|
32 | |
---|
33 | $_cols = $_POST['_cols']; |
---|
34 | $nocols = $_POST['nocols']; |
---|
35 | $_delcol = $_POST['_delcol']; |
---|
36 | $layout = $_POST['layout']; |
---|
37 | $editable = $_GET['editable']; |
---|
38 | $modifytable = $_GET['modifytable'] ? $_GET['modifytable'] : $_POST['modifytable']; |
---|
39 | |
---|
40 | $this->bolog = CreateObject('admin.bolog',True); |
---|
41 | $this->html = createobject('admin.html_tables'); |
---|
42 | $this->t = CreateObject('phpgwapi.Template',$GLOBALS['phpgw']->common->get_tpl_dir('admin')); |
---|
43 | $this->lastid = ''; |
---|
44 | $this->editmode = False; |
---|
45 | |
---|
46 | // Handle the Edit Table Button |
---|
47 | if (isset($editable)) |
---|
48 | { |
---|
49 | $this->editmode = $editable; |
---|
50 | } |
---|
51 | |
---|
52 | // Handle return from Modify Table form... |
---|
53 | if ($modifytable) |
---|
54 | { |
---|
55 | // the delete column must not be empty |
---|
56 | if (!isset($_delcol)) |
---|
57 | { |
---|
58 | $_delcol = array(); |
---|
59 | } |
---|
60 | |
---|
61 | // Build New fields_inc array... |
---|
62 | if (isset($_cols)) |
---|
63 | { |
---|
64 | $c = array(); |
---|
65 | $cols_count = count($_cols); |
---|
66 | for ($i=0;$i<$cols_count;++$i) |
---|
67 | { |
---|
68 | if (!in_array($i, $_delcol)) |
---|
69 | { |
---|
70 | $c[] = $_cols[$i]; |
---|
71 | } |
---|
72 | } |
---|
73 | $this->fields_inc = $c; |
---|
74 | } |
---|
75 | |
---|
76 | // Reset Mode to display... |
---|
77 | $this->editmode = False; |
---|
78 | $this->layout = $layout; |
---|
79 | |
---|
80 | // Save the fields_inc values in Session and User Preferences... |
---|
81 | $data = array('fields_inc'=>$this->fields_inc,'layout'=>$layout); |
---|
82 | $GLOBALS['phpgw']->session->appsession('session_data','log',$data); |
---|
83 | $GLOBALS['phpgw']->preferences->read_repository(); |
---|
84 | $GLOBALS['phpgw']->preferences->delete('log','fields_inc'); |
---|
85 | $GLOBALS['phpgw']->preferences->add('log','fields_inc',$this->fields_inc); |
---|
86 | $GLOBALS['phpgw']->preferences->delete('log','layout'); |
---|
87 | $GLOBALS['phpgw']->preferences->add('log','layout',$this->layout); |
---|
88 | $GLOBALS['phpgw']->preferences->save_repository(); |
---|
89 | } |
---|
90 | |
---|
91 | // Make sure that $this->fields_inc is filled |
---|
92 | if ( !isset($this->field_inc)) |
---|
93 | { |
---|
94 | // Need to fill from Session Data... |
---|
95 | $data = $GLOBALS['phpgw']->session->appsession('session_data','log'); |
---|
96 | if (isset($data) && isset($data['fields_inc'])) |
---|
97 | { |
---|
98 | $this->fields_inc = $data['fields_inc']; |
---|
99 | $this->layout = $data['layout']; |
---|
100 | } |
---|
101 | else |
---|
102 | { |
---|
103 | $GLOBALS['phpgw']->preferences->read_repository(); |
---|
104 | // Get From User Profile... |
---|
105 | if (@$GLOBALS['phpgw_info']['user']['preferences']['log']['fields_inc']) |
---|
106 | { |
---|
107 | $fields_inc = $GLOBALS['phpgw_info']['user']['preferences']['log']['fields_inc']; |
---|
108 | $this->fields_inc = $fields_inc; |
---|
109 | $layout = $GLOBALS['phpgw_info']['user']['preferences']['log']['layout']; |
---|
110 | $this->layout = $layout; |
---|
111 | $GLOBALS['phpgw']->session->appsession('session_data','log',array('fields_inc'=>$fields_inc,'layout'=>$layout)); |
---|
112 | } |
---|
113 | else |
---|
114 | { |
---|
115 | // Use defaults... |
---|
116 | $this->fields_inc = array( |
---|
117 | 'log_severity', |
---|
118 | 'log_id', |
---|
119 | 'log_date_e', |
---|
120 | 'log_app', |
---|
121 | 'log_full_name', |
---|
122 | 'log_msg_seq_no', |
---|
123 | 'log_msg_date_e', |
---|
124 | 'log_msg_severity', |
---|
125 | 'log_msg_code', |
---|
126 | 'log_msg_text', |
---|
127 | 'log_msg_file', |
---|
128 | 'log_msg_line' |
---|
129 | ); |
---|
130 | $this->layout[]= array(0,1,2,3,4,5,6,7,8,9); |
---|
131 | $this->layout[]= array(0,1,2,3,4,5,6,7,10,11); |
---|
132 | |
---|
133 | // Store defaults in session data... |
---|
134 | $GLOBALS['phpgw']->session->appsession( |
---|
135 | 'session_data', |
---|
136 | 'log', |
---|
137 | array( |
---|
138 | 'fields_inc'=>$this->fields_inc, |
---|
139 | 'layout'=>$this->layout |
---|
140 | ) |
---|
141 | ); |
---|
142 | } |
---|
143 | } |
---|
144 | |
---|
145 | } // Values already filled... |
---|
146 | reset($this->fields_inc); |
---|
147 | while(list($cno,$cname)=each($this->fields_inc)) |
---|
148 | { |
---|
149 | $this->column[$cname]=$cno; |
---|
150 | } |
---|
151 | } |
---|
152 | |
---|
153 | function list_log() |
---|
154 | { |
---|
155 | if (False) // add some errors to the log... |
---|
156 | { |
---|
157 | // Test 1: single Error line immedeately to errorlog |
---|
158 | // (could be type Debug, Info, Warning, or Error) |
---|
159 | $GLOBALS['phpgw']->log->write(array('text'=>'I-TestWrite, write: %1','p1'=>'This message should appear in log','file'=>__FILE__,'line'=>__LINE__)); |
---|
160 | |
---|
161 | // Test 2: A message should appear in log even if clearstack is called |
---|
162 | $GLOBALS['phpgw']->log->message(array('text'=>'I-TestMsg, msg: %1','p1'=>'This message should appear in log','file'=>__FILE__,'line'=>__LINE__)); |
---|
163 | $GLOBALS['phpgw']->log->error(array('text'=>'I-TestInfo, info: %1','p1'=>'This Informational should not be in log','file'=>__FILE__,'line'=>__LINE__)); |
---|
164 | $GLOBALS['phpgw']->log->clearstack(); |
---|
165 | $GLOBALS['phpgw']->log->commit(); // commit error stack to log... |
---|
166 | |
---|
167 | // Test 3: one debug message |
---|
168 | $GLOBALS['phpgw']->log->error(array('text'=>'D-Debug, dbg: %1','p1'=>'This debug statment should be in log','file'=>__FILE__,'line'=>__LINE__)); |
---|
169 | $GLOBALS['phpgw']->log->commit(); // commit error stack to log... |
---|
170 | |
---|
171 | // Test 3: debug and one informational |
---|
172 | $GLOBALS['phpgw']->log->error(array('text'=>'D-Debug, dbg: %1','p1'=>'This debug statment should be in log','file'=>__FILE__,'line'=>__LINE__)); |
---|
173 | $GLOBALS['phpgw']->log->error(array('text'=>'I-TestInfo, info: %1','p1'=>'This Informational should be in log','file'=>__FILE__,'line'=>__LINE__)); |
---|
174 | $GLOBALS['phpgw']->log->commit(); // commit error stack to log... |
---|
175 | |
---|
176 | // Test 4: an informational and a Warning |
---|
177 | $GLOBALS['phpgw']->log->error(array('text'=>'D-Debug, dbg: %1','p1'=>'This debug statment should be in log','file'=>__FILE__,'line'=>__LINE__)); |
---|
178 | $GLOBALS['phpgw']->log->error(array('text'=>'I-TestInfo, info: %1','p1'=>'This Informational should be in log','file'=>__FILE__,'line'=>__LINE__)); |
---|
179 | $GLOBALS['phpgw']->log->error(array('text'=>'W-TestWarn, warn: %1','p1'=>'This is a test Warning','file'=>__FILE__,'line'=>__LINE__)); |
---|
180 | $GLOBALS['phpgw']->log->commit(); // commit error stack to log... |
---|
181 | |
---|
182 | // Test 5: and an error |
---|
183 | $GLOBALS['phpgw']->log->error(array('text'=>'D-Debug, dbg: %1','p1'=>'This debug statment should be in log','file'=>__FILE__,'line'=>__LINE__)); |
---|
184 | $GLOBALS['phpgw']->log->error(array('text'=>'I-TestInfo, info: %1','p1'=>'This Informational should be in log','file'=>__FILE__,'line'=>__LINE__)); |
---|
185 | $GLOBALS['phpgw']->log->error(array('text'=>'W-TestWarn, warn: %1','p1'=>'This is a test Warning','file'=>__FILE__,'line'=>__LINE__)); |
---|
186 | $GLOBALS['phpgw']->log->error(array('text'=>'E-TestError, err: %1','p1'=>'This is a test Error','file'=>__FILE__,'line'=>__LINE__)); |
---|
187 | $GLOBALS['phpgw']->log->commit(); // commit error stack to log... |
---|
188 | |
---|
189 | // Test 6: and finally a fatal... |
---|
190 | $GLOBALS['phpgw']->log->error(array('text'=>'D-Debug, dbg: %1','p1'=>'This debug statment should be in log','file'=>__FILE__,'line'=>__LINE__)); |
---|
191 | $GLOBALS['phpgw']->log->error(array('text'=>'I-TestInfo, info: %1','p1'=>'This Informational should be in log','file'=>__FILE__,'line'=>__LINE__)); |
---|
192 | $GLOBALS['phpgw']->log->error(array('text'=>'W-TestWarn, warn: %1','p1'=>'This is a test Warning','file'=>__FILE__,'line'=>__LINE__)); |
---|
193 | $GLOBALS['phpgw']->log->error(array('text'=>'E-TestError, err: %1','p1'=>'This is a test Error','file'=>__FILE__,'line'=>__LINE__)); |
---|
194 | $GLOBALS['phpgw']->log->error(array('text'=>'F-Abend, abort: %1','p1'=>'Force abnormal termination','file'=>__FILE__,'line'=>__LINE__)); |
---|
195 | } |
---|
196 | $this->t->set_file(array('log_list_t' => 'log.tpl')); |
---|
197 | |
---|
198 | // -------------------------- Layout Description ------------------------------- |
---|
199 | $phycols = array('2%', '2%', '15%', '10%', '15%', '2%', '20%', '2%', '7%', '25%'); |
---|
200 | // -------------------------- end Layout Description --------------------------- |
---|
201 | |
---|
202 | // Get list of Possible Columns |
---|
203 | $header = $this->bolog->get_error_cols_e(); |
---|
204 | |
---|
205 | // Describe table layout... |
---|
206 | $header['#phycols'] = $phycols; |
---|
207 | $header['#layout'] = $this->layout; |
---|
208 | |
---|
209 | // Set User Configured List of columns to show |
---|
210 | $header['_cols']= $this->fields_inc; |
---|
211 | |
---|
212 | // Set Table formating parameters |
---|
213 | $header['#table_parms']=array('width'=>"98%", 'bgcolor'=>"#000000", 'border'=>"0"); |
---|
214 | |
---|
215 | // Set Header formating parameters |
---|
216 | $header['#head_parms']=array('bgcolor'=>"#D3DCFF"); |
---|
217 | |
---|
218 | // Column Log_ID |
---|
219 | $header['log_id']['#parms_hdr'] = array('align'=>"center"); |
---|
220 | $header['log_id']['#title'] = 'Id'; |
---|
221 | $header['log_id']['align'] = 'center'; |
---|
222 | |
---|
223 | // Column Log_Severity |
---|
224 | $header['log_severity']['#parms_hdr'] = array('align'=>"center"); |
---|
225 | $header['log_severity']['#title'] = 'S'; |
---|
226 | $header['log_severity']['align'] = 'center'; |
---|
227 | |
---|
228 | // Column Trans Date |
---|
229 | $header['log_date_e']['#title'] = 'Tans. Date'; |
---|
230 | |
---|
231 | // Column Application |
---|
232 | $header['log_app']['#title'] = 'App.'; |
---|
233 | |
---|
234 | // Column FullName |
---|
235 | $header['log_full_name']['#title'] = 'User'; |
---|
236 | $header['log_full_name']['align'] = 'center'; |
---|
237 | |
---|
238 | // Column log_msg_seq_no |
---|
239 | $header['log_msg_seq_no']['#parms_hdr'] = array('align'=>"center"); |
---|
240 | $header['log_msg_seq_no']['#title'] = 'Sno'; |
---|
241 | $header['log_msg_seq_no']['align'] = 'center'; |
---|
242 | |
---|
243 | // Column log_msg_seq_no |
---|
244 | $header['log_msg_date_e']['#title'] = 'TimeStamp'; |
---|
245 | $header['log_msg_severity']['#title'] = 'S'; |
---|
246 | $header['log_msg_severity']['align'] = 'center'; |
---|
247 | $header['log_msg_code']['#title'] = 'Code'; |
---|
248 | $header['log_msg_text']['#title'] = 'Error Msg'; |
---|
249 | $header['log_msg_file']['#title'] = 'File'; |
---|
250 | $header['log_msg_line']['#title'] = 'Line'; |
---|
251 | |
---|
252 | // Set up Grouping, Suppression... |
---|
253 | $header['_groupby']=array('log_id'=>1); |
---|
254 | $header['_supres']=array('log_id'=>1,'log_severity'=>1,'log_date_e'=>1,'log_app'=>1,'log_full_name'=>1); |
---|
255 | |
---|
256 | // Hack Get All Rows |
---|
257 | $rows = $this->bolog->get_error_e(array('orderby'=>array('log_id','log_msg_log_id'))); |
---|
258 | $norows = count($rows); |
---|
259 | $header['_edittable']=$this->editmode; |
---|
260 | $table = $this->html->hash_table($rows,$header,$this, 'format_row'); |
---|
261 | $this->t->set_var('event_list',$table); |
---|
262 | |
---|
263 | $GLOBALS['phpgw_info']['flags']['app_header'] = lang('Admin').' - '.($this->editmode?lang('Edit Table format') : lang('View error log')); |
---|
264 | if(!@is_object($GLOBALS['phpgw']->js)) |
---|
265 | { |
---|
266 | $GLOBALS['phpgw']->js = CreateObject('phpgwapi.javascript'); |
---|
267 | } |
---|
268 | $GLOBALS['phpgw']->js->validate_file('jscode','openwindow','admin'); |
---|
269 | $GLOBALS['phpgw']->common->phpgw_header(); |
---|
270 | echo parse_navbar(); |
---|
271 | $this->t->pfp('out','log_list_t'); |
---|
272 | // $this->set_app_langs(); |
---|
273 | } |
---|
274 | |
---|
275 | function format_row($rno, $row) |
---|
276 | { |
---|
277 | switch($row['log_severity']['value']) |
---|
278 | { |
---|
279 | case 'D': $row['log_severity']['bgcolor'] = '#D3DCFF'; break; |
---|
280 | case 'I': $row['log_severity']['bgcolor'] = '#C0FFC0'; break; |
---|
281 | case 'W': $row['log_severity']['bgcolor'] = '#FFFFC0'; break; |
---|
282 | case 'E': $row['log_severity']['bgcolor'] = '#FFC0C0'; break; |
---|
283 | case 'F': $row['log_severity']['bgcolor'] = '#FF0909'; break; |
---|
284 | } |
---|
285 | |
---|
286 | switch($row['log_msg_severity']['value']) |
---|
287 | { |
---|
288 | case 'D': $color = '#D3DCFF'; break; |
---|
289 | case 'I': $color = '#C0FFC0'; break; |
---|
290 | case 'W': $color = '#FFFFC0'; break; |
---|
291 | case 'E': $color = '#FFC0C0'; break; |
---|
292 | case 'F': $color = '#FF0909'; break; |
---|
293 | } |
---|
294 | reset($this->fields_inc); |
---|
295 | while(list($cno,$fld) = each($this->fields_inc)) |
---|
296 | { |
---|
297 | if (substr($fld,0,7) == 'log_msg') |
---|
298 | { |
---|
299 | $row[$fld]['bgcolor'] = $color; |
---|
300 | } |
---|
301 | else |
---|
302 | { |
---|
303 | // $row[$cno]['bgcolor'] = $lcolor; |
---|
304 | } |
---|
305 | } |
---|
306 | return $row; |
---|
307 | } |
---|
308 | } |
---|
309 | ?> |
---|