From: moodler Date: Sun, 10 Nov 2002 07:37:15 +0000 (+0000) Subject: Changes to enable jumping between activity modules, using a new menu in X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=d897cae41967fb681e652d18753bc979497c50df;p=moodle.git Changes to enable jumping between activity modules, using a new menu in the upper-right corner. Caution: Not well tested at this stage. --- diff --git a/course/lib.php b/course/lib.php index 1343763413..6da45412d4 100644 --- a/course/lib.php +++ b/course/lib.php @@ -384,6 +384,42 @@ function print_recent_activity($course) { } +function get_array_of_activities($courseid) { +// For a given course, returns an array of course activity objects +// Each item in the array contains he following properties: +// cm - course module id +// mod - name of the module (eg forum) +// section - the number of the section (eg week or topic) +// name - the name of the instance + + $mod = array(); + + if (!$rawmods = get_records_sql("SELECT cm.*, m.name as modname + FROM modules m, course_modules cm + WHERE cm.course = '$courseid' + AND cm.deleted = '0' + AND cm.module = m.id ") ) { + return NULL; + } + + if ($sections = get_records("course_sections", "course", $courseid, "section ASC")) { + foreach ($sections as $section) { + if ($section->sequence) { + $sequence = explode(",", $section->sequence); + foreach ($sequence as $seq) { + $mod[$seq]->cm = $rawmods[$seq]->id; + $mod[$seq]->mod = $rawmods[$seq]->modname; + $mod[$seq]->section = $section->section; + $mod[$seq]->name = urlencode(get_field($rawmods[$seq]->modname, "name", "id", $rawmods[$seq]->instance)); + } + } + } + } + return $mod; +} + + + function get_all_mods($courseid, &$mods, &$modnames, &$modnamesplural, &$modnamesused) { // Returns a number of useful structures for course displays @@ -429,7 +465,7 @@ function get_all_categories() { return get_records_sql("SELECT * FROM course_categories ORDER by name"); } -function print_section($courseid, $section, $mods, $modnamesused, $absolute=false, $width="100%") { +function print_section($course, $section, $mods, $modnamesused, $absolute=false, $width="100%") { global $CFG; @@ -444,7 +480,7 @@ function print_section($courseid, $section, $mods, $modnamesused, $absolute=fals echo "wwwroot/mod/$mod->modname/icon.gif\" HEIGHT=16 WIDTH=16 ALT=\"$mod->modfullname\">"; echo " modfullname\""; echo " HREF=\"$CFG->wwwroot/mod/$mod->modname/view.php?id=$mod->id\">$instancename"; - if (isediting($courseid)) { + if (isediting($course->id)) { echo make_editing_buttons($mod->id, $absolute); } echo "
\n"; diff --git a/course/mod.php b/course/mod.php index 5d48b09f4e..77908b7ac8 100644 --- a/course/mod.php +++ b/course/mod.php @@ -86,6 +86,12 @@ } + $modinfo = serialize(get_array_of_activities($mod->course)); + + if (!set_field("course", "modinfo", $modinfo, "id", $mod->course)) { + error("Could not cache module information!"); + } + if ($SESSION->returnpage) { $return = $SESSION->returnpage; unset($SESSION->returnpage); diff --git a/course/social.php b/course/social.php index 334083e386..4b2de15fe7 100644 --- a/course/social.php +++ b/course/social.php @@ -27,7 +27,7 @@ /// Then, print all the available resources (Section 0) print_simple_box(get_string("resources"), $align="CENTER", $width="100%", $color="$THEME->cellheading"); - print_section($course->id, $sections[0], $mods, $modnamesused, true); + print_section($course, $sections[0], $mods, $modnamesused, true); if (isediting($course->id)) { echo "
"; diff --git a/course/topics.php b/course/topics.php index 1436533ee5..82df112dba 100644 --- a/course/topics.php +++ b/course/topics.php @@ -37,6 +37,10 @@ $news = forum_get_course_forum($course->id, "news"); } + $streditsummary = get_string("editsummary"); + $stradd = get_string("add"); + $stractivities = get_string("activities"); + /// Layout the whole page as three big columns. echo ""; @@ -68,7 +72,7 @@ $modicon[] = "\"\""; } } - print_simple_box(get_string("activities"), $align="CENTER", $width="100%", $color="$THEME->cellheading"); + print_simple_box($stractivities, $align="CENTER", $width="100%", $color="$THEME->cellheading"); print_side_block("", $moddata, "", $modicon); /// Print a form to search forums @@ -87,8 +91,6 @@ print_simple_box(get_string("topicoutline"), $align="CENTER", $width="100%", $color="$THEME->cellheading"); - $streditsummary = get_string("editsummary"); - $stradd = get_string("add"); echo "
"; @@ -111,12 +113,12 @@ echo text_to_html($thistopic->summary); - print_section($course->id, $thistopic, $mods, $modnamesused); + print_section($course, $thistopic, $mods, $modnamesused); if (isediting($course->id)) { echo "
"; popup_form("$CFG->wwwroot/course/mod.php?id=$course->id§ion=$topic&add=", - $modnames, "section$topic", "", "$stradd...", "mods", get_string("activities")); + $modnames, "section$topic", "", "$stradd...", "mods", $stractivities); echo "
"; } @@ -173,12 +175,12 @@ echo text_to_html($thissection->summary); - print_section($course->id, $thissection, $mods, $modnamesused); + print_section($course, $thissection, $mods, $modnamesused); if (isediting($course->id)) { echo "
"; popup_form("$CFG->wwwroot/course/mod.php?id=$course->id§ion=$section&add=", - $modnames, "section$section", "", "$stradd...", "mods", get_string("activities")); + $modnames, "section$section", "", "$stradd...", "mods", $stractivities); echo "
"; } diff --git a/course/weeks.php b/course/weeks.php index 1db585b50d..7faa92cfdf 100644 --- a/course/weeks.php +++ b/course/weeks.php @@ -25,6 +25,10 @@ if ($course->newsitems) { $news = forum_get_course_forum($course->id, "news"); } + + $streditsummary = get_string("editsummary"); + $stradd = get_string("add"); + $stractivities = get_string("activities"); /// Layout the whole page as three big columns. @@ -57,7 +61,7 @@ $modicon[] = "\"\""; } } - print_simple_box(get_string("activities"), $align="CENTER", $width="100%", $color="$THEME->cellheading"); + print_simple_box($stractivities, $align="CENTER", $width="100%", $color="$THEME->cellheading"); print_side_block("", $moddata, "", $modicon); /// Print a form to search forums @@ -77,9 +81,6 @@ echo " +
"; print_simple_box(get_string("weeklyoutline"), $align="CENTER", $width="100%", $color="$THEME->cellheading"); - - $streditsummary = get_string("editsummary"); - $stradd = get_string("add"); echo ""; @@ -102,12 +103,12 @@ echo text_to_html($thisweek->summary); - print_section($course->id, $thisweek, $mods, $modnamesused); + print_section($course, $thisweek, $mods, $modnamesused); if (isediting($course->id)) { echo "
"; popup_form("$CFG->wwwroot/course/mod.php?id=$course->id§ion=$week&add=", - $modnames, "section$week", "", "$stradd...", "mods", get_string("activities")); + $modnames, "section$week", "", "$stradd...", "mods", $stractivities); echo "
"; } @@ -172,12 +173,12 @@ echo text_to_html($thisweek->summary); - print_section($course->id, $thisweek, $mods, $modnamesused); + print_section($course, $thisweek, $mods, $modnamesused); if (isediting($course->id)) { echo "
"; popup_form("$CFG->wwwroot/course/mod.php?id=$course->id§ion=$week&add=", - $modnames, "section$week", "", "$stradd...", "mods", get_string("activities")); + $modnames, "section$week", "", "$stradd...", "mods", $stractivities); echo "
"; } diff --git a/lang/en/moodle.php b/lang/en/moodle.php index a8aa1c95e8..009f5b4e7b 100644 --- a/lang/en/moodle.php +++ b/lang/en/moodle.php @@ -223,6 +223,7 @@ $string['htmleditordisabledbrowser'] = "The Richtext editor is unavailable becau $string['htmlformat'] = "Pretty HTML format"; $string['icqnumber'] = "ICQ number"; $string['idnumber'] = "ID number"; +$string['jumpto'] = "Jump to..."; $string['leavetokeep'] = "Leave blank to keep current password"; $string['invalidlogin'] = "Invalid login, please try again"; $string['invalidemail'] = "Invalid email address"; diff --git a/lib/db/mysql.php b/lib/db/mysql.php index 1807473fed..3801e236c4 100644 --- a/lib/db/mysql.php +++ b/lib/db/mysql.php @@ -167,6 +167,22 @@ function main_upgrade($oldversion=0) { } } + if ($oldversion < 2002111003) { + execute_sql(" ALTER TABLE `course` ADD `modinfo` TEXT NOT NULL AFTER `format` "); + if ($courses = get_records_sql("SELECT * FROM course")) { + require_once("$CFG->dirroot/course/lib.php"); + 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'!"); + } + } + } + } + + return true; } diff --git a/lib/db/mysql.sql b/lib/db/mysql.sql index 692e557cd8..53199240f3 100644 --- a/lib/db/mysql.sql +++ b/lib/db/mysql.sql @@ -35,6 +35,7 @@ CREATE TABLE `course` ( `shortname` varchar(15) NOT NULL default '', `summary` text NOT NULL, `format` enum('weeks','social','topics') NOT NULL default 'weeks', + `modinfo` text NOT NULL, `newsitems` smallint(5) unsigned NOT NULL default '1', `teacher` varchar(100) NOT NULL default 'Teacher', `teachers` varchar(100) NOT NULL default 'Teachers', diff --git a/lib/moodlelib.php b/lib/moodlelib.php index eb301d3ab1..b07cc449f1 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -10,14 +10,15 @@ /// STANDARD WEB PAGE PARTS /////////////////////////////////////////////////// -function print_header ($title="", $heading="", $navigation="", $focus="", $meta="", $cache=true, $button="") { +function print_header ($title="", $heading="", $navigation="", $focus="", $meta="", $cache=true, $button="", $menu="") { // $title - appears top of window // $heading - appears top of page // $navigation - premade navigation string // $focus - indicates form element eg inputform.password // $meta - meta tags in the header // $cache - should this page be cacheable? -// $button - code for a button in the top-right +// $button - HTML code for a button (usually for module editing) +// $menu - HTML code for a popup menu global $USER, $CFG, $THEME; if (file_exists("$CFG->dirroot/theme/$CFG->theme/styles.css")) { @@ -31,11 +32,11 @@ function print_header ($title="", $heading="", $navigation="", $focus="", $meta= $navigation = ""; } - if (!$button and $navigation) { + if (!$menu and $navigation) { if (isset($USER->id)) { - $button = "wwwroot/login/logout.php\">".get_string("logout").""; + $menu = "wwwroot/login/logout.php\">".get_string("logout").""; } else { - $button = "wwwroot/login/index.php\">".get_string("login").""; + $menu = "wwwroot/login/index.php\">".get_string("login").""; } } @@ -386,6 +387,46 @@ function update_module_button($moduleid, $courseid, $string) { } +function navmenu($course, $cm) { +// Given a course and a (current) coursemodule +// This function returns a small popup menu with all the +// course activity modules in it, as a navigation menu +// The data is taken from the serialised array stored in +// the course record + + global $CFG; + + if ($course->format = 'weeks') { + $strsection = get_string("week"); + } else { + $strsection = get_string("topic"); + } + + if (!$array = unserialize($course->modinfo)) { + return ""; + } + $section = -1; + $selected = ""; + foreach ($array as $mod) { + if ($mod->section > 0 and $section <> $mod->section) { + $menu[] = "-------------- $strsection $mod->section --------------"; + } + $section = $mod->section; + $url = "$mod->mod/view.php?id=$mod->cm"; + if ($cm->id == $mod->cm) { + $selected = $url; + } + $mod->name = urldecode($mod->name); + if (strlen($mod->name) > 55) { + $mod->name = substr($mod->name, 0, 50)."..."; + } + $menu[$url] = $mod->name; + } + + return popup_form("$CFG->wwwroot/mod/", $menu, "navmenu", $selected, get_string("jumpto"), "", "", true); +} + + function print_date_selector($day, $month, $year, $currenttime=0) { // Currenttime is a default timestamp in GMT // Prints form items with the names $day, $month and $year @@ -433,6 +474,7 @@ function make_timestamp($year, $month=1, $day=1, $hour=0, $minute=0, $second=0) return mktime((int)$hour,(int)$minute,(int)$second,(int)$month,(int)$day,(int)$year); } + function format_time($totalsecs, $str=NULL) { // Given an amount of time in seconds, prints it // nicely as months, days, hours etc as needed @@ -1659,6 +1701,11 @@ function get_directory_list($rootdir, $excludefile="", $descend=true) { $dir = opendir($rootdir); + if (!$dir) { + notify("Error: unable to read this directory! : $rootdir"); + return $dirs; + } + while ($file = readdir($dir)) { if ($file != "." and $file != ".." and $file != "CVS" and $file != $excludefile) { $fullfile = $rootdir."/".$file; diff --git a/lib/weblib.php b/lib/weblib.php index 129e164bec..8b3d22e315 100644 --- a/lib/weblib.php +++ b/lib/weblib.php @@ -273,7 +273,7 @@ function choose_from_menu ($options, $name, $selected="", $nothing="choose", $sc } } -function popup_form ($common, $options, $formname, $selected="", $nothing="choose", $help="", $helptext="") { +function popup_form ($common, $options, $formname, $selected="", $nothing="choose", $help="", $helptext="", $return=false) { /// Implements a complete little popup form /// $common = the URL up to the point of the variable that changes /// $options = A list of value-label pairs for the popup list @@ -287,29 +287,39 @@ function popup_form ($common, $options, $formname, $selected="", $nothing="choos $nothing = get_string("choose")."..."; } - echo ""; - echo "\n"; if ($nothing != "") { - echo " \n"; + $output .= " \n"; } foreach ($options as $value => $label) { - echo " \n"; + $output .= ">$label\n"; } else { - echo ">$value\n"; + $output .= ">$value\n"; } } - echo ""; - if ($help) { + $output .= ""; + if (!$return and $help) { helpbutton($help, $helptext); } - echo "\n"; + $output .= "\n"; + + if ($return) { + return $output; + } else { + echo $output; + } } diff --git a/mod/assignment/view.php b/mod/assignment/view.php index fbe3dfdd10..9ad6df9fcd 100644 --- a/mod/assignment/view.php +++ b/mod/assignment/view.php @@ -44,7 +44,7 @@ print_header("$course->shortname: $assignment->name", "$course->fullname", "$navigation id>$strassignments -> $assignment->name", - "", "", true, update_module_button($cm->id, $course->id, $strassignment)); + "", "", true, update_module_button($cm->id, $course->id, $strassignment), navmenu($course, $cm)); if (isteacher($course->id)) { if ($assignment->type == OFFLINE) { diff --git a/mod/choice/view.php b/mod/choice/view.php index e1d842e408..e41f248d23 100644 --- a/mod/choice/view.php +++ b/mod/choice/view.php @@ -59,7 +59,7 @@ } print_header("$course->shortname: $choice->name", "$course->fullname", "$navigation id>$strchoices -> $choice->name", "", "", true, - update_module_button($cm->id, $course->id, $strchoice)); + update_module_button($cm->id, $course->id, $strchoice), navmenu($course, $cm)); if (isteacher($course->id)) { if ( $allanswers = get_records("choice_answers", "choice", $choice->id)) { diff --git a/mod/forum/view.php b/mod/forum/view.php index befd2d4be3..3b0ba90618 100644 --- a/mod/forum/view.php +++ b/mod/forum/view.php @@ -58,7 +58,7 @@ add_to_log($course->id, "forum", "view forum", "view.php?f=$forum->id", "$forum->id"); print_header("$course->shortname: $forum->name", "$course->fullname", - "$navigation $forum->name", "", "", true, $buttontext); + "$navigation $forum->name", "", "", true, $buttontext, navmenu($course, $cm)); if ($USER) { $SESSION->fromdiscussion = "$FULLME"; diff --git a/mod/journal/view.php b/mod/journal/view.php index b4839eb917..ad49c945d9 100644 --- a/mod/journal/view.php +++ b/mod/journal/view.php @@ -34,7 +34,7 @@ print_header("$course->shortname: $journal->name", "$course->fullname", "$navigation id>$strjournals -> $journal->name", "", "", true, - update_module_button($cm->id, $course->id, $strjournal)); + update_module_button($cm->id, $course->id, $strjournal), navmenu($course, $cm)); if (isteacher($course->id)) { if ($allentries = get_records("journal_entries", "journal", $journal->id)) { diff --git a/mod/quiz/view.php b/mod/quiz/view.php index 9474d03fc2..cd8c68132b 100644 --- a/mod/quiz/view.php +++ b/mod/quiz/view.php @@ -51,7 +51,7 @@ print_header("$course->shortname: $quiz->name", "$course->fullname", "$navigation id>$strquizzes -> $quiz->name", - "", "", true, update_module_button($cm->id, $course->id, $strquiz)); + "", "", true, update_module_button($cm->id, $course->id, $strquiz), navmenu($course, $cm)); if (isteacher($course->id)) { if ($allanswers = get_records("quiz_grades", "quiz", $quiz->id)) { diff --git a/mod/resource/view.php b/mod/resource/view.php index a85ab7be79..016c3ad8e6 100644 --- a/mod/resource/view.php +++ b/mod/resource/view.php @@ -33,7 +33,7 @@ case 1: // Reference (eg Journal or Book etc) add_to_log($course->id, "resource", "view", "view.php?id=$cm->id", "$resource->id"); print_header("$course->shortname: $resource->name", "$course->fullname", "$navigation $resource->name", - "", "", true, update_module_button($cm->id, $course->id, $strresource)); + "", "", true, update_module_button($cm->id, $course->id, $strresource), navmenu($course, $cm)); print_simple_box($resource->reference, "center"); echo "

"; @@ -54,7 +54,7 @@ if ($frameset) { print_header("$course->shortname: $resource->name", "$course->fullname", "$navigation reference\" TITLE=\"$resource->reference\">$resource->name", - "", "", true, update_module_button($cm->id, $course->id, $strresource)); + "", "", true, update_module_button($cm->id, $course->id, $strresource), navmenu($course, $cm)); echo "

".text_to_html($resource->summary, true, false)."
"; } else { @@ -70,7 +70,7 @@ case 3: // Uploaded File if ($frameset) { print_header("$course->shortname: $resource->name", "$course->fullname", "$navigation $resource->name", - "", "", true, update_module_button($cm->id, $course->id, $strresource)); + "", "", true, update_module_button($cm->id, $course->id, $strresource), navmenu($course, $cm)); echo "
".text_to_html($resource->summary, true, false)."
"; } else { @@ -91,7 +91,7 @@ case 4: // Plain text add_to_log($course->id, "resource", "view", "view.php?id=$cm->id", "$resource->id"); print_header("$course->shortname: $resource->name", "$course->fullname", "$navigation $resource->name", - "", "", true, update_module_button($cm->id, $course->id, $strresource)); + "", "", true, update_module_button($cm->id, $course->id, $strresource), navmenu($course, $cm)); print_simple_box(text_to_html($resource->alltext), "CENTER", "", "$THEME->cellcontent", "20"); @@ -103,7 +103,7 @@ case 6: // HTML text add_to_log($course->id, "resource", "view", "view.php?id=$cm->id", "$resource->id"); print_header("$course->shortname: $resource->name", "$course->fullname", "$navigation $resource->name", - "", "", true, update_module_button($cm->id, $course->id, $strresource)); + "", "", true, update_module_button($cm->id, $course->id, $strresource), navmenu($course, $cm)); print_simple_box_start("CENTER", "", "$THEME->cellcontent", "20"); @@ -118,7 +118,7 @@ default: print_header("$course->shortname: $resource->name", "$course->fullname", "$navigation $resource->name", - "", "", true, update_module_button($cm->id, $course->id, $strresource)); + "", "", true, update_module_button($cm->id, $course->id, $strresource), navmenu($course, $cm)); print_heading($resource->name); print_simple_box("Error: unknown type of resource", "center"); diff --git a/mod/survey/view.php b/mod/survey/view.php index 6c019c18a9..c243466187 100644 --- a/mod/survey/view.php +++ b/mod/survey/view.php @@ -28,7 +28,7 @@ print_header("$course->shortname: $survey->name", "$course->fullname", "$navigation id>$strsurveys -> $survey->name", "", "", true, - update_module_button($cm->id, $course->id, $strsurvey)); + update_module_button($cm->id, $course->id, $strsurvey), navmenu($course, $cm)); if (isteacher($course->id)) { $numusers = survey_count_responses($survey->id); diff --git a/theme/standard/header.html b/theme/standard/header.html index c39fb09991..3340847538 100644 --- a/theme/standard/header.html +++ b/theme/standard/header.html @@ -15,7 +15,7 @@
- +
@@ -25,7 +25,7 @@ - +
@@ -39,6 +39,7 @@

diff --git a/theme/standard/styles.css b/theme/standard/styles.css index 2ab964116a..4272ce4de8 100644 --- a/theme/standard/styles.css +++ b/theme/standard/styles.css @@ -21,6 +21,9 @@ td {font-family: "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;} li {font-family: "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;} +form { margin-bottom: 0 ; } + .highlight { background-color: #AAFFAA; } + diff --git a/theme/standardblue/styles.css b/theme/standardblue/styles.css index e11bb08cc7..d25b6e0edb 100644 --- a/theme/standardblue/styles.css +++ b/theme/standardblue/styles.css @@ -13,6 +13,8 @@ td {font-family: "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;} li {font-family: "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;} +form { margin-bottom: 0 ; } + .highlight { background-color: #AAFFAA; } diff --git a/theme/standardgreen/styles.css b/theme/standardgreen/styles.css index 4bd26f5c51..8c96053c32 100644 --- a/theme/standardgreen/styles.css +++ b/theme/standardgreen/styles.css @@ -13,6 +13,8 @@ td {font-family: "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;} li {font-family: "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;} +form { margin-bottom: 0 ; } + .highlight { background-color: #FFAAAA; } diff --git a/theme/standardlogo/styles.css b/theme/standardlogo/styles.css index 2ab964116a..46c1c22581 100644 --- a/theme/standardlogo/styles.css +++ b/theme/standardlogo/styles.css @@ -21,6 +21,9 @@ td {font-family: "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;} li {font-family: "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;} +form { margin-bottom: 0 ; } + + .highlight { background-color: #AAFFAA; } diff --git a/theme/standardred/styles.css b/theme/standardred/styles.css index 4036004416..c75a4dcf4f 100644 --- a/theme/standardred/styles.css +++ b/theme/standardred/styles.css @@ -13,6 +13,9 @@ td {font-family: "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;} li {font-family: "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;} +form { margin-bottom: 0 ; } + + .highlight { background-color: #FFAAAA; } diff --git a/version.php b/version.php index 15c360b43b..2e70916a1b 100644 --- a/version.php +++ b/version.php @@ -5,7 +5,7 @@ // database to determine whether upgrades should // be performed (see lib/db/*.php) -$version = 2002110900; // The current version is a date (YYYYMMDDXX) +$version = 2002111003; // The current version is a date (YYYYMMDDXX) $release = "1.0.6.2"; // User-friendly version number