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