| [ Index ] |
PHP Cross Reference of Moodle 1.9.3 [Build 15-Oct-2008] |
[Summary view] [Print] [Text view]
1 <?PHP // $Id: modules.php,v 1.44.2.7 2008/04/30 13:08:46 skodak Exp $ 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 require_once($CFG->libdir.'/ddllib.php'); 9 10 // defines 11 define('MODULE_TABLE','module_administration_table'); 12 13 admin_externalpage_setup('managemodules'); 14 15 $show = optional_param('show', '', PARAM_SAFEDIR); 16 $hide = optional_param('hide', '', PARAM_SAFEDIR); 17 $delete = optional_param('delete', '', PARAM_SAFEDIR); 18 $confirm = optional_param('confirm', '', PARAM_BOOL); 19 20 21 /// Print headings 22 23 $stractivities = get_string("activities"); 24 $strdelete = get_string("delete"); 25 $strversion = get_string("version"); 26 $strhide = get_string("hide"); 27 $strshow = get_string("show"); 28 $strsettings = get_string("settings"); 29 $stractivities = get_string("activities"); 30 $stractivitymodule = get_string("activitymodule"); 31 $strshowmodulecourse = get_string('showmodulecourse'); 32 33 /// If data submitted, then process and store. 34 35 if (!empty($hide) and confirm_sesskey()) { 36 if (!$module = get_record("modules", "name", $hide)) { 37 error("Module doesn't exist!"); 38 } 39 set_field("modules", "visible", "0", "id", $module->id); // Hide main module 40 // Remember the visibility status in visibleold 41 // and hide... 42 $sql = "UPDATE {$CFG->prefix}course_modules 43 SET visibleold=visible, 44 visible=0 45 WHERE module={$module->id}"; 46 execute_sql($sql, false); 47 // clear the course modinfo cache for courses 48 // where we just deleted something 49 $sql = "UPDATE {$CFG->prefix}course 50 SET modinfo='' 51 WHERE id IN (SELECT DISTINCT course 52 FROM {$CFG->prefix}course_modules 53 WHERE visibleold=1 AND module={$module->id})"; 54 execute_sql($sql, false); 55 admin_get_root(true, false); // settings not required - only pages 56 } 57 58 if (!empty($show) and confirm_sesskey()) { 59 if (!$module = get_record("modules", "name", $show)) { 60 error("Module doesn't exist!"); 61 } 62 set_field("modules", "visible", "1", "id", $module->id); // Show main module 63 set_field('course_modules', 'visible', '1', 'visibleold', 64 '1', 'module', $module->id); // Get the previous saved visible state for the course module. 65 // clear the course modinfo cache for courses 66 // where we just made something visible 67 $sql = "UPDATE {$CFG->prefix}course 68 SET modinfo='' 69 WHERE id IN (SELECT DISTINCT course 70 FROM {$CFG->prefix}course_modules 71 WHERE visible=1 AND module={$module->id})"; 72 execute_sql($sql, false); 73 admin_get_root(true, false); // settings not required - only pages 74 } 75 76 if (!empty($delete) and confirm_sesskey()) { 77 admin_externalpage_print_header(); 78 print_heading($stractivities); 79 80 $strmodulename = get_string("modulename", "$delete"); 81 82 if (!$confirm) { 83 notice_yesno(get_string("moduledeleteconfirm", "", $strmodulename), 84 "modules.php?delete=$delete&confirm=1&sesskey=$USER->sesskey", 85 "modules.php"); 86 admin_externalpage_print_footer(); 87 exit; 88 89 } else { // Delete everything!! 90 91 if ($delete == "forum") { 92 error("You can not delete the forum module!!"); 93 } 94 95 if (!$module = get_record("modules", "name", $delete)) { 96 error("Module doesn't exist!"); 97 } 98 99 // OK, first delete all the relevant instances from all course sections 100 if ($coursemods = get_records("course_modules", "module", $module->id)) { 101 foreach ($coursemods as $coursemod) { 102 if (! delete_mod_from_section($coursemod->id, $coursemod->section)) { 103 notify("Could not delete the $strmodulename with id = $coursemod->id from section $coursemod->section"); 104 } 105 } 106 } 107 108 // delete calendar events 109 if (!delete_records("event", "modulename", $delete)) { 110 notify("Error occurred while deleting all $strmodulename records in calendar event table"); 111 } 112 113 // clear course.modinfo for courses 114 // that used this module... 115 $sql = "UPDATE {$CFG->prefix}course 116 SET modinfo='' 117 WHERE id IN (SELECT DISTINCT course 118 FROM {$CFG->prefix}course_modules 119 WHERE module={$module->id})"; 120 execute_sql($sql, false); 121 122 // Now delete all the course module records 123 if (!delete_records("course_modules", "module", $module->id)) { 124 notify("Error occurred while deleting all $strmodulename records in course_modules table"); 125 } 126 127 // Then delete all the logs 128 if (!delete_records("log", "module", $module->name)) { 129 notify("Error occurred while deleting all $strmodulename records in log table"); 130 } 131 132 // And log_display information 133 if (!delete_records("log_display", "module", $module->name)) { 134 notify("Error occurred while deleting all $strmodulename records in log_display table"); 135 } 136 137 // And the module entry itself 138 if (!delete_records("modules", "name", $module->name)) { 139 notify("Error occurred while deleting the $strmodulename record from modules table"); 140 } 141 142 // And the module configuration records 143 if (!execute_sql("DELETE FROM {$CFG->prefix}config WHERE name LIKE '{$module->name}_%'")) { 144 notify("Error occurred while deleting the $strmodulename records from the config table"); 145 } 146 147 // cleanup the gradebook 148 require_once($CFG->libdir.'/gradelib.php'); 149 grade_uninstalled_module($module->name); 150 151 // Then the tables themselves 152 drop_plugin_tables($module->name, "$CFG->dirroot/mod/$module->name/db/install.xml", false); 153 154 // Delete the capabilities that were defined by this module 155 capabilities_cleanup('mod/'.$module->name); 156 157 // remove entent handlers and dequeue pending events 158 events_uninstall('mod/'.$module->name); 159 160 // Perform any custom uninstall tasks 161 if (file_exists($CFG->dirroot . '/mod/' . $module->name . '/lib.php')) { 162 require_once($CFG->dirroot . '/mod/' . $module->name . '/lib.php'); 163 $uninstallfunction = $module->name . '_uninstall'; 164 if (function_exists($uninstallfunction)) { 165 if (! $uninstallfunction() ) { 166 notify('Encountered a problem running uninstall function for '. $module->name.'!'); 167 } 168 } 169 } 170 171 $a->module = $strmodulename; 172 $a->directory = "$CFG->dirroot/mod/$delete"; 173 notice(get_string("moduledeletefiles", "", $a), "modules.php"); 174 } 175 } 176 177 admin_externalpage_print_header(); 178 print_heading($stractivities); 179 180 /// Get and sort the existing modules 181 182 if (!$modules = get_records("modules")) { 183 error("No modules found!!"); // Should never happen 184 } 185 186 foreach ($modules as $module) { 187 $strmodulename = get_string("modulename", "$module->name"); 188 // Deal with modules which are lacking the language string 189 if ($strmodulename == '[[modulename]]') { 190 $strmodulename = $module->name; 191 } 192 $modulebyname[$strmodulename] = $module; 193 } 194 ksort($modulebyname, SORT_LOCALE_STRING); 195 196 /// Print the table of all modules 197 // construct the flexible table ready to display 198 $table = new flexible_table(MODULE_TABLE); 199 $table->define_columns(array('name', 'instances', 'version', 'hideshow', 'delete', 'settings')); 200 $table->define_headers(array($stractivitymodule, $stractivities, $strversion, "$strhide/$strshow", $strdelete, $strsettings)); 201 $table->define_baseurl($CFG->wwwroot.'/'.$CFG->admin.'/modules.php'); 202 $table->set_attribute('id', 'modules'); 203 $table->set_attribute('class', 'generaltable generalbox boxaligncenter boxwidthwide'); 204 $table->setup(); 205 206 foreach ($modulebyname as $modulename => $module) { 207 208 // took out hspace="\10\", because it does not validate. don't know what to replace with. 209 $icon = "<img src=\"$CFG->modpixpath/$module->name/icon.gif\" class=\"icon\" alt=\"\" />"; 210 211 $delete = "<a href=\"modules.php?delete=$module->name&sesskey=$USER->sesskey\">$strdelete</a>"; 212 213 if (file_exists("$CFG->dirroot/mod/$module->name/settings.php")) { 214 $settings = "<a href=\"settings.php?section=modsetting$module->name\">$strsettings</a>"; 215 } else if (file_exists("$CFG->dirroot/mod/$module->name/config.html")) { 216 $settings = "<a href=\"module.php?module=$module->name\">$strsettings</a>"; 217 } else { 218 $settings = ""; 219 } 220 221 $count = count_records_select("$module->name",'course<>0'); 222 if ($count>0) { 223 $countlink = "<a href=\"{$CFG->wwwroot}/course/search.php?modulelist=$module->name" . 224 "&sesskey={$USER->sesskey}\" title=\"$strshowmodulecourse\">$count</a>"; 225 } 226 else { 227 $countlink = "$count"; 228 } 229 230 if ($module->visible) { 231 $visible = "<a href=\"modules.php?hide=$module->name&sesskey=$USER->sesskey\" title=\"$strhide\">". 232 "<img src=\"$CFG->pixpath/i/hide.gif\" class=\"icon\" alt=\"$strhide\" /></a>"; 233 $class = ""; 234 } else { 235 $visible = "<a href=\"modules.php?show=$module->name&sesskey=$USER->sesskey\" title=\"$strshow\">". 236 "<img src=\"$CFG->pixpath/i/show.gif\" class=\"icon\" alt=\"$strshow\" /></a>"; 237 $class = " class=\"dimmed_text\""; 238 } 239 if ($module->name == "forum") { 240 $delete = ""; 241 $visible = ""; 242 $class = ""; 243 } 244 245 $extra = ''; 246 if (!file_exists("$CFG->dirroot/mod/$module->name/lib.php")) { 247 $extra = ' <span class="notifyproblem">('.get_string('missingfromdisk').')</span>'; 248 } 249 250 $table->add_data(array( 251 '<span'.$class.'>'.$icon.' '.$modulename.$extra.'</span>', 252 $countlink, 253 '<span'.$class.'>'.$module->version.'</span>', 254 $visible, 255 $delete, 256 $settings 257 )); 258 } 259 260 $table->print_html(); 261 262 admin_externalpage_print_footer(); 263 264 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Wed Jan 14 11:33:29 2009 | Cross-referenced by PHPXref 0.7 |