diff --git a/lang/en/moodle.php b/lang/en/moodle.php index 24e37efc311..7361225dd43 100644 --- a/lang/en/moodle.php +++ b/lang/en/moodle.php @@ -559,6 +559,13 @@ $string['emailconfirmsent'] = '

An email should have been sent to your address

It contains easy instructions to complete your registration.

If you continue to have difficulty, contact the site administrator.

'; $string['emaildigest'] = 'Email digest type'; +$string['emaildigest_help'] = 'This is the daily digest setting that forums will use by default. + +* No digest - you will receive one e-mail per forum post; +* Digest - complete posts - you will receive one digest e-mail per day containing the complete contents of each forum post; +* Digest - subjects only - you will receive one digest e-mail per day containing just the subject of each forum post. + +You can also choose a different setting for each forum if you wish.'; $string['emaildigestcomplete'] = 'Complete (daily email with full posts)'; $string['emaildigestoff'] = 'No digest (single email per forum post)'; $string['emaildigestsubjects'] = 'Subjects (daily email with subjects only)'; diff --git a/mod/forum/backup/moodle2/backup_forum_stepslib.php b/mod/forum/backup/moodle2/backup_forum_stepslib.php index 2ad3580c159..1a47641126d 100644 --- a/mod/forum/backup/moodle2/backup_forum_stepslib.php +++ b/mod/forum/backup/moodle2/backup_forum_stepslib.php @@ -70,6 +70,11 @@ class backup_forum_activity_structure_step extends backup_activity_structure_ste $subscription = new backup_nested_element('subscription', array('id'), array( 'userid')); + $digests = new backup_nested_element('digests'); + + $digest = new backup_nested_element('digest', array('id'), array( + 'userid', 'maildigest')); + $readposts = new backup_nested_element('readposts'); $read = new backup_nested_element('read', array('id'), array( @@ -89,6 +94,9 @@ class backup_forum_activity_structure_step extends backup_activity_structure_ste $forum->add_child($subscriptions); $subscriptions->add_child($subscription); + $forum->add_child($digests); + $digests->add_child($digest); + $forum->add_child($readposts); $readposts->add_child($read); @@ -118,6 +126,8 @@ class backup_forum_activity_structure_step extends backup_activity_structure_ste $subscription->set_source_table('forum_subscriptions', array('forum' => backup::VAR_PARENTID)); + $digest->set_source_table('forum_digests', array('forum' => backup::VAR_PARENTID)); + $read->set_source_table('forum_read', array('forumid' => backup::VAR_PARENTID)); $track->set_source_table('forum_track_prefs', array('forumid' => backup::VAR_PARENTID)); @@ -143,6 +153,8 @@ class backup_forum_activity_structure_step extends backup_activity_structure_ste $subscription->annotate_ids('user', 'userid'); + $digest->annotate_ids('user', 'userid'); + $read->annotate_ids('user', 'userid'); $track->annotate_ids('user', 'userid'); diff --git a/mod/forum/backup/moodle2/restore_forum_stepslib.php b/mod/forum/backup/moodle2/restore_forum_stepslib.php index c5b23867f90..2dfac63cf30 100644 --- a/mod/forum/backup/moodle2/restore_forum_stepslib.php +++ b/mod/forum/backup/moodle2/restore_forum_stepslib.php @@ -42,6 +42,7 @@ class restore_forum_activity_structure_step extends restore_activity_structure_s $paths[] = new restore_path_element('forum_post', '/activity/forum/discussions/discussion/posts/post'); $paths[] = new restore_path_element('forum_rating', '/activity/forum/discussions/discussion/posts/post/ratings/rating'); $paths[] = new restore_path_element('forum_subscription', '/activity/forum/subscriptions/subscription'); + $paths[] = new restore_path_element('forum_digest', '/activity/forum/digests/digest'); $paths[] = new restore_path_element('forum_read', '/activity/forum/readposts/read'); $paths[] = new restore_path_element('forum_track', '/activity/forum/trackedprefs/track'); } @@ -149,6 +150,18 @@ class restore_forum_activity_structure_step extends restore_activity_structure_s $newitemid = $DB->insert_record('forum_subscriptions', $data); } + protected function process_forum_digest($data) { + global $DB; + + $data = (object)$data; + $oldid = $data->id; + + $data->forum = $this->get_new_parentid('forum'); + $data->userid = $this->get_mappingid('user', $data->userid); + + $newitemid = $DB->insert_record('forum_digests', $data); + } + protected function process_forum_read($data) { global $DB; diff --git a/mod/forum/db/install.xml b/mod/forum/db/install.xml index 17ab2292bef..76dcc037896 100644 --- a/mod/forum/db/install.xml +++ b/mod/forum/db/install.xml @@ -1,5 +1,5 @@ - @@ -120,6 +120,20 @@ + + + + + + + + + + + + + +
@@ -153,4 +167,4 @@
-
\ No newline at end of file + diff --git a/mod/forum/db/upgrade.php b/mod/forum/db/upgrade.php old mode 100644 new mode 100755 index 7603626aa8a..703e93f6156 --- a/mod/forum/db/upgrade.php +++ b/mod/forum/db/upgrade.php @@ -84,9 +84,30 @@ function xmldb_forum_upgrade($oldversion) { // Moodle v2.5.0 release upgrade line. // Put any upgrade step following this. + if ($oldversion < 2013071000) { + // Define table forum_digests to be created. + $table = new xmldb_table('forum_digests'); + // Adding fields to table forum_digests. + $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); + $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null); + $table->add_field('forum', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null); + $table->add_field('maildigest', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '-1'); + + // Adding keys to table forum_digests. + $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); + $table->add_key('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id')); + $table->add_key('forum', XMLDB_KEY_FOREIGN, array('forum'), 'forum', array('id')); + $table->add_key('forumdigest', XMLDB_KEY_UNIQUE, array('forum', 'userid', 'maildigest')); + + // Conditionally launch create table for forum_digests. + if (!$dbman->table_exists($table)) { + $dbman->create_table($table); + } + + // Forum savepoint reached. + upgrade_mod_savepoint(true, 2013071000, 'forum'); + } return true; } - - diff --git a/mod/forum/index.php b/mod/forum/index.php index fc9903de13e..93b1656c483 100644 --- a/mod/forum/index.php +++ b/mod/forum/index.php @@ -68,9 +68,21 @@ $strunsubscribe = get_string('unsubscribe', 'forum'); $stryes = get_string('yes'); $strno = get_string('no'); $strrss = get_string('rss'); +$stremaildigest = get_string('emaildigest'); $searchform = forum_search_form($course); +// Retrieve the list of forum digest options for later. +$digestoptions = forum_get_user_digest_options(); +$digestoptions_selector = new single_select(new moodle_url('/mod/forum/maildigest.php', + array( + 'backtoindex' => 1, + )), + 'maildigest', + $digestoptions, + null, + ''); +$digestoptions_selector->method = 'post'; // Start of the table for General Forums @@ -94,6 +106,9 @@ $can_subscribe = is_enrolled($coursecontext); if ($can_subscribe) { $generaltable->head[] = $strsubscribed; $generaltable->align[] = 'center'; + + $generaltable->head[] = $stremaildigest . ' ' . $OUTPUT->help_icon('emaildigesttype', 'mod_forum'); + $generaltable->align[] = 'center'; } if ($show_rss = (($can_subscribe || $course->id == SITEID) && @@ -111,7 +126,13 @@ $table = new html_table(); // some special ones are not. These get placed in the general forums // category with the forums in section 0. -$forums = $DB->get_records('forum', array('course' => $course->id)); +$forums = $DB->get_records_sql(" + SELECT f.*, + d.maildigest + FROM {forum} f + LEFT JOIN {forum_digests} d ON d.forum = f.id AND d.userid = ? + WHERE f.course = ? + ", array($USER->id, $course->id)); $generalforums = array(); $learningforums = array(); @@ -252,6 +273,14 @@ if ($generalforums) { } else { $row[] = '-'; } + + $digestoptions_selector->url->param('id', $forum->id); + if ($forum->maildigest === null) { + $digestoptions_selector->selected = -1; + } else { + $digestoptions_selector->selected = $forum->maildigest; + } + $row[] = $OUTPUT->render($digestoptions_selector); } //If this forum has RSS activated, calculate it @@ -297,6 +326,9 @@ if ($usetracking) { if ($can_subscribe) { $learningtable->head[] = $strsubscribed; $learningtable->align[] = 'center'; + + $learningtable->head[] = $stremaildigest . ' ' . $OUTPUT->help_icon('emaildigesttype', 'mod_forum'); + $learningtable->align[] = 'center'; } if ($show_rss = (($can_subscribe || $course->id == SITEID) && @@ -390,6 +422,14 @@ if ($course->id != SITEID) { // Only real courses have learning forums } else { $row[] = '-'; } + + $digestoptions_selector->url->param('id', $forum->id); + if ($forum->maildigest === null) { + $digestoptions_selector->selected = -1; + } else { + $digestoptions_selector->selected = $forum->maildigest; + } + $row[] = $OUTPUT->render($digestoptions_selector); } //If this forum has RSS activated, calculate it diff --git a/mod/forum/lang/en/forum.php b/mod/forum/lang/en/forum.php index 79a7bc03377..990b10939be 100644 --- a/mod/forum/lang/en/forum.php +++ b/mod/forum/lang/en/forum.php @@ -113,7 +113,8 @@ $string['deletedpost'] = 'The post has been deleted'; $string['deletedposts'] = 'Those posts have been deleted'; $string['deletesure'] = 'Are you sure you want to delete this post?'; $string['deletesureplural'] = 'Are you sure you want to delete this post and all replies? ({$a} posts)'; -$string['digestmailheader'] = 'This is your daily digest of new posts from the {$a->sitename} forums. To change your forum email preferences, go to {$a->userprefs}.'; +$string['digestmailheader'] = 'This is your daily digest of new posts from the {$a->sitename} forums. To change your default forum email preferences, go to {$a->userprefs}.'; +$string['digestmailpost'] = 'Change your forum digest preferences'; $string['digestmailprefs'] = 'your user profile'; $string['digestmailsubject'] = '{$a}: forum digest'; $string['digestmailtime'] = 'Hour to send digest emails'; @@ -142,6 +143,23 @@ $string['edit'] = 'Edit'; $string['editedby'] = 'Edited by {$a->name} - original submission {$a->date}'; $string['editedpostupdated'] = '{$a}\'s post was updated'; $string['editing'] = 'Editing'; +$string['emaildigestcompleteshort'] = 'Complete posts'; +$string['emaildigestdefault'] = 'Default ({$a})'; +$string['emaildigestoffshort'] = 'No digest'; +$string['emaildigestsubjectsshort'] = 'Subjects only'; +$string['emaildigesttype'] = 'Email digest options'; +$string['emaildigesttype_help'] = 'The type of notification that you will receive for each forum. + +* Default - follow the digest setting found in your user profile. If you update your profile, then that change will be reflected here too; +* No digest - you will receive one e-mail per forum post; +* Digest - complete posts - you will receive one digest e-mail per day containing the complete contents of each forum post; +* Digest - subjects only - you will receive one digest e-mail per day containing just the subject of each forum post. +'; +$string['emaildigestupdated'] = 'The e-mail digest option was changed to \'{$a->maildigesttitle}\' for the forum \'{$a->forum}\'. {$a->maildigestdescription}'; +$string['emaildigestupdated_default'] = 'Your default profile setting of \'{$a->maildigesttitle}\' was used for the forum \'{$a->forum}\'. {$a->maildigestdescription}.'; +$string['emaildigest_0'] = 'You will receive one e-mail per forum post.'; +$string['emaildigest_1'] = 'You will receive one digest e-mail per day containing the complete contents of each forum post.'; +$string['emaildigest_2'] = 'You will receive one digest e-mail per day containing the subject of each forum post.'; $string['emptymessage'] = 'Something was wrong with your post. Perhaps you left it blank, or the attachment was too big. Your changes have NOT been saved.'; $string['erroremptymessage'] = 'Post message cannot be empty'; $string['erroremptysubject'] = 'Post subject cannot be empty.'; @@ -209,6 +227,7 @@ $string['introsocial'] = 'An open forum for chatting about anything you want to' $string['introteacher'] = 'A forum for teacher-only notes and discussion'; $string['invalidaccess'] = 'This page was not accessed correctly'; $string['invaliddiscussionid'] = 'Discussion ID was incorrect or no longer exists'; +$string['invaliddigestsetting'] = 'An invalid mail digest setting was provided'; $string['invalidforcesubscribe'] = 'Invalid force subscription mode'; $string['invalidforumid'] = 'Forum ID was incorrect'; $string['invalidparentpostid'] = 'Parent post ID was incorrect'; @@ -347,6 +366,7 @@ $string['replyforum'] = 'Reply to forum'; $string['replytouser'] = 'Use email address in reply'; $string['resetforums'] = 'Delete posts from'; $string['resetforumsall'] = 'Delete all posts'; +$string['resetdigests'] = 'Delete all per-user forum digest preferences'; $string['resetsubscriptions'] = 'Delete all forum subscriptions'; $string['resettrackprefs'] = 'Delete all forum tracking preferences'; $string['rsssubscriberssdiscussions'] = 'RSS feed of discussions'; diff --git a/mod/forum/lib.php b/mod/forum/lib.php index 0dac55b172f..8a5a46b449d 100644 --- a/mod/forum/lib.php +++ b/mod/forum/lib.php @@ -264,6 +264,10 @@ function forum_delete_instance($id) { } } + if (!$DB->delete_records('forum_digests', array('forum' => $forum->id))) { + $result = false; + } + if (!$DB->delete_records('forum_subscriptions', array('forum'=>$forum->id))) { $result = false; } @@ -457,6 +461,17 @@ function forum_cron() { $endtime = $timenow - $CFG->maxeditingtime; $starttime = $endtime - 48 * 3600; // Two days earlier + // Get the list of forum subscriptions for per-user per-forum maildigest settings. + $digestsset = $DB->get_recordset('forum_digests', null, '', 'id, userid, forum, maildigest'); + $digests = array(); + foreach ($digestsset as $thisrow) { + if (!isset($digests[$thisrow->forum])) { + $digests[$thisrow->forum] = array(); + } + $digests[$thisrow->forum][$thisrow->userid] = $thisrow->maildigest; + } + $digestsset->close(); + if ($posts = forum_get_unmailed_posts($starttime, $endtime, $timenow)) { // 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, @@ -666,7 +681,9 @@ function forum_cron() { // OK so we need to send the email. // Does the user want this post in a digest? If so postpone it for now. - if ($userto->maildigest > 0) { + $maildigest = forum_get_user_maildigest_bulk($digests, $userto, $forum->id); + + if ($maildigest > 0) { // This user wants the mails to be in digest form $queue = new stdClass(); $queue->userid = $userto->id; @@ -991,7 +1008,8 @@ function forum_cron() { $userfrom->customheaders = array ("Precedence: Bulk"); - if ($userto->maildigest == 2) { + $maildigest = forum_get_user_maildigest_bulk($digests, $userto, $forum->id); + if ($maildigest == 2) { // Subjects and link only $posttext .= "\n"; $posttext .= $CFG->wwwroot.'/mod/forum/discuss.php?d='.$discussion->id; @@ -1015,11 +1033,14 @@ function forum_cron() { } } } + $footerlinks = array(); if ($canunsubscribe) { - $posthtml .= "\n
wwwroot/mod/forum/subscribe.php?id=$forum->id\">".get_string("unsubscribe", "forum")."
"; + $footerlinks[] = "wwwroot/mod/forum/subscribe.php?id=$forum->id\">" . get_string("unsubscribe", "forum") . ""; } else { - $posthtml .= "\n
".get_string("everyoneissubscribed", "forum")."
"; + $footerlinks[] = get_string("everyoneissubscribed", "forum"); } + $footerlinks[] = "" . get_string("digestmailpost", "forum") . ''; + $posthtml .= "\n
" . implode(' ', $footerlinks) . '
'; $posthtml .= '

'; } $posthtml .= ''; @@ -1153,6 +1174,10 @@ function forum_make_mail_text($course, $cm, $forum, $discussion, $post, $userfro $posttext .= ": $CFG->wwwroot/mod/forum/subscribe.php?id=$forum->id\n"; } + $posttext .= "\n---------------------------------------------------------------------\n"; + $posttext .= get_string("digestmailpost", "forum"); + $posttext .= ": {$CFG->wwwroot}/mod/forum/index.php?id={$forum->course}\n"; + return $posttext; } @@ -1206,11 +1231,13 @@ function forum_make_mail_html($course, $cm, $forum, $discussion, $post, $userfro } $posthtml .= forum_make_mail_post($course, $cm, $forum, $discussion, $post, $userfrom, $userto, false, $canreply, true, false); + $footerlinks = array(); if ($canunsubscribe) { - $posthtml .= '
'; + $footerlinks[] = '' . get_string('unsubscribe', 'forum') . ''; + $footerlinks[] = '' . get_string('unsubscribeall', 'forum') . ''; } + $footerlinks[] = "" . get_string('digestmailpost', 'forum') . ''; + $posthtml .= '
'; $posthtml .= ''; @@ -4819,7 +4846,8 @@ function forum_subscribe($userid, $forumid) { */ function forum_unsubscribe($userid, $forumid) { global $DB; - return $DB->delete_records("forum_subscriptions", array("userid"=>$userid, "forum"=>$forumid)); + return ($DB->delete_records('forum_digests', array('userid' => $userid, 'forum' => $forumid)) + && $DB->delete_records('forum_subscriptions', array('userid' => $userid, 'forum' => $forumid))); } /** @@ -6277,6 +6305,7 @@ function forum_user_unenrolled($cp) { $params = array('userid'=>$cp->userid, 'courseid'=>$cp->courseid); $forumselect = "IN (SELECT f.id FROM {forum} f WHERE f.course = :courseid)"; + $DB->delete_records_select('forum_digests', "userid = :userid AND forum $forumselect", $params); $DB->delete_records_select('forum_subscriptions', "userid = :userid AND forum $forumselect", $params); $DB->delete_records_select('forum_track_prefs', "userid = :userid AND forumid $forumselect", $params); $DB->delete_records_select('forum_read', "userid = :userid AND forumid $forumselect", $params); @@ -7320,6 +7349,12 @@ function forum_reset_userdata($data) { } } + // remove all digest settings unconditionally - even for users still enrolled in course. + if (!empty($data->reset_forum_digests)) { + $DB->delete_records_select('forum_digests', "forum IN ($allforumssql)", $params); + $status[] = array('component' => $componentstr, 'item' => get_string('resetdigests', 'forum'), 'error' => false); + } + // remove all subscriptions unconditionally - even for users still enrolled in course if (!empty($data->reset_forum_subscriptions)) { $DB->delete_records_select('forum_subscriptions', "forum IN ($allforumssql)", $params); @@ -7355,6 +7390,9 @@ function forum_reset_course_form_definition(&$mform) { $mform->setAdvanced('reset_forum_types'); $mform->disabledIf('reset_forum_types', 'reset_forum_all', 'checked'); + $mform->addElement('checkbox', 'reset_forum_digests', get_string('resetdigests','forum')); + $mform->setAdvanced('reset_forum_digests'); + $mform->addElement('checkbox', 'reset_forum_subscriptions', get_string('resetsubscriptions','forum')); $mform->setAdvanced('reset_forum_subscriptions'); @@ -7371,7 +7409,7 @@ function forum_reset_course_form_definition(&$mform) { * @return array */ function forum_reset_course_form_defaults($course) { - return array('reset_forum_all'=>1, 'reset_forum_subscriptions'=>0, 'reset_forum_track_prefs'=>0, 'reset_forum_ratings'=>1); + return array('reset_forum_all'=>1, 'reset_forum_digests' => 0, 'reset_forum_subscriptions'=>0, 'reset_forum_track_prefs'=>0, 'reset_forum_ratings'=>1); } /** @@ -8443,3 +8481,118 @@ function forum_get_posts_by_user($user, array $courses, $musthaveaccess = false, return $return; } + +/** + * Set the per-forum maildigest option for the specified user. + * + * @param stdClass $forum The forum to set the option for. + * @param int $maildigest The maildigest option. + * @param stdClass $user The user object. This defaults to the global $USER object. + * @throws invalid_digest_setting thrown if an invalid maildigest option is provided. + */ +function forum_set_user_maildigest($forum, $maildigest, $user = null) { + global $DB, $USER; + + if (is_number($forum)) { + $forum = $DB->get_record('forum', array('id' => $forum)); + } + + if ($user === null) { + $user = $USER; + } + + $course = $DB->get_record('course', array('id' => $forum->course), '*', MUST_EXIST); + $cm = get_coursemodule_from_instance('forum', $forum->id, $course->id, false, MUST_EXIST); + $context = context_module::instance($cm->id); + + // User must be allowed to see this forum. + require_capability('mod/forum:viewdiscussion', $context, $user->id); + + // Validate the maildigest setting. + $digestoptions = forum_get_user_digest_options($user); + + if (!isset($digestoptions[$maildigest])) { + throw new moodle_exception('invaliddigestsetting', 'mod_forum'); + } + + // Attempt to retrieve any existing forum digest record. + $subscription = $DB->get_record('forum_digests', array( + 'userid' => $user->id, + 'forum' => $forum->id, + )); + + // Create or Update the existing maildigest setting. + if ($subscription) { + if ($maildigest == -1) { + $DB->delete_records('forum_digests', array('forum' => $forum->id, 'userid' => $user->id)); + } else if ($maildigest !== $subscription->maildigest) { + // Only update the maildigest setting if it's changed. + + $subscription->maildigest = $maildigest; + $DB->update_record('forum_digests', $subscription); + } + } else { + if ($maildigest != -1) { + // Only insert the maildigest setting if it's non-default. + + $subscription = new stdClass(); + $subscription->forum = $forum->id; + $subscription->userid = $user->id; + $subscription->maildigest = $maildigest; + $subscription->id = $DB->insert_record('forum_digests', $subscription); + } + } + + return true; +} + +/** + * Determine the maildigest setting for the specified user against the + * specified forum. + * + * @param Array $digests An array of forums and user digest settings. + * @param stdClass $user The user object containing the id and maildigest default. + * @param int $forumid The ID of the forum to check. + * @return int The calculated maildigest setting for this user and forum. + */ +function forum_get_user_maildigest_bulk($digests, $user, $forumid) { + if (isset($digests[$forumid]) && isset($digests[$forumid][$user->id])) { + $maildigest = $digests[$forumid][$user->id]; + if ($maildigest === -1) { + $maildigest = $user->maildigest; + } + } else { + $maildigest = $user->maildigest; + } + return $maildigest; +} + +/** + * Retrieve the list of available user digest options. + * + * @param stdClass $user The user object. This defaults to the global $USER object. + * @return array The mapping of values to digest options. + */ +function forum_get_user_digest_options($user = null) { + global $USER; + + // Revert to the global user object. + if ($user === null) { + $user = $USER; + } + + $digestoptions = array(); + $digestoptions['0'] = get_string('emaildigestoffshort', 'mod_forum'); + $digestoptions['1'] = get_string('emaildigestcompleteshort', 'mod_forum'); + $digestoptions['2'] = get_string('emaildigestsubjectsshort', 'mod_forum'); + + // We need to add the default digest option at the end - it relies on + // the contents of the existing values. + $digestoptions['-1'] = get_string('emaildigestdefault', 'mod_forum', + $digestoptions[$user->maildigest]); + + // Resort the options to be in a sensible order. + ksort($digestoptions); + + return $digestoptions; +} diff --git a/mod/forum/maildigest.php b/mod/forum/maildigest.php new file mode 100644 index 00000000000..e7fbd88a88a --- /dev/null +++ b/mod/forum/maildigest.php @@ -0,0 +1,77 @@ +. + +/** + * Set the mail digest option in a specific forum for a user. + * + * @copyright 2013 Andrew Nicols + * @package mod_forum + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +require_once(dirname(dirname(__DIR__)) . '/config.php'); +require_once($CFG->dirroot.'/mod/forum/lib.php'); + +$id = required_param('id', PARAM_INT); +$maildigest = required_param('maildigest', PARAM_INT); +$backtoindex = optional_param('backtoindex', 0, PARAM_INT); + +// We must have a valid session key. +require_sesskey(); + +$forum = $DB->get_record('forum', array('id' => $id)); +$course = $DB->get_record('course', array('id' => $forum->course), '*', MUST_EXIST); +$cm = get_coursemodule_from_instance('forum', $forum->id, $course->id, false, MUST_EXIST); +$context = context_module::instance($cm->id); + +require_course_login($course); + +$url = new moodle_url('/mod/forum/maildigest.php', array( + 'id' => $id, + 'maildigest' => $maildigest, +)); +$PAGE->set_url($url); +$PAGE->set_context($context); + +$digestoptions = forum_get_user_digest_options(); + +$info = new stdClass(); +$info->name = fullname($USER); +$info->forum = format_string($forum->name); +$info->maildigest = forum_set_user_maildigest($forum, $maildigest); + +if ($maildigest === -1) { + // Get the default maildigest options. + $info->maildigest = $USER->maildigest; + $info->maildigesttitle = $digestoptions[$info->maildigest]; + $info->maildigestdescription = get_string('emaildigest_' . $info->maildigest, + 'mod_forum', $info); + $updatemessage = get_string('emaildigestupdated_default', 'forum', $info); +} else { + $info->maildigesttitle = $digestoptions[$info->maildigest]; + $info->maildigestdescription = get_string('emaildigest_' . $info->maildigest, + 'mod_forum', $info); + $updatemessage = get_string('emaildigestupdated', 'forum', $info); +} + +if ($backtoindex) { + $returnto = "index.php?id={$course->id}"; +} else { + $returnto = "view.php?f={$id}"; +} + +redirect($returnto, $updatemessage, 1); diff --git a/mod/forum/version.php b/mod/forum/version.php index cbd7595762d..4c62e97084f 100644 --- a/mod/forum/version.php +++ b/mod/forum/version.php @@ -25,7 +25,7 @@ defined('MOODLE_INTERNAL') || die(); -$module->version = 2013050100; // The current module version (Date: YYYYMMDDXX) +$module->version = 2013071000; // The current module version (Date: YYYYMMDDXX) $module->requires = 2013050100; // Requires this Moodle version $module->component = 'mod_forum'; // Full name of the plugin (used for diagnostics) $module->cron = 60; diff --git a/user/editlib.php b/user/editlib.php index fd2dc575822..42489b19a04 100644 --- a/user/editlib.php +++ b/user/editlib.php @@ -208,6 +208,7 @@ function useredit_shared_definition(&$mform, $editoroptions = null, $filemanager $choices['2'] = get_string('emaildigestsubjects'); $mform->addElement('select', 'maildigest', get_string('emaildigest'), $choices); $mform->setDefault('maildigest', 0); + $mform->addHelpButton('maildigest', 'emaildigest'); $choices = array(); $choices['1'] = get_string('autosubscribeyes'); diff --git a/version.php b/version.php index 98f67545ded..4e51da6b11f 100644 --- a/version.php +++ b/version.php @@ -29,7 +29,7 @@ defined('MOODLE_INTERNAL') || die(); -$version = 2013081300.00; // YYYYMMDD = weekly release date of this DEV branch +$version = 2013081400.00; // YYYYMMDD = weekly release date of this DEV branch // RR = release increments - 00 in DEV branches // .XX = incremental changes