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