"using egw_session::session_list()"

This commit is contained in:
Ralf Becker 2008-08-13 20:14:44 +00:00
parent 5447cd6a6d
commit e2f72dcc70

View File

@ -13,10 +13,10 @@
/** /**
* Instant user notification with egroupware popup. * Instant user notification with egroupware popup.
* *
* @abstract egwpopup is a two stage notification. In the first stage * @abstract egwpopup is a two stage notification. In the first stage
* notification is written into self::_notification_table. * notification is written into self::_notification_table.
* In the second stage a request from the client reads * In the second stage a request from the client reads
* out the table to look if there is a notificaton for this * out the table to look if there is a notificaton for this
* client. The second stage is done in class.ajaxnotifications.inc.php * client. The second stage is done in class.ajaxnotifications.inc.php
* *
* Todo: * Todo:
@ -31,52 +31,52 @@
* *
*/ */
class notifications_popup implements notifications_iface { class notifications_popup implements notifications_iface {
/** /**
* Appname * Appname
*/ */
const _appname = 'notifications'; const _appname = 'notifications';
/** /**
* Notification table in SQL database * Notification table in SQL database
*/ */
const _notification_table = 'egw_notificationpopup'; const _notification_table = 'egw_notificationpopup';
/** /**
* holds account object for user who sends the message * holds account object for user who sends the message
* *
* @var object * @var object
*/ */
private $sender; private $sender;
/** /**
* holds account object for user to notify * holds account object for user to notify
* *
* @var object * @var object
*/ */
private $recipient; private $recipient;
/** /**
* holds config object (sitewide application config) * holds config object (sitewide application config)
* *
* @var object * @var object
*/ */
private $config; private $config;
/** /**
* holds preferences object of user to notify * holds preferences object of user to notify
* *
* @var object * @var object
*/ */
private $preferences; private $preferences;
/** /**
* holds db object of SQL database * holds db object of SQL database
* *
* @var egw_db * @var egw_db
*/ */
private $db; private $db;
/** /**
* constructor of notifications_egwpopup * constructor of notifications_egwpopup
* *
@ -94,7 +94,7 @@ class notifications_popup implements notifications_iface {
$this->preferences = $_preferences; $this->preferences = $_preferences;
$this->db = &$GLOBALS['egw']->db; $this->db = &$GLOBALS['egw']->db;
} }
/** /**
* sends notification if user is online * sends notification if user is online
* *
@ -104,7 +104,7 @@ class notifications_popup implements notifications_iface {
* @param array $_attachments * @param array $_attachments
*/ */
public function send(array $_messages, $_subject = false, $_links = false, $_attachments = false) { public function send(array $_messages, $_subject = false, $_links = false, $_attachments = false) {
$sessions = $GLOBALS['egw']->session->list_sessions(0, 'asc', 'session_dla', true); $sessions = egw_session::session_list(0, 'asc', 'session_dla');
$user_sessions = array(); $user_sessions = array();
foreach ($sessions as $session) { foreach ($sessions as $session) {
if ($session['session_lid'] == $this->recipient->account_lid. '@'. $GLOBALS['egw_info']['user']['domain']) { if ($session['session_lid'] == $this->recipient->account_lid. '@'. $GLOBALS['egw_info']['user']['domain']) {
@ -112,16 +112,16 @@ class notifications_popup implements notifications_iface {
} }
} }
if ( empty($user_sessions) ) throw new Exception("User {$this->recipient->account_lid} isn't online. Can't send notification via popup"); if ( empty($user_sessions) ) throw new Exception("User {$this->recipient->account_lid} isn't online. Can't send notification via popup");
$message = $this->render_infos($_subject) $message = $this->render_infos($_subject)
.html::hr() .html::hr()
.$_messages['html'] .$_messages['html']
.html::hr() .html::hr()
.$this->render_links($_links); .$this->render_links($_links);
$this->save( $message, $user_sessions ); $this->save( $message, $user_sessions );
} }
/** /**
* saves notification into database so that the client can fetch it from there * saves notification into database so that the client can fetch it from there
* *
@ -138,7 +138,7 @@ class notifications_popup implements notifications_iface {
} }
if ($result === false) throw new Exception("Can't save notification into SQL table"); if ($result === false) throw new Exception("Can't save notification into SQL table");
} }
/** /**
* renders plaintext/html links from given link array * renders plaintext/html links from given link array
* should be moved to the ajax class later - like mentioned in the Todo * should be moved to the ajax class later - like mentioned in the Todo
@ -149,11 +149,11 @@ class notifications_popup implements notifications_iface {
private function render_links($_links = false) { private function render_links($_links = false) {
if(!is_array($_links) || count($_links) == 0) { return false; } if(!is_array($_links) || count($_links) == 0) { return false; }
$newline = "<br />"; $newline = "<br />";
$rendered_links = array(); $rendered_links = array();
foreach($_links as $link) { foreach($_links as $link) {
if(!$link->popup) { $link->view['no_popup'] = 1; } if(!$link->popup) { $link->view['no_popup'] = 1; }
$url = html::link('/index.php', $link->view); $url = html::link('/index.php', $link->view);
// do not expose sensitive data // do not expose sensitive data
$url = preg_replace('/(sessionid|kp3|domain)=[^&]+&?/','',$url); $url = preg_replace('/(sessionid|kp3|domain)=[^&]+&?/','',$url);
@ -170,14 +170,14 @@ class notifications_popup implements notifications_iface {
$rendered_links[] = html::div($image.$link->text,'onclick="'.$this->jspopup($url, '_blank', $dimensions[0], $dimensions[1]).'"','link'); $rendered_links[] = html::div($image.$link->text,'onclick="'.$this->jspopup($url, '_blank', $dimensions[0], $dimensions[1]).'"','link');
} else { } else {
$rendered_links[] = html::div(html::a_href($image.$link->text, $url, false, 'target="_blank"'),'','link'); $rendered_links[] = html::div(html::a_href($image.$link->text, $url, false, 'target="_blank"'),'','link');
} }
} }
if(count($rendered_links) > 0) { if(count($rendered_links) > 0) {
return html::bold(lang('Linked entries:')).$newline.implode($newline,$rendered_links); return html::bold(lang('Linked entries:')).$newline.implode($newline,$rendered_links);
} }
} }
/** /**
* returns javascript to open a popup window: window.open(...) * returns javascript to open a popup window: window.open(...)
* *
@ -192,7 +192,7 @@ class notifications_popup implements notifications_iface {
return 'egw_openWindowCentered2('.($link == 'this.href' ? $link : "'".$link."'").','. return 'egw_openWindowCentered2('.($link == 'this.href' ? $link : "'".$link."'").','.
($target == 'this.target' ? $target : "'".$target."'").",$width,$height,'yes')"; ($target == 'this.target' ? $target : "'".$target."'").",$width,$height,'yes')";
} }
/** /**
* renders additional infos from sender and subject * renders additional infos from sender and subject
* *
@ -201,8 +201,8 @@ class notifications_popup implements notifications_iface {
*/ */
private function render_infos($_subject = false) { private function render_infos($_subject = false) {
$infos = array(); $infos = array();
$newline = "<br />"; $newline = "<br />";
$sender = $this->sender->account_fullname ? $this->sender->account_fullname : $this->sender_account_email; $sender = $this->sender->account_fullname ? $this->sender->account_fullname : $this->sender_account_email;
$infos[] = lang('Message from').': '.$sender; $infos[] = lang('Message from').': '.$sender;
if(!empty($_subject)) { $infos[] = html::bold($_subject); } if(!empty($_subject)) { $infos[] = html::bold($_subject); }