2007-05-28 23:17:15 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* InfoLog - history and notifications
|
|
|
|
*
|
|
|
|
* @link http://www.egroupware.org
|
|
|
|
* @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
|
|
|
|
* @package tracker
|
2016-04-30 19:05:23 +02:00
|
|
|
* @copyright (c) 2007-16 by Ralf Becker <RalfBecker-AT-outdoor-training.de>
|
2007-05-28 23:17:15 +02:00
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
2008-10-07 14:50:14 +02:00
|
|
|
* @version $Id$
|
2007-05-28 23:17:15 +02:00
|
|
|
*/
|
|
|
|
|
2016-04-30 19:05:23 +02:00
|
|
|
use EGroupware\Api;
|
|
|
|
use EGroupware\Api\Link;
|
|
|
|
|
2007-05-28 23:17:15 +02:00
|
|
|
/**
|
|
|
|
* Tracker - tracking object for the tracker
|
|
|
|
*/
|
2016-04-30 19:05:23 +02:00
|
|
|
class infolog_tracking extends Api\Storage\Tracking
|
2007-05-28 23:17:15 +02:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Application we are tracking (required!)
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
var $app = 'infolog';
|
|
|
|
/**
|
|
|
|
* Name of the id-field, used as id in the history log (required!)
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
var $id_field = 'info_id';
|
|
|
|
/**
|
|
|
|
* Name of the field with the creator id, if the creator of an entry should be notified
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
var $creator_field = 'info_owner';
|
|
|
|
/**
|
|
|
|
* Name of the field with the id(s) of assinged users, if they should be notified
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
var $assigned_field = 'info_responsible';
|
|
|
|
/**
|
|
|
|
* Translate field-names to 2-char history status
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2007-06-13 23:37:05 +02:00
|
|
|
var $field2history = array(
|
|
|
|
'info_type' => 'Ty',
|
|
|
|
'info_from' => 'Fr',
|
|
|
|
'info_link_id' => 'Li',
|
2012-07-09 18:57:53 +02:00
|
|
|
'info_id_parent' => 'parent',
|
2007-06-13 23:37:05 +02:00
|
|
|
'info_cat' => 'Ca',
|
|
|
|
'info_priority' => 'Pr',
|
|
|
|
'info_owner' => 'Ow',
|
|
|
|
'info_access' => 'Ac',
|
|
|
|
'info_status' => 'St',
|
|
|
|
'info_percent' => 'Pe',
|
|
|
|
'info_datecompleted' => 'Co',
|
|
|
|
'info_location' => 'Lo',
|
|
|
|
'info_startdate' => 'st',
|
|
|
|
'info_enddate' => 'En',
|
|
|
|
'info_responsible' => 'Re',
|
2011-03-08 20:18:07 +01:00
|
|
|
'info_cc' => 'cc',
|
2007-06-13 23:37:05 +02:00
|
|
|
'info_subject' => 'Su',
|
|
|
|
'info_des' => 'De',
|
|
|
|
'info_location' => 'Lo',
|
|
|
|
// PM fields
|
|
|
|
'info_planned_time' => 'pT',
|
2012-10-10 17:27:43 +02:00
|
|
|
'info_replanned_time' => 'replanned',
|
2007-06-13 23:37:05 +02:00
|
|
|
'info_used_time' => 'uT',
|
|
|
|
'pl_id' => 'pL',
|
|
|
|
'info_price' => 'pr',
|
|
|
|
// all custom fields together
|
|
|
|
'custom' => '#c',
|
|
|
|
);
|
2007-05-28 23:17:15 +02:00
|
|
|
/**
|
|
|
|
* Translate field-names to labels
|
|
|
|
*
|
2010-11-19 20:05:01 +01:00
|
|
|
* @note The order of these fields is used to determine the order for CSV export
|
2007-05-28 23:17:15 +02:00
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
var $field2label = array(
|
|
|
|
'info_type' => 'Type',
|
|
|
|
'info_from' => 'Contact',
|
2010-11-19 20:05:01 +01:00
|
|
|
'info_subject' => 'Subject',
|
|
|
|
'info_des' => 'Description',
|
2007-06-13 23:37:05 +02:00
|
|
|
'info_link_id' => 'primary link',
|
2012-07-09 18:57:53 +02:00
|
|
|
'info_id_parent' => 'Parent',
|
2007-05-28 23:17:15 +02:00
|
|
|
'info_cat' => 'Category',
|
|
|
|
'info_priority' => 'Priority',
|
|
|
|
'info_owner' => 'Owner',
|
2013-02-07 10:38:21 +01:00
|
|
|
'info_modifier' => 'Modifier',
|
2007-06-13 23:37:05 +02:00
|
|
|
'info_access' => 'Access',
|
2007-05-28 23:17:15 +02:00
|
|
|
'info_status' => 'Status',
|
|
|
|
'info_percent' => 'Completed',
|
|
|
|
'info_datecompleted' => 'Date completed',
|
2010-05-14 18:50:49 +02:00
|
|
|
'info_datemodified' => 'Last changed',
|
2007-05-28 23:17:15 +02:00
|
|
|
'info_location' => 'Location',
|
2011-12-08 16:25:56 +01:00
|
|
|
'info_startdate' => 'Start date',
|
2017-06-12 23:25:39 +02:00
|
|
|
'info_enddate' => 'Enddate',
|
2007-05-28 23:17:15 +02:00
|
|
|
'info_responsible' => 'Responsible',
|
2011-03-08 20:18:07 +01:00
|
|
|
'info_cc' => 'Cc',
|
2007-06-13 23:37:05 +02:00
|
|
|
// PM fields
|
|
|
|
'info_planned_time' => 'planned time',
|
2012-10-10 17:27:43 +02:00
|
|
|
'info_replanned_time' => 're-planned time',
|
2007-06-13 23:37:05 +02:00
|
|
|
'info_used_time' => 'used time',
|
|
|
|
'pl_id' => 'pricelist',
|
|
|
|
'info_price' => 'price',
|
|
|
|
// custom fields
|
|
|
|
'custom' => 'custom fields'
|
2007-05-28 23:17:15 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
2008-10-07 14:50:14 +02:00
|
|
|
* Instance of the infolog_bo class calling us
|
|
|
|
*
|
|
|
|
* @var infolog_bo
|
2007-05-28 23:17:15 +02:00
|
|
|
*/
|
2008-10-07 14:50:14 +02:00
|
|
|
private $infolog;
|
2007-05-28 23:17:15 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*
|
|
|
|
* @param botracker $botracker
|
|
|
|
* @return tracker_tracking
|
|
|
|
*/
|
2008-10-07 14:50:14 +02:00
|
|
|
function __construct(&$infolog_bo)
|
2007-05-28 23:17:15 +02:00
|
|
|
{
|
2011-04-20 08:31:45 +02:00
|
|
|
parent::__construct('infolog'); // add custom fields from infolog
|
2008-10-07 14:50:14 +02:00
|
|
|
|
|
|
|
$this->infolog =& $infolog_bo;
|
2007-05-28 23:17:15 +02:00
|
|
|
}
|
2008-10-07 14:50:14 +02:00
|
|
|
|
2007-06-13 23:37:05 +02:00
|
|
|
/**
|
|
|
|
* Get the subject for a given entry
|
2008-10-07 14:50:14 +02:00
|
|
|
*
|
2007-06-13 23:37:05 +02:00
|
|
|
* Reimpleneted to use a New|deleted|modified prefix.
|
|
|
|
*
|
|
|
|
* @param array $data
|
|
|
|
* @param array $old
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
function get_subject($data,$old)
|
|
|
|
{
|
2010-05-20 18:13:55 +02:00
|
|
|
if ($data['prefix'])
|
|
|
|
{
|
|
|
|
$prefix = $data['prefix']; // async notification
|
|
|
|
}
|
|
|
|
elseif (!$old || $old['info_status'] == 'deleted')
|
2007-06-13 23:37:05 +02:00
|
|
|
{
|
|
|
|
$prefix = lang('New %1',lang($this->infolog->enums['type'][$data['info_type']]));
|
|
|
|
}
|
|
|
|
elseif($data['info_status'] == 'deleted')
|
|
|
|
{
|
|
|
|
$prefix = lang('%1 deleted',lang($this->infolog->enums['type'][$data['info_type']]));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$prefix = lang('%1 modified',lang($this->infolog->enums['type'][$data['info_type']]));
|
|
|
|
}
|
|
|
|
return $prefix.': '.$data['info_subject'];
|
|
|
|
}
|
|
|
|
|
2007-05-28 23:17:15 +02:00
|
|
|
/**
|
|
|
|
* Get the modified / new message (1. line of mail body) for a given entry, can be reimplemented
|
2008-10-07 14:50:14 +02:00
|
|
|
*
|
2007-05-28 23:17:15 +02:00
|
|
|
* @param array $data
|
|
|
|
* @param array $old
|
2007-06-13 23:37:05 +02:00
|
|
|
* @return string
|
2007-05-28 23:17:15 +02:00
|
|
|
*/
|
|
|
|
function get_message($data,$old)
|
|
|
|
{
|
2007-06-10 11:21:04 +02:00
|
|
|
if ($data['message']) return $data['message']; // async notification
|
|
|
|
|
2007-06-13 23:37:05 +02:00
|
|
|
if (!$old || $old['info_status'] == 'deleted')
|
2007-05-28 23:17:15 +02:00
|
|
|
{
|
|
|
|
return lang('New %1 created by %2 at %3',lang($this->infolog->enums['type'][$data['info_type']]),
|
2016-04-30 19:05:23 +02:00
|
|
|
Api\Accounts::username($this->infolog->user),$this->datetime('now'));
|
2007-05-28 23:17:15 +02:00
|
|
|
}
|
2007-06-13 23:37:05 +02:00
|
|
|
elseif($data['info_status'] == 'deleted')
|
|
|
|
{
|
|
|
|
return lang('%1 deleted by %2 at %3',lang($this->infolog->enums['type'][$data['info_type']]),
|
2016-04-30 19:05:23 +02:00
|
|
|
Api\Accounts::username($data['info_modifier']),
|
2010-02-04 13:08:03 +01:00
|
|
|
$this->datetime($data['info_datemodified']));
|
2007-06-13 23:37:05 +02:00
|
|
|
}
|
2007-05-28 23:17:15 +02:00
|
|
|
return lang('%1 modified by %2 at %3',lang($this->infolog->enums['type'][$data['info_type']]),
|
2016-04-30 19:05:23 +02:00
|
|
|
Api\Accounts::username($data['info_modifier']),
|
2010-02-04 13:08:03 +01:00
|
|
|
$this->datetime($data['info_datemodified']));
|
2007-05-28 23:17:15 +02:00
|
|
|
}
|
2008-10-07 14:50:14 +02:00
|
|
|
|
2007-05-28 23:17:15 +02:00
|
|
|
/**
|
|
|
|
* Get the details of an entry
|
2008-10-07 14:50:14 +02:00
|
|
|
*
|
2012-08-09 14:41:47 +02:00
|
|
|
* @param array|object $data
|
|
|
|
* @param int|string $receiver nummeric account_id or email address
|
2007-05-28 23:17:15 +02:00
|
|
|
* @return array of details as array with values for keys 'label','value','type'
|
|
|
|
*/
|
2012-08-09 14:41:47 +02:00
|
|
|
function get_details($data,$receiver=null)
|
2007-05-28 23:17:15 +02:00
|
|
|
{
|
2014-01-28 11:02:11 +01:00
|
|
|
unset($receiver); // not used, but required function signature
|
2012-05-08 14:38:32 +02:00
|
|
|
//error_log(__METHOD__.__LINE__.' Data:'.array2string($data));
|
2007-05-28 23:17:15 +02:00
|
|
|
$responsible = array();
|
|
|
|
if ($data['info_responsible'])
|
|
|
|
{
|
|
|
|
foreach($data['info_responsible'] as $uid)
|
|
|
|
{
|
2016-04-30 19:05:23 +02:00
|
|
|
$responsible[] = Api\Accounts::username($uid);
|
2007-05-28 23:17:15 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($GLOBALS['egw_info']['user']['preferences']['infolog']['show_id'])
|
|
|
|
{
|
|
|
|
$id = ' #'.$data['info_id'];
|
|
|
|
}
|
|
|
|
foreach(array(
|
|
|
|
'info_type' => lang($this->infolog->enums['type'][$data['info_type']]).$id,
|
|
|
|
'info_from' => $data['info_from'],
|
|
|
|
'info_cat' => $data['info_cat'] ? $GLOBALS['egw']->categories->id2name($data['info_cat']) : '',
|
|
|
|
'info_priority' => lang($this->infolog->enums['priority'][$data['info_priority']]),
|
2016-04-30 19:05:23 +02:00
|
|
|
'info_owner' => Api\Accounts::username($data['info_owner']),
|
2007-06-13 23:37:05 +02:00
|
|
|
'info_status' => lang($data['info_status']=='deleted'?'deleted':$this->infolog->status[$data['info_type']][$data['info_status']]),
|
2007-05-28 23:17:15 +02:00
|
|
|
'info_percent' => (int)$data['info_percent'].'%',
|
2010-02-04 13:08:03 +01:00
|
|
|
'info_datecompleted' => $data['info_datecompleted'] ? $this->datetime($data['info_datecompleted']) : '',
|
2007-05-28 23:17:15 +02:00
|
|
|
'info_location' => $data['info_location'],
|
2010-02-04 13:08:03 +01:00
|
|
|
'info_startdate' => $data['info_startdate'] ? $this->datetime($data['info_startdate'],null) : '',
|
2012-04-04 12:37:23 +02:00
|
|
|
'info_enddate' => $data['info_enddate'] ? $this->datetime($data['info_enddate'],null) : '',
|
2007-05-28 23:17:15 +02:00
|
|
|
'info_responsible' => implode(', ',$responsible),
|
|
|
|
'info_subject' => $data['info_subject'],
|
|
|
|
) as $name => $value)
|
|
|
|
{
|
2012-05-08 14:38:32 +02:00
|
|
|
//error_log(__METHOD__.__LINE__.' Key:'.$name.' val:'.array2string($value));
|
2016-12-09 20:02:02 +01:00
|
|
|
if ($name=='info_from' && empty($value))
|
|
|
|
if(!empty($data['info_contact']) && is_array($data['link_to']['to_id']))
|
|
|
|
{
|
|
|
|
$lkeys = array_keys($data['link_to']['to_id']);
|
|
|
|
if (in_array($data['info_contact'],$lkeys))
|
|
|
|
{
|
|
|
|
list($app,$id) = explode(':',$data['info_contact']);
|
|
|
|
if (!empty($app)&&!empty($id)) $value = Link::title($app,$id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ($data['info_link_id'])
|
2012-05-08 14:38:32 +02:00
|
|
|
{
|
2016-12-09 20:02:02 +01:00
|
|
|
$this->infolog->link_id2from($data);
|
2012-05-08 14:38:32 +02:00
|
|
|
list($app,$id) = explode(':',$data['info_contact']);
|
2016-04-30 19:05:23 +02:00
|
|
|
if (!empty($app)&&!empty($id)) $value = Link::title($app,$id);
|
2012-05-08 14:38:32 +02:00
|
|
|
}
|
2007-05-28 23:17:15 +02:00
|
|
|
$details[$name] = array(
|
|
|
|
'label' => lang($this->field2label[$name]),
|
|
|
|
'value' => $value,
|
|
|
|
);
|
|
|
|
if ($name == 'info_subject') $details[$name]['type'] = 'summary';
|
|
|
|
}
|
|
|
|
$details['info_des'] = array(
|
|
|
|
'value' => $data['info_des'],
|
|
|
|
'type' => 'multiline',
|
|
|
|
);
|
2012-08-09 14:41:47 +02:00
|
|
|
// add custom fields for given type
|
|
|
|
$details += $this->get_customfields($data, $data['info_type']);
|
2008-10-07 14:50:14 +02:00
|
|
|
|
2007-05-28 23:17:15 +02:00
|
|
|
return $details;
|
|
|
|
}
|
2008-10-07 14:50:14 +02:00
|
|
|
|
2010-05-14 18:50:49 +02:00
|
|
|
/**
|
|
|
|
* Track changes
|
2010-05-20 18:13:55 +02:00
|
|
|
*
|
2010-05-14 18:50:49 +02:00
|
|
|
* Overrides parent to log the modified date in the history, but not to send a notification
|
|
|
|
*
|
2010-10-26 11:21:52 +02:00
|
|
|
* @param array $data current entry
|
2015-05-21 16:22:51 +02:00
|
|
|
* @param array $old = null old/last state of the entry or null for a new entry
|
|
|
|
* @param int $user = null user who made the changes, default to current user
|
|
|
|
* @param boolean $deleted = null can be set to true to let the tracking know the item got deleted or undeleted
|
|
|
|
* @param array $changed_fields = null changed fields from ealier call to $this->changed_fields($data,$old), to not compute it again
|
|
|
|
* @param boolean $skip_notification = false do NOT send any notification
|
2010-10-26 11:21:52 +02:00
|
|
|
* @return int|boolean false on error, integer number of changes logged or true for new entries ($old == null)
|
|
|
|
*/
|
|
|
|
public function track(array $data,array $old=null,$user=null,$deleted=null,array $changed_fields=null,$skip_notification=false)
|
|
|
|
{
|
2012-05-08 14:38:32 +02:00
|
|
|
//error_log(__METHOD__.__LINE__.' notify?'.($skip_notification?'no':'yes').function_backtrace());
|
2010-10-26 11:21:52 +02:00
|
|
|
$this->user = !is_null($user) ? $user : $GLOBALS['egw_info']['user']['account_id'];
|
2010-05-14 18:50:49 +02:00
|
|
|
|
2010-10-26 11:21:52 +02:00
|
|
|
$changes = true;
|
2010-05-14 18:50:49 +02:00
|
|
|
|
2010-10-26 11:21:52 +02:00
|
|
|
if ($old && $this->field2history)
|
|
|
|
{
|
|
|
|
$changes = $this->save_history($data,$old,$deleted,$changed_fields);
|
|
|
|
}
|
2010-05-14 18:50:49 +02:00
|
|
|
|
|
|
|
// Don't notify if the only change was to the modified date
|
|
|
|
if(is_null($changed_fields))
|
|
|
|
{
|
|
|
|
$changed_fields = $this->changed_fields($data, $old);
|
2010-06-29 14:08:34 +02:00
|
|
|
$changes = count($changed_fields); // we need that since TRUE evaluates to 1
|
2010-05-14 18:50:49 +02:00
|
|
|
}
|
2012-05-08 14:38:32 +02:00
|
|
|
//error_log(__METHOD__.__LINE__.array2string($changed_fields));
|
2010-05-14 18:50:49 +02:00
|
|
|
if(is_array($changed_fields) && $changes == 1 && in_array('info_datemodified', $changed_fields))
|
|
|
|
{
|
|
|
|
return count($changes);
|
|
|
|
}
|
|
|
|
|
2010-06-29 14:08:34 +02:00
|
|
|
// do not run do_notifications if we have no changes
|
|
|
|
if ($changes && !$skip_notification && !$this->do_notifications($data,$old,$deleted))
|
|
|
|
{
|
|
|
|
$changes = false;
|
|
|
|
}
|
|
|
|
return $changes;
|
|
|
|
}
|
2010-05-14 18:50:49 +02:00
|
|
|
|
2011-03-08 20:18:07 +01:00
|
|
|
/**
|
|
|
|
* Get a notification-config value
|
|
|
|
*
|
2015-05-21 16:22:51 +02:00
|
|
|
* @param string $name
|
2011-03-08 20:18:07 +01:00
|
|
|
* - 'copy' array of email addresses notifications should be copied too, can depend on $data
|
|
|
|
* - 'lang' string lang code for copy mail
|
|
|
|
* - 'sender' string send email address
|
|
|
|
* @param array $data current entry
|
2015-05-21 16:22:51 +02:00
|
|
|
* @param array $old = null old/last state of the entry or null for a new entry
|
2011-03-08 20:18:07 +01:00
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
function get_config($name,$data,$old=null)
|
|
|
|
{
|
2014-01-28 11:02:11 +01:00
|
|
|
unset($old); // not used, but required function signature
|
2011-03-08 20:18:07 +01:00
|
|
|
switch($name)
|
|
|
|
{
|
|
|
|
case 'copy': // include the info_cc addresses
|
|
|
|
if ($data['info_access'] == 'private') return array(); // no copies for private entries
|
|
|
|
if ($data['info_cc'])
|
|
|
|
{
|
2014-01-28 11:02:11 +01:00
|
|
|
$config = preg_split('/, ?/',$data['info_cc']);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$config = array();
|
2011-03-08 20:18:07 +01:00
|
|
|
}
|
|
|
|
break;
|
2013-01-31 00:12:52 +01:00
|
|
|
case self::CUSTOM_NOTIFICATION:
|
2016-04-30 19:05:23 +02:00
|
|
|
$info_config = Api\Config::read('infolog');
|
2013-01-31 00:12:52 +01:00
|
|
|
if(!$info_config[self::CUSTOM_NOTIFICATION])
|
|
|
|
{
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
// Per-type notification
|
2014-01-28 11:02:11 +01:00
|
|
|
$type_config = $info_config[self::CUSTOM_NOTIFICATION][$data['info_type']];
|
2013-01-31 20:39:01 +01:00
|
|
|
$global = $info_config[self::CUSTOM_NOTIFICATION]['~global~'];
|
|
|
|
|
|
|
|
// Disabled
|
2014-01-28 11:02:11 +01:00
|
|
|
if(!$type_config['use_custom'] && !$global['use_custom']) return '';
|
2013-01-31 20:39:01 +01:00
|
|
|
|
|
|
|
// Type or globabl
|
2014-01-28 11:02:11 +01:00
|
|
|
$config = trim(strip_tags($type_config['message'])) != '' && $type_config['use_custom'] ? $type_config['message'] : $global['message'];
|
2013-01-31 00:12:52 +01:00
|
|
|
break;
|
2011-03-08 20:18:07 +01:00
|
|
|
}
|
|
|
|
return $config;
|
|
|
|
}
|
2009-11-23 17:15:16 +01:00
|
|
|
}
|