# This patch file was generated by NetBeans IDE
# This patch can be applied using context Tools: Apply Diff Patch action on respective folder.
# It uses platform neutral UTF-8 encoding.
# Above lines and this line are ignored by the patching process.
Index: moodle/course/category.php
--- moodle/course/category.php Base (1.183)
+++ moodle/course/category.php Locally Modified (Based On 1.183)
@@ -321,7 +321,8 @@
             if ($editingon) {
                 echo '<td>';
                 if (has_capability('moodle/course:update', $coursecontext)) {
-                    echo '<a title="'.$strsettings.'" href="'.$CFG->wwwroot.'/course/edit.php?id='.$acourse->id.'">'.
+                    $url = new moodle_url($CFG->wwwroot.'/course/edit.php' , array('id'=>$acourse->id, 'returnto'=>'category'));
+                    echo '<a title="'.$strsettings.'" href="'.$url->out(true). '">'.
                             '<img src="'.$OUTPUT->pix_url('t/edit') . '" class="iconsmall" alt="'.$stredit.'" /></a> ';
                 } else {
                     echo $spacer;
Index: moodle/course/edit.php
--- moodle/course/edit.php Base (1.133)
+++ moodle/course/edit.php Locally Modified (Based On 1.133)
@@ -29,6 +29,7 @@
 
 $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,13 +82,13 @@
 }
 
 // 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);
+        navigate_back($returnto, $course);
     }
 
 } else if ($data = $editform->get_data()) {
@@ -110,20 +111,36 @@
         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");
     }
+    navigate_back($returnto, $course, get_string('changessaved'));
 }
 
+/**
+ * This centralises the return navigation for this page depending on what the return switch is set to
+ * @global <type> $CFG
+ * @param <type> $returnto a switch to route the return navigation path.
+ * @param <type> $params
+ * @param <type> $message
+ */
+function navigate_back($returnto, $params, $message=null) {
+    global $CFG;
+    switch ($returnto) {
+        case 'category':
+            $url = new moodle_url($CFG->wwwroot.'/course/category.php', array('id'=>$params->category));
+            break;
+        default:
+            $url = new moodle_url($CFG->wwwroot.'/course/view.php', array('id'=>$params->id));
+            break;
+    }
+    redirect($url, $message);
+}
 
 // Print the form
 
Index: moodle/course/edit_form.php
--- moodle/course/edit_form.php Base (1.86)
+++ moodle/course/edit_form.php Locally Modified (Based On 1.86)
@@ -16,6 +16,7 @@
         $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 @@
 //--------------------------------------------------------------------------------
         $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)) {
