Index: course/modedit.php =================================================================== RCS file: /cvsroot/moodle/moodle/course/modedit.php,v retrieving revision 1.34.2.12 diff -u -r1.34.2.12 modedit.php --- course/modedit.php 21 Jul 2008 11:46:00 -0000 1.34.2.12 +++ course/modedit.php 3 Dec 2009 06:03:08 -0000 @@ -194,14 +194,18 @@ redirect("view.php?id=$course->id#section-".$cw->section); } } else if ($fromform = $mform->get_data()) { - if (empty($fromform->coursemodule)) { //add + $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) { $cm = null; if (! $course = get_record("course", "id", $fromform->course)) { error("This course doesn't exist"); } $fromform->instance = ''; $fromform->coursemodule = ''; - } else { //update + } else { if (! $cm = get_record("course_modules", "id", $fromform->coursemodule)) { error("This course module doesn't exist"); } @@ -215,7 +219,7 @@ require_login($course->id); // needed to setup proper $COURSE - if (!empty($fromform->coursemodule)) { + if ($isupdating) { $context = get_context_instance(CONTEXT_MODULE, $fromform->coursemodule); } else { $context = get_context_instance(CONTEXT_COURSE, $course->id); @@ -240,7 +244,7 @@ $fromform->name = $fromform->modulename; } - if (!empty($fromform->update)) { + if ($isupdating) { if (!empty($course->groupmodeforce) or !isset($fromform->groupmode)) { $fromform->groupmode = $cm->groupmode; // keep original @@ -271,7 +275,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 @@ -414,10 +418,18 @@ 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; Index: course/moodleform_mod.php =================================================================== RCS file: /cvsroot/moodle/moodle/course/moodleform_mod.php,v retrieving revision 1.18.2.12 diff -u -r1.18.2.12 moodleform_mod.php --- course/moodleform_mod.php 13 Oct 2008 22:42:24 -0000 1.18.2.12 +++ course/moodleform_mod.php 3 Dec 2009 05:54:24 -0000 @@ -97,6 +97,18 @@ } } } + + /* + * 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() == '')) { + $button->setValue(get_string('saveasnewobject', '', strtolower($modulename))); + } + } } if ($COURSE->groupmodeforce) { @@ -313,12 +325,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'); + 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('savechanges'); + } } $mform =& $this->_form; Index: lang/en_utf8/moodle.php =================================================================== RCS file: /cvsroot/moodle/moodle/lang/en_utf8/moodle.php,v retrieving revision 1.141.2.70 diff -u -r1.141.2.70 moodle.php --- lang/en_utf8/moodle.php 21 Oct 2009 07:51:41 -0000 1.141.2.70 +++ lang/en_utf8/moodle.php 19 Nov 2009 06:44:34 -0000 @@ -1318,6 +1318,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';