prevent backslashes being inserted before #-sign in HTML entities by converting html...
[moodle.git] / question / type / edit_question_form.php
CommitLineData
36703ed7 1<?php
2/**
3 * A base class for question editing forms.
4 *
5 * @copyright &copy; 2006 The Open University
6 * @author T.J.Hunt@open.ac.uk
7 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
8 * @package quiz
9 *//** */
10
11/**
12 * Form definition base class. This defines the common fields that
13 * all question types need. Question types should define their own
14 * class that inherits from this one, and implements the definition_inner()
15 * method.
16 */
1d284fbd 17class question_edit_form extends moodleform {
36703ed7 18 /**
19 * Build the form definition.
1d284fbd 20 *
21 * This adds all the form files that the default question type supports.
36703ed7 22 * If your question type does not support all these fields, then you can
23 * override this method and remove the ones you don't want with $mform->removeElement().
24 */
25 function definition() {
26 global $COURSE;
1d284fbd 27
36703ed7 28 $qtype = $this->qtype();
29 $langfile = "qtype_$qtype";
1d284fbd 30
36703ed7 31 $mform =& $this->_form;
32 $renderer =& $mform->defaultRenderer();
33
34 // Standard fields at the start of the form.
35 $mform->addElement('header', 'formheader', get_string("editing$qtype", $langfile));
36 $mform->setHelpButton('formheader', array($qtype, get_string($qtype, $qtype), $qtype));
1d284fbd 37
36703ed7 38 $mform->addElement('questioncategory', 'category', get_string('category', 'quiz'),
39 array('courseid' => $COURSE->id, 'published' => true, 'only_editable' => true));
1d284fbd 40
36703ed7 41 $mform->addElement('text', 'name', get_string('questionname', 'quiz'),
42 array('size' => 50));
43 $mform->setType('name', PARAM_MULTILANG);
44 $mform->addRule('name', null, 'required', null, 'client');
1d284fbd 45
36703ed7 46 $mform->addElement('htmleditor', 'questiontext', get_string('questiontext', 'quiz'),
47 array('rows' => 15, 'course' => $COURSE->id));
48 $mform->setType('questiontext', PARAM_RAW);
49 $mform->setHelpButton('questiontext', array('questiontext', get_string('questiontext', 'quiz'), 'quiz'));
50 $mform->addElement('format', 'questiontextformat', get_string('format'));
51
52 if (empty($images)) {
53 $mform->addElement('static', 'image', get_string('imagedisplay', 'quiz'), get_string('noimagesyet'));
54 } else {
55 $images[''] = get_string('none');
56 $mform->addElement('select', 'image', get_string('imagedisplay', 'quiz'), $images);
57 $mform->setType('image', PARAM_FILE);
58 }
1d284fbd 59
36703ed7 60 $mform->addElement('text', 'defaultgrade', get_string('defaultgrade', 'quiz'),
61 array('size' => 3));
62 $mform->setType('defaultgrade', PARAM_INT);
63 $mform->addRule('defaultgrade', null, 'required', null, 'client');
64
65 $mform->addElement('text', 'penalty', get_string('penaltyfactor', 'quiz'),
66 array('size' => 3));
67 $mform->setType('penalty', PARAM_NUMBER);
68 $mform->addRule('penalty', null, 'required', null, 'client');
69 $mform->setHelpButton('penalty', array('penalty', get_string('penalty', 'quiz'), 'quiz'));
70
71 $mform->addElement('htmleditor', 'generalfeedback', get_string('generalfeedback', 'quiz'),
72 array('rows' => 10, 'course' => $COURSE->id));
73 $mform->setType('generalfeedback', PARAM_RAW);
74 $mform->setHelpButton('generalfeedback', array('generalfeedback', get_string('generalfeedback', 'quiz'), 'quiz'));
1d284fbd 75
36703ed7 76 // Any questiontype specific fields.
77 $this->definition_inner($mform);
78
79 // Standard fields at the end of the form.
80 $mform->addElement('hidden', 'id');
81 $mform->setType('id', PARAM_INT);
82
83 $mform->addElement('hidden', 'qtype');
84 $mform->setType('qtype', PARAM_ALPHA);
85
86 $mform->addElement('hidden', 'inpopup');
87 $mform->setType('inpopup', PARAM_INT);
88
89 $mform->addElement('hidden', 'versioning');
90 $mform->setType('versioning', PARAM_BOOL);
91
92 $buttonarray = array();
93 $buttonarray[] = &$mform->createElement('submit', 'submitbutton', get_string('savechanges'));
94 if (!empty($id)) {
95 $buttonarray[] = &$mform->createElement('submit', 'makecopy', get_string('makecopy', 'quiz'));
96 }
97 $buttonarray[] = &$mform->createElement('reset', 'resetbutton', get_string('revert'));
98 $buttonarray[] = &$mform->createElement('cancel');
99 $mform->addGroup($buttonarray, 'buttonar', '', array(' '), false);
100 $renderer->addStopFieldsetElements('buttonar');
101 }
1d284fbd 102
36703ed7 103 /**
104 * Add any question-type specific form fields.
1d284fbd 105 *
106 * @param object $mform the form being built.
36703ed7 107 */
108 function definition_inner(&$mform) {
109 // By default, do nothing.
110 }
1d284fbd 111
36703ed7 112 function set_defaults($question) {
113 global $QTYPES;
114 $QTYPES[$question->qtype]->set_default_options($question);
115 parent::set_defaults($question);
116 }
1d284fbd 117
36703ed7 118 /**
119 * Override this in the subclass to question type name.
120 * @return the question type name, should be the same as the name() method in the question type class.
121 */
122 function qtype() {
123 return '';
124 }
125}
126
127?>