Merged two-line deletes from stable (causing notices)
[moodle.git] / mod / forum / mod_form.php
CommitLineData
535e0ab6 1<?php
2require_once ($CFG->libdir.'/formslib.php');
3class forum_mod_form extends moodleform_mod {
4
5 function definition() {
6
a02c77dc 7 global $CFG, $FORUM_TYPES, $COURSE;
535e0ab6 8 $mform =& $this->_form;
9 $renderer =& $mform->defaultRenderer();
535e0ab6 10
11//-------------------------------------------------------------------------------
12 $mform->addElement('header', 'general', get_string('general', 'form'));
13
14 $mform->addElement('text', 'name', get_string('forumname', 'forum'));
15 $mform->setType('name', PARAM_TEXT);
16 $mform->addRule('name', null, 'required', null, 'client');
17
18 asort($FORUM_TYPES);
19 $mform->addElement('select', 'type', get_string('forumtype', 'forum'), $FORUM_TYPES);
20 $mform->setHelpButton('type', array('forumtype', get_string('forumtype', 'forum'), 'forum'));
21 $mform->setDefault('type', 'general');
22
23 $mform->addElement('htmleditor', 'intro', get_string('forumintro', 'forum'));
24 $mform->setType('intro', PARAM_RAW);
25 $mform->addRule('intro', get_string('required'), 'required', null, 'client');
26
27 $options = array();
28 $options[0] = get_string('no');
29 $options[1] = get_string('yesforever', 'forum');
30 $options[FORUM_INITIALSUBSCRIBE] = get_string('yesinitially', 'forum');
31 $options[FORUM_DISALLOWSUBSCRIBE] = get_string('disallowsubscribe','forum');
32 $mform->addElement('select', 'forcesubscribe', get_string('forcesubscribeq', 'forum'), $options);
33 $mform->setHelpButton('forcesubscribe', array('subscription2', get_string('forcesubscribeq', 'forum'), 'forum'));
34
35 $options = array();
36 $options[FORUM_TRACKING_OPTIONAL] = get_string('trackingoptional', 'forum');
37 $options[FORUM_TRACKING_OFF] = get_string('trackingoff', 'forum');
38 $options[FORUM_TRACKING_ON] = get_string('trackingon', 'forum');
39 $mform->addElement('select', 'trackingtype', get_string('trackingtype', 'forum'), $options);
40 $mform->setHelpButton('trackingtype', array('trackingtype', get_string('trackingtype', 'forum'), 'forum'));
41
a02c77dc 42 $choices = get_max_upload_sizes($CFG->maxbytes, $COURSE->maxbytes);
535e0ab6 43 $choices[1] = get_string('uploadnotallowed');
a02c77dc 44 $choices[0] = get_string('courseuploadlimit') . ' ('.display_size($COURSE->maxbytes).')';
535e0ab6 45 $mform->addElement('select', 'maxbytes', get_string('maxattachmentsize', 'forum'), $choices);
46 $mform->setHelpButton('maxbytes', array('maxattachmentsize', get_string('maxattachmentsize', 'forum'), 'forum'));
47 $mform->setDefault('maxbytes', $CFG->forum_maxbytes);
48
49 if ($CFG->enablerssfeeds && isset($CFG->forum_enablerssfeeds) && $CFG->forum_enablerssfeeds) {
a02c77dc 50//-------------------------------------------------------------------------------
535e0ab6 51 $mform->addElement('header', '', get_string('rss'));
52 $choices = array();
53 $choices[0] = get_string('none');
54 $choices[1] = get_string('discussions', 'forum');
55 $choices[2] = get_string('posts', 'forum');
56 $mform->addElement('select', 'rsstype', get_string('rsstype'), $choices);
57 $mform->setHelpButton('rsstype', array('rsstype', get_string('rsstype'), 'forum'));
58
59 $choices = array();
60 $choices[0] = '0';
61 $choices[1] = '1';
62 $choices[2] = '2';
63 $choices[3] = '3';
64 $choices[4] = '4';
65 $choices[5] = '5';
66 $choices[10] = '10';
67 $choices[15] = '15';
68 $choices[20] = '20';
69 $choices[25] = '25';
70 $choices[30] = '30';
71 $choices[40] = '40';
72 $choices[50] = '50';
73 $mform->addElement('select', 'rssarticles', get_string('rssarticles'), $choices);
74 $mform->setHelpButton('rssarticles', array('rssarticles', get_string('rssarticles'), 'forum'));
75 }
76
a02c77dc 77//-------------------------------------------------------------------------------
535e0ab6 78 $mform->addElement('header', '', get_string('grade'));
a02c77dc 79 $mform->addElement('checkbox', 'assessed', get_string('allowratings', 'forum') , get_string('ratingsuse', 'forum'));
535e0ab6 80
a02c77dc 81 $mform->addElement('modgrade', 'scale', get_string('grade'), false);
abf11956 82 $mform->disabledIf('scale', 'assessed');
6e372b25 83
84 $mform->addElement('checkbox', 'ratingtime', get_string('ratingtime', 'forum'));
abf11956 85 $mform->disabledIf('ratingtime', 'assessed');
535e0ab6 86
87 $mform->addElement('date_time_selector', 'assesstimestart', get_string('from'));
abf11956 88 $mform->disabledIf('assesstimestart', 'assessed');
89 $mform->disabledIf('assesstimestart', 'ratingtime');
535e0ab6 90
91 $mform->addElement('date_time_selector', 'assesstimefinish', get_string('to'));
abf11956 92 $mform->disabledIf('assesstimefinish', 'assessed');
93 $mform->disabledIf('assesstimefinish', 'ratingtime');
6e372b25 94
535e0ab6 95
a02c77dc 96//-------------------------------------------------------------------------------
535e0ab6 97 $mform->addElement('header', '', get_string('blockafter', 'forum'));
535e0ab6 98 $options = array();
99 $options[0] = get_string('blockperioddisabled','forum');
100 $options[60*60*24] = '1 '.get_string('day');
101 $options[60*60*24*2] = '2 '.get_string('days');
102 $options[60*60*24*3] = '3 '.get_string('days');
103 $options[60*60*24*4] = '4 '.get_string('days');
104 $options[60*60*24*5] = '5 '.get_string('days');
105 $options[60*60*24*6] = '6 '.get_string('days');
106 $options[60*60*24*7] = '1 '.get_string('week');
107 $mform->addElement('select', 'blockperiod', get_string("blockperiod", "forum") , $options);
108 $mform->setHelpButton('blockperiod', array('manageposts', get_string('blockperiod', 'forum'),'forum'));
109
9c03bbaa 110 $mform->addElement('text', 'blockafter', get_string('blockafter', 'forum'));
111 $mform->setType('blockafter', PARAM_INT);
112 $mform->setDefault('blockafter', '0');
113 $mform->addRule('blockafter', null, 'numeric', null, 'client');
114 $mform->setHelpButton('blockafter', array('manageposts', get_string('blockafter', 'forum'),'forum'));
abf11956 115 $mform->disabledIf('blockafter', 'blockperiod', 0);
9c03bbaa 116
117
118 $mform->addElement('text', 'warnafter', get_string('warnafter', 'forum'));
119 $mform->setType('warnafter', PARAM_INT);
120 $mform->setDefault('warnafter', '0');
121 $mform->addRule('warnafter', null, 'numeric', null, 'client');
122 $mform->setHelpButton('warnafter', array('manageposts', get_string('warnafter', 'forum'),'forum'));
abf11956 123 $mform->disabledIf('warnafter', 'blockperiod', 0);
9c03bbaa 124
a02c77dc 125//-------------------------------------------------------------------------------
535e0ab6 126 $this->standard_coursemodule_elements();
127
128 $buttonarray=array();
129 $buttonarray[] = &MoodleQuickForm::createElement('submit', 'submit', get_string('savechanges'));
130 $buttonarray[] = &MoodleQuickForm::createElement('submit', 'cancel', get_string('cancel'));
131 $mform->addGroup($buttonarray, 'buttonar', '', array(' '), false);
132 $renderer->addStopFieldsetElements('buttonar');
133 }
134
135 function definition_after_data(){
136 $mform =& $this->_form;
137 $type=&$mform->getElement('type');
d24206d6 138 $typevalue=$mform->getElementValue('type');
139 //we don't want to have these appear as possible selections in the form but
140 //we want the form to display them if they are set.
141 if ($typevalue[0]=='news'){
142 $type->addOption(get_string('namenews', 'forum'), 'news');
143 $type->freeze();
144 $type->setPersistantFreeze(true);
145 }
146 if ($typevalue[0]=='social'){
147 $type->addOption(get_string('namesocial', 'forum'), 'social');
535e0ab6 148 $type->freeze();
149 $type->setPersistantFreeze(true);
150 }
9c03bbaa 151 $assesstimestartvalue=is_array($mform->getElementValue('assesstimestart'));
152 $assesstimefinishvalue=is_array($mform->getElementValue('assesstimefinish'));
153 $ratingtime=&$mform->getElement('ratingtime');
154 if ($assesstimestartvalue && $assesstimefinishvalue){
155 $ratingtime->setValue(true);
156 } else {
157 $ratingtime->setValue(false);
158 }
535e0ab6 159 }
160
161
162
163}
164?>