]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-6826 New button added!
authornicolasconnault <nicolasconnault>
Wed, 23 Jan 2008 12:56:13 +0000 (12:56 +0000)
committernicolasconnault <nicolasconnault>
Wed, 23 Jan 2008 12:56:13 +0000 (12:56 +0000)
course/modedit.php
course/moodleform_mod.php
lang/en_utf8/moodle.php

index bee718346f5cf5a3ed0bc5f8895a903729b9b712..6336753a0eee9caf1be604c472c67bf6f3cb7734 100644 (file)
@@ -12,6 +12,8 @@
     $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);
+    $submitbutton  = optional_param('submitbutton', null, PARAM_ALPHANUM);
+    $submitbutton2 = optional_param('submitbutton2', null, PARAM_ALPHANUM);
 
     if (!empty($add)) {
         $section = required_param('section', PARAM_INT);
 
         rebuild_course_cache($course->id);
 
+        if ($submitbutton) {
         redirect("$CFG->wwwroot/mod/$module->name/view.php?id=$fromform->coursemodule");
+        } elseif ($submitbutton2) { 
+            redirect("$CFG->wwwroot/course/view.php?id=$course->id");
+        }
         exit;
 
     } else {
index 82a66b3ac4350532cbb6c59a701dc81e6c392ecf..9553bc01791d9ead9649f1b9a5e786446041692c 100644 (file)
@@ -2,7 +2,7 @@
 require_once ($CFG->libdir.'/formslib.php');
 /**
  * This class adds extra methods to form wrapper specific to be used for module
- * add / update forms (mod/{modname}.mod_form.php replaces deprecared mod/{modname}/mod.html
+ * add / update forms (mod/{modname}.mod_form.php replaces deprecated mod/{modname}/mod.html
  *
  */
 class moodleform_mod extends moodleform {
@@ -294,6 +294,37 @@ class moodleform_mod extends moodleform {
         $mform->setType('return', PARAM_BOOL);
     }
 
+    /**
+     * Overriding formslib's add_action_buttons() method, to add an extra submit "save changes and return" button.
+     * 
+     * @param bool $cancel
+     * @param string $submitlabel
+     * @param string $submit2label
+     * @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;
+        
+        //when two elements we need a group
+        $buttonarray=array();
+        $buttonarray[] = &$mform->createElement('submit', 'submitbutton', $submitlabel);
+        $buttonarray[] = &$mform->createElement('submit', 'submitbutton2', $submit2label);
+        
+        if ($cancel) {
+            $buttonarray[] = &$mform->createElement('cancel');
+        }
+
+        $mform->addGroup($buttonarray, 'buttonar', '', array(' '), false);
+        $mform->closeHeaderBefore('buttonar');
+    }
 }
 
 ?>
index c193a6183c456d232a6e5c2a2ec17522a76db412..a71cb0bd13d4abcdd41f894cae25efa87da5637b 100644 (file)
@@ -1258,6 +1258,8 @@ $string['rsserror'] = 'Error reading RSS data';
 $string['rsstype'] = 'RSS feed for this activity';
 $string['saveandnext'] = 'Save and show next';
 $string['savechanges'] = 'Save changes';
+$string['savechangesanddisplay'] = 'Save changes and display';
+$string['savechangesandreturntocourse'] = 'Save changes and return to course';
 $string['savedat'] = 'Saved at:';
 $string['savepreferences'] = 'Save preferences';
 $string['saveto'] = 'Save to';