2001-10-06 04:36:08 +02:00
|
|
|
<?php
|
|
|
|
/**************************************************************************\
|
2004-05-05 14:06:13 +02:00
|
|
|
* eGroupWare API - Record history logging *
|
2001-10-06 04:36:08 +02:00
|
|
|
* This file written by Joseph Engo <jengo@phpgroupware.org> *
|
|
|
|
* Copyright (C) 2001 Joseph Engo *
|
|
|
|
* -------------------------------------------------------------------------*
|
2004-05-05 14:06:13 +02:00
|
|
|
* This library is part of the eGroupWare API *
|
|
|
|
* http://www.egroupware.org/api *
|
2001-10-06 04:36:08 +02:00
|
|
|
* ------------------------------------------------------------------------ *
|
|
|
|
* This library is free software; you can redistribute it and/or modify it *
|
|
|
|
* under the terms of the GNU Lesser General Public License as published by *
|
|
|
|
* the Free Software Foundation; either version 2.1 of the License, *
|
|
|
|
* or any later version. *
|
|
|
|
* This library is distributed in the hope that it will be useful, but *
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
|
|
|
|
* See the GNU Lesser General Public License for more details. *
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License *
|
|
|
|
* along with this library; if not, write to the Free Software Foundation, *
|
|
|
|
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
|
|
|
|
\**************************************************************************/
|
|
|
|
|
2003-08-28 16:31:11 +02:00
|
|
|
// $Id$
|
2001-10-06 04:36:08 +02:00
|
|
|
|
|
|
|
class historylog
|
|
|
|
{
|
|
|
|
var $db;
|
2005-11-13 11:52:34 +01:00
|
|
|
var $table = 'egw_history_log';
|
2001-10-06 04:36:08 +02:00
|
|
|
var $appname;
|
|
|
|
var $template;
|
|
|
|
var $nextmatchs;
|
|
|
|
var $types = array(
|
|
|
|
'C' => 'Created',
|
|
|
|
'D' => 'Deleted',
|
|
|
|
'E' => 'Edited'
|
|
|
|
);
|
2001-10-17 04:21:03 +02:00
|
|
|
var $alternate_handlers = array();
|
2001-10-06 04:36:08 +02:00
|
|
|
|
2003-09-23 01:43:48 +02:00
|
|
|
function historylog($appname='')
|
2001-10-06 04:36:08 +02:00
|
|
|
{
|
2005-11-13 11:52:34 +01:00
|
|
|
if (!$appname)
|
2001-10-06 04:36:08 +02:00
|
|
|
{
|
2005-11-13 11:52:34 +01:00
|
|
|
$appname = $GLOBALS['egw_info']['flags']['currentapp'];
|
2001-10-06 04:36:08 +02:00
|
|
|
}
|
|
|
|
$this->appname = $appname;
|
2005-11-14 11:21:02 +01:00
|
|
|
|
|
|
|
if (is_object($GLOBALS['egw_setup']->db))
|
|
|
|
{
|
|
|
|
$this->db = clone($GLOBALS['egw_setup']->db);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$this->db = clone($GLOBALS['egw']->db);
|
|
|
|
}
|
2005-11-13 11:52:34 +01:00
|
|
|
$this->db->set_app('phpgwapi');
|
2001-10-06 04:36:08 +02:00
|
|
|
}
|
|
|
|
|
2001-10-17 04:33:05 +02:00
|
|
|
function delete($record_id)
|
|
|
|
{
|
2005-11-13 11:52:34 +01:00
|
|
|
if (is_array($record_id) || is_numeric($record_id))
|
|
|
|
{
|
|
|
|
$where = array(
|
|
|
|
'history_record_id' => $record_id,
|
|
|
|
'history_appname' => $this->appname,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$where = array('history_appname' => $record_id);
|
|
|
|
}
|
|
|
|
$this->db->delete($this->table,$where,__LINE__,__FILE__);
|
2003-09-23 01:43:48 +02:00
|
|
|
|
|
|
|
return $this->db->affected_rows();
|
2001-10-17 04:33:05 +02:00
|
|
|
}
|
|
|
|
|
2003-08-28 16:31:11 +02:00
|
|
|
function add($status,$record_id,$new_value,$old_value)
|
2001-10-06 04:36:08 +02:00
|
|
|
{
|
2003-08-28 16:31:11 +02:00
|
|
|
if ($new_value != $old_value)
|
|
|
|
{
|
2005-11-13 11:52:34 +01:00
|
|
|
$this->db->insert($this->table,array(
|
|
|
|
'history_record_id' => $record_id,
|
|
|
|
'history_appname' => $this->appname,
|
|
|
|
'history_owner' => $GLOBALS['egw_info']['user']['account_id'],
|
|
|
|
'history_status' => $status,
|
|
|
|
'history_new_value' => $new_value,
|
|
|
|
'history_old_value' => $old_value,
|
|
|
|
'history_timestamp' => time(),
|
|
|
|
),false,__LINE__,__FILE__);
|
2003-08-28 16:31:11 +02:00
|
|
|
}
|
2001-10-06 04:36:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// array $filter_out
|
2001-10-17 04:21:03 +02:00
|
|
|
function return_array($filter_out,$only_show,$_orderby = '',$sort = '', $record_id)
|
2001-10-06 04:36:08 +02:00
|
|
|
{
|
2001-10-17 03:10:23 +02:00
|
|
|
|
2005-11-13 11:52:34 +01:00
|
|
|
if (!$_orderby || !preg_match('/^[a-z0-9_]+$/i',$_orderby) || !preg_match('/^(asc|desc)?$/i',$sort))
|
2001-10-17 03:10:23 +02:00
|
|
|
{
|
2005-11-13 11:52:34 +01:00
|
|
|
$orderby = 'ORDER BY history_timestamp,history_id';
|
2001-10-17 03:10:23 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-11-13 11:52:34 +01:00
|
|
|
$orderby = "ORDER BY $_orderby $sort";
|
2001-10-17 03:10:23 +02:00
|
|
|
}
|
|
|
|
|
2005-11-13 11:52:34 +01:00
|
|
|
$where = array(
|
|
|
|
'history_appname' => $this->appname,
|
|
|
|
'history_record_id' => $record_id,
|
|
|
|
);
|
|
|
|
if (is_array($filter_out))
|
2001-10-06 04:36:08 +02:00
|
|
|
{
|
2005-11-13 11:52:34 +01:00
|
|
|
foreach($filter_out as $_filter)
|
|
|
|
{
|
|
|
|
$where[] = 'history_status != '.$this->db->quote($_filter);
|
|
|
|
}
|
2001-10-06 06:36:48 +02:00
|
|
|
}
|
2005-11-13 11:52:34 +01:00
|
|
|
if (is_array($only_show) && count($only_show))
|
2001-10-06 06:36:48 +02:00
|
|
|
{
|
2005-11-13 11:52:34 +01:00
|
|
|
$to_or = array();
|
|
|
|
foreach($only_show as $_filter)
|
|
|
|
{
|
|
|
|
$to_or[] = 'history_status = '.$this->db->quote($_filter);
|
|
|
|
}
|
|
|
|
$where[] = '('.implode(' OR ',$to_or).')';
|
2001-10-06 06:36:48 +02:00
|
|
|
}
|
2005-11-13 11:52:34 +01:00
|
|
|
|
|
|
|
$this->db->select($this->table,'*',$where,__LINE__,__FILE__,false,$orderby);
|
2001-10-06 04:36:08 +02:00
|
|
|
while ($this->db->next_record())
|
|
|
|
{
|
|
|
|
$return_values[] = array(
|
|
|
|
'id' => $this->db->f('history_id'),
|
|
|
|
'record_id' => $this->db->f('history_record_id'),
|
2005-11-13 11:52:34 +01:00
|
|
|
'owner' => $GLOBALS['egw']->accounts->id2name($this->db->f('history_owner')),
|
2003-12-14 18:07:16 +01:00
|
|
|
'status' => str_replace(' ','',$this->db->f('history_status')),
|
2001-10-06 04:36:08 +02:00
|
|
|
'new_value' => $this->db->f('history_new_value'),
|
2003-08-28 16:31:11 +02:00
|
|
|
'old_value' => $this->db->f('history_old_value'),
|
2001-10-06 04:36:08 +02:00
|
|
|
'datetime' => $this->db->from_timestamp($this->db->f('history_timestamp'))
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return $return_values;
|
|
|
|
}
|
|
|
|
|
2001-10-17 04:21:03 +02:00
|
|
|
function return_html($filter_out,$orderby = '',$sort = '', $record_id)
|
2001-10-06 04:36:08 +02:00
|
|
|
{
|
2005-11-13 11:52:34 +01:00
|
|
|
$this->template =& CreateObject('phpgwapi.Template',EGW_TEMPLATE_DIR);
|
|
|
|
$this->nextmatchs =& CreateObject('phpgwapi.nextmatchs');
|
2001-10-06 04:36:08 +02:00
|
|
|
|
|
|
|
$this->template->set_file('_history','history_list.tpl');
|
|
|
|
|
|
|
|
$this->template->set_block('_history','row_no_history');
|
|
|
|
$this->template->set_block('_history','list');
|
|
|
|
$this->template->set_block('_history','row');
|
|
|
|
|
|
|
|
$this->template->set_var('lang_user',lang('User'));
|
|
|
|
$this->template->set_var('lang_date',lang('Date'));
|
|
|
|
$this->template->set_var('lang_action',lang('Action'));
|
|
|
|
$this->template->set_var('lang_new_value',lang('New Value'));
|
|
|
|
|
2005-11-13 11:52:34 +01:00
|
|
|
$this->template->set_var('th_bg',$GLOBALS['egw_info']['theme']['th_bg']);
|
2001-10-06 04:36:08 +02:00
|
|
|
$this->template->set_var('sort_date',lang('Date'));
|
|
|
|
$this->template->set_var('sort_owner',lang('User'));
|
|
|
|
$this->template->set_var('sort_status',lang('Status'));
|
|
|
|
$this->template->set_var('sort_new_value',lang('New value'));
|
2003-08-28 16:31:11 +02:00
|
|
|
$this->template->set_var('sort_old_value',lang('Old value'));
|
2001-10-06 04:36:08 +02:00
|
|
|
|
2001-10-06 06:36:48 +02:00
|
|
|
$values = $this->return_array($filter_out,array(),$orderby,$sort,$record_id);
|
2001-10-06 04:36:08 +02:00
|
|
|
|
2005-11-13 11:52:34 +01:00
|
|
|
if (!is_array($values))
|
2001-10-06 04:36:08 +02:00
|
|
|
{
|
2005-11-13 11:52:34 +01:00
|
|
|
$this->template->set_var('tr_color',$GLOBALS['egw_info']['theme']['row_off']);
|
2001-10-06 04:36:08 +02:00
|
|
|
$this->template->set_var('lang_no_history',lang('No history for this record'));
|
|
|
|
$this->template->fp('rows','row_no_history');
|
|
|
|
return $this->template->fp('out','list');
|
|
|
|
}
|
|
|
|
|
2005-11-13 11:52:34 +01:00
|
|
|
foreach($values as $value)
|
2001-10-06 04:36:08 +02:00
|
|
|
{
|
2004-03-16 07:54:22 +01:00
|
|
|
$this->nextmatchs->template_alternate_row_color($this->template);
|
2001-10-06 04:36:08 +02:00
|
|
|
|
2005-11-13 11:52:34 +01:00
|
|
|
$this->template->set_var('row_date',$GLOBALS['egw']->common->show_date($value['datetime']));
|
2001-10-06 04:36:08 +02:00
|
|
|
$this->template->set_var('row_owner',$value['owner']);
|
2001-10-17 04:21:03 +02:00
|
|
|
|
|
|
|
if ($this->alternate_handlers[$value['status']])
|
|
|
|
{
|
|
|
|
eval('\$s = ' . $this->alternate_handlers[$value['status']] . '(' . $value['new_value'] . ');');
|
|
|
|
$this->template->set_var('row_new_value',$s);
|
|
|
|
unset($s);
|
2003-08-28 16:31:11 +02:00
|
|
|
|
|
|
|
eval('\$s = ' . $this->alternate_handlers[$value['status']] . '(' . $value['old_value'] . ');');
|
|
|
|
$this->template->set_var('row_old_value',$s);
|
|
|
|
unset($s);
|
2001-10-17 04:21:03 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$this->template->set_var('row_new_value',$value['new_value']);
|
2003-08-28 16:31:11 +02:00
|
|
|
$this->template->set_var('row_old_value',$value['old_value']);
|
2001-10-17 04:21:03 +02:00
|
|
|
}
|
2003-08-28 16:31:11 +02:00
|
|
|
|
2001-10-17 04:01:41 +02:00
|
|
|
$this->template->set_var('row_status',$this->types[$value['status']]);
|
2001-10-06 04:36:08 +02:00
|
|
|
|
2001-10-17 04:01:41 +02:00
|
|
|
$this->template->fp('rows','row',True);
|
2001-10-06 04:36:08 +02:00
|
|
|
}
|
|
|
|
return $this->template->fp('out','list');
|
|
|
|
}
|
2001-10-17 03:10:23 +02:00
|
|
|
}
|