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