diff --git a/admin/index.php b/admin/index.php index 2af34bcb592..98ed066ca5f 100644 --- a/admin/index.php +++ b/admin/index.php @@ -327,36 +327,37 @@ if (isadmin()) { $table->head = array (get_string("site"), get_string("courses"), get_string("users")); $table->align = array ("CENTER", "CENTER", "CENTER"); - $table->data[0][0] = "

".get_string("configvariables")."

". - "

".get_string("sitesettings")."

". - "

id\">".get_string("sitelogs")."

". - "

".get_string("choosetheme")."

". - "

".get_string("checklanguage")."

"; + $table->data[0][0] = "

".get_string("configvariables")."

". + "

".get_string("sitesettings")."

". + "

id\">".get_string("sitelogs")."

". + "

".get_string("choosetheme")."

". + "

".get_string("checklanguage")."

". + "

".get_string("managemodules")."

"; if (file_exists("$CFG->dirroot/admin/$CFG->dbtype")) { - $table->data[0][0] .= "

dbtype/frame.php\">".get_string("managedatabase")."

"; + $table->data[0][0] .= "

dbtype/frame.php\">".get_string("managedatabase")."

"; } - $table->data[0][1] = "

".get_string("addnewcourse")."

". - "

".get_string("assignteachers")."

". - "

".get_string("deletecourse")."

". - "

".get_string("categories")."

"; - if($CFG->auth == "email" || $CFG->auth == "none" || $CFG->auth == "manual"){ - $table->data[0][2] = "

".get_string("addnewuser")."

"; + $table->data[0][1] = "

".get_string("addnewcourse")."

". + "

".get_string("assignteachers")."

". + "

".get_string("deletecourse")."

". + "

".get_string("categories")."

"; + if ($CFG->auth == "email" || $CFG->auth == "none" || $CFG->auth == "manual") { + $table->data[0][2] = "

".get_string("addnewuser")."

"; } - $table->data[0][2] .= "

".get_string("edituser")."

". - "

".get_string("assignadmins")."

". - "

".get_string("assigncreators")."

". - "

".get_string("authentication")."

"; + $table->data[0][2] .= "

".get_string("edituser")."

". + "

".get_string("assignadmins")."

". + "

".get_string("assigncreators")."

". + "

".get_string("authentication")."

"; } else { /// user is coursecreator $table->head = array (get_string("courses")); $table->align = array ("CENTER"); - $table->data[0][1] = "

".get_string("addnewcourse")."

". - "

".get_string("assignteachers")."

"; + $table->data[0][1] = "

".get_string("addnewcourse")."

". + "

".get_string("assignteachers")."

"; } print_table($table); - echo "
"; + echo "
"; print_single_button("$CFG->wwwroot/doc", NULL, get_string("documentation")); - echo "
"; + echo "
"; print_heading("Moodle $CFG->release ($CFG->version)", "CENTER", 1); diff --git a/admin/modules.php b/admin/modules.php new file mode 100644 index 00000000000..8ad67de821e --- /dev/null +++ b/admin/modules.php @@ -0,0 +1,182 @@ +shortname: $strcategories", "$site->fullname", + "admin/index.php\">$stradministration -> $strmanagemodules"); + + print_heading($strmanagemodules); + + +/// If data submitted, then process and store. + + if (!empty($hide)) { + if (!$module = get_record("modules", "name", $hide)) { + error("Module doesn't exist!"); + } + set_field("modules", "visible", "0", "id", $module->id); // Hide main module + set_field("course_modules", "visible", "0", "module", $module->id); // Hide all related activity modules + } + + if (!empty($show)) { + if (!$module = get_record("modules", "name", $show)) { + error("Module doesn't exist!"); + } + set_field("modules", "visible", "1", "id", $module->id); // Show main module + set_field("course_modules", "visible", "1", "module", $module->id); // Show all related activity modules + } + + if (!empty($delete)) { + + $strmodulename = get_string("modulename", "$delete"); + + if (empty($confirm)) { + notice_yesno(get_string("moduledeleteconfirm", "", $strmodulename), + "modules.php?delete=$delete&confirm=$delete", + "modules.php"); + print_footer(); + exit; + + } else { // Delete everything!! + + if ($delete == "forum") { + error("You can not delete the forum module!!"); + } + + if (!$module = get_record("modules", "name", $delete)) { + error("Module doesn't exist!"); + } + + // OK, first delete all the relevant instances from all course sections + if ($coursemods = get_records("course_modules", "module", $module->id)) { + foreach ($coursemods as $coursemod) { + if (! delete_mod_from_section($coursemod->id, $coursemod->section)) { + notify("Could not delete the $strmodulename with id = $coursemod->id from section $coursemod->section"); + } + } + } + + // Now delete all the course module records + if (!delete_records("course_modules", "module", $module->id)) { + notify("Error occurred while deleting all $strmodulename records in course_modules table"); + } + + // Then delete all the logs + if (!delete_records("log", "module", $module->name)) { + notify("Error occurred while deleting all $strmodulename records in log table"); + } + + // And log_display information + if (!delete_records("log_display", "module", $module->name)) { + notify("Error occurred while deleting all $strmodulename records in log_display table"); + } + + // And the module entry itself + if (!delete_records("modules", "name", $module->name)) { + notify("Error occurred while deleting the $strmodulename record from modules table"); + } + + // Then the tables themselves + + if ($tables = $db->Metatables()) { + $prefix = $CFG->prefix.$module->name; + foreach ($tables as $table) { + if (strpos($table, $prefix) === 0) { + if (!execute_sql("DROP TABLE $table", false)) { + notify("ERROR: while trying to drop table $table"); + } + } + } + } + + rebuild_course_cache(); // Because things have changed + + + $a->module = $strmodulename; + $a->directory = "$CFG->dirroot/mod/$delete"; + notice(get_string("moduledeletefiles", "", $a), "modules.php"); + } + } + +/// Get and sort the existing modules + + if (!$modules = get_records("modules")) { + error("No modules found!!"); // Should never happen + } + + foreach ($modules as $module) { + $strmodulename = get_string("modulename", "$module->name"); + $modulebyname[$strmodulename] = $module; + } + ksort($modulebyname); + +/// Print the table of all modules + + if (empty($THEME->custompix)) { + $pixpath = "../pix"; + $modpixpath = "../mod"; + } else { + $pixpath = "../theme/$CFG->theme/pix"; + $modpixpath = "../theme/$CFG->theme/pix/mod"; + } + + $table->head = array ($stractivitymodule, "$strhide/$strshow", $strdelete); + $table->align = array ("LEFT", "CENTER", "CENTER"); + $table->wrap = array ("NOWRAP", "", ""); + $table->size = array ("100%", "10", "10"); + $table->width = "100"; + + foreach ($modulebyname as $modulename => $module) { + + $icon = "name/icon.gif\" hspace=10 height=16 width=16 border=0>"; + + $delete = "name\">$strdelete"; + + if ($module->visible) { + $visible = "name\" title=\"$strhide\">". + ""; + $class = ""; + } else { + $visible = "name\" title=\"$strshow\">". + ""; + $class = "class=\"dimmed_text\""; + } + if ($module->name == "forum") { + $delete = ""; + $visible = ""; + $class = ""; + } + $table->data[] = array ("

$icon $modulename

", $visible, $delete); + } + print_table($table); + + echo "

"; + + print_footer(); + +?> diff --git a/course/lib.php b/course/lib.php index 939972456c7..5a34a89a342 100644 --- a/course/lib.php +++ b/course/lib.php @@ -437,7 +437,7 @@ function get_array_of_activities($courseid) { // mod - name of the module (eg forum) // section - the number of the section (eg week or topic) // name - the name of the instance -// visible - when the instance is visible or no +// visible - is the instance visible or not $mod = array(); @@ -478,8 +478,10 @@ function get_all_mods($courseid, &$mods, &$modnames, &$modnamesplural, &$modname if ($allmods = get_records("modules")) { foreach ($allmods as $mod) { - $modnames[$mod->name] = get_string("modulename", "$mod->name"); - $modnamesplural[$mod->name] = get_string("modulenameplural", "$mod->name"); + if ($mod->visible) { + $modnames[$mod->name] = get_string("modulename", "$mod->name"); + $modnamesplural[$mod->name] = get_string("modulenameplural", "$mod->name"); + } } asort($modnames); } else { @@ -544,10 +546,7 @@ function set_section_visible($courseid, $sectionnumber, $visibility) { set_field("course_modules", "visible", "$visibility", "id", $moduleid); } } - $modinfo = serialize(get_array_of_activities($courseid)); - if (!set_field("course", "modinfo", $modinfo, "id", $courseid)) { - error("Could not cache module information!"); - } + rebuild_course_cache($courseid); } } @@ -632,6 +631,28 @@ function print_section($course, $section, $mods, $modnamesused, $absolute=false, echo "
\n\n"; } + +function rebuild_course_cache($courseid=0) { +// Rebuilds the cached list of course activities stored in the database +// If a courseid is not specified, then all are rebuilt + + if ($courseid) { + $select = "id = '$courseid'"; + } else { + $select = ""; + } + + if ($courses = get_records_select("course", $select)) { + foreach ($courses as $course) { + $modinfo = serialize(get_array_of_activities($course->id)); + if (!set_field("course", "modinfo", $modinfo, "id", $course->id)) { + notify("Could not cache module information for course '$course->fullname'!"); + } + } + } +} + + function print_heading_block($heading, $width="100%", $class="headingblock") { global $THEME; @@ -706,50 +727,52 @@ function print_admin_links ($siteid, $width=180) { } if (isadmin()) { - $moddata[]="wwwroot/$CFG->admin/config.php\">".get_string("configvariables").""; + $moddata[]="wwwroot/$CFG->admin/config.php\">".get_string("configvariables").""; $modicon[]=$icon; - $moddata[]="wwwroot/$CFG->admin/site.php\">".get_string("sitesettings").""; + $moddata[]="wwwroot/$CFG->admin/site.php\">".get_string("sitesettings").""; $modicon[]=$icon; - $moddata[]="wwwroot/course/log.php?id=$siteid\">".get_string("sitelogs").""; + $moddata[]="wwwroot/course/log.php?id=$siteid\">".get_string("sitelogs").""; $modicon[]=$icon; - $moddata[]="wwwroot/theme/index.php\">".get_string("choosetheme").""; + $moddata[]="wwwroot/theme/index.php\">".get_string("choosetheme").""; $modicon[]=$icon; - $moddata[]="wwwroot/$CFG->admin/lang.php\">".get_string("checklanguage").""; + $moddata[]="wwwroot/$CFG->admin/lang.php\">".get_string("checklanguage").""; + $modicon[]=$icon; + $moddata[]="wwwroot/$CFG->admin/modules.php\">".get_string("managemodules").""; $modicon[]=$icon; if (file_exists("$CFG->dirroot/$CFG->admin/$CFG->dbtype")) { - $moddata[]="wwwroot/$CFG->admin/$CFG->dbtype/frame.php\">".get_string("managedatabase").""; + $moddata[]="wwwroot/$CFG->admin/$CFG->dbtype/frame.php\">".get_string("managedatabase").""; $modicon[]=$icon; } - $moddata[]="
"; + $moddata[]="
"; $modicon[]=""; } if (iscreator()) { - $moddata[]="wwwroot/course/edit.php\">".get_string("addnewcourse").""; + $moddata[]="wwwroot/course/edit.php\">".get_string("addnewcourse").""; $modicon[]=$icon; - $moddata[]="wwwroot/course/teacher.php\">".get_string("assignteachers").""; + $moddata[]="wwwroot/course/teacher.php\">".get_string("assignteachers").""; $modicon[]=$icon; $fulladmin = ""; } if (isadmin()) { - $moddata[]="wwwroot/course/categories.php\">".get_string("categories").""; + $moddata[]="wwwroot/course/categories.php\">".get_string("categories").""; $modicon[]=$icon; - $moddata[]="wwwroot/course/delete.php\">".get_string("deletecourse").""; + $moddata[]="wwwroot/course/delete.php\">".get_string("deletecourse").""; $modicon[]=$icon; - $moddata[]="
"; + $moddata[]="
"; $modicon[]=""; if($CFG->auth == "email" || $CFG->auth == "none" || $CFG->auth == "manual"){ - $moddata[]="wwwroot/$CFG->admin/user.php?newuser=true\">".get_string("addnewuser").""; + $moddata[]="wwwroot/$CFG->admin/user.php?newuser=true\">".get_string("addnewuser").""; $modicon[]=$icon; } - $moddata[]="wwwroot/$CFG->admin/user.php\">".get_string("edituser").""; + $moddata[]="wwwroot/$CFG->admin/user.php\">".get_string("edituser").""; $modicon[]=$icon; - $moddata[]="wwwroot/$CFG->admin/admin.php\">".get_string("assignadmins").""; + $moddata[]="wwwroot/$CFG->admin/admin.php\">".get_string("assignadmins").""; $modicon[]=$icon; - $moddata[]="wwwroot/$CFG->admin/creators.php\">".get_string("assigncreators").""; + $moddata[]="wwwroot/$CFG->admin/creators.php\">".get_string("assigncreators").""; $modicon[]=$icon; - $moddata[]="wwwroot/$CFG->admin/auth.php\">".get_string("authentication").""; + $moddata[]="wwwroot/$CFG->admin/auth.php\">".get_string("authentication").""; $modicon[]=$icon; - $fulladmin = "

wwwroot/$CFG->admin/\">".get_string("admin")."..."; + $fulladmin = "

wwwroot/$CFG->admin/\">".get_string("admin")."..."; } print_side_block(get_string("administration"), "", $moddata, $modicon, $fulladmin, $width); diff --git a/course/mod.php b/course/mod.php index f6e05c7601e..48e7846f61f 100644 --- a/course/mod.php +++ b/course/mod.php @@ -47,7 +47,9 @@ if (! $updateinstancefunction($mod)) { error("Could not update the $mod->modulename"); } - add_to_log($mod->course, "course", "update mod", "../mod/$mod->modulename/view.php?id=$mod->coursemodule", "$mod->modulename $mod->instance"); + add_to_log($mod->course, "course", "update mod", + "../mod/$mod->modulename/view.php?id=$mod->coursemodule", + "$mod->modulename $mod->instance"); break; case "add": @@ -66,7 +68,9 @@ if (! set_field("course_modules", "section", $sectionid, "id", $mod->coursemodule)) { error("Could not update the course module with the correct section"); } - add_to_log($mod->course, "course", "add mod", "../mod/$mod->modulename/view.php?id=$mod->coursemodule", "$mod->modulename $mod->instance"); + add_to_log($mod->course, "course", "add mod", + "../mod/$mod->modulename/view.php?id=$mod->coursemodule", + "$mod->modulename $mod->instance"); break; case "delete": if (! $deleteinstancefunction($mod->instance)) { @@ -78,17 +82,18 @@ if (! delete_mod_from_section($mod->coursemodule, "$mod->section")) { notify("Could not delete the $mod->modulename from that section"); } - add_to_log($mod->course, "course", "delete mod", "view.php?id=$mod->course", "$mod->modulename $mod->instance"); + add_to_log($mod->course, "course", "delete mod", + "view.php?id=$mod->course", + "$mod->modulename $mod->instance"); break; default: error("No mode defined"); } - $modinfo = serialize(get_array_of_activities($mod->course)); - if (!set_field("course", "modinfo", $modinfo, "id", $mod->course)) { - error("Could not cache module information!"); - } + $db->debug = true; + rebuild_course_cache($mod->course); + $db->debug = false; if (!empty($SESSION->returnpage)) { $return = $SESSION->returnpage; @@ -111,10 +116,7 @@ move_module($cm, $move); - $modinfo = serialize(get_array_of_activities($cm->course)); - if (!set_field("course", "modinfo", $modinfo, "id", $cm->course)) { - error("Could not cache module information!"); - } + rebuild_course_cache($cm->course); $site = get_site(); if ($site->id == $cm->course) { @@ -130,12 +132,9 @@ error("This course module doesn't exist"); } - hide_course_module($hide); + hide_course_module($cm->id); - $modinfo = serialize(get_array_of_activities($cm->course)); - if (!set_field("course", "modinfo", $modinfo, "id", $cm->course)) { - error("Could not cache module information!"); - } + rebuild_course_cache($cm->course); $site = get_site(); if ($site->id == $cm->course) { @@ -151,14 +150,19 @@ error("This course module doesn't exist"); } + if (! $section = get_record("course_sections", "id", $cm->section)) { + error("This module doesn't exist"); + } + + if (! $module = get_record("modules", "id", $cm->module)) { + error("This module doesn't exist"); + } + $site = get_site(); - if ($cm->visible or $site->id == $cm->course) { - show_course_module($show); - $modinfo = serialize(get_array_of_activities($cm->course)); - if (!set_field("course", "modinfo", $modinfo, "id", $cm->course)) { - error("Could not cache module information!"); - } + if ($module->visible and ($section->visible or ($site->id == $cm->course))) { + show_course_module($cm->id); + rebuild_course_cache($cm->course); } if ($site->id == $cm->course) { diff --git a/lang/en/moodle.php b/lang/en/moodle.php index a69b511b59a..d23589d3cb9 100644 --- a/lang/en/moodle.php +++ b/lang/en/moodle.php @@ -4,8 +4,9 @@ $string['thislanguage'] = "English"; // Name of this language in the native lan $string['thischarset'] = "iso-8859-1"; // The best charset to use for this language $string['action'] = "Action"; -$string['activity'] = "Activity"; $string['activities'] = "Activities"; +$string['activity'] = "Activity"; +$string['activitymodule'] = "Activity module"; $string['activityreport'] = "Activity report"; $string['add'] = "Add"; $string['added'] = "Added \$a"; @@ -352,6 +353,7 @@ $string['makeafolder'] = "Make a folder"; $string['makeeditable'] = "If you make '\$a' editable by the web server process (eg apache) then you could edit this file directly from this page"; $string['mainmenu'] = "Main menu"; $string['managedatabase'] = "Manage database"; +$string['managemodules'] = "Manage modules"; $string['markedthistopic'] = "This topic is highlighted as the current topic"; $string['markthistopic'] = "Highlight this topic as the current topic"; $string['maximumchars'] = "Maximum of \$a characters"; @@ -381,6 +383,9 @@ $string['missingsummary'] = "Missing summary"; $string['missingteacher'] = "Must choose something"; $string['missingusername'] = "Missing username"; $string['modified'] = "Modified"; +$string['moduledeleteconfirm'] = "You are about to completely delete the module '\$a'. This will completely delete everything in the database associated with this activity module. Are you SURE you want to continue?"; +$string['moduledeletefiles'] = "All data associated with the module '\$a->module' has been deleted from the database. To complete the deletion (and prevent the module re-installing itself), you should now delete this directory from your server: \$a->directory"; +$string['modulesetup'] = "Setting up module tables"; $string['modulesetup'] = "Setting up module tables"; $string['modulesuccess'] = "\$a tables have been set up correctly"; $string['mostrecently'] = "most recently"; diff --git a/lib/db/mysql.php b/lib/db/mysql.php index 528c4d80c59..9d396c311a7 100644 --- a/lib/db/mysql.php +++ b/lib/db/mysql.php @@ -19,7 +19,7 @@ function main_upgrade($oldversion=0) { - global $CFG; + global $CFG, $THEME; $result = true; @@ -383,6 +383,12 @@ function main_upgrade($oldversion=0) { table_column("modules", "", "visible", "integer", "1", "unsigned", "1", "", ""); } + if ($oldversion < 2003050902) { + if (get_records("modules", "name", "pgassignment")) { + print_simple_box("Note: the pgassignment module will soon be deleted from CVS! Go to the new 'Manage Modules' page and DELETE IT from your system", "center", "50%", "$THEME->cellheading", "20", "noticebox"); + } + } + return $result; } diff --git a/lib/db/postgres7.php b/lib/db/postgres7.php index c01069bea9e..b278921bfcc 100644 --- a/lib/db/postgres7.php +++ b/lib/db/postgres7.php @@ -18,8 +18,12 @@ // This file is tailored to PostgreSQL 7 function main_upgrade($oldversion=0) { - global $CFG; + + global $CFG, $THEME; + $result = true; + + if ($oldversion < 2003010101) { delete_records("log_display", "module", "user"); $new->module = "user"; @@ -150,6 +154,12 @@ function main_upgrade($oldversion=0) { table_column("modules", "", "visible", "integer", "1", "unsigned", "1", "", ""); } + if ($oldversion < 2003050902) { + if (get_records("modules", "name", "pgassignment")) { + print_simple_box("Note: the pgassignment module will soon be deleted from CVS! Go to the new 'Manage Modules' page and DELETE IT from your system", "center", "50%", "$THEME->cellheading", "20", "noticebox"); + } + } + return $result; } ?> diff --git a/lib/weblib.php b/lib/weblib.php index de56c773abf..7ccc0210879 100644 --- a/lib/weblib.php +++ b/lib/weblib.php @@ -895,6 +895,7 @@ function print_table($table) { // $table->head is an array of heading names. // $table->align is an array of column alignments // $table->size is an array of column sizes +// $table->wrap is an array of "nowrap"s or nothing // $table->data[] is an array of arrays containing the data. // $table->width is an percentage of the page // $table->cellpadding padding on each cell @@ -918,6 +919,15 @@ function print_table($table) { } } } + if (isset($table->wrap)) { + foreach ($table->wrap as $key => $ww) { + if ($ww) { + $wrap[$key] = " NOWRAP "; + } else { + $wrap[$key] = ""; + } + } + } if (empty($table->width)) { $table->width = "80%"; @@ -931,12 +941,12 @@ function print_table($table) { $table->cellspacing = "1"; } - print_simple_box_start("CENTER", "$table->width", "#FFFFFF", 0); - echo "width", "#ffffff", 0); + echo "
cellpadding\" cellspacing=\"$table->cellspacing\" class=\"generaltable\">\n"; if (!empty($table->head)) { - echo ""; + echo ""; foreach ($table->head as $key => $heading) { if (!isset($size[$key])) { $size[$key] = ""; @@ -944,13 +954,13 @@ function print_table($table) { if (!isset($align[$key])) { $align[$key] = ""; } - echo ""; + echo ""; } echo "\n"; } foreach ($table->data as $row) { - echo ""; + echo ""; foreach ($row as $key => $item) { if (!isset($size[$key])) { $size[$key] = ""; @@ -958,11 +968,14 @@ function print_table($table) { if (!isset($align[$key])) { $align[$key] = ""; } - echo ""; + if (!isset($wrap[$key])) { + $wrap[$key] = ""; + } + echo ""; } - echo "\n"; + echo "\n"; } - echo "
$heading$heading
$item$item
\n"; + echo "\n"; print_simple_box_end(); return true; diff --git a/version.php b/version.php index 3a6637e9725..fc8ba1dcaa4 100644 --- a/version.php +++ b/version.php @@ -5,7 +5,7 @@ // database to determine whether upgrades should // be performed (see lib/db/*.php) -$version = 2003050900; // The current version is a date (YYYYMMDDXX) +$version = 2003050902; // The current version is a date (YYYYMMDDXX) -$release = "1.0.9 development version"; // User-friendly version number +$release = "1.0.9 development"; // User-friendly version number