]> git.mjollnir.org Git - moodle.git/commitdiff
* Added setAdvanced functionality see http://docs.moodle.org/en/Development:lib/forms...
authorjamiesensei <jamiesensei>
Tue, 19 Dec 2006 07:03:08 +0000 (07:03 +0000)
committerjamiesensei <jamiesensei>
Tue, 19 Dec 2006 07:03:08 +0000 (07:03 +0000)
* Added MoodleQuickForm method closeHeaderBefore($elementName); http://docs.moodle.org/en/Development:lib/formslib.php_Form_Definition#Use_Fieldsets_to_group_Form_Elements
* Added moodleform method add_action_buttons(); see http://docs.moodle.org/en/Development:lib/formslib.php_Form_Definition#add_action_buttons.28.24cancel_.3D_true.2C_.24revert_.3D_true.2C_.24submitlabel.3Dnull.29.3B
* is_cancelled method added to moodleform http://docs.moodle.org/en/Development:lib/formslib.php_Usage#Basic_Usage_in_A_Normal_Page
* added hidden labels to elements within groups such as the date_selector select boxes and other elements in 'groups'
* quiz/mod.html migrated to formslib
* glossary/edit.html migrated to formslib
* extended registerNoSubmitButton() functionality to automatically add js to onclick to bypass client side js input validation.
* added no_submit_button_pressed() function that can be used in a similar way to is_cancelled() as a test in the main script to see if some button in the page has been pressed that is a submit button that is used for some dynamic functionality within the form and not to submit the data for the whole form.
* added new condition for disabledIf which allows to disable another form element if no options are selected from within a select element.
* added default 'action' for moodleform  - strip_querystring(qualified_me()) http://docs.moodle.org/en/Development:lib/formslib.php_Usage#Basic_Usage_in_A_Normal_Page

42 files changed:
course/edit.php
course/edit_form.php
course/request.php
course/request_form.php
enrol/authorize/enrol_form.php
lang/en_utf8/form.php
lang/en_utf8/glossary.php
lib/form/adv.gif [new file with mode: 0644]
lib/form/adv.png [new file with mode: 0644]
lib/form/cancel.php
lib/form/checkbox.php
lib/form/format.php
lib/form/header.php [new file with mode: 0644]
lib/form/select.php
lib/form/submit.php [new file with mode: 0644]
lib/formslib.php
lib/javascript-static.js
login/change_password_form.php
login/forgot_password_form.php
login/signup_form.php
mod/assignment/type/online/assignment.class.php
mod/assignment/type/upload/assignment.class.php
mod/chat/mod_form.php
mod/choice/mod_form.php
mod/data/comment_form.php
mod/data/mod_form.php
mod/exercise/mod_form.php
mod/forum/mod_form.php
mod/forum/post_form.php
mod/glossary/comment_form.php
mod/glossary/edit.html [deleted file]
mod/glossary/edit.php
mod/glossary/edit_form.php [new file with mode: 0644]
mod/glossary/mod_form.php
mod/journal/mod_form.php
mod/label/mod_form.php
mod/lesson/mod_form.php
mod/quiz/lib.php
mod/quiz/mod.html [deleted file]
mod/quiz/mod_form.php [new file with mode: 0644]
mod/survey/details.php
theme/standard/styles_layout.css

index 80d4bb7fb2a3b343cb676d08d5618100ed4b8e24..886b1a8e0e7fb7fef9d93cde30ed5acd2a542d53 100644 (file)
@@ -60,10 +60,15 @@ if (!empty($course)) {
 
 /// first create the form
     $editform = new course_edit_form('edit.php', compact('course', 'category'));
+    if ($editform->is_cancelled()){
+        if (empty($course)) {
+            redirect($CFG->wwwroot);
+        } else {
+            redirect($CFG->wwwroot.'/course/view.php?id='.$course->id);
+        }
 
-
+    } elseif ($data = $editform->data_submitted()) {
 /// process data if submitted
-    if ($data = $editform->data_submitted()) {
 
         //preprocess data
         if ($data->enrolstartdisabled){
index 7660bf952937b8ce91953a18a46bb5ecce71fb3e..cfcb3324a93f459647a7716e1eb733ec45b689fb 100644 (file)
@@ -8,7 +8,6 @@ class course_edit_form extends moodleform {
         global $USER, $CFG;
 
         $mform    =& $this->_form;
-        $renderer =& $mform->defaultRenderer();
 
         $course   = $this->_customdata['course'];
         $category = $this->_customdata['category'];
@@ -92,7 +91,7 @@ class course_edit_form extends moodleform {
             $formcourseformats["$courseformat"] = get_string("format$courseformat","format_$courseformat");
             if($formcourseformats["$courseformat"]=="[[format$courseformat]]") {
                 $formcourseformats["$courseformat"] = get_string("format$courseformat");
-            }        
+            }
         }
         $mform->addElement('select', 'format', get_string('format'), $formcourseformats);
         $mform->setHelpButton('format', array('courseformats', get_string('courseformats')), true);
@@ -356,7 +355,7 @@ class course_edit_form extends moodleform {
         $mform->setType('restrictmodules', PARAM_INT);
 
 //--------------------------------------------------------------------------------
-        $mform->addElement('submit', 'submitbutton', get_string('savechanges'));
+        $this->add_action_buttons();
 //--------------------------------------------------------------------------------
         $mform->addElement('hidden', 'id', null);
         $mform->setType('id', PARAM_INT);
@@ -368,8 +367,6 @@ class course_edit_form extends moodleform {
         $mform->addElement('hidden', 'students', get_string('defaultcoursestudents'));
 
 
-//--------------------------------------------------------------------------------
-        $renderer->addStopFieldsetElements('submitbutton');
 
 
 // now override defaults if course already exists
index 4cf58e957ce9250169083679ffb0c46cec73a757..02589c295dc43c810c207af2a63f291994513a14 100644 (file)
     print_simple_box_end();
 
 
-    if (($data = $requestform->data_submitted())) {
+    if ($requestform->is_cancelled()){
 
+        redirect($CFG->wwwroot);
+
+    }elseif ($data = $requestform->data_submitted()) {
         $data->requester = $USER->id;
 
         if (insert_record('course_request', $data)) {
         } else {
             notice(get_string('courserequestfailed'));
         }
-        print_footer();
-        exit;
-
-    }
 
+    } else {
 
-    $requestform->display();
+        $requestform->display();
+    }
 
     print_footer();
 
-    exit;
-
-
 ?>
\ No newline at end of file
index 3f183bad8a85c4a244dc8bb5602183df737862b2..8d09ce139eb2650c1f74b497755afe2c4ee5e2af 100644 (file)
@@ -26,7 +26,7 @@ class course_request_form extends moodleform {
         $mform->setType('password', PARAM_RAW);
 
 
-        $mform->addElement('submit', '', get_string('savechanges'));
+        $this->add_action_buttons();
     }
 
     function validation($data) {
index 3d8b6c3bff537963557b595dce3cdccb866b8e23..63a445325928a4a1f23e8d7acb02b94099b930b4 100755 (executable)
@@ -16,7 +16,6 @@ class authorize_enrol_form extends moodleform
         }
 
         $mform =& $this->_form;
-        $renderer =& $mform->defaultRenderer();
 
         $mform->addElement('header', '', '&nbsp;&nbsp;' . get_string('paymentrequired'), '');
         if ($othermethodstr = other_method($paymentmethod)) {
@@ -173,8 +172,7 @@ class authorize_enrol_form extends moodleform
         $mform->addRule('cczip', get_string('missingzip', 'enrol_authorize'), 'required', null, 'client');
         $mform->addRule('cczip', get_string('missingzip', 'enrol_authorize'), 'numeric', null, 'client');
 
-        $mform->addElement('submit', 'submit', get_string('sendpaymentbutton', 'enrol_authorize'));
-        $renderer->addStopFieldsetElements('submit');
+        $this->add_action_buttons(false, true, get_string('sendpaymentbutton', 'enrol_authorize'));
     }
 
     function validation($data)
index c1ee2eea58947db022627fa8cbd71b00dbeaea2b..b230ebbb4fb1f990b672bd53f1af34d033f8d888 100644 (file)
@@ -27,4 +27,8 @@ $string['minute']='Minute';
 $string['advancedelement']='Advanced Element';
 $string['hideadvanced']='Hide Advanced';
 $string['showadvanced']='Show Advanced';
+
+$string['timing'] = 'Timing';
+$string['security'] = 'Security';
+$string['display'] = 'Display';
 ?>
\ No newline at end of file
index 70e50311da48625c5a938c0d085e855475ce08ee..bc7f66cfd70d35637f9b7ae04102e23b9a32d1fa 100644 (file)
@@ -1,4 +1,4 @@
-<?PHP // $Id$ 
+<?PHP // $Id$
       // glossary.php - created with Moodle 1.7 beta + (2006101003)
 
 
@@ -52,6 +52,9 @@ $string['concept'] = 'Concept';
 $string['concepts'] = 'Concepts';
 $string['configenablerssfeeds'] = 'This switch will enable the possibility of RSS feeds for all glosaries.  You will still need to turn feeds on manually in the settings for each glossary.';
 $string['currentglossary'] = 'Current glossary';
+$string['errconceptalreadyexists'] = 'This concept already exists. No duplicates allowed in this glossary.';
+$string['erredittimeexpired'] = 'The editing time for this entry has expired.';
+$string['errcannoteditothers'] = 'You cannot edit other people\'s entries.';
 $string['dateview'] = 'Browse by date';
 $string['defaultapproval'] = 'Approved by default';
 $string['definition'] = 'Definition';
@@ -124,6 +127,7 @@ $string['importedentries'] = 'Imported entries';
 $string['importentries'] = 'Import entries';
 $string['isglobal'] = 'Is this glossary global?';
 $string['linkcategory'] = 'Automatically link this category';
+$string['linking'] = 'Auto-linking';
 $string['mainglossary'] = 'Main glossary';
 $string['maxtimehaspassed'] = 'Sorry, but the maximum time for editing this comment ($a) has passed!';
 $string['modulename'] = 'Glossary';
diff --git a/lib/form/adv.gif b/lib/form/adv.gif
new file mode 100644 (file)
index 0000000..8446c80
Binary files /dev/null and b/lib/form/adv.gif differ
diff --git a/lib/form/adv.png b/lib/form/adv.png
new file mode 100644 (file)
index 0000000..e0694e8
Binary files /dev/null and b/lib/form/adv.png differ
index 88ca84e3abd10c1317bd39743779c41fe52213e9..ed263ec4f8f39cdcaf0cf82e33f89c267c4d4750 100644 (file)
@@ -7,7 +7,7 @@ require_once('HTML/QuickForm/submit.php');
  * @author       Jamie Pratt
  * @access       public
  */
-class MoodleQuickForm_cancel extends HTML_QuickForm_submit
+class MoodleQuickForm_cancel extends MoodleQuickForm_submit
 {
     // {{{ constructor
 
@@ -26,7 +26,7 @@ class MoodleQuickForm_cancel extends HTML_QuickForm_submit
         if ($value==null){
             $value=get_string('cancel');
         }
-        HTML_QuickForm_submit::HTML_QuickForm_submit($elementName, $value, $attributes);
+        MoodleQuickForm_submit::MoodleQuickForm_submit($elementName, $value, $attributes);
         $this->updateAttributes(array('onclick'=>'skipClientValidation = true; return true;'));
     } //end constructor
     function onQuickFormEvent($event, $arg, &$caller)
@@ -43,5 +43,5 @@ class MoodleQuickForm_cancel extends HTML_QuickForm_submit
     } // end func onQuickFormEvent
 
     // }}}
-} //end class HTML_QuickForm_submit
+} //end class MoodleQuickForm_cancel
 ?>
\ No newline at end of file
index 9c13dcaafdeef4dde9a3336c73cd4b69ac1edfa3..f1eaaa4bd87699aec170a8213208104768895b36 100644 (file)
@@ -60,5 +60,42 @@ class MoodleQuickForm_checkbox extends HTML_QuickForm_checkbox{
             $this->updateAttributes(array('id' => substr(md5(microtime() . $idx++), 0, 6)));
         }
     } // end func _generateId
+    /**
+     * Called by HTML_QuickForm whenever form event is made on this element
+     *
+     * @param     string    $event  Name of event
+     * @param     mixed     $arg    event arguments
+     * @param     object    $caller calling object
+     * @since     1.0
+     * @access    public
+     * @return    void
+     */
+    function onQuickFormEvent($event, $arg, &$caller)
+    {
+        //fixes bug in quickforms which lets previous set value override submitted value if checkbox is not checked
+        // and no value is submitted
+        switch ($event) {
+            case 'updateValue':
+                // constant values override both default and submitted ones
+                // default values are overriden by submitted
+                $value = $this->_findValue($caller->_constantValues);
+                if (null === $value) {
+                    // if no boxes were checked, then there is no value in the array
+                    // yet we don't want to display default value in this case
+                    if ($caller->isSubmitted()) {
+                        $value = $this->_findValue($caller->_submitValues);
+                    } else {
+
+                        $value = $this->_findValue($caller->_defaultValues);
+                    }
+                }
+                //fix here. setChecked should not be conditional
+                $this->setChecked($value);
+                break;
+            default:
+                parent::onQuickFormEvent($event, $arg, $caller);
+        }
+        return true;
+    } // end func onQuickFormEvent
 }
 ?>
\ No newline at end of file
index 3d12adbff733f44b2f55dbbd7a277bcb1c1802e6..6d8e31586357f5d7480b9336208bdb274da2faaa 100644 (file)
@@ -29,9 +29,16 @@ class MoodleQuickForm_format extends MoodleQuickForm_select{
      */
     function MoodleQuickForm_format($elementName=null, $elementLabel=null, $attributes=null, $useHtmlEditor=null)
     {
+        if ($elementName == null){
+            $elementName = 'format';
+        }
+        if ($elementLabel == null){
+            $elementLabel = get_string('format');
+        }
         HTML_QuickForm_element::HTML_QuickForm_element($elementName, $elementLabel, $attributes);
         $this->_persistantFreeze = true;
         $this->_type = 'format';
+
         $this->_useHtmlEditor=$useHtmlEditor;
         if ($this->_useHtmlEditor==null){
             $this->_useHtmlEditor=can_use_html_editor();
@@ -39,9 +46,6 @@ class MoodleQuickForm_format extends MoodleQuickForm_select{
         if ($this->_useHtmlEditor){
             $this->freeze();
         }
-
-
-
     } //end constructor
 
     /**
diff --git a/lib/form/header.php b/lib/form/header.php
new file mode 100644 (file)
index 0000000..d7ef023
--- /dev/null
@@ -0,0 +1,64 @@
+<?php
+// $Id$
+
+require_once 'HTML/QuickForm/header.php';
+
+/**
+ * A pseudo-element used for adding headers to form
+ *
+ */
+class MoodleQuickForm_header extends HTML_QuickForm_header
+{
+    /**
+     * html for help button, if empty then no help
+     *
+     * @var string
+     */
+    var $_helpbutton='';
+
+    // {{{ accept()
+
+   /**
+    * Accepts a renderer
+    *
+    * @param object     An HTML_QuickForm_Renderer object
+    * @access public
+    * @return void
+    */
+    function accept(&$renderer)
+    {
+        $this->_text .= $this->getHelpButton();
+        $renderer->renderHeader($this);
+    } // end func accept
+
+    // }}}
+    /**
+     * set html for help button
+     *
+     * @access   public
+     * @param array $help array of arguments to make a help button
+     * @param string $function function name to call to get html
+     */
+    function setHelpButton($helpbuttonargs, $function='helpbutton'){
+        if (!is_array($helpbuttonargs)){
+            $helpbuttonargs=array($helpbuttonargs);
+        }else{
+            $helpbuttonargs=$helpbuttonargs;
+        }
+        //we do this to to return html instead of printing it
+        //without having to specify it in every call to make a button.
+        $defaultargs=array('', '', 'moodle', true, false, '', true);
+        $helpbuttonargs=$helpbuttonargs + $defaultargs ;
+        $this->_helpbutton=call_user_func_array($function, $helpbuttonargs);
+    }
+    /**
+     * get html for help button
+     *
+     * @access   public
+     * @return  string html for help button
+     */
+    function getHelpButton(){
+        return $this->_helpbutton;
+    }
+} //end class MoodleQuickForm_header
+?>
index 63df3f919b00da5ad581885de9b0f9205d5af08b..245fa338a2c386ffc6455e8cfee32b3efd03ade5 100644 (file)
@@ -94,6 +94,18 @@ class MoodleQuickForm_select extends HTML_QuickForm_select{
             }
         }
     } // end func removeOption
+    /**
+     * Removes all OPTIONs from the SELECT
+     *
+     * @param     string    $value      Value for the OPTION to remove
+     * @since     1.0
+     * @access    public
+     * @return    void
+     */
+    function removeOptions()
+    {
+        $this->_options = array();
+    } // end func removeOption
 
 }
 ?>
\ No newline at end of file
diff --git a/lib/form/submit.php b/lib/form/submit.php
new file mode 100644 (file)
index 0000000..09a5bcc
--- /dev/null
@@ -0,0 +1,45 @@
+<?php
+require_once("HTML/QuickForm/submit.php");
+
+/**
+ * HTML class for a submit type element
+ *
+ * @author       Adam Daniel <adaniel1@eesus.jnj.com>
+ * @author       Bertrand Mansion <bmansion@mamasam.com>
+ * @version      1.0
+ * @since        PHP4.04pl1
+ * @access       public
+ */
+class MoodleQuickForm_submit extends HTML_QuickForm_submit {
+    /**
+     * Called by HTML_QuickForm whenever form event is made on this element
+     *
+     * @param     string    $event  Name of event
+     * @param     mixed     $arg    event arguments
+     * @param     object    $caller calling object
+     * @since     1.0
+     * @access    public
+     * @return    void
+     */
+    function onQuickFormEvent($event, $arg, &$caller)
+    {
+        switch ($event) {
+            case 'createElement':
+                parent::onQuickFormEvent($event, $arg, $caller);
+                if ($caller->isNoSubmitButton($arg[0])){
+                    //need this to bypass client validation
+                    //for buttons that submit but do not process the
+                    //whole form.
+                    $onClick = $this->getAttribute('onclick');
+                    $skip = 'skipClientValidation = true;';
+                    $onClick = ($onClick !== null)?$skip.' '.$onClick:$skip;
+                    $this->updateAttributes(array('onclick'=>$onClick));
+                }
+                return true;
+                break;
+        }
+        return parent::onQuickFormEvent($event, $arg, $caller);
+
+    } // end func onQuickFormEvent
+}
+?>
\ No newline at end of file
index 354262dad9a7cd50ee4e633dd6742181604d6047..f37f70ca6dd3bf520fb706cadf9f31861244ab69 100644 (file)
@@ -34,8 +34,19 @@ require_once $CFG->libdir.'/uploadlib.php';
 define('FORM_ADVANCEDIMAGEURL', $CFG->wwwroot.'/lib/form/adv.gif');
 define('FORM_REQIMAGEURL', $CFG->wwwroot.'/lib/form/req.gif');
 
+/**
+ * Callback called when PEAR throws an error
+ *
+ * @param PEAR_Error $error
+ */
+function pear_handle_error($error){
+    echo '<strong>'.$error->GetMessage().'</strong> '.$error->getUserInfo();
+    echo '<br /> <strong>Backtrace </strong>:';
+    print_object($error->backtrace);
+}
+
 if ($CFG->debug >= DEBUG_ALL){
-    PEAR::setErrorHandling(PEAR_ERROR_PRINT);
+    PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, 'pear_handle_error');
 }
 
 /**
@@ -79,7 +90,8 @@ class moodleform {
      * the name you gave the class extending moodleform. You should call your class something
      * like
      *
-     * @param string $action the action attribute for the form.
+     * @param string $action the action attribute for the form. If empty defaults to auto detect the
+     *                  current url.
      * @param array $customdata if your form defintion method needs access to data such as $course
      *               $cm, etc. to construct the form definition then pass it in this array. You can
      *               use globals for somethings.
@@ -91,7 +103,10 @@ class moodleform {
      * @param mixed $attributes you can pass a string of html attributes here or an array.
      * @return moodleform
      */
-    function moodleform($action, $customdata=null, $method='post', $target='', $attributes=null) {
+    function moodleform($action=null, $customdata=null, $method='post', $target='', $attributes=null) {
+        if (empty($action)){
+            $action = strip_querystring(qualified_me());
+        }
         //strip '_form' from the end of class name to make form 'id' attribute.
         $this->_formname = preg_replace('/_form$/', '', get_class($this), 1);
         $this->_customdata = $customdata;
@@ -257,6 +272,23 @@ class moodleform {
         return $this->_form->isSubmitted();
     }
 
+    function no_submit_button_pressed(){
+        static $nosubmit = null; // one check is enough
+        if (!is_null($nosubmit)){
+            return $nosubmit;
+        }
+        $mform =& $this->_form;
+        $nosubmit = false;
+        foreach ($mform->_noSubmitButtons as $nosubmitbutton){
+            if (optional_param($nosubmitbutton, 0, PARAM_RAW)){
+                $nosubmit = true;
+                break;
+            }
+        }
+        return $nosubmit;
+    }
+
+
     /**
      * Check that form data is valid.
      *
@@ -265,21 +297,21 @@ class moodleform {
     function is_validated() {
         static $validated = null; // one validation is enough
         $mform =& $this->_form;
-        foreach ($mform->_noSubmitButtons as $nosubmitbutton){
-            if (optional_param($nosubmitbutton, 0, PARAM_RAW)){
-                return false;
-            }
+        if ($this->no_submit_button_pressed()){
+            return false;
         }
         if ($validated === null) {
             $internal_val = $mform->validate();
             $moodle_val = $this->validation($mform->exportValues(null, true));
             if ($moodle_val !== true) {
-                if (!empty($moodle_val)) {
+                if ((is_array($moodle_val) && count($moodle_val)!==0)) {
                     foreach ($moodle_val as $element=>$msg) {
                         $mform->setElementError($element, $msg);
                     }
+                    $moodle_val = false;
+                } else {
+                    $moodle_val = true;
                 }
-                $moodle_val = false;
             }
             $file_val = $this->_validate_files();
             if ($file_val !== true) {
@@ -302,9 +334,11 @@ class moodleform {
      */
     function is_cancelled(){
         $mform =& $this->_form;
-        foreach ($mform->_cancelButtons as $cancelbutton){
-            if (optional_param($cancelbutton, 0, PARAM_RAW)){
-                return true;
+        if ($mform->isSubmitted()){
+            foreach ($mform->_cancelButtons as $cancelbutton){
+                if (optional_param($cancelbutton, 0, PARAM_RAW)){
+                    return true;
+                }
             }
         }
         return false;
@@ -390,6 +424,7 @@ class moodleform {
 
 
 
+
     /**
      * Method to add a repeating group of elements to a form.
      *
@@ -408,6 +443,7 @@ class moodleform {
      * @param int $addfieldsno how many fields to add at a time
      * @param array $addstring array of params for get_string for name of button, $a is no of fields that
      *                                  will be added.
+     * @return int no of repeats of element in this page
      */
     function repeat_elements($elementobjs, $repeats, $options, $repeathiddenname, $addfieldsname, $addfieldsno=5, $addstring=array('addfields', 'form')){
         $repeats = optional_param($repeathiddenname, $repeats, PARAM_INT);
@@ -416,7 +452,7 @@ class moodleform {
             $repeats += $addfieldsno;
         }
         $mform =& $this->_form;
-        $mform->_registerNoSubmitButton($addfieldsname);
+        $mform->registerNoSubmitButton($addfieldsname);
         $mform->addElement('hidden', $repeathiddenname, $repeats);
         //value not to be overridden by submitted value
         $mform->setConstants(array($repeathiddenname=>$repeats));
@@ -462,13 +498,45 @@ class moodleform {
                 }
             }
         }
-        $mform->addElement('submit', $addfieldsname, get_string('addfields', 'form', $addfieldsno),
-                            array('onclick'=>'skipClientValidation = true; return true;'));//need this to bypass client validation
+        $mform->addElement('submit', $addfieldsname, get_string('addfields', 'form', $addfieldsno));
+
+        $mform->closeHeaderBefore($addfieldsname);
 
-        $renderer =& $mform->defaultRenderer();
-        $renderer->addStopFieldsetElements($addfieldsname);
         return $repeats;
     }
+    /**
+     * Use this method to add the standard buttons to the end of your form. Pass a param of false
+     * if you don't want a cancel button in your form. If you have a cancel button make sure you
+     * check for it being pressed using is_cancelled() and redirecting if it is true before trying to
+     * get data with data_submitted().
+     *
+     * @param boolean $cancel whether to show cancel button, default true
+     * @param boolean $revert whether to show revert button, default true
+     * @param string $submitlabel label for submit button, defaults to get_string('savechanges')
+     */
+    function add_action_buttons($cancel = true, $revert = true, $submitlabel=null){
+        if (is_null($submitlabel)){
+            $submitlabel = get_string('savechanges');
+        }
+        $mform =& $this->_form;
+        if ($revert || $cancel){
+            //when two or more elements we need a group
+            $buttonarray=array();
+            $buttonarray[] = &$mform->createElement('submit', 'submitbutton', $submitlabel);
+            if ($revert){
+                $buttonarray[] = &$mform->createElement('reset', 'resetbutton', get_string('revert'));
+            }
+            if ($cancel){
+                $buttonarray[] = &$mform->createElement('cancel');
+            }
+            $mform->addGroup($buttonarray, 'buttonar', '', array(' '), false);
+               $mform->closeHeaderBefore('buttonar');
+        } else {
+            //no group needed
+            $mform->addElement('submit', 'submitbutton', $submitlabel);
+               $mform->closeHeaderBefore('submitbutton');
+        }
+    }
 }
 
 /**
@@ -542,8 +610,62 @@ class MoodleQuickForm extends HTML_QuickForm_DHTMLRulesTableless {
             FORM_REQIMAGEURL.'" />')));
     }
 
-    function setShowAdvanced($showadvancedNow){
-        $this->_showAdvanced=$showadvancedNow;
+    /**
+     * Use this method to indicate an element in a form is an advanced field. If items in a form
+     * are marked as advanced then 'Hide/Show Advanced' buttons will automatically be displayed in the
+     * form so the user can decide whether to display advanced form controls.
+     *
+     * If you set a header element to advanced then all elements it contains will also be set as advanced.
+     *
+     * @param string $elementName group or element name (not the element name of something inside a group).
+     * @param boolean $advanced default true sets the element to advanced. False removes advanced mark.
+     */
+    function setAdvanced($elementName, $advanced=true){
+        if ($advanced){
+            $this->_advancedElements[$elementName]='';
+        } elseif (isset($this->_advancedElements[$elementName])) {
+            unset($this->_advancedElements[$elementName]);
+        }
+        if ($advanced && $this->getElementType('mform_showadvanced_last')===false){
+            $this->setShowAdvanced();
+            $this->registerNoSubmitButton('mform_showadvanced');
+
+            $this->addElement('hidden', 'mform_showadvanced_last');
+        }
+    }
+    /**
+     * Set whether to show advanced elements in the form on first displaying form. Default is not to
+     * display advanced elements in the form until 'Show Advanced' is pressed.
+     *
+     * You can get the last state of the form and possibly save it for this user by using
+     * value 'mform_showadvanced_last' in submitted data.
+     *
+     * @param boolean $showadvancedNow
+     */
+    function setShowAdvanced($showadvancedNow = null){
+        if ($showadvancedNow === null){
+            if ($this->_showAdvanced !== null){
+                return;
+            } else { //if setShowAdvanced is called without any preference
+                     //make the default to not show advanced elements.
+                $showadvancedNow = 0;
+            }
+
+        }
+        //value of hidden element
+        $hiddenLast = optional_param('mform_showadvanced_last', -1, PARAM_INT);
+        //value of button
+        $buttonPressed = optional_param('mform_showadvanced', 0, PARAM_RAW);
+        //toggle if button pressed or else stay the same
+        if ($hiddenLast == -1) {
+            $next = $showadvancedNow;
+        } elseif ($buttonPressed) { //toggle on button press
+            $next = !$hiddenLast;
+        } else {
+            $next = $hiddenLast;
+        }
+        $this->_showAdvanced = $next;
+        $this->setConstants(array('mform_showadvanced_last'=>$next));
     }
     function getShowAdvanced(){
         return $this->_showAdvanced;
@@ -616,34 +738,7 @@ class MoodleQuickForm extends HTML_QuickForm_DHTMLRulesTableless {
         parent::accept($renderer);
     }
 
-    function setAdvanced($elementName, $advanced=true){
-        if ($advanced){
-            $this->_advancedElements[$elementName]='';
-        } elseif (isset($this->_advancedElements[$elementName])) {
-            unset($this->_advancedElements[$elementName]);
-        }
-        if ($advanced && $this->getShowAdvanced()===null){
-            //hidden element
-            $showadvanced_last = optional_param('mform_showadvanced_last', 0, PARAM_INT);
-            //button
-            $showadvanced = optional_param('mform_showadvanced', 0, PARAM_RAW);
-            //toggle if button pressed or else stay the same
-            if ($showadvanced && $showadvanced_last){
-                $showadvanced_now = 0;
-            } elseif ($showadvanced && !$showadvanced_last) {
-                $showadvanced_now = 1;
-            } else {
-                $showadvanced_now = $showadvanced_last;
-            }
-
-            $this->setConstants(array('mform_showadvanced_last'=>$showadvanced_now));
-            //below tells form whether to display elements or not
-            $this->setShowAdvanced($showadvanced_now);
-            $this->_registerNoSubmitButton('mform_showadvanced');
 
-            $this->addElement('hidden', 'mform_showadvanced_last');
-        }
-    }
 
     function closeHeaderBefore($elementName){
         $renderer =& $this->defaultRenderer();
@@ -1040,8 +1135,11 @@ function validate_' . $this->_attributes['id'] . '(frm) {
         $this->_dependencies[$dependentOn][] = array('dependent'=>$elementName,
                                     'condition'=>$condition, 'value'=>$value);
     }
-    function _registerNoSubmitButton($addfieldsname){
-        $this->_noSubmitButtons[]=$addfieldsname;
+    function registerNoSubmitButton($buttonname){
+        $this->_noSubmitButtons[]=$buttonname;
+    }
+    function isNoSubmitButton($buttonname){
+        return (array_search($buttonname, $this->_noSubmitButtons)!==FALSE);
     }
     function _registerCancelButton($addfieldsname){
         $this->_cancelButtons[]=$addfieldsname;
@@ -1079,7 +1177,7 @@ class MoodleQuickForm_Renderer extends HTML_QuickForm_Renderer_Tableless{
     * @access   private
     */
     var $_headerTemplate =
-       "\n\t\t<legend>{header}{advancedimg}{button}</legend>\n\t\t";
+       "\n\t\t<legend>{header}</legend>\n\t\t<div class=\"advancedbutton\">{advancedimg}{button}</div>\n\t\t";
 
    /**
     * Template used when closing a fieldset
@@ -1311,6 +1409,7 @@ MoodleQuickForm::registerElementType('modgrade', "$CFG->libdir/form/modgrade.php
 MoodleQuickForm::registerElementType('cancel', "$CFG->libdir/form/cancel.php", 'MoodleQuickForm_cancel');
 MoodleQuickForm::registerElementType('button', "$CFG->libdir/form/button.php", 'MoodleQuickForm_button');
 MoodleQuickForm::registerElementType('choosecoursefile', "$CFG->libdir/form/choosecoursefile.php", 'MoodleQuickForm_choosecoursefile');
-//MoodleQuickForm::registerElementType('header', "$CFG->libdir/form/header.php", 'MoodleQuickForm_header');  // where is it?
+MoodleQuickForm::registerElementType('header', "$CFG->libdir/form/header.php", 'MoodleQuickForm_header');
+MoodleQuickForm::registerElementType('submit', "$CFG->libdir/form/submit.php", 'MoodleQuickForm_submit');
 
 ?>
index 2a26f354b29ebbb0bb20b6590b5ac16518c776eb..eb0b8e8e8b728dc3771fcb04316af191d2b44bbb 100644 (file)
@@ -69,6 +69,8 @@ function lockoptionsall(formid) {
           thislock=!form.elements[master].checked;
       } else if (items[master].condition=='checked'){
           thislock=form.elements[master].checked;
+      } else if  (items[master].condition=='noitemselected'){
+          thislock=(form.elements[master].selectedIndex==-1);
       } else if  (items[master].condition=='eq'){
           thislock=(form.elements[master].value==items[master].value);
       } else {
@@ -200,21 +202,33 @@ function findParentNode(el, elName, elClass, elId) {
     Travels down the DOM hierarchy to find all child elements with the
     specified tag name, class, and id. All conditions must be met,
     but any can be ommitted.
+    Doesn't examine children of matches.
 */
 function findChildNodes(start, tagName, elementClass, elementID, elementName) {
     var children = new Array();
     for (var childIndex in start.childNodes) {
+        var classfound = false;
         var child = start.childNodes[childIndex];
-        if(
-            (child.nodeType == 1) &&//element node type
+        if((child.nodeType == 1) &&//element node type
+                  (elementClass && (typeof(child.className)=='string'))){
+            var childClasses = child.className.split(/\s+/);
+            for (var childClassIndex in childClasses){
+                if (childClasses[childClassIndex]==elementClass){
+                    classfound = true;
+                    break;
+                }
+            }
+        }
+        if( (child.nodeType == 1) &&//element node type
             (!tagName || child.nodeName == tagName) &&
-            (!elementClass || child.className.indexOf(elementClass) != -1) &&
+            (!elementClass || classfound)&&
             (!elementID || child.id == elementID) &&
             (!elementName || child.name == elementName))
         {
             children = children.concat(child);
+        } else {
+            children = children.concat(findChildNodes(child, tagName, elementClass, elementID, elementName));
         }
-        children = children.concat(findChildNodes(child, tagName, elementClass, elementID, elementName));
     }
     return children;
 }
index a6f9b946620f0a132b127c0de8dd3a66542ad646..1a3438dda92ad749370528ab3c9a8851d1054c14 100644 (file)
@@ -8,7 +8,6 @@ class change_password_form extends moodleform {
         global $USER;
 
         $mform    =& $this->_form;
-        $renderer =& $mform->defaultRenderer();
 
         $mform->addElement('header', '', get_string('changepassword'), '');
         $sitecontext = get_context_instance(CONTEXT_SYSTEM, SITEID);
@@ -47,14 +46,9 @@ class change_password_form extends moodleform {
 
         // buttons
         if (empty($USER->preference['auth_forcepasswordchange'])) {
-            $buttonarray = array();
-            $buttonarray[] = &$mform->createElement('submit', 'submitbutton', get_string('savechanges'));
-            $buttonarray[] = &$mform->createElement('cancel');
-            $mform->addGroup($buttonarray, 'buttonar', '', array(' '), false);
-            $renderer->addStopFieldsetElements('buttonar');
+            $this->add_action_buttons(true, false);
         } else {
-            $mform->addElement('submit', 'submitbutton', get_string('savechanges'));
-            $renderer->addStopFieldsetElements('submitbutton');
+            $this->add_action_buttons(false, false);
         }
     }
 
index bc64b74d57fb8c50d1a9d0870f0c179ecc9e7b14..bf2b386e6065e51855f061dbc80a4c918677ce4b 100644 (file)
@@ -20,13 +20,7 @@ class forgot_password_form extends moodleform {
         $mform->addElement('hidden', 'action', 'find');
         $mform->setType('action', PARAM_ALPHA);
 
-        // buttons
-        $buttonarray = array();
-        $buttonarray[] = &$mform->createElement('submit', 'submitbutton', get_string('ok'));
-        $buttonarray[] = &$mform->createElement('cancel');
-        $mform->addGroup($buttonarray, 'buttonar', '', array(' '), false);
-
-        $renderer->addStopFieldsetElements('buttonar');
+        $this->add_action_buttons(true, false, get_string('ok'));
     }
 }
 
index d3979bbe36e5f8668a3166060a5938a918c59ca0..1d559fffe45e25787e4e61a8f6e8dee5ddb40484 100644 (file)
@@ -7,7 +7,6 @@ class login_signup_form extends moodleform {
                global $USER, $CFG;
 
                $mform    =& $this->_form;
-               $renderer =& $mform->defaultRenderer();
 
                $mform->addElement('header', '', get_string('createuserandpass'), '');
 
@@ -50,12 +49,8 @@ class login_signup_form extends moodleform {
         $mform->setDefault('country', '');
 
         // buttons
-        $buttonarray = array();
-        $buttonarray[] = &$mform->createElement('submit', 'submitbutton', get_string('createaccount'));
-        $buttonarray[] = &$mform->createElement('cancel');
-        $mform->addGroup($buttonarray, 'buttonar', '', array(' '), false);
+        $this->add_action_buttons(true, false, get_string('createaccount'));
 
-        $renderer->addStopFieldsetElements('buttonar');
        }
 
        function definition_after_data(){
index 95988a90f8afeeccd97aa3c22eb6b03d8f631f57..592cc737999612a7a1e30a72be2e83bd56e6e23a 100644 (file)
@@ -256,12 +256,7 @@ class assignment_online_edit_form extends moodleform {
         $mform->setType('id', PARAM_INT);
 
         // buttons
-        $buttonarray = array();
-        $buttonarray[] =& $mform->createElement('submit', 'submitbutton', get_string('savechanges'));
-        $buttonarray[] =& $mform->createElement('reset', 'resetbutton', get_string('revert'));
-        $buttonarray[] =& $mform->createElement('cancel');
-
-        $mform->addGroup($buttonarray, 'buttonar', '', array(' '), false);
+        $this->add_action_buttons();
     }
 }
 
index 4e7814ecb8338e2d4cbbcecac3bc4492d3371d6e..274f2ce568f53b98bcc2ee2634026fae4f45dd91 100644 (file)
@@ -929,12 +929,7 @@ class assignment_upload_notes_form extends moodleform {
         $mform->setType('id', PARAM_ALPHA);
 
         // buttons
-        $buttonarray = array();
-        $buttonarray[] =& $mform->createElement('submit', 'submitbutton', get_string('savechanges'));
-        $buttonarray[] =& $mform->createElement('reset', 'resetbutton', get_string('revert'));
-        $buttonarray[] =& $mform->createElement('cancel');
-
-        $mform->addGroup($buttonarray, 'buttonar', '', array(' '), false);
+        $this->add_action_buttons();
     }
 }
 
index a6916be04fd5d2f0c975f2d05be956c249796b49..047913bf9b04f4795b1687538d4fbe92e7f42995 100644 (file)
@@ -48,12 +48,7 @@ class chat_mod_form extends moodleform_mod {
 
         $this->standard_coursemodule_elements();
 
-        $buttonarray=array();
-        $buttonarray[] = &$mform->createElement('submit', 'submitbutton', get_string('savechanges'));
-        $buttonarray[] = &$mform->createElement('reset', 'resetbutton', get_string('revert'));
-        $buttonarray[] = &$mform->createElement('cancel');
-        $mform->addGroup($buttonarray, 'buttonar', '', array(' '), false);
-               $mform->closeHeaderBefore('buttonar');
+        $this->add_action_buttons();
        }
 
 
index 38256ee89975f557b7e3567e4165864eca2d877b..810adc912e418f6a2d709c34a688aa302151f6ac 100644 (file)
@@ -83,13 +83,7 @@ class choice_mod_form extends moodleform_mod {
 //-------------------------------------------------------------------------------
                $this->standard_coursemodule_elements();
 //-------------------------------------------------------------------------------
-
-        $buttonarray=array();
-        $buttonarray[] = &$mform->createElement('submit', 'submitbutton', get_string('savechanges'));
-        $buttonarray[] = &$mform->createElement('reset', 'resetbutton', get_string('revert'));
-        $buttonarray[] = &$mform->createElement('cancel');
-        $mform->addGroup($buttonarray, 'buttonar', '', array(' '), false);
-               $mform->closeHeaderBefore('buttonar');
+        $this->add_action_buttons();
        }
 
        function defaults_preprocessing(&$default_values){
index b6a5754e43efa75759e5ff9d44e67f5ca9a77d5e..dafebf00cea8d47fe357bda6f2fe3fa933faf1de 100644 (file)
@@ -27,13 +27,10 @@ class data_comment_form extends moodleform {
         $mform->addElement('hidden', 'commentid', 0);
         $mform->setType('commentid', PARAM_INT);
 
+//-------------------------------------------------------------------------------
         // buttons
-        $buttonarray = array();
-        $buttonarray[] =& $mform->createElement('submit', 'submitbutton', get_string('savechanges'));
-        $buttonarray[] =& $mform->createElement('reset', 'reset', get_string('revert'));
-        $buttonarray[] =& $mform->createElement('cancel');
+        $this->add_action_buttons();
 
-        $mform->addGroup($buttonarray, 'buttonar', '', array(' '), false);
     }
 }
 ?>
\ No newline at end of file
index 358cdb1a94842a72b829c1b18093220114d33054..695bc7832177d38f2f45ab997d4ee2ab7f6ef637 100644 (file)
@@ -57,12 +57,9 @@ class data_mod_form extends moodleform_mod {
 
         $this->standard_coursemodule_elements();
 
-        $buttonarray=array();
-        $buttonarray[] = &$mform->createElement('submit', 'submitbutton', get_string('savechanges'));
-        $buttonarray[] = &$mform->createElement('reset', 'resetbutton', get_string('revert'));
-        $buttonarray[] = &$mform->createElement('cancel');
-        $mform->addGroup($buttonarray, 'buttonar', '', array(' '), false);
-               $mform->closeHeaderBefore('buttonar');
+//-------------------------------------------------------------------------------
+        // buttons
+        $this->add_action_buttons();
     }
 
 
index 58121214a359eeb14e6cc01bc7206a65de0bf0f0..a8d0f736fa1e5324257ff92534652ee52c32b5b9 100644 (file)
@@ -100,13 +100,8 @@ class exercise_mod_form extends moodleform_mod {
 //-------------------------------------------------------------------------------
         $this->standard_coursemodule_elements();
 //-------------------------------------------------------------------------------
-
-        $buttonarray=array();
-        $buttonarray[] = &$mform->createElement('submit', 'submitbutton', get_string('savechanges'));
-        $buttonarray[] = &$mform->createElement('reset', 'resetbutton', get_string('revert'));
-        $buttonarray[] = &$mform->createElement('cancel');
-        $mform->addGroup($buttonarray, 'buttonar', '', array(' '), false);
-               $mform->closeHeaderBefore('buttonar');
+        // buttons
+        $this->add_action_buttons();
        }
 
 
index cc4fe0c1c642fed9d0dd201c111e8d6d2bd765ae..58576ecc631068eb872b88ca63031f2f8c685fdf 100644 (file)
@@ -124,13 +124,10 @@ class forum_mod_form extends moodleform_mod {
 
 //-------------------------------------------------------------------------------
                $this->standard_coursemodule_elements();
+//-------------------------------------------------------------------------------
+        // buttons
+        $this->add_action_buttons();
 
-        $buttonarray=array();
-        $buttonarray[] = &$mform->createElement('submit', 'submitbutton', get_string('savechanges'));
-        $buttonarray[] = &$mform->createElement('reset', 'resetbutton', get_string('revert'));
-        $buttonarray[] = &$mform->createElement('cancel');
-        $mform->addGroup($buttonarray, 'buttonar', '', array(' '), false);
-               $mform->closeHeaderBefore('buttonar');
        }
 
        function definition_after_data(){
index 3a6ba948e481622fe159c5ae6251ce7afe52d8b9..a578aefa04c5a780e500d18bdb04aeeaeb3b60db 100644 (file)
@@ -79,13 +79,14 @@ class forum_post_form extends moodleform {
                        $mform->setType('timeend', PARAM_INT);
                    $mform->setConstants(array('timestart'=> 0, 'timeend'=>0));
                }
+//-------------------------------------------------------------------------------
+        // buttons
                if (isset($post->edit)) {
                        $submit_string = get_string('savechanges');
                } else {
                        $submit_string = get_string('posttoforum', 'forum');
                }
-               $mform->addElement('submit', 'submitbutton', $submit_string);
-               $mform->closeHeaderBefore('submitbutton');
+        $this->add_action_buttons(false, true, $submit_string);
 
                $mform->addElement('hidden', 'course');
                $mform->setType('course', PARAM_INT);
index dec379e3eff1173339b74761eaa21c921cef08f3..b1667d6e245008f938d635eaf4231b58cdf80c3d 100644 (file)
@@ -24,13 +24,9 @@ class glossary_comment_form extends moodleform {
         $mform->addElement('hidden', 'action', '');
         $mform->setType('action', PARAM_ACTION);
 
+//-------------------------------------------------------------------------------
         // buttons
-        $buttonarray = array();
-        $buttonarray[] =& $mform->createElement('submit', 'submitbutton', get_string('savechanges'));
-        $buttonarray[] =& $mform->createElement('reset', 'reset', get_string('revert'));
-        $buttonarray[] =& $mform->createElement('cancel');
-
-        $mform->addGroup($buttonarray, 'buttonar', '', array(' '), false);
+        $this->add_action_buttons(false);
     }
 }
 ?>
\ No newline at end of file
diff --git a/mod/glossary/edit.html b/mod/glossary/edit.html
deleted file mode 100644 (file)
index 9216962..0000000
+++ /dev/null
@@ -1,196 +0,0 @@
-<?php //$Id$
-    if (!isset($newentry->format)) {
-        $newentry->format = $defaultformat;
-    }
-
-    trusttext_prepare_edit($newentry->definition, $newentry->format, $usehtmleditor, $context);
-
-?>
-<form name="form" method="post" action="edit.php" enctype="multipart/form-data">
-<table border="0" cellpadding="5">
-<?php
-if (isset($errors)) {
-?>
-    <tr valign="top">
-        <td colspan="2" align="center"><strong><font color="red"><?php p($errors) ?></font></strong>
-        </td>
-    </tr>
-<?php
-}
-?>
-<tr valign="top">
-<td colspan="2">
-<table width="100%" border="0" cellspacing="0" cellpadding="0">
-  <tr>
-    <td valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="5">
-        <tr>
-          <td width="150" align="right"><b><?php echo get_string("concept","glossary") ?>:</b></td>
-          <td><input type="text" name="concept" size="30" value="<?php p(clean_text($newentry->concept)) ?>" alt="<?php print_string("concept","glossary") ?>" /></td>
-        </tr>
-        <tr>
-          <td align="right"><b><?php echo get_string("categories","glossary") ?>:</b></td>
-          <td valign="top">
-    <?php
-        $categories = get_records("glossary_categories","glossaryid",$glossary->id,'name ASC');
-        echo "<select size=\"5\" name=\"categories[]\" multiple=\"multiple\" >";
-        echo "<option value=\"0\">" . get_string("notcategorised","glossary") . "</option>";
-
-        if ( $categories ) {
-            foreach ( $categories as $category ) {
-                echo "  <option ";
-                if (isset($newentry->id)) {
-                    if ( record_exists("glossary_entries_categories","entryid",$newentry->id,"categoryid",$category->id) ) {
-                        echo "selected=\"selected\" " ;
-                    }
-                }
-                echo "value=\"$category->id\">".clean_text($category->name)."</option>\n";
-            }
-        }
-        echo "</select>\n";
-    ?>
-          </td>
-        </tr>
-      </table></td>
-    <td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="5">
-        <tr>
-          <td valign="top" align="right"><b>
-            <?php
-              echo get_string("aliases","glossary");
-              echo ':<br />';
-              helpbutton("aliases2", strip_tags(get_string("aliases", "glossary")), "glossary");
-            ?></b>
-          </td>
-          <td valign="top">
-             <textarea rows="2" name="aliases" cols="20"><?php p(clean_text($newentry->aliases)) ?></textarea>
-          </td>
-        </tr>
-        <tr>
-          <td colspan="2">
-<?php
-    if ( !$glossary->usedynalink ) {
-      echo '<input type="hidden" name="usedynalink" value="0" />';
-      echo '<input type="hidden" name="casesensitive" value="0" />';
-      echo '<input type="hidden" name="fullmatch" value="0" />';
-    } else {
-        echo '<script type="text/javascript">var items = [\'casesensitive\',\'fullmatch\'];</script>';
-
-        if (!empty($newentry->usedynalink)) {
-            $selected = "checked=\"checked\"";
-        } else {
-            $selected = "";
-        }
-        echo '<input type="checkbox" name="usedynalink" value="1" alt="' . get_string("entryusedynalink","glossary") . '" ' . $selected . ' onclick="return lockoptions(\'form\',\'usedynalink\', items)" /> ';
-        print_string("entryusedynalink","glossary");
-        echo helpbutton("usedynalinkentry", strip_tags(get_string("usedynalink", "glossary")), "glossary");
-        echo '<br />';
-
-        if (!empty($newentry->casesensitive)) {
-            $selected = "checked";
-        } else {
-            $selected = "";
-        }
-        echo '<input type="checkbox" name="casesensitive" value="1" alt="' . get_string("casesensitive","glossary") . '" ' . $selected . ' /> ';
-        print_string("casesensitive","glossary");
-        echo helpbutton("casesensitive", strip_tags(get_string("casesensitive", "glossary")), "glossary");
-        echo '<br />';
-
-
-        if (!empty($newentry->fullmatch)) {
-            $selected = "checked";
-        } else {
-            $selected = "";
-        }
-        echo '<input type="checkbox" name="fullmatch" value="1" alt="' . get_string("fullmatch","glossary") . '" ' . $selected . ' /> ';
-        print_string("fullmatch","glossary");
-        echo helpbutton("fullmatch", strip_tags(get_string("fullmatch", "glossary")), "glossary");
-        echo '<br />';
-    }
-?>
-          </td>
-        </tr>
-      </table></td>
-  </tr>
-</table>
-</td>
-</tr>
-<tr valign="top">
-    <td align="right"><b>
-     <?php print_string("definition", "glossary"); ?>:
-     </b></td>
-    <td align="left" rowspan="2">
-    <?php print_textarea($usehtmleditor, 25, 65, 630, 400, "text", $newentry->definition); ?>
-    </td>
-</tr>
-<tr valign="top">
-    <td align="right" valign="middle" nowrap="nowrap">
-
-     <?php
-        helpbutton("writing", get_string("helpwriting"), "moodle", true, true);
-        echo "<br />";
-        if ($usehtmleditor) {
-           helpbutton("richtext", get_string("helprichtext"), "moodle", true, true);
-        } else {
-           emoticonhelpbutton("form", "text");
-        }
-        echo "<br />";
-      ?>
-
-    </td>
-</tr>
-<tr valign="top">
-    <td align="right"><b><?php print_string("formattexttype"); ?>:</b></td>
-    <td>
-    <?php
-        if ($usehtmleditor) {   /// Trying this out for a while
-            print_string('formathtml');
-            echo '<input type="hidden" name="format" value="'.FORMAT_HTML.'" />';
-        } else {
-            choose_from_menu(format_text_menu(), "format", $newentry->format, "");
-        }
-        helpbutton("textformat", get_string("helpformatting"));
-     ?>
-    </td>
-</tr>
-
-<tr valign="top">
-    <td align="right"><b><?php print_string("attachment", "glossary") ?>:<br />
-        <?php
-        echo '(';
-        print_string("maxsize", "", display_size(get_max_upload_file_size($CFG->maxbytes, $course->maxbytes)));
-        echo ')<br />';
-        print_string("optional");
-        echo ' ';
-        helpbutton("attachment", get_string("attachment", "glossary"), "glossary");
-        ?></b>
-    </td>
-    <td>
-    <?php
-       require_once($CFG->dirroot.'/lib/uploadlib.php');
-       upload_print_form_fragment(1,array('attachment'),null,false,null,$course->maxbytes,0,false);
-    ?>
-    </td>
-</tr>
-<tr>
-<td colspan="2">
-    <p align="center">
-    <?php if (isset($newentry->id)) {
-        echo "<input type=\"hidden\" name=\"e\" value=\"$newentry->id\" />";
-    }
-  ?>
-
-  <input type="hidden" name="husedynalink" value="1" />
-  <input type="hidden" name="hcasesensitive" value="0" />
-  <input type="hidden" name="hfullmatch" value="1" />
-
-  <input type="hidden" name="id" value="<?php p($cm->id) ?>" />
-  <input type="hidden" name="mode" value="<?php p($mode) ?>" />
-  <input type="hidden" name="hook" value="<?php p($hook) ?>" />
-  <input type="hidden" name="confirm" value="1" />
-
-  <input type="submit" value="<?php print_string("savechanges") ?>" />
-  <input type="reset" value="<?php print_string("revert") ?>" />
-  </p>
-</td>
-</tr>
-</table>
-</form>
index 45e84a91e2cb09603b132b7a86037337247df45c..05b7c05653c334013338b84142253ae56672a340 100644 (file)
@@ -2,6 +2,7 @@
 
 require_once('../../config.php');
 require_once('lib.php');
+require_once('edit_form.php');
 
 global $CFG, $USER;
 
@@ -32,322 +33,196 @@ if (! $glossary = get_record("glossary", "id", $cm->instance)) {
     error("Course module is incorrect");
 }
 
-if ($e) { // if entry is sepcified
+if ($e) { // if entry is specified
     require_capability('mod/glossary:manageentries', $context);
 } else { // new entry
     require_capability('mod/glossary:write', $context);
 }
 
-if ( $confirm ) {
-    $form = data_submitted();
-    trusttext_after_edit($form->text, $context);
+$mform =& new glossary_entry_form(null, compact('cm', 'glossary', 'hook', 'mode', 'e', 'context'));
+if ($mform->is_cancelled()){
+    if ($e){
+        redirect("view.php?id=$cm->id&amp;mode=entry&amp;hook=$e");
+    } else {
+        redirect("view.php?id=$cm->id");
+    }
+
+} elseif ($fromform = $mform->data_submitted()) {
+    trusttext_after_edit($fromform->definition, $context);
 
-    if ( !isset($form->usedynalink) ) {
-        $form->usedynalink = 0;
+    if ( !isset($fromform->usedynalink) ) {
+        $fromform->usedynalink = 0;
     }
-    if ( !isset($form->casesensitive) ) {
-        $form->casesensitive = 0;
+    if ( !isset($fromform->casesensitive) ) {
+        $fromform->casesensitive = 0;
     }
-    if ( !isset($form->fullmatch) ) {
-        $form->fullmatch = 0;
+    if ( !isset($fromform->fullmatch) ) {
+        $fromform->fullmatch = 0;
     }
     $timenow = time();
-    //$form->text = clean_text($form->text, $form->format);
-
-    $newentry->course = $glossary->course;
-    $newentry->glossaryid = $glossary->id;
-
-    $newentry->concept = clean_text(trim($form->concept));
-    $newentry->definition = $form->text;
-    $newentry->format = $form->format;
-    $newentry->usedynalink = $form->usedynalink;
-    $newentry->casesensitive = $form->casesensitive;
-    $newentry->fullmatch = $form->fullmatch;
-    $newentry->timemodified = $timenow;
-    $newentry->approved = 0;
-    $newentry->aliases = "";
-    if ( $glossary->defaultapproval or has_capability('mod/glossary:approve', $context) ) {
-        $newentry->approved = 1;
-    }
-
-    $strglossary = get_string("modulename", "glossary");
-    $strglossaries = get_string("modulenameplural", "glossary");
-    $stredit = get_string("edit");
-
-    if ($form->concept == '' or trim($form->text) == '' ) {
-        $errors = get_string('fillfields','glossary');
-        if ($usehtmleditor = can_use_richtext_editor()) {
-            $defaultformat = FORMAT_HTML;
-        } else {
-            $defaultformat = FORMAT_MOODLE;
-        }
-
-        print_header_simple(format_string($glossary->name), "",
-             "<a href=\"index.php?id=$course->id\">$strglossaries</a> ->
-              <a href=\"view.php?id=$cm->id\">".format_string($glossary->name,true)."</a> -> $stredit", "form.text",
-              "", true, "", navmenu($course, $cm));
-
-        print_heading(format_string($glossary->name));
-
-        /// Info box
-        if ( $glossary->intro ) {
-            print_simple_box(format_text($glossary->intro), 'center', '70%', '', 5, 'generalbox', 'intro');
-        }
-        echo '<br />';
 
-        $tab = GLOSSARY_ADDENTRY_VIEW;
-        include("tabs.html");
-
-        include("edit.html");
-
-        echo '</center>';
-
-        glossary_print_tabbed_table_end();
-
-        // Lets give IE more time to load the whole page
-        // before trying to load the editor.
-        if ($usehtmleditor) {
-           use_html_editor("text");
-        }
-
-        print_footer($course);
-        die;
+    $todb = new object();
+    $todb->course = $glossary->course;
+    $todb->glossaryid = $glossary->id;
+
+    $todb->concept = trim($fromform->concept);
+    $todb->definition = $fromform->definition;
+    $todb->format = $fromform->format;
+    $todb->usedynalink = $fromform->usedynalink;
+    $todb->casesensitive = $fromform->casesensitive;
+    $todb->fullmatch = $fromform->fullmatch;
+    $todb->timemodified = $timenow;
+    $todb->approved = 0;
+    $todb->aliases = "";
+    if ( $glossary->defaultapproval or has_capability('mod/glossary:approve', $context) ) {
+        $todb->approved = 1;
     }
 
     if ($e) {
-        //We are updating an entry, so we compare current session user with
-        //existing entry user to avoid some potential problems if secureforms=off
-        //Perhaps too much security? Anyway thanks to skodak (Bug 1823)
-        $old = get_record('glossary_entries', 'id', $e);
-        $ineditperiod = ((time() - $old->timecreated <  $CFG->maxeditingtime) || $glossary->editalways);
-        if ( (!$ineditperiod  || $USER->id != $old->userid) and !has_capability('mod/glossary:manageentries', $context) and $e) {
-            if ( $USER->id != $old->userid ) {
-                error("You can't edit other people's entries!");
-            } elseif (!$ineditperiod) {
-                error("You can't edit this. Time expired!");
-            }
-            die;
+        /* TODO process file uploads
+        $todb->attachment = $_FILES["attachment"];
+        if ($newfilename = glossary_add_attachment($todb, 'attachment')) {
+            $todb->attachment = $newfilename;
+        } else {
+            unset($todb->attachment);
+        }*/
+        $todb->id = $e;
+        print_object($todb);
+        if (update_record('glossary_entries', $todb)) {
+            add_to_log($course->id, "glossary", "update entry",
+                       "view.php?id=$cm->id&amp;mode=entry&amp;hook=$todb->id",
+                       $todb->id, $cm->id);
+        } else {
+            error("Could not update your glossary");
         }
+    } else {
 
-        $newentry->id = $e;
-
-        $permissiongranted = 1;
-        if ( !$glossary->allowduplicatedentries ) {
-            if ($dupentries = get_records("glossary_entries","lower(concept)", moodle_strtolower($newentry->concept))) {
-                foreach ($dupentries as $curentry) {
-                    if ( $glossary->id == $curentry->glossaryid ) {
-                       if ( $curentry->id != $e ) {
-                          $permissiongranted = 0;
-                           break;
-                       }
-                    }
-                }
-            }
-        }
+        $todb->userid = $USER->id;
+        $todb->timecreated = $timenow;
+        $todb->sourceglossaryid = 0;
+        $todb->teacherentry = has_capability('mod/glossary:manageentries', $context);
 
-        if ( $permissiongranted ) {
-            $newentry->attachment = $_FILES["attachment"];
-            if ($newfilename = glossary_add_attachment($newentry, 'attachment')) {
-                $newentry->attachment = $newfilename;
-            } else {
-                unset($newentry->attachment);
-            }
 
-            if (update_record("glossary_entries", $newentry)) {
-                add_to_log($course->id, "glossary", "update entry", 
-                           "view.php?id=$cm->id&amp;mode=entry&amp;hook=$newentry->id", 
-                           $newentry->id, $cm->id);
-                $redirectmessage = get_string('entryupdated','glossary');
+        if ($todb->id = insert_record("glossary_entries", $todb)) {
+            $e = $todb->id;
+            /* TODO process file uploads
+            $todb->attachment = $_FILES["attachment"];
+            if ($newfilename = glossary_add_attachment($todb, 'attachment')) {
+                $todb->attachment = $newfilename;
             } else {
-                error("Could not update your glossary");
+                 unset($todb->attachment);
             }
+            set_field("glossary_entries", "attachment", $newfilename, "id", $todb->id);*/
+            add_to_log($course->id, "glossary", "add entry",
+                       "view.php?id=$cm->id&amp;mode=entry&amp;hook=$todb->id", $todb->id,$cm->id);
         } else {
-            error("Could not update this glossary entry because this concept already exist.");
-        }
-    } else {
-        
-        $newentry->userid = $USER->id;
-        $newentry->timecreated = $timenow;
-        $newentry->sourceglossaryid = 0;
-        $newentry->teacherentry = has_capability('mod/glossary:manageentries', $context);
-
-        $permissiongranted = 1;
-        if ( !$glossary->allowduplicatedentries ) {
-            if ($dupentries = get_record("glossary_entries","lower(concept)", moodle_strtolower($newentry->concept), "glossaryid", $glossary->id)) {
-                $permissiongranted = 0;
-            }
-        }
-        if ( $permissiongranted ) {
-            if ($newentry->id = insert_record("glossary_entries", $newentry)) {
-                $e = $newentry->id;
-                $newentry->attachment = $_FILES["attachment"];
-                if ($newfilename = glossary_add_attachment($newentry, 'attachment')) {
-                    $newentry->attachment = $newfilename;
-                } else {
-                     unset($newentry->attachment);
-                }
-                set_field("glossary_entries", "attachment", $newfilename, "id", $newentry->id);
-                add_to_log($course->id, "glossary", "add entry", 
-                           "view.php?id=$cm->id&amp;mode=entry&amp;hook=$newentry->id", $newentry->id,$cm->id);
-                $redirectmessage = get_string('entrysaved','glossary');
-            } else {
-                error("Could not insert this new entry");
-            }
-        } else {
-            error("Could not insert this glossary entry because this concept already exist.");
+            error("Could not insert this new entry");
         }
+
     }
 
-    delete_records("glossary_entries_categories","entryid",$e);
-    delete_records("glossary_alias","entryid",$e);
+    delete_records("glossary_entries_categories", "entryid", $e);
+    delete_records("glossary_alias", "entryid", $e);
 
-    if ( isset($form->categories) ) {
+    if (empty($fromform->notcategorised) && isset($fromform->categories)) {
         $newcategory->entryid = $e;
-        foreach ($form->categories as $category) {
+        foreach ($fromform->categories as $category) {
             if ( $category > 0 ) {
                 $newcategory->categoryid = $category;
-                insert_record("glossary_entries_categories",$newcategory, false);
+                insert_record("glossary_entries_categories", $newcategory, false);
             } else {
                 break;
             }
         }
     }
-    if ( isset($form->aliases) ) {
-        if ( $aliases = explode("\n",clean_text($form->aliases)) ) {
+    if ( isset($fromform->aliases) ) {
+        if ( $aliases = explode("\n", $fromform->aliases) ) {
             foreach ($aliases as $alias) {
                 $alias = trim($alias);
                 if ($alias) {
                     unset($newalias);
                     $newalias->entryid = $e;
                     $newalias->alias = $alias;
-                    insert_record("glossary_alias",$newalias, false);
+                    insert_record("glossary_alias", $newalias, false);
                 }
             }
         }
     }
-    redirect("view.php?id=$cm->id&amp;mode=entry&amp;hook=$newentry->id", $redirectmessage);
+    redirect("view.php?id=$cm->id&amp;mode=entry&amp;hook=$todb->id");
 
 } else {
     if ($e) {
-        $form = get_record("glossary_entries", "id", $e);
-
-        $newentry->id = $form->id;
-        $newentry->concept = $form->concept;
-        $newentry->definition = $form->definition;
-        $newentry->format = $form->format;
-        $newentry->timemodified = time();
-        $newentry->approved = $glossary->defaultapproval or has_capability('mod/glossary:approve', $context);
-        $newentry->usedynalink = $form->usedynalink;
-        $newentry->casesensitive = $form->casesensitive;
-        $newentry->fullmatch = $form->fullmatch;
-        $newentry->aliases = "";
-        $newentry->userid = $form->userid;
-        $newentry->timecreated = $form->timecreated;
-
-
-        if ( $aliases = get_records("glossary_alias","entryid",$e) ) {
-            foreach ($aliases as $alias) {
-                $newentry->aliases .= $alias->alias . "\n";
+        $fromdb = get_record("glossary_entries", "id", $e);
+
+        $toform = new object();
+
+        if ($categoriesarr = get_records_menu("glossary_entries_categories", "entryid", $e, '', 'id, categoryid')){
+            $toform->categories = array_values($categoriesarr);
+        } else {
+            $toform->categories = array(0);
+        }
+        $toform->concept = $fromdb->concept;
+        $toform->definition = $fromdb->definition;
+        $toform->format = $fromdb->format;
+        trusttext_prepare_edit($toform->definition, $toform->format, can_use_html_editor(), $context);
+        $toform->approved = $glossary->defaultapproval or has_capability('mod/glossary:approve', $context);
+        $toform->usedynalink = $fromdb->usedynalink;
+        $toform->casesensitive = $fromdb->casesensitive;
+        $toform->fullmatch = $fromdb->fullmatch;
+        $toform->aliases = '';
+        $ineditperiod = ((time() - $fromdb->timecreated <  $CFG->maxeditingtime) || $glossary->editalways);
+        if ((!$ineditperiod  || $USER->id != $fromdb->userid) and !has_capability('mod/glossary:manageentries', $context)) {
+            if ( $USER->id != $fromdb->userid ) {
+                error(get_string('errcannoteditothers', 'glossary'));
+            } elseif (!$ineditperiod) {
+                error(get_string('erredittimeexpired', 'glossary'));
             }
+            die;
         }
-    }
-}
-
 
-//Fill and print the form.
-//We check every field has a default values here!!
-if (!isset($newentry->concept)) {
-    $newentry->concept = "";
-}
-if (!isset($newentry->aliases)) {
-    $newentry->aliases = "";
-}
-if (!isset($newentry->usedynalink)) {
-    if (isset($CFG->glossary_linkentries)) {
-        $newentry->usedynalink = $CFG->glossary_linkentries;
-    } else {
-        $newentry->usedynalink = 0;
-    }
-}
-if (!isset($newentry->casesensitive)) {
-    if (isset($CFG->glossary_casesensitive)) {
-        $newentry->casesensitive = $CFG->glossary_casesensitive;
-    } else {
-        $newentry->casesensitive = 0;
-    }
-}
-if (!isset($newentry->fullmatch)) {
-    if (isset($CFG->glossary_fullmatch)) {
-        $newentry->fullmatch = $CFG->glossary_fullmatch;
-    } else {
-        $newentry->fullmatch = 0;
+        if ( $aliases = get_records_menu("glossary_alias", "entryid", $e, '', 'id, alias') ) {
+            $toform->aliases = implode("\n", $aliases) . "\n";
+        }
+        $mform->set_defaults($toform);
     }
 }
-if (!isset($newentry->definition)) {
-    $newentry->definition = "";
-}
-if (!isset($newentry->timecreated)) {
-    $newentry->timecreated = 0;
-}
-if (!isset($newentry->userid)) {
-    $newentry->userid = $USER->id;
-}
+
 $strglossary = get_string("modulename", "glossary");
 $strglossaries = get_string("modulenameplural", "glossary");
 $stredit = get_string("edit");
 
-if ($usehtmleditor = can_use_richtext_editor()) {
-    $defaultformat = FORMAT_HTML;
-} else {
-    $defaultformat = FORMAT_MOODLE;
-}
 
 print_header_simple(format_string($glossary->name), "",
              "<a href=\"index.php?id=$course->id\">$strglossaries</a> ->
               <a href=\"view.php?id=$cm->id\">".format_string($glossary->name,true)."</a> -> $stredit", "",
               "", true, "", navmenu($course, $cm));
 
-$ineditperiod = ((time() - $newentry->timecreated <  $CFG->maxeditingtime) || $glossary->editalways);
-if ( (!$ineditperiod  || $USER->id != $newentry->userid) and !has_capability('mod/glossary:manageentries', $context) and $e) {
-    if ( $USER->id != $newentry->userid ) {
-        error("You can't edit other people's entries!");
-    } elseif (!$ineditperiod) {
-        error("You can't edit this. Time expired!");
-    }
-    die;
-}
 
-    print_heading(format_string($glossary->name));
+
+print_heading(format_string($glossary->name));
 
 /// Info box
 
-    if ( $glossary->intro ) {
-        print_simple_box(format_text($glossary->intro), 'center', '70%', '', 5, 'generalbox', 'intro');
-    }
+if ( $glossary->intro ) {
+    print_simple_box(format_text($glossary->intro), 'center', '70%', '', 5, 'generalbox', 'intro');
+}
 
-    echo '<br />';
+echo '<br />';
 
 /// Tabbed browsing sections
 $tab = GLOSSARY_ADDENTRY_VIEW;
 include("tabs.html");
 
 if (!$e) {
-    require_capability('mod/glossary:write', $context);  
+    require_capability('mod/glossary:write', $context);
 }
 
-include("edit.html");
-
-echo '</center>';
+$mform->display();
 
+echo '</center>'; //TODO remove center tag from here and tabs.html
 glossary_print_tabbed_table_end();
 
-    // Lets give IE more time to load the whole page
-    // before trying to load the editor.
-    if ($usehtmleditor) {
-       use_html_editor("text");
-    }
-
 
 print_footer($course);
 
-?>
+?>
\ No newline at end of file
diff --git a/mod/glossary/edit_form.php b/mod/glossary/edit_form.php
new file mode 100644 (file)
index 0000000..d803c3d
--- /dev/null
@@ -0,0 +1,141 @@
+<?php
+require_once ($CFG->dirroot.'/lib/formslib.php');
+
+class glossary_entry_form extends moodleform {
+
+       function definition() {
+
+               global $CFG, $COURSE;
+               $mform    =& $this->_form;
+
+               $glossary =& $this->_customdata['glossary'];
+               $mode =& $this->_customdata['mode'];
+               $cm =& $this->_customdata['cm'];
+               $hook =& $this->_customdata['hook'];
+               $e =& $this->_customdata['e'];
+
+//-------------------------------------------------------------------------------
+        $mform->addElement('header', 'general', get_string('general', 'form'));
+
+        $mform->addElement('text', 'concept', get_string('concept', 'glossary'));
+               $mform->setType('concept', PARAM_TEXT);
+               $mform->addRule('concept', null, 'required', null, 'client');
+
+               $mform->addElement('htmleditor', 'definition', get_string('definition', 'glossary'), array('rows'=>20));
+               $mform->setType('definition', PARAM_RAW);
+               $mform->addRule('definition', null, 'required', null, 'client');
+
+               $mform->addElement('format');
+
+        $categories = array();
+        if ($categories = get_records_menu('glossary_categories', 'glossaryid', $glossary->id, 'name ASC', 'id, name')){
+            $categories = array(0 => get_string('notcategorised', 'glossary')) + $categories;
+        } else {
+            $categories = array(0 => get_string('notcategorised', 'glossary'));
+        }
+
+        $categoriesEl = $mform->addElement('select', 'categories', get_string('categories', 'glossary'), $categories);
+        $categoriesEl->setMultiple(true);
+        $categoriesEl->setSize(5);
+
+               $mform->addElement('textarea', 'aliases', get_string('aliases', 'glossary'), 'rows="2" cols="40"');
+               $mform->setType('aliases', PARAM_TEXT);
+        $mform->setHelpButton('aliases', array('aliases2', strip_tags(get_string('aliases', 'glossary')), 'glossary'));
+
+        $this->set_max_file_size();
+        $this->_upload_manager = new upload_manager('attachment', true, false, $COURSE, false, 0, true, true);
+               $mform->addElement('file', 'attachment', get_string('attachment', 'forum'));
+        $mform->setHelpButton('attachment', array('attachment', get_string('attachment', 'glossary'), 'glossary'));
+
+        if (isset($CFG->glossary_linkentries)) {
+            $usedynalink = $CFG->glossary_linkentries;
+        } else {
+            $usedynalink = 0;
+        }
+        if (isset($CFG->glossary_casesensitive)) {
+            $casesensitive = $CFG->glossary_casesensitive;
+        } else {
+            $casesensitive = 0;
+        }
+        if (isset($CFG->glossary_fullmatch)) {
+            $fullmatch = $CFG->glossary_fullmatch;
+        } else {
+            $fullmatch = 0;
+        }
+        if ( !$glossary->usedynalink ) {
+            $mform->addElement('hidden', 'usedynalink', $usedynalink);
+            $mform->addElement('hidden', 'casesensitive', $casesensitive);
+            $mform->addElement('hidden', 'fullmatch', $fullmatch);
+        } else {
+//-------------------------------------------------------------------------------
+            $mform->addElement('header', 'linkinghdr', get_string('linking', 'glossary'));
+
+            $mform->addElement('checkbox', 'usedynalink', get_string('entryusedynalink', 'glossary'));
+            $mform->setHelpButton('usedynalink', array('usedynalinkentry', strip_tags(get_string('usedynalink', 'glossary')), 'glossary'));
+            $mform->setDefault('usedynalink', $usedynalink);
+
+            $mform->addElement('checkbox', 'casesensitive', get_string('casesensitive', 'glossary'));
+            $mform->setHelpButton('casesensitive', array('casesensitive', strip_tags(get_string('casesensitive', 'glossary')), 'glossary'));
+            $mform->disabledIf('casesensitive', 'usedynalink');
+            $mform->setDefault('casesensitive', $casesensitive);
+
+            $mform->addElement('checkbox', 'fullmatch', get_string('fullmatch', 'glossary'));
+            $mform->setHelpButton('fullmatch', array('fullmatch', strip_tags(get_string('fullmatch', 'glossary')), 'glossary'));
+            $mform->disabledIf('fullmatch', 'usedynalink');
+            $mform->setDefault('fullmatch', $fullmatch);
+        }
+
+        $mform->addElement('hidden', 'e', $e);
+        $mform->addElement('hidden', 'id', $cm->id);
+        $mform->addElement('hidden', 'mode', $mode);
+        $mform->addElement('hidden', 'hook', $hook);
+
+//-------------------------------------------------------------------------------
+        $this->add_action_buttons();
+       }
+
+       function validation($data){
+           global $CFG, $USER;
+           $errors = array();
+           $e = $this->_customdata['e'];
+           $glossary = $this->_customdata['glossary'];
+           $context = $this->_customdata['context'];
+           $data['concept'] = trim($data['concept']);
+        if ($e) {
+            //We are updating an entry, so we compare current session user with
+            //existing entry user to avoid some potential problems if secureforms=off
+            //Perhaps too much security? Anyway thanks to skodak (Bug 1823)
+            $old = get_record('glossary_entries', 'id', $e);
+            $ineditperiod = ((time() - $old->timecreated <  $CFG->maxeditingtime) || $glossary->editalways);
+            if ( (!$ineditperiod  || $USER->id != $old->userid) and !has_capability('mod/glossary:manageentries', $context)) {
+                if ( $USER->id != $old->userid ) {
+                    $errors['concept'] = get_string('errcannoteditothers', 'glossary');
+                } elseif (!$ineditperiod) {
+                    $errors['concept'] = get_string('erredittimeexpired', 'glossary');
+                }
+            }
+            if ( !$glossary->allowduplicatedentries ) {
+                if ($dupentries = get_records('glossary_entries', 'lower(concept)', moodle_strtolower($data['concept']))) {
+                    foreach ($dupentries as $curentry) {
+                        if ( $glossary->id == $curentry->glossaryid ) {
+                           if ( $curentry->id != $e ) {
+                               $errors['concept'] = get_string('errconceptalreadyexists', 'glossary');
+                               break;
+                           }
+                        }
+                    }
+                }
+            }
+
+        } else {
+            if ( !$glossary->allowduplicatedentries ) {
+                if ($dupentries = get_record('glossary_entries', 'lower(concept)', moodle_strtolower($data['concept']), 'glossaryid', $glossary->id)) {
+                    $errors['concept'] = get_string('errconceptalreadyexists', 'glossary');
+                }
+            }
+        }
+        return $errors;
+       }
+
+}
+?>
\ No newline at end of file
index ccd523f996212c3fbec16962c491e2821233dc0c..ce99e581ceb98b29f519f19586ef608ea0327a11 100644 (file)
@@ -34,7 +34,7 @@ class glossary_mod_form extends moodleform_mod {
 
         $options = array(1=>get_string('mainglossary', 'glossary'), 0=>get_string('secondaryglossary', 'glossary'));
         $mform->addElement('select', 'mainglossary', get_string('glossarytype', 'glossary'), $options);
-        $mform->setHelpButton('mainglossary', array('mainglossary', get_string('mainglossary', 'glossary'), 'glossary'));$mform->setDefault('allowduplicatedentries', $CFG->glossary_dupentries);
+        $mform->setHelpButton('mainglossary', array('mainglossary', get_string('mainglossary', 'glossary'), 'glossary'));
         $mform->setDefault('mainglossary', 0);
 
         $mform->addElement('selectyesno', 'allowduplicatedentries', get_string('allowduplicatedentries', 'glossary'), $options);
@@ -145,12 +145,8 @@ class glossary_mod_form extends moodleform_mod {
         $this->standard_coursemodule_elements();
 
 //-------------------------------------------------------------------------------
-        $buttonarray=array();
-        $buttonarray[] = &$mform->createElement('submit', 'submitbutton', get_string('savechanges'));
-        $buttonarray[] = &$mform->createElement('reset', 'resetbutton', get_string('revert'));
-        $buttonarray[] = &$mform->createElement('cancel');
-        $mform->addGroup($buttonarray, 'buttonar', '', array(' '), false);
-               $mform->closeHeaderBefore('buttonar');
+        // buttons
+        $this->add_action_buttons();
        }
 
        function definition_after_data(){
index 137f2d12086d446450a93d2375dc3c09ff6d86d0..d8ab781c365797b67d95027b3aae62f6876a78bb 100644 (file)
@@ -44,13 +44,9 @@ class journal_mod_form extends moodleform_mod {
 //-------------------------------------------------------------------------------
                $this->standard_coursemodule_elements();
 //-------------------------------------------------------------------------------
+        // buttons
+        $this->add_action_buttons();
 
-        $buttonarray=array();
-        $buttonarray[] = &$mform->createElement('submit', 'submitbutton', get_string('savechanges'));
-        $buttonarray[] = &$mform->createElement('reset', 'resetbutton', get_string('revert'));
-        $buttonarray[] = &$mform->createElement('cancel');
-        $mform->addGroup($buttonarray, 'buttonar', '', array(' '), false);
-               $mform->closeHeaderBefore('buttonar');
        }
 
 
index 48069acd814a5e66ffaeee9c6b4745f925f74dbf..350d1801149c6045290f536c18345601a9995e65 100644 (file)
@@ -15,12 +15,10 @@ class label_mod_form extends moodleform_mod {
 
         $mform->addElement('modvisible', 'visible', get_string('visible'));
 
-        $buttonarray=array();
-        $buttonarray[] = &$mform->createElement('submit', 'submitbutton', get_string('savechanges'));
-        $buttonarray[] = &$mform->createElement('reset', 'resetbutton', get_string('revert'));
-        $buttonarray[] = &$mform->createElement('cancel');
-        $mform->addGroup($buttonarray, 'buttonar', '', array(' '), false);
-               $mform->closeHeaderBefore('buttonar');
+//-------------------------------------------------------------------------------
+        // buttons
+        $this->add_action_buttons();
+
        }
 
 }
index 3f340e159b29e432995ebeb3334428514b2a458c..f2c9807072425266369fe4a2779261cbba1c6dd4 100644 (file)
@@ -273,13 +273,8 @@ class lesson_mod_form extends moodleform_mod {
 //-------------------------------------------------------------------------------
                $this->standard_coursemodule_elements(false);
 //-------------------------------------------------------------------------------
-
-        $buttonarray=array();
-        $buttonarray[] = &$mform->createElement('submit', 'submitbutton', get_string('savechanges'));
-        $buttonarray[] = &$mform->createElement('reset', 'resetbutton', get_string('revert'));
-        $buttonarray[] = &$mform->createElement('cancel');
-        $mform->addGroup($buttonarray, 'buttonar', '', array(' '), false);
-               $mform->closeHeaderBefore('buttonar');
+        // buttons
+        $this->add_action_buttons();
        }
 
 
index 9a4366288bfdd224dbadb9a18a3be00453f7ef9e..f5f3c27da8a2185f10c6f74718565c0c77321412 100644 (file)
@@ -56,7 +56,7 @@ define("QUIZ_MAX_EVENT_LENGTH", "432000");   // 5 days maximum
  * (defined by the form in mod.html) this function
  * will create a new instance and return the id number
  * of the new instance.
- * 
+ *
  * @param object $quiz the data that came from the form.
  * @return mixed the id of the new instance on success,
  *          false or a string error message on failure.
@@ -78,7 +78,7 @@ function quiz_add_instance($quiz) {
 
     // Do the processing required after an add or an update.
     quiz_after_add_or_update($quiz);
-    
+
     return $quiz->id;
 }
 
@@ -86,7 +86,7 @@ function quiz_add_instance($quiz) {
  * Given an object containing all the necessary data,
  * (defined by the form in mod.html) this function
  * will update an existing instance with new data.
- * 
+ *
  * @param object $quiz the data that came from the form.
  * @return mixed true on success, false or a string error message on failure.
  */
@@ -175,7 +175,7 @@ function quiz_user_outline($course, $user, $mod, $quiz) {
 /// $return->time = the time they did it
 /// $return->info = a short text description
     if ($grade = get_record('quiz_grades', 'userid', $user->id, 'quiz', $quiz->id)) {
-        
+
         $result = new stdClass;
         if ((float)$grade->grade) {
             $result->info = get_string('grade').':&nbsp;'.round($grade->grade, $quiz->decimalpoints);
@@ -464,25 +464,8 @@ function quiz_process_options(&$quiz) {
     $quiz->timemodified = time();
 
     // Quiz open time.
-    if (empty($quiz->availableenable)) {
-        $quiz->timeopen = 0;
+    if (empty($quiz->timeopen)) {
         $quiz->preventlate = 0;
-    } else {
-        $quiz->timeopen = make_timestamp($quiz->availableyear, $quiz->availablemonth, 
-                $quiz->availableday, $quiz->availablehour, $quiz->availableminute);
-    }
-
-    // Quiz close time.
-    if (empty($quiz->dueenable)) {
-        $quiz->timeclose = 0;
-    } else {
-        $quiz->timeclose = make_timestamp($quiz->dueyear, $quiz->duemonth, 
-                $quiz->dueday, $quiz->duehour, $quiz->dueminute);
-    }
-
-    // Check open and close times are consistent.
-    if ($quiz->timeopen != 0 && $quiz->timeclose != 0 && $quiz->timeclose < $quiz->timeopen) {
-        return get_string('closebeforeopen', 'quiz');
     }
 
     // Quiz name. (Make up a default if one was not given.)
@@ -494,15 +477,15 @@ function quiz_process_options(&$quiz) {
         }
     }
     $quiz->name = trim($quiz->name);
-    
+
     // Time limit. (Get rid of it if the checkbox was not ticked.)
-    if (empty($quiz->timelimitenable) or empty($quiz->timelimit) or $quiz->timelimit < 0) {
+    if (empty($quiz->timelimitenable)) {
         $quiz->timelimit = 0;
     }
     $quiz->timelimit = round($quiz->timelimit);
-    
+
     // Quiz feedback
-    
+
     // Clean up the boundary text.
     for ($i = 0; $i < count($quiz->feedbacktext); $i += 1) {
         if (empty($quiz->feedbacktext[$i])) {
@@ -511,7 +494,7 @@ function quiz_process_options(&$quiz) {
             $quiz->feedbacktext[$i] = trim($quiz->feedbacktext[$i]);
         }
     }
-    
+
     // Check the boundary value is a number or a percentage, and in range.
     $i = 0;
     while (!empty($quiz->feedbackboundaries[$i])) {
@@ -536,7 +519,7 @@ function quiz_process_options(&$quiz) {
         $i += 1;
     }
     $numboundaries = $i;
-    
+
     // Check there is nothing in the remaining unused fields.
     for ($i = $numboundaries; $i < count($quiz->feedbackboundaries); $i += 1) {
         if (!empty($quiz->feedbackboundaries[$i]) && trim($quiz->feedbackboundaries[$i]) != '') {
@@ -551,7 +534,7 @@ function quiz_process_options(&$quiz) {
     $quiz->feedbackboundaries[-1] = $quiz->grade + 1; // Needs to be bigger than $quiz->grade because of '<' test in quiz_feedback_for_grade().
     $quiz->feedbackboundaries[$numboundaries] = 0;
     $quiz->feedbackboundarycount = $numboundaries;
-    
+
     // Settings that get combined to go into the optionflags column.
     $quiz->optionflags = 0;
     if (!empty($quiz->adaptive)) {
@@ -644,14 +627,14 @@ function quiz_process_options(&$quiz) {
 /**
  * This function is called at the end of quiz_add_instance
  * and quiz_update_instance, to do the common processing.
- * 
+ *
  * @param object $quiz the quiz object.
  */
 function quiz_after_add_or_update($quiz) {
 
     // Save the feedback
     delete_records('quiz_feedback', 'quizid', $quiz->id);
-    
+
     for ($i = 0; $i <= $quiz->feedbackboundarycount; $i += 1) {
         $feedback = new stdClass;
         $feedback->quizid = $quiz->id;
@@ -664,9 +647,7 @@ function quiz_after_add_or_update($quiz) {
     }
 
     // Remember whether this user likes the advanced settings visible or hidden.
-    if (isset($quiz->optionsettingspref)) {
-        set_user_preference('quiz_optionsettingspref', $quiz->optionsettingspref);
-    }
+    set_user_preference('quiz_optionsettingspref', $quiz->mform_showadvanced_last);
 
     // Update the events relating to this quiz.
     // This is slightly inefficient, deleting the old events and creating new ones. However,
diff --git a/mod/quiz/mod.html b/mod/quiz/mod.html
deleted file mode 100644 (file)
index eceb7f6..0000000
+++ /dev/null
@@ -1,570 +0,0 @@
-<?php
-// This page defines the form to create or edit an instance of this module -->
-// It is used from /course/mod.php. The whole instance is available as $form. -->
-
-    require_once("$CFG->dirroot/mod/quiz/locallib.php");
-
-    // Set any form variables that have not been initialized to their default value.
-    if (!isset($form->name)) {
-        $form->name = "";
-    }
-    if (!isset($form->intro)) {
-        $form->intro = "";
-    }
-    if (!isset($form->timeopen)) {
-        $form->timeopen = "";
-    }
-    if (!isset($form->timeclose)) {
-        $form->timeclose = "";
-    }
-    if (!isset($form->attempts)) {
-        $form->attempts = $CFG->quiz_attempts;
-    }
-    if (!isset($form->attemptonlast)) {
-        $form->attemptonlast = $CFG->quiz_attemptonlast;
-    }
-    if (!isset($form->grademethod)) {
-        $form->grademethod = $CFG->quiz_grademethod;
-    }
-    if (!isset($form->decimalpoints)) {
-        $form->decimalpoints = $CFG->quiz_decimalpoints;
-    }
-    if (!isset($form->review)) {
-        $form->review = $CFG->quiz_review;
-    }
-    if (!isset($form->questionsperpage)) {
-        $form->questionsperpage = $CFG->quiz_questionsperpage;
-    }
-    if (!isset($form->shufflequestions)) {
-        $form->shufflequestions = $CFG->quiz_shufflequestions;
-    }
-    if (!isset($form->shuffleanswers)) {
-        $form->shuffleanswers = $CFG->quiz_shuffleanswers;
-    }
-    if (!isset($form->grade)) {
-        $form->grade = $CFG->quiz_maximumgrade;
-    }
-    if (!isset($form->questions)) {
-        $form->questions = "";
-    }
-    if (!isset($form->password)) {
-        $form->password = $CFG->quiz_password;
-    }
-    if (!isset($form->subnet)) {
-        $form->subnet = $CFG->quiz_subnet;
-    }
-    if (!isset($form->timelimit)) {
-        $form->timelimit = $CFG->quiz_timelimit;
-    }
-    if (!isset($form->popup)) {
-        $form->popup = $CFG->quiz_popup;
-    }
-    if (!isset($form->optionflags)) {
-        $form->optionflags = $CFG->quiz_optionflags;
-    }
-    if (!isset($form->penaltyscheme)) {
-        $form->penaltyscheme = $CFG->quiz_penaltyscheme;
-    }
-    if (empty($form->timedue)) {
-        $form->timedue = "";
-    }
-    //enforced time delay between quiz attempts
-    //delay1: time delay between first and second attempt
-    //delay2: time delay between second and additional quiz attempt
-    if (!isset($form->delay1)) {
-         $form->delay1 = $CFG->quiz_delay1;
-    }
-    if (!isset($form->delay2)) {
-         $form->delay2 = $CFG->quiz_delay2;
-    }
-    
-    // Get any existing feedback text out of the database.
-    if (!empty($form->id)) {
-        $feedbacks = get_records('quiz_feedback', 'quizid', $form->id, 'mingrade DESC');
-    } else {
-        $feedbacks = array();
-    }
-    $form->feedbacktext = array();
-    $form->feedbackboundaries = array();
-    foreach ($feedbacks as $feedback) {
-        $form->feedbacktext[] = $feedback->feedbacktext;
-        if ($feedback->mingrade > 0) {
-            $form->feedbackboundaries[] = (100.0 * $feedback->mingrade / $form->grade) . '%';
-        }
-    }
-
-    // Make sure there are at least 5 feedbacktexts, or a bit more than the current nubmer.
-    $numfeedbacks = max(
-            count($form->feedbacktext) * 1.5,
-            count($form->feedbackboundaries) * 1.5,
-            5
-    );
-    
-    for ($i = 0; $i < $numfeedbacks; $i += 1) {
-        if (!array_key_exists($i, $form->feedbacktext)) {
-            $form->feedbacktext[$i] = '';
-        }
-        if (!array_key_exists($i, $form->feedbackboundaries)) {
-            $form->feedbackboundaries[$i] = '';
-        }
-    }
-
-    // The following are used for drop-down menus
-    $yesnooptions = array(get_string("no"), get_string("yes"));
-
-    $attemptoptions = array();
-    $attemptoptions[0] = get_string("attemptsunlimited", "quiz");
-    $attemptoptions[1] = "1 ".moodle_strtolower(get_string("attempt", "quiz"));
-    for ($i=2;$i<=6;$i++) {
-        $attemptoptions[$i] = "$i ".moodle_strtolower(get_string("attempts", "quiz"));
-    }
-
-    //enforced time delay between quiz attempts add-on
-    $timedelayoptions = array();
-    $timedelayoptions[0] = get_string('none');
-    $timedelayoptions[1800] = get_string('numminutes', '', 30);
-    $timedelayoptions[3600] = get_string('numminutes', '', 60);
-    for($i=2; $i<=23; $i++) {
-         $seconds  = $i*3600;
-         $timedelayoptions[$seconds] = get_string('numhours', '', $i);
-    }
-    $timedelayoptions[86400] = get_string('numhours', '', 24);
-    for($i=2; $i<=7; $i++) {
-         $seconds = $i*86400;
-         $timedelayoptions[$seconds] = get_string('numdays', '', $i);
-    }
-
-?>
-<script type="text/javascript" language="javascript">
-    var dueitems = ['dueday','duemonth','dueyear','duehour', 'dueminute'];
-    var availableitems = ['availableday','availablemonth','availableyear','availablehour', 'availableminute'];
-    var timelimititems = ['timelimit'];
-</script>
-
-<form name="form" method="post" action="mod.php">
-
-<center>
-
-<!-- Now comes a table with all the options that have not been fixed by the admin -->
-<table cellpadding="5">
-
-<tr valign="top">
-    <td align="right"><b><?php print_string("name") ?>:</b></td>
-    <td align="left">
-        <input type="text" name="name" size="40" value="<?php p($form->name) ?>" />
-    </td>
-</tr>
-
-<tr valign="top">
-    <td align="right"><b><?php print_string("introduction", "quiz") ?>:</b><br /><br />
-     <?php
-        if ($usehtmleditor) {
-           helpbutton("richtext", get_string("helprichtext"), "moodle", true, true);
-        } else {
-           helpbutton("text", get_string("helptext"), "moodle", true, true);
-           echo '<br />';
-           emoticonhelpbutton("form", "description");
-           echo '<br />';
-        }
-      ?>
-    </td>
-    <td align="left">
-        <?php
-           print_textarea($usehtmleditor, 20, 50, 680, 400, "intro", $form->intro);
-        ?>
-    </td>
-</tr>
-
-<tr valign="top">
-   <td align="right"><b><?php print_string("quizopen", "quiz") ?>:</b></td>
-    <td align="left">
-        <input name="availableenable" type="checkbox" value="1" alt="<?php print_string("quizopen", "quiz") ?>" onclick="return lockoptions('form', 'availableenable', availableitems)" <?php if ($form->timeopen) echo 'checked="checked"' ?> />
-    <?php
-           print_date_selector("availableday", "availablemonth", "availableyear", $form->timeopen);
-           echo "&nbsp;-&nbsp;";
-           print_time_selector("availablehour", "availableminute", $form->timeopen);
-           helpbutton('timeopen', get_string('quizopens', 'quiz'), 'quiz');
-     ?>
-        <input type="hidden" name="havailableday"    value="0" />
-        <input type="hidden" name="havailablemonth"  value="0" />
-        <input type="hidden" name="havailableyear"   value="0" />
-        <input type="hidden" name="havailablehour"   value="0" />
-        <input type="hidden" name="havailableminute" value="0" />
-    </td>
-</tr>
-
-<tr valign="top">
-    <td align="right"><b><?php print_string("quizclose", "quiz") ?>:</b></td>
-    <td align="left">
-        <input name="dueenable" type="checkbox" value="1" alt="<?php print_string("quizclose", "quiz") ?>" onclick="return lockoptions('form', 'dueenable', dueitems)" <?php if ($form->timeclose) echo 'checked="checked"' ?> />
-    <?php
-           print_date_selector("dueday", "duemonth", "dueyear", $form->timeclose);
-           echo "&nbsp;-&nbsp;";
-           print_time_selector("duehour", "dueminute", $form->timeclose);
-           helpbutton('timeopen', get_string('quizcloses', 'quiz'), 'quiz');
-     ?>
-        <input type="hidden" name="hdueday"    value="0" />
-        <input type="hidden" name="hduemonth"  value="0" />
-        <input type="hidden" name="hdueyear"   value="0" />
-        <input type="hidden" name="hduehour"   value="0" />
-        <input type="hidden" name="hdueminute" value="0" />
-    </td>
-</tr>
-
-<?php 
-
-    // Output all the options that may, or may not, have been fixed by the admin.
-    // This time out put the ones that were not fixed.
-    $fix = output_quiz_options_fields($form, 0);
-
-    // Output standard module settings.
-    print_standard_coursemodule_settings($form);
-
-    // Output the boxes for typing feedback depending on overall quiz score.
-?>
-<tr><td colspan="2">
-    <?php print_heading_with_help(get_string('overallfeedback', 'quiz'), 'overallfeedback', 'quiz'); ?>
-</td></tr>
-
-<tr valign="top">
-    <td align="right"><b><?php print_string('gradeboundary', 'quiz') ?>:</b></td>
-    <td align="left">100%</td>
-</tr>
-
-<?php for ($i = 0; $i < count($form->feedbacktext); $i = $i + 1) { ?>
-    
-<tr valign="top">
-    <td align="right"><b><?php print_string('feedback', 'quiz') ?>:</b></td>
-    <td align="left">
-        <input type="text" name="feedbacktext[]" size="60" value="<?php p($form->feedbacktext[$i]) ?>" />
-    </td>
-</tr>
-        
-<?php     if ($i < count($form->feedbacktext) - 1) { ?>    
-<tr valign="top">
-    <td align="right"><b><?php print_string('gradeboundary', 'quiz') ?>:</b></td>
-    <td align="left">
-        <input type="text" name="feedbackboundaries[]" size="20" value="<?php p($form->feedbackboundaries[$i]) ?>" />
-    </td>
-</tr>
-<?php     } ?>
-
-<?php } ?>
-<tr valign="top">
-    <td align="right"><b><?php print_string('gradeboundary', 'quiz') ?>:</b></td>
-    <td align="left">0%</td>
-</tr>
-
-<?php
-    if ($fix) {
-        // Some options were fixed by the admin. Show them, but hidden behind an Advanced button.
-?>
-<tr>
-    <td align="right"><b><?php print_string('advancedsettings') ?>:</b>
-        <!-- Some javascript to allow for the hiding of advanced options
-         This code was derived from mod.html in the resource module -->
-        <script language="javascript" type="text/javascript">
-            function showhide (id, set) {
-                divobj = document.getElementById(id);
-                butobj = document.getElementById(id+'button');
-                prefobj = document.getElementById(id+'pref');
-                if (set == true) {
-                    if (prefobj.value == '1') {
-                        divobj.style.display = 'block';
-                        butobj.value = '<?php print_string("hideadvancedsettings") ?>';
-                    } else {
-                        divobj.style.display = 'none';
-                        butobj.value = '<?php print_string("showadvancedsettings") ?>...';
-                    }
-                } else {
-                    if (prefobj.value == '1') {
-                        divobj.style.display = 'none';
-                        butobj.value = '<?php print_string("showadvancedsettings") ?>...';
-                        prefobj.value = '0';
-                    } else {
-                        divobj.style.display = 'block';
-                        butobj.value = '<?php print_string("hideadvancedsettings") ?>';
-                        prefobj.value = '1';
-                    }
-                }
-            }
-        </script>
-    </td>
-     <td align="left">
-        <input type="button" value="hide settings" id="optionsettingsbutton" onclick="javascript: return showhide('optionsettings');" />
-        <input type="hidden" name="optionsettingspref" id="optionsettingspref" value="<?php echo get_user_preferences('quiz_optionsettingspref', 0); ?>" />
-        <br />
-    </td>
-</tr>
-
-<!-- Now comes a copy of the options fields in a div with id optionsettings and with
-     the conditions reversed, so that it shows exactly the options that are usually hidden.
-     The visibility of this div is controlled by javascript. -->
-<tr><td colspan="2">
-<div id="optionsettings">
-<table align="center">
-
-<?php
-    // Output all the options that may, or may not, have been fixed by the admin.
-    // This time out put the ones that were fixed.
-    output_quiz_options_fields($form, 1);
-?>
-</table>
-<script language="javascript" type="text/javascript">
-    showhide('optionsettings', true);
-</script>
-</div></td></tr>
-<?php } ?>
-
-</table>
-<br />
-<input type="hidden" name="grade" value="<?php echo $form->grade; ?>" />
-
-<!-- these hidden variables are always the same -->
-<input type="hidden" name="course"        value="<?php p($form->course) ?>" />
-<input type="hidden" name="sesskey"       value="<?php p($form->sesskey) ?>" />
-<input type="hidden" name="coursemodule"  value="<?php p($form->coursemodule) ?>" />
-<input type="hidden" name="section"       value="<?php p($form->section) ?>" />
-<input type="hidden" name="module"        value="<?php p($form->module) ?>" />
-<input type="hidden" name="modulename"    value="<?php p($form->modulename) ?>" />
-<input type="hidden" name="instance"      value="<?php p($form->instance) ?>" />
-<input type="hidden" name="mode"          value="<?php p($form->mode) ?>" />
-<!-- provide an additional button to edit questions -->
-<?php if ($form->instance) { ?>
-<input type="hidden" name="redirecturl" value="<?php p("$CFG->wwwroot/mod/quiz/edit.php?quizid=$form->instance") ?>" />
-<input type="submit" name="redirect" value="<?php print_string("savechanges") ?>" />
-<?php } else { ?>
-<input type="submit" value="<?php print_string("savechanges") ?>" />
-<?php } ?>
-<input type="submit" name="cancel" value="<?php print_string("cancel") ?>" />
-</center>
-</form>
-
-<script type="text/javascript">
-<?php
-    if (!$form->timeclose) echo "lockoptions('form','dueenable', dueitems);";
-    if (!$form->timeopen) echo "lockoptions('form','availableenable', availableitems);";
-    if (!$form->timelimit) echo "lockoptions('form','timelimitenable', timelimititems);";
-?>
-</script>
-
-<?php
-/**
- * This function outputs all the quiz options that may, or may not, have been 
- * locked by admin. Whether the locked or unlocked fields are shown depends on
- * $showfixed.
- * 
- * @param object $form the data being used to initialise the form.
- * @param integer $showfixed if 0, output the unlocked fields, if 1 output the locked fields.
- * @return boolean true if some filds were not output with this setting of $showfixed
- */
-function output_quiz_options_fields($form, $showfixed) {
-    global $CFG, $QUIZ_GRADE_METHOD, $yesnooptions, $attemptoptions, $timedelayoptions;
-    
-    $hidden = false;
-?>
-
-<?php if ($CFG->quiz_fix_timelimit == $showfixed) { ?>
-    <tr valign="top">
-        <td align="right"><b><?php print_string("timelimit", "quiz") ?>:</b></td>
-        <td align="left">
-            <input name="timelimitenable" type="checkbox" value="1" alt="<?php print_string('timelimit', 'quiz') ?>" onclick="return lockoptions('form', 'timelimitenable', timelimititems)" <?php if ($form->timelimit) echo 'checked="checked"' ?> />
-            <input type="text" name="timelimit" size="3" value="<?php p($form->timelimit ? $form->timelimit : '') ?>" />
-            <?php
-                print_string('minutes');
-                helpbutton("timelimit", get_string("quiztimer","quiz"), "quiz");
-            ?>
-            <input type="hidden" name="htimelimit"    value="0" />
-        </td>
-    </tr>
-<?php } else { $hidden = true; } ?>
-
-<?php if ($CFG->quiz_fix_questionsperpage == $showfixed) { ?>
-    <tr valign="top">
-        <td align="right"><b><?php print_string('questionsperpage', 'quiz') ?>:</b></td>
-         <td align="left">
-        <?php
-            $perpage= array();
-            for ($i=0; $i<=50; ++$i) {
-                $perpage[$i] = $i;
-            }
-            $perpage[0] = get_string('allinone', 'quiz');
-
-            choose_from_menu($perpage, 'questionsperpage', $form->questionsperpage, '');
-            helpbutton('questionsperpage', get_string('questionsperpage', 'quiz'), 'quiz');
-         ?>
-        </td>
-    </tr>
-<?php } else { $hidden = true; } ?>
-
-<?php if ($CFG->quiz_fix_shufflequestions == $showfixed) { ?>
-    <tr valign="top">
-        <td align="right"><b><?php print_string("shufflequestions", "quiz") ?>:</b></td>
-         <td align="left">
-        <?php
-            choose_from_menu($yesnooptions, "shufflequestions", "$form->shufflequestions", "");
-            helpbutton("shufflequestions", get_string("shufflequestions","quiz"), "quiz");
-         ?>
-        </td>
-    </tr>
-<?php } else { $hidden = true; } ?>
-
-<?php if ($CFG->quiz_fix_shuffleanswers == $showfixed) { ?>
-    <tr valign="top">
-        <td align="right"><b><?php print_string("shufflewithin", "quiz") ?>:</b></td>
-         <td align="left">
-        <?php
-            choose_from_menu($yesnooptions, "shuffleanswers", "$form->shuffleanswers", "");
-            helpbutton("shufflewithin", get_string("shufflewithin","quiz"), "quiz");
-         ?>
-        </td>
-    </tr>
-<?php } else { $hidden = true; } ?>
-
-<?php if ($CFG->quiz_fix_attempts == $showfixed) { ?>
-    <tr valign="top">
-        <td align="right"><b><?php print_string("attemptsallowed", "quiz") ?>:</b></td>
-         <td align="left">
-        <?php
-            choose_from_menu($attemptoptions, "attempts", "$form->attempts", "");
-            helpbutton("attempts", get_string("attemptsallowed","quiz"), "quiz");
-         ?>
-        </td>
-    </tr>
-<?php } else { $hidden = true; } ?>
-
-<?php if ($CFG->quiz_fix_attemptonlast == $showfixed) { ?>
-    <tr valign="top">
-        <td align="right"><b><?php print_string("eachattemptbuildsonthelast", "quiz") ?>:</b></td>
-         <td align="left">
-        <?php
-            choose_from_menu($yesnooptions, "attemptonlast",
-                             "$form->attemptonlast", "");
-            helpbutton("repeatattempts",
-                       get_string("eachattemptbuildsonthelast", "quiz"),
-                       "quiz");
-        ?>
-        </td>
-    </tr>
-<?php } else { $hidden = true; } ?>
-
-<?php if ($CFG->quiz_fix_grademethod == $showfixed) { ?>
-    <tr valign="top">
-        <td align="right"><b><?php print_string("grademethod", "quiz") ?>:</b></td>
-         <td align="left">
-        <?php
-            choose_from_menu($QUIZ_GRADE_METHOD, "grademethod", "$form->grademethod", "");
-            helpbutton("grademethod", get_string("grademethod","quiz"), "quiz");
-         ?>
-        </td>
-    </tr>
-<?php } else { $hidden = true; } ?>
-
-<?php if ($CFG->quiz_fix_adaptive == $showfixed) { ?>
-    <tr valign="top">
-        <td align="right"><b><?php print_string("adaptive", "quiz") ?>:</b></td>
-         <td align="left">
-        <?php
-            choose_from_menu($yesnooptions, "adaptive", ($form->optionflags & QUESTION_ADAPTIVE) ? 1 : 0, "");
-            helpbutton("adaptive", get_string("adaptive","quiz"), "quiz");
-         ?>
-        </td>
-    </tr>
-<?php } else { $hidden = true; } ?>
-
-<?php if ($CFG->quiz_fix_penaltyscheme == $showfixed) { ?>
-    <tr valign="top">
-        <td align="right"><b><?php print_string("penaltyscheme", "quiz") ?>:</b></td>
-         <td align="left">
-        <?php
-            choose_from_menu($yesnooptions, "penaltyscheme", "$form->penaltyscheme", "");
-            helpbutton("penaltyscheme", get_string("penaltyscheme","quiz"), "quiz");
-         ?>
-        </td>
-    </tr>
-<?php } else { $hidden = true; } ?>
-
-<?php if ($CFG->quiz_fix_decimalpoints == $showfixed) { ?>
-    <tr valign="top">
-        <td align="right"><b><?php print_string("decimaldigits", "quiz") ?>:</b></td>
-         <td align="left">
-         <?php
-            $options = array(
-                    0 => '0',
-                    1 => '1',
-                    2 => '2',
-                    3 => '3'
-            );
-            choose_from_menu($options, "decimalpoints", "$form->decimalpoints", "");
-            helpbutton("decimalpoints", get_string("decimaldigits","quiz"), "quiz");
-         ?>
-        </td>
-    </tr>
-<?php } else { $hidden = true; } ?>
-
-<?php if ($CFG->quiz_fix_review == $showfixed) {
-    echo '<tr valign="top">';
-    include($CFG->dirroot . '/mod/quiz/reviewoptions.html');
-    echo '</tr>';
-    $output = true;
-} ?>
-
-<?php if ($CFG->quiz_fix_delay1 == $showfixed) { ?>
-    <tr valign="top">
-        <td align="right"><b><?php print_string("delay1", "quiz") ?>:</b></td>
-        <td align="left">
-        <?php
-             choose_from_menu($timedelayoptions, "delay1", "$form->delay1", "");
-             helpbutton("timedelay1", get_string("delay1","quiz"), "quiz");
-        ?>
-        </td>
-        </tr>
-<?php } else { $hidden = true; } ?>
-
-<?php if ($CFG->quiz_fix_delay2 == $showfixed) { ?>
-    <tr valign="top">
-        <td align="right"><b><?php print_string("delay2", "quiz") ?>:</b></td>
-        <td align="left">
-        <?php
-             choose_from_menu($timedelayoptions, "delay2", "$form->delay2", "");
-             helpbutton("timedelay2", get_string("delay2","quiz"), "quiz");
-        ?>
-        </td>
-        </tr>
-<?php } else { $hidden = true; } ?>
-
-<?php if ($CFG->quiz_fix_popup == $showfixed) { ?>
-    <tr valign="top">
-        <td align="right"><b><?php print_string("popup", "quiz") ?>:</b></td>
-         <td align="left">
-        <?php
-            choose_from_menu($yesnooptions, "popup", "$form->popup", "");
-            helpbutton("popup", get_string("popup","quiz"), "quiz");
-         ?>
-        </td>
-    </tr>
-<?php } else { $hidden = true; } ?>
-
-<?php if ($CFG->quiz_fix_password == $showfixed) { ?>
-    <tr valign="top">
-        <td align="right"><b><?php print_string("requirepassword", "quiz") ?>:</b></td>
-         <td align="left">
-            <input type="text" name="password" size="40" value="<?php p($form->password) ?>" />
-            <?php helpbutton("requirepassword", get_string("requirepassword", "quiz"), "quiz"); ?>
-        </td>
-    </tr>
-<?php } else { $hidden = true; } ?>
-
-<?php if ($CFG->quiz_fix_subnet == $showfixed) { ?>
-    <tr valign="top">
-        <td align="right"><b><?php print_string("requiresubnet", "quiz") ?>:</b></td>
-         <td align="left">
-            <input type="text" name="subnet" size="40" value="<?php p($form->subnet) ?>" />
-            <?php helpbutton("requiresubnet", get_string("requiresubnet", "quiz"), "quiz"); ?>
-        </td>
-    </tr>
-<?php } else { $hidden = true; } ?>
-<?php
-    return $hidden;
-}
-?>
\ No newline at end of file
diff --git a/mod/quiz/mod_form.php b/mod/quiz/mod_form.php
new file mode 100644 (file)
index 0000000..d083a9c
--- /dev/null
@@ -0,0 +1,334 @@
+<?php
+require_once ('moodleform_mod.php');
+
+require_once("$CFG->dirroot/mod/quiz/locallib.php");
+
+class quiz_mod_form extends moodleform_mod {
+    var $_feedbacks;
+
+       function definition() {
+
+               global $COURSE, $CFG, $QUIZ_GRADE_METHOD;
+               $mform    =& $this->_form;
+
+               $mform->setShowAdvanced(get_user_preferences('quiz_optionsettingspref', 0));
+//-------------------------------------------------------------------------------
+        $mform->addElement('header', 'general', get_string('general', 'form'));
+
+        $mform->addElement('text', 'name', get_string('name'));
+               $mform->setType('name', PARAM_TEXT);
+
+       $mform->addElement('htmleditor', 'intro', get_string("introduction", "quiz"));
+               $mform->setType('intro', PARAM_RAW);
+
+//-------------------------------------------------------------------------------
+        $mform->addElement('header', 'timinghdr', get_string('timing', 'form'));
+        $mform->addElement('date_selector', 'timeopen', get_string("quizopen", "quiz"), array('optional'=>true));
+               $mform->setHelpButton('timeopen', array('timeopen', get_string('quizopens', 'quiz'), 'quiz'));
+
+        $mform->addElement('date_selector', 'timeclose', get_string("quizcloses", "quiz"), array('optional'=>true));
+               $mform->setHelpButton('timeclose', array('timeopen', get_string('quizcloses', 'quiz'), 'quiz'));
+
+
+        $timelimitgrp=array();
+        $timelimitgrp[] = &$mform->createElement('text', 'timelimit');
+        $timelimitgrp[] = &$mform->createElement('checkbox', 'timelimitenable', '', get_string('enable'));
+        $mform->addGroup($timelimitgrp, 'timelimitgrp', get_string("timelimit", "quiz"), array(' '), false);
+               $mform->setType('timelimit', PARAM_TEXT);
+               $timelimitgrprules = array();
+               $timelimitgrprules['timelimit'][] = array(null, 'numeric', null, 'client');
+               $mform->addGroupRule('timelimitgrp', $timelimitgrprules);
+        $mform->disabledIf('timelimitgrp', 'timelimitenable');
+               $mform->setAdvanced('timelimitgrp', $CFG->quiz_fix_timelimit);
+               $mform->setHelpButton('timelimitgrp', array("timelimit", get_string("quiztimer","quiz"), "quiz"));
+        $mform->setDefault('timelimit', $CFG->quiz_timelimit);
+
+
+        //enforced time delay between quiz attempts add-on
+        $timedelayoptions = array();
+        $timedelayoptions[0] = get_string('none');
+        $timedelayoptions[1800] = get_string('numminutes', '', 30);
+        $timedelayoptions[3600] = get_string('numminutes', '', 60);
+        for($i=2; $i<=23; $i++) {
+             $seconds  = $i*3600;
+             $timedelayoptions[$seconds] = get_string('numhours', '', $i);
+        }
+        $timedelayoptions[86400] = get_string('numhours', '', 24);
+        for($i=2; $i<=7; $i++) {
+             $seconds = $i*86400;
+             $timedelayoptions[$seconds] = get_string('numdays', '', $i);
+        }
+        $mform->addElement('select', 'delay1', get_string("delay1", "quiz"), $timedelayoptions);
+               $mform->setHelpButton('delay1', array("timedelay1", get_string("delay1", "quiz"), "quiz"));
+               $mform->setAdvanced('delay1', $CFG->quiz_fix_delay1);
+        $mform->setDefault('delay1', $CFG->quiz_delay1);
+
+        $mform->addElement('select', 'delay2', get_string("delay2", "quiz"), $timedelayoptions);
+               $mform->setHelpButton('delay2', array("timedelay2", get_string("delay2", "quiz"), "quiz"));
+               $mform->setAdvanced('delay2', $CFG->quiz_fix_delay2);
+        $mform->setDefault('delay2', $CFG->quiz_delay2);
+
+//-------------------------------------------------------------------------------
+        $mform->addElement('header', 'displayhdr', get_string('display', 'form'));
+               $perpage = array();
+        for ($i = 0; $i <= 50; ++$i) {
+            $perpage[$i] = $i;
+        }
+        $perpage[0] = get_string('allinone', 'quiz');
+               $mform->addElement('select', 'questionsperpage', get_string('questionsperpage', 'quiz'), $perpage);
+               $mform->setHelpButton('questionsperpage', array('questionsperpage', get_string('questionsperpage', 'quiz'), 'quiz'));
+               $mform->setAdvanced('questionsperpage', $CFG->quiz_fix_questionsperpage);
+        $mform->setDefault('questionsperpage', $CFG->quiz_questionsperpage);
+
+               $mform->addElement('selectyesno', 'shufflequestions', get_string("shufflequestions", "quiz"));
+               $mform->setHelpButton('shufflequestions', array("shufflequestions", get_string("shufflequestions","quiz"), "quiz"));
+               $mform->setAdvanced('shufflequestions', $CFG->quiz_fix_shufflequestions);
+        $mform->setDefault('shufflequestions', $CFG->quiz_shufflequestions);
+
+               $mform->addElement('selectyesno', 'shuffleanswers', get_string("shufflewithin", "quiz"));
+               $mform->setHelpButton('shuffleanswers', array("shufflewithin", get_string("shufflewithin","quiz"), "quiz"));
+               $mform->setAdvanced('shuffleanswers', $CFG->quiz_fix_shuffleanswers);
+        $mform->setDefault('shuffleanswers', $CFG->quiz_shuffleanswers);
+
+//-------------------------------------------------------------------------------
+        $mform->addElement('header', 'attemptshdr', get_string('attempts', 'quiz'));
+               $attemptoptions = array();
+        $attemptoptions[0] = get_string("attemptsunlimited", "quiz");
+        $attemptoptions[1] = "1 ".moodle_strtolower(get_string("attempt", "quiz"));
+        for ($i=2;$i<=6;$i++) {
+            $attemptoptions[$i] = "$i ".moodle_strtolower(get_string("attempts", "quiz"));
+        }
+               $mform->addElement('select', 'attempts', get_string("attemptsallowed", "quiz"), $attemptoptions);
+               $mform->setHelpButton('attempts', array("attempts", get_string("attemptsallowed","quiz"), "quiz"));
+               $mform->setAdvanced('attempts', $CFG->quiz_fix_attempts);
+        $mform->setDefault('attempts', $CFG->quiz_attempts);
+
+               $mform->addElement('selectyesno', 'attemptonlast', get_string("eachattemptbuildsonthelast", "quiz"));
+               $mform->setHelpButton('attemptonlast', array("repeatattempts", get_string("eachattemptbuildsonthelast", "quiz"), "quiz"));
+               $mform->setAdvanced('attemptonlast', $CFG->quiz_fix_attemptonlast);
+        $mform->setDefault('attemptonlast', $CFG->quiz_attemptonlast);
+
+               $mform->addElement('selectyesno', 'adaptive', get_string("adaptive", "quiz"));
+               $mform->setHelpButton('adaptive', array("adaptive", get_string("adaptive","quiz"), "quiz"));
+               $mform->setAdvanced('adaptive', $CFG->quiz_fix_adaptive);
+               $mform->setDefault('adaptive', $CFG->quiz_optionflags & QUESTION_ADAPTIVE);
+
+
+//-------------------------------------------------------------------------------
+        $mform->addElement('header', 'gradeshdr', get_string('grades', 'grades'));
+               $mform->addElement('select', 'grademethod', get_string("grademethod", "quiz"), $QUIZ_GRADE_METHOD);
+               $mform->setHelpButton('grademethod', array("grademethod", get_string("grademethod","quiz"), "quiz"));
+               $mform->setAdvanced('grademethod', $CFG->quiz_fix_grademethod);
+        $mform->setDefault('grademethod', $CFG->quiz_grademethod);
+
+               $mform->addElement('selectyesno', 'penaltyscheme', get_string("penaltyscheme", "quiz"));
+               $mform->setHelpButton('penaltyscheme', array("penaltyscheme", get_string("penaltyscheme","quiz"), "quiz"));
+               $mform->setAdvanced('penaltyscheme', $CFG->quiz_fix_penaltyscheme);
+        $mform->setDefault('penaltyscheme', $CFG->quiz_penaltyscheme);
+
+               $options = array(
+                    0 => '0',
+                    1 => '1',
+                    2 => '2',
+                    3 => '3');
+               $mform->addElement('select', 'decimalpoints', get_string("decimaldigits", "quiz"), $options);
+               $mform->setHelpButton('decimalpoints', array("decimalpoints", get_string("decimaldigits","quiz"), "quiz"));
+               $mform->setAdvanced('decimalpoints', $CFG->quiz_fix_decimalpoints);
+
+               $mform->addElement('hidden', 'grade', $CFG->quiz_maximumgrade);
+
+//-------------------------------------------------------------------------------
+        $mform->addElement('header', 'reviewoptionshdr', get_string("reviewoptions", "quiz"));
+               $mform->setHelpButton('reviewoptionshdr', array("review2", get_string("allowreview","quiz"), "quiz"));
+               $mform->setAdvanced('reviewoptionshdr', $CFG->quiz_fix_review);
+
+               $immediatelyoptionsgrp=array();
+        $immediatelyoptionsgrp[] = &$mform->createElement('checkbox', 'responsesimmediately', '', get_string('responses', 'quiz'));
+        $immediatelyoptionsgrp[] = &$mform->createElement('checkbox', 'scoreimmediately', '', get_string('scores', 'quiz'));
+        $immediatelyoptionsgrp[] = &$mform->createElement('checkbox', 'feedbackimmediately', '', get_string('feedback', 'quiz'));
+        $immediatelyoptionsgrp[] = &$mform->createElement('checkbox', 'answersimmediately', '', get_string('answers', 'quiz'));
+        $immediatelyoptionsgrp[] = &$mform->createElement('checkbox', 'generalfeedbackimmediately', '', get_string('generalfeedback', 'quiz'));
+        $mform->addGroup($immediatelyoptionsgrp, 'immediatelyoptionsgrp', get_string("reviewimmediately", "quiz"), null, false);
+        $mform->setDefault('responsesimmediately', $CFG->quiz_review & QUIZ_REVIEW_RESPONSES & QUIZ_REVIEW_IMMEDIATELY);
+        $mform->setDefault('scoreimmediately', $CFG->quiz_review & QUIZ_REVIEW_SCORES & QUIZ_REVIEW_IMMEDIATELY);
+        $mform->setDefault('feedbackimmediately', $CFG->quiz_review & QUIZ_REVIEW_FEEDBACK & QUIZ_REVIEW_IMMEDIATELY);
+        $mform->setDefault('answersimmediately', $CFG->quiz_review & QUIZ_REVIEW_ANSWERS & QUIZ_REVIEW_IMMEDIATELY);
+        $mform->setDefault('generalfeedbackimmediately', $CFG->quiz_review & QUIZ_REVIEW_GENERALFEEDBACK & QUIZ_REVIEW_IMMEDIATELY);
+
+               $openoptionsgrp=array();
+        $openoptionsgrp[] = &$mform->createElement('checkbox', 'responsesopen', '', get_string('responses', 'quiz'));
+        $openoptionsgrp[] = &$mform->createElement('checkbox', 'scoreopen', '', get_string('scores', 'quiz'));
+        $openoptionsgrp[] = &$mform->createElement('checkbox', 'feedbackopen', '', get_string('feedback', 'quiz'));
+        $openoptionsgrp[] = &$mform->createElement('checkbox', 'answersopen', '', get_string('answers', 'quiz'));
+        $openoptionsgrp[] = &$mform->createElement('checkbox', 'generalfeedbackopen', '', get_string('generalfeedback', 'quiz'));
+        $mform->addGroup($openoptionsgrp, 'openoptionsgrp', get_string("reviewopen", "quiz"), array(' '), false);
+        $mform->setDefault('responsesopen', $CFG->quiz_review & QUIZ_REVIEW_RESPONSES & QUIZ_REVIEW_OPEN);
+        $mform->setDefault('scoreopen', $CFG->quiz_review & QUIZ_REVIEW_SCORES & QUIZ_REVIEW_OPEN);
+        $mform->setDefault('feedbackopen', $CFG->quiz_review & QUIZ_REVIEW_FEEDBACK & QUIZ_REVIEW_OPEN);
+        $mform->setDefault('answersopen', $CFG->quiz_review & QUIZ_REVIEW_ANSWERS & QUIZ_REVIEW_OPEN);
+        $mform->setDefault('generalfeedbackopen', $CFG->quiz_review & QUIZ_REVIEW_GENERALFEEDBACK & QUIZ_REVIEW_OPEN);
+
+
+               $closedoptionsgrp=array();
+        $closedoptionsgrp[] = &$mform->createElement('checkbox', 'responsesclosed', '', get_string('responses', 'quiz'));
+        $closedoptionsgrp[] = &$mform->createElement('checkbox', 'scoreclosed', '', get_string('scores', 'quiz'));
+        $closedoptionsgrp[] = &$mform->createElement('checkbox', 'feedbackclosed', '', get_string('feedback', 'quiz'));
+        $closedoptionsgrp[] = &$mform->createElement('checkbox', 'answersclosed', '', get_string('answers', 'quiz'));
+        $closedoptionsgrp[] = &$mform->createElement('checkbox', 'generalfeedbackclosed', '', get_string('generalfeedback', 'quiz'));
+        $mform->addGroup($closedoptionsgrp, 'closedoptionsgrp', get_string("reviewclosed", "quiz"), array(' '), false);
+        $mform->setDefault('responsesclosed', $CFG->quiz_review & QUIZ_REVIEW_RESPONSES & QUIZ_REVIEW_CLOSED);
+        $mform->setDefault('scoreclosed', $CFG->quiz_review & QUIZ_REVIEW_SCORES & QUIZ_REVIEW_CLOSED);
+        $mform->setDefault('feedbackclosed', $CFG->quiz_review & QUIZ_REVIEW_FEEDBACK & QUIZ_REVIEW_CLOSED);
+        $mform->setDefault('answersclosed', $CFG->quiz_review & QUIZ_REVIEW_ANSWERS & QUIZ_REVIEW_CLOSED);
+        $mform->setDefault('generalfeedbackclosed', $CFG->quiz_review & QUIZ_REVIEW_GENERALFEEDBACK & QUIZ_REVIEW_CLOSED);
+
+//-------------------------------------------------------------------------------
+        $mform->addElement('header', 'security', get_string('security', 'form'));
+
+        $mform->addElement('selectyesno', 'popup', get_string("popup", "quiz"));
+               $mform->setHelpButton('popup', array("popup", get_string("popup", "quiz"), "quiz"));
+               $mform->setAdvanced('popup', $CFG->quiz_fix_popup);
+        $mform->setDefault('popup', $CFG->quiz_popup);
+
+        $mform->addElement('text', 'password', get_string("requirepassword", "quiz"));
+               $mform->setType('password', PARAM_TEXT);
+               $mform->setHelpButton('password', array("requirepassword", get_string("requirepassword", "quiz"), "quiz"));
+               $mform->setAdvanced('password', $CFG->quiz_fix_password);
+        $mform->setDefault('password', $CFG->quiz_password);
+
+               $mform->addElement('text', 'subnet', get_string("requiresubnet", "quiz"));
+               $mform->setType('subnet', PARAM_TEXT);
+               $mform->setHelpButton('subnet', array("requiresubnet", get_string("requiresubnet", "quiz"), "quiz"));
+               $mform->setAdvanced('subnet', $CFG->quiz_fix_subnet);
+        $mform->setDefault('subnet', $CFG->quiz_subnet);
+
+//-------------------------------------------------------------------------------
+               $this->standard_coursemodule_elements();
+//-------------------------------------------------------------------------------
+        $mform->addElement('header', 'overallfeedbackhdr', get_string('overallfeedback', 'quiz'));
+               $mform->setHelpButton('overallfeedbackhdr', array('overallfeedback', get_string('overallfeedback', 'quiz'), 'quiz'));
+
+               $mform->addElement('static', 'gradeboundarystatic1', get_string('gradeboundary', 'quiz'), '100%');
+
+        $repeatarray=array();
+        $repeatarray[] = &MoodleQuickForm::createElement('text', 'feedbacktext', get_string('feedback', 'quiz'));
+        $repeatarray[] = &MoodleQuickForm::createElement('text', 'feedbackboundaries', get_string('gradeboundary', 'quiz'));
+
+        if (!empty($this->_instance)) {
+            $this->_feedbacks = get_records('quiz_feedback', 'quizid', $this->_instance, 'mingrade DESC');
+        } else {
+            $this->_feedbacks = array();
+        }
+        $numfeedbacks = max(count($this->_feedbacks) * 1.5, 5);
+        $nextel=$this->repeat_elements($repeatarray, $numfeedbacks-1,
+                    array('feedbacktext'=> array('type'=>PARAM_TEXT),
+                          'feedbackboundaries' => array('type'=>PARAM_TEXT)),
+                    'boundary_repeats', 'boundary_add_fields', 3);
+
+        //put some extra elements in before the button
+        $insertEl = &MoodleQuickForm::createElement('text', "feedbacktext[$nextel]", get_string('feedback', 'quiz'));
+        $mform->insertElementBefore($insertEl, 'boundary_add_fields');
+        $mform->setType("feedbacktext[$nextel]", PARAM_TEXT);
+        $mform->setHelpButton("feedbacktext[$nextel]", array('options', get_string('modulenameplural', 'choice'), 'choice'));
+
+        $insertEl = &MoodleQuickForm::createElement('static', 'gradeboundarystatic2', get_string('gradeboundary', 'quiz'), '0%');
+        $mform->insertElementBefore($insertEl, 'boundary_add_fields');
+
+//-------------------------------------------------------------------------------
+        // buttons
+        $this->add_action_buttons();
+       }
+
+       function defaults_preprocessing(&$default_values){
+        if (count($this->_feedbacks)) {
+            $key = 0;
+            foreach ($this->_feedbacks as $feedback){
+                $default_values['feedbacktext['.$key.']'] = $feedback->feedbacktext;
+                if ($feedback->mingrade > 0) {
+                    $default_values['feedbackboundaries['.$key.']'] = (100.0 * $feedback->mingrade / $default_values['grade']) . '%';
+                }
+                $key++;
+            }
+
+        }
+        if (empty($default_values['timelimit'])) {
+            $default_values['timelimitenable'] = 0;
+        } else {
+            $default_values['timelimitenable'] = 1;
+        }
+
+        if (isset($default_values['review'])){
+            $review = (int)$default_values['review'];
+            unset($default_values['review']);
+
+            $default_values['responsesimmediately'] = $review & QUIZ_REVIEW_RESPONSES & QUIZ_REVIEW_IMMEDIATELY;
+            $default_values['scoreimmediately'] = $review & QUIZ_REVIEW_SCORES & QUIZ_REVIEW_IMMEDIATELY;
+            $default_values['feedbackimmediately'] = $review & QUIZ_REVIEW_FEEDBACK & QUIZ_REVIEW_IMMEDIATELY;
+            $default_values['answersimmediately'] = $review & QUIZ_REVIEW_ANSWERS & QUIZ_REVIEW_IMMEDIATELY;
+            $default_values['generalfeedbackimmediately'] = $review & QUIZ_REVIEW_GENERALFEEDBACK & QUIZ_REVIEW_IMMEDIATELY;
+
+            $default_values['responsesopen'] = $review & QUIZ_REVIEW_RESPONSES & QUIZ_REVIEW_OPEN;
+            $default_values['scoreopen'] = $review & QUIZ_REVIEW_SCORES & QUIZ_REVIEW_OPEN;
+            $default_values['feedbackopen'] = $review & QUIZ_REVIEW_FEEDBACK & QUIZ_REVIEW_OPEN;
+            $default_values['answersopen'] = $review & QUIZ_REVIEW_ANSWERS & QUIZ_REVIEW_OPEN;
+            $default_values['generalfeedbackopen'] = $review & QUIZ_REVIEW_GENERALFEEDBACK & QUIZ_REVIEW_OPEN;
+
+            $default_values['responsesclosed'] = $review & QUIZ_REVIEW_RESPONSES & QUIZ_REVIEW_CLOSED;
+            $default_values['scoreclosed'] = $review & QUIZ_REVIEW_SCORES & QUIZ_REVIEW_CLOSED;
+            $default_values['feedbackclosed'] = $review & QUIZ_REVIEW_FEEDBACK & QUIZ_REVIEW_CLOSED;
+            $default_values['answersclosed'] = $review & QUIZ_REVIEW_ANSWERS & QUIZ_REVIEW_CLOSED;
+            $default_values['generalfeedbackclosed'] = $review & QUIZ_REVIEW_GENERALFEEDBACK & QUIZ_REVIEW_CLOSED;
+        }
+
+        if (isset($default_values['optionflags'])){
+            $default_values['adaptive'] = $default_values['optionflags'] & QUESTION_ADAPTIVE;
+            unset($default_values['optionflags']);
+        }
+       }
+
+       function validation($data){
+           $errors = array();
+        // Check open and close times are consistent.
+        if ($data['timeopen'] != 0 && $data['timeclose'] != 0 && $data['timeclose'] < $data['timeopen']) {
+            $errors['timeclose'] = get_string('closebeforeopen', 'quiz');
+        }
+
+        // Check the boundary value is a number or a percentage, and in range.
+        $i = 0;
+        while (!empty($data['feedbackboundaries'][$i] )) {
+            $boundary = trim($data['feedbackboundaries'][$i]);
+            if (strlen($boundary) > 0 && $boundary[strlen($boundary) - 1] == '%') {
+                $boundary = trim(substr($boundary, 0, -1));
+                if (is_numeric($boundary)) {
+                    $boundary = $boundary * $data['grade'] / 100.0;
+                } else {
+                    $errors["feedbackboundaries[$i]"] = get_string('feedbackerrorboundaryformat', 'quiz', $i + 1);
+                }
+            }
+            if (is_numeric($boundary) && $boundary <= 0 || $boundary >= $data['grade'] ) {
+                $errors["feedbackboundaries[$i]"] = get_string('feedbackerrorboundaryoutofrange', 'quiz', $i + 1);
+            }
+            if (is_numeric($boundary) && $i > 0 && $boundary >= $data['feedbackboundaries'][$i - 1]) {
+                $errors["feedbackboundaries[$i]"] = get_string('feedbackerrororder', 'quiz', $i + 1);
+            }
+            $data['feedbackboundaries'][$i] = $boundary;
+            $i += 1;
+        }
+        $numboundaries = $i;
+
+        // Check there is nothing in the remaining unused fields.
+        for ($i = $numboundaries; $i < count($data['feedbackboundaries'] ); $i += 1) {
+            if (!empty($data['feedbackboundaries'][$i] ) && trim($data['feedbackboundaries'][$i] ) != '') {
+                $errors["feedbackboundaries[$i]"] = get_string('feedbackerrorjunkinboundary', 'quiz', $i + 1);
+            }
+        }
+        for ($i = $numboundaries + 1; $i < count($data['feedbacktext'] ); $i += 1) {
+            if (!empty($data['feedbacktext'][$i] ) && trim($data['feedbacktext'][$i] ) != '') {
+                $errors["feedbacktext[$i]"] = get_string('feedbackerrorjunkinfeedback', 'quiz', $i + 1);
+            }
+        }
+        return $errors;
+       }
+
+}
+?>
\ No newline at end of file
index 379e5c1b820b456c8e01388feaacce00826821aa..4e4630d7554261ba77b405be6b24cb92ab122a5a 100644 (file)
@@ -31,7 +31,9 @@
             $mform->addElement('hidden', 'mode', $lastform->mode);
             $mform->addElement('hidden', 'visible', $lastform->visible);
             $mform->addElement('hidden', 'groupmode', $lastform->groupmode);
-            $mform->addElement('submit', 'submitbutton', get_string("savechanges"));
+//-------------------------------------------------------------------------------
+            // buttons
+            $this->add_action_buttons(false);
 
         }
     }
index 7c0dc5b19170469c7291e26a78c289bb3e6f8fb6..0ead3c3b16126e358a889b05fc839201b2bf40f6 100644 (file)
@@ -319,7 +319,10 @@ form.mform fieldset legend {
   font-weight: bold;
   margin-left: 0.5em;
 }
-
+form.mform fieldset .advancedbutton{
+   width:100%;
+   text-align:right;
+}
 form.mform div.fitem {
   clear: both;
   width: 100%;