]> git.mjollnir.org Git - moodle.git/commitdiff
Fix for MDL-3975. Also added function in rsslib.php to delete cached RSS feeds for...
authorvyshane <vyshane>
Tue, 26 Sep 2006 08:37:56 +0000 (08:37 +0000)
committervyshane <vyshane>
Tue, 26 Sep 2006 08:37:56 +0000 (08:37 +0000)
mod/forum/discuss.php
mod/forum/lib.php
mod/forum/rsslib.php
mod/forum/view.php

index cabb402b202b5f415279c5ee5c06d1349ba1647f..36620ce4f22866bfb094e8818ce690513ba01cba 100644 (file)
@@ -6,12 +6,13 @@
     require_once("../../config.php");
     require_once("lib.php");
 
-    $d      = required_param('d', PARAM_INT);         // Discussion ID
-    $parent = optional_param('parent', 0, PARAM_INT); // If set, then display this post and all children.
-    $mode   = optional_param('mode', 0, PARAM_INT);   // If set, changes the layout of the thread
-    $move   = optional_param('move', 0, PARAM_INT);   // If set, moves this discussion to another forum
-    $mark   = optional_param('mark', 0, PARAM_INT);   // Used for tracking read posts if user initiated.
-    $postid = optional_param('postid', 0, PARAM_INT); // Used for tracking read posts if user initiated.
+    $d      = required_param('d', PARAM_INT);                // Discussion ID
+    $parent = optional_param('parent', 0, PARAM_INT);        // If set, then display this post and all children.
+    $mode   = optional_param('mode', 0, PARAM_INT);          // If set, changes the layout of the thread
+    $move   = optional_param('move', 0, PARAM_INT);          // If set, moves this discussion to another forum
+    $fromforum = optional_param('fromforum', 0, PARAM_INT);  // Needs to be set when we want to move a discussion.
+    $mark   = optional_param('mark', 0, PARAM_INT);          // Used for tracking read posts if user initiated.
+    $postid = optional_param('postid', 0, PARAM_INT);        // Used for tracking read posts if user initiated.
 
     if (!$discussion = get_record("forum_discussions", "id", $d)) {
         error("Discussion ID was incorrect or no longer exists");
 
 
     if (!empty($move)) {
+        
+        if (!$sourceforum = get_record('forum', 'id', $fromforum)) {
+            error('Cannot find which forum this discussion is being moved from');
+        }
+        if ($sourceforum->type == 'single') {
+            error('Cannot move discussion from a simple single discussion forum');
+        }
+        
         require_capability('mod/forum:movediscussions', $modcontext);
 
         if ($forum = get_record("forum", "id", $move)) {
                 add_to_log($course->id, "forum", "move discussion", "discuss.php?d=$discussion->id", "$discussion->id");
             }
             $discussionmoved = true;
+            
             require_once('rsslib.php');
             require_once($CFG->libdir.'/rsslib.php');
 
             // Delete the RSS files for the 2 forums because we want to force
             // the regeneration of the feeds since the discussions have been
             // moved.
-            if (!forum_rss_delete_file($forum) || !forum_rss_delete_file($fromforum)) {
+            if (!forum_rss_delete_file($forum) || !forum_rss_delete_file($sourceforum)) {
                 notify('Could not purge the cached RSS feeds for the source and/or'.
                        'destination forum(s) - check your file permissionsforums');
             }
                 }
                 $section = $courseforum->section;
                 if ($courseforum->id != $forum->id) {
-                    $url = "discuss.php?d=$discussion->id&amp;move=$courseforum->id";
+                    $url = "discuss.php?d=$discussion->id&amp;fromforum=$discussion->forum&amp;move=$courseforum->id";
                     $forummenu[$url] = format_string($courseforum->name,true);
                 }
             }
index 4d1b13498fc578d56efd2ff46bfb9660237c9b0f..1bc243216a6556a959734007084ba5f4016a9ea7 100644 (file)
@@ -2397,11 +2397,23 @@ function forum_print_rating_menu($postid, $userid, $scale) {
     choose_from_menu($scale, $postid, $rating->rating, "$strrate...");
 }
 
-function forum_print_mode_form($discussion, $mode) {
+/**
+ * Print the drop down that allows the user to select how they want to have
+ * the discussion displayed.
+ * @param $id - forum id if $forumtype is 'single',
+ *              discussion id for any other forum type
+ * @param $mode - forum layout mode
+ * @param $forumtype - optional
+ */
+function forum_print_mode_form($id, $mode, $forumtype='') {
     GLOBAL $FORUM_LAYOUT_MODES;
 
     echo "<div align=\"center\">";
-    popup_form("discuss.php?d=$discussion&amp;mode=", $FORUM_LAYOUT_MODES, "mode", $mode, "");
+    if ($forumtype == 'single') {
+        popup_form("view.php?f=$id&amp;mode=", $FORUM_LAYOUT_MODES, "mode", $mode, "");
+    } else {
+        popup_form("discuss.php?d=$id&amp;mode=", $FORUM_LAYOUT_MODES, "mode", $mode, "");
+    }
     echo "</div>\n";
 }
 
index 01dd46f443b18b3b474f10ce6350aae4df5664b7..02166cfbf77a3f2776e3c4a679558b96a9c22626 100644 (file)
         return $status;
     }
 
+
+    // Given a forum object, deletes the RSS file
+    function forum_rss_delete_file($forum) {
+        global $CFG;
+        $rssfile = rss_file_name('forum', $forum);
+        if (file_exists($rssfile)) {
+            return unlink($rssfile);
+        } else {
+            return true;
+        }
+    }
+
+
     function forum_rss_newstuff($forum, $time) {
     // If there is new stuff in the forum since $time then this returns
     // true.  Otherwise it returns false.
index 95541c176fb50117a60cfeec7ce49349bc713157..509023ecf08efe14977f3a4cb3f706e8c44dc5dc 100644 (file)
@@ -61,7 +61,7 @@
 
 
     require_course_login($course, true, $cm);
-
+    $context = get_context_instance(CONTEXT_MODULE, $cm->id);
 
 
 /// Print header.
                  "$navigation ".format_string($forum->name), "", "", true, $buttontext, navmenu($course, $cm));
 
 
-
-/// Check whether the user should be able to view this forum.
-    $context = get_context_instance(CONTEXT_MODULE, $cm->id);
-    
+/// Some capability checks.
     if (empty($cm->visible) and !has_capability('moodle/course:viewhiddenactivities', $context)) {
         notice(get_string("activityiscurrentlyhidden"));
     }
 
 
 
-/// Print settings and things in a table across the top
+/// Print settings and things across the top
+
+    // If it's a simple single discussion forum, we need to print the display
+    // mode control.
+    if ($forum->type == 'single') {
+        if (! $discussion = get_record("forum_discussions", "forum", $forum->id)) {
+            if ($discussions = get_records("forum_discussions", "forum", $forum->id, "timemodified ASC")) {
+                $discussion = array_pop($discussions);
+            }
+        }
+        if ($discussion) {
+            if ($mode) {
+                set_user_preference("forum_displaymode", $mode);
+            }
+            $displaymode = get_user_preferences("forum_displaymode", $CFG->forum_displaymode);
+            forum_print_mode_form($forum->id, $displaymode, $forum->type);
+        }
+    }
+
     echo '<table width="100%" border="0" cellpadding="3" cellspacing="0"><tr valign="top">';
 
     /// 2 ways to do this, 1. we can changed the setup_and_print_groups functions