Index: course/modedit.php =================================================================== RCS file: /cvsroot/moodle/moodle/course/modedit.php,v retrieving revision 1.90 diff -u -r1.90 modedit.php --- course/modedit.php 1 Feb 2010 07:49:33 -0000 1.90 +++ course/modedit.php 24 Feb 2010 07:54:46 -0000 @@ -257,8 +257,12 @@ } } else if ($fromform = $mform->get_data()) { - if (empty($fromform->coursemodule)) { //add - $cm = null; + $isupdateform = !empty($fromform->coursemodule); + // We are updating an activity only if we are in updating form and "Save" button pressed + $isupdating = $isupdateform && !isset($fromform->submitbutton); + + if (!$isupdating) { //add + $cm = null; if (!$course = $DB->get_record('course', array('id'=>$fromform->course))) { print_error('invalidcourseid'); } @@ -277,7 +281,7 @@ } - if (!empty($fromform->coursemodule)) { + if ($isupdating) { $context = get_context_instance(CONTEXT_MODULE, $fromform->coursemodule); } else { $context = get_context_instance(CONTEXT_COURSE, $course->id); @@ -314,7 +318,7 @@ isset($fromform->completionusegrade) && $fromform->completionusegrade ? 0 : null; - if (!empty($fromform->update)) { + if ($isupdating) { if (!empty($course->groupmodeforce) or !isset($fromform->groupmode)) { $fromform->groupmode = $cm->groupmode; // keep original @@ -384,7 +388,7 @@ "view.php?id=$fromform->coursemodule", "$fromform->instance", $fromform->coursemodule); - } else if (!empty($fromform->add)) { + } else if (!$isupdating) { if (!empty($course->groupmodeforce) or !isset($fromform->groupmode)) { $fromform->groupmode = 0; // do not set groupmode @@ -581,13 +585,20 @@ rebuild_course_cache($course->id); grade_regrade_final_grades($course->id); - if (isset($fromform->submitbutton)) { - redirect("$CFG->wwwroot/mod/$module->name/view.php?id=$fromform->coursemodule"); - } else { - redirect("$CFG->wwwroot/course/view.php?id=$course->id"); + if (!$isupdateform) {//add + if (isset($fromform->submitbutton)) { + redirect("$CFG->wwwroot/mod/$module->name/view.php?id=$fromform->coursemodule"); + } else { + redirect("$CFG->wwwroot/course/view.php?id=$course->id#section-".$fromform->section); + } + } else {//update + if ($return) { + redirect("$CFG->wwwroot/mod/$module->name/view.php?id=$fromform->coursemodule"); + } else { + redirect("$CFG->wwwroot/course/view.php?id=$course->id#section-".$fromform->section); + } } exit; - } else { if (!empty($cm->id)) { $context = get_context_instance(CONTEXT_MODULE, $cm->id); Index: course/moodleform_mod.php =================================================================== RCS file: /cvsroot/moodle/moodle/course/moodleform_mod.php,v retrieving revision 1.53 diff -u -r1.53 moodleform_mod.php --- course/moodleform_mod.php 4 Nov 2009 08:11:03 -0000 1.53 +++ course/moodleform_mod.php 5 Mar 2010 21:12:24 -0000 @@ -144,6 +144,19 @@ } } } + + /* + * If activity is updating, it is necessary to change the label + * on "Save as new" button, because now we know the name of activity. + * As examlpe, the label on "Save as new" button will be "Save as new quiz" + */ + $actionbuttons = $mform->getElement('buttonar')->getElements(); + foreach ($actionbuttons as $button) { + if (($button->getName() == 'submitbutton') && ($button->getValue() == '')) { + $activity_name = strtolower(get_string('modulename',$this->_modname)); + $button->setValue(get_string('saveasnewobject', '', $activity_name)); + } + } } if ($COURSE->groupmodeforce) { @@ -609,12 +622,35 @@ * @return void */ function add_action_buttons($cancel=true, $submitlabel=null, $submit2label=null) { - if (is_null($submitlabel)) { - $submitlabel = get_string('savechangesanddisplay'); - } + /* + * When we adding some course activity + * we need buttons "Save and display" and "Save and return to course" + */ + if ($this->_instance === '') { + if (is_null($submitlabel)) { + $submitlabel = get_string('savechangesanddisplay'); + } + + if (is_null($submit2label)) { + $submit2label = get_string('savechangesandreturntocourse'); + } + /* + * Otherwise if it is updating of existing course activity there are + * should be another buttons: "Save changes" and "Save as new activity_name" + */ + } else { + if (is_null($submitlabel)) { + /* + * There is no way to determine activity name here, + * so we will set label on this button later + * in function definition_after_data() + */ + $submitlabel = ''; + } - if (is_null($submit2label)) { - $submit2label = get_string('savechangesandreturntocourse'); + if (is_null($submit2label)) { + $submit2label = get_string('savechanges'); + } } $mform = $this->_form; Index: lang/en_utf8/moodle.php =================================================================== RCS file: /cvsroot/moodle/moodle/lang/en_utf8/moodle.php,v retrieving revision 1.279 diff -u -r1.279 moodle.php --- lang/en_utf8/moodle.php 24 Feb 2010 10:53:59 -0000 1.279 +++ lang/en_utf8/moodle.php 5 Mar 2010 21:26:42 -0000 @@ -1414,6 +1414,7 @@ $string['rsserror'] = 'Error reading RSS data'; $string['rsstype'] = 'RSS feed for this activity'; $string['saveandnext'] = 'Save and show next'; +$string['saveasnewobject'] = 'Save as new $a'; $string['savechanges'] = 'Save changes'; $string['savechangesanddisplay'] = 'Save and display'; $string['savechangesandreturntocourse'] = 'Save and return to course';