diff --git a/course/editsection.php b/course/editsection.php index e9a065b5fdf..cd0db0a14a8 100644 --- a/course/editsection.php +++ b/course/editsection.php @@ -47,7 +47,7 @@ $mform->set_data($section); // set current value /// If data submitted, then process and store. if ($mform->is_cancelled()){ - redirect($CFG->wwwroot.'/course/view.php?id='.$course->id); + redirect(course_get_url($course, $section->section)); } else if ($data = $mform->get_data()) { if (empty($data->usedefaultname)) { @@ -61,7 +61,7 @@ if ($mform->is_cancelled()){ $DB->update_record('course_sections', $section); add_to_log($course->id, "course", "editsection", "editsection.php?id=$section->id", "$section->section"); $PAGE->navigation->clear_cache(); - redirect("view.php?id=$course->id"); + redirect(course_get_url($course, $section->section)); } $sectionname = get_section_name($course, $section); diff --git a/course/lib.php b/course/lib.php index b5544c94326..f9dcab0fb47 100644 --- a/course/lib.php +++ b/course/lib.php @@ -4512,3 +4512,24 @@ function include_course_ajax($course, $modules = array(), $config = null) { $PAGE->requires->string_for_js('pluginname', $module); } } + +/** + * The URL to use for the specified course (with section) + * + * @param stdClass $course The course to get the section name for + * @param int $sectionno The section number to return a link to + * @return moodle_url The url of course + */ +function course_get_url($course, $sectionno = null) { + $url = new moodle_url('/course/view.php', array('id' => $course->id)); + + if (!is_null($sectionno)) { + if ($course->coursedisplay == COURSE_DISPLAY_MULTIPAGE) { + $url->param('section', $sectionno); + } else { + $url->set_anchor('section-'.$sectionno); + } + } + + return $url; +} diff --git a/course/mod.php b/course/mod.php index 365c7e65182..6c22915877b 100644 --- a/course/mod.php +++ b/course/mod.php @@ -108,7 +108,7 @@ if (!empty($add)) { get_string('continue'), 'post'), new single_button( - new moodle_url('/course/view.php#section-' . $cm->sectionnum, array('id' => $cm->course)), + course_get_url($course, $cm->sectionnum), get_string('cancel'), 'get') ); @@ -125,7 +125,7 @@ if (!empty($add)) { $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id); require_capability('moodle/course:manageactivities', $modcontext); - $return = "$CFG->wwwroot/course/view.php?id=$cm->course#section-$cm->sectionnum"; + $return = course_get_url($course, $cm->sectionnum); if (!$confirm or !confirm_sesskey()) { $fullmodulename = get_string('modulename', $cm->modname); @@ -235,7 +235,7 @@ if ((!empty($movetosection) or !empty($moveto)) and confirm_sesskey()) { if (SITEID == $section->course) { redirect($CFG->wwwroot); } else { - redirect("view.php?id=$section->course#section-$sectionreturn"); + redirect(course_get_url($course, $sectionreturn)); } } else if (!empty($indent) and confirm_sesskey()) { @@ -262,7 +262,7 @@ if ((!empty($movetosection) or !empty($moveto)) and confirm_sesskey()) { if (SITEID == $cm->course) { redirect($CFG->wwwroot); } else { - redirect("view.php?id=$cm->course#section-$cm->sectionnum"); + redirect(course_get_url($course, $cm->sectionnum)); } } else if (!empty($hide) and confirm_sesskey()) { @@ -281,7 +281,7 @@ if ((!empty($movetosection) or !empty($moveto)) and confirm_sesskey()) { if (SITEID == $cm->course) { redirect($CFG->wwwroot); } else { - redirect("view.php?id=$cm->course#section-$cm->sectionnum"); + redirect(course_get_url($course, $cm->sectionnum)); } } else if (!empty($show) and confirm_sesskey()) { @@ -305,7 +305,7 @@ if ((!empty($movetosection) or !empty($moveto)) and confirm_sesskey()) { if (SITEID == $cm->course) { redirect($CFG->wwwroot); } else { - redirect("view.php?id=$cm->course#section-$cm->sectionnum"); + redirect(course_get_url($course, $cm->sectionnum)); } } else if ($groupmode > -1 and confirm_sesskey()) { @@ -326,7 +326,7 @@ if ((!empty($movetosection) or !empty($moveto)) and confirm_sesskey()) { if (SITEID == $cm->course) { redirect($CFG->wwwroot); } else { - redirect("view.php?id=$cm->course#section-$cm->sectionnum"); + redirect(course_get_url($course, $cm->sectionnum)); } } else if (!empty($copy) and confirm_sesskey()) { // value = course module @@ -344,7 +344,7 @@ if ((!empty($movetosection) or !empty($moveto)) and confirm_sesskey()) { $USER->activitycopycourse = $cm->course; $USER->activitycopyname = $cm->name; - redirect("view.php?id=$cm->course#section-$sectionreturn"); + redirect(course_get_url($course, $sectionreturn)); } else if (!empty($cancelcopy) and confirm_sesskey()) { // value = course module diff --git a/course/modedit.php b/course/modedit.php index 63ea832c487..b9bf127826d 100644 --- a/course/modedit.php +++ b/course/modedit.php @@ -260,7 +260,7 @@ if ($mform->is_cancelled()) { if ($return && !empty($cm->id)) { redirect("$CFG->wwwroot/mod/$module->name/view.php?id=$cm->id"); } else { - redirect("$CFG->wwwroot/course/view.php?id=$course->id#section-".$cw->section); + redirect(course_get_url($course, $cw->section)); } } else if ($fromform = $mform->get_data()) { if (empty($fromform->coursemodule)) { @@ -364,7 +364,7 @@ if ($mform->is_cancelled()) { } if (!$updateinstancefunction($fromform, $mform)) { - print_error('cannotupdatemod', '', "view.php?id={$course->id}#section-{$cw->section}", $fromform->modulename); + print_error('cannotupdatemod', '', course_get_url($course, $cw->section), $fromform->modulename); } // make sure visibility is set correctly (in particular in calendar) @@ -449,9 +449,9 @@ if ($mform->is_cancelled()) { $DB->delete_records('course_modules', array('id'=>$fromform->coursemodule)); if (!is_number($returnfromfunc)) { - print_error('invalidfunction', '', "view.php?id={$course->id}#section-{$cw->section}"); + print_error('invalidfunction', '', course_get_url($course, $cw->section)); } else { - print_error('cannotaddnewmodule', '', "view.php?id={$course->id}#section-{$cw->section}", $fromform->modulename); + print_error('cannotaddnewmodule', '', course_get_url($course, $cw->section), $fromform->modulename); } } @@ -629,7 +629,7 @@ if ($mform->is_cancelled()) { redirect($gradingman->get_management_url($returnurl)); } } else { - redirect("$CFG->wwwroot/course/view.php?id={$course->id}#section-{$cw->section}"); + redirect(course_get_url($course, $cw->section)); } exit;