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 |
/**
|
|
|
18 |
* Displays and processes the messaging form
|
|
|
19 |
*
|
|
|
20 |
* @package block_messageteacher
|
|
|
21 |
* @author Mark Johnson <mark@barrenfrozenwasteland.com>
|
|
|
22 |
* @copyright 2013 Mark Johnson
|
|
|
23 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
24 |
*/
|
|
|
25 |
|
|
|
26 |
require_once(__DIR__.'/../../config.php');
|
|
|
27 |
|
|
|
28 |
$courseid = required_param('courseid', PARAM_INT);
|
|
|
29 |
$recipientid = required_param('recipientid', PARAM_INT);
|
|
|
30 |
$referurl = required_param('referurl', PARAM_URL);
|
|
|
31 |
|
|
|
32 |
$coursecontext = context_course::instance($courseid);
|
|
|
33 |
$PAGE->set_context($coursecontext);
|
|
|
34 |
|
|
|
35 |
require_login();
|
|
|
36 |
require_capability('moodle/site:sendmessage', $coursecontext);
|
|
|
37 |
|
|
|
38 |
$url = '/blocks/messageteacher/message.php';
|
|
|
39 |
$PAGE->set_url($url);
|
|
|
40 |
|
|
|
41 |
$recipient = $DB->get_record('user', array('id' => $recipientid));
|
|
|
42 |
|
|
|
43 |
$defaultdata = array(
|
|
|
44 |
'recipientid' => $recipient->id,
|
|
|
45 |
'reciepientname' => fullname($recipient),
|
|
|
46 |
'referurl' => $referurl,
|
|
|
47 |
'courseid' => $courseid
|
|
|
48 |
);
|
|
|
49 |
$mform = new block_messageteacher\message_form();
|
|
|
50 |
$mform->set_data($defaultdata);
|
|
|
51 |
|
|
|
52 |
if ($mform->is_cancelled()) {
|
|
|
53 |
// Form cancelled, redirect.
|
|
|
54 |
redirect($referurl);
|
|
|
55 |
exit();
|
|
|
56 |
} else if (($data = $mform->get_data())) {
|
|
|
57 |
$mform->process($data);
|
|
|
58 |
redirect($data->referurl);
|
|
|
59 |
exit();
|
|
|
60 |
} else {
|
|
|
61 |
echo $OUTPUT->header();
|
|
|
62 |
$mform->display();
|
|
|
63 |
echo $OUTPUT->footer();
|
|
|
64 |
}
|