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