OptionDisplay   F
last analyzed

Complexity

Total Complexity 78

Size/Duplication

Total Lines 528
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 78
eloc 262
c 1
b 0
f 0
dl 0
loc 528
rs 2.16

12 Methods

Rating   Name   Duplication   Size   Complexity  
B prefilledOptionTable() 0 17 7
A __construct() 0 24 2
A optiontext() 0 33 6
A noPrefillText() 0 10 1
A inputFields() 0 7 3
A tooltip() 0 21 4
C prefillText() 0 81 16
C selectElement() 0 75 12
A selectLanguage() 0 13 3
A addOptionNew() 0 12 2
B addOptionEdit() 0 22 7
C enumerateOptionsToDisplay() 0 54 15

How to fix   Complexity   

Complex Class

Complex classes like OptionDisplay often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use OptionDisplay, and based on these observations, apply Extract Interface, too.

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
namespace web\lib\admin;
24
25
use Exception;
26
27
/**
28
 * We need to display previously set options in various forms. This class covers
29
 * the ways to do that; the generated page content can then be parsed with 
30
 * OptionParser.
31
 * 
32
 * @author Stefan Winter <[email protected]>
33
 */
34
class OptionDisplay extends \core\common\Entity
35
{
36
37
    /**
38
     * stores all the options we are caring about
39
     * 
40
     * @var array
41
     */
42
    private $listOfOptions;
43
44
    /**
45
     * on which level are we operating?
46
     * 
47
     * @var string
48
     */
49
    private $level;
50
51
    /**
52
     * a counter storing how many locations are to be displayed
53
     * 
54
     * @var integer
55
     */
56
    private $allLocationCount;
57
58
    /**
59
     * When "fresh" options are displayed (HTML select/option fields, optionally
60
     * with language, and of varying data types) we want to give each option
61
     * the same prominence and iterate over all options in the list. This
62
     * variable keeps track how many option HTML code we've already sent, so
63
     * that we can iterate correctly.
64
     * 
65
     * Only used inside noPrefillText variant of the optiontext() call
66
     * 
67
     * @var integer
68
     */
69
    private $optionIterator;
70
71
    private $htmlDatatypeTexts;
72
    
73
    private $enumPrettyPrints;
74
    /**
75
     * Which attributes are we talking about?
76
     * @param array  $options the options of interest
77
     * @param string $level   the level on which these options were defined by the user (not applicable for XHR UI, then it is NULL)
78
     */
79
    public function __construct(array $options, string $level = NULL)
80
    {
81
        $this->listOfOptions = $options;
82
        $this->level = $level;
83
        $this->allLocationCount = 0;
84
85
        $this->enumPrettyPrints = [
86
            "ask" => _("Ask User"),
87
            "ask-preagreed" => _("Ask User; T&C Pre-Agreed"),
88
            "always" => _("Always"),
89
            "always-preagreed" => _("Always; T&C Pre-Agreed"),
90
        ];
91
        $openRoamingTail = "";
92
        foreach ($this->enumPrettyPrints as $optionName => $optionDisplay) {
93
            $openRoamingTail .= "<option value='$optionName'>$optionDisplay</option>";
94
        }
95
        
96
        $this->htmlDatatypeTexts = [
97
            \core\Options::TYPECODE_FILE => ["html" => "input type='file'", "tail" => ' size=\'10\''],
98
            \core\Options::TYPECODE_BOOLEAN => ["html" => "input type='checkbox' checked", "tail" => ''],
99
            \core\Options::TYPECODE_INTEGER => ["html" => "input type='number'", "tail" => ''],
100
            \core\Options::TYPECODE_STRING => ["html" => "input type='string'", "tail" => ''],
101
            \core\Options::TYPECODE_ENUM_OPENROAMING => ["html" => "select", "tail" => ">$openRoamingTail</select"],
102
            \core\Options::TYPECODE_TEXT => ["html" => "textarea cols='30' rows='3'", "tail" => '></textarea'],
103
        ];
104
    }
105
106
    /**
107
     * creates a table with all the set options prefilled. Only displays options
108
     * of the category indicated.
109
     * @param string $attributePrefix category of option to display
110
     * @param string $fed             the federation we are in
111
     * @return string HTML code <table>
112
     */
113
    public function prefilledOptionTable(string $attributePrefix, $fed)
114
    {
115
        $retval = "<table id='expandable_$attributePrefix" . "_options'>";
116
117
        $prepopulate = [];
118
        foreach ($this->listOfOptions as $existingAttribute) {
119
            if ($existingAttribute['level'] == $this->level) {
120
                $prepopulate[] = $existingAttribute;
121
            }
122
        }
123
        if (is_array($prepopulate) && ( count($prepopulate) > 0 || $attributePrefix == "device-specific" || $attributePrefix == "eap-specific" )) { // editing... fill with values
124
            $retval .= $this->addOptionEdit($attributePrefix, $prepopulate);
125
        } else {
126
            $retval .= $this->addOptionNew($attributePrefix, $fed);
127
        }
128
        $retval .= "</table>";
129
        return $retval;
130
    }
131
132
    /**
133
     * Displays options for a given option class, in Edit mode.
134
     * 
135
     * @param string $class       the class of options that is to be displayed
136
     * @param array  $prepopulate should an empty set of fillable options be displayed, or do we have existing data to prefill with
137
     * @return string
138
     */
139
    private function addOptionEdit(string $class, array $prepopulate = [])
140
    { // no GET class ? we've been called directly:
141
        // this can mean either a new object (list all options with empty values)
142
        // or that an object is to be edited. In that case, $prepopulated has to
143
        // contain the array of existing variables
144
        // we expect the variable $class to contain the class of options
145
        $retval = "";
146
        $optioninfo = \core\Options::instance();
147
        $loggerInstance = new \core\common\Logging();
148
        
149
        $blackListOnPrefill = "user:fedadmin|managedsp:vlan|managedsp:operatorname";
150
        if (\config\Master::FUNCTIONALITY_LOCATIONS['CONFASSISTANT_SILVERBULLET'] == "LOCAL" && \config\Master::FUNCTIONALITY_LOCATIONS['CONFASSISTANT_RADIUS'] != "LOCAL") {
151
            $blackListOnPrefill .= "|fed:silverbullet";
152
        }
153
        foreach ($prepopulate as $option) {
154
            if (preg_match("/^$class:/", $option['name']) && !preg_match("/($blackListOnPrefill)/", $option['name'])) {
155
                $optiontypearray = $optioninfo->optionType($option['name']);
156
                $loggerInstance->debug(5, "About to execute optiontext with PREFILL!\n");
157
                $retval .= $this->optiontext([$option['name']], ($optiontypearray["type"] == "file" ? 'ROWID-' . $option['level'] . '-' . $option['row_id'] : $option['value']), $option['lang']);
158
            }
159
        }
160
        return $retval;
161
    }
162
163
    /**
164
     * Find which options to expose to UI and which to hide.
165
     * Not all options defined in the database are (always) displayed. Some have
166
     * custom UI not matching the usual dropdown display, some depend on context
167
     * (e.g. OpenRoaming or not, depending on whether the fed operator wants it
168
     * 
169
     * @param string $class the type of options requested
170
     * @param string $fed   the federation TLD, to determine fed ops preference context
171
     * @return array the list of options to display
172
     */
173
    public static function enumerateOptionsToDisplay($class, $fed, $device='')
174
    {
175
        $optioninfo = \core\Options::instance();
176
        $loggerInstance = new \core\common\Logging();
177
        $list = $optioninfo->availableOptions($class);
178
        // use federation context to delete more options, if the feds don't like
179
        // a particular one
180
        $fedInstance = new \core\Federation($fed);
181
        switch ($class) {
182
            case "general":
183
                unset($list[array_search("general:geo_coordinates", $list)]);
184
                break;
185
            case "user":
186
                unset($list[array_search("user:fedadmin", $list)]);
187
                break;
188
            case "managedsp":
189
                unset($list[array_search("managedsp:vlan", $list)]);
190
                unset($list[array_search("managedsp:operatorname", $list)]);
191
                break;
192
            case "fed":
193
                //normally, we have nothing to hide on that level
194
                // if we are a Managed IdP exclusive deployment, do not display or allow
195
                // to change the "Enable Managed IdP" boolean - it is simply always there
196
                if (\config\Master::FUNCTIONALITY_LOCATIONS['CONFASSISTANT_SILVERBULLET'] == "LOCAL" && \config\Master::FUNCTIONALITY_LOCATIONS['CONFASSISTANT_RADIUS'] != "LOCAL") {
197
                    unset($list[array_search("fed:silverbullet", $list)]);
198
                }
199
                break;
200
            case "media":
201
                if ($fedInstance->getAttributes("fed:openroaming") == []) {
202
                    // no openroaming here
203
                    unset($list[array_search("media:openroaming", $list)]);
204
                }
205
                break;
206
            case "device-specific":
207
                if ($device != '') {
208
                    $factory = new \core\DeviceFactory($device);
209
                    $dev = $factory->device;
210
                    foreach ($list as $l) {
211
                        $optFlag = $optioninfo->optionType($l)['flag'];
212
                        if ($optFlag == "SPECIFIC") {
213
                            $opt = str_replace('device-specific:', '', $l);
214
                            if (!isset($dev->options['device_options']) || !in_array($opt, $dev->options['device_options'])) {
215
                                $loggerInstance->debug(5, $l, "removing option: ", "\n");
216
                                unset($list[array_search($l, $list)]);
217
                            }
218
                        }
219
                    }
220
                }
221
                 break;
222
            default:
223
                break;
224
        }
225
226
        return $list;
227
    }
228
229
    /**
230
     * Displays options for a given option class, in New mode.
231
     * 
232
     * @param string $class           the class of options that is to be displayed
233
     * @param string $fed             the federation we are in
234
     * @return string
235
     */
236
    private function addOptionNew(string $class, $fed)
237
    {
238
        $retval = "";
239
240
        $list2 = array_values(OptionDisplay::enumerateOptionsToDisplay($class, $fed));
241
242
        // add as many options as there are different option types
243
        $numberOfOptions = count($list2);
244
        for ($this->optionIterator = 0; $this->optionIterator < $numberOfOptions; $this->optionIterator++) {
245
            $retval .= $this->optiontext($list2);
246
        }
247
        return $retval;
248
    }
249
250
    /**
251
     * produce code for a option-specific tooltip
252
     * @param int     $rowid     the number (once during page build) of the option 
253
     *                           that should get the tooltip
254
     * @param string  $input     the option name. Tooltip for it will be displayed
255
     *                           if we have one available.
256
     * @param boolean $isVisible should the tooltip be visible with the option,
257
     *                           or are they both currently hidden?
258
     * @return string
259
     */
260
    private function tooltip($rowid, $input, $isVisible)
261
    {
262
        \core\common\Entity::intoThePotatoes();
263
        $descriptions = [];
264
        if (count(\config\ConfAssistant::CONSORTIUM['ssid']) > 0) {
265
            $descriptions["media:SSID"] = sprintf(_("This attribute can be set if you want to configure an additional SSID besides the default SSIDs for %s. It is almost always a bad idea not to use the default SSIDs. The only exception is if you have premises with an overlap of the radio signal with another %s hotspot. Typical misconceptions about additional SSIDs include: I want to have a local SSID for my own users. It is much better to use the default SSID and separate user groups with VLANs. That approach has two advantages: 1) your users will configure %s properly because it is their everyday SSID; 2) if you use a custom name and advertise this one as extra secure, your users might at some point roam to another place which happens to have the same SSID name. They might then be misled to believe that they are connecting to an extra secure network while they are not."), \config\ConfAssistant::CONSORTIUM['display_name'], \config\ConfAssistant::CONSORTIUM['display_name'], \config\ConfAssistant::CONSORTIUM['display_name']);
266
        }
267
        $descriptions["media:force_proxy"] = sprintf(_("The format of this option is: IPv4|IPv6|hostname:port . Forcing your users through a content filter of your own is a significant invasion of user self-determination. It also has technical issues. Please thoroughly read the discussion at %s before specifying a proxy with this option. This feature is currently experimental and only has an effect in Apple installers."), "https://github.com/GEANT/CAT/issues/96");
268
        $descriptions["managedsp:realmforvlan"] = sprintf(_("If you are also using %s, then your own realm is automatically tagged with the VLAN you choose, there is no need to add it here manually."), \core\ProfileSilverbullet::PRODUCTNAME);
269
        $descriptions["media:openroaming"] = sprintf(_("By opting in to OpenRoaming, you agree to be bound by the %s."), "eduroam Ecosystem Broker OpenRoaming Identity Provider Policy") .
270
                " " .
271
                sprintf(_("Note that your requirement to inform users about the OpenRoaming End User Terms and Conditions is fulfilled when directing your end users to the %s download portal for installer download. Any other means of providing the installers needs to present this information via its own channel."), \config\Master::APPEARANCE['productname']) .
272
                " " .
273
                _("You are also aware that for best technical interoperability, you need to add a DNS entry into the DNS zone of your RADIUS realm.") .
274
                " " .
275
                _("Read the instructions in the wiki.");
276
        \core\common\Entity::outOfThePotatoes();
277
        if (!isset($descriptions[$input])) {
278
            return "";
279
        }
280
        return "<span class='tooltip' id='S$rowid-tooltip-$input' style='display:" . ($isVisible ? "block" : "none") . "' onclick='alert(\"" . $descriptions[$input] . "\")'><img src='../resources/images/icons/question-mark-icon.png" . "'></span>";
281
    }
282
283
    /**
284
     * 
285
     * @param int   $rowid the number (once during page build) of the option 
286
     *                     that should get the tooltip
287
     * @param array $list  elements of the drop-down list
288
     * @return array HTML code and which option is active
289
     * @throws \Exception
290
     */
291
    private function selectElement($rowid, $list)
292
    {
293
        $jsmagic = "onchange='
294
                               if (/#ML#/.test(document.getElementById(\"option-S" . $rowid . "-select\").value)) {
295
                                   document.getElementById(\"S$rowid-input-langselect\").style.display = \"block\";
296
                                   } else {
297
                                   document.getElementById(\"S$rowid-input-langselect\").style.display = \"none\";
298
                                   }";
299
        foreach (array_keys($this->htmlDatatypeTexts) as $key) {
300
            $jsmagic .= "if (/#" . $key . "#/.test(document.getElementById(\"option-S" . $rowid . "-select\").value)) {
301
                                  document.getElementById(\"S$rowid-input-file\").style.display = \"" . ($key == \core\Options::TYPECODE_FILE ? "block" : "none") . "\";
302
                                  document.getElementById(\"S$rowid-input-text\").style.display = \"" . ($key == \core\Options::TYPECODE_TEXT ? "block" : "none") . "\";
303
                                  document.getElementById(\"S$rowid-input-string\").style.display = \"" . ($key == \core\Options::TYPECODE_STRING ? "block" : "none") . "\";
304
                                  document.getElementById(\"S$rowid-input-enum_openroaming\").style.display = \"" . ($key == \core\Options::TYPECODE_ENUM_OPENROAMING ? "block" : "none") . "\";
305
                                  document.getElementById(\"S$rowid-input-boolean\").style.display = \"" . ($key == \core\Options::TYPECODE_BOOLEAN ? "block" : "none") . "\";
306
                                  document.getElementById(\"S$rowid-input-integer\").style.display = \"" . ($key == \core\Options::TYPECODE_INTEGER ? "block" : "none") . "\";
307
                             }
308
                             ";
309
            // hide all tooltips (each is a <span>, and there are no other <span>s)
310
            $jsmagic .= <<< FOO
311
                    var ourtooltips = document.querySelectorAll(&#34;[id^=&#39;S$rowid-tooltip-&#39;]&#34;);
312
                    for (var i=0; i<ourtooltips.length; i++) {
313
                      ourtooltips[i].style.display = "none";
314
                    }
315
                    var optionnamefull = document.getElementById("option-S$rowid-select").value;
316
                    var firstdelimiter = optionnamefull.indexOf("#");
317
                    var optionname = optionnamefull.substring(0,firstdelimiter);
318
                    var tooltipifany = document.getElementById("S$rowid-tooltip-"+optionname);
319
                    if (tooltipifany != null) {
320
                      tooltipifany.style.display = "block";
321
                    }
322
FOO;
323
        }
324
        $jsmagic .= "'";
325
326
        $optioninfo = \core\Options::instance();
327
        $retval = "<span style='display:flex';>";
328
        $iterator = 0;
329
        $tooltips = "";
330
        $uiElements = new UIElements();
331
        $activelisttype = [];
332
        switch (count($list)) {
333
            case 1: // if there is only one option available, don't introduce an artificial drop-down for it
334
                $value = array_shift($list);
335
                $listtype = $optioninfo->optionType($value);
336
                $retval .= $uiElements->displayName($value);
337
                $retval .= "<input type='hidden' name='option[S$rowid]' value='$value#" . $listtype["type"] . "#" . $listtype["flag"] . "#'/>";
338
                $activelisttype = $listtype;
339
                $tooltips = $this->tooltip($rowid, $value, TRUE);
340
                break;
341
            default:
342
                $retval .= "<select id='option-S$rowid-select' name='option[S$rowid]' $jsmagic>";
343
                foreach ($list as $value) {
344
                    $listtype = $optioninfo->optionType($value);
345
                    $retval .= "<option id='option-S$rowid-v-$value' value='$value#" . $listtype["type"] . "#" . $listtype["flag"] . "#' ";
346
                    if ($iterator == $this->optionIterator) {
347
                        $retval .= "selected='selected'";
348
                        $activelisttype = $listtype;
349
                        $tooltips .= $this->tooltip($rowid, $value, TRUE);
350
                    } else {
351
                        $tooltips .= $this->tooltip($rowid, $value, FALSE);
352
                    }
353
                    $retval .= ">" . $uiElements->displayName($value) . "</option>";
354
                    $iterator++;
355
                }
356
357
                if (count($activelisttype) == 0) {
358
                    throw new \Exception("We should have found the active list type by now!");
359
                }
360
                $retval .= "</select>";
361
        }
362
        $retval .= $tooltips;
363
        $retval .= "</span>";
364
365
        return ["TEXT" => $retval, "ACTIVE" => $activelisttype];
366
    }
367
368
    /**
369
     * HTML code to display the language selector
370
     * 
371
     * @param int     $rowid       the number (once during page build) of the option 
372
     *                             that should get the tooltip
373
     * @param boolean $makeVisible is the language selector to be made visible?
374
     * @return string
375
     */
376
    private function selectLanguage($rowid, $makeVisible)
377
    {
378
        \core\common\Entity::intoThePotatoes();
379
        $retval = "<select style='display:" . ($makeVisible ? "block" : "none") . "' name='value[S$rowid-lang]' id='S" . $rowid . "-input-langselect'>
380
            <option value='' name='select_language' selected>" . _("select language") . "</option>
381
            <option value='C' name='all_languages'>" . _("default/other languages") . "</option>";
382
        foreach (\config\Master::LANGUAGES as $langindex => $possibleLang) {
383
            $thislang = $possibleLang['display'];
384
            $retval .= "<option value='$langindex' name='$langindex'>$thislang</option>";
385
        }
386
        $retval .= "</select>";
387
        \core\common\Entity::outOfThePotatoes();
388
        return $retval;
389
    }
390
391
    /**
392
     * HTML code for a given option. Marks the matching datatype as visible, all other datatypes hidden
393
     * @param int   $rowid      the number (once during page build) of the option 
394
     *                          that should get the tooltip
395
     * @param array $activetype the active datatype that is to be visible
396
     * @return string
397
     */
398
    private function inputFields($rowid, $activetype)
399
    {
400
        $retval = "";
401
        foreach ($this->htmlDatatypeTexts as $key => $type) {
402
            $retval .= "<" . $type['html'] . " style='display:" . ($activetype['type'] == $key ? "block" : "none") . "' name='value[S$rowid-$key]' id='S" . $rowid . "-input-" . $key . "'" . $type['tail'] . ">";
403
        }
404
        return $retval;
405
    }
406
407
    /**
408
     * HTML code to display a "fresh" option (including type selector and JavaScript to show/hide relevant input fields)
409
     * @param int   $rowid the HTML field base name of the option to be displayed
410
     * @param array $list  the list of option names to include in the type selector
411
     * @return string HTML code
412
     * @throws Exception
413
     */
414
    private function noPrefillText(int $rowid, array $list)
415
    {
416
        // first column: the <select> element with the names of options and their field-toggling JS magic
417
        $selectorInfo = $this->selectElement($rowid, $list);
418
        $retval = "<td>" . $selectorInfo["TEXT"] . "</td>";
419
        // second column: the <select> element for language selection - only visible if the active option is multi-lang
420
        $retval .= "<td>" . $this->selectLanguage($rowid, $selectorInfo['ACTIVE']['flag'] == "ML") . "</td>";
421
        // third column: the actual input fields; the data type of the active option is visible, all others hidden
422
        $retval .= "<td>" . $this->inputFields($rowid, $selectorInfo['ACTIVE']) . "</td>";
423
        return $retval;
424
    }
425
426
    /**
427
     * generates HTML code that displays an already set option.
428
     * 
429
     * @param int    $rowid       the HTML field base name of the option to be displayed
430
     * @param string $optionName  the name of the option to display
431
     * @param string $optionValue the value of the option to display
432
     * @param mixed  $optionLang  the language of the option to display
433
     * @return string HTML code
434
     * @throws Exception
435
     */
436
    private function prefillText(int $rowid, string $optionName, string $optionValue, $optionLang)
437
    {
438
        \core\common\Entity::intoThePotatoes();
439
        $retval = "";
440
        $optioninfo = \core\Options::instance();
441
        $loggerInstance = new \core\common\Logging();
442
        $loggerInstance->debug(5, "Executed with PREFILL $optionValue!\n");
443
        $retval .= "<td>";
444
        $uiElements = new UIElements();
445
        $listtype = $optioninfo->optionType($optionName);
446
        $retval .= "<span style='display:flex;'>" . $uiElements->displayName($optionName);
447
        $retval .= $this->tooltip($rowid, $optionName, TRUE) . "</span>";
448
        $retval .= "<input type='hidden' id='option-S$rowid-select' name='option[S$rowid]' value='$optionName#" . $listtype["type"] . "#" . $listtype["flag"] . "#' ></td>";
449
450
        // language tag if any
451
        $retval .= "<td>";
452
        if ($listtype["flag"] == "ML") {
453
454
            $language = "(" . strtoupper($optionLang) . ")";
455
            if ($optionLang == 'C') {
456
                $language = _("(default/other languages)");
457
            }
458
            $retval .= $language;
459
            $retval .= "<input type='hidden' name='value[S$rowid-lang]' id='S" . $rowid . "-input-langselect' value='" . $optionLang . "' style='display:block'>";
460
        }
461
        $retval .= "</td>";
462
// attribute content
463
        $retval .= "<td>";
464
        $displayedVariant = "";
465
        switch ($listtype["type"]) {
466
            case \core\Options::TYPECODE_COORDINATES:
467
                $this->allLocationCount = $this->allLocationCount + 1;
468
                // display of the locations varies by map provider
469
                $classname = "\web\lib\admin\Map" . \config\ConfAssistant::MAPPROVIDER['PROVIDER'];
470
                $link = $classname::optionListDisplayCode($optionValue, $this->allLocationCount);
471
                $retval .= "<input readonly style='display:none' type='text' name='value[S$rowid-" . \core\Options::TYPECODE_TEXT . "]' id='S$rowid-input-text' value='$optionValue'>$link";
472
                break;
473
            case \core\Options::TYPECODE_FILE:
474
                $retval .= "<input readonly type='text' name='value[S$rowid-" . \core\Options::TYPECODE_STRING . "]' id='S" . $rowid . "-input-string' style='display:none' value='" . urlencode($optionValue) . "'>";
475
                $uiElements = new UIElements();
476
                switch ($optionName) {
477
                    case "eap:ca_file":
478
                    // fall-through intentional: display both types the same way
479
                    case "fed:minted_ca_file":
480
                        $retval .= $uiElements->previewCAinHTML($optionValue);
481
                        break;
482
                    case "general:logo_file":
483
                    // fall-through intentional: display both types the same way
484
                    case "fed:logo_file":
485
                        $retval .= $uiElements->previewImageinHTML($optionValue);
486
                        break;
487
                    case "support:info_file":
488
                        $retval .= $uiElements->previewInfoFileinHTML($optionValue);
489
                        break;
490
                    default:
491
                        $retval .= _("file content");
492
                }
493
                break;
494
            case \core\Options::TYPECODE_ENUM_OPENROAMING: // is a string after all
495
                $displayedVariant = $this->enumPrettyPrints[$optionValue];
496
                $retval .= "<strong>$displayedVariant</strong><input type='hidden' name='value[S$rowid-" . $listtype['type'] . "]' id='S" . $rowid . "-input-" . $listtype["type"] . "' value=\"" . htmlspecialchars($optionValue) . "\" style='display:block'>";
497
                break;
498
            case \core\Options::TYPECODE_STRING:
499
            // fall-thorugh is intentional; mostly identical HTML code for the three types
500
            case \core\Options::TYPECODE_INTEGER:
501
            // fall-thorugh is intentional; mostly identical HTML code for the three types
502
            case \core\Options::TYPECODE_TEXT:
503
                $displayedVariant = $optionValue; // for all three types, value tag and actual display are identical
504
                $retval .= "<strong>$displayedVariant</strong><input type='hidden' name='value[S$rowid-" . $listtype['type'] . "]' id='S" . $rowid . "-input-" . $listtype["type"] . "' value=\"" . htmlspecialchars($optionValue) . "\" style='display:block'>";
505
                break;
506
            case \core\Options::TYPECODE_BOOLEAN:
507
                $displayedVariant = ($optionValue == "on" ? _("on") : _("off"));
508
                $retval .= "<strong>$displayedVariant</strong><input type='hidden' name='value[S$rowid-" . $listtype['type'] . "]' id='S" . $rowid . "-input-" . $listtype["type"] . "' value=\"" . htmlspecialchars($optionValue) . "\" style='display:block'>";
509
                break;
510
            default:
511
                // this should never happen!
512
                throw new Exception("Internal Error: unknown attribute type $listtype!");
513
        }
514
        $retval .= "</td>";
515
        \core\common\Entity::outOfThePotatoes();
516
        return $retval;
517
    }
518
519
    /**
520
     * Displays a container for options. Either with prefilled data or empty; if
521
     * empty then has HTML <input> tags with clever javaScript to allow selection
522
     * of different option names and types
523
     * @param array  $list         options which should be displayed; can be only exactly one if existing option, or multiple if new option type
524
     * @param string $prefillValue for an existing option, it's value to be displayed
525
     * @param string $prefillLang  for an existing option, the language of the value to be displayed
526
     * @return string HTML code <tr>
527
     * @throws Exception
528
     */
529
    public function optiontext(array $list, string $prefillValue = NULL, string $prefillLang = NULL)
530
    {
531
        $rowid = mt_rand();
532
533
        $retval = "<tr id='option-S$rowid' style='vertical-align:top'>";
534
535
        $item = "MULTIPLE";
536
        if ($prefillValue === NULL) {
537
            $retval .= $this->noPrefillText($rowid, $list);
538
        }
539
540
        if ($prefillValue !== NULL) {
541
            // prefill is always only called with a list with exactly one element.
542
            // if we see anything else here, get excited.
543
            if (count($list) != 1) {
544
                throw new Exception("Optiontext prefilled display only can work with exactly one option!");
545
            }
546
            $item = array_pop($list);
547
            $retval .= $this->prefillText($rowid, $item, $prefillValue, $prefillLang);
548
        }
549
        $retval .= "
550
551
       <td>
552
          <button type='button' class='delete' onclick='";
553
        if ($prefillValue !== NULL && $item == "general:geo_coordinates") {
554
            $funcname = "Map" . \config\ConfAssistant::MAPPROVIDER['PROVIDER'] . 'DeleteCoord';
555
            $retval .= 'if (typeof ' . $funcname . ' === "function") { ' . $funcname . '(' . $this->allLocationCount . '); } ';
556
        }
557
        $retval .= 'deleteOption("option-S' . $rowid . '")';
558
        $retval .= "'>-</button>
559
       </td>
560
    </tr>";
561
        return $retval;
562
    }
563
}
564