Commit | Line | Data |
---|---|---|
8bdc9cac | 1 | <?php |
e24a1f36 | 2 | |
77eddcd5 | 3 | /////////////////////////////////////////////////////////////////////////// |
4 | // // | |
5 | // NOTICE OF COPYRIGHT // | |
6 | // // | |
7 | // Moodle - Modular Object-Oriented Dynamic Learning Environment // | |
8 | // http://moodle.org // | |
9 | // // | |
10 | // Copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com // | |
11 | // // | |
12 | // This program is free software; you can redistribute it and/or modify // | |
13 | // it under the terms of the GNU General Public License as published by // | |
14 | // the Free Software Foundation; either version 2 of the License, or // | |
15 | // (at your option) any later version. // | |
16 | // // | |
17 | // This program is distributed in the hope that it will be useful, // | |
18 | // but WITHOUT ANY WARRANTY; without even the implied warranty of // | |
19 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // | |
20 | // GNU General Public License for more details: // | |
21 | // // | |
22 | // http://www.gnu.org/copyleft/gpl.html // | |
23 | // // | |
24 | /////////////////////////////////////////////////////////////////////////// | |
25 | ||
26 | /** | |
27 | * Forms associated with requesting courses, and having requests approved. | |
28 | * Note that several related forms are defined in this one file. | |
29 | * | |
30 | * @license http://www.gnu.org/copyleft/gpl.html GNU Public License | |
31 | * @package course | |
8bdc9cac | 32 | */ |
77eddcd5 | 33 | |
bfebaf64 MD |
34 | if (!defined('MOODLE_INTERNAL')) { |
35 | die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page | |
36 | } | |
37 | ||
cffb18cc | 38 | require_once($CFG->libdir.'/formslib.php'); |
e24a1f36 | 39 | |
77eddcd5 | 40 | /** |
41 | * A form for a user to request a course. | |
42 | */ | |
e13cc88f | 43 | class course_request_form extends moodleform { |
44 | function definition() { | |
59b9a140 | 45 | global $CFG, $DB, $USER; |
e452210a | 46 | |
e24a1f36 | 47 | $mform =& $this->_form; |
e13cc88f | 48 | |
e452210a | 49 | if ($pending = $DB->get_records('course_request', array('requester' => $USER->id))) { |
50 | $mform->addElement('header', 'pendinglist', get_string('coursespending')); | |
51 | $list = array(); | |
52 | foreach ($pending as $cp) { | |
53 | $list[] = format_string($cp->fullname); | |
54 | } | |
55 | $list = implode(', ', $list); | |
56 | $mform->addElement('static', 'pendingcourses', get_string('courses'), $list); | |
57 | } | |
58 | ||
77eddcd5 | 59 | $mform->addElement('header','coursedetails', get_string('courserequestdetails')); |
60 | ||
9f48fa37 DM |
61 | $mform->addElement('text', 'fullname', get_string('fullnamecourse'), 'maxlength="254" size="50"'); |
62 | $mform->addHelpButton('fullname', 'fullnamecourse'); | |
05c8db0f | 63 | $mform->addRule('fullname', get_string('missingfullname'), 'required', null, 'client'); |
071e68f9 | 64 | $mform->setType('fullname', PARAM_TEXT); |
e13cc88f | 65 | |
29cbe431 | 66 | $mform->addElement('text', 'shortname', get_string('shortnamecourse'), 'maxlength="100" size="20"'); |
5fb88219 | 67 | $mform->addHelpButton('shortname', 'shortnamecourse'); |
05c8db0f | 68 | $mform->addRule('shortname', get_string('missingshortname'), 'required', null, 'client'); |
071e68f9 | 69 | $mform->setType('shortname', PARAM_TEXT); |
e13cc88f | 70 | |
959e4f0e | 71 | if (empty($CFG->lockrequestcategory)) { |
3e15abe5 | 72 | $displaylist = core_course_category::make_categories_list('moodle/course:request'); |
4cc4ca96 | 73 | $mform->addElement('select', 'category', get_string('coursecategory'), $displaylist); |
59b9a140 | 74 | $mform->setDefault('category', $CFG->defaultrequestcategory); |
4cc4ca96 | 75 | $mform->addHelpButton('category', 'coursecategory'); |
59b9a140 FM |
76 | } |
77 | ||
8bdc9cac | 78 | $mform->addElement('editor', 'summary_editor', get_string('summary'), null, course_request::summary_editor_options()); |
5fb88219 | 79 | $mform->addHelpButton('summary_editor', 'coursesummary'); |
8bdc9cac | 80 | $mform->setType('summary_editor', PARAM_RAW); |
18a77361 | 81 | |
77eddcd5 | 82 | $mform->addElement('header','requestreason', get_string('courserequestreason')); |
83 | ||
84 | $mform->addElement('textarea', 'reason', get_string('courserequestsupport'), array('rows'=>'15', 'cols'=>'50')); | |
e24a1f36 | 85 | $mform->addRule('reason', get_string('missingreqreason'), 'required', null, 'client'); |
e13cc88f | 86 | $mform->setType('reason', PARAM_TEXT); |
87 | ||
77eddcd5 | 88 | $this->add_action_buttons(true, get_string('requestcourse')); |
e13cc88f | 89 | } |
90 | ||
a78890d5 | 91 | function validation($data, $files) { |
32648682 | 92 | global $DB; |
93 | ||
a78890d5 | 94 | $errors = parent::validation($data, $files); |
e13cc88f | 95 | $foundcourses = null; |
96 | $foundreqcourses = null; | |
97 | ||
98 | if (!empty($data['shortname'])) { | |
32648682 | 99 | $foundcourses = $DB->get_records('course', array('shortname'=>$data['shortname'])); |
100 | $foundreqcourses = $DB->get_records('course_request', array('shortname'=>$data['shortname'])); | |
e13cc88f | 101 | } |
102 | if (!empty($foundreqcourses)) { | |
103 | if (!empty($foundcourses)) { | |
e24a1f36 | 104 | $foundcourses = array_merge($foundcourses, $foundreqcourses); |
e13cc88f | 105 | } else { |
106 | $foundcourses = $foundreqcourses; | |
107 | } | |
108 | } | |
109 | ||
110 | if (!empty($foundcourses)) { | |
77eddcd5 | 111 | foreach ($foundcourses as $foundcourse) { |
112 | if (!empty($foundcourse->requester)) { | |
113 | $pending = 1; | |
114 | $foundcoursenames[] = $foundcourse->fullname.' [*]'; | |
115 | } else { | |
116 | $foundcoursenames[] = $foundcourse->fullname; | |
e13cc88f | 117 | } |
77eddcd5 | 118 | } |
119 | $foundcoursenamestring = implode(',', $foundcoursenames); | |
e13cc88f | 120 | |
77eddcd5 | 121 | $errors['shortname'] = get_string('shortnametaken', '', $foundcoursenamestring); |
122 | if (!empty($pending)) { | |
123 | $errors['shortname'] .= get_string('starpending'); | |
e13cc88f | 124 | } |
125 | } | |
e13cc88f | 126 | |
a78890d5 | 127 | return $errors; |
e13cc88f | 128 | } |
77eddcd5 | 129 | } |
130 | ||
131 | /** | |
132 | * A form for an administrator to reject a course request. | |
133 | */ | |
134 | class reject_request_form extends moodleform { | |
135 | function definition() { | |
136 | $mform =& $this->_form; | |
e13cc88f | 137 | |
77eddcd5 | 138 | $mform->addElement('hidden', 'reject', 0); |
d18e0fe6 | 139 | $mform->setType('reject', PARAM_INT); |
77eddcd5 | 140 | |
141 | $mform->addElement('header','coursedetails', get_string('coursereasonforrejecting')); | |
142 | ||
143 | $mform->addElement('textarea', 'rejectnotice', get_string('coursereasonforrejectingemail'), array('rows'=>'15', 'cols'=>'50')); | |
144 | $mform->addRule('rejectnotice', get_string('missingreqreason'), 'required', null, 'client'); | |
145 | $mform->setType('rejectnotice', PARAM_TEXT); | |
146 | ||
147 | $this->add_action_buttons(true, get_string('reject')); | |
148 | } | |
e13cc88f | 149 | } |
aa6c1ced | 150 |