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