PageRenderTime 65ms CodeModel.GetById 38ms RepoModel.GetById 1ms app.codeStats 0ms

/moodle/mod/forum/post_form.php

https://bitbucket.org/geek745/moodle-db2
PHP | 143 lines | 103 code | 36 blank | 4 comment | 25 complexity | cb45376eb89da046e22992c69220fdcb MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, BSD-3-Clause, LGPL-2.0
  1. <?php // $Id: post_form.php,v 1.21.2.7 2009/09/26 16:25:48 skodak Exp $
  2. require_once($CFG->libdir.'/formslib.php');
  3. class mod_forum_post_form extends moodleform {
  4. function definition() {
  5. global $CFG;
  6. $mform =& $this->_form;
  7. $course = $this->_customdata['course'];
  8. $cm = $this->_customdata['cm'];
  9. $coursecontext = $this->_customdata['coursecontext'];
  10. $modcontext = $this->_customdata['modcontext'];
  11. $forum = $this->_customdata['forum'];
  12. $post = $this->_customdata['post']; // hack alert
  13. // the upload manager is used directly in post precessing, moodleform::save_files() is not used yet
  14. $this->set_upload_manager(new upload_manager('attachment', true, false, $course, false, $forum->maxbytes, true, true));
  15. $mform->addElement('header', 'general', '');//fill in the data depending on page params
  16. //later using set_data
  17. $mform->addElement('text', 'subject', get_string('subject', 'forum'), 'size="48"');
  18. $mform->setType('subject', PARAM_TEXT);
  19. $mform->addRule('subject', get_string('required'), 'required', null, 'client');
  20. $mform->addRule('subject', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
  21. $mform->addElement('htmleditor', 'message', get_string('message', 'forum'), array('cols'=>50, 'rows'=>30));
  22. $mform->setType('message', PARAM_RAW);
  23. $mform->addRule('message', get_string('required'), 'required', null, 'client');
  24. $mform->setHelpButton('message', array('reading', 'writing', 'questions', 'richtext'), false, 'editorhelpbutton');
  25. $mform->addElement('format', 'format', get_string('format'));
  26. if (isset($forum->id) && forum_is_forcesubscribed($forum)) {
  27. $mform->addElement('static', 'subscribemessage', get_string('subscription', 'forum'), get_string('everyoneissubscribed', 'forum'));
  28. $mform->addElement('hidden', 'subscribe');
  29. $mform->setType('subscribe', PARAM_INT);
  30. $mform->setHelpButton('subscribemessage', array('subscription', get_string('subscription', 'forum'), 'forum'));
  31. } else if (isset($forum->forcesubscribe)&& $forum->forcesubscribe != FORUM_DISALLOWSUBSCRIBE ||
  32. has_capability('moodle/course:manageactivities', $coursecontext)) {
  33. $options = array();
  34. $options[0] = get_string('subscribestop', 'forum');
  35. $options[1] = get_string('subscribestart', 'forum');
  36. $mform->addElement('select', 'subscribe', get_string('subscription', 'forum'), $options);
  37. $mform->setHelpButton('subscribe', array('subscription', get_string('subscription', 'forum'), 'forum'));
  38. } else if ($forum->forcesubscribe == FORUM_DISALLOWSUBSCRIBE) {
  39. $mform->addElement('static', 'subscribemessage', get_string('subscription', 'forum'), get_string('disallowsubscribe', 'forum'));
  40. $mform->addElement('hidden', 'subscribe');
  41. $mform->setType('subscribe', PARAM_INT);
  42. $mform->setHelpButton('subscribemessage', array('subscription', get_string('subscription', 'forum'), 'forum'));
  43. }
  44. if ($forum->maxbytes != 1 && has_capability('mod/forum:createattachment', $modcontext)) { // 1 = No attachments at all
  45. $mform->addElement('file', 'attachment', get_string('attachment', 'forum'));
  46. $mform->setHelpButton('attachment', array('attachment', get_string('attachment', 'forum'), 'forum'));
  47. }
  48. if (empty($post->id) && has_capability('moodle/course:manageactivities', $coursecontext)) { // hack alert
  49. $mform->addElement('checkbox', 'mailnow', get_string('mailnow', 'forum'));
  50. }
  51. if (!empty($CFG->forum_enabletimedposts) && !$post->parent && has_capability('mod/forum:viewhiddentimedposts', $coursecontext)) { // hack alert
  52. $mform->addElement('header', '', get_string('displayperiod', 'forum'));
  53. $mform->addElement('date_selector', 'timestart', get_string('displaystart', 'forum'), array('optional'=>true));
  54. $mform->setHelpButton('timestart', array('displayperiod', get_string('displayperiod', 'forum'), 'forum'));
  55. $mform->addElement('date_selector', 'timeend', get_string('displayend', 'forum'), array('optional'=>true));
  56. $mform->setHelpButton('timeend', array('displayperiod', get_string('displayperiod', 'forum'), 'forum'));
  57. } else {
  58. $mform->addElement('hidden', 'timestart');
  59. $mform->setType('timestart', PARAM_INT);
  60. $mform->addElement('hidden', 'timeend');
  61. $mform->setType('timeend', PARAM_INT);
  62. $mform->setConstants(array('timestart'=> 0, 'timeend'=>0));
  63. }
  64. if (groups_get_activity_groupmode($cm, $course)) { // hack alert
  65. if (empty($post->groupid)) {
  66. $groupname = get_string('allparticipants');
  67. } else {
  68. $group = groups_get_group($post->groupid);
  69. $groupname = format_string($group->name);
  70. }
  71. $mform->addElement('static', 'groupinfo', get_string('group'), $groupname);
  72. }
  73. //-------------------------------------------------------------------------------
  74. // buttons
  75. if (isset($post->edit)) { // hack alert
  76. $submit_string = get_string('savechanges');
  77. } else {
  78. $submit_string = get_string('posttoforum', 'forum');
  79. }
  80. $this->add_action_buttons(false, $submit_string);
  81. $mform->addElement('hidden', 'course');
  82. $mform->setType('course', PARAM_INT);
  83. $mform->addElement('hidden', 'forum');
  84. $mform->setType('forum', PARAM_INT);
  85. $mform->addElement('hidden', 'discussion');
  86. $mform->setType('discussion', PARAM_INT);
  87. $mform->addElement('hidden', 'parent');
  88. $mform->setType('parent', PARAM_INT);
  89. $mform->addElement('hidden', 'userid');
  90. $mform->setType('userid', PARAM_INT);
  91. $mform->addElement('hidden', 'groupid');
  92. $mform->setType('groupid', PARAM_INT);
  93. $mform->addElement('hidden', 'edit');
  94. $mform->setType('edit', PARAM_INT);
  95. $mform->addElement('hidden', 'reply');
  96. $mform->setType('reply', PARAM_INT);
  97. }
  98. function validation($data, $files) {
  99. $errors = parent::validation($data, $files);
  100. if (($data['timeend']!=0) && ($data['timestart']!=0)
  101. && $data['timeend'] <= $data['timestart']) {
  102. $errors['timeend'] = get_string('timestartenderror', 'forum');
  103. }
  104. return $errors;
  105. }
  106. }
  107. ?>