Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
 
3
// This file is part of Moodle - http://moodle.org/
4
//
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.
9
//
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.
14
//
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/>.
17
 
18
/**
19
 * Set the mail digest option in a specific forum for a user.
20
 *
21
 * @copyright 2013 Andrew Nicols
22
 * @package   mod_forum
23
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24
 */
25
 
26
require(__DIR__.'/../../config.php');
27
require_once($CFG->dirroot.'/mod/forum/lib.php');
28
 
29
$id = required_param('id', PARAM_INT);
30
$maildigest = required_param('maildigest', PARAM_INT);
31
$backtoindex = optional_param('backtoindex', 0, PARAM_INT);
32
 
33
// We must have a valid session key.
34
require_sesskey();
35
 
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);
40
 
41
require_login($course, false, $cm);
42
 
43
$url = new moodle_url('/mod/forum/maildigest.php', array(
44
    'id' => $id,
45
    'maildigest' => $maildigest,
46
));
47
$PAGE->set_url($url);
48
$PAGE->set_context($context);
49
 
50
$digestoptions = forum_get_user_digest_options();
51
 
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;
57
 
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,
63
        'mod_forum', $info);
64
    $updatemessage = get_string('emaildigestupdated_default', 'forum', $info);
65
} else {
66
    $info->maildigesttitle = $digestoptions[$info->maildigest];
67
    $info->maildigestdescription = get_string('emaildigest_' . $info->maildigest,
68
        'mod_forum', $info);
69
    $updatemessage = get_string('emaildigestupdated', 'forum', $info);
70
}
71
 
72
if ($backtoindex) {
73
    $returnto = "index.php?id={$course->id}";
74
} else {
75
    $returnto = "view.php?f={$id}";
76
}
77
 
78
redirect($returnto, $updatemessage, null, \core\output\notification::NOTIFY_SUCCESS);