"TYPO3 4.0.1: typo3_src-4.0.1/t3lib/class.t3lib_querygenerator.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_querygenerator.php

00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 2001-2006 Christian Jul Jensen (christian@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 ***************************************************************/
00098 class t3lib_queryGenerator      {
00099         var $lang = array(
00100                 'OR' => 'or',
00101                 'AND' => 'and',
00102                 'comparison' => array(
00103                                  // Type = text offset = 0
00104                         '0_' => 'contains',
00105                         '1_' => 'does not contain',
00106                         '2_' => 'starts with',
00107                         '3_' => 'does not start with',
00108                         '4_' => 'ends with',
00109                         '5_' => 'does not end with',
00110                         '6_' => 'equals',
00111                         '7_' => 'does not equal',
00112                                  // Type = number , offset = 32
00113                         '32_' => 'equals',
00114                         '33_' => 'does not equal',
00115                         '34_' => 'is greater than',
00116                         '35_' => 'is less than',
00117                         '36_' => 'is between',
00118                         '37_' => 'is not between',
00119                         '38_' => 'is in list',
00120                         '39_' => 'is not in list',
00121                         '40_' => 'binary AND equals',
00122                         '41_' => 'binary AND does not equal',
00123                         '42_' => 'binary OR equals',
00124                         '43_' => 'binary OR does not equal',
00125                                 // Type = multiple, relation, files , offset = 64
00126                         '64_' => 'equals',
00127                         '65_' => 'does not equal',
00128                         '66_' => 'contains',
00129                         '67_' => 'does not contain',
00130                         '68_' => 'is in list',
00131                         '69_' => 'is not in list',
00132                         '70_' => 'binary AND equals',
00133                         '71_' => 'binary AND does not equal',
00134                         '72_' => 'binary OR equals',
00135                         '73_' => 'binary OR does not equal',
00136                                 // Type = date,time  offset = 96
00137                         '96_' => 'equals',
00138                         '97_' => 'does not equal',
00139                         '98_' => 'is greater than',
00140                         '99_' => 'is less than',
00141                         '100_' => 'is between',
00142                         '101_' => 'is not between',
00143                         '102_' => 'binary AND equals',
00144                         '103_' => 'binary AND does not equal',
00145                         '104_' => 'binary OR equals',
00146                         '105_' => 'binary OR does not equal',
00147                                 // Type = boolean,  offset = 128
00148                         '128_' => 'is True',
00149                         '129_' => 'is False',
00150                                 // Type = binary , offset = 160
00151                         '160_' => 'equals',
00152                         '161_' => 'does not equal',
00153                         '162_' => 'contains',
00154                         '163_' => 'does not contain'
00155                 )
00156         );
00157 
00158         var $compSQL = array(
00159                         // Type = text  offset = 0
00160                 '0' => "#FIELD# LIKE '%#VALUE#%'",
00161                 '1' => "#FIELD# NOT LIKE '%#VALUE#%'",
00162                 '2' => "#FIELD# LIKE '#VALUE#%'",
00163                 '3' => "#FIELD# NOT LIKE '#VALUE#%'",
00164                 '4' => "#FIELD# LIKE '%#VALUE#'",
00165                 '5' => "#FIELD# NOT LIKE '%#VALUE#'",
00166                 '6' => "#FIELD# = '#VALUE#'",
00167                 '7' => "#FIELD# != '#VALUE#'",
00168                         // Type = number, offset = 32
00169                 '32' => "#FIELD# = '#VALUE#'",
00170                 '33' => "#FIELD# != '#VALUE#'",
00171                 '34' => '#FIELD# > #VALUE#',
00172                 '35' => '#FIELD# < #VALUE#',
00173                 '36' => '#FIELD# >= #VALUE# AND #FIELD# <= #VALUE1#',
00174                 '37' => 'NOT (#FIELD# >= #VALUE# AND #FIELD# <= #VALUE1#)',
00175                 '38' => '#FIELD# IN (#VALUE#)',
00176                 '39' => '#FIELD# NOT IN (#VALUE#)',
00177                 '40' => '(#FIELD# & #VALUE#)=#VALUE#',
00178                 '41' => '(#FIELD# & #VALUE#)!=#VALUE#',
00179                 '42' => '(#FIELD# | #VALUE#)=#VALUE#',
00180                 '43' => '(#FIELD# | #VALUE#)!=#VALUE#',
00181                         // Type = multiple, relation, files , offset = 64
00182                 '64' => "#FIELD# = '#VALUE#'",
00183                 '65' => "#FIELD# != '#VALUE#'",
00184                 '66' => "#FIELD# LIKE '%#VALUE#%' AND #FIELD# LIKE '%#VALUE1#%'",
00185                 '67' => "(#FIELD# NOT LIKE '%#VALUE#%' OR #FIELD# NOT LIKE '%#VALUE1#%')",
00186                 '68' => '#FIELD# IN (#VALUE#)',
00187                 '69' => '#FIELD# NOT IN (#VALUE#)',
00188                 '70' => '(#FIELD# & #VALUE#)=#VALUE#',
00189                 '71' => '(#FIELD# & #VALUE#)!=#VALUE#',
00190                 '72' => '(#FIELD# | #VALUE#)=#VALUE#',
00191                 '73' => '(#FIELD# | #VALUE#)!=#VALUE#',
00192                         // Type = date, offset = 32
00193                 '96' => "#FIELD# = '#VALUE#'",
00194                 '97' => "#FIELD# != '#VALUE#'",
00195                 '98' => '#FIELD# > #VALUE#',
00196                 '99' => '#FIELD# < #VALUE#',
00197                 '100' => '#FIELD# >= #VALUE# AND #FIELD# <= #VALUE1#',
00198                 '101' => 'NOT (#FIELD# >= #VALUE# AND #FIELD# <= #VALUE1#)',
00199                 '102' => '(#FIELD# & #VALUE#)=#VALUE#',
00200                 '103' => '(#FIELD# & #VALUE#)!=#VALUE#',
00201                 '104' => '(#FIELD# | #VALUE#)=#VALUE#',
00202                 '105' => '(#FIELD# | #VALUE#)!=#VALUE#',
00203                         // Type = boolean, offset = 128
00204                 '128' => "#FIELD# = '1'",
00205                 '129' => "#FIELD# != '1'",
00206                         // Type = binary = 160
00207                 '160' => "#FIELD# = '#VALUE#'",
00208                 '161' => "#FIELD# != '#VALUE#'",
00209                 '162' => '(#FIELD# & #VALUE#)=#VALUE#',
00210                 '163' => '(#FIELD# & #VALUE#)=0'
00211         );
00212 
00213         var $comp_offsets = array(
00214                 'text' => 0,
00215                 'number' => 1,
00216                 'multiple' => 2,
00217                 'relation' => 2,
00218                 'files' => 2,
00219                 'date' => 3,
00220                 'time' => 3,
00221                 'boolean' => 4,
00222                 'binary' => 5
00223         );
00224         var $noWrap=' nowrap';
00225 
00226         var $name;                      // Form data name prefix
00227         var $table;                     // table for the query
00228         var $fieldList;         // field list
00229         var $fields = array();  // Array of the fields possible
00230         var $extFieldLists = array();
00231         var $queryConfig=array(); // The query config
00232         var $enablePrefix=0;
00233         var $enableQueryParts = 0;
00234         var $extJSCODE='';
00235 
00236 
00237 
00238 
00239 
00240 
00241 
00245         function makeFieldList()        {
00246                 global $TCA;
00247                 $fieldListArr = array();
00248                 if (is_array($TCA[$this->table]))       {
00249                         t3lib_div::loadTCA($this->table);
00250                         reset($TCA[$this->table]['columns']);
00251                         while(list($fN)=each($TCA[$this->table]['columns']))    {
00252                                 $fieldListArr[]=$fN;
00253                         }
00254                         $fieldListArr[]='uid';
00255                         $fieldListArr[]='pid';
00256                         $fieldListArr[]='deleted';
00257                         if ($TCA[$this->table]['ctrl']['tstamp'])       $fieldListArr[]=$TCA[$this->table]['ctrl']['tstamp'];
00258                         if ($TCA[$this->table]['ctrl']['crdate'])       $fieldListArr[]=$TCA[$this->table]['ctrl']['crdate'];
00259                         if ($TCA[$this->table]['ctrl']['cruser_id'])    $fieldListArr[]=$TCA[$this->table]['ctrl']['cruser_id'];
00260                         if ($TCA[$this->table]['ctrl']['sortby'])       $fieldListArr[]=$TCA[$this->table]['ctrl']['sortby'];
00261                 }
00262                 return implode(',',$fieldListArr);
00263         }
00264 
00273         function init($name,$table,$fieldList='')       {
00274                 global $TCA;
00275 
00276                         // Analysing the fields in the table.
00277                 if (is_array($TCA[$table]))     {
00278                         t3lib_div::loadTCA($table);
00279                         $this->name = $name;
00280                         $this->table = $table;
00281                         $this->fieldList = $fieldList ? $fieldList : $this->makeFieldList();
00282 
00283                         $fieldArr = t3lib_div::trimExplode(',',$this->fieldList,1);
00284                         reset($fieldArr);
00285                         while(list(,$fN)=each($fieldArr))       {
00286                                 $fC = $TCA[$this->table]['columns'][$fN];
00287                                 $this->fields[$fN] = $fC['config'];
00288                                 $this->fields[$fN]['exclude'] = $fC['exclude'];
00289                                 if (is_array($fC) && $fC['label'])      {
00290                                         $this->fields[$fN]['label'] = ereg_replace(':$','',trim($GLOBALS['LANG']->sL($fC['label'])));
00291                                         switch ($this->fields[$fN]['type'])     {
00292                                                 case 'input':
00293                                                         if (eregi('int|year', $this->fields[$fN]['eval']))      {
00294                                                                 $this->fields[$fN]['type']='number';
00295                                                         } elseif (eregi('time', $this->fields[$fN]['eval']))    {
00296                                                                 $this->fields[$fN]['type'] = 'time';
00297                                                         } elseif (eregi('date', $this->fields[$fN]['eval']))    {
00298                                                                 $this->fields[$fN]['type']='date';
00299                                                         } else {
00300                                                                 $this->fields[$fN]['type']='text';
00301                                                         }
00302                                                 break;
00303                                                 case 'check':
00304                                                         if (!$this->fields[$fN]['items'])       {
00305                                                                 $this->fields[$fN]['type'] = 'boolean';
00306                                                         } else {
00307                                                                 $this->fields[$fN]['type'] = 'binary';
00308                                                         }
00309                                                 break;
00310                                                 case 'radio':
00311                                                         $this->fields[$fN]['type'] = 'multiple';
00312                                                 break;
00313                                                 case 'select':
00314                                                         $this->fields[$fN]['type'] = 'multiple';
00315                                                         if ($this->fields[$fN]['foreign_table'])        {
00316                                                                 $this->fields[$fN]['type'] = 'relation';
00317                                                         }
00318                                                         if ($this->fields[$fN]['special'])      {
00319                                                                 $this->fields[$fN]['type'] = 'text';
00320                                                         }
00321                                                 break;
00322                                                 case 'group':
00323                                                         $this->fields[$fN]['type'] = 'files';
00324                                                         if ($this->fields[$fN]['internal_type'] == 'db')        {
00325                                                                 $this->fields[$fN]['type'] = 'relation';
00326                                                         }
00327                                                 break;
00328                                                 case 'user':
00329                                                 case 'flex':
00330                                                 case 'passthrough':
00331                                                 case 'none':
00332                                                 case 'text':
00333                                                 default:
00334                                                         $this->fields[$fN]['type']='text';
00335                                                 break;
00336                                         }
00337 
00338                                 } else {
00339                                         $this->fields[$fN]['label']='[FIELD: '.$fN.']';
00340                                         switch ($fN)    {
00341                                                 case 'pid':
00342                                                         $this->fields[$fN]['type'] = 'relation';
00343                                                         $this->fields[$fN]['allowed'] = 'pages';
00344                                                 break;
00345                                                 case 'cruser_id':
00346                                                         $this->fields[$fN]['type'] = 'relation';
00347                                                         $this->fields[$fN]['allowed'] = 'be_users';
00348                                                 break;
00349                                                 case 'tstamp':
00350                                                 case 'crdate':
00351                                                         $this->fields[$fN]['type'] = 'time';
00352                                                 break;
00353                                                 case 'deleted':
00354                                                         $this->fields[$fN]['type'] = 'boolean';
00355                                                 break;
00356                                                 default:
00357                                                         $this->fields[$fN]['type'] = 'number';
00358                                                 break;
00359                                         }
00360                                 }
00361                         }
00362                 }
00363 
00364                 /*      // EXAMPLE:
00365                 $this->queryConfig = array(
00366                         array(
00367                                 'operator' => 'AND',
00368                                 'type' => 'FIELD_spaceBefore',
00369                         ),
00370                         array(
00371                                 'operator' => 'AND',
00372                                 'type' => 'FIELD_records',
00373                                 'negate' => 1,
00374                                 'inputValue' => 'foo foo'
00375                         ),
00376                         array(
00377                                 'type' => 'newlevel',
00378                                 'nl' => array(
00379                                         array(
00380                                                 'operator' => 'AND',
00381                                                 'type' => 'FIELD_spaceBefore',
00382                                                 'negate' => 1,
00383                                                 'inputValue' => 'foo foo'
00384                                         ),
00385                                         array(
00386                                                 'operator' => 'AND',
00387                                                 'type' => 'FIELD_records',
00388                                                 'negate' => 1,
00389                                                 'inputValue' => 'foo foo'
00390                                         )
00391                                 )
00392                         ),
00393                         array(
00394                                 'operator' => 'OR',
00395                                 'type' => 'FIELD_maillist',
00396                         )
00397                 );
00398                 */
00399                 $this->initUserDef();
00400         }
00401 
00410         function setAndCleanUpExternalLists($name,$list,$force='')      {
00411                 $fields = array_unique(t3lib_div::trimExplode(',',$list.','.$force,1));
00412                 reset($fields);
00413                 $reList=array();
00414                 while(list(,$fN)=each($fields)) {
00415                         if ($this->fields[$fN])         $reList[]=$fN;
00416                 }
00417                 $this->extFieldLists[$name]=implode(',',$reList);
00418         }
00419 
00426         function procesData($qC='')     {
00427                 $this->queryConfig = $qC;
00428 
00429                 $POST = t3lib_div::_POST();
00430 
00431                 // if delete...
00432                 if($POST['qG_del']) {
00433                         //initialize array to work on, save special parameters
00434                         $ssArr = $this->getSubscript($POST['qG_del']);
00435                         $workArr =& $this->queryConfig;
00436                         for($i=0;$i<sizeof($ssArr)-1;$i++) {
00437                                 $workArr =& $workArr[$ssArr[$i]];
00438                         }
00439                         // delete the entry and move the other entries
00440                         unset($workArr[$ssArr[$i]]);
00441                         for($j=$ssArr[$i];$j<sizeof($workArr);$j++) {
00442                                 $workArr[$j] = $workArr[$j+1];
00443                                 unset($workArr[$j+1]);
00444                         }
00445                 }
00446 
00447                 // if insert...
00448                 if($POST['qG_ins']) {
00449                         //initialize array to work on, save special parameters
00450                         $ssArr = $this->getSubscript($POST['qG_ins']);
00451                         $workArr =& $this->queryConfig;
00452                         for($i=0;$i<sizeof($ssArr)-1;$i++) {
00453                                 $workArr =& $workArr[$ssArr[$i]];
00454                         }
00455                         // move all entries above position where new entry is to be inserted
00456                         for($j=sizeof($workArr);$j>$ssArr[$i];$j--) {
00457                                 $workArr[$j] = $workArr[$j-1];
00458                         }
00459                         //clear new entry position
00460                         unset($workArr[$ssArr[$i]+1]);
00461                         $workArr[$ssArr[$i]+1]['type'] = 'FIELD_';
00462                 }
00463 
00464                 // if move up...
00465                 if($POST['qG_up']) {
00466                         //initialize array to work on
00467                         $ssArr = $this->getSubscript($POST['qG_up']);
00468                         $workArr =& $this->queryConfig;
00469                         for($i=0;$i<sizeof($ssArr)-1;$i++) {
00470                                 $workArr =& $workArr[$ssArr[$i]];
00471                         }
00472                         //swap entries
00473                         $qG_tmp = $workArr[$ssArr[$i]];
00474                         $workArr[$ssArr[$i]] = $workArr[$ssArr[$i]-1];
00475                         $workArr[$ssArr[$i]-1] = $qG_tmp;
00476                 }
00477 
00478                 // if new level...
00479                 if($POST['qG_nl']) {
00480                         //initialize array to work on
00481                         $ssArr = $this->getSubscript($POST['qG_nl']);
00482                         $workArr =& $this->queryConfig;
00483                         for($i=0;$i<sizeof($ssArr)-1;$i++) {
00484                                 $workArr =& $workArr[$ssArr[$i]];
00485                         }
00486                         // Do stuff:
00487                         $tempEl = $workArr[$ssArr[$i]];
00488                         if (is_array($tempEl))  {
00489                                 if ($tempEl['type']!='newlevel')        {
00490                                         $workArr[$ssArr[$i]]=array(
00491                                                 'type' => 'newlevel',
00492                                                 'operator' => $tempEl['operator'],
00493                                                 'nl' => array($tempEl)
00494                                         );
00495                                 }
00496                         }
00497                 }
00498 
00499                 // if collapse level...
00500                 if($POST['qG_remnl']) {
00501                         //initialize array to work on
00502                         $ssArr = $this->getSubscript($POST['qG_remnl']);
00503                         $workArr =& $this->queryConfig;
00504                         for($i=0;$i<sizeof($ssArr)-1;$i++) {
00505                                 $workArr =& $workArr[$ssArr[$i]];
00506                         }
00507 
00508                         // Do stuff:
00509                         $tempEl = $workArr[$ssArr[$i]];
00510                         if (is_array($tempEl))  {
00511                                 if ($tempEl['type']=='newlevel')        {
00512                                         $a1 = array_slice($workArr,0,$ssArr[$i]);
00513                                         $a2 = array_slice($workArr,$ssArr[$i]);
00514                                         array_shift($a2);
00515                                         $a3 = $tempEl['nl'];
00516                                         $a3[0]['operator'] = $tempEl['operator'];
00517                                         $workArr=array_merge($a1,$a3,$a2);
00518                                 }
00519                         }
00520                 }
00521         }
00522 
00529         function cleanUpQueryConfig($queryConfig)       {
00530                 //since we dont traverse the array using numeric keys in the upcoming whileloop make sure it's fresh and clean before displaying
00531                 if (is_array($queryConfig))     {
00532                         ksort($queryConfig);
00533                 } else {
00534                         //queryConfig should never be empty!
00535                         if(!$queryConfig[0] || !$queryConfig[0]['type']) $queryConfig[0] = array('type'=>'FIELD_');
00536                 }
00537                         // Traverse:
00538                 reset($queryConfig);
00539                 $c=0;
00540                 $arrCount=0;
00541                 while(list($key,$conf)=each($queryConfig))      {
00542                         if(substr($conf['type'],0,6)=='FIELD_') {
00543                                 $fName = substr($conf['type'],6);
00544                                 $fType = $this->fields[$fName]['type'];
00545                         } elseif($conf['type']=='newlevel') {
00546                                 $fType = $conf['type'];
00547                         } else {
00548                                 $fType = 'ignore';
00549                         }
00550 //                      debug($fType);
00551                         switch($fType)  {
00552                                 case 'newlevel':
00553                                         if(!$queryConfig[$key]['nl']) $queryConfig[$key]['nl'][0]['type'] = 'FIELD_';
00554                                         $queryConfig[$key]['nl']=$this->cleanUpQueryConfig($queryConfig[$key]['nl']);
00555                                 break;
00556                                 case 'userdef':
00557                                         $queryConfig[$key]=$this->userDefCleanUp($queryConfig[$key]);
00558                                 break;
00559                                 case 'ignore':
00560                                 default:
00561 //                                      debug($queryConfig[$key]);
00562                                         $verifiedName=$this->verifyType($fName);
00563                                         $queryConfig[$key]['type']='FIELD_'.$this->verifyType($verifiedName);
00564 
00565                                         if($conf['comparison'] >> 5 != $this->comp_offsets[$fType]) $conf['comparison'] = $this->comp_offsets[$fType] << 5;
00566                                         $queryConfig[$key]['comparison']=$this->verifyComparison($conf['comparison'],$conf['negate']?1:0);
00567 
00568                                         $queryConfig[$key]['inputValue']=$this->cleanInputVal($queryConfig[$key]);
00569                                         $queryConfig[$key]['inputValue1']=$this->cleanInputVal($queryConfig[$key],1);
00570 
00571 //                                      debug($queryConfig[$key]);
00572                         break;
00573                         }
00574                 }
00575                 return $queryConfig;
00576         }
00577 
00586         function getFormElements($subLevel=0,$queryConfig='',$parent='')        {
00587                 $codeArr=array();
00588                 if (!is_array($queryConfig))    $queryConfig=$this->queryConfig;
00589 
00590                 reset($queryConfig);
00591                 $c=0;
00592                 $arrCount=0;
00593                 while(list($key,$conf)=each($queryConfig))      {
00594                         $subscript = $parent.'['.$key.']';
00595                         $lineHTML = '';
00596                         $lineHTML.=$this->mkOperatorSelect($this->name.$subscript,$conf['operator'],$c,($conf['type']!='FIELD_'));
00597                         if(substr($conf['type'],0,6)=='FIELD_') {
00598                                 $fName = substr($conf['type'],6);
00599                                 $this->fieldName = $fName;
00600                                 $fType = $this->fields[$fName]['type'];
00601                                 if($conf['comparison'] >> 5 != $this->comp_offsets[$fType]) $conf['comparison'] = $this->comp_offsets[$fType] << 5;
00602 
00603                                 //nasty nasty...
00604                                 //make sure queryConfig contains _actual_ comparevalue.
00605                                 //mkCompSelect don't care, but getQuery does.
00606                                 $queryConfig[$key]['comparison'] += (isset($conf['negate'])-($conf['comparison']%2));
00607 
00608                         } elseif($conf['type']=='newlevel') {
00609                                 $fType = $conf['type'];
00610                         } else {
00611                                 $fType = 'ignore';
00612                         }
00613                         switch($fType)  {
00614                                 case 'ignore':
00615                                 break;
00616                                 case 'newlevel':
00617                                         if(!$queryConfig[$key]['nl']) $queryConfig[$key]['nl'][0]['type'] = 'FIELD_';
00618                                         $lineHTML.='<input type="hidden" name="'.$this->name.$subscript.'[type]" value="newlevel">';
00619                                         $codeArr[$arrCount]['sub'] = $this->getFormElements($subLevel+1,$queryConfig[$key]['nl'],$subscript.'[nl]');
00620                                 break;
00621                                 case 'userdef':
00622                                          $lineHTML.=$this->userDef($this->name.$subscript,$conf,$fName,$fType);
00623                                 break;
00624                                 case 'date':
00625                                         $lineHTML.=$this->mkTypeSelect($this->name.$subscript.'[type]',$fName);
00626                                         $lineHTML.=$this->mkCompSelect($this->name.$subscript.'[comparison]',$conf['comparison'],$conf['negate']?1:0);
00627                                         $lineHTML.='<input type="checkbox"'.($conf['negate']?' checked':'').' name="'.$this->name.$subscript.'[negate]'.'" onClick="submit();">';
00628 
00629                                         if ($conf['comparison']==100 || $conf['comparison']==101)       {       // between
00630                                                 $lineHTML.='<input type="text" name="'.$this->name.$subscript.'[inputValue]_hr'.'" value="'.strftime('%e-%m-%Y', $conf['inputValue']).'" '.$GLOBALS['TBE_TEMPLATE']->formWidth(10).' onChange="typo3FormFieldGet(\''.$this->name.$subscript.'[inputValue]\', \'date\', \'\', 0,0);"><input type="hidden" value="'.htmlspecialchars($conf['inputValue']).'" name="'.$this->name.$subscript.'[inputValue]'.'">';
00631                                                 $lineHTML.='<input type="text" name="'.$this->name.$subscript.'[inputValue1]_hr'.'" value="'.strftime('%e-%m-%Y', $conf['inputValue1']).'" '.$GLOBALS['TBE_TEMPLATE']->formWidth(10).' onChange="typo3FormFieldGet(\''.$this->name.$subscript.'[inputValue1]\', \'date\', \'\', 0,0);"><input type="hidden" value="'.htmlspecialchars($conf['inputValue1']).'" name="'.$this->name.$subscript.'[inputValue1]'.'">';
00632                                                 $this->extJSCODE.='typo3FormFieldSet("'.$this->name.$subscript.'[inputValue]", '.date.', "", 0,0);';
00633                                                 $this->extJSCODE.='typo3FormFieldSet("'.$this->name.$subscript.'[inputValue1]", '.date.', "", 0,0);';
00634                                         } else {
00635                                                 $lineHTML.='<input type="text" name="'.$this->name.$subscript.'[inputValue]_hr'.'" value="'.strftime('%e-%m-%Y', $conf['inputValue']).'" '.$GLOBALS['TBE_TEMPLATE']->formWidth(10).' onChange="typo3FormFieldGet(\''.$this->name.$subscript.'[inputValue]\', \'date\', \'\', 0,0);"><input type="hidden" value="'.htmlspecialchars($conf['inputValue']).'" name="'.$this->name.$subscript.'[inputValue]'.'">';
00636                                                 $this->extJSCODE.='typo3FormFieldSet("'.$this->name.$subscript.'[inputValue]", '.date.', "", 0,0);';
00637                                         }
00638                                 break;
00639                                 case 'time':
00640                                         $lineHTML.=$this->mkTypeSelect($this->name.$subscript.'[type]', $fName);
00641                                         $lineHTML.=$this->mkCompSelect($this->name.$subscript.'[comparison]', $conf['comparison'], $conf['negate']?1:0);
00642 
00643                                         $lineHTML.='<input type="checkbox"'.($conf['negate']?' checked':'').' name="'.$this->name.$subscript.'[negate]'.'" onClick="submit();">';
00644                                         if ($conf['comparison']==100 || $conf['comparison']==101)       {       // between:
00645                                                 $lineHTML.='<input type="text" name="'.$this->name.$subscript.'[inputValue]_hr'.'" value="'.strftime('%H:%M %e-%m-%Y', $conf['inputValue']).'" '.$GLOBALS['TBE_TEMPLATE']->formWidth(10).' onChange="typo3FormFieldGet(\''.$this->name.$subscript.'[inputValue]\', \'datetime\', \'\', 0,0);"><input type="hidden" value="'.htmlspecialchars($conf['inputValue']).'" name="'.$this->name.$subscript.'[inputValue]'.'">';
00646                                                 $lineHTML.='<input type="text" name="'.$this->name.$subscript.'[inputValue1]_hr'.'" value="'.strftime('%H:%M %e-%m-%Y', $conf['inputValue1']).'" '.$GLOBALS['TBE_TEMPLATE']->formWidth(10).' onChange="typo3FormFieldGet(\''.$this->name.$subscript.'[inputValue1]\', \'datetime\', \'\', 0,0);"><input type="hidden" value="'.htmlspecialchars($conf['inputValue1']).'" name="'.$this->name.$subscript.'[inputValue1]'.'">';
00647                                                 $this->extJSCODE.='typo3FormFieldSet("'.$this->name.$subscript.'[inputValue]", '.datetime.', "", 0,0);';
00648                                                 $this->extJSCODE.='typo3FormFieldSet("'.$this->name.$subscript.'[inputValue1]", '.datetime.', "", 0,0);';
00649                                         } else {
00650                                                 $lineHTML.='<input type="text" name="'.$this->name.$subscript.'[inputValue]_hr'.'" value="'.strftime('%H:%M %e-%m-%Y', $conf['inputValue']).'" '.$GLOBALS['TBE_TEMPLATE']->formWidth(10).' onChange="typo3FormFieldGet(\''.$this->name.$subscript.'[inputValue]\', \'datetime\', \'\', 0,0);"><input type="hidden" value="'.htmlspecialchars($conf['inputValue']).'" name="'.$this->name.$subscript.'[inputValue]'.'">';
00651                                                 $this->extJSCODE.='typo3FormFieldSet("'.$this->name.$subscript.'[inputValue]", '.datetime.', "", 0,0);';
00652                                         }
00653                                 break;
00654                                 case 'multiple':
00655                                 case 'binary':
00656                                 case 'relation':
00657                                         $lineHTML.=$this->mkTypeSelect($this->name.$subscript.'[type]', $fName);
00658                                         $lineHTML.=$this->mkCompSelect($this->name.$subscript.'[comparison]', $conf['comparison'], $conf['negate']?1:0);
00659                                         $lineHTML.='<input type="checkbox"'.($conf['negate']?' checked':'').' name="'.$this->name.$subscript.'[negate]'.'" onClick="submit();">';
00660                                         if ($conf['comparison']==68 || $conf['comparison']==69 || $conf['comparison']==162 || $conf['comparison']==163) {
00661                                                 $lineHTML.='<select name="'.$this->name.$subscript.'[inputValue]'.'[]" style="vertical-align:top;" size="5" multiple>';
00662                                         } elseif ($conf['comparison']==66 || $conf['comparison']==67)   {
00663                                                 if (is_array($conf['inputValue']))      {
00664                                                         $conf['inputValue'] = implode(',', $conf['inputValue']);
00665                                                 }
00666                                                 $lineHTML.= '<input type="text" value="'.htmlspecialchars($conf['inputValue']).'" name="'.$this->name.$subscript.'[inputValue]'.'"'.$GLOBALS['TBE_TEMPLATE']->formWidth(10).'>';
00667                                         } else {
00668                                                 $lineHTML.= '<select name="'.$this->name.$subscript.'[inputValue]'.'" style="vertical-align:top;" onChange="submit();">';
00669                                         }
00670                                         if ($conf['comparison']!=66 && $conf['comparison']!=67) {
00671                                                 $lineHTML.= $this->makeOptionList($fName, $conf, $this->table);
00672                                                 $lineHTML.= '</select>';
00673                                         }
00674                                 break;
00675                                 case 'files':
00676                                         $lineHTML.= $this->mkTypeSelect($this->name.$subscript.'[type]', $fName);
00677                                         $lineHTML.= $this->mkCompSelect($this->name.$subscript.'[comparison]', $conf['comparison'], $conf['negate']?1:0);
00678                                         $lineHTML.= '<input type="checkbox"'.($conf['negate']?' checked':'').' name="'.$this->name.$subscript.'[negate]'.'" onClick="submit();">';
00679                                         if ($conf['comparison']==68 || $conf['comparison']==69) {
00680                                                 $lineHTML .= '<select name="'.$this->name.$subscript.'[inputValue]'.'[]" style="vertical-align:top;" size="5" multiple>';
00681                                         } else {
00682                                                 $lineHTML .= '<select name="'.$this->name.$subscript.'[inputValue]'.'" style="vertical-align:top;" onChange="submit();">';
00683                                         }
00684                                         $lineHTML .= '<option value=""></option>'.$this->makeOptionList($fName, $conf, $this->table);
00685                                         $lineHTML .= '</select>';
00686                                         if ($conf['comparison']==66 || $conf['comparison']==67) {
00687                                                 $lineHTML .= ' + <input type="text" value="'.htmlspecialchars($conf['inputValue1']).'" name="'.$this->name.$subscript.'[inputValue1]'.'"'.$GLOBALS['TBE_TEMPLATE']->formWidth(10).'>';
00688                                         }
00689                                 break;
00690                                 case 'boolean':
00691                                         $lineHTML .= $this->mkTypeSelect($this->name.$subscript.'[type]', $fName);
00692                                         $lineHTML .= $this->mkCompSelect($this->name.$subscript.'[comparison]', $conf['comparison'], $conf['negate']?1:0);
00693                                         $lineHTML .= '<input type="checkbox"'.($conf['negate']?' checked':'').' name="'.$this->name.$subscript.'[negate]'.'" onClick="submit();">';
00694                                         $lineHTML .= '<input type="hidden" value="1" name="'.$this->name.$subscript.'[inputValue]'.'"'.$GLOBALS['TBE_TEMPLATE']->formWidth(10).'>';
00695                                 break;
00696                                 default:
00697                                         $lineHTML .= $this->mkTypeSelect($this->name.$subscript.'[type]', $fName);
00698                                         $lineHTML .= $this->mkCompSelect($this->name.$subscript.'[comparison]', $conf['comparison'], $conf['negate']?1:0);
00699                                         $lineHTML .= '<input type="checkbox"'.($conf['negate']?' checked':'').' name="'.$this->name.$subscript.'[negate]'.'" onClick="submit();">';
00700                                         if ($conf['comparison']==37 || $conf['comparison']==36) {       // between:
00701                                                 $lineHTML.='<input type="text" value="'.htmlspecialchars($conf['inputValue']).'" name="'.$this->name.$subscript.'[inputValue]'.'"'.$GLOBALS['TBE_TEMPLATE']->formWidth(5).'>
00702                                                 <input type="text" value="'.htmlspecialchars($conf['inputValue1']).'" name="'.$this->name.$subscript.'[inputValue1]'.'"'.$GLOBALS['TBE_TEMPLATE']->formWidth(5).'>';    // onChange='submit();'
00703                                         } else {
00704                                                 $lineHTML.='<input type="text" value="'.htmlspecialchars($conf['inputValue']).'" name="'.$this->name.$subscript.'[inputValue]'.'"'.$GLOBALS['TBE_TEMPLATE']->formWidth(10).'>'; // onChange="submit();"
00705                                         }
00706                                 break;
00707                         }
00708                         if($fType != 'ignore') {
00709                                 $lineHTML .= $this->updateIcon();
00710                                 if ($loopcount) {
00711                                         $lineHTML .= '<input type="image" border="0" src="'.$GLOBALS['BACK_PATH'].'gfx/garbage.gif" class="absmiddle" width="11" height="12" hspace="3" vspace="3" title="Remove condition" name="qG_del'.$subscript.'">';
00712                                 }
00713                                 $lineHTML .= '<input type="image" border="0" src="'.$GLOBALS['BACK_PATH'].'gfx/add.gif" class="absmiddle" width="12" height="12" hspace="3" vspace="3" title="Add condition" name="qG_ins'.$subscript.'">';
00714                                 if($c!=0) $lineHTML.= '<input type="image" border="0" src="'.$GLOBALS['BACK_PATH'].'gfx/pil2up.gif" class="absmiddle" width="12" height="7" hspace="3" vspace="3" title="Move up" name="qG_up'.$subscript.'">';
00715 
00716                                 if($c!=0 && $fType!='newlevel') {
00717                                         $lineHTML.= '<input type="image" border="0" src="'.$GLOBALS['BACK_PATH'].'gfx/pil2right.gif" class="absmiddle" height="12" width="7" hspace="3" vspace="3" title="New level" name="qG_nl'.$subscript.'">';
00718                                 }
00719                                 if($fType=='newlevel') {
00720                                         $lineHTML.= '<input type="image" border="0" src="'.$GLOBALS['BACK_PATH'].'gfx/pil2left.gif" class="absmiddle" height="12" width="7" hspace="3" vspace="3" title="Collapse new level" name="qG_remnl'.$subscript.'">';
00721                                 }
00722 
00723                                 $codeArr[$arrCount]['html'] = $lineHTML;
00724                                 $codeArr[$arrCount]['query'] = $this->getQuerySingle($conf,$c>0?0:1);
00725                                 $arrCount++;
00726                                 $c++;
00727                         }
00728                         $loopcount = 1;
00729                 }
00730 //              $codeArr[$arrCount] .='<input type="hidden" name="CMD" value="displayQuery">';
00731                 $this->queryConfig = $queryConfig;
00732 //modifyHTMLColor($color,$R,$G,$B)
00733                 return $codeArr;
00734         }
00735 
00744         function makeOptionList($fN, $conf, $table)     {
00745                 $fieldSetup = $this->fields[$fN];
00746                 if ($fieldSetup['type']=='files')       {
00747                         if ($conf['comparison']==66 || $conf['comparison']==67) {
00748                                 $fileExtArray = explode(',', $fieldSetup['allowed']);
00749                                 natcasesort($fileExtArray);
00750                                 foreach ($fileExtArray as $fileExt)     {
00751                                         if (t3lib_div::inList($conf['inputValue'], $fileExt))   {
00752                                                 $out .= '<option value="'.$fileExt.'" selected>.'.$fileExt.'</option>';
00753                                         } else {
00754                                                 $out .= '<option value="'.$fileExt.'">.'.$fileExt.'</option>';
00755                                         }
00756                                 }
00757                         }
00758                         $d = dir(t3lib_div::getIndpEnv(TYPO3_DOCUMENT_ROOT).'/'.$fieldSetup['uploadfolder']);
00759                         while (false !== ($entry=$d->read()))   {
00760                                 if ($entry=='.' || $entry=='..')        {
00761                                         continue;
00762                                 }
00763                                 $fileArray[] = $entry;
00764                         }
00765                         $d->close();
00766                         natcasesort($fileArray);
00767                         foreach ($fileArray as $fileName)       {
00768                                 if (t3lib_div::inList($conf['inputValue'], $fileName))  {
00769                                         $out .= '<option value="'.$fileName.'" selected>'.$fileName.'</option>';
00770                                 } else {
00771                                         $out .= '<option value="'.$fileName.'">'.$fileName.'</option>';
00772                                 }
00773                         }
00774                 }
00775                 if ($fieldSetup['type']=='multiple')    {
00776                         foreach ($fieldSetup['items'] as $key=>$val)    {
00777                                 if (substr($val[0], 0, 4) == 'LLL:')    {
00778                                         $value = $GLOBALS['LANG']->sL($val[0]);
00779                                 } else {
00780                                         $value = $val[0];
00781                                 }
00782                                 if (t3lib_div::inList($conf['inputValue'], $val[1]))    {
00783                                         $out .= '<option value="'.$val[1].'" selected>'.$value.'</option>';
00784                                 } else {
00785                                         $out .= '<option value="'.$val[1].'">'.$value.'</option>';
00786                                 }
00787                         }
00788                 }
00789                 if ($fieldSetup['type']=='binary')      {
00790                         foreach ($fieldSetup['items'] as $key=>$val)    {
00791                                 if (substr($val[0], 0, 4)=='LLL:')      {
00792                                         $value = $GLOBALS['LANG']->sL($val[0]);
00793                                 } else {
00794                                         $value = $val[0];
00795                                 }
00796                                 if (t3lib_div::inList($conf['inputValue'], pow(2, $key)))       {
00797                                         $out .= '<option value="'.pow(2, $key).'" selected>'.$value.'</option>';
00798                                 } else {
00799                                         $out .= '<option value="'.pow(2, $key).'">'.$value.'</option>';
00800                                 }
00801                         }
00802                 }
00803                 if ($fieldSetup['type']=='relation')    {
00804                         if ($fieldSetup['items'])       {
00805                                 foreach ($fieldSetup['items'] as $key=>$val)    {
00806                                         if (substr($val[0], 0, 4) == 'LLL:')    {
00807                                                 $value = $GLOBALS['LANG']->sL($val[0]);
00808                                         } else {
00809                                                 $value = $val[0];
00810                                         }
00811                                         if (t3lib_div::inList($conf['inputValue'], $val[1]))    {
00812                                                 $out .= '<option value="'.$val[1].'" selected>'.$value.'</option>';
00813                                         } else {
00814                                                 $out .= '<option value="'.$val[1].'">'.$value.'</option>';
00815                                         }
00816                                 }
00817                         }
00818                         global $TCA;
00819                         if (stristr($fieldSetup['allowed'], ','))       {
00820                                 $from_table_Arr = explode(',', $fieldSetup['allowed']);
00821                                 $useTablePrefix = 1;
00822                                 if (!$fieldSetup['prepend_tname'])      {
00823                                         $checkres = $GLOBALS['TYPO3_DB']->exec_SELECTquery($fN, $table, t3lib_BEfunc::deleteClause($table), $groupBy = '', $orderBy = '', $limit = '');
00824                                         if ($checkres)  {
00825                                                 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($checkres)) {
00826                                                         if (stristr($row[$fN], ','))    {
00827                                                                 $checkContent = explode(',', $row[$fN]);
00828                                                                 foreach ($checkContent as $singleValue) {
00829                                                                         if (!stristr($singleValue, '_'))        {
00830                                                                                 $dontPrefixFirstTable = 1;
00831                                                                         }
00832                                                                 }
00833                                                         } else {
00834                                                                 $singleValue = $row[$fN];
00835                                                                 if (strlen($singleValue) && !stristr($singleValue, '_'))        {
00836                                                                         $dontPrefixFirstTable = 1;
00837                                                                 }
00838                                                         }
00839                                                 }
00840                                         }
00841                                 }
00842                         } else {
00843                                 $from_table_Arr[0] = $fieldSetup['allowed'];
00844                         }
00845                         if ($fieldSetup['prepend_tname'])       {
00846                                 $useTablePrefix = 1;
00847                         }
00848                         if ($fieldSetup['foreign_table'])       {
00849                                 $from_table_Arr[0] = $fieldSetup['foreign_table'];
00850                         }
00851                         $counter = 0;
00852                         while (list(, $from_table) = each($from_table_Arr))     {
00853                                 if (($useTablePrefix && !$dontPrefixFirstTable && $counter!=1) || $counter==1)  {
00854                                         $tablePrefix = $from_table.'_';
00855                                 }
00856                                 $counter = 1;
00857                                 if (is_array($TCA[$from_table]))        {
00858                                         t3lib_div::loadTCA($from_table);
00859                                         $labelField = $TCA[$from_table]['ctrl']['label'];
00860                                         $altLabelField = $TCA[$from_table]['ctrl']['label_alt'];
00861                                         if ($TCA[$from_table]['columns'][$labelField]['config']['items'])       {
00862                                                 foreach ($TCA[$from_table]['columns'][$labelField]['config']['items'] as $labelArray)   {
00863                                                         if (substr($labelArray[0], 0, 4) == 'LLL:')     {
00864                                                                 $labelFieldSelect[$labelArray[1]] = $GLOBALS['LANG']->sL($labelArray[0]);
00865                                                         } else {
00866                                                                 $labelFieldSelect[$labelArray[1]] = $labelArray[0];
00867                                                         }
00868                                                 }
00869                                                 $useSelectLabels = 1;
00870                                         }
00871                                         if ($TCA[$from_table]['columns'][$altLabelField]['config']['items'])    {
00872                                                 foreach ($TCA[$from_table]['columns'][$altLabelField]['config']['items'] as $altLabelArray)     {
00873                                                         if (substr($altLabelArray[0], 0, 4) == 'LLL:')  {
00874                                                                 $altLabelFieldSelect[$altLabelArray[1]] = $GLOBALS['LANG']->sL($altLabelArray[0]);
00875                                                         } else {
00876                                                                 $altLabelFieldSelect[$altLabelArray[1]] = $altLabelArray[0];
00877                                                         }
00878                                                 }
00879                                                 $useAltSelectLabels = 1;
00880                                         }
00881                                         $altLabelFieldSelect = $altLabelField ? ','.$altLabelField : '';
00882                                         $select_fields = 'uid,'.$labelField.$altLabelFieldSelect;
00883                                         if (!$GLOBALS['BE_USER']->isAdmin() && $GLOBALS['TYPO3_CONF_VARS']['BE']['lockBeUserToDBmounts'])       {
00884                                                 $webMounts = $GLOBALS['BE_USER']->returnWebmounts();
00885                                                 $perms_clause = $GLOBALS['BE_USER']->getPagePermsClause(1);
00886                                                 foreach ($webMounts as $key => $val)    {
00887                                                         if ($webMountPageTree)  {
00888                                                                 $webMountPageTreePrefix = ',';
00889                                                         }
00890                                                         $webMountPageTree .= $webMountPageTreePrefix.$this->getTreeList($val, 999, $begin = 0, $perms_clause);
00891                                                 }
00892                                                 if ($from_table=='pages')       {
00893                                                         $where_clause = 'uid IN ('.$webMountPageTree.') ';
00894                                                         if (!$GLOBALS['SOBE']->MOD_SETTINGS['show_deleted'])    {
00895                                                                 $where_clause .= t3lib_BEfunc::deleteClause($from_table).' AND'.$perms_clause;
00896                                                         }
00897                                                 } else {
00898                                                         $where_clause = 'pid IN ('.$webMountPageTree.') ';
00899                                                         if (!$GLOBALS['SOBE']->MOD_SETTINGS['show_deleted'])    {
00900                                                                 $where_clause .= t3lib_BEfunc::deleteClause($from_table);
00901                                                         }
00902                                                 }
00903                                         } else {
00904                                                 $where_clause = 'uid';
00905                                                 if (!$GLOBALS['SOBE']->MOD_SETTINGS['show_deleted'])    {
00906                                                         $where_clause .= t3lib_BEfunc::deleteClause($from_table);
00907                                                 }
00908                                         }
00909                                         $orderBy = 'uid';
00910                                         if (!$this->tableArray[$from_table])    {
00911                                                 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($select_fields, $from_table, $where_clause, $groupBy = '', $orderBy, $limit = '');
00912                                         }
00913                                         if ($res)       {
00914                                                 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))      {
00915                                                         $this->tableArray[$from_table][] = $row;
00916                                                 }
00917                                         }
00918                                         foreach ($this->tableArray[$from_table] as $key=>$val)  {
00919                                                 if ($useSelectLabels)   {
00920                                                         $outArray[$tablePrefix.$val['uid']] = htmlspecialchars($labelFieldSelect[$val[$labelField]]);
00921                                                 } elseif ($val[$labelField])    {
00922                                                         $outArray[$tablePrefix.$val['uid']] = htmlspecialchars($val[$labelField]);
00923                                                 } elseif ($useAltSelectLabels)  {
00924                                                         $outArray[$tablePrefix.$val['uid']] = htmlspecialchars($altLabelFieldSelect[$val[$altLabelField]]);
00925                                                 } else {
00926                                                         $outArray[$tablePrefix.$val['uid']] = htmlspecialchars($val[$altLabelField]);
00927                                                 }
00928                                         }
00929                                         if ($GLOBALS['SOBE']->MOD_SETTINGS['options_sortlabel'] && is_array($outArray)) {
00930                                                 natcasesort($outArray);
00931                                         }
00932                                 }
00933                         }
00934                         foreach ($outArray as $key2 => $val2)   {
00935                                 if (t3lib_div::inList($conf['inputValue'], $key2))      {
00936                                         $out .= '<option value="'.$key2.'" selected>['.$key2.'] '.$val2.'</option>';
00937                                 } else {
00938                                         $out .= '<option value="'.$key2.'">['.$key2.'] '.$val2.'</option>';
00939                                 }
00940                         }
00941                 }
00942                 return $out;
00943         }
00944 
00945 
00953         function printCodeArray($codeArr,$l=0)  {
00954                 reset($codeArr);
00955                 $line='';
00956                 if ($l)         $indent='<td style="vertical-align:top;"><img height="1" width="50"></td>';
00957                 $lf=$l*30;
00958                 $bgColor = t3lib_div::modifyHTMLColor($GLOBALS['TBE_TEMPLATE']->bgColor2,$lf,$lf,$lf);
00959                 while(list($k,$v)=each($codeArr))       {
00960                         $line.= '<tr>'.$indent.'<td bgcolor="'.$bgColor.'"'.$this->noWrap.'>'.$v['html'].'</td></tr>';
00961                         if ($this->enableQueryParts)    {$line.= '<tr>'.$indent.'<td>'.$this->formatQ($v['query']).'</td></tr>';}
00962                         if (is_array($v['sub']))        {
00963                                 $line.= '<tr>'.$indent.'<td'.$this->noWrap.'>'.$this->printCodeArray($v['sub'],$l+1).'</td></tr>';
00964                         }
00965                 }
00966                 $out='<table border="0" cellpadding="0" cellspacing="1">'.$line.'</table>';
00967                 return $out;
00968         }
00969 
00976         function formatQ($str)  {
00977                 return '<font size="1" face="verdana" color="maroon"><i>'.$str.'</i></font>';
00978         }
00979 
00989         function mkOperatorSelect($name,$op,$draw,$submit)      {
00990                 if ($draw)      {
00991                         $out='<select name="'.$name.'[operator]"'.($submit?' onChange="submit();"':'').'>';     //
00992                         $out.='<option value="AND"'.(!$op||$op=="AND" ? ' selected':'').'>'.$this->lang["AND"].'</option>';
00993                         $out.='<option value="OR"'.($op=='OR' ? ' selected':'').'>'.$this->lang['OR'].'</option>';
00994                         $out.='</select>';
00995                 } else {
00996                         $out.='<input type="hidden" value="'.$op.'" name="'.$name.'[operator]">';
00997                         $out.='<img src="clear.gif" height="1" width="47">';
00998 
00999                 }
01000                 return $out;
01001         }
01002 
01011         function mkTypeSelect($name,$fieldName,$prepend='FIELD_')       {
01012                 $out='<select name="'.$name.'" onChange="submit();">';
01013                 $out.='<option value=""></option>';
01014                 reset($this->fields);
01015                 while(list($key,)=each($this->fields)) {
01016                         if (!$fieldValue['exclude'] || $GLOBALS['BE_USER']->check('non_exclude_fields', $this->table.':'.$key)) {
01017                                 $label = $this->fields[$key]['label'];
01018                                 $label_alt = $this->fields[$key]['label_alt'];
01019                                 $out .= '<option value="'.$prepend.$key.'"'.($key==$fieldName ? ' selected' : '').'>'.$label.'</option>';
01020                         }
01021                 }
01022                 $out.='</select>';
01023                 return $out;
01024         }
01025 
01032         function verifyType($fieldName) {
01033                 reset($this->fields);
01034                 $first = '';
01035                 while(list($key,)=each($this->fields)) {
01036                         if (!$first)    $first = $key;
01037                         if ($key==$fieldName) return $key;
01038                 }
01039                 return $first;
01040         }
01041 
01049         function verifyComparison($comparison,$neg)     {
01050                 $compOffSet = $comparison >> 5;
01051                 $first=-1;
01052                 for($i=32*$compOffSet+$neg;$i<32*($compOffSet+1);$i+=2) {
01053                         if ($first==-1) $first = $i;
01054                         if (($i >> 1)==($comparison >> 1))      {
01055                                 return $i;
01056                         }
01057                 }
01058                 return $first;
01059         }
01060 
01068         function mkFieldToInputSelect($name,$fieldName) {
01069                 $out='<input type="Text" value="'.htmlspecialchars($fieldName).'" name="'.$name.'"'.$GLOBALS['TBE_TEMPLATE']->formWidth().'>'.$this->updateIcon();
01070                 $out.='<a href="#" onClick="document.forms[0][\''.$name.'\'].value=\'\';return false;"><img src="'.$GLOBALS['BACK_PATH'].'gfx/garbage.gif" class="absmiddle" width="11" height="12" hspace="3" vspace="3" title="Clear list" border="0"></a>';
01071                 $out.='<BR><select name="_fieldListDummy" size="5" onChange="document.forms[0][\''.$name.'\'].value+=\',\'+this.value">';
01072                 reset($this->fields);
01073                 while(list($key,)=each($this->fields)) {
01074                         if (!$fieldValue['exclude'] || $GLOBALS['BE_USER']->check('non_exclude_fields', $this->table.':'.$key)) {
01075                                 $label = $this->fields[$key]['label'];
01076                                 $label_alt = $this->fields[$key]['label_alt'];
01077                                 $out .= '<option value="'.$key.'"'.($key==$fieldName ? ' selected':'').'>'.$label.'</option>';
01078                         }
01079                 }
01080                 $out.='</select>';
01081                 return $out;
01082         }
01083 
01091         function mkTableSelect($name,$cur)      {
01092                 global $TCA;
01093                 $out='<select name="'.$name.'" onChange="submit();">';
01094                 $out.='<option value=""></option>';
01095                 reset($TCA);
01096                 while(list($tN)=each($TCA)) {
01097                         if ($GLOBALS['BE_USER']->check('tables_select',$tN))    {
01098                                 $out.='<option value="'.$tN.'"'.($tN==$cur ? ' selected':'').'>'.$GLOBALS['LANG']->sl($TCA[$tN]['ctrl']['title']).'</option>';
01099                         }
01100                 }
01101                 $out.='</select>';
01102                 return $out;
01103         }
01104 
01113         function mkCompSelect($name,$comparison,$neg)   {
01114                 $compOffSet = $comparison >> 5;
01115                 $out='<select name="'.$name.'" onChange="submit();">';
01116                 for($i=32*$compOffSet+$neg;$i<32*($compOffSet+1);$i+=2) {
01117                         if($this->lang['comparison'][$i.'_']) {
01118                                 $out.='<option value="'.$i.'"'.(($i >> 1)==($comparison >> 1) ? ' selected':'').'>'.$this->lang['comparison'][$i.'_'].'</option>';
01119                         }
01120                 }
01121                 $out.='</select>';
01122                 return $out;
01123         }
01124 
01131         function getSubscript($arr) {
01132                 while(is_array($arr)) {
01133                         reset($arr);
01134                         list($key,)=each($arr);
01135                         $retArr[] = $key;
01136                         $arr = $arr[$key];
01137                 }
01138                 return $retArr;
01139         }
01140 
01146         function initUserDef()  {
01147 
01148         }
01149 
01155         function userDef()      {
01156         }
01157 
01164         function userDefCleanUp($queryConfig)   {
01165                 return $queryConfig;
01166         }
01167 
01175         function getQuery ($queryConfig,$pad='') {
01176                 $qs = '';
01177                         // Since we don't traverse the array using numeric keys in the upcoming whileloop make sure it's fresh and clean
01178                 ksort($queryConfig);
01179                 reset($queryConfig);
01180                 $first=1;
01181                 while(list($key,$conf) = each($queryConfig)) {
01182                         switch($conf['type']) {
01183                                 case 'newlevel':
01184                                         $qs.=chr(10).$pad.trim($conf['operator']).' ('.$this->getQuery($queryConfig[$key]['nl'],$pad.'   ').chr(10).$pad.')';
01185                                 break;
01186                                 case 'userdef':
01187                                         $qs.=chr(10).$pad.getUserDefQuery($conf,$first);
01188                                 break;
01189                                 default:
01190                                         $qs.=chr(10).$pad.$this->getQuerySingle($conf,$first);
01191                                 break;
01192                         }
01193                         $first=0;
01194                 }
01195                 return $qs;
01196         }
01197 
01205         function getQuerySingle($conf,$first)   {
01206                 $prefix = $this->enablePrefix ? $this->table.'.' : '';
01207                 if (!$first)    {
01208                                 // Is it OK to insert the AND operator if none is set?
01209                         $qs .= trim(($conf['operator'] ? $conf['operator'] : 'AND')).' ';
01210                 }
01211                 $qsTmp = str_replace('#FIELD#', $prefix.trim(substr($conf['type'],6)), $this->compSQL[$conf['comparison']]);
01212                 $inputVal = $this->cleanInputVal($conf);
01213                 if ($conf['comparison']==68 || $conf['comparison']==69) {
01214                         $inputVal = explode(',', $inputVal);
01215                         foreach ($inputVal as $key => $fileName)        {
01216                                 $inputVal[$key] = "'".$fileName."'";
01217                         }
01218                         $inputVal = implode(',', $inputVal);
01219                         $qsTmp = str_replace('#VALUE#', $inputVal, $qsTmp);
01220                 } elseif ($conf['comparison']==162 || $conf['comparison']==163) {
01221                         $inputValArray = explode(',', $inputVal);
01222                         $inputVal = 0;
01223                         foreach ($inputValArray as $key=>$fileName)     {
01224                                 $inputVal += intval($fileName);
01225                         }
01226                         $qsTmp = str_replace('#VALUE#', $inputVal, $qsTmp);
01227                 } else {
01228                 $qsTmp = str_replace('#VALUE#', $GLOBALS['TYPO3_DB']->quoteStr($inputVal,$this->table), $qsTmp);
01229                 }
01230                 if ($conf['comparison']==37 || $conf['comparison']==36 || $conf['comparison']==66 || $conf['comparison']==67 || $conf['comparison']==100 || $conf['comparison']==101)   {       // between:
01231                         $inputVal = $this->cleanInputVal($conf,'1');
01232                         $qsTmp = str_replace('#VALUE1#', $GLOBALS['TYPO3_DB']->quoteStr($inputVal,$this->table), $qsTmp);
01233                 }
01234                 $qs .= trim($qsTmp);
01235                 return $qs;
01236         }
01237 
01245         function cleanInputVal($conf,$suffix='')        {
01246                 if(($conf['comparison'] >> 5==0) || ($conf['comparison']==32 || $conf['comparison']==33 || $conf['comparison']==64 || $conf['comparison']==65 || $conf['comparison']==66 || $conf['comparison']==67 || $conf['comparison']==96 || $conf['comparison']==97))     {
01247                         $inputVal = $conf['inputValue'.$suffix];
01248                 } elseif ($conf['comparison']==39 || $conf['comparison']==38) { // in list:
01249                         $inputVal = implode(',',t3lib_div::intExplode(',',$conf['inputValue'.$suffix]));
01250                 } elseif ($conf['comparison']==68 || $conf['comparison']==69 || $conf['comparison']==162 || $conf['comparison']==163) { // in list:
01251                         if (is_array($conf['inputValue'.$suffix])) {
01252                                 $inputVal = implode(',', $conf['inputValue'.$suffix]);
01253                         } elseif ($conf['inputValue'.$suffix]) {
01254                                 $inputVal = $conf['inputValue'.$suffix];
01255                         } else {
01256                                 $inputVal = 0;
01257                         }
01258                 } else {
01259                         $inputVal = doubleval($conf['inputValue'.$suffix]);
01260                 }
01261                 return $inputVal;
01262         }
01263 
01270         function getUserDefQuery ($qcArr) {
01271         }
01272 
01278         function updateIcon()   {
01279                 return '<input type="image" border="0" src="'.$GLOBALS['BACK_PATH'].'gfx/refresh_n.gif" class="absmiddle" width="14" height="14" hspace="3" vspace="3" title="Update" name="just_update">';
01280         }
01281 
01287         function getLabelCol()  {
01288                 global $TCA;
01289                 return $TCA[$this->table]['ctrl']['label'];
01290         }
01291 
01299         function makeSelectorTable($modSettings,$enableList='table,fields,query,group,order,limit')     {
01300                 $enableArr=explode(',',$enableList);
01301                         // Make output
01302                 $TDparams = ' class="bgColor5" nowrap';
01303 
01304                 if (in_array('table',$enableArr) && !$GLOBALS['BE_USER']->userTS['mod.']['dbint.']['disableSelectATable'])      {
01305                         $out='
01306                         <tr>
01307                                 <td'.$TDparams.'><strong>Select a table:</strong></td>
01308                                 <td'.$TDparams.'>'.$this->mkTableSelect('SET[queryTable]',$this->table).'</td>
01309                         </tr>';
01310                 }
01311                 if ($this->table)       {
01312 
01313                                 // Init fields:
01314                         $this->setAndCleanUpExternalLists('queryFields',$modSettings['queryFields'],'uid,'.$this->getLabelCol());
01315                         $this->setAndCleanUpExternalLists('queryGroup',$modSettings['queryGroup']);
01316                         $this->setAndCleanUpExternalLists('queryOrder',$modSettings['queryOrder'].','.$modSettings['queryOrder2']);
01317 
01318                                 // Limit:
01319                         $this->extFieldLists['queryLimit']=$modSettings['queryLimit'];
01320                         if (!$this->extFieldLists['queryLimit'])        $this->extFieldLists['queryLimit']=100;
01321                         $parts = t3lib_div::intExplode(',',$this->extFieldLists['queryLimit']);
01322                         if ($parts[1])  {
01323                                 $this->limitBegin = $parts[0];
01324                                 $this->limitLength = $parts[1];
01325                         } else {
01326                                 $this->limitLength = $this->extFieldLists['queryLimit'];
01327                         }
01328                         $this->extFieldLists['queryLimit'] = implode(',',array_slice($parts,0,2));
01329 
01330                                 // Insert Descending parts
01331                         if ($this->extFieldLists['queryOrder']) {
01332                                 $descParts = explode(',',$modSettings['queryOrderDesc'].','.$modSettings['queryOrder2Desc']);
01333                                 $orderParts = explode(',',$this->extFieldLists['queryOrder']);
01334                                 reset($orderParts);
01335                                 $reList=array();
01336                                 while(list($kk,$vv)=each($orderParts))  {
01337                                         $reList[]=$vv.($descParts[$kk]?' DESC':'');
01338                                 }
01339                                 $this->extFieldLists['queryOrder_SQL'] = implode(',',$reList);
01340                         }
01341 
01342                                 // Query Generator:
01343                         $this->procesData($modSettings['queryConfig'] ? unserialize($modSettings['queryConfig']) : '');
01344         //              debug($this->queryConfig);
01345                         $this->queryConfig = $this->cleanUpQueryConfig($this->queryConfig);
01346         //              debug($this->queryConfig);
01347                         $this->enableQueryParts = $modSettings['search_query_smallparts'];
01348 
01349                         $codeArr=$this->getFormElements();
01350                         $queryCode=$this->printCodeArray($codeArr);
01351 
01352                         if (in_array('fields',$enableArr) && !$GLOBALS['BE_USER']->userTS['mod.']['dbint.']['disableSelectFields'])     {
01353                                 $out.='
01354                                 <tr>
01355                                         <td'.$TDparams.'><strong>Select fields:</strong></td>
01356                                         <td'.$TDparams.'>'.$this->mkFieldToInputSelect('SET[queryFields]',$this->extFieldLists['queryFields']).'</td>
01357                                 </tr>';
01358                         }
01359                         if (in_array('query',$enableArr) && !$GLOBALS['BE_USER']->userTS['mod.']['dbint.']['disableMakeQuery']) {
01360                                 $out.='<tr>
01361                                         <td colspan="2"'.$TDparams.'><strong>Make Query:</strong></td>
01362                                 </tr>
01363                                 <tr>
01364                                         <td colspan="2">'.$queryCode.'</td>
01365                                 </tr>
01366                                 ';
01367                         }
01368                         if (in_array('group',$enableArr) && !$GLOBALS['BE_USER']->userTS['mod.']['dbint.']['disableGroupBy'])   {
01369                                 $out.='<tr>
01370                                         <td'.$TDparams.'><strong>Group By:</strong></td>
01371                                         <td'.$TDparams.'>'.$this->mkTypeSelect('SET[queryGroup]',$this->extFieldLists['queryGroup'],'').'</td>
01372                                 </tr>';
01373                         }
01374                         if (in_array('order',$enableArr) && !$GLOBALS['BE_USER']->userTS['mod.']['dbint.']['disableOrderBy'])   {
01375                                 $orderByArr = explode(',',$this->extFieldLists['queryOrder']);
01376                 //              debug($orderByArr);
01377                                 $orderBy='';
01378                                 $orderBy.=$this->mkTypeSelect('SET[queryOrder]',$orderByArr[0],'').
01379                                 '&nbsp;'.t3lib_BEfunc::getFuncCheck($GLOBALS['SOBE']->id,'SET[queryOrderDesc]',$modSettings['queryOrderDesc']).'&nbsp;Descending';
01380                                 if ($orderByArr[0])     {
01381                                         $orderBy.= '<BR>'.$this->mkTypeSelect('SET[queryOrder2]',$orderByArr[1],'').
01382                                         '&nbsp;'.t3lib_BEfunc::getFuncCheck($GLOBALS['SOBE']->id,'SET[queryOrder2Desc]',$modSettings['queryOrder2Desc']).'&nbsp;Descending';
01383                                 }
01384                                 $out.='<tr>
01385                                         <td'.$TDparams.'><strong>Order By:</strong></td>
01386                                         <td'.$TDparams.'>'.$orderBy.'</td>
01387                                 </tr>';
01388                         }
01389                         if (in_array('limit',$enableArr) && !$GLOBALS['BE_USER']->userTS['mod.']['dbint.']['disableLimit'])     {
01390                                 $limit = '<input type="Text" value="'.htmlspecialchars($this->extFieldLists['queryLimit']).'" name="SET[queryLimit]" id="queryLimit"'.$GLOBALS['TBE_TEMPLATE']->formWidth(10).'>'.$this->updateIcon();
01391 
01392                                 $prevLimit = ($this->limitBegin-$this->limitLength) < 0 ? 0 :
01393                                 $this->limitBegin-$this->limitLength;
01394                                 if ($this->limitBegin)  {
01395                                         $prevButton = '<input type="button" value="previous '.$this->limitLength.'" onclick=\'document.getElementById("queryLimit").value="'.$prevLimit.','.$this->limitLength.'";document.forms[0].submit();\'>';
01396                                 }
01397                                 if (!$this->limitLength)        {
01398                                         $this->limitLength = 100;
01399                                 }
01400                                 $nextLimit = $this->limitBegin + $this->limitLength;
01401                                 if ($nextLimit < 0) $nextLimit = 0;
01402                                 if ($nextLimit) {
01403                                         $nextButton = '<input type="button" value="next '.$this->limitLength.'" onclick=\'document.getElementById("queryLimit").value="'.$nextLimit.','.$this->limitLength.'";document.forms[0].submit();\'>';
01404                                 }
01405 
01406                                 $numberButtons = '<input type="button" value="10" onclick=\'document.getElementById("queryLimit").value="10";document.forms[0].submit();\'>';
01407                                 $numberButtons .= '<input type="button" value="20" onclick=\'document.getElementById("queryLimit").value="20";document.forms[0].submit();\'>';
01408                                 $numberButtons .= '<input type="button" value="50" onclick=\'document.getElementById("queryLimit").value="50";document.forms[0].submit();\'>';
01409                                 $numberButtons .= '<input type="button" value="100" onclick=\'document.getElementById("queryLimit").value="100";document.forms[0].submit();\'>';
01410                                 $out.='<tr>
01411                                         <td'.$TDparams.'><strong>Limit:</strong></td>
01412                                         <td'.$TDparams.'>'.$limit.$prevButton.$nextButton.'&nbsp;'.$numberButtons.'</td>
01413                                 </tr>
01414                                 ';
01415                         }
01416                 }
01417                 $out='<table border="0" cellpadding="3" cellspacing="1">'.$out.'</table>';
01418                 $out.=$this->JSbottom();
01419                 return $out;
01420         }
01421 
01431         function getTreeList($id, $depth, $begin=0, $perms_clause)      {
01432                 $depth = intval($depth);
01433                 $begin = intval($begin);
01434                 $id = intval($id);
01435                 if ($begin==0)  {
01436                         $theList = $id;
01437                 } else {
01438                         $theList = '';
01439                 }
01440                 if ($id && $depth > 0)  {
01441                         $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
01442                                 'uid',
01443                                 'pages',
01444                                 'pid='.$id.' '.t3lib_BEfunc::deleteClause('pages').' AND '.$perms_clause
01445                         );
01446                         while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))      {
01447                                 if ($begin <= 0)        {
01448                                         $theList .= ','.$row['uid'];
01449                                 }
01450                                 if ($depth > 1) {
01451                                         $theList .= $this->getTreeList($row['uid'], $depth-1, $begin-1, $perms_clause);
01452                                 }
01453                         }
01454                 }
01455                 return $theList;
01456         }
01457 
01465         function getSelectQuery($qString = '', $fN = '')        {
01466                 if (!$qString) $qString = $this->getQuery($this->queryConfig);
01467                         $qString = '('.$qString.')';
01468                 if (!$GLOBALS['BE_USER']->isAdmin() && $GLOBALS['TYPO3_CONF_VARS']['BE']['lockBeUserToDBmounts']) {
01469                         $webMounts = $GLOBALS['BE_USER']->returnWebmounts();
01470                         $perms_clause = $GLOBALS['BE_USER']->getPagePermsClause(1);
01471                         foreach($webMounts as $key => $val) {
01472                                 if ($webMountPageTree) {
01473                                         $webMountPageTreePrefix = ',';
01474                                         }
01475                                 $webMountPageTree .= $webMountPageTreePrefix.$this->getTreeList($val, 999, $begin = 0, $perms_clause);
01476                         }
01477                         if ($this->table == 'pages') {
01478                                 $qString .= ' AND uid IN ('.$webMountPageTree.')';
01479                         } else {
01480                                 $qString .= ' AND pid IN ('.$webMountPageTree.')';
01481                         }
01482                 }
01483                 $fieldlist = $this->extFieldLists['queryFields'].',pid,deleted';
01484                 if (!$GLOBALS['SOBE']->MOD_SETTINGS['show_deleted'])    {
01485                         $qString .= t3lib_BEfunc::deleteClause($this->table);
01486                 }
01487                 $query = $GLOBALS['TYPO3_DB']->SELECTquery(
01488                                                 $fieldlist,
01489                                                 $this->table,
01490                                                 $qString,
01491                                                 trim($this->extFieldLists['queryGroup']),
01492                                                 $this->extFieldLists['queryOrder'] ? trim($this->extFieldLists['queryOrder_SQL']) : '',
01493                                                 $this->extFieldLists['queryLimit']
01494                                         );
01495                 return $query;
01496         }
01497 
01504         function JSbottom($formname='forms[0]') {
01505                 if ($this->extJSCODE)   {
01506                         $out.='
01507                         <script language="javascript" type="text/javascript" src="'.$GLOBALS['BACK_PATH'].'../t3lib/jsfunc.evalfield.js"></script>
01508                         <script language="javascript" type="text/javascript">
01509                                 var evalFunc = new evalFunc;
01510                                 function typo3FormFieldSet(theField, evallist, is_in, checkbox, checkboxValue)  {
01511                                         var theFObj = new evalFunc_dummy (evallist,is_in, checkbox, checkboxValue);
01512                                         var theValue = document.'.$formname.'[theField].value;
01513                                         if (checkbox && theValue==checkboxValue)        {
01514                                                 document.'.$formname.'[theField+"_hr"].value="";
01515                                                 if (document.'.$formname.'[theField+"_cb"])     document.'.$formname.'[theField+"_cb"].checked = "";
01516                                         } else {
01517                                                 document.'.$formname.'[theField+"_hr"].value = evalFunc.outputObjValue(theFObj, theValue);
01518                                                 if (document.'.$formname.'[theField+"_cb"])     document.'.$formname.'[theField+"_cb"].checked = "on";
01519                                         }
01520                                 }
01521 
01528                                 function typo3FormFieldGet(theField, evallist, is_in, checkbox, checkboxValue, checkbox_off)    {
01529                                         var theFObj = new evalFunc_dummy (evallist,is_in, checkbox, checkboxValue);
01530                                         if (checkbox_off)       {
01531                                                 document.'.$formname.'[theField].value=checkboxValue;
01532                                         }else{
01533                                                 document.'.$formname.'[theField].value = evalFunc.evalObjValue(theFObj, document.'.$formname.'[theField+"_hr"].value);
01534                                         }
01535                                         typo3FormFieldSet(theField, evallist, is_in, checkbox, checkboxValue);
01536                                 }
01537                         </script>
01538                         <script language="javascript" type="text/javascript">'.$this->extJSCODE.'</script>';
01539                         return $out;
01540                 }
01541         }
01542 }
01543 
01544 
01545 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_querygenerator.php'])    {
01546         include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_querygenerator.php']);
01547 }
01548 ?>