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 $cm = $this->_customdata
['cm'];
14 $coursecontext = $this->_customdata
['coursecontext'];
15 $modcontext = $this->_customdata
['modcontext'];
16 $forum = $this->_customdata
['forum'];
17 $post = $this->_customdata
['post']; // hack alert
20 // the upload manager is used directly in post precessing, moodleform::save_files() is not used yet
21 $this->set_upload_manager(new upload_manager('attachment', true, false, $course, false, $forum->maxbytes
, true, true));
23 $mform->addElement('header', 'general', '');//fill in the data depending on page params
24 //later using set_data
25 $mform->addElement('text', 'subject', get_string('subject', 'forum'), 'size="48"');
26 $mform->setType('subject', PARAM_TEXT
);
27 $mform->addRule('subject', get_string('required'), 'required', null, 'client');
28 $mform->addRule('subject', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
30 $mform->addElement('htmleditor', 'message', get_string('message', 'forum'), array('cols'=>50, 'rows'=>30));
31 $mform->setType('message', PARAM_RAW
);
32 $mform->addRule('message', get_string('required'), 'required', null, 'client');
33 $mform->setHelpButton('message', array('reading', 'writing', 'questions', 'richtext'), false, 'editorhelpbutton');
35 $mform->addElement('format', 'format', get_string('format'));
38 if (isset($forum->id
) && forum_is_forcesubscribed($forum)) {
40 $mform->addElement('static', 'subscribemessage', get_string('subscription', 'forum'), get_string('everyoneissubscribed', 'forum'));
41 $mform->addElement('hidden', 'subscribe');
42 $mform->setHelpButton('subscribemessage', array('subscription', get_string('subscription', 'forum'), 'forum'));
44 } else if (isset($forum->forcesubscribe
)&& $forum->forcesubscribe
!= FORUM_DISALLOWSUBSCRIBE ||
45 has_capability('moodle/course:manageactivities', $coursecontext)) {
48 $options[0] = get_string('subscribestop', 'forum');
49 $options[1] = get_string('subscribestart', 'forum');
51 $mform->addElement('select', 'subscribe', get_string('subscription', 'forum'), $options);
52 $mform->setHelpButton('subscribe', array('subscription', get_string('subscription', 'forum'), 'forum'));
53 } else if ($forum->forcesubscribe
== FORUM_DISALLOWSUBSCRIBE
) {
54 $mform->addElement('static', 'subscribemessage', get_string('subscription', 'forum'), get_string('disallowsubscribe', 'forum'));
55 $mform->addElement('hidden', 'subscribe');
56 $mform->setHelpButton('subscribemessage', array('subscription', get_string('subscription', 'forum'), 'forum'));
59 if ($forum->maxbytes
!= 1 && has_capability('mod/forum:createattachment', $modcontext)) { // 1 = No attachments at all
60 $mform->addElement('file', 'attachment', get_string('attachment', 'forum'));
61 $mform->setHelpButton('attachment', array('attachment', get_string('attachment', 'forum'), 'forum'));
65 if (empty($post->id
) && has_capability('moodle/course:manageactivities', $coursecontext)) { // hack alert
66 $mform->addElement('checkbox', 'mailnow', get_string('mailnow', 'forum'));
69 if (!empty($CFG->forum_enabletimedposts
) && !$post->parent
&& has_capability('mod/forum:viewhiddentimedposts', $coursecontext)) { // hack alert
70 $mform->addElement('header', '', get_string('displayperiod', 'forum'));
72 $mform->addElement('date_selector', 'timestart', get_string('displaystart', 'forum'), array('optional'=>true));
73 $mform->setHelpButton('timestart', array('displayperiod', get_string('displayperiod', 'forum'), 'forum'));
75 $mform->addElement('date_selector', 'timeend', get_string('displayend', 'forum'), array('optional'=>true));
76 $mform->setHelpButton('timeend', array('displayperiod', get_string('displayperiod', 'forum'), 'forum'));
79 $mform->addElement('hidden', 'timestart');
80 $mform->setType('timestart', PARAM_INT
);
81 $mform->addElement('hidden', 'timeend');
82 $mform->setType('timeend', PARAM_INT
);
83 $mform->setConstants(array('timestart'=> 0, 'timeend'=>0));
86 if (groups_get_activity_groupmode($cm, $course)) { // hack alert
87 if (empty($post->groupid
)) {
88 $groupname = get_string('allparticipants');
90 $group = groups_get_group($post->groupid
);
91 $groupname = format_string($group->name
);
93 $mform->addElement('static', 'groupinfo', get_string('group'), $groupname);
96 //-------------------------------------------------------------------------------
98 if (isset($post->edit
)) { // hack alert
99 $submit_string = get_string('savechanges');
101 $submit_string = get_string('posttoforum', 'forum');
103 $this->add_action_buttons(false, $submit_string);
105 $mform->addElement('hidden', 'course');
106 $mform->setType('course', PARAM_INT
);
108 $mform->addElement('hidden', 'forum');
109 $mform->setType('forum', PARAM_INT
);
111 $mform->addElement('hidden', 'discussion');
112 $mform->setType('discussion', PARAM_INT
);
114 $mform->addElement('hidden', 'parent');
115 $mform->setType('parent', PARAM_INT
);
117 $mform->addElement('hidden', 'userid');
118 $mform->setType('userid', PARAM_INT
);
120 $mform->addElement('hidden', 'groupid');
121 $mform->setType('groupid', PARAM_INT
);
123 $mform->addElement('hidden', 'edit');
124 $mform->setType('edit', PARAM_INT
);
126 $mform->addElement('hidden', 'reply');
127 $mform->setType('reply', PARAM_INT
);
131 function validation($data, $files) {
132 $errors = parent
::validation($data, $files);
133 if (($data['timeend']!=0) && ($data['timestart']!=0)
134 && $data['timeend'] <= $data['timestart']) {
135 $errors['timeend'] = get_string('timestartenderror', 'forum');