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