From b8be40ce52c96b4837ddb2adc29bc4da8c4190c6 Mon Sep 17 00:00:00 2001
From: moodler <moodler>
Date: Wed, 18 Feb 2004 03:30:05 +0000
Subject: [PATCH] Variable $CFG->admineditalways will enable admin editing all
 the time

---
 mod/forum/lib.php  | 7 ++++---
 mod/forum/post.php | 6 ++++--
 2 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/mod/forum/lib.php b/mod/forum/lib.php
index 443612f001..7ba8e0171c 100644
--- a/mod/forum/lib.php
+++ b/mod/forum/lib.php
@@ -1126,7 +1126,7 @@ function forum_print_post(&$post, $courseid, $ownpost=false, $reply=false, $link
 
     global $THEME, $USER, $CFG;
 
-    static $stredit, $strdelete, $strreply, $strparent, $threadedmode, $isteacher;
+    static $stredit, $strdelete, $strreply, $strparent, $threadedmode, $isteacher, $adminedit;
 
     if (empty($stredit)) {
         $stredit = get_string("edit", "forum");
@@ -1135,6 +1135,7 @@ function forum_print_post(&$post, $courseid, $ownpost=false, $reply=false, $link
         $strparent = get_string("parent", "forum");
         $threadedmode = (!empty($USER->mode) and ($USER->mode == FORUM_MODE_THREADED));
         $isteacher = isteacher($courseid);
+        $adminedit = (isadmin() and !empty($CFG->admineditalways));
     }
 
     echo "<a name=\"$post->id\"></a>";
@@ -1213,8 +1214,8 @@ function forum_print_post(&$post, $courseid, $ownpost=false, $reply=false, $link
     }
 
     $age = time() - $post->created;
-    if ($ownpost) {
-        if ($age < $CFG->maxeditingtime) {
+    if ($ownpost or $adminedit) {
+        if (($age < $CFG->maxeditingtime) or $adminedit) {
             echo "<a href=\"$CFG->wwwroot/mod/forum/post.php?edit=$post->id\">$stredit</a> | ";
         }
     }
diff --git a/mod/forum/post.php b/mod/forum/post.php
index 9330047ff5..8c0bd6553b 100644
--- a/mod/forum/post.php
+++ b/mod/forum/post.php
@@ -204,13 +204,15 @@
 
     } else if (isset($edit)) {  // User is editing their own post
 
+        $adminedit = (isadmin() and !empty($CFG->admineditalways));
+
         if (! $post = forum_get_post_full($edit)) {
             error("Post ID was incorrect");
         }
-        if ($post->userid <> $USER->id) {
+        if (($post->userid <> $USER->id) and !$adminedit) {
             error("You can't edit other people's posts!");
         }
-        if ((time() - $post->created) > $CFG->maxeditingtime) {
+        if (((time() - $post->created) > $CFG->maxeditingtime) and !$adminedit) {
             error( get_string("maxtimehaspassed", "forum", format_time($CFG->maxeditingtime)) );
         }
         if ($post->parent) {
-- 
2.39.5