4 * @author Martin Dougiamas
5 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
6 * @package moodle multiauth
8 * Authentication Plugin: Moodle Network Authentication
10 * Multiple host authentication support for Moodle Network.
12 * 2006-11-01 File created.
15 require_once dirname(dirname(dirname(__FILE__
))) . '/config.php';
17 // grab the GET params - wantsurl could be anything - take it
19 $hostid = optional_param('hostid', '0', PARAM_INT
);
20 $hostwwwroot = optional_param('hostwwwroot', '', PARAM_URL
);
21 $wantsurl = optional_param('wantsurl', '', PARAM_RAW
);
23 $url = new moodle_url('/auth/mnet/jump.php');
24 if ($hostid !== '0') $url->param('hostid', $hostid);
25 if ($hostwwwroot !== '') $url->param('hostwwwroot', $hostwwwroot);
26 if ($wantsurl !== '') $url->param('wantsurl', $wantsurl);
29 if (!isloggedin() or isguestuser()) {
30 $SESSION->wantsurl
= $PAGE->url
->out(false);
31 redirect(get_login_url());
34 if (!is_enabled_auth('mnet')) {
35 print_error('mnetdisable');
38 // If hostid hasn't been specified, try getting it using wwwroot
40 $hostwwwroot = trim($hostwwwroot);
41 $hostwwwroot = rtrim($hostwwwroot, '/');
43 // ensure the wwwroot starts with a http or https prefix
44 if (strtolower(substr($hostwwwroot, 0, 4)) != 'http') {
45 $hostwwwroot = 'http://'.$hostwwwroot;
47 $hostid = $DB->get_field('mnet_host', 'id', array('wwwroot' => $hostwwwroot));
50 // start the mnet session and redirect browser to remote URL
51 $mnetauth = get_auth_plugin('mnet');
52 $url = $mnetauth->start_jump_session($hostid, $wantsurl);
55 print_error('DEBUG: Jump session was not started correctly or blank URL returned.'); // TODO: errors