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

/course/request_form.php

https://bitbucket.org/synergylearning/campusconnect
PHP | 151 lines | 89 code | 27 blank | 35 comment | 11 complexity | c40a46592748f6bfd4e518f3678f1616 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, LGPL-3.0, GPL-3.0, LGPL-2.1, Apache-2.0, BSD-3-Clause, AGPL-3.0
  1. <?php
  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. if (!defined('MOODLE_INTERNAL')) {
  32. die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
  33. }
  34. require_once($CFG->libdir.'/formslib.php');
  35. require_once($CFG->libdir.'/coursecatlib.php');
  36. /**
  37. * A form for a user to request a course.
  38. */
  39. class course_request_form extends moodleform {
  40. function definition() {
  41. global $CFG, $DB, $USER;
  42. $mform =& $this->_form;
  43. if ($pending = $DB->get_records('course_request', array('requester' => $USER->id))) {
  44. $mform->addElement('header', 'pendinglist', get_string('coursespending'));
  45. $list = array();
  46. foreach ($pending as $cp) {
  47. $list[] = format_string($cp->fullname);
  48. }
  49. $list = implode(', ', $list);
  50. $mform->addElement('static', 'pendingcourses', get_string('courses'), $list);
  51. }
  52. $mform->addElement('header','coursedetails', get_string('courserequestdetails'));
  53. $mform->addElement('text', 'fullname', get_string('fullnamecourse'), 'maxlength="254" size="50"');
  54. $mform->addHelpButton('fullname', 'fullnamecourse');
  55. $mform->addRule('fullname', get_string('missingfullname'), 'required', null, 'client');
  56. $mform->setType('fullname', PARAM_TEXT);
  57. $mform->addElement('text', 'shortname', get_string('shortnamecourse'), 'maxlength="100" size="20"');
  58. $mform->addHelpButton('shortname', 'shortnamecourse');
  59. $mform->addRule('shortname', get_string('missingshortname'), 'required', null, 'client');
  60. $mform->setType('shortname', PARAM_TEXT);
  61. if (!empty($CFG->requestcategoryselection)) {
  62. $displaylist = coursecat::make_categories_list();
  63. $mform->addElement('select', 'category', get_string('coursecategory'), $displaylist);
  64. $mform->setDefault('category', $CFG->defaultrequestcategory);
  65. $mform->addHelpButton('category', 'coursecategory');
  66. }
  67. $mform->addElement('editor', 'summary_editor', get_string('summary'), null, course_request::summary_editor_options());
  68. $mform->addHelpButton('summary_editor', 'coursesummary');
  69. $mform->setType('summary_editor', PARAM_RAW);
  70. $mform->addElement('header','requestreason', get_string('courserequestreason'));
  71. $mform->addElement('textarea', 'reason', get_string('courserequestsupport'), array('rows'=>'15', 'cols'=>'50'));
  72. $mform->addRule('reason', get_string('missingreqreason'), 'required', null, 'client');
  73. $mform->setType('reason', PARAM_TEXT);
  74. $this->add_action_buttons(true, get_string('requestcourse'));
  75. }
  76. function validation($data, $files) {
  77. global $DB;
  78. $errors = parent::validation($data, $files);
  79. $foundcourses = null;
  80. $foundreqcourses = null;
  81. if (!empty($data['shortname'])) {
  82. $foundcourses = $DB->get_records('course', array('shortname'=>$data['shortname']));
  83. $foundreqcourses = $DB->get_records('course_request', array('shortname'=>$data['shortname']));
  84. }
  85. if (!empty($foundreqcourses)) {
  86. if (!empty($foundcourses)) {
  87. $foundcourses = array_merge($foundcourses, $foundreqcourses);
  88. } else {
  89. $foundcourses = $foundreqcourses;
  90. }
  91. }
  92. if (!empty($foundcourses)) {
  93. foreach ($foundcourses as $foundcourse) {
  94. if (!empty($foundcourse->requester)) {
  95. $pending = 1;
  96. $foundcoursenames[] = $foundcourse->fullname.' [*]';
  97. } else {
  98. $foundcoursenames[] = $foundcourse->fullname;
  99. }
  100. }
  101. $foundcoursenamestring = implode(',', $foundcoursenames);
  102. $errors['shortname'] = get_string('shortnametaken', '', $foundcoursenamestring);
  103. if (!empty($pending)) {
  104. $errors['shortname'] .= get_string('starpending');
  105. }
  106. }
  107. return $errors;
  108. }
  109. }
  110. /**
  111. * A form for an administrator to reject a course request.
  112. */
  113. class reject_request_form extends moodleform {
  114. function definition() {
  115. $mform =& $this->_form;
  116. $mform->addElement('hidden', 'reject', 0);
  117. $mform->setType('reject', PARAM_INT);
  118. $mform->addElement('header','coursedetails', get_string('coursereasonforrejecting'));
  119. $mform->addElement('textarea', 'rejectnotice', get_string('coursereasonforrejectingemail'), array('rows'=>'15', 'cols'=>'50'));
  120. $mform->addRule('rejectnotice', get_string('missingreqreason'), 'required', null, 'client');
  121. $mform->setType('rejectnotice', PARAM_TEXT);
  122. $this->add_action_buttons(true, get_string('reject'));
  123. }
  124. }