2007-06-06 10:18:45 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Addressbook - history and notifications
|
|
|
|
*
|
|
|
|
* @link http://www.egroupware.org
|
|
|
|
* @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
|
2007-06-17 15:55:43 +02:00
|
|
|
* @package addressbook
|
2007-06-06 10:18:45 +02:00
|
|
|
* @copyright (c) 2007 by Ralf Becker <RalfBecker-AT-outdoor-training.de>
|
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
2008-05-10 14:02:49 +02:00
|
|
|
* @version $Id$
|
2007-06-06 10:18:45 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Addressbook - tracking object
|
|
|
|
*/
|
|
|
|
class addressbook_tracking extends bo_tracking
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Application we are tracking (required!)
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
var $app = 'addressbook';
|
|
|
|
/**
|
|
|
|
* Name of the id-field, used as id in the history log (required!)
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
var $id_field = 'id';
|
|
|
|
/**
|
|
|
|
* Name of the field with the creator id, if the creator of an entry should be notified
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
var $creator_field = 'creator';
|
|
|
|
/**
|
|
|
|
* Name of the field with the id(s) of assinged users, if they should be notified
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
var $assigned_field;
|
|
|
|
/**
|
|
|
|
* Translate field-name to 2-char history status
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
var $field2history = array(
|
|
|
|
);
|
2010-02-12 17:47:15 +01:00
|
|
|
|
2007-06-06 10:18:45 +02:00
|
|
|
/**
|
|
|
|
* Should the user (passed to the track method or current user if not passed) be used as sender or get_config('sender')
|
|
|
|
*
|
|
|
|
* @var boolean
|
|
|
|
*/
|
2010-02-19 00:32:25 +01:00
|
|
|
var $prefer_user_as_sender = false;
|
2007-06-06 10:18:45 +02:00
|
|
|
/**
|
|
|
|
* Instance of the bocontacts class calling us
|
2008-05-10 14:02:49 +02:00
|
|
|
*
|
2007-06-06 10:18:45 +02:00
|
|
|
* @access private
|
2011-04-19 17:03:58 +02:00
|
|
|
* @var addressbook_bo
|
2007-06-06 10:18:45 +02:00
|
|
|
*/
|
|
|
|
var $contacts;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*
|
2011-04-19 17:03:58 +02:00
|
|
|
* @param addressbook_bo $bocontacts
|
2007-06-06 10:18:45 +02:00
|
|
|
* @return tracker_tracking
|
|
|
|
*/
|
2011-04-19 17:03:58 +02:00
|
|
|
function __construct(addressbook_bo $bocontacts)
|
2007-06-06 10:18:45 +02:00
|
|
|
{
|
2011-04-19 17:03:58 +02:00
|
|
|
$this->contacts = $bocontacts;
|
2010-02-08 18:53:47 +01:00
|
|
|
|
2010-04-16 18:06:37 +02:00
|
|
|
if (is_object($bocontacts->somain) && is_array($bocontacts->somain->db_cols))
|
2010-02-09 22:56:39 +01:00
|
|
|
{
|
2010-02-08 18:53:47 +01:00
|
|
|
$this->field2history = array_combine($bocontacts->somain->db_cols, $bocontacts->somain->db_cols);
|
2011-04-19 17:03:58 +02:00
|
|
|
|
|
|
|
// no need to store these
|
2010-02-08 18:53:47 +01:00
|
|
|
unset($this->field2history['modified']);
|
|
|
|
unset($this->field2history['modifier']);
|
|
|
|
unset($this->field2history['etag']);
|
2012-02-10 22:30:48 +01:00
|
|
|
unset($this->field2history['creator']);
|
2012-07-31 18:18:46 +02:00
|
|
|
unset($this->field2history['created']);
|
2012-02-10 22:30:48 +01:00
|
|
|
unset($this->field2history['tz']);
|
2011-04-19 17:03:58 +02:00
|
|
|
|
|
|
|
// we currently can only track text
|
2010-04-22 17:39:32 +02:00
|
|
|
unset($this->field2history['jpegphoto']);
|
2010-02-08 18:53:47 +01:00
|
|
|
}
|
2011-04-19 17:03:58 +02:00
|
|
|
// custom fields are now handled by parent::__construct('addressbook')
|
|
|
|
parent::__construct('addressbook');
|
2007-06-06 10:18:45 +02:00
|
|
|
}
|
2008-05-10 14:02:49 +02:00
|
|
|
|
2007-06-06 10:18:45 +02:00
|
|
|
/**
|
|
|
|
* Get a notification-config value
|
|
|
|
*
|
|
|
|
* @param string $what
|
|
|
|
* - '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
|
|
|
|
* @param array $old=null old/last state of the entry or null for a new entry
|
|
|
|
* @return mixed
|
|
|
|
*/
|
2008-11-08 11:37:52 +01:00
|
|
|
function get_config($name,$data,$old=null)
|
2007-06-06 10:18:45 +02:00
|
|
|
{
|
|
|
|
//echo "<p>addressbook_tracking::get_config($name,".print_r($data,true).",...)</p>\n";
|
|
|
|
switch($name)
|
|
|
|
{
|
|
|
|
case 'copy':
|
|
|
|
if ($data['is_contactform'])
|
|
|
|
{
|
2009-09-28 21:22:45 +02:00
|
|
|
$copy = preg_split('/, ?/',$data['email_contactform']);
|
2009-09-29 09:54:11 +02:00
|
|
|
if ($data['email_copytoreceiver']) $copy[] = $data['email'];
|
2009-09-28 21:22:45 +02:00
|
|
|
return $copy;
|
2007-06-06 10:18:45 +02:00
|
|
|
}
|
|
|
|
break;
|
2008-05-10 14:02:49 +02:00
|
|
|
|
2007-06-06 10:18:45 +02:00
|
|
|
case 'sender':
|
|
|
|
if ($data['is_contactform'])
|
|
|
|
{
|
|
|
|
//echo "<p>addressbook_tracking::get_config($name,...) email={$data['email']}, n_given={$data['n_given']}, n_family={$data['n_family']}</p>\n";
|
|
|
|
return $data['email'] ? $data['n_given'].' '.$data['n_family'].' <'.$data['email'].'>' : null;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
2008-05-10 14:02:49 +02:00
|
|
|
|
2010-11-15 17:29:31 +01:00
|
|
|
/**
|
|
|
|
* Override changes to do some special handling of the text country field vs the country code
|
|
|
|
*
|
|
|
|
* If the country name was changed at all, use the translated name from the country code as the other value.
|
|
|
|
* Otherwise, use country code.
|
|
|
|
*
|
|
|
|
* @internal use only track($data,$old)
|
|
|
|
* @param array $data current entry
|
|
|
|
* @param array $old=null old/last state of the entry or null for a new entry
|
|
|
|
* @param boolean $deleted=null can be set to true to let the tracking know the item got deleted or undelted
|
|
|
|
* @param array $changed_fields=null changed fields from ealier call to $this->changed_fields($data,$old), to not compute it again
|
|
|
|
* @return int number of log-entries made
|
|
|
|
*/
|
|
|
|
protected function save_history(array $data,array $old=null,$deleted=null,array $changed_fields=null)
|
|
|
|
{
|
2011-04-19 17:03:58 +02:00
|
|
|
if (is_null($changed_fields))
|
|
|
|
{
|
|
|
|
$changed_fields = self::changed_fields($data,$old);
|
|
|
|
}
|
|
|
|
if (!$changed_fields) return 0;
|
|
|
|
|
2010-11-15 17:29:31 +01:00
|
|
|
foreach(array('adr_one_countryname' => 'adr_one_countrycode', 'adr_two_countryname' => 'adr_two_countrycode') as $name => $code)
|
|
|
|
{
|
|
|
|
// Only codes involved, but old text name is automatically added when loaded
|
2011-04-19 17:03:58 +02:00
|
|
|
if($old[$code] && $data[$code])
|
|
|
|
{
|
2010-11-15 17:29:31 +01:00
|
|
|
unset($changed_fields[array_search($name, $changed_fields)]);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Code and a text name
|
|
|
|
if(in_array($name, $changed_fields) && in_array($code, $changed_fields))
|
|
|
|
{
|
2011-04-19 17:03:58 +02:00
|
|
|
if($data[$code])
|
|
|
|
{
|
2010-11-15 17:29:31 +01:00
|
|
|
$data[$name] = $GLOBALS['egw']->country->get_full_name($data[$code], true);
|
|
|
|
}
|
|
|
|
unset($changed_fields[array_search($code, $changed_fields)]);
|
|
|
|
}
|
|
|
|
}
|
2011-05-17 10:02:29 +02:00
|
|
|
//error_log(__METHOD__.__LINE__.' ChangedFields:'.array2string($changed_fields));
|
|
|
|
return parent::save_history($data,$old,$deleted,$changed_fields);
|
2010-11-15 17:29:31 +01:00
|
|
|
}
|
|
|
|
|
2007-06-06 10:18:45 +02:00
|
|
|
/**
|
|
|
|
* Get the modified / new message (1. line of mail body) for a given entry, can be reimplemented
|
2008-05-10 14:02:49 +02:00
|
|
|
*
|
2007-06-06 10:18:45 +02:00
|
|
|
* @param array $data
|
|
|
|
* @param array $old
|
2012-05-16 14:39:52 +02:00
|
|
|
* @param int|string $receiver nummeric account_id or email address
|
2007-06-06 10:18:45 +02:00
|
|
|
* @return string
|
|
|
|
*/
|
2012-05-16 14:39:52 +02:00
|
|
|
protected function get_message($data,$old,$receiver=null)
|
2007-06-06 10:18:45 +02:00
|
|
|
{
|
|
|
|
if (!$data['modified'] || !$old)
|
|
|
|
{
|
|
|
|
return lang('New contact submitted by %1 at %2',
|
2010-02-04 13:08:03 +01:00
|
|
|
common::grab_owner_name($data['creator']),
|
|
|
|
$this->datetime($data['created']));
|
2007-06-06 10:18:45 +02:00
|
|
|
}
|
|
|
|
return lang('Contact modified by %1 at %2',
|
2010-02-04 13:08:03 +01:00
|
|
|
common::grab_owner_name($data['modifier']),
|
|
|
|
$this->datetime($data['modified']));
|
2007-06-06 10:18:45 +02:00
|
|
|
}
|
2008-05-10 14:02:49 +02:00
|
|
|
|
2007-06-06 10:18:45 +02:00
|
|
|
/**
|
|
|
|
* Get the subject of the notification
|
2008-05-10 14:02:49 +02:00
|
|
|
*
|
2007-06-06 10:18:45 +02:00
|
|
|
* @param array $data
|
|
|
|
* @param array $old
|
2012-05-16 14:39:52 +02:00
|
|
|
* @param boolean $deleted=null can be set to true to let the tracking know the item got deleted or undelted
|
|
|
|
* @param int|string $receiver nummeric account_id or email address
|
2007-06-06 10:18:45 +02:00
|
|
|
* @return string
|
|
|
|
*/
|
2012-05-16 14:39:52 +02:00
|
|
|
protected function get_subject($data,$old,$deleted=null,$receiver=null)
|
2007-06-06 10:18:45 +02:00
|
|
|
{
|
|
|
|
if ($data['is_contactform'])
|
|
|
|
{
|
|
|
|
$prefix = ($data['subject_contactform'] ? $data['subject_contactform'] : lang('Contactform')).': ';
|
|
|
|
}
|
2007-06-13 18:29:06 +02:00
|
|
|
return $prefix.$this->contacts->link_title($data);
|
2007-06-06 10:18:45 +02:00
|
|
|
}
|
2008-05-10 14:02:49 +02:00
|
|
|
|
2007-06-06 10:18:45 +02:00
|
|
|
/**
|
|
|
|
* Get the details of an entry
|
2008-05-10 14:02:49 +02:00
|
|
|
*
|
2012-05-16 14:39:52 +02:00
|
|
|
* @param array|object $data
|
|
|
|
* @param int|string $receiver nummeric account_id or email address
|
2007-06-06 10:18:45 +02:00
|
|
|
* @return array of details as array with values for keys 'label','value','type'
|
|
|
|
*/
|
2012-05-16 14:39:52 +02:00
|
|
|
function get_details($data,$receiver=null)
|
2007-06-06 10:18:45 +02:00
|
|
|
{
|
|
|
|
foreach($this->contacts->contact_fields as $name => $label)
|
|
|
|
{
|
|
|
|
if (!$data[$name] && $name != 'owner') continue;
|
|
|
|
|
|
|
|
switch($name)
|
|
|
|
{
|
|
|
|
case 'n_prefix': case 'n_given': case 'n_middle': case 'n_family': case 'n_suffix': // already in n_fn
|
2007-06-13 18:29:06 +02:00
|
|
|
case 'n_fileas': case 'id': case 'tid':
|
2007-06-06 10:18:45 +02:00
|
|
|
break;
|
|
|
|
case 'created': case 'modified':
|
|
|
|
$details[$name] = array(
|
|
|
|
'label' => $label,
|
2010-02-04 13:08:03 +01:00
|
|
|
'value' => $this->datetime($data[$name]),
|
2007-06-06 10:18:45 +02:00
|
|
|
);
|
|
|
|
break;
|
|
|
|
case 'bday':
|
|
|
|
if ($data[$name])
|
|
|
|
{
|
|
|
|
list($y,$m,$d) = explode('-',$data[$name]);
|
|
|
|
$details[$name] = array(
|
|
|
|
'label' => $label,
|
2010-02-04 13:08:03 +01:00
|
|
|
'value' => common::dateformatorder($y,$m,$d,true),
|
2007-06-06 10:18:45 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'owner': case 'creator': case 'modifier':
|
|
|
|
$details[$name] = array(
|
|
|
|
'label' => $label,
|
2010-02-04 13:08:03 +01:00
|
|
|
'value' => common::grab_owner_name($data[$name]),
|
2007-06-06 10:18:45 +02:00
|
|
|
);
|
|
|
|
break;
|
|
|
|
case 'cat_id':
|
|
|
|
if ($data[$name])
|
|
|
|
{
|
|
|
|
$cats = array();
|
|
|
|
foreach(is_array($data[$name]) ? $data[$name] : explode(',',$data[$name]) as $cat_id)
|
|
|
|
{
|
|
|
|
$cats[] = $GLOBALS['egw']->cats->id2name($cat_id);
|
|
|
|
}
|
|
|
|
$details[$name] = array(
|
|
|
|
'label' => $label,
|
|
|
|
'value' => explode(', ',$cats),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
case 'note':
|
|
|
|
$details[$name] = array(
|
|
|
|
'label' => $label,
|
|
|
|
'value' => $data[$name],
|
|
|
|
'type' => 'multiline',
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
$details[$name] = array(
|
|
|
|
'label' => $label,
|
|
|
|
'value' => $data[$name],
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-08-09 14:43:52 +02:00
|
|
|
// add custom fields for given type
|
|
|
|
$details += $this->get_customfields($data, $data['tid']);
|
|
|
|
|
2007-06-06 10:18:45 +02:00
|
|
|
return $details;
|
|
|
|
}
|
2010-02-12 17:47:15 +01:00
|
|
|
}
|