diff --git a/course/editsection.php b/course/editsection.php index ecd905b2868..e4d6bea5454 100644 --- a/course/editsection.php +++ b/course/editsection.php @@ -33,9 +33,9 @@ require_once($CFG->libdir . '/conditionlib.php'); require_once('editsection_form.php'); $id = required_param('id',PARAM_INT); // Week/topic ID -$sectionreturn = optional_param('sectionreturn', 0, PARAM_BOOL); +$sectionreturn = optional_param('sr', 0, PARAM_INT); -$PAGE->set_url('/course/editsection.php', array('id'=>$id, 'sectionreturn'=> $sectionreturn)); +$PAGE->set_url('/course/editsection.php', array('id'=>$id, 'sr'=> $sectionreturn)); $section = $DB->get_record('course_sections', array('id' => $id), '*', MUST_EXIST); $course = $DB->get_record('course', array('id' => $section->course), '*', MUST_EXIST); @@ -60,11 +60,7 @@ $mform = new editsection_form($PAGE->url, array('course' => $course, 'editoropti 'cs' => $section, 'showavailability' => $section->showavailability)); $mform->set_data($section); // set current value -if ($sectionreturn) { - $returnurl = course_get_url($course, $section->section); -} else { - $returnurl = course_get_url($course); -} +$returnurl = course_get_url($course, $sectionreturn); /// If data submitted, then process and store. if ($mform->is_cancelled()){ diff --git a/course/format/renderer.php b/course/format/renderer.php index b7c0e21a5a6..1fec7b2389d 100644 --- a/course/format/renderer.php +++ b/course/format/renderer.php @@ -122,9 +122,10 @@ abstract class format_section_renderer_base extends plugin_renderer_base { * @param stdClass $section The course_section entry from DB * @param stdClass $course The course entry from DB * @param bool $onsectionpage true if being printed on a single-section page + * @param int $sectionreturn The section to return to after an action * @return string HTML to output. */ - protected function section_header($section, $course, $onsectionpage) { + protected function section_header($section, $course, $onsectionpage, $sectionreturn=0) { global $PAGE; $o = ''; @@ -159,12 +160,7 @@ abstract class format_section_renderer_base extends plugin_renderer_base { $context = context_course::instance($course->id); if ($PAGE->user_is_editing() && has_capability('moodle/course:update', $context)) { - $url = new moodle_url('/course/editsection.php', array('id'=>$section->id)); - - if ($onsectionpage) { - $url->param('sectionreturn', 1); - } - + $url = new moodle_url('/course/editsection.php', array('id'=>$section->id, 'sr'=>$sectionreturn)); $o.= html_writer::link($url, html_writer::empty_tag('img', array('src' => $this->output->pix_url('t/edit'), 'class' => 'iconsmall edit')), array('title' => get_string('editsummary'))); @@ -560,10 +556,10 @@ abstract class format_section_renderer_base extends plugin_renderer_base { $thissection = $sections[0]; if ($thissection->summary or $thissection->sequence or $PAGE->user_is_editing()) { echo $this->start_section_list(); - echo $this->section_header($thissection, $course, true); - print_section($course, $thissection, $mods, $modnamesused, true); + echo $this->section_header($thissection, $course, true, $displaysection); + print_section($course, $thissection, $mods, $modnamesused, true, "100%", false, $displaysection); if ($PAGE->user_is_editing()) { - print_section_add_menus($course, 0, $modnames, false, false, true); + print_section_add_menus($course, 0, $modnames, false, false, $displaysection); } echo $this->section_footer(); echo $this->end_section_list(); @@ -592,14 +588,14 @@ abstract class format_section_renderer_base extends plugin_renderer_base { // The requested section page. $thissection = $sections[$displaysection]; - echo $this->section_header($thissection, $course, true); + echo $this->section_header($thissection, $course, true, $displaysection); // Show completion help icon. $completioninfo = new completion_info($course); echo $completioninfo->display_help_icon(); - print_section($course, $thissection, $mods, $modnamesused, true, '100%', false, true); + print_section($course, $thissection, $mods, $modnamesused, true, '100%', false, $displaysection); if ($PAGE->user_is_editing()) { - print_section_add_menus($course, $displaysection, $modnames, false, false, true); + print_section_add_menus($course, $displaysection, $modnames, false, false, $displaysection); } echo $this->section_footer(); echo $this->end_section_list(); diff --git a/course/lib.php b/course/lib.php index 0376a3a14ae..3a2e3ad282f 100644 --- a/course/lib.php +++ b/course/lib.php @@ -1376,8 +1376,9 @@ function get_print_section_cm_text(cm_info $cm, $course) { /** * Prints a section full of activity modules + * @param int $sectionreturn The section to return to */ -function print_section($course, $section, $mods, $modnamesused, $absolute=false, $width="100%", $hidecompletion=false, $sectionreturn = false) { +function print_section($course, $section, $mods, $modnamesused, $absolute=false, $width="100%", $hidecompletion=false, $sectionreturn=0) { global $CFG, $USER, $DB, $PAGE, $OUTPUT; static $initialised; @@ -1637,12 +1638,7 @@ function print_section($course, $section, $mods, $modnamesused, $absolute=false, $mod->groupmode = false; } echo '  '; - - if ($sectionreturn) { - echo make_editing_buttons($mod, $absolute, true, $mod->indent, $section->section); - } else { - echo make_editing_buttons($mod, $absolute, true, $mod->indent, 0); - } + echo make_editing_buttons($mod, $absolute, true, $mod->indent, $sectionreturn); echo $mod->get_after_edit_icons(); } @@ -1761,8 +1757,9 @@ function print_section($course, $section, $mods, $modnamesused, $absolute=false, /** * Prints the menus to add activities and resources. + * @param int $sectionreturn The section to link back to */ -function print_section_add_menus($course, $section, $modnames, $vertical=false, $return=false, $sectionreturn = false) { +function print_section_add_menus($course, $section, $modnames, $vertical=false, $return=false, $sectionreturn=0) { global $CFG, $OUTPUT; // check to see if user can add menus @@ -1778,14 +1775,7 @@ function print_section_add_menus($course, $section, $modnames, $vertical=false, $activities = array(); // We need to add the section section to the link for each module - $sectionlink = '§ion=' . $section; - - // We need to add the section to return to - if ($sectionreturn) { - $sectionreturnlink = '&sr=' . $section; - } else { - $sectionreturnlink = '&sr=0'; - } + $sectionlink = '§ion=' . $section . '&sr=' . $sectionreturn; foreach ($modules as $module) { if (isset($module->types)) { @@ -1793,7 +1783,7 @@ function print_section_add_menus($course, $section, $modnames, $vertical=false, // NOTE: this is legacy stuff, module subtypes are very strongly discouraged!! $subtypes = array(); foreach ($module->types as $subtype) { - $subtypes[$subtype->link . $sectionlink . $sectionreturnlink] = $subtype->title; + $subtypes[$subtype->link . $sectionlink] = $subtype->title; } // Sort module subtypes into the list @@ -1815,11 +1805,11 @@ function print_section_add_menus($course, $section, $modnames, $vertical=false, } else { // This module has no subtypes if ($module->archetype == MOD_ARCHETYPE_RESOURCE) { - $resources[$module->link . $sectionlink . $sectionreturnlink] = $module->title; + $resources[$module->link . $sectionlink] = $module->title; } else if ($module->archetype === MOD_ARCHETYPE_SYSTEM) { // System modules cannot be added by user, do not add to dropdown } else { - $activities[$module->link . $sectionlink . $sectionreturnlink] = $module->title; + $activities[$module->link . $sectionlink] = $module->title; } } }