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;
 }
Пример #2
0
        // 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>';
    }
} else {
    if (isset($_GET['sent_notification_id']) && eF_checkParameter($_GET['sent_notification_id'], 'id')) {
        $sent_notification = eF_getTableData("sent_notifications", "*", "id = " . $_GET['sent_notification_id']);
        if (!empty($sent_notification)) {
            $notification = $sent_notification[0];
            // Get recipient's email
            $recipient = substr($notification['recipient'], 0, strpos($notification['recipient'], " "));