Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
// This file is part of Moodle - http://moodle.org/
3
//
4
// Moodle is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8
//
9
// Moodle is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
16
 
17
// Email form added to enable email to selected users.
18
require_once('../../config.php');
19
require_once($CFG->libdir . '/formslib.php');
20
 
21
require_login();
22
global $PAGE, $USER, $DB, $COURSE;
23
$context = context_course::instance($COURSE->id);
24
$PAGE->set_context($context);
25
 
26
if (!has_capability('block/configurable_reports:managereports', $context) && !has_capability('block/configurable_reports:manageownreports', $context)) {
27
    print_error('badpermissions');
28
}
29
 
30
class sendemail_form extends moodleform {
31
 
32
    public function definition() {
33
        global $COURSE;
34
 
35
        $mform =& $this->_form;
36
        $context = \context_course::instance($COURSE->id);
37
        $editoroptions = [
38
            'trusttext' => true,
39
            'subdirs' => true,
40
            'maxfiles' => EDITOR_UNLIMITED_FILES,
41
            'context' => $context
42
        ];
43
 
44
        $mform->addElement('hidden', 'usersids', $this->_customdata['usersids']);
45
        $mform->addElement('hidden', 'courseid', $this->_customdata['courseid']);
46
 
47
        $mform->addElement('text', 'subject', get_string('email_subject', 'block_configurable_reports'));
48
        $mform->setType('subject', PARAM_TEXT);
49
        $mform->addRule('subject', null, 'required');
50
 
51
        $mform->addElement('editor', 'content', get_string('email_message', 'block_configurable_reports'), null, $editoroptions);
52
 
53
        $buttons = array();
54
        $buttons[] =& $mform->createElement('submit', 'send', get_string('email_send', 'block_configurable_reports'));
55
        $buttons[] =& $mform->createElement('cancel');
56
 
57
        $mform->addGroup($buttons, 'buttons', get_string('actions'), array(' '), false);
58
    }
59
}
60
 
61
$form = new \sendemail_form(null, ['usersids' => implode(',', $_POST['userids']), 'courseid' => $_POST['courseid']]);
62
 
63
if ($form->is_cancelled()) {
64
    redirect(new \moodle_url('/course/view.php?id='.$data->courseid));
65
} else if ($data = $form->get_data()) {
66
    foreach (explode(',', $data->usersids) as $userid) {
67
        $abouttosenduser = $DB->get_record('user', ['id' => $userid]);
68
        email_to_user($abouttosenduser, $USER, $data->subject, format_text($data->content['text']), $data->content['text']);
69
    }
70
    // After emails were sent... go back to where you came from.
71
    redirect(new \moodle_url('/course/view.php?id='.$data->courseid));
72
}
73
 
74
$PAGE->set_title(get_string('email', 'questionnaire'));
75
$PAGE->set_heading(format_string($COURSE->fullname));
76
$PAGE->navbar->add(get_string('email', 'questionnaire'));
77
 
78
echo $OUTPUT->header();
79
 
80
echo \html_writer::start_tag('div', ['class' => 'no-overflow']);
81
$form->display();
82
echo \html_writer::end_tag('div');
83
 
84
echo $OUTPUT->footer();