From: gustav_delius Date: Sun, 15 Aug 2004 21:01:34 +0000 (+0000) Subject: Improved subscription editing interface according to discussion at http://moodle... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=f88803e06daa1f9643cf0457c04b29a10f66fdd8;p=moodle.git Improved subscription editing interface according to discussion at http://moodle.org/mod/forum/discuss.php?d=11089#53612 --- diff --git a/lang/en/forum.php b/lang/en/forum.php index 8ef3c04200..f01bfd2d26 100644 --- a/lang/en/forum.php +++ b/lang/en/forum.php @@ -149,7 +149,6 @@ $string['subscription'] = 'Subscription'; $string['subscriptions'] = 'Subscriptions'; $string['unsubscribe'] = 'Unsubscribe from this forum'; $string['unsubscribed'] = 'Unsubscribed'; -$string['unsubscribeshort'] = 'Unsubscribe'; $string['youratedthis'] = 'You rated this'; $string['yournewtopic'] = 'Your new discussion topic'; $string['yourreply'] = 'Your reply'; diff --git a/mod/forum/lib.php b/mod/forum/lib.php index dd3fa71958..14394597d5 100644 --- a/mod/forum/lib.php +++ b/mod/forum/lib.php @@ -2813,7 +2813,7 @@ function forum_update_subscriptions_button($courseid, $forumid) { // Prints the editing button on subscribers page global $CFG, $USER; - if (isteacheredit($courseid)) { + if (isteacher($courseid)) { if (!empty($USER->subscriptionsediting)) { $string = get_string("turneditingoff"); $edit = "off"; diff --git a/mod/forum/subscribers.php b/mod/forum/subscribers.php index a398dfc9ad..263bc00f39 100644 --- a/mod/forum/subscribers.php +++ b/mod/forum/subscribers.php @@ -4,8 +4,6 @@ require_once("lib.php"); require_variable($id); // forum - optional_variable($subscribe, ''); // 'all' or 'none' - optional_variable($unsubscribe, ''); // a single user id optional_variable($group); // change of group optional_variable($edit); // Turn editing on and off @@ -32,19 +30,14 @@ add_to_log($course->id, "forum", "view subscribers", "subscribers.php?id=$forum->id", $forum->id, $cm->id); - if (isteacheredit($course->id)) { - if (isset($_GET['edit'])) { - if($edit == "on") { - $USER->subscriptionsediting = true; - } else { - $USER->subscriptionsediting = false; - } + if (isset($_GET['edit'])) { + if($edit == "on") { + $USER->subscriptionsediting = true; + } else { + $USER->subscriptionsediting = false; } - } else { - $USER->subscriptionsediting = false; } - $strunsubscribeshort = get_string("unsubscribeshort", "forum"); $strsubscribeall = get_string("subscribeall", "forum"); $strsubscribenone = get_string("subscribenone", "forum"); $strsubscribers = get_string("subscribers", "forum"); @@ -62,77 +55,21 @@ print_header("$course->shortname: $strsubscribers", "$course->fullname", "$navigation", "", "", true, forum_update_subscriptions_button($course->id, $id)); - if (empty($USER->subscriptionsediting)) { /// Display an overview of subscribers - /// Check to see if groups are being used in this forum - if ($groupmode = groupmode($course, $cm)) { // Groups are being used - $currentgroup = setup_and_print_groups($course, $groupmode, "subscribers.php?id=$forum->id"); - } else { - $currentgroup = false; - } - - if ($subscribe == 'all') { - if ($forum->type == 'teacher') { - $users = get_course_teachers($course->id); - } elseif ($currentgroup) { - $users = get_group_users($currentgroup); - } else { - $users = get_course_users($course->id); - } - if ($users) { - foreach ($users as $user) { - forum_subscribe($user->id, $forum->id); - } - } - } else if ($subscribe == 'none') { - if ($currentgroup) { - if ($users = get_group_users($currentgroup)) { - foreach ($users as $user) { - forum_unsubscribe($user->id, $forum->id); - } - } - } else { - delete_records("forum_subscriptions", "forum", $forum->id); - } - } - - if ($unsubscribe) { - if ($user = get_record('user', 'id', $unsubscribe)) { - forum_unsubscribe($user->id, $forum->id); - $info->name = fullname($user); - $info->forum = $forum->name; - notify(get_string("nownotsubscribed", "forum", $info)); - } - } - + if ($groupmode = groupmode($course, $cm)) { // Groups are being used + $currentgroup = setup_and_print_groups($course, $groupmode, "subscribers.php?id=$forum->id"); + } else { + $currentgroup = false; + } + + if (empty($USER->subscriptionsediting)) { /// Display an overview of subscribers + if (! $users = forum_subscribed_users($course, $forum, $currentgroup) ) { - if (!$forum->forcesubscribe) { - echo '
'; - $options['id'] = $forum->id; - $options['subscribe'] = 'all'; - print_single_button('subscribers.php', $options, $strsubscribeall); - echo '
'; - } - print_heading(get_string("nosubscribers", "forum")); } else { - if (!$forum->forcesubscribe) { - echo ''; - echo ''; - echo ''; - echo '
'; - $options['id'] = $forum->id; - $options['subscribe'] = 'all'; - print_single_button('subscribers.php', $options, $strsubscribeall); - echo ''; - $options['subscribe'] = 'none'; - print_single_button('subscribers.php', $options, $strsubscribenone); - echo '
'; - } - print_heading(get_string("subscribersto","forum", "'$forum->name'")); echo ''; @@ -140,11 +77,9 @@ echo ""; } echo "
"; print_user_picture($user->id, $course->id, $user->picture); echo "cellcontent\">"; - echo "$user->firstname $user->lastname"; + echo fullname($user); echo "cellcontent\">"; echo "$user->email"; - echo ""; - echo "id&unsubscribe=$user->id\">$strunsubscribeshort"; echo "
"; @@ -196,7 +131,7 @@ $previoussearch = (!empty($frm->search) or ($frm->previoussearch == 1)) ; /// Get all existing subscribers for this forum. - if (!$subscribers = forum_subscribed_users($course, $forum)) { + if (!$subscribers = forum_subscribed_users($course, $forum, $currentgroup)) { $subscribers = array(); } @@ -228,7 +163,22 @@ $except = ''; } if (!empty($frm->searchtext) and $previoussearch) { - $searchusers = get_records_sql("SELECT u.id, u.firstname, u.lastname, u.email + if ($currentgroup) { + $searchusers = get_records_sql("SELECT u.id, u.firstname, u.lastname, u.email + FROM {$CFG->prefix}user u, + {$CFG->prefix}groups_members g + WHERE g.groupid = '$currentgroup' AND g.userid = u.id AND u.deleted = '0' + AND ($fullname $LIKE '%$frm->searchtext%' OR u.email $LIKE '%$frm->searchtext%') + $except + ORDER BY u.firstname ASC, u.lastname ASC"); + + $usercount = count_records_sql("SELECT COUNT(*) + FROM {$CFG->prefix}user u, + {$CFG->prefix}groups_members g + WHERE g.groupid = '$currentgroup' AND g.userid = u.id AND u.deleted = '0' + $except"); + } else { + $searchusers = get_records_sql("SELECT u.id, u.firstname, u.lastname, u.email FROM {$CFG->prefix}user u, {$CFG->prefix}user_students s WHERE s.course = '$course->id' AND s.userid = u.id AND u.deleted = '0' @@ -243,40 +193,48 @@ $except ORDER BY u.firstname ASC, u.lastname ASC"); - $usercount = count_records_sql("SELECT COUNT(*) + $usercount = count_records_sql("SELECT COUNT(*) FROM {$CFG->prefix}user u, {$CFG->prefix}user_students s WHERE s.course = '$course->id' AND s.userid = u.id AND u.deleted = '0' $except") + - count_records_sql("SELECT COUNT(*) + count_records_sql("SELECT COUNT(*) FROM {$CFG->prefix}user u, {$CFG->prefix}user_teachers s WHERE s.course = '$course->id' AND s.userid = u.id AND u.deleted = '0' $except"); + } } /// If no search results then get potential subscribers for this forum excluding users already subscribed if (empty($searchusers)) { - if (!$users = get_records_sql("SELECT u.id, u.firstname, u.lastname, u.email - FROM {$CFG->prefix}user u, - {$CFG->prefix}user_students s - WHERE s.course = '$course->id' AND s.userid = u.id AND u.deleted = '0' - $except - UNION - SELECT u.id, u.firstname, u.lastname, u.email - FROM {$CFG->prefix}user u, - {$CFG->prefix}user_teachers s - WHERE s.course = '$course->id' AND s.userid = u.id AND u.deleted = '0' - $except - ORDER BY u.firstname ASC, u.lastname ASC")) { + if ($currentgroup) { + $users = get_records_sql("SELECT u.id, u.firstname, u.lastname, u.email + FROM {$CFG->prefix}user u, + {$CFG->prefix}groups_members g + WHERE g.groupid = '$currentgroup' AND g.userid = u.id AND u.deleted = '0' + $except + ORDER BY u.firstname ASC, u.lastname ASC"); + } else { + $users = get_records_sql("SELECT u.id, u.firstname, u.lastname, u.email + FROM {$CFG->prefix}user u, + {$CFG->prefix}user_students s + WHERE s.course = '$course->id' AND s.userid = u.id AND u.deleted = '0' + $except + UNION + SELECT u.id, u.firstname, u.lastname, u.email + FROM {$CFG->prefix}user u, + {$CFG->prefix}user_teachers s + WHERE s.course = '$course->id' AND s.userid = u.id AND u.deleted = '0' + $except + ORDER BY u.firstname ASC, u.lastname ASC"); + } + if (!$users) { $users = array(); } $usercount = count($users); } - - - $searchtext = (isset($frm->searchtext)) ? $frm->searchtext : ""; $previoussearch = ($previoussearch) ? '1' : '0';