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;
 }
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
            eF_deleteTableData("notifications", "id = '" . $notification->notification['id'] . "'");
        }
    } catch (EfrontNotificationException $e) {
        $smarty->assign("T_EXCEPTION_TRACE", $e->getTraceAsString());
        $message = $e->getMessage() . ' (' . $e->getCode() . ') &nbsp;<a href = "javascript:void(0)" onclick = "eF_js_showDivPopup(event, \'' . _ERRORDETAILS . '\', 2, \'error_details\')">' . _MOREINFO . '</a>';