Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/mod/forum/post_form.php
Go to the documentation of this file.
00001 <?php
00002 
00003 // This file is part of Moodle - http://moodle.org/
00004 //
00005 // Moodle is free software: you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation, either version 3 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // Moodle is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00017 
00024 if (!defined('MOODLE_INTERNAL')) {
00025     die('Direct access to this script is forbidden.');    
00026 }
00027 
00028 require_once($CFG->libdir.'/formslib.php');
00029 
00030 class mod_forum_post_form extends moodleform {
00031 
00032     function definition() {
00033 
00034         global $CFG;
00035         $mform    =& $this->_form;
00036 
00037         $course        = $this->_customdata['course'];
00038         $cm            = $this->_customdata['cm'];
00039         $coursecontext = $this->_customdata['coursecontext'];
00040         $modcontext    = $this->_customdata['modcontext'];
00041         $forum         = $this->_customdata['forum'];
00042         $post          = $this->_customdata['post'];
00043         // if $forum->maxbytes == '0' means we should use $course->maxbytes
00044         if ($forum->maxbytes == '0') {
00045             $forum->maxbytes = $course->maxbytes;
00046         }
00047         // TODO: add max files and max size support
00048         $editoroptions = array('maxfiles' => EDITOR_UNLIMITED_FILES, 'trusttext'=>true, 'context'=>$modcontext);
00049 
00050         $mform->addElement('header', 'general', '');//fill in the data depending on page params later using set_data
00051         $mform->addElement('text', 'subject', get_string('subject', 'forum'), 'size="48"');
00052         $mform->setType('subject', PARAM_TEXT);
00053         $mform->addRule('subject', get_string('required'), 'required', null, 'client');
00054         $mform->addRule('subject', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
00055 
00056         $mform->addElement('editor', 'message', get_string('message', 'forum'), null, $editoroptions);
00057         $mform->setType('message', PARAM_RAW);
00058         $mform->addRule('message', get_string('required'), 'required', null, 'client');
00059 
00060         if (isset($forum->id) && forum_is_forcesubscribed($forum)) {
00061 
00062             $mform->addElement('static', 'subscribemessage', get_string('subscription', 'forum'), get_string('everyoneissubscribed', 'forum'));
00063             $mform->addElement('hidden', 'subscribe');
00064             $mform->setType('subscribe', PARAM_INT);
00065             $mform->addHelpButton('subscribemessage', 'subscription', 'forum');
00066 
00067         } else if (isset($forum->forcesubscribe)&& $forum->forcesubscribe != FORUM_DISALLOWSUBSCRIBE ||
00068                    has_capability('moodle/course:manageactivities', $coursecontext)) {
00069 
00070                 $options = array();
00071                 $options[0] = get_string('subscribestop', 'forum');
00072                 $options[1] = get_string('subscribestart', 'forum');
00073 
00074                 $mform->addElement('select', 'subscribe', get_string('subscription', 'forum'), $options);
00075                 $mform->addHelpButton('subscribe', 'subscription', 'forum');
00076             } else if ($forum->forcesubscribe == FORUM_DISALLOWSUBSCRIBE) {
00077                 $mform->addElement('static', 'subscribemessage', get_string('subscription', 'forum'), get_string('disallowsubscribe', 'forum'));
00078                 $mform->addElement('hidden', 'subscribe');
00079                 $mform->setType('subscribe', PARAM_INT);
00080                 $mform->addHelpButton('subscribemessage', 'subscription', 'forum');
00081             }
00082 
00083         if (!empty($forum->maxattachments) && $forum->maxbytes != 1 && has_capability('mod/forum:createattachment', $modcontext))  {  //  1 = No attachments at all
00084             $mform->addElement('filemanager', 'attachments', get_string('attachment', 'forum'), null,
00085                 array('subdirs'=>0,
00086                       'maxbytes'=>$forum->maxbytes,
00087                       'maxfiles'=>$forum->maxattachments,
00088                       'accepted_types'=>'*',
00089                       'return_types'=>FILE_INTERNAL));
00090             $mform->addHelpButton('attachments', 'attachment', 'forum');
00091         }
00092 
00093         if (empty($post->id) && has_capability('moodle/course:manageactivities', $coursecontext)) { // hack alert
00094             $mform->addElement('checkbox', 'mailnow', get_string('mailnow', 'forum'));
00095         }
00096 
00097         if (!empty($CFG->forum_enabletimedposts) && !$post->parent && has_capability('mod/forum:viewhiddentimedposts', $coursecontext)) { // hack alert
00098             $mform->addElement('header', '', get_string('displayperiod', 'forum'));
00099 
00100             $mform->addElement('date_selector', 'timestart', get_string('displaystart', 'forum'), array('optional'=>true));
00101             $mform->addHelpButton('timestart', 'displaystart', 'forum');
00102 
00103             $mform->addElement('date_selector', 'timeend', get_string('displayend', 'forum'), array('optional'=>true));
00104             $mform->addHelpButton('timeend', 'displayend', 'forum');
00105 
00106         } else {
00107             $mform->addElement('hidden', 'timestart');
00108             $mform->setType('timestart', PARAM_INT);
00109             $mform->addElement('hidden', 'timeend');
00110             $mform->setType('timeend', PARAM_INT);
00111             $mform->setConstants(array('timestart'=> 0, 'timeend'=>0));
00112         }
00113 
00114         if (groups_get_activity_groupmode($cm, $course)) { // hack alert
00115             $groupdata = groups_get_activity_allowed_groups($cm);
00116             $groupcount = count($groupdata);
00117             $modulecontext = get_context_instance(CONTEXT_MODULE, $cm->id);
00118             $contextcheck = has_capability('mod/forum:movediscussions', $modulecontext) && empty($post->parent) && $groupcount > 1;
00119             if ($contextcheck) {
00120                 $groupinfo = array('0' => get_string('allparticipants'));
00121                 foreach ($groupdata as $grouptemp) {
00122                     $groupinfo[$grouptemp->id] = $grouptemp->name;
00123                 }
00124                 $mform->addElement('select','groupinfo', get_string('group'), $groupinfo);
00125                 $mform->setDefault('groupinfo', $post->groupid);
00126             } else {
00127                 if (empty($post->groupid)) {
00128                     $groupname = get_string('allparticipants');
00129                 } else {
00130                     $groupname = format_string($groupdata[$post->groupid]->name);
00131                 }
00132                 $mform->addElement('static', 'groupinfo', get_string('group'), $groupname);
00133             }
00134         }
00135         //-------------------------------------------------------------------------------
00136         // buttons
00137         if (isset($post->edit)) { // hack alert
00138             $submit_string = get_string('savechanges');
00139         } else {
00140             $submit_string = get_string('posttoforum', 'forum');
00141         }
00142         $this->add_action_buttons(false, $submit_string);
00143 
00144         $mform->addElement('hidden', 'course');
00145         $mform->setType('course', PARAM_INT);
00146 
00147         $mform->addElement('hidden', 'forum');
00148         $mform->setType('forum', PARAM_INT);
00149 
00150         $mform->addElement('hidden', 'discussion');
00151         $mform->setType('discussion', PARAM_INT);
00152 
00153         $mform->addElement('hidden', 'parent');
00154         $mform->setType('parent', PARAM_INT);
00155 
00156         $mform->addElement('hidden', 'userid');
00157         $mform->setType('userid', PARAM_INT);
00158 
00159         $mform->addElement('hidden', 'groupid');
00160         $mform->setType('groupid', PARAM_INT);
00161 
00162         $mform->addElement('hidden', 'edit');
00163         $mform->setType('edit', PARAM_INT);
00164 
00165         $mform->addElement('hidden', 'reply');
00166         $mform->setType('reply', PARAM_INT);
00167     }
00168 
00169     function validation($data, $files) {
00170         $errors = parent::validation($data, $files);
00171         if (($data['timeend']!=0) && ($data['timestart']!=0) && $data['timeend'] <= $data['timestart']) {
00172             $errors['timeend'] = get_string('timestartenderror', 'forum');
00173         }
00174         if (empty($data['message']['text'])) {
00175             $errors['message'] = get_string('erroremptymessage', 'forum');
00176         }
00177         if (empty($data['subject'])) {
00178             $errors['subject'] = get_string('erroremptysubject', 'forum');
00179         }
00180         return $errors;
00181     }
00182 }
00183 
 All Data Structures Namespaces Files Functions Variables Enumerations