]> git.mjollnir.org Git - moodle.git/commitdiff
Improved subscription editing interface according to discussion at http://moodle...
authorgustav_delius <gustav_delius>
Sun, 15 Aug 2004 21:01:34 +0000 (21:01 +0000)
committergustav_delius <gustav_delius>
Sun, 15 Aug 2004 21:01:34 +0000 (21:01 +0000)
lang/en/forum.php
mod/forum/lib.php
mod/forum/subscribers.php

index 8ef3c0420066656a6658706426c0fae085072272..f01bfd2d2653ccdb2d02dc02ec713ba443568251 100644 (file)
@@ -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';
index dd3fa71958a5a8506e78c1f2a206cff1488ae1fa..14394597d51b2a72de621137b64681a17b740fc0 100644 (file)
@@ -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";
index a398dfc9ad3818a265c3edbe0e72f0c0d0b3873a..263bc00f39fc7f9bcaf14948853fa82b8fef73f1 100644 (file)
@@ -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
 
     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");
     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 '<center>';
-                $options['id'] = $forum->id;
-                $options['subscribe'] = 'all';
-                print_single_button('subscribers.php', $options, $strsubscribeall);
-                echo '</center>';
-            }
-    
             print_heading(get_string("nosubscribers", "forum"));
     
         } else {
     
-            if (!$forum->forcesubscribe) {
-                echo '<table align="center"><tr>';
-                echo '<td>';
-                $options['id'] = $forum->id;
-                $options['subscribe'] = 'all';
-                print_single_button('subscribers.php', $options, $strsubscribeall);
-                echo '</td>';
-                echo '<td>';
-                $options['subscribe'] = 'none';
-                print_single_button('subscribers.php', $options, $strsubscribenone);
-                echo '</td>';
-                echo '</tr></table>';
-            }
-    
             print_heading(get_string("subscribersto","forum", "'$forum->name'"));
     
             echo '<table align="center" cellpadding="5" cellspacing="5">';
                 echo "<tr><td>";
                 print_user_picture($user->id, $course->id, $user->picture);
                 echo "</td><td bgcolor=\"$THEME->cellcontent\">";
-                echo "$user->firstname $user->lastname";
+                echo fullname($user);
                 echo "</td><td bgcolor=\"$THEME->cellcontent\">";
                 echo "$user->email";
-                echo "</td><td>";
-                echo "<font size=1><a href=\"subscribers.php?id=$forum->id&unsubscribe=$user->id\">$strunsubscribeshort</a></font>";
                 echo "</td></tr>";
             }
             echo "</table>";
     $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();
     }
     
         $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'
                                   $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';