migrated mod/forum/mod.html to new formslib
[moodle.git] / mod / forum / mod_form.php
CommitLineData
535e0ab6 1<?php
2require_once ($CFG->libdir.'/formslib.php');
3class forum_mod_form extends moodleform_mod {
4
5 function definition() {
6
7 global $CFG, $FORUM_TYPES;
8 $mform =& $this->_form;
9 $renderer =& $mform->defaultRenderer();
10 $course=$this->_customdata['course'];
11
12//-------------------------------------------------------------------------------
13 $mform->addElement('header', 'general', get_string('general', 'form'));
14
15 $mform->addElement('text', 'name', get_string('forumname', 'forum'));
16 $mform->setType('name', PARAM_TEXT);
17 $mform->addRule('name', null, 'required', null, 'client');
18
19 asort($FORUM_TYPES);
20 $mform->addElement('select', 'type', get_string('forumtype', 'forum'), $FORUM_TYPES);
21 $mform->setHelpButton('type', array('forumtype', get_string('forumtype', 'forum'), 'forum'));
22 $mform->setDefault('type', 'general');
23
24 $mform->addElement('htmleditor', 'intro', get_string('forumintro', 'forum'));
25 $mform->setType('intro', PARAM_RAW);
26 $mform->addRule('intro', get_string('required'), 'required', null, 'client');
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
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);
49
50 if ($CFG->enablerssfeeds && isset($CFG->forum_enablerssfeeds) && $CFG->forum_enablerssfeeds) {
51 $mform->addElement('header', '', get_string('rss'));
52 $choices = array();
53 $choices[0] = get_string('none');
54 $choices[1] = get_string('discussions', 'forum');
55 $choices[2] = get_string('posts', 'forum');
56 $mform->addElement('select', 'rsstype', get_string('rsstype'), $choices);
57 $mform->setHelpButton('rsstype', array('rsstype', get_string('rsstype'), 'forum'));
58
59 $choices = array();
60 $choices[0] = '0';
61 $choices[1] = '1';
62 $choices[2] = '2';
63 $choices[3] = '3';
64 $choices[4] = '4';
65 $choices[5] = '5';
66 $choices[10] = '10';
67 $choices[15] = '15';
68 $choices[20] = '20';
69 $choices[25] = '25';
70 $choices[30] = '30';
71 $choices[40] = '40';
72 $choices[50] = '50';
73 $mform->addElement('select', 'rssarticles', get_string('rssarticles'), $choices);
74 $mform->setHelpButton('rssarticles', array('rssarticles', get_string('rssarticles'), 'forum'));
75 }
76
77 $mform->addElement('header', '', get_string('grade'));
78 $mform->addElement('checkbox', 'assessed', get_string('allowratings', 'data') , get_string('ratingsuse', 'data'));
79
80 $strscale = get_string('scale');
81 $strscales = get_string('scales');
82 $scales = get_scales_menu($course->id);
83 foreach ($scales as $i => $scalename) {
84 $grades[-$i] = $strscale .': '. $scalename;
85 }
86 for ($i=100; $i>=1; $i--) {
87 $grades[$i] = $i;
88 }
89 $mform->addElement('select', 'scale', get_string('grade') , $grades);
90
91 $mform->addElement('date_time_selector', 'assesstimestart', get_string('from'));
92
93 $mform->addElement('date_time_selector', 'assesstimefinish', get_string('to'));
94
95 $mform->addElement('header', '', get_string('blockafter', 'forum'));
96 $mform->addElement('text', 'warnafter', get_string('warnafter', 'forum'));
97 $mform->setType('warnafter', PARAM_INT);
98 $mform->setDefault('warnafter', '0');
99 $mform->addRule('warnafter', null, 'required', null, 'client');
100 $mform->addRule('warnafter', null, 'numeric', null, 'client');
101 $mform->setHelpButton('warnafter', array('manageposts', get_string('warnafter', 'forum'),'forum'));
102
103 $mform->addElement('text', 'blockafter', get_string('blockafter', 'forum'));
104 $mform->setType('blockafter', PARAM_INT);
105 $mform->setDefault('blockafter', '0');
106 $mform->addRule('blockafter', null, 'required', null, 'client');
107 $mform->addRule('blockafter', null, 'numeric', null, 'client');
108 $mform->setHelpButton('blockafter', array('manageposts', get_string('blockafter', 'forum'),'forum'));
109
110 $options = array();
111 $options[0] = get_string('blockperioddisabled','forum');
112 $options[60*60*24] = '1 '.get_string('day');
113 $options[60*60*24*2] = '2 '.get_string('days');
114 $options[60*60*24*3] = '3 '.get_string('days');
115 $options[60*60*24*4] = '4 '.get_string('days');
116 $options[60*60*24*5] = '5 '.get_string('days');
117 $options[60*60*24*6] = '6 '.get_string('days');
118 $options[60*60*24*7] = '1 '.get_string('week');
119 $mform->addElement('select', 'blockperiod', get_string("blockperiod", "forum") , $options);
120 $mform->setHelpButton('blockperiod', array('manageposts', get_string('blockperiod', 'forum'),'forum'));
121
122 $this->standard_coursemodule_elements();
123
124 $buttonarray=array();
125 $buttonarray[] = &MoodleQuickForm::createElement('submit', 'submit', get_string('savechanges'));
126 $buttonarray[] = &MoodleQuickForm::createElement('submit', 'cancel', get_string('cancel'));
127 $mform->addGroup($buttonarray, 'buttonar', '', array(' '), false);
128 $renderer->addStopFieldsetElements('buttonar');
129 }
130
131 function definition_after_data(){
132 $mform =& $this->_form;
133 $type=&$mform->getElement('type');
134 $typevalue=$mform->exportValue('type');
135 if ($typevalue=='news' || $typevalue=='social'){
136 $type->freeze();
137 $type->setPersistantFreeze(true);
138 }
139 }
140
141
142
143}
144?>