Forum Subscription Disable Feature

Forum Subscription Disable Feature

by Manish Verma -
Number of replies: 9

As if now, a student can control whether he/she wants to subscribe to a forum or not.  This is fine for most of the students.  However, some students intentionally or unintentionally may post something that may be beyond the guidelines of the course.  A situation may also arise when someone may even post something related to pornography.  If it does happen and email is sent to all those who have subscribed to the forum, it may further deepen the problem.  There must be some way by which the forum subscription feature is disabled by the admin.  Right now, there is a provision to diasble it manually, but it is quite cumbersome to do it, as many students get subscribed again.

P.S.: We are using Moodle 1.3.1.

Average of ratings: -
In reply to Manish Verma

Re: Forum Subscription Disable Feature

by Enrique Castro -
Picture of Core developers Picture of Particularly helpful Moodlers
Hi Manish,
I think that this issue is better handled by education and rules rather that technology.

If that bad ussage does occur, you will need to have the subscription turned off by default to avoid the email messages. A you never knows in advance what users will do, that means that what you need is completely turning off the subscription for whole courses. Not a setting the admins can activate deactivate at will.

You can do that by editing /mod/forum/view.php and eliminating the subscribing link. That way, once unsubscribed, the users will not be abel to subscribe again.

But that means to lose a powerful feature to enhance comunication between your students. Due to one, you are puting a penalty on all users of the site. It is a serious loss. I think it is better to address the problem if ever arise. Users must know that their postings are logged and identified with their full name.

- Enrique -
In reply to Enrique Castro

Re: Forum Subscription Disable Feature

by Manish Verma -

Hello,

Here are my thoughts on the points raised by you:

  1. I intend to keep one course free and open for all students.  Here, the students are not personally known to us.  Many of them are hundreds of miles away.  Due to this reason, undesirable post from a student is more likely to take place.  If such a post is emailed to all, everybody will have a copy of it no matter if we delete it afterwards or not.  This may be quite dangerous.  If it happens to be illegal stuff (for example porn is illegal in India), then there may be a serious problem.
  2. The feature of subscribing to forum is good on its own, but considering the risk involved as mentioned above, it will be all right to compeltely disable it in this particular course.  We can allow students to have RSS feed, as in RSS feed, a copy of the message does not go to a person.
  3. The solution suggested by you may remove the link, but as you very well know, there are other ways to subscribe.  In most cases, whenever, one posts a message, he/she gets subscribed by default.
In reply to Manish Verma

Re: Forum Subscription Disable Feature

by Enrique Castro -
Picture of Core developers Picture of Particularly helpful Moodlers
Hi Manish,
    You can turn off autosubscribing when posting, and autosubscription to News forum. In the worst case, e-mails are sent to people that asked them expicitly by subscribing you can turn off autosubscribing when posting, and autosubscription to News forum, so it cannot be considered unsolicited mail.

However, the idea on RSS is a good one. By using RSS you can maintain people in contact without the e-mail. If you do get non-appropiate meterial there, RSS will distribute it to everybody (that subcribed to RSS feed) like e-mail. Just  that  material will not reside in your personal mailbox. Psychologically is less intrusive.

You may opt to suppress all e-mail sending from forums in a given course. You can do that by editing the routine that actually sends the e-mails. Look for routine function forum_cron () in the file /mod/forum/lib.php. You may introduce a check to test the course id or the course name. If active course is "The free one" you can simply return without composing or sending e-mails.

- Enrique -
In reply to Enrique Castro

Re: Forum Subscription Disable Feature

by Roland Gesthuizen -

G'day, I wonder if there is merit in still having an admin option to supress / hide particular posts, say if a student reply bordered on being defamatory. Although we could respond with a stern reply to reinforce a community rule, unlike an e-mail, there might be problems with leaving the defamatory message in place in a web forum archive.

I agree it would be sad to delete the entire thread or close a web forum.  Closing down the entire web forum is messy as it unsubscribes all the interested participants.

Perhaps an option for Mash is to move the entire problem discussion thread out of the way into a private (teacher only) forum. Is this option worth clarifying in the forum help?

In reply to Roland Gesthuizen

Re: Forum Subscription Disable Feature

by Martin Dougiamas -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
If you set this in your config.php

$CFG->admineditalways = true;

Admins can edit any post at any time. In 1.5 it will even add a note to the post showing who edited it and when.
In reply to Martin Dougiamas

Re: Forum Subscription Disable Feature

by Manish Verma -

Hello,

The real concern is the email subscription feature.  If emails have already been sent to all or most of the users, it may not be quite useful to edit the posts afterwards.

Please clarify.

In reply to Enrique Castro

Re: Enrique

by Manish Verma -

Hello,

Coming to paragraph 3 of yours, here is the code:

function forum_cron () {
/// Function to be run periodically according to the moodle cron
/// Finds all posts that have yet to be mailed out, and mails them
/// out to all subscribers

    global $CFG, $USER;

    if (!empty($USER)) { // Remember real USER account if necessary
        $realuser = $USER;
    }

    $cutofftime = time() - $CFG->maxeditingtime;

    if ($posts = forum_get_unmailed_posts($cutofftime)) {

        /// Mark them all now as being mailed.  It's unlikely but possible there
        /// might be an error later so that a post is NOT actually mailed out,
        /// but since mail isn't crucial, we can accept this risk.  Doing it now
        /// prevents the risk of duplicated mails, which is a worse problem.

        foreach ($posts as $key => $post) {
            if (! set_field("forum_posts", "mailed", "1", "id", "$post->id")) {
                echo "Error marking post id post->id as being mailed.  This post will not be mailed.\n";
                unset($posts[$key]);
            }
        }

        $timenow = time();

        foreach ($posts as $post) {

            echo "\n";
            print_string("processingpost", "forum", $post->id);
            echo "\n";

            if (! $userfrom = get_record("user", "id", "$post->userid")) {
                echo "Could not find user $post->userid\n";
                continue;
            }

            $userfrom->precedence = "bulk";   // This gets added to the email header

            if (! $discussion = get_record("forum_discussions", "id", "$post->discussion")) {
                echo "Could not find discussion $post->discussion\n";
                continue;
            }

            if (! $forum = get_record("forum", "id", "$discussion->forum")) {
                echo "Could not find forum $discussion->forum\n";
                continue;
            }

            if (! $course = get_record("course", "id", "$forum->course")) {
                echo "Could not find course $forum->course\n";
                continue;
            }

            if (!empty($course->lang)) {
                $CFG->courselang = $course->lang;
            } else {
                unset($CFG->courselang);
            }

            $groupmode = false;
            if ($cm = get_coursemodule_from_instance("forum", $forum->id, $course->id)) {
                if ($groupmode = groupmode($course, $cm)) {                  // Groups are being used
                    if (!$group = get_record("groups", "id", $discussion->groupid)) {   // Can't find group
                        continue;                                            // Be safe and don't send it to anyone

                    }
                }
            } else {
                $cm->id = 0;
            }


            if ($users = forum_subscribed_users($course, $forum)) {
                $canunsubscribe = ! forum_is_forcesubscribed($forum->id);

                $mailcount=0;
                $errorcount=0;
                foreach ($users as $userto) {
                    if ($groupmode) {    // Look for a reason not to send this email
                        if (!isteacheredit($course->id, $userto->id)) {
                            if (!ismember($group->id, $userto->id)) {
                                continue;
                            }
                        }
                    }

                    /// GWD: reset timelimit so that script does not get timed out when posting to many users
                    @set_time_limit(0);

                    /// Override the language and timezone of the "current" user, so that
                    /// mail is customised for the receiver.
                    $USER->lang     = $userto->lang;
                    $USER->timezone = $userto->timezone;

                    $canreply = forum_user_can_post($forum, $userto);

                    $by->name = fullname($userfrom, isteacher($course->id, $userto->id));
                    $by->date = userdate($post->modified, "", $userto->timezone);
                    $strbynameondate = get_string("bynameondate", "forum", $by);

                    $strforums = get_string("forums", "forum");

                    $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 .= format_text_email($post->message, $post->format);
                    $posttext .= "\n\n";
                    if ($post->attachment) {
                        $post->course = $course->id;
                        $post->forum = $forum->id;
                        $posttext .= forum_print_attachments($post, "text");
                    }
                    if ($canreply) {
                        $posttext .= "---------------------------------------------------------------------\n";
                        $posttext .= get_string("postmailinfo", "forum", $course->shortname)."\n";
                        $posttext .= "$CFG->wwwroot/mod/forum/post.php?reply=$post->id\n";
                    }
                    if ($canunsubscribe) {
                        $posttext .= "\n---------------------------------------------------------------------\n";
                        $posttext .= get_string("unsubscribe", "forum");
                        $posttext .= ": $CFG->wwwroot/mod/forum/subscribe.php?id=$forum->id\n";
                    }

                    if ($userto->mailformat == 1) {  // HTML
                        $posthtml = "<p><font face=\"sans-serif\">".
                        "<a target=\"_blank\" href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</a> -> ".
                        "<a target=\"_blank\" href=\"$CFG->wwwroot/mod/forum/index.php?id=$course->id\">$strforums</a> -> ".
                        "<a target=\"_blank\" href=\"$CFG->wwwroot/mod/forum/view.php?f=$forum->id\">$forum->name</a>";
                        if ($discussion->name == $forum->name) {
                            $posthtml .= "</font></p>";
                        } else {
                            $posthtml .= " -> <a target=\"_blank\" 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, $canreply, false, false);

                        if ($canunsubscribe) {
                            $posthtml .= "\n<br /><hr size=\"1\" noshade /><p align=\"right\"><font size=\"1\"><a href=\"$CFG->wwwroot/mod/forum/subscribe.php?id=$forum->id\">".get_string("unsubscribe", "forum")."</a></font></p>";
                        }

                    } 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) .. not trying again.\n";
                        add_to_log($course->id, 'forum', 'mail error', "discuss.php?d=$discussion->id#$post->id", substr($post->subject,0,15), $cm->id, $userto->id);
                        $errorcount++;
                    } else {
                        $mailcount++;
                    }
                }

                echo ".... mailed to $mailcount users.\n";
                if ($errorcount) {
                    set_field("forum_posts", "mailed", "2", "id", "$post->id");
                }
            }
        }
    }

    if (!empty($realuser)) {   // Restore real USER if necessary
        $USER = $realuser;
    }

    return true;
}

As I am not into php coding, it will take a lot of time for me to come out with something that will take away the ability to send email to the students for a particular course.

However, there is one thing I noticed that I've shown in bold.  Does it mean that if group feature is activated for a course but group is not defined, no email will be sent?

Also, do you think that Martin's suggestion will stop emails?

What happens if this whole code that is shown here is deleted?

An alternate solution could be to increase the maximum editing time.  If it can be made say 24 hrs. or so by which admin can surely check the post before it gets emailed.  However, the maximum time allowed is 1 hour and it is a common practice to keep it 30 minutes.

Please comment!

In reply to Manish Verma

Re: Enrique

by Enrique Castro -
Picture of Core developers Picture of Particularly helpful Moodlers
Hi Manish,
I have not tried it my self, but that code do indeed indicate that if you have a forum set in group mode, and there is no groupid, then e-mails will not be posted. You can try it (setting the forums in group mode and not defining groups in course), but I think that you may find that users cannot post.

I have been thinking about, and I think that the easier thing to do is just doing what you asked originally: disabling susbcription. A coupel of lines below the bold part you have:
if ($users = forum_subscribed_users($course, $forum))

So, let's tell to Moodle that there are NO subscribed users to a particular forum or course.

In /mod/lib.php you have the function :

function forum_subscribed_users($course, $forum, $groupid=0) {
/// Returns list of user objects that are subscribed to this forum
global $CFG;

$users=array(); // Ecastro, setting NO users subscribed
if ($course->id = xxx) { // put the id number of the course you
    return $users;       //
want to disable e-mails from here, as XXX
} // ecastro

if ($groupid) {
$grouptables = ", {$CFG->prefix}groups_members g";
$groupselect = " AND g.groupid = '$groupid' AND u.id = g.userid";
} else {
$grouptables = "";
$groupselect = "";
}
................ function continues
 

If you need more customization of you site, perhaps you may hire a local php programmer there in Bhopal for a few hours/days.

- Enrique -
In reply to Enrique Castro

Re: Enrique

by Manish Verma -

Hello,

Thanks for taking trouble to write the code.  However, before receiving your reply, I made some changes in the forum area.  The changes were simple.  The forum guidelines were made prominantly visible.  Now, if I encounter the problem of inappropriate forum posts, I will have to include the code mentioned by you.