Updated the 19 build version to 20080928
[moodle.git] / mod / forum / mod_form.php
blob14bda5344b7c85115b2fa0e700e8420be1ab6645
1 <?php
2 require_once ($CFG->dirroot.'/course/moodleform_mod.php');
4 class mod_forum_mod_form extends moodleform_mod {
6 function definition() {
8 global $CFG, $COURSE;
9 $mform =& $this->_form;
11 //-------------------------------------------------------------------------------
12 $mform->addElement('header', 'general', get_string('general', 'form'));
14 $mform->addElement('text', 'name', get_string('forumname', 'forum'), array('size'=>'64'));
15 if (!empty($CFG->formatstringstriptags)) {
16 $mform->setType('name', PARAM_TEXT);
17 } else {
18 $mform->setType('name', PARAM_CLEAN);
20 $mform->addRule('name', null, 'required', null, 'client');
21 $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
23 $forum_types = forum_get_forum_types();
25 asort($forum_types);
26 $mform->addElement('select', 'type', get_string('forumtype', 'forum'), $forum_types);
27 $mform->setHelpButton('type', array('forumtype', get_string('forumtype', 'forum'), 'forum'));
28 $mform->setDefault('type', 'general');
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');
33 $mform->setHelpButton('intro', array('writing', 'questions', 'richtext'), false, 'editorhelpbutton');
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);
41 $mform->setHelpButton('forcesubscribe', array('subscription2', get_string('forcesubscribeq', 'forum'), 'forum'));
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);
48 $mform->setHelpButton('trackingtype', array('trackingtype', get_string('trackingtype', 'forum'), 'forum'));
50 $choices = get_max_upload_sizes($CFG->maxbytes, $COURSE->maxbytes);
51 $choices[1] = get_string('uploadnotallowed');
52 $choices[0] = get_string('courseuploadlimit') . ' ('.display_size($COURSE->maxbytes).')';
53 $mform->addElement('select', 'maxbytes', get_string('maxattachmentsize', 'forum'), $choices);
54 $mform->setHelpButton('maxbytes', array('maxattachmentsize', get_string('maxattachmentsize', 'forum'), 'forum'));
55 $mform->setDefault('maxbytes', $CFG->forum_maxbytes);
57 if ($CFG->enablerssfeeds && isset($CFG->forum_enablerssfeeds) && $CFG->forum_enablerssfeeds) {
58 //-------------------------------------------------------------------------------
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'));
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'));
85 //-------------------------------------------------------------------------------
86 $mform->addElement('header', '', get_string('grade'));
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'));
92 $mform->addElement('modgrade', 'scale', get_string('grade'), false);
93 $mform->disabledIf('scale', 'assessed', 'eq', 0);
95 $mform->addElement('checkbox', 'ratingtime', get_string('ratingtime', 'forum'));
96 $mform->disabledIf('ratingtime', 'assessed', 'eq', 0);
98 $mform->addElement('date_time_selector', 'assesstimestart', get_string('from'));
99 $mform->disabledIf('assesstimestart', 'assessed', 'eq', 0);
100 $mform->disabledIf('assesstimestart', 'ratingtime');
102 $mform->addElement('date_time_selector', 'assesstimefinish', get_string('to'));
103 $mform->disabledIf('assesstimefinish', 'assessed', 'eq', 0);
104 $mform->disabledIf('assesstimefinish', 'ratingtime');
107 //-------------------------------------------------------------------------------
108 $mform->addElement('header', '', get_string('blockafter', 'forum'));
109 $options = array();
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);
119 $mform->setHelpButton('blockperiod', array('manageposts', get_string('blockperiod', 'forum'),'forum'));
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);
129 $mform->addElement('text', 'warnafter', get_string('warnafter', 'forum'));
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);
136 //-------------------------------------------------------------------------------
137 $features = new stdClass;
138 $features->groups = true;
139 $features->groupings = true;
140 $features->groupmembersonly = true;
141 $this->standard_coursemodule_elements($features);
142 //-------------------------------------------------------------------------------
143 // buttons
144 $this->add_action_buttons();
148 function definition_after_data(){
149 parent::definition_after_data();
150 $mform =& $this->_form;
151 $type =& $mform->getElement('type');
152 $typevalue = $mform->getElementValue('type');
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');
158 $type->setHelpButton(array('forumtypenews', get_string('forumtype', 'forum'), 'forum'));
159 $type->freeze();
160 $type->setPersistantFreeze(true);
162 if ($typevalue[0]=='social'){
163 $type->addOption(get_string('namesocial', 'forum'), 'social');
164 $type->freeze();
165 $type->setPersistantFreeze(true);
170 function data_preprocessing(&$default_values){
171 if (empty($default_values['scale'])){
172 $default_values['assessed'] = 0;
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;