2 /***************************************************************
5 * (c) 1999-2011 Kasper Skårhøj (kasperYYYY@typo3.com)
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.
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.
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.
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
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.
31 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
32 * @coauthor Jo Hasenau <info@cybercraft.de>
35 * [CLASS/FUNCTION INDEX of SCRIPT]
39 * 88: class t3lib_fullsearch
40 * 103: function form()
41 * 117: function makeStoreControl()
42 * 156: function initStoreArray()
43 * 176: function cleanStoreQueryConfigs($storeQueryConfigs,$storeArray)
44 * 193: function addToStoreQueryConfigs($storeQueryConfigs,$index)
45 * 209: function saveQueryInAction($uid)
46 * 256: function loadStoreQueryConfigs($storeQueryConfigs,$storeIndex,$writeArray)
47 * 272: function procesStoreControl()
48 * 344: function queryMaker()
49 * 414: function getQueryResultCode($mQ,$res,$table)
50 * 534: function csvValues($row, $delim=',', $quote='"', $conf=array(), $table='')
51 * 550: function tableWrap($str)
52 * 559: function search()
53 * 614: function resultRowDisplay($row,$conf,$table)
54 * 662: function getProcessedValueExtra($table, $fN, $fV, $conf, $splitString)
55 * 781: function getTreeList($id, $depth, $begin = 0, $perms_clause)
56 * 818: function makeValueList($fN, $fV, $conf, $table, $splitString)
57 * 1028: function resultRowTitles($row,$conf,$table)
58 * 1058: function csvRowTitles($row, $conf, $table)
61 * (This index is automatically created/updated by the extension "extdeveval")
67 * Class used in module tools/dbint (advanced search) and which may hold code specific for that module
68 * However the class has a general principle in it which may be used in the web/export module.
70 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
74 class t3lib_fullsearch
{
75 var $storeList = 'search_query_smallparts,search_result_labels,labels_noprefix,show_deleted,queryConfig,queryTable,queryFields,queryLimit,queryOrder,queryOrderDesc,queryOrder2,queryOrder2Desc,queryGroup,search_query_makeQuery';
76 var $downloadScript = 'index.php';
80 protected $formName = '';
85 public function __construct() {
86 $GLOBALS['LANG']->includeLLFile('EXT:lang/locallang_t3lib_fullsearch.xml');
91 * [Describe function...]
98 <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">
105 * [Describe function...]
109 function makeStoreControl() {
111 $storeArray = $this->initStoreArray();
116 foreach ($storeArray as $k => $v) {
117 $opt[] = '<option value="' . $k . '"' . (!strcmp($cur, $v) ?
' selected' : '') . '>' . htmlspecialchars($v) . '</option>';
121 if (t3lib_extMgm
::isLoaded('sys_action') && $GLOBALS['BE_USER']->isAdmin()) {
122 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'sys_action', 'type=2', '', 'title');
123 if ($GLOBALS['TYPO3_DB']->sql_num_rows($res)) {
124 $opt[] = '<option value="0">__Save to Action:__</option>';
125 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
126 $opt[] = '<option value="-' . $row['uid'] . '"' . (!strcmp($cur, '-' . $row['uid']) ?
' selected' : '') . '>' . htmlspecialchars($row['title'] . ' [' . $row['uid'] . ']') . '</option>';
129 $GLOBALS['TYPO3_DB']->sql_free_result($res);
132 $TDparams = ' nowrap="nowrap" class="bgColor4"';
134 <table border="0" cellpadding="3" cellspacing="1">
135 <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>
136 <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>
143 * [Describe function...]
147 function initStoreArray() {
152 $savedStoreArray = unserialize($GLOBALS['SOBE']->MOD_SETTINGS
['storeArray']);
154 if (is_array($savedStoreArray)) {
155 $storeArray = array_merge($storeArray, $savedStoreArray);
161 * [Describe function...]
163 * @param [type] $storeQueryConfigs: ...
164 * @param [type] $storeArray: ...
167 function cleanStoreQueryConfigs($storeQueryConfigs, $storeArray) {
168 if (is_array($storeQueryConfigs)) {
169 foreach ($storeQueryConfigs as $k => $v) {
170 if (!isset($storeArray[$k])) {
171 unset($storeQueryConfigs[$k]);
175 return $storeQueryConfigs;
179 * [Describe function...]
181 * @param [type] $storeQueryConfigs: ...
182 * @param [type] $index: ...
185 function addToStoreQueryConfigs($storeQueryConfigs, $index) {
186 $keyArr = explode(',', $this->storeList
);
187 $storeQueryConfigs[$index] = array();
188 foreach ($keyArr as $k) {
189 $storeQueryConfigs[$index][$k] = $GLOBALS['SOBE']->MOD_SETTINGS
[$k];
191 return $storeQueryConfigs;
195 * [Describe function...]
197 * @param [type] $uid: ...
200 function saveQueryInAction($uid) {
201 if (t3lib_extMgm
::isLoaded('sys_action')) {
202 $keyArr = explode(',', $this->storeList
);
204 foreach ($keyArr as $k) {
205 $saveArr[$k] = $GLOBALS['SOBE']->MOD_SETTINGS
[$k];
210 if ($saveArr['queryTable']) {
211 /* @var t3lib_queryGenerator */
212 $qGen = t3lib_div
::makeInstance('t3lib_queryGenerator');
213 $qGen->init('queryConfig', $saveArr['queryTable']);
214 $qGen->makeSelectorTable($saveArr);
216 $qGen->enablePrefix
= 1;
217 $qString = $qGen->getQuery($qGen->queryConfig
);
218 $qCount = $GLOBALS['TYPO3_DB']->SELECTquery('count(*)', $qGen->table
, $qString . t3lib_BEfunc
::deleteClause($qGen->table
));
219 $qSelect = $qGen->getSelectQuery($qString);
221 $res = @$GLOBALS['TYPO3_DB']->sql_query($qCount);
222 if (!$GLOBALS['TYPO3_DB']->sql_error()) {
223 $GLOBALS['TYPO3_DB']->sql_free_result($res);
225 $dA['t2_data'] = serialize(array(
228 'qSelect' => $qSelect,
229 'qString' => $qString
231 $GLOBALS['TYPO3_DB']->exec_UPDATEquery('sys_action', 'uid=' . intval($uid), $dA);
241 * [Describe function...]
243 * @param [type] $storeQueryConfigs: ...
244 * @param [type] $storeIndex: ...
245 * @param [type] $writeArray: ...
248 function loadStoreQueryConfigs($storeQueryConfigs, $storeIndex, $writeArray) {
249 if ($storeQueryConfigs[$storeIndex]) {
250 $keyArr = explode(',', $this->storeList
);
251 foreach ($keyArr as $k) {
252 $writeArray[$k] = $storeQueryConfigs[$storeIndex][$k];
259 * [Describe function...]
263 function procesStoreControl() {
264 $storeArray = $this->initStoreArray();
265 $storeQueryConfigs = unserialize($GLOBALS['SOBE']->MOD_SETTINGS
['storeQueryConfigs']);
267 $storeControl = t3lib_div
::_GP('storeControl');
268 $storeIndex = intval($storeControl['STORE']);
270 $writeArray = array();
271 if (is_array($storeControl)) {
273 if ($storeControl['LOAD']) {
274 if ($storeIndex > 0) {
275 $writeArray = $this->loadStoreQueryConfigs($storeQueryConfigs, $storeIndex, $writeArray);
277 $flashMessage = t3lib_div
::makeInstance(
278 't3lib_FlashMessage',
279 sprintf($GLOBALS['LANG']->getLL('query_loaded'), htmlspecialchars($storeArray[$storeIndex]))
281 } elseif ($storeIndex < 0 && t3lib_extMgm
::isLoaded('sys_action')) {
282 $actionRecord = t3lib_BEfunc
::getRecord('sys_action', abs($storeIndex));
283 if (is_array($actionRecord)) {
284 $dA = unserialize($actionRecord['t2_data']);
286 if (is_array($dA['qC'])) {
287 $dbSC[0] = $dA['qC'];
289 $writeArray = $this->loadStoreQueryConfigs($dbSC, '0', $writeArray);
292 $flashMessage = t3lib_div
::makeInstance(
293 't3lib_FlashMessage',
294 sprintf($GLOBALS['LANG']->getLL('query_from_action_loaded'), htmlspecialchars($actionRecord['title']))
298 } elseif ($storeControl['SAVE']) {
299 if ($storeIndex < 0) {
300 $qOK = $this->saveQueryInAction(abs($storeIndex));
302 $flashMessage = t3lib_div
::makeInstance(
303 't3lib_FlashMessage',
304 $GLOBALS['LANG']->getLL('query_saved')
307 $flashMessage = t3lib_div
::makeInstance(
308 't3lib_FlashMessage',
309 $GLOBALS['LANG']->getLL('query_notsaved'),
311 t3lib_FlashMessage
::ERROR
315 if (trim($storeControl['title'])) {
316 if ($storeIndex > 0) {
317 $storeArray[$storeIndex] = $storeControl['title'];
319 $storeArray[] = $storeControl['title'];
321 $storeIndex = key($storeArray);
323 $storeQueryConfigs = $this->addToStoreQueryConfigs($storeQueryConfigs, $storeIndex);
325 $flashMessage = t3lib_div
::makeInstance(
326 't3lib_FlashMessage',
327 $GLOBALS['LANG']->getLL('query_saved')
331 } elseif ($storeControl['REMOVE']) {
332 if ($storeIndex > 0) {
333 $flashMessage = t3lib_div
::makeInstance(
334 't3lib_FlashMessage',
335 sprintf($GLOBALS['LANG']->getLL('query_removed'), htmlspecialchars($storeArray[$storeControl['STORE']]))
337 unset($storeArray[$storeControl['STORE']]); // Removing
342 $msg = $flashMessage->render();
345 if ($saveStoreArray) {
346 unset($storeArray[0]); // making sure, index 0 is not set!
347 $writeArray['storeArray'] = serialize($storeArray);
348 $writeArray['storeQueryConfigs'] = serialize($this->cleanStoreQueryConfigs($storeQueryConfigs, $storeArray));
349 $GLOBALS['SOBE']->MOD_SETTINGS
= t3lib_BEfunc
::getModuleData($GLOBALS['SOBE']->MOD_MENU
, $writeArray, $GLOBALS['SOBE']->MCONF
['name'], 'ses');
355 * [Describe function...]
359 function queryMaker() {
363 if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['t3lib_fullsearch'])) {
364 $this->hookArray
= $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['t3lib_fullsearch'];
366 $msg = $this->procesStoreControl();
368 if (!$GLOBALS['BE_USER']->userTS
['mod.']['dbint.']['disableStoreControl']) {
369 $output .= $GLOBALS['SOBE']->doc
->section('Load/Save Query', $this->makeStoreControl(), 0, 1);
371 $output .= '<br />' . $msg;
373 $output .= $GLOBALS['SOBE']->doc
->spacer(20);
378 $qGen = t3lib_div
::makeInstance('t3lib_queryGenerator');
379 $qGen->init('queryConfig', $GLOBALS['SOBE']->MOD_SETTINGS
['queryTable']);
380 if ($this->formName
) {
381 $qGen->setFormName($this->formName
);
383 $tmpCode = $qGen->makeSelectorTable($GLOBALS['SOBE']->MOD_SETTINGS
);
384 $output .= $GLOBALS['SOBE']->doc
->section('Make query', $tmpCode, 0, 1);
386 $mQ = $GLOBALS['SOBE']->MOD_SETTINGS
['search_query_makeQuery'];
388 // Make form elements:
389 if ($qGen->table
&& is_array($TCA[$qGen->table
])) {
392 $qGen->enablePrefix
= 1;
393 $qString = $qGen->getQuery($qGen->queryConfig
);
394 // debug($qGen->queryConfig);
398 $qExplain = $GLOBALS['TYPO3_DB']->SELECTquery('count(*)', $qGen->table
, $qString . t3lib_BEfunc
::deleteClause($qGen->table
));
401 $qExplain = $qGen->getSelectQuery($qString);
402 if ($mQ == 'explain') {
403 $qExplain = 'EXPLAIN ' . $qExplain;
408 if (!$GLOBALS['BE_USER']->userTS
['mod.']['dbint.']['disableShowSQLQuery']) {
409 $output .= $GLOBALS['SOBE']->doc
->section('SQL query', $this->tableWrap(htmlspecialchars($qExplain)), 0, 1);
412 $res = @$GLOBALS['TYPO3_DB']->sql_query($qExplain);
413 if ($GLOBALS['TYPO3_DB']->sql_error()) {
414 $out = '<BR><strong>Error:</strong><BR><font color="red"><strong>' . $GLOBALS['TYPO3_DB']->sql_error() . '</strong></font>';
415 $output .= $GLOBALS['SOBE']->doc
->section('SQL error', $out, 0, 1);
417 $cPR = $this->getQueryResultCode($mQ, $res, $qGen->table
);
418 $GLOBALS['TYPO3_DB']->sql_free_result($res);
419 $output .= $GLOBALS['SOBE']->doc
->section($cPR['header'], $cPR['content'], 0, 1);
427 * [Describe function...]
429 * @param [type] $mQ: ...
430 * @param [type] $res: ...
431 * @param [type] $table: ...
434 function getQueryResultCode($mQ, $res, $table) {
440 $row = $GLOBALS['TYPO3_DB']->sql_fetch_row($res);
441 $cPR['header'] = 'Count';
442 $cPR['content'] = '<BR><strong>' . $row[0] . '</strong> records selected.';
446 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
447 $rowArr[] = $this->resultRowDisplay($row, $TCA[$table], $table);
450 if (is_array($this->hookArray
['beforeResultTable'])) {
451 foreach ($this->hookArray
['beforeResultTable'] as $_funcRef) {
452 $out .= t3lib_div
::callUserFunction($_funcRef, $GLOBALS['SOBE']->MOD_SETTINGS
, $this);
455 if (count($rowArr)) {
456 $out .= '<table border="0" cellpadding="2" cellspacing="1" width="100%">' . $this->resultRowTitles($lrow, $TCA[$table], $table) . implode(LF
, $rowArr) . '</table>';
459 $out = '<em>No rows selected!</em>';
461 $cPR['header'] = 'Result';
462 $cPR['content'] = $out;
467 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
469 $rowArr[] = $this->csvValues(array_keys($row), ',', '');
472 $rowArr[] = $this->csvValues($row, ',', '"', $TCA[$table], $table);
474 if (count($rowArr)) {
475 $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>';
476 if (!$this->noDownloadB
) {
477 $out .= '<BR><input type="submit" name="download_file" value="Click to download file" onClick="window.location.href=\'' . $this->downloadScript
. '\';">'; // document.forms[0].target=\'_blank\';
480 if (t3lib_div
::_GP('download_file')) {
481 $filename = 'TYPO3_' . $table . '_export_' . date('dmy-Hi') . '.csv';
482 $mimeType = 'application/octet-stream';
483 header('Content-Type: ' . $mimeType);
484 header('Content-Disposition: attachment; filename=' . $filename);
485 echo implode(CRLF
, $rowArr);
490 $out = '<em>No rows selected!</em>';
492 $cPR['header'] = 'Result';
493 $cPR['content'] = $out;
496 $xmlObj = t3lib_div
::makeInstance('t3lib_xml', 'typo3_export');
497 $xmlObj->includeNonEmptyValues
= 1;
498 $xmlObj->renderHeader();
500 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
502 $xmlObj->setRecFields($table, implode(',', array_keys($row)));
506 if ($GLOBALS['SOBE']->MOD_SETTINGS
['search_result_labels']) {
507 foreach ($valueArray as $key => $val) {
508 $valueArray[$key] = $this->getProcessedValueExtra($table, $key, $val, array(), ',');
511 $xmlObj->addRecord($table, $valueArray);
513 $xmlObj->renderFooter();
514 if ($GLOBALS['TYPO3_DB']->sql_num_rows($res)) {
515 $xmlData = $xmlObj->getResult();
516 $out .= '<textarea name="whatever" rows="20" wrap="off"' . $GLOBALS['SOBE']->doc
->formWidthText($this->formW
, '', 'off') . ' class="fixed-font">' . t3lib_div
::formatForTextarea($xmlData) . '</textarea>';
517 if (!$this->noDownloadB
) {
518 $out .= '<BR><input type="submit" name="download_file" value="Click to download file" onClick="window.location.href=\'' . $this->downloadScript
. '\';">'; // document.forms[0].target=\'_blank\';
521 if (t3lib_div
::_GP('download_file')) {
522 $filename = 'TYPO3_' . $table . '_export_' . date('dmy-Hi') . '.xml';
523 $mimeType = 'application/octet-stream';
524 header('Content-Type: ' . $mimeType);
525 header('Content-Disposition: attachment; filename=' . $filename);
531 $out = '<em>No rows selected!</em>';
533 $cPR['header'] = 'Result';
534 $cPR['content'] = $out;
538 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
539 $out .= '<br />' . t3lib_utility_Debug
::viewArray($row);
541 $cPR['header'] = 'Explain SQL query';
542 $cPR['content'] = $out;
549 * [Describe function...]
551 * @param [type] $row: ...
552 * @param [type] $delim: ...
553 * @param [type] $quote: ...
554 * @param [type] $conf: ...
555 * @param [type] $table: ...
558 function csvValues($row, $delim = ',', $quote = '"', $conf = array(), $table = '') {
560 if ($GLOBALS['SOBE']->MOD_SETTINGS
['search_result_labels'] && $table) {
561 foreach ($valueArray as $key => $val) {
562 $valueArray[$key] = $this->getProcessedValueExtra($table, $key, $val, $conf, ';');
565 return t3lib_div
::csvValues($valueArray, $delim, $quote);
569 * [Describe function...]
571 * @param [type] $str: ...
574 function tableWrap($str) {
575 return '<table border="0" cellpadding="10" cellspacing="0" class="bgColor4"><tr><td nowrap><pre>' . $str . '</pre></td></tr></table>';
579 * [Describe function...]
585 $SET = $GLOBALS['SOBE']->MOD_SETTINGS
;
586 $swords = $SET['sword'];
592 foreach ($TCA as $table => $value) {
594 t3lib_div
::loadTCA($table);
595 $conf = $TCA[$table];
597 // avoid querying tables with no columns
598 if (empty($conf['columns'])) {
602 $list = array_keys($conf['columns']);
604 $qp = $GLOBALS['TYPO3_DB']->searchQuery(array($swords), $list, $table);
607 $count = $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('*', $table, $qp . t3lib_BEfunc
::deleteClause($table));
608 if ($count ||
$showAlways) {
610 $out .= '<strong>TABLE:</strong> ' . $GLOBALS['LANG']->sL($conf['ctrl']['title']) . '<BR>';
611 $out .= '<strong>Results:</strong> ' . $count . '<BR>';
616 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid,' . $conf['ctrl']['label'], $table, $qp . t3lib_BEfunc
::deleteClause($table), '', '', $limit);
617 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
618 $rowArr[] = $this->resultRowDisplay($row, $conf, $table);
621 $GLOBALS['TYPO3_DB']->sql_free_result($res);
622 $out .= '<table border="0" cellpadding="2" cellspacing="1">' . $this->resultRowTitles($lrow, $conf, $table) . implode(LF
, $rowArr) . '</table>';
632 * [Describe function...]
634 * @param [type] $row: ...
635 * @param [type] $conf: ...
636 * @param [type] $table: ...
639 function resultRowDisplay($row, $conf, $table) {
640 static $even = FALSE;
641 $tce = t3lib_div
::makeInstance('t3lib_TCEmain');
642 $SET = $GLOBALS['SOBE']->MOD_SETTINGS
;
643 $out = '<tr class="bgColor' . ($even ?
'6' : '4') . '">';
645 foreach ($row as $fN => $fV) {
646 if (t3lib_div
::inList($SET['queryFields'], $fN) ||
(!$SET['queryFields'] && $fN != 'pid' && $fN != 'deleted')) {
647 if ($SET['search_result_labels']) {
648 $fVnew = $this->getProcessedValueExtra($table, $fN, $fV, $conf, '<br />');
650 $fVnew = htmlspecialchars($fV);
652 $out .= '<td>' . $fVnew . '</td>';
655 $params = '&edit[' . $table . '][' . $row['uid'] . ']=edit';
656 $out .= '<td nowrap>';
657 if (!$row['deleted']) {
658 $out .= '<a href="#" onClick="top.launchView(\'' . $table . '\',' . $row['uid'] . ',\'' . $GLOBALS['BACK_PATH'] . '\');return false;">' . t3lib_iconWorks
::getSpriteIcon('status-dialog-information') . '</a>';
659 $out .= '<a href="#" onClick="' . t3lib_BEfunc
::editOnClick($params, $GLOBALS['BACK_PATH'], t3lib_div
::getIndpEnv('REQUEST_URI') . t3lib_div
::implodeArrayForUrl('SET', (array) t3lib_div
::_POST('SET'))) . '">' . t3lib_iconWorks
::getSpriteIcon('actions-document-open') . '</a>';
661 $out .= '<a href="' . t3lib_div
::linkThisUrl($GLOBALS['BACK_PATH'] . 'tce_db.php',
663 'cmd[' . $table . '][' . $row['uid'] . '][undelete]' => '1',
664 'redirect' => t3lib_div
::linkThisScript(array()))) . t3lib_BEfunc
::getUrlToken('tceAction') . '">';
665 $out .= t3lib_iconWorks
::getSpriteIcon('actions-edit-restore', array('title' => 'undelete only')) . '</a>';
666 $out .= '<a href="' . t3lib_div
::linkThisUrl($GLOBALS['BACK_PATH'] . 'tce_db.php',
668 'cmd[' . $table . '][' . $row['uid'] . '][undelete]' => '1',
669 'redirect' => t3lib_div
::linkThisUrl('alt_doc.php',
671 'edit[' . $table . '][' . $row['uid'] . ']' => 'edit',
672 'returnUrl' => t3lib_div
::linkThisScript(array())
676 ) . t3lib_BEfunc
::getUrlToken('tceAction') . '">';
677 $out .= t3lib_iconWorks
::getSpriteIcon('actions-edit-restore-edit', array('title' => 'undelete and edit')) . '</a>';
679 $_params = array($table => $row);
680 if (is_array($this->hookArray
['additionalButtons'])) {
681 foreach ($this->hookArray
['additionalButtons'] as $_funcRef) {
682 $out .= t3lib_div
::callUserFunction($_funcRef, $_params, $this);
692 * [Describe function...]
694 * @param [type] $table: ...
695 * @param [type] $fN: ...
696 * @param [type] $fV: ...
697 * @param [type] $conf: ...
698 * @param [type] $splitString: ...
701 function getProcessedValueExtra($table, $fN, $fV, $conf, $splitString) {
703 // Analysing the fields in the table.
704 if (is_array($TCA[$table])) {
705 t3lib_div
::loadTCA($table);
706 $fC = $TCA[$table]['columns'][$fN];
707 $fields = $fC['config'];
708 $fields['exclude'] = $fC['exclude'];
709 if (is_array($fC) && $fC['label']) {
710 $fields['label'] = preg_replace('/:$/', '', trim($GLOBALS['LANG']->sL($fC['label'])));
712 switch ($fields['type']) {
714 if (preg_match('/int|year/i', $fields['eval'])) {
715 $fields['type'] = 'number';
716 } elseif (preg_match('/time/i', $fields['eval'])) {
717 $fields['type'] = 'time';
718 } elseif (preg_match('/date/i', $fields['eval'])) {
719 $fields['type'] = 'date';
721 $fields['type'] = 'text';
725 if (!$fields['items']) {
726 $fields['type'] = 'boolean';
728 $fields['type'] = 'binary';
732 $fields['type'] = 'multiple';
735 $fields['type'] = 'multiple';
736 if ($fields['foreign_table']) {
737 $fields['type'] = 'relation';
739 if ($fields['special']) {
740 $fields['type'] = 'text';
744 $fields['type'] = 'files';
745 if ($fields['internal_type'] == 'db') {
746 $fields['type'] = 'relation';
755 $fields['type'] = 'text';
759 $fields['label'] = '[FIELD: ' . $fN . ']';
762 $fields['type'] = 'relation';
763 $fields['allowed'] = 'pages';
766 $fields['type'] = 'relation';
767 $fields['allowed'] = 'be_users';
771 $fields['type'] = 'time';
774 $fields['type'] = 'number';
780 switch ($fields['type']) {
783 $out = strftime('%e-%m-%Y', $fV);
788 if ($splitString == '<br />') {
789 $out = strftime('%H:%M' . $splitString . '%e-%m-%Y', $fV);
791 $out = strftime('%H:%M %e-%m-%Y', $fV);
798 $out = $this->makeValueList($fN, $fV, $fields, $table, $splitString);
801 $out = $fV ?
'True' : 'False';
805 $out = htmlspecialchars($fV);
812 * [Describe function...]
814 * @param [type] $qString: ...
815 * @param [type] $depth: ...
816 * @param [type] $begin: ...
817 * @param [type] $perms_clause: ...
820 function getTreeList($id, $depth, $begin = 0, $perms_clause) {
821 $depth = intval($depth);
822 $begin = intval($begin);
829 if ($id && $depth > 0) {
830 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
833 'pid=' . $id . ' ' . t3lib_BEfunc
::deleteClause('pages') . ' AND ' . $perms_clause
835 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
837 $theList .= ',' . $row['uid'];
840 $theList .= $this->getTreeList($row['uid'], $depth - 1, $begin - 1, $perms_clause);
843 $GLOBALS['TYPO3_DB']->sql_free_result($res);
849 * [Describe function...]
851 * @param [type] $fN: ...
852 * @param [type] $fV: ...
853 * @param [type] $conf: ...
854 * @param [type] $table: ...
855 * @param [type] $splitString: ...
858 function makeValueList($fN, $fV, $conf, $table, $splitString) {
861 if ($fieldSetup['type'] == 'files') {
862 $d = dir(PATH_site
. $fieldSetup['uploadfolder']);
863 while (FALSE !== ($entry = $d->read())) {
864 if ($entry == '.' ||
$entry == '..') {
867 $fileArray[] = $entry;
870 natcasesort($fileArray);
871 while (list(, $fileName) = each($fileArray)) {
872 if (t3lib_div
::inList($fV, $fileName) ||
$fV == $fileName) {
874 $out = htmlspecialchars($fileName);
876 $out .= $splitString . htmlspecialchars($fileName);
881 if ($fieldSetup['type'] == 'multiple') {
882 foreach ($fieldSetup['items'] as $key => $val) {
883 if (substr($val[0], 0, 4) == 'LLL:') {
884 $value = $GLOBALS['LANG']->sL($val[0]);
888 if (t3lib_div
::inList($fV, $val[1]) ||
$fV == $val[1]) {
890 $out = htmlspecialchars($value);
892 $out .= $splitString . htmlspecialchars($value);
897 if ($fieldSetup['type'] == 'binary') {
898 foreach ($fieldSetup['items'] as $Key => $val) {
899 if (substr($val[0], 0, 4) == 'LLL:') {
900 $value = $GLOBALS['LANG']->sL($val[0]);
905 $out = htmlspecialchars($value);
907 $out .= $splitString . htmlspecialchars($value);
911 if ($fieldSetup['type'] == 'relation') {
912 if ($fieldSetup['items']) {
913 foreach ($fieldSetup['items'] as $key => $val) {
914 if (substr($val[0], 0, 4) == 'LLL:') {
915 $value = $GLOBALS['LANG']->sL($val[0]);
919 if (t3lib_div
::inList($fV, $value) ||
$fV == $value) {
921 $out = htmlspecialchars($value);
923 $out .= $splitString . htmlspecialchars($value);
929 if (stristr($fieldSetup['allowed'], ',')) {
930 $from_table_Arr = explode(',', $fieldSetup['allowed']);
932 if (!$fieldSetup['prepend_tname']) {
933 $checkres = $GLOBALS['TYPO3_DB']->exec_SELECTquery($fN, $table, 'uid ' . t3lib_BEfunc
::deleteClause($table), $groupBy = '', $orderBy = '', $limit = '');
935 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($checkres)) {
936 if (stristr($row[$fN], ',')) {
937 $checkContent = explode(',', $row[$fN]);
938 foreach ($checkContent as $singleValue) {
939 if (!stristr($singleValue, '_')) {
940 $dontPrefixFirstTable = 1;
944 $singleValue = $row[$fN];
945 if (strlen($singleValue) && !stristr($singleValue, '_')) {
946 $dontPrefixFirstTable = 1;
950 $GLOBALS['TYPO3_DB']->sql_free_result($checkres);
954 $from_table_Arr[0] = $fieldSetup['allowed'];
956 if ($fieldSetup['prepend_tname']) {
959 if ($fieldSetup['foreign_table']) {
960 $from_table_Arr[0] = $fieldSetup['foreign_table'];
963 foreach ($from_table_Arr as $from_table) {
964 if (($useTablePrefix && !$dontPrefixFirstTable && $counter != 1) ||
$counter == 1) {
965 $tablePrefix = $from_table . '_';
968 if (is_array($TCA[$from_table])) {
969 t3lib_div
::loadTCA($from_table);
970 $labelField = $TCA[$from_table]['ctrl']['label'];
971 $altLabelField = $TCA[$from_table]['ctrl']['label_alt'];
972 if ($TCA[$from_table]['columns'][$labelField]['config']['items']) {
973 reset($TCA[$from_table]['columns'][$labelField]['config']['items']);
974 while (list(, $labelArray) = each($TCA[$from_table]['columns'][$labelField]['config']['items'])) {
975 if (substr($labelArray[0], 0, 4) == 'LLL:') {
976 $labelFieldSelect[$labelArray[1]] = $GLOBALS['LANG']->sL($labelArray[0]);
978 $labelFieldSelect[$labelArray[1]] = $labelArray[0];
981 $useSelectLabels = 1;
983 if ($TCA[$from_table]['columns'][$altLabelField]['config']['items']) {
984 reset($TCA[$from_table]['columns'][$altLabelField]['config']['items']);
985 foreach ($TCA[$from_table]['columns'][$altLabelField]['config']['items'] as $altLabelArray) {
986 if (substr($altLabelArray[0], 0, 4) == 'LLL:') {
987 $altLabelFieldSelect[$altLabelArray[1]] = $GLOBALS['LANG']->sL($altLabelArray[0]);
989 $altLabelFieldSelect[$altLabelArray[1]] = $altLabelArray[0];
992 $useAltSelectLabels = 1;
994 $altLabelFieldSelect = $altLabelField ?
',' . $altLabelField : '';
995 $select_fields = 'uid,' . $labelField . $altLabelFieldSelect;
996 if (!$GLOBALS['BE_USER']->isAdmin() && $GLOBALS['TYPO3_CONF_VARS']['BE']['lockBeUserToDBmounts']) {
997 $webMounts = $GLOBALS['BE_USER']->returnWebmounts();
998 $perms_clause = $GLOBALS['BE_USER']->getPagePermsClause(1);
999 $webMountPageTree = '';
1000 foreach ($webMounts as $key => $val) {
1001 if ($webMountPageTree) {
1002 $webMountPageTreePrefix = ',';
1004 $webMountPageTree .= $webMountPageTreePrefix . $this->getTreeList($val, 999, $begin = 0, $perms_clause);
1006 if ($from_table == 'pages') {
1007 $where_clause = 'uid IN (' . $webMountPageTree . ') ' . t3lib_BEfunc
::deleteClause($from_table) . ' AND ' . $perms_clause;
1009 $where_clause = 'pid IN (' . $webMountPageTree . ') ' . t3lib_BEfunc
::deleteClause($from_table);
1012 $where_clause = 'uid' . t3lib_BEfunc
::deleteClause($from_table);
1015 if (!$this->tableArray
[$from_table]) {
1016 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($select_fields, $from_table, $where_clause, $groupBy = '', $orderBy, $limit = '');
1017 $this->tableArray
[$from_table] = array();
1020 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
1021 $this->tableArray
[$from_table][] = $row;
1023 $GLOBALS['TYPO3_DB']->sql_free_result($res);
1025 reset($this->tableArray
[$from_table]);
1026 foreach ($this->tableArray
[$from_table] as $key => $val) {
1027 $GLOBALS['SOBE']->MOD_SETTINGS
['labels_noprefix'] = $GLOBALS['SOBE']->MOD_SETTINGS
['labels_noprefix'] == 1 ?
'on' :
1028 $GLOBALS['SOBE']->MOD_SETTINGS
['labels_noprefix'];
1029 $prefixString = $GLOBALS['SOBE']->MOD_SETTINGS
['labels_noprefix'] == 'on' ?
'' : ' [' . $tablePrefix . $val['uid'] . '] ';
1030 if (t3lib_div
::inList($fV, $tablePrefix . $val['uid']) ||
$fV == $tablePrefix . $val['uid']) {
1031 if ($useSelectLabels) {
1033 $out = htmlspecialchars($prefixString . $labelFieldSelect[$val[$labelField]]);
1035 $out .= $splitString . htmlspecialchars($prefixString . $labelFieldSelect[$val[$labelField]]);
1037 } elseif ($val[$labelField]) {
1039 $out = htmlspecialchars($prefixString . $val[$labelField]);
1041 $out .= $splitString . htmlspecialchars($prefixString . $val[$labelField]);
1043 } elseif ($useAltSelectLabels) {
1045 $out = htmlspecialchars($prefixString . $altLabelFieldSelect[$val[$altLabelField]]);
1047 $out .= $splitString . htmlspecialchars($prefixString . $altLabelFieldSelect[$val[$altLabelField]]);
1051 $out = htmlspecialchars($prefixString . $val[$altLabelField]);
1053 $out .= $splitString . htmlspecialchars($prefixString . $val[$altLabelField]);
1065 * Render table header
1067 * @param array row: Table columns
1068 * @param array conf: Table TCA
1069 * @param string table: Table name
1070 * @return string HTML of table header
1072 function resultRowTitles($row, $conf, $table) {
1073 $SET = $GLOBALS['SOBE']->MOD_SETTINGS
;
1075 $tableHeader = array();
1078 $tableHeader[] = '<thead><tr class="bgColor5">';
1080 // Iterate over given columns
1081 foreach ($row as $fieldName => $fieldValue) {
1082 if (t3lib_div
::inList($SET['queryFields'], $fieldName) ||
(!$SET['queryFields'] && $fieldName != 'pid' && $fieldName != 'deleted')) {
1083 $THparams = (strlen($fieldValue) < 50) ?
' style="white-space:nowrap;"' : '';
1085 if ($GLOBALS['SOBE']->MOD_SETTINGS
['search_result_labels']) {
1086 $title = $GLOBALS['LANG']->sL($conf['columns'][$fieldName]['label'] ?
$conf['columns'][$fieldName]['label'] : $fieldName, 1);
1088 $title = $GLOBALS['LANG']->sL($fieldName, 1);
1091 $tableHeader[] = '<th' . $THparams . '>' . $title . '</th>';
1095 // Add empty icon column
1096 $tableHeader[] = '<th style="white-space:nowrap;"></th>';
1098 $tableHeader[] = '</tr></thead>';
1100 return implode($tableHeader, LF
);
1104 * [Describe function...]
1106 * @param [type] $row: ...
1107 * @param [type] $conf: ...
1108 * @param [type] $table: ...
1109 * @return [type] ...
1111 function csvRowTitles($row, $conf, $table) {
1113 $SET = $GLOBALS['SOBE']->MOD_SETTINGS
;
1114 foreach ($row as $fN => $fV) {
1115 if (t3lib_div
::inList($SET['queryFields'], $fN) ||
(!$SET['queryFields'] && $fN != 'pid')) {
1117 if ($GLOBALS['SOBE']->MOD_SETTINGS
['search_result_labels']) {
1118 $out = $GLOBALS['LANG']->sL($conf['columns'][$fN]['label'] ?
$conf['columns'][$fN]['label'] : $fN, 1);
1120 $out = $GLOBALS['LANG']->sL($fN, 1);
1123 if ($GLOBALS['SOBE']->MOD_SETTINGS
['search_result_labels']) {
1124 $out .= ',' . $GLOBALS['LANG']->sL($conf['columns'][$fN]['label'] ?
$conf['columns'][$fN]['label'] : $fN, 1);
1126 $out .= ',' . $GLOBALS['LANG']->sL($fN, 1);
1135 * Sets the current name of the input form.
1137 * @param string $formName: The name of the form.
1140 public function setFormName($formName) {
1141 $this->formName
= trim($formName);
1145 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE
]['XCLASS']['t3lib/class.t3lib_fullsearch.php'])) {
1146 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE
]['XCLASS']['t3lib/class.t3lib_fullsearch.php']);