moodle/mod/forum/post_form.php

140 lines
6.0 KiB
PHP
Raw Normal View History

2006-11-09 23:04:55 +00:00
<?php // $Id$
require_once($CFG->libdir.'/formslib.php');
class forum_post_form extends moodleform {
function definition() {
global $CFG;
$mform =& $this->_form;
$renderer =& $mform->defaultRenderer();
$course = $this->_customdata['course'];
2006-11-09 23:04:55 +00:00
$coursecontext = $this->_customdata['coursecontext'];
$modcontext = $this->_customdata['modcontext'];
2006-11-09 23:04:55 +00:00
$forum = $this->_customdata['forum'];
$post = $this->_customdata['post'];
// the upload manager is used directly in post precessing, moodleform::save_files() is not used yet
$this->_upload_manager = new upload_manager('attachment', true, false, $course, false, $forum->maxbytes, true, true);
$this->set_max_file_size($course, $forum->maxbytes);
$mform->addElement('header', 'general', '');//fill in the data depending on page params
2006-11-09 23:04:55 +00:00
//later using set_defaults
$mform->addElement('text', 'subject', get_string('subject', 'forum'), 'size="60"');
$mform->setType('subject', PARAM_TEXT);
$mform->addRule('subject', get_string('required'), 'required', null, 'client');
2006-11-09 23:04:55 +00:00
$mform->addElement('htmleditor', 'message', get_string('message', 'forum'));
$mform->setType('message', PARAM_RAW);
$mform->addRule('message', get_string('required'), 'required', null, 'client');
$mform->addElement('format', 'format', get_string('format'));
2006-11-09 23:04:55 +00:00
if (isset($forum->id) && forum_is_forcesubscribed($forum->id)) {
2006-11-09 23:04:55 +00:00
$mform->addElement('static', 'subscribemessage', get_string('subscription', 'forum'), get_string('everyoneissubscribed', 'forum'));
$mform->addElement('hidden', 'subscribe');
2006-11-09 23:04:55 +00:00
$mform->setHelpButton('subscribemessage', array('subscription', get_string('subscription', 'forum'), 'forum'));
} else if (isset($forum->forcesubscribe)&& $forum->forcesubscribe != FORUM_DISALLOWSUBSCRIBE ||
2006-11-09 23:04:55 +00:00
has_capability('moodle/course:manageactivities', $coursecontext)) {
$options = array();
$options[0] = get_string('subscribestop', 'forum');
$options[1] = get_string('subscribestart', 'forum');
2006-11-09 23:04:55 +00:00
$mform->addElement('select', 'subscribe', get_string('subscription', 'forum'), $options);
$mform->setHelpButton('subscribe', array('subscription', get_string('subscription', 'forum'), 'forum'));
} else if ($forum->forcesubscribe == FORUM_DISALLOWSUBSCRIBE) {
2006-11-09 23:04:55 +00:00
$mform->addElement('static', 'subscribemessage', get_string('subscription', 'forum'), get_string('disallowsubscribe', 'forum'));
$mform->addElement('hidden', 'subscribe');
2006-11-09 23:04:55 +00:00
$mform->setHelpButton('subscribemessage', array('subscription', get_string('subscription', 'forum'), 'forum'));
}
if ($forum->maxbytes != 1 && has_capability('mod/forum:createattachment', $modcontext)) { // 1 = No attachments at all
$mform->addElement('file', 'attachment', get_string('attachment', 'forum'));
2006-11-29 19:53:21 +00:00
$mform->setHelpButton('attachment', array('attachment', get_string('attachment', 'forum'), 'forum'));
}
if (empty($post->id) && has_capability('moodle/course:manageactivities', $coursecontext)) {
2006-11-09 23:04:55 +00:00
$mform->addElement('checkbox', 'mailnow', get_string('mailnow', 'forum'));
}
if (!isset($discussion->timestart)) {
$discussion->timestart = 0;
}
if (!isset($discussion->timeend)) {
$discussion->timeend = 0;
}
if (!empty($CFG->forum_enabletimedposts) && !$post->parent) {
2006-11-09 23:04:55 +00:00
$mform->addElement('header', '', get_string('displayperiod', 'forum'));
$timestartgroup = array();
$timestartgroup[] = &MoodleQuickForm::createElement('date_selector', 'timestart', get_string('timestartday', 'forum'));
$timestartgroup[] = &MoodleQuickForm::createElement('checkbox', 'timestartdisabled', '', get_string('disable'));
$mform->addGroup($timestartgroup, 'timestartgroup', get_string('displaystart', 'forum'), '&nbsp;', false);
2006-11-09 23:04:55 +00:00
$mform->setHelpButton('timestartgroup', array('displayperiod', get_string('displayperiod', 'forum'), 'forum'));
$timeendgroup = array();
$timeendgroup[] = &MoodleQuickForm::createElement('date_selector', 'timeend', get_string('timeendday', 'forum'));
$timeendgroup[] = &MoodleQuickForm::createElement('checkbox', 'timeenddisabled', '', get_string('disable'));
$mform->addGroup($timeendgroup, 'timeendgroup', get_string('displayend', 'forum'), '&nbsp;', false);
2006-11-09 23:04:55 +00:00
$mform->setHelpButton('timeendgroup', array('displayperiod', get_string('displayperiod', 'forum'), 'forum'));
} else {
$mform->addElement('hidden', 'timestartdisabled', '1');
$mform->setType('timestartdisabled', PARAM_INT);
$mform->addElement('hidden', 'timeenddisabled', '1');
$mform->setType('timeenddisabled', PARAM_INT);
}
2006-11-09 23:04:55 +00:00
if (isset($post->edit)) {
$submit_string = get_string('savechanges');
} else {
$submit_string = get_string('posttoforum', 'forum');
}
$mform->addElement('submit', 'submitbutton', $submit_string);
$renderer->addStopFieldsetElements('submitbutton');
$mform->addElement('hidden', 'course');
$mform->setType('course', PARAM_INT);
$mform->addElement('hidden', 'forum');
$mform->setType('forum', PARAM_INT);
$mform->addElement('hidden', 'discussion');
$mform->setType('discussion', PARAM_INT);
$mform->addElement('hidden', 'parent');
$mform->setType('parent', PARAM_INT);
$mform->addElement('hidden', 'userid');
$mform->setType('userid', PARAM_INT);
$mform->addElement('hidden', 'groupid');
$mform->setType('groupid', PARAM_INT);
$mform->addElement('hidden', 'edit');
$mform->setType('edit', PARAM_INT);
$mform->addElement('hidden', 'reply');
$mform->setType('reply', PARAM_INT);
}
2006-11-09 23:04:55 +00:00
function validation($data) {
$error = array();
if (empty($data['timeenddisabled']) && empty($data['timestartdisabled'])
&& $data['timeend'] <= $data['timestart']) {
$error['timeendgroup'] = get_string('timestartenderror', 'forum');
}
2006-11-09 23:04:55 +00:00
return (count($error)==0) ? true : $error;
}
}
?>