MDL-38712 mod_glossary: fix missing PARAM type
[moodle.git] / mod / glossary / mod_form.php
CommitLineData
a02c77dc 1<?php
bfebaf64
MD
2if (!defined('MOODLE_INTERNAL')) {
3 die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
4}
5
23a7718b 6require_once ($CFG->dirroot.'/course/moodleform_mod.php');
e24b7f85 7
f07b9627 8class mod_glossary_mod_form extends moodleform_mod {
a02c77dc 9
2ee60b49 10 function definition() {
c18269c7 11 global $CFG, $COURSE, $DB;
a02c77dc 12
2ee60b49 13 $mform =& $this->_form;
a02c77dc 14
15//-------------------------------------------------------------------------------
16 $mform->addElement('header', 'general', get_string('general', 'form'));
17
26de8d35 18 $mform->addElement('text', 'name', get_string('name'), array('size'=>'64'));
8eb1d25f 19 if (!empty($CFG->formatstringstriptags)) {
20 $mform->setType('name', PARAM_TEXT);
21 } else {
b8ea3041 22 $mform->setType('name', PARAM_CLEANHTML);
8eb1d25f 23 }
2ee60b49 24 $mform->addRule('name', null, 'required', null, 'client');
a02c77dc 25
4ba2221a 26 $this->add_intro_editor(true);
a02c77dc 27
ed904dce 28 $mform->addElement('text', 'entbypage', get_string('entbypage', 'glossary'));
a02c77dc 29 $mform->setDefault('entbypage', 10);
ed904dce 30 $mform->addRule('entbypage', null, 'required', null, 'client');
31 $mform->addRule('entbypage', null, 'numeric', null, 'client');
1f0cd6ee 32 $mform->setType('entbypage', PARAM_INT);
a02c77dc 33
e0a91e11 34 if (has_capability('mod/glossary:manageentries', context_system::instance())) {
a02c77dc 35 $mform->addElement('checkbox', 'globalglossary', get_string('isglobal', 'glossary'));
94c8a386 36 $mform->addHelpButton('globalglossary', 'isglobal', 'glossary');
a02c77dc 37
38 }else{
39 $mform->addElement('hidden', 'globalglossary');
d18e0fe6 40 $mform->setType('globalglossary', PARAM_INT);
a02c77dc 41 }
42
43 $options = array(1=>get_string('mainglossary', 'glossary'), 0=>get_string('secondaryglossary', 'glossary'));
44 $mform->addElement('select', 'mainglossary', get_string('glossarytype', 'glossary'), $options);
94c8a386 45 $mform->addHelpButton('mainglossary', 'glossarytype', 'glossary');
a02c77dc 46 $mform->setDefault('mainglossary', 0);
47
62215411 48 $mform->addElement('selectyesno', 'allowduplicatedentries', get_string('allowduplicatedentries', 'glossary'));
a02c77dc 49 $mform->setDefault('allowduplicatedentries', $CFG->glossary_dupentries);
94c8a386 50 $mform->addHelpButton('allowduplicatedentries', 'allowduplicatedentries', 'glossary');
a02c77dc 51
52 $mform->addElement('selectyesno', 'allowcomments', get_string('allowcomments', 'glossary'));
53 $mform->setDefault('allowcomments', $CFG->glossary_allowcomments);
94c8a386 54 $mform->addHelpButton('allowcomments', 'allowcomments', 'glossary');
a02c77dc 55
56 $mform->addElement('selectyesno', 'allowprintview', get_string('allowprintview', 'glossary'));
57 $mform->setDefault('allowprintview', 1);
94c8a386 58 $mform->addHelpButton('allowprintview', 'allowprintview', 'glossary');
a02c77dc 59
60 $mform->addElement('selectyesno', 'usedynalink', get_string('usedynalink', 'glossary'));
61 $mform->setDefault('usedynalink', $CFG->glossary_linkbydefault);
94c8a386 62 $mform->addHelpButton('usedynalink', 'usedynalink', 'glossary');
a02c77dc 63
64 $mform->addElement('selectyesno', 'defaultapproval', get_string('defaultapproval', 'glossary'));
65 $mform->setDefault('defaultapproval', $CFG->glossary_defaultapproval);
94c8a386 66 $mform->addHelpButton('defaultapproval', 'defaultapproval', 'glossary');
a02c77dc 67
68 //get and update available formats
69 $recformats = glossary_get_available_formats();
70
71 $formats = array();
72
73 //Take names
74 foreach ($recformats as $format) {
75 $formats[$format->name] = get_string('displayformat'.$format->name, 'glossary');
76 }
77 //Sort it
78 asort($formats);
79 $mform->addElement('select', 'displayformat', get_string('displayformat', 'glossary'), $formats);
80 $mform->setDefault('displayformat', 'dictionary');
94c8a386 81 $mform->addHelpButton('displayformat', 'displayformat', 'glossary');
a02c77dc 82
c042fc81
ARN
83 $displayformats['default'] = get_string('displayformatdefault', 'glossary');
84 $displayformats = array_merge($displayformats, $formats);
85 $mform->addElement('select', 'approvaldisplayformat', get_string('approvaldisplayformat', 'glossary'), $displayformats);
86 $mform->setDefault('approvaldisplayformat', 'default');
87 $mform->addHelpButton('approvaldisplayformat', 'approvaldisplayformat', 'glossary');
88
a02c77dc 89 $mform->addElement('selectyesno', 'showspecial', get_string('showspecial', 'glossary'));
90 $mform->setDefault('showspecial', 1);
94c8a386 91 $mform->addHelpButton('showspecial', 'showspecial', 'glossary');
a02c77dc 92
93 $mform->addElement('selectyesno', 'showalphabet', get_string('showalphabet', 'glossary'));
94 $mform->setDefault('showalphabet', 1);
94c8a386 95 $mform->addHelpButton('showalphabet', 'showalphabet', 'glossary');
a02c77dc 96
97 $mform->addElement('selectyesno', 'showall', get_string('showall', 'glossary'));
98 $mform->setDefault('showall', 1);
94c8a386 99 $mform->addHelpButton('showall', 'showall', 'glossary');
a02c77dc 100
101 $mform->addElement('selectyesno', 'editalways', get_string('editalways', 'glossary'));
102 $mform->setDefault('editalways', 0);
94c8a386 103 $mform->addHelpButton('editalways', 'editalways', 'glossary');
a02c77dc 104
105 if ($CFG->enablerssfeeds && isset($CFG->glossary_enablerssfeeds) && $CFG->glossary_enablerssfeeds) {
106//-------------------------------------------------------------------------------
807cf3d0 107 $mform->addElement('header', 'rssheader', get_string('rss'));
a02c77dc 108 $choices = array();
109 $choices[0] = get_string('none');
110 $choices[1] = get_string('withauthor', 'glossary');
111 $choices[2] = get_string('withoutauthor', 'glossary');
112 $mform->addElement('select', 'rsstype', get_string('rsstype'), $choices);
94c8a386 113 $mform->addHelpButton('rsstype', 'rsstype', 'glossary');
a02c77dc 114
115 $choices = array();
116 $choices[0] = '0';
117 $choices[1] = '1';
118 $choices[2] = '2';
119 $choices[3] = '3';
120 $choices[4] = '4';
121 $choices[5] = '5';
122 $choices[10] = '10';
123 $choices[15] = '15';
124 $choices[20] = '20';
125 $choices[25] = '25';
126 $choices[30] = '30';
127 $choices[40] = '40';
128 $choices[50] = '50';
129 $mform->addElement('select', 'rssarticles', get_string('rssarticles'), $choices);
94c8a386 130 $mform->addHelpButton('rssarticles', 'rssarticles', 'glossary');
e24b7f85 131 $mform->disabledIf('rssarticles', 'rsstype', 'eq', 0);
a02c77dc 132 }
133
134//-------------------------------------------------------------------------------
16306628
AD
135
136 $this->standard_grading_coursemodule_elements();
b8ea3041 137
42f103be 138 $this->standard_coursemodule_elements();
a02c77dc 139
140//-------------------------------------------------------------------------------
a23f0aaf 141 // buttons
142 $this->add_action_buttons();
2ee60b49 143 }
a02c77dc 144
71ee4471 145 function definition_after_data() {
ae8c3566 146 global $COURSE, $DB;
147
71ee4471 148 parent::definition_after_data();
2ee60b49 149 $mform =& $this->_form;
a02c77dc 150 $mainglossaryel =& $mform->getElement('mainglossary');
ae8c3566 151 $mainglossary = $DB->get_record('glossary', array('mainglossary'=>1, 'course'=>$COURSE->id));
a02c77dc 152 if ($mainglossary && ($mainglossary->id != $mform->getElementValue('instance'))){
153 //secondary glossary, a main one already exists in this course.
154 $mainglossaryel->setValue(0);
155 $mainglossaryel->freeze();
156 $mainglossaryel->setPersistantFreeze(true);
157 } else {
158 $mainglossaryel->unfreeze();
159 $mainglossaryel->setPersistantFreeze(false);
160
161 }
2ee60b49 162 }
a02c77dc 163
63e21b9b 164 function data_preprocessing(&$default_values){
55d95d90 165 parent::data_preprocessing($default_values);
dde5bfbc
EL
166
167 // Set up the completion checkboxes which aren't part of standard data.
168 // We also make the default value (if you turn on the checkbox) for those
169 // numbers to be 1, this will not apply unless checkbox is ticked.
170 $default_values['completionentriesenabled']=
171 !empty($default_values['completionentries']) ? 1 : 0;
172 if (empty($default_values['completionentries'])) {
173 $default_values['completionentries']=1;
174 }
175 }
176
177 function add_completion_rules() {
178 $mform =& $this->_form;
179
180 $group=array();
181 $group[] =& $mform->createElement('checkbox', 'completionentriesenabled', '', get_string('completionentries','glossary'));
182 $group[] =& $mform->createElement('text', 'completionentries', '', array('size'=>3));
183 $mform->setType('completionentries', PARAM_INT);
184 $mform->addGroup($group, 'completionentriesgroup', get_string('completionentriesgroup','glossary'), array(' '), false);
185 $mform->disabledIf('completionentries','completionentriesenabled','notchecked');
186
187 return array('completionentriesgroup');
188 }
189
190 function completion_rule_enabled($data) {
191 return (!empty($data['completionentriesenabled']) && $data['completionentries']!=0);
192 }
193
194 function get_data() {
195 $data = parent::get_data();
196 if (!$data) {
197 return false;
198 }
199 // Turn off completion settings if the checkboxes aren't ticked
200 $autocompletion = !empty($data->completion) && $data->completion==COMPLETION_TRACKING_AUTOMATIC;
201 if (empty($data->completionentriesenabled) || !$autocompletion) {
202 $data->completionentries = 0;
203 }
204 return $data;
2ee60b49 205 }
e24b7f85 206
a02c77dc 207}
1adbd2c3 208