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