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');
33 if (has_capability('mod/glossary:manageentries', context_system::instance())) {
34 $mform->addElement('checkbox', 'globalglossary', get_string('isglobal', 'glossary'));
35 $mform->addHelpButton('globalglossary', 'isglobal', 'glossary');
38 $mform->addElement('hidden', 'globalglossary');
39 $mform->setType('globalglossary', PARAM_INT);
42 $options = array(1=>get_string('mainglossary', 'glossary'), 0=>get_string('secondaryglossary', 'glossary'));
43 $mform->addElement('select', 'mainglossary', get_string('glossarytype', 'glossary'), $options);
44 $mform->addHelpButton('mainglossary', 'glossarytype', 'glossary');
45 $mform->setDefault('mainglossary', 0);
47 $mform->addElement('selectyesno', 'allowduplicatedentries', get_string('allowduplicatedentries', 'glossary'));
48 $mform->setDefault('allowduplicatedentries', $CFG->glossary_dupentries);
49 $mform->addHelpButton('allowduplicatedentries', 'allowduplicatedentries', 'glossary');
51 $mform->addElement('selectyesno', 'allowcomments', get_string('allowcomments', 'glossary'));
52 $mform->setDefault('allowcomments', $CFG->glossary_allowcomments);
53 $mform->addHelpButton('allowcomments', 'allowcomments', 'glossary');
55 $mform->addElement('selectyesno', 'allowprintview', get_string('allowprintview', 'glossary'));
56 $mform->setDefault('allowprintview', 1);
57 $mform->addHelpButton('allowprintview', 'allowprintview', 'glossary');
59 $mform->addElement('selectyesno', 'usedynalink', get_string('usedynalink', 'glossary'));
60 $mform->setDefault('usedynalink', $CFG->glossary_linkbydefault);
61 $mform->addHelpButton('usedynalink', 'usedynalink', 'glossary');
63 $mform->addElement('selectyesno', 'defaultapproval', get_string('defaultapproval', 'glossary'));
64 $mform->setDefault('defaultapproval', $CFG->glossary_defaultapproval);
65 $mform->addHelpButton('defaultapproval', 'defaultapproval', 'glossary');
67 //get and update available formats
68 $recformats = glossary_get_available_formats();
73 foreach ($recformats as $format) {
74 $formats[$format->name] = get_string('displayformat'.$format->name, 'glossary');
78 $mform->addElement('select', 'displayformat', get_string('displayformat', 'glossary'), $formats);
79 $mform->setDefault('displayformat', 'dictionary');
80 $mform->addHelpButton('displayformat', 'displayformat', 'glossary');
82 $displayformats['default'] = get_string('displayformatdefault', 'glossary');
83 $displayformats = array_merge($displayformats, $formats);
84 $mform->addElement('select', 'approvaldisplayformat', get_string('approvaldisplayformat', 'glossary'), $displayformats);
85 $mform->setDefault('approvaldisplayformat', 'default');
86 $mform->addHelpButton('approvaldisplayformat', 'approvaldisplayformat', 'glossary');
88 $mform->addElement('selectyesno', 'showspecial', get_string('showspecial', 'glossary'));
89 $mform->setDefault('showspecial', 1);
90 $mform->addHelpButton('showspecial', 'showspecial', 'glossary');
92 $mform->addElement('selectyesno', 'showalphabet', get_string('showalphabet', 'glossary'));
93 $mform->setDefault('showalphabet', 1);
94 $mform->addHelpButton('showalphabet', 'showalphabet', 'glossary');
96 $mform->addElement('selectyesno', 'showall', get_string('showall', 'glossary'));
97 $mform->setDefault('showall', 1);
98 $mform->addHelpButton('showall', 'showall', 'glossary');
100 $mform->addElement('selectyesno', 'editalways', get_string('editalways', 'glossary'));
101 $mform->setDefault('editalways', 0);
102 $mform->addHelpButton('editalways', 'editalways', 'glossary');
104 if ($CFG->enablerssfeeds && isset($CFG->glossary_enablerssfeeds) && $CFG->glossary_enablerssfeeds) {
105 //-------------------------------------------------------------------------------
106 $mform->addElement('header', 'rssheader', get_string('rss'));
108 $choices[0] = get_string('none');
109 $choices[1] = get_string('withauthor', 'glossary');
110 $choices[2] = get_string('withoutauthor', 'glossary');
111 $mform->addElement('select', 'rsstype', get_string('rsstype'), $choices);
112 $mform->addHelpButton('rsstype', 'rsstype', 'glossary');
128 $mform->addElement('select', 'rssarticles', get_string('rssarticles'), $choices);
129 $mform->addHelpButton('rssarticles', 'rssarticles', 'glossary');
130 $mform->disabledIf('rssarticles', 'rsstype', 'eq', 0);
133 //-------------------------------------------------------------------------------
135 $this->standard_grading_coursemodule_elements();
137 $this->standard_coursemodule_elements();
139 //-------------------------------------------------------------------------------
141 $this->add_action_buttons();
144 function definition_after_data() {
147 parent::definition_after_data();
148 $mform =& $this->_form;
149 $mainglossaryel =& $mform->getElement('mainglossary');
150 $mainglossary = $DB->get_record('glossary', array('mainglossary'=>1, 'course'=>$COURSE->id));
151 if ($mainglossary && ($mainglossary->id != $mform->getElementValue('instance'))){
152 //secondary glossary, a main one already exists in this course.
153 $mainglossaryel->setValue(0);
154 $mainglossaryel->freeze();
155 $mainglossaryel->setPersistantFreeze(true);
157 $mainglossaryel->unfreeze();
158 $mainglossaryel->setPersistantFreeze(false);
163 function data_preprocessing(&$default_values){
164 parent::data_preprocessing($default_values);
166 // Set up the completion checkboxes which aren't part of standard data.
167 // We also make the default value (if you turn on the checkbox) for those
168 // numbers to be 1, this will not apply unless checkbox is ticked.
169 $default_values['completionentriesenabled']=
170 !empty($default_values['completionentries']) ? 1 : 0;
171 if (empty($default_values['completionentries'])) {
172 $default_values['completionentries']=1;
176 function add_completion_rules() {
177 $mform =& $this->_form;
180 $group[] =& $mform->createElement('checkbox', 'completionentriesenabled', '', get_string('completionentries','glossary'));
181 $group[] =& $mform->createElement('text', 'completionentries', '', array('size'=>3));
182 $mform->setType('completionentries', PARAM_INT);
183 $mform->addGroup($group, 'completionentriesgroup', get_string('completionentriesgroup','glossary'), array(' '), false);
184 $mform->disabledIf('completionentries','completionentriesenabled','notchecked');
186 return array('completionentriesgroup');
189 function completion_rule_enabled($data) {
190 return (!empty($data['completionentriesenabled']) && $data['completionentries']!=0);
193 function get_data() {
194 $data = parent::get_data();
198 // Turn off completion settings if the checkboxes aren't ticked
199 $autocompletion = !empty($data->completion) && $data->completion==COMPLETION_TRACKING_AUTOMATIC;
200 if (empty($data->completionentriesenabled) || !$autocompletion) {
201 $data->completionentries = 0;