This repository has been archived on 2025-01-01. You can view files and clone it, but cannot push or open issues or pull requests.
moodle-local_treestudyplan/invitations.php

72 lines
2.7 KiB
PHP
Raw Normal View History

<?php
2023-08-24 23:02:41 +02:00
// This file is part of the Studyplan plugin for Moodle
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <https://www.gnu.org/licenses/>.
2024-07-19 12:31:26 +02:00
2023-08-24 23:02:41 +02:00
/**
2023-08-27 15:12:54 +02:00
* Entry point for students to manage invitations to view their study plan
2023-08-24 23:02:41 +02:00
* @package local_treestudyplan
* @copyright 2023 P.M. Kuipers
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
2023-08-25 13:04:19 +02:00
require_once("../../config.php");
require_once($CFG->libdir.'/weblib.php');
require_once($CFG->dirroot.'/grade/querylib.php');
$systemcontext = context_system::instance();
2024-06-02 19:23:40 +02:00
$PAGE->set_url("/local/treestudyplan/invitations.php", []);
require_login();
$PAGE->set_pagelayout('base');
$PAGE->set_context($systemcontext);
$PAGE->set_title(get_string('manage_invites', 'local_treestudyplan'));
$PAGE->set_heading(get_string('manage_invites', 'local_treestudyplan'));
2023-08-24 23:02:41 +02:00
// Load javascripts.
$PAGE->requires->js_call_amd('local_treestudyplan/page-invitemanager', 'init');
2023-08-25 13:04:19 +02:00
// Retrieve list of courses that the student is enrolled in.
2023-08-24 23:02:41 +02:00
$sent = optional_param('sent', '', PARAM_INT);
if (!empty($sent)) {
2024-06-02 19:23:40 +02:00
$invite = $DB->get_record('local_treestudyplan_invit', ['id' => $sent]);
2023-08-25 09:44:34 +02:00
\core\notification::success(get_string('invite_resent_msg', 'local_treestudyplan', $invite));
};
2024-06-02 19:23:40 +02:00
if (!get_config("local_treestudyplan", "enableplansharing")) {
$PAGE->set_title(get_string('accessdenied', 'admin'));
$PAGE->set_heading(get_string('accessdenied', 'admin'));
print $OUTPUT->header();
print $OUTPUT->render_from_template('local_treestudyplan/error', [
"title" => get_string('accessdenied', 'admin'),
"message" => get_string('error:invitationsdisabled', 'local_treestudyplan'),
]);
print $OUTPUT->footer();
exit; // Just in case some code is added after this if statement erroneously later.
2023-08-25 09:33:42 +02:00
} else {
print $OUTPUT->header();
2024-06-02 19:23:40 +02:00
$invites = $DB->get_records('local_treestudyplan_invit', ['user_id' => $USER->id]);
$data = [
"invites" => array_values($invites),
"hasinvites" => boolval(count($invites) > 0),
"invitedurl" => "{$CFG->wwwroot}/local/treestudyplan/invited.php",
];
print $OUTPUT->render_from_template('local_treestudyplan/invitations', $data);
print $OUTPUT->footer();
2024-06-02 23:23:32 +02:00
}