forked from lushonline/moodle2-skillsoft-activity
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsso.php
169 lines (155 loc) · 5.52 KB
/
sso.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
<?php
/*
* @package mod-skillsoft
* @author $Author$
* @version SVN: $Header$
* @copyright 2009-2014 Martin Holden
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once('../../config.php');
require_once($CFG->dirroot.'/mod/skillsoft/locallib.php');
require_once($CFG->dirroot.'/mod/skillsoft/olsalib.php');
$a = required_param('a', PARAM_INT);
if (!empty($a)) {
if (! $skillsoft = $DB->get_record('skillsoft', array('id'=> $a))) {
print_error('Skillsoft asset is incorrect');
}
if (! $course = $DB->get_record('course', array('id'=> $skillsoft->course))) {
print_error('Course is misconfigured');
}
if (! $cm = get_coursemodule_from_instance('skillsoft', $skillsoft->id, $course->id)) {
print_error('Course Module ID was incorrect');
}
} else {
print_error('A required parameter is missing');
}
require_login($course->id, false, $cm);
$strskillsofts = get_string('modulenameplural', 'skillsoft');
$strskillsoft = get_string('modulename', 'skillsoft');
if (strtolower($skillsoft->assetid) == "sso") {
//We are using the "custom" assetid for seamless login to the home page
//of SkillPort
$lcl_actiontype = "home";
$lcl_assetid = "";
} else {
//We have a real SkillSoft AssetId
$lcl_actiontype = $CFG->skillsoft_sso_actiontype;
$lcl_assetid = $skillsoft->assetid;
}
//Section 508 Enhancement - add x508 value of $user->screenreader
if ($USER->screenreader == 1) {
$userx508 = true;
} else {
$userx508 = false;
}
if ($CFG->skillsoft_trackingmode != TRACK_TO_LMS ) {
//We are in "Track to OLSA" so perform SSO
$response = SO_GetMultiActionSignOnUrl(
$CFG->skillsoft_accountprefix.$USER->{$CFG->skillsoft_useridentifier},
$USER->firstname,
$USER->lastname,
$USER->email,
"",
"",
$lcl_actiontype,
$lcl_assetid,
$userx508
);
if (!$response->success) {
//Check if we failed because no groupcode and resubmit
if (!stripos($response->errormessage, "the property '_pathid_' or '_orgcode_' must be specified") == false)
{
$response = SO_GetMultiActionSignOnUrl(
$CFG->skillsoft_accountprefix.$USER->{$CFG->skillsoft_useridentifier},
$USER->firstname,
$USER->lastname,
$USER->email,
"",
$CFG->skillsoft_defaultssogroup,
$lcl_actiontype,
$lcl_assetid,
$userx508
);
}
}
} else {
$response = new olsaresponse(false,get_string('skillsoft_ssomodeerror','skillsoft'),NULL);
}
//Log minimal data if success
//Disabled for anything other than SSO
// issues when importing the resulting OLSA data for assets as timestamps differ for firstaccess,
//resulting in incorrect recording of attempts
if (!$skillsoft->completable) {
if ($response->success) {
$now = time();
$id = skillsoft_setFirstAccessDate($USER->id, $skillsoft->id, 1, $now);
$id = skillsoft_setLastAccessDate($USER->id, $skillsoft->id, 1, $now);
$id = skillsoft_setAccessCount($USER->id, $skillsoft->id, 1);
}
}
$waitimage = '<p><img src="'. $OUTPUT->pix_url('wait', 'skillsoft').'" class="icon" alt="'.get_string('skillsoft_waitingalt','skillsoft').'" /><br/></p>';
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<title><?php echo get_string('skillsoft_ssotitle', 'skillsoft');?></title>
<script type="text/javascript">
function doit() {
<?php
if ($response->success) {
print "var popupBlocker = false;\n";
print "var win = window.open('".$response->result->olsaURL."','_blank');\n";
print "try {\n";
print "win.focus();\n";
print "}\n";
print "catch(e) {\n";
print "popupBlocker = true;\n";
print "}\n";
print "if (popupBlocker) {\n";
print "var errorDiv = document.getElementById('errormessage');\n";
print "errorDiv.innerHTML = '".get_string('skillsoft_ssopopupdetected','skillsoft')."';\n";
//print "var olsaURL = document.createElement('a');\n";
//print "olsaURL.setAttribute('id','olsalaunchurl');\n";
//print "olsaURL.setAttribute('href','".$response->result->olsaURL."');\n";
//print "olsaURL.innerHTML = 'Click Here';\n";
//print "errorDiv.appendChild(olsaURL);\n";
print "errorDiv.style.display = 'block';\n";
print "document.getElementById('waitingmessage').style.display = 'none';\n";
print "} else { \n";
print "var errorDiv = document.getElementById('errormessage');\n";
print "errorDiv.innerHTML = '".get_string('skillsoft_ssopopupopened','skillsoft')."';\n";
print "errorDiv.style.display = 'block';\n";
print "document.getElementById('waitingmessage').style.display = 'none';\n";
print "//Close the window after 5 seconds";
print "window.open('', '_self', '');\n";
print "window.setTimeout('window.close();', 5000);\n";
print "}\n";
//print "document.location = ".'"'.$response->result->olsaURL.'";';
} else {
//error($response->errormessage);
print "document.getElementById('waitingmessage').style.display = 'none';";
print "document.getElementById('errormessage').style.display = 'block';";
}
?>
}
function closeWindow() {
window.open('', '_self', '');
window.close();
}
</script>
</head>
<body onload="doit();">
<div id="waitingmessage">
<?php echo $waitimage;?>
</div>
<div id="errormessage" style="display: none;">
<p><?php
print '<button type="button" onclick="closeWindow();">'.get_string('closewindow').'</button>';
if ($CFG->skillsoft_trackingmode != TRACK_TO_LMS) {
print '<p>'.get_string('skillsoft_ssoerror', 'skillsoft').'</p>';
}
print '<p>'.$response->errormessage.'</p>';
?></p>
</div>
</body>
</html>