PageRenderTime 40ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/moodle/course/request_form.php

https://bitbucket.org/geek745/moodle-db2
PHP | 142 lines | 83 code | 24 blank | 35 comment | 9 complexity | 22a94f23b146521f2c1a147b7f8a2e23 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, BSD-3-Clause, LGPL-2.0
  1. <?php // $Id: request_form.php,v 1.11.2.5 2009/09/26 16:23:34 skodak Exp $
  2. ///////////////////////////////////////////////////////////////////////////
  3. // //
  4. // NOTICE OF COPYRIGHT //
  5. // //
  6. // Moodle - Modular Object-Oriented Dynamic Learning Environment //
  7. // http://moodle.org //
  8. // //
  9. // Copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com //
  10. // //
  11. // This program is free software; you can redistribute it and/or modify //
  12. // it under the terms of the GNU General Public License as published by //
  13. // the Free Software Foundation; either version 2 of the License, or //
  14. // (at your option) any later version. //
  15. // //
  16. // This program is distributed in the hope that it will be useful, //
  17. // but WITHOUT ANY WARRANTY; without even the implied warranty of //
  18. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
  19. // GNU General Public License for more details: //
  20. // //
  21. // http://www.gnu.org/copyleft/gpl.html //
  22. // //
  23. ///////////////////////////////////////////////////////////////////////////
  24. /**
  25. * Forms associated with requesting courses, and having requests approved.
  26. * Note that several related forms are defined in this one file.
  27. *
  28. * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
  29. * @package course
  30. *//** */
  31. require_once($CFG->libdir.'/formslib.php');
  32. /**
  33. * A form for a user to request a course.
  34. */
  35. class course_request_form extends moodleform {
  36. function definition() {
  37. global $USER;
  38. $mform =& $this->_form;
  39. if ($pending = get_records('course_request', 'requester', $USER->id)) {
  40. $mform->addElement('header', 'pendinglist', get_string('coursespending'));
  41. $list = array();
  42. foreach ($pending as $cp) {
  43. $list[] = format_string($cp->fullname);
  44. }
  45. $list = implode(', ', $list);
  46. $mform->addElement('static', 'pendingcourses', get_string('courses'), $list);
  47. }
  48. $mform->addElement('header','coursedetails', get_string('courserequestdetails'));
  49. $mform->addElement('text', 'fullname', get_string('fullname'), 'maxlength="254" size="50"');
  50. $mform->setHelpButton('fullname', array('coursefullname', get_string('fullname')), true);
  51. $mform->addRule('fullname', get_string('missingfullname'), 'required', null, 'client');
  52. $mform->setType('fullname', PARAM_MULTILANG);
  53. $mform->addElement('text', 'shortname', get_string('shortname'), 'maxlength="15" size="20"');
  54. $mform->setHelpButton('shortname', array('courseshortname', get_string('shortname')), true);
  55. $mform->addRule('shortname', get_string('missingshortname'), 'required', null, 'client');
  56. $mform->setType('shortname', PARAM_MULTILANG);
  57. $mform->addElement('htmleditor', 'summary', get_string('summary'), array('rows'=>'15', 'cols'=>'50'));
  58. $mform->setHelpButton('summary', array('text', get_string('helptext')), true);
  59. $mform->setType('summary', PARAM_RAW);
  60. $mform->addElement('passwordunmask', 'password', get_string('enrolmentkey'), 'size="25"');
  61. $mform->setHelpButton('password', array('enrolmentkey', get_string('enrolmentkey')), true);
  62. $mform->setDefault('password', '');
  63. $mform->setType('password', PARAM_RAW);
  64. $mform->addElement('header','requestreason', get_string('courserequestreason'));
  65. $mform->addElement('textarea', 'reason', get_string('courserequestsupport'), array('rows'=>'15', 'cols'=>'50'));
  66. $mform->addRule('reason', get_string('missingreqreason'), 'required', null, 'client');
  67. $mform->setType('reason', PARAM_TEXT);
  68. $this->add_action_buttons(true, get_string('requestcourse'));
  69. }
  70. function validation($data, $files) {
  71. $errors = parent::validation($data, $files);
  72. $foundcourses = null;
  73. $foundreqcourses = null;
  74. if (!empty($data['shortname'])) {
  75. $foundcourses = get_records('course', 'shortname', $data['shortname']);
  76. $foundreqcourses = get_records('course_request', 'shortname', $data['shortname']);
  77. }
  78. if (!empty($foundreqcourses)) {
  79. if (!empty($foundcourses)) {
  80. $foundcourses = array_merge($foundcourses, $foundreqcourses);
  81. } else {
  82. $foundcourses = $foundreqcourses;
  83. }
  84. }
  85. if (!empty($foundcourses)) {
  86. foreach ($foundcourses as $foundcourse) {
  87. if (!empty($foundcourse->requester)) {
  88. $pending = 1;
  89. $foundcoursenames[] = $foundcourse->fullname.' [*]';
  90. } else {
  91. $foundcoursenames[] = $foundcourse->fullname;
  92. }
  93. }
  94. $foundcoursenamestring = implode(',', $foundcoursenames);
  95. $errors['shortname'] = get_string('shortnametaken', '', $foundcoursenamestring);
  96. if (!empty($pending)) {
  97. $errors['shortname'] .= get_string('starpending');
  98. }
  99. }
  100. return $errors;
  101. }
  102. }
  103. /**
  104. * A form for an administrator to reject a course request.
  105. */
  106. class reject_request_form extends moodleform {
  107. function definition() {
  108. $mform =& $this->_form;
  109. $mform->addElement('hidden', 'reject', 0);
  110. $mform->setType('reject', PARAM_INT);
  111. $mform->addElement('header','coursedetails', get_string('coursereasonforrejecting'));
  112. $mform->addElement('textarea', 'rejectnotice', get_string('coursereasonforrejectingemail'), array('rows'=>'15', 'cols'=>'50'));
  113. $mform->addRule('rejectnotice', get_string('missingreqreason'), 'required', null, 'client');
  114. $mform->setType('rejectnotice', PARAM_TEXT);
  115. $this->add_action_buttons(true, get_string('reject'));
  116. }
  117. }
  118. ?>