This commit is contained in:
Ralf Becker 2007-05-28 21:17:15 +00:00
parent f6552713ca
commit f2fb5fad4b
6 changed files with 1038 additions and 127 deletions

View File

@ -0,0 +1,621 @@
<?php
/**
* eGroupWare - abstract base class for tracking (history log, notifications, ...)
*
* @link http://www.egroupware.org
* @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
* @package etemplate
* @subpackage api
* @copyright (c) 2007 by Ralf Becker <RalfBecker-AT-outdoor-training.de>
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
* @version $Id$
*/
/**
* Abstract base class for trackering:
* - logging all modifications of an entry
* - notifying users about changes in an entry
*
* You need to extend these class in your application:
* 1. set the required class-vars: app, id_field
* 2. optional set class-vars: creator_field, assigned_field, check2prefs
* 3. implement the required methods: get_config, get_details
* 4. optionally re-implement: get_subject, get_body, get_attachments, get_link, get_message
* They are all documented in this file via phpDocumentor comments.
*/
class bo_tracking
{
/**
* Application we are tracking
*
* @var string
*/
var $app;
/**
* Name of the id-field, used as id in the history log (required!)
*
* @var string
*/
var $id_field;
/**
* Name of the field with the creator id, if the creator of an entry should be notified
*
* @var string
*/
var $creator_field;
/**
* Name of the field with the id(s) of assinged users, if they should be notified
*
* @var string
*/
var $assigned_field;
/**
* Can be used to map the following prefs to different names:
* - notify_creator - user wants to be notified for items he created
* - notify_assigned - user wants to be notified for items assigned to him
* - notify_html - user wants his notifications as html-email
* @var array
*/
var $check2pref;
/**
* Translate field-name to 2-char history status
*
* @var array
*/
var $field2history = array();
/**
* Should the user (passed to the track method or current user if not passed) be used as sender or get_config('sender')
*
* @var boolean
*/
var $prefer_user_as_sender = true;
/**
* Array with error-messages if track($data,$old) returns false
*
* @var array
*/
var $errors = array();
/**
* instance of the historylog object for the app we are tracking
*
* @access private
* @var historylog
*/
var $historylog;
/**
* Current user, can be set via bo_tracking::track(,,$user)
*
* @access private
* @var int;
*/
var $user;
/**
* Saved user preferences, if send_notifications need to set an other language
*
* @access private
* @var array
*/
var $save_prefs;
/**
* Datetime format of the currently notified user (send_notificaton)
*
* @var string
*/
var $datetime_format;
/**
* Offset to server-time of the currently notified user (send_notificaton)
*
* @var int
*/
var $tz_offset_s;
/**
* Get a config value, which can depend on $data and $old
*
* Need to be implemented in your extended tracking class!
*
* @abstract
* @param string $what possible values are:
* - 'copy' array of email addresses notifications should be copied too, can depend on $data
* - 'lang' string lang code for copy mail
* - 'subject' string subject line for the notification of $data,$old, defaults to link-title
* @param array $data current entry
* @param array $old=null old/last state of the entry or null for a new entry
* @return mixed
*/
function get_config($name,$data,$old=null)
{
die('You need to extend the bo_tracking class, to be able to use it (abstract base class)!');
}
/**
* Tracks the changes in one entry $data, by comparing it with the last version in $old
*
* @param array $data current entry
* @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
* @return int/boolean false on error, integer number of changes logged or true for new entries ($old == null)
*/
function track($data,$old=null,$user=null)
{
$this->user = !is_null($user) ? $user : $GLOBALS['egw_info']['user']['account_id'];
$changes = true;
if ($old)
{
$changes = $this->save_history($data,$old);
}
if (!$this->do_notifications($data,$old))
{
$changes = false;
}
return $changes;
}
/**
* Save changes to the history log
*
* @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 int number of log-entries made
*/
function save_history($data,$old)
{
$changes = 0;
foreach($this->field2history as $name => $status)
{
if ($old[$name] != $data[$name])
{
if (!is_object($this->historylog))
{
require_once(EGW_API_INC.'/class.historylog.inc.php');
$this->historylog =& new historylog($this->app);
}
$this->historylog->add($status,$data[$this->id_field],$data[$name],$old[$name]);
++$changes;
}
}
return $changes;
}
/**
* sending all notifications for the changed entry
*
* @internal use only track($data,$old,$user)
* @param array $data current entry
* @param array $old=null old/last state of the entry or null for a new entry
* @return boolean true on success, false on error (error messages are in $this->errors)
*/
function do_notifications($data,$old)
{
$this->errors = $email_sent = array();
// entry creator
if ($this->creator_field && ($email = $GLOBALS['egw']->accounts->id2name($data[$this->creator_field],'account_email')) &&
!in_array($email, $email_sent))
{
$this->send_notification($data,$old,$email,$data[$this->creator_field],'notify_creator');
$email_sent[] = $email;
}
// assigned / responsible users
if ($this->assigned_field)
{
$assignees = $old_assignees = array();
if ($data[$this->assigned_field]) // current assignments
{
$assignees = is_array($data[$this->assigned_field]) ?
$data[$this->assigned_field] : explode(',',$data[$this->assigned_field]);
}
if ($old && $old[$this->assigned_field])
{
$old_assignees = is_array($old[$this->assigned_field]) ?
$old[$this->assigned_field] : explode(',',$old[$this->assigned_field]);
}
foreach(array_unique(array_merge($assignees,$old_assignees)) as $assignee)
{
if (!$assignee) continue;
// item assignee is a user
if ($GLOBALS['egw']->accounts->get_type($assignee) == 'u')
{
if (($email = $GLOBALS['egw']->accounts->id2name($assignee,'account_email')) && !in_array($email, $email_sent))
{
$this->send_notification($old,$email,$data['tr_assigned'],'notify_assigned');
$email_sent[] = $email;
}
}
else // item assignee is a group
{
foreach($GLOBALS['egw']->accounts->members($assignee,true) as $u)
{
if ($email = $GLOBALS['egw']->accounts->id2name($u,'account_email') && !in_array($email, $email_sent))
{
$this->send_notification($old,$email,$u,'notify_assigned');
$email_sent[] = $email;
}
}
}
}
}
// notification copies
if (($copies = $this->get_config('copy',$data,$old)))
{
$lang = $this->get_config('lang',$data,$old);
foreach($copies as $email)
{
if (strchr($email,'@') !== false && !in_array($email, $email_sent))
{
$this->send_notification($data,$old,$email,$lang,'notify_copy');
$email_sent[] = $email;
}
}
}
// restore the user enviroment
if ($this->save_prefs) $GLOBALS['egw_info']['user'] = $this->save_prefs; unset($this->save_prefs);
if ($GLOBALS['egw_info']['user']['preferences']['common']['lang'] != $GLOBALS['egw']->translation->userlang)
{
$GLOBALS['egw']->translation->init();
}
return !count($this->errors);
}
/**
* Send a popup notification via the notification app
*
* @param int $user
* @param string $message
* @return boolean true on success, false on error
*/
function popup_notification($user,$message)
{
static $is_php51;
if (is_null($is_php51)) $is_php51 = version_compare(phpversion(),'5.1.0','>=');
if (!$is_php51) return false;
// check if the to notifying user has rights to run the notifcation app
$ids = $GLOBALS['egw']->accounts->memberships($user,true);
$ids[] = $user;
if (!$GLOBALS['egw']->acl->get_specific_rights_for_account($ids,'run','notifications')) return false;
if (!include_once(EGW_INCLUDE_ROOT. '/notifications/inc/class.notification.inc.php')) return false;
return is_null(notify(array($user),$message)); // return the exeception on error
}
/**
* Sending a notification to the given email-address
*
* @internal use only track($data,$old,$user)
* @param array $data current entry
* @param array $old=null old/last state of the entry or null for a new entry
* @param string $email address to send the notification to
* @param string $user_or_lang='en' user-id or 2 char lang-code for a non-system user
* @param string $check=null pref. to check if a notification is wanted
* @return boolean true on success or false on error (error-message is in $this->errors)
*/
function send_notification($data,$old,$email,$user_or_lang,$check=null)
{
if (!$email) return false;
//echo "<p>botracker::send_notification(,'$email',$user_or_lang)</p>\n";
//echo "old"; _debug_array($old);
//echo "data"; _debug_array($data);
if (!$this->save_prefs) $this->save_prefs = $GLOBALS['egw_info']['user'];
if (is_numeric($user_or_lang)) // user --> read everything from his prefs
{
if ($user_or_lang != $this->user)
{
$GLOBALS['egw']->preferences->preferences($user_or_lang);
$GLOBALS['egw_info']['user']['preferences'] = $GLOBALS['egw']->preferences->read_repository();
}
if ($check && !$GLOBALS['egw_info']['user']['preferences'][$this->app][$this->check2pref ? $this->check2pref[$check] : $check])
{
return false; // no notification requested
}
// notification via notification app.
$this->popup_notification($user_or_lang,$this->get_subject($data,$old));
}
else
{
// for the notification copy, we use the default-prefs plus the language from the the tracker config
$GLOBALS['egw_info']['user']['preferences'] = $GLOBALS['egw']->preferences->default;
$GLOBALS['egw_info']['user']['preferences']['common']['lang'] = $user_or_lang;
}
$this->datetime_format = $GLOBALS['egw_info']['user']['preferences']['common']['dateformat'].' '.
($GLOBALS['egw_info']['user']['preferences']['common']['timeformat'] != 12 ? 'H:i' : 'h:i a');
$this->tz_offset_s = 3600 * $GLOBALS['egw_info']['user']['preferences']['common']['tz_offset'];
if ($lang != $GLOBALS['egw']->translation->userlang) // load the right language if needed
{
$GLOBALS['egw']->translation->init();
}
// PHPMailer aka send-class, seems not to be able to send more then one mail, IF we need to authenticate to the SMTP server
// There for the object is newly created for ever mail, 'til this get fixed in PHPMailer.
//if(!is_object($GLOBALS['egw']->send))
{
require_once(EGW_API_INC.'/class.send.inc.php');
$GLOBALS['egw']->send = $send =& new send();
}
//$send = &$GLOBALS['egw']->send;
$send->ClearAddresses();
$send->ClearAttachments();
// does the user wants html-emails
$html_email = !!$GLOBALS['egw_info']['user']['preferences']['tracker'][$this->check2pref ? $this->check2pref['notify_html'] : 'notify_html'];
$send->IsHTML($html_email);
if (preg_match('/^(.+) *<(.+)>/',$email,$matches)) // allow to use eg. "Ralf Becker <ralf@egw.org>" as address
{
$send->AddAddress($matches[2],$matches[1]);
}
else
{
$send->AddAddress($email,is_numeric($user_or_lang) ? $GLOBALS['egw']->accounts->id2name($user_or_lang,'account_fullname') : '');
}
$send->AddCustomHeader("X-eGroupWare-type: {$this->app}update");
$sender = $this->get_sender($user,$data,$old);
if (preg_match('/^(.+) *<(.+)>/',$sender,$matches)) // allow to use eg. "Ralf Becker <ralf@egw.org>" as sender
{
$send->From = $matches[2];
$send->FromName = $matches[1];
}
else
{
$send->From = $sender;
$send->FromName = '';
}
$send->Subject = $this->get_subject($data,$old);
$send->Body = $this->get_body($html_email,$data,$old);
foreach($this->get_attachments($data,$old) as $attachment)
{
if (isset($attachment['content']))
{
$send->AddStringAttachment($attachment['content'],$attachment['filename'],$attachment['encoding'],$attachment['mimetype']);
}
elseif (isset($attachment['path']))
{
$send->AddAttachment($attachment['path'],$attachment['filename'],$attachment['encoding'],$attachment['$mimetype']);
}
}
if (!$send->Send())
{
$this->errors[] = lang('Error while notifying %1: %2',$email,$send->ErrorInfo);
return false;
}
return true;
}
/**
* Return date+time formatted for the currently notified user (send_notification)
*
* @param int $timestamp
* @return string
*/
function datetime($timestamp)
{
return date($this->datetime_format,$timestamp+$this->tz_offset_s);
}
/**
* Get sender address
*
* @param array $data
* @param array $old
* @return string
*/
function get_sender($data,$old)
{
if ($this->prefer_user_as_sender && $this->user && ($email = $GLOBALS['egw']->accounts->id2name($this->user,'account_email')))
{
$name = $GLOBALS['egw']->accounts->id2name($this->user,'account_fullname');
return $name ? $name.' <'.$email.'>' : $email;
}
if (($sender = $this->get_config('sender',$data,$old)))
{
return $sender;
}
return 'eGroupWare '.lang($this->app).' <noreply@'.$GLOBALS['egw_info']['server']['mail_suffix'];
}
/**
* Get the subject for a given entry, can be reimplemented
*
* Default implementation uses the link-title
*
* @param array $data
* @param array $old
* @return string
*/
function get_subject($data,$old)
{
if (!is_object($GLOBALS['egw']->link))
{
require_once(EGW_API_INC.'/class.bolink.inc.php');
$GLOBALS['egw']->link =& new bolink();
}
return $GLOBALS['egw']->link->title($this->app,$data[$this->id_field]);
}
/**
* Get the modified / new message (1. line of mail body) for a given entry, can be reimplemented
*
* Default implementation does nothing
*
* @param array $data
* @param array $old
* @return string
*/
function get_message($data,$old)
{
return '';
}
/**
* Get a link to view the entry, can be reimplemented
*
* Default implementation checks get_config('link') (appending the id) or link::view($this->app,$id)
*
* @param array $data
* @param array $old
* @return string
*/
function get_link($data,$old)
{
if (($link = $this->get_config('link',$data,$old)))
{
if (strpos($link,$this->id_field.'=') === false)
{
$link .= '&'.$this->id_field.'='.$data[$this->id_field];
}
}
elseif (($view = $GLOBALS['egw']->link->view($this->app,$data[$this->id_field])))
{
$link = preg_replace('/(sessionid|kp3|domain)=[^&]+&?/','',$GLOBALS['egw']->link('/index.php',$view));
if ($link{0} == '/')
{
$link = ($_SERVER['HTTPS'] || $GLOBALS['egw_info']['server']['enforce_ssl'] ? 'https://' : 'http://').
($GLOBALS['egw_info']['server']['hostname'] ? $GLOBALS['egw_info']['server']['hostname'] : $_SERVER['HTTP_HOST']).$link;
}
if ($GLOBALS['egw']->link->is_popup($this->app,'view')) $link .= '&nopopup=1';
}
return $link;
}
/**
* Get the body of the notification message, can be reimplemented
*
* @param boolean $html_email
* @param array $data
* @param array $old
* @return string
*/
function get_body($html_email,$data,$old)
{
$body = '';
if ($html_email)
{
$body = "<html>\n<body>\n".'<table cellspacing="2" cellpadding="0" border="0" width="100%">'."\n";
}
// new or modified message
if (($message = $this->get_message($data,$old)))
{
$body .= $this->format_line($html_email,'message',false,$message);
}
if (($link = $this->get_link($data,$old)))
{
$body .= $this->format_line($html_email,'link',false,lang('You can respond by visiting:'),$link);
}
foreach($this->get_details($data) as $name => $detail)
{
$modified = $old && $data[$name] != $old[$name];
if ($modified) error_log("data[$name]='{$data[$name]}', old[$name]='{$old[$name]}' --> modified=".(int)$modified);
if (empty($detail['value']) && !$modified) continue; // skip unchanged, empty values
$body .= $this->format_line($html_email,$detail['type'],$modified,
($detail['label'] ? $detail['label'].': ':'').$detail['value']);
}
if ($html_email)
{
$body .= "</table>\n</body>\n</html>\n";
}
return $body;
}
/**
* Format one line to the mail body
*
* @internal
* @param boolean $html_mail
* @param string $type 'link', 'message', 'summary', 'multiline', 'reply' and ''=regular content
* @param boolean $modified mark field as modified
* @param string $line
* @param string $link=null
* @return string
*/
function format_line($html_mail,$type,$modified,$line,$link=null)
{
$content = '';
if ($html_mail)
{
$color = $modified ? 'red' : false;
$size = 'small';
$bold = false;
$background = '#FFFFF1';
switch($type)
{
case 'message':
$background = '#D3DCE3;';
$bold = true;
break;
case 'link':
$background = '#F1F1F1';
break;
case 'summary':
$background = '#F1F1F1';
$bold = true;
break;
case 'multiline':
$line = nl2br($line);
break;
case 'reply':
$background = '#F1F1F1';
break;
default:
$size = 'x-small';
}
$style = ($bold ? 'font-weight:bold;' : '').($size ? 'font-size:'.$size.';' : '').($color?'color:'.$color:'');
$content = '<tr style="background-color: '.$background.';"><td style="'.$style.'">';
}
else // text-mail
{
if ($type == 'reply') $content = str_repeat('-',64)."\n";
if ($modified) $content .= '> ';
}
$content .= $line;
if ($link)
{
$content .= ' ';
if ($html_mail) $content .= '<a href="'.$link.'" target="_blank">';
$content .= $link;
if ($html_mail) $content .= '</a>';
}
if ($html_mail) $content .= '</td></tr>';
$content .= "\n";
return $content;
}
/**
* Get the attachments for a notificaton mail
*
* @param array $data
* @param array $old
* @return array with values for either 'content' or 'path' and optionally 'mimetype', 'filename' and 'encoding'
*/
function get_attachments($data,$old)
{
return array();
}
}

View File

@ -105,6 +105,12 @@ class boinfolog
* @var array * @var array
*/ */
var $group_owners=array(); var $group_owners=array();
/**
* Current user
*
* @var int
*/
var $user;
/** /**
* Constructor Infolog BO * Constructor Infolog BO
@ -606,10 +612,10 @@ class boinfolog
{ {
if ($to_write[$time]) $to_write[$time] -= $this->tz_offset_s; if ($to_write[$time]) $to_write[$time] -= $this->tz_offset_s;
} }
// if we have links in customfields, we need to get the old values, to be able to remove changed links // we need to get the old values to update the links in customfields and for the tracking
if ($this->has_customfields($values['info_type'],true) && $values['info_id']) if ($values['info_id'])
{ {
$old = $this->read($values['info_id']); $old = $this->read($values['info_id'],false);
} }
if(($info_id = $this->so->write($to_write,$check_modified))) if(($info_id = $this->so->write($to_write,$check_modified)))
{ {
@ -640,6 +646,14 @@ class boinfolog
// notify the link-class about the update, as other apps may be subscribt to it // notify the link-class about the update, as other apps may be subscribt to it
$this->link->notify_update('infolog',$info_id,$values); $this->link->notify_update('infolog',$info_id,$values);
// send email notifications and do the history logging
require_once(EGW_INCLUDE_ROOT.'/infolog/inc/class.infolog_tracking.inc.php');
if (!is_object($this->tracking))
{
$this->tracking =& new infolog_tracking($this);
}
$this->tracking->track($values,$old,$this->user);
} }
if ($info_from_set) $values['info_from'] = ''; if ($info_from_set) $values['info_from'] = '';

View File

@ -0,0 +1,226 @@
<?php
/**
* InfoLog - history and notifications
*
* @link http://www.egroupware.org
* @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
* @package tracker
* @copyright (c) 2007 by Ralf Becker <RalfBecker-AT-outdoor-training.de>
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
* @version $Id$
*/
require_once(EGW_INCLUDE_ROOT.'/etemplate/inc/class.bo_tracking.inc.php');
/**
* Tracker - tracking object for the tracker
*/
class infolog_tracking extends bo_tracking
{
/**
* 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
*/
var $field2history = array();
/**
* Translate field-names to labels
*
* @var array
*/
var $field2label = array(
'info_type' => 'Type',
'info_from' => 'Contact',
'info_addr' => 'Phone/Email',
'info_cat' => 'Category',
'info_priority' => 'Priority',
'info_owner' => 'Owner',
'info_status' => 'Status',
'info_percent' => 'Completed',
'info_datecompleted' => 'Date completed',
'info_location' => 'Location',
'info_startdate' => 'Startdate',
'info_enddate' => 'Enddate',
'info_responsible' => 'Responsible',
'info_subject' => 'Subject',
);
/**
* Instance of the boinfolog class calling us
*
* @access private
* @var boinfolog
*/
var $infolog;
/**
* Constructor
*
* @param botracker $botracker
* @return tracker_tracking
*/
function infolog_tracking(&$boinfolog)
{
$this->infolog =& $boinfolog;
}
/**
* Tracks the changes in one entry $data, by comparing it with the last version in $old
*
* Reimplemented to fix some fields, who otherwise allways show up as modified
*
* @param array $data current entry
* @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
* @return int/boolean false on error, integer number of changes logged or true for new entries ($old == null)
*/
function track($data,$old=null,$user=null)
{
if ($old)
{
foreach($this->infolog->timestamps as $name)
{
if (!$old[$name]) $old[$name] = '';
}
}
return parent::track($data,$old,$user);
}
/**
* 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
*/
function get_config($name,$data,$old)
{
return null;
}
/**
* Get the modified / new message (1. line of mail body) for a given entry, can be reimplemented
*
* @param array $data
* @param array $old
* @return array/string array(message,user-id,timestamp-in-servertime) or string
*/
function get_message($data,$old)
{
if (!$data['info_datemodified'] || !$old)
{
return lang('New %1 created by %2 at %3',lang($this->infolog->enums['type'][$data['info_type']]),
$GLOBALS['egw']->common->grab_owner_name($this->infolog->user),$this->datetime(time()));
}
return lang('%1 modified by %2 at %3',lang($this->infolog->enums['type'][$data['info_type']]),
$GLOBALS['egw']->common->grab_owner_name($data['info_modifier']),
$this->datetime($data['info_datemodified']-$this->infolog->tz_offset_s));
}
/**
* Get the details of an entry
*
* @param array $data
* @param string $datetime_format of user to notify, eg. 'Y-m-d H:i'
* @param int $tz_offset_s offset in sec to be add to server-time to get the user-time of the user to notify
* @return array of details as array with values for keys 'label','value','type'
*/
function get_details($data)
{
$responsible = array();
if ($data['info_responsible'])
{
foreach($data['info_responsible'] as $uid)
{
$responsible[] = $GLOBALS['egw']->common->grab_owner_name($uid);
}
}
if ($data['info_cat'] && !is_object($GLOBALS['egw']->categories))
{
require_once(EGW_API_INC.'/class.categories.inc.php');
$GLOBALS['egw']->categories =& new categories($this->infolog->user,'infolog');
}
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_addr' => $data['info_addr'],
'info_cat' => $data['info_cat'] ? $GLOBALS['egw']->categories->id2name($data['info_cat']) : '',
'info_priority' => lang($this->infolog->enums['priority'][$data['info_priority']]),
'info_owner' => $GLOBALS['egw']->common->grab_owner_name($data['info_owner']),
'info_status' => lang($this->infolog->status[$data['info_type']][$data['info_status']]),
'info_percent' => (int)$data['info_percent'].'%',
'info_datecompleted' => $data['info_datecomplete'] ? $this->datetime($data['info_datecompleted']-$this->infolog->tz_offset_s) : '',
'info_location' => $data['info_location'],
'info_startdate' => $data['info_startdate'] ? $this->datetime($data['info_startdate']-$this->infolog->tz_offset_s) : '',
'info_enddate' => $data['info_enddate'] ? $this->datetime($data['info_enddate']-$this->infolog->tz_offset_s) : '',
'info_responsible' => implode(', ',$responsible),
'info_subject' => $data['info_subject'],
) as $name => $value)
{
$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',
);
// should be moved to bo_tracking because auf the different custom field types
if ($this->infolog->customfields)
{
foreach($this->infolog->customfields as $name => $field)
{
if ($field['type2'] && $field['type2'] != $data['info_type']) continue; // different type
if (!$header_done)
{
$details['custom'] = array(
'value' => lang('Custom fields').':',
'type' => 'reply',
);
$header_done = true;
}
$details[$name] = array(
'label' => $field['label'],
'value' => $data['#'.$name],
);
}
}
return $details;
}
}

View File

@ -130,3 +130,29 @@
unset($show_details); unset($show_details);
unset($filters); unset($filters);
unset($show_links); unset($show_links);
// notification preferences
$GLOBALS['settings']['notify_creator'] = array(
'type' => 'check',
'label' => 'Receive notifications about own items',
'name' => 'notify_creator',
'help' => 'Do you want a notification mail, if items you created get updated?',
'xmlrpc' => True,
'admin' => False,
);
$GLOBALS['settings']['notify_assigned'] = array(
'type' => 'check',
'label' => 'Receive notifications about items assigned to you',
'name' => 'notify_assigned',
'help' => 'Do you want a notification mails, if items get assigned to you or assigned items get updated?',
'xmlrpc' => True,
'admin' => False,
);
$GLOBALS['settings']['notify_html'] = array(
'type' => 'check',
'label' => 'Receive notifications as html-mails',
'name' => 'notify_html',
'help' => 'Do you want to receive notifications as html-mails or plain text?',
'xmlrpc' => True,
'admin' => False,
);

View File

@ -126,3 +126,25 @@ final class notification {
} }
} }
/**
* Small helper function to just send a message
*
* @param array $receivers
* @param string $message
* @return Exception
*/
function notify(array $receivers,$message)
{
$notification = new notification();
$notification->set_receivers($receivers);
$notification->set_message($message);
try{
$notification->send();
}
catch(Exception $exception) {
error_log("notify(array($user),'$message'".$exception->getMessage());
return $exception;
}
return null;
}

View File

@ -68,10 +68,12 @@ class notification_popup implements iface_notification {
// If we are called from class notification account and prefs are objects. // If we are called from class notification account and prefs are objects.
// otherwise we have to fetch this objects for current user. // otherwise we have to fetch this objects for current user.
if (!is_object($_account)) { if (!is_object($_account)) {
$account_id = $GLOBALS['egw_info']['user']['account_id']; $_account = (object) $GLOBALS['egw']->accounts->read($_account);
$this->account = $GLOBALS['egw']->accounts->get_account_data($account_id); $_account->id =& $_account->account_id;
$this->account[$account_id]['id'] = $account_id; // $account_id = $GLOBALS['egw_info']['user']['account_id'];
$this->account = (object)$this->account[$account_id]; // $this->account = $GLOBALS['egw']->accounts->get_account_data($account_id);
// $this->account[$account_id]['id'] = $account_id;
// $this->account = (object)$this->account[$account_id];
} }
else { else {
$this->account = $_account; $this->account = $_account;
@ -94,7 +96,7 @@ class notification_popup implements iface_notification {
$user_sessions[] = $session['session_id']; $user_sessions[] = $session['session_id'];
} }
} }
if ( empty($user_sessions) ) throw new Exception("Notice: User $this->account isn't online. Can't send notification via popup"); if ( empty($user_sessions) ) throw new Exception("Notice: User #{$this->account->id} isn't online. Can't send notification via popup");
$this->save( $_message, $user_sessions ); $this->save( $_message, $user_sessions );
} }