// Find and check all modules and load them up or upgrade them if necessary
- $dir = opendir("$CFG->dirroot/mod");
- while ($mod = readdir($dir)) {
- if ($mod == "." || $mod == ".." || $mod == "CVS") {
- continue;
- }
+ if (!$mods = get_list_of_modules() ) {
+ error("No modules installed!");
+ }
+
+ foreach ($mods as $mod) {
$fullmod = "$CFG->dirroot/mod/$mod";
- if (filetype($fullmod) != "dir") {
- continue;
- }
unset($module);
- include_once("$CFG->dirroot/mod/$mod/version.php"); # defines $module with version etc
+ include_once("$fullmod/version.php"); # defines $module with version etc
if (!isset($module)) {
continue;
redirect("$CFG->wwwroot/admin/");
}
- if (isset($USER->id)) {
+ if (isadmin()) {
+ if (moodle_needs_upgrading()) {
+ redirect("$CFG->wwwroot/admin/");
+ }
$headerbutton = update_course_icon($site->id);
} else {
$headerbutton = "<FONT SIZE=2><A HREF=\"login/\">".get_string("login")."</A></FONT>";
}
function generate_password($maxlen=10) {
-/* returns a randomly generated password of length $maxlen. inspired by
- * http://www.phpbuilder.com/columns/jesus19990502.php3 */
+// returns a randomly generated password of length $maxlen. inspired by
+// http://www.phpbuilder.com/columns/jesus19990502.php3
global $CFG;
return substr($word1 . $filler1 . $word2, 0, $maxlen);
}
+function moodle_needs_upgrading() {
+// Checks version numbers of Main code and all modules to see
+// if there are any mismatches ... returns true or false
+ global $CFG;
+
+ include_once("$CFG->dirroot/version.php"); # defines $version and upgrades
+ if ($dversion = get_field("config", "value", "name", "version")) {
+ if ($version > $dversion) {
+ return true;
+ }
+ if ($mods = get_list_of_modules()) {
+ foreach ($mods as $mod) {
+ $fullmod = "$CFG->dirroot/mod/$mod";
+ unset($module);
+ include_once("$fullmod/version.php"); # defines $module with version etc
+ if ($currmodule = get_record("modules", "name", $mod)) {
+ if ($module->version > $currmodule->version) {
+ return true;
+ }
+ }
+ }
+ }
+ } else {
+ return true;
+ }
+ return false;
+
+
+}
+
+
+function get_list_of_modules() {
+ global $CFG;
+
+ $dir = opendir("$CFG->dirroot/mod");
+ while ($mod = readdir($dir)) {
+ if ($mod == "." || $mod == ".." || $mod == "CVS") {
+ continue;
+ }
+ if (filetype("$CFG->dirroot/mod/$mod") != "dir") {
+ continue;
+ }
+ $mods[] = $mod;
+ }
+ return $mods;
+}
+
?>
// This fragment is called by /admin/index.php
////////////////////////////////////////////////////////////////////////////////
-$module->version = 2002080500;
+$module->version = 2002080503;
$module->cron = 60;
function forum_upgrade($oldversion) {