public static function sendNextNotifications($limit = false)
 {
     if (!$limit) {
         $limit = 5;
     }
     $init_limit = $limit;
     $result = eF_getTableData("notifications", "*", "active = 1 AND timestamp <" . time(), "timestamp ASC LIMIT {$limit}");
     // Delete notifications for inactive users
     $notifications_to_delete = eF_getTableData("notifications as n, users as u", "n.id", "n.recipient=u.login AND u.active=0");
     foreach ($notifications_to_delete as $notification) {
         eF_deleteTableData("notifications", "id = '" . $notification['id'] . "'");
     }
     $notifications_to_send = array();
     foreach ($result as $next_notification) {
         $notification = new EfrontNotification($next_notification);
         // Try to send all messages of this notification
         // Get message recipients: one or more
         $recipients = $notification->getRecipients();
         try {
             foreach ($recipients as $login => $recipient) {
                 // Send message
                 if ($notification->sendTo($recipient)) {
                     $limit--;
                 }
                 unset($recipients[$login]);
                 if (!$limit) {
                     break;
                 }
             }
         } catch (Exception $e) {
             $sendingErrors[] = $e->getMessage();
         }
         // Check if the notification is periodical - if so  arrange (insert) the next notification
         // Note here: generated single recipient notifications should never have a send interval
         if ($notification->notification['send_interval'] != "") {
             $notification->scheduleNext();
         } else {
             // Pop this notification - delete it
             eF_deleteTableData("notifications", "id = '" . $notification->notification['id'] . "'");
         }
         if ($sendingErrors) {
             throw new Exception(implode(",", $sendingErrors));
         }
         // If all $limit messages have been sent, check whether some recipients still remain
         if (!$limit) {
             // Push all remaining recipients back to the notifications list, as single user notifications
             if (sizeof($recipients) > 0) {
                 $notifications_to_send = array();
                 foreach ($recipients as $login => $recipient) {
                     $notifications_to_send[] = time() . "', '" . $login . "', '" . $notification->notification['message'] . "', '" . $notification->notification['subject'] . "', '" . $notification->notification['id_type_entity'];
                 }
                 if (sizeof($notifications_to_send)) {
                     eF_executeNew("INSERT INTO notifications (timestamp, recipient, message, subject, id_type_entity) VALUES ('" . implode("'),('", $notifications_to_send) . "')");
                 }
             }
             return $init_limit;
             // all messages have been sent
         }
     }
     return $init_limit - $limit;
 }
Beispiel #2
0
                                 }
                             }
                         }
                     }
                 }
             } else {
                 $sending_queue_msgs[$key]['recipients'] = formatLogin($sending_queue_msgs[$key]['recipient']);
             }
         }
     }
     $smarty->assign("T_MESSAGE_QUEUE_SIZE", $sending_queue_size[0]['count']);
     // This is almost buggy - cannot filter according to recipients count - significant optimization however
     foreach ($sending_queue_msgs as $key => $message) {
         $notification = new EfrontNotification($message);
         if ($notification->notification['recipient'] == "") {
             $sending_queue_msgs[$key]['recipients_count'] = sizeof($notification->getRecipients());
         }
     }
     if (!empty($sending_queue_msgs)) {
         $smarty->assign("T_QUEUE_MSGS", $sending_queue_msgs);
     }
     $smarty->display('administrator.tpl');
     exit;
 }
 $notifications = EfrontNotification::getAllNotifications();
 $events_table = EfrontEvent::getEventTypes(false);
 if (sizeof($notifications) > 0) {
     try {
         foreach ($notifications as $key => $notification) {
             // when
             if (isset($notification['event'])) {
Beispiel #3
0
header("Cache-Control: no-cache, must-revalidate");
// HTTP/1.1
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
// Date in the past
//debug();
session_write_close();
$lowest_possible_time = time() - 21600;
// last acceptable time - pending 6 hours in the queue to be sent
//eF_deleteTableData("notifications", "timestamp != 0 AND timestamp <" . $lowest_possible_time);
//echo G_SERVERNAME;
if (isset($_GET['notification_id']) && eF_checkParameter($_GET['notification_id'], 'id')) {
    try {
        $notification = new EfrontNotification($_GET['notification_id']);
        // Try to send all messages of this notification
        // Get message recipients: one or more
        $recipients = $notification->getRecipients();
        $sent_messages = 0;
        ////pr ($recipients);
        foreach ($recipients as $login => $recipient) {
            // Send message
            if ($notification->sendTo($recipient)) {
                // no limit here
                $sent_messages++;
            }
        }
        // Check if the notification is periodical - if so  arrange (insert) the next notification
        // Note here: generated single recipient notifications should never have a send interval
        if ($notification->notification['send_interval']) {
            $notification->scheduleNext();
        } else {
            // Pop this notification - delete it