* 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
/// 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){
global $USER, $CFG;
$mform =& $this->_form;
- $renderer =& $mform->defaultRenderer();
$course = $this->_customdata['course'];
$category = $this->_customdata['category'];
$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);
$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);
$mform->addElement('hidden', 'students', get_string('defaultcoursestudents'));
-//--------------------------------------------------------------------------------
- $renderer->addStopFieldsetElements('submitbutton');
// now override defaults if course already exists
print_simple_box_end();
- if (($data = $requestform->data_submitted())) {
+ if ($requestform->is_cancelled()){
+ redirect($CFG->wwwroot);
+
+ }elseif ($data = $requestform->data_submitted()) {
$data->requester = $USER->id;
if (insert_record('course_request', $data)) {
} else {
notice(get_string('courserequestfailed'));
}
- print_footer();
- exit;
-
- }
+ } else {
- $requestform->display();
+ $requestform->display();
+ }
print_footer();
- exit;
-
-
?>
\ No newline at end of file
$mform->setType('password', PARAM_RAW);
- $mform->addElement('submit', '', get_string('savechanges'));
+ $this->add_action_buttons();
}
function validation($data) {
}
$mform =& $this->_form;
- $renderer =& $mform->defaultRenderer();
$mform->addElement('header', '', ' ' . get_string('paymentrequired'), '');
if ($othermethodstr = other_method($paymentmethod)) {
$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)
$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
-<?PHP // $Id$
+<?PHP // $Id$
// glossary.php - created with Moodle 1.7 beta + (2006101003)
$string['concepts'] = 'Concepts';
$string['configenablerssfeeds'] = 'This switch will enable the possibility of RSS feeds for all glosaries. You will still need to turn feeds on manually in the settings for each glossary.';
$string['currentglossary'] = 'Current glossary';
+$string['errconceptalreadyexists'] = 'This concept already exists. No duplicates allowed in this glossary.';
+$string['erredittimeexpired'] = 'The editing time for this entry has expired.';
+$string['errcannoteditothers'] = 'You cannot edit other people\'s entries.';
$string['dateview'] = 'Browse by date';
$string['defaultapproval'] = 'Approved by default';
$string['definition'] = 'Definition';
$string['importentries'] = 'Import entries';
$string['isglobal'] = 'Is this glossary global?';
$string['linkcategory'] = 'Automatically link this category';
+$string['linking'] = 'Auto-linking';
$string['mainglossary'] = 'Main glossary';
$string['maxtimehaspassed'] = 'Sorry, but the maximum time for editing this comment ($a) has passed!';
$string['modulename'] = 'Glossary';
* @author Jamie Pratt
* @access public
*/
-class MoodleQuickForm_cancel extends HTML_QuickForm_submit
+class MoodleQuickForm_cancel extends MoodleQuickForm_submit
{
// {{{ constructor
if ($value==null){
$value=get_string('cancel');
}
- HTML_QuickForm_submit::HTML_QuickForm_submit($elementName, $value, $attributes);
+ MoodleQuickForm_submit::MoodleQuickForm_submit($elementName, $value, $attributes);
$this->updateAttributes(array('onclick'=>'skipClientValidation = true; return true;'));
} //end constructor
function onQuickFormEvent($event, $arg, &$caller)
} // end func onQuickFormEvent
// }}}
-} //end class HTML_QuickForm_submit
+} //end class MoodleQuickForm_cancel
?>
\ No newline at end of file
$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
*/
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();
if ($this->_useHtmlEditor){
$this->freeze();
}
-
-
-
} //end constructor
/**
--- /dev/null
+<?php
+// $Id$
+
+require_once 'HTML/QuickForm/header.php';
+
+/**
+ * A pseudo-element used for adding headers to form
+ *
+ */
+class MoodleQuickForm_header extends HTML_QuickForm_header
+{
+ /**
+ * html for help button, if empty then no help
+ *
+ * @var string
+ */
+ var $_helpbutton='';
+
+ // {{{ accept()
+
+ /**
+ * Accepts a renderer
+ *
+ * @param object An HTML_QuickForm_Renderer object
+ * @access public
+ * @return void
+ */
+ function accept(&$renderer)
+ {
+ $this->_text .= $this->getHelpButton();
+ $renderer->renderHeader($this);
+ } // end func accept
+
+ // }}}
+ /**
+ * set html for help button
+ *
+ * @access public
+ * @param array $help array of arguments to make a help button
+ * @param string $function function name to call to get html
+ */
+ function setHelpButton($helpbuttonargs, $function='helpbutton'){
+ if (!is_array($helpbuttonargs)){
+ $helpbuttonargs=array($helpbuttonargs);
+ }else{
+ $helpbuttonargs=$helpbuttonargs;
+ }
+ //we do this to to return html instead of printing it
+ //without having to specify it in every call to make a button.
+ $defaultargs=array('', '', 'moodle', true, false, '', true);
+ $helpbuttonargs=$helpbuttonargs + $defaultargs ;
+ $this->_helpbutton=call_user_func_array($function, $helpbuttonargs);
+ }
+ /**
+ * get html for help button
+ *
+ * @access public
+ * @return string html for help button
+ */
+ function getHelpButton(){
+ return $this->_helpbutton;
+ }
+} //end class MoodleQuickForm_header
+?>
}
}
} // 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
--- /dev/null
+<?php
+require_once("HTML/QuickForm/submit.php");
+
+/**
+ * HTML class for a submit type element
+ *
+ * @author Adam Daniel <adaniel1@eesus.jnj.com>
+ * @author Bertrand Mansion <bmansion@mamasam.com>
+ * @version 1.0
+ * @since PHP4.04pl1
+ * @access public
+ */
+class MoodleQuickForm_submit extends HTML_QuickForm_submit {
+ /**
+ * Called by HTML_QuickForm whenever form event is made on this element
+ *
+ * @param string $event Name of event
+ * @param mixed $arg event arguments
+ * @param object $caller calling object
+ * @since 1.0
+ * @access public
+ * @return void
+ */
+ function onQuickFormEvent($event, $arg, &$caller)
+ {
+ switch ($event) {
+ case 'createElement':
+ parent::onQuickFormEvent($event, $arg, $caller);
+ if ($caller->isNoSubmitButton($arg[0])){
+ //need this to bypass client validation
+ //for buttons that submit but do not process the
+ //whole form.
+ $onClick = $this->getAttribute('onclick');
+ $skip = 'skipClientValidation = true;';
+ $onClick = ($onClick !== null)?$skip.' '.$onClick:$skip;
+ $this->updateAttributes(array('onclick'=>$onClick));
+ }
+ return true;
+ break;
+ }
+ return parent::onQuickFormEvent($event, $arg, $caller);
+
+ } // end func onQuickFormEvent
+}
+?>
\ No newline at end of file
define('FORM_ADVANCEDIMAGEURL', $CFG->wwwroot.'/lib/form/adv.gif');
define('FORM_REQIMAGEURL', $CFG->wwwroot.'/lib/form/req.gif');
+/**
+ * Callback called when PEAR throws an error
+ *
+ * @param PEAR_Error $error
+ */
+function pear_handle_error($error){
+ echo '<strong>'.$error->GetMessage().'</strong> '.$error->getUserInfo();
+ echo '<br /> <strong>Backtrace </strong>:';
+ print_object($error->backtrace);
+}
+
if ($CFG->debug >= DEBUG_ALL){
- PEAR::setErrorHandling(PEAR_ERROR_PRINT);
+ PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, 'pear_handle_error');
}
/**
* 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.
* @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;
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.
*
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) {
*/
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;
+
/**
* Method to add a repeating group of elements to a form.
*
* @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);
$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));
}
}
}
- $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');
+ }
+ }
}
/**
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;
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();
$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;
* @access private
*/
var $_headerTemplate =
- "\n\t\t<legend>{header}{advancedimg}{button}</legend>\n\t\t";
+ "\n\t\t<legend>{header}</legend>\n\t\t<div class=\"advancedbutton\">{advancedimg}{button}</div>\n\t\t";
/**
* Template used when closing a fieldset
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');
?>
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 {
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;
}
global $USER;
$mform =& $this->_form;
- $renderer =& $mform->defaultRenderer();
$mform->addElement('header', '', get_string('changepassword'), '');
$sitecontext = get_context_instance(CONTEXT_SYSTEM, SITEID);
// 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);
}
}
$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'));
}
}
global $USER, $CFG;
$mform =& $this->_form;
- $renderer =& $mform->defaultRenderer();
$mform->addElement('header', '', get_string('createuserandpass'), '');
$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(){
$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();
}
}
$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();
}
}
$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();
}
//-------------------------------------------------------------------------------
$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){
$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
$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();
}
//-------------------------------------------------------------------------------
$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();
}
//-------------------------------------------------------------------------------
$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(){
$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);
$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
+++ /dev/null
-<?php //$Id$
- if (!isset($newentry->format)) {
- $newentry->format = $defaultformat;
- }
-
- trusttext_prepare_edit($newentry->definition, $newentry->format, $usehtmleditor, $context);
-
-?>
-<form name="form" method="post" action="edit.php" enctype="multipart/form-data">
-<table border="0" cellpadding="5">
-<?php
-if (isset($errors)) {
-?>
- <tr valign="top">
- <td colspan="2" align="center"><strong><font color="red"><?php p($errors) ?></font></strong>
- </td>
- </tr>
-<?php
-}
-?>
-<tr valign="top">
-<td colspan="2">
-<table width="100%" border="0" cellspacing="0" cellpadding="0">
- <tr>
- <td valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="5">
- <tr>
- <td width="150" align="right"><b><?php echo get_string("concept","glossary") ?>:</b></td>
- <td><input type="text" name="concept" size="30" value="<?php p(clean_text($newentry->concept)) ?>" alt="<?php print_string("concept","glossary") ?>" /></td>
- </tr>
- <tr>
- <td align="right"><b><?php echo get_string("categories","glossary") ?>:</b></td>
- <td valign="top">
- <?php
- $categories = get_records("glossary_categories","glossaryid",$glossary->id,'name ASC');
- echo "<select size=\"5\" name=\"categories[]\" multiple=\"multiple\" >";
- echo "<option value=\"0\">" . get_string("notcategorised","glossary") . "</option>";
-
- if ( $categories ) {
- foreach ( $categories as $category ) {
- echo " <option ";
- if (isset($newentry->id)) {
- if ( record_exists("glossary_entries_categories","entryid",$newentry->id,"categoryid",$category->id) ) {
- echo "selected=\"selected\" " ;
- }
- }
- echo "value=\"$category->id\">".clean_text($category->name)."</option>\n";
- }
- }
- echo "</select>\n";
- ?>
- </td>
- </tr>
- </table></td>
- <td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="5">
- <tr>
- <td valign="top" align="right"><b>
- <?php
- echo get_string("aliases","glossary");
- echo ':<br />';
- helpbutton("aliases2", strip_tags(get_string("aliases", "glossary")), "glossary");
- ?></b>
- </td>
- <td valign="top">
- <textarea rows="2" name="aliases" cols="20"><?php p(clean_text($newentry->aliases)) ?></textarea>
- </td>
- </tr>
- <tr>
- <td colspan="2">
-<?php
- if ( !$glossary->usedynalink ) {
- echo '<input type="hidden" name="usedynalink" value="0" />';
- echo '<input type="hidden" name="casesensitive" value="0" />';
- echo '<input type="hidden" name="fullmatch" value="0" />';
- } else {
- echo '<script type="text/javascript">var items = [\'casesensitive\',\'fullmatch\'];</script>';
-
- if (!empty($newentry->usedynalink)) {
- $selected = "checked=\"checked\"";
- } else {
- $selected = "";
- }
- echo '<input type="checkbox" name="usedynalink" value="1" alt="' . get_string("entryusedynalink","glossary") . '" ' . $selected . ' onclick="return lockoptions(\'form\',\'usedynalink\', items)" /> ';
- print_string("entryusedynalink","glossary");
- echo helpbutton("usedynalinkentry", strip_tags(get_string("usedynalink", "glossary")), "glossary");
- echo '<br />';
-
- if (!empty($newentry->casesensitive)) {
- $selected = "checked";
- } else {
- $selected = "";
- }
- echo '<input type="checkbox" name="casesensitive" value="1" alt="' . get_string("casesensitive","glossary") . '" ' . $selected . ' /> ';
- print_string("casesensitive","glossary");
- echo helpbutton("casesensitive", strip_tags(get_string("casesensitive", "glossary")), "glossary");
- echo '<br />';
-
-
- if (!empty($newentry->fullmatch)) {
- $selected = "checked";
- } else {
- $selected = "";
- }
- echo '<input type="checkbox" name="fullmatch" value="1" alt="' . get_string("fullmatch","glossary") . '" ' . $selected . ' /> ';
- print_string("fullmatch","glossary");
- echo helpbutton("fullmatch", strip_tags(get_string("fullmatch", "glossary")), "glossary");
- echo '<br />';
- }
-?>
- </td>
- </tr>
- </table></td>
- </tr>
-</table>
-</td>
-</tr>
-<tr valign="top">
- <td align="right"><b>
- <?php print_string("definition", "glossary"); ?>:
- </b></td>
- <td align="left" rowspan="2">
- <?php print_textarea($usehtmleditor, 25, 65, 630, 400, "text", $newentry->definition); ?>
- </td>
-</tr>
-<tr valign="top">
- <td align="right" valign="middle" nowrap="nowrap">
-
- <?php
- helpbutton("writing", get_string("helpwriting"), "moodle", true, true);
- echo "<br />";
- if ($usehtmleditor) {
- helpbutton("richtext", get_string("helprichtext"), "moodle", true, true);
- } else {
- emoticonhelpbutton("form", "text");
- }
- echo "<br />";
- ?>
-
- </td>
-</tr>
-<tr valign="top">
- <td align="right"><b><?php print_string("formattexttype"); ?>:</b></td>
- <td>
- <?php
- if ($usehtmleditor) { /// Trying this out for a while
- print_string('formathtml');
- echo '<input type="hidden" name="format" value="'.FORMAT_HTML.'" />';
- } else {
- choose_from_menu(format_text_menu(), "format", $newentry->format, "");
- }
- helpbutton("textformat", get_string("helpformatting"));
- ?>
- </td>
-</tr>
-
-<tr valign="top">
- <td align="right"><b><?php print_string("attachment", "glossary") ?>:<br />
- <?php
- echo '(';
- print_string("maxsize", "", display_size(get_max_upload_file_size($CFG->maxbytes, $course->maxbytes)));
- echo ')<br />';
- print_string("optional");
- echo ' ';
- helpbutton("attachment", get_string("attachment", "glossary"), "glossary");
- ?></b>
- </td>
- <td>
- <?php
- require_once($CFG->dirroot.'/lib/uploadlib.php');
- upload_print_form_fragment(1,array('attachment'),null,false,null,$course->maxbytes,0,false);
- ?>
- </td>
-</tr>
-<tr>
-<td colspan="2">
- <p align="center">
- <?php if (isset($newentry->id)) {
- echo "<input type=\"hidden\" name=\"e\" value=\"$newentry->id\" />";
- }
- ?>
-
- <input type="hidden" name="husedynalink" value="1" />
- <input type="hidden" name="hcasesensitive" value="0" />
- <input type="hidden" name="hfullmatch" value="1" />
-
- <input type="hidden" name="id" value="<?php p($cm->id) ?>" />
- <input type="hidden" name="mode" value="<?php p($mode) ?>" />
- <input type="hidden" name="hook" value="<?php p($hook) ?>" />
- <input type="hidden" name="confirm" value="1" />
-
- <input type="submit" value="<?php print_string("savechanges") ?>" />
- <input type="reset" value="<?php print_string("revert") ?>" />
- </p>
-</td>
-</tr>
-</table>
-</form>
require_once('../../config.php');
require_once('lib.php');
+require_once('edit_form.php');
global $CFG, $USER;
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), "",
- "<a href=\"index.php?id=$course->id\">$strglossaries</a> ->
- <a href=\"view.php?id=$cm->id\">".format_string($glossary->name,true)."</a> -> $stredit", "form.text",
- "", true, "", navmenu($course, $cm));
-
- print_heading(format_string($glossary->name));
-
- /// Info box
- if ( $glossary->intro ) {
- print_simple_box(format_text($glossary->intro), 'center', '70%', '', 5, 'generalbox', 'intro');
- }
- echo '<br />';
- $tab = GLOSSARY_ADDENTRY_VIEW;
- include("tabs.html");
-
- include("edit.html");
-
- echo '</center>';
-
- glossary_print_tabbed_table_end();
-
- // Lets give IE more time to load the whole page
- // before trying to load the editor.
- if ($usehtmleditor) {
- use_html_editor("text");
- }
-
- print_footer($course);
- die;
+ $todb = new object();
+ $todb->course = $glossary->course;
+ $todb->glossaryid = $glossary->id;
+
+ $todb->concept = trim($fromform->concept);
+ $todb->definition = $fromform->definition;
+ $todb->format = $fromform->format;
+ $todb->usedynalink = $fromform->usedynalink;
+ $todb->casesensitive = $fromform->casesensitive;
+ $todb->fullmatch = $fromform->fullmatch;
+ $todb->timemodified = $timenow;
+ $todb->approved = 0;
+ $todb->aliases = "";
+ if ( $glossary->defaultapproval or has_capability('mod/glossary:approve', $context) ) {
+ $todb->approved = 1;
}
if ($e) {
- //We are updating an entry, so we compare current session user with
- //existing entry user to avoid some potential problems if secureforms=off
- //Perhaps too much security? Anyway thanks to skodak (Bug 1823)
- $old = get_record('glossary_entries', 'id', $e);
- $ineditperiod = ((time() - $old->timecreated < $CFG->maxeditingtime) || $glossary->editalways);
- if ( (!$ineditperiod || $USER->id != $old->userid) and !has_capability('mod/glossary:manageentries', $context) and $e) {
- if ( $USER->id != $old->userid ) {
- error("You can't edit other people's entries!");
- } elseif (!$ineditperiod) {
- error("You can't edit this. Time expired!");
- }
- die;
+ /* TODO process file uploads
+ $todb->attachment = $_FILES["attachment"];
+ if ($newfilename = glossary_add_attachment($todb, 'attachment')) {
+ $todb->attachment = $newfilename;
+ } else {
+ unset($todb->attachment);
+ }*/
+ $todb->id = $e;
+ print_object($todb);
+ if (update_record('glossary_entries', $todb)) {
+ add_to_log($course->id, "glossary", "update entry",
+ "view.php?id=$cm->id&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), "",
"<a href=\"index.php?id=$course->id\">$strglossaries</a> ->
<a href=\"view.php?id=$cm->id\">".format_string($glossary->name,true)."</a> -> $stredit", "",
"", true, "", navmenu($course, $cm));
-$ineditperiod = ((time() - $newentry->timecreated < $CFG->maxeditingtime) || $glossary->editalways);
-if ( (!$ineditperiod || $USER->id != $newentry->userid) and !has_capability('mod/glossary:manageentries', $context) and $e) {
- if ( $USER->id != $newentry->userid ) {
- error("You can't edit other people's entries!");
- } elseif (!$ineditperiod) {
- error("You can't edit this. Time expired!");
- }
- die;
-}
- print_heading(format_string($glossary->name));
+
+print_heading(format_string($glossary->name));
/// Info box
- if ( $glossary->intro ) {
- print_simple_box(format_text($glossary->intro), 'center', '70%', '', 5, 'generalbox', 'intro');
- }
+if ( $glossary->intro ) {
+ print_simple_box(format_text($glossary->intro), 'center', '70%', '', 5, 'generalbox', 'intro');
+}
- echo '<br />';
+echo '<br />';
/// Tabbed browsing sections
$tab = GLOSSARY_ADDENTRY_VIEW;
include("tabs.html");
if (!$e) {
- require_capability('mod/glossary:write', $context);
+ require_capability('mod/glossary:write', $context);
}
-include("edit.html");
-
-echo '</center>';
+$mform->display();
+echo '</center>'; //TODO remove center tag from here and tabs.html
glossary_print_tabbed_table_end();
- // Lets give IE more time to load the whole page
- // before trying to load the editor.
- if ($usehtmleditor) {
- use_html_editor("text");
- }
-
print_footer($course);
-?>
+?>
\ No newline at end of file
--- /dev/null
+<?php
+require_once ($CFG->dirroot.'/lib/formslib.php');
+
+class glossary_entry_form extends moodleform {
+
+ function definition() {
+
+ global $CFG, $COURSE;
+ $mform =& $this->_form;
+
+ $glossary =& $this->_customdata['glossary'];
+ $mode =& $this->_customdata['mode'];
+ $cm =& $this->_customdata['cm'];
+ $hook =& $this->_customdata['hook'];
+ $e =& $this->_customdata['e'];
+
+//-------------------------------------------------------------------------------
+ $mform->addElement('header', 'general', get_string('general', 'form'));
+
+ $mform->addElement('text', 'concept', get_string('concept', 'glossary'));
+ $mform->setType('concept', PARAM_TEXT);
+ $mform->addRule('concept', null, 'required', null, 'client');
+
+ $mform->addElement('htmleditor', 'definition', get_string('definition', 'glossary'), array('rows'=>20));
+ $mform->setType('definition', PARAM_RAW);
+ $mform->addRule('definition', null, 'required', null, 'client');
+
+ $mform->addElement('format');
+
+ $categories = array();
+ if ($categories = get_records_menu('glossary_categories', 'glossaryid', $glossary->id, 'name ASC', 'id, name')){
+ $categories = array(0 => get_string('notcategorised', 'glossary')) + $categories;
+ } else {
+ $categories = array(0 => get_string('notcategorised', 'glossary'));
+ }
+
+ $categoriesEl = $mform->addElement('select', 'categories', get_string('categories', 'glossary'), $categories);
+ $categoriesEl->setMultiple(true);
+ $categoriesEl->setSize(5);
+
+ $mform->addElement('textarea', 'aliases', get_string('aliases', 'glossary'), 'rows="2" cols="40"');
+ $mform->setType('aliases', PARAM_TEXT);
+ $mform->setHelpButton('aliases', array('aliases2', strip_tags(get_string('aliases', 'glossary')), 'glossary'));
+
+ $this->set_max_file_size();
+ $this->_upload_manager = new upload_manager('attachment', true, false, $COURSE, false, 0, true, true);
+ $mform->addElement('file', 'attachment', get_string('attachment', 'forum'));
+ $mform->setHelpButton('attachment', array('attachment', get_string('attachment', 'glossary'), 'glossary'));
+
+ if (isset($CFG->glossary_linkentries)) {
+ $usedynalink = $CFG->glossary_linkentries;
+ } else {
+ $usedynalink = 0;
+ }
+ if (isset($CFG->glossary_casesensitive)) {
+ $casesensitive = $CFG->glossary_casesensitive;
+ } else {
+ $casesensitive = 0;
+ }
+ if (isset($CFG->glossary_fullmatch)) {
+ $fullmatch = $CFG->glossary_fullmatch;
+ } else {
+ $fullmatch = 0;
+ }
+ if ( !$glossary->usedynalink ) {
+ $mform->addElement('hidden', 'usedynalink', $usedynalink);
+ $mform->addElement('hidden', 'casesensitive', $casesensitive);
+ $mform->addElement('hidden', 'fullmatch', $fullmatch);
+ } else {
+//-------------------------------------------------------------------------------
+ $mform->addElement('header', 'linkinghdr', get_string('linking', 'glossary'));
+
+ $mform->addElement('checkbox', 'usedynalink', get_string('entryusedynalink', 'glossary'));
+ $mform->setHelpButton('usedynalink', array('usedynalinkentry', strip_tags(get_string('usedynalink', 'glossary')), 'glossary'));
+ $mform->setDefault('usedynalink', $usedynalink);
+
+ $mform->addElement('checkbox', 'casesensitive', get_string('casesensitive', 'glossary'));
+ $mform->setHelpButton('casesensitive', array('casesensitive', strip_tags(get_string('casesensitive', 'glossary')), 'glossary'));
+ $mform->disabledIf('casesensitive', 'usedynalink');
+ $mform->setDefault('casesensitive', $casesensitive);
+
+ $mform->addElement('checkbox', 'fullmatch', get_string('fullmatch', 'glossary'));
+ $mform->setHelpButton('fullmatch', array('fullmatch', strip_tags(get_string('fullmatch', 'glossary')), 'glossary'));
+ $mform->disabledIf('fullmatch', 'usedynalink');
+ $mform->setDefault('fullmatch', $fullmatch);
+ }
+
+ $mform->addElement('hidden', 'e', $e);
+ $mform->addElement('hidden', 'id', $cm->id);
+ $mform->addElement('hidden', 'mode', $mode);
+ $mform->addElement('hidden', 'hook', $hook);
+
+//-------------------------------------------------------------------------------
+ $this->add_action_buttons();
+ }
+
+ function validation($data){
+ global $CFG, $USER;
+ $errors = array();
+ $e = $this->_customdata['e'];
+ $glossary = $this->_customdata['glossary'];
+ $context = $this->_customdata['context'];
+ $data['concept'] = trim($data['concept']);
+ if ($e) {
+ //We are updating an entry, so we compare current session user with
+ //existing entry user to avoid some potential problems if secureforms=off
+ //Perhaps too much security? Anyway thanks to skodak (Bug 1823)
+ $old = get_record('glossary_entries', 'id', $e);
+ $ineditperiod = ((time() - $old->timecreated < $CFG->maxeditingtime) || $glossary->editalways);
+ if ( (!$ineditperiod || $USER->id != $old->userid) and !has_capability('mod/glossary:manageentries', $context)) {
+ if ( $USER->id != $old->userid ) {
+ $errors['concept'] = get_string('errcannoteditothers', 'glossary');
+ } elseif (!$ineditperiod) {
+ $errors['concept'] = get_string('erredittimeexpired', 'glossary');
+ }
+ }
+ if ( !$glossary->allowduplicatedentries ) {
+ if ($dupentries = get_records('glossary_entries', 'lower(concept)', moodle_strtolower($data['concept']))) {
+ foreach ($dupentries as $curentry) {
+ if ( $glossary->id == $curentry->glossaryid ) {
+ if ( $curentry->id != $e ) {
+ $errors['concept'] = get_string('errconceptalreadyexists', 'glossary');
+ break;
+ }
+ }
+ }
+ }
+ }
+
+ } else {
+ if ( !$glossary->allowduplicatedentries ) {
+ if ($dupentries = get_record('glossary_entries', 'lower(concept)', moodle_strtolower($data['concept']), 'glossaryid', $glossary->id)) {
+ $errors['concept'] = get_string('errconceptalreadyexists', 'glossary');
+ }
+ }
+ }
+ return $errors;
+ }
+
+}
+?>
\ No newline at end of file
$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);
$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(){
//-------------------------------------------------------------------------------
$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');
}
$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();
+
}
}
//-------------------------------------------------------------------------------
$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();
}
* (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.
// Do the processing required after an add or an update.
quiz_after_add_or_update($quiz);
-
+
return $quiz->id;
}
* 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.
*/
/// $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);
$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.)
}
}
$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])) {
$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])) {
$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]) != '') {
$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)) {
/**
* 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;
}
// 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,
+++ /dev/null
-<?php
-// This page defines the form to create or edit an instance of this module -->
-// It is used from /course/mod.php. The whole instance is available as $form. -->
-
- require_once("$CFG->dirroot/mod/quiz/locallib.php");
-
- // Set any form variables that have not been initialized to their default value.
- if (!isset($form->name)) {
- $form->name = "";
- }
- if (!isset($form->intro)) {
- $form->intro = "";
- }
- if (!isset($form->timeopen)) {
- $form->timeopen = "";
- }
- if (!isset($form->timeclose)) {
- $form->timeclose = "";
- }
- if (!isset($form->attempts)) {
- $form->attempts = $CFG->quiz_attempts;
- }
- if (!isset($form->attemptonlast)) {
- $form->attemptonlast = $CFG->quiz_attemptonlast;
- }
- if (!isset($form->grademethod)) {
- $form->grademethod = $CFG->quiz_grademethod;
- }
- if (!isset($form->decimalpoints)) {
- $form->decimalpoints = $CFG->quiz_decimalpoints;
- }
- if (!isset($form->review)) {
- $form->review = $CFG->quiz_review;
- }
- if (!isset($form->questionsperpage)) {
- $form->questionsperpage = $CFG->quiz_questionsperpage;
- }
- if (!isset($form->shufflequestions)) {
- $form->shufflequestions = $CFG->quiz_shufflequestions;
- }
- if (!isset($form->shuffleanswers)) {
- $form->shuffleanswers = $CFG->quiz_shuffleanswers;
- }
- if (!isset($form->grade)) {
- $form->grade = $CFG->quiz_maximumgrade;
- }
- if (!isset($form->questions)) {
- $form->questions = "";
- }
- if (!isset($form->password)) {
- $form->password = $CFG->quiz_password;
- }
- if (!isset($form->subnet)) {
- $form->subnet = $CFG->quiz_subnet;
- }
- if (!isset($form->timelimit)) {
- $form->timelimit = $CFG->quiz_timelimit;
- }
- if (!isset($form->popup)) {
- $form->popup = $CFG->quiz_popup;
- }
- if (!isset($form->optionflags)) {
- $form->optionflags = $CFG->quiz_optionflags;
- }
- if (!isset($form->penaltyscheme)) {
- $form->penaltyscheme = $CFG->quiz_penaltyscheme;
- }
- if (empty($form->timedue)) {
- $form->timedue = "";
- }
- //enforced time delay between quiz attempts
- //delay1: time delay between first and second attempt
- //delay2: time delay between second and additional quiz attempt
- if (!isset($form->delay1)) {
- $form->delay1 = $CFG->quiz_delay1;
- }
- if (!isset($form->delay2)) {
- $form->delay2 = $CFG->quiz_delay2;
- }
-
- // Get any existing feedback text out of the database.
- if (!empty($form->id)) {
- $feedbacks = get_records('quiz_feedback', 'quizid', $form->id, 'mingrade DESC');
- } else {
- $feedbacks = array();
- }
- $form->feedbacktext = array();
- $form->feedbackboundaries = array();
- foreach ($feedbacks as $feedback) {
- $form->feedbacktext[] = $feedback->feedbacktext;
- if ($feedback->mingrade > 0) {
- $form->feedbackboundaries[] = (100.0 * $feedback->mingrade / $form->grade) . '%';
- }
- }
-
- // Make sure there are at least 5 feedbacktexts, or a bit more than the current nubmer.
- $numfeedbacks = max(
- count($form->feedbacktext) * 1.5,
- count($form->feedbackboundaries) * 1.5,
- 5
- );
-
- for ($i = 0; $i < $numfeedbacks; $i += 1) {
- if (!array_key_exists($i, $form->feedbacktext)) {
- $form->feedbacktext[$i] = '';
- }
- if (!array_key_exists($i, $form->feedbackboundaries)) {
- $form->feedbackboundaries[$i] = '';
- }
- }
-
- // The following are used for drop-down menus
- $yesnooptions = array(get_string("no"), get_string("yes"));
-
- $attemptoptions = array();
- $attemptoptions[0] = get_string("attemptsunlimited", "quiz");
- $attemptoptions[1] = "1 ".moodle_strtolower(get_string("attempt", "quiz"));
- for ($i=2;$i<=6;$i++) {
- $attemptoptions[$i] = "$i ".moodle_strtolower(get_string("attempts", "quiz"));
- }
-
- //enforced time delay between quiz attempts add-on
- $timedelayoptions = array();
- $timedelayoptions[0] = get_string('none');
- $timedelayoptions[1800] = get_string('numminutes', '', 30);
- $timedelayoptions[3600] = get_string('numminutes', '', 60);
- for($i=2; $i<=23; $i++) {
- $seconds = $i*3600;
- $timedelayoptions[$seconds] = get_string('numhours', '', $i);
- }
- $timedelayoptions[86400] = get_string('numhours', '', 24);
- for($i=2; $i<=7; $i++) {
- $seconds = $i*86400;
- $timedelayoptions[$seconds] = get_string('numdays', '', $i);
- }
-
-?>
-<script type="text/javascript" language="javascript">
- var dueitems = ['dueday','duemonth','dueyear','duehour', 'dueminute'];
- var availableitems = ['availableday','availablemonth','availableyear','availablehour', 'availableminute'];
- var timelimititems = ['timelimit'];
-</script>
-
-<form name="form" method="post" action="mod.php">
-
-<center>
-
-<!-- Now comes a table with all the options that have not been fixed by the admin -->
-<table cellpadding="5">
-
-<tr valign="top">
- <td align="right"><b><?php print_string("name") ?>:</b></td>
- <td align="left">
- <input type="text" name="name" size="40" value="<?php p($form->name) ?>" />
- </td>
-</tr>
-
-<tr valign="top">
- <td align="right"><b><?php print_string("introduction", "quiz") ?>:</b><br /><br />
- <?php
- if ($usehtmleditor) {
- helpbutton("richtext", get_string("helprichtext"), "moodle", true, true);
- } else {
- helpbutton("text", get_string("helptext"), "moodle", true, true);
- echo '<br />';
- emoticonhelpbutton("form", "description");
- echo '<br />';
- }
- ?>
- </td>
- <td align="left">
- <?php
- print_textarea($usehtmleditor, 20, 50, 680, 400, "intro", $form->intro);
- ?>
- </td>
-</tr>
-
-<tr valign="top">
- <td align="right"><b><?php print_string("quizopen", "quiz") ?>:</b></td>
- <td align="left">
- <input name="availableenable" type="checkbox" value="1" alt="<?php print_string("quizopen", "quiz") ?>" onclick="return lockoptions('form', 'availableenable', availableitems)" <?php if ($form->timeopen) echo 'checked="checked"' ?> />
- <?php
- print_date_selector("availableday", "availablemonth", "availableyear", $form->timeopen);
- echo " - ";
- print_time_selector("availablehour", "availableminute", $form->timeopen);
- helpbutton('timeopen', get_string('quizopens', 'quiz'), 'quiz');
- ?>
- <input type="hidden" name="havailableday" value="0" />
- <input type="hidden" name="havailablemonth" value="0" />
- <input type="hidden" name="havailableyear" value="0" />
- <input type="hidden" name="havailablehour" value="0" />
- <input type="hidden" name="havailableminute" value="0" />
- </td>
-</tr>
-
-<tr valign="top">
- <td align="right"><b><?php print_string("quizclose", "quiz") ?>:</b></td>
- <td align="left">
- <input name="dueenable" type="checkbox" value="1" alt="<?php print_string("quizclose", "quiz") ?>" onclick="return lockoptions('form', 'dueenable', dueitems)" <?php if ($form->timeclose) echo 'checked="checked"' ?> />
- <?php
- print_date_selector("dueday", "duemonth", "dueyear", $form->timeclose);
- echo " - ";
- print_time_selector("duehour", "dueminute", $form->timeclose);
- helpbutton('timeopen', get_string('quizcloses', 'quiz'), 'quiz');
- ?>
- <input type="hidden" name="hdueday" value="0" />
- <input type="hidden" name="hduemonth" value="0" />
- <input type="hidden" name="hdueyear" value="0" />
- <input type="hidden" name="hduehour" value="0" />
- <input type="hidden" name="hdueminute" value="0" />
- </td>
-</tr>
-
-<?php
-
- // Output all the options that may, or may not, have been fixed by the admin.
- // This time out put the ones that were not fixed.
- $fix = output_quiz_options_fields($form, 0);
-
- // Output standard module settings.
- print_standard_coursemodule_settings($form);
-
- // Output the boxes for typing feedback depending on overall quiz score.
-?>
-<tr><td colspan="2">
- <?php print_heading_with_help(get_string('overallfeedback', 'quiz'), 'overallfeedback', 'quiz'); ?>
-</td></tr>
-
-<tr valign="top">
- <td align="right"><b><?php print_string('gradeboundary', 'quiz') ?>:</b></td>
- <td align="left">100%</td>
-</tr>
-
-<?php for ($i = 0; $i < count($form->feedbacktext); $i = $i + 1) { ?>
-
-<tr valign="top">
- <td align="right"><b><?php print_string('feedback', 'quiz') ?>:</b></td>
- <td align="left">
- <input type="text" name="feedbacktext[]" size="60" value="<?php p($form->feedbacktext[$i]) ?>" />
- </td>
-</tr>
-
-<?php if ($i < count($form->feedbacktext) - 1) { ?>
-<tr valign="top">
- <td align="right"><b><?php print_string('gradeboundary', 'quiz') ?>:</b></td>
- <td align="left">
- <input type="text" name="feedbackboundaries[]" size="20" value="<?php p($form->feedbackboundaries[$i]) ?>" />
- </td>
-</tr>
-<?php } ?>
-
-<?php } ?>
-<tr valign="top">
- <td align="right"><b><?php print_string('gradeboundary', 'quiz') ?>:</b></td>
- <td align="left">0%</td>
-</tr>
-
-<?php
- if ($fix) {
- // Some options were fixed by the admin. Show them, but hidden behind an Advanced button.
-?>
-<tr>
- <td align="right"><b><?php print_string('advancedsettings') ?>:</b>
- <!-- Some javascript to allow for the hiding of advanced options
- This code was derived from mod.html in the resource module -->
- <script language="javascript" type="text/javascript">
- function showhide (id, set) {
- divobj = document.getElementById(id);
- butobj = document.getElementById(id+'button');
- prefobj = document.getElementById(id+'pref');
- if (set == true) {
- if (prefobj.value == '1') {
- divobj.style.display = 'block';
- butobj.value = '<?php print_string("hideadvancedsettings") ?>';
- } else {
- divobj.style.display = 'none';
- butobj.value = '<?php print_string("showadvancedsettings") ?>...';
- }
- } else {
- if (prefobj.value == '1') {
- divobj.style.display = 'none';
- butobj.value = '<?php print_string("showadvancedsettings") ?>...';
- prefobj.value = '0';
- } else {
- divobj.style.display = 'block';
- butobj.value = '<?php print_string("hideadvancedsettings") ?>';
- prefobj.value = '1';
- }
- }
- }
- </script>
- </td>
- <td align="left">
- <input type="button" value="hide settings" id="optionsettingsbutton" onclick="javascript: return showhide('optionsettings');" />
- <input type="hidden" name="optionsettingspref" id="optionsettingspref" value="<?php echo get_user_preferences('quiz_optionsettingspref', 0); ?>" />
- <br />
- </td>
-</tr>
-
-<!-- Now comes a copy of the options fields in a div with id optionsettings and with
- the conditions reversed, so that it shows exactly the options that are usually hidden.
- The visibility of this div is controlled by javascript. -->
-<tr><td colspan="2">
-<div id="optionsettings">
-<table align="center">
-
-<?php
- // Output all the options that may, or may not, have been fixed by the admin.
- // This time out put the ones that were fixed.
- output_quiz_options_fields($form, 1);
-?>
-</table>
-<script language="javascript" type="text/javascript">
- showhide('optionsettings', true);
-</script>
-</div></td></tr>
-<?php } ?>
-
-</table>
-<br />
-<input type="hidden" name="grade" value="<?php echo $form->grade; ?>" />
-
-<!-- these hidden variables are always the same -->
-<input type="hidden" name="course" value="<?php p($form->course) ?>" />
-<input type="hidden" name="sesskey" value="<?php p($form->sesskey) ?>" />
-<input type="hidden" name="coursemodule" value="<?php p($form->coursemodule) ?>" />
-<input type="hidden" name="section" value="<?php p($form->section) ?>" />
-<input type="hidden" name="module" value="<?php p($form->module) ?>" />
-<input type="hidden" name="modulename" value="<?php p($form->modulename) ?>" />
-<input type="hidden" name="instance" value="<?php p($form->instance) ?>" />
-<input type="hidden" name="mode" value="<?php p($form->mode) ?>" />
-<!-- provide an additional button to edit questions -->
-<?php if ($form->instance) { ?>
-<input type="hidden" name="redirecturl" value="<?php p("$CFG->wwwroot/mod/quiz/edit.php?quizid=$form->instance") ?>" />
-<input type="submit" name="redirect" value="<?php print_string("savechanges") ?>" />
-<?php } else { ?>
-<input type="submit" value="<?php print_string("savechanges") ?>" />
-<?php } ?>
-<input type="submit" name="cancel" value="<?php print_string("cancel") ?>" />
-</center>
-</form>
-
-<script type="text/javascript">
-<?php
- if (!$form->timeclose) echo "lockoptions('form','dueenable', dueitems);";
- if (!$form->timeopen) echo "lockoptions('form','availableenable', availableitems);";
- if (!$form->timelimit) echo "lockoptions('form','timelimitenable', timelimititems);";
-?>
-</script>
-
-<?php
-/**
- * This function outputs all the quiz options that may, or may not, have been
- * locked by admin. Whether the locked or unlocked fields are shown depends on
- * $showfixed.
- *
- * @param object $form the data being used to initialise the form.
- * @param integer $showfixed if 0, output the unlocked fields, if 1 output the locked fields.
- * @return boolean true if some filds were not output with this setting of $showfixed
- */
-function output_quiz_options_fields($form, $showfixed) {
- global $CFG, $QUIZ_GRADE_METHOD, $yesnooptions, $attemptoptions, $timedelayoptions;
-
- $hidden = false;
-?>
-
-<?php if ($CFG->quiz_fix_timelimit == $showfixed) { ?>
- <tr valign="top">
- <td align="right"><b><?php print_string("timelimit", "quiz") ?>:</b></td>
- <td align="left">
- <input name="timelimitenable" type="checkbox" value="1" alt="<?php print_string('timelimit', 'quiz') ?>" onclick="return lockoptions('form', 'timelimitenable', timelimititems)" <?php if ($form->timelimit) echo 'checked="checked"' ?> />
- <input type="text" name="timelimit" size="3" value="<?php p($form->timelimit ? $form->timelimit : '') ?>" />
- <?php
- print_string('minutes');
- helpbutton("timelimit", get_string("quiztimer","quiz"), "quiz");
- ?>
- <input type="hidden" name="htimelimit" value="0" />
- </td>
- </tr>
-<?php } else { $hidden = true; } ?>
-
-<?php if ($CFG->quiz_fix_questionsperpage == $showfixed) { ?>
- <tr valign="top">
- <td align="right"><b><?php print_string('questionsperpage', 'quiz') ?>:</b></td>
- <td align="left">
- <?php
- $perpage= array();
- for ($i=0; $i<=50; ++$i) {
- $perpage[$i] = $i;
- }
- $perpage[0] = get_string('allinone', 'quiz');
-
- choose_from_menu($perpage, 'questionsperpage', $form->questionsperpage, '');
- helpbutton('questionsperpage', get_string('questionsperpage', 'quiz'), 'quiz');
- ?>
- </td>
- </tr>
-<?php } else { $hidden = true; } ?>
-
-<?php if ($CFG->quiz_fix_shufflequestions == $showfixed) { ?>
- <tr valign="top">
- <td align="right"><b><?php print_string("shufflequestions", "quiz") ?>:</b></td>
- <td align="left">
- <?php
- choose_from_menu($yesnooptions, "shufflequestions", "$form->shufflequestions", "");
- helpbutton("shufflequestions", get_string("shufflequestions","quiz"), "quiz");
- ?>
- </td>
- </tr>
-<?php } else { $hidden = true; } ?>
-
-<?php if ($CFG->quiz_fix_shuffleanswers == $showfixed) { ?>
- <tr valign="top">
- <td align="right"><b><?php print_string("shufflewithin", "quiz") ?>:</b></td>
- <td align="left">
- <?php
- choose_from_menu($yesnooptions, "shuffleanswers", "$form->shuffleanswers", "");
- helpbutton("shufflewithin", get_string("shufflewithin","quiz"), "quiz");
- ?>
- </td>
- </tr>
-<?php } else { $hidden = true; } ?>
-
-<?php if ($CFG->quiz_fix_attempts == $showfixed) { ?>
- <tr valign="top">
- <td align="right"><b><?php print_string("attemptsallowed", "quiz") ?>:</b></td>
- <td align="left">
- <?php
- choose_from_menu($attemptoptions, "attempts", "$form->attempts", "");
- helpbutton("attempts", get_string("attemptsallowed","quiz"), "quiz");
- ?>
- </td>
- </tr>
-<?php } else { $hidden = true; } ?>
-
-<?php if ($CFG->quiz_fix_attemptonlast == $showfixed) { ?>
- <tr valign="top">
- <td align="right"><b><?php print_string("eachattemptbuildsonthelast", "quiz") ?>:</b></td>
- <td align="left">
- <?php
- choose_from_menu($yesnooptions, "attemptonlast",
- "$form->attemptonlast", "");
- helpbutton("repeatattempts",
- get_string("eachattemptbuildsonthelast", "quiz"),
- "quiz");
- ?>
- </td>
- </tr>
-<?php } else { $hidden = true; } ?>
-
-<?php if ($CFG->quiz_fix_grademethod == $showfixed) { ?>
- <tr valign="top">
- <td align="right"><b><?php print_string("grademethod", "quiz") ?>:</b></td>
- <td align="left">
- <?php
- choose_from_menu($QUIZ_GRADE_METHOD, "grademethod", "$form->grademethod", "");
- helpbutton("grademethod", get_string("grademethod","quiz"), "quiz");
- ?>
- </td>
- </tr>
-<?php } else { $hidden = true; } ?>
-
-<?php if ($CFG->quiz_fix_adaptive == $showfixed) { ?>
- <tr valign="top">
- <td align="right"><b><?php print_string("adaptive", "quiz") ?>:</b></td>
- <td align="left">
- <?php
- choose_from_menu($yesnooptions, "adaptive", ($form->optionflags & QUESTION_ADAPTIVE) ? 1 : 0, "");
- helpbutton("adaptive", get_string("adaptive","quiz"), "quiz");
- ?>
- </td>
- </tr>
-<?php } else { $hidden = true; } ?>
-
-<?php if ($CFG->quiz_fix_penaltyscheme == $showfixed) { ?>
- <tr valign="top">
- <td align="right"><b><?php print_string("penaltyscheme", "quiz") ?>:</b></td>
- <td align="left">
- <?php
- choose_from_menu($yesnooptions, "penaltyscheme", "$form->penaltyscheme", "");
- helpbutton("penaltyscheme", get_string("penaltyscheme","quiz"), "quiz");
- ?>
- </td>
- </tr>
-<?php } else { $hidden = true; } ?>
-
-<?php if ($CFG->quiz_fix_decimalpoints == $showfixed) { ?>
- <tr valign="top">
- <td align="right"><b><?php print_string("decimaldigits", "quiz") ?>:</b></td>
- <td align="left">
- <?php
- $options = array(
- 0 => '0',
- 1 => '1',
- 2 => '2',
- 3 => '3'
- );
- choose_from_menu($options, "decimalpoints", "$form->decimalpoints", "");
- helpbutton("decimalpoints", get_string("decimaldigits","quiz"), "quiz");
- ?>
- </td>
- </tr>
-<?php } else { $hidden = true; } ?>
-
-<?php if ($CFG->quiz_fix_review == $showfixed) {
- echo '<tr valign="top">';
- include($CFG->dirroot . '/mod/quiz/reviewoptions.html');
- echo '</tr>';
- $output = true;
-} ?>
-
-<?php if ($CFG->quiz_fix_delay1 == $showfixed) { ?>
- <tr valign="top">
- <td align="right"><b><?php print_string("delay1", "quiz") ?>:</b></td>
- <td align="left">
- <?php
- choose_from_menu($timedelayoptions, "delay1", "$form->delay1", "");
- helpbutton("timedelay1", get_string("delay1","quiz"), "quiz");
- ?>
- </td>
- </tr>
-<?php } else { $hidden = true; } ?>
-
-<?php if ($CFG->quiz_fix_delay2 == $showfixed) { ?>
- <tr valign="top">
- <td align="right"><b><?php print_string("delay2", "quiz") ?>:</b></td>
- <td align="left">
- <?php
- choose_from_menu($timedelayoptions, "delay2", "$form->delay2", "");
- helpbutton("timedelay2", get_string("delay2","quiz"), "quiz");
- ?>
- </td>
- </tr>
-<?php } else { $hidden = true; } ?>
-
-<?php if ($CFG->quiz_fix_popup == $showfixed) { ?>
- <tr valign="top">
- <td align="right"><b><?php print_string("popup", "quiz") ?>:</b></td>
- <td align="left">
- <?php
- choose_from_menu($yesnooptions, "popup", "$form->popup", "");
- helpbutton("popup", get_string("popup","quiz"), "quiz");
- ?>
- </td>
- </tr>
-<?php } else { $hidden = true; } ?>
-
-<?php if ($CFG->quiz_fix_password == $showfixed) { ?>
- <tr valign="top">
- <td align="right"><b><?php print_string("requirepassword", "quiz") ?>:</b></td>
- <td align="left">
- <input type="text" name="password" size="40" value="<?php p($form->password) ?>" />
- <?php helpbutton("requirepassword", get_string("requirepassword", "quiz"), "quiz"); ?>
- </td>
- </tr>
-<?php } else { $hidden = true; } ?>
-
-<?php if ($CFG->quiz_fix_subnet == $showfixed) { ?>
- <tr valign="top">
- <td align="right"><b><?php print_string("requiresubnet", "quiz") ?>:</b></td>
- <td align="left">
- <input type="text" name="subnet" size="40" value="<?php p($form->subnet) ?>" />
- <?php helpbutton("requiresubnet", get_string("requiresubnet", "quiz"), "quiz"); ?>
- </td>
- </tr>
-<?php } else { $hidden = true; } ?>
-<?php
- return $hidden;
-}
-?>
\ No newline at end of file
--- /dev/null
+<?php
+require_once ('moodleform_mod.php');
+
+require_once("$CFG->dirroot/mod/quiz/locallib.php");
+
+class quiz_mod_form extends moodleform_mod {
+ var $_feedbacks;
+
+ function definition() {
+
+ global $COURSE, $CFG, $QUIZ_GRADE_METHOD;
+ $mform =& $this->_form;
+
+ $mform->setShowAdvanced(get_user_preferences('quiz_optionsettingspref', 0));
+//-------------------------------------------------------------------------------
+ $mform->addElement('header', 'general', get_string('general', 'form'));
+
+ $mform->addElement('text', 'name', get_string('name'));
+ $mform->setType('name', PARAM_TEXT);
+
+ $mform->addElement('htmleditor', 'intro', get_string("introduction", "quiz"));
+ $mform->setType('intro', PARAM_RAW);
+
+//-------------------------------------------------------------------------------
+ $mform->addElement('header', 'timinghdr', get_string('timing', 'form'));
+ $mform->addElement('date_selector', 'timeopen', get_string("quizopen", "quiz"), array('optional'=>true));
+ $mform->setHelpButton('timeopen', array('timeopen', get_string('quizopens', 'quiz'), 'quiz'));
+
+ $mform->addElement('date_selector', 'timeclose', get_string("quizcloses", "quiz"), array('optional'=>true));
+ $mform->setHelpButton('timeclose', array('timeopen', get_string('quizcloses', 'quiz'), 'quiz'));
+
+
+ $timelimitgrp=array();
+ $timelimitgrp[] = &$mform->createElement('text', 'timelimit');
+ $timelimitgrp[] = &$mform->createElement('checkbox', 'timelimitenable', '', get_string('enable'));
+ $mform->addGroup($timelimitgrp, 'timelimitgrp', get_string("timelimit", "quiz"), array(' '), false);
+ $mform->setType('timelimit', PARAM_TEXT);
+ $timelimitgrprules = array();
+ $timelimitgrprules['timelimit'][] = array(null, 'numeric', null, 'client');
+ $mform->addGroupRule('timelimitgrp', $timelimitgrprules);
+ $mform->disabledIf('timelimitgrp', 'timelimitenable');
+ $mform->setAdvanced('timelimitgrp', $CFG->quiz_fix_timelimit);
+ $mform->setHelpButton('timelimitgrp', array("timelimit", get_string("quiztimer","quiz"), "quiz"));
+ $mform->setDefault('timelimit', $CFG->quiz_timelimit);
+
+
+ //enforced time delay between quiz attempts add-on
+ $timedelayoptions = array();
+ $timedelayoptions[0] = get_string('none');
+ $timedelayoptions[1800] = get_string('numminutes', '', 30);
+ $timedelayoptions[3600] = get_string('numminutes', '', 60);
+ for($i=2; $i<=23; $i++) {
+ $seconds = $i*3600;
+ $timedelayoptions[$seconds] = get_string('numhours', '', $i);
+ }
+ $timedelayoptions[86400] = get_string('numhours', '', 24);
+ for($i=2; $i<=7; $i++) {
+ $seconds = $i*86400;
+ $timedelayoptions[$seconds] = get_string('numdays', '', $i);
+ }
+ $mform->addElement('select', 'delay1', get_string("delay1", "quiz"), $timedelayoptions);
+ $mform->setHelpButton('delay1', array("timedelay1", get_string("delay1", "quiz"), "quiz"));
+ $mform->setAdvanced('delay1', $CFG->quiz_fix_delay1);
+ $mform->setDefault('delay1', $CFG->quiz_delay1);
+
+ $mform->addElement('select', 'delay2', get_string("delay2", "quiz"), $timedelayoptions);
+ $mform->setHelpButton('delay2', array("timedelay2", get_string("delay2", "quiz"), "quiz"));
+ $mform->setAdvanced('delay2', $CFG->quiz_fix_delay2);
+ $mform->setDefault('delay2', $CFG->quiz_delay2);
+
+//-------------------------------------------------------------------------------
+ $mform->addElement('header', 'displayhdr', get_string('display', 'form'));
+ $perpage = array();
+ for ($i = 0; $i <= 50; ++$i) {
+ $perpage[$i] = $i;
+ }
+ $perpage[0] = get_string('allinone', 'quiz');
+ $mform->addElement('select', 'questionsperpage', get_string('questionsperpage', 'quiz'), $perpage);
+ $mform->setHelpButton('questionsperpage', array('questionsperpage', get_string('questionsperpage', 'quiz'), 'quiz'));
+ $mform->setAdvanced('questionsperpage', $CFG->quiz_fix_questionsperpage);
+ $mform->setDefault('questionsperpage', $CFG->quiz_questionsperpage);
+
+ $mform->addElement('selectyesno', 'shufflequestions', get_string("shufflequestions", "quiz"));
+ $mform->setHelpButton('shufflequestions', array("shufflequestions", get_string("shufflequestions","quiz"), "quiz"));
+ $mform->setAdvanced('shufflequestions', $CFG->quiz_fix_shufflequestions);
+ $mform->setDefault('shufflequestions', $CFG->quiz_shufflequestions);
+
+ $mform->addElement('selectyesno', 'shuffleanswers', get_string("shufflewithin", "quiz"));
+ $mform->setHelpButton('shuffleanswers', array("shufflewithin", get_string("shufflewithin","quiz"), "quiz"));
+ $mform->setAdvanced('shuffleanswers', $CFG->quiz_fix_shuffleanswers);
+ $mform->setDefault('shuffleanswers', $CFG->quiz_shuffleanswers);
+
+//-------------------------------------------------------------------------------
+ $mform->addElement('header', 'attemptshdr', get_string('attempts', 'quiz'));
+ $attemptoptions = array();
+ $attemptoptions[0] = get_string("attemptsunlimited", "quiz");
+ $attemptoptions[1] = "1 ".moodle_strtolower(get_string("attempt", "quiz"));
+ for ($i=2;$i<=6;$i++) {
+ $attemptoptions[$i] = "$i ".moodle_strtolower(get_string("attempts", "quiz"));
+ }
+ $mform->addElement('select', 'attempts', get_string("attemptsallowed", "quiz"), $attemptoptions);
+ $mform->setHelpButton('attempts', array("attempts", get_string("attemptsallowed","quiz"), "quiz"));
+ $mform->setAdvanced('attempts', $CFG->quiz_fix_attempts);
+ $mform->setDefault('attempts', $CFG->quiz_attempts);
+
+ $mform->addElement('selectyesno', 'attemptonlast', get_string("eachattemptbuildsonthelast", "quiz"));
+ $mform->setHelpButton('attemptonlast', array("repeatattempts", get_string("eachattemptbuildsonthelast", "quiz"), "quiz"));
+ $mform->setAdvanced('attemptonlast', $CFG->quiz_fix_attemptonlast);
+ $mform->setDefault('attemptonlast', $CFG->quiz_attemptonlast);
+
+ $mform->addElement('selectyesno', 'adaptive', get_string("adaptive", "quiz"));
+ $mform->setHelpButton('adaptive', array("adaptive", get_string("adaptive","quiz"), "quiz"));
+ $mform->setAdvanced('adaptive', $CFG->quiz_fix_adaptive);
+ $mform->setDefault('adaptive', $CFG->quiz_optionflags & QUESTION_ADAPTIVE);
+
+
+//-------------------------------------------------------------------------------
+ $mform->addElement('header', 'gradeshdr', get_string('grades', 'grades'));
+ $mform->addElement('select', 'grademethod', get_string("grademethod", "quiz"), $QUIZ_GRADE_METHOD);
+ $mform->setHelpButton('grademethod', array("grademethod", get_string("grademethod","quiz"), "quiz"));
+ $mform->setAdvanced('grademethod', $CFG->quiz_fix_grademethod);
+ $mform->setDefault('grademethod', $CFG->quiz_grademethod);
+
+ $mform->addElement('selectyesno', 'penaltyscheme', get_string("penaltyscheme", "quiz"));
+ $mform->setHelpButton('penaltyscheme', array("penaltyscheme", get_string("penaltyscheme","quiz"), "quiz"));
+ $mform->setAdvanced('penaltyscheme', $CFG->quiz_fix_penaltyscheme);
+ $mform->setDefault('penaltyscheme', $CFG->quiz_penaltyscheme);
+
+ $options = array(
+ 0 => '0',
+ 1 => '1',
+ 2 => '2',
+ 3 => '3');
+ $mform->addElement('select', 'decimalpoints', get_string("decimaldigits", "quiz"), $options);
+ $mform->setHelpButton('decimalpoints', array("decimalpoints", get_string("decimaldigits","quiz"), "quiz"));
+ $mform->setAdvanced('decimalpoints', $CFG->quiz_fix_decimalpoints);
+
+ $mform->addElement('hidden', 'grade', $CFG->quiz_maximumgrade);
+
+//-------------------------------------------------------------------------------
+ $mform->addElement('header', 'reviewoptionshdr', get_string("reviewoptions", "quiz"));
+ $mform->setHelpButton('reviewoptionshdr', array("review2", get_string("allowreview","quiz"), "quiz"));
+ $mform->setAdvanced('reviewoptionshdr', $CFG->quiz_fix_review);
+
+ $immediatelyoptionsgrp=array();
+ $immediatelyoptionsgrp[] = &$mform->createElement('checkbox', 'responsesimmediately', '', get_string('responses', 'quiz'));
+ $immediatelyoptionsgrp[] = &$mform->createElement('checkbox', 'scoreimmediately', '', get_string('scores', 'quiz'));
+ $immediatelyoptionsgrp[] = &$mform->createElement('checkbox', 'feedbackimmediately', '', get_string('feedback', 'quiz'));
+ $immediatelyoptionsgrp[] = &$mform->createElement('checkbox', 'answersimmediately', '', get_string('answers', 'quiz'));
+ $immediatelyoptionsgrp[] = &$mform->createElement('checkbox', 'generalfeedbackimmediately', '', get_string('generalfeedback', 'quiz'));
+ $mform->addGroup($immediatelyoptionsgrp, 'immediatelyoptionsgrp', get_string("reviewimmediately", "quiz"), null, false);
+ $mform->setDefault('responsesimmediately', $CFG->quiz_review & QUIZ_REVIEW_RESPONSES & QUIZ_REVIEW_IMMEDIATELY);
+ $mform->setDefault('scoreimmediately', $CFG->quiz_review & QUIZ_REVIEW_SCORES & QUIZ_REVIEW_IMMEDIATELY);
+ $mform->setDefault('feedbackimmediately', $CFG->quiz_review & QUIZ_REVIEW_FEEDBACK & QUIZ_REVIEW_IMMEDIATELY);
+ $mform->setDefault('answersimmediately', $CFG->quiz_review & QUIZ_REVIEW_ANSWERS & QUIZ_REVIEW_IMMEDIATELY);
+ $mform->setDefault('generalfeedbackimmediately', $CFG->quiz_review & QUIZ_REVIEW_GENERALFEEDBACK & QUIZ_REVIEW_IMMEDIATELY);
+
+ $openoptionsgrp=array();
+ $openoptionsgrp[] = &$mform->createElement('checkbox', 'responsesopen', '', get_string('responses', 'quiz'));
+ $openoptionsgrp[] = &$mform->createElement('checkbox', 'scoreopen', '', get_string('scores', 'quiz'));
+ $openoptionsgrp[] = &$mform->createElement('checkbox', 'feedbackopen', '', get_string('feedback', 'quiz'));
+ $openoptionsgrp[] = &$mform->createElement('checkbox', 'answersopen', '', get_string('answers', 'quiz'));
+ $openoptionsgrp[] = &$mform->createElement('checkbox', 'generalfeedbackopen', '', get_string('generalfeedback', 'quiz'));
+ $mform->addGroup($openoptionsgrp, 'openoptionsgrp', get_string("reviewopen", "quiz"), array(' '), false);
+ $mform->setDefault('responsesopen', $CFG->quiz_review & QUIZ_REVIEW_RESPONSES & QUIZ_REVIEW_OPEN);
+ $mform->setDefault('scoreopen', $CFG->quiz_review & QUIZ_REVIEW_SCORES & QUIZ_REVIEW_OPEN);
+ $mform->setDefault('feedbackopen', $CFG->quiz_review & QUIZ_REVIEW_FEEDBACK & QUIZ_REVIEW_OPEN);
+ $mform->setDefault('answersopen', $CFG->quiz_review & QUIZ_REVIEW_ANSWERS & QUIZ_REVIEW_OPEN);
+ $mform->setDefault('generalfeedbackopen', $CFG->quiz_review & QUIZ_REVIEW_GENERALFEEDBACK & QUIZ_REVIEW_OPEN);
+
+
+ $closedoptionsgrp=array();
+ $closedoptionsgrp[] = &$mform->createElement('checkbox', 'responsesclosed', '', get_string('responses', 'quiz'));
+ $closedoptionsgrp[] = &$mform->createElement('checkbox', 'scoreclosed', '', get_string('scores', 'quiz'));
+ $closedoptionsgrp[] = &$mform->createElement('checkbox', 'feedbackclosed', '', get_string('feedback', 'quiz'));
+ $closedoptionsgrp[] = &$mform->createElement('checkbox', 'answersclosed', '', get_string('answers', 'quiz'));
+ $closedoptionsgrp[] = &$mform->createElement('checkbox', 'generalfeedbackclosed', '', get_string('generalfeedback', 'quiz'));
+ $mform->addGroup($closedoptionsgrp, 'closedoptionsgrp', get_string("reviewclosed", "quiz"), array(' '), false);
+ $mform->setDefault('responsesclosed', $CFG->quiz_review & QUIZ_REVIEW_RESPONSES & QUIZ_REVIEW_CLOSED);
+ $mform->setDefault('scoreclosed', $CFG->quiz_review & QUIZ_REVIEW_SCORES & QUIZ_REVIEW_CLOSED);
+ $mform->setDefault('feedbackclosed', $CFG->quiz_review & QUIZ_REVIEW_FEEDBACK & QUIZ_REVIEW_CLOSED);
+ $mform->setDefault('answersclosed', $CFG->quiz_review & QUIZ_REVIEW_ANSWERS & QUIZ_REVIEW_CLOSED);
+ $mform->setDefault('generalfeedbackclosed', $CFG->quiz_review & QUIZ_REVIEW_GENERALFEEDBACK & QUIZ_REVIEW_CLOSED);
+
+//-------------------------------------------------------------------------------
+ $mform->addElement('header', 'security', get_string('security', 'form'));
+
+ $mform->addElement('selectyesno', 'popup', get_string("popup", "quiz"));
+ $mform->setHelpButton('popup', array("popup", get_string("popup", "quiz"), "quiz"));
+ $mform->setAdvanced('popup', $CFG->quiz_fix_popup);
+ $mform->setDefault('popup', $CFG->quiz_popup);
+
+ $mform->addElement('text', 'password', get_string("requirepassword", "quiz"));
+ $mform->setType('password', PARAM_TEXT);
+ $mform->setHelpButton('password', array("requirepassword", get_string("requirepassword", "quiz"), "quiz"));
+ $mform->setAdvanced('password', $CFG->quiz_fix_password);
+ $mform->setDefault('password', $CFG->quiz_password);
+
+ $mform->addElement('text', 'subnet', get_string("requiresubnet", "quiz"));
+ $mform->setType('subnet', PARAM_TEXT);
+ $mform->setHelpButton('subnet', array("requiresubnet", get_string("requiresubnet", "quiz"), "quiz"));
+ $mform->setAdvanced('subnet', $CFG->quiz_fix_subnet);
+ $mform->setDefault('subnet', $CFG->quiz_subnet);
+
+//-------------------------------------------------------------------------------
+ $this->standard_coursemodule_elements();
+//-------------------------------------------------------------------------------
+ $mform->addElement('header', 'overallfeedbackhdr', get_string('overallfeedback', 'quiz'));
+ $mform->setHelpButton('overallfeedbackhdr', array('overallfeedback', get_string('overallfeedback', 'quiz'), 'quiz'));
+
+ $mform->addElement('static', 'gradeboundarystatic1', get_string('gradeboundary', 'quiz'), '100%');
+
+ $repeatarray=array();
+ $repeatarray[] = &MoodleQuickForm::createElement('text', 'feedbacktext', get_string('feedback', 'quiz'));
+ $repeatarray[] = &MoodleQuickForm::createElement('text', 'feedbackboundaries', get_string('gradeboundary', 'quiz'));
+
+ if (!empty($this->_instance)) {
+ $this->_feedbacks = get_records('quiz_feedback', 'quizid', $this->_instance, 'mingrade DESC');
+ } else {
+ $this->_feedbacks = array();
+ }
+ $numfeedbacks = max(count($this->_feedbacks) * 1.5, 5);
+ $nextel=$this->repeat_elements($repeatarray, $numfeedbacks-1,
+ array('feedbacktext'=> array('type'=>PARAM_TEXT),
+ 'feedbackboundaries' => array('type'=>PARAM_TEXT)),
+ 'boundary_repeats', 'boundary_add_fields', 3);
+
+ //put some extra elements in before the button
+ $insertEl = &MoodleQuickForm::createElement('text', "feedbacktext[$nextel]", get_string('feedback', 'quiz'));
+ $mform->insertElementBefore($insertEl, 'boundary_add_fields');
+ $mform->setType("feedbacktext[$nextel]", PARAM_TEXT);
+ $mform->setHelpButton("feedbacktext[$nextel]", array('options', get_string('modulenameplural', 'choice'), 'choice'));
+
+ $insertEl = &MoodleQuickForm::createElement('static', 'gradeboundarystatic2', get_string('gradeboundary', 'quiz'), '0%');
+ $mform->insertElementBefore($insertEl, 'boundary_add_fields');
+
+//-------------------------------------------------------------------------------
+ // buttons
+ $this->add_action_buttons();
+ }
+
+ function defaults_preprocessing(&$default_values){
+ if (count($this->_feedbacks)) {
+ $key = 0;
+ foreach ($this->_feedbacks as $feedback){
+ $default_values['feedbacktext['.$key.']'] = $feedback->feedbacktext;
+ if ($feedback->mingrade > 0) {
+ $default_values['feedbackboundaries['.$key.']'] = (100.0 * $feedback->mingrade / $default_values['grade']) . '%';
+ }
+ $key++;
+ }
+
+ }
+ if (empty($default_values['timelimit'])) {
+ $default_values['timelimitenable'] = 0;
+ } else {
+ $default_values['timelimitenable'] = 1;
+ }
+
+ if (isset($default_values['review'])){
+ $review = (int)$default_values['review'];
+ unset($default_values['review']);
+
+ $default_values['responsesimmediately'] = $review & QUIZ_REVIEW_RESPONSES & QUIZ_REVIEW_IMMEDIATELY;
+ $default_values['scoreimmediately'] = $review & QUIZ_REVIEW_SCORES & QUIZ_REVIEW_IMMEDIATELY;
+ $default_values['feedbackimmediately'] = $review & QUIZ_REVIEW_FEEDBACK & QUIZ_REVIEW_IMMEDIATELY;
+ $default_values['answersimmediately'] = $review & QUIZ_REVIEW_ANSWERS & QUIZ_REVIEW_IMMEDIATELY;
+ $default_values['generalfeedbackimmediately'] = $review & QUIZ_REVIEW_GENERALFEEDBACK & QUIZ_REVIEW_IMMEDIATELY;
+
+ $default_values['responsesopen'] = $review & QUIZ_REVIEW_RESPONSES & QUIZ_REVIEW_OPEN;
+ $default_values['scoreopen'] = $review & QUIZ_REVIEW_SCORES & QUIZ_REVIEW_OPEN;
+ $default_values['feedbackopen'] = $review & QUIZ_REVIEW_FEEDBACK & QUIZ_REVIEW_OPEN;
+ $default_values['answersopen'] = $review & QUIZ_REVIEW_ANSWERS & QUIZ_REVIEW_OPEN;
+ $default_values['generalfeedbackopen'] = $review & QUIZ_REVIEW_GENERALFEEDBACK & QUIZ_REVIEW_OPEN;
+
+ $default_values['responsesclosed'] = $review & QUIZ_REVIEW_RESPONSES & QUIZ_REVIEW_CLOSED;
+ $default_values['scoreclosed'] = $review & QUIZ_REVIEW_SCORES & QUIZ_REVIEW_CLOSED;
+ $default_values['feedbackclosed'] = $review & QUIZ_REVIEW_FEEDBACK & QUIZ_REVIEW_CLOSED;
+ $default_values['answersclosed'] = $review & QUIZ_REVIEW_ANSWERS & QUIZ_REVIEW_CLOSED;
+ $default_values['generalfeedbackclosed'] = $review & QUIZ_REVIEW_GENERALFEEDBACK & QUIZ_REVIEW_CLOSED;
+ }
+
+ if (isset($default_values['optionflags'])){
+ $default_values['adaptive'] = $default_values['optionflags'] & QUESTION_ADAPTIVE;
+ unset($default_values['optionflags']);
+ }
+ }
+
+ function validation($data){
+ $errors = array();
+ // Check open and close times are consistent.
+ if ($data['timeopen'] != 0 && $data['timeclose'] != 0 && $data['timeclose'] < $data['timeopen']) {
+ $errors['timeclose'] = get_string('closebeforeopen', 'quiz');
+ }
+
+ // Check the boundary value is a number or a percentage, and in range.
+ $i = 0;
+ while (!empty($data['feedbackboundaries'][$i] )) {
+ $boundary = trim($data['feedbackboundaries'][$i]);
+ if (strlen($boundary) > 0 && $boundary[strlen($boundary) - 1] == '%') {
+ $boundary = trim(substr($boundary, 0, -1));
+ if (is_numeric($boundary)) {
+ $boundary = $boundary * $data['grade'] / 100.0;
+ } else {
+ $errors["feedbackboundaries[$i]"] = get_string('feedbackerrorboundaryformat', 'quiz', $i + 1);
+ }
+ }
+ if (is_numeric($boundary) && $boundary <= 0 || $boundary >= $data['grade'] ) {
+ $errors["feedbackboundaries[$i]"] = get_string('feedbackerrorboundaryoutofrange', 'quiz', $i + 1);
+ }
+ if (is_numeric($boundary) && $i > 0 && $boundary >= $data['feedbackboundaries'][$i - 1]) {
+ $errors["feedbackboundaries[$i]"] = get_string('feedbackerrororder', 'quiz', $i + 1);
+ }
+ $data['feedbackboundaries'][$i] = $boundary;
+ $i += 1;
+ }
+ $numboundaries = $i;
+
+ // Check there is nothing in the remaining unused fields.
+ for ($i = $numboundaries; $i < count($data['feedbackboundaries'] ); $i += 1) {
+ if (!empty($data['feedbackboundaries'][$i] ) && trim($data['feedbackboundaries'][$i] ) != '') {
+ $errors["feedbackboundaries[$i]"] = get_string('feedbackerrorjunkinboundary', 'quiz', $i + 1);
+ }
+ }
+ for ($i = $numboundaries + 1; $i < count($data['feedbacktext'] ); $i += 1) {
+ if (!empty($data['feedbacktext'][$i] ) && trim($data['feedbacktext'][$i] ) != '') {
+ $errors["feedbacktext[$i]"] = get_string('feedbackerrorjunkinfeedback', 'quiz', $i + 1);
+ }
+ }
+ return $errors;
+ }
+
+}
+?>
\ No newline at end of file
$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);
}
}
font-weight: bold;
margin-left: 0.5em;
}
-
+form.mform fieldset .advancedbutton{
+ width:100%;
+ text-align:right;
+}
form.mform div.fitem {
clear: both;
width: 100%;