removed shorttag
[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)) {
16 $mform->setType('name', PARAM_TEXT);
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
2ee60b49 30 $mform->addElement('htmleditor', 'intro', get_string('forumintro', 'forum'));
31 $mform->setType('intro', PARAM_RAW);
32 $mform->addRule('intro', get_string('required'), 'required', null, 'client');
18a77361 33 $mform->setHelpButton('intro', array('writing', 'questions', 'richtext'), false, 'editorhelpbutton');
535e0ab6 34
35 $options = array();
36 $options[0] = get_string('no');
37 $options[1] = get_string('yesforever', 'forum');
38 $options[FORUM_INITIALSUBSCRIBE] = get_string('yesinitially', 'forum');
39 $options[FORUM_DISALLOWSUBSCRIBE] = get_string('disallowsubscribe','forum');
40 $mform->addElement('select', 'forcesubscribe', get_string('forcesubscribeq', 'forum'), $options);
2ee60b49 41 $mform->setHelpButton('forcesubscribe', array('subscription2', get_string('forcesubscribeq', 'forum'), 'forum'));
535e0ab6 42
43 $options = array();
44 $options[FORUM_TRACKING_OPTIONAL] = get_string('trackingoptional', 'forum');
45 $options[FORUM_TRACKING_OFF] = get_string('trackingoff', 'forum');
46 $options[FORUM_TRACKING_ON] = get_string('trackingon', 'forum');
47 $mform->addElement('select', 'trackingtype', get_string('trackingtype', 'forum'), $options);
2ee60b49 48 $mform->setHelpButton('trackingtype', array('trackingtype', get_string('trackingtype', 'forum'), 'forum'));
535e0ab6 49
a02c77dc 50 $choices = get_max_upload_sizes($CFG->maxbytes, $COURSE->maxbytes);
535e0ab6 51 $choices[1] = get_string('uploadnotallowed');
a02c77dc 52 $choices[0] = get_string('courseuploadlimit') . ' ('.display_size($COURSE->maxbytes).')';
535e0ab6 53 $mform->addElement('select', 'maxbytes', get_string('maxattachmentsize', 'forum'), $choices);
2ee60b49 54 $mform->setHelpButton('maxbytes', array('maxattachmentsize', get_string('maxattachmentsize', 'forum'), 'forum'));
55 $mform->setDefault('maxbytes', $CFG->forum_maxbytes);
535e0ab6 56
57 if ($CFG->enablerssfeeds && isset($CFG->forum_enablerssfeeds) && $CFG->forum_enablerssfeeds) {
a02c77dc 58//-------------------------------------------------------------------------------
535e0ab6 59 $mform->addElement('header', '', get_string('rss'));
60 $choices = array();
61 $choices[0] = get_string('none');
62 $choices[1] = get_string('discussions', 'forum');
63 $choices[2] = get_string('posts', 'forum');
64 $mform->addElement('select', 'rsstype', get_string('rsstype'), $choices);
65 $mform->setHelpButton('rsstype', array('rsstype', get_string('rsstype'), 'forum'));
66
67 $choices = array();
68 $choices[0] = '0';
69 $choices[1] = '1';
70 $choices[2] = '2';
71 $choices[3] = '3';
72 $choices[4] = '4';
73 $choices[5] = '5';
74 $choices[10] = '10';
75 $choices[15] = '15';
76 $choices[20] = '20';
77 $choices[25] = '25';
78 $choices[30] = '30';
79 $choices[40] = '40';
80 $choices[50] = '50';
81 $mform->addElement('select', 'rssarticles', get_string('rssarticles'), $choices);
82 $mform->setHelpButton('rssarticles', array('rssarticles', get_string('rssarticles'), 'forum'));
83 }
84
a02c77dc 85//-------------------------------------------------------------------------------
535e0ab6 86 $mform->addElement('header', '', get_string('grade'));
13bbe067 87
88 $mform->addElement('select', 'assessed', get_string('aggregatetype', 'forum') , forum_get_aggregate_types());
89 $mform->setDefault('assessed', 0);
90 $mform->setHelpButton('assessed', array('assessaggregate', get_string('aggregatetype', 'forum'), 'forum'));
535e0ab6 91
a02c77dc 92 $mform->addElement('modgrade', 'scale', get_string('grade'), false);
13bbe067 93 $mform->disabledIf('scale', 'assessed', 'eq', 0);
6e372b25 94
95 $mform->addElement('checkbox', 'ratingtime', get_string('ratingtime', 'forum'));
13bbe067 96 $mform->disabledIf('ratingtime', 'assessed', 'eq', 0);
535e0ab6 97
98 $mform->addElement('date_time_selector', 'assesstimestart', get_string('from'));
13bbe067 99 $mform->disabledIf('assesstimestart', 'assessed', 'eq', 0);
abf11956 100 $mform->disabledIf('assesstimestart', 'ratingtime');
535e0ab6 101
102 $mform->addElement('date_time_selector', 'assesstimefinish', get_string('to'));
13bbe067 103 $mform->disabledIf('assesstimefinish', 'assessed', 'eq', 0);
abf11956 104 $mform->disabledIf('assesstimefinish', 'ratingtime');
6e372b25 105
535e0ab6 106
a02c77dc 107//-------------------------------------------------------------------------------
535e0ab6 108 $mform->addElement('header', '', get_string('blockafter', 'forum'));
2ee60b49 109 $options = array();
535e0ab6 110 $options[0] = get_string('blockperioddisabled','forum');
111 $options[60*60*24] = '1 '.get_string('day');
112 $options[60*60*24*2] = '2 '.get_string('days');
113 $options[60*60*24*3] = '3 '.get_string('days');
114 $options[60*60*24*4] = '4 '.get_string('days');
115 $options[60*60*24*5] = '5 '.get_string('days');
116 $options[60*60*24*6] = '6 '.get_string('days');
117 $options[60*60*24*7] = '1 '.get_string('week');
118 $mform->addElement('select', 'blockperiod', get_string("blockperiod", "forum") , $options);
2ee60b49 119 $mform->setHelpButton('blockperiod', array('manageposts', get_string('blockperiod', 'forum'),'forum'));
535e0ab6 120
2ee60b49 121 $mform->addElement('text', 'blockafter', get_string('blockafter', 'forum'));
122 $mform->setType('blockafter', PARAM_INT);
123 $mform->setDefault('blockafter', '0');
124 $mform->addRule('blockafter', null, 'numeric', null, 'client');
125 $mform->setHelpButton('blockafter', array('manageposts', get_string('blockafter', 'forum'),'forum'));
126 $mform->disabledIf('blockafter', 'blockperiod', 'eq', 0);
9c03bbaa 127
128
129 $mform->addElement('text', 'warnafter', get_string('warnafter', 'forum'));
2ee60b49 130 $mform->setType('warnafter', PARAM_INT);
131 $mform->setDefault('warnafter', '0');
132 $mform->addRule('warnafter', null, 'numeric', null, 'client');
133 $mform->setHelpButton('warnafter', array('manageposts', get_string('warnafter', 'forum'),'forum'));
134 $mform->disabledIf('warnafter', 'blockperiod', 'eq', 0);
9c03bbaa 135
a02c77dc 136//-------------------------------------------------------------------------------
010a47bf 137 $features = new stdClass;
138 $features->groups = true;
139 $features->groupings = true;
140 $features->groupmembersonly = true;
141 $this->standard_coursemodule_elements($features);
a23f0aaf 142//-------------------------------------------------------------------------------
2ee60b49 143// buttons
a23f0aaf 144 $this->add_action_buttons();
535e0ab6 145
2ee60b49 146 }
535e0ab6 147
2ee60b49 148 function definition_after_data(){
4050572d 149 parent::definition_after_data();
150 $mform =& $this->_form;
151 $type =& $mform->getElement('type');
152 $typevalue = $mform->getElementValue('type');
153
d24206d6 154 //we don't want to have these appear as possible selections in the form but
155 //we want the form to display them if they are set.
156 if ($typevalue[0]=='news'){
157 $type->addOption(get_string('namenews', 'forum'), 'news');
d4175332 158 $type->setHelpButton(array('forumtypenews', get_string('forumtype', 'forum'), 'forum'));
d24206d6 159 $type->freeze();
160 $type->setPersistantFreeze(true);
161 }
162 if ($typevalue[0]=='social'){
163 $type->addOption(get_string('namesocial', 'forum'), 'social');
535e0ab6 164 $type->freeze();
165 $type->setPersistantFreeze(true);
166 }
02f8f37d 167
2ee60b49 168 }
535e0ab6 169
c3cec421 170 function data_preprocessing(&$default_values){
171 if (empty($default_values['scale'])){
172 $default_values['assessed'] = 0;
65bcf17b 173 }
c3cec421 174
353228d8 175 if (empty($default_values['assessed'])){
176 $default_values['ratingtime'] = 0;
177 } else {
178 $default_values['ratingtime']=
179 ($default_values['assesstimestart'] && $default_values['assesstimefinish']) ? 1 : 0;
2ee60b49 180 }
181 }
e24b7f85 182
535e0ab6 183}
2ee60b49 184?>