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
|
|
|
|
2016-05-06 11:19:36 +02:00
|
|
|
use EGroupware\Api;
|
|
|
|
|
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
|
|
|
*
|
2016-05-06 11:19:36 +02:00
|
|
|
* @var Api\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
|
|
|
|
*
|
2016-05-06 11:19:36 +02:00
|
|
|
* @var Api\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() {
|
2016-05-06 11:19:36 +02:00
|
|
|
$this->response = Api\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
|
|
|
|
2016-05-06 11:19:36 +02:00
|
|
|
$this->config = (object)Api\Config::read(self::_appname);
|
2007-12-18 16:53:38 +01:00
|
|
|
|
2016-05-06 11:19:36 +02:00
|
|
|
$prefs = new Api\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();
|
2016-05-06 11:19:36 +02:00
|
|
|
Api\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
|
|
|
/**
|
2017-05-16 18:03:50 +02:00
|
|
|
* Remove given notification id(s) from the table
|
2011-04-14 15:43:16 +02:00
|
|
|
*
|
2017-05-16 18:03:50 +02:00
|
|
|
* @param array|int $notify_ids one or multiple notify_id(s)
|
2011-04-13 19:51:02 +02:00
|
|
|
*/
|
2017-05-16 18:03:50 +02:00
|
|
|
public function delete_message($notify_ids)
|
2011-04-14 15:43:16 +02:00
|
|
|
{
|
2017-05-16 18:03:50 +02:00
|
|
|
if ($notify_ids)
|
2011-04-14 15:43:16 +02:00
|
|
|
{
|
|
|
|
$this->db->delete(self::_notification_table,array(
|
2017-05-16 18:03:50 +02:00
|
|
|
'notify_id' => $notify_ids,
|
|
|
|
'account_id' => $this->recipient->account_id,
|
|
|
|
'notify_type' => self::_type
|
|
|
|
),__LINE__,__FILE__,self::_appname);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Method to update message(s) status
|
|
|
|
*
|
|
|
|
* @param int|array $notify_ids one or more notify_id(s)
|
|
|
|
* @param string $status = SEEN, status of message:
|
|
|
|
* - SEEN: message has been seen
|
|
|
|
* - UNSEEN: message has not been seen
|
|
|
|
* - DISPLAYED: message has been shown but no further status applied yet
|
|
|
|
* this status has been used more specifically for browser type
|
|
|
|
* of notifications.
|
|
|
|
*/
|
|
|
|
public function update_status($notify_ids,$status = "SEEN")
|
|
|
|
{
|
|
|
|
if ($notify_ids)
|
|
|
|
{
|
|
|
|
$this->db->update(self::_notification_table,array('notify_status' => $status),array(
|
|
|
|
'notify_id' => $notify_ids,
|
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) {
|
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
|
|
|
),
|
2018-06-19 14:58:32 +02:00
|
|
|
__LINE__,__FILE__,false,'ORDER BY notify_id DESC LIMIT 0,100',self::_appname);
|
|
|
|
$result = array();
|
2009-04-03 22:17:22 +02:00
|
|
|
if ($rs->NumRows() > 0) {
|
|
|
|
foreach ($rs as $notification) {
|
2018-01-25 11:07:51 +01:00
|
|
|
$actions = null;
|
2018-01-24 19:02:35 +01:00
|
|
|
$data = json_decode($notification['notify_data'], true);
|
|
|
|
if ($data['appname'])
|
|
|
|
{
|
|
|
|
$_actions = Api\Hooks::process (array(
|
|
|
|
'location' => 'notifications_actions',
|
|
|
|
'data' => $data['data']
|
|
|
|
), $data['appname'], true);
|
|
|
|
$actions = $_actions[$data['appname']];
|
|
|
|
}
|
2018-06-19 14:58:32 +02:00
|
|
|
$result[] = array(
|
|
|
|
'id' => $notification['notify_id'],
|
|
|
|
'message' => $notification['notify_message'],
|
|
|
|
'status' => $notification['notify_status'],
|
|
|
|
'created' => Api\DateTime::to($notification['notify_created']),
|
|
|
|
'current' => new DateTime(),
|
|
|
|
'action' => is_array($actions)?$actions:NULL
|
2017-09-18 18:47:44 +02:00
|
|
|
);
|
2009-04-28 22:24:05 +02:00
|
|
|
|
2009-04-03 22:17:22 +02:00
|
|
|
}
|
2018-06-19 14:58:32 +02:00
|
|
|
$this->response->apply('app.notifications.append', array($result, $browserNotify));
|
2009-04-03 22:17:22 +02:00
|
|
|
}
|
|
|
|
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() {
|
2016-10-12 17:52:30 +02:00
|
|
|
$session_data = Api\Cache::getSession(self::_appname, 'session_data');
|
2009-02-11 20:32:26 +01:00
|
|
|
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() {
|
2016-10-12 17:52:30 +02:00
|
|
|
Api\Cache::setSession(self::_appname, 'session_data', $this->session_data);
|
2009-02-11 20:32:26 +01:00
|
|
|
return true;
|
2007-12-18 16:53:38 +01:00
|
|
|
}
|
2009-02-11 20:32:26 +01:00
|
|
|
}
|