2 if (!defined('MOODLE_INTERNAL')) {
3 die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
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);
22 $mform->setType('name', PARAM_CLEAN);
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');
38 $mform->addElement('hidden', 'globalglossary');
39 $mform->setType('globalglossary', PARAM_INT);
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();
73 foreach ($recformats as $format) {
74 $formats[$format->name] = get_string('displayformat'.$format->name, 'glossary');
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'));
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');
122 $mform->addElement('select', 'rssarticles', get_string('rssarticles'), $choices);
123 $mform->addHelpButton('rssarticles', 'rssarticles', 'glossary');
124 $mform->disabledIf('rssarticles', 'rsstype', 'eq', 0);
127 //-------------------------------------------------------------------------------
129 $this->standard_coursemodule_elements();
131 //-------------------------------------------------------------------------------
133 $this->add_action_buttons();
136 function definition_after_data() {
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);
149 $mainglossaryel->unfreeze();
150 $mainglossaryel->setPersistantFreeze(false);
155 function data_preprocessing(&$default_values){
156 parent::data_preprocessing($default_values);