[TASK] Change input type of search-fields from text to search
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Classes / Database / QueryView.php
1 <?php
2 namespace TYPO3\CMS\Core\Database;
3
4 /**
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Core\Utility\GeneralUtility;
18 use TYPO3\CMS\Backend\Utility\BackendUtility;
19
20 /**
21 * Class used in module tools/dbint (advanced search) and which may hold code specific for that module
22 * However the class has a general principle in it which may be used in the web/export module.
23 *
24 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
25 * @author Jo Hasenau <info@cybercraft.de>
26 */
27 class QueryView {
28
29 /**
30 * @todo Define visibility
31 */
32 public $storeList = 'search_query_smallparts,search_result_labels,labels_noprefix,show_deleted,queryConfig,queryTable,queryFields,queryLimit,queryOrder,queryOrderDesc,queryOrder2,queryOrder2Desc,queryGroup,search_query_makeQuery';
33
34 /**
35 * @todo Define visibility
36 */
37 public $downloadScript = 'index.php';
38
39 /**
40 * @todo Define visibility
41 */
42 public $formW = 48;
43
44 /**
45 * @todo Define visibility
46 */
47 public $noDownloadB = 0;
48
49 protected $formName = '';
50
51 /**
52 * constructor
53 */
54 public function __construct() {
55 $GLOBALS['LANG']->includeLLFile('EXT:lang/locallang_t3lib_fullsearch.xlf');
56 }
57
58 /**
59 * [Describe function...]
60 *
61 * @return string
62 * @todo Define visibility
63 */
64 public function form() {
65 $out = '
66 Search Word:<BR>
67 <input type="search" name="SET[sword]" value="' . htmlspecialchars($GLOBALS['SOBE']->MOD_SETTINGS['sword']) . '"' . $GLOBALS['TBE_TEMPLATE']->formWidth(20) . '><input type="submit" name="submit" value="Search All Records">
68 ';
69 return $out;
70 }
71
72 /**
73 * [Describe function...]
74 *
75 * @return string
76 * @todo Define visibility
77 */
78 public function makeStoreControl() {
79 // Load/Save
80 $storeArray = $this->initStoreArray();
81 // Store Array:
82 $opt = array();
83 foreach ($storeArray as $k => $v) {
84 $opt[] = '<option value="' . $k . '">' . htmlspecialchars($v) . '</option>';
85 }
86 // Actions:
87 if (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('sys_action') && $GLOBALS['BE_USER']->isAdmin()) {
88 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'sys_action', 'type=2', '', 'title');
89 if ($GLOBALS['TYPO3_DB']->sql_num_rows($res)) {
90 $opt[] = '<option value="0">__Save to Action:__</option>';
91 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
92 $opt[] = '<option value="-' . $row['uid'] . '">' . htmlspecialchars(($row['title'] . ' [' . $row['uid'] . ']')) . '</option>';
93 }
94 }
95 $GLOBALS['TYPO3_DB']->sql_free_result($res);
96 }
97 $TDparams = ' nowrap="nowrap" class="bgColor4"';
98 $tmpCode = '
99 <table border="0" cellpadding="3" cellspacing="1">
100 <tr' . $TDparams . '><td><select 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><input type="submit" name="storeControl[LOAD]" value="Load"></td></tr>
101 <tr' . $TDparams . '><td nowrap><input name="storeControl[title]" value="" type="text" max="80"' . $GLOBALS['SOBE']->doc->formWidth() . '><input type="submit" name="storeControl[SAVE]" value="Save" onClick="if (document.forms[0][\'storeControl[STORE]\'].options[document.forms[0][\'storeControl[STORE]\'].selectedIndex].value<0) return confirm(\'Are you sure you want to overwrite the existing query in this action?\');"><input type="submit" name="storeControl[REMOVE]" value="Remove"></td></tr>
102 </table>
103 ';
104 return $tmpCode;
105 }
106
107 /**
108 * [Describe function...]
109 *
110 * @return array
111 * @todo Define visibility
112 */
113 public function initStoreArray() {
114 $storeArray = array(
115 '0' => '[New]'
116 );
117 $savedStoreArray = unserialize($GLOBALS['SOBE']->MOD_SETTINGS['storeArray']);
118 if (is_array($savedStoreArray)) {
119 $storeArray = array_merge($storeArray, $savedStoreArray);
120 }
121 return $storeArray;
122 }
123
124 /**
125 * [Describe function...]
126 *
127 * @param array $storeQueryConfigs
128 * @param array $storeArray
129 * @return array
130 * @todo Define visibility
131 */
132 public function cleanStoreQueryConfigs($storeQueryConfigs, $storeArray) {
133 if (is_array($storeQueryConfigs)) {
134 foreach ($storeQueryConfigs as $k => $v) {
135 if (!isset($storeArray[$k])) {
136 unset($storeQueryConfigs[$k]);
137 }
138 }
139 }
140 return $storeQueryConfigs;
141 }
142
143 /**
144 * [Describe function...]
145 *
146 * @param array $storeQueryConfigs
147 * @param integer $index
148 * @return array
149 * @todo Define visibility
150 */
151 public function addToStoreQueryConfigs($storeQueryConfigs, $index) {
152 $keyArr = explode(',', $this->storeList);
153 $storeQueryConfigs[$index] = array();
154 foreach ($keyArr as $k) {
155 $storeQueryConfigs[$index][$k] = $GLOBALS['SOBE']->MOD_SETTINGS[$k];
156 }
157 return $storeQueryConfigs;
158 }
159
160 /**
161 * [Describe function...]
162 *
163 * @param integer $uid
164 * @return integer
165 * @todo Define visibility
166 */
167 public function saveQueryInAction($uid) {
168 if (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('sys_action')) {
169 $keyArr = explode(',', $this->storeList);
170 $saveArr = array();
171 foreach ($keyArr as $k) {
172 $saveArr[$k] = $GLOBALS['SOBE']->MOD_SETTINGS[$k];
173 }
174 $qOK = 0;
175 // Show query
176 if ($saveArr['queryTable']) {
177 /** @var \TYPO3\CMS\Core\Database\QueryGenerator */
178 $qGen = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Database\\QueryGenerator');
179 $qGen->init('queryConfig', $saveArr['queryTable']);
180 $qGen->makeSelectorTable($saveArr);
181 $qGen->enablePrefix = 1;
182 $qString = $qGen->getQuery($qGen->queryConfig);
183 $qCount = $GLOBALS['TYPO3_DB']->SELECTquery('count(*)', $qGen->table, $qString . BackendUtility::deleteClause($qGen->table));
184 $qSelect = $qGen->getSelectQuery($qString);
185 $res = @$GLOBALS['TYPO3_DB']->sql_query($qCount);
186 if (!$GLOBALS['TYPO3_DB']->sql_error()) {
187 $GLOBALS['TYPO3_DB']->sql_free_result($res);
188 $dA = array();
189 $dA['t2_data'] = serialize(array(
190 'qC' => $saveArr,
191 'qCount' => $qCount,
192 'qSelect' => $qSelect,
193 'qString' => $qString
194 ));
195 $GLOBALS['TYPO3_DB']->exec_UPDATEquery('sys_action', 'uid=' . (int)$uid, $dA);
196 $qOK = 1;
197 }
198 }
199 return $qOK;
200 }
201 }
202
203 /**
204 * [Describe function...]
205 *
206 * @param array $storeQueryConfigs
207 * @param integer $storeIndex
208 * @param array $writeArray
209 * @return array
210 * @todo Define visibility
211 */
212 public function loadStoreQueryConfigs($storeQueryConfigs, $storeIndex, $writeArray) {
213 if ($storeQueryConfigs[$storeIndex]) {
214 $keyArr = explode(',', $this->storeList);
215 foreach ($keyArr as $k) {
216 $writeArray[$k] = $storeQueryConfigs[$storeIndex][$k];
217 }
218 }
219 return $writeArray;
220 }
221
222 /**
223 * [Describe function...]
224 *
225 * @return string
226 * @todo Define visibility
227 */
228 public function procesStoreControl() {
229 $storeArray = $this->initStoreArray();
230 $storeQueryConfigs = unserialize($GLOBALS['SOBE']->MOD_SETTINGS['storeQueryConfigs']);
231 $storeControl = GeneralUtility::_GP('storeControl');
232 $storeIndex = (int)$storeControl['STORE'];
233 $saveStoreArray = 0;
234 $writeArray = array();
235 if (is_array($storeControl)) {
236 $msg = '';
237 if ($storeControl['LOAD']) {
238 if ($storeIndex > 0) {
239 $writeArray = $this->loadStoreQueryConfigs($storeQueryConfigs, $storeIndex, $writeArray);
240 $saveStoreArray = 1;
241 $flashMessage = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', sprintf($GLOBALS['LANG']->getLL('query_loaded'), htmlspecialchars($storeArray[$storeIndex])));
242 } elseif ($storeIndex < 0 && \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('sys_action')) {
243 $actionRecord = BackendUtility::getRecord('sys_action', abs($storeIndex));
244 if (is_array($actionRecord)) {
245 $dA = unserialize($actionRecord['t2_data']);
246 $dbSC = array();
247 if (is_array($dA['qC'])) {
248 $dbSC[0] = $dA['qC'];
249 }
250 $writeArray = $this->loadStoreQueryConfigs($dbSC, '0', $writeArray);
251 $saveStoreArray = 1;
252 $flashMessage = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', sprintf($GLOBALS['LANG']->getLL('query_from_action_loaded'), htmlspecialchars($actionRecord['title'])));
253 }
254 }
255 } elseif ($storeControl['SAVE']) {
256 if ($storeIndex < 0) {
257 $qOK = $this->saveQueryInAction(abs($storeIndex));
258 if ($qOK) {
259 $flashMessage = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', $GLOBALS['LANG']->getLL('query_saved'));
260 } else {
261 $flashMessage = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', $GLOBALS['LANG']->getLL('query_notsaved'), '', \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
262 }
263 } else {
264 if (trim($storeControl['title'])) {
265 if ($storeIndex > 0) {
266 $storeArray[$storeIndex] = $storeControl['title'];
267 } else {
268 $storeArray[] = $storeControl['title'];
269 end($storeArray);
270 $storeIndex = key($storeArray);
271 }
272 $storeQueryConfigs = $this->addToStoreQueryConfigs($storeQueryConfigs, $storeIndex);
273 $saveStoreArray = 1;
274 $flashMessage = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', $GLOBALS['LANG']->getLL('query_saved'));
275 }
276 }
277 } elseif ($storeControl['REMOVE']) {
278 if ($storeIndex > 0) {
279 $flashMessage = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', sprintf($GLOBALS['LANG']->getLL('query_removed'), htmlspecialchars($storeArray[$storeControl['STORE']])));
280 // Removing
281 unset($storeArray[$storeControl['STORE']]);
282 $saveStoreArray = 1;
283 }
284 }
285 if ($flashMessage) {
286 $msg = $flashMessage->render();
287 }
288 }
289 if ($saveStoreArray) {
290 // Making sure, index 0 is not set!
291 unset($storeArray[0]);
292 $writeArray['storeArray'] = serialize($storeArray);
293 $writeArray['storeQueryConfigs'] = serialize($this->cleanStoreQueryConfigs($storeQueryConfigs, $storeArray));
294 $GLOBALS['SOBE']->MOD_SETTINGS = BackendUtility::getModuleData($GLOBALS['SOBE']->MOD_MENU, $writeArray, $GLOBALS['SOBE']->MCONF['name'], 'ses');
295 }
296 return $msg;
297 }
298
299 /**
300 * [Describe function...]
301 *
302 * @return string
303 * @todo Define visibility
304 */
305 public function queryMaker() {
306 $output = '';
307 if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['t3lib_fullsearch'])) {
308 $this->hookArray = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['t3lib_fullsearch'];
309 }
310 $msg = $this->procesStoreControl();
311 if (!$GLOBALS['BE_USER']->userTS['mod.']['dbint.']['disableStoreControl']) {
312 $output .= $GLOBALS['SOBE']->doc->section('Load/Save Query', $this->makeStoreControl(), 0, 1);
313 if ($msg) {
314 $output .= '<br />' . $msg;
315 }
316 $output .= $GLOBALS['SOBE']->doc->spacer(20);
317 }
318 // Query Maker:
319 $qGen = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Database\\QueryGenerator');
320 $qGen->init('queryConfig', $GLOBALS['SOBE']->MOD_SETTINGS['queryTable']);
321 if ($this->formName) {
322 $qGen->setFormName($this->formName);
323 }
324 $tmpCode = $qGen->makeSelectorTable($GLOBALS['SOBE']->MOD_SETTINGS);
325 $output .= $GLOBALS['SOBE']->doc->section('Make query', $tmpCode, 0, 1);
326 $mQ = $GLOBALS['SOBE']->MOD_SETTINGS['search_query_makeQuery'];
327 // Make form elements:
328 if ($qGen->table && is_array($GLOBALS['TCA'][$qGen->table])) {
329 if ($mQ) {
330 // Show query
331 $qGen->enablePrefix = 1;
332 $qString = $qGen->getQuery($qGen->queryConfig);
333 switch ($mQ) {
334 case 'count':
335 $qExplain = $GLOBALS['TYPO3_DB']->SELECTquery('count(*)', $qGen->table, $qString . BackendUtility::deleteClause($qGen->table));
336 break;
337 default:
338 $qExplain = $qGen->getSelectQuery($qString);
339 if ($mQ == 'explain') {
340 $qExplain = 'EXPLAIN ' . $qExplain;
341 }
342 }
343 if (!$GLOBALS['BE_USER']->userTS['mod.']['dbint.']['disableShowSQLQuery']) {
344 $output .= $GLOBALS['SOBE']->doc->section('SQL query', $this->tableWrap(htmlspecialchars($qExplain)), 0, 1);
345 }
346 $res = @$GLOBALS['TYPO3_DB']->sql_query($qExplain);
347 if ($GLOBALS['TYPO3_DB']->sql_error()) {
348 $out = '<BR><strong>Error:</strong><BR><font color="red"><strong>' . $GLOBALS['TYPO3_DB']->sql_error() . '</strong></font>';
349 $output .= $GLOBALS['SOBE']->doc->section('SQL error', $out, 0, 1);
350 } else {
351 $cPR = $this->getQueryResultCode($mQ, $res, $qGen->table);
352 $GLOBALS['TYPO3_DB']->sql_free_result($res);
353 $output .= $GLOBALS['SOBE']->doc->section($cPR['header'], $cPR['content'], 0, 1);
354 }
355 }
356 }
357 return $output;
358 }
359
360 /**
361 * [Describe function...]
362 *
363 * @param string $mQ
364 * @param pointer $res
365 * @param string $table
366 * @return string
367 * @todo Define visibility
368 */
369 public function getQueryResultCode($mQ, $res, $table) {
370 $out = '';
371 $cPR = array();
372 switch ($mQ) {
373 case 'count':
374 $row = $GLOBALS['TYPO3_DB']->sql_fetch_row($res);
375 $cPR['header'] = 'Count';
376 $cPR['content'] = '<BR><strong>' . $row[0] . '</strong> records selected.';
377 break;
378 case 'all':
379 $rowArr = array();
380 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
381 $rowArr[] = $this->resultRowDisplay($row, $GLOBALS['TCA'][$table], $table);
382 $lrow = $row;
383 }
384 if (is_array($this->hookArray['beforeResultTable'])) {
385 foreach ($this->hookArray['beforeResultTable'] as $_funcRef) {
386 $out .= GeneralUtility::callUserFunction($_funcRef, $GLOBALS['SOBE']->MOD_SETTINGS, $this);
387 }
388 }
389 if (count($rowArr)) {
390 $out .= '<table border="0" cellpadding="2" cellspacing="1" width="100%">' . $this->resultRowTitles($lrow, $GLOBALS['TCA'][$table], $table) . implode(LF, $rowArr) . '</table>';
391 }
392 if (!$out) {
393 $out = '<em>No rows selected!</em>';
394 }
395 $cPR['header'] = 'Result';
396 $cPR['content'] = $out;
397 break;
398 case 'csv':
399 $rowArr = array();
400 $first = 1;
401 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
402 if ($first) {
403 $rowArr[] = $this->csvValues(array_keys($row), ',', '');
404 $first = 0;
405 }
406 $rowArr[] = $this->csvValues($row, ',', '"', $GLOBALS['TCA'][$table], $table);
407 }
408 if (count($rowArr)) {
409 $out .= '<textarea name="whatever" rows="20" wrap="off"' . $GLOBALS['SOBE']->doc->formWidthText($this->formW, '', 'off') . ' class="fixed-font">' . GeneralUtility::formatForTextarea(implode(LF, $rowArr)) . '</textarea>';
410 if (!$this->noDownloadB) {
411 $out .= '<BR><input type="submit" name="download_file" value="Click to download file" onClick="window.location.href=\'' . $this->downloadScript . '\';">';
412 }
413 // Downloads file:
414 if (GeneralUtility::_GP('download_file')) {
415 $filename = 'TYPO3_' . $table . '_export_' . date('dmy-Hi') . '.csv';
416 $mimeType = 'application/octet-stream';
417 header('Content-Type: ' . $mimeType);
418 header('Content-Disposition: attachment; filename=' . $filename);
419 echo implode(CRLF, $rowArr);
420 die;
421 }
422 }
423 if (!$out) {
424 $out = '<em>No rows selected!</em>';
425 }
426 $cPR['header'] = 'Result';
427 $cPR['content'] = $out;
428 break;
429 case 'explain':
430
431 default:
432 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
433 $out .= '<br />' . \TYPO3\CMS\Core\Utility\DebugUtility::viewArray($row);
434 }
435 $cPR['header'] = 'Explain SQL query';
436 $cPR['content'] = $out;
437 }
438 return $cPR;
439 }
440
441 /**
442 * [Describe function...]
443 *
444 * @param array $row
445 * @param string $delim
446 * @param string $quote
447 * @param array $conf
448 * @param string $table
449 * @return string A single line of CSV
450 * @todo Define visibility
451 */
452 public function csvValues($row, $delim = ',', $quote = '"', $conf = array(), $table = '') {
453 $valueArray = $row;
454 if ($GLOBALS['SOBE']->MOD_SETTINGS['search_result_labels'] && $table) {
455 foreach ($valueArray as $key => $val) {
456 $valueArray[$key] = $this->getProcessedValueExtra($table, $key, $val, $conf, ';');
457 }
458 }
459 return GeneralUtility::csvValues($valueArray, $delim, $quote);
460 }
461
462 /**
463 * [Describe function...]
464 *
465 * @param string $str
466 * @return string
467 * @todo Define visibility
468 */
469 public function tableWrap($str) {
470 return '<table border="0" cellpadding="10" cellspacing="0" class="bgColor4"><tr><td nowrap><pre>' . $str . '</pre></td></tr></table>';
471 }
472
473 /**
474 * [Describe function...]
475 *
476 * @return string
477 * @todo Define visibility
478 */
479 public function search() {
480 $SET = $GLOBALS['SOBE']->MOD_SETTINGS;
481 $swords = $SET['sword'];
482 $out = '';
483 $limit = 200;
484 $showAlways = 0;
485 if ($swords) {
486 foreach ($GLOBALS['TCA'] as $table => $value) {
487 // Get fields list
488 $conf = $GLOBALS['TCA'][$table];
489 // Avoid querying tables with no columns
490 if (empty($conf['columns'])) {
491 continue;
492 }
493 $list = array_keys($conf['columns']);
494 // Get query
495 $qp = $GLOBALS['TYPO3_DB']->searchQuery(array($swords), $list, $table);
496 // Count:
497 $count = $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('*', $table, $qp . BackendUtility::deleteClause($table));
498 if ($count || $showAlways) {
499 // Output header:
500 $out .= '<strong>TABLE:</strong> ' . $GLOBALS['LANG']->sL($conf['ctrl']['title']) . '<BR>';
501 $out .= '<strong>Results:</strong> ' . $count . '<BR>';
502 // Show to limit
503 if ($count) {
504 $rowArr = array();
505 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid,' . $conf['ctrl']['label'], $table, $qp . BackendUtility::deleteClause($table), '', '', $limit);
506 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
507 $rowArr[] = $this->resultRowDisplay($row, $conf, $table);
508 $lrow = $row;
509 }
510 $GLOBALS['TYPO3_DB']->sql_free_result($res);
511 $out .= '<table border="0" cellpadding="2" cellspacing="1">' . $this->resultRowTitles($lrow, $conf, $table) . implode(LF, $rowArr) . '</table>';
512 }
513 $out .= '<HR>';
514 }
515 }
516 }
517 return $out;
518 }
519
520 /**
521 * [Describe function...]
522 *
523 * @param array $row
524 * @param array $conf
525 * @param string $table
526 * @return string
527 * @todo Define visibility
528 */
529 public function resultRowDisplay($row, $conf, $table) {
530 static $even = FALSE;
531 $tce = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\DataHandling\\DataHandler');
532 $SET = $GLOBALS['SOBE']->MOD_SETTINGS;
533 $out = '<tr class="bgColor' . ($even ? '6' : '4') . '">';
534 $even = !$even;
535 foreach ($row as $fN => $fV) {
536 if (GeneralUtility::inList($SET['queryFields'], $fN) || !$SET['queryFields'] && $fN != 'pid' && $fN != 'deleted') {
537 if ($SET['search_result_labels']) {
538 $fVnew = $this->getProcessedValueExtra($table, $fN, $fV, $conf, '<br />');
539 } else {
540 $fVnew = htmlspecialchars($fV);
541 }
542 $out .= '<td>' . $fVnew . '</td>';
543 }
544 }
545 $params = '&edit[' . $table . '][' . $row['uid'] . ']=edit';
546 $out .= '<td nowrap>';
547 if (!$row['deleted']) {
548 $out .= '<a href="#" onClick="top.launchView(\'' . $table . '\',' . $row['uid'] . ',\'' . $GLOBALS['BACK_PATH'] . '\');return false;">' . \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('status-dialog-information') . '</a>';
549 $out .= '<a href="#" onClick="' . BackendUtility::editOnClick($params, $GLOBALS['BACK_PATH'], (GeneralUtility::getIndpEnv('REQUEST_URI') . GeneralUtility::implodeArrayForUrl('SET', (array) GeneralUtility::_POST('SET')))) . '">' . \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('actions-document-open') . '</a>';
550 } else {
551 $out .= '<a href="' . GeneralUtility::linkThisUrl(($GLOBALS['BACK_PATH'] . 'tce_db.php'), array(
552 ('cmd[' . $table . '][' . $row['uid'] . '][undelete]') => '1',
553 'redirect' => GeneralUtility::linkThisScript(array())
554 )) . BackendUtility::getUrlToken('tceAction') . '">';
555 $out .= \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('actions-edit-restore', array('title' => 'undelete only')) . '</a>';
556 $out .= '<a href="' . GeneralUtility::linkThisUrl(($GLOBALS['BACK_PATH'] . 'tce_db.php'), array(
557 ('cmd[' . $table . '][' . $row['uid'] . '][undelete]') => '1',
558 'redirect' => GeneralUtility::linkThisUrl('alt_doc.php', array(
559 ('edit[' . $table . '][' . $row['uid'] . ']') => 'edit',
560 'returnUrl' => GeneralUtility::linkThisScript(array())
561 ))
562 )) . BackendUtility::getUrlToken('tceAction') . '">';
563 $out .= \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('actions-edit-restore-edit', array('title' => 'undelete and edit')) . '</a>';
564 }
565 $_params = array($table => $row);
566 if (is_array($this->hookArray['additionalButtons'])) {
567 foreach ($this->hookArray['additionalButtons'] as $_funcRef) {
568 $out .= GeneralUtility::callUserFunction($_funcRef, $_params, $this);
569 }
570 }
571 $out .= '</td>
572 </tr>
573 ';
574 return $out;
575 }
576
577 /**
578 * [Describe function...]
579 *
580 * @param string $table
581 * @param string $fN
582 * @param string $fV
583 * @param array $conf Not used
584 * @param string $splitString
585 * @return string
586 * @todo Define visibility
587 */
588 public function getProcessedValueExtra($table, $fN, $fV, $conf, $splitString) {
589 // Analysing the fields in the table.
590 if (is_array($GLOBALS['TCA'][$table])) {
591 $fC = $GLOBALS['TCA'][$table]['columns'][$fN];
592 $fields = $fC['config'];
593 $fields['exclude'] = $fC['exclude'];
594 if (is_array($fC) && $fC['label']) {
595 $fields['label'] = preg_replace('/:$/', '', trim($GLOBALS['LANG']->sL($fC['label'])));
596 switch ($fields['type']) {
597 case 'input':
598 if (preg_match('/int|year/i', $fields['eval'])) {
599 $fields['type'] = 'number';
600 } elseif (preg_match('/time/i', $fields['eval'])) {
601 $fields['type'] = 'time';
602 } elseif (preg_match('/date/i', $fields['eval'])) {
603 $fields['type'] = 'date';
604 } else {
605 $fields['type'] = 'text';
606 }
607 break;
608 case 'check':
609 if (!$fields['items']) {
610 $fields['type'] = 'boolean';
611 } else {
612 $fields['type'] = 'binary';
613 }
614 break;
615 case 'radio':
616 $fields['type'] = 'multiple';
617 break;
618 case 'select':
619 $fields['type'] = 'multiple';
620 if ($fields['foreign_table']) {
621 $fields['type'] = 'relation';
622 }
623 if ($fields['special']) {
624 $fields['type'] = 'text';
625 }
626 break;
627 case 'group':
628 $fields['type'] = 'files';
629 if ($fields['internal_type'] == 'db') {
630 $fields['type'] = 'relation';
631 }
632 break;
633 case 'user':
634
635 case 'flex':
636
637 case 'passthrough':
638
639 case 'none':
640
641 case 'text':
642
643 default:
644 $fields['type'] = 'text';
645 }
646 } else {
647 $fields['label'] = '[FIELD: ' . $fN . ']';
648 switch ($fN) {
649 case 'pid':
650 $fields['type'] = 'relation';
651 $fields['allowed'] = 'pages';
652 break;
653 case 'cruser_id':
654 $fields['type'] = 'relation';
655 $fields['allowed'] = 'be_users';
656 break;
657 case 'tstamp':
658
659 case 'crdate':
660 $fields['type'] = 'time';
661 break;
662 default:
663 $fields['type'] = 'number';
664 }
665 }
666 }
667 switch ($fields['type']) {
668 case 'date':
669 if ($fV != -1) {
670 $out = strftime('%e-%m-%Y', $fV);
671 }
672 break;
673 case 'time':
674 if ($fV != -1) {
675 if ($splitString == '<br />') {
676 $out = strftime('%H:%M' . $splitString . '%e-%m-%Y', $fV);
677 } else {
678 $out = strftime('%H:%M %e-%m-%Y', $fV);
679 }
680 }
681 break;
682 case 'multiple':
683
684 case 'binary':
685
686 case 'relation':
687 $out = $this->makeValueList($fN, $fV, $fields, $table, $splitString);
688 break;
689 case 'boolean':
690 $out = $fV ? 'True' : 'False';
691 break;
692 case 'files':
693
694 default:
695 $out = htmlspecialchars($fV);
696 }
697 return $out;
698 }
699
700 /**
701 * [Describe function...]
702 *
703 * @param integer $id
704 * @param integer $depth
705 * @param integer $begin
706 * @param string $perms_clause
707 * @return string
708 * @todo Define visibility
709 */
710 public function getTreeList($id, $depth, $begin = 0, $perms_clause) {
711 $depth = (int)$depth;
712 $begin = (int)$begin;
713 $id = (int)$id;
714 if ($id < 0) {
715 $id = abs($id);
716 }
717 if ($begin == 0) {
718 $theList = $id;
719 } else {
720 $theList = '';
721 }
722 if ($id && $depth > 0) {
723 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid', 'pages', 'pid=' . $id . ' ' . BackendUtility::deleteClause('pages') . ' AND ' . $perms_clause);
724 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
725 if ($begin <= 0) {
726 $theList .= ',' . $row['uid'];
727 }
728 if ($depth > 1) {
729 $theList .= $this->getTreeList($row['uid'], $depth - 1, $begin - 1, $perms_clause);
730 }
731 }
732 $GLOBALS['TYPO3_DB']->sql_free_result($res);
733 }
734 return $theList;
735 }
736
737 /**
738 * [Describe function...]
739 *
740 * @param string $fN
741 * @param string $fV
742 * @param array $conf
743 * @param string $table
744 * @param string $splitString
745 * @return string
746 * @todo Define visibility
747 */
748 public function makeValueList($fN, $fV, $conf, $table, $splitString) {
749 $fieldSetup = $conf;
750 $out = '';
751 if ($fieldSetup['type'] == 'files') {
752 $d = dir(PATH_site . $fieldSetup['uploadfolder']);
753 while (FALSE !== ($entry = $d->read())) {
754 if ($entry == '.' || $entry == '..') {
755 continue;
756 }
757 $fileArray[] = $entry;
758 }
759 $d->close();
760 natcasesort($fileArray);
761 while (list(, $fileName) = each($fileArray)) {
762 if (GeneralUtility::inList($fV, $fileName) || $fV == $fileName) {
763 if (!$out) {
764 $out = htmlspecialchars($fileName);
765 } else {
766 $out .= $splitString . htmlspecialchars($fileName);
767 }
768 }
769 }
770 }
771 if ($fieldSetup['type'] == 'multiple') {
772 foreach ($fieldSetup['items'] as $key => $val) {
773 if (substr($val[0], 0, 4) == 'LLL:') {
774 $value = $GLOBALS['LANG']->sL($val[0]);
775 } else {
776 $value = $val[0];
777 }
778 if (GeneralUtility::inList($fV, $val[1]) || $fV == $val[1]) {
779 if (!$out) {
780 $out = htmlspecialchars($value);
781 } else {
782 $out .= $splitString . htmlspecialchars($value);
783 }
784 }
785 }
786 }
787 if ($fieldSetup['type'] == 'binary') {
788 foreach ($fieldSetup['items'] as $Key => $val) {
789 if (substr($val[0], 0, 4) == 'LLL:') {
790 $value = $GLOBALS['LANG']->sL($val[0]);
791 } else {
792 $value = $val[0];
793 }
794 if (!$out) {
795 $out = htmlspecialchars($value);
796 } else {
797 $out .= $splitString . htmlspecialchars($value);
798 }
799 }
800 }
801 if ($fieldSetup['type'] == 'relation') {
802 if ($fieldSetup['items']) {
803 foreach ($fieldSetup['items'] as $key => $val) {
804 if (substr($val[0], 0, 4) == 'LLL:') {
805 $value = $GLOBALS['LANG']->sL($val[0]);
806 } else {
807 $value = $val[0];
808 }
809 if (GeneralUtility::inList($fV, $value) || $fV == $value) {
810 if (!$out) {
811 $out = htmlspecialchars($value);
812 } else {
813 $out .= $splitString . htmlspecialchars($value);
814 }
815 }
816 }
817 }
818 if (stristr($fieldSetup['allowed'], ',')) {
819 $from_table_Arr = explode(',', $fieldSetup['allowed']);
820 $useTablePrefix = 1;
821 if (!$fieldSetup['prepend_tname']) {
822 $checkres = $GLOBALS['TYPO3_DB']->exec_SELECTquery($fN, $table, 'uid ' . BackendUtility::deleteClause($table), ($groupBy = ''), ($orderBy = ''), ($limit = ''));
823 if ($checkres) {
824 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($checkres)) {
825 if (stristr($row[$fN], ',')) {
826 $checkContent = explode(',', $row[$fN]);
827 foreach ($checkContent as $singleValue) {
828 if (!stristr($singleValue, '_')) {
829 $dontPrefixFirstTable = 1;
830 }
831 }
832 } else {
833 $singleValue = $row[$fN];
834 if (strlen($singleValue) && !stristr($singleValue, '_')) {
835 $dontPrefixFirstTable = 1;
836 }
837 }
838 }
839 $GLOBALS['TYPO3_DB']->sql_free_result($checkres);
840 }
841 }
842 } else {
843 $from_table_Arr[0] = $fieldSetup['allowed'];
844 }
845 if ($fieldSetup['prepend_tname']) {
846 $useTablePrefix = 1;
847 }
848 if ($fieldSetup['foreign_table']) {
849 $from_table_Arr[0] = $fieldSetup['foreign_table'];
850 }
851 $counter = 0;
852 foreach ($from_table_Arr as $from_table) {
853 if ($useTablePrefix && !$dontPrefixFirstTable && $counter != 1 || $counter == 1) {
854 $tablePrefix = $from_table . '_';
855 }
856 $counter = 1;
857 if (is_array($GLOBALS['TCA'][$from_table])) {
858 $labelField = $GLOBALS['TCA'][$from_table]['ctrl']['label'];
859 $altLabelField = $GLOBALS['TCA'][$from_table]['ctrl']['label_alt'];
860 if ($GLOBALS['TCA'][$from_table]['columns'][$labelField]['config']['items']) {
861 foreach ($GLOBALS['TCA'][$from_table]['columns'][$labelField]['config']['items'] as $labelArray) {
862 if (substr($labelArray[0], 0, 4) == 'LLL:') {
863 $labelFieldSelect[$labelArray[1]] = $GLOBALS['LANG']->sL($labelArray[0]);
864 } else {
865 $labelFieldSelect[$labelArray[1]] = $labelArray[0];
866 }
867 }
868 $useSelectLabels = 1;
869 }
870 if ($GLOBALS['TCA'][$from_table]['columns'][$altLabelField]['config']['items']) {
871 foreach ($GLOBALS['TCA'][$from_table]['columns'][$altLabelField]['config']['items'] as $altLabelArray) {
872 if (substr($altLabelArray[0], 0, 4) == 'LLL:') {
873 $altLabelFieldSelect[$altLabelArray[1]] = $GLOBALS['LANG']->sL($altLabelArray[0]);
874 } else {
875 $altLabelFieldSelect[$altLabelArray[1]] = $altLabelArray[0];
876 }
877 }
878 $useAltSelectLabels = 1;
879 }
880 $altLabelFieldSelect = $altLabelField ? ',' . $altLabelField : '';
881 $select_fields = 'uid,' . $labelField . $altLabelFieldSelect;
882 if (!$GLOBALS['BE_USER']->isAdmin() && $GLOBALS['TYPO3_CONF_VARS']['BE']['lockBeUserToDBmounts']) {
883 $webMounts = $GLOBALS['BE_USER']->returnWebmounts();
884 $perms_clause = $GLOBALS['BE_USER']->getPagePermsClause(1);
885 $webMountPageTree = '';
886 foreach ($webMounts as $key => $val) {
887 if ($webMountPageTree) {
888 $webMountPageTreePrefix = ',';
889 }
890 $webMountPageTree .= $webMountPageTreePrefix . $this->getTreeList($val, 999, ($begin = 0), $perms_clause);
891 }
892 if ($from_table == 'pages') {
893 $where_clause = 'uid IN (' . $webMountPageTree . ') ' . BackendUtility::deleteClause($from_table) . ' AND ' . $perms_clause;
894 } else {
895 $where_clause = 'pid IN (' . $webMountPageTree . ') ' . BackendUtility::deleteClause($from_table);
896 }
897 } else {
898 $where_clause = 'uid' . BackendUtility::deleteClause($from_table);
899 }
900 $orderBy = 'uid';
901 if (!$this->tableArray[$from_table]) {
902 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($select_fields, $from_table, $where_clause, ($groupBy = ''), $orderBy, ($limit = ''));
903 $this->tableArray[$from_table] = array();
904 }
905 if ($res) {
906 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
907 $this->tableArray[$from_table][] = $row;
908 }
909 $GLOBALS['TYPO3_DB']->sql_free_result($res);
910 }
911 foreach ($this->tableArray[$from_table] as $key => $val) {
912 $GLOBALS['SOBE']->MOD_SETTINGS['labels_noprefix'] = $GLOBALS['SOBE']->MOD_SETTINGS['labels_noprefix'] == 1 ? 'on' : $GLOBALS['SOBE']->MOD_SETTINGS['labels_noprefix'];
913 $prefixString = $GLOBALS['SOBE']->MOD_SETTINGS['labels_noprefix'] == 'on' ? '' : ' [' . $tablePrefix . $val['uid'] . '] ';
914 if (GeneralUtility::inList($fV, $tablePrefix . $val['uid']) || $fV == $tablePrefix . $val['uid']) {
915 if ($useSelectLabels) {
916 if (!$out) {
917 $out = htmlspecialchars($prefixString . $labelFieldSelect[$val[$labelField]]);
918 } else {
919 $out .= $splitString . htmlspecialchars(($prefixString . $labelFieldSelect[$val[$labelField]]));
920 }
921 } elseif ($val[$labelField]) {
922 if (!$out) {
923 $out = htmlspecialchars($prefixString . $val[$labelField]);
924 } else {
925 $out .= $splitString . htmlspecialchars(($prefixString . $val[$labelField]));
926 }
927 } elseif ($useAltSelectLabels) {
928 if (!$out) {
929 $out = htmlspecialchars($prefixString . $altLabelFieldSelect[$val[$altLabelField]]);
930 } else {
931 $out .= $splitString . htmlspecialchars(($prefixString . $altLabelFieldSelect[$val[$altLabelField]]));
932 }
933 } else {
934 if (!$out) {
935 $out = htmlspecialchars($prefixString . $val[$altLabelField]);
936 } else {
937 $out .= $splitString . htmlspecialchars(($prefixString . $val[$altLabelField]));
938 }
939 }
940 }
941 }
942 }
943 }
944 }
945 return $out;
946 }
947
948 /**
949 * Render table header
950 *
951 * @param array $row Table columns
952 * @param array $conf Table TCA
953 * @param string $table Table name
954 * @return string HTML of table header
955 * @todo Define visibility
956 */
957 public function resultRowTitles($row, $conf, $table) {
958 $SET = $GLOBALS['SOBE']->MOD_SETTINGS;
959 $tableHeader = array();
960 // Start header row
961 $tableHeader[] = '<thead><tr class="bgColor5">';
962 // Iterate over given columns
963 foreach ($row as $fieldName => $fieldValue) {
964 if (GeneralUtility::inList($SET['queryFields'], $fieldName) || !$SET['queryFields'] && $fieldName != 'pid' && $fieldName != 'deleted') {
965 $THparams = strlen($fieldValue) < 50 ? ' style="white-space:nowrap;"' : '';
966 if ($GLOBALS['SOBE']->MOD_SETTINGS['search_result_labels']) {
967 $title = $GLOBALS['LANG']->sL($conf['columns'][$fieldName]['label'] ? $conf['columns'][$fieldName]['label'] : $fieldName, TRUE);
968 } else {
969 $title = $GLOBALS['LANG']->sL($fieldName, TRUE);
970 }
971 $tableHeader[] = '<th' . $THparams . '>' . $title . '</th>';
972 }
973 }
974 // Add empty icon column
975 $tableHeader[] = '<th style="white-space:nowrap;"></th>';
976 // Close header row
977 $tableHeader[] = '</tr></thead>';
978 return implode($tableHeader, LF);
979 }
980
981 /**
982 * [Describe function...]
983 *
984 * @param array $row
985 * @param array $conf
986 * @param mixed $table Not used
987 * @return string
988 * @todo Define visibility
989 */
990 public function csvRowTitles($row, $conf, $table) {
991 $out = '';
992 $SET = $GLOBALS['SOBE']->MOD_SETTINGS;
993 foreach ($row as $fN => $fV) {
994 if (GeneralUtility::inList($SET['queryFields'], $fN) || !$SET['queryFields'] && $fN != 'pid') {
995 if (!$out) {
996 if ($GLOBALS['SOBE']->MOD_SETTINGS['search_result_labels']) {
997 $out = $GLOBALS['LANG']->sL($conf['columns'][$fN]['label'] ? $conf['columns'][$fN]['label'] : $fN, TRUE);
998 } else {
999 $out = $GLOBALS['LANG']->sL($fN, TRUE);
1000 }
1001 } else {
1002 if ($GLOBALS['SOBE']->MOD_SETTINGS['search_result_labels']) {
1003 $out .= ',' . $GLOBALS['LANG']->sL(($conf['columns'][$fN]['label'] ? $conf['columns'][$fN]['label'] : $fN), TRUE);
1004 } else {
1005 $out .= ',' . $GLOBALS['LANG']->sL($fN, TRUE);
1006 }
1007 }
1008 }
1009 }
1010 return $out;
1011 }
1012
1013 /**
1014 * Sets the current name of the input form.
1015 *
1016 * @param string $formName The name of the form.
1017 * @return void
1018 */
1019 public function setFormName($formName) {
1020 $this->formName = trim($formName);
1021 }
1022
1023 }