]> git.mjollnir.org Git - moodle.git/commitdiff
A teacher can now delete any post (as long as it doesn't have replies).
authormartin <martin>
Mon, 5 Aug 2002 09:48:17 +0000 (09:48 +0000)
committermartin <martin>
Mon, 5 Aug 2002 09:48:17 +0000 (09:48 +0000)
mod/forum/lib.php
mod/forum/post.php

index 2c873f4e115d6ecf817c12e37a75fbe24a0e51ac..523bc0a9bd2c195683b66059378ef39b1e6def25 100644 (file)
@@ -196,15 +196,18 @@ function forum_print_post(&$post, $courseid, $ownpost=false, $reply=false, $link
         if ($age < $CFG->maxeditingtime) {
             echo "<A HREF=\"$CFG->wwwroot/mod/forum/post.php?edit=$post->id\">".get_string("edit", "forum")."</A> | ";
         }
+    }
+    if ($ownpost or isteacher($courseid)) {
         echo "<A HREF=\"$CFG->wwwroot/mod/forum/post.php?delete=$post->id\">".get_string("delete", "forum")."</A>";
         if ($reply) {
-            echo "| <A HREF=\"$CFG->wwwroot/mod/forum/post.php?reply=$post->id\">".get_string("reply", "forum")."</A>";
+            echo "| ";
+        } else {
+            echo "&nbsp;&nbsp;";
         }
+    }
+    if ($reply) {
+        echo "<A HREF=\"$CFG->wwwroot/mod/forum/post.php?reply=$post->id\">".get_string("reply", "forum")."</A>";
         echo "&nbsp;&nbsp;";
-    } else {
-        if ($reply) {
-            echo "<A HREF=\"$CFG->wwwroot/mod/forum/post.php?reply=$post->id\">".get_string("reply", "forum")."</A>&nbsp;&nbsp;";
-        }
     }
 
 
@@ -423,6 +426,14 @@ function forum_delete_discussion($discussion) {
 }
 
 
+function forum_delete_post($postid) {
+   if (delete_records("forum_posts", "id", $postid)) {
+       delete_records("forum_ratings", "post", $postid);  // Just in case
+       return true;
+   }
+   return false;
+}
+
 
 function forum_print_user_discussions($courseid, $userid) {
     global $CFG, $USER;
index ad6789139c4b10d362332e34cab66ed558f43323..9ddaf2284870e073af4757d28bd99861e12e30fe 100644 (file)
         if (! $post = forum_get_post_full($delete)) {
             error("Post ID was incorrect");
         }
-        if ($post->user <> $USER->id) {
-            error("You can't delete other people's posts!");
-        }
         if (! $discussion = get_record("forum_discussions", "id", $post->discussion)) {
             error("This post is not part of a discussion!");
         }
+        if (! $forum = get_record("forum", "id", $discussion->forum)) {
+            error("The forum number was incorrect ($discussion->forum)");
+        }
+        if (($post->user <> $USER->id) and !isteacher($forum->course)) {
+            error("You can't delete other people's posts!");
+        }
 
         if (isset($confirm)) {    // User has confirmed the delete
 
 
             } else {
                 if (! $post->parent) {  // post is a discussion topic as well, so delete discussion
+                    if ($forum->type == "single") {
+                        notice("Sorry, but you are not allowed to delete that discussion!", 
+                                forum_go_back_to("discuss.php?d=$post->discussion"));
+                    }
                     forum_delete_discussion($discussion);
 
                     add_to_log($discussion->course, "forum", "delete discussion", "view.php?id=$discussion->forum", "$post->id");
                     redirect("view.php?f=$discussion->forum", 
-                             "Your discussion topic was deleted", 1);
+                             "The discussion topic has been deleted", 1);
 
-                } else if (delete_records("forum_posts", "id", $post->id)) {
+                } else if (forum_delete_post($post->id)) {
 
                     add_to_log($discussion->course, "forum", "delete post", "discuss.php?d=$post->discussion", "$post->id");
                     redirect(forum_go_back_to("discuss.php?d=$post->discussion"), 
-                             "Your post was deleted", 1);
+                             "The post has been deleted", 1);
                 } else {
                     error("An error occurred while deleting record $post->id");
                 }