Skip to content
Snippets Groups Projects
Select Git revision
  • a1714f4838786b0359677dbc7c62d3dc647a6b19
  • master default protected
  • pymilter-1.0.4
  • pymilter-1.0.3
  • pymilter-1.0.2
  • pymilter-1.0.1
  • pymilter-1_0
  • milter-0_8_18
  • pymilter-0_9_8
  • pymilter-0_9_7
  • pymilter-0_9_6
  • pymilter-0_9_5
  • pymilter-0_9_4
  • pymilter-0_9_2
  • pymilter-0_9_1
  • pymilter-0_9_0
  • pymilter-0_8_12
  • pymilter-0_8_11
  • pymilter-0_8_10
  • pymilter-0_8_9
  • milter-0_8_8
  • milter-0_8_7
22 results

testgrey.py

Blame
  • request_form.php 12.73 KiB
    <?php
    
    ///////////////////////////////////////////////////////////////////////////
    //                                                                       //
    // NOTICE OF COPYRIGHT                                                   //
    //                                                                       //
    // Moodle - Modular Object-Oriented Dynamic Learning Environment         //
    //          http://moodle.org                                            //
    //                                                                       //
    // Copyright (C) 1999 onwards Martin Dougiamas  http://dougiamas.com     //
    //                                                                       //
    // This program is free software; you can redistribute it and/or modify  //
    // it under the terms of the GNU General Public License as published by  //
    // the Free Software Foundation; either version 2 of the License, or     //
    // (at your option) any later version.                                   //
    //                                                                       //
    // This program is distributed in the hope that it will be useful,       //
    // but WITHOUT ANY WARRANTY; without even the implied warranty of        //
    // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         //
    // GNU General Public License for more details:                          //
    //                                                                       //
    //          http://www.gnu.org/copyleft/gpl.html                         //
    //                                                                       //
    ///////////////////////////////////////////////////////////////////////////
    
    /**
     * Forms associated with requesting courses, and having requests approved.
     * Note that several related forms are defined in this one file.
     *
     * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
     * @package course
     */
    if (!defined('MOODLE_INTERNAL')) {
        die('Direct access to this script is forbidden.');    ///  It must be included from a Moodle page
    }
    
    require_once($CFG->libdir . '/formslib.php');
    // > HsH peter werner - we need course/lib.php
    require_once($CFG->dirroot . '/course/lib.php');
    require_once($CFG->dirroot . '/local/hsh/lib.php');
    // < HsH
    
    /**
     * A form for a user to request a course.
     */
    class course_request_hsh_form extends moodleform {
    
        function definition() {
            global $CFG, $DB, $USER;
    
            $mform =& $this->_form;
    
            if ($pending = $DB->get_records('local_hsh_course_request', array('requester' => $USER->id))) {
                $mform->addElement('header', 'pendinglist', get_string('yourscoursespending', 'local_hsh'));
                $list = array();
                foreach ($pending as $cp) {
                    $list[] = format_string($cp->fullname);
                }
                $list = implode(' --- ', $list);
                $mform->addElement('static', 'pendingcourses', get_string('courses', 'local_hsh'), $list);
            }
    
            $mform->addElement('header', 'coursedetails', get_string('courserequestdetails', 'local_hsh'));
    
            $mform->addElement('text', 'fullname', get_string('fullnamecourse', 'local_hsh'), 'maxlength="254" size="50"');
            $mform->addHelpButton('fullname', 'fullnamecourse', 'local_hsh');
            $mform->addRule('fullname', get_string('missingfullname', 'local_hsh'), 'required', null, 'client');
            $mform->setType('fullname', PARAM_TEXT);
    
            $mform->addElement('text', 'shortname', get_string('shortnamecourse', 'local_hsh'), 'maxlength="100" size="50"');
            $mform->addHelpButton('shortname', 'shortnamecourse', 'local_hsh');
            $mform->addRule('shortname', get_string('missingshortname', 'local_hsh'), 'required', null, 'client');
            $mform->setType('shortname', PARAM_TEXT);
    
    //        $mform->addElement('text', 'teachername', get_string('teachername', 'local_hsh'), 'maxlength="25" size="34"');
            $mform->addElement('text', 'teachername', get_string('teachername', 'local_hsh'), 'maxlength="25" size="50"');
            $mform->addHelpButton('teachername', 'teachername', 'local_hsh');
            $mform->addRule('teachername', get_string('missingteachername', 'local_hsh'), 'required', null, 'client');
            $mform->setType('teachername', PARAM_TEXT);
            $mform->setDefault('teachername', $USER->lastname);
    
            $mform->addElement('text', 'password', get_string('enrolmentkey', 'local_hsh'), 'maxlength="50" size="34"');
            $mform->addHelpButton('password', 'enrolmentkey', 'local_hsh');
            $mform->addRule('password', get_string('missingenrolmentkey', 'local_hsh'), 'required', null, 'client');
            $mform->setType('password', PARAM_RAW);
    
            $courselist = $this->get_short_categories_list();
            $displaylist = array("0" => get_string('choosecoursecategory', 'local_hsh')) + $courselist;
            $mform->addElement('select', 'category', get_string('coursecategory', 'local_hsh'), $displaylist, 'style="width: 20em;"');
            $mform->addHelpButton('category', 'coursecategory', 'local_hsh');
            $mform->addRule('category', get_string("wrongcategory", 'local_hsh'), 'required', null, 'client');
            $mform->addRule('category', get_string("wrongcategory", 'local_hsh'), 'numeric', null, 'client');
            $mform->setDefault('category', 0);
    
            $mform->addElement('header', 'semesterheader', get_string('choosesemester', 'local_hsh'));
            $semesterfieldname = 'semester';
            if ($field = $DB->get_record('customfield_field', array('shortname' => $semesterfieldname, 'type' => 'semester'))) {
                $fieldcontroller = \core_customfield\field_controller::create($field->id);
                $fieldcontroller = $this->set_configdata($fieldcontroller);
                $datacontroller = \core_customfield\data_controller::create(0, null, $fieldcontroller);
                $datacontroller->instance_form_definition($mform);
            }
    
            $mform->addElement('header', 'moodlesupport', get_string('elcsupportheader', 'local_hsh'));
            $mform->setExpanded('moodlesupport');
    
            $mform->addElement('text', 'coursecopyurl', get_string('coursecopyurl', 'local_hsh'), array('maxlength' => 254, 'size' => 34));
            $mform->addHelpButton('coursecopyurl', 'coursecopyurl', 'local_hsh');
            $mform->setType('coursecopyurl', PARAM_RAW);
    
            $mform->addElement('textarea', 'reason', get_string('elcsupportshort', 'local_hsh'), 'wrap="virtual" rows="4" cols="36"');
            $mform->addHelpButton('reason', 'elcsupportshort', 'local_hsh');
            $mform->setType('reason', PARAM_TEXT);
    
            $mform->addElement('checkbox', 'consult', get_string('elcconsult', 'local_hsh'));
            $mform->addHelpButton('consult', 'elcconsult', 'local_hsh');
    
            $mform->addElement('header', 'summaryhead', get_string('summaryhead', 'local_hsh'));
            $mform->setExpanded('summaryhead', false);
    
            $mform->addElement('editor', 'summary_editor', get_string('summary', 'local_hsh'), null, course_request_hsh::summary_editor_options());
            $mform->addHelpButton('summary_editor', 'summary', 'local_hsh');
            $mform->setType('summary_editor', PARAM_RAW, array('rows' => '25', 'cols' => '30'));
    
            $this->add_action_buttons(true, get_string('requestcourse', 'local_hsh'));
        }
    
        /**
         * > HsH peter werner
         * replaces coursecategory items
         * @static
         * @return array
         */
        private function get_short_categories_list() {
            $selectedcatecorieids = get_config('local_hsh', 'categoriesenabled');
            $selectedcatecories = core_course_category::get_many(explode(',', $selectedcatecorieids));
            $categorylist = core_course_category::make_categories_list('', 0, '$$$');
            $selected = array_intersect_key($categorylist, $selectedcatecories);
            foreach ($selected as &$actCourse) {
                $actCourseArr = explode('$$$', $actCourse);
                $actCourseSize = sizeof($actCourseArr);
                if ($actCourseSize > 1) {
                    $actCourse = '';
                    for ($i = 0; $i < $actCourseSize - 1; $i++) {
                        $actCourse .= '../ ';
                    }
                    $actCourse .= $actCourseArr[$actCourseSize - 1];
                }
            }
            return $selected;
        }
    
        // < HsH
    
    
        function validation($data, $files) {
            global $DB, $CFG;
    
            $errors = parent::validation($data, $files);
            $foundcourses = null;
            $foundreqcourses = null;
            if (!empty($data['shortname'])) {
                $data['fullname'] = \course_request_hsh::get_hsh_name($data['fullname'], $data['teachername'], $data['customfield_semester'],false);
                $data['shortname'] = \course_request_hsh::get_hsh_name($data['shortname'], $data['teachername'], $data['customfield_semester'],true);
                $foundcourses = $DB->get_records('course', array('shortname' => $data['shortname']));
                $foundreqcourses = $DB->get_records('local_hsh_course_request', array('shortname' => $data['shortname']));
            }
            if (!empty($foundreqcourses)) {
                if (!empty($foundcourses)) {
                    $foundcourses = array_merge($foundcourses, $foundreqcourses);
                } else {
                    $foundcourses = $foundreqcourses;
                }
            }
    
            if (!empty($foundcourses)) {
                foreach ($foundcourses as $foundcourse) {
                    if (!empty($foundcourse->requester)) {
                        $pending = 1;
                        $foundcoursenames[] = $foundcourse->fullname . ' [*]';
                    } else {
                        $foundcoursenames[] = $foundcourse->fullname;
                    }
                }
                $foundcoursenamestring = implode(',', $foundcoursenames);
    
                $errors['shortname'] = get_string('shortnametaken', 'local_hsh', $foundcoursenamestring);
                if (!empty($pending)) {
                    $errors['shortname'] .= get_string('starpending', 'local_hsh');
                }
            }
            // > HsH peter werner - check category
    
            if ((empty($data['category'])) || ($data['category'] == '')) {
                $errors['category'] = get_string("wrongcategory", "local_hsh");
            }
    
            if ($data['category'] == '0') {
                $errors['category'] = get_string("wrongcategory", "local_hsh");
            }
    
            if (strlen($data['coursecopyurl']) > 1 && strpos($data['coursecopyurl'], 'course/view.php') === FALSE) {
                $errors['coursecopyurl'] = get_string("nocoursecopyurl", "local_hsh");
            }
            // password should not be like shortname,fullname or summary
            if (strlen(stristr($data['shortname'], $data['password'])) > 0) {
                $errors['password'] = get_string('containspassword', 'local_hsh',
                    get_string('shortnamecourse', 'local_hsh'));
            } elseif (strlen(stristr($data['fullname'], $data['password'])) > 0) {
                $errors['password'] = get_string('containspassword', 'local_hsh',
                    get_string('fullnamecourse', 'local_hsh'));
            } elseif (strlen(stristr($data['summary_editor']['text'], $data['password'])) > 0) {
                $errors['password'] = get_string('containspassword', 'local_hsh',
                    get_string('summary', 'local_hsh'));
            }
            //end HsH
    
            return $errors;
        }
    
        // > HsH
        /**
        * > HsH Elke Kreim
        * Set new beginofsemester and add it to configdata of fieldcontroller to reduce offered semester terms in select button
        * @return object
        */
        private function set_configdata($fieldcontroller) {
    
            $today = getdate();
            $futuremonth = 12;  // two future semester terms should be displayed
            $wintertermstartmonth = \customfield_semester\data_controller::get_winterterm_startmonth();
            $configdata = $fieldcontroller->get('configdata');
            $pastyear = $today['mon'] >= $wintertermstartmonth - $configdata['defaultmonthsintofuture'] ? 0 : 1;
            // semester terms of the last year should be displayed
            $configdata["beginofsemesters"] = $today['year'] - $pastyear;
            $configdata["showmonthsintofuture"] = $futuremonth;
            $fieldcontroller->set('configdata', json_encode($configdata));
    
            return $fieldcontroller;
        }
    
        // < HsH
    
    }
    
    /**
     * A form for an administrator to reject a course request.
     */
    class reject_request_form extends moodleform {
    
        function definition() {
            $mform = & $this->_form;
    
            $mform->addElement('hidden', 'reject', 0);
            $mform->setType('reject', PARAM_INT);
    
            $mform->addElement('header', 'coursedetails', get_string('coursereasonforrejecting', 'local_hsh'));
    
            $mform->addElement('textarea', 'rejectnotice',
                get_string('coursereasonforrejectingemail', 'local_hsh'),
                array('rows' => '15', 'cols' => '50')
            );
            $mform->addRule('rejectnotice', get_string('missingreqreason', 'local_hsh'), 'required', null, 'client');
            $mform->setType('rejectnotice', PARAM_TEXT);
    
            $this->add_action_buttons(true, get_string('reject', 'local_hsh'));
        }
    
    }