diff --git a/notifications/inc/class.notifications.inc.php b/notifications/inc/class.notifications.inc.php index 291dbc4b52..59db29dc83 100644 --- a/notifications/inc/class.notifications.inc.php +++ b/notifications/inc/class.notifications.inc.php @@ -614,4 +614,19 @@ final class notifications { return false; } + + /** + * Actions to take when an account is deleted + * + * @param settings array with keys account_id and new_owner (new_owner is optional) + */ + public function deleteaccount($settings) { + foreach($this->backends as $backend) { + $notification_backend = self::_appname.'_'.$backend; + $backend_obj = new $notification_backend(); + if(method_exists($backend_obj, 'deleteaccount')) { + $backend_obj->deleteaccount($settings); + } + } + } } diff --git a/notifications/inc/class.notifications_ajax.inc.php b/notifications/inc/class.notifications_ajax.inc.php index 2387559c18..7fdfcbbbfa 100644 --- a/notifications/inc/class.notifications_ajax.inc.php +++ b/notifications/inc/class.notifications_ajax.inc.php @@ -118,6 +118,18 @@ class notifications_ajax { return $this->response->getXML(); } + /** + * Let the user confirm that they have seen the message. + * After they've seen it, remove it from the database + */ + public function confirm_message($message) { +error_log( html_entity_decode($message)); + $myval=$this->db->delete(self::_notification_table,array( + 'account_id' => $this->recipient->account_id, + 'message' => html_entity_decode($message) + ),__LINE__,__FILE__,self::_appname); + } + /** * checks users mailbox and sends a notification if new mails have arrived * @@ -211,22 +223,16 @@ class notifications_ajax { * @return boolean true or false */ private function get_egwpopup() { - $session_id = $GLOBALS['egw_info']['user']['sessionid']; $message = ''; $rs = $this->db->select(self::_notification_table, '*', array( 'account_id' => $this->recipient->account_id, - 'session_id' => $session_id, ), __LINE__,__FILE__,false,'',self::_appname); if ($rs->NumRows() > 0) { foreach ($rs as $notification) { $this->response->addScriptCall('append_notification_message',$notification['message']); } - $myval=$this->db->delete(self::_notification_table,array( - 'account_id' => $this->recipient->account_id, - 'session_id' => $session_id, - ),__LINE__,__FILE__,self::_appname); switch($this->preferences[self::_appname]['egwpopup_verbosity']) { case 'low': diff --git a/notifications/inc/class.notifications_popup.inc.php b/notifications/inc/class.notifications_popup.inc.php index 2291c2a902..e743078868 100644 --- a/notifications/inc/class.notifications_popup.inc.php +++ b/notifications/inc/class.notifications_popup.inc.php @@ -104,21 +104,18 @@ class notifications_popup implements notifications_iface { * @param array $_attachments */ public function send(array $_messages, $_subject = false, $_links = false, $_attachments = false) { - $sessions = egw_session::session_list(0, 'asc', 'session_dla', true); - $user_sessions = array(); - foreach ($sessions as $session) { - if ($session['session_lid'] == $this->recipient->account_lid. '@'. $GLOBALS['egw_info']['user']['domain']) { - $user_sessions[] = $session['session_id']; - } + // Check access log to see if user is still logged in + if ( !egw_session::notifications_active($this->recipient->account_id) ) + { + 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) .html::hr() .$_messages['html'] .$this->render_links($_links); - $this->save( $message, $user_sessions ); + $this->save( $message ); } /** @@ -127,14 +124,11 @@ class notifications_popup implements notifications_iface { * @param string $_message * @param array $_user_sessions */ - private function save( $_message, array $_user_sessions ) { - foreach ($_user_sessions as $user_session) { - $result = $this->db->insert( self::_notification_table, array( - 'account_id' => $this->recipient->account_id, - 'session_id' => $user_session, - 'message' => $_message - ), false,__LINE__,__FILE__,self::_appname); - } + private function save( $_message ) { + $result = $this->db->insert( self::_notification_table, array( + 'account_id' => $this->recipient->account_id, + 'message' => $_message + ), false,__LINE__,__FILE__,self::_appname); if ($result === false) throw new Exception("Can't save notification into SQL table"); } @@ -207,4 +201,23 @@ class notifications_popup implements notifications_iface { if(!empty($_subject)) { $infos[] = html::bold($_subject); } return implode($newline,$infos); } + + /** + * Actions to take when deleting an account + * + * @param settings array with keys account_id and new_owner (new_owner is optional) + */ + public function deleteaccount($settings) { + if($settings['new_owner']) { + $this->db->update( self::_notification_table, array( + 'account_id' => $settings['new_owner'] + ), array( + 'account_id' => $settings['account_id'] + ),__LINE__,__FILE__,self::_appname); + } else { + $this->db->delete( self::_notification_table, array( + 'account_id' => $settings['account_id'] + ),__LINE__,__FILE__,self::_appname); + } + } } diff --git a/notifications/inc/hook_after_navbar.inc.php b/notifications/inc/hook_after_navbar.inc.php index 12c6d039af..be3866231b 100644 --- a/notifications/inc/hook_after_navbar.inc.php +++ b/notifications/inc/hook_after_navbar.inc.php @@ -22,7 +22,9 @@ if ($notification_config['popup_enable'] && $GLOBALS['egw_info']['user']['apps'] echo ''; echo '