glossary form migrated to formslib
[moodle.git] / mod / glossary / mod_form.php
CommitLineData
a02c77dc 1<?php
2require_once ($CFG->libdir.'/formslib.php');
3class glossary_mod_form extends moodleform_mod {
4
5 function definition() {
6
7 global $CFG;
8 $mform =& $this->_form;
9 $renderer =& $mform->defaultRenderer();
10
11//-------------------------------------------------------------------------------
12 $mform->addElement('header', 'general', get_string('general', 'form'));
13
14 $mform->addElement('text', 'name', get_string('name'));
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');
21
22 $options=array();
23 $options=array_combine(range(1,10), range(1,10))+//keys, values, step=1
24 array_combine(range(15,100, 5), range(15,100, 5)) ;
25 $mform->addElement('select', 'entbypage', get_string('entbypage', 'glossary'), $options);
26 $mform->setDefault('entbypage', 10);
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);
38 $mform->setHelpButton('mainglossary', array('mainglossary', get_string('mainglossary', 'glossary'), 'glossary'));$mform->setDefault('allowduplicatedentries', $CFG->glossary_dupentries);
39 $mform->setDefault('mainglossary', 0);
40
41 $mform->addElement('selectyesno', 'allowduplicatedentries', get_string('allowduplicatedentries', 'glossary'), $options);
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'));
118 }
119
120//-------------------------------------------------------------------------------
121 $mform->addElement('header', '', get_string('grade'));
122 $mform->addElement('checkbox', 'assessed', get_string('allowratings', 'glossary') , get_string('ratingsuse', 'glossary'));
123
124 $mform->addElement('modgrade', 'scale', get_string('grade'), false);
125
126 $mform->addElement('date_time_selector', 'assesstimestart', get_string('from'));
127
128 $mform->addElement('date_time_selector', 'assesstimefinish', get_string('to'));
129
130//-------------------------------------------------------------------------------
131 $this->standard_coursemodule_elements();
132
133//-------------------------------------------------------------------------------
134 $buttonarray=array();
135 $buttonarray[] = &MoodleQuickForm::createElement('submit', 'submit', get_string('savechanges'));
136 $buttonarray[] = &MoodleQuickForm::createElement('submit', 'cancel', get_string('cancel'));
137 $mform->addGroup($buttonarray, 'buttonar', '', array(' '), false);
138 $renderer->addStopFieldsetElements('buttonar');
139 }
140
141 function definition_after_data(){
142 global $COURSE;
143 $mform =& $this->_form;
144 $mainglossaryel =& $mform->getElement('mainglossary');
145 $mainglossary = get_record('glossary', 'mainglossary', 1, 'course', $COURSE->id);
146 if ($mainglossary && ($mainglossary->id != $mform->getElementValue('instance'))){
147 //secondary glossary, a main one already exists in this course.
148 $mainglossaryel->setValue(0);
149 $mainglossaryel->freeze();
150 $mainglossaryel->setPersistantFreeze(true);
151 } else {
152 $mainglossaryel->unfreeze();
153 $mainglossaryel->setPersistantFreeze(false);
154
155 }
156 }
157
158
159
160}
161?>