]> git.mjollnir.org Git - moodle.git/commitdiff
Merging changes from Moodle 13 Stable
authormoodler <moodler>
Wed, 7 Jul 2004 17:42:53 +0000 (17:42 +0000)
committermoodler <moodler>
Wed, 7 Jul 2004 17:42:53 +0000 (17:42 +0000)
mod/forum/db/mysql.php
mod/forum/db/mysql.sql
mod/forum/discuss.php
mod/forum/index.php
mod/forum/lib.php
mod/forum/post.php
mod/forum/version.php
mod/forum/view.php

index 896d3e234a3f440fd55ee9f92d42df4ccec43cfc..ffb527f819a3d7496df595239d7fe4de2ad17f50 100644 (file)
@@ -127,6 +127,10 @@ function forum_upgrade($oldversion) {
                               ) TYPE=MyISAM COMMENT='For keeping track of posts that will be mailed in digest form';");
   }
 
+  if ($oldversion < 2004070700) {    // This may be redoing it from STABLE but that's OK
+      table_column("forum_discussions", "groupid", "groupid", "integer", "10", "", "0", "");
+  }
+
   return true;
 
 }
index 6b542a97efd611fb8ffda9043ea383fd63cdc56b..278675243ac70d57b566fbcba749c2aaad0ee864 100644 (file)
@@ -35,7 +35,7 @@ CREATE TABLE prefix_forum_discussions (
   name varchar(255) NOT NULL default '',
   firstpost int(10) unsigned NOT NULL default '0',
   userid int(10) unsigned NOT NULL default '0',
-  groupid int(10) unsigned NOT NULL default '0',
+  groupid int(10) NOT NULL default '-1',
   assessed tinyint(1) NOT NULL default '1',
   timemodified int(10) unsigned NOT NULL default '0',
   usermodified int(10) unsigned NOT NULL default '0',
index 0dc54660972ef81d547e3a5f80bffa132d65b8e7..50301a99cb0d3cbe65c43139f275da5359fb6cbf 100644 (file)
 
             if (mygroupid($course->id) == $discussion->groupid) {
                 $canreply = true;
+            } elseif ($discussion->groupid == -1) {
+                $canreply = false;
             } else {
                 print_heading("Sorry, you can't see this discussion because you are not in this group");
                 print_footer();
index d585ca415ba7b6f557072ab1e32622246ec09cb0..47dd7eca0e36ecb04f6c092dc2b3fd68b1802b9d 100644 (file)
             }
                 
             if ($groupmode == SEPARATEGROUPS and !isteacheredit($course->id)) {
-                $count = count_records("forum_discussions", "forum", "$forum->id", "groupid", $currentgroup);
+                $count = count_records_select("forum_discussions", "forum = '$forum->id' AND (groupid = '$currentgroup' OR groupid = '-1')");
             } else {
                 $count = count_records("forum_discussions", "forum", "$forum->id");
             }
index f407f4911b8a1649819352ba0a6cc6bf0107620b..88410ffd1c498d6598e12bf109045c8efe212879 100644 (file)
@@ -251,7 +251,7 @@ function forum_cron () {
 
             $groupmode = false;
             if ($cm = get_coursemodule_from_instance("forum", $forum->id, $course->id)) {
-                if ($groupmode = groupmode($course, $cm)) {                  // Groups are being used
+                if ($groupmode = groupmode($course, $cm) and $discussion->groupid > 0) {   // Groups are being used
                     if (!$group = get_record("groups", "id", $discussion->groupid)) {   // Can't find group
                         continue;                                            // Be safe and don't send it to anyone
                     }
@@ -267,8 +267,10 @@ function forum_cron () {
                 foreach ($users as $userto) {
                     if ($groupmode) {    // Look for a reason not to send this email
                         if (!isteacheredit($course->id, $userto->id)) {
-                            if (!ismember($group->id, $userto->id)) {
-                                continue;
+                            if (!empty($group->id)) {
+                                if (!ismember($group->id, $userto->id)) {
+                                    continue;
+                                }
                             }
                         }
                     }
@@ -634,7 +636,7 @@ function forum_print_recent_activity($course, $isteacher, $timestart) {
                 /// Check whether this is belongs to a discussion in a group that
                 /// should NOT be accessible to the current user
 
-                if (!$isteacheredit) {   /// Because editing teachers can see everything anyway
+                if (!$isteacheredit and $post->groupid != -1) {   /// Editing teachers or open discussions
                     if (!isset($cm[$post->forum])) {
                         $cm[$forum->id] = get_coursemodule_from_instance("forum", $forum->id, $course->id);
                         $groupmode[$forum->id] = groupmode($course, $cm[$forum->id]);
@@ -1069,7 +1071,7 @@ function forum_count_unrated_posts($discussionid, $userid) {
 }
 
 function forum_get_discussions($forum="0", $forumsort="d.timemodified DESC",
-                               $user=0, $fullpost=true, $currentgroup=0) {
+                               $user=0, $fullpost=true, $visiblegroups=-1) {
 /// Get all discussions in a forum
     global $CFG;
 
@@ -1078,11 +1080,14 @@ function forum_get_discussions($forum="0", $forumsort="d.timemodified DESC",
     } else {
         $userselect = "";
     }
-    if ($currentgroup) {
-        $groupselect = " AND d.groupid = '$currentgroup' ";
-    } else  {
+
+    
+    if ($visiblegroups == -1) {
         $groupselect = "";
+    } else  {
+        $groupselect = " AND (d.groupid = '$visiblegroups' OR d.groupid = '-1') ";
     }
+
     if (empty($forumsort)) {
         $forumsort = "d.timemodified DESC";
     }
@@ -1116,7 +1121,7 @@ function forum_get_user_discussions($courseid, $userid, $groupid=0) {
         $groupselect = "";
     }
 
-    return get_records_sql("SELECT p.*, u.firstname, u.lastname, u.email, u.picture,
+    return get_records_sql("SELECT p.*, d.groupid, u.firstname, u.lastname, u.email, u.picture,
                                    f.type as forumtype, f.name as forumname, f.id as forumid
                               FROM {$CFG->prefix}forum_discussions d,
                                    {$CFG->prefix}forum_posts p,
@@ -1744,7 +1749,7 @@ function forum_print_search_form($course, $search="", $return=false, $type="") {
         $output = "<table border=0 cellpadding=0 cellspacing=0><tr><td nowrap>";
         $output .= "<form name=search action=\"$CFG->wwwroot/mod/forum/search.php\">";
         $output .= "<font size=\"-1\">";
-        $output .= "<input name=search type=text size=20 value=\"$search\">";
+        $output .= "<input name=search type=text size=15 value=\"$search\">";
         $output .= "<input value=\"".get_string("searchforums", "forum")."\" type=submit>";
         $output .= "</font>";
         $output .= "<input name=id type=hidden value=\"$course->id\">";
@@ -1754,7 +1759,7 @@ function forum_print_search_form($course, $search="", $return=false, $type="") {
         $output = "<table border=0 cellpadding=10 cellspacing=0><tr><td align=center>";
         $output .= "<form name=search action=\"$CFG->wwwroot/mod/forum/search.php\">";
         $output .= "<font size=\"-1\">";
-        $output .= "<input name=search type=text size=20 value=\"$search\"><br>";
+        $output .= "<input name=search type=text size=15 value=\"$search\"><br>";
         $output .= "<input value=\"".get_string("searchforums", "forum")."\" type=submit>";
         $output .= "</font>";
         $output .= "<input name=id type=hidden value=\"$course->id\">";
@@ -2106,12 +2111,22 @@ function forum_print_user_discussions($courseid, $userid, $groupid=0) {
 
     $visible = array();
 
+    $course = get_record("course", "id", $courseid);
+
+    $currentgroup = get_current_group($courseid);
+    $isteacheredit = isteacheredit($courseid);
+
     if ($discussions = forum_get_user_discussions($courseid, $userid, $groupid=0)) {
-        $user = get_record("user", "id", $userid);
-        echo "<hr />";
+
+        $user    = get_record("user", "id", $userid);
         $fullname = fullname($user, isteacher($courseid));
-        print_heading( get_string("discussionsstartedbyrecent", "forum", $fullname) );
+
         $replies = forum_count_discussion_replies();
+
+        echo "<hr />";
+
+        print_heading( get_string("discussionsstartedbyrecent", "forum", $fullname) );
+
         foreach ($discussions as $discussion) {
             $countdiscussions++;
             if ($countdiscussions > $maxdiscussions) {
@@ -2129,6 +2144,22 @@ function forum_print_user_discussions($courseid, $userid, $groupid=0) {
             if(!$visible[$discussion->forumid] && !isteacheredit($courseid, $USER->id)) {
                 continue;
             }
+
+            /// Check whether this is belongs to a discussion in a group that
+            /// should NOT be accessible to the current user
+
+            if (!$isteacheredit and $discussion->groupid != -1) {   /// Editing teachers or open discussions
+                if (!isset($cm[$discussion->forum])) {
+                    $cm[$discussion->forum] = get_coursemodule_from_instance("forum", $discussion->forum, $courseid);
+                    $groupmode[$discussion->forum] = groupmode($course, $cm[$discussion->forum]);
+                }
+                if ($groupmode[$discussion->forum] == SEPARATEGROUPS) {
+                    if ($currentgroup != $discussion->groupid) {
+                        continue;
+                    }
+                }
+            }
+
             if (!empty($replies[$discussion->discussion])) {
                 $discussion->replies = $replies[$discussion->discussion]->replies;
             } else {
@@ -2253,7 +2284,7 @@ function forum_user_can_post($forum, $user=NULL) {
 
 function forum_print_latest_discussions($forum_id=0, $forum_numdiscussions=5,
                                         $forum_style="plain", $forum_sort="",
-                                        $currentgroup=0) {
+                                        $currentgroup=0, $groupmode=-1) {
     global $CFG, $USER;
 
     if ($forum_id) {
@@ -2277,6 +2308,15 @@ function forum_print_latest_discussions($forum_id=0, $forum_numdiscussions=5,
         }
     }
 
+    if ($groupmode == -1) {    /// We need to reconstruct groupmode because none was given
+        if ($cm = get_coursemodule_from_instance("forum", $forum->id, $course->id)) {
+            $groupmode = groupmode($course, $cm);
+        } else {
+            $groupmode = SEPARATEGROUPS;
+        }
+    }
+    
+
     if (forum_user_can_post_discussion($forum, $currentgroup)) {
         echo "<p align=center>";
         echo "<a href=\"$CFG->wwwroot/mod/forum/post.php?forum=$forum->id\">";
@@ -2301,7 +2341,18 @@ function forum_print_latest_discussions($forum_id=0, $forum_numdiscussions=5,
         $fullpost = true;
     }
 
-    if (! $discussions = forum_get_discussions($forum->id, $forum_sort, 0, $fullpost, $currentgroup) ) {
+
+/// Decides if current user is allowed to see ALL the current discussions or not
+
+    if (!$currentgroup and ($groupmode != SEPARATEGROUPS or isteacheredit($forum->course)) ) {
+        $visiblegroups = -1;
+    } else {
+        $visiblegroups = $currentgroup;
+    }
+
+/// Get all the recent discussions we're allowed to see
+
+    if (! $discussions = forum_get_discussions($forum->id, $forum_sort, 0, $fullpost, $visiblegroups) ) {
         if ($forum->type == "news") {
             echo "<p align=center><b>(".get_string("nonews", "forum").")</b></p>";
         } else {
@@ -2555,14 +2606,14 @@ function forum_print_posts_nested($parent, $course, $ratings, $reply) {
     return $ratingsmenuused;
 }
 
-function forum_get_recent_mod_activity(&$activities, &$index, $sincetime, $courseid, $forum="0", $user="", $groupid="") {
+function forum_get_recent_mod_activity(&$activities, &$index, $sincetime, $courseid, $cmid="0", $user="", $groupid="") {
 // Returns all forum posts since a given time.  If forum is specified then
 // this restricts the results
 
     global $CFG;
 
-    if ($forum) {
-        $forumselect = " AND cm.id = '$forum'";
+    if ($cmid) {
+        $forumselect = " AND cm.id = '$cmid'";
     } else {
         $forumselect = "";
     }
@@ -2583,39 +2634,44 @@ function forum_get_recent_mod_activity(&$activities, &$index, $sincetime, $cours
                               WHERE p.modified > '$sincetime' $forumselect
                                 AND p.userid = u.id $userselect
                                 AND d.course = '$courseid'
-                                AND p.discussion = d.id $groupselect
+                                AND p.discussion = d.id 
                                 AND cm.instance = f.id
                                 AND cm.course = d.course
                                 AND cm.course = f.course
                                 AND f.id = d.forum
                               ORDER BY d.id");
 
-    if (empty($posts))
-      return;
+    if (empty($posts)) {
+        return;
+    }
+
+    $isteacheredit = isteacheredit($courseid);
 
     foreach ($posts as $post) {
 
-        if (empty($groupid) || ismember($groupid, $post->userid)) {
-            $tmpactivity->type = "forum";
-            $tmpactivity->defaultindex = $index;
-            $tmpactivity->instance = $post->instance;
-            $tmpactivity->name = $post->name;
-            $tmpactivity->section = $post->section;
+        if ($groupid and ($post->groupid != -1 and $groupid != $post->groupid and !$isteacheredit)) {
+            continue;
+        }
 
-            $tmpactivity->content->id = $post->id;
-            $tmpactivity->content->discussion = $post->discussion;
-            $tmpactivity->content->subject = $post->subject;
-            $tmpactivity->content->parent = $post->parent;
+        $tmpactivity->type = "forum";
+        $tmpactivity->defaultindex = $index;
+        $tmpactivity->instance = $post->instance;
+        $tmpactivity->name = $post->name;
+        $tmpactivity->section = $post->section;
 
-            $tmpactivity->user->userid = $post->userid;
-            $tmpactivity->user->fullname = fullname($post);
-            $tmpactivity->user->picture = $post->picture;
+        $tmpactivity->content->id = $post->id;
+        $tmpactivity->content->discussion = $post->discussion;
+        $tmpactivity->content->subject = $post->subject;
+        $tmpactivity->content->parent = $post->parent;
 
-            $tmpactivity->timestamp = $post->modified;
-            $activities[] = $tmpactivity;
+        $tmpactivity->user->userid = $post->userid;
+        $tmpactivity->user->fullname = fullname($post);
+        $tmpactivity->user->picture = $post->picture;
 
-            $index++;
-        }
+        $tmpactivity->timestamp = $post->modified;
+        $activities[] = $tmpactivity;
+
+        $index++;
     }
 
     return;
index 6ae9abd1d867331a0744309129547adcc7dda923..62934e23f17b408a8cfbdcd2e5fa2e78b447dca1 100644 (file)
         $post->parent = 0;
         $post->subject = "";
         $post->userid = $USER->id;
-        $post->groupid = get_current_group($course->id);
         $post->message = "";
         $post->format = $defaultformat;
 
+        $post->groupid = get_current_group($course->id);
+        if (isteacheredit($course->id) and $post->groupid == 0) {
+            $post->groupid = -1;
+        }
+
         forum_set_return();
 
     } else if (isset($reply)) {      // User is writing a new reply
index 60d6eb629e4b86f873026b77af5265dfa52b7287..55fc578e29fa983b9a39a691842dafac64da130d 100644 (file)
@@ -5,7 +5,7 @@
 //  This fragment is called by /admin/index.php
 ////////////////////////////////////////////////////////////////////////////////
 
-$module->version  = 2004060400;
+$module->version  = 2004070700;
 $module->requires = 2004060100;  // Requires this Moodle version
 $module->cron     = 60;
 
index f6e253e55c981d837abc6bb8a6d4cb71d379d41a..51a7792c15d5d753562c5bcb3fdc211bfaa45446 100644 (file)
             }
             echo '</p>';
             if (!empty($showall)) {
-                forum_print_latest_discussions($forum->id, 0, 'header', '', $currentgroup);
+                forum_print_latest_discussions($forum->id, 0, 'header', '', $currentgroup, $groupmode);
             } else {
-                forum_print_latest_discussions($forum->id, $CFG->forum_manydiscussions, 'header', '', $currentgroup);
+                forum_print_latest_discussions($forum->id, $CFG->forum_manydiscussions, 'header', '', $currentgroup, $groupmode);
             }
             break;
 
         case 'teacher':
             if (!empty($showall)) {
-                forum_print_latest_discussions($forum->id, 0, 'header', '', $currentgroup);
+                forum_print_latest_discussions($forum->id, 0, 'header', '', $currentgroup, $groupmode);
             } else {
-                forum_print_latest_discussions($forum->id, $CFG->forum_manydiscussions, 'header', '', $currentgroup);
+                forum_print_latest_discussions($forum->id, $CFG->forum_manydiscussions, 'header', '', $currentgroup, $groupmode);
             }
             break;
 
             }
             echo '<p>&nbsp;</p>';
             if (!empty($showall)) {
-                forum_print_latest_discussions($forum->id, 0, 'header', '', $currentgroup);
+                forum_print_latest_discussions($forum->id, 0, 'header', '', $currentgroup, $groupmode);
             } else {
-                forum_print_latest_discussions($forum->id, $CFG->forum_manydiscussions, 'header', '', $currentgroup);
+                forum_print_latest_discussions($forum->id, $CFG->forum_manydiscussions, 'header', '', $currentgroup, $groupmode);
             }
             break;
     }