From ae044a9a084f878313e40b902b471240f0d2d3e7 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Tue, 27 May 2008 09:25:25 +0000 Subject: [PATCH] allow to instanciate the historylog with a given user or 0 for changes by the system itself (eg. async service). bo_tracking passes on it's user param of the constructor. --- etemplate/inc/class.bo_tracking.inc.php | 9 +++---- phpgwapi/inc/class.historylog.inc.php | 36 ++++++++++++------------- 2 files changed, 21 insertions(+), 24 deletions(-) diff --git a/etemplate/inc/class.bo_tracking.inc.php b/etemplate/inc/class.bo_tracking.inc.php index 5cab462279..59b918e786 100644 --- a/etemplate/inc/class.bo_tracking.inc.php +++ b/etemplate/inc/class.bo_tracking.inc.php @@ -6,7 +6,7 @@ * @author Ralf Becker * @package etemplate * @subpackage api - * @copyright (c) 2007 by Ralf Becker + * @copyright (c) 2007/8 by Ralf Becker * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License * @version $Id$ */ @@ -202,10 +202,9 @@ class bo_tracking { if ($old[$name] != $data[$name] && !(!$old[$name] && !$data[$name])) { - if (!is_object($this->historylog)) + if (!is_object($this->historylog) || $this->historylog->user != $this->user) { - require_once(EGW_API_INC.'/class.historylog.inc.php'); - $this->historylog =& new historylog($this->app); + $this->historylog = new historylog($this->app,$this->user); } $this->historylog->add($status,$data[$this->id_field], is_array($data[$name]) ? implode(',',$data[$name]) : $data[$name], @@ -229,7 +228,7 @@ class bo_tracking { $this->errors = $email_sent = array(); - if (!$this->notify_current_user) // should we notify the current user about his own changes + if (!$this->notify_current_user && $this->user) // do we have a current user and should we notify the current user about his own changes { //error_log("do_notificaton() adding user=$this->user to email_sent, to not notify him"); $email_sent[] = $GLOBALS['egw']->accounts->id2name($this->user,'account_email'); diff --git a/phpgwapi/inc/class.historylog.inc.php b/phpgwapi/inc/class.historylog.inc.php index d323c790da..4ef914ec6f 100644 --- a/phpgwapi/inc/class.historylog.inc.php +++ b/phpgwapi/inc/class.historylog.inc.php @@ -1,17 +1,17 @@ * @copyright 2001 by Joseph Engo * @author Ralf Becker new DB-methods and search - * + * * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License * @package api * @subpackage db @@ -42,10 +42,11 @@ class historylog /** * offset in secconds between user and server-time, * it need to be add to a server-time to get the user-time or substracted from a user-time to get the server-time - * + * * @var int */ var $tz_offset_s; + var $user; var $template; var $nextmatchs; var $types = array( @@ -61,14 +62,11 @@ class historylog * @param string $appname app name this instance operates on * @return historylog */ - function historylog($appname='') + function historylog($appname='',$user=null) { - if (!$appname) - { - $appname = $GLOBALS['egw_info']['flags']['currentapp']; - } - $this->appname = $appname; - + $this->appname = $appname ? $appname : $GLOBALS['egw_info']['flags']['currentapp']; + $this->user = !is_null($user) ? $user : $GLOBALS['egw_info']['user']['account_id']; + if (is_object($GLOBALS['egw_setup']->db)) { $this->db = $GLOBALS['egw_setup']->db; @@ -89,7 +87,7 @@ class historylog function delete($record_id) { $where = array('history_appname' => $this->appname); - + if (is_array($record_id) || is_numeric($record_id)) { $where['history_record_id'] = $record_id; @@ -114,7 +112,7 @@ class historylog $this->db->insert(self::TABLE,array( 'history_record_id' => $record_id, 'history_appname' => $this->appname, - 'history_owner' => $GLOBALS['egw_info']['user']['account_id'], + 'history_owner' => $this->user, 'history_status' => $status, 'history_new_value' => $new_value, 'history_old_value' => $old_value, @@ -129,13 +127,13 @@ class historylog * @param array/int $filter array with filters, or int record_id * @param string $order='history_id' sorting after history_id is identical to history_timestamp * @param string $sort='ASC' - * @return array of arrays with keys id, record_id, appname, owner (account_id), status, new_value, old_value, + * @return array of arrays with keys id, record_id, appname, owner (account_id), status, new_value, old_value, * timestamp (Y-m-d H:i:s in servertime), user_ts (timestamp in user-time) */ function search($filter,$order='history_id',$sort='DESC') { if (!is_array($filter)) $filter = (int)$filter ? array('history_record_id' => $filter) : array(); - + if (!$_orderby || !preg_match('/^[a-z0-9_]+$/i',$_orderby) || !preg_match('/^(asc|desc)?$/i',$sort)) { $orderby = 'ORDER BY history_id DESC'; @@ -176,7 +174,7 @@ class historylog */ function return_array($filter_out,$only_show,$_orderby,$sort, $record_id) { - + if (!$_orderby || !preg_match('/^[a-z0-9_]+$/i',$_orderby) || !preg_match('/^(asc|desc)?$/i',$sort)) { $orderby = 'ORDER BY history_timestamp,history_id'; @@ -206,13 +204,13 @@ class historylog } $where[] = '('.implode(' OR ',$to_or).')'; } - + foreach($this->db->select(self::TABLE,'*',$where,__LINE__,__FILE__,false,$orderby) as $row) { $return_values[] = array( 'id' => $row['history_id'], 'record_id' => $row['history_record_id'], - 'owner' => $GLOBALS['egw']->accounts->id2name($row['history_owner']), + 'owner' => $row['history_owner'] ? $GLOBALS['egw']->accounts->id2name($row['history_owner']) : lang('eGroupWare'), 'status' => str_replace(' ','',$row['history_status']), 'new_value' => $row['history_new_value'], 'old_value' => $row['history_old_value'], @@ -221,7 +219,7 @@ class historylog } return $return_values; } - + /** * Creates html to show the history-log of one record *