Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/course/request_form.php
Go to the documentation of this file.
00001 <?php
00002 
00004 //                                                                       //
00005 // NOTICE OF COPYRIGHT                                                   //
00006 //                                                                       //
00007 // Moodle - Modular Object-Oriented Dynamic Learning Environment         //
00008 //          http://moodle.org                                            //
00009 //                                                                       //
00010 // Copyright (C) 1999 onwards Martin Dougiamas  http://dougiamas.com     //
00011 //                                                                       //
00012 // This program is free software; you can redistribute it and/or modify  //
00013 // it under the terms of the GNU General Public License as published by  //
00014 // the Free Software Foundation; either version 2 of the License, or     //
00015 // (at your option) any later version.                                   //
00016 //                                                                       //
00017 // This program is distributed in the hope that it will be useful,       //
00018 // but WITHOUT ANY WARRANTY; without even the implied warranty of        //
00019 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         //
00020 // GNU General Public License for more details:                          //
00021 //                                                                       //
00022 //          http://www.gnu.org/copyleft/gpl.html                         //
00023 //                                                                       //
00025 
00034 if (!defined('MOODLE_INTERNAL')) {
00035     die('Direct access to this script is forbidden.');    
00036 }
00037 
00038 require_once($CFG->libdir.'/formslib.php');
00039 
00043 class course_request_form extends moodleform {
00044     function definition() {
00045         global $DB, $USER;
00046 
00047         $mform =& $this->_form;
00048 
00049         if ($pending = $DB->get_records('course_request', array('requester' => $USER->id))) {
00050             $mform->addElement('header', 'pendinglist', get_string('coursespending'));
00051             $list = array();
00052             foreach ($pending as $cp) {
00053                 $list[] = format_string($cp->fullname);
00054             }
00055             $list = implode(', ', $list);
00056             $mform->addElement('static', 'pendingcourses', get_string('courses'), $list);
00057         }
00058 
00059         $mform->addElement('header','coursedetails', get_string('courserequestdetails'));
00060 
00061         $mform->addElement('text', 'fullname', get_string('fullnamecourse'), 'maxlength="254" size="50"');
00062         $mform->addHelpButton('fullname', 'fullnamecourse');
00063         $mform->addRule('fullname', get_string('missingfullname'), 'required', null, 'client');
00064         $mform->setType('fullname', PARAM_MULTILANG);
00065 
00066         $mform->addElement('text', 'shortname', get_string('shortnamecourse'), 'maxlength="100" size="20"');
00067         $mform->addHelpButton('shortname', 'shortnamecourse');
00068         $mform->addRule('shortname', get_string('missingshortname'), 'required', null, 'client');
00069         $mform->setType('shortname', PARAM_MULTILANG);
00070 
00071         $mform->addElement('editor', 'summary_editor', get_string('summary'), null, course_request::summary_editor_options());
00072         $mform->addHelpButton('summary_editor', 'coursesummary');
00073         $mform->setType('summary_editor', PARAM_RAW);
00074 
00075         $mform->addElement('header','requestreason', get_string('courserequestreason'));
00076 
00077         $mform->addElement('textarea', 'reason', get_string('courserequestsupport'), array('rows'=>'15', 'cols'=>'50'));
00078         $mform->addRule('reason', get_string('missingreqreason'), 'required', null, 'client');
00079         $mform->setType('reason', PARAM_TEXT);
00080 
00081         $this->add_action_buttons(true, get_string('requestcourse'));
00082     }
00083 
00084     function validation($data, $files) {
00085         global $DB;
00086 
00087         $errors = parent::validation($data, $files);
00088         $foundcourses = null;
00089         $foundreqcourses = null;
00090 
00091         if (!empty($data['shortname'])) {
00092             $foundcourses = $DB->get_records('course', array('shortname'=>$data['shortname']));
00093             $foundreqcourses = $DB->get_records('course_request', array('shortname'=>$data['shortname']));
00094         }
00095         if (!empty($foundreqcourses)) {
00096             if (!empty($foundcourses)) {
00097                 $foundcourses = array_merge($foundcourses, $foundreqcourses);
00098             } else {
00099                 $foundcourses = $foundreqcourses;
00100             }
00101         }
00102 
00103         if (!empty($foundcourses)) {
00104             foreach ($foundcourses as $foundcourse) {
00105                 if (!empty($foundcourse->requester)) {
00106                     $pending = 1;
00107                     $foundcoursenames[] = $foundcourse->fullname.' [*]';
00108                 } else {
00109                     $foundcoursenames[] = $foundcourse->fullname;
00110                 }
00111             }
00112             $foundcoursenamestring = implode(',', $foundcoursenames);
00113 
00114             $errors['shortname'] = get_string('shortnametaken', '', $foundcoursenamestring);
00115             if (!empty($pending)) {
00116                 $errors['shortname'] .= get_string('starpending');
00117             }
00118         }
00119 
00120         return $errors;
00121     }
00122 }
00123 
00127 class reject_request_form extends moodleform {
00128     function definition() {
00129         $mform =& $this->_form;
00130 
00131         $mform->addElement('hidden', 'reject', 0);
00132         $mform->setType('reject', PARAM_INT);
00133 
00134         $mform->addElement('header','coursedetails', get_string('coursereasonforrejecting'));
00135 
00136         $mform->addElement('textarea', 'rejectnotice', get_string('coursereasonforrejectingemail'), array('rows'=>'15', 'cols'=>'50'));
00137         $mform->addRule('rejectnotice', get_string('missingreqreason'), 'required', null, 'client');
00138         $mform->setType('rejectnotice', PARAM_TEXT);
00139 
00140         $this->add_action_buttons(true, get_string('reject'));
00141     }
00142 }
00143 
 All Data Structures Namespaces Files Functions Variables Enumerations