From 64eacd6f768b5bd60fe718c82ea6a62b3f4b4b61 Mon Sep 17 00:00:00 2001 From: martin Date: Mon, 5 Aug 2002 09:48:17 +0000 Subject: [PATCH] A teacher can now delete any post (as long as it doesn't have replies). --- mod/forum/lib.php | 21 ++++++++++++++++----- mod/forum/post.php | 19 +++++++++++++------ 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/mod/forum/lib.php b/mod/forum/lib.php index 2c873f4e11..523bc0a9bd 100644 --- a/mod/forum/lib.php +++ b/mod/forum/lib.php @@ -196,15 +196,18 @@ function forum_print_post(&$post, $courseid, $ownpost=false, $reply=false, $link if ($age < $CFG->maxeditingtime) { echo "wwwroot/mod/forum/post.php?edit=$post->id\">".get_string("edit", "forum")." | "; } + } + if ($ownpost or isteacher($courseid)) { echo "wwwroot/mod/forum/post.php?delete=$post->id\">".get_string("delete", "forum").""; if ($reply) { - echo "| wwwroot/mod/forum/post.php?reply=$post->id\">".get_string("reply", "forum").""; + echo "| "; + } else { + echo "  "; } + } + if ($reply) { + echo "wwwroot/mod/forum/post.php?reply=$post->id\">".get_string("reply", "forum").""; echo "  "; - } else { - if ($reply) { - echo "wwwroot/mod/forum/post.php?reply=$post->id\">".get_string("reply", "forum")."  "; - } } @@ -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; diff --git a/mod/forum/post.php b/mod/forum/post.php index ad6789139c..9ddaf22848 100644 --- a/mod/forum/post.php +++ b/mod/forum/post.php @@ -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"); } -- 2.39.5