Test Failed
Push — master ( 7c9196...d32c48 )
by Stefan
07:03
created

CAT::getExternalCountriesList()   A

Complexity

Conditions 6
Paths 2

Size

Total Lines 19
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 15
nc 2
nop 0
dl 0
loc 19
rs 9.2222
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * *****************************************************************************
5
 * Contributions to this work were made on behalf of the GÉANT project, a 
6
 * project that has received funding from the European Union’s Framework 
7
 * Programme 7 under Grant Agreements No. 238875 (GN3) and No. 605243 (GN3plus),
8
 * Horizon 2020 research and innovation programme under Grant Agreements No. 
9
 * 691567 (GN4-1) and No. 731122 (GN4-2).
10
 * On behalf of the aforementioned projects, GEANT Association is the sole owner
11
 * of the copyright in all material which was developed by a member of the GÉANT
12
 * project. GÉANT Vereniging (Association) is registered with the Chamber of 
13
 * Commerce in Amsterdam with registration number 40535155 and operates in the 
14
 * UK as a branch of GÉANT Vereniging.
15
 * 
16
 * Registered office: Hoekenrode 3, 1102BR Amsterdam, The Netherlands. 
17
 * UK branch address: City House, 126-130 Hills Road, Cambridge CB2 1PQ, UK
18
 *
19
 * License: see the web/copyright.inc.php file in the file structure or
20
 *          <base_url>/copyright.php after deploying the software
21
 */
22
23
/**
24
 *  This is the definition of the CAT class
25
 * @author Stefan Winter <[email protected]>
26
 * @author Tomasz Wolniewicz <[email protected]>
27
 *
28
 * @package Developer
29
 */
30
/**
31
 * necessary includes
32
 */
33
34
namespace core;
35
36
/**
37
 * Define some variables which need to be globally accessible
38
 * and some general purpose methods
39
 *
40
 * @author Stefan Winter <[email protected]>
41
 * @author Tomasz Wolniewicz <[email protected]>
42
 *
43
 * @package Developer
44
 */
45
class CAT extends \core\common\Entity {
46
47
    /**
48
     * which version is this?
49
     * even if we are unreleased, keep track of internal version-to-be
50
     * developers need to set this in code. The user-displayed string
51
     * is generated into $CAT_VERSION_STRING and $CAT_COPYRIGHT below
52
     */
53
    const VERSION_MAJOR = 2;
54
    const VERSION_MINOR = 1;
55
    const VERSION_PATCH = 0;
56
    const VERSION_EXTRA = "alpha1";
57
    const RELEASE_VERSION = FALSE;
58
    const USER_API_VERSION = 2;
59
60
    /**
61
     * trying to keep up with the name changes of copyright holder and consortia
62
     * updating those on *one* place should change display everywhere!
63
     */
64
    const COPYRIGHT_HOLDER = "G&Eacute;ANT Association";
65
    const COPYRIGHT_CONSORTIA = "the G&Eacute;ANT Projects funded by EU";
66
    const COPYRIGHT_MIN_YEAR = 2011;
67
    const COPYRIGHT_MAX_YEAR = 2019;
68
69
    /**
70
     * This is the user-displayed string; controlled by the four options above
71
     * It is generated in the constructor.
72
     * 
73
     * @var string
74
     */
75
    public $CAT_VERSION_STRING;
76
77
    /**
78
     * The entire copyright line, generated in constructor
79
     * 
80
     * @var string
81
     */
82
    public $CAT_COPYRIGHT;
83
84
    /**
85
     * all known federation, in an array with ISO short name as an index, and localised version of the pretty-print name as value.
86
     * The static value is only filled with meaningful content after the first object has been instantiated. That is because it is not
87
     * possible to define static properties with function calls like _().
88
     * 
89
     * @var array of all known federations
90
     */
91
    public $knownFederations;
92
93
    /**
94
     * the default database to query in this class.
95
     */
96
    const DB_TYPE = "INST";
97
98
    /**
99
     *  Constructor sets the language by calling set_lang 
100
     *  and stores language settings in object properties
101
     */
102
    public function __construct() {
103
        parent::__construct();
104
        common\Entity::intoThePotatoes();
105
106
        $this->CAT_VERSION_STRING = sprintf(_("Unreleased %s Git Revision"), "<a href='https://github.com/GEANT/CAT/tree/master/Changes.md'>") . "</a>";
107
        if (CAT::RELEASE_VERSION) {
108
            $temp_version = "CAT-" . CAT::VERSION_MAJOR . "." . CAT::VERSION_MINOR;
109
            $branch = "release_" . CAT::VERSION_MAJOR . "_" . CAT::VERSION_MINOR;
110
            if (CAT::VERSION_PATCH != 0) {
111
                $temp_version .= "." . CAT::VERSION_PATCH;
112
            }
113
            if (CAT::VERSION_EXTRA != "") {
114
                $temp_version .= "-" . CAT::VERSION_EXTRA;
115
            }
116
            $this->CAT_VERSION_STRING = sprintf(_("Release <a href='%s'>%s</a>"), "https://github.com/GEANT/CAT/tree/" . $branch . "/Changes.md", $temp_version);
117
        }
118
        $this->CAT_COPYRIGHT = \config\Master::CONFIG['APPEARANCE']['productname'] . " - " . $this->CAT_VERSION_STRING . " &copy; " . CAT::COPYRIGHT_MIN_YEAR . "-" . CAT::COPYRIGHT_MAX_YEAR . " " . CAT::COPYRIGHT_HOLDER . "<br/>on behalf of " . CAT::COPYRIGHT_CONSORTIA . "; and others <a href='copyright.php'>Full Copyright and Licenses</a>";
119
120
121
        /* Federations are created in DB with bootstrapFederation, and listed via listFederations
122
         */
123
124
        $this->knownFederations = [
125
            'AD' => _("Andorra"),
126
            'AT' => _("Austria"),
127
            'BE' => _("Belgium"),
128
            'BG' => _("Bulgaria"),
129
            'CY' => _("Cyprus"),
130
            'CZ' => _("Czech Republic"),
131
            'DK' => _("Denmark"),
132
            'EE' => _("Estonia"),
133
            'FI' => _("Finland"),
134
            'FR' => _("France"),
135
            'DE' => _("Germany"),
136
            'GR' => _("Greece"),
137
            'HR' => _("Croatia"),
138
            'IE' => _("Ireland"),
139
            'IS' => _("Iceland"),
140
            'IT' => _("Italy"),
141
            'HU' => _("Hungary"),
142
            'LU' => _("Luxembourg"),
143
            'LV' => _("Latvia"),
144
            'LT' => _("Lithuania"),
145
            'MK' => _("Macedonia"),
146
            'RS' => _("Serbia"),
147
            'NL' => _("Netherlands"),
148
            'NO' => _("Norway"),
149
            'PL' => _("Poland"),
150
            'PT' => _("Portugal"),
151
            'RO' => _("Romania"),
152
            'SI' => _("Slovenia"),
153
            'ES' => _("Spain"),
154
            'SE' => _("Sweden"),
155
            'SK' => _("Slovakia"),
156
            'CH' => _("Switzerland"),
157
            'TR' => _("Turkey"),
158
            'UK' => _("United Kingdom"),
159
            'TEST' => 'TEST Country',
160
            'AU' => _("Australia"),
161
            'CA' => _("Canada"),
162
            'IL' => _("Israel"),
163
            'JP' => _("Japan"),
164
            'NZ' => _("New Zealand"),
165
            'US' => _("U.S.A."),
166
            'BR' => _("Brazil"),
167
            'CL' => _("Chile"),
168
            'PE' => _("Peru"),
169
            'VE' => _("Venezuela"),
170
            'DEFAULT' => _("Default"),
171
            'AM' => _("Armenia"),
172
            'AZ' => _("Azerbaijan"),
173
            'BY' => _("Belarus"),
174
            'EC' => _("Ecuador"),
175
            'HK' => _("Hong Kong"),
176
            'KE' => _("Kenya"),
177
            'KG' => _("Kyrgyzstan"),
178
            'KR' => _("Korea"),
179
            'KZ' => _("Kazakhstan"),
180
            'MA' => _("Morocco"),
181
            'MD' => _("Moldova"),
182
            'ME' => _("Montenegro"),
183
            'MO' => _("Macau"),
184
            'MT' => _("Malta"),
185
            'RU' => _("Russia"),
186
            'SG' => _("Singapore"),
187
            'TH' => _("Thailand"),
188
            'TW' => _("Taiwan"),
189
            'ZA' => _("South Africa"),
190
            'AF' => 'Afghanistan',
191
            'AL' => 'Albania',
192
            'DZ' => 'Algeria',
193
            'AS' => 'American Samoa',
194
            'AO' => 'Angola',
195
            'AI' => 'Anguilla',
196
            'AQ' => 'Antarctica',
197
            'AG' => 'Antigua And Barbuda',
198
            'AR' => 'Argentina',
199
            'AW' => 'Aruba',
200
            'BS' => 'Bahamas, The',
201
            'BH' => 'Bahrain',
202
            'BD' => 'Bangladesh',
203
            'BB' => 'Barbados',
204
            'BZ' => 'Belize',
205
            'BJ' => 'Benin',
206
            'BM' => 'Bermuda',
207
            'BT' => 'Bhutan',
208
            'BO' => 'Bolivia',
209
            'BA' => 'Bosnia And Herzegovina',
210
            'BW' => 'Botswana',
211
            'BV' => 'Bouvet Island',
212
            'IO' => 'British Indian Ocean Territory',
213
            'BN' => 'Brunei',
214
            'BF' => 'Burkina Faso',
215
            'MM' => 'Burma',
216
            'BI' => 'Burundi',
217
            'KH' => 'Cambodia',
218
            'CM' => 'Cameroon',
219
            'CV' => 'Cape Verde',
220
            'KY' => 'Cayman Islands',
221
            'CF' => 'Central African Republic',
222
            'TD' => 'Chad',
223
            'CN' => 'China',
224
            'CX' => 'Christmas Island',
225
            'CC' => 'Cocos (keeling) Islands',
226
            'CO' => 'Colombia',
227
            'KM' => 'Comoros',
228
            'CG' => 'Congo (brazzaville) ',
229
            'CD' => 'Congo (kinshasa)',
230
            'CK' => 'Cook Islands',
231
            'CR' => 'Costa Rica',
232
            'CI' => 'CÔte D’ivoire',
233
            'CU' => 'Cuba',
234
            'CW' => 'CuraÇao',
235
            'DJ' => 'Djibouti',
236
            'DM' => 'Dominica',
237
            'DO' => 'Dominican Republic',
238
            'EG' => 'Egypt',
239
            'SV' => 'El Salvador',
240
            'GQ' => 'Equatorial Guinea',
241
            'ER' => 'Eritrea',
242
            'ET' => 'Ethiopia',
243
            'FK' => 'Falkland Islands (islas Malvinas)',
244
            'FO' => 'Faroe Islands',
245
            'FJ' => 'Fiji',
246
            'GF' => 'French Guiana',
247
            'PF' => 'French Polynesia',
248
            'TF' => 'French Southern And Antarctic Lands',
249
            'GA' => 'Gabon',
250
            'GM' => 'Gambia, The',
251
            'GE' => 'Georgia',
252
            'GEANT' => 'The GEANT country',
253
            'GH' => 'Ghana',
254
            'GI' => 'Gibraltar',
255
            'GL' => 'Greenland',
256
            'GD' => 'Grenada',
257
            'GP' => 'Guadeloupe',
258
            'GU' => 'Guam',
259
            'GT' => 'Guatemala',
260
            'GG' => 'Guernsey',
261
            'GN' => 'Guinea',
262
            'GW' => 'Guinea-bissau',
263
            'GY' => 'Guyana',
264
            'HT' => 'Haiti',
265
            'HM' => 'Heard Island And Mcdonald Islands',
266
            'HN' => 'Honduras',
267
            'IN' => 'India',
268
            'ID' => 'Indonesia',
269
            'IR' => 'Iran',
270
            'IQ' => 'Iraq',
271
            'IM' => 'Isle Of Man',
272
            'JM' => 'Jamaica',
273
            'JE' => 'Jersey',
274
            'JO' => 'Jordan',
275
            'KI' => 'Kiribati',
276
            'KP' => 'Korea, North',
277
            'KW' => 'Kuwait',
278
            'LA' => 'Laos',
279
            'LB' => 'Lebanon',
280
            'LS' => 'Lesotho',
281
            'LR' => 'Liberia',
282
            'LY' => 'Libya',
283
            'LI' => 'Liechtenstein',
284
            'MG' => 'Madagascar',
285
            'MW' => 'Malawi',
286
            'MY' => 'Malaysia',
287
            'MV' => 'Maldives',
288
            'ML' => 'Mali',
289
            'MH' => 'Marshall Islands',
290
            'MQ' => 'Martinique',
291
            'MR' => 'Mauritania',
292
            'MU' => 'Mauritius',
293
            'YT' => 'Mayotte',
294
            'MX' => 'Mexico',
295
            'FM' => 'Micronesia, Federated States Of',
296
            'MC' => 'Monaco',
297
            'MN' => 'Mongolia',
298
            'MS' => 'Montserrat',
299
            'MZ' => 'Mozambique',
300
            'NA' => 'Namibia',
301
            'NR' => 'Nauru',
302
            'NP' => 'Nepal',
303
            'NC' => 'New Caledonia',
304
            'NI' => 'Nicaragua',
305
            'NE' => 'Niger',
306
            'NG' => 'Nigeria',
307
            'NU' => 'Niue',
308
            'NF' => 'Norfolk Island',
309
            'MP' => 'Northern Mariana Islands',
310
            'OM' => 'Oman',
311
            'PK' => 'Pakistan',
312
            'PW' => 'Palau',
313
            'PA' => 'Panama',
314
            'PG' => 'Papua New Guinea',
315
            'PY' => 'Paraguay',
316
            'PH' => 'Philippines',
317
            'PN' => 'Pitcairn Islands',
318
            'PR' => 'Puerto Rico',
319
            'QA' => 'Qatar',
320
            'RE' => 'Reunion',
321
            'RW' => 'Rwanda',
322
            'BL' => 'Saint Barthelemy',
323
            'SH' => 'Saint Helena, Ascension, And Tristan Da Cunha',
324
            'KN' => 'Saint Kitts And Nevis',
325
            'LC' => 'Saint Lucia',
326
            'MF' => 'Saint Martin',
327
            'PM' => 'Saint Pierre And Miquelon',
328
            'VC' => 'Saint Vincent And The Grenadines',
329
            'WS' => 'Samoa',
330
            'SM' => 'San Marino',
331
            'ST' => 'Sao Tome And Principe',
332
            'SA' => 'Saudi Arabia',
333
            'SN' => 'Senegal',
334
            'SC' => 'Seychelles',
335
            'SL' => 'Sierra Leone',
336
            'SX' => 'Sint Maarten',
337
            'SB' => 'Solomon Islands',
338
            'SO' => 'Somalia',
339
            'GS' => 'South Georgia And South Sandwich Islands',
340
            'SS' => 'South Sudan',
341
            'LK' => 'Sri Lanka',
342
            'SD' => 'Sudan',
343
            'SR' => 'Suriname',
344
            'SZ' => 'Swaziland',
345
            'SY' => 'Syria',
346
            'TJ' => 'Tajikistan',
347
            'TZ' => 'Tanzania',
348
            'TL' => 'Timor-leste',
349
            'TG' => 'Togo',
350
            'TK' => 'Tokelau',
351
            'TO' => 'Tonga',
352
            'TT' => 'Trinidad And Tobago',
353
            'TN' => 'Tunisia',
354
            'TM' => 'Turkmenistan',
355
            'TC' => 'Turks And Caicos Islands',
356
            'TV' => 'Tuvalu',
357
            'UG' => 'Uganda',
358
            'UA' => 'Ukraine',
359
            'AE' => 'United Arab Emirates',
360
            'GB' => 'United Kingdom',
361
            'UY' => 'Uruguay',
362
            'UZ' => 'Uzbekistan',
363
            'VU' => 'Vanuatu',
364
            'VA' => 'Vatican City',
365
            'VN' => 'Vietnam',
366
            'VG' => 'Virgin Islands, British',
367
            'VI' => 'Virgin Islands, United States ',
368
            'WF' => 'Wallis And Futuna',
369
            'EH' => 'Western Sahara',
370
            'YE' => 'Yemen',
371
            'ZM' => 'Zambia',
372
            'ZW' => 'Zimbabwe',
373
        ];
374
375
        common\Entity::outOfThePotatoes();
376
    }
377
378
    /**
379
     * Calculates the number of IdPs overall in the system
380
     * 
381
     * @param string $level completeness level of IdPs that are to be taken into consideration for counting
382
     * @return int
383
     */
384
    public function totalIdPs($level) {
385
        $handle = DBConnection::handle(CAT::DB_TYPE);
386
        switch ($level) {
387
            case "ALL":
388
                $idpcount = $handle->exec("SELECT COUNT(inst_id) AS instcount FROM institution");
389
                break;
390
            case "VALIDPROFILE":
391
                $idpcount = $handle->exec("SELECT COUNT(DISTINCT institution.inst_id) AS instcount FROM institution,profile WHERE institution.inst_id = profile.inst_id AND profile.sufficient_config = 1");
392
                break;
393
            case "PUBLICPROFILE":
394
                $idpcount = $handle->exec("SELECT COUNT(DISTINCT institution.inst_id) AS instcount FROM institution,profile WHERE institution.inst_id = profile.inst_id AND profile.showtime = 1");
395
                break;
396
            default:
397
                return -1;
398
        }
399
        // SELECTs never return a booleans, always an object
400
        $dbresult = mysqli_fetch_object(/** @scrutinizer ignore-type */ $idpcount);
401
        return $dbresult->instcount;
402
    }
403
404
    /**
405
     * Lists all identity providers in the database
406
     * adding information required by DiscoJuice.
407
     * 
408
     * @param int    $activeOnly if set to non-zero will cause listing of only those institutions which have some valid profiles defined.
409
     * @param string $country    if set, only list IdPs in a specific country
410
     * @return array the list of identity providers
411
     *
412
     */
413
    public function listAllIdentityProviders($activeOnly = 0, $country = "") {
414
        common\Entity::intoThePotatoes();
415
        $handle = DBConnection::handle("INST");
416
        $handle->exec("SET SESSION group_concat_max_len=10000");
417
        $query = "SELECT distinct institution.inst_id AS inst_id, institution.country AS country,
418
                     group_concat(concat_ws('===',institution_option.option_name,LEFT(institution_option.option_value,200), institution_option.option_lang) separator '---') AS options
419
                     FROM institution ";
420
        if ($activeOnly == 1) {
421
            $query .= "JOIN v_active_inst ON institution.inst_id = v_active_inst.inst_id ";
422
        }
423
        $query .= "JOIN institution_option ON institution.inst_id = institution_option.institution_id ";
424
        $query .= "WHERE (institution_option.option_name = 'general:instname' 
425
                          OR institution_option.option_name = 'general:geo_coordinates'
426
                          OR institution_option.option_name = 'general:logo_file') ";
427
428
        $query .= ($country != "" ? "AND institution.country = ? " : "");
429
430
        $query .= "GROUP BY institution.inst_id ORDER BY inst_id";
431
432
        $allIDPs = ($country != "" ? $handle->exec($query, "s", $country) : $handle->exec($query));
433
        $returnarray = [];
434
        // SELECTs never return a booleans, always an object
435
        while ($queryResult = mysqli_fetch_object(/** @scrutinizer ignore-type */ $allIDPs)) {
436
            $institutionOptions = explode('---', $queryResult->options);
437
            $oneInstitutionResult = [];
438
            $geo = [];
439
            $names = [];
440
441
            $oneInstitutionResult['entityID'] = $queryResult->inst_id;
442
            $oneInstitutionResult['country'] = strtoupper($queryResult->country);
443
            foreach ($institutionOptions as $institutionOption) {
444
                $opt = explode('===', $institutionOption);
445
                switch ($opt[0]) {
446
                    case 'general:logo_file':
447
                        $oneInstitutionResult['icon'] = $queryResult->inst_id;
448
                        break;
449
                    case 'general:geo_coordinates':
450
                        $at1 = json_decode($opt[1], true);
451
                        $geo[] = $at1;
452
                        break;
453
                    case 'general:instname':
454
                        $names[] = [
455
                            'lang' => $opt[2],
456
                            'value' => $opt[1]
457
                        ];
458
                        break;
459
                    default:
460
                        break;
461
                }
462
            }
463
464
            $name = _("Unnamed Entity");
465
            if (count($names) != 0) {
466
                $langObject = new \core\common\Language();
467
                $name = $langObject->getLocalisedValue($names);
468
            }
469
            $oneInstitutionResult['title'] = $name;
470
            if (count($geo) > 0) {
471
                $oneInstitutionResult['geo'] = $geo;
472
            }
473
            $returnarray[] = $oneInstitutionResult;
474
        }
475
        common\Entity::outOfThePotatoes();
476
        return $returnarray;
477
    }
478
479
    /**
480
     * Prepares a list of countries known to the CAT.
481
     * 
482
     * @param int $activeOnly is set and nonzero will cause that only countries with some institutions underneath will be listed
483
     * @return array Array indexed by (uppercase) lang codes and sorted according to the current locale
484
     */
485
    public function printCountryList($activeOnly = 0) {
486
        $olddomain = $this->languageInstance->setTextDomain("core");
487
        $handle = DBConnection::handle(CAT::DB_TYPE);
488
        $returnArray = []; // in if -> the while might never be executed, so initialise
489
        if ($activeOnly) {
490
            $federations = $handle->exec("SELECT DISTINCT UPPER(institution.country) AS country FROM institution JOIN profile
491
                          ON institution.inst_id = profile.inst_id WHERE profile.showtime = 1 ORDER BY country");
492
            // SELECT never returns a boolean, always a mysqli_object
493
            while ($activeFederations = mysqli_fetch_object(/** @scrutinizer ignore-type */ $federations)) {
494
                $fedIdentifier = $activeFederations->country; // UPPER() has capitalised this for us
495
                $returnArray[$fedIdentifier] = isset($this->knownFederations[$fedIdentifier]) ? $this->knownFederations[$fedIdentifier] : $fedIdentifier;
496
            }
497
        } else {
498
            $returnArray = $this->knownFederations;
499
        }
500
        asort($returnArray, SORT_LOCALE_STRING);
501
        $this->languageInstance->setTextDomain($olddomain);
502
        return($returnArray);
503
    }
504
505
    /**
506
     * get additional details about an institution from the EXTERNAL customer DB
507
     * (if any; for eduroam, this would be the official eduroam database)
508
     * 
509
     * @param string $externalId the ID of the institution in the external DB
510
     * @param string $realm      the function can also try to find an inst by its realm in the external DB
511
     * @return array a list of institutions, ideally with only one member
512
     * @throws \Exception
513
     */
514
    public function getExternalDBEntityDetails($externalId, $realm = NULL) {
515
        $list = [];
516
        if (\config\ConfAssistant::CONFIG['CONSORTIUM']['name'] == "eduroam" && isset(\config\ConfAssistant::CONFIG['CONSORTIUM']['deployment-voodoo']) && \config\ConfAssistant::CONFIG['CONSORTIUM']['deployment-voodoo'] == "Operations Team") { // SW: APPROVED
517
            $scanforrealm = "";
518
            if ($realm !== NULL) {
519
                $scanforrealm = "OR inst_realm LIKE '%$realm%'";
520
            }
521
            $externalHandle = DBConnection::handle("EXTERNAL");
522
            $infoList = $externalHandle->exec("SELECT name AS collapsed_name, inst_realm as realmlist, contact AS collapsed_contact, country, type FROM view_active_institution WHERE id_institution = $externalId $scanforrealm");
523
            // split names and contacts into proper pairs
524
            // SELECT never returns a boolean, always a mysqli_object
525
            while ($externalEntityQuery = mysqli_fetch_object(/** @scrutinizer ignore-type */ $infoList)) {
526
                $names = explode('#', $externalEntityQuery->collapsed_name);
527
                foreach ($names as $name) {
528
                    $perlang = explode(': ', $name, 2);
529
                    $list['names'][$perlang[0]] = $perlang[1];
530
                }
531
                $contacts = explode('#', $externalEntityQuery->collapsed_contact);
532
                foreach ($contacts as $contact) {
533
                    $email1 = explode('e: ', $contact);
534
                    $email2 = explode(',', $email1[1]);
535
                    $list['admins'][] = ["email" => $email2[0]];
536
                }
537
                $list['country'] = strtoupper($externalEntityQuery->country);
538
                $list['realmlist'] = $externalEntityQuery->realmlist;
539
                switch ($externalEntityQuery->type) {
540
                    case ExternalEduroamDBData::TYPE_IDP:
541
                        $list['type'] = IdP::TYPE_IDP;
542
                        break;
543
                    case ExternalEduroamDBData::TYPE_SP:
544
                        $list['type'] = IdP::TYPE_SP;
545
                        break;
546
                    case ExternalEduroamDBData::TYPE_IDPSP:
547
                        $list['type'] = IdP::TYPE_IDPSP;
548
                        break;
549
                    default:
550
                        throw new \Exception("Eduroam DB returned a participant type we do not know.");
551
                }
552
            }
553
        }
554
        return $list;
555
    }
556
557
    /**
558
     * the list of countries as per external DB
559
     * @return array the list
560
     */
561
    public function getExternalCountriesList() {
562
        $olddomain = $this->languageInstance->setTextDomain("core");
563
        $returnArray = []; // in if -> the while might never be executed, so initialise
564
        if (\config\ConfAssistant::CONFIG['CONSORTIUM']['name'] == "eduroam" && isset(\config\ConfAssistant::CONFIG['CONSORTIUM']['deployment-voodoo']) && \config\ConfAssistant::CONFIG['CONSORTIUM']['deployment-voodoo'] == "Operations Team") { // SW: APPROVED
565
            $handle = DBConnection::handle("EXTERNAL");
566
            $timeStart = microtime(true);
567
            $federations = $handle->exec("SELECT DISTINCT UPPER(country) AS country FROM view_country_eduroamdb ORDER BY country");
568
            $timeEnd = microtime(true);
569
            $timeElapsed = $timeEnd - $timeStart;
570
            // the query yielded a mysqli_result because it's a SELECT, this never gives back a boolean
571
            while ($eduroamFederations = mysqli_fetch_object(/** @scrutinizer ignore-type */ $federations)) {
572
                $fedIdentifier = $eduroamFederations->country;
573
                $returnArray[$fedIdentifier] = isset($this->knownFederations[$fedIdentifier]) ? $this->knownFederations[$fedIdentifier] : $fedIdentifier;
574
            }
575
            asort($returnArray, SORT_LOCALE_STRING);
576
            $returnArray['time'] = $timeElapsed;
577
        }
578
        $this->languageInstance->setTextDomain($olddomain);
579
        return($returnArray);
580
    }
581
582
    /**
583
     * the (HTML) root path of the CAT deployment
584
     * 
585
     * @return string
586
     */
587
    public static function getRootUrlPath() {
588
        return substr(\config\Master::CONFIG['PATHS']['cat_base_url'], -1) === '/' ? substr(\config\Master::CONFIG['PATHS']['cat_base_url'], 0, -1) : \config\Master::CONFIG['PATHS']['cat_base_url'];
589
    }
590
591
    /**
592
     * takes care of starting our session
593
     * 
594
     * @return void
595
     */
596
    public static function sessionStart() {
597
        if (session_status() != PHP_SESSION_ACTIVE) {
598
            session_name("CAT");
599
            session_set_cookie_params(0, "/", $_SERVER['SERVER_NAME'], (isset($_SERVER['HTTPS']) ? TRUE : FALSE));
600
            session_start();
601
        }
602
    }
603
604
}
605