MDL-51853 calendar: Whitespace fix
[moodle.git] / auth / shibboleth / login.php
blob6f984c591e7527e9dd9fbeb0112b8e862f459eff
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 //HTTPS is required in this page when $CFG->loginhttps enabled
19 $PAGE->https_required();
21 /// Define variables used in page
22 $site = get_site();
24 $loginsite = get_string("loginsite");
26 $loginurl = (!empty($CFG->alternateloginurl)) ? $CFG->alternateloginurl : '';
29 if (!empty($CFG->registerauth) or is_enabled_auth('none') or !empty($CFG->auth_instructions)) {
30 $show_instructions = true;
31 } else {
32 $show_instructions = false;
35 // Set SAML domain cookie
36 $config = get_config('auth/shibboleth');
39 $IdPs = get_idp_list($config->organization_selection);
40 if (isset($_POST['idp']) && isset($IdPs[$_POST['idp']])){
41 $selectedIdP = $_POST['idp'];
42 set_saml_cookie($selectedIdP);
44 // Redirect to SessionInitiator with entityID as argument
45 if (isset($IdPs[$selectedIdP][1]) && !empty($IdPs[$selectedIdP][1])) {
46 // For Shibbolet 1.x Service Providers
47 header('Location: '.$IdPs[$selectedIdP][1].'?providerId='. urlencode($selectedIdP) .'&target='. urlencode($CFG->httpswwwroot.'/auth/shibboleth/index.php'));
49 // For Shibbolet 2.x Service Providers
50 // header('Location: '.$IdPs[$selectedIdP][1].'?entityID='. urlencode($selectedIdP) .'&target='. urlencode($CFG->httpswwwroot.'/auth/shibboleth/index.php'));
52 } else {
53 // For Shibbolet 1.x Service Providers
54 header('Location: /Shibboleth.sso?providerId='. urlencode($selectedIdP) .'&target='. urlencode($CFG->httpswwwroot.'/auth/shibboleth/index.php'));
56 // For Shibboleth 2.x Service Providers
57 // header('Location: /Shibboleth.sso/DS?entityID='. urlencode($selectedIdP) .'&target='. urlencode($CFG->httpswwwroot.'/auth/shibboleth/index.php'));
59 } elseif (isset($_POST['idp']) && !isset($IdPs[$_POST['idp']])) {
60 $errormsg = get_string('auth_shibboleth_errormsg', 'auth_shibboleth');
63 $loginsite = get_string("loginsite");
65 $PAGE->set_url('/auth/shibboleth/login.php');
66 $PAGE->set_context(context_system::instance());
67 $PAGE->navbar->add($loginsite);
68 $PAGE->set_title("$site->fullname: $loginsite");
69 $PAGE->set_heading($site->fullname);
71 echo $OUTPUT->header();
72 include("index_form.html");
73 echo $OUTPUT->footer();