NOBUG: Added missing call to require login to grade/edit/letter/index.php
[moodle.git] / mod / glossary / mod_form.php
CommitLineData
a02c77dc 1<?php
23a7718b 2require_once ($CFG->dirroot.'/course/moodleform_mod.php');
e24b7f85 3
f07b9627 4class mod_glossary_mod_form extends moodleform_mod {
a02c77dc 5
2ee60b49 6 function definition() {
c18269c7 7 global $CFG, $COURSE, $DB;
a02c77dc 8
2ee60b49 9 $mform =& $this->_form;
a02c77dc 10
11//-------------------------------------------------------------------------------
12 $mform->addElement('header', 'general', get_string('general', 'form'));
13
26de8d35 14 $mform->addElement('text', 'name', get_string('name'), array('size'=>'64'));
8eb1d25f 15 if (!empty($CFG->formatstringstriptags)) {
16 $mform->setType('name', PARAM_TEXT);
17 } else {
18 $mform->setType('name', PARAM_CLEAN);
19 }
2ee60b49 20 $mform->addRule('name', null, 'required', null, 'client');
a02c77dc 21
4ba2221a 22 $this->add_intro_editor(true);
a02c77dc 23
ed904dce 24 $mform->addElement('text', 'entbypage', get_string('entbypage', 'glossary'));
a02c77dc 25 $mform->setDefault('entbypage', 10);
ed904dce 26 $mform->addRule('entbypage', null, 'required', null, 'client');
27 $mform->addRule('entbypage', null, 'numeric', null, 'client');
a02c77dc 28
957f6fc9 29 if (has_capability('mod/glossary:manageentries', get_context_instance(CONTEXT_SYSTEM))) {
a02c77dc 30 $mform->addElement('checkbox', 'globalglossary', get_string('isglobal', 'glossary'));
31 $mform->setHelpButton('globalglossary', array('globalglossary', get_string('globalglossary', 'glossary'), 'glossary'));
32
33 }else{
34 $mform->addElement('hidden', 'globalglossary');
d18e0fe6 35 $mform->setType('globalglossary', PARAM_INT);
a02c77dc 36 }
37
38 $options = array(1=>get_string('mainglossary', 'glossary'), 0=>get_string('secondaryglossary', 'glossary'));
39 $mform->addElement('select', 'mainglossary', get_string('glossarytype', 'glossary'), $options);
a23f0aaf 40 $mform->setHelpButton('mainglossary', array('mainglossary', get_string('mainglossary', 'glossary'), 'glossary'));
a02c77dc 41 $mform->setDefault('mainglossary', 0);
42
62215411 43 $mform->addElement('selectyesno', 'allowduplicatedentries', get_string('allowduplicatedentries', 'glossary'));
a02c77dc 44 $mform->setDefault('allowduplicatedentries', $CFG->glossary_dupentries);
45 $mform->setHelpButton('allowduplicatedentries', array('allowduplicatedentries', get_string('allowduplicatedentries', 'glossary'), 'glossary'));
46
47 $mform->addElement('selectyesno', 'allowcomments', get_string('allowcomments', 'glossary'));
48 $mform->setDefault('allowcomments', $CFG->glossary_allowcomments);
49 $mform->setHelpButton('allowcomments', array('allowcomments', get_string('allowcomments', 'glossary'), 'glossary'));
50
51 $mform->addElement('selectyesno', 'allowprintview', get_string('allowprintview', 'glossary'));
52 $mform->setDefault('allowprintview', 1);
53 $mform->setHelpButton('allowprintview', array('allowprintview', get_string('allowprintview', 'glossary'), 'glossary'));
54
55 $mform->addElement('selectyesno', 'usedynalink', get_string('usedynalink', 'glossary'));
56 $mform->setDefault('usedynalink', $CFG->glossary_linkbydefault);
57 $mform->setHelpButton('usedynalink', array('usedynalink', get_string('usedynalink', 'glossary'), 'glossary'));
58
59 $mform->addElement('selectyesno', 'defaultapproval', get_string('defaultapproval', 'glossary'));
60 $mform->setDefault('defaultapproval', $CFG->glossary_defaultapproval);
61 $mform->setHelpButton('defaultapproval', array('defaultapproval', get_string('defaultapproval', 'glossary'), 'glossary'));
62
63 //get and update available formats
64 $recformats = glossary_get_available_formats();
65
66 $formats = array();
67
68 //Take names
69 foreach ($recformats as $format) {
70 $formats[$format->name] = get_string('displayformat'.$format->name, 'glossary');
71 }
72 //Sort it
73 asort($formats);
74 $mform->addElement('select', 'displayformat', get_string('displayformat', 'glossary'), $formats);
75 $mform->setDefault('displayformat', 'dictionary');
76 $mform->setHelpButton('displayformat', array('displayformat', get_string('displayformat', 'glossary'), 'glossary'));
77
78 $mform->addElement('selectyesno', 'showspecial', get_string('showspecial', 'glossary'));
79 $mform->setDefault('showspecial', 1);
80 $mform->setHelpButton('showspecial', array('shows', get_string('showspecial', 'glossary'), 'glossary'));
81
82 $mform->addElement('selectyesno', 'showalphabet', get_string('showalphabet', 'glossary'));
83 $mform->setDefault('showalphabet', 1);
84 $mform->setHelpButton('showalphabet', array('shows', get_string('showalphabet', 'glossary'), 'glossary'));
85
86 $mform->addElement('selectyesno', 'showall', get_string('showall', 'glossary'));
87 $mform->setDefault('showall', 1);
88 $mform->setHelpButton('showall', array('shows', get_string('showall', 'glossary'), 'glossary'));
89
90 $mform->addElement('selectyesno', 'editalways', get_string('editalways', 'glossary'));
91 $mform->setDefault('editalways', 0);
92 $mform->setHelpButton('editalways', array('editalways', get_string('editalways', 'glossary'), 'glossary'));
93
94 if ($CFG->enablerssfeeds && isset($CFG->glossary_enablerssfeeds) && $CFG->glossary_enablerssfeeds) {
95//-------------------------------------------------------------------------------
96 $mform->addElement('header', '', get_string('rss'));
97 $choices = array();
98 $choices[0] = get_string('none');
99 $choices[1] = get_string('withauthor', 'glossary');
100 $choices[2] = get_string('withoutauthor', 'glossary');
101 $mform->addElement('select', 'rsstype', get_string('rsstype'), $choices);
102 $mform->setHelpButton('rsstype', array('rsstype', get_string('rsstype'), 'glossary'));
103
104 $choices = array();
105 $choices[0] = '0';
106 $choices[1] = '1';
107 $choices[2] = '2';
108 $choices[3] = '3';
109 $choices[4] = '4';
110 $choices[5] = '5';
111 $choices[10] = '10';
112 $choices[15] = '15';
113 $choices[20] = '20';
114 $choices[25] = '25';
115 $choices[30] = '30';
116 $choices[40] = '40';
117 $choices[50] = '50';
118 $mform->addElement('select', 'rssarticles', get_string('rssarticles'), $choices);
119 $mform->setHelpButton('rssarticles', array('rssarticles', get_string('rssarticles'), 'glossary'));
e24b7f85 120 $mform->disabledIf('rssarticles', 'rsstype', 'eq', 0);
a02c77dc 121 }
122
123//-------------------------------------------------------------------------------
a09aeee4 124 /*$mform->addElement('header', '', get_string('grade'));
7a3d8c60 125 $mform->addElement('checkbox', 'userating', get_string('allowratings', 'glossary') , get_string('ratingsuse', 'glossary'));
126
127 $options=array();
9101efd3 128 $options[2] = get_string('ratingonlywithpermissions', 'glossary');
7a3d8c60 129 $options[1] = get_string('ratingeveryone', 'glossary');
130 $mform->addElement('select', 'assessed', get_string('users'), $options);
131 $mform->disabledIf('assessed', 'userating');
a02c77dc 132
133 $mform->addElement('modgrade', 'scale', get_string('grade'), false);
7a3d8c60 134 $mform->disabledIf('scale', 'userating');
135
136 $mform->addElement('checkbox', 'ratingtime', get_string('ratingtime', 'glossary'));
137 $mform->disabledIf('ratingtime', 'userating');
a02c77dc 138
139 $mform->addElement('date_time_selector', 'assesstimestart', get_string('from'));
7a3d8c60 140 $mform->disabledIf('assesstimestart', 'userating');
141 $mform->disabledIf('assesstimestart', 'ratingtime');
a02c77dc 142
143 $mform->addElement('date_time_selector', 'assesstimefinish', get_string('to'));
7a3d8c60 144 $mform->disabledIf('assesstimefinish', 'userating');
a09aeee4 145 $mform->disabledIf('assesstimefinish', 'ratingtime');*/
a02c77dc 146
147//-------------------------------------------------------------------------------
42f103be 148 $this->standard_coursemodule_elements();
a02c77dc 149
150//-------------------------------------------------------------------------------
a23f0aaf 151 // buttons
152 $this->add_action_buttons();
2ee60b49 153 }
a02c77dc 154
71ee4471 155 function definition_after_data() {
ae8c3566 156 global $COURSE, $DB;
157
71ee4471 158 parent::definition_after_data();
2ee60b49 159 $mform =& $this->_form;
a02c77dc 160 $mainglossaryel =& $mform->getElement('mainglossary');
ae8c3566 161 $mainglossary = $DB->get_record('glossary', array('mainglossary'=>1, 'course'=>$COURSE->id));
a02c77dc 162 if ($mainglossary && ($mainglossary->id != $mform->getElementValue('instance'))){
163 //secondary glossary, a main one already exists in this course.
164 $mainglossaryel->setValue(0);
165 $mainglossaryel->freeze();
166 $mainglossaryel->setPersistantFreeze(true);
167 } else {
168 $mainglossaryel->unfreeze();
169 $mainglossaryel->setPersistantFreeze(false);
170
171 }
2ee60b49 172 }
a02c77dc 173
63e21b9b 174 function data_preprocessing(&$default_values){
2ee60b49 175 }
e24b7f85 176
a02c77dc 177}
1adbd2c3 178