egroupware_official/admin/inc/class.solog.inc.php

179 lines
4.6 KiB
PHP
Raw Normal View History

2001-08-05 08:48:42 +02:00
<?php
/**************************************************************************\
* phpGroupWare - solog *
* http://www.phpgroupware.org *
* 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;
var $owner;
var $error_cols = '';
var $error_cols_e = '';
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()
{
2001-12-18 07:00:48 +01:00
$this->db = $GLOBALS['phpgw']->db;
2001-08-05 08:48:42 +02:00
}
function get_error_cols()
{
if ($this->error_cols == '')
{
$this->error_cols = array();
/* fields from phpgw_log table */
2001-08-05 08:48:42 +02:00
$clist = $this->db->metadata('phpgw_log');
for ($i=0; $i<count($clist); $i++)
{
$name = $clist[$i]['name'];
$this->error_cols[$name] = array();
}
/* fields from phpgw_log_msg table */
2001-08-05 08:48:42 +02:00
$clist = $this->db->metadata('phpgw_log_msg');
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 == '')
{
/* Get Columns for Errors */
2001-08-05 08:48:42 +02:00
$this->error_cols_e = $this->get_error_cols();
/* Enhance with Columns for phpgw_accounts */
2001-08-05 08:48:42 +02:00
$clist = $this->db->metadata('phpgw_accounts');
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)
{
/* Fixed From */
if (!isset($parms['from']))
2001-08-05 08:48:42 +02:00
{
$parms['from'] = array('phpgw_accounts');
}
else
{
$parms['from'][] = 'phpgw_accounts';
}
/* Fix Where */
if (!isset($parms['where']))
2001-08-05 08:48:42 +02:00
{
$parms['where'] = array('phpgw_log.log_user = phpgw_accounts.account_id');
}
else
{
$parms['where'][] = 'phpgw_log.log_id = phpgw_accounts.account_id';
}
/* Fix Default Fields */
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 */
2001-08-12 03:06:07 +02:00
$this->db->query("select count(*) as max_id from phpgw_log, phpgw_log_msg WHERE phpgw_log.log_id = phpgw_log_msg.log_msg_log_id",__LINE__,__FILE__);
$this->db->next_record();
return $this->db->f('max_id');
}
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'];
/* Build From_Clause */
2001-08-05 08:48:42 +02:00
$from_clause = 'FROM phpgw_log, phpgw_log_msg ';
if (isset($from))
2001-08-05 08:48:42 +02:00
{
$from[] = 'phpgw_log';
$from[] = 'phpgw_log_msg';
$from_clause = 'FROM '.implode(', ' , $from).' ';
}
/* Build Where_Clause */
2001-08-05 08:48:42 +02:00
$where_clause = 'WHERE phpgw_log.log_id = phpgw_log_msg.log_msg_log_id ';
if (isset($where))
2001-08-05 08:48:42 +02:00
{
$where[] = 'phpgw_log.log_id = phpgw_log_msg.log_msg_log_id';
$where_clause = 'WHERE ' . implode(' AND ',$where) . ' ';
}
/* Build Order_By_Clause */
$orderby_clause = 'ORDER BY phpgw_log.log_id, phpgw_log_msg.log_msg_seq_no ';
if (isset($orderby))
2001-08-05 08:48:42 +02:00
{
$orderby_clause = 'ORDER BY ' . implode(', ',$orderby);
2001-08-05 08:48:42 +02:00
}
/* If no Fields specified default to * */
if (!isset($fields))
2001-08-05 08:48:42 +02:00
{
$fields = $this->error_cols();
2001-08-05 08:48:42 +02:00
}
2001-08-05 08:48:42 +02:00
$rows = array();
/* Do Select */
@reset($fields);
while(list($key,$val) = @each($fields))
{
$fkeys .= $key . ',';
}
$fkeys = substr($fkeys,0,-1);
$select = 'SELECT ' . $fkeys . ' ' . $from_clause . $where_clause . $orderby_clause;
$this->db->query($select,__LINE__,__FILE__);
2001-08-05 08:48:42 +02:00
while($this->db->next_record())
{
reset($fields);
while(list($fname,$fopt) = each($fields))
{
2001-08-12 03:06:07 +02:00
$this_row[$fname]['value'] = $this->db->f($fname);
}
$rows[] = $this_row;
}
2001-08-05 08:48:42 +02:00
return $rows;
}
}