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