Revert "Merge branch 'MDL-45594_m27' of git://github.com/markn86/moodle into MOODLE_2...
[moodle.git] / user / policy.php
blob5186868c20de43a8e04b126c15b9905a2377401a
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 require_once('../config.php');
26 require_once($CFG->libdir.'/filelib.php');
27 require_once($CFG->libdir.'/resourcelib.php');
29 $agree = optional_param('agree', 0, PARAM_BOOL);
31 $PAGE->set_url('/user/policy.php');
32 $PAGE->set_popup_notification_allowed(false);
34 if (!isloggedin()) {
35 require_login();
38 if (isguestuser()) {
39 $sitepolicy = $CFG->sitepolicyguest;
40 } else {
41 $sitepolicy = $CFG->sitepolicy;
44 if (!empty($SESSION->wantsurl)) {
45 $return = $SESSION->wantsurl;
46 } else {
47 $return = $CFG->wwwroot.'/';
50 if (empty($sitepolicy)) {
51 // Nothing to agree to, sorry, hopefully we will not get to infinite loop.
52 redirect($return);
55 if ($agree and confirm_sesskey()) { // User has agreed.
56 if (!isguestuser()) { // Don't remember guests.
57 $DB->set_field('user', 'policyagreed', 1, array('id' => $USER->id));
59 $USER->policyagreed = 1;
60 unset($SESSION->wantsurl);
61 redirect($return);
64 $strpolicyagree = get_string('policyagree');
65 $strpolicyagreement = get_string('policyagreement');
66 $strpolicyagreementclick = get_string('policyagreementclick');
68 $PAGE->set_context(context_system::instance());
69 $PAGE->set_title($strpolicyagreement);
70 $PAGE->set_heading($SITE->fullname);
71 $PAGE->navbar->add($strpolicyagreement);
73 echo $OUTPUT->header();
74 echo $OUTPUT->heading($strpolicyagreement);
76 $mimetype = mimeinfo('type', $sitepolicy);
77 if ($mimetype == 'document/unknown') {
78 // Fallback for missing index.php, index.html.
79 $mimetype = 'text/html';
82 // We can not use our popups here, because the url may be arbitrary, see MDL-9823.
83 $clicktoopen = '<a href="'.$sitepolicy.'" onclick="this.target=\'_blank\'">'.$strpolicyagreementclick.'</a>';
85 echo '<div class="noticebox">';
86 echo resourcelib_embed_general($sitepolicy, $strpolicyagreement, $clicktoopen, $mimetype);
87 echo '</div>';
89 $formcontinue = new single_button(new moodle_url('policy.php', array('agree' => 1)), get_string('yes'));
90 $formcancel = new single_button(new moodle_url($CFG->wwwroot.'/login/logout.php', array('agree' => 0)), get_string('no'));
91 echo $OUTPUT->confirm($strpolicyagree, $formcontinue, $formcancel);
93 echo $OUTPUT->footer();