quiz MDL-10128 popup checker no longer requests a non-existent file which was causing...
[moodle.git] / mod / forum / mod_form.php
CommitLineData
535e0ab6 1<?php
23a7718b 2require_once ($CFG->dirroot.'/course/moodleform_mod.php');
e24b7f85 3
f07b9627 4class mod_forum_mod_form extends moodleform_mod {
535e0ab6 5
2ee60b49 6 function definition() {
c18269c7 7 global $CFG, $COURSE, $DB;
535e0ab6 8
2ee60b49 9 $mform =& $this->_form;
535e0ab6 10
11//-------------------------------------------------------------------------------
12 $mform->addElement('header', 'general', get_string('general', 'form'));
13
26de8d35 14 $mform->addElement('text', 'name', get_string('forumname', 'forum'), array('size'=>'64'));
8eb1d25f 15 if (!empty($CFG->formatstringstriptags)) {
4e781c7b 16 $mform->setType('name', PARAM_TEXT);
8eb1d25f 17 } else {
18 $mform->setType('name', PARAM_CLEAN);
19 }
2ee60b49 20 $mform->addRule('name', null, 'required', null, 'client');
b230cac1 21 $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
535e0ab6 22
65bcf17b 23 $forum_types = forum_get_forum_types();
24
25 asort($forum_types);
26 $mform->addElement('select', 'type', get_string('forumtype', 'forum'), $forum_types);
2ee60b49 27 $mform->setHelpButton('type', array('forumtype', get_string('forumtype', 'forum'), 'forum'));
28 $mform->setDefault('type', 'general');
535e0ab6 29
4ba2221a 30 $this->add_intro_editor(true, get_string('forumintro', 'forum'));
b2a9505b 31
535e0ab6 32 $options = array();
33 $options[0] = get_string('no');
34 $options[1] = get_string('yesforever', 'forum');
35 $options[FORUM_INITIALSUBSCRIBE] = get_string('yesinitially', 'forum');
36 $options[FORUM_DISALLOWSUBSCRIBE] = get_string('disallowsubscribe','forum');
37 $mform->addElement('select', 'forcesubscribe', get_string('forcesubscribeq', 'forum'), $options);
2ee60b49 38 $mform->setHelpButton('forcesubscribe', array('subscription2', get_string('forcesubscribeq', 'forum'), 'forum'));
535e0ab6 39
40 $options = array();
41 $options[FORUM_TRACKING_OPTIONAL] = get_string('trackingoptional', 'forum');
42 $options[FORUM_TRACKING_OFF] = get_string('trackingoff', 'forum');
43 $options[FORUM_TRACKING_ON] = get_string('trackingon', 'forum');
44 $mform->addElement('select', 'trackingtype', get_string('trackingtype', 'forum'), $options);
2ee60b49 45 $mform->setHelpButton('trackingtype', array('trackingtype', get_string('trackingtype', 'forum'), 'forum'));
535e0ab6 46
a02c77dc 47 $choices = get_max_upload_sizes($CFG->maxbytes, $COURSE->maxbytes);
535e0ab6 48 $choices[1] = get_string('uploadnotallowed');
a02c77dc 49 $choices[0] = get_string('courseuploadlimit') . ' ('.display_size($COURSE->maxbytes).')';
535e0ab6 50 $mform->addElement('select', 'maxbytes', get_string('maxattachmentsize', 'forum'), $choices);
2ee60b49 51 $mform->setHelpButton('maxbytes', array('maxattachmentsize', get_string('maxattachmentsize', 'forum'), 'forum'));
52 $mform->setDefault('maxbytes', $CFG->forum_maxbytes);
535e0ab6 53
30a9aff5 54 $choices = array(0,1,2,3,4,5,6,7,8,9);
55 $mform->addElement('select', 'maxattachments', get_string('maxattachments', 'forum'), $choices);
56 $mform->setHelpButton('maxattachments', array('maxattachments', get_string('maxattachments', 'forum'), 'forum'));
57 $mform->setDefault('maxattachments', $CFG->forum_maxattachments);
58
535e0ab6 59 if ($CFG->enablerssfeeds && isset($CFG->forum_enablerssfeeds) && $CFG->forum_enablerssfeeds) {
a02c77dc 60//-------------------------------------------------------------------------------
535e0ab6 61 $mform->addElement('header', '', get_string('rss'));
62 $choices = array();
63 $choices[0] = get_string('none');
64 $choices[1] = get_string('discussions', 'forum');
65 $choices[2] = get_string('posts', 'forum');
66 $mform->addElement('select', 'rsstype', get_string('rsstype'), $choices);
67 $mform->setHelpButton('rsstype', array('rsstype', get_string('rsstype'), 'forum'));
68
69 $choices = array();
70 $choices[0] = '0';
71 $choices[1] = '1';
72 $choices[2] = '2';
73 $choices[3] = '3';
74 $choices[4] = '4';
75 $choices[5] = '5';
76 $choices[10] = '10';
77 $choices[15] = '15';
78 $choices[20] = '20';
79 $choices[25] = '25';
80 $choices[30] = '30';
81 $choices[40] = '40';
82 $choices[50] = '50';
83 $mform->addElement('select', 'rssarticles', get_string('rssarticles'), $choices);
84 $mform->setHelpButton('rssarticles', array('rssarticles', get_string('rssarticles'), 'forum'));
85 }
86
a02c77dc 87//-------------------------------------------------------------------------------
535e0ab6 88 $mform->addElement('header', '', get_string('grade'));
13bbe067 89
90 $mform->addElement('select', 'assessed', get_string('aggregatetype', 'forum') , forum_get_aggregate_types());
91 $mform->setDefault('assessed', 0);
92 $mform->setHelpButton('assessed', array('assessaggregate', get_string('aggregatetype', 'forum'), 'forum'));
535e0ab6 93
a02c77dc 94 $mform->addElement('modgrade', 'scale', get_string('grade'), false);
13bbe067 95 $mform->disabledIf('scale', 'assessed', 'eq', 0);
6e372b25 96
97 $mform->addElement('checkbox', 'ratingtime', get_string('ratingtime', 'forum'));
13bbe067 98 $mform->disabledIf('ratingtime', 'assessed', 'eq', 0);
535e0ab6 99
100 $mform->addElement('date_time_selector', 'assesstimestart', get_string('from'));
13bbe067 101 $mform->disabledIf('assesstimestart', 'assessed', 'eq', 0);
abf11956 102 $mform->disabledIf('assesstimestart', 'ratingtime');
535e0ab6 103
104 $mform->addElement('date_time_selector', 'assesstimefinish', get_string('to'));
13bbe067 105 $mform->disabledIf('assesstimefinish', 'assessed', 'eq', 0);
abf11956 106 $mform->disabledIf('assesstimefinish', 'ratingtime');
6e372b25 107
535e0ab6 108
a02c77dc 109//-------------------------------------------------------------------------------
535e0ab6 110 $mform->addElement('header', '', get_string('blockafter', 'forum'));
2ee60b49 111 $options = array();
535e0ab6 112 $options[0] = get_string('blockperioddisabled','forum');
113 $options[60*60*24] = '1 '.get_string('day');
114 $options[60*60*24*2] = '2 '.get_string('days');
115 $options[60*60*24*3] = '3 '.get_string('days');
116 $options[60*60*24*4] = '4 '.get_string('days');
117 $options[60*60*24*5] = '5 '.get_string('days');
118 $options[60*60*24*6] = '6 '.get_string('days');
119 $options[60*60*24*7] = '1 '.get_string('week');
120 $mform->addElement('select', 'blockperiod', get_string("blockperiod", "forum") , $options);
2ee60b49 121 $mform->setHelpButton('blockperiod', array('manageposts', get_string('blockperiod', 'forum'),'forum'));
535e0ab6 122
2ee60b49 123 $mform->addElement('text', 'blockafter', get_string('blockafter', 'forum'));
124 $mform->setType('blockafter', PARAM_INT);
125 $mform->setDefault('blockafter', '0');
126 $mform->addRule('blockafter', null, 'numeric', null, 'client');
127 $mform->setHelpButton('blockafter', array('manageposts', get_string('blockafter', 'forum'),'forum'));
128 $mform->disabledIf('blockafter', 'blockperiod', 'eq', 0);
9c03bbaa 129
130
131 $mform->addElement('text', 'warnafter', get_string('warnafter', 'forum'));
2ee60b49 132 $mform->setType('warnafter', PARAM_INT);
133 $mform->setDefault('warnafter', '0');
134 $mform->addRule('warnafter', null, 'numeric', null, 'client');
135 $mform->setHelpButton('warnafter', array('manageposts', get_string('warnafter', 'forum'),'forum'));
136 $mform->disabledIf('warnafter', 'blockperiod', 'eq', 0);
9c03bbaa 137
a02c77dc 138//-------------------------------------------------------------------------------
42f103be 139 $this->standard_coursemodule_elements();
a23f0aaf 140//-------------------------------------------------------------------------------
2ee60b49 141// buttons
a23f0aaf 142 $this->add_action_buttons();
535e0ab6 143
2ee60b49 144 }
535e0ab6 145
4ba2221a 146 function definition_after_data() {
4050572d 147 parent::definition_after_data();
148 $mform =& $this->_form;
149 $type =& $mform->getElement('type');
150 $typevalue = $mform->getElementValue('type');
151
d24206d6 152 //we don't want to have these appear as possible selections in the form but
153 //we want the form to display them if they are set.
4ba2221a 154 if ($typevalue[0]=='news') {
d24206d6 155 $type->addOption(get_string('namenews', 'forum'), 'news');
d4175332 156 $type->setHelpButton(array('forumtypenews', get_string('forumtype', 'forum'), 'forum'));
d24206d6 157 $type->freeze();
158 $type->setPersistantFreeze(true);
159 }
4ba2221a 160 if ($typevalue[0]=='social') {
d24206d6 161 $type->addOption(get_string('namesocial', 'forum'), 'social');
535e0ab6 162 $type->freeze();
163 $type->setPersistantFreeze(true);
164 }
02f8f37d 165
2ee60b49 166 }
535e0ab6 167
4ba2221a 168 function data_preprocessing(&$default_values) {
169 if (empty($default_values['scale'])) {
c3cec421 170 $default_values['assessed'] = 0;
65bcf17b 171 }
c3cec421 172
4ba2221a 173 if (empty($default_values['assessed'])) {
353228d8 174 $default_values['ratingtime'] = 0;
175 } else {
176 $default_values['ratingtime']=
177 ($default_values['assesstimestart'] && $default_values['assesstimefinish']) ? 1 : 0;
2ee60b49 178 }
4e781c7b 179
180 // Set up the completion checkboxes which aren't part of standard data.
181 // We also make the default value (if you turn on the checkbox) for those
182 // numbers to be 1, this will not apply unless checkbox is ticked.
183 $default_values['completiondiscussionsenabled']=
184 !empty($default_values['completiondiscussions']) ? 1 : 0;
4ba2221a 185 if (empty($default_values['completiondiscussions'])) {
4e781c7b 186 $default_values['completiondiscussions']=1;
187 }
188 $default_values['completionrepliesenabled']=
189 !empty($default_values['completionreplies']) ? 1 : 0;
4ba2221a 190 if (empty($default_values['completionreplies'])) {
4e781c7b 191 $default_values['completionreplies']=1;
192 }
193 $default_values['completionpostsenabled']=
194 !empty($default_values['completionposts']) ? 1 : 0;
4ba2221a 195 if (empty($default_values['completionposts'])) {
4e781c7b 196 $default_values['completionposts']=1;
197 }
2ee60b49 198 }
e24b7f85 199
4e781c7b 200 function add_completion_rules() {
201 $mform =& $this->_form;
202
203 $group=array();
204 $group[] =& $mform->createElement('checkbox', 'completionpostsenabled', '', get_string('completionposts','forum'));
205 $group[] =& $mform->createElement('text', 'completionposts', '', array('size'=>3));
206 $mform->setType('completionposts',PARAM_INT);
207 $mform->addGroup($group, 'completionpostsgroup', get_string('completionpostsgroup','forum'), array(' '), false);
208 $mform->setHelpButton('completionpostsgroup', array('completion', get_string('completionpostshelp', 'forum'), 'forum'));
209 $mform->disabledIf('completionposts','completionpostsenabled','notchecked');
210
211 $group=array();
212 $group[] =& $mform->createElement('checkbox', 'completiondiscussionsenabled', '', get_string('completiondiscussions','forum'));
213 $group[] =& $mform->createElement('text', 'completiondiscussions', '', array('size'=>3));
214 $mform->setType('completiondiscussions',PARAM_INT);
215 $mform->addGroup($group, 'completiondiscussionsgroup', get_string('completiondiscussionsgroup','forum'), array(' '), false);
216 $mform->setHelpButton('completiondiscussionsgroup', array('completion', get_string('completiondiscussionshelp', 'forum'), 'forum'));
217 $mform->disabledIf('completiondiscussions','completiondiscussionsenabled','notchecked');
218
219 $group=array();
220 $group[] =& $mform->createElement('checkbox', 'completionrepliesenabled', '', get_string('completionreplies','forum'));
221 $group[] =& $mform->createElement('text', 'completionreplies', '', array('size'=>3));
222 $mform->setType('completionreplies',PARAM_INT);
223 $mform->addGroup($group, 'completionrepliesgroup', get_string('completionrepliesgroup','forum'), array(' '), false);
224 $mform->setHelpButton('completionrepliesgroup', array('completion', get_string('completionreplieshelp', 'forum'), 'forum'));
225 $mform->disabledIf('completionreplies','completionrepliesenabled','notchecked');
226
227 return array('completiondiscussionsgroup','completionrepliesgroup','completionpostsgroup');
228 }
229
230 function completion_rule_enabled($data) {
231 return (!empty($data['completiondiscussionsenabled']) && $data['completiondiscussions']!=0) ||
232 (!empty($data['completionrepliesenabled']) && $data['completionreplies']!=0) ||
233 (!empty($data['completionpostsenabled']) && $data['completionposts']!=0);
234 }
235
49f6e5f4 236 function get_data() {
4ba2221a 237 $data = parent::get_data();
238 if (!$data) {
4e781c7b 239 return false;
240 }
241 // Turn off completion settings if the checkboxes aren't ticked
4ba2221a 242 $autocompletion = !empty($data->completion) && $data->completion==COMPLETION_TRACKING_AUTOMATIC;
243 if (empty($data->completiondiscussionsenabled) || !$autocompletion) {
244 $data->completiondiscussions = 0;
4e781c7b 245 }
4ba2221a 246 if (empty($data->completionrepliesenabled) || !$autocompletion) {
247 $data->completionreplies = 0;
4e781c7b 248 }
4ba2221a 249 if (empty($data->completionpostsenabled) || !$autocompletion) {
250 $data->completionposts = 0;
4e781c7b 251 }
252 return $data;
253 }
535e0ab6 254}
1adbd2c3 255