Index: course/lib.php
===================================================================
RCS file: /cvsroot/moodle/moodle/course/lib.php,v
retrieving revision 1.720
diff -u -p -r1.720 lib.php
--- course/lib.php 25 Feb 2010 10:17:46 -0000 1.720
+++ course/lib.php 12 Mar 2010 09:27:24 -0000
@@ -2813,6 +2813,7 @@ function make_editing_buttons($mod, $abs
if (!isset($str)) {
$str->assign = get_string("assignroles", 'role');
+ $str->copy = get_string("copy");
$str->delete = get_string("delete");
$str->move = get_string("move");
$str->moveup = get_string("moveup");
@@ -2945,6 +2946,10 @@ function make_editing_buttons($mod, $abs
'&sesskey='.$sesskey.$section.'">
'."\n".
+ '
'."\n".
'
wwwroot/course/modedit.php?update=$update&return=$returntomod");
+ $saveasnew = optional_param('saveasnew', 0, PARAM_BOOL);
+ if (!empty($saveasnew)) {
+ redirect("$CFG->wwwroot/course/modedit.php?update=$update&saveasnew=1&return=$returntomod");
+ } else {
+ redirect("$CFG->wwwroot/course/modedit.php?update=$update&return=$returntomod");
+ }
} else if (!empty($delete)) {
if (!$cm = get_coursemodule_from_id('', $delete, 0, true)) {
Index: course/modedit.php
===================================================================
RCS file: /cvsroot/moodle/moodle/course/modedit.php,v
retrieving revision 1.90
diff -u -p -r1.90 modedit.php
--- course/modedit.php 1 Feb 2010 07:49:33 -0000 1.90
+++ course/modedit.php 12 Mar 2010 09:27:24 -0000
@@ -34,6 +34,7 @@
$update = optional_param('update', 0, PARAM_INT);
$return = optional_param('return', 0, PARAM_BOOL); //return to course/view.php if false or mod/modname/view.php if true
$type = optional_param('type', '', PARAM_ALPHANUM); //TODO: hopefully will be removed in 2.0
+ $saveasnew = optional_param('saveasnew', 0, PARAM_BOOL);
$url = new moodle_url('/course/modedit.php');
if (!empty($add)) {
@@ -212,6 +213,11 @@
$heading->what = $fullmodulename;
$heading->in = "$sectionname $cw->section";
$pageheading = get_string('updatingain', 'moodle', $heading);
+ } else if(!empty($saveasnew)) {
+ $heading = new object();
+ $heading->what = "$fullmodulename";
+ $heading->in = "$sectionname $cw->section";
+ $pageheading = get_string('copyingain', 'moodle', $heading);
} else {
$pageheading = get_string('updatinga', 'moodle', $fullmodulename);
}
@@ -246,7 +252,7 @@
}
$mformclassname = 'mod_'.$module->name.'_mod_form';
- $mform = new $mformclassname($data, $cw->section, $cm, $course);
+ $mform = new $mformclassname($data, $cw->section, $cm, $course, array('saveasnew'=>$saveasnew));
$mform->set_data($data);
if ($mform->is_cancelled()) {
@@ -257,7 +263,11 @@
}
} 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) { //add
$cm = null;
if (!$course = $DB->get_record('course', array('id'=>$fromform->course))) {
print_error('invalidcourseid');
@@ -276,8 +286,7 @@
$fromform->coursemodule = $cm->id;
}
-
- 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 +323,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 +393,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,10 +590,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.53
diff -u -p -r1.53 moodleform_mod.php
--- course/moodleform_mod.php 4 Nov 2009 08:11:03 -0000 1.53
+++ course/moodleform_mod.php 12 Mar 2010 09:27:25 -0000
@@ -48,8 +48,9 @@ abstract class moodleform_mod extends mo
protected $_modname;
/** current context, course or module depends if already exists*/
protected $context;
+ protected $_options = array('saveasnew'=>false);
- function moodleform_mod($current, $section, $cm, $course) {
+ function moodleform_mod($current, $section, $cm, $course, $options = null) {
$this->current = $current;
$this->_instance = $current->instance;
$this->_section = $section;
@@ -59,6 +60,12 @@ abstract class moodleform_mod extends mo
} else {
$this->context = get_context_instance(CONTEXT_COURSE, $course->id);
}
+ $options = (array)$options;
+ foreach ($options as $name=>$value) {
+ if (array_key_exists($name, $this->_options)) {
+ $this->_options[$name] = $value;
+ }
+ }
// Guess module name
$matches = array();
@@ -144,6 +151,18 @@ abstract class moodleform_mod extends mo
}
}
}
+
+ /*
+ * 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() == 'saveasnew')) {
+ $button->setValue(get_string('saveasnewobject', '', strtolower(get_string('modulename',$this->_modname))));
+ }
+ }
}
if ($COURSE->groupmodeforce) {
@@ -609,25 +628,49 @@ abstract class moodleform_mod extends mo
* @return void
*/
function add_action_buttons($cancel=true, $submitlabel=null, $submit2label=null) {
- if (is_null($submitlabel)) {
- $submitlabel = get_string('savechangesanddisplay');
- }
-
- if (is_null($submit2label)) {
- $submit2label = get_string('savechangesandreturntocourse');
- }
$mform = $this->_form;
-
// elements in a row need a group
$buttonarray = array();
- if ($submit2label !== false) {
- $buttonarray[] = &$mform->createElement('submit', 'submitbutton2', $submit2label);
- }
+ /*
+ * When we adding some course activity
+ * we need buttons "Save and display" and "Save and return to course"
+ */
+ if ($this->_instance === '') {
+ // create a module instance
+ if (is_null($submitlabel)) {
+ $saveanddisplay = get_string('savechangesanddisplay');
+ }
- if ($submitlabel !== false) {
- $buttonarray[] = &$mform->createElement('submit', 'submitbutton', $submitlabel);
+ if (is_null($submit2label)) {
+ $saveandreturn = get_string('savechangesandreturntocourse');
+ }
+ $buttonarray[] = &$mform->createElement('submit', 'submitbutton2', $saveandreturn);
+ $buttonarray[] = &$mform->createElement('submit', 'submitbutton', $saveanddisplay);
+
+ } else {
+ /*
+ * Otherwise if it is updating of existing course activity there are
+ * should be another buttons: "Save changes" and "Save as new activity_name"
+ */
+ 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 = 'saveasnew';
+ }
+ if (is_null($submit2label)) {
+ $submit2label = get_string('savechanges');
+ }
+ if (!empty($this->_options['saveasnew'])) {
+ $buttonarray[] = &$mform->createElement('submit', 'submitbutton', $submitlabel);
+ } else {
+ $buttonarray[] = &$mform->createElement('submit', 'submitbutton2', $submit2label);
+ $buttonarray[] = &$mform->createElement('submit', 'submitbutton', 'saveasnew');
+ }
}
if ($cancel) {
@@ -639,5 +682,3 @@ abstract class moodleform_mod extends mo
$mform->closeHeaderBefore('buttonar');
}
}
-
-
Index: lang/en_utf8/moodle.php
===================================================================
RCS file: /cvsroot/moodle/moodle/lang/en_utf8/moodle.php,v
retrieving revision 1.280
diff -u -p -r1.280 moodle.php
--- lang/en_utf8/moodle.php 9 Mar 2010 21:42:38 -0000 1.280
+++ lang/en_utf8/moodle.php 12 Mar 2010 09:27:25 -0000
@@ -268,6 +268,7 @@ $string['cookiesenabled'] = 'Cookies mus
$string['cookiesnotenabled'] = 'Unfortunately, cookies are currently not enabled in your browser';
$string['copy'] = 'copy';
$string['copyasnoun'] = 'copy';
+$string['copyingain'] = 'Copying a $a->what in $a->in';
$string['copyingcoursefiles'] = 'Copying course files';
$string['copyingsitefiles'] = 'Copying site files used in course';
$string['copyinguserfiles'] = 'Copying user files';
@@ -1414,6 +1415,7 @@ $string['rssarticles'] = 'Number of RSS
$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';