3 // This file is part of Moodle - http://moodle.org/
5 // Moodle is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
10 // Moodle is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
19 * Set the mail digest option in a specific forum for a user.
21 * @copyright 2013 Andrew Nicols
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 require(__DIR__
.'/../../config.php');
27 require_once($CFG->dirroot
.'/mod/forum/lib.php');
29 $id = required_param('id', PARAM_INT
);
30 $maildigest = required_param('maildigest', PARAM_INT
);
31 $backtoindex = optional_param('backtoindex', 0, PARAM_INT
);
33 // We must have a valid session key.
36 $forum = $DB->get_record('forum', array('id' => $id));
37 $course = $DB->get_record('course', array('id' => $forum->course
), '*', MUST_EXIST
);
38 $cm = get_coursemodule_from_instance('forum', $forum->id
, $course->id
, false, MUST_EXIST
);
39 $context = context_module
::instance($cm->id
);
41 require_login($course, false, $cm);
43 $url = new moodle_url('/mod/forum/maildigest.php', array(
45 'maildigest' => $maildigest,
48 $PAGE->set_context($context);
50 $digestoptions = forum_get_user_digest_options();
52 $info = new stdClass();
53 $info->name
= fullname($USER);
54 $info->forum
= format_string($forum->name
);
55 forum_set_user_maildigest($forum, $maildigest);
56 $info->maildigest
= $maildigest;
58 if ($maildigest === -1) {
59 // Get the default maildigest options.
60 $info->maildigest
= $USER->maildigest
;
61 $info->maildigesttitle
= $digestoptions[$info->maildigest
];
62 $info->maildigestdescription
= get_string('emaildigest_' . $info->maildigest
,
64 $updatemessage = get_string('emaildigestupdated_default', 'forum', $info);
66 $info->maildigesttitle
= $digestoptions[$info->maildigest
];
67 $info->maildigestdescription
= get_string('emaildigest_' . $info->maildigest
,
69 $updatemessage = get_string('emaildigestupdated', 'forum', $info);
73 $returnto = "index.php?id={$course->id}";
75 $returnto = "view.php?f={$id}";
78 redirect($returnto, $updatemessage, null, \core\output\notification
::NOTIFY_SUCCESS
);