Test Setup Failed
Push — master ( e08099...578d16 )
by Stefan
05:59
created

OptionDisplay::inputFields()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
c 0
b 0
f 0
dl 0
loc 7
rs 10
cc 3
nc 3
nop 2
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/otion 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
        $blackListOnPrefill = "user:fedadmin|managedsp:vlan|managedsp:operatorname";
148
        if (\config\Master::FUNCTIONALITY_LOCATIONS['CONFASSISTANT_SILVERBULLET'] == "LOCAL" && \config\Master::FUNCTIONALITY_LOCATIONS['CONFASSISTANT_RADIUS'] != "LOCAL") {
149
            $blackListOnPrefill .= "|fed:silverbullet";
150
        }
151
        foreach ($prepopulate as $option) {
152
            if (preg_match("/$class:/", $option['name']) && !preg_match("/($blackListOnPrefill)/", $option['name'])) {
153
                $optiontypearray = $optioninfo->optionType($option['name']);
154
                $loggerInstance = new \core\common\Logging();
155
                $loggerInstance->debug(5, "About to execute optiontext with PREFILL!\n");
156
                $retval .= $this->optiontext([$option['name']], ($optiontypearray["type"] == "file" ? 'ROWID-' . $option['level'] . '-' . $option['row'] : $option['value']), $option['lang']);
157
            }
158
        }
159
        return $retval;
160
    }
161
162
    /**
163
     * Find which options to expose to UI and which to hide.
164
     * Not all options defined in the database are (always) displayed. Some have
165
     * custom UI not matching the usual dropdown display, some depend on context
166
     * (e.g. OpenRoaming or not, depending on whether the fed operator wants it
167
     * 
168
     * @param string $class the type of options requested
169
     * @param string $fed   the federation TLD, to determine fed ops prefernce context
170
     * @return array the list of options to display
171
     */
172
    public static function enumerateOptionsToDisplay($class, $fed)
173
    {
174
        $optioninfo = \core\Options::instance();
175
176
        $list = $optioninfo->availableOptions($class);
177
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_always", $list)]);
204
                    unset($list[array_search("media:openroaming_ask", $list)]);
205
                    unset($list[array_search("media:openroaming", $list)]);
206
                }
207
                break;
208
            default:
209
                break;
210
        }
211
212
        return $list;
213
    }
214
215
    /**
216
     * Displays options for a given option class, in New mode.
217
     * 
218
     * @param string $class           the class of options that is to be displayed
219
     * @param string $fed             the federation we are in
220
     * @return string
221
     */
222
    private function addOptionNew(string $class, $fed)
223
    {
224
        $retval = "";
225
226
        $list2 = array_values(OptionDisplay::enumerateOptionsToDisplay($class, $fed));
227
228
        // add as many options as there are different option types
229
        $numberOfOptions = count($list2);
230
        for ($this->optionIterator = 0; $this->optionIterator < $numberOfOptions; $this->optionIterator++) {
231
            $retval .= $this->optiontext($list2);
232
        }
233
        return $retval;
234
    }
235
236
    /**
237
     * produce code for a option-specific tooltip
238
     * @param int     $rowid     the number (nonce during page build) of the option 
239
     *                           that should get the tooltip
240
     * @param string  $input     the option name. Tooltip for it will be displayed
241
     *                           if we have one available.
242
     * @param boolean $isVisible should the tooltip be visible with the option,
243
     *                           or are they both currently hidden?
244
     * @return string
245
     */
246
    private function tooltip($rowid, $input, $isVisible)
247
    {
248
        \core\common\Entity::intoThePotatoes();
249
        $descriptions = [];
250
        if (count(\config\ConfAssistant::CONSORTIUM['ssid']) > 0) {
251
            $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']);
252
        }
253
        $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 throughly 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");
254
        $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);
255
        $descriptions["media:openroaming"] = sprintf(_("By opting in to OpenRoaming, you agree to be bound by the %s."), "eduroam Ecosystem Broker OpenRoaming Identity Provider Policy") .
256
                " " .
257
                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']) .
258
                " " .
259
                _("You are also aware that for best technical interoperability, you need to add a DNS entry into the DNS zone of your RADIUS realm.") .
260
                " " .
261
                _("Read the instructions in the wiki.");
262
        \core\common\Entity::outOfThePotatoes();
263
        if (!isset($descriptions[$input])) {
264
            return "";
265
        }
266
        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>";
267
    }
268
269
    /**
270
     * 
271
     * @param int   $rowid the number (nonce during page build) of the option 
272
     *                     that should get the tooltip
273
     * @param array $list  elements of the drop-down list
274
     * @return array HTML code and which option is active
275
     * @throws \Exception
276
     */
277
    private function selectElement($rowid, $list)
278
    {
279
        $jsmagic = "onchange='
280
                               if (/#ML#/.test(document.getElementById(\"option-S" . $rowid . "-select\").value)) {
281
                                   document.getElementById(\"S$rowid-input-langselect\").style.display = \"block\";
282
                                   } else {
283
                                   document.getElementById(\"S$rowid-input-langselect\").style.display = \"none\";
284
                                   }";
285
        foreach (array_keys($this->htmlDatatypeTexts) as $key) {
286
            $jsmagic .= "if (/#" . $key . "#/.test(document.getElementById(\"option-S" . $rowid . "-select\").value)) {
287
                                  document.getElementById(\"S$rowid-input-file\").style.display = \"" . ($key == \core\Options::TYPECODE_FILE ? "block" : "none") . "\";
288
                                  document.getElementById(\"S$rowid-input-text\").style.display = \"" . ($key == \core\Options::TYPECODE_TEXT ? "block" : "none") . "\";
289
                                  document.getElementById(\"S$rowid-input-string\").style.display = \"" . ($key == \core\Options::TYPECODE_STRING ? "block" : "none") . "\";
290
                                  document.getElementById(\"S$rowid-input-enum_openroaming\").style.display = \"" . ($key == \core\Options::TYPECODE_ENUM_OPENROAMING ? "block" : "none") . "\";
291
                                  document.getElementById(\"S$rowid-input-boolean\").style.display = \"" . ($key == \core\Options::TYPECODE_BOOLEAN ? "block" : "none") . "\";
292
                                  document.getElementById(\"S$rowid-input-integer\").style.display = \"" . ($key == \core\Options::TYPECODE_INTEGER ? "block" : "none") . "\";
293
                             }
294
                             ";
295
            // hide all tooltips (each is a <span>, and there are no other <span>s)
296
            $jsmagic .= <<< FOO
297
                    var ourtooltips = document.querySelectorAll(&#34;[id^=&#39;S$rowid-tooltip-&#39;]&#34;);
298
                    for (var i=0; i<ourtooltips.length; i++) {
299
                      ourtooltips[i].style.display = "none";
300
                    }
301
                    var optionnamefull = document.getElementById("option-S$rowid-select").value;
302
                    var firstdelimiter = optionnamefull.indexOf("#");
303
                    var optionname = optionnamefull.substring(0,firstdelimiter);
304
                    var tooltipifany = document.getElementById("S$rowid-tooltip-"+optionname);
305
                    if (tooltipifany != null) {
306
                      tooltipifany.style.display = "block";
307
                    }
308
FOO;
309
        }
310
        $jsmagic .= "'";
311
312
        $optioninfo = \core\Options::instance();
313
        $retval = "<span style='display:flex';>";
314
        $iterator = 0;
315
        $tooltips = "";
316
        $uiElements = new UIElements();
317
        $activelisttype = [];
318
        switch (count($list)) {
319
            case 1: // if there is only one option available, don't introduce an artificial drop-down for it
320
                $value = array_shift($list);
321
                $listtype = $optioninfo->optionType($value);
322
                $retval .= $uiElements->displayName($value);
323
                $retval .= "<input type='hidden' name='option[S$rowid]' value='$value#" . $listtype["type"] . "#" . $listtype["flag"] . "#'/>";
324
                $activelisttype = $listtype;
325
                $tooltips = $this->tooltip($rowid, $value, TRUE);
326
                break;
327
            default:
328
                $retval .= "<select id='option-S$rowid-select' name='option[S$rowid]' $jsmagic>";
329
                foreach ($list as $value) {
330
                    $listtype = $optioninfo->optionType($value);
331
                    $retval .= "<option id='option-S$rowid-v-$value' value='$value#" . $listtype["type"] . "#" . $listtype["flag"] . "#' ";
332
                    if ($iterator == $this->optionIterator) {
333
                        $retval .= "selected='selected'";
334
                        $activelisttype = $listtype;
335
                        $tooltips .= $this->tooltip($rowid, $value, TRUE);
336
                    } else {
337
                        $tooltips .= $this->tooltip($rowid, $value, FALSE);
338
                    }
339
                    $retval .= ">" . $uiElements->displayName($value) . "</option>";
340
                    $iterator++;
341
                }
342
343
                if (count($activelisttype) == 0) {
344
                    throw new \Exception("We should have found the active list type by now!");
345
                }
346
                $retval .= "</select>";
347
        }
348
        $retval .= $tooltips;
349
        $retval .= "</span>";
350
351
        return ["TEXT" => $retval, "ACTIVE" => $activelisttype];
352
    }
353
354
    /**
355
     * HTML code to display the language selector
356
     * 
357
     * @param int     $rowid       the number (nonce during page build) of the option 
358
     *                             that should get the tooltip
359
     * @param boolean $makeVisible is the language selector to be made visible?
360
     * @return string
361
     */
362
    private function selectLanguage($rowid, $makeVisible)
363
    {
364
        \core\common\Entity::intoThePotatoes();
365
        $retval = "<select style='display:" . ($makeVisible ? "block" : "none") . "' name='value[S$rowid-lang]' id='S" . $rowid . "-input-langselect'>
366
            <option value='' name='select_language' selected>" . _("select language") . "</option>
367
            <option value='C' name='all_languages'>" . _("default/other languages") . "</option>";
368
        foreach (\config\Master::LANGUAGES as $langindex => $possibleLang) {
369
            $thislang = $possibleLang['display'];
370
            $retval .= "<option value='$langindex' name='$langindex'>$thislang</option>";
371
        }
372
        $retval .= "</select>";
373
        \core\common\Entity::outOfThePotatoes();
374
        return $retval;
375
    }
376
377
    /**
378
     * HTML code for a given option. Marks the matching datatype as visible, all other datatypes hidden
379
     * @param int   $rowid      the number (nonce during page build) of the option 
380
     *                          that should get the tooltip
381
     * @param array $activetype the active datatype that is to be visible
382
     * @return string
383
     */
384
    private function inputFields($rowid, $activetype)
385
    {
386
        $retval = "";
387
        foreach ($this->htmlDatatypeTexts as $key => $type) {
388
            $retval .= "<" . $type['html'] . " style='display:" . ($activetype['type'] == $key ? "block" : "none") . "' name='value[S$rowid-$key]' id='S" . $rowid . "-input-" . $key . "'" . $type['tail'] . ">";
389
        }
390
        return $retval;
391
    }
392
393
    /**
394
     * HTML code to display a "fresh" option (including type selector and JavaScript to show/hide relevant input fields)
395
     * @param int   $rowid the HTML field base name of the option to be displayed
396
     * @param array $list  the list of option names to include in the type selector
397
     * @return string HTML code
398
     * @throws Exception
399
     */
400
    private function noPrefillText(int $rowid, array $list)
401
    {
402
        // first column: the <select> element with the names of options and their field-toggling JS magic
403
        $selectorInfo = $this->selectElement($rowid, $list);
404
        $retval = "<td>" . $selectorInfo["TEXT"] . "</td>";
405
        // second column: the <select> element for language selection - only visible if the active option is multi-lang
406
        $retval .= "<td>" . $this->selectLanguage($rowid, $selectorInfo['ACTIVE']['flag'] == "ML") . "</td>";
407
        // third column: the actual input fields; the data type of the active option is visible, all others hidden
408
        $retval .= "<td>" . $this->inputFields($rowid, $selectorInfo['ACTIVE']) . "</td>";
409
        return $retval;
410
    }
411
412
    /**
413
     * generates HTML code that displays an already set option.
414
     * 
415
     * @param int    $rowid       the HTML field base name of the option to be displayed
416
     * @param string $optionName  the name of the option to display
417
     * @param string $optionValue the value of the option to display
418
     * @param mixed  $optionLang  the language of the option to display
419
     * @return string HTML code
420
     * @throws Exception
421
     */
422
    private function prefillText(int $rowid, string $optionName, string $optionValue, $optionLang)
423
    {
424
        \core\common\Entity::intoThePotatoes();
425
        $retval = "";
426
        $optioninfo = \core\Options::instance();
427
        $loggerInstance = new \core\common\Logging();
428
        $loggerInstance->debug(5, "Executed with PREFILL $optionValue!\n");
429
        $retval .= "<td>";
430
        $uiElements = new UIElements();
431
        $listtype = $optioninfo->optionType($optionName);
432
        $retval .= "<span style='display:flex;'>" . $uiElements->displayName($optionName);
433
        $retval .= $this->tooltip($rowid, $optionName, TRUE) . "</span>";
434
        $retval .= "<input type='hidden' id='option-S$rowid-select' name='option[S$rowid]' value='$optionName#" . $listtype["type"] . "#" . $listtype["flag"] . "#' ></td>";
435
436
        // language tag if any
437
        $retval .= "<td>";
438
        if ($listtype["flag"] == "ML") {
439
440
            $language = "(" . strtoupper($optionLang) . ")";
441
            if ($optionLang == 'C') {
442
                $language = _("(default/other languages)");
443
            }
444
            $retval .= $language;
445
            $retval .= "<input type='hidden' name='value[S$rowid-lang]' id='S" . $rowid . "-input-langselect' value='" . $optionLang . "' style='display:block'>";
446
        }
447
        $retval .= "</td>";
448
// attribute content
449
        $retval .= "<td>";
450
        $displayedVariant = "";
451
        switch ($listtype["type"]) {
452
            case \core\Options::TYPECODE_COORDINATES:
453
                $this->allLocationCount = $this->allLocationCount + 1;
454
                // display of the locations varies by map provider
455
                $classname = "\web\lib\admin\Map" . \config\ConfAssistant::MAPPROVIDER['PROVIDER'];
456
                $link = $classname::optionListDisplayCode($optionValue, $this->allLocationCount);
457
                $retval .= "<input readonly style='display:none' type='text' name='value[S$rowid-" . \core\Options::TYPECODE_TEXT . "]' id='S$rowid-input-text' value='$optionValue'>$link";
458
                break;
459
            case \core\Options::TYPECODE_FILE:
460
                $retval .= "<input readonly type='text' name='value[S$rowid-" . \core\Options::TYPECODE_STRING . "]' id='S" . $rowid . "-input-string' style='display:none' value='" . urlencode($optionValue) . "'>";
461
                $uiElements = new UIElements();
462
                switch ($optionName) {
463
                    case "eap:ca_file":
464
                    // fall-through intentional: display both types the same way
465
                    case "fed:minted_ca_file":
466
                        $retval .= $uiElements->previewCAinHTML($optionValue);
467
                        break;
468
                    case "general:logo_file":
469
                    // fall-through intentional: display both types the same way
470
                    case "fed:logo_file":
471
                        $retval .= $uiElements->previewImageinHTML($optionValue);
472
                        break;
473
                    case "support:info_file":
474
                        $retval .= $uiElements->previewInfoFileinHTML($optionValue);
475
                        break;
476
                    default:
477
                        $retval .= _("file content");
478
                }
479
                break;
480
            case \core\Options::TYPECODE_ENUM_OPENROAMING: // is a string after all
481
                $displayedVariant = $this->enumPrettyPrints[$optionValue];
482
                $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'>";
483
                break;
484
            case \core\Options::TYPECODE_STRING:
485
            // fall-thorugh is intentional; mostly identical HTML code for the three types
486
            case \core\Options::TYPECODE_INTEGER:
487
            // fall-thorugh is intentional; mostly identical HTML code for the three types
488
            case \core\Options::TYPECODE_TEXT:
489
                $displayedVariant = $optionValue; // for all three types, value tag and actual display are identical
490
                $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'>";
491
                break;
492
            case \core\Options::TYPECODE_BOOLEAN:
493
                $displayedVariant = ($optionValue == "on" ? _("on") : _("off"));
494
                $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'>";
495
                break;
496
            default:
497
                // this should never happen!
498
                throw new Exception("Internal Error: unknown attribute type $listtype!");
499
        }
500
        $retval .= "</td>";
501
        \core\common\Entity::outOfThePotatoes();
502
        return $retval;
503
    }
504
505
    /**
506
     * Displays a container for options. Either with prefilled data or empty; if
507
     * empty then has HTML <input> tags with clever javaScript to allow selection
508
     * of different option names and types
509
     * @param array  $list         options which should be displayed; can be only exactly one if existing option, or multiple if new option type
510
     * @param string $prefillValue for an existing option, it's value to be displayed
511
     * @param string $prefillLang  for an existing option, the language of the value to be displayed
512
     * @return string HTML code <tr>
513
     * @throws Exception
514
     */
515
    public function optiontext(array $list, string $prefillValue = NULL, string $prefillLang = NULL)
516
    {
517
        $rowid = mt_rand();
518
519
        $retval = "<tr id='option-S$rowid' style='vertical-align:top'>";
520
521
        $item = "MULTIPLE";
522
        if ($prefillValue === NULL) {
523
            $retval .= $this->noPrefillText($rowid, $list);
524
        }
525
526
        if ($prefillValue !== NULL) {
527
            // prefill is always only called with a list with exactly one element.
528
            // if we see anything else here, get excited.
529
            if (count($list) != 1) {
530
                throw new Exception("Optiontext prefilled display only can work with exactly one option!");
531
            }
532
            $item = array_pop($list);
533
            $retval .= $this->prefillText($rowid, $item, $prefillValue, $prefillLang);
534
        }
535
        $retval .= "
536
537
       <td>
538
          <button type='button' class='delete' onclick='";
539
        if ($prefillValue !== NULL && $item == "general:geo_coordinates") {
540
            $funcname = "Map" . \config\ConfAssistant::MAPPROVIDER['PROVIDER'] . 'DeleteCoord';
541
            $retval .= 'if (typeof ' . $funcname . ' === "function") { ' . $funcname . '(' . $this->allLocationCount . '); } ';
542
        }
543
        $retval .= 'deleteOption("option-S' . $rowid . '")';
544
        $retval .= "'>-</button>
545
       </td>
546
    </tr>";
547
        return $retval;
548
    }
549
}