From 3aa2f72e2cdf85da166d0cc6f808304bffe1a34a Mon Sep 17 00:00:00 2001 From: Angel Fernando Quiroz Campos Date: Tue, 14 Mar 2017 17:24:42 -0500 Subject: [PATCH] Allow sent announcements to all users in course/group - refs BT#12454 --- main/announcements/announcements.php | 22 +++++++++++++++++++++- main/inc/lib/AnnouncementManager.php | 10 +++++----- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/main/announcements/announcements.php b/main/announcements/announcements.php index 10cb93a007..6e8022d371 100755 --- a/main/announcements/announcements.php +++ b/main/announcements/announcements.php @@ -378,6 +378,9 @@ switch ($action) { $nameTools = $form_name; $form->addElement('header', $form_name); + $form->addButtonAdvancedSettings('choose_recipients', [get_lang('ChooseRecipients'), get_lang('AnnouncementChooseRecipientsDescription')]); + $form->addHtml(''); +// $form->setRequired($element); $form->addCheckBox('email_ann', '', get_lang('EmailOption')); if (!isset($announcement_to_modify)) { @@ -461,6 +465,21 @@ switch ($action) { } } + foreach ($defaults['users'] as $value) { + $parts = explode(':', $value); + + if (isset($parts[1]) && !empty($parts[1])) { + $form->addHtml(" + + "); + break; + } + } + $defaults['email_ann'] = true; $form->addElement('text', 'title', get_lang('EmailTitle')); @@ -500,6 +519,7 @@ switch ($action) { if ($form->validate()) { $data = $form->getSubmitValues(); + $data['users'] = isset($data['users']) ? $data['users'] : ['everyone']; $sendToUsersInSession = isset($data['send_to_users_in_session']) ? true : false; diff --git a/main/inc/lib/AnnouncementManager.php b/main/inc/lib/AnnouncementManager.php index ef4b79f3bc..d91b53a98e 100755 --- a/main/inc/lib/AnnouncementManager.php +++ b/main/inc/lib/AnnouncementManager.php @@ -1475,7 +1475,7 @@ class AnnouncementManager // No group $cond_user_id = " AND ( ip.lastedit_user_id = '".$user_id."' OR ( - ip.to_user_id='".$user_id."' OR + (ip.to_user_id='$user_id' OR ip.to_user_id IS NULL) OR (ip.to_group_id IS NULL OR ip.to_group_id IN (0, ".implode(", ", $group_memberships).")) ) ) "; @@ -1487,11 +1487,11 @@ class AnnouncementManager } else { if ($group_id == 0) { $cond_user_id = " AND ( - ip.to_user_id = $user_id AND (ip.to_group_id IS NULL OR ip.to_group_id IN (0, ".implode(", ", $group_memberships).")) + (ip.to_user_id='$user_id' OR ip.to_user_id IS NULL) AND (ip.to_group_id IS NULL OR ip.to_group_id IN (0, ".implode(", ", $group_memberships).")) ) "; } else { $cond_user_id = " AND ( - ip.to_user_id = $user_id AND (ip.to_group_id IS NULL OR ip.to_group_id IN (0, ".$group_id.")) + (ip.to_user_id='$user_id' OR ip.to_user_id IS NULL) AND (ip.to_group_id IS NULL OR ip.to_group_id IN (0, ".$group_id.")) )"; } } @@ -1514,10 +1514,10 @@ class AnnouncementManager if ($allowUserEditSetting && !api_is_anonymous()) { $cond_user_id = " AND ( ip.lastedit_user_id = '".api_get_user_id()."' OR - (ip.to_user_id='".$user_id."' AND (ip.to_group_id='0' OR ip.to_group_id IS NULL)) + ((ip.to_user_id='$user_id' OR ip.to_user_id IS NULL) AND (ip.to_group_id='0' OR ip.to_group_id IS NULL)) ) "; } else { - $cond_user_id = " AND (ip.to_user_id='".$user_id."' AND (ip.to_group_id='0' OR ip.to_group_id IS NULL) ) "; + $cond_user_id = " AND ((ip.to_user_id='$user_id' OR ip.to_user_id IS NULL) AND (ip.to_group_id='0' OR ip.to_group_id IS NULL) ) "; } $sql = "SELECT $select