diff --git a/course/category.php b/course/category.php
index 35dd01b692a..a7c857826e2 100644
--- a/course/category.php
+++ b/course/category.php
@@ -321,7 +321,8 @@
if ($editingon) {
echo '
';
if (has_capability('moodle/course:update', $coursecontext)) {
- echo ''.
+ $url = new moodle_url($CFG->wwwroot.'/course/edit.php' , array('id'=>$acourse->id, 'category'=>$id,'returnto'=>'category'));
+ echo ''.
' ';
} else {
echo $spacer;
@@ -441,6 +442,7 @@
/// Print button to create a new course
unset($options);
$options['category'] = $category->id;
+ $options['returnto'] = 'category';
echo $OUTPUT->single_button(new moodle_url('edit.php', $options), get_string('addnewcourse'), 'get');
}
diff --git a/course/edit.php b/course/edit.php
index d095f07179b..e5f55500b71 100644
--- a/course/edit.php
+++ b/course/edit.php
@@ -29,6 +29,7 @@ require_once('edit_form.php');
$id = optional_param('id', 0, PARAM_INT); // course id
$categoryid = optional_param('category', 0, PARAM_INT); // course category - can be changed in edit form
+$returnto = optional_param('returnto', 0, PARAM_ALPHANUM); // generic navigation return page switch
$PAGE->set_pagelayout('admin');
$PAGE->set_url('/course/edit.php');
@@ -81,15 +82,25 @@ if (!empty($course)) {
}
// first create the form
-$editform = new course_edit_form(NULL, array('course'=>$course, 'category'=>$category, 'editoroptions'=>$editoroptions));
-
+$editform = new course_edit_form(NULL, array('course'=>$course, 'category'=>$category, 'editoroptions'=>$editoroptions, 'returnto'=>$returnto));
if ($editform->is_cancelled()) {
- if (empty($course->id)) {
- redirect($CFG->wwwroot.'/course');
- } else {
- redirect($CFG->wwwroot.'/course/view.php?id='.$course->id);
- }
-
+ switch ($returnto) {
+ case 'category':
+ $url = new moodle_url($CFG->wwwroot.'/course/category.php', array('id'=>$categoryid));
+ break;
+ case 'topcat':
+ $url = new moodle_url($CFG->wwwroot.'/course/');
+ break;
+ default:
+ if (!empty($course->id)) {
+ $url = new moodle_url($CFG->wwwroot.'/course/view.php', array('id'=>$course->id));
+ } else {
+ $url = new moodle_url($CFG->wwwroot.'/course/');
+ }
+ break;
+ }
+ redirect($url);
+
} else if ($data = $editform->get_data()) {
// process data if submitted
@@ -110,18 +121,25 @@ if ($editform->is_cancelled()) {
foreach($instances as $instance) {
if ($plugin = enrol_get_plugin($instance->enrol)) {
if ($link = $plugin->get_manual_enrol_link($instance)) {
- redirect($link);
+ redirect($link, get_string('changessaved'));
}
}
}
-
- redirect($CFG->wwwroot."/course/view.php?id=$course->id");
-
} else {
// Save any changes to the files used in the editor
update_course($data, $editoroptions);
- redirect($CFG->wwwroot."/course/view.php?id=$course->id");
}
+
+ switch ($returnto) {
+ case 'category':
+ case 'topcat': //redirecting to where the new course was created by default.
+ $url = new moodle_url($CFG->wwwroot.'/course/category.php', array('id'=>$categoryid));
+ break;
+ default:
+ $url = new moodle_url($CFG->wwwroot.'/course/view.php', array('id'=>$course->id));
+ break;
+ }
+ redirect($url, get_string('changessaved'));
}
diff --git a/course/edit_form.php b/course/edit_form.php
index c37d99d0bd4..cac6cd11d80 100644
--- a/course/edit_form.php
+++ b/course/edit_form.php
@@ -16,6 +16,7 @@ class course_edit_form extends moodleform {
$course = $this->_customdata['course']; // this contains the data of this form
$category = $this->_customdata['category'];
$editoroptions = $this->_customdata['editoroptions'];
+ $returnto = $this->_customdata['returnto'];
$systemcontext = get_context_instance(CONTEXT_SYSTEM);
$categorycontext = get_context_instance(CONTEXT_COURSECAT, $category->id);
@@ -37,6 +38,10 @@ class course_edit_form extends moodleform {
//--------------------------------------------------------------------------------
$mform->addElement('header','general', get_string('general', 'form'));
+ $mform->addElement('hidden', 'returnto', null);
+ $mform->setType('returnto', PARAM_ALPHANUM);
+ $mform->setConstant('returnto', $returnto);
+
// verify permissions to change course category or keep current
if (empty($course->id)) {
if (has_capability('moodle/course:create', $categorycontext)) {
diff --git a/course/index.php b/course/index.php
index 7725b299e56..e23a71a2199 100644
--- a/course/index.php
+++ b/course/index.php
@@ -267,6 +267,7 @@ echo '';
if (has_capability('moodle/course:create', $systemcontext)) {
// print create course link to first category
$options = array('category' => $CFG->defaultrequestcategory);
+ $options['returnto'] = 'topcat';
echo $OUTPUT->single_button(new moodle_url('edit.php', $options), get_string('addnewcourse'), 'get');
}
|