Fixes bug 112
authormoodler <moodler>
Thu, 3 Oct 2002 11:15:50 +0000 (11:15 +0000)
committermoodler <moodler>
Thu, 3 Oct 2002 11:15:50 +0000 (11:15 +0000)
Changes to expand "open" option in forums.  Now have a choice between
three options:  new discussions and new replies, new replies only and
no new discussions or new replies.

Three new options in lang/forum.php and I changed "allowdiscussions".

lang/en/forum.php
lang/en/help/forum/allowdiscussions.html
lang/en/moodle.php
mod/forum/db/mysql.sql
mod/forum/lib.php
mod/forum/mod.html
mod/forum/version.php

index 80906b5..92eb0f5 100644 (file)
@@ -7,13 +7,12 @@ $string['modulenameplural'] = "Forums";
 
 $string['addanewdiscussion'] = "Add a new discussion topic";
 $string['allowchoice'] = "Allow everyone to choose";
-$string['allowdiscussions'] = "Can a \$a start new discussions?";
+$string['allowdiscussions'] = "Can a \$a post to this forum?";
 $string['allowratings'] = "Allow posts to be rated?";
 $string['allowsdiscussions'] = "This forum allows each person to start one discussion topic.";
 $string['anyfile'] = "Any file";
 $string['attachment'] = "Attachment";
 $string['bynameondate'] = "by \$a->name - \$a->date";
-$string['canstudentsstart'] = "Can a \$a start new discussions?";
 $string['couldnotadd'] = "Could not add your post due to an unknown error";
 $string['couldnotdeleteratings'] = "Sorry, that cannot be deleted as people have already rated it";
 $string['couldnotdeletereplies'] = "Sorry, that cannot be deleted as people have already responded to it";
@@ -65,6 +64,9 @@ $string['nownotsubscribed'] = "\$a->name will NOT receive copies of '\$a->forum'
 $string['nowsubscribed'] = "\$a->name will receive copies of '\$a->forum' by email.";
 $string['numposts'] = "\$a posts";
 $string['olderdiscussions'] = "Older discussions";
+$string['openmode0'] = "No discussions, no replies";
+$string['openmode1'] = "No discussions, but replies are allowed";
+$string['openmode2'] = "Discussions and replies are allowed";
 $string['parentofthispost'] = "Parent of this post";
 $string['postadded'] = "Your post was successfully added.<P>You have \$a to edit it if you want to make any changes.";
 $string['postmailinfo'] = "This is a copy of a message posted on the \$a website.
index 2049809..fac7554 100644 (file)
@@ -1,9 +1,20 @@
-<P ALIGN=CENTER><B>Allowing new discussions</B></P>
+<P ALIGN=CENTER><B>Allowing new posts</B></P>
 
-<P>For most forums you will want to allow non-teachers to start new 
-   discussion topics (threads).
+<P>This option allows you to restrict students from posting 
+   new content in this forum.
+
+<P>For most forums you will want to leave students unrestricted
+   and choose the first option to allow them to start new discussion 
+   topics (threads), and also to post replies within those threads.
 
 <P>Sometimes, however, you will want to disable this ability.  For
    example, this is useful for the News forum when you only want 
    teachers to post new items that appear on the course main page.
-   Students will still be able to REPLY to existing posts though.
+   In this case you might choose the third option "No discussions, no replies".
+
+<P>Sometimes you might want to only allow teachers to start new
+   discussions, but still allow students to reply within those  
+   threads (for example within the news forum on the site home page).
+   In this case you would choose the second option, "No discussions, but 
+   replies are allowed".
+
index 22d81cb..4f278df 100644 (file)
@@ -216,7 +216,7 @@ $string['listofallpeople'] = "List of all people";
 $string['license'] = "GPL License";
 $string['livelogs'] = "Live logs from the past hour";
 $string['location'] = "Location";
-$string['loggedinas'] = "You are logged in as \$a.";
+$string['loggedinas'] = "You are logged in as \$a ";
 $string['loggedinnot'] = "You are not logged in.";
 $string['login'] = "Login";
 $string['loginas'] = "Login as";
index d3680b2..3227e42 100644 (file)
@@ -8,7 +8,8 @@ CREATE TABLE forum (
   type enum('single','news','general','social','eachuser','teacher') NOT NULL default 'general',
   name varchar(255) NOT NULL default '',
   intro text NOT NULL,
-  open tinyint(1) unsigned NOT NULL default '0',
+  opendiscuss tinyint(1) unsigned NOT NULL default '1',
+  openpost tinyint(1) unsigned NOT NULL default '1',
   assessed tinyint(1) unsigned NOT NULL default '0',
   forcesubscribe tinyint(1) unsigned NOT NULL default '0',
   timemodified int(10) unsigned NOT NULL default '0',
index b6a8c34..a427cff 100644 (file)
@@ -20,6 +20,10 @@ $FORUM_POST_RATINGS = array ("3" => get_string("postrating3", "forum"),
                              "2" => get_string("postrating2", "forum"),
                              "1" => get_string("postrating1", "forum") );
 
+$FORUM_OPEN_MODES   = array ("2" => get_string("openmode2", "forum"),
+                             "1" => get_string("openmode1", "forum"),
+                             "0" => get_string("openmode0", "forum") );
+
 $FORUM_SHORT_POST = 300;  // Less than this is "short"
 
 $FORUM_LONG_POST  = 600;  // More than this is "long"
@@ -43,21 +47,21 @@ function forum_get_course_forum($courseid, $type) {
             case "news":
                 $forum->name  = get_string("namenews", "forum");
                 $forum->intro = get_string("intronews", "forum");
-                $forum->open  = 0;
+                $forum->open = 1;   // 0 - no, 1 - posts only, 2 - discuss and post
                 $forum->assessed = 0;
                 $forum->forcesubscribe = 1;
                 break;
             case "social":
                 $forum->name  = get_string("namesocial", "forum");
                 $forum->intro = get_string("introsocial", "forum");
-                $forum->open  = 1;
+                $forum->open = 2;   // 0 - no, 1 - posts only, 2 - discuss and post
                 $forum->assessed = 0;
                 $forum->forcesubscribe = 0;
                 break;
             case "teacher":
                 $forum->name  = get_string("nameteacher", "forum");
                 $forum->intro = get_string("introteacher", "forum");
-                $forum->open  = 0;
+                $forum->open = 0;   // 0 - no, 1 - posts only, 2 - discuss and post
                 $forum->assessed = 0;
                 $forum->forcesubscribe = 0;
                 break;
@@ -1045,10 +1049,22 @@ function forum_user_can_post_discussion($forum) {
     } else if (isteacher($forum->course)) {
         return true;
     } else {
-        return $forum->open;
+        return ($forum->open == 2);
     }
 }
 
+function forum_user_can_post($forum) {
+// $forum is an object
+    global $USER;
+
+    if ($forum->type == "teacher") {
+        return isteacher($forum->course);
+    } else if (isteacher($forum->course)) {
+        return true;
+    } else {
+        return $forum->open;
+    }
+}
 
 function forum_get_discussions($forum="0", $forum_sort="DESC", $user=0) {
     if ($user) {
@@ -1148,8 +1164,9 @@ function forum_print_discussion($course, $forum, $discussion, $post, $mode) {
     global $USER;
 
     $ownpost = ($USER->id == $post->user);
+    $reply   = forum_user_can_post($forum);
 
-    forum_print_post($post, $course->id, $ownpost, $reply=true, $link=false, $rate=false);
+    forum_print_post($post, $course->id, $ownpost, $reply, $link=false, $rate=false);
 
     forum_print_mode_form($discussion->id, $mode);
 
@@ -1171,16 +1188,16 @@ function forum_print_discussion($course, $forum, $discussion, $post, $mode) {
         case -1 :  // Flat descending
         default:   
             echo "<UL>";
-            forum_print_posts_flat($post->discussion, $course->id, $mode, $forum->assessed);
+            forum_print_posts_flat($post->discussion, $course->id, $mode, $forum->assessed, $reply);
             echo "</UL>";
             break;
 
         case 2 :   // Threaded 
-            forum_print_posts_threaded($post->id, $course->id, 0, $forum->assessed);
+            forum_print_posts_threaded($post->id, $course->id, 0, $forum->assessed, $reply);
             break;
 
         case 3 :   // Nested
-            forum_print_posts_nested($post->id, $course->id, $forum->assessed);
+            forum_print_posts_nested($post->id, $course->id, $forum->assessed, $reply);
             break;
     }
 
@@ -1192,10 +1209,9 @@ function forum_print_discussion($course, $forum, $discussion, $post, $mode) {
     }
 }
 
-function forum_print_posts_flat($discussion, $course, $direction, $assessed) { 
+function forum_print_posts_flat($discussion, $course, $direction, $assessed, $reply) { 
     global $USER;
 
-    $reply = true;
     $link  = false;
 
     if ($direction < 0) {
@@ -1217,10 +1233,9 @@ function forum_print_posts_flat($discussion, $course, $direction, $assessed) {
     }
 }
 
-function forum_print_posts_threaded($parent, $course, $depth, $assessed) { 
+function forum_print_posts_threaded($parent, $course, $depth, $assessed, $reply) { 
     global $USER;
 
-    $reply = true;
     $link  = false;
 
     if ($posts = get_records_sql("SELECT p.*, u.id as userid, u.firstname, u.lastname, u.email, u.picture
@@ -1242,7 +1257,7 @@ function forum_print_posts_threaded($parent, $course, $depth, $assessed) {
                 echo "</FONT></P></LI>";
             }
 
-            forum_print_posts_threaded($post->id, $course, $depth-1, $assessed);
+            forum_print_posts_threaded($post->id, $course, $depth-1, $assessed, $reply);
             echo "</UL>\n";
         }
     } else {
@@ -1250,10 +1265,9 @@ function forum_print_posts_threaded($parent, $course, $depth, $assessed) {
     }
 }
 
-function forum_print_posts_nested($parent, $course, $assessed) { 
+function forum_print_posts_nested($parent, $course, $assessed, $reply) { 
     global $USER;
 
-    $reply = true;
     $link  = false;
 
     if ($posts = get_records_sql("SELECT p.*, u.id as userid, u.firstname, u.lastname, u.email, u.picture
@@ -1268,7 +1282,7 @@ function forum_print_posts_nested($parent, $course, $assessed) {
             echo "<UL>";
             forum_print_post($post, $course, $ownpost, $reply, $link, $assessed);
             echo "<BR>";
-            forum_print_posts_nested($post->id, $course, $assessed);
+            forum_print_posts_nested($post->id, $course, $assessed, $reply);
             echo "</UL>\n";
         }
     } else {
index cb3f0a7..d206ee0 100644 (file)
 </tr>
 
 <tr valign=top>
-    <td align=right><P><B><? print_string("allowdiscussions", "forum", "$course->student") ?>:</B></P></TD>
+    <td align=right><P><B><? print_string("allowdiscussions", "forum", strtolower("$course->student")) ?>:</B></P></TD>
     <td>
-        <? $stryes = get_string("yes"); $strno = get_string("no"); ?>
-        <input type=radio name=open value=1 <? if ($form->open == 1) echo "CHECKED"; ?> ><?=$stryes ?>
-        <input type=radio name=open value=0 <? if ($form->open == 0) echo "CHECKED"; ?> ><?=$strno ?>
+        <?  choose_from_menu($FORUM_OPEN_MODES, "open", $form->open, ""); ?>
         <? helpbutton("allowdiscussions", get_string("allowdiscussions", "forum"), "forum") ?>
     </td>
 </tr>
+
 <tr>
     <td align=right><P><B><? print_string("allowratings", "forum") ?>:</B></P></TD>
     <td>
-        <input type=radio name=assessed value=1 <? if ($form->assessed == 1) echo "CHECKED"; ?> ><?=$stryes ?>
-        <input type=radio name=assessed value=0 <? if ($form->assessed == 0) echo "CHECKED"; ?> ><?=$strno ?>
+        <? $options[0] = get_string("no"); $options[1] = get_string("yes"); ?>
+        <? choose_from_menu($options, "assessed", $form->assessed, ""); ?>
         <? helpbutton("ratings", get_string("allowratings", "forum"), "forum") ?>
     </td>
 </tr>
 <tr>
     <td align=right><P><B><? print_string("forcesubscribeq", "forum") ?>:</B></P></TD>
     <td>
-        <input type=radio name=forcesubscribe value=1 <? if ($form->forcesubscribe == 1) echo "CHECKED"; ?> ><?=$stryes ?>
-        <input type=radio name=forcesubscribe value=0 <? if ($form->forcesubscribe == 0) echo "CHECKED"; ?> ><?=$strno ?>
+        <? choose_from_menu($options, "forcesubscribe", $form->forcesubscribe, ""); ?>
         <? helpbutton("subscription", get_string("forcesubscribeq", "forum"), "forum") ?>
     </td>
 </tr>
index 3f256e3..9baedd3 100644 (file)
@@ -5,7 +5,7 @@
 //  This fragment is called by /admin/index.php
 ////////////////////////////////////////////////////////////////////////////////
 
-$module->version  = 2002091000;
+$module->version  = 2002100300;
 $module->cron     = 60;
 
 function forum_upgrade($oldversion) {
@@ -49,6 +49,12 @@ function forum_upgrade($oldversion) {
     }
   }
 
+  if ($oldversion < 2002100300) {
+      execute_sql(" ALTER TABLE `forum` CHANGE `open` `open` TINYINT(2) UNSIGNED DEFAULT '2' NOT NULL ");
+      execute_sql(" UPDATE `forum` SET `open` = 2 WHERE `open` = 1 ");
+      execute_sql(" UPDATE `forum` SET `open` = 1 WHERE `open` = 0 ");
+  }
+
   return true;
 
 }