weekly release 2.3dev (blame stronk7 for 0202 mistake)
[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');
a02c77dc 32
957f6fc9 33 if (has_capability('mod/glossary:manageentries', get_context_instance(CONTEXT_SYSTEM))) {
a02c77dc 34 $mform->addElement('checkbox', 'globalglossary', get_string('isglobal', 'glossary'));
94c8a386 35 $mform->addHelpButton('globalglossary', 'isglobal', 'glossary');
a02c77dc 36
37 }else{
38 $mform->addElement('hidden', 'globalglossary');
d18e0fe6 39 $mform->setType('globalglossary', PARAM_INT);
a02c77dc 40 }
41
42 $options = array(1=>get_string('mainglossary', 'glossary'), 0=>get_string('secondaryglossary', 'glossary'));
43 $mform->addElement('select', 'mainglossary', get_string('glossarytype', 'glossary'), $options);
94c8a386 44 $mform->addHelpButton('mainglossary', 'glossarytype', 'glossary');
a02c77dc 45 $mform->setDefault('mainglossary', 0);
46
62215411 47 $mform->addElement('selectyesno', 'allowduplicatedentries', get_string('allowduplicatedentries', 'glossary'));
a02c77dc 48 $mform->setDefault('allowduplicatedentries', $CFG->glossary_dupentries);
94c8a386 49 $mform->addHelpButton('allowduplicatedentries', 'allowduplicatedentries', 'glossary');
a02c77dc 50
51 $mform->addElement('selectyesno', 'allowcomments', get_string('allowcomments', 'glossary'));
52 $mform->setDefault('allowcomments', $CFG->glossary_allowcomments);
94c8a386 53 $mform->addHelpButton('allowcomments', 'allowcomments', 'glossary');
a02c77dc 54
55 $mform->addElement('selectyesno', 'allowprintview', get_string('allowprintview', 'glossary'));
56 $mform->setDefault('allowprintview', 1);
94c8a386 57 $mform->addHelpButton('allowprintview', 'allowprintview', 'glossary');
a02c77dc 58
59 $mform->addElement('selectyesno', 'usedynalink', get_string('usedynalink', 'glossary'));
60 $mform->setDefault('usedynalink', $CFG->glossary_linkbydefault);
94c8a386 61 $mform->addHelpButton('usedynalink', 'usedynalink', 'glossary');
a02c77dc 62
63 $mform->addElement('selectyesno', 'defaultapproval', get_string('defaultapproval', 'glossary'));
64 $mform->setDefault('defaultapproval', $CFG->glossary_defaultapproval);
94c8a386 65 $mform->addHelpButton('defaultapproval', 'defaultapproval', 'glossary');
a02c77dc 66
67 //get and update available formats
68 $recformats = glossary_get_available_formats();
69
70 $formats = array();
71
72 //Take names
73 foreach ($recformats as $format) {
74 $formats[$format->name] = get_string('displayformat'.$format->name, 'glossary');
75 }
76 //Sort it
77 asort($formats);
78 $mform->addElement('select', 'displayformat', get_string('displayformat', 'glossary'), $formats);
79 $mform->setDefault('displayformat', 'dictionary');
94c8a386 80 $mform->addHelpButton('displayformat', 'displayformat', 'glossary');
a02c77dc 81
82 $mform->addElement('selectyesno', 'showspecial', get_string('showspecial', 'glossary'));
83 $mform->setDefault('showspecial', 1);
94c8a386 84 $mform->addHelpButton('showspecial', 'showspecial', 'glossary');
a02c77dc 85
86 $mform->addElement('selectyesno', 'showalphabet', get_string('showalphabet', 'glossary'));
87 $mform->setDefault('showalphabet', 1);
94c8a386 88 $mform->addHelpButton('showalphabet', 'showalphabet', 'glossary');
a02c77dc 89
90 $mform->addElement('selectyesno', 'showall', get_string('showall', 'glossary'));
91 $mform->setDefault('showall', 1);
94c8a386 92 $mform->addHelpButton('showall', 'showall', 'glossary');
a02c77dc 93
94 $mform->addElement('selectyesno', 'editalways', get_string('editalways', 'glossary'));
95 $mform->setDefault('editalways', 0);
94c8a386 96 $mform->addHelpButton('editalways', 'editalways', 'glossary');
a02c77dc 97
98 if ($CFG->enablerssfeeds && isset($CFG->glossary_enablerssfeeds) && $CFG->glossary_enablerssfeeds) {
99//-------------------------------------------------------------------------------
100 $mform->addElement('header', '', get_string('rss'));
101 $choices = array();
102 $choices[0] = get_string('none');
103 $choices[1] = get_string('withauthor', 'glossary');
104 $choices[2] = get_string('withoutauthor', 'glossary');
105 $mform->addElement('select', 'rsstype', get_string('rsstype'), $choices);
94c8a386 106 $mform->addHelpButton('rsstype', 'rsstype', 'glossary');
a02c77dc 107
108 $choices = array();
109 $choices[0] = '0';
110 $choices[1] = '1';
111 $choices[2] = '2';
112 $choices[3] = '3';
113 $choices[4] = '4';
114 $choices[5] = '5';
115 $choices[10] = '10';
116 $choices[15] = '15';
117 $choices[20] = '20';
118 $choices[25] = '25';
119 $choices[30] = '30';
120 $choices[40] = '40';
121 $choices[50] = '50';
122 $mform->addElement('select', 'rssarticles', get_string('rssarticles'), $choices);
94c8a386 123 $mform->addHelpButton('rssarticles', 'rssarticles', 'glossary');
e24b7f85 124 $mform->disabledIf('rssarticles', 'rsstype', 'eq', 0);
a02c77dc 125 }
126
127//-------------------------------------------------------------------------------
16306628
AD
128
129 $this->standard_grading_coursemodule_elements();
b8ea3041 130
42f103be 131 $this->standard_coursemodule_elements();
a02c77dc 132
133//-------------------------------------------------------------------------------
a23f0aaf 134 // buttons
135 $this->add_action_buttons();
2ee60b49 136 }
a02c77dc 137
71ee4471 138 function definition_after_data() {
ae8c3566 139 global $COURSE, $DB;
140
71ee4471 141 parent::definition_after_data();
2ee60b49 142 $mform =& $this->_form;
a02c77dc 143 $mainglossaryel =& $mform->getElement('mainglossary');
ae8c3566 144 $mainglossary = $DB->get_record('glossary', array('mainglossary'=>1, 'course'=>$COURSE->id));
a02c77dc 145 if ($mainglossary && ($mainglossary->id != $mform->getElementValue('instance'))){
146 //secondary glossary, a main one already exists in this course.
147 $mainglossaryel->setValue(0);
148 $mainglossaryel->freeze();
149 $mainglossaryel->setPersistantFreeze(true);
150 } else {
151 $mainglossaryel->unfreeze();
152 $mainglossaryel->setPersistantFreeze(false);
153
154 }
2ee60b49 155 }
a02c77dc 156
63e21b9b 157 function data_preprocessing(&$default_values){
55d95d90 158 parent::data_preprocessing($default_values);
dde5bfbc
EL
159
160 // Set up the completion checkboxes which aren't part of standard data.
161 // We also make the default value (if you turn on the checkbox) for those
162 // numbers to be 1, this will not apply unless checkbox is ticked.
163 $default_values['completionentriesenabled']=
164 !empty($default_values['completionentries']) ? 1 : 0;
165 if (empty($default_values['completionentries'])) {
166 $default_values['completionentries']=1;
167 }
168 }
169
170 function add_completion_rules() {
171 $mform =& $this->_form;
172
173 $group=array();
174 $group[] =& $mform->createElement('checkbox', 'completionentriesenabled', '', get_string('completionentries','glossary'));
175 $group[] =& $mform->createElement('text', 'completionentries', '', array('size'=>3));
176 $mform->setType('completionentries', PARAM_INT);
177 $mform->addGroup($group, 'completionentriesgroup', get_string('completionentriesgroup','glossary'), array(' '), false);
178 $mform->disabledIf('completionentries','completionentriesenabled','notchecked');
179
180 return array('completionentriesgroup');
181 }
182
183 function completion_rule_enabled($data) {
184 return (!empty($data['completionentriesenabled']) && $data['completionentries']!=0);
185 }
186
187 function get_data() {
188 $data = parent::get_data();
189 if (!$data) {
190 return false;
191 }
192 // Turn off completion settings if the checkboxes aren't ticked
193 $autocompletion = !empty($data->completion) && $data->completion==COMPLETION_TRACKING_AUTOMATIC;
194 if (empty($data->completionentriesenabled) || !$autocompletion) {
195 $data->completionentries = 0;
196 }
197 return $data;
2ee60b49 198 }
e24b7f85 199
a02c77dc 200}
1adbd2c3 201