]> git.mjollnir.org Git - moodle.git/commitdiff
Fix for MDL-6405
authorvyshane <vyshane>
Mon, 11 Sep 2006 03:13:52 +0000 (03:13 +0000)
committervyshane <vyshane>
Mon, 11 Sep 2006 03:13:52 +0000 (03:13 +0000)
mod/forum/post.php

index 04252e6bcd4ac4f26abbe6cd0d6dc186c1d888e1..5026d5573413d6b77c4c72167489213adddff336 100644 (file)
@@ -14,7 +14,6 @@
     $confirm = optional_param('confirm',0,PARAM_INT);
     
     
-    
     if (isguest()) {
         $wwwroot = $CFG->wwwroot.'/login/index.php';
         if (!empty($CFG->loginhttps)) {
@@ -41,8 +40,7 @@
         }
         
         if (!$cm = get_coursemodule_from_instance('forum', $forum->id, $course->id)) { // For the logs
-            // Teacher forum?
-            $cm->id = 0;
+            error('Could not get the course module for the forum instance.');
         } else {
             $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
         }
@@ -92,7 +90,7 @@
         $post->attachment = isset($_FILES['attachment']) ? $_FILES['attachment'] : NULL;
 
         if (!$cm = get_coursemodule_from_instance("forum", $post->forum, $course->id)) { // For the logs
-            $cm->id = 0;
+            error('Could not get the course module for the forum instance.');
         }
         $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
         trusttext_after_edit($post->message, $modcontext);
         if (! $post = forum_get_post_full($edit)) {
             error("Post ID was incorrect");
         }
-        if (($post->userid <> $USER->id) and
-                    !has_capability('mod/forum:editanypost', $modcontext)) {
-            error("You can't edit other people's posts!");
-        }
         if ($post->parent) {
             if (! $parent = forum_get_post_full($post->parent)) {
                 error("Parent post ID was incorrect ($post->parent)");
         if (! $course = get_record("course", "id", $discussion->course)) {
             error("The course number was incorrect ($discussion->course)");
         }
+        if (!$cm = get_coursemodule_from_instance("forum", $forum->id, $course->i)) {
+            error('Could not get the course module for the forum instance.');
+        } else {
+            $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
+        }
+        if (($post->userid <> $USER->id) and
+                    !has_capability('mod/forum:editanypost', $modcontext)) {
+            error("You can't edit other people's posts!");
+        }
 
         // Load up the $post variable.
-
         $post->edit = $edit;
 
         $post->course  = $course->id;
             error("The forum number was incorrect ($discussion->forum)");
         }
         if (!$cm = get_coursemodule_from_instance("forum", $forum->id, $forum->course)) {
-            $cm->id = 0;
+            error('Could not get the course module for the forum instance.');
         } else {
             $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
         }
             forum_set_return();
 
             if ($replycount) {
-                if (!has_capability('mof/forum:deleteanypost', $modcontext)) {
+                if (!has_capability('mod/forum:deleteanypost', $modcontext)) {
                     error(get_string("couldnotdeletereplies", "forum"),
                           forum_go_back_to("discuss.php?d=$post->discussion"));
                 }
         die;
 
 
-    } else if (!empty($prune)) {  // Teacher is pruning
+    } else if (!empty($prune)) {  // Pruning
 
         if (!$post = forum_get_post_full($prune)) {
             error("Post ID was incorrect");
         if (!$forum = get_record("forum", "id", $discussion->forum)) {
             error("The forum number was incorrect ($discussion->forum)");
         }
-        if (!has_capability('mod/forum:splitdiscussions', $modcontext)) {
-            error("You can't split discussions!");
-        }
         if (!$post->parent) {
             error('This is already the first post in the discussion');
         }
         if (!$cm = get_coursemodule_from_instance("forum", $forum->id, $forum->course)) { // For the logs
-            $cm->id = 0;
+            error('Could not get the course module for the forum instance.');
+        } else {
+            $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
+        }
+        if (!has_capability('mod/forum:splitdiscussions', $modcontext)) {
+            error("You can't split discussions!");
         }
 
         if (!empty($name)) {    // User has confirmed the prune