Merge branch 'MDL-69883-310' of https://github.com/paulholden/moodle into MOODLE_310_...
[moodle.git] / auth / mnet / jump.php
blob6ee75590033e0a3617068f002f15951c14728f35
1 <?php
2 // This file is part of Moodle - http://moodle.org/
3 //
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.
8 //
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/>.
17 /**
18 * Authentication Plugin: Moodle Network Authentication
19 * Multiple host authentication support for Moodle Network.
21 * @package auth_mnet
22 * @author Martin Dougiamas
23 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
26 require_once __DIR__ . '/../../config.php';
28 // grab the GET params - wantsurl could be anything - take it
29 // with PARAM_RAW
30 $hostid = optional_param('hostid', '0', PARAM_INT);
31 $hostwwwroot = optional_param('hostwwwroot', '', PARAM_URL);
32 $wantsurl = optional_param('wantsurl', '', PARAM_RAW);
34 $url = new moodle_url('/auth/mnet/jump.php');
35 if ($hostid !== '0') $url->param('hostid', $hostid);
36 if ($hostwwwroot !== '') $url->param('hostwwwroot', $hostwwwroot);
37 if ($wantsurl !== '') $url->param('wantsurl', $wantsurl);
38 $PAGE->set_url($url);
40 if (!isloggedin() or isguestuser()) {
41 $SESSION->wantsurl = $PAGE->url->out(false);
42 redirect(get_login_url());
45 if (!is_enabled_auth('mnet')) {
46 print_error('mnetdisable');
49 // If hostid hasn't been specified, try getting it using wwwroot
50 if (!$hostid) {
51 $hostwwwroot = trim($hostwwwroot);
52 $hostwwwroot = rtrim($hostwwwroot, '/');
54 // ensure the wwwroot starts with a http or https prefix
55 if (strtolower(substr($hostwwwroot, 0, 4)) != 'http') {
56 $hostwwwroot = 'http://'.$hostwwwroot;
58 $hostid = $DB->get_field('mnet_host', 'id', array('wwwroot' => $hostwwwroot));
61 // start the mnet session and redirect browser to remote URL
62 $mnetauth = get_auth_plugin('mnet');
63 $url = $mnetauth->start_jump_session($hostid, $wantsurl);
65 if (empty($url)) {
66 print_error('DEBUG: Jump session was not started correctly or blank URL returned.'); // TODO: errors
68 redirect($url);