Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 310 and 401] [Versions 311 and 401] [Versions 39 and 401] [Versions 400 and 401]

   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   * Accept or revoke policies on behalf of users (non-JS version)
  19   *
  20   * @package     tool_policy
  21   * @copyright   2018 Marina Glancy
  22   * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  require(__DIR__.'/../../../config.php');
  26  require_once($CFG->dirroot.'/user/editlib.php');
  27  
  28  $userids = optional_param_array('userids', null, PARAM_INT);
  29  $versionids = optional_param_array('versionids', null, PARAM_INT);
  30  $returnurl = optional_param('returnurl', null, PARAM_LOCALURL);
  31  $action = optional_param('action', null, PARAM_ALPHA);
  32  
  33  require_login();
  34  if (isguestuser()) {
  35      throw new \moodle_exception('noguest');
  36  }
  37  $context = context_system::instance();
  38  
  39  $PAGE->set_context($context);
  40  $PAGE->set_url(new moodle_url('/admin/tool/policy/accept.php'));
  41  
  42  if (!in_array($action, ['accept', 'decline', 'revoke'])) {
  43      throw new moodle_exception('invalidaccessparameter');
  44  }
  45  
  46  if ($returnurl) {
  47      $returnurl = new moodle_url($returnurl);
  48  } else if (count($userids) == 1) {
  49      $userid = reset($userids);
  50      $returnurl = new moodle_url('/admin/tool/policy/user.php', ['userid' => $userid]);
  51  } else {
  52      $returnurl = new moodle_url('/admin/tool/policy/acceptances.php');
  53  }
  54  // Initialise the form, this will also validate users, versions and check permission to accept policies.
  55  $form = new \tool_policy\form\accept_policy(null,
  56      ['versionids' => $versionids, 'userids' => $userids, 'showbuttons' => true, 'action' => $action]);
  57  $form->set_data(['returnurl' => $returnurl]);
  58  
  59  if ($form->is_cancelled()) {
  60      redirect($returnurl);
  61  } else if ($form->get_data()) {
  62      $form->process();
  63      redirect($returnurl);
  64  }
  65  
  66  $output = $PAGE->get_renderer('tool_policy');
  67  echo $output->header();
  68  echo $output->heading(get_string('statusformtitle'.$action, 'tool_policy'));
  69  $form->display();
  70  echo $output->footer();