]> git.mjollnir.org Git - moodle.git/commitdiff
When posting a forum, users can unsubscribe/subscribe on the fly.
authormoodler <moodler>
Tue, 13 May 2003 13:53:36 +0000 (13:53 +0000)
committermoodler <moodler>
Tue, 13 May 2003 13:53:36 +0000 (13:53 +0000)
The flag has a memory, but it keeps pushing you to subscribe.  :-)
(so that by default it behaves like it did before)

Hopefully now subscription is a bit easier to understand.

lang/en/forum.php
mod/forum/lib.php
mod/forum/post.html
mod/forum/post.php

index 134a29af64268307d9a5e3a8d5efe227eb998034..ad4eb80e5f29aec9839954572f23a919cdcf500c 100644 (file)
@@ -104,8 +104,10 @@ $string['subscribe'] = "Subscribe to this forum";
 $string['subscribed'] = "Subscribed";
 $string['subscribers'] = "Subscribers";
 $string['subscribersto'] = "Subscribers to '\$a'";
+$string['subscription'] = "Subscription";
 $string['subscriptions'] = "Subscriptions";
 $string['unsubscribe'] = "Unsubscribe from this forum";
+$string['unsubscribed'] = "Unsubscribed";
 $string['youratedthis'] = "You rated this";
 $string['yournewtopic'] = "Your new discussion topic";
 $string['yourreply'] = "Your reply";
index 511e0ef411eafedf7bb3fbb989a1f376cd2e73f9..ae7e4ae46292eec06501ab8401d70ce9e7177a7e 100644 (file)
@@ -1445,6 +1445,32 @@ function forum_unsubscribe($userid, $forumid) {
     return delete_records("forum_subscriptions", "userid", $userid, "forum", $forumid);
 }
 
+function forum_post_subscription($post) {
+/// Given a new post, subscribes or unsubscribes as appropriate.
+/// Returns some text which describes what happened.
+
+    global $USER;
+
+    if (empty($post->subscribe) and empty($post->unsubscribe)) {
+        return "";
+    }
+
+    if (!$forum = get_record("forum", "id", $post->forum)) {
+        return "";
+    }
+
+    $info->name  = "$USER->firstname $USER->lastname";
+    $info->forum = $forum->name;
+
+    if (!empty($post->subscribe)) {
+        forum_subscribe($USER->id, $post->forum);
+        return "<p>".get_string("nowsubscribed", "forum", $info)."</p>";
+    }
+
+    forum_unsubscribe($USER->id, $post->forum);
+    return "<p>".get_string("nownotsubscribed", "forum", $info)."</p>";
+}
+
 
 function forum_user_has_posted_discussion($forumid, $userid) {
     if ($discussions = forum_get_discussions($forumid, "", $userid)) {
index 0c90dbe8cd289c7d8eedf87ad96d07b9dd7e8881..5c36ca7611005fb4256a3aa0b8652c93671012bd 100644 (file)
@@ -1,24 +1,24 @@
-<form name="theform" method="post" action="post.php" <?=$onsubmit ?> enctype="multipart/form-data">
+<form name="theform" method="post" action="post.php" <?php echo $onsubmit ?> enctype="multipart/form-data">
 <table border="0" cellpadding="5">
 <tr valign="top">
-    <td align=right><p><b><? print_string("subject", "forum"); ?>:</b></p></td>
+    <td align=right><p><b><?php print_string("subject", "forum"); ?>:</b></p></td>
     <td>
-        <input type="text" name="subject" size=60 value="<? p($post->subject) ?>">
+        <input type="text" name="subject" size=60 value="<?php p($post->subject) ?>">
     </td>
 </tr>
 <tr valign="top">
     <td align=right><p><b>
-     <? print_string("message", "forum"); ?>:
+     <?php print_string("message", "forum"); ?>:
      </b></p></td>
     <td align=left rowspan=2>
-    <? print_textarea($usehtmleditor, 15, 50, 595, 400, "message", $post->message); ?>
+    <?php print_textarea($usehtmleditor, 15, 50, 595, 400, "message", $post->message); ?>
     </td>
 </tr>
 <tr valign="top">
     <td align="right" valign="center" nowrap>
 
     <font SIZE="1">
-     <?PHP
+     <?php
         helpbutton("reading", get_string("helpreading"), "moodle", true, true);
         echo "<br />";
         helpbutton("writing", get_string("helpwriting"), "moodle", true, true);
 
     </td>
 </tr>
+
+
+
+
 <tr valign=top>
-    <td align=right><p><b><? print_string("formattexttype"); ?>:</b></p></td>
+    <td align=right><p><b><?php print_string("formattexttype"); ?>:</b></p></td>
     <td>
-    <?PHP 
+    <?php 
        choose_from_menu(format_text_menu(), "format", $post->format, "");
      ?>
     <font SIZE="1">
-    <?PHP 
+    <?php 
         helpbutton("textformat", get_string("helpformatting"));
      ?>
     </font>
 
     </td>
 </tr>
+
+<tr valign=top>
+    <td align=right><p><b><?php print_string("subscription", "forum") ?>:</b></p></td>
+    <td>
+    <?php 
+       if ($forum->forcesubscribe) {
+           print_string("everyoneissubscribed", "forum");
+       } else {
+           unset($options);
+           if (forum_is_subscribed($USER->id, $post->forum)) {
+               $options[0] = get_string("subscribed", "forum");
+               $options[1] = get_string("unsubscribe", "forum");
+               choose_from_menu($options, "unsubscribe", 0, "");
+           } else {
+               $options[0] = get_string("unsubscribed", "forum");
+               $options[1] = get_string("subscribe", "forum");
+               choose_from_menu($options, "subscribe", 1, "");
+           }
+       }
+       helpbutton("subscription", get_string("subscription", "forum"), "forum"); 
+    ?>
+    </td>
+</tr>
+
+
 <tr valign=top>
-    <td align=right><p><b><? print_string("attachment", "forum") ?>:<br \>(<? print_string("optional") ?>)&nbsp;</b></p></td>
+    <td align=right><p><b><?php print_string("attachment", "forum") ?>:<br \>(<?php print_string("optional") ?>)&nbsp;</b></p></td>
     <td>
-    <input type="hidden" name="MAX_FILE_SIZE" value="<? echo get_max_upload_file_size() ?>">
+    <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo get_max_upload_file_size() ?>">
     <input type="file" name="attachment" size=40> 
-    <? helpbutton("attachment", get_string("attachment", "forum"), "forum"); 
+    <?php 
+       helpbutton("attachment", get_string("attachment", "forum"), "forum"); 
        print_string("maxsize", "", display_size(get_max_upload_file_size())); 
     ?>
     </td>
 
 </tr>
+
+
 <tr>
     <td align=center colspan=2>
-    <input type="hidden" name=course     value="<? p($post->course) ?>">
-    <input type="hidden" name=forum      value="<? p($post->forum) ?>">
-    <input type="hidden" name=discussion value="<? p($post->discussion) ?>">
-    <input type="hidden" name=parent     value="<? p($post->parent) ?>">
-    <input type="hidden" name=userid     value="<? p($post->userid) ?>">
-    <input type="hidden" name=edit       value="<? p($post->edit) ?>">
-    <input type="submit" value="<? print_string("savechanges"); ?>">
+    <input type="hidden" name=course     value="<?php p($post->course) ?>">
+    <input type="hidden" name=forum      value="<?php p($post->forum) ?>">
+    <input type="hidden" name=discussion value="<?php p($post->discussion) ?>">
+    <input type="hidden" name=parent     value="<?php p($post->parent) ?>">
+    <input type="hidden" name=userid     value="<?php p($post->userid) ?>">
+    <input type="hidden" name=edit       value="<?php p($post->edit) ?>">
+    <input type="submit" value="<?php print_string("savechanges"); ?>">
     </td>
 
 </tr>
 </table>
 </form>
 
-<? 
+<?php 
    if ($usehtmleditor) { 
        print_richedit_javascript("theform", "message", "no");
    }
index 60fe9e7a66fecbedd4f254638f83fae3783fb586..a3676c13cf31bf23a5412601d276494de5f6cabd 100644 (file)
             $post->id = $post->edit;
             if (forum_update_post($post)) {
                 add_to_log($post->course, "forum", "update post", "discuss.php?d=$post->discussion&parent=$post->id", "$post->id");
-                redirect(forum_go_back_to("discuss.php?d=$post->discussion"), get_string("postupdated", "forum"), 1);
+                $message = get_string("postupdated", "forum");
+                $timemessage = 1;
+
+                if ($subscribemessage = forum_post_subscription($post)) {
+                    $timemessage = 2;
+                }
+                redirect(forum_go_back_to("discuss.php?d=$post->discussion"), $message.$subscribemessage, $timemessage);
+
             } else {
                 error(get_string("couldnotupdate", "forum"), $errordestination); 
             }
 
         } else if ($post->discussion) { // Adding a new post to an existing discussion
             if ($post->id = forum_add_new_post($post)) {
-                if ( ! forum_is_subscribed($USER->id, $post->forum) ) {
-                    forum_subscribe($USER->id, $post->forum);
+                add_to_log($post->course, "forum", "add post", "discuss.php?d=$post->discussion&parent=$post->id", "$post->id");
+                $message = get_string("postadded", "forum", format_time($CFG->maxeditingtime));
+                $timemessage = 2;
+
+                if ($subscribemessage = forum_post_subscription($post)) {
+                    $timemessage = 4;
                 }
 
-                add_to_log($post->course, "forum", "add post", "discuss.php?d=$post->discussion&parent=$post->id", "$post->id");
-                redirect(forum_go_back_to("discuss.php?d=$post->discussion"), 
-                         get_string("postadded", "forum", format_time($CFG->maxeditingtime)), 2);
+                redirect(forum_go_back_to("discuss.php?d=$post->discussion"), $message.$subscribemessage, $timemessage);
+
             } else {
                 error(get_string("couldnotadd", "forum"), $errordestination); 
             }
             $discussion->name  = $post->subject;
             $discussion->intro = $post->message;
             if ($discussion->id = forum_add_discussion($discussion)) {
-                if ( ! forum_is_subscribed($USER->id, $post->forum) ) {
-                    forum_subscribe($USER->id, $post->forum);
-                }
                 add_to_log($post->course, "forum", "add discussion", "discuss.php?d=$discussion->id", "$discussion->id");
-                redirect(forum_go_back_to("view.php?f=$post->forum"), 
-                         get_string("postadded", "forum", format_time($CFG->maxeditingtime)), 3);
+                $message = get_string("postadded", "forum", format_time($CFG->maxeditingtime));
+                $timemessage = 2;
+
+                if ($subscribemessage = forum_post_subscription($discussion)) {
+                    $timemessage = 4;
+                }
+
+                redirect(forum_go_back_to("view.php?f=$post->forum"), $message.$subscribemessage, $timemessage);
+
             } else {
                 error(get_string("couldnotadd", "forum"), $errordestination); 
             }