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 * listdoc=<array> List of policy version ids that were displayed to the user to accept.
22 * agreedoc=<array> List of policy version ids that were accepted by the user.
23 * behalfid=<id> The user id to view the policy version as (such as child's id).
25 * @package tool_policy
26 * @copyright 2018 Sara Arjona (sara@moodle.com)
27 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
31 use tool_policy\output\page_agreedocs;
33 // Do not check for the site policies in require_login() to avoid the redirect loop.
34 define('NO_SITEPOLICY_CHECK', true);
36 // @codingStandardsIgnoreLine See the {@link page_agreedocs} for the access control checks.
37 require(__DIR__.'/../../../config.php');
39 $submit = optional_param('submit', null, PARAM_NOTAGS);
40 $cancel = optional_param('cancel', null, PARAM_NOTAGS);
41 $listdocs = optional_param_array('listdoc', [], PARAM_INT);
42 $agreedocs = optional_param_array('agreedoc', [], PARAM_INT);
43 $behalfid = optional_param('userid', null, PARAM_INT);
45 $PAGE->set_context(context_system::instance());
46 $PAGE->set_pagelayout('standard');
47 $PAGE->set_url('/admin/tool/policy/index.php');
48 $PAGE->set_popup_notification_allowed(false);
50 if (array_diff($agreedocs, $listdocs)) {
51 throw new moodle_exception('invalidaccessparameter');
54 if (isloggedin() && !isguestuser()) {
56 $haspermissionagreedocs = api::can_accept_policies($behalfid);
59 $haspermissionagreedocs = true;
62 if (!$haspermissionagreedocs) {
63 $outputpage = new \tool_policy\output\page_nopermission($behalfid);
65 redirect(new moodle_url('/'));
67 if (!$behalfid && \core\session\manager::is_loggedinas()) {
68 $behalfid = $USER->id;
70 $outputpage = new \tool_policy\output\page_agreedocs($listdocs, $agreedocs, $behalfid, $submit);
73 $output = $PAGE->get_renderer('tool_policy');
75 echo $output->header();
76 echo $output->render($outputpage);
77 echo $output->footer();