glossary MDL-23373 removed commented out code
[moodle.git] / mod / glossary / mod_form.php
1 <?php
2 if (!defined('MOODLE_INTERNAL')) {
3     die('Direct access to this script is forbidden.');    ///  It must be included from a Moodle page
4 }
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);
21         } else {
22             $mform->setType('name', PARAM_CLEAN);
23         }
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', get_context_instance(CONTEXT_SYSTEM))) {
34             $mform->addElement('checkbox', 'globalglossary', get_string('isglobal', 'glossary'));
35             $mform->addHelpButton('globalglossary', 'isglobal', 'glossary');
37         }else{
38             $mform->addElement('hidden', 'globalglossary');
39             $mform->setType('globalglossary', PARAM_INT);
40         }
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();
70         $formats = array();
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');
80         $mform->addHelpButton('displayformat', 'displayformat', 'glossary');
82         $mform->addElement('selectyesno', 'showspecial', get_string('showspecial', 'glossary'));
83         $mform->setDefault('showspecial', 1);
84         $mform->addHelpButton('showspecial', 'showspecial', 'glossary');
86         $mform->addElement('selectyesno', 'showalphabet', get_string('showalphabet', 'glossary'));
87         $mform->setDefault('showalphabet', 1);
88         $mform->addHelpButton('showalphabet', 'showalphabet', 'glossary');
90         $mform->addElement('selectyesno', 'showall', get_string('showall', 'glossary'));
91         $mform->setDefault('showall', 1);
92         $mform->addHelpButton('showall', 'showall', 'glossary');
94         $mform->addElement('selectyesno', 'editalways', get_string('editalways', 'glossary'));
95         $mform->setDefault('editalways', 0);
96         $mform->addHelpButton('editalways', 'editalways', 'glossary');
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);
106             $mform->addHelpButton('rsstype', 'rsstype', 'glossary');
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);
123             $mform->addHelpButton('rssarticles', 'rssarticles', 'glossary');
124             $mform->disabledIf('rssarticles', 'rsstype', 'eq', 0);
125         }
127 //-------------------------------------------------------------------------------
128         
129         $this->standard_coursemodule_elements();
131 //-------------------------------------------------------------------------------
132         // buttons
133         $this->add_action_buttons();
134     }
136     function definition_after_data() {
137         global $COURSE, $DB;
139         parent::definition_after_data();
140         $mform    =& $this->_form;
141         $mainglossaryel =& $mform->getElement('mainglossary');
142         $mainglossary = $DB->get_record('glossary', array('mainglossary'=>1, 'course'=>$COURSE->id));
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);
152         }
153     }
155     function data_preprocessing(&$default_values){
156         parent::data_preprocessing($default_values);
157     }