Permalink
Browse files

A teacher can now delete any post (as long as it doesn't have replies).

  • Loading branch information...
1 parent d0daec3 commit 64eacd6f768b5bd60fe718c82ea6a62b3f4b4b61 martin committed Aug 5, 2002
Showing with 29 additions and 11 deletions.
  1. +16 −5 mod/forum/lib.php
  2. +13 −6 mod/forum/post.php
View
@@ -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;
View
@@ -156,12 +156,15 @@
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
@@ -176,17 +179,21 @@
} 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");
}

0 comments on commit 64eacd6

Please sign in to comment.