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.
/admin/ -> enrol.php (source)

Differences Between: [Versions 311 and 400] [Versions 311 and 401] [Versions 311 and 402] [Versions 311 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   * 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  $syscontext = context_system::instance();
  47  
  48  switch ($action) {
  49      case 'disable':
  50          unset($enabled[$enrol]);
  51          set_config('enrol_plugins_enabled', implode(',', array_keys($enabled)));
  52          core_plugin_manager::reset_caches();
  53          $syscontext->mark_dirty(); // resets all enrol caches
  54          break;
  55  
  56      case 'enable':
  57          if (!isset($all[$enrol])) {
  58              break;
  59          }
  60          $enabled = array_keys($enabled);
  61          $enabled[] = $enrol;
  62          set_config('enrol_plugins_enabled', implode(',', $enabled));
  63          core_plugin_manager::reset_caches();
  64          $syscontext->mark_dirty(); // resets all enrol caches
  65          break;
  66  
  67      case 'up':
  68          if (!isset($enabled[$enrol])) {
  69              break;
  70          }
  71          $enabled = array_keys($enabled);
  72          $enabled = array_flip($enabled);
  73          $current = $enabled[$enrol];
  74          if ($current == 0) {
  75              break; //already at the top
  76          }
  77          $enabled = array_flip($enabled);
  78          $enabled[$current] = $enabled[$current - 1];
  79          $enabled[$current - 1] = $enrol;
  80          set_config('enrol_plugins_enabled', implode(',', $enabled));
  81          break;
  82  
  83      case 'down':
  84          if (!isset($enabled[$enrol])) {
  85              break;
  86          }
  87          $enabled = array_keys($enabled);
  88          $enabled = array_flip($enabled);
  89          $current = $enabled[$enrol];
  90          if ($current == count($enabled) - 1) {
  91              break; //already at the end
  92          }
  93          $enabled = array_flip($enabled);
  94          $enabled[$current] = $enabled[$current + 1];
  95          $enabled[$current + 1] = $enrol;
  96          set_config('enrol_plugins_enabled', implode(',', $enabled));
  97          break;
  98  
  99      case 'migrate':
 100          if (get_string_manager()->string_exists('pluginname', 'enrol_'.$enrol)) {
 101              $strplugin = get_string('pluginname', 'enrol_'.$enrol);
 102          } else {
 103              $strplugin = $enrol;
 104          }
 105  
 106          $PAGE->set_title($strplugin);
 107          echo $OUTPUT->header();
 108  
 109          // This may take a long time.
 110          core_php_time_limit::raise();
 111  
 112          // Disable plugin to prevent concurrent cron execution.
 113          unset($enabled[$enrol]);
 114          set_config('enrol_plugins_enabled', implode(',', array_keys($enabled)));
 115  
 116          echo $OUTPUT->heading(get_string('uninstallmigrating', 'enrol', 'enrol_'.$enrol));
 117  
 118          require_once("$CFG->dirroot/enrol/manual/locallib.php");
 119          enrol_manual_migrate_plugin_enrolments($enrol);
 120  
 121          echo $OUTPUT->notification(get_string('success'), 'notifysuccess');
 122  
 123          if (!$return = core_plugin_manager::instance()->get_uninstall_url('enrol_'.$enrol, 'manage')) {
 124              $return = new moodle_url('/admin/plugins.php');
 125          }
 126          echo $OUTPUT->continue_button($return);
 127          echo $OUTPUT->footer();
 128          exit;
 129  }
 130  
 131  
 132  redirect($return);