TYPO3 CMS  TYPO3_6-2
QueryView.php
Go to the documentation of this file.
1 <?php
3 
19 
27 class QueryView {
28 
32  public $storeList = 'search_query_smallparts,search_result_labels,labels_noprefix,show_deleted,queryConfig,queryTable,queryFields,queryLimit,queryOrder,queryOrderDesc,queryOrder2,queryOrder2Desc,queryGroup,search_query_makeQuery';
33 
37  public $downloadScript = 'index.php';
38 
42  public $formW = 48;
43 
47  public $noDownloadB = 0;
48 
49  protected $formName = '';
50 
54  public function __construct() {
55  $GLOBALS['LANG']->includeLLFile('EXT:lang/locallang_t3lib_fullsearch.xlf');
56  }
57 
64  public function form() {
65  $out = '
66  Search Word:<BR>
67  <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">
68  ';
69  return $out;
70  }
71 
78  public function makeStoreControl() {
79  // Load/Save
80  $storeArray = $this->initStoreArray();
81  // Store Array:
82  $opt = array();
83  foreach ($storeArray as $k => $v) {
84  $opt[] = '<option value="' . $k . '">' . htmlspecialchars($v) . '</option>';
85  }
86  // Actions:
87  if (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('sys_action') && $GLOBALS['BE_USER']->isAdmin()) {
88  $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'sys_action', 'type=2', '', 'title');
89  if ($GLOBALS['TYPO3_DB']->sql_num_rows($res)) {
90  $opt[] = '<option value="0">__Save to Action:__</option>';
91  while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
92  $opt[] = '<option value="-' . $row['uid'] . '">' . htmlspecialchars(($row['title'] . ' [' . $row['uid'] . ']')) . '</option>';
93  }
94  }
95  $GLOBALS['TYPO3_DB']->sql_free_result($res);
96  }
97  $TDparams = ' nowrap="nowrap" class="bgColor4"';
98  $tmpCode = '
99  <table border="0" cellpadding="3" cellspacing="1">
100  <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>
101  <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>
102  </table>
103  ';
104  return $tmpCode;
105  }
106 
113  public function initStoreArray() {
114  $storeArray = array(
115  '0' => '[New]'
116  );
117  $savedStoreArray = unserialize($GLOBALS['SOBE']->MOD_SETTINGS['storeArray']);
118  if (is_array($savedStoreArray)) {
119  $storeArray = array_merge($storeArray, $savedStoreArray);
120  }
121  return $storeArray;
122  }
123 
132  public function cleanStoreQueryConfigs($storeQueryConfigs, $storeArray) {
133  if (is_array($storeQueryConfigs)) {
134  foreach ($storeQueryConfigs as $k => $v) {
135  if (!isset($storeArray[$k])) {
136  unset($storeQueryConfigs[$k]);
137  }
138  }
139  }
140  return $storeQueryConfigs;
141  }
142 
151  public function addToStoreQueryConfigs($storeQueryConfigs, $index) {
152  $keyArr = explode(',', $this->storeList);
153  $storeQueryConfigs[$index] = array();
154  foreach ($keyArr as $k) {
155  $storeQueryConfigs[$index][$k] = $GLOBALS['SOBE']->MOD_SETTINGS[$k];
156  }
157  return $storeQueryConfigs;
158  }
159 
167  public function saveQueryInAction($uid) {
168  if (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('sys_action')) {
169  $keyArr = explode(',', $this->storeList);
170  $saveArr = array();
171  foreach ($keyArr as $k) {
172  $saveArr[$k] = $GLOBALS['SOBE']->MOD_SETTINGS[$k];
173  }
174  $qOK = 0;
175  // Show query
176  if ($saveArr['queryTable']) {
178  $qGen = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Database\\QueryGenerator');
179  $qGen->init('queryConfig', $saveArr['queryTable']);
180  $qGen->makeSelectorTable($saveArr);
181  $qGen->enablePrefix = 1;
182  $qString = $qGen->getQuery($qGen->queryConfig);
183  $qCount = $GLOBALS['TYPO3_DB']->SELECTquery('count(*)', $qGen->table, $qString . BackendUtility::deleteClause($qGen->table));
184  $qSelect = $qGen->getSelectQuery($qString);
185  $res = @$GLOBALS['TYPO3_DB']->sql_query($qCount);
186  if (!$GLOBALS['TYPO3_DB']->sql_error()) {
187  $GLOBALS['TYPO3_DB']->sql_free_result($res);
188  $dA = array();
189  $dA['t2_data'] = serialize(array(
190  'qC' => $saveArr,
191  'qCount' => $qCount,
192  'qSelect' => $qSelect,
193  'qString' => $qString
194  ));
195  $GLOBALS['TYPO3_DB']->exec_UPDATEquery('sys_action', 'uid=' . (int)$uid, $dA);
196  $qOK = 1;
197  }
198  }
199  return $qOK;
200  }
201  }
202 
212  public function loadStoreQueryConfigs($storeQueryConfigs, $storeIndex, $writeArray) {
213  if ($storeQueryConfigs[$storeIndex]) {
214  $keyArr = explode(',', $this->storeList);
215  foreach ($keyArr as $k) {
216  $writeArray[$k] = $storeQueryConfigs[$storeIndex][$k];
217  }
218  }
219  return $writeArray;
220  }
221 
228  public function procesStoreControl() {
229  $storeArray = $this->initStoreArray();
230  $storeQueryConfigs = unserialize($GLOBALS['SOBE']->MOD_SETTINGS['storeQueryConfigs']);
231  $storeControl = GeneralUtility::_GP('storeControl');
232  $storeIndex = (int)$storeControl['STORE'];
233  $saveStoreArray = 0;
234  $writeArray = array();
235  if (is_array($storeControl)) {
236  $msg = '';
237  if ($storeControl['LOAD']) {
238  if ($storeIndex > 0) {
239  $writeArray = $this->loadStoreQueryConfigs($storeQueryConfigs, $storeIndex, $writeArray);
240  $saveStoreArray = 1;
241  $flashMessage = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', sprintf($GLOBALS['LANG']->getLL('query_loaded'), htmlspecialchars($storeArray[$storeIndex])));
242  } elseif ($storeIndex < 0 && \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('sys_action')) {
243  $actionRecord = BackendUtility::getRecord('sys_action', abs($storeIndex));
244  if (is_array($actionRecord)) {
245  $dA = unserialize($actionRecord['t2_data']);
246  $dbSC = array();
247  if (is_array($dA['qC'])) {
248  $dbSC[0] = $dA['qC'];
249  }
250  $writeArray = $this->loadStoreQueryConfigs($dbSC, '0', $writeArray);
251  $saveStoreArray = 1;
252  $flashMessage = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', sprintf($GLOBALS['LANG']->getLL('query_from_action_loaded'), htmlspecialchars($actionRecord['title'])));
253  }
254  }
255  } elseif ($storeControl['SAVE']) {
256  if ($storeIndex < 0) {
257  $qOK = $this->saveQueryInAction(abs($storeIndex));
258  if ($qOK) {
259  $flashMessage = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', $GLOBALS['LANG']->getLL('query_saved'));
260  } else {
261  $flashMessage = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', $GLOBALS['LANG']->getLL('query_notsaved'), '', \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
262  }
263  } else {
264  if (trim($storeControl['title'])) {
265  if ($storeIndex > 0) {
266  $storeArray[$storeIndex] = $storeControl['title'];
267  } else {
268  $storeArray[] = $storeControl['title'];
269  end($storeArray);
270  $storeIndex = key($storeArray);
271  }
272  $storeQueryConfigs = $this->addToStoreQueryConfigs($storeQueryConfigs, $storeIndex);
273  $saveStoreArray = 1;
274  $flashMessage = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', $GLOBALS['LANG']->getLL('query_saved'));
275  }
276  }
277  } elseif ($storeControl['REMOVE']) {
278  if ($storeIndex > 0) {
279  $flashMessage = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', sprintf($GLOBALS['LANG']->getLL('query_removed'), htmlspecialchars($storeArray[$storeControl['STORE']])));
280  // Removing
281  unset($storeArray[$storeControl['STORE']]);
282  $saveStoreArray = 1;
283  }
284  }
285  if ($flashMessage) {
286  $msg = $flashMessage->render();
287  }
288  }
289  if ($saveStoreArray) {
290  // Making sure, index 0 is not set!
291  unset($storeArray[0]);
292  $writeArray['storeArray'] = serialize($storeArray);
293  $writeArray['storeQueryConfigs'] = serialize($this->cleanStoreQueryConfigs($storeQueryConfigs, $storeArray));
294  $GLOBALS['SOBE']->MOD_SETTINGS = BackendUtility::getModuleData($GLOBALS['SOBE']->MOD_MENU, $writeArray, $GLOBALS['SOBE']->MCONF['name'], 'ses');
295  }
296  return $msg;
297  }
298 
305  public function queryMaker() {
306  $output = '';
307  if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['t3lib_fullsearch'])) {
308  $this->hookArray = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['t3lib_fullsearch'];
309  }
310  $msg = $this->procesStoreControl();
311  if (!$GLOBALS['BE_USER']->userTS['mod.']['dbint.']['disableStoreControl']) {
312  $output .= $GLOBALS['SOBE']->doc->section('Load/Save Query', $this->makeStoreControl(), 0, 1);
313  if ($msg) {
314  $output .= '<br />' . $msg;
315  }
316  $output .= $GLOBALS['SOBE']->doc->spacer(20);
317  }
318  // Query Maker:
319  $qGen = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Database\\QueryGenerator');
320  $qGen->init('queryConfig', $GLOBALS['SOBE']->MOD_SETTINGS['queryTable']);
321  if ($this->formName) {
322  $qGen->setFormName($this->formName);
323  }
324  $tmpCode = $qGen->makeSelectorTable($GLOBALS['SOBE']->MOD_SETTINGS);
325  $output .= $GLOBALS['SOBE']->doc->section('Make query', $tmpCode, 0, 1);
326  $mQ = $GLOBALS['SOBE']->MOD_SETTINGS['search_query_makeQuery'];
327  // Make form elements:
328  if ($qGen->table && is_array($GLOBALS['TCA'][$qGen->table])) {
329  if ($mQ) {
330  // Show query
331  $qGen->enablePrefix = 1;
332  $qString = $qGen->getQuery($qGen->queryConfig);
333  switch ($mQ) {
334  case 'count':
335  $qExplain = $GLOBALS['TYPO3_DB']->SELECTquery('count(*)', $qGen->table, $qString . BackendUtility::deleteClause($qGen->table));
336  break;
337  default:
338  $qExplain = $qGen->getSelectQuery($qString);
339  if ($mQ == 'explain') {
340  $qExplain = 'EXPLAIN ' . $qExplain;
341  }
342  }
343  if (!$GLOBALS['BE_USER']->userTS['mod.']['dbint.']['disableShowSQLQuery']) {
344  $output .= $GLOBALS['SOBE']->doc->section('SQL query', $this->tableWrap(htmlspecialchars($qExplain)), 0, 1);
345  }
346  $res = @$GLOBALS['TYPO3_DB']->sql_query($qExplain);
347  if ($GLOBALS['TYPO3_DB']->sql_error()) {
348  $out = '<BR><strong>Error:</strong><BR><font color="red"><strong>' . $GLOBALS['TYPO3_DB']->sql_error() . '</strong></font>';
349  $output .= $GLOBALS['SOBE']->doc->section('SQL error', $out, 0, 1);
350  } else {
351  $cPR = $this->getQueryResultCode($mQ, $res, $qGen->table);
352  $GLOBALS['TYPO3_DB']->sql_free_result($res);
353  $output .= $GLOBALS['SOBE']->doc->section($cPR['header'], $cPR['content'], 0, 1);
354  }
355  }
356  }
357  return $output;
358  }
359 
369  public function getQueryResultCode($mQ, $res, $table) {
370  $out = '';
371  $cPR = array();
372  switch ($mQ) {
373  case 'count':
374  $row = $GLOBALS['TYPO3_DB']->sql_fetch_row($res);
375  $cPR['header'] = 'Count';
376  $cPR['content'] = '<BR><strong>' . $row[0] . '</strong> records selected.';
377  break;
378  case 'all':
379  $rowArr = array();
380  while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
381  $rowArr[] = $this->resultRowDisplay($row, $GLOBALS['TCA'][$table], $table);
382  $lrow = $row;
383  }
384  if (is_array($this->hookArray['beforeResultTable'])) {
385  foreach ($this->hookArray['beforeResultTable'] as $_funcRef) {
386  $out .= GeneralUtility::callUserFunction($_funcRef, $GLOBALS['SOBE']->MOD_SETTINGS, $this);
387  }
388  }
389  if (count($rowArr)) {
390  $out .= '<table border="0" cellpadding="2" cellspacing="1" width="100%">' . $this->resultRowTitles($lrow, $GLOBALS['TCA'][$table], $table) . implode(LF, $rowArr) . '</table>';
391  }
392  if (!$out) {
393  $out = '<em>No rows selected!</em>';
394  }
395  $cPR['header'] = 'Result';
396  $cPR['content'] = $out;
397  break;
398  case 'csv':
399  $rowArr = array();
400  $first = 1;
401  while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
402  if ($first) {
403  $rowArr[] = $this->csvValues(array_keys($row), ',', '');
404  $first = 0;
405  }
406  $rowArr[] = $this->csvValues($row, ',', '"', $GLOBALS['TCA'][$table], $table);
407  }
408  if (count($rowArr)) {
409  $out .= '<textarea name="whatever" rows="20" wrap="off"' . $GLOBALS['SOBE']->doc->formWidthText($this->formW, '', 'off') . ' class="fixed-font">' . GeneralUtility::formatForTextarea(implode(LF, $rowArr)) . '</textarea>';
410  if (!$this->noDownloadB) {
411  $out .= '<BR><input type="submit" name="download_file" value="Click to download file" onClick="window.location.href=\'' . $this->downloadScript . '\';">';
412  }
413  // Downloads file:
414  if (GeneralUtility::_GP('download_file')) {
415  $filename = 'TYPO3_' . $table . '_export_' . date('dmy-Hi') . '.csv';
416  $mimeType = 'application/octet-stream';
417  header('Content-Type: ' . $mimeType);
418  header('Content-Disposition: attachment; filename=' . $filename);
419  echo implode(CRLF, $rowArr);
420  die;
421  }
422  }
423  if (!$out) {
424  $out = '<em>No rows selected!</em>';
425  }
426  $cPR['header'] = 'Result';
427  $cPR['content'] = $out;
428  break;
429  case 'explain':
430 
431  default:
432  while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
433  $out .= '<br />' . \TYPO3\CMS\Core\Utility\DebugUtility::viewArray($row);
434  }
435  $cPR['header'] = 'Explain SQL query';
436  $cPR['content'] = $out;
437  }
438  return $cPR;
439  }
440 
452  public function csvValues($row, $delim = ',', $quote = '"', $conf = array(), $table = '') {
453  $valueArray = $row;
454  if ($GLOBALS['SOBE']->MOD_SETTINGS['search_result_labels'] && $table) {
455  foreach ($valueArray as $key => $val) {
456  $valueArray[$key] = $this->getProcessedValueExtra($table, $key, $val, $conf, ';');
457  }
458  }
459  return GeneralUtility::csvValues($valueArray, $delim, $quote);
460  }
461 
469  public function tableWrap($str) {
470  return '<table border="0" cellpadding="10" cellspacing="0" class="bgColor4"><tr><td nowrap><pre>' . $str . '</pre></td></tr></table>';
471  }
472 
479  public function search() {
480  $SET = $GLOBALS['SOBE']->MOD_SETTINGS;
481  $swords = $SET['sword'];
482  $out = '';
483  $limit = 200;
484  $showAlways = 0;
485  if ($swords) {
486  foreach ($GLOBALS['TCA'] as $table => $value) {
487  // Get fields list
488  $conf = $GLOBALS['TCA'][$table];
489  // Avoid querying tables with no columns
490  if (empty($conf['columns'])) {
491  continue;
492  }
493  $fieldsInDatabase = $GLOBALS['TYPO3_DB']->admin_get_fields($table);
494  $list = array_intersect(array_keys($conf['columns']), array_keys($fieldsInDatabase));
495  // Get query
496  $qp = $GLOBALS['TYPO3_DB']->searchQuery(array($swords), $list, $table);
497  // Count:
498  $count = $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('*', $table, $qp . BackendUtility::deleteClause($table));
499  if ($count || $showAlways) {
500  // Output header:
501  $out .= '<strong>TABLE:</strong> ' . $GLOBALS['LANG']->sL($conf['ctrl']['title']) . '<BR>';
502  $out .= '<strong>Results:</strong> ' . $count . '<BR>';
503  // Show to limit
504  if ($count) {
505  $rowArr = array();
506  $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid,' . $conf['ctrl']['label'], $table, $qp . BackendUtility::deleteClause($table), '', '', $limit);
507  while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
508  $rowArr[] = $this->resultRowDisplay($row, $conf, $table);
509  $lrow = $row;
510  }
511  $GLOBALS['TYPO3_DB']->sql_free_result($res);
512  $out .= '<table border="0" cellpadding="2" cellspacing="1">' . $this->resultRowTitles($lrow, $conf, $table) . implode(LF, $rowArr) . '</table>';
513  }
514  $out .= '<HR>';
515  }
516  }
517  }
518  return $out;
519  }
520 
530  public function resultRowDisplay($row, $conf, $table) {
531  static $even = FALSE;
532  $tce = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\DataHandling\\DataHandler');
533  $SET = $GLOBALS['SOBE']->MOD_SETTINGS;
534  $out = '<tr class="bgColor' . ($even ? '6' : '4') . '">';
535  $even = !$even;
536  foreach ($row as $fN => $fV) {
537  if (GeneralUtility::inList($SET['queryFields'], $fN) || !$SET['queryFields'] && $fN != 'pid' && $fN != 'deleted') {
538  if ($SET['search_result_labels']) {
539  $fVnew = $this->getProcessedValueExtra($table, $fN, $fV, $conf, '<br />');
540  } else {
541  $fVnew = htmlspecialchars($fV);
542  }
543  $out .= '<td>' . $fVnew . '</td>';
544  }
545  }
546  $params = '&edit[' . $table . '][' . $row['uid'] . ']=edit';
547  $out .= '<td nowrap>';
548  if (!$row['deleted']) {
549  $out .= '<a href="#" onClick="top.launchView(\'' . $table . '\',' . $row['uid'] . ',\'' . $GLOBALS['BACK_PATH'] . '\');return false;">' . \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('status-dialog-information') . '</a>';
550  $out .= '<a href="#" onClick="' . BackendUtility::editOnClick($params, $GLOBALS['BACK_PATH'], (GeneralUtility::getIndpEnv('REQUEST_URI') . GeneralUtility::implodeArrayForUrl('SET', (array) GeneralUtility::_POST('SET')))) . '">' . \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('actions-document-open') . '</a>';
551  } else {
552  $out .= '<a href="' . GeneralUtility::linkThisUrl(($GLOBALS['BACK_PATH'] . 'tce_db.php'), array(
553  ('cmd[' . $table . '][' . $row['uid'] . '][undelete]') => '1',
554  'redirect' => GeneralUtility::linkThisScript(array())
555  )) . BackendUtility::getUrlToken('tceAction') . '">';
556  $out .= \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('actions-edit-restore', array('title' => 'undelete only')) . '</a>';
557  $out .= '<a href="' . GeneralUtility::linkThisUrl(($GLOBALS['BACK_PATH'] . 'tce_db.php'), array(
558  ('cmd[' . $table . '][' . $row['uid'] . '][undelete]') => '1',
559  'redirect' => GeneralUtility::linkThisUrl('alt_doc.php', array(
560  ('edit[' . $table . '][' . $row['uid'] . ']') => 'edit',
561  'returnUrl' => GeneralUtility::linkThisScript(array())
562  ))
563  )) . BackendUtility::getUrlToken('tceAction') . '">';
564  $out .= \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('actions-edit-restore-edit', array('title' => 'undelete and edit')) . '</a>';
565  }
566  $_params = array($table => $row);
567  if (is_array($this->hookArray['additionalButtons'])) {
568  foreach ($this->hookArray['additionalButtons'] as $_funcRef) {
569  $out .= GeneralUtility::callUserFunction($_funcRef, $_params, $this);
570  }
571  }
572  $out .= '</td>
573  </tr>
574  ';
575  return $out;
576  }
577 
589  public function getProcessedValueExtra($table, $fN, $fV, $conf, $splitString) {
590  // Analysing the fields in the table.
591  if (is_array($GLOBALS['TCA'][$table])) {
592  $fC = $GLOBALS['TCA'][$table]['columns'][$fN];
593  $fields = $fC['config'];
594  $fields['exclude'] = $fC['exclude'];
595  if (is_array($fC) && $fC['label']) {
596  $fields['label'] = preg_replace('/:$/', '', trim($GLOBALS['LANG']->sL($fC['label'])));
597  switch ($fields['type']) {
598  case 'input':
599  if (preg_match('/int|year/i', $fields['eval'])) {
600  $fields['type'] = 'number';
601  } elseif (preg_match('/time/i', $fields['eval'])) {
602  $fields['type'] = 'time';
603  } elseif (preg_match('/date/i', $fields['eval'])) {
604  $fields['type'] = 'date';
605  } else {
606  $fields['type'] = 'text';
607  }
608  break;
609  case 'check':
610  if (!$fields['items']) {
611  $fields['type'] = 'boolean';
612  } else {
613  $fields['type'] = 'binary';
614  }
615  break;
616  case 'radio':
617  $fields['type'] = 'multiple';
618  break;
619  case 'select':
620  $fields['type'] = 'multiple';
621  if ($fields['foreign_table']) {
622  $fields['type'] = 'relation';
623  }
624  if ($fields['special']) {
625  $fields['type'] = 'text';
626  }
627  break;
628  case 'group':
629  $fields['type'] = 'files';
630  if ($fields['internal_type'] == 'db') {
631  $fields['type'] = 'relation';
632  }
633  break;
634  case 'user':
635 
636  case 'flex':
637 
638  case 'passthrough':
639 
640  case 'none':
641 
642  case 'text':
643 
644  default:
645  $fields['type'] = 'text';
646  }
647  } else {
648  $fields['label'] = '[FIELD: ' . $fN . ']';
649  switch ($fN) {
650  case 'pid':
651  $fields['type'] = 'relation';
652  $fields['allowed'] = 'pages';
653  break;
654  case 'cruser_id':
655  $fields['type'] = 'relation';
656  $fields['allowed'] = 'be_users';
657  break;
658  case 'tstamp':
659 
660  case 'crdate':
661  $fields['type'] = 'time';
662  break;
663  default:
664  $fields['type'] = 'number';
665  }
666  }
667  }
668  switch ($fields['type']) {
669  case 'date':
670  if ($fV != -1) {
671  $out = strftime('%e-%m-%Y', $fV);
672  }
673  break;
674  case 'time':
675  if ($fV != -1) {
676  if ($splitString == '<br />') {
677  $out = strftime('%H:%M' . $splitString . '%e-%m-%Y', $fV);
678  } else {
679  $out = strftime('%H:%M %e-%m-%Y', $fV);
680  }
681  }
682  break;
683  case 'multiple':
684 
685  case 'binary':
686 
687  case 'relation':
688  $out = $this->makeValueList($fN, $fV, $fields, $table, $splitString);
689  break;
690  case 'boolean':
691  $out = $fV ? 'True' : 'False';
692  break;
693  case 'files':
694 
695  default:
696  $out = htmlspecialchars($fV);
697  }
698  return $out;
699  }
700 
711  public function getTreeList($id, $depth, $begin = 0, $perms_clause) {
712  $depth = (int)$depth;
713  $begin = (int)$begin;
714  $id = (int)$id;
715  if ($id < 0) {
716  $id = abs($id);
717  }
718  if ($begin == 0) {
719  $theList = $id;
720  } else {
721  $theList = '';
722  }
723  if ($id && $depth > 0) {
724  $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid', 'pages', 'pid=' . $id . ' ' . BackendUtility::deleteClause('pages') . ' AND ' . $perms_clause);
725  while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
726  if ($begin <= 0) {
727  $theList .= ',' . $row['uid'];
728  }
729  if ($depth > 1) {
730  $theList .= $this->getTreeList($row['uid'], $depth - 1, $begin - 1, $perms_clause);
731  }
732  }
733  $GLOBALS['TYPO3_DB']->sql_free_result($res);
734  }
735  return $theList;
736  }
737 
749  public function makeValueList($fN, $fV, $conf, $table, $splitString) {
750  $fieldSetup = $conf;
751  $out = '';
752  if ($fieldSetup['type'] == 'files') {
753  $d = dir(PATH_site . $fieldSetup['uploadfolder']);
754  while (FALSE !== ($entry = $d->read())) {
755  if ($entry == '.' || $entry == '..') {
756  continue;
757  }
758  $fileArray[] = $entry;
759  }
760  $d->close();
761  natcasesort($fileArray);
762  while (list(, $fileName) = each($fileArray)) {
763  if (GeneralUtility::inList($fV, $fileName) || $fV == $fileName) {
764  if (!$out) {
765  $out = htmlspecialchars($fileName);
766  } else {
767  $out .= $splitString . htmlspecialchars($fileName);
768  }
769  }
770  }
771  }
772  if ($fieldSetup['type'] == 'multiple') {
773  foreach ($fieldSetup['items'] as $key => $val) {
774  if (substr($val[0], 0, 4) == 'LLL:') {
775  $value = $GLOBALS['LANG']->sL($val[0]);
776  } else {
777  $value = $val[0];
778  }
779  if (GeneralUtility::inList($fV, $val[1]) || $fV == $val[1]) {
780  if (!$out) {
781  $out = htmlspecialchars($value);
782  } else {
783  $out .= $splitString . htmlspecialchars($value);
784  }
785  }
786  }
787  }
788  if ($fieldSetup['type'] == 'binary') {
789  foreach ($fieldSetup['items'] as $Key => $val) {
790  if (substr($val[0], 0, 4) == 'LLL:') {
791  $value = $GLOBALS['LANG']->sL($val[0]);
792  } else {
793  $value = $val[0];
794  }
795  if (!$out) {
796  $out = htmlspecialchars($value);
797  } else {
798  $out .= $splitString . htmlspecialchars($value);
799  }
800  }
801  }
802  if ($fieldSetup['type'] == 'relation') {
803  if ($fieldSetup['items']) {
804  foreach ($fieldSetup['items'] as $key => $val) {
805  if (substr($val[0], 0, 4) == 'LLL:') {
806  $value = $GLOBALS['LANG']->sL($val[0]);
807  } else {
808  $value = $val[0];
809  }
810  if (GeneralUtility::inList($fV, $value) || $fV == $value) {
811  if (!$out) {
812  $out = htmlspecialchars($value);
813  } else {
814  $out .= $splitString . htmlspecialchars($value);
815  }
816  }
817  }
818  }
819  if (stristr($fieldSetup['allowed'], ',')) {
820  $from_table_Arr = explode(',', $fieldSetup['allowed']);
821  $useTablePrefix = 1;
822  if (!$fieldSetup['prepend_tname']) {
823  $checkres = $GLOBALS['TYPO3_DB']->exec_SELECTquery($fN, $table, 'uid ' . BackendUtility::deleteClause($table), ($groupBy = ''), ($orderBy = ''), ($limit = ''));
824  if ($checkres) {
825  while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($checkres)) {
826  if (stristr($row[$fN], ',')) {
827  $checkContent = explode(',', $row[$fN]);
828  foreach ($checkContent as $singleValue) {
829  if (!stristr($singleValue, '_')) {
830  $dontPrefixFirstTable = 1;
831  }
832  }
833  } else {
834  $singleValue = $row[$fN];
835  if (strlen($singleValue) && !stristr($singleValue, '_')) {
836  $dontPrefixFirstTable = 1;
837  }
838  }
839  }
840  $GLOBALS['TYPO3_DB']->sql_free_result($checkres);
841  }
842  }
843  } else {
844  $from_table_Arr[0] = $fieldSetup['allowed'];
845  }
846  if ($fieldSetup['prepend_tname']) {
847  $useTablePrefix = 1;
848  }
849  if ($fieldSetup['foreign_table']) {
850  $from_table_Arr[0] = $fieldSetup['foreign_table'];
851  }
852  $counter = 0;
853  foreach ($from_table_Arr as $from_table) {
854  if ($useTablePrefix && !$dontPrefixFirstTable && $counter != 1 || $counter == 1) {
855  $tablePrefix = $from_table . '_';
856  }
857  $counter = 1;
858  if (is_array($GLOBALS['TCA'][$from_table])) {
859  $labelField = $GLOBALS['TCA'][$from_table]['ctrl']['label'];
860  $altLabelField = $GLOBALS['TCA'][$from_table]['ctrl']['label_alt'];
861  if ($GLOBALS['TCA'][$from_table]['columns'][$labelField]['config']['items']) {
862  foreach ($GLOBALS['TCA'][$from_table]['columns'][$labelField]['config']['items'] as $labelArray) {
863  if (substr($labelArray[0], 0, 4) == 'LLL:') {
864  $labelFieldSelect[$labelArray[1]] = $GLOBALS['LANG']->sL($labelArray[0]);
865  } else {
866  $labelFieldSelect[$labelArray[1]] = $labelArray[0];
867  }
868  }
869  $useSelectLabels = 1;
870  }
871  if ($GLOBALS['TCA'][$from_table]['columns'][$altLabelField]['config']['items']) {
872  foreach ($GLOBALS['TCA'][$from_table]['columns'][$altLabelField]['config']['items'] as $altLabelArray) {
873  if (substr($altLabelArray[0], 0, 4) == 'LLL:') {
874  $altLabelFieldSelect[$altLabelArray[1]] = $GLOBALS['LANG']->sL($altLabelArray[0]);
875  } else {
876  $altLabelFieldSelect[$altLabelArray[1]] = $altLabelArray[0];
877  }
878  }
879  $useAltSelectLabels = 1;
880  }
881  $altLabelFieldSelect = $altLabelField ? ',' . $altLabelField : '';
882  $select_fields = 'uid,' . $labelField . $altLabelFieldSelect;
883  if (!$GLOBALS['BE_USER']->isAdmin() && $GLOBALS['TYPO3_CONF_VARS']['BE']['lockBeUserToDBmounts']) {
884  $webMounts = $GLOBALS['BE_USER']->returnWebmounts();
885  $perms_clause = $GLOBALS['BE_USER']->getPagePermsClause(1);
886  $webMountPageTree = '';
887  foreach ($webMounts as $key => $val) {
888  if ($webMountPageTree) {
889  $webMountPageTreePrefix = ',';
890  }
891  $webMountPageTree .= $webMountPageTreePrefix . $this->getTreeList($val, 999, ($begin = 0), $perms_clause);
892  }
893  if ($from_table == 'pages') {
894  $where_clause = 'uid IN (' . $webMountPageTree . ') ' . BackendUtility::deleteClause($from_table) . ' AND ' . $perms_clause;
895  } else {
896  $where_clause = 'pid IN (' . $webMountPageTree . ') ' . BackendUtility::deleteClause($from_table);
897  }
898  } else {
899  $where_clause = 'uid' . BackendUtility::deleteClause($from_table);
900  }
901  $orderBy = 'uid';
902  if (!$this->tableArray[$from_table]) {
903  $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($select_fields, $from_table, $where_clause, ($groupBy = ''), $orderBy, ($limit = ''));
904  $this->tableArray[$from_table] = array();
905  }
906  if ($res) {
907  while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
908  $this->tableArray[$from_table][] = $row;
909  }
910  $GLOBALS['TYPO3_DB']->sql_free_result($res);
911  }
912  foreach ($this->tableArray[$from_table] as $key => $val) {
913  $GLOBALS['SOBE']->MOD_SETTINGS['labels_noprefix'] = $GLOBALS['SOBE']->MOD_SETTINGS['labels_noprefix'] == 1 ? 'on' : $GLOBALS['SOBE']->MOD_SETTINGS['labels_noprefix'];
914  $prefixString = $GLOBALS['SOBE']->MOD_SETTINGS['labels_noprefix'] == 'on' ? '' : ' [' . $tablePrefix . $val['uid'] . '] ';
915  if (GeneralUtility::inList($fV, $tablePrefix . $val['uid']) || $fV == $tablePrefix . $val['uid']) {
916  if ($useSelectLabels) {
917  if (!$out) {
918  $out = htmlspecialchars($prefixString . $labelFieldSelect[$val[$labelField]]);
919  } else {
920  $out .= $splitString . htmlspecialchars(($prefixString . $labelFieldSelect[$val[$labelField]]));
921  }
922  } elseif ($val[$labelField]) {
923  if (!$out) {
924  $out = htmlspecialchars($prefixString . $val[$labelField]);
925  } else {
926  $out .= $splitString . htmlspecialchars(($prefixString . $val[$labelField]));
927  }
928  } elseif ($useAltSelectLabels) {
929  if (!$out) {
930  $out = htmlspecialchars($prefixString . $altLabelFieldSelect[$val[$altLabelField]]);
931  } else {
932  $out .= $splitString . htmlspecialchars(($prefixString . $altLabelFieldSelect[$val[$altLabelField]]));
933  }
934  } else {
935  if (!$out) {
936  $out = htmlspecialchars($prefixString . $val[$altLabelField]);
937  } else {
938  $out .= $splitString . htmlspecialchars(($prefixString . $val[$altLabelField]));
939  }
940  }
941  }
942  }
943  }
944  }
945  }
946  return $out;
947  }
948 
958  public function resultRowTitles($row, $conf, $table) {
959  $SET = $GLOBALS['SOBE']->MOD_SETTINGS;
960  $tableHeader = array();
961  // Start header row
962  $tableHeader[] = '<thead><tr class="bgColor5">';
963  // Iterate over given columns
964  foreach ($row as $fieldName => $fieldValue) {
965  if (GeneralUtility::inList($SET['queryFields'], $fieldName) || !$SET['queryFields'] && $fieldName != 'pid' && $fieldName != 'deleted') {
966  $THparams = strlen($fieldValue) < 50 ? ' style="white-space:nowrap;"' : '';
967  if ($GLOBALS['SOBE']->MOD_SETTINGS['search_result_labels']) {
968  $title = $GLOBALS['LANG']->sL($conf['columns'][$fieldName]['label'] ? $conf['columns'][$fieldName]['label'] : $fieldName, TRUE);
969  } else {
970  $title = $GLOBALS['LANG']->sL($fieldName, TRUE);
971  }
972  $tableHeader[] = '<th' . $THparams . '>' . $title . '</th>';
973  }
974  }
975  // Add empty icon column
976  $tableHeader[] = '<th style="white-space:nowrap;"></th>';
977  // Close header row
978  $tableHeader[] = '</tr></thead>';
979  return implode($tableHeader, LF);
980  }
981 
991  public function csvRowTitles($row, $conf, $table) {
992  $out = '';
993  $SET = $GLOBALS['SOBE']->MOD_SETTINGS;
994  foreach ($row as $fN => $fV) {
995  if (GeneralUtility::inList($SET['queryFields'], $fN) || !$SET['queryFields'] && $fN != 'pid') {
996  if (!$out) {
997  if ($GLOBALS['SOBE']->MOD_SETTINGS['search_result_labels']) {
998  $out = $GLOBALS['LANG']->sL($conf['columns'][$fN]['label'] ? $conf['columns'][$fN]['label'] : $fN, TRUE);
999  } else {
1000  $out = $GLOBALS['LANG']->sL($fN, TRUE);
1001  }
1002  } else {
1003  if ($GLOBALS['SOBE']->MOD_SETTINGS['search_result_labels']) {
1004  $out .= ',' . $GLOBALS['LANG']->sL(($conf['columns'][$fN]['label'] ? $conf['columns'][$fN]['label'] : $fN), TRUE);
1005  } else {
1006  $out .= ',' . $GLOBALS['LANG']->sL($fN, TRUE);
1007  }
1008  }
1009  }
1010  }
1011  return $out;
1012  }
1013 
1020  public function setFormName($formName) {
1021  $this->formName = trim($formName);
1022  }
1023 
1024 }
getQueryResultCode($mQ, $res, $table)
Definition: QueryView.php:369
csvValues($row, $delim=',', $quote='"', $conf = array(), $table = '')
Definition: QueryView.php:452
$uid
Definition: server.php:36
loadStoreQueryConfigs($storeQueryConfigs, $storeIndex, $writeArray)
Definition: QueryView.php:212
static callUserFunction($funcName, &$params, &$ref, $checkPrefix='', $errorMode=0)
resultRowTitles($row, $conf, $table)
Definition: QueryView.php:958
static getModuleData($MOD_MENU, $CHANGED_SETTINGS, $modName, $type='', $dontValidateList='', $setDefaultList='')
resultRowDisplay($row, $conf, $table)
Definition: QueryView.php:530
addToStoreQueryConfigs($storeQueryConfigs, $index)
Definition: QueryView.php:151
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]
cleanStoreQueryConfigs($storeQueryConfigs, $storeArray)
Definition: QueryView.php:132
static deleteClause($table, $tableAlias='')