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 * Show a user the policy documents to be agreed to.
21 * agreedoc=<array> Policy version id which have been accepted by the user.
22 * behalfid=<id> The user id to view the policy version as (such as child's id).
24 * @package tool_policy
25 * @copyright 2018 Sara Arjona (sara@moodle.com)
26 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
30 use tool_policy\output\page_agreedocs;
32 // Do not check for the site policies in require_login() to avoid the redirect loop.
33 define('NO_SITEPOLICY_CHECK', true);
35 // @codingStandardsIgnoreLine See the {@link page_agreedocs} for the access control checks.
36 require(__DIR__.'/../../../config.php');
38 $submit = optional_param('submit', null, PARAM_NOTAGS);
39 $cancel = optional_param('cancel', null, PARAM_NOTAGS);
40 $agreedocs = optional_param_array('agreedoc', null, PARAM_INT);
41 $behalfid = optional_param('userid', null, PARAM_INT);
43 $PAGE->set_context(context_system::instance());
44 $PAGE->set_pagelayout('standard');
45 $PAGE->set_url('/admin/tool/policy/index.php');
46 $PAGE->set_popup_notification_allowed(false);
48 if (isloggedin() && !isguestuser()) {
50 $haspermissionagreedocs = api::can_accept_policies($behalfid);
53 $haspermissionagreedocs = true;
56 if (!$haspermissionagreedocs) {
57 $outputpage = new \tool_policy\output\page_nopermission($behalfid);
59 redirect(new moodle_url('/'));
61 if (!$behalfid && \core\session\manager::is_loggedinas()) {
62 $behalfid = $USER->id;
64 $outputpage = new \tool_policy\output\page_agreedocs($agreedocs, $behalfid, $submit);
67 $output = $PAGE->get_renderer('tool_policy');
69 echo $output->header();
70 echo $output->render($outputpage);
71 echo $output->footer();