Merge branch 'MDL-59169-master' of https://github.com/nwp90/moodle
[moodle.git] / auth / shibboleth / login.php
blob2ed931a21c80469396bd934aa1f8fe3ec88b9cde
1 <?php
3 require_once("../../config.php");
4 require_once($CFG->dirroot."/auth/shibboleth/auth.php");
6 //initialize variables
7 $errormsg = '';
9 /// Check for timed out sessions
10 if (!empty($SESSION->has_timed_out)) {
11 $session_has_timed_out = true;
12 $SESSION->has_timed_out = false;
13 } else {
14 $session_has_timed_out = false;
18 /// Define variables used in page
19 $site = get_site();
21 $loginsite = get_string("loginsite");
23 $loginurl = (!empty($CFG->alternateloginurl)) ? $CFG->alternateloginurl : '';
25 $config = get_config('auth_shibboleth');
26 if (!empty($CFG->registerauth) or is_enabled_auth('none') or !empty($config->auth_instructions)) {
27 $show_instructions = true;
28 } else {
29 $show_instructions = false;
32 $IdPs = get_idp_list($config->organization_selection);
33 if (isset($_POST['idp']) && isset($IdPs[$_POST['idp']])){
34 $selectedIdP = $_POST['idp'];
35 set_saml_cookie($selectedIdP);
37 // Redirect to SessionInitiator with entityID as argument
38 if (isset($IdPs[$selectedIdP][1]) && !empty($IdPs[$selectedIdP][1])) {
39 // For Shibbolet 1.x Service Providers
40 header('Location: '.$IdPs[$selectedIdP][1].'?providerId='. urlencode($selectedIdP) .'&target='. urlencode($CFG->wwwroot.'/auth/shibboleth/index.php'));
42 // For Shibbolet 2.x Service Providers
43 // header('Location: '.$IdPs[$selectedIdP][1].'?entityID='. urlencode($selectedIdP) .'&target='. urlencode($CFG->wwwroot.'/auth/shibboleth/index.php'));
45 } else {
46 // For Shibbolet 1.x Service Providers
47 header('Location: /Shibboleth.sso?providerId='. urlencode($selectedIdP) .'&target='. urlencode($CFG->wwwroot.'/auth/shibboleth/index.php'));
49 // For Shibboleth 2.x Service Providers
50 // header('Location: /Shibboleth.sso/DS?entityID='. urlencode($selectedIdP) .'&target='. urlencode($CFG->wwwroot.'/auth/shibboleth/index.php'));
52 } elseif (isset($_POST['idp']) && !isset($IdPs[$_POST['idp']])) {
53 $errormsg = get_string('auth_shibboleth_errormsg', 'auth_shibboleth');
56 $loginsite = get_string("loginsite");
58 $PAGE->set_url('/auth/shibboleth/login.php');
59 $PAGE->set_context(context_system::instance());
60 $PAGE->navbar->add($loginsite);
61 $PAGE->set_title("$site->fullname: $loginsite");
62 $PAGE->set_heading($site->fullname);
64 echo $OUTPUT->header();
65 include("index_form.html");
66 echo $OUTPUT->footer();