Merge branch 'MDL-80633-main' of https://github.com/laurentdavid/moodle
[moodle.git] / user / policy.php
blobc8e42d0824de24d50e87b45ba616dd4c815a54b6
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 * This file is part of the User section Moodle
20 * @copyright 1999 Martin Dougiamas http://dougiamas.com
21 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
22 * @package core_user
25 // Do not check for the site policies in require_login() to avoid the redirect loop.
26 define('NO_SITEPOLICY_CHECK', true);
28 require_once('../config.php');
29 require_once($CFG->libdir.'/filelib.php');
30 require_once($CFG->libdir.'/resourcelib.php');
32 $agree = optional_param('agree', 0, PARAM_BOOL);
34 $PAGE->set_url('/user/policy.php');
35 $PAGE->set_popup_notification_allowed(false);
37 if (!isloggedin()) {
38 require_login();
41 if (!empty($SESSION->wantsurl)) {
42 $return = $SESSION->wantsurl;
43 } else {
44 $return = $CFG->wwwroot.'/';
47 $sitepolicymanager = new \core_privacy\local\sitepolicy\manager();
48 if (!empty($CFG->sitepolicyhandler)) {
49 // We are on the wrong page, site policies are managed by somebody else.
50 if ($sitepolicyurl = $sitepolicymanager->get_redirect_url(isguestuser())) {
51 redirect($sitepolicyurl);
52 } else {
53 redirect($return);
57 $sitepolicy = $sitepolicymanager->get_embed_url(isguestuser());
58 if (empty($sitepolicy)) {
59 // Nothing to agree to, sorry, hopefully we will not get to infinite loop.
60 redirect($return);
63 if ($agree and confirm_sesskey()) { // User has agreed.
64 $sitepolicymanager->accept();
65 unset($SESSION->wantsurl);
66 redirect($return);
69 $strpolicyagree = get_string('policyagree');
70 $strpolicyagreement = get_string('policyagreement');
71 $strpolicyagreementclick = get_string('policyagreementclick');
73 $PAGE->set_context(context_system::instance());
74 $PAGE->set_title($strpolicyagreement);
75 $PAGE->set_heading($SITE->fullname);
76 $PAGE->navbar->add($strpolicyagreement);
78 echo $OUTPUT->header();
79 echo $OUTPUT->heading($strpolicyagreement);
81 $mimetype = mimeinfo('type', $sitepolicy);
82 if ($mimetype == 'document/unknown') {
83 // Fallback for missing index.php, index.html.
84 $mimetype = 'text/html';
87 // We can not use our popups here, because the url may be arbitrary, see MDL-9823.
88 $clicktoopen = '<a href="'.$sitepolicy.'" onclick="this.target=\'_blank\'">'.$strpolicyagreementclick.'</a>';
90 echo '<div class="noticebox">';
91 echo resourcelib_embed_general($sitepolicy, $strpolicyagreement, $clicktoopen, $mimetype);
92 echo '</div>';
94 $formcontinue = new single_button(new moodle_url('policy.php', array('agree' => 1)), get_string('yes'));
95 $formcancel = new single_button(new moodle_url($CFG->wwwroot.'/login/logout.php', array('agree' => 0)), get_string('no'));
96 echo $OUTPUT->confirm($strpolicyagree, $formcontinue, $formcancel);
98 echo $OUTPUT->footer();