MDL-9742 Converting tabs to spaces
[moodle.git] / mod / forum / mod_form.php
CommitLineData
535e0ab6 1<?php
e24b7f85 2require_once ('moodleform_mod.php');
3
f07b9627 4class mod_forum_mod_form extends moodleform_mod {
535e0ab6 5
6 function definition() {
7
a02c77dc 8 global $CFG, $FORUM_TYPES, $COURSE;
535e0ab6 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'));
535e0ab6 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');
18a77361 26 $mform->setHelpButton('intro', array('writing', 'questions', 'richtext'), false, 'editorhelpbutton');
535e0ab6 27
28 $options = array();
29 $options[0] = get_string('no');
30 $options[1] = get_string('yesforever', 'forum');
31 $options[FORUM_INITIALSUBSCRIBE] = get_string('yesinitially', 'forum');
32 $options[FORUM_DISALLOWSUBSCRIBE] = get_string('disallowsubscribe','forum');
33 $mform->addElement('select', 'forcesubscribe', get_string('forcesubscribeq', 'forum'), $options);
34 $mform->setHelpButton('forcesubscribe', array('subscription2', get_string('forcesubscribeq', 'forum'), 'forum'));
35
36 $options = array();
37 $options[FORUM_TRACKING_OPTIONAL] = get_string('trackingoptional', 'forum');
38 $options[FORUM_TRACKING_OFF] = get_string('trackingoff', 'forum');
39 $options[FORUM_TRACKING_ON] = get_string('trackingon', 'forum');
40 $mform->addElement('select', 'trackingtype', get_string('trackingtype', 'forum'), $options);
41 $mform->setHelpButton('trackingtype', array('trackingtype', get_string('trackingtype', 'forum'), 'forum'));
42
a02c77dc 43 $choices = get_max_upload_sizes($CFG->maxbytes, $COURSE->maxbytes);
535e0ab6 44 $choices[1] = get_string('uploadnotallowed');
a02c77dc 45 $choices[0] = get_string('courseuploadlimit') . ' ('.display_size($COURSE->maxbytes).')';
535e0ab6 46 $mform->addElement('select', 'maxbytes', get_string('maxattachmentsize', 'forum'), $choices);
47 $mform->setHelpButton('maxbytes', array('maxattachmentsize', get_string('maxattachmentsize', 'forum'), 'forum'));
48 $mform->setDefault('maxbytes', $CFG->forum_maxbytes);
49
50 if ($CFG->enablerssfeeds && isset($CFG->forum_enablerssfeeds) && $CFG->forum_enablerssfeeds) {
a02c77dc 51//-------------------------------------------------------------------------------
535e0ab6 52 $mform->addElement('header', '', get_string('rss'));
53 $choices = array();
54 $choices[0] = get_string('none');
55 $choices[1] = get_string('discussions', 'forum');
56 $choices[2] = get_string('posts', 'forum');
57 $mform->addElement('select', 'rsstype', get_string('rsstype'), $choices);
58 $mform->setHelpButton('rsstype', array('rsstype', get_string('rsstype'), 'forum'));
59
60 $choices = array();
61 $choices[0] = '0';
62 $choices[1] = '1';
63 $choices[2] = '2';
64 $choices[3] = '3';
65 $choices[4] = '4';
66 $choices[5] = '5';
67 $choices[10] = '10';
68 $choices[15] = '15';
69 $choices[20] = '20';
70 $choices[25] = '25';
71 $choices[30] = '30';
72 $choices[40] = '40';
73 $choices[50] = '50';
74 $mform->addElement('select', 'rssarticles', get_string('rssarticles'), $choices);
75 $mform->setHelpButton('rssarticles', array('rssarticles', get_string('rssarticles'), 'forum'));
76 }
77
a02c77dc 78//-------------------------------------------------------------------------------
535e0ab6 79 $mform->addElement('header', '', get_string('grade'));
a02c77dc 80 $mform->addElement('checkbox', 'assessed', get_string('allowratings', 'forum') , get_string('ratingsuse', 'forum'));
535e0ab6 81
a02c77dc 82 $mform->addElement('modgrade', 'scale', get_string('grade'), false);
abf11956 83 $mform->disabledIf('scale', 'assessed');
6e372b25 84
85 $mform->addElement('checkbox', 'ratingtime', get_string('ratingtime', 'forum'));
abf11956 86 $mform->disabledIf('ratingtime', 'assessed');
535e0ab6 87
88 $mform->addElement('date_time_selector', 'assesstimestart', get_string('from'));
abf11956 89 $mform->disabledIf('assesstimestart', 'assessed');
90 $mform->disabledIf('assesstimestart', 'ratingtime');
535e0ab6 91
92 $mform->addElement('date_time_selector', 'assesstimefinish', get_string('to'));
abf11956 93 $mform->disabledIf('assesstimefinish', 'assessed');
94 $mform->disabledIf('assesstimefinish', 'ratingtime');
6e372b25 95
535e0ab6 96
a02c77dc 97//-------------------------------------------------------------------------------
535e0ab6 98 $mform->addElement('header', '', get_string('blockafter', 'forum'));
535e0ab6 99 $options = array();
100 $options[0] = get_string('blockperioddisabled','forum');
101 $options[60*60*24] = '1 '.get_string('day');
102 $options[60*60*24*2] = '2 '.get_string('days');
103 $options[60*60*24*3] = '3 '.get_string('days');
104 $options[60*60*24*4] = '4 '.get_string('days');
105 $options[60*60*24*5] = '5 '.get_string('days');
106 $options[60*60*24*6] = '6 '.get_string('days');
107 $options[60*60*24*7] = '1 '.get_string('week');
108 $mform->addElement('select', 'blockperiod', get_string("blockperiod", "forum") , $options);
109 $mform->setHelpButton('blockperiod', array('manageposts', get_string('blockperiod', 'forum'),'forum'));
110
9c03bbaa 111 $mform->addElement('text', 'blockafter', get_string('blockafter', 'forum'));
112 $mform->setType('blockafter', PARAM_INT);
113 $mform->setDefault('blockafter', '0');
114 $mform->addRule('blockafter', null, 'numeric', null, 'client');
115 $mform->setHelpButton('blockafter', array('manageposts', get_string('blockafter', 'forum'),'forum'));
e24b7f85 116 $mform->disabledIf('blockafter', 'blockperiod', 'eq', 0);
9c03bbaa 117
118
119 $mform->addElement('text', 'warnafter', get_string('warnafter', 'forum'));
120 $mform->setType('warnafter', PARAM_INT);
121 $mform->setDefault('warnafter', '0');
122 $mform->addRule('warnafter', null, 'numeric', null, 'client');
123 $mform->setHelpButton('warnafter', array('manageposts', get_string('warnafter', 'forum'),'forum'));
e24b7f85 124 $mform->disabledIf('warnafter', 'blockperiod', 'eq', 0);
9c03bbaa 125
a02c77dc 126//-------------------------------------------------------------------------------
535e0ab6 127 $this->standard_coursemodule_elements();
a23f0aaf 128//-------------------------------------------------------------------------------
129 // buttons
130 $this->add_action_buttons();
535e0ab6 131
535e0ab6 132 }
133
134 function definition_after_data(){
135 $mform =& $this->_form;
136 $type=&$mform->getElement('type');
d24206d6 137 $typevalue=$mform->getElementValue('type');
138 //we don't want to have these appear as possible selections in the form but
139 //we want the form to display them if they are set.
140 if ($typevalue[0]=='news'){
141 $type->addOption(get_string('namenews', 'forum'), 'news');
b2e8e723 142 $type->setHelpButton(array('forumtypenews', get_string('forumtypenews', 'forum'), 'forum'));
d24206d6 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 }
02f8f37d 151
152 }
a7f7e52f 153 function data_preprocessing($default_values){
02f8f37d 154 if (isset($default_values['assessed'])){
155 $default_values['ratingtime']=($default_values['assessed']
156 && $default_values['assesstimestart']
157 && $default_values['assesstimefinish'] )?1:0;
158 }
535e0ab6 159 }
160
161
162
e24b7f85 163
535e0ab6 164}
165?>