From: moodler Date: Tue, 25 Nov 2003 04:19:58 +0000 (+0000) Subject: Added new navmenu function that now prints next/previous buttons - it's X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=f2d91421fd010d9cc48c67aecb7b35c4e5a5f07f;p=moodle.git Added new navmenu function that now prints next/previous buttons - it's based on code from Gustav Delius. Thanks, Gustav! --- diff --git a/lib/weblib.php b/lib/weblib.php index dc2005f06a..54c3d11484 100644 --- a/lib/weblib.php +++ b/lib/weblib.php @@ -1416,17 +1416,18 @@ function update_categories_button() { } } + function navmenu($course, $cm=NULL, $targetwindow="self") { // Given a course and a (current) coursemodule -// This function returns a small popup menu with all the +// 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 data is taken from the serialised array stored in // the course record global $CFG; if ($cm) { - $cm = $cm->id; + $cm = $cm->id; } if ($course->format == 'weeks') { @@ -1438,8 +1439,15 @@ function navmenu($course, $cm=NULL, $targetwindow="self") { if (!$modinfo = unserialize($course->modinfo)) { return ""; } + $isteacher = isteacher($course->id); $section = -1; $selected = ""; + $url = ""; + $previousmod = NULL; + $backmod = NULL; + $nextmod = NULL; + $flag = false; + foreach ($modinfo as $mod) { if ($mod->mod == "label") { continue; @@ -1449,10 +1457,16 @@ function navmenu($course, $cm=NULL, $targetwindow="self") { } $section = $mod->section; //Only add visible or teacher mods to jumpmenu - if ($mod->visible or isteacher($course->id)) { + if ($mod->visible or $isteacher) { $url = "$mod->mod/view.php?id=$mod->cm"; + if ($flag) { // the current mod is the "next" mod + $nextmod = $mod; + $flag = false; + } if ($cm == $mod->cm) { $selected = $url; + $backmod = $previousmod; + $flag = true; // set flag so we know to use next mod for "next" } $mod->name = urldecode($mod->name); if (strlen($mod->name) > 55) { @@ -1461,14 +1475,25 @@ function navmenu($course, $cm=NULL, $targetwindow="self") { if (!$mod->visible) { $mod->name = "(".$mod->name.")"; } - $menu[$url] = $mod->name; + $menu[$url] = $mod->name; } + $previousmod = $mod; } - - return popup_form("$CFG->wwwroot/mod/", $menu, "navmenu", $selected, get_string("jumpto"), - "", "", true, $targetwindow); -} - + if ($backmod) { + $backmod = "
wwwroot/mod/$backmod->mod/view.php\" target=\"$CFG->framename\">". + "cm\">". + "
"; + } + if ($nextmod) { + $nextmod = "
wwwroot/mod/$nextmod->mod/view.php\" target=\"$CFG->framename\">". + "cm\">". + "
"; + } + return "
$backmod" . + popup_form("$CFG->wwwroot/mod/", $menu, "navmenu", $selected, get_string("jumpto"), + "", "", true, $targetwindow). + "$nextmod
"; +} function print_date_selector($day, $month, $year, $currenttime=0) {