2023-05-17 21:19:14 +02:00
|
|
|
<?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/>.
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @package local_treestudyplan
|
|
|
|
* @copyright 2023 P.M. Kuipers
|
|
|
|
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
|
*/
|
|
|
|
|
|
|
|
require_once("../../config.php");
|
2023-05-17 21:19:14 +02:00
|
|
|
|
|
|
|
require_once("./lib.php");
|
|
|
|
require_once($CFG->libdir.'/weblib.php');
|
|
|
|
require_once($CFG->dirroot.'/local/treestudyplan/classes/reportinvite_form.php');
|
|
|
|
|
2023-08-25 10:41:56 +02:00
|
|
|
$add = optional_param('add', '', PARAM_ALPHANUM); // Module name.
|
2023-05-17 21:19:14 +02:00
|
|
|
$update = optional_param('update', 0, PARAM_INT);
|
|
|
|
$resend = optional_param('resend', 0, PARAM_INT);
|
|
|
|
$delete = optional_param('delete', 0, PARAM_INT);
|
|
|
|
|
|
|
|
$systemcontext = context_system::instance();
|
|
|
|
|
|
|
|
$PAGE->set_url("/local/treestudyplan/edit-invite.php");
|
|
|
|
$PAGE->set_pagelayout('base');
|
|
|
|
$PAGE->set_context($systemcontext);
|
|
|
|
|
2023-08-24 23:02:41 +02:00
|
|
|
if ($update > 0) {
|
2023-08-25 09:44:34 +02:00
|
|
|
$PAGE->set_title(get_string('invite_desc_edit', 'local_treestudyplan'));
|
|
|
|
$PAGE->set_heading(get_string('invite_desc_edit', 'local_treestudyplan'));
|
2023-08-25 09:33:42 +02:00
|
|
|
} else {
|
2023-08-25 09:44:34 +02:00
|
|
|
$PAGE->set_title(get_string('invite_desc_new', 'local_treestudyplan'));
|
|
|
|
$PAGE->set_heading(get_string('invite_desc_new', 'local_treestudyplan'));
|
2023-05-17 21:19:14 +02:00
|
|
|
}
|
|
|
|
|
2023-08-24 23:02:41 +02:00
|
|
|
// Check if user has capability to manage study plan units.
|
2023-05-17 21:19:14 +02:00
|
|
|
require_login();
|
|
|
|
|
|
|
|
print $OUTPUT->header();
|
|
|
|
|
2023-08-24 23:02:41 +02:00
|
|
|
if (!empty($add)) {
|
2023-08-25 09:44:34 +02:00
|
|
|
$data = array(
|
|
|
|
'add' => 1,
|
|
|
|
);
|
2023-05-17 21:19:14 +02:00
|
|
|
|
2023-08-24 23:09:20 +02:00
|
|
|
} else if (!empty($update)) {
|
2023-08-25 09:44:34 +02:00
|
|
|
$data = $DB->get_record("local_treestudyplan_invit", array('id' => $update));
|
|
|
|
$data->update = $update;
|
2023-08-25 10:41:56 +02:00
|
|
|
if (empty($data) || $data->user_id != $USER->id) {
|
2023-08-25 09:44:34 +02:00
|
|
|
print_error('invalidaction');
|
|
|
|
exit;
|
|
|
|
}
|
2023-05-17 21:19:14 +02:00
|
|
|
|
2023-08-24 23:09:20 +02:00
|
|
|
} else if (!empty($resend)) {
|
2023-08-25 09:44:34 +02:00
|
|
|
$data = $DB->get_record("local_treestudyplan_invit", array('id' => $resend));
|
|
|
|
$data->resend = $resend;
|
2023-08-25 10:41:56 +02:00
|
|
|
if (empty($data) || $data->user_id != $USER->id) {
|
2023-08-25 09:44:34 +02:00
|
|
|
print_error('invalidaction');
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Do some resending of an invitation.
|
2023-08-25 10:41:56 +02:00
|
|
|
local_treestudyplan_send_invite($data->id);
|
2023-08-25 09:44:34 +02:00
|
|
|
redirect("$CFG->wwwroot/local/treestudyplan/invitations.php?sent={$resend}");
|
|
|
|
print $OUTPUT->footer();
|
|
|
|
exit;
|
2023-08-24 23:09:20 +02:00
|
|
|
} else if (!empty($delete)) {
|
2023-08-25 09:44:34 +02:00
|
|
|
$data = $DB->get_record("local_treestudyplan_invit", array('id' => $delete));
|
|
|
|
$data->delete = $delete;
|
2023-08-25 10:41:56 +02:00
|
|
|
if (empty($data) || $data->user_id != $USER->id) {
|
2023-08-25 09:44:34 +02:00
|
|
|
print_error('invalidaction');
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
$DB->delete_records('local_treestudyplan_invit', ['id' => $data->delete]);
|
2023-08-25 10:41:56 +02:00
|
|
|
|
2023-08-25 09:44:34 +02:00
|
|
|
redirect("$CFG->wwwroot/local/treestudyplan/invitations.php");
|
|
|
|
print $OUTPUT->footer();
|
|
|
|
exit;
|
2023-08-24 23:09:20 +02:00
|
|
|
} else {
|
2023-08-25 09:44:34 +02:00
|
|
|
print_error('invalidaction');
|
2023-05-17 21:19:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$mform = new reportinvite_form();
|
|
|
|
$mform->set_data($data);
|
|
|
|
|
2023-08-24 23:02:41 +02:00
|
|
|
if ($mform->is_cancelled()) {
|
2023-08-25 09:44:34 +02:00
|
|
|
redirect("$CFG->wwwroot/local/treestudyplan/invitations.php");
|
2023-08-24 23:09:20 +02:00
|
|
|
} else if ($data = $mform->get_data()) {
|
2023-08-25 10:41:56 +02:00
|
|
|
if (!empty($data->update)) {
|
|
|
|
|
2023-08-25 09:44:34 +02:00
|
|
|
$id = $data->update;
|
|
|
|
$data->id = $id;
|
|
|
|
|
|
|
|
$DB->update_record('local_treestudyplan_invit', $data);
|
|
|
|
|
|
|
|
redirect("$CFG->wwwroot/local/treestudyplan/invitations.php");
|
|
|
|
|
2023-08-25 11:52:05 +02:00
|
|
|
} else if (!empty($data->add)) {
|
2023-08-25 09:44:34 +02:00
|
|
|
|
|
|
|
$id = $DB->insert_record("local_treestudyplan_invit", $data, true);
|
2023-08-25 10:41:56 +02:00
|
|
|
|
2023-08-25 09:44:34 +02:00
|
|
|
// Send invitaion mail.
|
2023-08-25 10:41:56 +02:00
|
|
|
local_treestudyplan_send_invite($id);
|
2023-08-25 09:44:34 +02:00
|
|
|
|
|
|
|
redirect("$CFG->wwwroot/local/treestudyplan/invitations.php?sent={$id}");
|
2023-08-25 11:52:05 +02:00
|
|
|
} else if (!empty($data->resend)) {
|
2023-08-25 09:44:34 +02:00
|
|
|
|
2023-08-25 11:52:05 +02:00
|
|
|
} else if (!empty($data->delete)) {
|
2023-08-25 09:44:34 +02:00
|
|
|
|
2023-08-25 11:52:05 +02:00
|
|
|
} else
|
2023-08-25 09:44:34 +02:00
|
|
|
{
|
|
|
|
print_error("invaliddata");
|
|
|
|
}
|
|
|
|
|
|
|
|
exit;
|
2023-08-25 10:41:56 +02:00
|
|
|
|
2023-08-25 09:33:42 +02:00
|
|
|
} else {
|
2023-08-25 09:44:34 +02:00
|
|
|
$data = null;
|
2023-08-25 10:41:56 +02:00
|
|
|
if ($unitid > 0) {
|
|
|
|
|
2023-08-25 09:44:34 +02:00
|
|
|
}
|
|
|
|
$mform->display();
|
2023-05-17 21:19:14 +02:00
|
|
|
}
|
|
|
|
|
2023-08-25 11:52:05 +02:00
|
|
|
print $OUTPUT->footer();
|