2001-08-05 08:48:42 +02:00
< ? php
/*************************************************************************** \
* phpGroupWare - uilog *
* http :// www . phpgroupware . org *
* Written by : jerry westrick [ jerry @ westrick . com ] *
* ------------------------------------------------- *
* This program is free software ; you can redistribute it and / or modify it *
* under the terms of the GNU General Public License as published by the *
* Free Software Foundation ; either version 2 of the License , or ( at your *
* option ) any later version . *
\ ***************************************************************************/
2002-01-04 01:55:01 +01:00
2001-08-05 08:48:42 +02:00
/* $Id$ */
class uilog
{
var $grants ;
var $cat_id ;
var $start ;
var $search ;
var $filter ;
2001-09-26 03:02:39 +02:00
var $public_functions = array (
'list_log' => True
2001-08-05 08:48:42 +02:00
);
function uilog ()
{
2001-09-26 03:02:39 +02:00
$_cols = $GLOBALS [ 'HTTP_POST_VARS' ][ '_cols' ];
$nocols = $GLOBALS [ 'HTTP_POST_VARS' ][ 'nocols' ];
$_delcol = $GLOBALS [ 'HTTP_POST_VARS' ][ '_delcol' ];
$layout = $GLOBALS [ 'HTTP_POST_VARS' ][ 'layout' ];
$editable = $GLOBALS [ 'HTTP_GET_VARS' ][ 'editable' ];
$modifytable = $GLOBALS [ 'HTTP_GET_VARS' ][ 'modifytable' ] ? $GLOBALS [ 'HTTP_GET_VARS' ][ 'modifytable' ] : $GLOBALS [ 'HTTP_POST_VARS' ][ 'modifytable' ];
2001-08-05 08:48:42 +02:00
2002-01-04 01:55:01 +01:00
$this -> bolog = CreateObject ( 'admin.bolog' , True );
$this -> html = createobject ( 'admin.html' );
$this -> t = CreateObject ( 'phpgwapi.Template' , $GLOBALS [ 'phpgw' ] -> common -> get_tpl_dir ( 'admin' ));
$this -> lastid = '' ;
$this -> editmode = False ;
2001-08-05 08:48:42 +02:00
// Handle the Edit Table Button
2001-09-26 03:02:39 +02:00
if ( isset ( $editable ))
2001-08-05 08:48:42 +02:00
{
$this -> editmode = $editable ;
2001-09-26 03:02:39 +02:00
}
2001-08-05 08:48:42 +02:00
// Handle return from Modify Table form...
2001-09-26 03:02:39 +02:00
if ( $modifytable )
{
2001-08-05 08:48:42 +02:00
// the delete column must not be empty
if ( ! isset ( $_delcol ))
{
$_delcol = array ();
2001-09-26 03:02:39 +02:00
}
2001-08-05 08:48:42 +02:00
// Build New fields_inc array...
if ( isset ( $_cols ))
{
$c = array ();
2001-08-12 03:06:07 +02:00
for ( $i = 0 ; $i < count ( $_cols ); $i ++ )
2001-08-05 08:48:42 +02:00
{
if ( ! in_array ( $i , $_delcol ))
{
$c [] = $_cols [ $i ];
2001-09-26 03:02:39 +02:00
}
2001-08-05 08:48:42 +02:00
}
$this -> fields_inc = $c ;
2001-09-26 03:02:39 +02:00
}
2001-08-05 08:48:42 +02:00
// Reset Mode to display...
2002-01-04 01:55:01 +01:00
$this -> editmode = False ;
2001-08-12 03:06:07 +02:00
$this -> layout = $layout ;
2001-09-26 03:02:39 +02:00
2001-08-05 08:48:42 +02:00
// Save the fields_inc values in Session and User Preferences...
2001-08-12 03:06:07 +02:00
$data = array ( 'fields_inc' => $this -> fields_inc , 'layout' => $layout );
2001-09-26 03:02:39 +02:00
$GLOBALS [ 'phpgw' ] -> session -> appsession ( 'session_data' , 'log' , $data );
$GLOBALS [ 'phpgw' ] -> preferences -> read_repository ();
$GLOBALS [ 'phpgw' ] -> preferences -> delete ( 'log' , 'fields_inc' );
$GLOBALS [ 'phpgw' ] -> preferences -> add ( 'log' , 'fields_inc' , $this -> fields_inc );
$GLOBALS [ 'phpgw' ] -> preferences -> delete ( 'log' , 'layout' );
$GLOBALS [ 'phpgw' ] -> preferences -> add ( 'log' , 'layout' , $this -> layout );
$GLOBALS [ 'phpgw' ] -> preferences -> save_repository ();
2001-08-05 08:48:42 +02:00
}
// Make sure that $this->fields_inc is filled
if ( ! isset ( $this -> field_inc ))
2001-09-26 03:02:39 +02:00
{
2001-08-05 08:48:42 +02:00
// Need to fill from Session Data...
2001-09-26 03:02:39 +02:00
$data = $GLOBALS [ 'phpgw' ] -> session -> appsession ( 'session_data' , 'log' );
2001-08-05 08:48:42 +02:00
if ( isset ( $data ) && isset ( $data [ 'fields_inc' ]))
{
$this -> fields_inc = $data [ 'fields_inc' ];
2001-08-12 03:06:07 +02:00
$this -> layout = $data [ 'layout' ];
2001-08-05 08:48:42 +02:00
}
else
{
2001-09-26 03:02:39 +02:00
$GLOBALS [ 'phpgw' ] -> preferences -> read_repository ();
2001-08-05 08:48:42 +02:00
// Get From User Profile...
2001-09-26 03:02:39 +02:00
if ( @ $GLOBALS [ 'phpgw_info' ][ 'user' ][ 'preferences' ][ 'log' ][ 'fields_inc' ])
2001-08-05 08:48:42 +02:00
{
2001-09-26 03:02:39 +02:00
$fields_inc = $GLOBALS [ 'phpgw_info' ][ 'user' ][ 'preferences' ][ 'log' ][ 'fields_inc' ];
2001-08-05 08:48:42 +02:00
$this -> fields_inc = $fields_inc ;
2001-09-26 03:02:39 +02:00
$layout = $GLOBALS [ 'phpgw_info' ][ 'user' ][ 'preferences' ][ 'log' ][ 'layout' ];
2001-08-12 03:06:07 +02:00
$this -> layout = $layout ;
2001-09-26 03:02:39 +02:00
$GLOBALS [ 'phpgw' ] -> session -> appsession ( 'session_data' , 'log' , array ( 'fields_inc' => $fields_inc , 'layout' => $layout ));
2001-08-05 08:48:42 +02:00
}
else
{
// Use defaults...
2001-09-26 03:02:39 +02:00
$this -> fields_inc = array (
'log_severity' ,
'log_id' ,
'log_date_e' ,
'log_app' ,
'log_full_name' ,
'log_msg_seq_no' ,
'log_msg_date_e' ,
'log_msg_severity' ,
'log_msg_code' ,
'log_msg_text' ,
'log_msg_file' ,
'log_msg_line'
);
$this -> layout [] = array ( 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 );
$this -> layout [] = array ( 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 10 , 11 );
2001-08-05 08:48:42 +02:00
2001-09-26 03:02:39 +02:00
// Store defaults in session data...
$GLOBALS [ 'phpgw' ] -> session -> appsession (
'session_data' ,
'log' ,
array (
'fields_inc' => $this -> fields_inc ,
'layout' => $this -> layout
)
);
2001-08-05 08:48:42 +02:00
}
}
} // Values already filled...
2001-08-06 18:51:44 +02:00
reset ( $this -> fields_inc );
while ( list ( $cno , $cname ) = each ( $this -> fields_inc ))
{
$this -> column [ $cname ] = $cno ;
2001-09-26 03:02:39 +02:00
}
}
2001-08-05 08:48:42 +02:00
function list_log ()
{
2002-01-04 01:55:01 +01:00
if ( False ) // add some errors to the log...
2001-08-08 09:21:29 +02:00
{
// Test 1: single Error line immedeately to errorlog
// (could be type Debug, Info, Warning, or Error)
2001-09-26 03:02:39 +02:00
$GLOBALS [ 'phpgw' ] -> log -> write ( array ( 'text' => 'I-TestWrite, write: %1' , 'p1' => 'This message should appear in log' , 'file' => __FILE__ , 'line' => __LINE__ ));
2001-08-08 09:21:29 +02:00
// Test 2: A message should appear in log even if clearstack is called
2001-09-26 03:02:39 +02:00
$GLOBALS [ 'phpgw' ] -> log -> message ( array ( 'text' => 'I-TestMsg, msg: %1' , 'p1' => 'This message should appear in log' , 'file' => __FILE__ , 'line' => __LINE__ ));
$GLOBALS [ 'phpgw' ] -> log -> error ( array ( 'text' => 'I-TestInfo, info: %1' , 'p1' => 'This Informational should not be in log' , 'file' => __FILE__ , 'line' => __LINE__ ));
$GLOBALS [ 'phpgw' ] -> log -> clearstack ();
$GLOBALS [ 'phpgw' ] -> log -> commit (); // commit error stack to log...
2001-08-08 09:21:29 +02:00
// Test 3: one debug message
2001-09-26 03:02:39 +02:00
$GLOBALS [ 'phpgw' ] -> log -> error ( array ( 'text' => 'D-Debug, dbg: %1' , 'p1' => 'This debug statment should be in log' , 'file' => __FILE__ , 'line' => __LINE__ ));
$GLOBALS [ 'phpgw' ] -> log -> commit (); // commit error stack to log...
2001-08-08 09:21:29 +02:00
// Test 3: debug and one informational
2001-09-26 03:02:39 +02:00
$GLOBALS [ 'phpgw' ] -> log -> error ( array ( 'text' => 'D-Debug, dbg: %1' , 'p1' => 'This debug statment should be in log' , 'file' => __FILE__ , 'line' => __LINE__ ));
$GLOBALS [ 'phpgw' ] -> log -> error ( array ( 'text' => 'I-TestInfo, info: %1' , 'p1' => 'This Informational should be in log' , 'file' => __FILE__ , 'line' => __LINE__ ));
$GLOBALS [ 'phpgw' ] -> log -> commit (); // commit error stack to log...
2001-08-08 09:21:29 +02:00
// Test 4: an informational and a Warning
2001-09-26 03:02:39 +02:00
$GLOBALS [ 'phpgw' ] -> log -> error ( array ( 'text' => 'D-Debug, dbg: %1' , 'p1' => 'This debug statment should be in log' , 'file' => __FILE__ , 'line' => __LINE__ ));
$GLOBALS [ 'phpgw' ] -> log -> error ( array ( 'text' => 'I-TestInfo, info: %1' , 'p1' => 'This Informational should be in log' , 'file' => __FILE__ , 'line' => __LINE__ ));
$GLOBALS [ 'phpgw' ] -> log -> error ( array ( 'text' => 'W-TestWarn, warn: %1' , 'p1' => 'This is a test Warning' , 'file' => __FILE__ , 'line' => __LINE__ ));
$GLOBALS [ 'phpgw' ] -> log -> commit (); // commit error stack to log...
2001-08-08 09:21:29 +02:00
// Test 5: and an error
2001-09-26 03:02:39 +02:00
$GLOBALS [ 'phpgw' ] -> log -> error ( array ( 'text' => 'D-Debug, dbg: %1' , 'p1' => 'This debug statment should be in log' , 'file' => __FILE__ , 'line' => __LINE__ ));
$GLOBALS [ 'phpgw' ] -> log -> error ( array ( 'text' => 'I-TestInfo, info: %1' , 'p1' => 'This Informational should be in log' , 'file' => __FILE__ , 'line' => __LINE__ ));
$GLOBALS [ 'phpgw' ] -> log -> error ( array ( 'text' => 'W-TestWarn, warn: %1' , 'p1' => 'This is a test Warning' , 'file' => __FILE__ , 'line' => __LINE__ ));
$GLOBALS [ 'phpgw' ] -> log -> error ( array ( 'text' => 'E-TestError, err: %1' , 'p1' => 'This is a test Error' , 'file' => __FILE__ , 'line' => __LINE__ ));
$GLOBALS [ 'phpgw' ] -> log -> commit (); // commit error stack to log...
2001-08-08 09:21:29 +02:00
// Test 6: and finally a fatal...
2001-09-26 03:02:39 +02:00
$GLOBALS [ 'phpgw' ] -> log -> error ( array ( 'text' => 'D-Debug, dbg: %1' , 'p1' => 'This debug statment should be in log' , 'file' => __FILE__ , 'line' => __LINE__ ));
$GLOBALS [ 'phpgw' ] -> log -> error ( array ( 'text' => 'I-TestInfo, info: %1' , 'p1' => 'This Informational should be in log' , 'file' => __FILE__ , 'line' => __LINE__ ));
$GLOBALS [ 'phpgw' ] -> log -> error ( array ( 'text' => 'W-TestWarn, warn: %1' , 'p1' => 'This is a test Warning' , 'file' => __FILE__ , 'line' => __LINE__ ));
$GLOBALS [ 'phpgw' ] -> log -> error ( array ( 'text' => 'E-TestError, err: %1' , 'p1' => 'This is a test Error' , 'file' => __FILE__ , 'line' => __LINE__ ));
$GLOBALS [ 'phpgw' ] -> log -> error ( array ( 'text' => 'F-Abend, abort: %1' , 'p1' => 'Force abnormal termination' , 'file' => __FILE__ , 'line' => __LINE__ ));
}
2001-08-05 08:48:42 +02:00
$this -> t -> set_file ( array ( 'log_list_t' => 'log.tpl' ));
2001-08-06 18:51:44 +02:00
2001-09-26 03:02:39 +02:00
// -------------------------- Layout Description -------------------------------
$phycols = array ( '2%' , '2%' , '15%' , '10%' , '15%' , '2%' , '20%' , '2%' , '7%' , '25%' );
// -------------------------- end Layout Description ---------------------------
2001-08-05 08:48:42 +02:00
// Get list of Possible Columns
$header = $this -> bolog -> get_error_cols_e ();
2001-08-12 03:06:07 +02:00
// Describe table layout...
$header [ '#phycols' ] = $phycols ;
$header [ '#layout' ] = $this -> layout ;
2001-09-26 03:02:39 +02:00
2001-08-05 08:48:42 +02:00
// Set User Configured List of columns to show
$header [ '_cols' ] = $this -> fields_inc ;
2001-08-12 03:06:07 +02:00
// Set Table formating parameters
$header [ '#table_parms' ] = array ( 'width' => " 98% " , 'bgcolor' => " 000000 " , 'border' => " 0 " );
// Set Header formating parameters
$header [ '#head_parms' ] = array ( 'bgcolor' => " D3DCFF " );
2001-08-05 08:48:42 +02:00
// Column Log_ID
2001-08-12 03:06:07 +02:00
$header [ 'log_id' ][ '#parms_hdr' ] = array ( 'align' => " center " );
$header [ 'log_id' ][ '#title' ] = 'Id' ;
$header [ 'log_id' ][ 'align' ] = 'center' ;
2001-09-26 03:02:39 +02:00
2001-08-05 08:48:42 +02:00
// Column Log_Severity
2001-08-12 03:06:07 +02:00
$header [ 'log_severity' ][ '#parms_hdr' ] = array ( 'align' => " center " );
$header [ 'log_severity' ][ '#title' ] = 'S' ;
$header [ 'log_severity' ][ 'align' ] = 'center' ;
2001-09-26 03:02:39 +02:00
2001-08-05 08:48:42 +02:00
// Column Trans Date
2001-08-12 03:06:07 +02:00
$header [ 'log_date_e' ][ '#title' ] = 'Tans. Date' ;
2001-08-05 08:48:42 +02:00
// Column Application
2001-08-12 03:06:07 +02:00
$header [ 'log_app' ][ '#title' ] = 'App.' ;
2001-08-05 08:48:42 +02:00
// Column FullName
2001-08-12 03:06:07 +02:00
$header [ 'log_full_name' ][ '#title' ] = 'User' ;
$header [ 'log_full_name' ][ 'align' ] = 'center' ;
2001-08-05 08:48:42 +02:00
// Column log_msg_seq_no
2001-08-12 03:06:07 +02:00
$header [ 'log_msg_seq_no' ][ '#parms_hdr' ] = array ( 'align' => " center " );
$header [ 'log_msg_seq_no' ][ '#title' ] = 'Sno' ;
$header [ 'log_msg_seq_no' ][ 'align' ] = 'center' ;
2001-09-26 03:02:39 +02:00
2001-08-05 08:48:42 +02:00
// Column log_msg_seq_no
2001-08-12 03:06:07 +02:00
$header [ 'log_msg_date_e' ][ '#title' ] = 'TimeStamp' ;
$header [ 'log_msg_severity' ][ '#title' ] = 'S' ;
2001-09-26 03:02:39 +02:00
$header [ 'log_msg_severity' ][ 'align' ] = 'center' ;
2001-08-12 03:06:07 +02:00
$header [ 'log_msg_code' ][ '#title' ] = 'Code' ;
$header [ 'log_msg_text' ][ '#title' ] = 'Error Msg' ;
$header [ 'log_msg_file' ][ '#title' ] = 'File' ;
$header [ 'log_msg_line' ][ '#title' ] = 'Line' ;
2001-08-05 08:48:42 +02:00
2001-08-06 18:51:44 +02:00
// Set up Grouping, Suppression...
$header [ '_groupby' ] = array ( 'log_id' => 1 );
$header [ '_supres' ] = array ( 'log_id' => 1 , 'log_severity' => 1 , 'log_date_e' => 1 , 'log_app' => 1 , 'log_full_name' => 1 );
2001-08-05 08:48:42 +02:00
// Hack Get All Rows
$rows = $this -> bolog -> get_error_e ( array ( 'orderby' => array ( 'log_id' , 'log_msg_log_id' )));
2001-08-06 18:51:44 +02:00
$norows = count ( $rows );
2001-08-05 08:48:42 +02:00
$header [ '_edittable' ] = $this -> editmode ;
$table = $this -> html -> hash_table ( $rows , $header , $this , 'format_row' );
$this -> t -> set_var ( 'event_list' , $table );
2001-09-26 03:02:39 +02:00
$GLOBALS [ 'phpgw' ] -> common -> phpgw_header ();
echo parse_navbar ();
2001-08-05 08:48:42 +02:00
$this -> t -> pfp ( 'out' , 'log_list_t' );
// $this->set_app_langs();
}
function format_row ( $rno , $row )
{
2001-08-12 03:06:07 +02:00
switch ( $row [ 'log_severity' ][ 'value' ])
2001-08-05 08:48:42 +02:00
{
2001-08-12 03:06:07 +02:00
case 'D' : $row [ 'log_severity' ][ 'bgcolor' ] = 'D3DCFF' ; break ;
case 'I' : $row [ 'log_severity' ][ 'bgcolor' ] = 'C0FFC0' ; break ;
case 'W' : $row [ 'log_severity' ][ 'bgcolor' ] = 'FFFFC0' ; break ;
case 'E' : $row [ 'log_severity' ][ 'bgcolor' ] = 'FFC0C0' ; break ;
case 'F' : $row [ 'log_severity' ][ 'bgcolor' ] = 'FF0909' ; break ;
2001-08-05 08:48:42 +02:00
}
2001-08-12 03:06:07 +02:00
switch ( $row [ 'log_msg_severity' ][ 'value' ])
2001-08-05 08:48:42 +02:00
{
2001-08-08 09:21:29 +02:00
case 'D' : $color = 'D3DCFF' ; break ;
2001-08-05 08:48:42 +02:00
case 'I' : $color = 'C0FFC0' ; break ;
case 'W' : $color = 'FFFFC0' ; break ;
case 'E' : $color = 'FFC0C0' ; break ;
case 'F' : $color = 'FF0909' ; break ;
}
reset ( $this -> fields_inc );
2001-08-06 18:51:44 +02:00
while ( list ( $cno , $fld ) = each ( $this -> fields_inc ))
2001-08-05 08:48:42 +02:00
{
if ( substr ( $fld , 0 , 7 ) == 'log_msg' )
{
2001-08-12 03:06:07 +02:00
$row [ $fld ][ 'bgcolor' ] = $color ;
2001-08-05 08:48:42 +02:00
}
else
{
2001-08-06 18:51:44 +02:00
// $row[$cno]['bgcolor'] = $lcolor;
}
2001-09-26 03:02:39 +02:00
}
2001-08-05 08:48:42 +02:00
return $row ;
}
}
?>