2007-12-18 16:53:38 +01:00
|
|
|
<?php
|
|
|
|
/**
|
2011-04-14 15:43:16 +02:00
|
|
|
* EGroupware - Notifications
|
2007-12-18 16:53:38 +01:00
|
|
|
*
|
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
|
|
|
* @package notifications
|
|
|
|
* @subpackage ajaxpopup
|
|
|
|
* @link http://www.egroupware.org
|
|
|
|
* @author Cornelius Weiss <nelius@cwtech.de>, Christian Binder <christian@jaytraxx.de>
|
2013-07-22 15:29:20 +02:00
|
|
|
* @version $Id$
|
2007-12-18 16:53:38 +01:00
|
|
|
*/
|
2009-04-28 22:24:05 +02:00
|
|
|
|
2007-12-18 16:53:38 +01:00
|
|
|
/**
|
|
|
|
* Ajax methods for notifications
|
|
|
|
*/
|
2009-04-03 22:36:28 +02:00
|
|
|
class notifications_ajax {
|
2007-12-18 16:53:38 +01:00
|
|
|
/**
|
|
|
|
* Appname
|
|
|
|
*/
|
|
|
|
const _appname = 'notifications';
|
2009-04-28 22:24:05 +02:00
|
|
|
|
2009-02-11 20:32:26 +01:00
|
|
|
/**
|
|
|
|
* Mailappname
|
|
|
|
*/
|
2014-05-13 17:02:07 +02:00
|
|
|
const _mailappname = 'mail';
|
2009-04-28 22:24:05 +02:00
|
|
|
|
2007-12-18 16:53:38 +01:00
|
|
|
/**
|
|
|
|
* Notification table in SQL database
|
|
|
|
*/
|
|
|
|
const _notification_table = 'egw_notificationpopup';
|
2009-04-28 22:24:05 +02:00
|
|
|
|
2012-12-09 06:56:42 +01:00
|
|
|
/**
|
|
|
|
* Notification type
|
|
|
|
*/
|
|
|
|
const _type = 'base';
|
|
|
|
|
2007-12-18 16:53:38 +01:00
|
|
|
/**
|
|
|
|
* holds account object for user to notify
|
|
|
|
*
|
|
|
|
* @var object
|
|
|
|
*/
|
|
|
|
private $recipient;
|
2009-04-28 22:24:05 +02:00
|
|
|
|
2007-12-18 16:53:38 +01:00
|
|
|
/**
|
|
|
|
* holds config object (sitewide application config)
|
|
|
|
*
|
|
|
|
* @var object
|
|
|
|
*/
|
|
|
|
private $config;
|
2009-04-28 22:24:05 +02:00
|
|
|
|
2007-12-18 16:53:38 +01:00
|
|
|
/**
|
2009-02-11 20:32:26 +01:00
|
|
|
* holds preferences array of user to notify
|
2007-12-18 16:53:38 +01:00
|
|
|
*
|
2009-02-11 20:32:26 +01:00
|
|
|
* @var array
|
2007-12-18 16:53:38 +01:00
|
|
|
*/
|
|
|
|
private $preferences;
|
2009-04-28 22:24:05 +02:00
|
|
|
|
2007-12-18 16:53:38 +01:00
|
|
|
/**
|
2008-03-22 13:34:27 +01:00
|
|
|
* reference to global db object
|
2007-12-18 16:53:38 +01:00
|
|
|
*
|
2011-04-14 11:50:35 +02:00
|
|
|
* @var egw_db
|
2007-12-18 16:53:38 +01:00
|
|
|
*/
|
|
|
|
private $db;
|
2009-04-28 22:24:05 +02:00
|
|
|
|
2009-02-11 20:32:26 +01:00
|
|
|
/**
|
|
|
|
* holds the users session data
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
var $session_data;
|
2009-04-28 22:24:05 +02:00
|
|
|
|
2009-02-11 20:32:26 +01:00
|
|
|
/**
|
|
|
|
* holds the users session data defaults
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
var $session_data_defaults = array(
|
|
|
|
'notified_mail_uids' => array(),
|
|
|
|
);
|
2009-04-28 22:24:05 +02:00
|
|
|
|
2009-02-11 20:32:26 +01:00
|
|
|
/**
|
|
|
|
* the xml response object
|
|
|
|
*
|
2013-08-25 17:14:19 +02:00
|
|
|
* @var egw_json_response
|
2009-02-11 20:32:26 +01:00
|
|
|
*/
|
|
|
|
private $response;
|
2009-04-28 22:24:05 +02:00
|
|
|
|
2007-12-18 16:53:38 +01:00
|
|
|
/**
|
2009-04-03 22:36:28 +02:00
|
|
|
* constructor
|
2007-12-18 16:53:38 +01:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
public function __construct() {
|
2013-08-25 17:14:19 +02:00
|
|
|
$this->response = egw_json_response::get();
|
2012-08-08 09:06:32 +02:00
|
|
|
$this->recipient = (object)$GLOBALS['egw']->accounts->read($GLOBALS['egw_info']['user']['account_id']);
|
2007-12-18 16:53:38 +01:00
|
|
|
|
2011-04-14 11:50:35 +02:00
|
|
|
$this->config = (object)config::read(self::_appname);
|
2007-12-18 16:53:38 +01:00
|
|
|
|
|
|
|
$prefs = new preferences($this->recipient->account_id);
|
2009-02-11 20:32:26 +01:00
|
|
|
$this->preferences = $prefs->read();
|
2007-12-18 16:53:38 +01:00
|
|
|
|
2008-03-22 13:34:27 +01:00
|
|
|
$this->db = $GLOBALS['egw']->db;
|
2007-12-18 16:53:38 +01:00
|
|
|
}
|
2009-04-28 22:24:05 +02:00
|
|
|
|
2007-12-18 16:53:38 +01:00
|
|
|
/**
|
2009-04-03 22:17:22 +02:00
|
|
|
* public AJAX trigger function to be called by the JavaScript client
|
|
|
|
*
|
|
|
|
* this function calls all other recurring AJAX notifications methods
|
|
|
|
* to have ONE single recurring AJAX call per user
|
2009-04-28 22:24:05 +02:00
|
|
|
*
|
2007-12-18 16:53:38 +01:00
|
|
|
* @return xajax response
|
|
|
|
*/
|
2015-10-19 10:07:00 +02:00
|
|
|
public function get_notifications($browserNotify = false)
|
|
|
|
{
|
|
|
|
// close session now, to not block other user actions, as specially mail checks can be time consuming
|
|
|
|
$GLOBALS['egw']->session->commit_session();
|
|
|
|
|
2014-01-10 10:19:07 +01:00
|
|
|
// call a hook for notifications on new mail
|
2014-05-13 17:02:07 +02:00
|
|
|
//if ($GLOBALS['egw_info']['user']['apps']['mail']) $this->check_mailbox();
|
2014-01-10 10:19:07 +01:00
|
|
|
$GLOBALS['egw']->hooks->process('check_notify');
|
2011-04-14 11:50:35 +02:00
|
|
|
|
|
|
|
// update currentusers
|
|
|
|
if ($GLOBALS['egw_info']['user']['apps']['admin'] &&
|
|
|
|
$GLOBALS['egw_info']['user']['preferences']['common']['show_currentusers'])
|
|
|
|
{
|
2011-06-08 11:14:17 +02:00
|
|
|
$this->response->jquery('#currentusers', 'text', array((string)$GLOBALS['egw']->session->session_count()));
|
2011-04-14 11:50:35 +02:00
|
|
|
}
|
|
|
|
|
2011-11-24 00:48:58 +01:00
|
|
|
$this->get_egwpopup($browserNotify);
|
2009-02-11 20:32:26 +01:00
|
|
|
}
|
2009-04-28 22:24:05 +02:00
|
|
|
|
2011-04-13 19:51:02 +02:00
|
|
|
/**
|
2011-04-14 11:50:35 +02:00
|
|
|
* Let the user confirm that they have seen the message.
|
2011-04-13 19:51:02 +02:00
|
|
|
* After they've seen it, remove it from the database
|
2011-04-14 15:43:16 +02:00
|
|
|
*
|
|
|
|
* @param int|array $notify_id one or more notify_id's
|
2011-04-13 19:51:02 +02:00
|
|
|
*/
|
2011-04-14 15:43:16 +02:00
|
|
|
public function confirm_message($notify_id)
|
|
|
|
{
|
|
|
|
if ($notify_id)
|
|
|
|
{
|
|
|
|
$this->db->delete(self::_notification_table,array(
|
|
|
|
'notify_id' => $notify_id,
|
2011-11-24 00:48:58 +01:00
|
|
|
'account_id' => $this->recipient->account_id,
|
2012-12-09 06:56:42 +01:00
|
|
|
'notify_type' => self::_type
|
2011-04-14 15:43:16 +02:00
|
|
|
),__LINE__,__FILE__,self::_appname);
|
|
|
|
}
|
2011-04-13 19:51:02 +02:00
|
|
|
}
|
|
|
|
|
2009-04-03 22:17:22 +02:00
|
|
|
/**
|
|
|
|
* gets all egwpopup notifications for calling user
|
2009-04-28 22:24:05 +02:00
|
|
|
*
|
2009-04-03 22:17:22 +02:00
|
|
|
* @return boolean true or false
|
|
|
|
*/
|
2011-11-24 00:48:58 +01:00
|
|
|
private function get_egwpopup($browserNotify = false) {
|
2009-04-03 22:17:22 +02:00
|
|
|
$message = '';
|
2011-04-14 15:43:16 +02:00
|
|
|
$rs = $this->db->select(self::_notification_table, '*', array(
|
2009-04-03 22:17:22 +02:00
|
|
|
'account_id' => $this->recipient->account_id,
|
2012-12-09 06:56:42 +01:00
|
|
|
'notify_type' => self::_type
|
2009-04-03 22:17:22 +02:00
|
|
|
),
|
|
|
|
__LINE__,__FILE__,false,'',self::_appname);
|
|
|
|
if ($rs->NumRows() > 0) {
|
|
|
|
foreach ($rs as $notification) {
|
2011-11-24 17:22:34 +01:00
|
|
|
$message = null;
|
2011-12-01 17:20:00 +01:00
|
|
|
if($browserNotify)
|
2011-11-24 00:48:58 +01:00
|
|
|
{
|
2011-11-24 17:22:34 +01:00
|
|
|
$message = $notification['notify_message'];
|
|
|
|
|
2011-11-24 00:48:58 +01:00
|
|
|
// Check for a link - doesn't work in notification
|
2011-11-24 17:22:34 +01:00
|
|
|
if(strpos($message, lang('Linked entries:')))
|
2011-11-24 00:48:58 +01:00
|
|
|
{
|
2011-11-24 17:22:34 +01:00
|
|
|
$message = substr_replace($message, '', strpos($message, lang('Linked entries:')));
|
2011-11-24 00:48:58 +01:00
|
|
|
}
|
2011-11-24 17:22:34 +01:00
|
|
|
$message = preg_replace('#</?a[^>]*>#is','',$message);
|
2012-08-08 09:06:32 +02:00
|
|
|
|
2011-11-28 17:15:21 +01:00
|
|
|
$message = 'data:text/html;charset=' . translation::charset() .';base64,'.base64_encode($message);
|
2011-11-24 00:48:58 +01:00
|
|
|
}
|
2013-09-05 00:52:43 +02:00
|
|
|
$this->response->apply('app.notifications.append',array($notification['notify_id'],$notification['notify_message'],$message));
|
2009-04-03 22:17:22 +02:00
|
|
|
}
|
2009-04-28 22:24:05 +02:00
|
|
|
|
2009-04-03 22:17:22 +02:00
|
|
|
switch($this->preferences[self::_appname]['egwpopup_verbosity']) {
|
|
|
|
case 'low':
|
2013-09-05 00:52:43 +02:00
|
|
|
$this->response->apply('app.notifications.bell', array('active'));
|
2009-04-03 22:17:22 +02:00
|
|
|
break;
|
|
|
|
case 'high':
|
2013-09-05 00:52:43 +02:00
|
|
|
$this->response->alert(lang('EGroupware has notifications for you'));
|
|
|
|
$this->response->apply('app.notifications.display');
|
2009-04-03 22:17:22 +02:00
|
|
|
break;
|
|
|
|
case 'medium':
|
|
|
|
default:
|
2013-09-05 00:52:43 +02:00
|
|
|
$this->response->apply('app.notifications.display');
|
2009-04-03 22:17:22 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
2009-02-11 20:32:26 +01:00
|
|
|
}
|
2009-04-28 22:24:05 +02:00
|
|
|
|
2009-02-11 20:32:26 +01:00
|
|
|
/**
|
|
|
|
* restores the users session data for notifications
|
2009-04-28 22:24:05 +02:00
|
|
|
*
|
2009-02-11 20:32:26 +01:00
|
|
|
* @return boolean true
|
|
|
|
*/
|
|
|
|
private function restore_session_data() {
|
|
|
|
$session_data = $GLOBALS['egw']->session->appsession('session_data',self::_appname);
|
|
|
|
if(is_array($session_data)) {
|
|
|
|
$this->session_data = $session_data;
|
|
|
|
} else {
|
|
|
|
$this->session_data = $this->session_data_defaults;
|
|
|
|
}
|
2009-04-28 22:24:05 +02:00
|
|
|
|
2009-02-11 20:32:26 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* saves the users session data for notifications
|
2009-04-28 22:24:05 +02:00
|
|
|
*
|
2009-02-11 20:32:26 +01:00
|
|
|
* @return boolean true
|
|
|
|
*/
|
|
|
|
private function save_session_data() {
|
|
|
|
$GLOBALS['egw']->session->appsession('session_data',self::_appname,$this->session_data);
|
|
|
|
return true;
|
2007-12-18 16:53:38 +01:00
|
|
|
}
|
2009-02-11 20:32:26 +01:00
|
|
|
}
|