Cleaned up code of scripts in t3lib/ and typo3/
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_querygenerator.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2001-2008 Christian Jul Jensen (christian@typo3.com)
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
18 *
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27 /**
28 * Class for generating front end for building queries
29 *
30 * $Id$
31 *
32 * @author Christian Jul Jensen <christian@typo3.com>
33 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
34 * @coauthor Jo Hasenau <info@cybercraft.de>
35 */
36 /**
37 * [CLASS/FUNCTION INDEX of SCRIPT]
38 *
39 *
40 *
41 * 98: class t3lib_queryGenerator
42 * 245: function makeFieldList()
43 * 273: function init($name,$table,$fieldList='')
44 * 410: function setAndCleanUpExternalLists($name,$list,$force='')
45 * 426: function procesData($qC='')
46 * 529: function cleanUpQueryConfig($queryConfig)
47 * 586: function getFormElements($subLevel=0,$queryConfig='',$parent='')
48 * 744: function makeOptionList($fN, $conf, $table)
49 * 953: function printCodeArray($codeArr,$l=0)
50 * 976: function formatQ($str)
51 * 989: function mkOperatorSelect($name,$op,$draw,$submit)
52 * 1011: function mkTypeSelect($name,$fieldName,$prepend='FIELD_')
53 * 1032: function verifyType($fieldName)
54 * 1049: function verifyComparison($comparison,$neg)
55 * 1068: function mkFieldToInputSelect($name,$fieldName)
56 * 1091: function mkTableSelect($name,$cur)
57 * 1113: function mkCompSelect($name,$comparison,$neg)
58 * 1131: function getSubscript($arr)
59 * 1146: function initUserDef()
60 * 1155: function userDef()
61 * 1164: function userDefCleanUp($queryConfig)
62 * 1175: function getQuery ($queryConfig,$pad='')
63 * 1205: function getQuerySingle($conf,$first)
64 * 1245: function cleanInputVal($conf,$suffix='')
65 * 1270: function getUserDefQuery ($qcArr)
66 * 1278: function updateIcon()
67 * 1287: function getLabelCol()
68 * 1299: function makeSelectorTable($modSettings,$enableList='table,fields,query,group,order,limit')
69 * 1431: function getTreeList($id, $depth, $begin=0, $perms_clause)
70 * 1465: function getSelectQuery($qString = '', $fN = '')
71 * 1504: function JSbottom($formname='forms[0]')
72 * 1510: function typo3FormFieldSet(theField, evallist, is_in, checkbox, checkboxValue)
73 * 1528: function typo3FormFieldGet(theField, evallist, is_in, checkbox, checkboxValue, checkbox_off)
74 *
75 * TOTAL FUNCTIONS: 32
76 * (This index is automatically created/updated by the extension "extdeveval")
77 *
78 */
79
80
81
82
83
84
85
86
87
88
89
90 /**
91 * Class for generating front end for building queries
92 *
93 * @author Christian Jul Jensen <christian@typo3.com>
94 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
95 * @package TYPO3
96 * @subpackage t3lib
97 */
98 class t3lib_queryGenerator {
99 var $lang = array(
100 'OR' => 'or',
101 'AND' => 'and',
102 'comparison' => array(
103 // Type = text offset = 0
104 '0_' => 'contains',
105 '1_' => 'does not contain',
106 '2_' => 'starts with',
107 '3_' => 'does not start with',
108 '4_' => 'ends with',
109 '5_' => 'does not end with',
110 '6_' => 'equals',
111 '7_' => 'does not equal',
112 // Type = number , offset = 32
113 '32_' => 'equals',
114 '33_' => 'does not equal',
115 '34_' => 'is greater than',
116 '35_' => 'is less than',
117 '36_' => 'is between',
118 '37_' => 'is not between',
119 '38_' => 'is in list',
120 '39_' => 'is not in list',
121 '40_' => 'binary AND equals',
122 '41_' => 'binary AND does not equal',
123 '42_' => 'binary OR equals',
124 '43_' => 'binary OR does not equal',
125 // Type = multiple, relation, files , offset = 64
126 '64_' => 'equals',
127 '65_' => 'does not equal',
128 '66_' => 'contains',
129 '67_' => 'does not contain',
130 '68_' => 'is in list',
131 '69_' => 'is not in list',
132 '70_' => 'binary AND equals',
133 '71_' => 'binary AND does not equal',
134 '72_' => 'binary OR equals',
135 '73_' => 'binary OR does not equal',
136 // Type = date,time offset = 96
137 '96_' => 'equals',
138 '97_' => 'does not equal',
139 '98_' => 'is greater than',
140 '99_' => 'is less than',
141 '100_' => 'is between',
142 '101_' => 'is not between',
143 '102_' => 'binary AND equals',
144 '103_' => 'binary AND does not equal',
145 '104_' => 'binary OR equals',
146 '105_' => 'binary OR does not equal',
147 // Type = boolean, offset = 128
148 '128_' => 'is True',
149 '129_' => 'is False',
150 // Type = binary , offset = 160
151 '160_' => 'equals',
152 '161_' => 'does not equal',
153 '162_' => 'contains',
154 '163_' => 'does not contain'
155 )
156 );
157
158 var $compSQL = array(
159 // Type = text offset = 0
160 '0' => "#FIELD# LIKE '%#VALUE#%'",
161 '1' => "#FIELD# NOT LIKE '%#VALUE#%'",
162 '2' => "#FIELD# LIKE '#VALUE#%'",
163 '3' => "#FIELD# NOT LIKE '#VALUE#%'",
164 '4' => "#FIELD# LIKE '%#VALUE#'",
165 '5' => "#FIELD# NOT LIKE '%#VALUE#'",
166 '6' => "#FIELD# = '#VALUE#'",
167 '7' => "#FIELD# != '#VALUE#'",
168 // Type = number, offset = 32
169 '32' => "#FIELD# = '#VALUE#'",
170 '33' => "#FIELD# != '#VALUE#'",
171 '34' => '#FIELD# > #VALUE#',
172 '35' => '#FIELD# < #VALUE#',
173 '36' => '#FIELD# >= #VALUE# AND #FIELD# <= #VALUE1#',
174 '37' => 'NOT (#FIELD# >= #VALUE# AND #FIELD# <= #VALUE1#)',
175 '38' => '#FIELD# IN (#VALUE#)',
176 '39' => '#FIELD# NOT IN (#VALUE#)',
177 '40' => '(#FIELD# & #VALUE#)=#VALUE#',
178 '41' => '(#FIELD# & #VALUE#)!=#VALUE#',
179 '42' => '(#FIELD# | #VALUE#)=#VALUE#',
180 '43' => '(#FIELD# | #VALUE#)!=#VALUE#',
181 // Type = multiple, relation, files , offset = 64
182 '64' => "#FIELD# = '#VALUE#'",
183 '65' => "#FIELD# != '#VALUE#'",
184 '66' => "#FIELD# LIKE '%#VALUE#%' AND #FIELD# LIKE '%#VALUE1#%'",
185 '67' => "(#FIELD# NOT LIKE '%#VALUE#%' OR #FIELD# NOT LIKE '%#VALUE1#%')",
186 '68' => '#FIELD# IN (#VALUE#)',
187 '69' => '#FIELD# NOT IN (#VALUE#)',
188 '70' => '(#FIELD# & #VALUE#)=#VALUE#',
189 '71' => '(#FIELD# & #VALUE#)!=#VALUE#',
190 '72' => '(#FIELD# | #VALUE#)=#VALUE#',
191 '73' => '(#FIELD# | #VALUE#)!=#VALUE#',
192 // Type = date, offset = 32
193 '96' => "#FIELD# = '#VALUE#'",
194 '97' => "#FIELD# != '#VALUE#'",
195 '98' => '#FIELD# > #VALUE#',
196 '99' => '#FIELD# < #VALUE#',
197 '100' => '#FIELD# >= #VALUE# AND #FIELD# <= #VALUE1#',
198 '101' => 'NOT (#FIELD# >= #VALUE# AND #FIELD# <= #VALUE1#)',
199 '102' => '(#FIELD# & #VALUE#)=#VALUE#',
200 '103' => '(#FIELD# & #VALUE#)!=#VALUE#',
201 '104' => '(#FIELD# | #VALUE#)=#VALUE#',
202 '105' => '(#FIELD# | #VALUE#)!=#VALUE#',
203 // Type = boolean, offset = 128
204 '128' => "#FIELD# = '1'",
205 '129' => "#FIELD# != '1'",
206 // Type = binary = 160
207 '160' => "#FIELD# = '#VALUE#'",
208 '161' => "#FIELD# != '#VALUE#'",
209 '162' => '(#FIELD# & #VALUE#)=#VALUE#',
210 '163' => '(#FIELD# & #VALUE#)=0'
211 );
212
213 var $comp_offsets = array(
214 'text' => 0,
215 'number' => 1,
216 'multiple' => 2,
217 'relation' => 2,
218 'files' => 2,
219 'date' => 3,
220 'time' => 3,
221 'boolean' => 4,
222 'binary' => 5
223 );
224 var $noWrap=' nowrap';
225
226 var $name; // Form data name prefix
227 var $table; // table for the query
228 var $fieldList; // field list
229 var $fields = array(); // Array of the fields possible
230 var $extFieldLists = array();
231 var $queryConfig=array(); // The query config
232 var $enablePrefix=0;
233 var $enableQueryParts = 0;
234 var $extJSCODE='';
235
236 protected $formName = '';
237
238
239
240
241
242
243
244 /**
245 * @return [type] ...
246 */
247 function makeFieldList() {
248 global $TCA;
249 $fieldListArr = array();
250 if (is_array($TCA[$this->table])) {
251 t3lib_div::loadTCA($this->table);
252 reset($TCA[$this->table]['columns']);
253 while(list($fN)=each($TCA[$this->table]['columns'])) {
254 $fieldListArr[]=$fN;
255 }
256 $fieldListArr[]='uid';
257 $fieldListArr[]='pid';
258 $fieldListArr[]='deleted';
259 if ($TCA[$this->table]['ctrl']['tstamp']) $fieldListArr[]=$TCA[$this->table]['ctrl']['tstamp'];
260 if ($TCA[$this->table]['ctrl']['crdate']) $fieldListArr[]=$TCA[$this->table]['ctrl']['crdate'];
261 if ($TCA[$this->table]['ctrl']['cruser_id']) $fieldListArr[]=$TCA[$this->table]['ctrl']['cruser_id'];
262 if ($TCA[$this->table]['ctrl']['sortby']) $fieldListArr[]=$TCA[$this->table]['ctrl']['sortby'];
263 }
264 return implode(',',$fieldListArr);
265 }
266
267 /**
268 * [Describe function...]
269 *
270 * @param [type] $name: ...
271 * @param [type] $table: ...
272 * @param [type] $fieldList: ...
273 * @return [type] ...
274 */
275 function init($name,$table,$fieldList='') {
276 global $TCA;
277
278 // Analysing the fields in the table.
279 if (is_array($TCA[$table])) {
280 t3lib_div::loadTCA($table);
281 $this->name = $name;
282 $this->table = $table;
283 $this->fieldList = $fieldList ? $fieldList : $this->makeFieldList();
284
285 $fieldArr = t3lib_div::trimExplode(',',$this->fieldList,1);
286 reset($fieldArr);
287 while(list(,$fN)=each($fieldArr)) {
288 $fC = $TCA[$this->table]['columns'][$fN];
289 $this->fields[$fN] = $fC['config'];
290 $this->fields[$fN]['exclude'] = $fC['exclude'];
291 if (is_array($fC) && $fC['label']) {
292 $this->fields[$fN]['label'] = ereg_replace(':$','',trim($GLOBALS['LANG']->sL($fC['label'])));
293 switch ($this->fields[$fN]['type']) {
294 case 'input':
295 if (eregi('int|year', $this->fields[$fN]['eval'])) {
296 $this->fields[$fN]['type']='number';
297 } elseif (eregi('time', $this->fields[$fN]['eval'])) {
298 $this->fields[$fN]['type'] = 'time';
299 } elseif (eregi('date', $this->fields[$fN]['eval'])) {
300 $this->fields[$fN]['type']='date';
301 } else {
302 $this->fields[$fN]['type']='text';
303 }
304 break;
305 case 'check':
306 if (!$this->fields[$fN]['items']) {
307 $this->fields[$fN]['type'] = 'boolean';
308 } else {
309 $this->fields[$fN]['type'] = 'binary';
310 }
311 break;
312 case 'radio':
313 $this->fields[$fN]['type'] = 'multiple';
314 break;
315 case 'select':
316 $this->fields[$fN]['type'] = 'multiple';
317 if ($this->fields[$fN]['foreign_table']) {
318 $this->fields[$fN]['type'] = 'relation';
319 }
320 if ($this->fields[$fN]['special']) {
321 $this->fields[$fN]['type'] = 'text';
322 }
323 break;
324 case 'group':
325 $this->fields[$fN]['type'] = 'files';
326 if ($this->fields[$fN]['internal_type'] == 'db') {
327 $this->fields[$fN]['type'] = 'relation';
328 }
329 break;
330 case 'user':
331 case 'flex':
332 case 'passthrough':
333 case 'none':
334 case 'text':
335 default:
336 $this->fields[$fN]['type']='text';
337 break;
338 }
339
340 } else {
341 $this->fields[$fN]['label']='[FIELD: '.$fN.']';
342 switch ($fN) {
343 case 'pid':
344 $this->fields[$fN]['type'] = 'relation';
345 $this->fields[$fN]['allowed'] = 'pages';
346 break;
347 case 'cruser_id':
348 $this->fields[$fN]['type'] = 'relation';
349 $this->fields[$fN]['allowed'] = 'be_users';
350 break;
351 case 'tstamp':
352 case 'crdate':
353 $this->fields[$fN]['type'] = 'time';
354 break;
355 case 'deleted':
356 $this->fields[$fN]['type'] = 'boolean';
357 break;
358 default:
359 $this->fields[$fN]['type'] = 'number';
360 break;
361 }
362 }
363 }
364 }
365
366 /* // EXAMPLE:
367 $this->queryConfig = array(
368 array(
369 'operator' => 'AND',
370 'type' => 'FIELD_spaceBefore',
371 ),
372 array(
373 'operator' => 'AND',
374 'type' => 'FIELD_records',
375 'negate' => 1,
376 'inputValue' => 'foo foo'
377 ),
378 array(
379 'type' => 'newlevel',
380 'nl' => array(
381 array(
382 'operator' => 'AND',
383 'type' => 'FIELD_spaceBefore',
384 'negate' => 1,
385 'inputValue' => 'foo foo'
386 ),
387 array(
388 'operator' => 'AND',
389 'type' => 'FIELD_records',
390 'negate' => 1,
391 'inputValue' => 'foo foo'
392 )
393 )
394 ),
395 array(
396 'operator' => 'OR',
397 'type' => 'FIELD_maillist',
398 )
399 );
400 */
401 $this->initUserDef();
402 }
403
404 /**
405 * [Describe function...]
406 *
407 * @param [type] $name: ...
408 * @param [type] $list: ...
409 * @param [type] $force: ...
410 * @return [type] ...
411 */
412 function setAndCleanUpExternalLists($name,$list,$force='') {
413 $fields = array_unique(t3lib_div::trimExplode(',',$list.','.$force,1));
414 reset($fields);
415 $reList=array();
416 while(list(,$fN)=each($fields)) {
417 if ($this->fields[$fN]) $reList[]=$fN;
418 }
419 $this->extFieldLists[$name]=implode(',',$reList);
420 }
421
422 /**
423 * [Describe function...]
424 *
425 * @param [type] $qC: ...
426 * @return [type] ...
427 */
428 function procesData($qC='') {
429 $this->queryConfig = $qC;
430
431 $POST = t3lib_div::_POST();
432
433 // if delete...
434 if($POST['qG_del']) {
435 //initialize array to work on, save special parameters
436 $ssArr = $this->getSubscript($POST['qG_del']);
437 $workArr =& $this->queryConfig;
438 for($i=0;$i<sizeof($ssArr)-1;$i++) {
439 $workArr =& $workArr[$ssArr[$i]];
440 }
441 // delete the entry and move the other entries
442 unset($workArr[$ssArr[$i]]);
443 for($j=$ssArr[$i];$j<sizeof($workArr);$j++) {
444 $workArr[$j] = $workArr[$j+1];
445 unset($workArr[$j+1]);
446 }
447 }
448
449 // if insert...
450 if($POST['qG_ins']) {
451 //initialize array to work on, save special parameters
452 $ssArr = $this->getSubscript($POST['qG_ins']);
453 $workArr =& $this->queryConfig;
454 for($i=0;$i<sizeof($ssArr)-1;$i++) {
455 $workArr =& $workArr[$ssArr[$i]];
456 }
457 // move all entries above position where new entry is to be inserted
458 for($j=sizeof($workArr);$j>$ssArr[$i];$j--) {
459 $workArr[$j] = $workArr[$j-1];
460 }
461 //clear new entry position
462 unset($workArr[$ssArr[$i]+1]);
463 $workArr[$ssArr[$i]+1]['type'] = 'FIELD_';
464 }
465
466 // if move up...
467 if($POST['qG_up']) {
468 //initialize array to work on
469 $ssArr = $this->getSubscript($POST['qG_up']);
470 $workArr =& $this->queryConfig;
471 for($i=0;$i<sizeof($ssArr)-1;$i++) {
472 $workArr =& $workArr[$ssArr[$i]];
473 }
474 //swap entries
475 $qG_tmp = $workArr[$ssArr[$i]];
476 $workArr[$ssArr[$i]] = $workArr[$ssArr[$i]-1];
477 $workArr[$ssArr[$i]-1] = $qG_tmp;
478 }
479
480 // if new level...
481 if($POST['qG_nl']) {
482 //initialize array to work on
483 $ssArr = $this->getSubscript($POST['qG_nl']);
484 $workArr =& $this->queryConfig;
485 for($i=0;$i<sizeof($ssArr)-1;$i++) {
486 $workArr =& $workArr[$ssArr[$i]];
487 }
488 // Do stuff:
489 $tempEl = $workArr[$ssArr[$i]];
490 if (is_array($tempEl)) {
491 if ($tempEl['type']!='newlevel') {
492 $workArr[$ssArr[$i]]=array(
493 'type' => 'newlevel',
494 'operator' => $tempEl['operator'],
495 'nl' => array($tempEl)
496 );
497 }
498 }
499 }
500
501 // if collapse level...
502 if($POST['qG_remnl']) {
503 //initialize array to work on
504 $ssArr = $this->getSubscript($POST['qG_remnl']);
505 $workArr =& $this->queryConfig;
506 for($i=0;$i<sizeof($ssArr)-1;$i++) {
507 $workArr =& $workArr[$ssArr[$i]];
508 }
509
510 // Do stuff:
511 $tempEl = $workArr[$ssArr[$i]];
512 if (is_array($tempEl)) {
513 if ($tempEl['type']=='newlevel') {
514 $a1 = array_slice($workArr,0,$ssArr[$i]);
515 $a2 = array_slice($workArr,$ssArr[$i]);
516 array_shift($a2);
517 $a3 = $tempEl['nl'];
518 $a3[0]['operator'] = $tempEl['operator'];
519 $workArr=array_merge($a1,$a3,$a2);
520 }
521 }
522 }
523 }
524
525 /**
526 * [Describe function...]
527 *
528 * @param [type] $queryConfig: ...
529 * @return [type] ...
530 */
531 function cleanUpQueryConfig($queryConfig) {
532 //since we dont traverse the array using numeric keys in the upcoming whileloop make sure it's fresh and clean before displaying
533 if (is_array($queryConfig)) {
534 ksort($queryConfig);
535 } else {
536 //queryConfig should never be empty!
537 if(!$queryConfig[0] || !$queryConfig[0]['type']) $queryConfig[0] = array('type'=>'FIELD_');
538 }
539 // Traverse:
540 reset($queryConfig);
541 $c=0;
542 $arrCount=0;
543 while(list($key,$conf)=each($queryConfig)) {
544 if(substr($conf['type'],0,6)=='FIELD_') {
545 $fName = substr($conf['type'],6);
546 $fType = $this->fields[$fName]['type'];
547 } elseif($conf['type']=='newlevel') {
548 $fType = $conf['type'];
549 } else {
550 $fType = 'ignore';
551 }
552 // debug($fType);
553 switch($fType) {
554 case 'newlevel':
555 if(!$queryConfig[$key]['nl']) $queryConfig[$key]['nl'][0]['type'] = 'FIELD_';
556 $queryConfig[$key]['nl']=$this->cleanUpQueryConfig($queryConfig[$key]['nl']);
557 break;
558 case 'userdef':
559 $queryConfig[$key]=$this->userDefCleanUp($queryConfig[$key]);
560 break;
561 case 'ignore':
562 default:
563 // debug($queryConfig[$key]);
564 $verifiedName=$this->verifyType($fName);
565 $queryConfig[$key]['type']='FIELD_'.$this->verifyType($verifiedName);
566
567 if($conf['comparison'] >> 5 != $this->comp_offsets[$fType]) $conf['comparison'] = $this->comp_offsets[$fType] << 5;
568 $queryConfig[$key]['comparison']=$this->verifyComparison($conf['comparison'],$conf['negate']?1:0);
569
570 $queryConfig[$key]['inputValue']=$this->cleanInputVal($queryConfig[$key]);
571 $queryConfig[$key]['inputValue1']=$this->cleanInputVal($queryConfig[$key],1);
572
573 // debug($queryConfig[$key]);
574 break;
575 }
576 }
577 return $queryConfig;
578 }
579
580 /**
581 * [Describe function...]
582 *
583 * @param [type] $subLevel: ...
584 * @param [type] $queryConfig: ...
585 * @param [type] $parent: ...
586 * @return [type] ...
587 */
588 function getFormElements($subLevel=0,$queryConfig='',$parent='') {
589 $codeArr=array();
590 if (!is_array($queryConfig)) $queryConfig=$this->queryConfig;
591
592 reset($queryConfig);
593 $c=0;
594 $arrCount=0;
595 while(list($key,$conf)=each($queryConfig)) {
596 $subscript = $parent.'['.$key.']';
597 $lineHTML = '';
598 $lineHTML.=$this->mkOperatorSelect($this->name.$subscript,$conf['operator'],$c,($conf['type']!='FIELD_'));
599 if(substr($conf['type'],0,6)=='FIELD_') {
600 $fName = substr($conf['type'],6);
601 $this->fieldName = $fName;
602 $fType = $this->fields[$fName]['type'];
603 if($conf['comparison'] >> 5 != $this->comp_offsets[$fType]) $conf['comparison'] = $this->comp_offsets[$fType] << 5;
604
605 //nasty nasty...
606 //make sure queryConfig contains _actual_ comparevalue.
607 //mkCompSelect don't care, but getQuery does.
608 $queryConfig[$key]['comparison'] += (isset($conf['negate'])-($conf['comparison']%2));
609
610 } elseif($conf['type']=='newlevel') {
611 $fType = $conf['type'];
612 } else {
613 $fType = 'ignore';
614 }
615 switch($fType) {
616 case 'ignore':
617 break;
618 case 'newlevel':
619 if(!$queryConfig[$key]['nl']) $queryConfig[$key]['nl'][0]['type'] = 'FIELD_';
620 $lineHTML.='<input type="hidden" name="'.$this->name.$subscript.'[type]" value="newlevel">';
621 $codeArr[$arrCount]['sub'] = $this->getFormElements($subLevel+1,$queryConfig[$key]['nl'],$subscript.'[nl]');
622 break;
623 case 'userdef':
624 $lineHTML.=$this->userDef($this->name.$subscript,$conf,$fName,$fType);
625 break;
626 case 'date':
627 $lineHTML.=$this->mkTypeSelect($this->name.$subscript.'[type]',$fName);
628 $lineHTML.=$this->mkCompSelect($this->name.$subscript.'[comparison]',$conf['comparison'],$conf['negate']?1:0);
629 $lineHTML.='<input type="checkbox"'.($conf['negate']?' checked':'').' name="'.$this->name.$subscript.'[negate]'.'" onClick="submit();">';
630
631 if ($conf['comparison']==100 || $conf['comparison']==101) { // between
632 $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]'.'">';
633 $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]'.'">';
634 $this->extJSCODE.='typo3form.fieldSet("'.$this->name.$subscript.'[inputValue]", "date", "", 0,0);';
635 $this->extJSCODE.='typo3form.fieldSet("'.$this->name.$subscript.'[inputValue1]", "date", "", 0,0);';
636 } else {
637 $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]'.'">';
638 $this->extJSCODE.='typo3form.fieldSet("'.$this->name.$subscript.'[inputValue]", "date", "", 0,0);';
639 }
640 break;
641 case 'time':
642 $lineHTML.=$this->mkTypeSelect($this->name.$subscript.'[type]', $fName);
643 $lineHTML.=$this->mkCompSelect($this->name.$subscript.'[comparison]', $conf['comparison'], $conf['negate']?1:0);
644
645 $lineHTML.='<input type="checkbox"'.($conf['negate']?' checked':'').' name="'.$this->name.$subscript.'[negate]'.'" onClick="submit();">';
646 if ($conf['comparison']==100 || $conf['comparison']==101) { // between:
647 $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]'.'">';
648 $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]'.'">';
649 $this->extJSCODE.='typo3form.fieldSet("'.$this->name.$subscript.'[inputValue]", "datetime", "", 0,0);';
650 $this->extJSCODE.='typo3form.fieldSet("'.$this->name.$subscript.'[inputValue1]", "datetime", "", 0,0);';
651 } else {
652 $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]'.'">';
653 $this->extJSCODE.='typo3form.fieldSet("'.$this->name.$subscript.'[inputValue]", "datetime", "", 0,0);';
654 }
655 break;
656 case 'multiple':
657 case 'binary':
658 case 'relation':
659 $lineHTML.=$this->mkTypeSelect($this->name.$subscript.'[type]', $fName);
660 $lineHTML.=$this->mkCompSelect($this->name.$subscript.'[comparison]', $conf['comparison'], $conf['negate']?1:0);
661 $lineHTML.='<input type="checkbox"'.($conf['negate']?' checked':'').' name="'.$this->name.$subscript.'[negate]'.'" onClick="submit();">';
662 if ($conf['comparison']==68 || $conf['comparison']==69 || $conf['comparison']==162 || $conf['comparison']==163) {
663 $lineHTML.='<select name="'.$this->name.$subscript.'[inputValue]'.'[]" style="vertical-align:top;" size="5" multiple>';
664 } elseif ($conf['comparison']==66 || $conf['comparison']==67) {
665 if (is_array($conf['inputValue'])) {
666 $conf['inputValue'] = implode(',', $conf['inputValue']);
667 }
668 $lineHTML.= '<input type="text" value="'.htmlspecialchars($conf['inputValue']).'" name="'.$this->name.$subscript.'[inputValue]'.'"'.$GLOBALS['TBE_TEMPLATE']->formWidth(10).'>';
669 } else {
670 $lineHTML.= '<select name="'.$this->name.$subscript.'[inputValue]'.'" style="vertical-align:top;" onChange="submit();">';
671 }
672 if ($conf['comparison']!=66 && $conf['comparison']!=67) {
673 $lineHTML.= $this->makeOptionList($fName, $conf, $this->table);
674 $lineHTML.= '</select>';
675 }
676 break;
677 case 'files':
678 $lineHTML.= $this->mkTypeSelect($this->name.$subscript.'[type]', $fName);
679 $lineHTML.= $this->mkCompSelect($this->name.$subscript.'[comparison]', $conf['comparison'], $conf['negate']?1:0);
680 $lineHTML.= '<input type="checkbox"'.($conf['negate']?' checked':'').' name="'.$this->name.$subscript.'[negate]'.'" onClick="submit();">';
681 if ($conf['comparison']==68 || $conf['comparison']==69) {
682 $lineHTML .= '<select name="'.$this->name.$subscript.'[inputValue]'.'[]" style="vertical-align:top;" size="5" multiple>';
683 } else {
684 $lineHTML .= '<select name="'.$this->name.$subscript.'[inputValue]'.'" style="vertical-align:top;" onChange="submit();">';
685 }
686 $lineHTML .= '<option value=""></option>'.$this->makeOptionList($fName, $conf, $this->table);
687 $lineHTML .= '</select>';
688 if ($conf['comparison']==66 || $conf['comparison']==67) {
689 $lineHTML .= ' + <input type="text" value="'.htmlspecialchars($conf['inputValue1']).'" name="'.$this->name.$subscript.'[inputValue1]'.'"'.$GLOBALS['TBE_TEMPLATE']->formWidth(10).'>';
690 }
691 break;
692 case 'boolean':
693 $lineHTML .= $this->mkTypeSelect($this->name.$subscript.'[type]', $fName);
694 $lineHTML .= $this->mkCompSelect($this->name.$subscript.'[comparison]', $conf['comparison'], $conf['negate']?1:0);
695 $lineHTML .= '<input type="checkbox"'.($conf['negate']?' checked':'').' name="'.$this->name.$subscript.'[negate]'.'" onClick="submit();">';
696 $lineHTML .= '<input type="hidden" value="1" name="'.$this->name.$subscript.'[inputValue]'.'"'.$GLOBALS['TBE_TEMPLATE']->formWidth(10).'>';
697 break;
698 default:
699 $lineHTML .= $this->mkTypeSelect($this->name.$subscript.'[type]', $fName);
700 $lineHTML .= $this->mkCompSelect($this->name.$subscript.'[comparison]', $conf['comparison'], $conf['negate']?1:0);
701 $lineHTML .= '<input type="checkbox"'.($conf['negate']?' checked':'').' name="'.$this->name.$subscript.'[negate]'.'" onClick="submit();">';
702 if ($conf['comparison']==37 || $conf['comparison']==36) { // between:
703 $lineHTML.='<input type="text" value="'.htmlspecialchars($conf['inputValue']).'" name="'.$this->name.$subscript.'[inputValue]'.'"'.$GLOBALS['TBE_TEMPLATE']->formWidth(5).'>
704 <input type="text" value="'.htmlspecialchars($conf['inputValue1']).'" name="'.$this->name.$subscript.'[inputValue1]'.'"'.$GLOBALS['TBE_TEMPLATE']->formWidth(5).'>'; // onChange='submit();'
705 } else {
706 $lineHTML.='<input type="text" value="'.htmlspecialchars($conf['inputValue']).'" name="'.$this->name.$subscript.'[inputValue]'.'"'.$GLOBALS['TBE_TEMPLATE']->formWidth(10).'>'; // onChange="submit();"
707 }
708 break;
709 }
710 if($fType != 'ignore') {
711 $lineHTML .= $this->updateIcon();
712 if ($loopcount) {
713 $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.'">';
714 }
715 $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.'">';
716 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.'">';
717
718 if($c!=0 && $fType!='newlevel') {
719 $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.'">';
720 }
721 if($fType=='newlevel') {
722 $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.'">';
723 }
724
725 $codeArr[$arrCount]['html'] = $lineHTML;
726 $codeArr[$arrCount]['query'] = $this->getQuerySingle($conf,$c>0?0:1);
727 $arrCount++;
728 $c++;
729 }
730 $loopcount = 1;
731 }
732 // $codeArr[$arrCount] .='<input type="hidden" name="CMD" value="displayQuery">';
733 $this->queryConfig = $queryConfig;
734 //modifyHTMLColor($color,$R,$G,$B)
735 return $codeArr;
736 }
737
738 /**
739 * [Describe function...]
740 *
741 * @param [type] $codeArr: ...
742 * @param [type] $l: ...
743 * @param [type] $table: ...
744 * @return [type] ...
745 */
746 function makeOptionList($fN, $conf, $table) {
747 $fieldSetup = $this->fields[$fN];
748 if ($fieldSetup['type']=='files') {
749 if ($conf['comparison']==66 || $conf['comparison']==67) {
750 $fileExtArray = explode(',', $fieldSetup['allowed']);
751 natcasesort($fileExtArray);
752 foreach ($fileExtArray as $fileExt) {
753 if (t3lib_div::inList($conf['inputValue'], $fileExt)) {
754 $out .= '<option value="'.$fileExt.'" selected>.'.$fileExt.'</option>';
755 } else {
756 $out .= '<option value="'.$fileExt.'">.'.$fileExt.'</option>';
757 }
758 }
759 }
760 $d = dir(t3lib_div::getIndpEnv(TYPO3_DOCUMENT_ROOT).'/'.$fieldSetup['uploadfolder']);
761 while (false !== ($entry=$d->read())) {
762 if ($entry=='.' || $entry=='..') {
763 continue;
764 }
765 $fileArray[] = $entry;
766 }
767 $d->close();
768 natcasesort($fileArray);
769 foreach ($fileArray as $fileName) {
770 if (t3lib_div::inList($conf['inputValue'], $fileName)) {
771 $out .= '<option value="'.$fileName.'" selected>'.$fileName.'</option>';
772 } else {
773 $out .= '<option value="'.$fileName.'">'.$fileName.'</option>';
774 }
775 }
776 }
777 if ($fieldSetup['type']=='multiple') {
778 foreach ($fieldSetup['items'] as $key=>$val) {
779 if (substr($val[0], 0, 4) == 'LLL:') {
780 $value = $GLOBALS['LANG']->sL($val[0]);
781 } else {
782 $value = $val[0];
783 }
784 if (t3lib_div::inList($conf['inputValue'], $val[1])) {
785 $out .= '<option value="'.$val[1].'" selected>'.$value.'</option>';
786 } else {
787 $out .= '<option value="'.$val[1].'">'.$value.'</option>';
788 }
789 }
790 }
791 if ($fieldSetup['type']=='binary') {
792 foreach ($fieldSetup['items'] as $key=>$val) {
793 if (substr($val[0], 0, 4)=='LLL:') {
794 $value = $GLOBALS['LANG']->sL($val[0]);
795 } else {
796 $value = $val[0];
797 }
798 if (t3lib_div::inList($conf['inputValue'], pow(2, $key))) {
799 $out .= '<option value="'.pow(2, $key).'" selected>'.$value.'</option>';
800 } else {
801 $out .= '<option value="'.pow(2, $key).'">'.$value.'</option>';
802 }
803 }
804 }
805 if ($fieldSetup['type']=='relation') {
806 if ($fieldSetup['items']) {
807 foreach ($fieldSetup['items'] as $key=>$val) {
808 if (substr($val[0], 0, 4) == 'LLL:') {
809 $value = $GLOBALS['LANG']->sL($val[0]);
810 } else {
811 $value = $val[0];
812 }
813 if (t3lib_div::inList($conf['inputValue'], $val[1])) {
814 $out .= '<option value="'.$val[1].'" selected>'.$value.'</option>';
815 } else {
816 $out .= '<option value="'.$val[1].'">'.$value.'</option>';
817 }
818 }
819 }
820 global $TCA;
821 if (stristr($fieldSetup['allowed'], ',')) {
822 $from_table_Arr = explode(',', $fieldSetup['allowed']);
823 $useTablePrefix = 1;
824 if (!$fieldSetup['prepend_tname']) {
825 $checkres = $GLOBALS['TYPO3_DB']->exec_SELECTquery($fN, $table, t3lib_BEfunc::deleteClause($table), $groupBy = '', $orderBy = '', $limit = '');
826 if ($checkres) {
827 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($checkres)) {
828 if (stristr($row[$fN], ',')) {
829 $checkContent = explode(',', $row[$fN]);
830 foreach ($checkContent as $singleValue) {
831 if (!stristr($singleValue, '_')) {
832 $dontPrefixFirstTable = 1;
833 }
834 }
835 } else {
836 $singleValue = $row[$fN];
837 if (strlen($singleValue) && !stristr($singleValue, '_')) {
838 $dontPrefixFirstTable = 1;
839 }
840 }
841 }
842 }
843 }
844 } else {
845 $from_table_Arr[0] = $fieldSetup['allowed'];
846 }
847 if ($fieldSetup['prepend_tname']) {
848 $useTablePrefix = 1;
849 }
850 if ($fieldSetup['foreign_table']) {
851 $from_table_Arr[0] = $fieldSetup['foreign_table'];
852 }
853 $counter = 0;
854 while (list(, $from_table) = each($from_table_Arr)) {
855 if (($useTablePrefix && !$dontPrefixFirstTable && $counter!=1) || $counter==1) {
856 $tablePrefix = $from_table.'_';
857 }
858 $counter = 1;
859 if (is_array($TCA[$from_table])) {
860 t3lib_div::loadTCA($from_table);
861 $labelField = $TCA[$from_table]['ctrl']['label'];
862 $altLabelField = $TCA[$from_table]['ctrl']['label_alt'];
863 if ($TCA[$from_table]['columns'][$labelField]['config']['items']) {
864 foreach ($TCA[$from_table]['columns'][$labelField]['config']['items'] as $labelArray) {
865 if (substr($labelArray[0], 0, 4) == 'LLL:') {
866 $labelFieldSelect[$labelArray[1]] = $GLOBALS['LANG']->sL($labelArray[0]);
867 } else {
868 $labelFieldSelect[$labelArray[1]] = $labelArray[0];
869 }
870 }
871 $useSelectLabels = 1;
872 }
873 if ($TCA[$from_table]['columns'][$altLabelField]['config']['items']) {
874 foreach ($TCA[$from_table]['columns'][$altLabelField]['config']['items'] as $altLabelArray) {
875 if (substr($altLabelArray[0], 0, 4) == 'LLL:') {
876 $altLabelFieldSelect[$altLabelArray[1]] = $GLOBALS['LANG']->sL($altLabelArray[0]);
877 } else {
878 $altLabelFieldSelect[$altLabelArray[1]] = $altLabelArray[0];
879 }
880 }
881 $useAltSelectLabels = 1;
882 }
883 $altLabelFieldSelect = $altLabelField ? ','.$altLabelField : '';
884 $select_fields = 'uid,'.$labelField.$altLabelFieldSelect;
885 if (!$GLOBALS['BE_USER']->isAdmin() && $GLOBALS['TYPO3_CONF_VARS']['BE']['lockBeUserToDBmounts']) {
886 $webMounts = $GLOBALS['BE_USER']->returnWebmounts();
887 $perms_clause = $GLOBALS['BE_USER']->getPagePermsClause(1);
888 foreach ($webMounts as $key => $val) {
889 if ($webMountPageTree) {
890 $webMountPageTreePrefix = ',';
891 }
892 $webMountPageTree .= $webMountPageTreePrefix.$this->getTreeList($val, 999, $begin = 0, $perms_clause);
893 }
894 if ($from_table=='pages') {
895 $where_clause = 'uid IN ('.$webMountPageTree.') ';
896 if (!$GLOBALS['SOBE']->MOD_SETTINGS['show_deleted']) {
897 $where_clause .= t3lib_BEfunc::deleteClause($from_table).' AND'.$perms_clause;
898 }
899 } else {
900 $where_clause = 'pid IN ('.$webMountPageTree.') ';
901 if (!$GLOBALS['SOBE']->MOD_SETTINGS['show_deleted']) {
902 $where_clause .= t3lib_BEfunc::deleteClause($from_table);
903 }
904 }
905 } else {
906 $where_clause = 'uid';
907 if (!$GLOBALS['SOBE']->MOD_SETTINGS['show_deleted']) {
908 $where_clause .= t3lib_BEfunc::deleteClause($from_table);
909 }
910 }
911 $orderBy = 'uid';
912 if (!$this->tableArray[$from_table]) {
913 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($select_fields, $from_table, $where_clause, $groupBy = '', $orderBy, $limit = '');
914 }
915 if ($res) {
916 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
917 $this->tableArray[$from_table][] = $row;
918 }
919 }
920 foreach ($this->tableArray[$from_table] as $key=>$val) {
921 if ($useSelectLabels) {
922 $outArray[$tablePrefix.$val['uid']] = htmlspecialchars($labelFieldSelect[$val[$labelField]]);
923 } elseif ($val[$labelField]) {
924 $outArray[$tablePrefix.$val['uid']] = htmlspecialchars($val[$labelField]);
925 } elseif ($useAltSelectLabels) {
926 $outArray[$tablePrefix.$val['uid']] = htmlspecialchars($altLabelFieldSelect[$val[$altLabelField]]);
927 } else {
928 $outArray[$tablePrefix.$val['uid']] = htmlspecialchars($val[$altLabelField]);
929 }
930 }
931 if ($GLOBALS['SOBE']->MOD_SETTINGS['options_sortlabel'] && is_array($outArray)) {
932 natcasesort($outArray);
933 }
934 }
935 }
936 foreach ($outArray as $key2 => $val2) {
937 if (t3lib_div::inList($conf['inputValue'], $key2)) {
938 $out .= '<option value="'.$key2.'" selected>['.$key2.'] '.$val2.'</option>';
939 } else {
940 $out .= '<option value="'.$key2.'">['.$key2.'] '.$val2.'</option>';
941 }
942 }
943 }
944 return $out;
945 }
946
947
948 /**
949 * [Describe function...]
950 *
951 * @param [type] $codeArr: ...
952 * @param [type] $l: ...
953 * @return [type] ...
954 */
955 function printCodeArray($codeArr,$l=0) {
956 reset($codeArr);
957 $line='';
958 if ($l) $indent='<td style="vertical-align:top;"><img height="1" width="50"></td>';
959 $lf=$l*30;
960 $bgColor = t3lib_div::modifyHTMLColor($GLOBALS['TBE_TEMPLATE']->bgColor2,$lf,$lf,$lf);
961 while(list($k,$v)=each($codeArr)) {
962 $line.= '<tr>'.$indent.'<td bgcolor="'.$bgColor.'"'.$this->noWrap.'>'.$v['html'].'</td></tr>';
963 if ($this->enableQueryParts) {$line.= '<tr>'.$indent.'<td>'.$this->formatQ($v['query']).'</td></tr>';}
964 if (is_array($v['sub'])) {
965 $line.= '<tr>'.$indent.'<td'.$this->noWrap.'>'.$this->printCodeArray($v['sub'],$l+1).'</td></tr>';
966 }
967 }
968 $out='<table border="0" cellpadding="0" cellspacing="1">'.$line.'</table>';
969 return $out;
970 }
971
972 /**
973 * [Describe function...]
974 *
975 * @param [type] $str: ...
976 * @return [type] ...
977 */
978 function formatQ($str) {
979 return '<font size="1" face="verdana" color="maroon"><i>'.$str.'</i></font>';
980 }
981
982 /**
983 * [Describe function...]
984 *
985 * @param [type] $name: ...
986 * @param [type] $op: ...
987 * @param [type] $draw: ...
988 * @param [type] $submit: ...
989 * @return [type] ...
990 */
991 function mkOperatorSelect($name,$op,$draw,$submit) {
992 if ($draw) {
993 $out='<select name="'.$name.'[operator]"'.($submit?' onChange="submit();"':'').'>'; //
994 $out.='<option value="AND"'.(!$op||$op=="AND" ? ' selected':'').'>'.$this->lang["AND"].'</option>';
995 $out.='<option value="OR"'.($op=='OR' ? ' selected':'').'>'.$this->lang['OR'].'</option>';
996 $out.='</select>';
997 } else {
998 $out.='<input type="hidden" value="'.$op.'" name="'.$name.'[operator]">';
999 $out.='<img src="clear.gif" height="1" width="47">';
1000
1001 }
1002 return $out;
1003 }
1004
1005 /**
1006 * [Describe function...]
1007 *
1008 * @param [type] $name: ...
1009 * @param [type] $fieldName: ...
1010 * @param [type] $prepend: ...
1011 * @return [type] ...
1012 */
1013 function mkTypeSelect($name,$fieldName,$prepend='FIELD_') {
1014 $out='<select name="'.$name.'" onChange="submit();">';
1015 $out.='<option value=""></option>';
1016 reset($this->fields);
1017 while(list($key,)=each($this->fields)) {
1018 if (!$fieldValue['exclude'] || $GLOBALS['BE_USER']->check('non_exclude_fields', $this->table.':'.$key)) {
1019 $label = $this->fields[$key]['label'];
1020 $label_alt = $this->fields[$key]['label_alt'];
1021 $out .= '<option value="'.$prepend.$key.'"'.($key==$fieldName ? ' selected' : '').'>'.$label.'</option>';
1022 }
1023 }
1024 $out.='</select>';
1025 return $out;
1026 }
1027
1028 /**
1029 * [Describe function...]
1030 *
1031 * @param [type] $fieldName: ...
1032 * @return [type] ...
1033 */
1034 function verifyType($fieldName) {
1035 reset($this->fields);
1036 $first = '';
1037 while(list($key,)=each($this->fields)) {
1038 if (!$first) $first = $key;
1039 if ($key==$fieldName) return $key;
1040 }
1041 return $first;
1042 }
1043
1044 /**
1045 * [Describe function...]
1046 *
1047 * @param [type] $comparison: ...
1048 * @param [type] $neg: ...
1049 * @return [type] ...
1050 */
1051 function verifyComparison($comparison,$neg) {
1052 $compOffSet = $comparison >> 5;
1053 $first=-1;
1054 for($i=32*$compOffSet+$neg;$i<32*($compOffSet+1);$i+=2) {
1055 if ($first==-1) $first = $i;
1056 if (($i >> 1)==($comparison >> 1)) {
1057 return $i;
1058 }
1059 }
1060 return $first;
1061 }
1062
1063 /**
1064 * [Describe function...]
1065 *
1066 * @param [type] $name: ...
1067 * @param [type] $fieldName: ...
1068 * @return [type] ...
1069 */
1070 function mkFieldToInputSelect($name,$fieldName) {
1071 $out='<input type="Text" value="'.htmlspecialchars($fieldName).'" name="'.$name.'"'.$GLOBALS['TBE_TEMPLATE']->formWidth().'>'.$this->updateIcon();
1072 $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>';
1073 $out.='<BR><select name="_fieldListDummy" size="5" onChange="document.forms[0][\''.$name.'\'].value+=\',\'+this.value">';
1074 reset($this->fields);
1075 while(list($key,)=each($this->fields)) {
1076 if (!$fieldValue['exclude'] || $GLOBALS['BE_USER']->check('non_exclude_fields', $this->table.':'.$key)) {
1077 $label = $this->fields[$key]['label'];
1078 $label_alt = $this->fields[$key]['label_alt'];
1079 $out .= '<option value="'.$key.'"'.($key==$fieldName ? ' selected':'').'>'.$label.'</option>';
1080 }
1081 }
1082 $out.='</select>';
1083 return $out;
1084 }
1085
1086 /**
1087 * [Describe function...]
1088 *
1089 * @param [type] $name: ...
1090 * @param [type] $cur: ...
1091 * @return [type] ...
1092 */
1093 function mkTableSelect($name,$cur) {
1094 global $TCA;
1095 $out='<select name="'.$name.'" onChange="submit();">';
1096 $out.='<option value=""></option>';
1097 reset($TCA);
1098 while(list($tN)=each($TCA)) {
1099 if ($GLOBALS['BE_USER']->check('tables_select',$tN)) {
1100 $out.='<option value="'.$tN.'"'.($tN==$cur ? ' selected':'').'>'.$GLOBALS['LANG']->sl($TCA[$tN]['ctrl']['title']).'</option>';
1101 }
1102 }
1103 $out.='</select>';
1104 return $out;
1105 }
1106
1107 /**
1108 * [Describe function...]
1109 *
1110 * @param [type] $name: ...
1111 * @param [type] $comparison: ...
1112 * @param [type] $neg: ...
1113 * @return [type] ...
1114 */
1115 function mkCompSelect($name,$comparison,$neg) {
1116 $compOffSet = $comparison >> 5;
1117 $out='<select name="'.$name.'" onChange="submit();">';
1118 for($i=32*$compOffSet+$neg;$i<32*($compOffSet+1);$i+=2) {
1119 if($this->lang['comparison'][$i.'_']) {
1120 $out.='<option value="'.$i.'"'.(($i >> 1)==($comparison >> 1) ? ' selected':'').'>'.$this->lang['comparison'][$i.'_'].'</option>';
1121 }
1122 }
1123 $out.='</select>';
1124 return $out;
1125 }
1126
1127 /**
1128 * [Describe function...]
1129 *
1130 * @param [type] $arr: ...
1131 * @return [type] ...
1132 */
1133 function getSubscript($arr) {
1134 while(is_array($arr)) {
1135 reset($arr);
1136 list($key,)=each($arr);
1137 $retArr[] = $key;
1138 $arr = $arr[$key];
1139 }
1140 return $retArr;
1141 }
1142
1143 /**
1144 * [Describe function...]
1145 *
1146 * @return [type] ...
1147 */
1148 function initUserDef() {
1149
1150 }
1151
1152 /**
1153 * [Describe function...]
1154 *
1155 * @return [type] ...
1156 */
1157 function userDef() {
1158 }
1159
1160 /**
1161 * [Describe function...]
1162 *
1163 * @param [type] $queryConfig: ...
1164 * @return [type] ...
1165 */
1166 function userDefCleanUp($queryConfig) {
1167 return $queryConfig;
1168 }
1169
1170 /**
1171 * [Describe function...]
1172 *
1173 * @param [type] $queryConfig: ...
1174 * @param [type] $pad: ...
1175 * @return [type] ...
1176 */
1177 function getQuery ($queryConfig,$pad='') {
1178 $qs = '';
1179 // Since we don't traverse the array using numeric keys in the upcoming whileloop make sure it's fresh and clean
1180 ksort($queryConfig);
1181 reset($queryConfig);
1182 $first=1;
1183 while(list($key,$conf) = each($queryConfig)) {
1184 switch($conf['type']) {
1185 case 'newlevel':
1186 $qs.=chr(10).$pad.trim($conf['operator']).' ('.$this->getQuery($queryConfig[$key]['nl'],$pad.' ').chr(10).$pad.')';
1187 break;
1188 case 'userdef':
1189 $qs.=chr(10).$pad.getUserDefQuery($conf,$first);
1190 break;
1191 default:
1192 $qs.=chr(10).$pad.$this->getQuerySingle($conf,$first);
1193 break;
1194 }
1195 $first=0;
1196 }
1197 return $qs;
1198 }
1199
1200 /**
1201 * [Describe function...]
1202 *
1203 * @param [type] $conf: ...
1204 * @param [type] $first: ...
1205 * @return [type] ...
1206 */
1207 function getQuerySingle($conf,$first) {
1208 $prefix = $this->enablePrefix ? $this->table.'.' : '';
1209 if (!$first) {
1210 // Is it OK to insert the AND operator if none is set?
1211 $qs .= trim(($conf['operator'] ? $conf['operator'] : 'AND')).' ';
1212 }
1213 $qsTmp = str_replace('#FIELD#', $prefix.trim(substr($conf['type'],6)), $this->compSQL[$conf['comparison']]);
1214 $inputVal = $this->cleanInputVal($conf);
1215 if ($conf['comparison']==68 || $conf['comparison']==69) {
1216 $inputVal = explode(',', $inputVal);
1217 foreach ($inputVal as $key => $fileName) {
1218 $inputVal[$key] = "'".$fileName."'";
1219 }
1220 $inputVal = implode(',', $inputVal);
1221 $qsTmp = str_replace('#VALUE#', $inputVal, $qsTmp);
1222 } elseif ($conf['comparison']==162 || $conf['comparison']==163) {
1223 $inputValArray = explode(',', $inputVal);
1224 $inputVal = 0;
1225 foreach ($inputValArray as $key=>$fileName) {
1226 $inputVal += intval($fileName);
1227 }
1228 $qsTmp = str_replace('#VALUE#', $inputVal, $qsTmp);
1229 } else {
1230 $qsTmp = str_replace('#VALUE#', $GLOBALS['TYPO3_DB']->quoteStr($inputVal,$this->table), $qsTmp);
1231 }
1232 if ($conf['comparison']==37 || $conf['comparison']==36 || $conf['comparison']==66 || $conf['comparison']==67 || $conf['comparison']==100 || $conf['comparison']==101) { // between:
1233 $inputVal = $this->cleanInputVal($conf,'1');
1234 $qsTmp = str_replace('#VALUE1#', $GLOBALS['TYPO3_DB']->quoteStr($inputVal,$this->table), $qsTmp);
1235 }
1236 $qs .= trim($qsTmp);
1237 return $qs;
1238 }
1239
1240 /**
1241 * [Describe function...]
1242 *
1243 * @param [type] $conf: ...
1244 * @param [type] $suffix: ...
1245 * @return [type] ...
1246 */
1247 function cleanInputVal($conf,$suffix='') {
1248 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)) {
1249 $inputVal = $conf['inputValue'.$suffix];
1250 } elseif ($conf['comparison']==39 || $conf['comparison']==38) { // in list:
1251 $inputVal = implode(',',t3lib_div::intExplode(',',$conf['inputValue'.$suffix]));
1252 } elseif ($conf['comparison']==68 || $conf['comparison']==69 || $conf['comparison']==162 || $conf['comparison']==163) { // in list:
1253 if (is_array($conf['inputValue'.$suffix])) {
1254 $inputVal = implode(',', $conf['inputValue'.$suffix]);
1255 } elseif ($conf['inputValue'.$suffix]) {
1256 $inputVal = $conf['inputValue'.$suffix];
1257 } else {
1258 $inputVal = 0;
1259 }
1260 } else {
1261 $inputVal = doubleval($conf['inputValue'.$suffix]);
1262 }
1263 return $inputVal;
1264 }
1265
1266 /**
1267 * [Describe function...]
1268 *
1269 * @param [type] $qcArr: ...
1270 * @return [type] ...
1271 */
1272 function getUserDefQuery ($qcArr) {
1273 }
1274
1275 /**
1276 * [Describe function...]
1277 *
1278 * @return [type] ...
1279 */
1280 function updateIcon() {
1281 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">';
1282 }
1283
1284 /**
1285 * [Describe function...]
1286 *
1287 * @return [type] ...
1288 */
1289 function getLabelCol() {
1290 global $TCA;
1291 return $TCA[$this->table]['ctrl']['label'];
1292 }
1293
1294 /**
1295 * [Describe function...]
1296 *
1297 * @param [type] $modSettings: ...
1298 * @param [type] $enableList: ...
1299 * @return [type] ...
1300 */
1301 function makeSelectorTable($modSettings,$enableList='table,fields,query,group,order,limit') {
1302 $enableArr=explode(',',$enableList);
1303 // Make output
1304 $TDparams = ' class="bgColor5" nowrap';
1305
1306 if (in_array('table',$enableArr) && !$GLOBALS['BE_USER']->userTS['mod.']['dbint.']['disableSelectATable']) {
1307 $out='
1308 <tr>
1309 <td'.$TDparams.'><strong>Select a table:</strong></td>
1310 <td'.$TDparams.'>'.$this->mkTableSelect('SET[queryTable]',$this->table).'</td>
1311 </tr>';
1312 }
1313 if ($this->table) {
1314
1315 // Init fields:
1316 $this->setAndCleanUpExternalLists('queryFields',$modSettings['queryFields'],'uid,'.$this->getLabelCol());
1317 $this->setAndCleanUpExternalLists('queryGroup',$modSettings['queryGroup']);
1318 $this->setAndCleanUpExternalLists('queryOrder',$modSettings['queryOrder'].','.$modSettings['queryOrder2']);
1319
1320 // Limit:
1321 $this->extFieldLists['queryLimit']=$modSettings['queryLimit'];
1322 if (!$this->extFieldLists['queryLimit']) $this->extFieldLists['queryLimit']=100;
1323 $parts = t3lib_div::intExplode(',',$this->extFieldLists['queryLimit']);
1324 if ($parts[1]) {
1325 $this->limitBegin = $parts[0];
1326 $this->limitLength = $parts[1];
1327 } else {
1328 $this->limitLength = $this->extFieldLists['queryLimit'];
1329 }
1330 $this->extFieldLists['queryLimit'] = implode(',',array_slice($parts,0,2));
1331
1332 // Insert Descending parts
1333 if ($this->extFieldLists['queryOrder']) {
1334 $descParts = explode(',',$modSettings['queryOrderDesc'].','.$modSettings['queryOrder2Desc']);
1335 $orderParts = explode(',',$this->extFieldLists['queryOrder']);
1336 reset($orderParts);
1337 $reList=array();
1338 while(list($kk,$vv)=each($orderParts)) {
1339 $reList[]=$vv.($descParts[$kk]?' DESC':'');
1340 }
1341 $this->extFieldLists['queryOrder_SQL'] = implode(',',$reList);
1342 }
1343
1344 // Query Generator:
1345 $this->procesData($modSettings['queryConfig'] ? unserialize($modSettings['queryConfig']) : '');
1346 // debug($this->queryConfig);
1347 $this->queryConfig = $this->cleanUpQueryConfig($this->queryConfig);
1348 // debug($this->queryConfig);
1349 $this->enableQueryParts = $modSettings['search_query_smallparts'];
1350
1351 $codeArr=$this->getFormElements();
1352 $queryCode=$this->printCodeArray($codeArr);
1353
1354 if (in_array('fields',$enableArr) && !$GLOBALS['BE_USER']->userTS['mod.']['dbint.']['disableSelectFields']) {
1355 $out.='
1356 <tr>
1357 <td'.$TDparams.'><strong>Select fields:</strong></td>
1358 <td'.$TDparams.'>'.$this->mkFieldToInputSelect('SET[queryFields]',$this->extFieldLists['queryFields']).'</td>
1359 </tr>';
1360 }
1361 if (in_array('query',$enableArr) && !$GLOBALS['BE_USER']->userTS['mod.']['dbint.']['disableMakeQuery']) {
1362 $out.='<tr>
1363 <td colspan="2"'.$TDparams.'><strong>Make Query:</strong></td>
1364 </tr>
1365 <tr>
1366 <td colspan="2">'.$queryCode.'</td>
1367 </tr>
1368 ';
1369 }
1370 if (in_array('group',$enableArr) && !$GLOBALS['BE_USER']->userTS['mod.']['dbint.']['disableGroupBy']) {
1371 $out.='<tr>
1372 <td'.$TDparams.'><strong>Group By:</strong></td>
1373 <td'.$TDparams.'>'.$this->mkTypeSelect('SET[queryGroup]',$this->extFieldLists['queryGroup'],'').'</td>
1374 </tr>';
1375 }
1376 if (in_array('order',$enableArr) && !$GLOBALS['BE_USER']->userTS['mod.']['dbint.']['disableOrderBy']) {
1377 $orderByArr = explode(',',$this->extFieldLists['queryOrder']);
1378 // debug($orderByArr);
1379 $orderBy='';
1380 $orderBy.=$this->mkTypeSelect('SET[queryOrder]',$orderByArr[0],'').
1381 '&nbsp;'.t3lib_BEfunc::getFuncCheck($GLOBALS['SOBE']->id,'SET[queryOrderDesc]',$modSettings['queryOrderDesc'],'','','id="checkQueryOrderDesc"').'&nbsp;<label for="checkQueryOrderDesc">Descending</label>';
1382 if ($orderByArr[0]) {
1383 $orderBy.= '<BR>'.$this->mkTypeSelect('SET[queryOrder2]',$orderByArr[1],'').
1384 '&nbsp;'.t3lib_BEfunc::getFuncCheck($GLOBALS['SOBE']->id,'SET[queryOrder2Desc]',$modSettings['queryOrder2Desc'],'','','id="checkQueryOrder2Desc"').'&nbsp;<label for="checkQueryOrder2Desc">Descending</label>';
1385 }
1386 $out.='<tr>
1387 <td'.$TDparams.'><strong>Order By:</strong></td>
1388 <td'.$TDparams.'>'.$orderBy.'</td>
1389 </tr>';
1390 }
1391 if (in_array('limit',$enableArr) && !$GLOBALS['BE_USER']->userTS['mod.']['dbint.']['disableLimit']) {
1392 $limit = '<input type="Text" value="'.htmlspecialchars($this->extFieldLists['queryLimit']).'" name="SET[queryLimit]" id="queryLimit"'.$GLOBALS['TBE_TEMPLATE']->formWidth(10).'>'.$this->updateIcon();
1393
1394 $prevLimit = ($this->limitBegin-$this->limitLength) < 0 ? 0 :
1395 $this->limitBegin-$this->limitLength;
1396 if ($this->limitBegin) {
1397 $prevButton = '<input type="button" value="previous '.$this->limitLength.'" onclick=\'document.getElementById("queryLimit").value="'.$prevLimit.','.$this->limitLength.'";document.forms[0].submit();\'>';
1398 }
1399 if (!$this->limitLength) {
1400 $this->limitLength = 100;
1401 }
1402 $nextLimit = $this->limitBegin + $this->limitLength;
1403 if ($nextLimit < 0) $nextLimit = 0;
1404 if ($nextLimit) {
1405 $nextButton = '<input type="button" value="next '.$this->limitLength.'" onclick=\'document.getElementById("queryLimit").value="'.$nextLimit.','.$this->limitLength.'";document.forms[0].submit();\'>';
1406 }
1407
1408 $numberButtons = '<input type="button" value="10" onclick=\'document.getElementById("queryLimit").value="10";document.forms[0].submit();\'>';
1409 $numberButtons .= '<input type="button" value="20" onclick=\'document.getElementById("queryLimit").value="20";document.forms[0].submit();\'>';
1410 $numberButtons .= '<input type="button" value="50" onclick=\'document.getElementById("queryLimit").value="50";document.forms[0].submit();\'>';
1411 $numberButtons .= '<input type="button" value="100" onclick=\'document.getElementById("queryLimit").value="100";document.forms[0].submit();\'>';
1412 $out.='<tr>
1413 <td'.$TDparams.'><strong>Limit:</strong></td>
1414 <td'.$TDparams.'>'.$limit.$prevButton.$nextButton.'&nbsp;'.$numberButtons.'</td>
1415 </tr>
1416 ';
1417 }
1418 }
1419 $out='<table border="0" cellpadding="3" cellspacing="1">'.$out.'</table>';
1420 $out.=$this->JSbottom($this->formName);
1421 return $out;
1422 }
1423
1424 /**
1425 * [Describe function...]
1426 *
1427 * @param [type] $qString: ...
1428 * @param [type] $depth: ...
1429 * @param [type] $begin: ...
1430 * @param [type] $perms_clause: ...
1431 * @return [type] ...
1432 */
1433 function getTreeList($id, $depth, $begin=0, $perms_clause) {
1434 $depth = intval($depth);
1435 $begin = intval($begin);
1436 $id = intval($id);
1437 if ($begin==0) {
1438 $theList = $id;
1439 } else {
1440 $theList = '';
1441 }
1442 if ($id && $depth > 0) {
1443 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
1444 'uid',
1445 'pages',
1446 'pid='.$id.' '.t3lib_BEfunc::deleteClause('pages').' AND '.$perms_clause
1447 );
1448 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
1449 if ($begin <= 0) {
1450 $theList .= ','.$row['uid'];
1451 }
1452 if ($depth > 1) {
1453 $theList .= $this->getTreeList($row['uid'], $depth-1, $begin-1, $perms_clause);
1454 }
1455 }
1456 }
1457 return $theList;
1458 }
1459
1460 /**
1461 * [Describe function...]
1462 *
1463 * @param [type] $qString: ...
1464 * @param [type] $fN: ...
1465 * @return [type] ...
1466 */
1467 function getSelectQuery($qString = '', $fN = '') {
1468 if (!$qString) $qString = $this->getQuery($this->queryConfig);
1469 $qString = '('.$qString.')';
1470 if (!$GLOBALS['BE_USER']->isAdmin() && $GLOBALS['TYPO3_CONF_VARS']['BE']['lockBeUserToDBmounts']) {
1471 $webMounts = $GLOBALS['BE_USER']->returnWebmounts();
1472 $perms_clause = $GLOBALS['BE_USER']->getPagePermsClause(1);
1473 foreach($webMounts as $key => $val) {
1474 if ($webMountPageTree) {
1475 $webMountPageTreePrefix = ',';
1476 }
1477 $webMountPageTree .= $webMountPageTreePrefix.$this->getTreeList($val, 999, $begin = 0, $perms_clause);
1478 }
1479 if ($this->table == 'pages') {
1480 $qString .= ' AND uid IN ('.$webMountPageTree.')';
1481 } else {
1482 $qString .= ' AND pid IN ('.$webMountPageTree.')';
1483 }
1484 }
1485 $fieldlist = $this->extFieldLists['queryFields'].',pid,deleted';
1486 if (!$GLOBALS['SOBE']->MOD_SETTINGS['show_deleted']) {
1487 $qString .= t3lib_BEfunc::deleteClause($this->table);
1488 }
1489 $query = $GLOBALS['TYPO3_DB']->SELECTquery(
1490 $fieldlist,
1491 $this->table,
1492 $qString,
1493 trim($this->extFieldLists['queryGroup']),
1494 $this->extFieldLists['queryOrder'] ? trim($this->extFieldLists['queryOrder_SQL']) : '',
1495 $this->extFieldLists['queryLimit']
1496 );
1497 return $query;
1498 }
1499
1500 /**
1501 * [Describe function...]
1502 *
1503 * @param [type] $formname: ...
1504 * @return [type] ...
1505 */
1506 function JSbottom($formname) {
1507 if ($this->extJSCODE) {
1508 $out.='
1509 <script language="javascript" type="text/javascript" src="'.$GLOBALS['BACK_PATH'].'../t3lib/jsfunc.evalfield.js"></script>
1510 <script language="javascript" type="text/javascript" src="'.$GLOBALS['BACK_PATH'].'jsfunc.tbe_editor.js"></script>
1511 <script language="javascript" type="text/javascript">
1512 TBE_EDITOR.formname = "'.$formname.'";
1513 TBE_EDITOR.formnameUENC = "'.rawurlencode($formname).'";
1514 '.$this->extJSCODE.'
1515 </script>';
1516 return $out;
1517 }
1518 }
1519
1520 /**
1521 * Sets the current name of the input form.
1522 *
1523 * @param string $formName: The name of the form.
1524 * @return void
1525 */
1526 public function setFormName($formName) {
1527 $this->formName = trim($formName);
1528 }
1529 }
1530
1531
1532 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_querygenerator.php']) {
1533 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_querygenerator.php']);
1534 }
1535 ?>