Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.
/user/ -> policy.php (source)
   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.
  13  //
  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/>.
  16  
  17  /**
  18   * This file is part of the User section Moodle
  19   *
  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
  23   */
  24  
  25  // Do not check for the site policies in require_login() to avoid the redirect loop.
  26  define('NO_SITEPOLICY_CHECK', true);
  27  
  28  require_once('../config.php');
  29  require_once($CFG->libdir.'/filelib.php');
  30  require_once($CFG->libdir.'/resourcelib.php');
  31  
  32  $agree = optional_param('agree', 0, PARAM_BOOL);
  33  
  34  $PAGE->set_url('/user/policy.php');
  35  $PAGE->set_popup_notification_allowed(false);
  36  
  37  if (!isloggedin()) {
  38      require_login();
  39  }
  40  
  41  if (!empty($SESSION->wantsurl)) {
  42      $return = $SESSION->wantsurl;
  43  } else {
  44      $return = $CFG->wwwroot.'/';
  45  }
  46  
  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);
  54      }
  55  }
  56  
  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);
  61  }
  62  
  63  if ($agree and confirm_sesskey()) {    // User has agreed.
  64      $sitepolicymanager->accept();
  65      unset($SESSION->wantsurl);
  66      redirect($return);
  67  }
  68  
  69  $strpolicyagree = get_string('policyagree');
  70  $strpolicyagreement = get_string('policyagreement');
  71  $strpolicyagreementclick = get_string('policyagreementclick');
  72  
  73  $PAGE->set_context(context_system::instance());
  74  $PAGE->set_title($strpolicyagreement);
  75  $PAGE->set_heading($SITE->fullname);
  76  $PAGE->navbar->add($strpolicyagreement);
  77  
  78  echo $OUTPUT->header();
  79  echo $OUTPUT->heading($strpolicyagreement);
  80  
  81  $mimetype = mimeinfo('type', $sitepolicy);
  82  if ($mimetype == 'document/unknown') {
  83      // Fallback for missing index.php, index.html.
  84      $mimetype = 'text/html';
  85  }
  86  
  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>';
  89  
  90  echo '<div class="noticebox">';
  91  echo resourcelib_embed_general($sitepolicy, $strpolicyagreement, $clicktoopen, $mimetype);
  92  echo '</div>';
  93  
  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);
  97  
  98  echo $OUTPUT->footer();
  99