Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.
/admin/ -> enrol.php (source)

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

   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   * Enrol config manipulation script.
  19   *
  20   * @package    core
  21   * @subpackage enrol
  22   * @copyright  2010 Petr Skoda {@link http://skodak.org}
  23   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   */
  25  
  26  define('NO_OUTPUT_BUFFERING', true);
  27  
  28  require_once('../config.php');
  29  require_once($CFG->libdir.'/adminlib.php');
  30  
  31  $action  = required_param('action', PARAM_ALPHANUMEXT);
  32  $enrol   = required_param('enrol', PARAM_PLUGIN);
  33  $confirm = optional_param('confirm', 0, PARAM_BOOL);
  34  
  35  $PAGE->set_url('/admin/enrol.php');
  36  $PAGE->set_context(context_system::instance());
  37  
  38  require_admin();
  39  require_sesskey();
  40  
  41  $enabled = enrol_get_plugins(true);
  42  $all     = enrol_get_plugins(false);
  43  
  44  $return = new moodle_url('/admin/settings.php', array('section'=>'manageenrols'));
  45  
  46  switch ($action) {
  47      case 'disable':
  48          $class = \core_plugin_manager::resolve_plugininfo_class('enrol');
  49          $class::enable_plugin($enrol, false);
  50          break;
  51  
  52      case 'enable':
  53          if (!isset($all[$enrol])) {
  54              break;
  55          }
  56          $class = \core_plugin_manager::resolve_plugininfo_class('enrol');
  57          $class::enable_plugin($enrol, true);
  58          break;
  59  
  60      case 'up':
  61          if (!isset($enabled[$enrol])) {
  62              break;
  63          }
  64          $enabled = array_keys($enabled);
  65          $enabled = array_flip($enabled);
  66          $current = $enabled[$enrol];
  67          if ($current == 0) {
  68              break; //already at the top
  69          }
  70          $enabled = array_flip($enabled);
  71          $enabled[$current] = $enabled[$current - 1];
  72          $enabled[$current - 1] = $enrol;
  73          set_config('enrol_plugins_enabled', implode(',', $enabled));
  74          break;
  75  
  76      case 'down':
  77          if (!isset($enabled[$enrol])) {
  78              break;
  79          }
  80          $enabled = array_keys($enabled);
  81          $enabled = array_flip($enabled);
  82          $current = $enabled[$enrol];
  83          if ($current == count($enabled) - 1) {
  84              break; //already at the end
  85          }
  86          $enabled = array_flip($enabled);
  87          $enabled[$current] = $enabled[$current + 1];
  88          $enabled[$current + 1] = $enrol;
  89          set_config('enrol_plugins_enabled', implode(',', $enabled));
  90          break;
  91  
  92      case 'migrate':
  93          if (get_string_manager()->string_exists('pluginname', 'enrol_'.$enrol)) {
  94              $strplugin = get_string('pluginname', 'enrol_'.$enrol);
  95          } else {
  96              $strplugin = $enrol;
  97          }
  98  
  99          $PAGE->set_title($strplugin);
 100          echo $OUTPUT->header();
 101  
 102          // This may take a long time.
 103          core_php_time_limit::raise();
 104  
 105          // Disable plugin to prevent concurrent cron execution.
 106          unset($enabled[$enrol]);
 107          set_config('enrol_plugins_enabled', implode(',', array_keys($enabled)));
 108  
 109          echo $OUTPUT->heading(get_string('uninstallmigrating', 'enrol', 'enrol_'.$enrol));
 110  
 111          require_once("$CFG->dirroot/enrol/manual/locallib.php");
 112          enrol_manual_migrate_plugin_enrolments($enrol);
 113  
 114          echo $OUTPUT->notification(get_string('success'), 'notifysuccess');
 115  
 116          if (!$return = core_plugin_manager::instance()->get_uninstall_url('enrol_'.$enrol, 'manage')) {
 117              $return = new moodle_url('/admin/plugins.php');
 118          }
 119          echo $OUTPUT->continue_button($return);
 120          echo $OUTPUT->footer();
 121          exit;
 122  }
 123  
 124  
 125  redirect($return);