Merge branch 'MDL-63625-master' of git://github.com/marinaglancy/moodle
[moodle.git] / message / pendingcontactrequests.php
blobcab15e921b129d66d95d3676cd948e42b051380a
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.
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/>.
17 /**
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);
32 if (isguestuser()) {
33 redirect($CFG->wwwroot);
36 if (empty($CFG->messaging)) {
37 print_error('disabled', 'message');
40 $id = optional_param('id', '', PARAM_INT); // The id of the request.
41 $action = optional_param('action', '', PARAM_ALPHA);
43 // Confirm the request is able to be approved/disapproved.
44 if ($id) {
45 $request = $DB->get_record('message_contact_requests', ['id' => $id, 'requesteduserid' => $USER->id], '*', MUST_EXIST);
48 // Use external functions as these are what we will be using in the new UI.
49 if ($id && $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();
61 $headers = [];
62 $headers[] = '';
63 $headers[] = '';
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', ['id' => $contactrequest->contactrequestid,
71 'action' => 'approve', 'sesskey' => sesskey()]);
72 $declinelink = new moodle_url('/message/pendingcontactrequests.php', ['id' => $contactrequest->contactrequestid,
73 'action' => 'decline', 'sesskey' => sesskey()]);
75 $cells = array();
76 $cells[] = fullname($contactrequest);
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');
84 $PAGE->set_url($url);
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();