Commit | Line | Data |
---|---|---|
a02c77dc | 1 | <?php |
bfebaf64 MD |
2 | if (!defined('MOODLE_INTERNAL')) { |
3 | die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page | |
4 | } | |
5 | ||
23a7718b | 6 | require_once ($CFG->dirroot.'/course/moodleform_mod.php'); |
e24b7f85 | 7 | |
f07b9627 | 8 | class 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 { | |
22 | $mform->setType('name', PARAM_CLEAN); | |
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 | //------------------------------------------------------------------------------- | |
37e3256a | 128 | |
42f103be | 129 | $this->standard_coursemodule_elements(); |
a02c77dc | 130 | |
131 | //------------------------------------------------------------------------------- | |
a23f0aaf | 132 | // buttons |
133 | $this->add_action_buttons(); | |
2ee60b49 | 134 | } |
a02c77dc | 135 | |
71ee4471 | 136 | function definition_after_data() { |
ae8c3566 | 137 | global $COURSE, $DB; |
138 | ||
71ee4471 | 139 | parent::definition_after_data(); |
2ee60b49 | 140 | $mform =& $this->_form; |
a02c77dc | 141 | $mainglossaryel =& $mform->getElement('mainglossary'); |
ae8c3566 | 142 | $mainglossary = $DB->get_record('glossary', array('mainglossary'=>1, 'course'=>$COURSE->id)); |
a02c77dc | 143 | if ($mainglossary && ($mainglossary->id != $mform->getElementValue('instance'))){ |
144 | //secondary glossary, a main one already exists in this course. | |
145 | $mainglossaryel->setValue(0); | |
146 | $mainglossaryel->freeze(); | |
147 | $mainglossaryel->setPersistantFreeze(true); | |
148 | } else { | |
149 | $mainglossaryel->unfreeze(); | |
150 | $mainglossaryel->setPersistantFreeze(false); | |
151 | ||
152 | } | |
2ee60b49 | 153 | } |
a02c77dc | 154 | |
63e21b9b | 155 | function data_preprocessing(&$default_values){ |
55d95d90 | 156 | parent::data_preprocessing($default_values); |
2ee60b49 | 157 | } |
e24b7f85 | 158 | |
a02c77dc | 159 | } |
1adbd2c3 | 160 |