forked from catalyst/moodle-mod_skillsoft
-
Notifications
You must be signed in to change notification settings - Fork 0
/
olsalib.php
1269 lines (1076 loc) · 44.7 KB
/
olsalib.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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?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
*/
defined('MOODLE_INTERNAL') || die();
/**
* Extendes the PHP SOAPCLIENT to incorporate the USERNAMETOKEN with PasswordDigest WS-Security standard
* http://www.oasis-open.org/committees/download.php/16782/wss-v1.1-spec-os-UsernameTokenProfile.pdf
*
* Extends the PHP SOAPCLIENT to use cURL as transport to allow access through proxy servers
*
*/
class olsa_soapclient extends SoapClient{
/* ---------------------------------------------------------------------------------------------- */
/* Constants and Private Variables */
//Constants for use in code.
const WSSE_NS = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd';
const WSSE_PFX = 'wsse';
const WSU_NS = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd';
const WSU_PFX = 'wsu';
const PASSWORD_TYPE = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest';
//Private variables
private $username;
private $password;
/* ---------------------------------------------------------------------------------------------- */
/* Helper Functions */
/* Generate a GUID */
private function guid(){
mt_srand((double)microtime()*10000);//optional for php 4.2.0 and up.
$charid = strtoupper(md5(uniqid(rand(), true)));
$hyphen = chr(45);// "-"
$uuid = substr($charid, 0, 8).$hyphen
.substr($charid, 8, 4).$hyphen
.substr($charid,12, 4).$hyphen
.substr($charid,16, 4).$hyphen
.substr($charid,20,12);
return $uuid;
}
private function generate_header() {
//Get the current time
$currentTime = time();
//Create the ISO8601 formatted timestamp
$timestamp=gmdate('Y-m-d\TH:i:s', $currentTime).'Z';
//Create the expiry timestamp 5 minutes later (60*5)
$expiretimestamp=gmdate('Y-m-d\TH:i:s', $currentTime + 300).'Z';
//Generate the random Nonce. The use of rand() may repeat the word if the server is very loaded.
$nonce=mt_rand();
//Create the PasswordDigest for the usernametoken
$passdigest=base64_encode(pack('H*',sha1(pack('H*',$nonce).pack('a*',$timestamp).pack('a*',$this->password))));
//Build the header text
$header='
<wsse:Security env:mustUnderstand="1" xmlns:wsse="'.self::WSSE_NS.'" xmlns:wsu="'.self::WSU_NS.'">
<wsu:Timestamp wsu:Id="Timestamp-'.$this->guid().'">
<wsu:Created>'.$timestamp.'</wsu:Created>
<wsu:Expires>'.$expiretimestamp.'</wsu:Expires>
</wsu:Timestamp>
<wsse:UsernameToken xmlns:wsu="'.self::WSU_NS.'">
<wsse:Username>'.$this->username.'</wsse:Username>
<wsse:Password Type="'.self::PASSWORD_TYPE.'">'.$passdigest.'</wsse:Password>
<wsse:Nonce>'.base64_encode(pack('H*',$nonce)).'</wsse:Nonce>
<wsu:Created>'.$timestamp.'</wsu:Created>
</wsse:UsernameToken>
</wsse:Security>
';
$headerSoapVar=new SoapVar($header,XSD_ANYXML); //XSD_ANYXML (or 147) is the code to add xml directly into a SoapVar. Using other codes such as SOAP_ENC, it's really difficult to set the correct namespace for the variables, so the axis server rejects the xml.
$soapheader=new SoapHeader(self::WSSE_NS, "Security" , $headerSoapVar , true);
return $soapheader;
}
/* Helper function
* used for download WSDL files locally to work around poor proxy support in soapclient
* Downloaded files are cached and only redownloaded when cache is stale
*
* @param string $url - Full URL to download
* @param string $filename - Filename to save to
* @param string $cachefolder - Folder to store downloads
* @param int $cachetime - How long the saved file is valid for in seconds
* @param bool $forcedownload - Force the files to be downloaded
* @return object
*/
/*
* 13-SEP-2013 Modifications to use CACHE folder rather than UPLOAD and change name to skillsoft
*/
private function downloadfile($url, $filename , $forcedownload=false, $cachefolder='skillsoft' , $cachetime=86400) {
global $CFG;
$basefolder = str_replace('\\','/', $CFG->cachedir);
$folder=$cachefolder;
/// Create cache directory if necesary
if (!make_cache_directory($folder, false)) {
//Couldn't create temp folder
throw new Exception('Could not create WSDL Cache Folder (skillsoft): '.$basefolder.$folder);
}
$fullpath = $basefolder.'/'.$folder.'/'.$filename;
//Check if we have a cached copy
if(!file_exists($fullpath) || filemtime($fullpath) < time() - $cachetime || $forcedownload == true) {
//No copy so download
if (!extension_loaded('curl') or ($ch = curl_init($url)) === false) {
//No curl so error
} else {
$fp = fopen($fullpath, 'wb');
$ch = curl_init($url);
//Ignore SSL errors
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
curl_setopt($ch, CURLOPT_FILE, $fp);
//Force SSLv3 to workaround Openssl 1.0.1 issue
//See https://bugs.launchpad.net/ubuntu/+source/curl/+bug/595415
//curl_setopt($ch, CURLOPT_SSLVERSION, 3);
//Force CURL to use TLSv1 or later as SSLv3 deprecated on Skillsoft servers
//Bug Fix - http://code.google.com/p/moodle2-skillsoft-activity/issues/detail?id=17
curl_setopt($ch, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1);
//Setup Proxy Connection
if (!empty($CFG->proxyhost)) {
// SOCKS supported in PHP5 only
if (!empty($CFG->proxytype) and ($CFG->proxytype == 'SOCKS5')) {
if (defined('CURLPROXY_SOCKS5')) {
curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
} else {
curl_close($ch);
return false;
}
}
curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, false);
if (empty($CFG->proxyport)) {
curl_setopt($ch, CURLOPT_PROXY, $CFG->proxyhost);
} else {
curl_setopt($ch, CURLOPT_PROXY, $CFG->proxyhost.':'.$CFG->proxyport);
}
if (!empty($CFG->proxyuser) and !empty($CFG->proxypassword)) {
curl_setopt($ch, CURLOPT_PROXYUSERPWD, $CFG->proxyuser.':'.$CFG->proxypassword);
if (defined('CURLOPT_PROXYAUTH')) {
// any proxy authentication if PHP 5.1
curl_setopt($ch, CURLOPT_PROXYAUTH, CURLAUTH_BASIC | CURLAUTH_NTLM);
}
}
}
$data = curl_exec($ch);
// Check if any error occured
if(!curl_errno($ch))
{
$downloadresult = new stdClass();
$downloadresult->status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$downloadresult->filename = $filename;
$downloadresult->filepath = $basefolder.'/'.$folder.'/'.$filename;
$downloadresult->error = '';
fclose($fp);
} else {
fclose($fp);
$error = curl_error($ch);
$downloadresult = new stdClass();
$downloadresult->status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$downloadresult->filename = '';
$downloadresult->filepath = '';
$downloadresult->error = $error;
}
}
} else {
//We do so use it
$downloadresult = new stdClass();
$downloadresult->status = '200';
$downloadresult->filename = $filename;
$downloadresult->filepath = $fullpath;
$downloadresult->error = '';
}
return $downloadresult;
}
/**
* Loads an XML file (olsa.wsdl/*.xsd) and extracts the paths to embedded scema files
* and recursively downloads these and stores them. Updating the XML document with new
* paths.
*
* This is needed as SOAPClient needs to be able to resolve all files referenced in WSDL
* and when accessing internet via Proxy this is not possible.
*
* @param string $filepath - Fullpath to XML to process
* @param string $basepath - The basepath of the XML we are processing. This is needed when
* schema reference is relative.
*/
private function processExternalSchema($filepath, $basepath, $forcedownload=false) {
//This will find any embedded schemas and download them
libxml_use_internal_errors(true);
$simplexml = simplexml_load_file($filepath);
if (!$simplexml) {
throw new Exception("Failed Loading ".$filepath);
} else {
$simplexml->registerXPathNamespace("xsd", "http://www.w3.org/2001/XMLSchema");
//Select the xsd:* elements with external SCHEMA
$linkedxsd = $simplexml->xpath('//xsd:*[@schemaLocation]');
//Loop thru the external schema
foreach ($linkedxsd as $xsdnode) {
$schemaurl = $xsdnode->attributes()->schemaLocation;
//If path is "relative" we complete it using WSDL path
if (@parse_url($schemaurl, PHP_URL_SCHEME) == false) {
//It is relative
$schemafilename = $schemaurl;
$schemaurl = $basepath.$schemaurl;
} else {
$schemafilename = basename($schemaurl);
}
//Attempt to download the External schame files
if ($content = $this->downloadfile($schemaurl,$schemafilename, $forcedownload)) {
//Check for HTTP 200 response
if ($content->status != 200) {
//We have an error so throw an exception
throw new Exception($content->error);
} else {
//now we update the $xsdnode
//Shows how to change it
$xsdnode->attributes()->schemaLocation = $content->filename;
$this->processExternalSchema($content->filepath, $basepath, $forcedownload);
}
}
}
}
$simplexml->asXML($filepath);
}
/**
* Retrieve and save locally the WSDL and all referenced XSD
* if the XSD is not relative modify WSDL
*
* @param string $wsdl - Full URL
* @return string - The locally saved WSDL filepath
*/
private function retrieveWSDL($wsdl) {
global $CFG;
if ($CFG->skillsoft_clearwsdlcache == 1) {
$forcedownload = true;
} else {
$forcedownload = false;
}
//Attempt to download the WSDL
if ($wsdlcontent = $this->downloadfile($wsdl,'olsa.wsdl',$forcedownload)) {
//Check for HTTP 200 response
if ($wsdlcontent->status != 200) {
//We have an error so throw an exception
throw new Exception($wsdlcontent->error);
}
else {
$this->processExternalSchema($wsdlcontent->filepath, $CFG->skillsoft_olsaendpoint.'/../', $forcedownload);
}
}
//If we forced a redownload clear the setting
if ($CFG->skillsoft_clearwsdlcache == 1) {
set_config('skillsoft_clearwsdlcache', 0);
}
return $wsdlcontent->filepath;
}
/*It's necessary to call it if you want to set a different user and password*/
public function __setUsernameToken($username,$password){
$this->username=$username;
$this->password=$password;
}
public function __construct($wsdl,$options) {
$wsdl = $this->retrieveWSDL($wsdl);
$result = parent::__construct($wsdl, $options);
return $result;
}
/*Overload the original method, to use CURL for requests as SOAPClient has limited proxy support
* 13-SEP-2013 Modifications to signature to adhere to PHp STRICT based on code supplied by
* https://github.com/eugeneventer/moodle2-skillsoft/commit/85b4404433664e030252625f917f5e666a1c1d43
*/
public function __doRequest($request, $location, $action, $version, $one_way=0) {
global $CFG;
$headers = array(
'Method: POST',
'Connection: Keep-Alive',
'User-Agent: PHP-SOAP-CURL',
'Content-Type: text/xml; charset=utf-8',
'SOAPAction: "'.$action.'"'
);
$this->__last_request_headers = $headers;
$ch = curl_init($location);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POST, true );
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
//Force SSLv3 to workaround Openssl 1.0.1 issue
//See https://bugs.launchpad.net/ubuntu/+source/curl/+bug/595415
//curl_setopt($ch, CURLOPT_SSLVERSION, 3);
//Force CURL to use TLSv1 or later as SSLv3 deprecated on Skillsoft servers
//Bug Fix - http://code.google.com/p/moodle2-skillsoft-activity/issues/detail?id=17
curl_setopt($ch, CURLOPT_SSLVERSION, 6);
curl_setopt($ch, CURLOPT_SSL_CIPHER_LIST, 'TLSv1');
if (!empty($CFG->proxyhost)) {
// SOCKS supported in PHP5 only
if (!empty($CFG->proxytype) and ($CFG->proxytype == 'SOCKS5')) {
if (defined('CURLPROXY_SOCKS5')) {
curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
} else {
curl_close($ch);
debugging("SOCKS5 proxy is not supported in PHP4.", DEBUG_ALL);
return false;
}
}
curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, false);
if (empty($CFG->proxyport)) {
curl_setopt($ch, CURLOPT_PROXY, $CFG->proxyhost);
} else {
curl_setopt($ch, CURLOPT_PROXY, $CFG->proxyhost.':'.$CFG->proxyport);
}
if (!empty($CFG->proxyuser) and !empty($CFG->proxypassword)) {
curl_setopt($ch, CURLOPT_PROXYUSERPWD, $CFG->proxyuser.':'.$CFG->proxypassword);
if (defined('CURLOPT_PROXYAUTH')) {
// any proxy authentication if PHP 5.1
curl_setopt($ch, CURLOPT_PROXYAUTH, CURLAUTH_BASIC | CURLAUTH_NTLM);
}
}
}
$response = curl_exec($ch);
return $response;
}
/*Overload the original method, to use CURL for requests as SOAPClient has limited proxy support
*
*/
public function __getLastRequestHeaders() {
return implode("\n", $this->__last_request_headers)."\n";
}
/*Overload the original method, and add the WS-Security Header */
/* 13-SEP-2013 Modifications to signature to adhere to PHp STRICT based on code supplied by
* https://github.com/eugeneventer/moodle2-skillsoft/commit/85b4404433664e030252625f917f5e666a1c1d43
*/
public function __soapCall($function_name,$arguments,$options=array(),$input_headers=null,&$output_headers=array()){
$result = parent::__soapCall($function_name,$arguments,$options,$this->generate_header());
return $result;
}
}
/**
* Standard object for an OLSA response
*
* @author Martin Holden
* @copyright 2009-2011 Martin Holden
*/
class olsaresponse implements IteratorAggregate {
private $success; //true/false
private $errormessage; //null or the olsa error message;
private $result; //the object
/**
* @param bool $success indicates if OLSA call was successful
* @param string $errormessage error message or NULL
* @param object $result the OLSA response object
*/
public function __construct($success,$errormessage,$result)
{
$this->success = $success;
$this->errormessage = $errormessage;
$this->result = $result;
}
public function __set($var, $value) {
$this->$var = $value;
}
public function __get($var) {
return $this->$var;
}
// Create an iterator because private/protected vars can't
// be seen by json_encode().
public function getIterator() {
$iArray['success'] = $this->success;
$iArray['errormessage'] = $this->errormessage;
$iArray['results'] = $this->result;
return new ArrayIterator($iArray);
}
}
/**
* Format a string from OLSA so it can be output
*
* This function replaces any linefeeds with <br /> and
* processes the string using addslashes
*
* @param string $text
* @return string
*/
function olsadatatohtml($text) {
return addcslashes(strtr($text, array("\r\n" => '<br />', "\r" => '<br />', "\n" => '<br />')),"\\\'\"&\n\r<>");
}
/**
* Helper function to confirm OLSA settings configured and valid
*
* TO DO: Add URl check to confirm WSDL present
* @return book
*/
function isolsaconfigurationset() {
global $CFG;
if (!isset($CFG->skillsoft_olsaendpoint, $CFG->skillsoft_olsacustomerid, $CFG->skillsoft_olsasharedsecret)) {
return false;
} else {
//They are set BUT are they empty
if (empty($CFG->skillsoft_olsaendpoint) || empty($CFG->skillsoft_olsacustomerid) || empty($CFG->skillsoft_olsasharedsecret)) {
return false;
}
}
return true;
}
/**
* Retrieves the metadata for the supplied SkillSoft assetid
*
* @param string $assetid the SkillSoft assetid
* @return olsasoapresponse olsasoapresponse->result is an object representing the deserialised XML response
*/
function AI_GetXmlAssetMetaData($assetid) {
global $CFG;
if (!isolsaconfigurationset()) {
$response = new olsaresponse(false,get_string('skillsoft_olsasettingsmissing','skillsoft'),NULL);
} else {
//Set local OLSA Variables
$endpoint = $CFG->skillsoft_olsaendpoint;
$customerId = $CFG->skillsoft_olsacustomerid;
$sharedsecret = $CFG->skillsoft_olsasharedsecret;
//Specify the WSDL using the EndPoint
$wsdlurl = $endpoint.'?WSDL';
//Specify the SOAP Client Options
$options = array(
"trace" => 0,
"exceptions" => 0,
"soap_version" => SOAP_1_2,
"cache_wsdl" => WSDL_CACHE_BOTH,
"encoding"=> "UTF-8"
);
//Create a new instance of the OLSA Soap Client
$client = new olsa_soapclient($wsdlurl,$options);
//Create the USERNAMETOKEN
$client->__setUsernameToken($customerId,$sharedsecret);
//Create the Request
$GetXmlAssetMetaDataRequest = array(
"customerId" => $customerId,
"assetId" => $assetid,
);
//Call the WebService and stored result in $result
$result=$client->__soapCall('AI_GetXmlAssetMetaData',array('parameters'=>$GetXmlAssetMetaDataRequest));
if (is_soap_fault($result)) {
if (stripos($result->getmessage(),'security token could not be authenticated or authorized')) {
//Authentication Failure
//print_error('olsassoapauthentication','skillsoft');
$response = new olsaresponse(false,get_string('skillsoft_olsassoapauthentication','skillsoft'),NULL);
} elseif (stripos($result->getmessage(), 'does not exist.')){
//Asset ID is invalid
//print_error('olsassoapinvalidassetid','skillsoft','',$id);
$response = new olsaresponse(false,get_string('skillsoft_olsassoapinvalidassetid','skillsoft',$assetid),NULL);
} else {
//General SOAP Fault
//print_error('olsassoapfault','skillsoft','',$result->getmessage());
$response = new olsaresponse(false,get_string('skillsoft_olsassoapfault','skillsoft',$result->getmessage()),NULL);
}
} else {
$asset = $result->metadata->asset;
$response = new olsaresponse(true,'',$asset);
}
}
return $response;
}
/**
* Retrieves the usage data for the supplied SkillSoft assetid
* for the specified user
*
* @param string $userid the userid
* @param string $assetid the SkillSoft assetid
* @param bool $summarylevel return only summary details
* @return olsasoapresponse olsasoapresponse->result is an object representing the deserialised XML response
*/
function UD_GetAssetResults($userid,$assetid,$summarylevel=true) {
global $CFG;
if (!isolsaconfigurationset()) {
$response = new olsaresponse(false,get_string('skillsoft_olsasettingsmissing','skillsoft'),NULL);
} else {
//Set local OLSA Variables
$endpoint = $CFG->skillsoft_olsaendpoint;
$customerId = $CFG->skillsoft_olsacustomerid;
$sharedsecret = $CFG->skillsoft_olsasharedsecret;
//Specify the WSDL using the EndPoint
$wsdlurl = $endpoint.'?WSDL';
//Specify the SOAP Client Options
$options = array(
"trace" => 0,
"exceptions" => 0,
"soap_version" => SOAP_1_2,
"cache_wsdl" => WSDL_CACHE_BOTH,
"encoding"=> "UTF-8"
);
//Create a new instance of the OLSA Soap Client
$client = new olsa_soapclient($wsdlurl,$options);
//Create the USERNAMETOKEN
$client->__setUsernameToken($customerId,$sharedsecret);
//Create the Request
if (empty($assetid)) {
$GetAssetResultsRequest = array(
"customerId" => $customerId,
"userName" => $userid,
"summaryLevel" => $summarylevel,
);
} else {
$GetAssetResultsRequest = array(
"customerId" => $customerId,
"userName" => $userid,
"assetId" => $assetid,
"summaryLevel" => $summarylevel,
);
}
//Call the WebService and stored result in $result
$result=$client->__soapCall('UD_GetAssetResults',array('parameters'=>$GetAssetResultsRequest));
if (is_soap_fault($result)) {
if (!stripos($result->getmessage(),'security token could not be authenticated or authorized') == false) {
//Authentication Failure
$response = new olsaresponse(false,get_string('skillsoft_olsassoapauthentication','skillsoft'),NULL);
} elseif (!stripos($result->getmessage(), 'The specified course could not be found') == false){
//Asset ID is invalid
$response = new olsaresponse(false,get_string('skillsoft_olsassoapinvalidassetid','skillsoft',$assetid),NULL);
} elseif (!stripos($result->getmessage(), 'does not exist, or is not in Source Users Scope') == false){
//User ID is invalid
$response = new olsaresponse(false,get_string('skillsoft_olsassoapinvaliduserid','skillsoft',$userid),NULL);
} elseif (!stripos($result->getmessage(), 'are no results for') == false){
//No results repond as OK with NULL object
$response = new olsaresponse(true,'',NULL);
} else {
//General SOAP Fault
//print_error('olsassoapfault','skillsoft','',$result->getmessage());
$response = new olsaresponse(false,get_string('skillsoft_olsassoapfault','skillsoft',$result->getmessage()),NULL);
}
} else {
$results = $result->RESULTS;
$response = new olsaresponse(true,'',$results);
}
}
return $response;
}
/**
* Initialise the OnDemandCommunications
*
* @return olsasoapresponse olsasoapresponse->result is a NULL object
*/
function OC_InitializeTrackingData() {
global $CFG;
if (!isolsaconfigurationset()) {
$response = new olsaresponse(false,get_string('skillsoft_olsasettingsmissing','skillsoft'),NULL);
} else {
//Set local OLSA Variables
$endpoint = $CFG->skillsoft_olsaendpoint;
$customerId = $CFG->skillsoft_olsacustomerid;
$sharedsecret = $CFG->skillsoft_olsasharedsecret;
//Specify the WSDL using the EndPoint
$wsdlurl = $endpoint.'?WSDL';
//Specify the SOAP Client Options
$options = array(
"trace" => 0,
"exceptions" => 0,
"soap_version" => SOAP_1_2,
"cache_wsdl" => WSDL_CACHE_BOTH,
"encoding"=> "UTF-8"
);
//Create a new instance of the OLSA Soap Client
$client = new olsa_soapclient($wsdlurl,$options);
//Create the USERNAMETOKEN
$client->__setUsernameToken($customerId,$sharedsecret);
//Create the Request
$InitializeTrackingDataRequest = array(
"customerId" => $customerId,
);
//Call the WebService and stored result in $result
$result=$client->__soapCall('OC_InitializeTrackingData',array('parameters'=>$InitializeTrackingDataRequest));
if (is_soap_fault($result)) {
if (!stripos($result->getmessage(),'security token could not be authenticated or authorized') == false) {
//Authentication Failure
$response = new olsaresponse(false,get_string('skillsoft_olsassoapauthentication','skillsoft'),NULL);
} else {
//General SOAP Fault
//print_error('olsassoapfault','skillsoft','',$result->getmessage());
$response = new olsaresponse(false,get_string('skillsoft_olsassoapfault','skillsoft',$result->getmessage()),NULL);
}
} else {
$response = new olsaresponse(true,'',NULL);
}
}
return $response;
}
/**
* Acknowledge the TDRs received the OnDemandCommunications
* Only use this call after the associated TDRs have been truly processed
* and persisted on the caller's side and if OC_GetTrackingData returned
* a non-empty result.
*
* @param string $handle the ODC handle to acknowledge
* @return olsasoapresponse olsasoapresponse->result is a NULL object
*/
function OC_AcknowledgeTrackingData($handle) {
global $CFG;
if (!isolsaconfigurationset()) {
$response = new olsaresponse(false,get_string('skillsoft_olsasettingsmissing','skillsoft'),NULL);
} else {
//Set local OLSA Variables
$endpoint = $CFG->skillsoft_olsaendpoint;
$customerId = $CFG->skillsoft_olsacustomerid;
$sharedsecret = $CFG->skillsoft_olsasharedsecret;
//Specify the WSDL using the EndPoint
$wsdlurl = $endpoint.'?WSDL';
//Specify the SOAP Client Options
$options = array(
"trace" => 0,
"exceptions" => 0,
"soap_version" => SOAP_1_2,
"cache_wsdl" => WSDL_CACHE_BOTH,
"encoding"=> "UTF-8"
);
//Create a new instance of the OLSA Soap Client
$client = new olsa_soapclient($wsdlurl,$options);
//Create the USERNAMETOKEN
$client->__setUsernameToken($customerId,$sharedsecret);
//Create the Request
$AcknowledgeTrackingDataRequest = array(
"customerId" => $customerId,
"handle" => $handle,
);
//Call the WebService and stored result in $result
$result=$client->__soapCall('OC_AcknowledgeTrackingData',array('parameters'=>$AcknowledgeTrackingDataRequest));
if (is_soap_fault($result)) {
if (!stripos($result->getmessage(),'security token could not be authenticated or authorized') == false) {
//Authentication Failure
$response = new olsaresponse(false,get_string('skillsoft_olsassoapauthentication','skillsoft'),NULL);
} elseif (!stripos($result->getmessage(), 'The specified course could not be found') == false){
//TODO: Need check here for INVALID HANDLE and add appropriate Lanaguge Tag
$response = new olsaresponse(false,get_string('skillsoft_olsassoapinvalidassetid','skillsoft',$assetid),NULL);
} else {
//General SOAP Fault
//print_error('olsassoapfault','skillsoft','',$result->getmessage());
$response = new olsaresponse(false,get_string('skillsoft_olsassoapfault','skillsoft',$result->getmessage()),NULL);
}
} else {
$response = new olsaresponse(true,'',NULL);
}
}
return $response;
}
/**
* Retrieve the TrackingData
*
* @return olsasoapresponse olsasoapresponse->result is GetTrackingDataResponse object
*/
function OC_GetTrackingData() {
global $CFG;
if (!isolsaconfigurationset()) {
$response = new olsaresponse(false,get_string('skillsoft_olsasettingsmissing','skillsoft'),NULL);
} else {
//Set local OLSA Variables
$endpoint = $CFG->skillsoft_olsaendpoint;
$customerId = $CFG->skillsoft_olsacustomerid;
$sharedsecret = $CFG->skillsoft_olsasharedsecret;
//Specify the WSDL using the EndPoint
$wsdlurl = $endpoint.'?WSDL';
//Specify the SOAP Client Options
$options = array(
"trace" => 0,
"exceptions" => 0,
"soap_version" => SOAP_1_2,
"cache_wsdl" => WSDL_CACHE_BOTH,
"encoding"=> "UTF-8"
);
//Create a new instance of the OLSA Soap Client
$client = new olsa_soapclient($wsdlurl,$options);
//Create the USERNAMETOKEN
$client->__setUsernameToken($customerId,$sharedsecret);
//Create the Request
$GetTrackingDataRequest = array(
"customerId" => $customerId,
);
//Call the WebService and stored result in $result
$result=$client->__soapCall('OC_GetTrackingData',array('parameters'=>$GetTrackingDataRequest));
if (is_soap_fault($result)) {
if (!stripos($result->getmessage(),'security token could not be authenticated or authorized') == false) {
//Authentication Failure
$response = new olsaresponse(false,get_string('skillsoft_olsassoapauthentication','skillsoft'),NULL);
} elseif (isset($result->detail->NoResultsAvailableFault)) {
$response = new olsaresponse(false,get_string('skillsoft_odcnoresultsavailable','skillsoft'),NULL);
} else {
//General SOAP Fault
$response = new olsaresponse(false,get_string('skillsoft_olsassoapfault','skillsoft',$result->getmessage()),NULL);
}
} else {
$response = new olsaresponse(true,'',$result);
}
}
return $response;
}
/**
* Perform a SignOn
*
* @param string $userName the SkillPort username
* @param string $firstName the first name
* @param string $lastName the last name
* @param string $email the email
* @param string $password the password
* @param string $groupCode the definitive list of groups
* @param string $actionType the action to perform
* @param string $assetId the assetid to perform action with
* @param bool $enable508 enable section 508 support
* @param string $authType the type of account
* @param string $newUserName the name to rename username to
* @param bool $active is the account active
* @param string $address1 optional parameter
* @param string $address2 optional parameter
* @param string $city optional parameter
* @param string $state optional parameter
* @param string $zip optional parameter
* @param string $country optional parameter
* @param string $phone optional parameter
* @param string $sex optional parameter
* @param string $ccExpr optional parameter
* @param string $ccNumber optional parameter
* @param string $ccType optional parameter
* @param string $free1 optional parameter
* @param string $birthDate optional parameter
* @param string $language the UI language must be one of SkillSoft supported values
* @param string $manager the users managers skillport username (manager account must already exist and be manager level in skillport)
* @return olsasoapresponse olsasoapresponse->result. result->olsaURL is the time/user scoped URL to redirect the user to
*/
function SO_GetMultiActionSignOnUrl(
$userName,
$firstName = '',
$lastName = '',
$email = '',
$password = '',
$groupCode = '',
$actionType = 'home',
$assetId = '',
$enable508 = false,
$authType = 'End-User',
$newUserName = '',
$active = true,
$address1 = '',
$address2 = '',
$city = '',
$state = '',
$zip = '',
$country = '',
$phone = '',
$sex = '',
$ccExpr = '',
$ccNumber = '',
$ccType = '',
$free1 = '',
$birthDate = '',
$language = '',
$manager = ''
) {
global $CFG;
if (!isolsaconfigurationset()) {
$response = new olsaresponse(false,get_string('skillsoft_olsasettingsmissing','skillsoft'),NULL);
} else {
//Set local OLSA Variables
$endpoint = $CFG->skillsoft_olsaendpoint;
$customerId = $CFG->skillsoft_olsacustomerid;
$sharedsecret = $CFG->skillsoft_olsasharedsecret;
//Specify the WSDL using the EndPoint
$wsdlurl = $endpoint.'?WSDL';
//Specify the SOAP Client Options
$options = array(
"trace" => 1,
"exceptions" => 0,
"soap_version" => SOAP_1_2,
"cache_wsdl" => WSDL_CACHE_BOTH,
"encoding"=> "UTF-8"
);
//Create a new instance of the OLSA Soap Client
$client = new olsa_soapclient($wsdlurl,$options);
//Create the USERNAMETOKEN
$client->__setUsernameToken($customerId,$sharedsecret);
//Create the Request
$GetMultiActionSignOnUrlRequest = array(
"customerId" => $customerId,
"userName" => $userName,
"firstName" => $firstName,
"lastName" => $lastName,
"email" => $email,
"password" => $password,
"groupCode" => $groupCode,
"actionType" => $actionType,
"assetId" => $assetId,
"enable508" => $enable508,
"authType" => $authType,
"newUserName" => $newUserName,
"active" => $active,
"address1" => $address1,
"address2" => $address2,
"city" => $city,
"state" => $state,
"zip" => $zip,
"country" => $country,
"phone" => $phone,
"sex" => $sex,
"ccExpr" => $ccExpr,
"ccNumber" => $ccNumber,
"ccType" => $ccType,
"free1" => $free1,
// "birthDate" => $birthDate,
"language" => $language,
"manager" => $manager,
);
if (!empty($birthDate)){
if ($birthTimestamp = strtotime($birthDate)) {
$GetMultiActionSignOnUrlRequest["birthDate"] = date('Y-m-d', $birthTimestamp);
}
}
//Call the WebService and stored result in $result
$result=$client->__soapCall('SO_GetMultiActionSignOnUrl',array('parameters'=>$GetMultiActionSignOnUrlRequest));
if (is_soap_fault($result)) {
if (!stripos($result->getmessage(),'security token could not be authenticated or authorized') == false) {
//Authentication Failure
$response = new olsaresponse(false,get_string('skillsoft_olsassoapauthentication','skillsoft'),NULL);
}
elseif (!stripos($result->getmessage(), "the property '_pathid_' or '_orgcode_' must be specified") == false)
{
//Captures if the USER does not exist and we have NOT SENT the _req.groupCode value.
//This is a good methodology when the SSO process will not be aware of all groups a
//user belongs to. This way capturing this exception means that we only need to send
//an orgcode when we know we have to create the user.
//This avoids the issue of overwriting existing group membership for user already in
//SkillPort.
//You would capture this exception and resubmit the request now including the "default"
//orgcode.
$response = new olsaresponse(false,get_string('skillsoft_olsassoapfault','skillsoft',$result->getmessage()),NULL);
}
elseif (!stripos($result->getmessage(), "invalid new username") == false)
{
//The username specified is not valid
//Supported Characters: abcdefghijklmnopqrstuvwxyz0123456789@$_.~'-
//Cannot start with apostrophe (') or dash (-)
//Non-breaking white spaces (space, tab, new line) are not allowed in login names
//No double-byte characters are allowed (e.g. Japanese or Chinese characters)
$response = new olsaresponse(false,get_string('skillsoft_olsassoapfault','skillsoft',$result->getmessage()),NULL);
}
elseif (!stripos($result->getmessage(), "invalid password") == false)
{
//The password specified is not valid
//All single-byte characters are allowed except back slash (\)
//Non-breaking white spaces (space, tab, new line) are not allowed
//No double-byte characters are allowed (e.g. Japanese or Chinese characters)
$response = new olsaresponse(false,get_string('skillsoft_olsassoapfault','skillsoft',$result->getmessage()),NULL);
}
elseif (!stripos($result->getmessage(), "enter a valid email address") == false)
{
//The email address specified is not a valid SMTP email address
$response = new olsaresponse(false,get_string('skillsoft_olsassoapfault','skillsoft',$result->getmessage()),NULL);
}
elseif (!stripos($result->getmessage(), "error: org code") == false)
{
//The single orgcode specified in the _req.groupCode is not valid
$response = new olsaresponse(false,get_string('skillsoft_olsassoapfault','skillsoft',$result->getmessage()),NULL);
}
elseif (!stripos($result->getmessage(), "user group with orgcode") == false)
{
//One of the multiple orgcodes specified in the _req.groupCode is not valid
$response = new olsaresponse(false,get_string('skillsoft_olsassoapfault','skillsoft',$result->getmessage()),NULL);
}
elseif (!stripos($result->getmessage(), "field is too long") == false)