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

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

   1  <?php
   2  
   3  /**
   4   * Allows admin to edit all auth plugin settings.
   5   *
   6   * JH: copied and Hax0rd from admin/enrol.php and admin/filters.php
   7   *
   8   */
   9  
  10  require_once('../config.php');
  11  require_once($CFG->libdir.'/adminlib.php');
  12  require_once($CFG->libdir.'/tablelib.php');
  13  
  14  require_admin();
  15  
  16  $returnurl = new moodle_url('/admin/settings.php', array('section'=>'manageauths'));
  17  
  18  $PAGE->set_url($returnurl);
  19  
  20  $action = optional_param('action', '', PARAM_ALPHANUMEXT);
  21  $auth   = optional_param('auth', '', PARAM_PLUGIN);
  22  
  23  get_enabled_auth_plugins(true); // fix the list of enabled auths
  24  if (empty($CFG->auth)) {
  25      $authsenabled = array();
  26  } else {
  27      $authsenabled = explode(',', $CFG->auth);
  28  }
  29  
  30  if (!empty($auth) and !exists_auth_plugin($auth)) {
  31      throw new \moodle_exception('pluginnotinstalled', 'auth', $returnurl, $auth);
  32  }
  33  
  34  ////////////////////////////////////////////////////////////////////////////////
  35  // process actions
  36  
  37  if (!confirm_sesskey()) {
  38      redirect($returnurl);
  39  }
  40  
  41  switch ($action) {
  42      case 'disable':
  43          // Remove from enabled list.
  44          $class = \core_plugin_manager::resolve_plugininfo_class('auth');
  45          $class::enable_plugin($auth, false);
  46          break;
  47  
  48      case 'enable':
  49          // Add to enabled list.
  50          $class = \core_plugin_manager::resolve_plugininfo_class('auth');
  51          $class::enable_plugin($auth, true);
  52          break;
  53  
  54      case 'down':
  55          $key = array_search($auth, $authsenabled);
  56          // check auth plugin is valid
  57          if ($key === false) {
  58              throw new \moodle_exception('pluginnotenabled', 'auth', $returnurl, $auth);
  59          }
  60          // move down the list
  61          if ($key < (count($authsenabled) - 1)) {
  62              $fsave = $authsenabled[$key];
  63              $authsenabled[$key] = $authsenabled[$key + 1];
  64              $authsenabled[$key + 1] = $fsave;
  65              $value = implode(',', $authsenabled);
  66              add_to_config_log('auth', $CFG->auth, $value, 'core');
  67              set_config('auth', $value);
  68          }
  69          break;
  70  
  71      case 'up':
  72          $key = array_search($auth, $authsenabled);
  73          // check auth is valid
  74          if ($key === false) {
  75              throw new \moodle_exception('pluginnotenabled', 'auth', $returnurl, $auth);
  76          }
  77          // move up the list
  78          if ($key >= 1) {
  79              $fsave = $authsenabled[$key];
  80              $authsenabled[$key] = $authsenabled[$key - 1];
  81              $authsenabled[$key - 1] = $fsave;
  82              $value = implode(',', $authsenabled);
  83              add_to_config_log('auth', $CFG->auth, $value, 'core');
  84              set_config('auth', $value);
  85          }
  86          break;
  87  
  88      default:
  89          break;
  90  }
  91  
  92  redirect($returnurl);