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