2 if (!defined('MOODLE_INTERNAL')) {
3 die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
6 require_once ($CFG->dirroot.'/course/moodleform_mod.php');
8 class mod_glossary_mod_form extends moodleform_mod {
10 function definition() {
11 global $CFG, $COURSE, $DB;
13 $mform =& $this->_form;
15 //-------------------------------------------------------------------------------
16 $mform->addElement('header', 'general', get_string('general', 'form'));
18 $mform->addElement('text', 'name', get_string('name'), array('size'=>'64'));
19 if (!empty($CFG->formatstringstriptags)) {
20 $mform->setType('name', PARAM_TEXT);
22 $mform->setType('name', PARAM_CLEANHTML);
24 $mform->addRule('name', null, 'required', null, 'client');
26 $this->add_intro_editor(true);
28 $mform->addElement('text', 'entbypage', get_string('entbypage', 'glossary'));
29 $mform->setDefault('entbypage', 10);
30 $mform->addRule('entbypage', null, 'required', null, 'client');
31 $mform->addRule('entbypage', null, 'numeric', null, 'client');
32 $mform->setType('entbypage', PARAM_INT);
34 if (has_capability('mod/glossary:manageentries', context_system::instance())) {
35 $mform->addElement('checkbox', 'globalglossary', get_string('isglobal', 'glossary'));
36 $mform->addHelpButton('globalglossary', 'isglobal', 'glossary');
39 $mform->addElement('hidden', 'globalglossary');
40 $mform->setType('globalglossary', PARAM_INT);
43 $options = array(1=>get_string('mainglossary', 'glossary'), 0=>get_string('secondaryglossary', 'glossary'));
44 $mform->addElement('select', 'mainglossary', get_string('glossarytype', 'glossary'), $options);
45 $mform->addHelpButton('mainglossary', 'glossarytype', 'glossary');
46 $mform->setDefault('mainglossary', 0);
48 $mform->addElement('selectyesno', 'allowduplicatedentries', get_string('allowduplicatedentries', 'glossary'));
49 $mform->setDefault('allowduplicatedentries', $CFG->glossary_dupentries);
50 $mform->addHelpButton('allowduplicatedentries', 'allowduplicatedentries', 'glossary');
52 $mform->addElement('selectyesno', 'allowcomments', get_string('allowcomments', 'glossary'));
53 $mform->setDefault('allowcomments', $CFG->glossary_allowcomments);
54 $mform->addHelpButton('allowcomments', 'allowcomments', 'glossary');
56 $mform->addElement('selectyesno', 'allowprintview', get_string('allowprintview', 'glossary'));
57 $mform->setDefault('allowprintview', 1);
58 $mform->addHelpButton('allowprintview', 'allowprintview', 'glossary');
60 $mform->addElement('selectyesno', 'usedynalink', get_string('usedynalink', 'glossary'));
61 $mform->setDefault('usedynalink', $CFG->glossary_linkbydefault);
62 $mform->addHelpButton('usedynalink', 'usedynalink', 'glossary');
64 $mform->addElement('selectyesno', 'defaultapproval', get_string('defaultapproval', 'glossary'));
65 $mform->setDefault('defaultapproval', $CFG->glossary_defaultapproval);
66 $mform->addHelpButton('defaultapproval', 'defaultapproval', 'glossary');
68 //get and update available formats
69 $recformats = glossary_get_available_formats();
74 foreach ($recformats as $format) {
75 $formats[$format->name] = get_string('displayformat'.$format->name, 'glossary');
79 $mform->addElement('select', 'displayformat', get_string('displayformat', 'glossary'), $formats);
80 $mform->setDefault('displayformat', 'dictionary');
81 $mform->addHelpButton('displayformat', 'displayformat', 'glossary');
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');
89 $mform->addElement('selectyesno', 'showspecial', get_string('showspecial', 'glossary'));
90 $mform->setDefault('showspecial', 1);
91 $mform->addHelpButton('showspecial', 'showspecial', 'glossary');
93 $mform->addElement('selectyesno', 'showalphabet', get_string('showalphabet', 'glossary'));
94 $mform->setDefault('showalphabet', 1);
95 $mform->addHelpButton('showalphabet', 'showalphabet', 'glossary');
97 $mform->addElement('selectyesno', 'showall', get_string('showall', 'glossary'));
98 $mform->setDefault('showall', 1);
99 $mform->addHelpButton('showall', 'showall', 'glossary');
101 $mform->addElement('selectyesno', 'editalways', get_string('editalways', 'glossary'));
102 $mform->setDefault('editalways', 0);
103 $mform->addHelpButton('editalways', 'editalways', 'glossary');
105 if ($CFG->enablerssfeeds && isset($CFG->glossary_enablerssfeeds) && $CFG->glossary_enablerssfeeds) {
106 //-------------------------------------------------------------------------------
107 $mform->addElement('header', 'rssheader', get_string('rss'));
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);
113 $mform->addHelpButton('rsstype', 'rsstype', 'glossary');
129 $mform->addElement('select', 'rssarticles', get_string('rssarticles'), $choices);
130 $mform->addHelpButton('rssarticles', 'rssarticles', 'glossary');
131 $mform->disabledIf('rssarticles', 'rsstype', 'eq', 0);
134 //-------------------------------------------------------------------------------
136 $this->standard_grading_coursemodule_elements();
138 $this->standard_coursemodule_elements();
140 //-------------------------------------------------------------------------------
142 $this->add_action_buttons();
145 function definition_after_data() {
148 parent::definition_after_data();
149 $mform =& $this->_form;
150 $mainglossaryel =& $mform->getElement('mainglossary');
151 $mainglossary = $DB->get_record('glossary', array('mainglossary'=>1, 'course'=>$COURSE->id));
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);
158 $mainglossaryel->unfreeze();
159 $mainglossaryel->setPersistantFreeze(false);
164 function data_preprocessing(&$default_values){
165 parent::data_preprocessing($default_values);
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;
177 function add_completion_rules() {
178 $mform =& $this->_form;
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');
187 return array('completionentriesgroup');
190 function completion_rule_enabled($data) {
191 return (!empty($data['completionentriesenabled']) && $data['completionentries']!=0);
194 function get_data() {
195 $data = parent::get_data();
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;