[ Index ]

PHP Cross Reference of Moodle 1.9.3 [Build 15-Oct-2008]

title

Body

[close]

/mod/forum/ -> post_form.php (source)

   1  <?php  // $Id: post_form.php,v 1.21.2.6 2008/07/18 13:18:28 ericmerrill Exp $
   2  
   3  require_once($CFG->libdir.'/formslib.php');
   4  
   5  class mod_forum_post_form extends moodleform {
   6  
   7      function definition() {
   8  
   9          global $CFG;
  10          $mform    =& $this->_form;
  11  
  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
  18  
  19  
  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));
  22  
  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'); 
  29  
  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');
  34  
  35          $mform->addElement('format', 'format', get_string('format'));
  36  
  37  
  38          if (isset($forum->id) && forum_is_forcesubscribed($forum)) {
  39  
  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'));
  43  
  44          } else if (isset($forum->forcesubscribe)&& $forum->forcesubscribe != FORUM_DISALLOWSUBSCRIBE ||
  45                      has_capability('moodle/course:manageactivities', $coursecontext)) {
  46  
  47              $options = array();
  48              $options[0] = get_string('subscribestop', 'forum');
  49              $options[1] = get_string('subscribestart', 'forum');
  50  
  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'));
  57          }
  58  
  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'));
  62  
  63          }
  64  
  65          if (empty($post->id) && has_capability('moodle/course:manageactivities', $coursecontext)) { // hack alert
  66              $mform->addElement('checkbox', 'mailnow', get_string('mailnow', 'forum'));
  67          }
  68  
  69          if (!empty($CFG->forum_enabletimedposts) && !$post->parent && has_capability('mod/forum:viewhiddentimedposts', $coursecontext)) { // hack alert
  70              $mform->addElement('header', '', get_string('displayperiod', 'forum'));
  71  
  72              $mform->addElement('date_selector', 'timestart', get_string('displaystart', 'forum'), array('optional'=>true));
  73              $mform->setHelpButton('timestart', array('displayperiod', get_string('displayperiod', 'forum'), 'forum'));
  74  
  75              $mform->addElement('date_selector', 'timeend', get_string('displayend', 'forum'), array('optional'=>true));
  76              $mform->setHelpButton('timeend', array('displayperiod', get_string('displayperiod', 'forum'), 'forum'));
  77  
  78          } else {
  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));
  84          }
  85  
  86          if (groups_get_activity_groupmode($cm, $course)) { // hack alert
  87              if (empty($post->groupid)) {
  88                  $groupname = get_string('allparticipants');
  89              } else {
  90                  $group = groups_get_group($post->groupid);
  91                  $groupname = format_string($group->name);
  92              }
  93              $mform->addElement('static', 'groupinfo', get_string('group'), $groupname);
  94          }
  95  
  96  //-------------------------------------------------------------------------------
  97          // buttons
  98          if (isset($post->edit)) { // hack alert
  99              $submit_string = get_string('savechanges');
 100          } else {
 101              $submit_string = get_string('posttoforum', 'forum');
 102          }
 103          $this->add_action_buttons(false, $submit_string);
 104  
 105          $mform->addElement('hidden', 'course');
 106          $mform->setType('course', PARAM_INT);
 107  
 108          $mform->addElement('hidden', 'forum');
 109          $mform->setType('forum', PARAM_INT);
 110  
 111          $mform->addElement('hidden', 'discussion');
 112          $mform->setType('discussion', PARAM_INT);
 113  
 114          $mform->addElement('hidden', 'parent');
 115          $mform->setType('parent', PARAM_INT);
 116  
 117          $mform->addElement('hidden', 'userid');
 118          $mform->setType('userid', PARAM_INT);
 119  
 120          $mform->addElement('hidden', 'groupid');
 121          $mform->setType('groupid', PARAM_INT);
 122  
 123          $mform->addElement('hidden', 'edit');
 124          $mform->setType('edit', PARAM_INT);
 125  
 126          $mform->addElement('hidden', 'reply');
 127          $mform->setType('reply', PARAM_INT);
 128  
 129      }
 130  
 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');
 136              }
 137          return $errors;
 138      }
 139  
 140  }
 141  ?>


Generated: Wed Jan 14 11:33:29 2009 Cross-referenced by PHPXref 0.7