2 // This file is part of Moodle - http://moodle.org/
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.
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.
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/>.
18 * A page displaying the user's contact requests.
20 * This is a temporary (well, should be) page until the new UI is introduced for 3.6.
22 * @package core_message
23 * @copyright 2018 Mark Nelson <markn@moodle.com>
24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27 require_once('../config.php');
28 require_once($CFG->dirroot
. '/message/externallib.php');
30 require_login(null, false);
33 redirect($CFG->wwwroot
);
36 if (empty($CFG->messaging
)) {
37 print_error('disabled', 'message');
40 $userid = optional_param('userid', '', PARAM_INT
); // The userid of the request.
41 $action = optional_param('action', '', PARAM_ALPHA
);
43 // Confirm the request is able to be approved/disapproved.
45 $request = $DB->get_record('message_contact_requests', ['userid' => $userid, 'requesteduserid' => $USER->id
], '*', MUST_EXIST
);
48 // Use external functions as these are what we will be using in the new UI.
49 if ($userid && $action && confirm_sesskey()) {
50 if ($action == 'approve') {
51 core_message_external
::confirm_contact_request($request->userid
, $USER->id
);
52 } else if ($action == 'decline') {
53 core_message_external
::decline_contact_request($request->userid
, $USER->id
);
56 redirect(new moodle_url('/message/pendingcontactrequests.php'));
59 $table = new html_table();
65 $table->head
= $headers;
67 // Use external functions as these are what we will be using in the new UI.
68 if ($contactrequests = core_message_external
::get_contact_requests($USER->id
)) {
69 foreach ($contactrequests as $contactrequest) {
70 $approvelink = new moodle_url('/message/pendingcontactrequests.php', ['userid' => $contactrequest->id
,
71 'action' => 'approve', 'sesskey' => sesskey()]);
72 $declinelink = new moodle_url('/message/pendingcontactrequests.php', ['userid' => $contactrequest->id
,
73 'action' => 'decline', 'sesskey' => sesskey()]);
76 $cells[] = $contactrequest->fullname
;
77 $cells[] = html_writer
::link($approvelink, get_string('approve')) . " | " .
78 html_writer
::link($declinelink, get_string('cancel'));
79 $table->data
[] = new html_table_row($cells);
83 $url = new moodle_url('/message/pendingcontactrequests.php');
86 $PAGE->set_context(context_user
::instance($USER->id
));
87 $PAGE->set_pagelayout('standard');
88 $PAGE->set_title('Pending contact requests');
89 $PAGE->set_heading('Pending contact requests');
91 echo $OUTPUT->header();
92 echo html_writer
::table($table);
93 echo $OUTPUT->footer();