Moodle 1.9.19 release
[moodle.git] / course / request_form.php
blob142b24a00923659aeedf76074d4f2d982c6ff4bb
1 <?php // $Id$
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 ///////////////////////////////////////////////////////////////////////////
26 /**
27 * Forms associated with requesting courses, and having requests approved.
28 * Note that several related forms are defined in this one file.
30 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
31 * @package course
32 *//** */
34 if (!defined('MOODLE_INTERNAL')) {
35 die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
38 require_once($CFG->libdir.'/formslib.php');
40 /**
41 * A form for a user to request a course.
43 class course_request_form extends moodleform {
44 function definition() {
45 global $USER;
47 $mform =& $this->_form;
49 if ($pending = get_records('course_request', '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);
55 $list = implode(', ', $list);
56 $mform->addElement('static', 'pendingcourses', get_string('courses'), $list);
59 $mform->addElement('header','coursedetails', get_string('courserequestdetails'));
61 $mform->addElement('text', 'fullname', get_string('fullname'), 'maxlength="254" size="50"');
62 $mform->setHelpButton('fullname', array('coursefullname', get_string('fullname')), true);
63 $mform->addRule('fullname', get_string('missingfullname'), 'required', null, 'client');
64 $mform->setType('fullname', PARAM_MULTILANG);
66 $mform->addElement('text', 'shortname', get_string('shortname'), 'maxlength="15" size="20"');
67 $mform->setHelpButton('shortname', array('courseshortname', get_string('shortname')), true);
68 $mform->addRule('shortname', get_string('missingshortname'), 'required', null, 'client');
69 $mform->setType('shortname', PARAM_MULTILANG);
71 $mform->addElement('htmleditor', 'summary', get_string('summary'), array('rows'=>'15', 'cols'=>'50'));
72 $mform->setHelpButton('summary', array('text', get_string('helptext')), true);
73 $mform->setType('summary', PARAM_RAW);
75 $mform->addElement('passwordunmask', 'password', get_string('enrolmentkey'), 'size="25"');
76 $mform->setHelpButton('password', array('enrolmentkey', get_string('enrolmentkey')), true);
77 $mform->setDefault('password', '');
78 $mform->setType('password', PARAM_RAW);
80 $mform->addElement('header','requestreason', get_string('courserequestreason'));
82 $mform->addElement('textarea', 'reason', get_string('courserequestsupport'), array('rows'=>'15', 'cols'=>'50'));
83 $mform->addRule('reason', get_string('missingreqreason'), 'required', null, 'client');
84 $mform->setType('reason', PARAM_TEXT);
86 $this->add_action_buttons(true, get_string('requestcourse'));
89 function validation($data, $files) {
90 $errors = parent::validation($data, $files);
91 $foundcourses = null;
92 $foundreqcourses = null;
94 if (!empty($data['shortname'])) {
95 $foundcourses = get_records('course', 'shortname', $data['shortname']);
96 $foundreqcourses = get_records('course_request', 'shortname', $data['shortname']);
98 if (!empty($foundreqcourses)) {
99 if (!empty($foundcourses)) {
100 $foundcourses = array_merge($foundcourses, $foundreqcourses);
101 } else {
102 $foundcourses = $foundreqcourses;
106 if (!empty($foundcourses)) {
107 foreach ($foundcourses as $foundcourse) {
108 if (!empty($foundcourse->requester)) {
109 $pending = 1;
110 $foundcoursenames[] = $foundcourse->fullname.' [*]';
111 } else {
112 $foundcoursenames[] = $foundcourse->fullname;
115 $foundcoursenamestring = implode(',', $foundcoursenames);
117 $errors['shortname'] = get_string('shortnametaken', '', $foundcoursenamestring);
118 if (!empty($pending)) {
119 $errors['shortname'] .= get_string('starpending');
123 return $errors;
128 * A form for an administrator to reject a course request.
130 class reject_request_form extends moodleform {
131 function definition() {
132 $mform =& $this->_form;
134 $mform->addElement('hidden', 'reject', 0);
135 $mform->setType('reject', PARAM_INT);
137 $mform->addElement('header','coursedetails', get_string('coursereasonforrejecting'));
139 $mform->addElement('textarea', 'rejectnotice', get_string('coursereasonforrejectingemail'), array('rows'=>'15', 'cols'=>'50'));
140 $mform->addRule('rejectnotice', get_string('missingreqreason'), 'required', null, 'client');
141 $mform->setType('rejectnotice', PARAM_TEXT);
143 $this->add_action_buttons(true, get_string('reject'));