Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/admin/modules.php
Go to the documentation of this file.
00001 <?php
00002       // Allows the admin to manage activity modules
00003 
00004     require_once('../config.php');
00005     require_once('../course/lib.php');
00006     require_once($CFG->libdir.'/adminlib.php');
00007     require_once($CFG->libdir.'/tablelib.php');
00008 
00009     // defines
00010     define('MODULE_TABLE','module_administration_table');
00011 
00012     admin_externalpage_setup('managemodules');
00013 
00014     $show    = optional_param('show', '', PARAM_PLUGIN);
00015     $hide    = optional_param('hide', '', PARAM_PLUGIN);
00016     $delete  = optional_param('delete', '', PARAM_PLUGIN);
00017     $confirm = optional_param('confirm', '', PARAM_BOOL);
00018 
00019 
00021 
00022     $stractivities = get_string("activities");
00023     $strdelete = get_string("delete");
00024     $strversion = get_string("version");
00025     $strhide = get_string("hide");
00026     $strshow = get_string("show");
00027     $strsettings = get_string("settings");
00028     $stractivities = get_string("activities");
00029     $stractivitymodule = get_string("activitymodule");
00030     $strshowmodulecourse = get_string('showmodulecourse');
00031 
00033 
00034     if (!empty($hide) and confirm_sesskey()) {
00035         if (!$module = $DB->get_record("modules", array("name"=>$hide))) {
00036             print_error('moduledoesnotexist', 'error');
00037         }
00038         $DB->set_field("modules", "visible", "0", array("id"=>$module->id)); // Hide main module
00039         // Remember the visibility status in visibleold
00040         // and hide...
00041         $sql = "UPDATE {course_modules}
00042                    SET visibleold=visible, visible=0
00043                  WHERE module=?";
00044         $DB->execute($sql, array($module->id));
00045         // clear the course modinfo cache for courses
00046         // where we just deleted something
00047         $sql = "UPDATE {course}
00048                    SET modinfo=''
00049                  WHERE id IN (SELECT DISTINCT course
00050                                 FROM {course_modules}
00051                                WHERE visibleold=1 AND module=?)";
00052         $DB->execute($sql, array($module->id));
00053         admin_get_root(true, false);  // settings not required - only pages
00054     }
00055 
00056     if (!empty($show) and confirm_sesskey()) {
00057         if (!$module = $DB->get_record("modules", array("name"=>$show))) {
00058             print_error('moduledoesnotexist', 'error');
00059         }
00060         $DB->set_field("modules", "visible", "1", array("id"=>$module->id)); // Show main module
00061         $DB->set_field('course_modules', 'visible', '1', array('visibleold'=>1, 'module'=>$module->id)); // Get the previous saved visible state for the course module.
00062         // clear the course modinfo cache for courses
00063         // where we just made something visible
00064         $sql = "UPDATE {course}
00065                    SET modinfo = ''
00066                  WHERE id IN (SELECT DISTINCT course
00067                                 FROM {course_modules}
00068                                WHERE visible=1 AND module=?)";
00069         $DB->execute($sql, array($module->id));
00070         admin_get_root(true, false);  // settings not required - only pages
00071     }
00072 
00073     if (!empty($delete) and confirm_sesskey()) {
00074         echo $OUTPUT->header();
00075         echo $OUTPUT->heading($stractivities);
00076 
00077         if (get_string_manager()->string_exists('modulename', $delete)) {
00078             $strmodulename = get_string('modulename', $delete);
00079         } else {
00080             $strmodulename = $delete;
00081         }
00082 
00083         if (!$confirm) {
00084             echo $OUTPUT->confirm(get_string("moduledeleteconfirm", "", $strmodulename), "modules.php?delete=$delete&confirm=1", "modules.php");
00085             echo $OUTPUT->footer();
00086             exit;
00087 
00088         } else {  // Delete everything!!
00089 
00090             if ($delete == "forum") {
00091                 print_error("cannotdeleteforummodule", 'forum');
00092             }
00093 
00094             uninstall_plugin('mod', $delete);
00095             $a = new stdClass();
00096             $a->module = $strmodulename;
00097             $a->directory = "$CFG->dirroot/mod/$delete";
00098             echo $OUTPUT->notification(get_string("moduledeletefiles", "", $a), 'notifysuccess');
00099             echo $OUTPUT->continue_button("modules.php");
00100             echo $OUTPUT->footer();
00101             exit;
00102         }
00103     }
00104 
00105     echo $OUTPUT->header();
00106     echo $OUTPUT->heading($stractivities);
00107 
00109 
00110     if (!$modules = $DB->get_records('modules', array(), 'name ASC')) {
00111         print_error('moduledoesnotexist', 'error');
00112     }
00113 
00115     // construct the flexible table ready to display
00116     $table = new flexible_table(MODULE_TABLE);
00117     $table->define_columns(array('name', 'instances', 'version', 'hideshow', 'delete', 'settings'));
00118     $table->define_headers(array($stractivitymodule, $stractivities, $strversion, "$strhide/$strshow", $strdelete, $strsettings));
00119     $table->define_baseurl($CFG->wwwroot.'/'.$CFG->admin.'/modules.php');
00120     $table->set_attribute('id', 'modules');
00121     $table->set_attribute('class', 'generaltable');
00122     $table->setup();
00123 
00124     foreach ($modules as $module) {
00125 
00126         if (!file_exists("$CFG->dirroot/mod/$module->name/lib.php")) {
00127             $strmodulename = '<span class="notifyproblem">'.$module->name.' ('.get_string('missingfromdisk').')</span>';
00128             $missing = true;
00129         } else {
00130             // took out hspace="\10\", because it does not validate. don't know what to replace with.
00131             $icon = "<img src=\"" . $OUTPUT->pix_url('icon', $module->name) . "\" class=\"icon\" alt=\"\" />";
00132             $strmodulename = $icon.' '.get_string('modulename', $module->name);
00133             $missing = false;
00134         }
00135 
00136         $delete = "<a href=\"modules.php?delete=$module->name&amp;sesskey=".sesskey()."\">$strdelete</a>";
00137 
00138         if (file_exists("$CFG->dirroot/mod/$module->name/settings.php") ||
00139                 file_exists("$CFG->dirroot/mod/$module->name/settingstree.php")) {
00140             $settings = "<a href=\"settings.php?section=modsetting$module->name\">$strsettings</a>";
00141         } else {
00142             $settings = "";
00143         }
00144 
00145         try {
00146             $count = $DB->count_records_select($module->name, "course<>0");
00147         } catch (dml_exception $e) {
00148             $count = -1;
00149         }
00150         if ($count>0) {
00151             $countlink = "<a href=\"{$CFG->wwwroot}/course/search.php?modulelist=$module->name" .
00152                 "&amp;sesskey=".sesskey()."\" title=\"$strshowmodulecourse\">$count</a>";
00153         } else if ($count < 0) {
00154             $countlink = get_string('error');
00155         } else {
00156             $countlink = "$count";
00157         }
00158 
00159         if ($missing) {
00160             $visible = '';
00161             $class   = '';
00162         } else if ($module->visible) {
00163             $visible = "<a href=\"modules.php?hide=$module->name&amp;sesskey=".sesskey()."\" title=\"$strhide\">".
00164                        "<img src=\"" . $OUTPUT->pix_url('i/hide') . "\" class=\"icon\" alt=\"$strhide\" /></a>";
00165             $class   = '';
00166         } else {
00167             $visible = "<a href=\"modules.php?show=$module->name&amp;sesskey=".sesskey()."\" title=\"$strshow\">".
00168                        "<img src=\"" . $OUTPUT->pix_url('i/show') . "\" class=\"icon\" alt=\"$strshow\" /></a>";
00169             $class =   ' class="dimmed_text"';
00170         }
00171         if ($module->name == "forum") {
00172             $delete = "";
00173             $visible = "";
00174             $class = "";
00175         }
00176 
00177 
00178         $table->add_data(array(
00179             '<span'.$class.'>'.$strmodulename.'</span>',
00180             $countlink,
00181             '<span'.$class.'>'.$module->version.'</span>',
00182             $visible,
00183             $delete,
00184             $settings
00185         ));
00186     }
00187 
00188     $table->print_html();
00189 
00190     echo $OUTPUT->footer();
00191 
00192 
 All Data Structures Namespaces Files Functions Variables Enumerations