PageRenderTime 45ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/feature/forward/forward_form.php

https://github.com/NigelCunningham/moodle-mod_forumng
PHP | 104 lines | 62 code | 13 blank | 29 comment | 6 complexity | ee9d6755ceac003981063f9be8150508 MD5 | raw file
  1. <?php
  2. // This file is part of Moodle - http://moodle.org/
  3. //
  4. // Moodle is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // Moodle is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
  16. /**
  17. * Form for email forwarding.
  18. * @package forumngfeature
  19. * @subpackage forward
  20. * @copyright 2011 The Open University
  21. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  22. */
  23. require_once($CFG->libdir.'/formslib.php');
  24. class mod_forumng_forward_form extends moodleform {
  25. function definition() {
  26. global $CFG, $USER;
  27. $mform = $this->_form;
  28. // Informational paragraph
  29. $a = (object)array(
  30. 'email' => $USER->email,
  31. 'fullname' => fullname($USER, true));
  32. $mform->addElement('static', '', '',
  33. get_string('forward_info_' .
  34. ($this->_customdata->onlyselected ? 'selected' : 'all'),
  35. 'forumngfeature_forward', $a));
  36. // Email address
  37. $mform->addElement('text', 'email', get_string('forward_email', 'forumngfeature_forward'),
  38. array('size'=>48));
  39. $mform->setType('email', PARAM_RAW);
  40. $mform->addHelpButton('email', 'forward_email', 'forumngfeature_forward');
  41. $mform->addRule('email', get_string('required'), 'required', null,
  42. 'client');
  43. // CC me
  44. $mform->addElement('checkbox', 'ccme',
  45. get_string('forward_ccme', 'forumngfeature_forward'));
  46. // Email subject
  47. $mform->addElement('text', 'subject', get_string('subject', 'forumng'),
  48. array('size'=>48));
  49. $mform->setType('subject', PARAM_TEXT);
  50. $mform->addRule('subject', get_string('maximumchars', '', 255),
  51. 'maxlength', 255, 'client');
  52. $mform->addRule('subject', get_string('required'), 'required', null, 'client');
  53. $mform->setDefault('subject', $this->_customdata->subject);
  54. // Special field just to tell javascript that we're trying to use the
  55. // html editor
  56. $mform->addElement('hidden', 'tryinghtmleditor', can_use_html_editor() ? 1 : 0);
  57. // Email message
  58. $mform->addElement('editor', 'message',
  59. get_string('forward_intro', 'forumngfeature_forward'), array('cols'=>50, 'rows'=> 15));
  60. $mform->setType('message', PARAM_RAW);
  61. // Hidden fields
  62. if ($this->_customdata->postids) {
  63. foreach ($this->_customdata->postids as $postid) {
  64. $mform->addElement('hidden', 'selectp' . $postid, 1);
  65. }
  66. } else {
  67. $mform->addElement('hidden', 'all', 1);
  68. }
  69. $mform->addElement('hidden', 'd', $this->_customdata->discussionid);
  70. $mform->addElement('hidden', 'clone', $this->_customdata->cloneid);
  71. $mform->addElement('hidden', 'postselectform', 1);
  72. $this->add_action_buttons(true, get_string('forward', 'forumngfeature_forward'));
  73. }
  74. function validation($data, $files) {
  75. $errors = parent::validation($data, $files);
  76. if (isset($data['email'])) {
  77. $emails = preg_split('~[; ]+~', $data['email']);
  78. if (count($emails) < 1) {
  79. $errors['email'] = get_string('invalidemails', 'forumng');
  80. } else {
  81. foreach ($emails as $email) {
  82. if (!validate_email($email)) {
  83. $errors['email'] = get_string('invalidemails', 'forumng');
  84. break;
  85. }
  86. }
  87. }
  88. }
  89. return $errors;
  90. }
  91. }