### Eclipse Workspace Patch 1.0
#P 19stable
Index: lib/weblib.php
===================================================================
RCS file: /cvsroot/moodle/moodle/lib/weblib.php,v
retrieving revision 1.970.2.134
diff -u -r1.970.2.134 weblib.php
--- lib/weblib.php	16 Feb 2009 04:15:59 -0000	1.970.2.134
+++ lib/weblib.php	23 Mar 2009 06:33:07 -0000
@@ -50,6 +50,8 @@
 /**
  * Does all sorts of transformations and filtering
  */
+define('FORMAT_PENDING',   '-1');   // Do not display because the text has not been approved
+ 
 define('FORMAT_MOODLE',   '0');   // Does all sorts of transformations and filtering
 
 /**
@@ -1494,7 +1496,7 @@
 
     static $croncache = array();
 
-    if ($text === '') {
+    if (($text === '') or ($format==FORMAT_PENDING)){
         return ''; // no need to do any filters and cleaning
     }
 
Index: lang/en_utf8/forum.php
===================================================================
RCS file: /cvsroot/moodle/moodle/lang/en_utf8/forum.php,v
retrieving revision 1.21.4.15
diff -u -r1.21.4.15 forum.php
--- lang/en_utf8/forum.php	30 Jan 2009 11:30:21 -0000	1.21.4.15
+++ lang/en_utf8/forum.php	23 Mar 2009 06:33:06 -0000
@@ -89,6 +89,7 @@
 $string['forcesubscribeq'] = 'Force everyone to be subscribed?';
 $string['forum'] = 'Forum';
 $string['forum:addnews'] = 'Add news';
+$string['forum:approvepost'] = 'Approve posts';
 $string['forumauthorhidden'] = 'Author (hidden)';
 $string['forumblockingalmosttoomanyposts'] = 'You are approaching the posting threshold. You have posted $a->numposts times in the last $a->blockperiod and the limit is $a->blockafter posts.';
 $string['forumbodyhidden'] = 'This post cannot be viewed by you, probably because you have not posted in the discussion yet.';
@@ -230,6 +231,7 @@
 $string['reply'] = 'Reply';
 $string['replyforum'] = 'Reply to forum';
 $string['replytouser'] = 'Use email address in reply';
+$string['requireapprovalq'] = 'Require approval?';
 $string['resetforumsall'] = 'Delete all posts';
 $string['resetforums'] = 'Delete posts from';
 $string['resetsubscriptions'] = 'Delete all forum subscriptions';
Index: mod/forum/lib.php
===================================================================
RCS file: /cvsroot/moodle/moodle/mod/forum/lib.php,v
retrieving revision 1.609.2.90
diff -u -r1.609.2.90 lib.php
--- mod/forum/lib.php	20 Mar 2009 13:38:27 -0000	1.609.2.90
+++ mod/forum/lib.php	23 Mar 2009 06:33:08 -0000
@@ -26,6 +26,41 @@
 define ('FORUM_AGGREGATE_MIN', 4);
 define ('FORUM_AGGREGATE_SUM', 5);
 
+/// check for installation of patch
+global $CFG;
+$cfg_forum = get_config('patch/forum');
+
+
+    if (!isset($cfg_forum->version) or (!$cfg_forum->version=2009032200)) { // the patch has not been installed, modify tables and create capability
+        $result = true;
+        require_once($CFG->libdir.'/xmldb/classes/XMLDBConstants.php');
+        require_once($CFG->libdir.'/xmldb/classes/XMLDBObject.class.php');
+        require_once($CFG->libdir.'/xmldb/classes/XMLDBTable.class.php');
+        require_once($CFG->libdir.'/xmldb/classes/XMLDBField.class.php');
+        require_once($CFG->libdir.'/ddllib.php'); // Install/upgrade related db functions
+        
+        $table  = new XMLDBTable('forum');
+        $field = new XMLDBField('approve');
+        $field->setAttributes(XMLDB_TYPE_INTEGER, 2, TRUE, TRUE, null, null, null, 0, 'blockperiod');
+        
+        $table2  = new XMLDBTable('forum_posts');
+        $field2 = new XMLDBField('approved');
+        $field2->setAttributes(XMLDB_TYPE_INTEGER, 2, TRUE, TRUE, null, null, null, 0,'mailnow');
+        
+        $result = $result && add_field($table, $field);
+        $result = $result && add_field($table2, $field2);
+        $result = $result && update_capabilities('mod/forum');
+        
+        if (!$result) { // if something goes wrong
+            error($result);
+            die;
+        } else {
+            set_config('version',2009032200,'patch/forum');
+            echo 'Forum patch tables successfully installed';
+        }
+    }
+
+
 /// STANDARD FUNCTIONS ///////////////////////////////////////////////////////////
 
 /**
@@ -61,7 +96,7 @@
         $discussion->name     = $forum->name;
         $discussion->intro    = $forum->intro;
         $discussion->assessed = $forum->assessed;
-        $discussion->format   = $forum->type;
+        $discussion->format =  ($forum->approve) ? $discussion->format   = -1 : $discussion->format   = $forum->type;
         $discussion->mailnow  = false;
         $discussion->groupid  = -1;
 
Index: mod/forum/mod_form.php
===================================================================
RCS file: /cvsroot/moodle/moodle/mod/forum/mod_form.php,v
retrieving revision 1.23.2.6
diff -u -r1.23.2.6 mod_form.php
--- mod/forum/mod_form.php	26 Jul 2008 15:17:05 -0000	1.23.2.6
+++ mod/forum/mod_form.php	23 Mar 2009 06:33:08 -0000
@@ -41,6 +41,14 @@
         $mform->setHelpButton('forcesubscribe', array('subscription2', get_string('forcesubscribeq', 'forum'), 'forum'));
 
         $options = array();
+        $options[0] = get_string('no');
+        $options[1] = get_string('yes');
+        $mform->addElement('select', 'approve', get_string('requireapprovalq', 'forum'), $options);
+        $mform->setHelpButton('approve', array('approve', get_string('requireapprovalq', 'forum'), 'forum'));
+        $mform->setDefault('approve',0);
+        
+
+        $options = array();
         $options[FORUM_TRACKING_OPTIONAL] = get_string('trackingoptional', 'forum');
         $options[FORUM_TRACKING_OFF] = get_string('trackingoff', 'forum');
         $options[FORUM_TRACKING_ON] = get_string('trackingon', 'forum');
Index: mod/forum/db/access.php
===================================================================
RCS file: /cvsroot/moodle/moodle/mod/forum/db/access.php,v
retrieving revision 1.15.2.1
diff -u -r1.15.2.1 access.php
--- mod/forum/db/access.php	23 Jul 2008 16:09:14 -0000	1.15.2.1
+++ mod/forum/db/access.php	23 Mar 2009 06:33:08 -0000
@@ -182,6 +182,17 @@
         )
     ),
 
+    'mod/forum:approvepost' => array(
+
+        'captype' => 'read',
+        'contextlevel' => CONTEXT_MODULE,
+        'legacy' => array(
+            'teacher' => CAP_ALLOW,
+            'editingteacher' => CAP_ALLOW,
+            'admin' => CAP_ALLOW
+        )
+    ),
+    
     'mod/forum:splitdiscussions' => array(
 
         'captype' => 'read',
Index: mod/forum/patch_forum_approveposts.txt
===================================================================
RCS file: mod/forum/patch_forum_approveposts.txt
diff -N mod/forum/patch_forum_approveposts.txt
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ mod/forum/patch_forum_approveposts.txt	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,18 @@
+This file serves as a README.txt file for the Forum Approve Posts patch contributed by Anthony Borrow (anthony@moodle.org).
+
+DESCRIPTION - The Forum Approve Posts patch is designed to enable the ability for a teacher or other user with the mod/forum:approvepost capability to approve posts before they are visible to other users or emailed to subscribers. 
+
+USAGE 
+
+1) When creating the forum, the teacher indicates that the forum will require approval.
+2) The teacher then reviews the forums and clicks on the Approve link to approve individual posts.
+
+INSTALLATION
+
+1) Apply the patch file to your Moodle installation (see http://docs.moodle.org/en/Development:How_to_apply_a_patch)
+2) Login as the system adminstrator and go to any page that requires the /mod/forum/lib.php file
+3) The modified /mod/forum/lib.php file will check to see if the patch has been installed and if not it will begin to add the approve field to the forum table and the approved field to the forum_post table and create the mod/forum:approvepost capability. After installation, a message indicating that the patch has been successfully installed will be displayed.
+
+TODO
+
+This patch is currently being developed in response to http://tracker.moodle.org/browse/CONTRIB-1085. Suggestions and comments are welcome in the tracker. 
