QueryView.php 52.2 KB
Newer Older
1
2
3
<?php
namespace TYPO3\CMS\Core\Database;

4
/*
5
 * This file is part of the TYPO3 CMS project.
6
 *
7
8
9
 * It is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License, either version 2
 * of the License, or any later version.
10
 *
11
12
 * For the full copyright and license information, please read the
 * LICENSE.txt file that was distributed with this source code.
13
 *
14
15
 * The TYPO3 project - inspiring people to share!
 */
16

17
use Doctrine\DBAL\DBALException;
18
use TYPO3\CMS\Backend\Utility\BackendUtility;
19
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
20
21
use TYPO3\CMS\Core\Database\Query\QueryHelper;
use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
22
23
use TYPO3\CMS\Core\Imaging\Icon;
use TYPO3\CMS\Core\Imaging\IconFactory;
24
use TYPO3\CMS\Core\Localization\LanguageService;
25
use TYPO3\CMS\Core\Messaging\FlashMessage;
26
use TYPO3\CMS\Core\Messaging\FlashMessageRendererResolver;
27
use TYPO3\CMS\Core\Type\Bitmask\Permission;
28
use TYPO3\CMS\Core\Utility\CsvUtility;
29
30
use TYPO3\CMS\Core\Utility\DebugUtility;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
31
32
use TYPO3\CMS\Core\Utility\GeneralUtility;

33
34
35
36
/**
 * Class used in module tools/dbint (advanced search) and which may hold code specific for that module
 * However the class has a general principle in it which may be used in the web/export module.
 */
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
class QueryView
{
    /**
     * @var string
     */
    public $storeList = 'search_query_smallparts,search_result_labels,labels_noprefix,show_deleted,queryConfig,queryTable,queryFields,queryLimit,queryOrder,queryOrderDesc,queryOrder2,queryOrder2Desc,queryGroup,search_query_makeQuery';

    /**
     * @var string
     */
    public $downloadScript = 'index.php';

    /**
     * @var int
     */
    public $formW = 48;

    /**
     * @var int
     */
    public $noDownloadB = 0;

    /**
     * @var array
     */
62
    public $hookArray = [];
63
64
65
66
67
68
69
70
71
72
73

    /**
     * @var string
     */
    protected $formName = '';

    /**
     * @var \TYPO3\CMS\Core\Imaging\IconFactory
     */
    protected $iconFactory;

74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
    /**
     * @var array
     */
    protected $tableArray = [];

    /**
     * @var LanguageService
     */
    protected $languageService;

    /**
     * @var BackendUserAuthentication
     */
    protected $backendUserAuthentication;

89
90
91
92
93
    /**
     * constructor
     */
    public function __construct()
    {
94
95
        $this->backendUserAuthentication = $GLOBALS['BE_USER'];
        $this->languageService = $GLOBALS['LANG'];
96
        $this->languageService->includeLLFile('EXT:core/Resources/Private/Language/locallang_t3lib_fullsearch.xlf');
97
98
99
100
101
102
103
104
105
106
        $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
    }

    /**
     * Get form
     *
     * @return string
     */
    public function form()
    {
107
108
109
110
111
112
113
114
115
        $markup = [];
        $markup[] = '<div class="form-group">';
        $markup[] = '<input placeholder="Search Word" class="form-control" type="search" name="SET[sword]" value="'
            . htmlspecialchars($GLOBALS['SOBE']->MOD_SETTINGS['sword']) . '">';
        $markup[] = '</div>';
        $markup[] = '<div class="form-group">';
        $markup[] = '<input class="btn btn-default" type="submit" name="submit" value="Search All Records">';
        $markup[] = '</div>';
        return implode(LF, $markup);
116
117
118
119
120
121
122
123
124
125
126
127
    }

    /**
     * Make store control
     *
     * @return string
     */
    public function makeStoreControl()
    {
        // Load/Save
        $storeArray = $this->initStoreArray();

128
        $opt = [];
129
130
131
132
        foreach ($storeArray as $k => $v) {
            $opt[] = '<option value="' . $k . '">' . htmlspecialchars($v) . '</option>';
        }
        // Actions:
133
        if (ExtensionManagementUtility::isLoaded('sys_action') && $this->backendUserAuthentication->isAdmin()) {
134
135
136
137
            $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_action');
            $queryBuilder->getRestrictions()->removeAll();
            $statement = $queryBuilder->select('uid', 'title')
                ->from('sys_action')
138
                ->where($queryBuilder->expr()->eq('type', $queryBuilder->createNamedParameter(2, \PDO::PARAM_INT)))
139
140
                ->orderBy('title')
                ->execute();
141
            $opt[] = '<option value="0">__Save to Action:__</option>';
142
            while ($row = $statement->fetch()) {
143
144
                $opt[] = '<option value="-' . (int)$row['uid'] . '">' . htmlspecialchars(($row['title']
                        . ' [' . (int)$row['uid'] . ']')) . '</option>';
145
146
            }
        }
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
        $markup = [];
        $markup[] = '<div class="load-queries">';
        $markup[] = '  <div class="form-inline">';
        $markup[] = '    <div class="form-group">';
        $markup[] = '      <select class="form-control" name="storeControl[STORE]" onChange="document.forms[0]'
            . '[\'storeControl[title]\'].value= this.options[this.selectedIndex].value!=0 '
            . '? this.options[this.selectedIndex].text : \'\';">' . implode(LF, $opt) . '</select>';
        $markup[] = '      <input class="form-control" name="storeControl[title]" value="" type="text" max="80">';
        $markup[] = '      <input class="btn btn-default" type="submit" name="storeControl[LOAD]" value="Load">';
        $markup[] = '      <input class="btn btn-default" type="submit" name="storeControl[SAVE]" value="Save">';
        $markup[] = '      <input class="btn btn-default" type="submit" name="storeControl[REMOVE]" value="Remove">';
        $markup[] = '    </div>';
        $markup[] = '  </div>';
        $markup[] = '</div>';

        return implode(LF, $markup);
163
164
165
166
167
168
169
170
171
    }

    /**
     * Init store array
     *
     * @return array
     */
    public function initStoreArray()
    {
172
        $storeArray = [
173
            '0' => '[New]'
174
        ];
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
        $savedStoreArray = unserialize($GLOBALS['SOBE']->MOD_SETTINGS['storeArray']);
        if (is_array($savedStoreArray)) {
            $storeArray = array_merge($storeArray, $savedStoreArray);
        }
        return $storeArray;
    }

    /**
     * Clean store query configs
     *
     * @param array $storeQueryConfigs
     * @param array $storeArray
     * @return array
     */
    public function cleanStoreQueryConfigs($storeQueryConfigs, $storeArray)
    {
        if (is_array($storeQueryConfigs)) {
            foreach ($storeQueryConfigs as $k => $v) {
                if (!isset($storeArray[$k])) {
                    unset($storeQueryConfigs[$k]);
                }
            }
        }
        return $storeQueryConfigs;
    }

    /**
     * Add to store query configs
     *
     * @param array $storeQueryConfigs
     * @param int $index
     * @return array
     */
    public function addToStoreQueryConfigs($storeQueryConfigs, $index)
    {
        $keyArr = explode(',', $this->storeList);
211
        $storeQueryConfigs[$index] = [];
212
213
214
215
216
217
218
219
220
221
222
223
224
225
        foreach ($keyArr as $k) {
            $storeQueryConfigs[$index][$k] = $GLOBALS['SOBE']->MOD_SETTINGS[$k];
        }
        return $storeQueryConfigs;
    }

    /**
     * Save query in action
     *
     * @param int $uid
     * @return int
     */
    public function saveQueryInAction($uid)
    {
226
        if (ExtensionManagementUtility::isLoaded('sys_action')) {
227
            $keyArr = explode(',', $this->storeList);
228
            $saveArr = [];
229
230
231
232
233
234
            foreach ($keyArr as $k) {
                $saveArr[$k] = $GLOBALS['SOBE']->MOD_SETTINGS[$k];
            }
            // Show query
            if ($saveArr['queryTable']) {
                /** @var \TYPO3\CMS\Core\Database\QueryGenerator */
235
236
237
238
239
240
                $queryGenerator = GeneralUtility::makeInstance(QueryGenerator::class);
                $queryGenerator->init('queryConfig', $saveArr['queryTable']);
                $queryGenerator->makeSelectorTable($saveArr);
                $queryGenerator->enablePrefix = 1;
                $queryString = $queryGenerator->getQuery($queryGenerator->queryConfig);

241
242
243
244
                $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
                    ->getQueryBuilderForTable($queryGenerator->table);
                $queryBuilder->getRestrictions()->removeAll()
                    ->add(GeneralUtility::makeInstance(DeletedRestriction::class));
245
246
247
248
249
250
251
252
253
254
255
                $rowCount = $queryBuilder->count('*')
                    ->from($queryGenerator->table)
                    ->where(QueryHelper::stripLogicalOperatorPrefix($queryString))
                    ->execute()->fetchColumn(0);

                $t2DataValue = [
                    'qC' => $saveArr,
                    'qCount' => $rowCount,
                    'qSelect' => $queryGenerator->getSelectQuery($queryString),
                    'qString' => $queryString
                ];
256
257
258
259
260
261
262
                GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable('sys_action')
                    ->update(
                        'sys_action',
                        ['t2_data' => serialize($t2DataValue)],
                        ['uid' => (int)$uid],
                        ['t2_data' => Connection::PARAM_LOB]
                    );
263
            }
264
            return 1;
265
        }
266
        return null;
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
    }

    /**
     * Load store query configs
     *
     * @param array $storeQueryConfigs
     * @param int $storeIndex
     * @param array $writeArray
     * @return array
     */
    public function loadStoreQueryConfigs($storeQueryConfigs, $storeIndex, $writeArray)
    {
        if ($storeQueryConfigs[$storeIndex]) {
            $keyArr = explode(',', $this->storeList);
            foreach ($keyArr as $k) {
                $writeArray[$k] = $storeQueryConfigs[$storeIndex][$k];
            }
        }
        return $writeArray;
    }

    /**
     * Process store control
     *
     * @return string
     */
    public function procesStoreControl()
    {
        $storeArray = $this->initStoreArray();
        $storeQueryConfigs = unserialize($GLOBALS['SOBE']->MOD_SETTINGS['storeQueryConfigs']);
        $storeControl = GeneralUtility::_GP('storeControl');
        $storeIndex = (int)$storeControl['STORE'];
        $saveStoreArray = 0;
300
        $writeArray = [];
301
        $msg = '';
302
303
304
305
306
        if (is_array($storeControl)) {
            if ($storeControl['LOAD']) {
                if ($storeIndex > 0) {
                    $writeArray = $this->loadStoreQueryConfigs($storeQueryConfigs, $storeIndex, $writeArray);
                    $saveStoreArray = 1;
307
308
309
310
311
                    $flashMessage = GeneralUtility::makeInstance(
                        FlashMessage::class,
                        sprintf($this->languageService->getLL('query_loaded'), $storeArray[$storeIndex])
                    );
                } elseif ($storeIndex < 0 && ExtensionManagementUtility::isLoaded('sys_action')) {
312
313
314
                    $actionRecord = BackendUtility::getRecord('sys_action', abs($storeIndex));
                    if (is_array($actionRecord)) {
                        $dA = unserialize($actionRecord['t2_data']);
315
                        $dbSC = [];
316
317
318
319
320
                        if (is_array($dA['qC'])) {
                            $dbSC[0] = $dA['qC'];
                        }
                        $writeArray = $this->loadStoreQueryConfigs($dbSC, '0', $writeArray);
                        $saveStoreArray = 1;
321
322
323
324
                        $flashMessage = GeneralUtility::makeInstance(
                            FlashMessage::class,
                            sprintf($this->languageService->getLL('query_from_action_loaded'), $actionRecord['title'])
                        );
325
326
327
328
329
330
                    }
                }
            } elseif ($storeControl['SAVE']) {
                if ($storeIndex < 0) {
                    $qOK = $this->saveQueryInAction(abs($storeIndex));
                    if ($qOK) {
331
332
333
334
                        $flashMessage = GeneralUtility::makeInstance(
                            FlashMessage::class,
                            $this->languageService->getLL('query_saved')
                        );
335
                    } else {
336
337
338
339
340
341
                        $flashMessage = GeneralUtility::makeInstance(
                            FlashMessage::class,
                            $this->languageService->getLL('query_notsaved'),
                            '',
                            FlashMessage::ERROR
                        );
342
343
344
345
346
347
348
349
350
351
352
353
                    }
                } else {
                    if (trim($storeControl['title'])) {
                        if ($storeIndex > 0) {
                            $storeArray[$storeIndex] = $storeControl['title'];
                        } else {
                            $storeArray[] = $storeControl['title'];
                            end($storeArray);
                            $storeIndex = key($storeArray);
                        }
                        $storeQueryConfigs = $this->addToStoreQueryConfigs($storeQueryConfigs, $storeIndex);
                        $saveStoreArray = 1;
354
355
356
357
                        $flashMessage = GeneralUtility::makeInstance(
                            FlashMessage::class,
                            $this->languageService->getLL('query_saved')
                        );
358
359
360
361
                    }
                }
            } elseif ($storeControl['REMOVE']) {
                if ($storeIndex > 0) {
362
363
364
365
                    $flashMessage = GeneralUtility::makeInstance(
                        FlashMessage::class,
                        sprintf($this->languageService->getLL('query_removed'), $storeArray[$storeControl['STORE']])
                    );
366
367
368
369
370
                    // Removing
                    unset($storeArray[$storeControl['STORE']]);
                    $saveStoreArray = 1;
                }
            }
371
            if (!empty($flashMessage)) {
372
373
374
                $msg = GeneralUtility::makeInstance(FlashMessageRendererResolver::class)
                    ->resolve()
                    ->render([$flashMessage]);
375
376
377
378
379
380
            }
        }
        if ($saveStoreArray) {
            // Making sure, index 0 is not set!
            unset($storeArray[0]);
            $writeArray['storeArray'] = serialize($storeArray);
381
382
383
384
385
386
387
388
            $writeArray['storeQueryConfigs'] =
                serialize($this->cleanStoreQueryConfigs($storeQueryConfigs, $storeArray));
            $GLOBALS['SOBE']->MOD_SETTINGS = BackendUtility::getModuleData(
                $GLOBALS['SOBE']->MOD_MENU,
                $writeArray,
                $GLOBALS['SOBE']->MCONF['name'],
                'ses'
            );
389
390
391
392
393
394
395
396
397
398
399
400
        }
        return $msg;
    }

    /**
     * Query marker
     *
     * @return string
     */
    public function queryMaker()
    {
        $output = '';
401
        $this->hookArray = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['t3lib_fullsearch'] ?? [];
402
        $msg = $this->procesStoreControl();
403
404
405
406
        if (!$this->backendUserAuthentication->userTS['mod.']['dbint.']['disableStoreControl']) {
            $output .= '<h2>Load/Save Query</h2>';
            $output .= '<div>' . $this->makeStoreControl() . '</div>';
            $output .= $msg;
407
408
        }
        // Query Maker:
409
410
        $queryGenerator = GeneralUtility::makeInstance(QueryGenerator::class);
        $queryGenerator->init('queryConfig', $GLOBALS['SOBE']->MOD_SETTINGS['queryTable']);
411
        if ($this->formName) {
412
            $queryGenerator->setFormName($this->formName);
413
        }
414
        $tmpCode = $queryGenerator->makeSelectorTable($GLOBALS['SOBE']->MOD_SETTINGS);
415
        $output .= '<div id="query"></div>' . '<h2>Make query</h2><div>' . $tmpCode . '</div>';
416
417
        $mQ = $GLOBALS['SOBE']->MOD_SETTINGS['search_query_makeQuery'];
        // Make form elements:
418
        if ($queryGenerator->table && is_array($GLOBALS['TCA'][$queryGenerator->table])) {
419
420
            if ($mQ) {
                // Show query
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
                $queryGenerator->enablePrefix = 1;
                $queryString = $queryGenerator->getQuery($queryGenerator->queryConfig);
                $selectQueryString = $queryGenerator->getSelectQuery($queryString);
                $connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable($queryGenerator->table);

                $isConnectionMysql = (bool)(strpos($connection->getServerVersion(), 'MySQL') === 0);
                $fullQueryString = '';
                try {
                    if ($mQ === 'explain' && $isConnectionMysql) {
                        // EXPLAIN is no ANSI SQL, for now this is only executed on mysql
                        // @todo: Move away from getSelectQuery() or model differently
                        $fullQueryString = 'EXPLAIN ' . $selectQueryString;
                        $dataRows = $connection->executeQuery('EXPLAIN ' . $selectQueryString)->fetchAll();
                    } elseif ($mQ === 'count') {
                        $queryBuilder = $connection->createQueryBuilder();
                        $queryBuilder->getRestrictions()->removeAll()->add(GeneralUtility::makeInstance(DeletedRestriction::class));
                        $dataRows = $queryBuilder->count('*')
                            ->from($queryGenerator->table)
                            ->where(QueryHelper::stripLogicalOperatorPrefix($queryString));
                        $fullQueryString = $queryBuilder->getSQL();
                        $queryBuilder->execute()->fetchColumn(0);
                        $dataRows = [$dataRows];
                    } else {
                        $fullQueryString = $selectQueryString;
                        $dataRows = $connection->executeQuery($selectQueryString)->fetchAll();
                    }
                    if (!$this->backendUserAuthentication->userTS['mod.']['dbint.']['disableShowSQLQuery']) {
                        $output .= '<h2>SQL query</h2><div><pre>' . htmlspecialchars($fullQueryString) . '</pre></div>';
                    }
                    $cPR = $this->getQueryResultCode($mQ, $dataRows, $queryGenerator->table);
                    $output .= '<h2>' . $cPR['header'] . '</h2><div>' . $cPR['content'] . '</div>';
                } catch (DBALException $e) {
                    if (!$this->backendUserAuthentication->userTS['mod.']['dbint.']['disableShowSQLQuery']) {
                        $output .= '<h2>SQL query</h2><div><pre>' . htmlspecialchars($fullQueryString) . '</pre></div>';
                    }
456
                    $out = '<p><strong>Error: <span class="text-danger">'
457
                        . $e->getMessage()
458
                        . '</span></strong></p>';
459
                    $output .= '<h2>SQL error</h2><div>' . $out . '</div>';
460
461
462
463
464
465
466
467
468
                }
            }
        }
        return '<div class="query-builder">' . $output . '</div>';
    }

    /**
     * Get query result code
     *
469
470
     * @param string $type
     * @param array $dataRows Rows to display
471
472
473
     * @param string $table
     * @return string
     */
474
    public function getQueryResultCode($type, array $dataRows, $table)
475
476
    {
        $out = '';
477
478
        $cPR = [];
        switch ($type) {
479
480
            case 'count':
                $cPR['header'] = 'Count';
481
                $cPR['content'] = '<BR><strong>' . $dataRows[0] . '</strong> records selected.';
482
483
                break;
            case 'all':
484
485
486
487
                $rowArr = [];
                $dataRow = null;
                foreach ($dataRows as $dataRow) {
                    $rowArr[] = $this->resultRowDisplay($dataRow, $GLOBALS['TCA'][$table], $table);
488
489
490
491
492
493
494
                }
                if (is_array($this->hookArray['beforeResultTable'])) {
                    foreach ($this->hookArray['beforeResultTable'] as $_funcRef) {
                        $out .= GeneralUtility::callUserFunction($_funcRef, $GLOBALS['SOBE']->MOD_SETTINGS, $this);
                    }
                }
                if (!empty($rowArr)) {
495
                    $out .= '<table class="table table-striped table-hover">'
496
                        . $this->resultRowTitles($dataRow, $GLOBALS['TCA'][$table], $table) . implode(LF, $rowArr)
497
                        . '</table>';
498
499
                }
                if (!$out) {
500
501
502
503
504
505
                    $flashMessage = GeneralUtility::makeInstance(
                        FlashMessage::class,
                        'No rows selected!',
                        '',
                        FlashMessage::INFO
                    );
506
507
508
                    GeneralUtility::makeInstance(FlashMessageRendererResolver::class)
                        ->resolve()
                        ->render([$flashMessage]);
509
510
511
512
513
                }
                $cPR['header'] = 'Result';
                $cPR['content'] = $out;
                break;
            case 'csv':
514
                $rowArr = [];
515
                $first = 1;
516
                foreach ($dataRows as $dataRow) {
517
                    if ($first) {
518
                        $rowArr[] = $this->csvValues(array_keys($dataRow), ',', '');
519
520
                        $first = 0;
                    }
521
                    $rowArr[] = $this->csvValues($dataRow, ',', '"', $GLOBALS['TCA'][$table], $table);
522
523
                }
                if (!empty($rowArr)) {
524
525
526
                    $out .= '<textarea name="whatever" rows="20" class="text-monospace" style="width:100%">'
                        . htmlspecialchars(implode(LF, $rowArr))
                        . '</textarea>';
527
                    if (!$this->noDownloadB) {
528
529
530
                        $out .= '<br><input class="btn btn-default" type="submit" name="download_file" '
                            . 'value="Click to download file" onClick="window.location.href=\'' . $this->downloadScript
                            . '\';">';
531
532
                    }
                    // Downloads file:
533
                    // @todo: args. routing anyone?
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
                    if (GeneralUtility::_GP('download_file')) {
                        $filename = 'TYPO3_' . $table . '_export_' . date('dmy-Hi') . '.csv';
                        $mimeType = 'application/octet-stream';
                        header('Content-Type: ' . $mimeType);
                        header('Content-Disposition: attachment; filename=' . $filename);
                        echo implode(CRLF, $rowArr);
                        die;
                    }
                }
                if (!$out) {
                    $out = '<em>No rows selected!</em>';
                }
                $cPR['header'] = 'Result';
                $cPR['content'] = $out;
                break;
            case 'explain':
            default:
551
552
                foreach ($dataRows as $dataRow) {
                    $out .= '<br />' . DebugUtility::viewArray($dataRow);
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
                }
                $cPR['header'] = 'Explain SQL query';
                $cPR['content'] = $out;
        }
        return $cPR;
    }

    /**
     * CSV values
     *
     * @param array $row
     * @param string $delim
     * @param string $quote
     * @param array $conf
     * @param string $table
     * @return string A single line of CSV
     */
570
    public function csvValues($row, $delim = ',', $quote = '"', $conf = [], $table = '')
571
572
573
574
575
576
577
    {
        $valueArray = $row;
        if ($GLOBALS['SOBE']->MOD_SETTINGS['search_result_labels'] && $table) {
            foreach ($valueArray as $key => $val) {
                $valueArray[$key] = $this->getProcessedValueExtra($table, $key, $val, $conf, ';');
            }
        }
578
        return CsvUtility::csvValues($valueArray, $delim, $quote);
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
    }

    /**
     * Search
     *
     * @return string
     */
    public function search()
    {
        $SET = $GLOBALS['SOBE']->MOD_SETTINGS;
        $swords = $SET['sword'];
        $out = '';
        if ($swords) {
            foreach ($GLOBALS['TCA'] as $table => $value) {
                // Get fields list
                $conf = $GLOBALS['TCA'][$table];
                // Avoid querying tables with no columns
                if (empty($conf['columns'])) {
                    continue;
                }
599
600
601
602
603
604
605
606
607
608
609
610
611
612
                $connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable($table);
                $tableColumns = $connection->getSchemaManager()->listTableColumns($table);
                $fieldsInDatabase = [];
                foreach ($tableColumns as $column) {
                    $fieldsInDatabase[] = $column->getName();
                }
                $fields = array_intersect(array_keys($conf['columns']), $fieldsInDatabase);

                $queryBuilder = $connection->createQueryBuilder();
                $queryBuilder->getRestrictions()->removeAll()->add(GeneralUtility::makeInstance(DeletedRestriction::class));
                $queryBuilder->count('*')->from($table);
                $likes = [];
                $excapedLikeString = '%' . $queryBuilder->escapeLikeWildcards($swords) . '%';
                foreach ($fields as $field) {
613
614
615
616
                    $likes[] = $queryBuilder->expr()->like(
                        $field,
                        $queryBuilder->createNamedParameter($excapedLikeString, \PDO::PARAM_STR)
                    );
617
618
619
620
621
622
623
624
625
626
627
                }
                $count = $queryBuilder->orWhere(...$likes)->execute()->fetchColumn(0);

                if ($count > 0) {
                    $queryBuilder = $connection->createQueryBuilder();
                    $queryBuilder->getRestrictions()->removeAll()->add(GeneralUtility::makeInstance(DeletedRestriction::class));
                    $queryBuilder->select('uid', $conf['ctrl']['label'])
                        ->from($table)
                        ->setMaxResults(200);
                    $likes = [];
                    foreach ($fields as $field) {
628
629
630
631
                        $likes[] = $queryBuilder->expr()->like(
                            $field,
                            $queryBuilder->createNamedParameter($excapedLikeString, \PDO::PARAM_STR)
                        );
632
633
634
635
636
                    }
                    $statement = $queryBuilder->orWhere(...$likes)->execute();
                    $lastRow = null;
                    $rowArr = [];
                    while ($row = $statement->fetch()) {
637
                        $rowArr[] = $this->resultRowDisplay($row, $conf, $table);
638
                        $lastRow = $row;
639
                    }
640
641
642
                    $markup = [];
                    $markup[] = '<div class="panel panel-default">';
                    $markup[] = '  <div class="panel-heading">';
643
                    $markup[] = htmlspecialchars($this->languageService->sL($conf['ctrl']['title'])) . ' (' . $count . ')';
644
645
                    $markup[] = '  </div>';
                    $markup[] = '  <table class="table table-striped table-hover">';
646
647
                    $markup[] = $this->resultRowTitles($lastRow, $conf, $table);
                    $markup[] = implode(LF, $rowArr);
648
649
650
651
                    $markup[] = '  </table>';
                    $markup[] = '</div>';

                    $out .= implode(LF, $markup);
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
                }
            }
        }
        return $out;
    }

    /**
     * Result row display
     *
     * @param array $row
     * @param array $conf
     * @param string $table
     * @return string
     */
    public function resultRowDisplay($row, $conf, $table)
    {
        $SET = $GLOBALS['SOBE']->MOD_SETTINGS;
        $out = '<tr>';
        foreach ($row as $fieldName => $fieldValue) {
671
672
            if (GeneralUtility::inList($SET['queryFields'], $fieldName)
                || !$SET['queryFields']
673
674
                && $fieldName !== 'pid'
                && $fieldName !== 'deleted'
675
            ) {
676
677
678
679
680
681
682
683
                if ($SET['search_result_labels']) {
                    $fVnew = $this->getProcessedValueExtra($table, $fieldName, $fieldValue, $conf, '<br />');
                } else {
                    $fVnew = htmlspecialchars($fieldValue);
                }
                $out .= '<td>' . $fVnew . '</td>';
            }
        }
684
        $out .= '<td>';
685
686
687
        /** @var \TYPO3\CMS\Backend\Routing\UriBuilder $uriBuilder */
        $uriBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Routing\UriBuilder::class);

688
        if (!$row['deleted']) {
689
            $out .= '<div class="btn-group" role="group">';
690
            $url = (string)$uriBuilder->buildUriFromRoute('record_edit', [
691
692
693
694
695
                'edit' => [
                    $table => [
                        $row['uid'] => 'edit'
                    ]
                ],
696
697
                'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
                    . GeneralUtility::implodeArrayForUrl('SET', (array)GeneralUtility::_POST('SET'))
698
            ]);
699
700
701
            $out .= '<a class="btn btn-default" href="' . htmlspecialchars($url) . '">'
                . $this->iconFactory->getIcon('actions-open', Icon::SIZE_SMALL)->render() . '</a>';
            $out .= '</div><div class="btn-group" role="group">';
702
703
704
            $out .= '<a class="btn btn-default" href="#" onClick="top.launchView(\'' . $table . '\',' . $row['uid']
                . ');return false;">' . $this->iconFactory->getIcon('actions-document-info', Icon::SIZE_SMALL)->render()
                . '</a>';
705
            $out .= '</div>';
706
        } else {
707
            $out .= '<div class="btn-group" role="group">';
708
            $out .= '<a class="btn btn-default" href="' . htmlspecialchars((string)$uriBuilder->buildUriFromRoute('tce_db', [
709
710
711
712
713
714
715
716
                        'cmd' => [
                            $table => [
                                $row['uid'] => [
                                    'undelete' => 1
                                ]
                            ]
                        ],
                        'redirect' => GeneralUtility::linkThisScript()
717
                    ])) . '" title="' . htmlspecialchars($this->languageService->getLL('undelete_only')) . '">';
718
            $out .= $this->iconFactory->getIcon('actions-edit-restore', Icon::SIZE_SMALL)->render() . '</a>';
719
720
721
722
723
724
725
726
            $formEngineParameters = [
                'edit' => [
                    $table => [
                        $row['uid'] => 'edit'
                    ]
                ],
                'returnUrl' => GeneralUtility::linkThisScript()
            ];
727
728
            $redirectUrl = (string)$uriBuilder->buildUriFromRoute('record_edit', $formEngineParameters);
            $out .= '<a class="btn btn-default" href="' . htmlspecialchars((string)$uriBuilder->buildUriFromRoute('tce_db', [
729
730
731
732
733
734
735
                    'cmd' => [
                        $table => [
                            $row['uid'] => [
                                'undelete' => 1
                            ]
                        ]
                    ],
736
                    'redirect' => $redirectUrl
737
                ])) . '" title="' . htmlspecialchars($this->languageService->getLL('undelete_and_edit')) . '">';
738
            $out .= $this->iconFactory->getIcon('actions-edit-restore-edit', Icon::SIZE_SMALL)->render() . '</a>';
739
            $out .= '</div>';
740
        }
741
        $_params = [$table => $row];
742
743
744
745
746
        if (is_array($this->hookArray['additionalButtons'])) {
            foreach ($this->hookArray['additionalButtons'] as $_funcRef) {
                $out .= GeneralUtility::callUserFunction($_funcRef, $_params, $this);
            }
        }
747
        $out .= '</td></tr>';
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
        return $out;
    }

    /**
     * Get processed value extra
     *
     * @param string $table
     * @param string $fieldName
     * @param string $fieldValue
     * @param array $conf Not used
     * @param string $splitString
     * @return string
     */
    public function getProcessedValueExtra($table, $fieldName, $fieldValue, $conf, $splitString)
    {
        $out = '';
764
        $fields = [];
765
766
767
768
769
770
        // Analysing the fields in the table.
        if (is_array($GLOBALS['TCA'][$table])) {
            $fC = $GLOBALS['TCA'][$table]['columns'][$fieldName];
            $fields = $fC['config'];
            $fields['exclude'] = $fC['exclude'];
            if (is_array($fC) && $fC['label']) {
771
                $fields['label'] = preg_replace('/:$/', '', trim($this->languageService->sL($fC['label'])));
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
                switch ($fields['type']) {
                    case 'input':
                        if (preg_match('/int|year/i', $fields['eval'])) {
                            $fields['type'] = 'number';
                        } elseif (preg_match('/time/i', $fields['eval'])) {
                            $fields['type'] = 'time';
                        } elseif (preg_match('/date/i', $fields['eval'])) {
                            $fields['type'] = 'date';
                        } else {
                            $fields['type'] = 'text';
                        }
                        break;
                    case 'check':
                        if (!$fields['items']) {
                            $fields['type'] = 'boolean';
                        } else {
                            $fields['type'] = 'binary';
                        }
                        break;
                    case 'radio':
                        $fields['type'] = 'multiple';
                        break;
                    case 'select':
                        $fields['type'] = 'multiple';
                        if ($fields['foreign_table']) {
                            $fields['type'] = 'relation';
                        }
                        if ($fields['special']) {
                            $fields['type'] = 'text';
                        }
                        break;
                    case 'group':
                        $fields['type'] = 'files';
805
                        if ($fields['internal_type'] === 'db') {
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
                            $fields['type'] = 'relation';
                        }
                        break;
                    case 'user':
                    case 'flex':
                    case 'passthrough':
                    case 'none':
                    case 'text':
                    default:
                        $fields['type'] = 'text';
                }
            } else {
                $fields['label'] = '[FIELD: ' . $fieldName . ']';
                switch ($fieldName) {
                    case 'pid':
                        $fields['type'] = 'relation';
                        $fields['allowed'] = 'pages';
                        break;
                    case 'cruser_id':
                        $fields['type'] = 'relation';
                        $fields['allowed'] = 'be_users';
                        break;
                    case 'tstamp':
                    case 'crdate':
                        $fields['type'] = 'time';
                        break;
                    default:
                        $fields['type'] = 'number';
                }
            }
        }
        switch ($fields['type']) {
            case 'date':
                if ($fieldValue != -1) {
840
                    $out = strftime('%d-%m-%Y', $fieldValue);
841
842
843
844
                }
                break;
            case 'time':
                if ($fieldValue != -1) {
845
                    if ($splitString === '<br />') {
846
                        $out = strftime('%H:%M' . $splitString . '%d-%m-%Y', $fieldValue);
847
                    } else {
848
                        $out = strftime('%H:%M %d-%m-%Y', $fieldValue);
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
                    }
                }
                break;
            case 'multiple':
            case 'binary':
            case 'relation':
                $out = $this->makeValueList($fieldName, $fieldValue, $fields, $table, $splitString);
                break;
            case 'boolean':
                $out = $fieldValue ? 'True' : 'False';
                break;
            case 'files':
            default:
                $out = htmlspecialchars($fieldValue);
        }
        return $out;
    }

    /**
     * Get tree list
     *
     * @param int $id
     * @param int $depth
     * @param int $begin
873
874
     * @param string $permsClause
     *
875
876
     * @return string
     */
877
    public function getTreeList($id, $depth, $begin = 0, $permsClause = null)
878
879
880
881
882
883
884
885
886
887
888
889
890
    {
        $depth = (int)$depth;
        $begin = (int)$begin;
        $id = (int)$id;
        if ($id < 0) {
            $id = abs($id);
        }
        if ($begin == 0) {
            $theList = $id;
        } else {
            $theList = '';
        }
        if ($id && $depth > 0) {
891
892
893
894
895
            $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('pages');
            $queryBuilder->getRestrictions()->removeAll()->add(GeneralUtility::makeInstance(DeletedRestriction::class));
            $statement = $queryBuilder->select('uid')
                ->from('pages')
                ->where(
896
                    $queryBuilder->expr()->eq('pid', $queryBuilder->createNamedParameter($id, \PDO::PARAM_INT)),
897
898
899
900
                    QueryHelper::stripLogicalOperatorPrefix($permsClause)
                )
                ->execute();
            while ($row = $statement->fetch()) {
901
902
903
904
                if ($begin <= 0) {
                    $theList .= ',' . $row['uid'];
                }
                if ($depth > 1) {
905
                    $theList .= $this->getTreeList($row['uid'], $depth - 1, $begin - 1, $permsClause);
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
                }
            }
        }
        return $theList;
    }

    /**
     * Make value list
     *
     * @param string $fieldName
     * @param string $fieldValue
     * @param array $conf
     * @param string $table
     * @param string $splitString
     * @return string
     */
    public function makeValueList($fieldName, $fieldValue, $conf, $table, $splitString)
    {
        $fieldSetup = $conf;
        $out = '';
926
        if ($fieldSetup['type'] === 'files') {
927
928
            $d = dir(PATH_site . $fieldSetup['uploadfolder']);
            while (false !== ($entry = $d->read())) {
929
                if ($entry === '.' || $entry === '..') {
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
                    continue;
                }
                $fileArray[] = $entry;
            }
            $d->close();
            natcasesort($fileArray);
            foreach ($fileArray as $fileName) {
                if (GeneralUtility::inList($fieldValue, $fileName) || $fieldValue == $fileName) {
                    if (!$out) {
                        $out = htmlspecialchars($fileName);
                    } else {
                        $out .= $splitString . htmlspecialchars($fileName);
                    }
                }
            }
        }
946
        if ($fieldSetup['type'] === 'multiple') {
947
            foreach ($fieldSetup['items'] as $key => $val) {
948
                if (substr($val[0], 0, 4) === 'LLL:') {
949
                    $value = $this->languageService->sL($val[0]);
950
951
952
953
954
955
956
957
958
959
960
961
                } else {
                    $value = $val[0];
                }
                if (GeneralUtility::inList($fieldValue, $val[1]) || $fieldValue == $val[1]) {
                    if (!$out) {
                        $out = htmlspecialchars($value);
                    } else {
                        $out .= $splitString . htmlspecialchars($value);
                    }
                }
            }
        }
962
        if ($fieldSetup['type'] === 'binary') {
963
            foreach ($fieldSetup['items'] as $Key => $val) {
964
                if (substr($val[0], 0, 4) === 'LLL:') {
965
                    $value = $this->languageService->sL($val[0]);
966
967
968
969
970
971
972
973
974
975
                } else {
                    $value = $val[0];
                }
                if (!$out) {
                    $out = htmlspecialchars($value);
                } else {
                    $out .= $splitString . htmlspecialchars($value);
                }
            }
        }
976
        if ($fieldSetup['type'] === 'relation') {
977
978
            $dontPrefixFirstTable = 0;
            $useTablePrefix = 0;
979
980
            if ($fieldSetup['items']) {
                foreach ($fieldSetup['items'] as $key => $val) {
981
                    if (substr($val[0], 0, 4) === 'LLL:') {
982
                        $value = $this->languageService->sL($val[0]);
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
                    } else {
                        $value = $val[0];
                    }
                    if (GeneralUtility::inList($fieldValue, $value) || $fieldValue == $value) {
                        if (!$out) {
                            $out = htmlspecialchars($value);
                        } else {
                            $out .= $splitString . htmlspecialchars($value);
                        }
                    }
                }
            }
            if (stristr($fieldSetup['allowed'], ',')) {
                $from_table_Arr = explode(',', $fieldSetup['allowed']);
                $useTablePrefix = 1;
                if (!$fieldSetup['prepend_tname']) {
999
1000
1001
1002
1003
1004
1005
1006
                    $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($table);
                    $queryBuilder->getRestrictions()->removeAll()->add(GeneralUtility::makeInstance(DeletedRestriction::class));
                    $statement = $queryBuilder->select($fieldName)->from($table)->execute();
                    while ($row = $statement->fetch()) {
                        if (stristr($row[$fieldName], ',')) {
                            $checkContent = explode(',', $row[$fieldName]);
                            foreach ($checkContent as $singleValue) {
                                if (!stristr($singleValue, '_')) {
1007
1008
1009
                                    $dontPrefixFirstTable = 1;
                                }
                            }
1010
1011
1012
1013
1014
                        } else {
                            $singleValue = $row[$fieldName];
                            if ($singleValue !== '' && !stristr($singleValue, '_')) {
                                $dontPrefixFirstTable = 1;
                            }
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
                        }
                    }
                }
            } else {
                $from_table_Arr[0] = $fieldSetup['allowed'];
            }
            if ($fieldSetup['prepend_tname']) {
                $useTablePrefix = 1;
            }
            if ($fieldSetup['foreign_table']) {
                $from_table_Arr[0] = $fieldSetup['foreign_table'];
            }
            $counter = 0;
1028
1029
1030
1031
            $useSelectLabels = 0;
            $useAltSelectLabels = 0;
            $tablePrefix = '';
            $labelFieldSelect = [];
1032
1033
1034
1035
1036
1037
1038
1039
1040
            foreach ($from_table_Arr as $from_table) {
                if ($useTablePrefix && !$dontPrefixFirstTable && $counter != 1 || $counter == 1) {
                    $tablePrefix = $from_table . '_';
                }
                $counter = 1;
                if (is_array($GLOBALS['TCA'][$from_table])) {
                    $labelField = $GLOBALS['TCA'][$from_table]['ctrl']['label'];
                    $altLabelField = $GLOBALS['TCA'][$from_table]['ctrl']['label_alt'];
                    if ($GLOBALS['TCA'][$from_table]['columns'][$labelField]['config']['items']) {
1041
1042
                        $items = $GLOBALS['TCA'][$from_table]['columns'][$labelField]['config']['items'];
                        foreach ($items as $labelArray) {
1043
                            if (substr($labelArray[0], 0, 4) === 'LLL:') {
1044
                                $labelFieldSelect[$labelArray[1]] = $this->languageService->sL($labelArray[0]);
1045
1046
1047
1048
1049
1050
                            } else {
                                $labelFieldSelect[$labelArray[1]] = $labelArray[0];
                            }
                        }
                        $useSelectLabels = 1;
                    }
1051
                    $altLabelFieldSelect = [];
1052
                    if ($GLOBALS['TCA'][$from_table]['columns'][$altLabelField]['config']['items']) {
1053
1054
                        $items = $GLOBALS['TCA'][$from_table]['columns'][$altLabelField]['config']['items'];
                        foreach ($items as $altLabelArray) {
1055
                            if (substr($altLabelArray[0], 0, 4) === 'LLL:') {
1056
                                $altLabelFieldSelect[$altLabelArray[1]] = $this->languageService->sL($altLabelArray[0]);
1057
1058
1059
1060
1061
1062
                            } else {
                                $altLabelFieldSelect[$altLabelArray[1]] = $altLabelArray[0];
                            }
                        }
                        $useAltSelectLabels = 1;
                    }
1063
1064
1065
1066
1067
1068
1069

                    if (!$this->tableArray[$from_table]) {
                        $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($from_table);
                        $queryBuilder->getRestrictions()->removeAll()->add(GeneralUtility::makeInstance(DeletedRestriction::class));
                        $selectFields = ['uid', $labelField];
                        if ($altLabelField) {
                            $selectFields[] = $altLabelField;
1070
                        }
1071
1072
1073
1074
1075
                        $queryBuilder->select(...$selectFields)
                            ->from($from_table)
                            ->orderBy('uid');
                        if (!$this->backendUserAuthentication->isAdmin() && $GLOBALS['TYPO3_CONF_VARS']['BE']['lockBeUserToDBmounts']) {
                            $webMounts = $this->backendUserAuthentication->returnWebmounts();
1076
                            $perms_clause = $this->backendUserAuthentication->getPagePermsClause(Permission::PAGE_SHOW);
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
                            $webMountPageTree = '';
                            $webMountPageTreePrefix = '';
                            foreach ($webMounts as $webMount) {
                                if ($webMountPageTree) {
                                    $webMountPageTreePrefix = ',';
                                }
                                $webMountPageTree .= $webMountPageTreePrefix
                                    . $this->getTreeList($webMount, 999, ($begin = 0), $perms_clause);
                            }
                            if ($from_table === 'pages') {
                                $queryBuilder->where(
                                    QueryHelper::stripLogicalOperatorPrefix($perms_clause),
1089
1090
1091
1092
1093
1094
1095
                                    $queryBuilder->expr()->in(
                                        'uid',
                                        $queryBuilder->createNamedParameter(
                                            GeneralUtility::intExplode(',', $webMountPageTree),
                                            Connection::PARAM_INT_ARRAY
                                        )
                                    )
1096
1097
1098
                                );
                            } else {
                                $queryBuilder->where(
1099
1100
1101
1102
1103
1104
1105
                                    $queryBuilder->expr()->in(
                                        'pid',
                                        $queryBuilder->createNamedParameter(
                                            GeneralUtility::intExplode(',', $webMountPageTree),
                                            Connection::PARAM_INT_ARRAY
                                        )
                                    )
1106
1107
                                );
                            }
1108
                        }
1109
1110
1111
                        $statement = $queryBuilder->execute();
                        $this->tableArray[$from_table] = [];
                        while ($row = $statement->fetch()) {
1112
1113
1114
                            $this->tableArray[$from_table][] = $row;
                        }
                    }
1115

1116
                    foreach ($this->tableArray[$from_table] as $key => $val) {
1117
1118
1119
1120
1121
                        $GLOBALS['SOBE']->MOD_SETTINGS['labels_noprefix'] =
                            $GLOBALS['SOBE']->MOD_SETTINGS['labels_noprefix'] == 1
                                ? 'on'
                                : $GLOBALS['SOBE']->MOD_SETTINGS['labels_noprefix'];
                        $prefixString =
1122
                            $GLOBALS['SOBE']->MOD_SETTINGS['labels_noprefix'] === 'on'
1123
1124
1125
1126
                                ? ''
                                : ' [' . $tablePrefix . $val['uid'] . '] ';
                        if (GeneralUtility::inList($fieldValue, $tablePrefix . $val['uid'])
                            || $fieldValue == $tablePrefix . $val['uid']) {
1127
1128
1129
1130
                            if ($useSelectLabels) {
                                if (!$out) {
                                    $out = htmlspecialchars($prefixString . $labelFieldSelect[$val[$labelField]]);
                                } else {
1131
1132
1133
                                    $out .= $splitString . htmlspecialchars(
                                        $prefixString . $labelFieldSelect[$val[$labelField]]
                                    );
1134
1135
1136
1137
1138
                                }
                            } elseif ($val[$labelField]) {
                                if (!$out) {
                                    $out = htmlspecialchars($prefixString . $val[$labelField]);
                                } else {
1139
1140
1141
                                    $out .= $splitString . htmlspecialchars(
                                        $prefixString . $val[$labelField]
                                    );
1142
1143
1144
1145
1146
                                }
                            } elseif ($useAltSelectLabels) {
                                if (!$out) {
                                    $out = htmlspecialchars($prefixString . $altLabelFieldSelect[$val[$altLabelField]]);
                                } else {
1147
1148
1149
                                    $out .= $splitString . htmlspecialchars(
                                        $prefixString . $altLabelFieldSelect[$val[$altLabelField]]
                                    );
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
                                }
                            } else {
                                if (!$out) {
                                    $out = htmlspecialchars($prefixString . $val[$altLabelField]);
                                } else {
                                    $out .= $splitString . htmlspecialchars(($prefixString . $val[$altLabelField]));
                                }
                            }
                        }
                    }
                }
            }
        }
        return $out;
    }

    /**
     * Render table header
     *
     * @param array $row Table columns
     * @param array $conf Table TCA
     * @param string $table Table name
     * @return string HTML of table header
     */
    public function resultRowTitles($row, $conf, $table)
    {
        $SET = $GLOBALS['SOBE']->MOD_SETTINGS;
1177
        $tableHeader = [];
1178
1179
1180
1181
        // Start header row
        $tableHeader[] = '<thead><tr>';
        // Iterate over given columns
        foreach ($row as $fieldName => $fieldValue) {
1182
1183
            if (GeneralUtility::inList($SET['queryFields'], $fieldName)
                || !$SET['queryFields']
1184
1185
                && $fieldName !== 'pid'
                && $fieldName !== 'deleted'
1186
            ) {
1187
                if ($GLOBALS['SOBE']->MOD_SETTINGS['search_result_labels']) {
1188
                    $title = htmlspecialchars($this->languageService->sL($conf['columns'][$fieldName]['label']
1189
                        ? $conf['columns'][$fieldName]['label']
1190
                        : $fieldName));
1191
                } else {
1192
                    $title = htmlspecialchars($this->languageService->sL($fieldName));
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
                }
                $tableHeader[] = '<th>' . $title . '</th>';
            }
        }
        // Add empty icon column
        $tableHeader[] = '<th></th>';
        // Close header row
        $tableHeader[] = '</tr></thead>';
        return implode(LF, $tableHeader);
    }

    /**
     * CSV row titles
     *
     * @param array $row
     * @param array $conf
     * @param mixed $table Not used
     * @return string
     */
    public function csvRowTitles($row, $conf, $table)
    {
        $out = '';
        $SET = $GLOBALS['SOBE']->MOD_SETTINGS;
        foreach ($row as $fieldName => $fieldValue) {
1217
            if (GeneralUtility::inList($SET['queryFields'], $fieldName)
1218
                || !$SET['queryFields'] && $fieldName !== 'pid') {
1219
1220
                if (!$out) {
                    if ($GLOBALS['SOBE']->MOD_SETTINGS['search_result_labels']) {
1221
                        $out = htmlspecialchars($this->languageService->sL($conf['columns'][$fieldName]['label']
1222
                            ? $conf['columns'][$fieldName]['label']
1223
                            : $fieldName));
1224
                    } else {
1225
                        $out = htmlspecialchars($this->languageService->sL($fieldName));
1226
1227
1228
                    }
                } else {
                    if ($GLOBALS['SOBE']->MOD_SETTINGS['search_result_labels']) {
1229
                        $out .= ',' . htmlspecialchars($this->languageService->sL(($conf['columns'][$fieldName]['label']
1230
                            ? $conf['columns'][$fieldName]['label']
1231
                            : $fieldName)));
1232
                    } else {
1233
                        $out .= ',' . htmlspecialchars($this->languageService->sL($fieldName));
1234
1235
1236
1237
1238
1239
                    }
                }
            }
        }
        return $out;
    }
1240

1241
1242
1243
1244
1245
1246
1247
1248
1249
    /**
     * Sets the current name of the input form.
     *
     * @param string $formName The name of the form.
     */
    public function setFormName($formName)
    {
        $this->formName = trim($formName);
    }
1250
}