Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

Differences Between: [Versions 310 and 311] [Versions 310 and 400] [Versions 310 and 401] [Versions 310 and 402] [Versions 310 and 403]

   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   * Show a user the policy documents to be agreed to.
  19   *
  20   * Script parameters:
  21   *  listdoc=<array> List of policy version ids that were displayed to the user to accept.
  22   *  statusXX=<int> Acceptance status to be set for the policy version with id XX.
  23   *  behalfid=<id> The user id to view the policy version as (such as child's id).
  24   *
  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
  28   */
  29  
  30  use tool_policy\api;
  31  use tool_policy\output\page_agreedocs;
  32  
  33  // Do not check for the site policies in require_login() to avoid the redirect loop.
  34  define('NO_SITEPOLICY_CHECK', true);
  35  
  36  // @codingStandardsIgnoreLine See the {@link page_agreedocs} for the access control checks.
  37  require(__DIR__.'/../../../config.php');
  38  
  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  $behalfid = optional_param('userid', null, PARAM_INT);
  43  
  44  $agreedocs = [];
  45  $declinedocs = [];
  46  
  47  foreach ($listdocs as $pvid) {
  48      $status = optional_param('status'.$pvid, null, PARAM_INT);
  49      if ($status === 1) {
  50          $agreedocs[] = $pvid;
  51      } else if ($status === 0) {
  52          $declinedocs[] = $pvid;
  53      }
  54  }
  55  
  56  $listdocs = array_values(array_unique($listdocs));
  57  $agreedocs = array_values(array_unique($agreedocs));
  58  $declinedocs = array_values(array_unique($declinedocs));
  59  
  60  $PAGE->set_context(context_system::instance());
  61  $PAGE->set_pagelayout('standard');
  62  $PAGE->set_url('/admin/tool/policy/index.php');
  63  $PAGE->set_popup_notification_allowed(false);
  64  
  65  if (array_diff($agreedocs, $listdocs) || array_diff($declinedocs, $listdocs)) {
  66      throw new moodle_exception('invalidaccessparameter');
  67  }
  68  
  69  if (isloggedin() && !isguestuser()) {
  70      // Existing user.
  71      $haspermissionagreedocs = api::can_accept_policies($listdocs, $behalfid);
  72  } else {
  73      // New user.
  74      $haspermissionagreedocs = true;
  75  }
  76  
  77  if (!$haspermissionagreedocs) {
  78      $outputpage = new \tool_policy\output\page_nopermission($listdocs, $behalfid);
  79  } else if ($cancel) {
  80      redirect(new moodle_url('/'));
  81  } else {
  82      if (!$behalfid && \core\session\manager::is_loggedinas()) {
  83          $behalfid = $USER->id;
  84      }
  85      $outputpage = new \tool_policy\output\page_agreedocs($listdocs, $agreedocs, $declinedocs, $behalfid, $submit);
  86  }
  87  
  88  $output = $PAGE->get_renderer('tool_policy');
  89  
  90  echo $output->header();
  91  echo $output->render($outputpage);
  92  echo $output->footer();