2001-08-05 08:48:42 +02:00
< ? php
/************************************************************************** \
2004-01-27 00:26:19 +01:00
* eGroupWare - solog *
* http :// www . egroupware . org *
2001-08-05 08:48:42 +02:00
* This application written by Jerry Westrick < jerry @ westrick . com > *
* -------------------------------------------- *
* Funding for this program was provided by http :// www . checkwithmom . 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 . *
\ **************************************************************************/
/* $Id$ */
class solog
{
var $db ;
2005-11-02 12:45:52 +01:00
var $accounts_table = 'egw_accounts' ;
var $log_table = 'egw_log' ;
var $msg_table = 'egw_log_msg' ;
2001-08-05 08:48:42 +02:00
var $owner ;
var $error_cols = '' ;
var $error_cols_e = '' ;
2001-09-26 03:02:39 +02:00
var $public_functions = array (
'get_error_cols' => True ,
'get_error_cols_e' => True ,
'get_error' => True ,
'get_error_e' => True
);
2001-08-05 08:48:42 +02:00
function solog ()
{
2005-10-14 19:03:16 +02:00
$this -> db = clone ( $GLOBALS [ 'egw' ] -> db );
2001-08-05 08:48:42 +02:00
}
function get_error_cols ()
{
if ( $this -> error_cols == '' )
{
$this -> error_cols = array ();
2005-11-02 12:45:52 +01:00
/* fields from log table */
$clist = $this -> db -> metadata ( $this -> log_table );
2001-08-05 08:48:42 +02:00
for ( $i = 0 ; $i < count ( $clist ); $i ++ )
{
$name = $clist [ $i ][ 'name' ];
$this -> error_cols [ $name ] = array ();
}
2005-11-02 12:45:52 +01:00
/* fields from msg table */
$clist = $this -> db -> metadata ( $this -> msg_table );
2001-08-05 08:48:42 +02:00
for ( $i = 0 ; $i < count ( $clist ); $i ++ )
{
$name = $clist [ $i ][ 'name' ];
$this -> error_cols [ $name ] = array ();
}
}
return $this -> error_cols ;
}
function get_error_cols_e ()
{
if ( $this -> task_cols_e == '' )
{
2001-09-26 03:02:39 +02:00
/* Get Columns for Errors */
2001-08-05 08:48:42 +02:00
$this -> error_cols_e = $this -> get_error_cols ();
2005-11-02 12:45:52 +01:00
/* Enhance with Columns from accounts-table */
$clist = $this -> db -> metadata ( $this -> accounts_table );
2001-08-05 08:48:42 +02:00
for ( $i = 0 ; $i < count ( $clist ); $i ++ )
{
$name = $clist [ $i ][ 'name' ];
$this -> error_cols_e [ $name ] = array ();
}
}
return $this -> error_cols_e ;
}
function get_error_e ( $parms )
2001-09-26 03:02:39 +02:00
{
2003-10-22 07:18:45 +02:00
2001-09-26 03:02:39 +02:00
/* Fixed From */
2001-08-06 18:50:20 +02:00
if ( ! isset ( $parms [ 'from' ]))
2001-08-05 08:48:42 +02:00
{
2005-11-02 12:45:52 +01:00
$parms [ 'from' ] = array ( $this -> accounts_table );
2001-08-05 08:48:42 +02:00
}
else
{
2005-11-02 12:45:52 +01:00
$parms [ 'from' ][] = $this -> accounts_table ;
2001-08-05 08:48:42 +02:00
}
2001-09-26 03:02:39 +02:00
/* Fix Where */
2001-08-06 18:50:20 +02:00
if ( ! isset ( $parms [ 'where' ]))
2001-08-05 08:48:42 +02:00
{
2005-11-02 12:45:52 +01:00
$parms [ 'where' ] = array ( " $this->log_table .log_user = $this->accounts_table .account_id " );
2001-08-05 08:48:42 +02:00
}
else
{
2005-11-02 12:45:52 +01:00
$parms [ 'where' ][] = " $this->log_table .log_user = $this->accounts_table .account_id " ;
2001-08-05 08:48:42 +02:00
}
2003-10-22 07:18:45 +02:00
2001-09-26 03:02:39 +02:00
/* Fix Default Fields */
2001-08-06 18:50:20 +02:00
if ( ! isset ( $parms [ 'fields' ]))
2001-08-05 08:48:42 +02:00
{
$parms [ 'fields' ] = $this -> get_error_cols_e ();
}
return $this -> get_error ( $parms );
}
2001-08-12 03:06:07 +02:00
function get_no_errors ()
2001-12-18 07:00:48 +01:00
{
/* Get max ErrorId */
2005-11-02 12:45:52 +01:00
$this -> db -> query ( " select count(*) as max_id from $this->log_table , $this->msg_table WHERE $this->log_table .log_id = $this->msg_table .log_msg_log_id " , __LINE__ , __FILE__ );
return $this -> db -> next_record () ? $this -> db -> f ( 'max_id' ) : 0 ;
2001-08-12 03:06:07 +02:00
}
2001-08-05 08:48:42 +02:00
function get_error ( $parms )
2001-12-18 07:00:48 +01:00
{
/* Get parameter values */
2001-08-05 08:48:42 +02:00
$from = $parms [ 'from' ];
$where = $parms [ 'where' ];
$orderby = $parms [ 'orderby' ];
$fields = $parms [ 'fields' ];
2001-09-26 03:02:39 +02:00
/* Build From_Clause */
2005-11-02 12:45:52 +01:00
$from_clause = " FROM $this->log_table , $this->msg_table " ;
2001-08-06 18:50:20 +02:00
if ( isset ( $from ))
2001-08-05 08:48:42 +02:00
{
2005-11-02 12:45:52 +01:00
$from [] = $this -> log_table ;
$from [] = $this -> msg_table ;
2001-08-05 08:48:42 +02:00
$from_clause = 'FROM ' . implode ( ', ' , $from ) . ' ' ;
}
2001-09-26 03:02:39 +02:00
/* Build Where_Clause */
2005-11-02 12:45:52 +01:00
$where_clause = " WHERE $this->log_table .log_id = $this->msg_table .log_msg_log_id " ;
2001-08-06 18:50:20 +02:00
if ( isset ( $where ))
2001-08-05 08:48:42 +02:00
{
2005-11-02 12:45:52 +01:00
$where [] = " $this->log_table .log_id = $this->msg_table .log_msg_log_id " ;
2001-08-05 08:48:42 +02:00
$where_clause = 'WHERE ' . implode ( ' AND ' , $where ) . ' ' ;
}
2001-09-26 03:02:39 +02:00
/* Build Order_By_Clause */
2005-11-02 12:45:52 +01:00
$orderby_clause = " ORDER BY $this->log_table .log_id, $this->msg_table .log_msg_seq_no " ;
2001-08-06 18:50:20 +02:00
if ( isset ( $orderby ))
2001-08-05 08:48:42 +02:00
{
2001-09-26 03:02:39 +02:00
$orderby_clause = 'ORDER BY ' . implode ( ', ' , $orderby );
2001-08-05 08:48:42 +02:00
}
2001-09-26 03:02:39 +02:00
/* If no Fields specified default to * */
2001-08-06 18:50:20 +02:00
if ( ! isset ( $fields ))
2001-08-05 08:48:42 +02:00
{
2002-02-15 02:51:32 +01:00
$fields = $this -> get_error_cols ();
2001-08-05 08:48:42 +02:00
}
2001-09-26 03:02:39 +02:00
2001-08-05 08:48:42 +02:00
$rows = array ();
2001-09-26 03:02:39 +02:00
2005-11-02 12:45:52 +01:00
$select = 'SELECT ' . implode ( ',' , array_keys ( $fields )) . ' ' . $from_clause . $where_clause . $orderby_clause ;
2001-08-06 18:50:20 +02:00
$this -> db -> query ( $select , __LINE__ , __FILE__ );
2001-08-05 08:48:42 +02:00
while ( $this -> db -> next_record ())
{
2005-11-02 12:45:52 +01:00
foreach ( $fields as $fname => $fopt )
2001-08-05 08:48:42 +02:00
{
2001-08-12 03:06:07 +02:00
$this_row [ $fname ][ 'value' ] = $this -> db -> f ( $fname );
2001-09-26 03:02:39 +02:00
}
2001-08-06 18:50:20 +02:00
$rows [] = $this_row ;
2001-09-26 03:02:39 +02:00
}
2001-08-05 08:48:42 +02:00
return $rows ;
}
}