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

Differences Between: [Versions 311 and 400] [Versions 311 and 401] [Versions 311 and 402] [Versions 311 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          if (!$module = $DB->get_record("modules", array("name"=>$hide))) {
  34              print_error('moduledoesnotexist', 'error');
  35          }
  36          $DB->set_field("modules", "visible", "0", array("id"=>$module->id)); // Hide main module
  37          // Remember the visibility status in visibleold
  38          // and hide...
  39          $sql = "UPDATE {course_modules}
  40                     SET visibleold=visible, visible=0
  41                   WHERE module=?";
  42          $DB->execute($sql, array($module->id));
  43          // Increment course.cacherev for courses where we just made something invisible.
  44          // This will force cache rebuilding on the next request.
  45          increment_revision_number('course', 'cacherev',
  46                  "id IN (SELECT DISTINCT course
  47                                  FROM {course_modules}
  48                                 WHERE visibleold=1 AND module=?)",
  49                  array($module->id));
  50          core_plugin_manager::reset_caches();
  51          admin_get_root(true, false);  // settings not required - only pages
  52          redirect(new moodle_url('/admin/modules.php'));
  53      }
  54  
  55      if (!empty($show) and confirm_sesskey()) {
  56          if (!$module = $DB->get_record("modules", array("name"=>$show))) {
  57              print_error('moduledoesnotexist', 'error');
  58          }
  59          $DB->set_field("modules", "visible", "1", array("id"=>$module->id)); // Show main module
  60          $DB->set_field('course_modules', 'visible', '1', array('visibleold'=>1, 'module'=>$module->id)); // Get the previous saved visible state for the course module.
  61          // Increment course.cacherev for courses where we just made something visible.
  62          // This will force cache rebuilding on the next request.
  63          increment_revision_number('course', 'cacherev',
  64                  "id IN (SELECT DISTINCT course
  65                                  FROM {course_modules}
  66                                 WHERE visible=1 AND module=?)",
  67                  array($module->id));
  68          core_plugin_manager::reset_caches();
  69          admin_get_root(true, false);  // settings not required - only pages
  70          redirect(new moodle_url('/admin/modules.php'));
  71      }
  72  
  73      echo $OUTPUT->header();
  74      echo $OUTPUT->heading($stractivities);
  75  
  76  /// Get and sort the existing modules
  77  
  78      if (!$modules = $DB->get_records('modules', array(), 'name ASC')) {
  79          print_error('moduledoesnotexist', 'error');
  80      }
  81  
  82  /// Print the table of all modules
  83      // construct the flexible table ready to display
  84      $table = new flexible_table(MODULE_TABLE);
  85      $table->define_columns(array('name', 'instances', 'version', 'hideshow', 'uninstall', 'settings'));
  86      $table->define_headers(array($stractivitymodule, $stractivities, $strversion, "$strhide/$strshow", $strsettings, $struninstall));
  87      $table->define_baseurl($CFG->wwwroot.'/'.$CFG->admin.'/modules.php');
  88      $table->set_attribute('id', 'modules');
  89      $table->set_attribute('class', 'admintable generaltable');
  90      $table->setup();
  91  
  92      $pluginmanager = core_plugin_manager::instance();
  93  
  94      foreach ($modules as $module) {
  95          $plugininfo = $pluginmanager->get_plugin_info('mod_'.$module->name);
  96          $status = $plugininfo->get_status();
  97  
  98          if ($status === core_plugin_manager::PLUGIN_STATUS_MISSING) {
  99              $strmodulename = '<span class="notifyproblem">'.$module->name.' ('.get_string('missingfromdisk').')</span>';
 100              $missing = true;
 101          } else {
 102              // took out hspace="\10\", because it does not validate. don't know what to replace with.
 103              $icon = "<img src=\"" . $OUTPUT->image_url('icon', $module->name) . "\" class=\"icon\" alt=\"\" />";
 104              $strmodulename = $icon.' '.get_string('modulename', $module->name);
 105              $missing = false;
 106          }
 107  
 108          $uninstall = '';
 109          if ($uninstallurl = core_plugin_manager::instance()->get_uninstall_url('mod_'.$module->name, 'manage')) {
 110              $uninstall = html_writer::link($uninstallurl, $struninstall);
 111          }
 112  
 113          if (file_exists("$CFG->dirroot/mod/$module->name/settings.php") ||
 114                  file_exists("$CFG->dirroot/mod/$module->name/settingstree.php")) {
 115              $settings = "<a href=\"settings.php?section=modsetting$module->name\">$strsettings</a>";
 116          } else {
 117              $settings = "";
 118          }
 119  
 120          try {
 121              $count = $DB->count_records_select($module->name, "course<>0");
 122          } catch (dml_exception $e) {
 123              $count = -1;
 124          }
 125          if ($count>0) {
 126              $countlink = $OUTPUT->action_link(new moodle_url('/course/search.php', ['modulelist' => $module->name]),
 127                  $count, null, ['title' => $strshowmodulecourse]);
 128          } else if ($count < 0) {
 129              $countlink = get_string('error');
 130          } else {
 131              $countlink = "$count";
 132          }
 133  
 134          if ($missing) {
 135              $visible = '';
 136              $class   = '';
 137          } else if ($module->visible) {
 138              $visible = "<a href=\"modules.php?hide=$module->name&amp;sesskey=".sesskey()."\" title=\"$strhide\">".
 139                         $OUTPUT->pix_icon('t/hide', $strhide) . '</a>';
 140              $class   = '';
 141          } else {
 142              $visible = "<a href=\"modules.php?show=$module->name&amp;sesskey=".sesskey()."\" title=\"$strshow\">".
 143                         $OUTPUT->pix_icon('t/show', $strshow) . '</a>';
 144              $class =   'dimmed_text';
 145          }
 146          if ($module->name == "forum") {
 147              $uninstall = "";
 148              $visible = "";
 149              $class = "";
 150          }
 151          $version = get_config('mod_'.$module->name, 'version');
 152  
 153          $table->add_data(array(
 154              $strmodulename,
 155              $countlink,
 156              $version,
 157              $visible,
 158              $settings,
 159              $uninstall,
 160          ), $class);
 161      }
 162  
 163      $table->print_html();
 164  
 165      echo $OUTPUT->footer();
 166  
 167