3 require_once($CFG->libdir
.'/formslib.php');
5 class mod_forum_post_form
extends moodleform
{
7 function definition() {
10 $mform =& $this->_form
;
12 $course = $this->_customdata
['course'];
13 $coursecontext = $this->_customdata
['coursecontext'];
14 $modcontext = $this->_customdata
['modcontext'];
15 $forum = $this->_customdata
['forum'];
16 $post = $this->_customdata
['post'];
19 // the upload manager is used directly in post precessing, moodleform::save_files() is not used yet
20 $this->set_upload_manager(new upload_manager('attachment', true, false, $course, false, $forum->maxbytes
, true, true));
22 $mform->addElement('header', 'general', '');//fill in the data depending on page params
23 //later using set_data
24 $mform->addElement('text', 'subject', get_string('subject', 'forum'), 'size="48"');
25 $mform->setType('subject', PARAM_TEXT
);
26 $mform->addRule('subject', get_string('required'), 'required', null, 'client');
28 $mform->addElement('htmleditor', 'message', get_string('message', 'forum'), array('cols'=>50, 'rows'=>30));
29 $mform->setType('message', PARAM_RAW
);
30 $mform->addRule('message', get_string('required'), 'required', null, 'client');
31 $mform->setHelpButton('message', array('reading', 'writing', 'questions', 'richtext'), false, 'editorhelpbutton');
33 $mform->addElement('format', 'format', get_string('format'));
36 if (isset($forum->id
) && forum_is_forcesubscribed($forum->id
)) {
38 $mform->addElement('static', 'subscribemessage', get_string('subscription', 'forum'), get_string('everyoneissubscribed', 'forum'));
39 $mform->addElement('hidden', 'subscribe');
40 $mform->setHelpButton('subscribemessage', array('subscription', get_string('subscription', 'forum'), 'forum'));
42 } else if (isset($forum->forcesubscribe
)&& $forum->forcesubscribe
!= FORUM_DISALLOWSUBSCRIBE ||
43 has_capability('moodle/course:manageactivities', $coursecontext)) {
46 $options[0] = get_string('subscribestop', 'forum');
47 $options[1] = get_string('subscribestart', 'forum');
49 $mform->addElement('select', 'subscribe', get_string('subscription', 'forum'), $options);
50 $mform->setHelpButton('subscribe', array('subscription', get_string('subscription', 'forum'), 'forum'));
51 } else if ($forum->forcesubscribe
== FORUM_DISALLOWSUBSCRIBE
) {
52 $mform->addElement('static', 'subscribemessage', get_string('subscription', 'forum'), get_string('disallowsubscribe', 'forum'));
53 $mform->addElement('hidden', 'subscribe');
54 $mform->setHelpButton('subscribemessage', array('subscription', get_string('subscription', 'forum'), 'forum'));
57 if ($forum->maxbytes
!= 1 && has_capability('mod/forum:createattachment', $modcontext)) { // 1 = No attachments at all
58 $mform->addElement('file', 'attachment', get_string('attachment', 'forum'));
59 $mform->setHelpButton('attachment', array('attachment', get_string('attachment', 'forum'), 'forum'));
63 if (empty($post->id
) && has_capability('moodle/course:manageactivities', $coursecontext)) {
64 $mform->addElement('checkbox', 'mailnow', get_string('mailnow', 'forum'));
67 if (!empty($CFG->forum_enabletimedposts
) && !$post->parent
) {
68 $mform->addElement('header', '', get_string('displayperiod', 'forum'));
70 $mform->addElement('date_selector', 'timestart', get_string('displaystart', 'forum'), array('optional'=>true));
71 $mform->setHelpButton('timestart', array('displayperiod', get_string('displayperiod', 'forum'), 'forum'));
73 $mform->addElement('date_selector', 'timeend', get_string('displayend', 'forum'), array('optional'=>true));
74 $mform->setHelpButton('timeend', array('displayperiod', get_string('displayperiod', 'forum'), 'forum'));
77 $mform->addElement('hidden', 'timestart');
78 $mform->setType('timestart', PARAM_INT
);
79 $mform->addElement('hidden', 'timeend');
80 $mform->setType('timeend', PARAM_INT
);
81 $mform->setConstants(array('timestart'=> 0, 'timeend'=>0));
83 //-------------------------------------------------------------------------------
85 if (isset($post->edit
)) {
86 $submit_string = get_string('savechanges');
88 $submit_string = get_string('posttoforum', 'forum');
90 $this->add_action_buttons(false, $submit_string);
92 $mform->addElement('hidden', 'course');
93 $mform->setType('course', PARAM_INT
);
95 $mform->addElement('hidden', 'forum');
96 $mform->setType('forum', PARAM_INT
);
98 $mform->addElement('hidden', 'discussion');
99 $mform->setType('discussion', PARAM_INT
);
101 $mform->addElement('hidden', 'parent');
102 $mform->setType('parent', PARAM_INT
);
104 $mform->addElement('hidden', 'userid');
105 $mform->setType('userid', PARAM_INT
);
107 $mform->addElement('hidden', 'groupid');
108 $mform->setType('groupid', PARAM_INT
);
110 $mform->addElement('hidden', 'edit');
111 $mform->setType('edit', PARAM_INT
);
113 $mform->addElement('hidden', 'reply');
114 $mform->setType('reply', PARAM_INT
);
118 function validation($data) {
120 if (($data['timeend']!=0) && ($data['timestart']!=0)
121 && $data['timeend'] <= $data['timestart']) {
122 $error['timeend'] = get_string('timestartenderror', 'forum');
124 return (count($error)==0) ?
true : $error;