PageRenderTime 64ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/t3lib/class.t3lib_querygenerator.php

https://bitbucket.org/linxpinx/mercurial
PHP | 1527 lines | 1063 code | 88 blank | 376 comment | 237 complexity | c873dda7fe11b5c41560a8669b70293f MD5 | raw file
Possible License(s): BSD-3-Clause, GPL-2.0, Unlicense, LGPL-2.1, Apache-2.0

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /***************************************************************
  3. * Copyright notice
  4. *
  5. * (c) 2001-2010 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: class.t3lib_querygenerator.php 8157 2010-07-11 12:45:16Z psychomieze $
  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. * Class for generating front end for building queries
  81. *
  82. * @author Christian Jul Jensen <christian@typo3.com>
  83. * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
  84. * @package TYPO3
  85. * @subpackage t3lib
  86. */
  87. class t3lib_queryGenerator {
  88. var $lang = array(
  89. 'OR' => 'or',
  90. 'AND' => 'and',
  91. 'comparison' => array(
  92. // Type = text offset = 0
  93. '0_' => 'contains',
  94. '1_' => 'does not contain',
  95. '2_' => 'starts with',
  96. '3_' => 'does not start with',
  97. '4_' => 'ends with',
  98. '5_' => 'does not end with',
  99. '6_' => 'equals',
  100. '7_' => 'does not equal',
  101. // Type = number , offset = 32
  102. '32_' => 'equals',
  103. '33_' => 'does not equal',
  104. '34_' => 'is greater than',
  105. '35_' => 'is less than',
  106. '36_' => 'is between',
  107. '37_' => 'is not between',
  108. '38_' => 'is in list',
  109. '39_' => 'is not in list',
  110. '40_' => 'binary AND equals',
  111. '41_' => 'binary AND does not equal',
  112. '42_' => 'binary OR equals',
  113. '43_' => 'binary OR does not equal',
  114. // Type = multiple, relation, files , offset = 64
  115. '64_' => 'equals',
  116. '65_' => 'does not equal',
  117. '66_' => 'contains',
  118. '67_' => 'does not contain',
  119. '68_' => 'is in list',
  120. '69_' => 'is not in list',
  121. '70_' => 'binary AND equals',
  122. '71_' => 'binary AND does not equal',
  123. '72_' => 'binary OR equals',
  124. '73_' => 'binary OR does not equal',
  125. // Type = date,time offset = 96
  126. '96_' => 'equals',
  127. '97_' => 'does not equal',
  128. '98_' => 'is greater than',
  129. '99_' => 'is less than',
  130. '100_' => 'is between',
  131. '101_' => 'is not between',
  132. '102_' => 'binary AND equals',
  133. '103_' => 'binary AND does not equal',
  134. '104_' => 'binary OR equals',
  135. '105_' => 'binary OR does not equal',
  136. // Type = boolean, offset = 128
  137. '128_' => 'is True',
  138. '129_' => 'is False',
  139. // Type = binary , offset = 160
  140. '160_' => 'equals',
  141. '161_' => 'does not equal',
  142. '162_' => 'contains',
  143. '163_' => 'does not contain'
  144. )
  145. );
  146. var $compSQL = array(
  147. // Type = text offset = 0
  148. '0' => "#FIELD# LIKE '%#VALUE#%'",
  149. '1' => "#FIELD# NOT LIKE '%#VALUE#%'",
  150. '2' => "#FIELD# LIKE '#VALUE#%'",
  151. '3' => "#FIELD# NOT LIKE '#VALUE#%'",
  152. '4' => "#FIELD# LIKE '%#VALUE#'",
  153. '5' => "#FIELD# NOT LIKE '%#VALUE#'",
  154. '6' => "#FIELD# = '#VALUE#'",
  155. '7' => "#FIELD# != '#VALUE#'",
  156. // Type = number, offset = 32
  157. '32' => "#FIELD# = '#VALUE#'",
  158. '33' => "#FIELD# != '#VALUE#'",
  159. '34' => '#FIELD# > #VALUE#',
  160. '35' => '#FIELD# < #VALUE#',
  161. '36' => '#FIELD# >= #VALUE# AND #FIELD# <= #VALUE1#',
  162. '37' => 'NOT (#FIELD# >= #VALUE# AND #FIELD# <= #VALUE1#)',
  163. '38' => '#FIELD# IN (#VALUE#)',
  164. '39' => '#FIELD# NOT IN (#VALUE#)',
  165. '40' => '(#FIELD# & #VALUE#)=#VALUE#',
  166. '41' => '(#FIELD# & #VALUE#)!=#VALUE#',
  167. '42' => '(#FIELD# | #VALUE#)=#VALUE#',
  168. '43' => '(#FIELD# | #VALUE#)!=#VALUE#',
  169. // Type = multiple, relation, files , offset = 64
  170. '64' => "#FIELD# = '#VALUE#'",
  171. '65' => "#FIELD# != '#VALUE#'",
  172. '66' => "#FIELD# LIKE '%#VALUE#%' AND #FIELD# LIKE '%#VALUE1#%'",
  173. '67' => "(#FIELD# NOT LIKE '%#VALUE#%' OR #FIELD# NOT LIKE '%#VALUE1#%')",
  174. '68' => '#FIELD# IN (#VALUE#)',
  175. '69' => '#FIELD# NOT IN (#VALUE#)',
  176. '70' => '(#FIELD# & #VALUE#)=#VALUE#',
  177. '71' => '(#FIELD# & #VALUE#)!=#VALUE#',
  178. '72' => '(#FIELD# | #VALUE#)=#VALUE#',
  179. '73' => '(#FIELD# | #VALUE#)!=#VALUE#',
  180. // Type = date, offset = 32
  181. '96' => "#FIELD# = '#VALUE#'",
  182. '97' => "#FIELD# != '#VALUE#'",
  183. '98' => '#FIELD# > #VALUE#',
  184. '99' => '#FIELD# < #VALUE#',
  185. '100' => '#FIELD# >= #VALUE# AND #FIELD# <= #VALUE1#',
  186. '101' => 'NOT (#FIELD# >= #VALUE# AND #FIELD# <= #VALUE1#)',
  187. '102' => '(#FIELD# & #VALUE#)=#VALUE#',
  188. '103' => '(#FIELD# & #VALUE#)!=#VALUE#',
  189. '104' => '(#FIELD# | #VALUE#)=#VALUE#',
  190. '105' => '(#FIELD# | #VALUE#)!=#VALUE#',
  191. // Type = boolean, offset = 128
  192. '128' => "#FIELD# = '1'",
  193. '129' => "#FIELD# != '1'",
  194. // Type = binary = 160
  195. '160' => "#FIELD# = '#VALUE#'",
  196. '161' => "#FIELD# != '#VALUE#'",
  197. '162' => '(#FIELD# & #VALUE#)=#VALUE#',
  198. '163' => '(#FIELD# & #VALUE#)=0'
  199. );
  200. var $comp_offsets = array(
  201. 'text' => 0,
  202. 'number' => 1,
  203. 'multiple' => 2,
  204. 'relation' => 2,
  205. 'files' => 2,
  206. 'date' => 3,
  207. 'time' => 3,
  208. 'boolean' => 4,
  209. 'binary' => 5
  210. );
  211. var $noWrap=' nowrap';
  212. var $name; // Form data name prefix
  213. var $table; // table for the query
  214. var $fieldList; // field list
  215. var $fields = array(); // Array of the fields possible
  216. var $extFieldLists = array();
  217. var $queryConfig=array(); // The query config
  218. var $enablePrefix=0;
  219. var $enableQueryParts = 0;
  220. var $extJSCODE='';
  221. protected $formName = '';
  222. /**
  223. * @return [type] ...
  224. */
  225. function makeFieldList() {
  226. global $TCA;
  227. $fieldListArr = array();
  228. if (is_array($TCA[$this->table])) {
  229. t3lib_div::loadTCA($this->table);
  230. foreach ($TCA[$this->table]['columns'] as $fN => $value) {
  231. $fieldListArr[]=$fN;
  232. }
  233. $fieldListArr[]='uid';
  234. $fieldListArr[]='pid';
  235. $fieldListArr[]='deleted';
  236. if ($TCA[$this->table]['ctrl']['tstamp']) $fieldListArr[]=$TCA[$this->table]['ctrl']['tstamp'];
  237. if ($TCA[$this->table]['ctrl']['crdate']) $fieldListArr[]=$TCA[$this->table]['ctrl']['crdate'];
  238. if ($TCA[$this->table]['ctrl']['cruser_id']) $fieldListArr[]=$TCA[$this->table]['ctrl']['cruser_id'];
  239. if ($TCA[$this->table]['ctrl']['sortby']) $fieldListArr[]=$TCA[$this->table]['ctrl']['sortby'];
  240. }
  241. return implode(',',$fieldListArr);
  242. }
  243. /**
  244. * [Describe function...]
  245. *
  246. * @param [type] $name: ...
  247. * @param [type] $table: ...
  248. * @param [type] $fieldList: ...
  249. * @return [type] ...
  250. */
  251. function init($name,$table,$fieldList='') {
  252. global $TCA;
  253. // Analysing the fields in the table.
  254. if (is_array($TCA[$table])) {
  255. t3lib_div::loadTCA($table);
  256. $this->name = $name;
  257. $this->table = $table;
  258. $this->fieldList = $fieldList ? $fieldList : $this->makeFieldList();
  259. $fieldArr = t3lib_div::trimExplode(',',$this->fieldList,1);
  260. foreach ($fieldArr as $fN) {
  261. $fC = $TCA[$this->table]['columns'][$fN];
  262. $this->fields[$fN] = $fC['config'];
  263. $this->fields[$fN]['exclude'] = $fC['exclude'];
  264. if (is_array($fC) && $fC['label']) {
  265. $this->fields[$fN]['label'] = rtrim(trim($GLOBALS['LANG']->sL($fC['label'])), ':');
  266. switch ($this->fields[$fN]['type']) {
  267. case 'input':
  268. if (preg_match('/int|year/i', $this->fields[$fN]['eval'])) {
  269. $this->fields[$fN]['type']='number';
  270. } elseif (preg_match('/time/i', $this->fields[$fN]['eval'])) {
  271. $this->fields[$fN]['type'] = 'time';
  272. } elseif (preg_match('/date/i', $this->fields[$fN]['eval'])) {
  273. $this->fields[$fN]['type']='date';
  274. } else {
  275. $this->fields[$fN]['type']='text';
  276. }
  277. break;
  278. case 'check':
  279. if (!$this->fields[$fN]['items']) {
  280. $this->fields[$fN]['type'] = 'boolean';
  281. } else {
  282. $this->fields[$fN]['type'] = 'binary';
  283. }
  284. break;
  285. case 'radio':
  286. $this->fields[$fN]['type'] = 'multiple';
  287. break;
  288. case 'select':
  289. $this->fields[$fN]['type'] = 'multiple';
  290. if ($this->fields[$fN]['foreign_table']) {
  291. $this->fields[$fN]['type'] = 'relation';
  292. }
  293. if ($this->fields[$fN]['special']) {
  294. $this->fields[$fN]['type'] = 'text';
  295. }
  296. break;
  297. case 'group':
  298. $this->fields[$fN]['type'] = 'files';
  299. if ($this->fields[$fN]['internal_type'] == 'db') {
  300. $this->fields[$fN]['type'] = 'relation';
  301. }
  302. break;
  303. case 'user':
  304. case 'flex':
  305. case 'passthrough':
  306. case 'none':
  307. case 'text':
  308. default:
  309. $this->fields[$fN]['type']='text';
  310. break;
  311. }
  312. } else {
  313. $this->fields[$fN]['label']='[FIELD: '.$fN.']';
  314. switch ($fN) {
  315. case 'pid':
  316. $this->fields[$fN]['type'] = 'relation';
  317. $this->fields[$fN]['allowed'] = 'pages';
  318. break;
  319. case 'cruser_id':
  320. $this->fields[$fN]['type'] = 'relation';
  321. $this->fields[$fN]['allowed'] = 'be_users';
  322. break;
  323. case 'tstamp':
  324. case 'crdate':
  325. $this->fields[$fN]['type'] = 'time';
  326. break;
  327. case 'deleted':
  328. $this->fields[$fN]['type'] = 'boolean';
  329. break;
  330. default:
  331. $this->fields[$fN]['type'] = 'number';
  332. break;
  333. }
  334. }
  335. }
  336. }
  337. /* // EXAMPLE:
  338. $this->queryConfig = array(
  339. array(
  340. 'operator' => 'AND',
  341. 'type' => 'FIELD_spaceBefore',
  342. ),
  343. array(
  344. 'operator' => 'AND',
  345. 'type' => 'FIELD_records',
  346. 'negate' => 1,
  347. 'inputValue' => 'foo foo'
  348. ),
  349. array(
  350. 'type' => 'newlevel',
  351. 'nl' => array(
  352. array(
  353. 'operator' => 'AND',
  354. 'type' => 'FIELD_spaceBefore',
  355. 'negate' => 1,
  356. 'inputValue' => 'foo foo'
  357. ),
  358. array(
  359. 'operator' => 'AND',
  360. 'type' => 'FIELD_records',
  361. 'negate' => 1,
  362. 'inputValue' => 'foo foo'
  363. )
  364. )
  365. ),
  366. array(
  367. 'operator' => 'OR',
  368. 'type' => 'FIELD_maillist',
  369. )
  370. );
  371. */
  372. $this->initUserDef();
  373. }
  374. /**
  375. * [Describe function...]
  376. *
  377. * @param [type] $name: ...
  378. * @param [type] $list: ...
  379. * @param [type] $force: ...
  380. * @return [type] ...
  381. */
  382. function setAndCleanUpExternalLists($name,$list,$force='') {
  383. $fields = array_unique(t3lib_div::trimExplode(',',$list.','.$force,1));
  384. $reList=array();
  385. foreach ($fields as $fN) {
  386. if ($this->fields[$fN]) $reList[]=$fN;
  387. }
  388. $this->extFieldLists[$name]=implode(',',$reList);
  389. }
  390. /**
  391. * [Describe function...]
  392. *
  393. * @param [type] $qC: ...
  394. * @return [type] ...
  395. */
  396. function procesData($qC='') {
  397. $this->queryConfig = $qC;
  398. $POST = t3lib_div::_POST();
  399. // if delete...
  400. if($POST['qG_del']) {
  401. //initialize array to work on, save special parameters
  402. $ssArr = $this->getSubscript($POST['qG_del']);
  403. $workArr =& $this->queryConfig;
  404. for($i=0;$i<sizeof($ssArr)-1;$i++) {
  405. $workArr =& $workArr[$ssArr[$i]];
  406. }
  407. // delete the entry and move the other entries
  408. unset($workArr[$ssArr[$i]]);
  409. for($j=$ssArr[$i];$j<sizeof($workArr);$j++) {
  410. $workArr[$j] = $workArr[$j+1];
  411. unset($workArr[$j+1]);
  412. }
  413. }
  414. // if insert...
  415. if($POST['qG_ins']) {
  416. //initialize array to work on, save special parameters
  417. $ssArr = $this->getSubscript($POST['qG_ins']);
  418. $workArr =& $this->queryConfig;
  419. for($i=0;$i<sizeof($ssArr)-1;$i++) {
  420. $workArr =& $workArr[$ssArr[$i]];
  421. }
  422. // move all entries above position where new entry is to be inserted
  423. for($j=sizeof($workArr);$j>$ssArr[$i];$j--) {
  424. $workArr[$j] = $workArr[$j-1];
  425. }
  426. //clear new entry position
  427. unset($workArr[$ssArr[$i]+1]);
  428. $workArr[$ssArr[$i]+1]['type'] = 'FIELD_';
  429. }
  430. // if move up...
  431. if($POST['qG_up']) {
  432. //initialize array to work on
  433. $ssArr = $this->getSubscript($POST['qG_up']);
  434. $workArr =& $this->queryConfig;
  435. for($i=0;$i<sizeof($ssArr)-1;$i++) {
  436. $workArr =& $workArr[$ssArr[$i]];
  437. }
  438. //swap entries
  439. $qG_tmp = $workArr[$ssArr[$i]];
  440. $workArr[$ssArr[$i]] = $workArr[$ssArr[$i]-1];
  441. $workArr[$ssArr[$i]-1] = $qG_tmp;
  442. }
  443. // if new level...
  444. if($POST['qG_nl']) {
  445. //initialize array to work on
  446. $ssArr = $this->getSubscript($POST['qG_nl']);
  447. $workArr =& $this->queryConfig;
  448. for($i=0;$i<sizeof($ssArr)-1;$i++) {
  449. $workArr =& $workArr[$ssArr[$i]];
  450. }
  451. // Do stuff:
  452. $tempEl = $workArr[$ssArr[$i]];
  453. if (is_array($tempEl)) {
  454. if ($tempEl['type']!='newlevel') {
  455. $workArr[$ssArr[$i]]=array(
  456. 'type' => 'newlevel',
  457. 'operator' => $tempEl['operator'],
  458. 'nl' => array($tempEl)
  459. );
  460. }
  461. }
  462. }
  463. // if collapse level...
  464. if($POST['qG_remnl']) {
  465. //initialize array to work on
  466. $ssArr = $this->getSubscript($POST['qG_remnl']);
  467. $workArr =& $this->queryConfig;
  468. for($i=0;$i<sizeof($ssArr)-1;$i++) {
  469. $workArr =& $workArr[$ssArr[$i]];
  470. }
  471. // Do stuff:
  472. $tempEl = $workArr[$ssArr[$i]];
  473. if (is_array($tempEl)) {
  474. if ($tempEl['type']=='newlevel') {
  475. $a1 = array_slice($workArr,0,$ssArr[$i]);
  476. $a2 = array_slice($workArr,$ssArr[$i]);
  477. array_shift($a2);
  478. $a3 = $tempEl['nl'];
  479. $a3[0]['operator'] = $tempEl['operator'];
  480. $workArr=array_merge($a1,$a3,$a2);
  481. }
  482. }
  483. }
  484. }
  485. /**
  486. * [Describe function...]
  487. *
  488. * @param [type] $queryConfig: ...
  489. * @return [type] ...
  490. */
  491. function cleanUpQueryConfig($queryConfig) {
  492. //since we dont traverse the array using numeric keys in the upcoming whileloop make sure it's fresh and clean before displaying
  493. if (is_array($queryConfig)) {
  494. ksort($queryConfig);
  495. } else {
  496. //queryConfig should never be empty!
  497. if(!$queryConfig[0] || !$queryConfig[0]['type']) $queryConfig[0] = array('type'=>'FIELD_');
  498. }
  499. // Traverse:
  500. $c=0;
  501. $arrCount=0;
  502. foreach ($queryConfig as $key => $conf) {
  503. if(substr($conf['type'],0,6)=='FIELD_') {
  504. $fName = substr($conf['type'],6);
  505. $fType = $this->fields[$fName]['type'];
  506. } elseif($conf['type']=='newlevel') {
  507. $fType = $conf['type'];
  508. } else {
  509. $fType = 'ignore';
  510. }
  511. // debug($fType);
  512. switch($fType) {
  513. case 'newlevel':
  514. if(!$queryConfig[$key]['nl']) $queryConfig[$key]['nl'][0]['type'] = 'FIELD_';
  515. $queryConfig[$key]['nl']=$this->cleanUpQueryConfig($queryConfig[$key]['nl']);
  516. break;
  517. case 'userdef':
  518. $queryConfig[$key]=$this->userDefCleanUp($queryConfig[$key]);
  519. break;
  520. case 'ignore':
  521. default:
  522. // debug($queryConfig[$key]);
  523. $verifiedName=$this->verifyType($fName);
  524. $queryConfig[$key]['type']='FIELD_'.$this->verifyType($verifiedName);
  525. if($conf['comparison'] >> 5 != $this->comp_offsets[$fType]) $conf['comparison'] = $this->comp_offsets[$fType] << 5;
  526. $queryConfig[$key]['comparison']=$this->verifyComparison($conf['comparison'],$conf['negate']?1:0);
  527. $queryConfig[$key]['inputValue']=$this->cleanInputVal($queryConfig[$key]);
  528. $queryConfig[$key]['inputValue1']=$this->cleanInputVal($queryConfig[$key],1);
  529. // debug($queryConfig[$key]);
  530. break;
  531. }
  532. }
  533. return $queryConfig;
  534. }
  535. /**
  536. * [Describe function...]
  537. *
  538. * @param [type] $subLevel: ...
  539. * @param [type] $queryConfig: ...
  540. * @param [type] $parent: ...
  541. * @return [type] ...
  542. */
  543. function getFormElements($subLevel=0,$queryConfig='',$parent='') {
  544. $codeArr=array();
  545. if (!is_array($queryConfig)) $queryConfig=$this->queryConfig;
  546. $c=0;
  547. $arrCount=0;
  548. foreach ($queryConfig as $key => $conf) {
  549. $subscript = $parent.'['.$key.']';
  550. $lineHTML = '';
  551. $lineHTML.=$this->mkOperatorSelect($this->name.$subscript,$conf['operator'],$c,($conf['type']!='FIELD_'));
  552. if(substr($conf['type'],0,6)=='FIELD_') {
  553. $fName = substr($conf['type'],6);
  554. $this->fieldName = $fName;
  555. $fType = $this->fields[$fName]['type'];
  556. if($conf['comparison'] >> 5 != $this->comp_offsets[$fType]) $conf['comparison'] = $this->comp_offsets[$fType] << 5;
  557. //nasty nasty...
  558. //make sure queryConfig contains _actual_ comparevalue.
  559. //mkCompSelect don't care, but getQuery does.
  560. $queryConfig[$key]['comparison'] += (isset($conf['negate'])-($conf['comparison']%2));
  561. } elseif($conf['type']=='newlevel') {
  562. $fType = $conf['type'];
  563. } else {
  564. $fType = 'ignore';
  565. }
  566. switch($fType) {
  567. case 'ignore':
  568. break;
  569. case 'newlevel':
  570. if(!$queryConfig[$key]['nl']) $queryConfig[$key]['nl'][0]['type'] = 'FIELD_';
  571. $lineHTML.='<input type="hidden" name="'.$this->name.$subscript.'[type]" value="newlevel">';
  572. $codeArr[$arrCount]['sub'] = $this->getFormElements($subLevel+1,$queryConfig[$key]['nl'],$subscript.'[nl]');
  573. break;
  574. case 'userdef':
  575. $lineHTML.=$this->userDef($this->name.$subscript,$conf,$fName,$fType);
  576. break;
  577. case 'date':
  578. $lineHTML.=$this->mkTypeSelect($this->name.$subscript.'[type]',$fName);
  579. $lineHTML.=$this->mkCompSelect($this->name.$subscript.'[comparison]',$conf['comparison'],$conf['negate']?1:0);
  580. $lineHTML.='<input type="checkbox" class="checkbox"' . ($conf['negate']?' checked':'').' name="'.$this->name.$subscript.'[negate]'.'" onClick="submit();">';
  581. if ($conf['comparison']==100 || $conf['comparison']==101) { // between
  582. $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]'.'">';
  583. $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]'.'">';
  584. $this->extJSCODE.='typo3form.fieldSet("'.$this->name.$subscript.'[inputValue]", "date", "", 0,0);';
  585. $this->extJSCODE.='typo3form.fieldSet("'.$this->name.$subscript.'[inputValue1]", "date", "", 0,0);';
  586. } else {
  587. $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]'.'">';
  588. $this->extJSCODE.='typo3form.fieldSet("'.$this->name.$subscript.'[inputValue]", "date", "", 0,0);';
  589. }
  590. break;
  591. case 'time':
  592. $lineHTML.=$this->mkTypeSelect($this->name.$subscript.'[type]', $fName);
  593. $lineHTML.=$this->mkCompSelect($this->name.$subscript.'[comparison]', $conf['comparison'], $conf['negate']?1:0);
  594. $lineHTML.='<input type="checkbox" class="checkbox"'.($conf['negate']?' checked':'').' name="'.$this->name.$subscript.'[negate]'.'" onClick="submit();">';
  595. if ($conf['comparison']==100 || $conf['comparison']==101) { // between:
  596. $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]'.'">';
  597. $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]'.'">';
  598. $this->extJSCODE.='typo3form.fieldSet("'.$this->name.$subscript.'[inputValue]", "datetime", "", 0,0);';
  599. $this->extJSCODE.='typo3form.fieldSet("'.$this->name.$subscript.'[inputValue1]", "datetime", "", 0,0);';
  600. } else {
  601. $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]'.'">';
  602. $this->extJSCODE.='typo3form.fieldSet("'.$this->name.$subscript.'[inputValue]", "datetime", "", 0,0);';
  603. }
  604. break;
  605. case 'multiple':
  606. case 'binary':
  607. case 'relation':
  608. $lineHTML.=$this->mkTypeSelect($this->name.$subscript.'[type]', $fName);
  609. $lineHTML.=$this->mkCompSelect($this->name.$subscript.'[comparison]', $conf['comparison'], $conf['negate']?1:0);
  610. $lineHTML.='<input type="checkbox" class="checkbox"'.($conf['negate']?' checked':'').' name="'.$this->name.$subscript.'[negate]'.'" onClick="submit();">';
  611. if ($conf['comparison']==68 || $conf['comparison']==69 || $conf['comparison']==162 || $conf['comparison']==163) {
  612. $lineHTML.='<select name="'.$this->name.$subscript.'[inputValue]'.'[]" style="vertical-align:top;" size="5" multiple>';
  613. } elseif ($conf['comparison']==66 || $conf['comparison']==67) {
  614. if (is_array($conf['inputValue'])) {
  615. $conf['inputValue'] = implode(',', $conf['inputValue']);
  616. }
  617. $lineHTML.= '<input type="text" value="'.htmlspecialchars($conf['inputValue']).'" name="'.$this->name.$subscript.'[inputValue]'.'"'.$GLOBALS['TBE_TEMPLATE']->formWidth(10).'>';
  618. } else {
  619. $lineHTML.= '<select name="'.$this->name.$subscript.'[inputValue]'.'" style="vertical-align:top;" onChange="submit();">';
  620. }
  621. if ($conf['comparison']!=66 && $conf['comparison']!=67) {
  622. $lineHTML.= $this->makeOptionList($fName, $conf, $this->table);
  623. $lineHTML.= '</select>';
  624. }
  625. break;
  626. case 'files':
  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" class="checkbox"'.($conf['negate']?' checked':'').' name="'.$this->name.$subscript.'[negate]'.'" onClick="submit();">';
  630. if ($conf['comparison']==68 || $conf['comparison']==69) {
  631. $lineHTML .= '<select name="'.$this->name.$subscript.'[inputValue]'.'[]" style="vertical-align:top;" size="5" multiple>';
  632. } else {
  633. $lineHTML .= '<select name="'.$this->name.$subscript.'[inputValue]'.'" style="vertical-align:top;" onChange="submit();">';
  634. }
  635. $lineHTML .= '<option value=""></option>'.$this->makeOptionList($fName, $conf, $this->table);
  636. $lineHTML .= '</select>';
  637. if ($conf['comparison']==66 || $conf['comparison']==67) {
  638. $lineHTML .= ' + <input type="text" value="'.htmlspecialchars($conf['inputValue1']).'" name="'.$this->name.$subscript.'[inputValue1]'.'"'.$GLOBALS['TBE_TEMPLATE']->formWidth(10).'>';
  639. }
  640. break;
  641. case 'boolean':
  642. $lineHTML .= $this->mkTypeSelect($this->name.$subscript.'[type]', $fName);
  643. $lineHTML .= $this->mkCompSelect($this->name.$subscript.'[comparison]', $conf['comparison'], $conf['negate']?1:0);
  644. $lineHTML .= '<input type="checkbox" class="checkbox"'.($conf['negate']?' checked':'').' name="'.$this->name.$subscript.'[negate]'.'" onClick="submit();">';
  645. $lineHTML .= '<input type="hidden" value="1" name="'.$this->name.$subscript.'[inputValue]'.'"'.$GLOBALS['TBE_TEMPLATE']->formWidth(10).'>';
  646. break;
  647. default:
  648. $lineHTML .= $this->mkTypeSelect($this->name.$subscript.'[type]', $fName);
  649. $lineHTML .= $this->mkCompSelect($this->name.$subscript.'[comparison]', $conf['comparison'], $conf['negate']?1:0);
  650. $lineHTML .= '<input type="checkbox" class="checkbox"'.($conf['negate']?' checked':'').' name="'.$this->name.$subscript.'[negate]'.'" onClick="submit();">';
  651. if ($conf['comparison']==37 || $conf['comparison']==36) { // between:
  652. $lineHTML.='<input type="text" value="'.htmlspecialchars($conf['inputValue']).'" name="'.$this->name.$subscript.'[inputValue]'.'"'.$GLOBALS['TBE_TEMPLATE']->formWidth(5).'>
  653. <input type="text" value="'.htmlspecialchars($conf['inputValue1']).'" name="'.$this->name.$subscript.'[inputValue1]'.'"'.$GLOBALS['TBE_TEMPLATE']->formWidth(5).'>'; // onChange='submit();'
  654. } else {
  655. $lineHTML.='<input type="text" value="'.htmlspecialchars($conf['inputValue']).'" name="'.$this->name.$subscript.'[inputValue]'.'"'.$GLOBALS['TBE_TEMPLATE']->formWidth(10).'>'; // onChange="submit();"
  656. }
  657. break;
  658. }
  659. if($fType != 'ignore') {
  660. $lineHTML .= $this->updateIcon();
  661. if ($loopcount) {
  662. $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.'">';
  663. }
  664. $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.'">';
  665. if($c!=0) $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.'">';
  666. if($c!=0 && $fType!='newlevel') {
  667. $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.'">';
  668. }
  669. if($fType=='newlevel') {
  670. $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.'">';
  671. }
  672. $codeArr[$arrCount]['html'] = $lineHTML;
  673. $codeArr[$arrCount]['query'] = $this->getQuerySingle($conf,$c>0?0:1);
  674. $arrCount++;
  675. $c++;
  676. }
  677. $loopcount = 1;
  678. }
  679. // $codeArr[$arrCount] .='<input type="hidden" name="CMD" value="displayQuery">';
  680. $this->queryConfig = $queryConfig;
  681. //modifyHTMLColor($color,$R,$G,$B)
  682. return $codeArr;
  683. }
  684. /**
  685. * [Describe function...]
  686. *
  687. * @param [type] $codeArr: ...
  688. * @param [type] $l: ...
  689. * @param [type] $table: ...
  690. * @return [type] ...
  691. */
  692. function makeOptionList($fN, $conf, $table) {
  693. $fieldSetup = $this->fields[$fN];
  694. if ($fieldSetup['type']=='files') {
  695. if ($conf['comparison']==66 || $conf['comparison']==67) {
  696. $fileExtArray = explode(',', $fieldSetup['allowed']);
  697. natcasesort($fileExtArray);
  698. foreach ($fileExtArray as $fileExt) {
  699. if (t3lib_div::inList($conf['inputValue'], $fileExt)) {
  700. $out .= '<option value="'.$fileExt.'" selected>.'.$fileExt.'</option>';
  701. } else {
  702. $out .= '<option value="'.$fileExt.'">.'.$fileExt.'</option>';
  703. }
  704. }
  705. }
  706. $d = dir(t3lib_div::getIndpEnv(TYPO3_DOCUMENT_ROOT).'/'.$fieldSetup['uploadfolder']);
  707. while (false !== ($entry=$d->read())) {
  708. if ($entry=='.' || $entry=='..') {
  709. continue;
  710. }
  711. $fileArray[] = $entry;
  712. }
  713. $d->close();
  714. natcasesort($fileArray);
  715. foreach ($fileArray as $fileName) {
  716. if (t3lib_div::inList($conf['inputValue'], $fileName)) {
  717. $out .= '<option value="'.$fileName.'" selected>'.$fileName.'</option>';
  718. } else {
  719. $out .= '<option value="'.$fileName.'">'.$fileName.'</option>';
  720. }
  721. }
  722. }
  723. if ($fieldSetup['type']=='multiple') {
  724. foreach ($fieldSetup['items'] as $key=>$val) {
  725. if (substr($val[0], 0, 4) == 'LLL:') {
  726. $value = $GLOBALS['LANG']->sL($val[0]);
  727. } else {
  728. $value = $val[0];
  729. }
  730. if (t3lib_div::inList($conf['inputValue'], $val[1])) {
  731. $out .= '<option value="'.$val[1].'" selected>'.$value.'</option>';
  732. } else {
  733. $out .= '<option value="'.$val[1].'">'.$value.'</option>';
  734. }
  735. }
  736. }
  737. if ($fieldSetup['type']=='binary') {
  738. foreach ($fieldSetup['items'] as $key=>$val) {
  739. if (substr($val[0], 0, 4)=='LLL:') {
  740. $value = $GLOBALS['LANG']->sL($val[0]);
  741. } else {
  742. $value = $val[0];
  743. }
  744. if (t3lib_div::inList($conf['inputValue'], pow(2, $key))) {
  745. $out .= '<option value="'.pow(2, $key).'" selected>'.$value.'</option>';
  746. } else {
  747. $out .= '<option value="'.pow(2, $key).'">'.$value.'</option>';
  748. }
  749. }
  750. }
  751. if ($fieldSetup['type']=='relation') {
  752. if ($fieldSetup['items']) {
  753. foreach ($fieldSetup['items'] as $key=>$val) {
  754. if (substr($val[0], 0, 4) == 'LLL:') {
  755. $value = $GLOBALS['LANG']->sL($val[0]);
  756. } else {
  757. $value = $val[0];
  758. }
  759. if (t3lib_div::inList($conf['inputValue'], $val[1])) {
  760. $out .= '<option value="'.$val[1].'" selected>'.$value.'</option>';
  761. } else {
  762. $out .= '<option value="'.$val[1].'">'.$value.'</option>';
  763. }
  764. }
  765. }
  766. global $TCA;
  767. if (stristr($fieldSetup['allowed'], ',')) {
  768. $from_table_Arr = explode(',', $fieldSetup['allowed']);
  769. $useTablePrefix = 1;
  770. if (!$fieldSetup['prepend_tname']) {
  771. $checkres = $GLOBALS['TYPO3_DB']->exec_SELECTquery($fN, $table, t3lib_BEfunc::deleteClause($table), $groupBy = '', $orderBy = '', $limit = '');
  772. if ($checkres) {
  773. while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($checkres)) {
  774. if (stristr($row[$fN], ',')) {
  775. $checkContent = explode(',', $row[$fN]);
  776. foreach ($checkContent as $singleValue) {
  777. if (!stristr($singleValue, '_')) {
  778. $dontPrefixFirstTable = 1;
  779. }
  780. }
  781. } else {
  782. $singleValue = $row[$fN];
  783. if (strlen($singleValue) && !stristr($singleValue, '_')) {
  784. $dontPrefixFirstTable = 1;
  785. }
  786. }
  787. }
  788. }
  789. }
  790. } else {
  791. $from_table_Arr[0] = $fieldSetup['allowed'];
  792. }
  793. if ($fieldSetup['prepend_tname']) {
  794. $useTablePrefix = 1;
  795. }
  796. if ($fieldSetup['foreign_table']) {
  797. $from_table_Arr[0] = $fieldSetup['foreign_table'];
  798. }
  799. $counter = 0;
  800. while (list(, $from_table) = each($from_table_Arr)) {
  801. if (($useTablePrefix && !$dontPrefixFirstTable && $counter!=1) || $counter==1) {
  802. $tablePrefix = $from_table.'_';
  803. }
  804. $counter = 1;
  805. if (is_array($TCA[$from_table])) {
  806. t3lib_div::loadTCA($from_table);
  807. $labelField = $TCA[$from_table]['ctrl']['label'];
  808. $altLabelField = $TCA[$from_table]['ctrl']['label_alt'];
  809. if ($TCA[$from_table]['columns'][$labelField]['config']['items']) {
  810. foreach ($TCA[$from_table]['columns'][$labelField]['config']['items'] as $labelArray) {
  811. if (substr($labelArray[0], 0, 4) == 'LLL:') {
  812. $labelFieldSelect[$labelArray[1]] = $GLOBALS['LANG']->sL($labelArray[0]);
  813. } else {
  814. $labelFieldSelect[$labelArray[1]] = $labelArray[0];
  815. }
  816. }
  817. $useSelectLabels = 1;
  818. }
  819. if ($TCA[$from_table]['columns'][$altLabelField]['config']['items']) {
  820. foreach ($TCA[$from_table]['columns'][$altLabelField]['config']['items'] as $altLabelArray) {
  821. if (substr($altLabelArray[0], 0, 4) == 'LLL:') {
  822. $altLabelFieldSelect[$altLabelArray[1]] = $GLOBALS['LANG']->sL($altLabelArray[0]);
  823. } else {
  824. $altLabelFieldSelect[$altLabelArray[1]] = $altLabelArray[0];
  825. }
  826. }
  827. $useAltSelectLabels = 1;
  828. }
  829. $altLabelFieldSelect = $altLabelField ? ','.$altLabelField : '';
  830. $select_fields = 'uid,'.$labelField.$altLabelFieldSelect;
  831. if (!$GLOBALS['BE_USER']->isAdmin() && $GLOBALS['TYPO3_CONF_VARS']['BE']['lockBeUserToDBmounts']) {
  832. $webMounts = $GLOBALS['BE_USER']->returnWebmounts();
  833. $perms_clause = $GLOBALS['BE_USER']->getPagePermsClause(1);
  834. foreach ($webMounts as $key => $val) {
  835. if ($webMountPageTree) {
  836. $webMountPageTreePrefix = ',';
  837. }
  838. $webMountPageTree .= $webMountPageTreePrefix.$this->getTreeList($val, 999, $begin = 0, $perms_clause);
  839. }
  840. if ($from_table=='pages') {
  841. $where_clause = 'uid IN ('.$webMountPageTree.') ';
  842. if (!$GLOBALS['SOBE']->MOD_SETTINGS['show_deleted']) {
  843. $where_clause .= t3lib_BEfunc::deleteClause($from_table).' AND'.$perms_clause;
  844. }
  845. } else {
  846. $where_clause = 'pid IN ('.$webMountPageTree.') ';
  847. if (!$GLOBALS['SOBE']->MOD_SETTINGS['show_deleted']) {
  848. $where_clause .= t3lib_BEfunc::deleteClause($from_table);
  849. }
  850. }
  851. } else {
  852. $where_clause = 'uid';
  853. if (!$GLOBALS['SOBE']->MOD_SETTINGS['show_deleted']) {
  854. $where_clause .= t3lib_BEfunc::deleteClause($from_table);
  855. }
  856. }
  857. $orderBy = 'uid';
  858. if (!$this->tableArray[$from_table]) {
  859. $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($select_fields, $from_table, $where_clause, $groupBy = '', $orderBy, $limit = '');
  860. }
  861. if ($res) {
  862. while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
  863. $this->tableArray[$from_table][] = $row;
  864. }
  865. }
  866. foreach ($this->tableArray[$from_table] as $key=>$val) {
  867. if ($useSelectLabels) {
  868. $outArray[$tablePrefix.$val['uid']] = htmlspecialchars($labelFieldSelect[$val[$labelField]]);
  869. } elseif ($val[$labelField]) {
  870. $outArray[$tablePrefix.$val['uid']] = htmlspecialchars($val[$labelField]);
  871. } elseif ($useAltSelectLabels) {
  872. $outArray[$tablePrefix.$val['uid']] = htmlspecialchars($altLabelFieldSelect[$val[$altLabelField]]);
  873. } else {
  874. $outArray[$tablePrefix.$val['uid']] = htmlspecialchars($val[$altLabelField]);
  875. }
  876. }
  877. if ($GLOBALS['SOBE']->MOD_SETTINGS['options_sortlabel'] && is_array($outArray)) {
  878. natcasesort($outArray);
  879. }
  880. }
  881. }
  882. foreach ($outArray as $key2 => $val2) {
  883. if (t3lib_div::inList($conf['inputValue'], $key2)) {
  884. $out .= '<option value="'.$key2.'" selected>['.$key2.'] '.$val2.'</option>';
  885. } else {
  886. $out .= '<option value="'.$key2.'">['.$key2.'] '.$val2.'</option>';
  887. }
  888. }
  889. }
  890. return $out;
  891. }
  892. /**
  893. * [Describe function...]
  894. *
  895. * @param [type] $codeArr: ...
  896. * @param [type] $l: ...
  897. * @return [type] ...
  898. */
  899. function printCodeArray($codeArr,$l=0) {
  900. $line='';
  901. if ($l) $indent='<td style="vertical-align:top;"><img height="1" width="50"></td>';
  902. $lf=$l*30;
  903. $bgColor = t3lib_div::modifyHTMLColor($GLOBALS['TBE_TEMPLATE']->bgColor2,$lf,$lf,$lf);
  904. foreach ($codeArr as $k => $v) {
  905. $line.= '<tr>'.$indent.'<td bgcolor="'.$bgColor.'"'.$this->noWrap.'>'.$v['html'].'</td></tr>';
  906. if ($this->enableQueryParts) {$line.= '<tr>'.$indent.'<td>'.$this->formatQ($v['query']).'</td></tr>';}
  907. if (is_array($v['sub'])) {
  908. $line.= '<tr>'.$indent.'<td'.$this->noWrap.'>'.$this->printCodeArray($v['sub'],$l+1).'</td></tr>';
  909. }
  910. }
  911. $out='<table border="0" cellpadding="0" cellspacing="1">'.$line.'</table>';
  912. return $out;
  913. }
  914. /**
  915. * [Describe function...]
  916. *
  917. * @param [type] $str: ...
  918. * @return [type] ...
  919. */
  920. function formatQ($str) {
  921. return '<font size="1" face="verdana" color="maroon"><i>' . htmlspecialchars($str) . '</i></font>';
  922. }
  923. /**
  924. * [Describe function...]
  925. *
  926. * @param [type] $name: ...
  927. * @param [type] $op: ...
  928. * @param [type] $draw: ...
  929. * @param [type] $submit: ...
  930. * @return [type] ...
  931. */
  932. function mkOperatorSelect($name,$op,$draw,$submit) {
  933. if ($draw) {
  934. $out='<select name="'.$name.'[operator]"'.($submit?' onChange="submit();"':'').'>'; //
  935. $out.='<option value="AND"'.(!$op||$op=="AND" ? ' selected':'').'>'.$this->lang["AND"].'</option>';
  936. $out.='<option value="OR"'.($op=='OR' ? ' selected':'').'>'.$this->lang['OR'].'</option>';
  937. $out.='</select>';
  938. } else {
  939. $out.='<input type="hidden" value="'.$op.'" name="'.$name.'[operator]">';
  940. $out.='<img src="clear.gif" height="1" width="47">';
  941. }
  942. return $out;
  943. }
  944. /**
  945. * [Describe function...]
  946. *
  947. * @param [type] $name: ...
  948. * @param [type] $fieldName: ...
  949. * @param [type] $prepend: ...
  950. * @return [type] ...
  951. */
  952. function mkTypeSelect($name,$fieldName,$prepend='FIELD_') {
  953. $out='<select name="'.$name.'" onChange="submit();">';
  954. $out.='<option value=""></option>';
  955. foreach ($this->fields as $key => $value) {
  956. if (!$fieldValue['exclude'] || $GLOBALS['BE_USER']->check('non_exclude_fields', $this->table.':'.$key)) {
  957. $label = $this->fields[$key]['label'];
  958. $label_alt = $this->fields[$key]['label_alt'];
  959. $out .= '<option value="'.$prepend.$key.'"'.($key==$fieldName ? ' selected' : '').'>'.$label.'</option>';
  960. }
  961. }
  962. $out.='</select>';
  963. return $out;
  964. }
  965. /**
  966. * [Describe function...]
  967. *
  968. * @param [type] $fieldName: ...
  969. * @return [type] ...
  970. */
  971. function verifyType($fieldName) {
  972. $first = '';
  973. foreach ($this->fields as $key => $value) {
  974. if (!$first) $first = $key;
  975. if ($key==$fieldName) return $key;
  976. }
  977. return $first;
  978. }
  979. /**
  980. * [Describe function...]
  981. *
  982. * @param [type] $comparison: ...
  983. * @param [type] $neg: ...
  984. * @return [type] ...
  985. */
  986. function verifyComparison($comparison,$neg) {
  987. $compOffSet = $comparison >> 5;
  988. $first=-1;
  989. for($i=32*$compOffSet+$neg;$i<32*($compOffSet+1);$i+=2) {
  990. if ($first==-1) $first = $i;
  991. if (($i >> 1)==($comparison >> 1)) {
  992. return $i;
  993. }
  994. }
  995. return $first;
  996. }
  997. /**
  998. * [Describe function...]
  999. *
  1000. * @param [type] $name: ...
  1001. * @param [type] $fieldName: ...
  1002. * @return [type] ...
  1003. */
  1004. function mkFieldToInputSelect($name,$fieldName) {
  1005. $out='<input type="Text" value="'.htmlspecialchars($fieldName).'" name="'.$name.'"'.$GLOBALS['TBE_TEMPLATE']->formWidth().'>'.$this->updateIcon();
  1006. $out.='<a href="#" onClick="document.forms[0][\''.$name.'\'].value=\'\';return false;">' . t3lib_iconWorks::getSpriteIcon('actions-edit-delete', array('title' => 'Clear list')) . '</a>';
  1007. $out.='<BR><select name="_fieldListDummy" size="5" onChange="document.forms[0][\''.$name.'\'].value+=\',\'+this.value">';
  1008. foreach ($this->fields as $key => $value) {
  1009. if (!$fieldValue['exclude'] || $GLOBALS['BE_USER']->check('non_exclude_fields', $this->table.':'.$key)) {
  1010. $label = $this->fields[$key]['label'];
  1011. $label_alt = $this->fields[$key]['label_alt'];
  1012. $out .= '<option value="'.$key.'"'.($key==$fieldName ? ' selected':'').'>'.$label.'</option>';
  1013. }
  1014. }
  1015. $out.='</select>';
  1016. return $out;
  1017. }
  1018. /**
  1019. * [Describe function...]
  1020. *
  1021. * @param [type] $name: ...
  1022. * @param [type] $cur: ...
  1023. * @return [type] ...
  1024. */
  1025. function mkTableSelect($name,$cur) {
  1026. global $TCA;
  1027. $out='<select name="'.$name.'" onChange="submit();">';
  1028. $out.='<option value=""></option>';
  1029. foreach ($TCA as $tN => $value) {
  1030. if ($GLOBALS['BE_USER']->check('tables_select',$tN)) {
  1031. $out.='<option value="'.$tN.'"'.($tN==$cur ? ' selected':'').'>'.$GLOBALS['LANG']->sl($TCA[$tN]['ctrl']['title']).'</option>';
  1032. }
  1033. }
  1034. $out.='</select>';
  1035. return $out;
  1036. }
  1037. /**
  1038. * [Describe function...]
  1039. *
  1040. * @param [type] $name: ...
  1041. * @param [type] $comparison: ...
  1042. * @param [type] $neg: ...
  1043. * @return [type] ...
  1044. */
  1045. function mkCompSelect($name,$comparison,$neg) {
  1046. $compOffSet = $comparison >> 5;
  1047. $out='<select name="'.$name.'" onChange="submit();">';
  1048. for($i=32*$compOffSet+$neg;$i<32*($compOffSet+1);$i+=2) {
  1049. if($this->lang['comparison'][$i.'_']) {
  1050. $out.='<option value="'.$i.'"'.(($i >> 1)==($comparison >> 1) ? ' selected':'').'>'.$this->lang['comparison'][$i.'_'].'</option>';
  1051. }
  1052. }
  1053. $out.='</select>';
  1054. return $out;
  1055. }
  1056. /**
  1057. * [Describe function...]
  1058. *
  1059. * @param [type] $arr: ...
  1060. * @return [type] ...
  1061. */
  1062. function getSubscript($arr) {
  1063. while(is_array($arr)) {
  1064. reset($arr);
  1065. list($key,)=each($arr);
  1066. $retArr[] = $key;
  1067. $arr = $arr[$key];
  1068. }
  1069. return $retArr;
  1070. }
  1071. /**
  1072. * [Describe function...]
  1073. *
  1074. * @return [type] ...
  1075. */
  1076. function initUserDef() {
  1077. }
  1078. /**
  1079. * [Describe function...]
  1080. *
  1081. * @return [type] ...
  1082. */
  1083. function userDef() {
  1084. }
  1085. /**
  1086. * [Describe function...]
  1087. *
  1088. * @param [type] $queryConfig: ...
  1089. * @return [type] ...
  1090. */
  1091. function userDefCleanUp($queryConfig) {
  1092. return $queryConfig;
  1093. }
  1094. /**
  1095. * [Describe function...]
  1096. *
  1097. * @param [type] $queryConfig: ...
  1098. * @param [type] $pad: ...
  1099. * @return [type] ...
  1100. */
  1101. function getQuery ($queryConfig,$pad='') {
  1102. $qs = '';
  1103. // Since we don't traverse the array using numeric keys in the upcoming whileloop make sure it's fresh and clean
  1104. ksort($queryConfig);
  1105. $first=1;
  1106. foreach ($queryConfig as $key => $conf) {
  1107. switch($conf['type']) {
  1108. case 'newlevel':
  1109. $qs.=LF.$pad.trim($conf['operator']).' ('.$this->getQuery($queryConfig[$key]['nl'],$pad.' ').LF.$pad.')';
  1110. break;
  1111. case 'userdef':
  1112. $qs.=LF.$pad.getUserDefQuery($conf,$first);
  1113. break;
  1114. default:
  1115. $qs.=LF.$pad.$this->getQuerySingle($conf,$first);
  1116. break;
  1117. }
  1118. $first=0;
  1119. }
  1120. return $qs;
  1121. }
  1122. /**
  1123. * [Describe function...]
  1124. *
  1125. * @param [type] $conf: ...
  1126. * @param [type] $first: ...
  1127. * @return [type] ...
  1128. */
  1129. function getQuerySingle($conf,$first) {
  1130. $prefix = $this->enablePrefix ? $this->table.'.' : '';
  1131. if (!$first) {
  1132. // Is it OK to insert the AND operator if none is set?
  1133. $qs .= trim(($conf['operator'] ? $conf['operator'] : 'AND')).' ';
  1134. }
  1135. $qsTmp = str_replace('#FIELD#', $prefix.trim(substr($conf['type'],6)), $this->compSQL[$conf['comparison']]);
  1136. $inputVal = $this->cleanInputVal($conf);
  1137. if ($conf['comparison']==68 || $conf['comparison']==69) {
  1138. $inputVal = explode(',', $inputVal);
  1139. foreach ($inputVal as $key => $fileName) {
  1140. $inputVal[$key] = "'".$fileName."'";
  1141. }
  1142. $inputVal = implode(',', $inputVal);
  1143. $qsTmp = str_replace('#VALUE#', $inputVal, $qsTmp);
  1144. } elseif ($conf['comparison']==162 || $conf['comparison']==163) {
  1145. $inputValArray = explode(',', $inputVal);
  1146. $inputVal = 0;
  1147. foreach ($inputValArray as $key=>$fileName) {
  1148. $inputVal += intval($fileName);
  1149. }
  1150. $qsTmp = str_replace('#VALUE#', $inputVal, $qsTmp);
  1151. } else {
  1152. $qsTmp = str_replace('#VALUE#', $GLOBALS['TYPO3_DB']->quoteStr($inputVal,$this->table), $qsTmp);
  1153. }
  1154. if ($conf['comparison']==37 || $conf['comparison']==36 || $conf['comparison']==66 || $conf['comparison']==67 || $conf['comparison']==100 || $conf['comparison']==101) { // between:
  1155. $inputVal = $this->cleanInputVal($conf,'1');
  1156. $qsTmp = str_replace('#VALUE1#', $GLOBALS['TYPO3_DB']->quoteStr($inputVal,$this->table), $qsTmp);
  1157. }
  1158. $qs .= trim($qsTmp);
  1159. return $qs;
  1160. }
  1161. /**
  1162. * [Describe function...]
  1163. *
  1164. * @param [type] $conf: ...
  1165. * @param [type] $suffix: ...
  1166. * @return [type] ...
  1167. */
  1168. function cleanInputVal($conf,$suffix='') {
  1169. 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)) {
  1170. $inputVal = $conf['inputValue'.$suffix];
  1171. } elseif ($conf['comparison']==39 || $conf['comparison']==38) { // in list:
  1172. $inputVal = implode(',',t3lib_div::intExplode(',',$conf['inputValue'.$suffix]));
  1173. } elseif ($conf['comparison']==68 || $conf['comparison']==69 || $conf['comparison']==162 || $conf['comparison']==163) { // in list:
  1174. if (is_array($conf['inputValue'.$suffix])) {
  1175. $inputVal = implode(',', $conf['inputValue'.$suffix]);
  1176. } elseif ($conf['inputValue'.$suffix]) {
  1177. $inputVal = $conf['inputValue'.$suffix];
  1178. } else {
  1179. $inputVal = 0;
  1180. }
  1181. } else {
  1182. $inputVal = doubleval($conf['inputValue'.$suffix]);
  1183. }
  1184. return $inputVal;
  1185. }
  1186. /**
  1187. * [Describe function...]
  1188. *
  1189. * @param [type] $qcArr: ...
  1190. * @return [type] ...
  1191. */
  1192. function getUserDefQuery ($qcArr) {
  1193. }
  1194. /**
  1195. * [Describe function...]
  1196. *
  1197. * @return [type] ...
  1198. */
  1199. function updateIcon() {
  1200. 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">';
  1201. }
  1202. /**
  1203. * [Describe function...]
  1204. *
  1205. * @return [type] ...
  1206. */
  1207. function getLabelCol() {
  1208. global $TCA;
  1209. return $TCA[$this->table]['ctrl']['label'];
  1210. }
  1211. /**
  1212. * [Describe function...]
  1213. *
  1214. * @param [type] $modSettings: ...
  1215. * @param [type] $enableList: ...
  1216. * @return [type] ...
  1217. */
  1218. function makeSelectorTable($modSettings,$enableList='table,fields,query,group,order,limit') {
  1219. $enableArr=explode(',',$enableList);
  1220. // Make output
  1221. $TDparams = ' class="bgColor5" nowrap';
  1222. if (in_array('table',$enableArr) && !$GLOBALS['BE_USER']->userTS['mod.']['dbint.']['disableSelectATable']) {
  1223. $out='
  1224. <tr>
  1225. <td'.$TDparams.'><strong>Select a table:</strong></td>
  1226. <td'.$TDparams.'>'.$this->mkTableSelect('SET[queryTable]',$this->table).'</td>
  1227. </tr>';
  1228. }
  1229. if ($this->table) {
  1230. // Init fields:
  1231. $this->setAndCleanUpExternalLists('queryFields',$modSettings['queryFields'],'uid,'.$this->getLabelCol());
  1232. $this->setAndCleanUpExternalLists('queryGroup',$modSettings['queryGroup']);
  1233. $this->setAndCleanUpExternalLists('queryOrder',$modSettings['queryOrder'].','.$modSettings['queryOrder2']);
  1234. // Limit:
  1235. $this->extFieldLists['queryLimit']=$modSettings['queryLimit'];
  1236. if (!$this->extFieldLists['queryLimit']) $this->extFieldLists['queryLimit']=100;
  1237. $parts = t3lib_div::intExplode(',',$this->extFieldLists['queryLimit']);
  1238. if ($parts[1]) {
  1239. $this->limitBegin = $parts[0];
  1240. $this->limitLength = $parts[1];
  1241. } else {
  1242. $this->limitLength = $this->extFieldLists['queryLimit'];
  1243. }
  1244. $this->extFieldLists['queryLimit'] = implode(',',array_slice($parts,0,2));
  1245. // Insert Descending parts
  1246. if ($this->extFieldLists['queryOrder']) {
  1247. $descParts = explode(',',$modSettings['queryOrderDesc'].','.$modSettings['queryOrder2Desc']);
  1248. $orderParts = explode(',',$this->extFieldLists['queryOrder']);
  1249. $reList=array();
  1250. foreach ($orderParts as $kk => $vv) {
  1251. $reList[]=$vv.($descParts[$kk]?' DESC':'');
  1252. }
  1253. $this->extFieldLists['queryOrder_SQL'] = implode(',',$reList);
  1254. }
  1255. // Query Generator:
  1256. $this->procesData($modSettings['queryConfig'] ? unserialize($modSettings['queryConfig']) : '');
  1257. // debug($this->queryConfig);
  1258. $this->queryConfig = $this->cleanUpQueryConfig($this->queryConfig);
  1259. // debug($this->queryConfig);
  1260. $this->enableQueryParts = $modSettings['search_query_smallparts'];
  1261. $codeArr=$this->getFormElements();
  1262. $queryCode=$this->printCodeArray($codeArr);
  1263. if (in_array('fields',$enableArr) && !$GLOBALS['BE_USER']->userTS['mod.']['dbint.']['disableSelectFields']) {
  1264. $out.='
  1265. <tr>
  1266. <td'.$TDparams.'><strong>Select fields:</strong></td>
  1267. <td'.$TDparams.'>'.$this->mkFieldToInputSelect('SET[queryFields]',$this->extFieldLists['queryFields']).'</td>
  1268. </tr>';
  1269. }
  1270. if (in_array('query',$enableArr) && !$GLOBALS['BE_USER']->userTS['mod.']['dbint.']['disableMakeQuery']) {
  1271. $out.='<tr>
  1272. <td colspan="2"'.$TDparams.'><strong>Make Query:</strong></td>
  1273. </tr>
  1274. <tr>
  1275. <td colspan="2">'.$queryCode.'</td>
  1276. </tr>
  1277. ';
  1278. }
  1279. if (in_array('group',$enableArr) && !$GLOBALS['BE_USER']->userTS['mod.']['dbint.']['disableGroupBy']) {
  1280. $out.='<tr>
  1281. <td'.$TDparams.'><strong>Group By:</strong></td>
  1282. <td'.$TDparams.'>'.$this->mkTypeSelect('SET[queryGroup]',$this->extFieldLists['queryGroup'],'').'</td>
  1283. </tr>';
  1284. }
  1285. if (in_array('order',$enableArr) && !$GLOBALS['BE_USER']->userTS['mod.']['dbint.']['disableOrderBy']) {
  1286. $orderByArr = explode(',',$this->extFieldLists['queryOrder']);
  1287. // debug($orderByArr);
  1288. $orderBy='';
  1289. $orderBy.=$this->mkTypeSelect('SET[queryOrder]',$orderByArr[0],'').
  1290. '&nbsp;'.t3lib_BEfunc::getFuncCheck($GLOBALS['SOBE']->id,'SET[queryOrderDesc]',$modSettings['queryOrderDesc'],'','','id="checkQueryO…

Large files files are truncated, but you can click here to view the full file