]> git.mjollnir.org Git - moodle.git/commitdiff
Fixes to finding list of subscribers to a forum for site-level forums
authormartin <martin>
Thu, 15 Aug 2002 04:16:39 +0000 (04:16 +0000)
committermartin <martin>
Thu, 15 Aug 2002 04:16:39 +0000 (04:16 +0000)
which affected both the displayed list and the mailouts.

lib/setup.php
mod/forum/lib.php
mod/forum/subscribers.php

index 90af95571c4facfa659c67b6316d0d596676d72a..a0a4a3a5ce4698a7b94f1120e80f97367df50aa6 100644 (file)
@@ -18,7 +18,7 @@
 
 // Default editing time for posts and the like (in seconds)
 
-    $CFG->maxeditingtime = 1800;
+    $CFG->maxeditingtime = 10;
 
 // Location of standard files
 
index daabe4be3daa11e4a42b0ba1909c2bb7939db86a..6aceaf6397786fcdbe07ff04d75143996e259080 100644 (file)
@@ -106,7 +106,7 @@ function forum_make_mail_post(&$post, $user, $touser, $course,
     $output .= "</FONT></P></TD></TR>";
     $output .= "<TR><TD BGCOLOR=\"$THEME->body\" WIDTH=10>";
     $output .= "&nbsp;";
-    $output .= "</TD><TD BGCOLOR=\"#FFFFFF\">\n";
+    $output .= "</TD><TD BGCOLOR=\"$THEME->cellcontent\">\n";
 
     $output .= text_to_html($post->message);
 
@@ -175,7 +175,7 @@ function forum_print_post(&$post, $courseid, $ownpost=false, $reply=false, $link
     echo "</FONT></P></TD></TR>";
     echo "<TR><TD BGCOLOR=\"$THEME->body\" WIDTH=10>";
     echo "&nbsp;";
-    echo "</TD><TD BGCOLOR=\"#FFFFFF\">\n";
+    echo "</TD><TD BGCOLOR=\"$THEME->cellcontent\">\n";
 
     if ($link && (strlen($post->message) > $FORUM_LONG_POST)) {
         // Print shortened version
@@ -691,7 +691,7 @@ function forum_cron () {
                 continue;
             }
 
-            if ($users = get_course_users($course->id)) {
+            if ($users = forum_subscribed_users($course, $forum)) {
                 $strforums = get_string("forums", "forum");
 
                 $mailcount=0;
@@ -700,44 +700,43 @@ function forum_cron () {
                     $by->date = userdate($post->created, "", $userto->timezone);
                     $strbynameondate = get_string("bynameondate", "forum", $by);
 
-                    if (forum_is_subscribed($userto->id, $forum->id)) {
-                        $postsubject = "$course->shortname: $post->subject";
-                        $posttext  = "$course->shortname -> $strforums -> $forum->name";
+                    $postsubject = "$course->shortname: $post->subject";
+                    $posttext  = "$course->shortname -> $strforums -> $forum->name";
+
+                    if ($discussion->name == $forum->name) {
+                        $posttext  .= "\n";
+                    } else {
+                        $posttext  .= " -> $discussion->name\n";
+                    }
+                    $posttext .= "---------------------------------------------------------------------\n";
+                    $posttext .= "$post->subject\n";
+                    $posttext .= $strbynameondate."\n";
+                    $posttext .= "---------------------------------------------------------------------\n";
+                    $posttext .= strip_tags($post->message);
+                    $posttext .= "\n\n";
+                    $posttext .= "---------------------------------------------------------------------\n";
+                    $posttext .= get_string("postmailinfo", "forum", $course->shortname)."\n";
+                    $posttext .= "$CFG->wwwroot/mod/forum/post.php?reply=$post->id";
+  
+                    if ($userto->mailformat == 1) {  // HTML
+                        $posthtml = "<P><FONT FACE=sans-serif>".
+                        "<A HREF=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</A> -> ".
+                        "<A HREF=\"$CFG->wwwroot/mod/forum/index.php?id=$course->id\">$strforums</A> -> ".
+                        "<A HREF=\"$CFG->wwwroot/mod/forum/view.php?f=$forum->id\">$forum->name</A>";
                         if ($discussion->name == $forum->name) {
-                            $posttext  .= "\n";
-                        } else {
-                            $posttext  .= " -> $discussion->name\n";
-                        }
-                        $posttext .= "---------------------------------------------------------------------\n";
-                        $posttext .= "$post->subject\n";
-                        $posttext .= $strbynameondate."\n";
-                        $posttext .= "---------------------------------------------------------------------\n";
-                        $posttext .= strip_tags($post->message);
-                        $posttext .= "\n\n";
-                        $posttext .= "---------------------------------------------------------------------\n";
-                        $posttext .= get_string("postmailinfo", "forum", $course->shortname)."\n";
-                        $posttext .= "$CFG->wwwroot/mod/forum/post.php?reply=$post->id";
-    
-                        if ($userto->mailformat == 1) {  // HTML
-                            $posthtml = "<P><FONT FACE=sans-serif>".
-                            "<A HREF=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</A> -> ".
-                            "<A HREF=\"$CFG->wwwroot/mod/forum/index.php?id=$course->id\">$strforums</A> -> ".
-                            "<A HREF=\"$CFG->wwwroot/mod/forum/view.php?f=$forum->id\">$forum->name</A>";
-                            if ($discussion->name == $forum->name) {
-                                $posthtml .= "</FONT></P>";
-                            } else {
-                                $posthtml .= " -> <A HREF=\"$CFG->wwwroot/mod/forum/discuss.php?d=$discussion->id\">$discussion->name</A></FONT></P>";
-                            }
-                            $posthtml .= forum_make_mail_post($post, $userfrom, $userto, $course, false, true, false, false);
-                        } else {
-                          $posthtml = "";
-                        }
-    
-                        if (! email_to_user($userto, $userfrom, $postsubject, $posttext, $posthtml)) {
-                            echo "Error: mod/forum/cron.php: Could not send out mail for id $post->id to user $userto->id ($userto->email)\n";
+                            $posthtml .= "</FONT></P>";
                         } else {
-                            $mailcount++;
+                            $posthtml .= " -> <A HREF=\"$CFG->wwwroot/mod/forum/discuss.php?d=$discussion->id\">$discussion->name</A></FONT></P>";
                         }
+                        $posthtml .= forum_make_mail_post($post, $userfrom, $userto, $course, false, true, false, false);
+                    } else {
+                      $posthtml = "";
+                    }
+   
+                    if (! email_to_user($userto, $userfrom, $postsubject, $posttext, $posthtml)) {
+                        echo "Error: mod/forum/cron.php: Could not send out mail for id $post->id to user $userto->id ($userto->email)\n";
+                    } else {
+                        $mailcount++;
                     }
                 }
                 echo "mailed to $mailcount users ...";
@@ -769,6 +768,19 @@ function forum_is_subscribed($userid, $forumid) {
     return record_exists_sql("SELECT * FROM forum_subscriptions WHERE user='$userid' AND forum='$forumid'");
 }
 
+function forum_subscribed_users($course, $forum) {
+// Returns list of user objects that are subscribed to this forum
+
+    if ($course->category) {   // normal course
+        if ($forum->forcesubscribe) {
+            return get_course_users($course->id);
+        }
+    }
+    return get_records_sql("SELECT u.* FROM user u, forum_subscriptions s
+                            WHERE s.forum = '$forum->id'
+                              AND s.user = u.id");
+}
+
 function forum_subscribe($userid, $forumid) {
     global $db;
 
index 9281f6051d7202a746a53f56e62ce69d32a2bea8..d6874c421e52d253e3b972abe5e29c064a83e370 100644 (file)
 
     print_header("$course->shortname: $strsubscribers", "$course->fullname", "$navigation");
 
-    if ($course->category) {
-        $users = get_course_users($course->id);
-    } else {
-        $users = get_records_sql("SELECT * from user");
-    }
-
-    if (! $users) {
-        print_heading(get_string("nousersyet"));
+    if (! $users = forum_subscribed_users($course, $forum) ) {
+        print_heading(get_string("nosubscribers", "forum"));
 
     } else {
         print_heading(get_string("subscribersto","forum", "'$forum->name'"));
-        echo "<TABLE ALIGN=CENTER>";
-        $count = 0;
+        echo "<TABLE ALIGN=CENTER cellpadding=5 cellspacing=5>";
         foreach ($users as $user) {
-            if (forum_is_subscribed($user->id, $forum->id)) {
-                echo "<TR><TD>";
-                print_user_picture($user->id, $course->id, $user->picture);
-                echo "</TD><TD>";
-                echo "$user->firstname $user->lastname";
-                echo "</TD></TR>";
-                $count++;
-            }
-        }
-        if (!$count) {
-            echo "<TR><TD>".get_string("nosubscribers", "forum")."</TD></TR>";
+            echo "<TR><TD>";
+            print_user_picture($user->id, $course->id, $user->picture);
+            echo "</TD><TD BGCOLOR=\"$THEME->cellcontent\">";
+            echo "$user->firstname $user->lastname";
+            echo "</TD><TD BGCOLOR=\"$THEME->cellcontent\">";
+            echo "$user->email";
+            echo "</TD></TR>";
         }
         echo "</TABLE>";
     }