2 // This file is part of Moodle - http://moodle.org/
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 * Form to add an instance of enrol_mnet plugin
21 * @copyright 2010 David Mudrak <david@moodle.com>
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 defined('MOODLE_INTERNAL') ||
die();
27 require_once("$CFG->libdir/formslib.php");
29 class enrol_mnet_addinstance_form
extends moodleform
{
30 function definition() {
33 $mform = $this->_form
;
34 $course = $this->_customdata
['course'];
35 $enrol = $this->_customdata
['enrol'];
36 $service = $this->_customdata
['service'];
37 $coursecontext = context_course
::instance($course->id
);
39 $subscribers = $service->get_remote_subscribers();
40 $hosts = array(0 => get_string('remotesubscribersall', 'enrol_mnet'));
41 foreach ($subscribers as $hostid => $subscriber) {
42 $hosts[$hostid] = $subscriber->appname
.': '.$subscriber->hostname
.' ('.$subscriber->hosturl
.')';
44 $roles = get_assignable_roles($coursecontext);
46 $mform->addElement('header','general', get_string('pluginname', 'enrol_mnet'));
48 $mform->addElement('select', 'hostid', get_string('remotesubscriber', 'enrol_mnet'), $hosts);
49 $mform->addHelpButton('hostid', 'remotesubscriber', 'enrol_mnet');
50 $mform->addRule('hostid', get_string('required'), 'required', null, 'client');
52 $mform->addElement('select', 'roleid', get_string('roleforremoteusers', 'enrol_mnet'), $roles);
53 $mform->addHelpButton('roleid', 'roleforremoteusers', 'enrol_mnet');
54 $mform->addRule('roleid', get_string('required'), 'required', null, 'client');
55 $mform->setDefault('roleid', $enrol->get_config('roleid'));
57 $mform->addElement('text', 'name', get_string('instancename', 'enrol_mnet'));
58 $mform->addHelpButton('name', 'instancename', 'enrol_mnet');
59 $mform->setType('name', PARAM_TEXT
);
61 $mform->addElement('hidden', 'id', null);
62 $mform->setType('id', PARAM_INT
);
64 $this->add_action_buttons();
66 $this->set_data(array('id'=>$course->id
));
70 * Do not allow multiple instances for single remote host
72 * @param array $data raw form data
74 * @return array of errors
76 function validation($data, $files) {
81 if ($DB->record_exists('enrol', array('enrol' => 'mnet', 'courseid' => $data['id'], 'customint1' => $data['hostid']))) {
82 $errors['hostid'] = get_string('error_multiplehost', 'enrol_mnet');