Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/enrol/mnet/addinstance_form.php
Go to the documentation of this file.
00001 <?php
00002 
00003 // This file is part of Moodle - http://moodle.org/
00004 //
00005 // Moodle is free software: you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation, either version 3 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // Moodle is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00017 
00027 defined('MOODLE_INTERNAL') || die();
00028 
00029 require_once("$CFG->libdir/formslib.php");
00030 
00031 class enrol_mnet_addinstance_form extends moodleform {
00032     function definition() {
00033         global $CFG, $DB;
00034 
00035         $mform   = $this->_form;
00036         $course  = $this->_customdata['course'];
00037         $enrol   = $this->_customdata['enrol'];
00038         $service = $this->_customdata['service'];
00039         $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
00040 
00041         $subscribers = $service->get_remote_subscribers();
00042         $hosts = array(0 => get_string('remotesubscribersall', 'enrol_mnet'));
00043         foreach ($subscribers as $hostid => $subscriber) {
00044             $hosts[$hostid] = $subscriber->appname.': '.$subscriber->hostname.' ('.$subscriber->hosturl.')';
00045         }
00046         $roles = get_assignable_roles($coursecontext);
00047 
00048         $mform->addElement('header','general', get_string('pluginname', 'enrol_mnet'));
00049 
00050         $mform->addElement('select', 'hostid', get_string('remotesubscriber', 'enrol_mnet'), $hosts);
00051         $mform->addHelpButton('hostid', 'remotesubscriber', 'enrol_mnet');
00052         $mform->addRule('hostid', get_string('required'), 'required', null, 'client');
00053 
00054         $mform->addElement('select', 'roleid', get_string('roleforremoteusers', 'enrol_mnet'), $roles);
00055         $mform->addHelpButton('roleid', 'roleforremoteusers', 'enrol_mnet');
00056         $mform->addRule('roleid', get_string('required'), 'required', null, 'client');
00057         $mform->setDefault('roleid', $enrol->get_config('roleid'));
00058 
00059         $mform->addElement('text', 'name', get_string('instancename', 'enrol_mnet'));
00060         $mform->addHelpButton('name', 'instancename', 'enrol_mnet');
00061         $mform->setType('name', PARAM_TEXT);
00062 
00063         $mform->addElement('hidden', 'id', null);
00064         $mform->setType('id', PARAM_INT);
00065 
00066         $this->add_action_buttons();
00067 
00068         $this->set_data(array('id'=>$course->id));
00069     }
00070 
00077     function validation($data) {
00078         global $DB;
00079 
00080         $errors = array();
00081 
00082         if ($DB->record_exists('enrol', array('enrol' => 'mnet', 'courseid' => $data['id'], 'customint1' => $data['hostid']))) {
00083             $errors['hostid'] = get_string('error_multiplehost', 'enrol_mnet');
00084         }
00085 
00086         return $errors;
00087     }
00088 }
 All Data Structures Namespaces Files Functions Variables Enumerations