From d1df89adf058481050ed42f4d22ec3a047a4c908 Mon Sep 17 00:00:00 2001
From: Nestor <npegane@hotmail.com>
Date: Fri, 26 Jan 2018 12:00:44 +0100
Subject: [PATCH] FIX #6694 added control on diffusion_type and changed array
 for events

---
 .../batch/basket_event_stack.php              | 25 +++++++++++--------
 1 file changed, 15 insertions(+), 10 deletions(-)

diff --git a/modules/notifications/batch/basket_event_stack.php b/modules/notifications/batch/basket_event_stack.php
index 6ad1628babc..6b8f4c4b482 100755
--- a/modules/notifications/batch/basket_event_stack.php
+++ b/modules/notifications/batch/basket_event_stack.php
@@ -60,16 +60,21 @@ while ($state <> 'END') {
 
             $u=1;
             while ($line2 = $stmt2->fetchObject()) {
-                $recipients = array();
-                $recipients = $diffusion_type_controler->getRecipients($notification, '');
-                $aRecipients = [];
-                foreach ($recipients as $itemRecipient) {
-                    array_push($aRecipients, $itemRecipient->user_id);
-                }
-                if(empty($aRecipients)){
-                    $aRecipients = "0=1";
+                if ($notification->diffusion_type == "groups"){
+                    $recipients = array();
+                    $recipients = $diffusion_type_controler->getRecipients($notification, '');
+                    $aRecipients = [];
+                    foreach ($recipients as $itemRecipient) {
+                        array_push($aRecipients, $itemRecipient->user_id);
+                    }
+                    if(empty($aRecipients)){
+                        $aRecipients = "0=1";
+                    }
+                    $stmt3 = $db->query("SELECT usergroup_content.user_id,users.status FROM usergroup_content, users WHERE group_id = ? and users.status in ('OK') and usergroup_content.user_id=users.user_id and users.user_id in (?)", array($line2->group_id, $aRecipients));
+                } else {
+                    $stmt3 = $db->query("SELECT usergroup_content.user_id,users.status FROM usergroup_content, users WHERE group_id = ? and users.status in ('OK') and usergroup_content.user_id=users.user_id",array($line2->group_id));
                 }
-                $stmt3 = $db->query("SELECT usergroup_content.user_id,users.status FROM usergroup_content, users WHERE group_id = ? and users.status in ('OK') and usergroup_content.user_id=users.user_id and users.user_id in (?)", array($line2->group_id, $aRecipients));
+
                 $baskets_notif = array();
                 $rowCount3 = $stmt3->rowCount();
                 $logger->write("GROUP: " . $line2->group_id . " ... " . $rowCount3 . " user(s) to notify", 'INFO');
@@ -225,7 +230,7 @@ while ($state <> 'END') {
                 $attachments = array();
                 if ($tmpNotif['attach']) {
                     $logger->write('Adding attachments', 'INFO');
-                    foreach ($tmpNotif['events'] as $event) {
+                    foreach ($basket_list['events'] as $event) {
                         // Check if event is related to document in collection
                         if ($event->res_id != '') {
                             $query = "SELECT "
-- 
GitLab