From: jamiesensei Date: Tue, 19 Dec 2006 07:03:08 +0000 (+0000) Subject: * Added setAdvanced functionality see http://docs.moodle.org/en/Development:lib/forms... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=a23f0aaf9570886bf5803459f0018dd68e835328;p=moodle.git * Added setAdvanced functionality see http://docs.moodle.org/en/Development:lib/formslib.php_setAdvanced * 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 --- diff --git a/course/edit.php b/course/edit.php index 80d4bb7fb2..886b1a8e0e 100644 --- a/course/edit.php +++ b/course/edit.php @@ -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){ diff --git a/course/edit_form.php b/course/edit_form.php index 7660bf9529..cfcb3324a9 100644 --- a/course/edit_form.php +++ b/course/edit_form.php @@ -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 diff --git a/course/request.php b/course/request.php index 4cf58e957c..02589c295d 100644 --- a/course/request.php +++ b/course/request.php @@ -25,8 +25,11 @@ 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)) { @@ -34,17 +37,12 @@ } else { notice(get_string('courserequestfailed')); } - print_footer(); - exit; - - } + } else { - $requestform->display(); + $requestform->display(); + } print_footer(); - exit; - - ?> \ No newline at end of file diff --git a/course/request_form.php b/course/request_form.php index 3f183bad8a..8d09ce139e 100644 --- a/course/request_form.php +++ b/course/request_form.php @@ -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) { diff --git a/enrol/authorize/enrol_form.php b/enrol/authorize/enrol_form.php index 3d8b6c3bff..63a4453259 100755 --- a/enrol/authorize/enrol_form.php +++ b/enrol/authorize/enrol_form.php @@ -16,7 +16,6 @@ class authorize_enrol_form extends moodleform } $mform =& $this->_form; - $renderer =& $mform->defaultRenderer(); $mform->addElement('header', '', '  ' . 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) diff --git a/lang/en_utf8/form.php b/lang/en_utf8/form.php index c1ee2eea58..b230ebbb4f 100644 --- a/lang/en_utf8/form.php +++ b/lang/en_utf8/form.php @@ -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 diff --git a/lang/en_utf8/glossary.php b/lang/en_utf8/glossary.php index 70e50311da..bc7f66cfd7 100644 --- a/lang/en_utf8/glossary.php +++ b/lang/en_utf8/glossary.php @@ -1,4 +1,4 @@ -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 diff --git a/lib/form/checkbox.php b/lib/form/checkbox.php index 9c13dcaafd..f1eaaa4bd8 100644 --- a/lib/form/checkbox.php +++ b/lib/form/checkbox.php @@ -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 diff --git a/lib/form/format.php b/lib/form/format.php index 3d12adbff7..6d8e315863 100644 --- a/lib/form/format.php +++ b/lib/form/format.php @@ -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 index 0000000000..d7ef023bc6 --- /dev/null +++ b/lib/form/header.php @@ -0,0 +1,64 @@ +_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 +?> diff --git a/lib/form/select.php b/lib/form/select.php index 63df3f919b..245fa338a2 100644 --- a/lib/form/select.php +++ b/lib/form/select.php @@ -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 index 0000000000..09a5bccac9 --- /dev/null +++ b/lib/form/submit.php @@ -0,0 +1,45 @@ + + * @author Bertrand Mansion + * @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 diff --git a/lib/formslib.php b/lib/formslib.php index 354262dad9..f37f70ca6d 100644 --- a/lib/formslib.php +++ b/lib/formslib.php @@ -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 ''.$error->GetMessage().' '.$error->getUserInfo(); + echo '
Backtrace :'; + 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{header}{advancedimg}{button}\n\t\t"; + "\n\t\t{header}\n\t\t
{advancedimg}{button}
\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'); ?> diff --git a/lib/javascript-static.js b/lib/javascript-static.js index 2a26f354b2..eb0b8e8e8b 100644 --- a/lib/javascript-static.js +++ b/lib/javascript-static.js @@ -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; } diff --git a/login/change_password_form.php b/login/change_password_form.php index a6f9b94662..1a3438dda9 100644 --- a/login/change_password_form.php +++ b/login/change_password_form.php @@ -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); } } diff --git a/login/forgot_password_form.php b/login/forgot_password_form.php index bc64b74d57..bf2b386e60 100644 --- a/login/forgot_password_form.php +++ b/login/forgot_password_form.php @@ -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')); } } diff --git a/login/signup_form.php b/login/signup_form.php index d3979bbe36..1d559fffe4 100644 --- a/login/signup_form.php +++ b/login/signup_form.php @@ -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(){ diff --git a/mod/assignment/type/online/assignment.class.php b/mod/assignment/type/online/assignment.class.php index 95988a90f8..592cc73799 100644 --- a/mod/assignment/type/online/assignment.class.php +++ b/mod/assignment/type/online/assignment.class.php @@ -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(); } } diff --git a/mod/assignment/type/upload/assignment.class.php b/mod/assignment/type/upload/assignment.class.php index 4e7814ecb8..274f2ce568 100644 --- a/mod/assignment/type/upload/assignment.class.php +++ b/mod/assignment/type/upload/assignment.class.php @@ -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(); } } diff --git a/mod/chat/mod_form.php b/mod/chat/mod_form.php index a6916be04f..047913bf9b 100644 --- a/mod/chat/mod_form.php +++ b/mod/chat/mod_form.php @@ -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(); } diff --git a/mod/choice/mod_form.php b/mod/choice/mod_form.php index 38256ee899..810adc912e 100644 --- a/mod/choice/mod_form.php +++ b/mod/choice/mod_form.php @@ -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){ diff --git a/mod/data/comment_form.php b/mod/data/comment_form.php index b6a5754e43..dafebf00ce 100644 --- a/mod/data/comment_form.php +++ b/mod/data/comment_form.php @@ -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 diff --git a/mod/data/mod_form.php b/mod/data/mod_form.php index 358cdb1a94..695bc78321 100644 --- a/mod/data/mod_form.php +++ b/mod/data/mod_form.php @@ -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(); } diff --git a/mod/exercise/mod_form.php b/mod/exercise/mod_form.php index 58121214a3..a8d0f736fa 100644 --- a/mod/exercise/mod_form.php +++ b/mod/exercise/mod_form.php @@ -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(); } diff --git a/mod/forum/mod_form.php b/mod/forum/mod_form.php index cc4fe0c1c6..58576ecc63 100644 --- a/mod/forum/mod_form.php +++ b/mod/forum/mod_form.php @@ -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(){ diff --git a/mod/forum/post_form.php b/mod/forum/post_form.php index 3a6ba948e4..a578aefa04 100644 --- a/mod/forum/post_form.php +++ b/mod/forum/post_form.php @@ -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); diff --git a/mod/glossary/comment_form.php b/mod/glossary/comment_form.php index dec379e3ef..b1667d6e24 100644 --- a/mod/glossary/comment_form.php +++ b/mod/glossary/comment_form.php @@ -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 index 921696296c..0000000000 --- a/mod/glossary/edit.html +++ /dev/null @@ -1,196 +0,0 @@ -format)) { - $newentry->format = $defaultformat; - } - - trusttext_prepare_edit($newentry->definition, $newentry->format, $usehtmleditor, $context); - -?> -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
- - - - - -
- - - - - - - - -
:" />
: - id,'name ASC'); - echo "\n"; - ?> -
- - - - - - - -
- '; - helpbutton("aliases2", strip_tags(get_string("aliases", "glossary")), "glossary"); - ?> - - -
-usedynalink ) { - echo ''; - echo ''; - echo ''; - } else { - echo ''; - - if (!empty($newentry->usedynalink)) { - $selected = "checked=\"checked\""; - } else { - $selected = ""; - } - echo ' '; - print_string("entryusedynalink","glossary"); - echo helpbutton("usedynalinkentry", strip_tags(get_string("usedynalink", "glossary")), "glossary"); - echo '
'; - - if (!empty($newentry->casesensitive)) { - $selected = "checked"; - } else { - $selected = ""; - } - echo ' '; - print_string("casesensitive","glossary"); - echo helpbutton("casesensitive", strip_tags(get_string("casesensitive", "glossary")), "glossary"); - echo '
'; - - - if (!empty($newentry->fullmatch)) { - $selected = "checked"; - } else { - $selected = ""; - } - echo ' '; - print_string("fullmatch","glossary"); - echo helpbutton("fullmatch", strip_tags(get_string("fullmatch", "glossary")), "glossary"); - echo '
'; - } -?> -
-
- : - - definition); ?> -
- - "; - if ($usehtmleditor) { - helpbutton("richtext", get_string("helprichtext"), "moodle", true, true); - } else { - emoticonhelpbutton("form", "text"); - } - echo "
"; - ?> - -
: - '; - } else { - choose_from_menu(format_text_menu(), "format", $newentry->format, ""); - } - helpbutton("textformat", get_string("helpformatting")); - ?> -
:
- maxbytes, $course->maxbytes))); - echo ')
'; - print_string("optional"); - echo ' '; - helpbutton("attachment", get_string("attachment", "glossary"), "glossary"); - ?>
-
- dirroot.'/lib/uploadlib.php'); - upload_print_form_fragment(1,array('attachment'),null,false,null,$course->maxbytes,0,false); - ?> -
-

- id)) { - echo "id\" />"; - } - ?> - - - - - - - - - - - " /> - " /> -

-
-
diff --git a/mod/glossary/edit.php b/mod/glossary/edit.php index 45e84a91e2..05b7c05653 100644 --- a/mod/glossary/edit.php +++ b/mod/glossary/edit.php @@ -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&mode=entry&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), "", - "id\">$strglossaries -> - id\">".format_string($glossary->name,true)." -> $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 '
'; - $tab = GLOSSARY_ADDENTRY_VIEW; - include("tabs.html"); - - include("edit.html"); - - echo ''; - - 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&mode=entry&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&mode=entry&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&mode=entry&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&mode=entry&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&mode=entry&hook=$newentry->id", $redirectmessage); + redirect("view.php?id=$cm->id&mode=entry&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), "", "id\">$strglossaries -> id\">".format_string($glossary->name,true)." -> $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 '
'; +echo '
'; /// 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 ''; +$mform->display(); +echo ''; //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 index 0000000000..d803c3d485 --- /dev/null +++ b/mod/glossary/edit_form.php @@ -0,0 +1,141 @@ +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 diff --git a/mod/glossary/mod_form.php b/mod/glossary/mod_form.php index ccd523f996..ce99e581ce 100644 --- a/mod/glossary/mod_form.php +++ b/mod/glossary/mod_form.php @@ -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(){ diff --git a/mod/journal/mod_form.php b/mod/journal/mod_form.php index 137f2d1208..d8ab781c36 100644 --- a/mod/journal/mod_form.php +++ b/mod/journal/mod_form.php @@ -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'); } diff --git a/mod/label/mod_form.php b/mod/label/mod_form.php index 48069acd81..350d180114 100644 --- a/mod/label/mod_form.php +++ b/mod/label/mod_form.php @@ -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(); + } } diff --git a/mod/lesson/mod_form.php b/mod/lesson/mod_form.php index 3f340e159b..f2c9807072 100644 --- a/mod/lesson/mod_form.php +++ b/mod/lesson/mod_form.php @@ -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(); } diff --git a/mod/quiz/lib.php b/mod/quiz/lib.php index 9a4366288b..f5f3c27da8 100644 --- a/mod/quiz/lib.php +++ b/mod/quiz/lib.php @@ -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').': '.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 index eceb7f6f4f..0000000000 --- a/mod/quiz/mod.html +++ /dev/null @@ -1,570 +0,0 @@ - -// 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); - } - -?> - - -
- -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -feedbacktext); $i = $i + 1) { ?> - - - - - - -feedbacktext) - 1) { ?> - - - - - - - - - - - - - - - - - - - - - - -
: - -
:

- '; - emoticonhelpbutton("form", "description"); - echo '
'; - } - ?> -
- intro); - ?> -
: - " onclick="return lockoptions('form', 'availableenable', availableitems)" timeopen) echo 'checked="checked"' ?> /> - timeopen); - echo " - "; - print_time_selector("availablehour", "availableminute", $form->timeopen); - helpbutton('timeopen', get_string('quizopens', 'quiz'), 'quiz'); - ?> - - - - - -
: - " onclick="return lockoptions('form', 'dueenable', dueitems)" timeclose) echo 'checked="checked"' ?> /> - timeclose); - echo " - "; - print_time_selector("duehour", "dueminute", $form->timeclose); - helpbutton('timeopen', get_string('quizcloses', 'quiz'), 'quiz'); - ?> - - - - - -
- -
:100%
: - -
: - -
:0%
: - - - - - -
-
-
- - - -
- -
-
- - - - - - - - - - - - -instance) { ?> -wwwroot/mod/quiz/edit.php?quizid=$form->instance") ?>" /> -" /> - -" /> - -" /> -
-
- - - - - -quiz_fix_timelimit == $showfixed) { ?> - - : - - timelimit) echo 'checked="checked"' ?> /> - - - - - - - -quiz_fix_questionsperpage == $showfixed) { ?> - - : - - questionsperpage, ''); - helpbutton('questionsperpage', get_string('questionsperpage', 'quiz'), 'quiz'); - ?> - - - - -quiz_fix_shufflequestions == $showfixed) { ?> - - : - - shufflequestions", ""); - helpbutton("shufflequestions", get_string("shufflequestions","quiz"), "quiz"); - ?> - - - - -quiz_fix_shuffleanswers == $showfixed) { ?> - - : - - shuffleanswers", ""); - helpbutton("shufflewithin", get_string("shufflewithin","quiz"), "quiz"); - ?> - - - - -quiz_fix_attempts == $showfixed) { ?> - - : - - attempts", ""); - helpbutton("attempts", get_string("attemptsallowed","quiz"), "quiz"); - ?> - - - - -quiz_fix_attemptonlast == $showfixed) { ?> - - : - - attemptonlast", ""); - helpbutton("repeatattempts", - get_string("eachattemptbuildsonthelast", "quiz"), - "quiz"); - ?> - - - - -quiz_fix_grademethod == $showfixed) { ?> - - : - - grademethod", ""); - helpbutton("grademethod", get_string("grademethod","quiz"), "quiz"); - ?> - - - - -quiz_fix_adaptive == $showfixed) { ?> - - : - - optionflags & QUESTION_ADAPTIVE) ? 1 : 0, ""); - helpbutton("adaptive", get_string("adaptive","quiz"), "quiz"); - ?> - - - - -quiz_fix_penaltyscheme == $showfixed) { ?> - - : - - penaltyscheme", ""); - helpbutton("penaltyscheme", get_string("penaltyscheme","quiz"), "quiz"); - ?> - - - - -quiz_fix_decimalpoints == $showfixed) { ?> - - : - - '0', - 1 => '1', - 2 => '2', - 3 => '3' - ); - choose_from_menu($options, "decimalpoints", "$form->decimalpoints", ""); - helpbutton("decimalpoints", get_string("decimaldigits","quiz"), "quiz"); - ?> - - - - -quiz_fix_review == $showfixed) { - echo ''; - include($CFG->dirroot . '/mod/quiz/reviewoptions.html'); - echo ''; - $output = true; -} ?> - -quiz_fix_delay1 == $showfixed) { ?> - - : - - delay1", ""); - helpbutton("timedelay1", get_string("delay1","quiz"), "quiz"); - ?> - - - - -quiz_fix_delay2 == $showfixed) { ?> - - : - - delay2", ""); - helpbutton("timedelay2", get_string("delay2","quiz"), "quiz"); - ?> - - - - -quiz_fix_popup == $showfixed) { ?> - - : - - popup", ""); - helpbutton("popup", get_string("popup","quiz"), "quiz"); - ?> - - - - -quiz_fix_password == $showfixed) { ?> - - : - - - - - - - -quiz_fix_subnet == $showfixed) { ?> - - : - - - - - - - \ No newline at end of file diff --git a/mod/quiz/mod_form.php b/mod/quiz/mod_form.php new file mode 100644 index 0000000000..d083a9c67f --- /dev/null +++ b/mod/quiz/mod_form.php @@ -0,0 +1,334 @@ +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 diff --git a/mod/survey/details.php b/mod/survey/details.php index 379e5c1b82..4e4630d755 100644 --- a/mod/survey/details.php +++ b/mod/survey/details.php @@ -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); } } diff --git a/theme/standard/styles_layout.css b/theme/standard/styles_layout.css index 7c0dc5b191..0ead3c3b16 100644 --- a/theme/standard/styles_layout.css +++ b/theme/standard/styles_layout.css @@ -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%;