[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 <?php 2 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 32 */ 33 34 if (!defined('MOODLE_INTERNAL')) { 35 die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page 36 } 37 38 require_once($CFG->libdir.'/formslib.php'); 39 require_once($CFG->libdir.'/coursecatlib.php'); 40 41 /** 42 * A form for a user to request a course. 43 */ 44 class course_request_form extends moodleform { 45 function definition() { 46 global $CFG, $DB, $USER; 47 48 $mform =& $this->_form; 49 50 if ($pending = $DB->get_records('course_request', array('requester' => $USER->id))) { 51 $mform->addElement('header', 'pendinglist', get_string('coursespending')); 52 $list = array(); 53 foreach ($pending as $cp) { 54 $list[] = format_string($cp->fullname); 55 } 56 $list = implode(', ', $list); 57 $mform->addElement('static', 'pendingcourses', get_string('courses'), $list); 58 } 59 60 $mform->addElement('header','coursedetails', get_string('courserequestdetails')); 61 62 $mform->addElement('text', 'fullname', get_string('fullnamecourse'), 'maxlength="254" size="50"'); 63 $mform->addHelpButton('fullname', 'fullnamecourse'); 64 $mform->addRule('fullname', get_string('missingfullname'), 'required', null, 'client'); 65 $mform->setType('fullname', PARAM_TEXT); 66 67 $mform->addElement('text', 'shortname', get_string('shortnamecourse'), 'maxlength="100" size="20"'); 68 $mform->addHelpButton('shortname', 'shortnamecourse'); 69 $mform->addRule('shortname', get_string('missingshortname'), 'required', null, 'client'); 70 $mform->setType('shortname', PARAM_TEXT); 71 72 if (!empty($CFG->requestcategoryselection)) { 73 $displaylist = coursecat::make_categories_list(); 74 $mform->addElement('select', 'category', get_string('coursecategory'), $displaylist); 75 $mform->setDefault('category', $CFG->defaultrequestcategory); 76 $mform->addHelpButton('category', 'coursecategory'); 77 } 78 79 $mform->addElement('editor', 'summary_editor', get_string('summary'), null, course_request::summary_editor_options()); 80 $mform->addHelpButton('summary_editor', 'coursesummary'); 81 $mform->setType('summary_editor', PARAM_RAW); 82 83 $mform->addElement('header','requestreason', get_string('courserequestreason')); 84 85 $mform->addElement('textarea', 'reason', get_string('courserequestsupport'), array('rows'=>'15', 'cols'=>'50')); 86 $mform->addRule('reason', get_string('missingreqreason'), 'required', null, 'client'); 87 $mform->setType('reason', PARAM_TEXT); 88 89 $this->add_action_buttons(true, get_string('requestcourse')); 90 } 91 92 function validation($data, $files) { 93 global $DB; 94 95 $errors = parent::validation($data, $files); 96 $foundcourses = null; 97 $foundreqcourses = null; 98 99 if (!empty($data['shortname'])) { 100 $foundcourses = $DB->get_records('course', array('shortname'=>$data['shortname'])); 101 $foundreqcourses = $DB->get_records('course_request', array('shortname'=>$data['shortname'])); 102 } 103 if (!empty($foundreqcourses)) { 104 if (!empty($foundcourses)) { 105 $foundcourses = array_merge($foundcourses, $foundreqcourses); 106 } else { 107 $foundcourses = $foundreqcourses; 108 } 109 } 110 111 if (!empty($foundcourses)) { 112 foreach ($foundcourses as $foundcourse) { 113 if (!empty($foundcourse->requester)) { 114 $pending = 1; 115 $foundcoursenames[] = $foundcourse->fullname.' [*]'; 116 } else { 117 $foundcoursenames[] = $foundcourse->fullname; 118 } 119 } 120 $foundcoursenamestring = implode(',', $foundcoursenames); 121 122 $errors['shortname'] = get_string('shortnametaken', '', $foundcoursenamestring); 123 if (!empty($pending)) { 124 $errors['shortname'] .= get_string('starpending'); 125 } 126 } 127 128 return $errors; 129 } 130 } 131 132 /** 133 * A form for an administrator to reject a course request. 134 */ 135 class reject_request_form extends moodleform { 136 function definition() { 137 $mform =& $this->_form; 138 139 $mform->addElement('hidden', 'reject', 0); 140 $mform->setType('reject', PARAM_INT); 141 142 $mform->addElement('header','coursedetails', get_string('coursereasonforrejecting')); 143 144 $mform->addElement('textarea', 'rejectnotice', get_string('coursereasonforrejectingemail'), array('rows'=>'15', 'cols'=>'50')); 145 $mform->addRule('rejectnotice', get_string('missingreqreason'), 'required', null, 'client'); 146 $mform->setType('rejectnotice', PARAM_TEXT); 147 148 $this->add_action_buttons(true, get_string('reject')); 149 } 150 } 151
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |