BuildFormBootstrap.php 35.7 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
<?php
/**
 * Created by PhpStorm.
 * User: crose
 * Date: 1/25/16
 * Time: 10:00 PM
 */

namespace qfq;

use qfq;

13
14
15
16
17
require_once(__DIR__ . '/Constants.php');
require_once(__DIR__ . '/helper/OnArray.php');
require_once(__DIR__ . '/AbstractBuildForm.php');
require_once(__DIR__ . '/exceptions/UserFormException.php');
require_once(__DIR__ . '/report/Link.php');
18

Carsten  Rose's avatar
Carsten Rose committed
19
20
21
22
/**
 * Class BuildFormBootstrap
 * @package qfq
 */
23
24
class BuildFormBootstrap extends AbstractBuildForm {

25
26
27
28
29
30
    private $isFirstPill;

    /**
     * @param array $formSpec
     * @param array $feSpecAction
     * @param array $feSpecNative
31
     * @param array $db Array of 'Database' instances
32
33
     * @throws CodeException
     * @throws UserFormException
34
     * @throws UserReportException
35
     */
36
37
    public function __construct(array $formSpec, array $feSpecAction, array $feSpecNative, array $db) {
        parent::__construct($formSpec, $feSpecAction, $feSpecNative, $db);
38
39
40
        $this->isFirstPill = true;
    }

Carsten  Rose's avatar
Carsten Rose committed
41
42
43
    /**
     *
     */
44
    public function fillWrap() {
45
46
47
48

//        $this->wrap[WRAP_SETUP_OUTER][WRAP_SETUP_START] = '<div class="tab-content">';
//        $this->wrap[WRAP_SETUP_OUTER][WRAP_SETUP_END] = '</div>';

49
        $this->wrap[WRAP_SETUP_TITLE][WRAP_SETUP_START] = "<div class='row'><div class='col-md-12'><h1>";
50
        $this->wrap[WRAP_SETUP_TITLE][WRAP_SETUP_END] = "</h1></div></div>";
51

52
        // Element: Label + Input + Note
53
        $this->wrap[WRAP_SETUP_ELEMENT][WRAP_SETUP_CLASS] = "form-group clearfix";
54
        $this->wrap[WRAP_SETUP_ELEMENT][WRAP_SETUP_START] = "<div class='" . $this->wrap[WRAP_SETUP_ELEMENT][WRAP_SETUP_CLASS] . "'>";
55
        $this->wrap[WRAP_SETUP_ELEMENT][WRAP_SETUP_END] = "</div>";
56

57
58
        $this->wrap[WRAP_SETUP_SUBRECORD][WRAP_SETUP_START] = "<div class='col-md-12'>";
        $this->wrap[WRAP_SETUP_SUBRECORD][WRAP_SETUP_END] = "</div>";
59

60
61
        $this->wrap[WRAP_SETUP_IN_FIELDSET][WRAP_SETUP_START] = "";
        $this->wrap[WRAP_SETUP_IN_FIELDSET][WRAP_SETUP_END] = "";
62

63
64
65
        $this->wrap[WRAP_SETUP_IN_TEMPLATE_GROUP][WRAP_SETUP_START] = "";
        $this->wrap[WRAP_SETUP_IN_TEMPLATE_GROUP][WRAP_SETUP_END] = "";

66
67
//        $this->feDivClass['radio'] = 'radio';
//        $this->feDivClass['checkbox'] = 'checkbox';
68
69
    }

70
71
    /**
     * @param string $addClass
Carsten  Rose's avatar
Carsten Rose committed
72
     *
73
     * @return string
74
     * @throws CodeException
75
76
77
78
79
80
81
     */
    public function getRowOpenTag($addClass = '') {
        $class = Support::doAttribute('class', [$this->wrap[WRAP_SETUP_ELEMENT][WRAP_SETUP_CLASS], $addClass]);

        return "<div $class>";

    }
82

83
    /**
84
85
86
     * Fill the BS wrapper for Label/Input/Note.
     * For legacy reasons, $label/$input/$note might be a number (0-12) or the bs column classes ('col-md-12 col-lg9')
     *
87
88
89
90
91
     * @param $label
     * @param $input
     * @param $note
     */
    public function fillWrapLabelInputNote($label, $input, $note) {
92
93
94

        $label = is_numeric($label) ? ('col-md-' . $label) : $label;
        $this->wrap[WRAP_SETUP_LABEL][WRAP_SETUP_START] = "<div class='$label qfq-label'>";
95
        $this->wrap[WRAP_SETUP_LABEL][WRAP_SETUP_END] = "</div>";
96
97
98

        $input = is_numeric($input) ? ('col-md-' . $input) : $input;
        $this->wrap[WRAP_SETUP_INPUT][WRAP_SETUP_START] = "<div class='$input'>";
99
        $this->wrap[WRAP_SETUP_INPUT][WRAP_SETUP_END] = "</div>";
100
101
102

        $note = is_numeric($note) ? ('col-md-' . $note) : $note;
        $this->wrap[WRAP_SETUP_NOTE][WRAP_SETUP_START] = "<div class='$note qfq-note'>";
103
104
105
106
        $this->wrap[WRAP_SETUP_NOTE][WRAP_SETUP_END] = "</div>";

    }

Carsten  Rose's avatar
Carsten Rose committed
107
108
109
    /**
     * @return string
     */
110
111
112
113
    public function getProcessFilter() {
        return FORM_ELEMENTS_NATIVE_SUBRECORD;
    }

Carsten  Rose's avatar
Carsten Rose committed
114
115
116
    /**
     * @return string
     */
117
118
119
120
121
    public function doSubrecords() {
        return '';
    }

    /**
122
     * @param string $mode
123
     * @return string
124
125
126
     * @throws CodeException
     * @throws DbException
     * @throws UserFormException
127
     * @throws UserReportException
128
     */
129
    public function head($mode = FORM_LOAD) {
130
        $html = '';
131
        $title = '';
132

Carsten  Rose's avatar
Carsten Rose committed
133
        $html .= '<div ' . Support::doAttribute('class', $this->formSpec[F_CLASS], true) . '>'; // main <div class=...> around everything, Whole FORM; class="container" or class="container-fluid"
134

135
136
        $button = Support::wrapTag('<div class="row"><div class="col-md-12">', $this->buildButtons());

137
        // Show title / frame only if there is a title given.
138
        if (trim($this->formSpec[F_TITLE]) != '') {
139
            $classTitle = isset($this->formSpec[F_CLASS_TITLE]) ? $this->formSpec[F_CLASS_TITLE] : "qfq-form-title";
140
            $title = Support::wrapTag('<div class="row"><div class="col-md-12">', Support::wrapTag('<div class="' . $classTitle . '">', $this->formSpec[F_TITLE]));
141
        }
142
143

        $html .= $button . $title;
144

145
        $dummy = array();
146
        $pill = $this->buildPillNavigation($mode, OnArray::filter($this->feSpecNative, FE_TYPE, FE_TYPE_PILL), $dummy);
147
        $html .= Support::wrapTag('<div class="row">', $pill);
148

149
150
        $html .= $this->getFormTag();

151
152
153
154
155
        $class = ['tab-content', $this->formSpec[F_CLASS_BODY]];
        if ($pill == '') {
            $class[] = 'col-md-12';
        }
        $html .= "<div " . Support::doAttribute('class', $class) . ">";
156
157
158
159

        return $html;
    }

160
161
162
163
164
165
    /**
     * Creates a Checkbox, which toggles 'hide'/'unhide' via JS, on all elements with class= CLASS_FORM_ELEMENT_EDIT.
     *
     * @return string - the rendered Checkbox
     */
    private function buildShowEditFormElementCheckbox() {
Carsten  Rose's avatar
Carsten Rose committed
166
        // EditFormElement Icons
167
168
        $js = '$(".' . CLASS_FORM_ELEMENT_EDIT . '").toggleClass("hidden")';
        $element = "<input type='checkbox' onchange='" . $js . "'>" .
169
            Support::wrapTag("<span title='Toggle: Edit form element icons' class='" . GLYPH_ICON . ' ' . GLYPH_ICON_TASKS . "'>", '');
170
        $element = Support::wrapTag('<label class="btn btn-default navbar-btn">', $element);
Carsten  Rose's avatar
Carsten Rose committed
171

172
173
174
        return Support::wrapTag('<div class="btn-group" data-toggle="buttons">', $element);
    }

Carsten  Rose's avatar
Carsten Rose committed
175
176
177
178
    /**
     * Creates a button to open 'CopyForm' with the current form as source.
     *
     * @return string - the rendered button
179
180
     * @throws CodeException
     * @throws UserFormException
Carsten  Rose's avatar
Carsten Rose committed
181
182
183
184
185
186
187
188
189
190
191
     */
    private function buildButtonCopyForm() {

        // Show copy icon only on form 'form' and only if there is a form loaded (id>0)
        if ($this->formSpec[COLUMN_ID] != 1) {
            return '';
        }
        // current loaded form.
        $formId = $this->store->getVar(COLUMN_ID, STORE_RECORD . STORE_ZERO);

        $queryStringArray = [
Carsten  Rose's avatar
Carsten Rose committed
192
            'id' => $this->store->getVar(SYSTEM_EDIT_FORM_PAGE, STORE_SYSTEM),
Carsten  Rose's avatar
Carsten Rose committed
193
            'form' => 'copyForm',
Carsten  Rose's avatar
Carsten Rose committed
194
            'r' => 0,
Carsten  Rose's avatar
Carsten Rose committed
195
196
197
198
199
200
201
202
203
204
205
206
            'idSrc' => $formId,
        ];
        $queryString = Support::arrayToQueryString($queryStringArray);
        $sip = $this->store->getSipInstance();
        $url = $sip->queryStringToSip($queryString);

        $toolTip = "Duplicate form" . PHP_EOL . PHP_EOL . OnArray::toString($queryStringArray, ' = ', PHP_EOL, "'");
        $status = ($formId == 0) ? 'disabled' : '';

        return $this->buildButtonAnchor($url, 'form-view-' . $this->formSpec[F_ID], '', $toolTip, GLYPH_ICON_DUPLICATE, $status, 'btn btn-default navbar-btn');
    }

207
208
209
210
211
212
213
214
215
    /**
     * Builds a button to open the formLog. The formLog appears on the same page as the form, but the form is not rendered and the log is shown.
     *
     * @return string
     * @throws CodeException
     * @throws UserFormException
     * @throws UserReportException
     */
    private function buildLogForm() {
216
217
218
219
220

        $pageAlias = $this->store::getVar(TYPO3_PAGE_ALIAS, STORE_TYPO3);

        $baseUrl = 'p:' . $pageAlias . '&form=' . $this->formSpec[F_NAME];
        $baseMisc = '|b|G:glyphicon-bell|s|c:btn btn-default navbar-btn';
Carsten  Rose's avatar
Carsten Rose committed
221
        $baseTooltip = '|o:Set form in debugmode and show actions from ';
222
223
224
225

        $stateAll = ($this->formSpec[FORM_LOG_FILE_ALL] == '') ? '' : ' btn-warning';
        $stateSession = ($this->formSpec[FORM_LOG_FILE_SESSION] == '') ? '' : ' btn-warning';

Carsten  Rose's avatar
Carsten Rose committed
226
227
        $formLogAll = $this->link->renderLink($baseUrl . "&" . FORM_LOG_MODE . "=" . FORM_LOG_ALL . $baseMisc . $stateAll . $baseTooltip . 'all user');
        $formLogSession = $this->link->renderLink($baseUrl . "&" . FORM_LOG_MODE . "=" . FORM_LOG_SESSION . $baseMisc . $stateSession . $baseTooltip . 'current user');
228
229

        return $formLogAll . $formLogSession;
230
231
    }

Carsten  Rose's avatar
Carsten Rose committed
232
233
234
235
    /**
     * Creates a link to open current form loaded in FormEditor
     *
     * @return string - the rendered Checkbox
236
237
238
     * @throws CodeException
     * @throws DbException
     * @throws UserFormException
Carsten  Rose's avatar
Carsten Rose committed
239
240
241
     */
    private function buildViewForm() {

242
243
244
245
        $form = false;
        $url = '';
        $status = '';

Carsten  Rose's avatar
Carsten Rose committed
246
247
248
249
250
        switch ($this->formSpec[F_NAME]) {
            case 'form':
                $form = $this->store->getVar(F_NAME, STORE_RECORD);
                break;
            case 'formElement':
251
                if (false !== ($formId = $this->store->getVar(FE_FORM_ID, STORE_SIP . STORE_RECORD))) {
252
                    $row = $this->dbArray[$this->dbIndexQfq]->sql("SELECT f.name FROM Form AS f WHERE id=" . $formId, ROW_EXPECT_1);
253
254
                    $form = current($row);
                }
Carsten  Rose's avatar
Carsten Rose committed
255
256
257
258
259
260
                break;
            default:
                return '';
        }

        if ($form === false) {
261
262
263
            $toolTip = "Form not 'form' or 'formElement'";
            $status = 'disabled';
        } else {
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
            $requiredNew = $this->store->getVar(F_REQUIRED_PARAMETER_NEW, STORE_RECORD . STORE_EMPTY);
            if (trim($requiredNew) !== '') {
                $toolTip = "Form has 'required new' parameters and therefore cannot be previewed.";
                $status = 'disabled';
            } else {
                $queryStringArray = [
                    'id' => $this->store->getVar(SYSTEM_EDIT_FORM_PAGE, STORE_SYSTEM),
                    'form' => $form,
                    'r' => 0,
                ];
                $queryString = Support::arrayToQueryString($queryStringArray);
                $sip = $this->store->getSipInstance();
                $url = $sip->queryStringToSip($queryString);

                $toolTip = "View current form with r=0" . PHP_EOL . PHP_EOL . OnArray::toString($queryStringArray, ' = ', PHP_EOL, "'");
            }
Carsten  Rose's avatar
Carsten Rose committed
280
281
        }

282
        return $this->buildButtonAnchor($url, 'form-view-' . $this->formSpec[F_ID], '', $toolTip, GLYPH_ICON_VIEW, $status, 'btn btn-default navbar-btn');
Carsten  Rose's avatar
Carsten Rose committed
283
284
    }

285
    /**
286
     * Build Buttons panel on top right corner of form.
287
     * Simulate Submit Button: http://www.javascript-coder.com/javascript-form/javascript-form-submit.phtml
288
289
     *
     * @return string
290
     * @throws CodeException
Carsten  Rose's avatar
Carsten Rose committed
291
     * @throws DbException
292
     * @throws UserFormException
293
     * @throws UserReportException
294
295
296
     */
    private function buildButtons() {
        $buttonNew = '';
297
298
299
        $buttonDelete = '';
        $buttonClose = '';
        $buttonSave = '';
300
        $buttonDebugForm = '';
Carsten  Rose's avatar
Carsten Rose committed
301
302
303
        $recordId = $this->store->getVar(SIP_RECORD_ID, STORE_SIP);

        // Button: FormEdit
304
        if ($this->showDebugInfoFlag) {
305
            $toolTip = "Edit form" . PHP_EOL . PHP_EOL . OnArray::toString($this->store->getStore(STORE_SIP), ' = ', PHP_EOL, "'");
306
            $url = $this->createFormEditorUrl(FORM_NAME_FORM, $this->formSpec[F_ID]);
307

308
309
            $buttonDebugForm = $this->buildLogForm() .
                $this->buildViewForm() .
Carsten  Rose's avatar
Carsten Rose committed
310
                $this->buildShowEditFormElementCheckbox() .
Carsten  Rose's avatar
Carsten Rose committed
311
                $this->buildButtonCopyForm() .
312
                $this->buildButtonAnchor($url, 'form-edit-button', '', $toolTip, GLYPH_ICON_TOOL, '', 'btn btn-default navbar-btn');
313
314
315
        }

        // Button: Save
Carsten  Rose's avatar
Carsten Rose committed
316
        if (Support::findInSet(FORM_BUTTON_SAVE, $this->formSpec[F_SHOW_BUTTON]) && $this->formSpec[F_SUBMIT_BUTTON_TEXT] === '') {
317
            $toolTip = $this->formSpec[F_SAVE_BUTTON_TOOLTIP];
318
319
320
321
322
323
324
325
326
327
328

            if ($toolTip == 'Save') {

                if ($recordId == 0) {
                    $toolTip .= PHP_EOL . 'Create new record';
                } else {
                    $toolTip .= PHP_EOL . 'Record id: ' . $recordId;
                    $toolTip .= PHP_EOL . 'Created: ' . $this->store->getVar('created', STORE_RECORD . STORE_EMPTY);;
                    $toolTip .= PHP_EOL . 'Modified: ' . $this->store->getVar('modified', STORE_RECORD . STORE_EMPTY);;
                }
            }
329
            // In debugMode every button link should show the information behind the SIP.
330
            if ($this->showDebugInfoFlag) {
331
                $toolTip .= PHP_EOL . "Table: " . $this->formSpec[F_TABLE_NAME];
332
333
            }

334
335
            $buttonSave = $this->buildButtonCode('save-button', $this->formSpec[F_SAVE_BUTTON_TEXT], $toolTip,
                $this->formSpec[F_SAVE_BUTTON_GLYPH_ICON], '', $this->formSpec[F_BUTTON_ON_CHANGE_CLASS], $this->formSpec[F_SAVE_BUTTON_CLASS]);
336
337
338
        }

        // Button: Close
Carsten  Rose's avatar
Carsten Rose committed
339
        if (Support::findInSet(FORM_BUTTON_CLOSE, $this->formSpec[F_SHOW_BUTTON])) {
340
341
342
            $buttonClose = $this->buildButtonCode('close-button', $this->formSpec[F_CLOSE_BUTTON_TEXT],
                $this->formSpec[F_CLOSE_BUTTON_TOOLTIP],
                $this->formSpec[F_CLOSE_BUTTON_GLYPH_ICON], '', '', $this->formSpec[F_CLOSE_BUTTON_CLASS]);
Carsten  Rose's avatar
Carsten Rose committed
343
        }
344

Carsten  Rose's avatar
Carsten Rose committed
345
        // Button: Delete
Carsten  Rose's avatar
Carsten Rose committed
346
        if (Support::findInSet(FORM_BUTTON_DELETE, $this->formSpec[F_SHOW_BUTTON])) {
347
            $toolTip = $this->formSpec[F_DELETE_BUTTON_TOOLTIP];
348

349
            if ($this->showDebugInfoFlag && $recordId > 0) {
350
                $toolTip .= PHP_EOL . "form = '" . $this->formSpec[F_FINAL_DELETE_FORM] . "'" . PHP_EOL . "r = '" . $recordId . "'";
Carsten  Rose's avatar
Carsten Rose committed
351
            }
352
            $disabled = ($recordId > 0) ? '' : 'disabled';
Carsten  Rose's avatar
Carsten Rose committed
353

354
355
            $buttonDelete = $this->buildButtonCode('delete-button', $this->formSpec[F_DELETE_BUTTON_TEXT], $toolTip,
                $this->formSpec[F_DELETE_BUTTON_GLYPH_ICON], $disabled, '', $this->formSpec[F_DELETE_BUTTON_CLASS]);
356
357
        }

Carsten  Rose's avatar
Carsten Rose committed
358
        // Button: New
Carsten  Rose's avatar
Carsten Rose committed
359
        if (Support::findInSet(FORM_BUTTON_NEW, $this->formSpec[F_SHOW_BUTTON])) {
360
            $url = $this->deriveNewRecordUrlFromExistingSip($toolTip);
Carsten  Rose's avatar
Carsten Rose committed
361

362
363
            $buttonNew = $this->buildButtonAnchor($url, 'form-new-button', $this->formSpec[F_NEW_BUTTON_TEXT],
                $this->formSpec[F_NEW_BUTTON_TOOLTIP], $this->formSpec[F_NEW_BUTTON_GLYPH_ICON], '', $this->formSpec[F_NEW_BUTTON_CLASS]);
364
365
        }

366
367
        // Arrangement: Edit Form / Save / Close / Delete / New
        $html = '';
368
369
370
371
372

        $html .= Support::wrapTag('<div class="btn-group" role="group">', $buttonDebugForm, true);
        $html .= Support::wrapTag('<div class="btn-group" role="group">', $buttonSave . $buttonClose, true);
        $html .= Support::wrapTag('<div class="btn-group" role="group">', $buttonDelete, true);
        $html .= Support::wrapTag('<div class="btn-group" role="group">', $buttonNew, true);
373

374
        $html = Support::wrapTag('<div class="btn-toolbar pull-right" role="toolbar">', $html);
375

376
377
378
        return $html;
    }

379
    /**
380
381
     * Generic function to create a button with a given $buttonHtmlId, $url, $title, $icon (=glyph), $disabled
     *
Carsten  Rose's avatar
Carsten Rose committed
382
     * @param string $url
383
384
385
     * @param string $buttonHtmlId
     * @param string $text
     * @param string $toolTip
Carsten  Rose's avatar
Carsten Rose committed
386
     * @param string $icon
387
     * @param string $disabled
388
     * @param string $class
Carsten  Rose's avatar
Carsten Rose committed
389
     *
390
     * @return string
391
     * @throws CodeException
392
     */
393
394
395
396
397
398
399
    private function buildButtonAnchor($url, $buttonHtmlId, $text, $toolTip, $icon, $disabled = '', $class = '') {

        if ($icon === '') {
            $element = $text;
        } else {
            $element = Support::wrapTag("<span " . Support::doAttribute('class', "glyphicon $icon") . ">", $text);
        }
Carsten  Rose's avatar
Carsten Rose committed
400
401

        $attribute = Support::doAttribute('href', $url);
402
403
404
        $attribute .= Support::doAttribute('id', $buttonHtmlId);
        $attribute .= Support::doAttribute('class', "$class $disabled");
        $attribute .= Support::doAttribute('title', $toolTip);
Carsten  Rose's avatar
Carsten Rose committed
405

406
407
        // disabled links do not show tooltips -> use a span
        $wrapTag = $disabled == 'disabled' ? 'span' : 'a';
408
409

        return Support::wrapTag("<$wrapTag $attribute>", $element);
410
411
412
    }

    /**
413
414
     * Creates a button with the given attributes. If there is no $icon given, render the button without glyph.
     *
415
416
417
     * @param string $buttonHtmlId
     * @param string $text
     * @param string $tooltip
418
     * @param string $icon
419
     * @param string $disabled
Carsten  Rose's avatar
Carsten Rose committed
420
     *
421
422
     * @param string $buttonOnChangeClass
     * @param string $class
423
     * @return string
424
     * @throws CodeException
425
     */
426
    private function buildButtonCode($buttonHtmlId, $text, $tooltip, $icon, $disabled = '', $buttonOnChangeClass = '', $class = '') {
427
428

        if ($icon === '') {
429
430
            $element = $text;
        } else {
431
            $element = "<span class='glyphicon $icon'></span>" . ' ' . $text;
432
433
        }

434
        $class = Support::doAttribute('class', $class);
435
        $dataClassOnChange = Support::doAttribute('data-class-on-change', $buttonOnChangeClass);
436
437
438
        $tooltip = Support::doAttribute('title', $tooltip);

        return "<button id='$buttonHtmlId' type='button' $class $dataClassOnChange $tooltip $disabled>$element</button>";
439
440
    }

Carsten  Rose's avatar
Carsten Rose committed
441
    /**
442
443
444
     * Builds the BS-pills on top of a form.
     *
     * @param string $mode FORM_LOAD | FORM_UPDATE | FORM_SAVE
445
     * @param array $pillArray
Carsten  Rose's avatar
Carsten Rose committed
446
     *
447
     * @param array $json
Carsten  Rose's avatar
Carsten Rose committed
448
     * @return string
449
     * @throws CodeException
450
     * @throws DbException
451
     * @throws UserFormException
452
     * @throws UserReportException
Carsten  Rose's avatar
Carsten Rose committed
453
     */
454
    private function buildPillNavigation($mode, array $pillArray, array &$json) {
455
456
        $pillButton = '';
        $pillDropdown = '';
457
        $htmlDropdown = '';
458

459
        if ($pillArray == null) {
460
            return '';
461
        }
462
463
464

        $maxVisiblePill = (isset($this->formSpec['maxVisiblePill']) && $this->formSpec['maxVisiblePill'] !== '') ? $this->formSpec['maxVisiblePill'] : 1000;

465
466
        $parameterLanguageFieldName = $this->store->getVar(SYSTEM_PARAMETER_LANGUAGE_FIELD_NAME, STORE_SYSTEM);

467
468
        // Iterate over all 'pill'
        $ii = 0;
469
        $isFirstPill = true;
470
        $recordId = $this->store->getVar(COLUMN_ID, STORE_RECORD . STORE_ZERO);
471
        foreach ($pillArray as $formElement) {
472

473
474
475
476
            if ($mode != FORM_LOAD && $formElement[FE_DYNAMIC_UPDATE] !== 'yes') {
                continue; // During save/update: Process only FE dynamic_update=yes
            }

477
478
            $htmlIdLi = $formElement[FE_HTML_ID] . HTML_ID_EXTENSION_PILL_LI;
            $htmlIdLiA = $formElement[FE_HTML_ID] . HTML_ID_EXTENSION_PILL_LI_A;
479
480
481
482

            $formElement = $this->evaluate->parseArray($formElement);
            HelperFormElement::explodeParameter($formElement, F_PARAMETER);
            $formElement = HelperFormElement::setLanguage($formElement, $parameterLanguageFieldName);
483
484
485
            if (!empty($formElement[FE_MODE_SQL])) {
                $formElement[FE_MODE] = $formElement[FE_MODE_SQL];
            }
486

487
488
            $ii++;

489
            if ($formElement[FE_NAME] === '' || $formElement[FE_LABEL] === '') {
490
                $this->store->setVar(SYSTEM_FORM_ELEMENT, Logger::formatFormElementName($formElement), STORE_SYSTEM);
491
                $this->store->setVar(SYSTEM_FORM_ELEMENT_COLUMN, 'name, label', STORE_SYSTEM);
492
                throw new UserFormException("Field 'name' and/or 'label' are empty", ERROR_NAME_LABEL_EMPTY);
493
494
            }

495
            // Anker for pill navigation
496
497
//            $a = '<a ' . Support::doAttribute('href', '#' . $this->createAnker($formElement[FE_ID])) . ' data-toggle="tab">' . $formElement[FE_LABEL] . '</a>';

498
            $attributeLiA = 'data-toggle="tab" ';
499
500
            $hrefTarget = '#' . $this->createAnker($formElement[FE_ID]);

501
            $htmlFormElementName = HelperFormElement::buildFormElementName($formElement, $recordId);
502
503
504
505
            switch ($formElement[FE_MODE]) {
                case FE_MODE_SHOW:
                case FE_MODE_REQUIRED:
                    $attributeLi = '';
506
507
                    $json[$htmlFormElementName][API_ELEMENT_UPDATE][$htmlIdLi][API_ELEMENT_ATTRIBUTE][HTML_ATTR_CLASS] = '';
                    $json[$htmlFormElementName][API_ELEMENT_UPDATE][$htmlIdLiA][API_ELEMENT_ATTRIBUTE][HTML_ATTR_CLASS] = '';
508
                    break;
509

510
                case FE_MODE_READONLY:
511
512
                    $hrefTarget = '#';

513
                    $attributeLi = Support::doAttribute('class', 'disabled');
514
                    $json[$htmlFormElementName][API_ELEMENT_UPDATE][$htmlIdLi][API_ELEMENT_ATTRIBUTE][HTML_ATTR_CLASS] = 'disabled';
515
516

                    $attributeLiA .= Support::doAttribute('class', 'noclick');
517
                    $json[$htmlFormElementName][API_ELEMENT_UPDATE][$htmlIdLiA][API_ELEMENT_ATTRIBUTE][HTML_ATTR_CLASS] = 'noclick';
518
                    break;
519

520
                case FE_MODE_HIDDEN:
521
522
//                    $attributeLi = Support::doAttribute('style', 'display: none');
                    $attributeLi = Support::doAttribute('class', 'hidden');
523
                    $json[$htmlFormElementName][API_ELEMENT_UPDATE][$htmlIdLi][API_ELEMENT_ATTRIBUTE][HTML_ATTR_CLASS] = 'hidden';
524
                    break;
525

526
527
528
                default:
                    throw new UserFormException("Unknown Mode: " . $formElement[FE_MODE], ERROR_UNKNOWN_MODE);
            }
529

530
            $attributeLi .= Support::doAttribute(HTML_ATTR_ID, $htmlIdLi);
531
            $attributeLi .= Support::doAttribute('title', $formElement[FE_TOOLTIP]);
532
            $attributeLiA .= Support::doAttribute(HTML_ATTR_ID, $htmlIdLiA);
533
            $a = Support::wrapTag("<a $attributeLiA" . Support::doAttribute('href', $hrefTarget) . ">", $formElement[FE_LABEL]);
534
            $json[$htmlFormElementName][API_ELEMENT_UPDATE][$htmlIdLiA][API_ELEMENT_CONTENT] = $formElement[FE_LABEL];
535

536
            if ($isFirstPill && $formElement[FE_MODE] != FE_MODE_HIDDEN) {
537
                $attributeLi .= 'class="active" ';
538
539
540
                $isFirstPill = false;
            }

541
            if ($ii <= $maxVisiblePill) {
542
                $pillButton .= '<li role="presentation"' . $attributeLi . ">" . $a . "</li>";
543
            } else {
544
                $pillDropdown .= '<li ' . $attributeLi . '>' . $a . "</li>";
545
546
            }
        }
547

548
549
        // Pill Dropdown necessary?
        if ($ii > $maxVisiblePill) {
550
            $htmlDropdown = Support::wrapTag('<ul class="dropdown-menu qfq-form-pill ' . $this->formSpec[F_CLASS_PILL] . '">', $pillDropdown, true);
551
            $htmlDropdown = '<a class="dropdown-toggle" data-toggle="dropdown" href="#" role="button">more <span class="caret"></span></a>' . $htmlDropdown;
552
            $htmlDropdown = Support::wrapTag('<li role="presentation" class="dropdown">', $htmlDropdown, false);
553
        }
554

555
        $htmlDropdown = Support::wrapTag('<ul id="' . $this->getTabId() . '" class="nav nav-pills qfq-form-pill ' . $this->formSpec[F_CLASS_PILL] . '" role="tablist">', $pillButton . $htmlDropdown);
556
        $htmlDropdown = Support::wrapTag('<div class="col-md-12">', $htmlDropdown);
557

558
        return $htmlDropdown;
559
560
561
562
563
564
    }

    /**
     * Create an identifier for the pill navigation menu
     *
     * @param $id
Carsten  Rose's avatar
Carsten Rose committed
565
     *
566
567
568
     * @return string
     */
    private function createAnker($id) {
569
        return $this->formSpec[FE_NAME] . '_' . $id;
570
571
    }

Carsten  Rose's avatar
Carsten Rose committed
572
573
574
575
576
577
578
    /**
     * @return string
     */
    private function getTabId() {
        return 'qfqTabs';
    }

579
580
581
582
    /**
     * Builds the complete HTML '<form ...>'-tag
     *
     * @return string
583
584
     * @throws CodeException
     * @throws DbException
585
     * @throws UserFormException
586
     */
587
    public function getFormTag() {
588

589
        $attribute = $this->getFormTagAttributes();
590
591

        $attribute['class'] = 'form-horizontal';
592
        $attribute['data-toggle'] = 'validator';
593
        if (isset($this->formSpec[F_SAVE_BUTTON_ACTIVE]) && $this->formSpec[F_SAVE_BUTTON_ACTIVE] != '0') {
594
595
            $attribute[DATA_ENABLE_SAVE_BUTTON] = 'true';
        }
596
597

        $honeypot = $this->getHoneypotVars();
598
        $md5 = $this->buildInputRecordHashMd5();
599

Carsten  Rose's avatar
Carsten Rose committed
600
        return '<form ' . OnArray::toString($attribute, '=', ' ', "'") . '>' . $honeypot . $md5;
601
602
    }

603
604
    /**
     * @return string
605
606
     * @throws CodeException
     * @throws UserFormException
607
     * @throws UserReportException
608
     */
609
    public function tail() {
610

611
        $html = '';
Carsten  Rose's avatar
Carsten Rose committed
612
        $deleteUrl = '';
613

614
615
        $formId = $this->getFormId();

616
617
        // Button Save at bottom of form - only if there is a button text given.
        if ($this->formSpec[F_SUBMIT_BUTTON_TEXT] !== '') {
618
619
620
621

            // Default setzen:
            $this->fillWrapLabelInputNote($this->formSpec[F_BS_LABEL_COLUMNS], $this->formSpec[F_BS_INPUT_COLUMNS], $this->formSpec[F_BS_NOTE_COLUMNS]);

622
623
            $buttonText = $this->formSpec[F_SUBMIT_BUTTON_TEXT];

624
625
626
            $htmlElement = $this->buildButtonCode('save-button', $buttonText, $this->formSpec[F_SUBMIT_BUTTON_TOOLTIP],
                $this->formSpec[F_SUBMIT_BUTTON_GLYPH_ICON], '', $this->formSpec[F_BUTTON_ON_CHANGE_CLASS],
                $this->formSpec[F_SUBMIT_BUTTON_CLASS]);
627
628
629
630
631
632
633
634

            $html .= $this->wrapItem(WRAP_SETUP_LABEL, '');
            $html .= $this->wrapItem(WRAP_SETUP_INPUT, $htmlElement);
            $html .= $this->wrapItem(WRAP_SETUP_NOTE, '');

            $html = $this->wrapItem(WRAP_SETUP_ELEMENT, $html);
        }

635
        $html .= '</div> <!--class="tab-content" -->';  //  <div class="tab-content">
636
//        $html .= '<input type="submit" value="Submit">';
637

Carsten  Rose's avatar
Carsten Rose committed
638
639
640
        $formId = $this->getFormId();
        $tabId = $this->getTabId();

Carsten  Rose's avatar
Carsten Rose committed
641
        if (0 < ($recordId = $this->store->getVar(SIP_RECORD_ID, STORE_SIP))) {
642
            $deleteUrl = $this->createDeleteUrl($this->formSpec[F_FINAL_DELETE_FORM], $recordId);
Carsten  Rose's avatar
Carsten Rose committed
643
        }
644

645
646
647
        $actionUpload = FILE_ACTION . '=' . FILE_ACTION_UPLOAD;
        $actionDelete = FILE_ACTION . '=' . FILE_ACTION_DELETE;

648
649
650
        $apiDir = API_DIR;
        $apiDeletePhp = API_DIR . '/' . API_DELETE_PHP;

651
        $dirtyAction = ($this->formSpec[F_DIRTY_MODE] == DIRTY_MODE_NONE) ? '' : "dirtyUrl: '$apiDir/dirty.php',";
Carsten  Rose's avatar
Carsten Rose committed
652

653
        $html .= '</form>';  //  <form class="form-horizontal" ...
654
655
656
657
658
659
        $html .= <<<EOF
        <script type="text/javascript">
            $(function () {
                'use strict';
                QfqNS.Log.level = 0;

Carsten  Rose's avatar
Carsten Rose committed
660
661
662
                var qfqPage = new QfqNS.QfqPage({
                    tabsId: '$tabId',
                    formId: '$formId',
663
                    submitTo: '$apiDir/save.php',
Carsten  Rose's avatar
Carsten Rose committed
664
                    $dirtyAction
Carsten  Rose's avatar
Carsten Rose committed
665
                    deleteUrl: '$deleteUrl',
666
667
668
                    refreshUrl: '$apiDir/load.php',
                    fileUploadTo: '$apiDir/file.php?$actionUpload',
                    fileDeleteUrl: '$apiDir/file.php?$actionDelete'
Carsten  Rose's avatar
Carsten Rose committed
669
670
                });

671
               
672
                var qfqRecordList = new QfqNS.QfqRecordList('$apiDeletePhp');
Carsten  Rose's avatar
Carsten Rose committed
673
            })
674
675
         </script>
EOF;
676
        $html .= '</div>';  //  <div class="container-fluid"> === main <div class=...> around everything
677

678
679
680
681
682
        return $html;
    }

    /**
     * @param array $formElement
Carsten  Rose's avatar
Carsten Rose committed
683
684
685
     * @param       $htmlFormElementName
     * @param       $value
     *
686
     * @param array $json
687
     * @return mixed
688
689
     * @throws CodeException
     * @throws DbException
690
     * @throws DownloadException
691
     * @throws UserFormException
692
     * @throws UserReportException
693
694
695
     * @throws \PhpOffice\PhpSpreadsheet\Exception
     * @throws \PhpOffice\PhpSpreadsheet\Reader\Exception
     * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
696
     */
697
    public function buildPill(array $formElement, $htmlFormElementName, $value, array &$json) {
698
        $html = '';
699

700
        if ($formElement[FE_MODE] == FE_MODE_HIDDEN) {
701
702
703
            return '';
        }

704
705
706
707
        // save parent processed FE's
        $tmpStore = $this->feSpecNative;

        // child FE's
708
        $this->feSpecNative = $this->dbArray[$this->dbIndexQfq]->getNativeFormElements(SQL_FORM_ELEMENT_SPECIFIC_CONTAINER,
709
710
            ['yes', $this->formSpec["id"], 'native,container', $formElement['id']], $this->formSpec);

Carsten  Rose's avatar
Carsten Rose committed
711
        $html = $this->elements($this->store->getVar(SIP_RECORD_ID, STORE_SIP), FORM_ELEMENTS_NATIVE_SUBRECORD, 0, $json);
712
713
714
715

        // restore parent processed FE's
        $this->feSpecNative = $tmpStore;

716
717
718
        return $html;
    }

719
    /**
Carsten  Rose's avatar
Carsten Rose committed
720
     * @param array $formElement Complete FormElement, especially some FE_WRAP
721
     * @param string $htmlElement Content to wrap.
Carsten  Rose's avatar
Carsten Rose committed
722
723
     * @param        $htmlFormElementName
     *
724
     * @return string               Wrapped $htmlElement
725
726
     * @throws CodeException
     * @throws UserFormException
727
     */
728
    public function buildRowNative(array $formElement, $htmlElement, $htmlFormElementName) {
729
        $html = '';
730
        $htmlLabel = '';
731
732
        $classHideRow = '';
        $classHideElement = '';
733

734
        if ($formElement[FE_MODE] == FE_MODE_HIDDEN) {
735
            if ($formElement[FE_FLAG_ROW_OPEN_TAG] && $formElement[FE_FLAG_ROW_CLOSE_TAG]) {
736
737
738
739
740
741
                $classHideRow = 'hidden';
            } else {
                $classHideElement = 'hidden';
            }
        }

Carsten  Rose's avatar
Carsten Rose committed
742
        // Label
743
        if ($formElement[FE_BS_LABEL_COLUMNS] != '0') {
744
            $addClass = ($formElement[FE_MODE] == FE_MODE_REQUIRED || $formElement[FE_MODE] == FE_MODE_SHOW_REQUIRED) ? CSS_REQUIRED : '';
745
            $htmlLabel = $this->buildLabel($htmlFormElementName, $formElement[FE_LABEL], $addClass);
746
        }
747

748
749
        $html .= $this->customWrap($formElement, $htmlLabel, FE_WRAP_LABEL, $formElement[FE_BS_LABEL_COLUMNS],
            [$this->wrap[WRAP_SETUP_LABEL][WRAP_SETUP_START], $this->wrap[WRAP_SETUP_LABEL][WRAP_SETUP_END]], $formElement[FE_HTML_ID] . HTML_ID_EXTENSION_LABEL);
750

Carsten  Rose's avatar
Carsten Rose committed
751
        // Input
752
753
        $html .= $this->customWrap($formElement, $htmlElement, FE_WRAP_INPUT, $formElement[FE_BS_INPUT_COLUMNS],
            [$this->wrap[WRAP_SETUP_INPUT][WRAP_SETUP_START], $this->wrap[WRAP_SETUP_INPUT][WRAP_SETUP_END]],
754
            $formElement[FE_HTML_ID] . HTML_ID_EXTENSION_INPUT, $classHideElement);
755

Carsten  Rose's avatar
Carsten Rose committed
756
        // Note
Carsten  Rose's avatar
Carsten Rose committed
757
        $note = $formElement[FE_NOTE];
758
759
        $html .= $this->customWrap($formElement, $note, FE_WRAP_NOTE, $formElement[FE_BS_NOTE_COLUMNS],
            [$this->wrap[WRAP_SETUP_NOTE][WRAP_SETUP_START], $this->wrap[WRAP_SETUP_NOTE][WRAP_SETUP_END]], $formElement[FE_HTML_ID] . HTML_ID_EXTENSION_NOTE);
760

761
        // Row
762
763
764
765
        $openTag = $formElement[FE_FLAG_ROW_OPEN_TAG] ? $this->getRowOpenTag($classHideRow) : '';
        $closeTag = $formElement[FE_FLAG_ROW_CLOSE_TAG] ? $this->wrap[WRAP_SETUP_ELEMENT][WRAP_SETUP_END] : '';

        $html = $this->customWrap($formElement, $html, FE_WRAP_ROW, -1, [$openTag, $closeTag], $formElement[FE_HTML_ID] . HTML_ID_EXTENSION_ROW);
766
767
768
769

        return $html;
    }

770
    /**
771
     * Wrap content with $wrapArray or, if specified use $formElement[$wrapName]. Inject $htmlId in wrap.
772
773
774
     *
     * Result:
     * - if $bsColumns==0 and empty $formElement[$wrapName]: no wrap
775
776
     * - if $formElement[$wrapName] is given: wrap with that one. Else: wrap with $wrapArray
     * - if $htmlId is give, inject it in $wrap.
777
     *
Carsten  Rose's avatar
Carsten Rose committed
778
     * @param array $formElement Complete FormElement, especially some FE_WRAP
779
     * @param string $htmlElement Content to wrap.
Carsten  Rose's avatar
Carsten Rose committed
780
781
     * @param string $wrapName FE_WRAP_ROW, FE_WRAP_LABEL, FE_WRAP_INPUT, FE_WRAP_NOTE
     * @param int $bsColumns
782
     * @param array $wrapArray System wide Defaults: [ 'open wrap', 'close wrap' ]
783
784
     * @param string $htmlId
     * @param string $class
Carsten  Rose's avatar
Carsten Rose committed
785
     *
786
     * @return string Wrapped $htmlElement
787
     * @throws CodeException
788
789
     * @throws \qfq\UserFormException
     */
790
    private function customWrap(array $formElement, $htmlElement, $wrapName, $bsColumns, array $wrapArray, $htmlId = '', $class = '') {
791

792
        // If $bsColumns==0: do not wrap with default.
793
        if ($bsColumns == '0') {
794
795
            $wrapArray[0] = '';
            $wrapArray[1] = '';
796
        }
797

798
        // If there is a 'per FormElement'-wrap, take it.
799
800
801
802
        if (isset($formElement[$wrapName])) {
            $wrapArray = explode('|', $formElement[$wrapName], 2);
        }

803
804
805
806
807
808
809
        if (count($wrapArray) != 2) {
            throw new UserFormException("Need open & close wrap token for FormElement.parameter" . $wrapName . " - E.g.: <div ...>|</div>", ERROR_MISSING_VALUE);
        }

        if ($wrapArray[0] != '') {
            $wrapArray[0] = Support::insertAttribute($wrapArray[0], 'id', $htmlId);
            $wrapArray[0] = Support::insertAttribute($wrapArray[0], 'class', $class); // might be problematic, if there is already a 'class' defined.
810
            if ($wrapName == FE_WRAP_LABEL) {
811
                $wrapArray[0] = Support::insertAttribute($wrapArray[0], 'style', 'text-align: ' . $formElement[F_FE_LABEL_ALIGN] . ';'); // might be problematic, if there is already a 'class' defined.
812
            }
813
814
        }

815
        return $wrapArray[0] . $htmlElement . $wrapArray[1];
816
817
    }

818

819
820
821
    /**
     * @param $formElement
     * @param $elementHtml
Carsten  Rose's avatar
Carsten Rose committed
822
     *
823
824
     * @return string
     */
825
    public function buildRowPill(array $formElement, $elementHtml) {
826
827
        $html = '';

828
        $html .= Support::wrapTag('<div class="col-md-12 qfq-form-body ' . $this->formSpec[F_CLASS_BODY] . '">', $elementHtml);
829

830
831
832
833
        if ($formElement[FE_MODE] == FE_MODE_HIDDEN) {
            $class = ' hidden';
        } else {
            $class = $this->isFirstPill ? 'active ' : '';
834
835
            $this->isFirstPill = false;
        }
836

837
        $html = Support::wrapTag('<div role="tabpanel" class="tab-pane ' . $class . '" id="' . $this->createAnker($formElement['id']) . '">', $html);
838
839
840
841
842


        return $html;
    }

843
    /**