moodle/mod/forum/post_form.php

137 lines
6.2 KiB
PHP
Raw Normal View History

2006-11-09 23:04:55 +00:00
<?php // $Id$
require_once($CFG->libdir.'/formslib.php');
class mod_forum_post_form extends moodleform {
function definition() {
global $CFG;
$mform =& $this->_form;
$course = $this->_customdata['course'];
$cm = $this->_customdata['cm'];
$coursecontext = $this->_customdata['coursecontext'];
$modcontext = $this->_customdata['modcontext'];
2006-11-09 23:04:55 +00:00
$forum = $this->_customdata['forum'];
$post = $this->_customdata['post']; // hack alert
$mform->addElement('header', 'general', '');//fill in the data depending on page params
//later using set_data
$mform->addElement('text', 'subject', get_string('subject', 'forum'), 'size="48"');
$mform->setType('subject', PARAM_TEXT);
$mform->addRule('subject', get_string('required'), 'required', null, 'client');
$mform->addRule('subject', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
$mform->addElement('htmleditor', 'message', get_string('message', 'forum'), array('cols'=>50, 'rows'=>30));
$mform->setType('message', PARAM_RAW);
$mform->addRule('message', get_string('required'), 'required', null, 'client');
$mform->setHelpButton('message', array('reading', 'writing', 'questions', 'richtext'), false, 'editorhelpbutton');
$mform->addElement('format', 'format', get_string('format'));
if (isset($forum->id) && forum_is_forcesubscribed($forum)) {
$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 ||
has_capability('moodle/course:manageactivities', $coursecontext)) {
$options = array();
$options[0] = get_string('subscribestop', 'forum');
$options[1] = get_string('subscribestart', 'forum');
$mform->addElement('select', 'subscribe', get_string('subscription', 'forum'), $options);
2006-11-09 23:04:55 +00:00
$mform->setHelpButton('subscribe', array('subscription', get_string('subscription', 'forum'), 'forum'));
} else if ($forum->forcesubscribe == FORUM_DISALLOWSUBSCRIBE) {
$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('filepicker', 'attachment', get_string('attachment', 'forum'), 'forum_submission');
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)) { // hack alert
2006-11-09 23:04:55 +00:00
$mform->addElement('checkbox', 'mailnow', get_string('mailnow', 'forum'));
}
if (!empty($CFG->forum_enabletimedposts) && !$post->parent && has_capability('mod/forum:viewhiddentimedposts', $coursecontext)) { // hack alert
2006-11-09 23:04:55 +00:00
$mform->addElement('header', '', get_string('displayperiod', 'forum'));
$mform->addElement('date_selector', 'timestart', get_string('displaystart', 'forum'), array('optional'=>true));
$mform->setHelpButton('timestart', array('displayperiod', get_string('displayperiod', 'forum'), 'forum'));
2006-11-09 23:04:55 +00:00
$mform->addElement('date_selector', 'timeend', get_string('displayend', 'forum'), array('optional'=>true));
$mform->setHelpButton('timeend', array('displayperiod', get_string('displayperiod', 'forum'), 'forum'));
2006-11-09 23:04:55 +00:00
} else {
$mform->addElement('hidden', 'timestart');
$mform->setType('timestart', PARAM_INT);
$mform->addElement('hidden', 'timeend');
$mform->setType('timeend', PARAM_INT);
$mform->setConstants(array('timestart'=> 0, 'timeend'=>0));
}
if (groups_get_activity_groupmode($cm, $course)) { // hack alert
if (empty($post->groupid)) {
$groupname = get_string('allparticipants');
} else {
$group = groups_get_group($post->groupid);
$groupname = format_string($group->name);
}
$mform->addElement('static', 'groupinfo', get_string('group'), $groupname);
}
* Added setAdvanced functionality see http://docs.moodle.org/en/Development:lib/formslib.php_setAdvanced * Added MoodleQuickForm method closeHeaderBefore($elementName); http://docs.moodle.org/en/Development:lib/formslib.php_Form_Definition#Use_Fieldsets_to_group_Form_Elements * Added moodleform method add_action_buttons(); see http://docs.moodle.org/en/Development:lib/formslib.php_Form_Definition#add_action_buttons.28.24cancel_.3D_true.2C_.24revert_.3D_true.2C_.24submitlabel.3Dnull.29.3B * is_cancelled method added to moodleform http://docs.moodle.org/en/Development:lib/formslib.php_Usage#Basic_Usage_in_A_Normal_Page * added hidden labels to elements within groups such as the date_selector select boxes and other elements in 'groups' * quiz/mod.html migrated to formslib * glossary/edit.html migrated to formslib * extended registerNoSubmitButton() functionality to automatically add js to onclick to bypass client side js input validation. * added no_submit_button_pressed() function that can be used in a similar way to is_cancelled() as a test in the main script to see if some button in the page has been pressed that is a submit button that is used for some dynamic functionality within the form and not to submit the data for the whole form. * added new condition for disabledIf which allows to disable another form element if no options are selected from within a select element. * added default 'action' for moodleform - strip_querystring(qualified_me()) http://docs.moodle.org/en/Development:lib/formslib.php_Usage#Basic_Usage_in_A_Normal_Page
2006-12-19 07:03:08 +00:00
//-------------------------------------------------------------------------------
// buttons
if (isset($post->edit)) { // hack alert
$submit_string = get_string('savechanges');
} else {
$submit_string = get_string('posttoforum', 'forum');
}
$this->add_action_buttons(false, $submit_string);
$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);
}
function validation($data, $files) {
$errors = parent::validation($data, $files);
if (($data['timeend']!=0) && ($data['timestart']!=0)
&& $data['timeend'] <= $data['timestart']) {
$errors['timeend'] = get_string('timestartenderror', 'forum');
}
return $errors;
}
}
?>