diff --git a/app/controllers/course/members.php b/app/controllers/course/members.php index 0a892d50100de6173ceaf07187cc11af573e365a..936bd999ec3e39dbb3cbbaa7d63ef99cf060b652 100644 --- a/app/controllers/course/members.php +++ b/app/controllers/course/members.php @@ -1817,10 +1817,11 @@ class Course_MembersController extends AuthenticatedController } //Calculate the amount of recipients for each group: - $this->user_count = CourseMember::countByCourseAndStatus($this->course_id, 'user'); - $this->autor_count = CourseMember::countByCourseAndStatus($this->course_id, 'autor'); - $this->tutor_count = CourseMember::countByCourseAndStatus($this->course_id, 'tutor'); - $this->dozent_count = CourseMember::countByCourseAndStatus($this->course_id, 'dozent'); + $visibility_constraint = !$this->is_tutor ? " AND visible <> 'no'" : ""; + $this->user_count = CourseMember::countBySql("seminar_id=? AND status=?" . $visibility_constraint, [$this->course_id, 'user']); + $this->autor_count = CourseMember::countBySql("seminar_id=? AND status=?" . $visibility_constraint, [$this->course_id, 'autor']); + $this->tutor_count = CourseMember::countBySql("seminar_id=? AND status=?" . $visibility_constraint, [$this->course_id, 'tutor']); + $this->dozent_count = CourseMember::countBySql("seminar_id=? AND status=?" . $visibility_constraint, [$this->course_id, 'dozent']); //Use the correct names for thte four status groups: $sem = Seminar::GetInstance($this->course_id); @@ -1844,6 +1845,10 @@ class Course_MembersController extends AuthenticatedController 'course_id' => $this->course_id ] ); + $cs = CourseSet::getSetForCourse($this->course_id); + if (is_object($cs) && !$cs->hasAlgorithmRun()) { + $this->claiming_count = count(AdmissionPriority::getPrioritiesByCourse($cs->getId(), $this->course_id)); + } } $this->default_selected_groups = ['dozent', 'tutor', 'autor', 'user']; $this->all_available_groups = $this->default_selected_groups; @@ -1855,6 +1860,9 @@ class Course_MembersController extends AuthenticatedController if ($this->awaiting_count) { $this->all_available_groups[] = 'awaiting'; } + if ($this->claiming_count) { + $this->all_available_groups[] = 'claiming'; + } } if (Request::submitted('write')) { CSRFProtection::verifyUnsafeRequest(); @@ -1867,73 +1875,54 @@ class Course_MembersController extends AuthenticatedController $filtered_groups[] = $group; } } - if ($filtered_groups == $this->default_selected_groups) { - $this->redirect(URLHelper::getURL( - 'dispatch.php/messages/write', - [ - 'course_id' => $this->course_id, - 'default_subject' => $this->default_subject, - 'filter' => 'all', - 'emailrequest' => 1 - ] - )); - } elseif ($filtered_groups == $this->all_available_groups) { - $this->redirect(URLHelper::getURL( - 'dispatch.php/messages/write', - [ - 'course_id' => $this->course_id, - 'default_subject' => $this->default_subject, - 'filter' => 'really_all', - 'emailrequest' => 1 - ] - )); - } else { - //Do custom filtering. - $filters = []; - $who_param = []; - - foreach ($filtered_groups as $group) { - if ($group === 'awaiting') { - $filters[] = 'awaiting'; - } elseif ($group === 'accepted') { - $filters[] = 'prelim'; - } elseif ($group === 'user') { - $filters[] = 'all'; - $who_param[] = 'user'; - } elseif ($group === 'autor') { - $filters[] = 'all'; - $who_param[] = 'autor'; - } elseif ($group === 'tutor') { - $filters[] = 'all'; - $who_param[] = 'tutor'; - } elseif ($group === 'dozent') { - $filters[] = 'all'; - $who_param[] = 'dozent'; - } - } - $filters = array_unique($filters); - if (!$filters) { - PageLayout::postError( - _('Es wurde keine Gruppe ausgewählt!') - ); - return; - } - - $url_params = [ - 'course_id' => $this->course_id, - 'default_subject' => $this->default_subject, - 'filter' => implode(',', array_unique($filters)), - 'emailrequest' => 1 - ]; - if ($who_param) { - $url_params['who'] = implode(',', $who_param); + //Do custom filtering. + $filters = []; + $who_param = []; + + foreach ($filtered_groups as $group) { + if ($group === 'awaiting') { + $filters[] = 'awaiting'; + } elseif ($group === 'accepted') { + $filters[] = 'prelim'; + } elseif ($group === 'claiming') { + $filters[] = 'claiming'; + } elseif ($group === 'user') { + $filters[] = 'all'; + $who_param[] = 'user'; + } elseif ($group === 'autor') { + $filters[] = 'all'; + $who_param[] = 'autor'; + } elseif ($group === 'tutor') { + $filters[] = 'all'; + $who_param[] = 'tutor'; + } elseif ($group === 'dozent') { + $filters[] = 'all'; + $who_param[] = 'dozent'; } + } + $filters = array_unique($filters); + if (!$filters) { + PageLayout::postError( + _('Es wurde keine Gruppe ausgewählt!') + ); + return; + } - $this->redirect(URLHelper::getURL( - 'dispatch.php/messages/write', - $url_params - )); + $url_params = [ + 'course_id' => $this->course_id, + 'default_subject' => $this->default_subject, + 'filter' => implode(',', array_unique($filters)), + 'emailrequest' => 1 + ]; + if ($who_param) { + $url_params['who'] = implode(',', $who_param); } + + $this->redirect(URLHelper::getURL( + 'dispatch.php/messages/write', + $url_params + )); + } } public function checkUserVisibility() diff --git a/app/controllers/messages.php b/app/controllers/messages.php index 5f8411741aa02f198196bad20ff436407946404d..d633a723b803577056eb4a4f7fd3f2b86439d5e4 100644 --- a/app/controllers/messages.php +++ b/app/controllers/messages.php @@ -291,13 +291,17 @@ class MessagesController extends AuthenticatedController { //check if the message shall be sent to all (or some) members of a course: $filters = explode(',', Request::get('filter', '')); - if ($filters && Request::option('course_id')) { + $course = Course::find(Request::option('course_id')); + if ($filters && $course) { $additional = ''; - $course = new Course(Request::option('course_id')); - $allow_tutor_filters = false; - if ($GLOBALS['perm']->have_studip_perm('tutor', $course->id) || $course->getSemClass()['studygroup_mode'] || CourseConfig::get($course->id)->COURSE_STUDENT_MAILING) { + if ($GLOBALS['perm']->have_studip_perm('tutor', $course->id)) { $allow_tutor_filters = true; + } elseif ($GLOBALS['perm']->have_studip_perm('user', $course->id) + && ($course->getSemClass()['studygroup_mode'] || CourseConfig::get($course->id)->COURSE_STUDENT_MAILING)) { $additional = " AND seminar_user.visible != 'no'"; + $allow_tutor_filters = false; + } else { + throw new AccessDeniedException(); } $this->default_message->receivers = []; $all_recipients = []; @@ -307,14 +311,7 @@ class MessagesController extends AuthenticatedController { if (Request::get('who')) { $params['status'] = explode(',', Request::get('who', '')); } - - if ($filter === 'send_sms_to_all' && $allow_tutor_filters) { - $query = "SELECT user_id, 'rec' AS snd_rec - FROM seminar_user - JOIN auth_user_md5 USING (user_id) - WHERE Seminar_id = :course_id AND status IN ( :status ) {$additional} - ORDER BY Nachname, Vorname"; - } elseif ($filter === 'all') { + if ($filter === 'all' || $filter === 'send_sms_to_all') { if ($params['status']) { $additional .= ' AND seminar_user.status IN ( :status )'; } @@ -323,12 +320,6 @@ class MessagesController extends AuthenticatedController { JOIN auth_user_md5 USING (user_id) WHERE Seminar_id = :course_id {$additional} ORDER BY Nachname, Vorname"; - } elseif ($filter === 'really_all' && $allow_tutor_filters) { - $query = "SELECT user_id, 'rec' as snd_rec - FROM seminar_user - WHERE seminar_id = :course_id - UNION SELECT user_id, 'rec' as snd_rec FROM admission_seminar_user WHERE seminar_id = :course_id - UNION SELECT user_id, 'rec' as snd_rec FROM priorities WHERE seminar_id = :course_id"; } elseif ($filter === 'prelim' && $allow_tutor_filters) { $query = "SELECT user_id, 'rec' AS snd_rec FROM admission_seminar_user @@ -341,13 +332,6 @@ class MessagesController extends AuthenticatedController { JOIN auth_user_md5 USING (user_id) WHERE Seminar_id = :course_id AND status = 'awaiting' ORDER BY Nachname, Vorname"; - } elseif ($filter === 'inst_status') { - $query = "SELECT user_id, 'rec' AS snd_rec - FROM user_inst - JOIN auth_user_md5 USING (user_id) - WHERE Institut_id = :course_id AND inst_perms IN ( :status ) - {$additional} - ORDER BY Nachname, Vorname"; } elseif ($filter === 'not_grouped' && $allow_tutor_filters) { $query = "SELECT seminar_user.user_id, 'rec' as snd_rec FROM seminar_user @@ -363,18 +347,9 @@ class MessagesController extends AuthenticatedController { $cs = CourseSet::getSetForCourse($course->id); if (is_object($cs) && !$cs->hasAlgorithmRun()) { foreach (AdmissionPriority::getPrioritiesByCourse($cs->getId(), $course->id) as $user_id => $p) { - $all_recipients = array_merge( - $all_recipients, - MessageUser::build(['user_id' => $user_id, 'snd_rec' => 'rec']) - ); + $all_recipients[] = MessageUser::build(['user_id' => $user_id, 'snd_rec' => 'rec']); } } - } else { - $query = "SELECT user_id, 'rec' AS snd_rec - FROM seminar_user - JOIN auth_user_md5 USING (user_id) - WHERE Seminar_id = :course_id AND seminar_user.visible != 'no' - ORDER BY Nachname, Vorname"; } if ($query) { $all_recipients = array_merge( diff --git a/app/views/course/members/circular_mail.php b/app/views/course/members/circular_mail.php index 725be878d2aa08015de3790630458b12f076fb2b..140a9a0d9598658b66b9908b70d03aeec397109d 100644 --- a/app/views/course/members/circular_mail.php +++ b/app/views/course/members/circular_mail.php @@ -95,6 +95,21 @@ </em> </label> <? endif ?> + <? if (in_array('claiming', $all_available_groups)) : ?> + <label> + <input type="checkbox" name="selected_groups[]" value="claiming" + <? if (!$claiming_count): echo 'disabled'; ?> + <? elseif (in_array('claiming', $default_selected_groups)): echo 'checked'; ?> + <? endif; ?>> + <?= _('Alle Personen auf der Losliste der Veranstaltung') ?> + <em> + (<?= sprintf( + ngettext('%u Person', '%u Personen', $claiming_count), + $claiming_count + ) ?>) + </em> + </label> + <? endif ?> </fieldset> <div data-dialog-button> <?= \Studip\Button::create(_('Rundmail schreiben'), 'write') ?>