MDL-11517 reserved word MOD used in table alias in questions backup code
[moodle-pu.git] / mod / forum / mod_form.php
blob18ff7699cf25f34ed3fc296c46c55210ab121c6d
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, $FORUM_TYPES, $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 $mform->setType('name', PARAM_TEXT);
16 $mform->addRule('name', null, 'required', null, 'client');
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');
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 $mform->setHelpButton('intro', array('writing', 'questions', 'richtext'), false, 'editorhelpbutton');
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'));
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'));
43 $choices = get_max_upload_sizes($CFG->maxbytes, $COURSE->maxbytes);
44 $choices[1] = get_string('uploadnotallowed');
45 $choices[0] = get_string('courseuploadlimit') . ' ('.display_size($COURSE->maxbytes).')';
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);
50 if ($CFG->enablerssfeeds && isset($CFG->forum_enablerssfeeds) && $CFG->forum_enablerssfeeds) {
51 //-------------------------------------------------------------------------------
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'));
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'));
78 //-------------------------------------------------------------------------------
79 $mform->addElement('header', '', get_string('grade'));
80 $mform->addElement('checkbox', 'assessed', get_string('allowratings', 'forum') , get_string('ratingsuse', 'forum'));
82 $mform->addElement('modgrade', 'scale', get_string('grade'), false);
83 $mform->disabledIf('scale', 'assessed');
85 $mform->addElement('checkbox', 'ratingtime', get_string('ratingtime', 'forum'));
86 $mform->disabledIf('ratingtime', 'assessed');
88 $mform->addElement('date_time_selector', 'assesstimestart', get_string('from'));
89 $mform->disabledIf('assesstimestart', 'assessed');
90 $mform->disabledIf('assesstimestart', 'ratingtime');
92 $mform->addElement('date_time_selector', 'assesstimefinish', get_string('to'));
93 $mform->disabledIf('assesstimefinish', 'assessed');
94 $mform->disabledIf('assesstimefinish', 'ratingtime');
97 //-------------------------------------------------------------------------------
98 $mform->addElement('header', '', get_string('blockafter', 'forum'));
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'));
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'));
116 $mform->disabledIf('blockafter', 'blockperiod', 'eq', 0);
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'));
124 $mform->disabledIf('warnafter', 'blockperiod', 'eq', 0);
126 //-------------------------------------------------------------------------------
127 $features = new stdClass;
128 $features->groups = true;
129 $features->groupings = true;
130 $features->groupmembersonly = true;
131 $this->standard_coursemodule_elements($features);
132 //-------------------------------------------------------------------------------
133 // buttons
134 $this->add_action_buttons();
138 function definition_after_data(){
139 $mform =& $this->_form;
140 $type=&$mform->getElement('type');
141 $typevalue=$mform->getElementValue('type');
142 //we don't want to have these appear as possible selections in the form but
143 //we want the form to display them if they are set.
144 if ($typevalue[0]=='news'){
145 $type->addOption(get_string('namenews', 'forum'), 'news');
146 $type->setHelpButton(array('forumtypenews', get_string('forumtypenews', 'forum'), 'forum'));
147 $type->freeze();
148 $type->setPersistantFreeze(true);
150 if ($typevalue[0]=='social'){
151 $type->addOption(get_string('namesocial', 'forum'), 'social');
152 $type->freeze();
153 $type->setPersistantFreeze(true);
158 function data_preprocessing(&$default_values){
159 if (empty($default_values['scale'])){
160 $default_values['assessed'] = 0;
163 if (empty($default_values['assessed'])){
164 $default_values['ratingtime'] = 0;
165 } else {
166 $default_values['ratingtime']=
167 ($default_values['assesstimestart'] && $default_values['assesstimefinish']) ? 1 : 0;