"TYPO3 4.0.1: typo3_src-4.0.1/t3lib/class.t3lib_fullsearch.php Source File", "datetime" => "Sat Dec 2 19:22:18 2006", "date" => "2 Dec 2006", "doxygenversion" => "1.4.6", "projectname" => "TYPO3 4.0.1", "projectnumber" => "4.0.1" ); get_header($doxygen_vars); ?>

class.t3lib_fullsearch.php

00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 1999-2006 Kasper Skaarhoj (kasperYYYY@typo3.com)
00006 *  All rights reserved
00007 *
00008 *  This script is part of the TYPO3 project. The TYPO3 project is
00009 *  free software; you can redistribute it and/or modify
00010 *  it under the terms of the GNU General Public License as published by
00011 *  the Free Software Foundation; either version 2 of the License, or
00012 *  (at your option) any later version.
00013 *
00014 *  The GNU General Public License can be found at
00015 *  http://www.gnu.org/copyleft/gpl.html.
00016 *  A copy is found in the textfile GPL.txt and important notices to the license
00017 *  from the author is found in LICENSE.txt distributed with these scripts.
00018 *
00019 *
00020 *  This script is distributed in the hope that it will be useful,
00021 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00022 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023 *  GNU General Public License for more details.
00024 *
00025 *  This copyright notice MUST APPEAR in all copies of the script!
00026 ***************************************************************/
00088 class t3lib_fullsearch {
00089         var $storeList = 'search_query_smallparts,search_result_labels,labels_noprefix,show_deleted,queryConfig,queryTable,queryFields,queryLimit,queryOrder,queryOrderDesc,queryOrder2,queryOrder2Desc,queryGroup,search_query_makeQuery';
00090         var $downloadScript = 'index.php';
00091         var $formW=48;
00092         var $noDownloadB=0;
00093 
00094 
00095 
00096 
00097 
00103         function form() {
00104                 $out='
00105                 Search Word:<BR>
00106                 <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">
00107                 ';
00108 
00109                 return $out;
00110         }
00111 
00117         function makeStoreControl()     {
00118                         // Load/Save
00119                 $storeArray = $this->initStoreArray();
00120                 $cur='';
00121 
00122                         // Store Array:
00123                 $opt=array();
00124                 reset($storeArray);
00125                 while(list($k,$v)=each($storeArray))    {
00126                         $opt[]='<option value="'.$k.'"'.(!strcmp($cur,$v)?' selected':'').'>'.htmlspecialchars($v).'</option>';
00127                 }
00128 
00129                         // Actions:
00130                 if (t3lib_extMgm::isLoaded('sys_action') && $GLOBALS['BE_USER']->isAdmin())     {
00131                         $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'sys_action', 'type=2', '', 'title');
00132                         if ($GLOBALS['TYPO3_DB']->sql_num_rows($res))   {
00133                                 $opt[]='<option value="0">__Save to Action:__</option>';
00134                                 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))       {
00135                                         $opt[]='<option value="-'.$row['uid'].'"'.(!strcmp($cur,'-'.$row['uid'])?' selected':'').'>'.htmlspecialchars($row['title'].' ['.$row['uid'].']').'</option>';
00136                                 }
00137                         }
00138                         $GLOBALS['TYPO3_DB']->sql_free_result($res);
00139                 }
00140 
00141                 $TDparams=' nowrap="nowrap" class="bgColor4"';
00142                 $tmpCode='
00143                 <table border="0" cellpadding="3" cellspacing="1">
00144                 <tr'.$TDparams.'><td><select name="storeControl[STORE]" onChange="document.forms[0][\'storeControl[title]\'].value= this.options[this.selectedIndex].value!=0 ? this.options[this.selectedIndex].text : \'\';">'.implode(chr(10),$opt).'</select><input type="submit" name="storeControl[LOAD]" value="Load"></td></tr>
00145                 <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>
00146                 </table>
00147                 ';
00148                 return $tmpCode;
00149         }
00150 
00156         function initStoreArray()       {
00157                 $storeArray=array(
00158                         '0' => '[New]'
00159                 );
00160 
00161                 $savedStoreArray = unserialize($GLOBALS['SOBE']->MOD_SETTINGS['storeArray']);
00162 
00163                 if (is_array($savedStoreArray)) {
00164                         $storeArray = array_merge($storeArray,$savedStoreArray);
00165                 }
00166                 return $storeArray;
00167         }
00168 
00176         function cleanStoreQueryConfigs($storeQueryConfigs,$storeArray) {
00177                 if (is_array($storeQueryConfigs))       {
00178                         reset($storeQueryConfigs);
00179                         while(list($k,$v)=each($storeQueryConfigs))     {
00180                                 if (!isset($storeArray[$k]))    unset($storeQueryConfigs[$k]);
00181                         }
00182                 }
00183                 return $storeQueryConfigs;
00184         }
00185 
00193         function addToStoreQueryConfigs($storeQueryConfigs,$index)      {
00194                 $keyArr = explode(',',$this->storeList);
00195                 reset($keyArr);
00196                 $storeQueryConfigs[$index]=array();
00197                 while(list(,$k)=each($keyArr))  {
00198                         $storeQueryConfigs[$index][$k]=$GLOBALS['SOBE']->MOD_SETTINGS[$k];
00199                 }
00200                 return $storeQueryConfigs;
00201         }
00202 
00209         function saveQueryInAction($uid)        {
00210                 if (t3lib_extMgm::isLoaded('sys_action'))       {
00211                         $keyArr = explode(',',$this->storeList);
00212                         reset($keyArr);
00213                         $saveArr=array();
00214                         while(list(,$k)=each($keyArr))  {
00215                                 $saveArr[$k]=$GLOBALS['SOBE']->MOD_SETTINGS[$k];
00216                         }
00217 
00218                         $qOK = 0;
00219                                 // Show query
00220                         if ($saveArr['queryTable'])     {
00221                                 $qGen = t3lib_div::makeInstance('t3lib_queryGenerator');
00222                                 $qGen->init('queryConfig',$saveArr['queryTable']);
00223                                 $qGen->makeSelectorTable($saveArr);
00224 
00225                                 $qGen->enablePrefix=1;
00226                                 $qString = $qGen->getQuery($qGen->queryConfig);
00227                                 $qCount = $GLOBALS['TYPO3_DB']->SELECTquery('count(*)', $qGen->table, $qString.t3lib_BEfunc::deleteClause($qGen->table));
00228                                 $qSelect = $qGen->getSelectQuery($qString);
00229 
00230                                 $res = @$GLOBALS['TYPO3_DB']->sql(TYPO3_db,$qCount);
00231                                 if (!$GLOBALS['TYPO3_DB']->sql_error()) {
00232                                         $dA = array();
00233                                         $dA['t2_data'] = serialize(array(
00234                                                 'qC'=>$saveArr,
00235                                                 'qCount' => $qCount,
00236                                                 'qSelect' => $qSelect,
00237                                                 'qString' => $qString
00238                                         ));
00239                                         $GLOBALS['TYPO3_DB']->exec_UPDATEquery('sys_action', 'uid='.intval($uid), $dA);
00240                                         $qOK=1;
00241                                 }
00242                         }
00243 
00244                         return $qOK;
00245                 }
00246         }
00247 
00256         function loadStoreQueryConfigs($storeQueryConfigs,$storeIndex,$writeArray)      {
00257                 if ($storeQueryConfigs[$storeIndex])    {
00258                         $keyArr = explode(',',$this->storeList);
00259                         reset($keyArr);
00260                         while(list(,$k)=each($keyArr))  {
00261                                 $writeArray[$k]=$storeQueryConfigs[$storeIndex][$k];
00262                         }
00263                 }
00264                 return $writeArray;
00265         }
00266 
00272         function procesStoreControl()   {
00273                 $storeArray = $this->initStoreArray();
00274                 $storeQueryConfigs = unserialize($GLOBALS['SOBE']->MOD_SETTINGS['storeQueryConfigs']);
00275 
00276                 $storeControl = t3lib_div::_GP('storeControl');
00277                 $storeIndex = intval($storeControl['STORE']);
00278                 $saveStoreArray=0;
00279                 $writeArray=array();
00280                 if (is_array($storeControl))    {
00281                         if ($storeControl['LOAD'])      {
00282                                 if ($storeIndex>0)      {
00283                                         $writeArray=$this->loadStoreQueryConfigs($storeQueryConfigs,$storeIndex,$writeArray);
00284                                         $saveStoreArray=1;
00285                                         $msg="'".htmlspecialchars($storeArray[$storeIndex])."' query loaded!";
00286                                 } elseif ($storeIndex<0 && t3lib_extMgm::isLoaded('sys_action'))        {
00287                                         $actionRecord=t3lib_BEfunc::getRecord('sys_action',abs($storeIndex));
00288                                         if (is_array($actionRecord))    {
00289                                                 $dA = unserialize($actionRecord['t2_data']);
00290                                                 $dbSC=array();
00291                                                 if (is_array($dA['qC']))        {
00292                                                         $dbSC[0] = $dA['qC'];
00293                                                 }
00294                                                 $writeArray=$this->loadStoreQueryConfigs($dbSC,'0',$writeArray);
00295                                                 $saveStoreArray=1;
00296                                                 $acTitle=htmlspecialchars($actionRecord['title']);
00297                                                 $msg="Query from action '".$acTitle."' loaded!";
00298                                         }
00299                                 }
00300                         } elseif ($storeControl['SAVE'])        {
00301                                 if ($storeIndex<0)      {
00302                                         $qOK = $this->saveQueryInAction(abs($storeIndex));
00303                                         if ($qOK)       {
00304                                                 $msg='Query OK and saved.';
00305                                         } else {
00306                                                 $msg='No query saved!';
00307                                         }
00308                                 } else {
00309                                         if (trim($storeControl['title']))       {
00310                                                 if ($storeIndex>0)      {
00311                                                         $storeArray[$storeIndex]=$storeControl['title'];
00312                                                 } else {
00313                                                         $storeArray[]=$storeControl['title'];
00314                                                         end($storeArray);
00315                                                         $storeIndex=key($storeArray);
00316                                                 }
00317                                                 $storeQueryConfigs=$this->addToStoreQueryConfigs($storeQueryConfigs,$storeIndex);
00318                                                 $saveStoreArray=1;
00319                                                 $msg="'".htmlspecialchars($storeArray[$storeIndex])."' query saved!";
00320                                         }
00321                                 }
00322                         } elseif ($storeControl['REMOVE'])      {
00323                                 if ($storeIndex>0)      {
00324                                         $msg="'".$storeArray[$storeControl['STORE']]."' query entry removed!";
00325                                         unset($storeArray[$storeControl['STORE']]);     // Removing
00326                                         $saveStoreArray=1;
00327                                 }
00328                         }
00329                 }
00330                 if ($saveStoreArray)    {
00331                         unset($storeArray[0]);  // making sure, index 0 is not set!
00332                         $writeArray['storeArray']=serialize($storeArray);
00333                         $writeArray['storeQueryConfigs']=serialize($this->cleanStoreQueryConfigs($storeQueryConfigs,$storeArray));
00334                         $GLOBALS['SOBE']->MOD_SETTINGS = t3lib_BEfunc::getModuleData($GLOBALS['SOBE']->MOD_MENU, $writeArray, $GLOBALS['SOBE']->MCONF['name'], 'ses');
00335                 }
00336                 return $msg;
00337         }
00338 
00344         function queryMaker()   {
00345                 global $TCA;
00346 
00347                 if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['t3lib_fullsearch']))       {
00348                         $this->hookArray = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['t3lib_fullsearch'];
00349                 }
00350                 $msg=$this->procesStoreControl();
00351 
00352                 if (!$GLOBALS['BE_USER']->userTS['mod.']['dbint.']['disableStoreControl']) {
00353                         $output.= $GLOBALS['SOBE']->doc->section('Load/Save Query',$this->makeStoreControl(),0,1);
00354                         if ($msg)       {
00355                                 $output.= $GLOBALS['SOBE']->doc->section('','<font color=red><strong>'.$msg.'</strong></font>');
00356                         }
00357                         $output.= $GLOBALS['SOBE']->doc->spacer(20);
00358                 }
00359 
00360 
00361                         // Query Maker:
00362                 $qGen = t3lib_div::makeInstance('t3lib_queryGenerator');
00363                 $qGen->init('queryConfig',$GLOBALS['SOBE']->MOD_SETTINGS['queryTable']);
00364                 $tmpCode=$qGen->makeSelectorTable($GLOBALS['SOBE']->MOD_SETTINGS);
00365                 $output.= $GLOBALS['SOBE']->doc->section('Make query',$tmpCode,0,1);
00366 
00367                 $mQ = $GLOBALS['SOBE']->MOD_SETTINGS['search_query_makeQuery'];
00368 
00369                         // Make form elements:
00370                 if ($qGen->table && is_array($TCA[$qGen->table]))       {
00371                         if ($mQ)        {
00372                                         // Show query
00373                                 $qGen->enablePrefix=1;
00374                                 $qString = $qGen->getQuery($qGen->queryConfig);
00375 //                              debug($qGen->queryConfig);
00376 
00377                                 switch($mQ)     {
00378                                         case 'count':
00379                                                 $qExplain = $GLOBALS['TYPO3_DB']->SELECTquery('count(*)', $qGen->table, $qString.t3lib_BEfunc::deleteClause($qGen->table));
00380                                         break;
00381                                         default:
00382                                                 $qExplain = $qGen->getSelectQuery($qString);
00383                                                 if ($mQ=='explain')     {
00384                                                         $qExplain='EXPLAIN '.$qExplain;
00385                                                 }
00386                                         break;
00387                                 }
00388 
00389                 if (!$GLOBALS['BE_USER']->userTS['mod.']['dbint.']['disableShowSQLQuery'])      {
00390                                 $output.= $GLOBALS['SOBE']->doc->section('SQL query',$this->tableWrap(htmlspecialchars($qExplain)),0,1);
00391                 }
00392 
00393                                 $res = @$GLOBALS['TYPO3_DB']->sql(TYPO3_db,$qExplain);
00394                                 if ($GLOBALS['TYPO3_DB']->sql_error())  {
00395                                         $out.='<BR><strong>Error:</strong><BR><font color="red"><strong>'.$GLOBALS['TYPO3_DB']->sql_error().'</strong></font>';
00396                                         $output.= $GLOBALS['SOBE']->doc->section('SQL error',$out,0,1);
00397                                 } else {
00398                                         $cPR = $this->getQueryResultCode($mQ,$res,$qGen->table);
00399                                         $output.=$GLOBALS['SOBE']->doc->section($cPR['header'],$cPR['content'],0,1);
00400                                 }
00401                         }
00402                 }
00403                 return $output;
00404         }
00405 
00414         function getQueryResultCode($mQ,$res,$table)    {
00415                 global $TCA;
00416                 $output='';
00417                 $cPR=array();
00418                 switch($mQ)     {
00419                         case 'count':
00420                                 $row = $GLOBALS['TYPO3_DB']->sql_fetch_row($res);
00421                                 $cPR['header']='Count';
00422                                 $cPR['content']='<BR><strong>'.$row[0]. '</strong> records selected.';
00423                         break;
00424                         case 'all':
00425                                 $rowArr=array();
00426                                 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))       {
00427                                         $rowArr[]=$this->resultRowDisplay($row,$TCA[$table],$table);
00428                                         $lrow=$row;
00429                                 }
00430                                 if (is_array($this->hookArray['beforeResultTable']))    {
00431                                         foreach ($this->hookArray['beforeResultTable'] as $_funcRef)    {
00432                                                 $out.=t3lib_div::callUserFunction($_funcRef, $GLOBALS['SOBE']->MOD_SETTINGS, $this);
00433                                         }
00434                                 }
00435                                 if (count($rowArr))     {
00436                                         $out.='<table border="0" cellpadding="2" cellspacing="1" width="100%">'.$this->resultRowTitles($lrow, $TCA[$table], $table).implode(chr(10), $rowArr).'</table>';
00437                                 }
00438                                 if (!$out)      $out='<em>No rows selected!</em>';
00439                                 $cPR['header']='Result';
00440                                 $cPR['content']=$out;
00441                         break;
00442                         case 'csv':
00443                                 $rowArr=array();
00444                                 $first=1;
00445                                 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))       {
00446                                         if ($first)     {
00447                                                 $rowArr[]=$this->csvValues(array_keys($row),',','');
00448                                                 $first=0;
00449                                         }
00450                                         $rowArr[]=$this->csvValues($row, ',', '"', $TCA[$table], $table);
00451                                 }
00452                                 if (count($rowArr))     {
00453                                         $out.='<textarea name="whatever" rows="20" wrap="off"'.$GLOBALS['SOBE']->doc->formWidthText($this->formW,'','off').' class="fixed-font">'.t3lib_div::formatForTextarea(implode(chr(10),$rowArr)).'</textarea>';
00454                                         if (!$this->noDownloadB)        {
00455                                                 $out.='<BR><input type="submit" name="download_file" value="Click to download file" onClick="window.location.href=\''.$this->downloadScript.'\';">';            // document.forms[0].target=\'_blank\';
00456                                         }
00457                                                 // Downloads file:
00458                                         if (t3lib_div::_GP('download_file'))    {
00459                                                 $filename='TYPO3_'.$table.'_export_'.date('dmy-Hi').'.csv';
00460                                                 $mimeType = 'application/octet-stream';
00461                                                 header('Content-Type: '.$mimeType);
00462                                                 header('Content-Disposition: attachment; filename='.$filename);
00463                                                 echo implode(chr(13).chr(10),$rowArr);
00464                                                 exit;
00465                                         }
00466                                 }
00467                                 if (!$out)      $out='<em>No rows selected!</em>';
00468                                 $cPR['header']='Result';
00469                                 $cPR['content']=$out;
00470                         break;
00471                         case 'xml':
00472                                 $className=t3lib_div::makeInstanceClassName('t3lib_xml');
00473                                 $xmlObj = new $className('typo3_export');
00474                                 $xmlObj->includeNonEmptyValues=1;
00475                                 $xmlObj->renderHeader();
00476                                 $first=1;
00477                                 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))       {
00478                                         if ($first)     {
00479                                                 $xmlObj->setRecFields($table,implode(',',array_keys($row)));
00480                 //                              debug($xmlObj->XML_recFields);
00481                                                 $first=0;
00482                                         }
00483                                         $valueArray = $row;
00484                                         if ($GLOBALS['SOBE']->MOD_SETTINGS['search_result_labels'])     {
00485                                                 foreach ($valueArray as $key => $val)   {
00486                                                         $valueArray[$key] = $this->getProcessedValueExtra($table, $key, $val, $conf, ',');
00487                                                 }
00488                                         }
00489                                         $xmlObj->addRecord($table, $valueArray);
00490                                 }
00491                                 $xmlObj->renderFooter();
00492                                 if ($GLOBALS['TYPO3_DB']->sql_num_rows($res))   {
00493                                         $xmlData=$xmlObj->getResult();
00494                                         $out.='<textarea name="whatever" rows="20" wrap="off"'.$GLOBALS['SOBE']->doc->formWidthText($this->formW,'','off').' class="fixed-font">'.t3lib_div::formatForTextarea($xmlData).'</textarea>';
00495                                         if (!$this->noDownloadB)        {
00496                                                 $out.='<BR><input type="submit" name="download_file" value="Click to download file" onClick="window.location.href=\''.$this->downloadScript.'\';">';            // document.forms[0].target=\'_blank\';
00497                                         }
00498                                                 // Downloads file:
00499                                         if (t3lib_div::_GP('download_file'))    {
00500                                                 $filename='TYPO3_'.$table.'_export_'.date('dmy-Hi').'.xml';
00501                                                 $mimeType = 'application/octet-stream';
00502                                                 header('Content-Type: '.$mimeType);
00503                                                 header('Content-Disposition: attachment; filename='.$filename);
00504                                                 echo $xmlData;
00505                                                 exit;
00506                                         }
00507                                 }
00508                                 if (!$out)      $out='<em>No rows selected!</em>';
00509                                 $cPR['header']='Result';
00510                                 $cPR['content']=$out;
00511                         break;
00512                         case 'explain':
00513                         default:
00514                                 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))       {
00515                                         $out.='<BR>'.t3lib_div::view_array($row);
00516                                 }
00517                                 $cPR['header']='Explain SQL query';
00518                                 $cPR['content']=$out;
00519                         break;
00520                 }
00521                 return $cPR;
00522         }
00523 
00534         function csvValues($row, $delim=',', $quote='"', $conf=array(), $table='')      {
00535                 $valueArray = $row;
00536                 if ($GLOBALS['SOBE']->MOD_SETTINGS['search_result_labels'] && $table)   {
00537                         foreach ($valueArray as $key => $val)   {
00538                                 $valueArray[$key] = $this->getProcessedValueExtra($table, $key, $val, $conf, ';');
00539                         }
00540                 }
00541                 return t3lib_div::csvValues($valueArray, $delim, $quote);
00542         }
00543 
00550         function tableWrap($str)        {
00551                 return '<table border="0" cellpadding="10" cellspacing="0" class="bgColor4"><tr><td nowrap><pre>'.$str.'</pre></td></tr></table>';
00552         }
00553 
00559         function search()       {
00560                 global $TCA;
00561                 $SET = $GLOBALS['SOBE']->MOD_SETTINGS;
00562                 $swords = $SET['sword'];
00563 
00564                 $limit=200;
00565                 $showAlways=0;
00566                 if ($swords)    {
00567                         reset($TCA);
00568                         while(list($table)=each($TCA))  {
00569                                         // Get fields list
00570                                 t3lib_div::loadTCA($table);
00571                                 $conf=$TCA[$table];
00572 
00573                                 reset($conf['columns']);
00574                                 $list=array();
00575                                 while(list($field,)=each($conf['columns']))     {
00576                                         $list[]=$field;
00577                                 }
00578                                         // Get query
00579                                 $qp = $GLOBALS['TYPO3_DB']->searchQuery(array($swords), $list, $table);
00580 
00581                                         // Count:
00582                                 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('count(*)', $table, $qp.t3lib_BEfunc::deleteClause($table));
00583                                 list($count) = $GLOBALS['TYPO3_DB']->sql_fetch_row($res);
00584                                 if($count || $showAlways)       {
00585                                                 // Output header:
00586                                         $out.='<strong>TABLE:</strong> '.$GLOBALS['LANG']->sL($conf['ctrl']['title']).'<BR>';
00587                                         $out.='<strong>Results:</strong> '.$count.'<BR>';
00588 
00589                                                 // Show to limit
00590                                         if ($count)     {
00591                                                 $rowArr = array();
00592                                                 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid,'.$conf['ctrl']['label'], $table, $qp.t3lib_BEfunc::deleteClause($table), '', '', $limit);
00593                                                 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))       {
00594                                                         $rowArr[]=$this->resultRowDisplay($row,$conf,$table);
00595                                                         $lrow=$row;
00596                                                 }
00597                                                 $out.='<table border="0" cellpadding="2" cellspacing="1">'.$this->resultRowTitles($lrow,$conf,$table).implode(chr(10),$rowArr).'</table>';
00598                                         }
00599                                         $out.='<HR>';
00600                                 }
00601                         }
00602                 }
00603                 return $out;
00604         }
00605 
00614         function resultRowDisplay($row,$conf,$table)    {
00615                 $tce = t3lib_div::makeInstance('t3lib_TCEmain');
00616                 $SET = $GLOBALS['SOBE']->MOD_SETTINGS;
00617                 $out='<tr class="bgColor4">';
00618                 reset($row);
00619                 while(list($fN,$fV)=each($row)) {
00620                         if (t3lib_div::inList($SET['queryFields'], $fN) || (!$SET['queryFields'] && $fN!='pid' && $fN!='deleted'))      {
00621                                 if ($SET['search_result_labels'])       {
00622                                         $fVnew = $this->getProcessedValueExtra($table, $fN, $fV, $conf, '<br />');
00623                                 } else {
00624                                         $fVnew = $fV;
00625                                 }
00626                                 $out.='<td'.$TDparams.'>'.$fVnew.'</td>';
00627                         }
00628                 }
00629                 $params = '&edit['.$table.']['.$row['uid'].']=edit';
00630                 $out.='<td nowrap>';
00631                 if (!$row['deleted'])   {
00632                         $out .= '<a href="#" onClick="top.launchView(\''.$table.'\','.$row['uid'].',\''.$GLOBALS['BACK_PATH'].'\');return false;"><img src="'.$GLOBALS['BACK_PATH'].'gfx/zoom2.gif" width="12" height="12" alt="" /></a>';
00633                         $out .= '<a href="#" onClick="'.t3lib_BEfunc::editOnClick($params, $GLOBALS['BACK_PATH'], t3lib_div::getIndpEnv('REQUEST_URI').t3lib_div::implodeArrayForUrl('SET', t3lib_div::_POST('SET'))).'"><img src="'.$GLOBALS['BACK_PATH'].'gfx/edit2.gif" width="11" height="12" border="0" alt=""></a>';
00634                 } else {
00635                         $out.= '<a href="'.t3lib_div::linkThisUrl($GLOBALS['BACK_PATH'].'tce_db.php', array('cmd['.$table.']['.$row['uid'].'][undelete]' => '1', 'redirect' => t3lib_div::linkThisScript(array()))).'">';
00636                         $out.= '<img src="'.$GLOBALS['BACK_PATH'].'gfx/undelete.gif" width="13" height="12" border="0" alt="undelete" only></A>';
00637                         $out.= '<a href="'.t3lib_div::linkThisUrl($GLOBALS['BACK_PATH'].'tce_db.php', array('cmd['.$table.']['.$row['uid'].'][undelete]' => '1', 'redirect' => t3lib_div::linkThisUrl('alt_doc.php', array('edit['.$table.']['.$row['uid'].']' => 'edit', 'returnUrl' => t3lib_div::linkThisScript(array()))))).'">';
00638                         $out.= '<img src="'.$GLOBALS['BACK_PATH'].'gfx/undelete_and_edit.gif" width="13" height="12" border="0" alt="undelete and edit">';
00639                 }
00640                 $_params = array($table=>$row);
00641                 if (is_array($this->hookArray['additionalButtons']))    {
00642                         foreach ($this->hookArray['additionalButtons'] as $_funcRef)    {
00643                                 $out.=t3lib_div::callUserFunction($_funcRef, $_params, $this);
00644                         }
00645                 }
00646                 $out.='</td>
00647                 </tr>
00648                 ';
00649                 return $out;
00650         }
00651 
00662         function getProcessedValueExtra($table, $fN, $fV, $conf, $splitString)  {
00663                 global $TCA;
00664                         // Analysing the fields in the table.
00665                 if (is_array($TCA[$table]))     {
00666                         t3lib_div::loadTCA($table);
00667                         $fC = $TCA[$table]['columns'][$fN];
00668                         $fields = $fC['config'];
00669                         $fields['exclude'] = $fC['exclude'];
00670                         if (is_array($fC) && $fC['label'])      {
00671                                 $fields['label'] = ereg_replace(":$", '', trim($GLOBALS['LANG']->sL($fC['label'])));
00672 
00673                                 switch ($fields['type'])        {
00674                                         case 'input':
00675                                                 if (eregi('int|year', $fields['eval'])) {
00676                                                         $fields['type'] = 'number';
00677                                                 } elseif (eregi('time', $fields['eval']))       {
00678                                                         $fields['type'] = 'time';
00679                                                 } elseif (eregi('date', $fields['eval']))       {
00680                                                         $fields['type'] = 'date';
00681                                                 } else {
00682                                                         $fields['type'] = 'text';
00683                                                 }
00684                                         break;
00685                                         case 'check':
00686                                                 if (!$fields['items'])  {
00687                                                         $fields['type'] = 'boolean';
00688                                                 } else {
00689                                                         $fields['type'] = 'binary';
00690                                                 }
00691                                         break;
00692                                         case 'radio':
00693                                                 $fields['type'] = 'multiple';
00694                                         break;
00695                                         case 'select':
00696                                                 $fields['type'] = 'multiple';
00697                                                 if ($fields['foreign_table'])   {
00698                                                         $fields['type'] = 'relation';
00699                                                 }
00700                                                 if ($fields['special']) {
00701                                                         $fields['type'] = 'text';
00702                                                 }
00703                                         break;
00704                                         case 'group':
00705                                                 $fields['type'] = 'files';
00706                                                 if ($fields['internal_type']=='db')     {
00707                                                         $fields['type'] = 'relation';
00708                                                 }
00709                                         break;
00710                                         case 'user':
00711                                         case 'flex':
00712                                         case 'passthrough':
00713                                         case 'none':
00714                                         case 'text':
00715                                         default:
00716                                                 $fields['type'] = 'text';
00717                                         break;
00718                                 }
00719                         } else {
00720                                 $fields['label'] = '[FIELD: '.$fN.']';
00721                                 switch ($fN)    {
00722                                         case 'pid':
00723                                                 $fields['type'] = 'relation';
00724                                                 $fields['allowed'] = 'pages';
00725                                         break;
00726                                         case 'cruser_id':
00727                                                 $fields['type'] = 'relation';
00728                                                 $fields['allowed'] = 'be_users';
00729                                         break;
00730                                         case 'tstamp':
00731                                         case 'crdate':
00732                                                 $fields['type'] = 'time';
00733                                         break;
00734                                         default:
00735                                                 $fields['type'] = 'number';
00736                                         break;
00737                                 }
00738                         }
00739                 }
00740 
00741                 switch ($fields['type'])        {
00742                         case 'date':
00743                                 if ($fV != -1)  {
00744                                         $out = strftime('%e-%m-%Y', $fV);
00745                                 }
00746                         break;
00747                         case 'time':
00748                                 if ($fV != -1)  {
00749                                         if ($splitString=='<br />')     {
00750                                                 $out = strftime('%H:%M'.$splitString.'%e-%m-%Y', $fV);
00751                                         } else {
00752                                                 $out = strftime('%H:%M %e-%m-%Y', $fV);
00753                                         }
00754                                 }
00755                         break;
00756                         case 'multiple':
00757                         case 'binary':
00758                         case 'relation':
00759                                 $out = $this->makeValueList($fN, $fV, $fields, $table, $splitString);
00760                         break;
00761                         case 'boolean':
00762                                 $out = $fV ? 'True' : 'False';
00763                         break;
00764                         case 'files':
00765                         default:
00766                                 $out = htmlspecialchars($fV);
00767                         break;
00768                 }
00769                 return $out;
00770         }
00771 
00772         /*
00773         * [Describe function...]
00774         *
00775         * @param        [type]          $qString: ...
00776         * @param        [type]          $depth: ...
00777         * @param        [type]          $begin: ...
00778         * @param        [type]          $perms_clause: ...
00779         * @return       [type]          ...
00780         */
00781         function getTreeList($id, $depth, $begin = 0, $perms_clause)    {
00782                 $depth = intval($depth);
00783                 $begin = intval($begin);
00784                 $id = intval($id);
00785                 if ($begin == 0)        {
00786                         $theList = $id;
00787                 } else {
00788                         $theList = '';
00789                 }
00790                 if ($id && $depth > 0)  {
00791                         $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
00792                                 'uid',
00793                                 'pages',
00794                                 'pid='.$id.' '.t3lib_BEfunc::deleteClause('pages').' AND '.$perms_clause
00795                         );
00796                         while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))      {
00797                                 if ($begin <= 0)        {
00798                                         $theList .= ','.$row['uid'];
00799                                 }
00800                                 if ($depth > 1) {
00801                                         $theList .= $this->getTreeList($row['uid'], $depth-1, $begin-1, $perms_clause);
00802                                 }
00803                         }
00804                 }
00805                 return $theList;
00806         }
00807 
00818         function makeValueList($fN, $fV, $conf, $table, $splitString) {
00819                 $fieldSetup = $conf;
00820                 if ($fieldSetup['type'] == 'files') {
00821                         $d = dir(t3lib_div::getIndpEnv(TYPO3_DOCUMENT_ROOT).'/'.$fieldSetup['uploadfolder']);
00822                         while (false !== ($entry = $d->read())) {
00823                                 if ($entry == '.' || $entry == '..') {
00824                                         continue;
00825                                 }
00826                                 $fileArray[] = $entry;
00827                         }
00828                         $d->close();
00829                         natcasesort($fileArray);
00830                         while (list(, $fileName) = each($fileArray)) {
00831                                 if (t3lib_div::inList($fV, $fileName) || $fV == $fileName) {
00832                                         if (!$out) {
00833                                                 $out = htmlspecialchars($fileName);
00834                                         } else {
00835                                                 $out .= $splitString.htmlspecialchars($fileName);
00836                                         }
00837                                 }
00838                         }
00839                 }
00840                 if ($fieldSetup['type'] == 'multiple') {
00841                         foreach ($fieldSetup['items'] as $key => $val) {
00842                                 if (substr($val[0], 0, 4) == 'LLL:') {
00843                                         $value = $GLOBALS['LANG']->sL($val[0]);
00844                                 } else {
00845                                         $value = $val[0];
00846                                 }
00847                                 if (t3lib_div::inList($fV, $val[1]) || $fV == $val[1]) {
00848                                         if (!$out) {
00849                                                 $out = htmlspecialchars($value);
00850                                         } else {
00851                                                 $out .= $splitString.htmlspecialchars($value);
00852                                         }
00853                                 }
00854                         }
00855                 }
00856                 if ($fieldSetup['type'] == 'binary') {
00857                         foreach($fieldSetup['items'] as $Key => $val) {
00858                                 if (substr($val[0], 0, 4) == 'LLL:') {
00859                                         $value = $GLOBALS['LANG']->sL($val[0]);
00860                                 } else {
00861                                         $value = $val[0];
00862                                 }
00863                                 if (!$out) {
00864                                         $out = htmlspecialchars($value);
00865                                 } else {
00866                                         $out .= $splitString.htmlspecialchars($value);
00867                                 }
00868                         }
00869                 }
00870                 if ($fieldSetup['type']=='relation')    {
00871                         if ($fieldSetup['items'])       {
00872                                 foreach($fieldSetup['items'] as $key => $val)   {
00873                                         if (substr($val[0], 0, 4) == 'LLL:')    {
00874                                                 $value = $GLOBALS['LANG']->sL($val[0]);
00875                                         } else {
00876                                                 $value = $val[0];
00877                                         }
00878                                         if (t3lib_div::inList($fV, $value) || $fV == $value) {
00879                                                 if (!$out) {
00880                                                         $out = htmlspecialchars($value);
00881                                                 } else {
00882                                                         $out .= $splitString.htmlspecialchars($value);
00883                                                 }
00884                                         }
00885                                 }
00886                         }
00887                         global $TCA;
00888                         if (stristr($fieldSetup['allowed'], ',')) {
00889                                 $from_table_Arr = explode(',', $fieldSetup['allowed']);
00890                                 $useTablePrefix = 1;
00891                                 if (!$fieldSetup['prepend_tname']) {
00892                                         $checkres = $GLOBALS['TYPO3_DB']->exec_SELECTquery($fN, $table, 'uid '.t3lib_BEfunc::deleteClause($table), $groupBy = '', $orderBy = '', $limit = '');
00893                                         if ($checkres) {
00894                                                 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($checkres)) {
00895                                                         if (stristr($row[$fN], ',')) {
00896                                                                 $checkContent = explode(',', $row[$fN]);
00897                                                                 foreach($checkContent as $singleValue) {
00898                                                                         if (!stristr($singleValue, '_')) {
00899                                                                                 $dontPrefixFirstTable = 1;
00900                                                                         }
00901                                                                 }
00902                                                         } else {
00903                                                                 $singleValue = $row[$fN];
00904                                                                 if (strlen($singleValue) && !stristr($singleValue, '_')) {
00905                                                                         $dontPrefixFirstTable = 1;
00906                                                                 }
00907                                                         }
00908                                                 }
00909                                         }
00910                                 }
00911                         } else {
00912                                 $from_table_Arr[0] = $fieldSetup['allowed'];
00913                         }
00914                         if ($fieldSetup['prepend_tname']) {
00915                                 $useTablePrefix = 1;
00916                         }
00917                         if ($fieldSetup['foreign_table']) {
00918                                 $from_table_Arr[0] = $fieldSetup['foreign_table'];
00919                         }
00920                         $counter = 0;
00921                         foreach($from_table_Arr as $from_table) {
00922                                 if (($useTablePrefix && !$dontPrefixFirstTable && $counter != 1) || $counter == 1) {
00923                                         $tablePrefix = $from_table.'_';
00924                                 }
00925                                 $counter = 1;
00926                                 if (is_array($TCA[$from_table])) {
00927                                         t3lib_div::loadTCA($from_table);
00928                                         $labelField = $TCA[$from_table]['ctrl']['label'];
00929                                         $altLabelField = $TCA[$from_table]['ctrl']['label_alt'];
00930                                         if ($TCA[$from_table]['columns'][$labelField]['config']['items']) {
00931                                                 reset($TCA[$from_table]['columns'][$labelField]['config']['items']);
00932                                                 while (list(, $labelArray) = each($TCA[$from_table]['columns'][$labelField]['config']['items'])) {
00933                                                         if (substr($labelArray[0], 0, 4) == 'LLL:') {
00934                                                                 $labelFieldSelect[$labelArray[1]] = $GLOBALS['LANG']->sL($labelArray[0]);
00935                                                         } else {
00936                                                                 $labelFieldSelect[$labelArray[1]] = $labelArray[0];
00937                                                         }
00938                                                 }
00939                                                 $useSelectLabels = 1;
00940                                         }
00941                                         if ($TCA[$from_table]['columns'][$altLabelField]['config']['items']) {
00942                                                 reset($TCA[$from_table]['columns'][$altLabelField]['config']['items']);
00943                                                 foreach($TCA[$from_table]['columns'][$altLabelField]['config']['items'] as $altLabelArray) {
00944                                                         if (substr($altLabelArray[0], 0, 4) == 'LLL:') {
00945                                                                 $altLabelFieldSelect[$altLabelArray[1]] = $GLOBALS['LANG']->sL($altLabelArray[0]);
00946                                                         } else {
00947                                                                 $altLabelFieldSelect[$altLabelArray[1]] = $altLabelArray[0];
00948                                                         }
00949                                                 }
00950                                                 $useAltSelectLabels = 1;
00951                                         }
00952                                         $altLabelFieldSelect = $altLabelField ? ','.$altLabelField : '';
00953                                         $select_fields = 'uid,'.$labelField.$altLabelFieldSelect;
00954                                         if (!$GLOBALS['BE_USER']->isAdmin() && $GLOBALS['TYPO3_CONF_VARS']['BE']['lockBeUserToDBmounts']) {
00955                                                 $webMounts = $GLOBALS['BE_USER']->returnWebmounts();
00956                                                 $perms_clause = $GLOBALS['BE_USER']->getPagePermsClause(1);
00957                                                 foreach($webMounts as $key => $val) {
00958                                                         if ($webMountPageTree) {
00959                                                                 $webMountPageTreePrefix = ',';
00960                                                         }
00961                                                         $webMountPageTree .= $webMountPageTreePrefix.$this->getTreeList($val, 999, $begin = 0, $perms_clause);
00962                                                 }
00963                                                 if ($from_table == 'pages') {
00964                                                         $where_clause = 'uid IN ('.$webMountPageTree.') '.t3lib_BEfunc::deleteClause($from_table).' AND '.$perms_clause;
00965                                                 } else {
00966                                                         $where_clause = 'pid IN ('.$webMountPageTree.') '.t3lib_BEfunc::deleteClause($from_table);
00967                                                 }
00968                                         } else {
00969                                                 $where_clause = 'uid'.t3lib_BEfunc::deleteClause($from_table);
00970                                         }
00971                                         $orderBy = 'uid';
00972                                         if (!$this->tableArray[$from_table]) {
00973                                                 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($select_fields, $from_table, $where_clause, $groupBy = '', $orderBy, $limit = '');
00974                                                 $this->tableArray[$from_table] = array();
00975                                         }
00976                                         if ($res) {
00977                                                 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00978                                                         $this->tableArray[$from_table][] = $row;
00979                                                 }
00980                                         }
00981                                         reset($this->tableArray[$from_table]);
00982                                         foreach ($this->tableArray[$from_table] as $key => $val) {
00983                                                 $GLOBALS['SOBE']->MOD_SETTINGS['labels_noprefix'] = $GLOBALS['SOBE']->MOD_SETTINGS['labels_noprefix'] == 1 ? 'on' :
00984                                                 $GLOBALS['SOBE']->MOD_SETTINGS['labels_noprefix'];
00985                                                 $prefixString = $GLOBALS['SOBE']->MOD_SETTINGS['labels_noprefix'] == 'on' ? '' : ' ['.$tablePrefix.$val['uid'].'] ';
00986                                                 if (t3lib_div::inList($fV, $tablePrefix.$val['uid']) || $fV == $tablePrefix.$val['uid']) {
00987                                                         if ($useSelectLabels) {
00988                                                                 if (!$out) {
00989                                                                         $out = htmlspecialchars($prefixString.$labelFieldSelect[$val[$labelField]]);
00990                                                                 } else {
00991                                                                         $out .= $splitString.htmlspecialchars($prefixString.$labelFieldSelect[$val[$labelField]]);
00992                                                                 }
00993                                                         } elseif ($val[$labelField]) {
00994                                                                 if (!$out) {
00995                                                                         $out = htmlspecialchars($prefixString.$val[$labelField]);
00996                                                                 } else {
00997                                                                         $out .= $splitString.htmlspecialchars($prefixString.$val[$labelField]);
00998                                                                 }
00999                                                         } elseif ($useAltSelectLabels) {
01000                                                                 if (!$out) {
01001                                                                         $out = htmlspecialchars($prefixString.$altLabelFieldSelect[$val[$altLabelField]]);
01002                                                                 } else {
01003                                                                         $out .= $splitString.htmlspecialchars($prefixString.$altLabelFieldSelect[$val[$altLabelField]]);
01004                                                                 }
01005                                                         } else {
01006                                                                 if (!$out) {
01007                                                                         $out = htmlspecialchars($prefixString.$val[$altLabelField]);
01008                                                                 } else {
01009                                                                         $out .= $splitString.htmlspecialchars($prefixString.$val[$altLabelField]);
01010                                                                 }
01011                                                         }
01012                                                 }
01013                                         }
01014                                 }
01015                         }
01016                 }
01017                 return $out;
01018         }
01019 
01028         function resultRowTitles($row,$conf,$table)     {
01029                 $SET = $GLOBALS['SOBE']->MOD_SETTINGS;
01030                 $out='<tr class="bgColor5">';
01031                 reset($row);
01032                 while(list($fN,$fV)=each($row)) {
01033                         if (t3lib_div::inList($SET['queryFields'], $fN) || (!$SET['queryFields'] && $fN!='pid' && $fN!='deleted'))      {
01034                                 if (strlen($fV) < 50)   $TDparams = ' nowrap';
01035                                 else $TDparams = '';
01036 
01037                                 if ($GLOBALS['SOBE']->MOD_SETTINGS['search_result_labels'])     {
01038                                         $out.='<td'.$TDparams.'><strong>'.$GLOBALS['LANG']->sL($conf['columns'][$fN]['label']?$conf['columns'][$fN]['label']:$fN,1).'</strong></td>';
01039                                 } else {
01040                                         $out.='<td'.$TDparams.'><strong>'.$GLOBALS['LANG']->sL($fN, 1).'</strong></td>';
01041                                 }
01042                         }
01043                 }
01044                 $out.='<td nowrap></td>
01045                 </tr>
01046                 ';
01047                 return $out;
01048         }
01049 
01058         function csvRowTitles($row, $conf, $table)      {
01059                 $SET = $GLOBALS['SOBE']->MOD_SETTINGS;
01060                 foreach ($row as $fN => $fV)    {
01061                         if (t3lib_div::inList($SET['queryFields'], $fN) || (!$SET['queryFields'] && $fN!='pid'))        {
01062                                 if (!$out)      {
01063                                         if ($GLOBALS['SOBE']->MOD_SETTINGS['search_result_labels'])     {
01064                                                 $out = $GLOBALS['LANG']->sL($conf['columns'][$fN]['label']?$conf['columns'][$fN]['label']:$fN, 1);
01065                                         } else {
01066                                                 $out = $GLOBALS['LANG']->sL($fN, 1);
01067                                         }
01068                                 } else {
01069                                         if ($GLOBALS['SOBE']->MOD_SETTINGS['search_result_labels'])     {
01070                                                 $out.= ','.$GLOBALS['LANG']->sL($conf['columns'][$fN]['label']?$conf['columns'][$fN]['label']:$fN, 1);
01071                                         } else {
01072                                                 $out.= ','.$GLOBALS['LANG']->sL($fN, 1);
01073                                         }
01074                                 }
01075                         }
01076                 }
01077                 return $out;
01078         }
01079 }
01080 
01081 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_fullsearch.php'])        {
01082         include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_fullsearch.php']);
01083 }
01084 ?>