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

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

   1  <?php
   2        // Allows the admin to manage activity modules
   3  
   4      require_once('../config.php');
   5      require_once ('../course/lib.php');
   6      require_once($CFG->libdir.'/adminlib.php');
   7      require_once($CFG->libdir.'/tablelib.php');
   8  
   9      // defines
  10      define('MODULE_TABLE','module_administration_table');
  11  
  12      admin_externalpage_setup('managemodules');
  13  
  14      $show    = optional_param('show', '', PARAM_PLUGIN);
  15      $hide    = optional_param('hide', '', PARAM_PLUGIN);
  16  
  17  
  18  /// Print headings
  19  
  20      $stractivities = get_string("activities");
  21      $struninstall = get_string('uninstallplugin', 'core_admin');
  22      $strversion = get_string("version");
  23      $strhide = get_string("hide");
  24      $strshow = get_string("show");
  25      $strsettings = get_string("settings");
  26      $stractivities = get_string("activities");
  27      $stractivitymodule = get_string("activitymodule");
  28      $strshowmodulecourse = get_string('showmodulecourse');
  29  
  30  /// If data submitted, then process and store.
  31  
  32      if (!empty($hide) and confirm_sesskey()) {
  33          $class = \core_plugin_manager::resolve_plugininfo_class('mod');
  34          if ($class::enable_plugin($hide, false)) {
  35              // Settings not required - only pages.
  36              admin_get_root(true, false);
  37          }
  38          redirect(new moodle_url('/admin/modules.php'));
  39      }
  40  
  41      if (!empty($show) && confirm_sesskey()) {
  42          $class = \core_plugin_manager::resolve_plugininfo_class('mod');
  43          if ($class::enable_plugin($show, true)) {
  44              // Settings not required - only pages.
  45              admin_get_root(true, false);
  46          }
  47          redirect(new moodle_url('/admin/modules.php'));
  48      }
  49  
  50      echo $OUTPUT->header();
  51      echo $OUTPUT->heading($stractivities);
  52  
  53  /// Get and sort the existing modules
  54  
  55      if (!$modules = $DB->get_records('modules', array(), 'name ASC')) {
  56          print_error('moduledoesnotexist', 'error');
  57      }
  58  
  59  /// Print the table of all modules
  60      // construct the flexible table ready to display
  61      $table = new flexible_table(MODULE_TABLE);
  62      $table->define_columns(array('name', 'instances', 'version', 'hideshow', 'uninstall', 'settings'));
  63      $table->define_headers(array($stractivitymodule, $stractivities, $strversion, "$strhide/$strshow", $strsettings, $struninstall));
  64      $table->define_baseurl($CFG->wwwroot.'/'.$CFG->admin.'/modules.php');
  65      $table->set_attribute('id', 'modules');
  66      $table->set_attribute('class', 'admintable generaltable');
  67      $table->setup();
  68  
  69      $pluginmanager = core_plugin_manager::instance();
  70  
  71      foreach ($modules as $module) {
  72          $plugininfo = $pluginmanager->get_plugin_info('mod_'.$module->name);
  73          $status = $plugininfo->get_status();
  74  
  75          if ($status === core_plugin_manager::PLUGIN_STATUS_MISSING) {
  76              $strmodulename = '<span class="notifyproblem">'.$module->name.' ('.get_string('missingfromdisk').')</span>';
  77              $missing = true;
  78          } else {
  79              // took out hspace="\10\", because it does not validate. don't know what to replace with.
  80              $icon = "<img src=\"" . $OUTPUT->image_url('monologo', $module->name) . "\" class=\"icon\" alt=\"\" />";
  81              $strmodulename = $icon.' '.get_string('modulename', $module->name);
  82              $missing = false;
  83          }
  84  
  85          $uninstall = '';
  86          if ($uninstallurl = core_plugin_manager::instance()->get_uninstall_url('mod_'.$module->name, 'manage')) {
  87              $uninstall = html_writer::link($uninstallurl, $struninstall);
  88          }
  89  
  90          if (file_exists("$CFG->dirroot/mod/$module->name/settings.php") ||
  91                  file_exists("$CFG->dirroot/mod/$module->name/settingstree.php")) {
  92              $settings = "<a href=\"settings.php?section=modsetting$module->name\">$strsettings</a>";
  93          } else {
  94              $settings = "";
  95          }
  96  
  97          try {
  98              $count = $DB->count_records_select($module->name, "course<>0");
  99          } catch (dml_exception $e) {
 100              $count = -1;
 101          }
 102          if ($count>0) {
 103              $countlink = $OUTPUT->action_link(new moodle_url('/course/search.php', ['modulelist' => $module->name]),
 104                  $count, null, ['title' => $strshowmodulecourse]);
 105          } else if ($count < 0) {
 106              $countlink = get_string('error');
 107          } else {
 108              $countlink = "$count";
 109          }
 110  
 111          if ($missing) {
 112              $visible = '';
 113              $class   = '';
 114          } else if ($module->visible) {
 115              $visible = "<a href=\"modules.php?hide=$module->name&amp;sesskey=".sesskey()."\" title=\"$strhide\">".
 116                         $OUTPUT->pix_icon('t/hide', $strhide) . '</a>';
 117              $class   = '';
 118          } else {
 119              $visible = "<a href=\"modules.php?show=$module->name&amp;sesskey=".sesskey()."\" title=\"$strshow\">".
 120                         $OUTPUT->pix_icon('t/show', $strshow) . '</a>';
 121              $class =   'dimmed_text';
 122          }
 123          if ($module->name == "forum") {
 124              $uninstall = "";
 125              $visible = "";
 126              $class = "";
 127          }
 128          $version = get_config('mod_'.$module->name, 'version');
 129  
 130          $table->add_data(array(
 131              $strmodulename,
 132              $countlink,
 133              $version,
 134              $visible,
 135              $settings,
 136              $uninstall,
 137          ), $class);
 138      }
 139  
 140      $table->print_html();
 141  
 142      echo $OUTPUT->footer();