Fixed a FlexForm problem in class.t3lib_transferdata.php
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_transferdata.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2004 Kasper Skaarhoj (kasper@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 * Contains class for getting and transforming data for display in backend forms (TCEforms)
29 *
30 * $Id$
31 * Revised for TYPO3 3.6 September/2003 by Kasper Skaarhoj
32 *
33 * @author Kasper Skaarhoj <kasper@typo3.com>
34 */
35 /**
36 * [CLASS/FUNCTION INDEX of SCRIPT]
37 *
38 *
39 *
40 * 97: class t3lib_transferData
41 *
42 * SECTION: Getting record content, ready for display in TCEforms
43 * 135: function fetchRecord($table,$idList,$operation)
44 * 221: function renderRecord($table, $id, $pid, $row)
45 * 288: function renderRecord_SW($data,$fieldConfig,$TSconfig,$table,$row,$field)
46 * 318: function renderRecord_groupProc($data,$fieldConfig,$TSconfig,$table,$row,$field)
47 * 369: function renderRecord_selectProc($data,$fieldConfig,$TSconfig,$table,$row,$field)
48 * 431: function renderRecord_flexProc($data,$fieldConfig,$TSconfig,$table,$row,$field)
49 * 460: function renderRecord_typesProc($totalRecordContent,$types_fieldConfig,$tscPID,$table,$pid)
50 *
51 * SECTION: FlexForm processing functions
52 * 544: function renderRecord_flexProc_procInData($dataPart,$dataStructArray,$pParams)
53 * 573: function renderRecord_flexProc_procInData_travDS(&$dataValues,$DSelements,$pParams)
54 *
55 * SECTION: Selector box processing functions
56 * 648: function selectAddSpecial($dataAcc, $elements, $specialKey)
57 * 728: function selectAddForeign($dataAcc, $elements, $fieldConfig, $field, $TSconfig, $row)
58 * 781: function getDataIdList($elements, $fieldConfig, $row)
59 * 804: function procesItemArray($selItems,$config,$fieldTSConfig,$table,$row,$field)
60 * 819: function addItems($items,$iArray)
61 * 841: function procItems($items,$itemsProcFuncTSconfig,$config,$table,$row,$field)
62 *
63 * SECTION: Helper functions
64 * 876: function lockRecord($table, $id, $pid=0)
65 * 893: function regItem($table, $id, $field, $content)
66 * 903: function sL($in)
67 *
68 * TOTAL FUNCTIONS: 18
69 * (This index is automatically created/updated by the extension "extdeveval")
70 *
71 */
72
73
74
75 require_once (PATH_t3lib.'class.t3lib_loadmodules.php');
76 require_once (PATH_t3lib.'class.t3lib_parsehtml_proc.php');
77
78
79
80
81
82
83
84
85
86
87
88
89
90 /**
91 * Class for getting and transforming data for display in backend forms (TCEforms)
92 *
93 * @author Kasper Skaarhoj <kasper@typo3.com>
94 * @package TYPO3
95 * @subpackage t3lib
96 */
97 class t3lib_transferData {
98 // External, static:
99 var $lockRecords=0; // If set, the records requested are locked.
100 var $disableRTE=0; // Is set externally if RTE is disabled.
101 var $prevPageID = ''; // If the pid in the command is 'prev' then $prevPageID is used as pid for the record. This is used to attach new records to other previous records eg. new pages.
102 var $defVals=array(); // Can be set with an array of default values for tables. First key is table name, second level keys are field names. Originally this was a GLOBAL array used internally.
103
104 // Internal, dynamic
105 var $regTableItems = Array(); // Used to register, which items are already loaded!!
106 var $regTableItems_data = Array(); // This stores the record data of the loaded records
107 var $loadModules=''; // Contains loadModules object, if used. (for reuse internally)
108
109
110
111
112
113
114
115
116
117
118 /***********************************************
119 *
120 * Getting record content, ready for display in TCEforms
121 *
122 ***********************************************/
123
124 /**
125 * A function which can be used for load a batch of records from $table into internal memory of this object.
126 * The function is also used to produce proper default data for new records
127 * Ultimately the function will call renderRecord()
128 *
129 * @param string Table name, must be found in $TCA
130 * @param string Comma list of id values. If $idList is "prev" then the value from $this->prevPageID is used. NOTICE: If $operation is "new", then negative ids are meant to point to a "previous" record and positive ids are PID values for new records. Otherwise (for existing records that is) it is straight forward table/id pairs.
131 * @param string If "new", then a record with default data is returned. Further, the $id values are meant to be PID values (or if negative, pointing to a previous record). If NOT new, then the table/ids are just pointing to an existing record!
132 * @return void
133 * @see renderRecord()
134 */
135 function fetchRecord($table,$idList,$operation) {
136 global $TCA;
137
138 if ((string)$idList == 'prev') {$idList = $this->prevPageID;}
139
140 if ($TCA[$table]) {
141 t3lib_div::loadTCA($table);
142
143 // For each ID value (integer) we
144 $ids = t3lib_div::trimExplode(',',$idList,1);
145 foreach($ids as $id) {
146 if (strcmp($id,'')) { // If ID is not blank:
147
148 // For new records to be created, find default values:
149 if ($operation=='new') {
150
151 // Default values:
152 $newRow = Array(); // Used to store default values as found here:
153
154 // Default values as set in userTS:
155 $TCAdefaultOverride = $GLOBALS['BE_USER']->getTSConfigProp('TCAdefaults');
156 if (is_array($TCAdefaultOverride[$table.'.'])) {
157 foreach($TCAdefaultOverride[$table.'.'] as $theF => $theV) {
158 if (isset($TCA[$table]['columns'][$theF])) {
159 $newRow[$theF]=$theV;
160 }
161 }
162 }
163
164 // Default values as submitted:
165 if (is_array($this->defVals[$table])) {
166 foreach($this->defVals[$table] as $theF => $theV) {
167 if (isset($TCA[$table]['columns'][$theF])) {
168 $newRow[$theF]=$theV;
169 }
170 }
171 }
172
173 // Fetch default values if a previous record exists
174 if ($id<0 && $TCA[$table]['ctrl']['useColumnsForDefaultValues']) {
175 // Fetches the previous record:
176 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', $table, 'uid='.abs($id).t3lib_BEfunc::deleteClause($table));
177 if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
178 // Gets the list of fields to copy from the previous record.
179 $fArr=t3lib_div::trimExplode(',',$TCA[$table]['ctrl']['useColumnsForDefaultValues'],1);
180 while(list(,$theF)=each($fArr)) {
181 if (isset($TCA[$table]['columns'][$theF])) {
182 $newRow[$theF]=$row[$theF];
183 }
184 }
185 }
186 $GLOBALS['TYPO3_DB']->sql_free_result($res);
187 }
188
189 // Finally, call renderRecord:
190 $this->renderRecord($table, uniqid('NEW'), $id, $newRow);
191 } else {
192 $id=intval($id);
193
194 // Fetch database values
195 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', $table, 'uid='.intval($id).t3lib_BEfunc::deleteClause($table));
196 if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
197 $this->renderRecord($table, $id, $row['pid'], $row);
198 $contentTable = $GLOBALS['TYPO3_CONF_VARS']['SYS']['contentTable'];
199 $this->lockRecord($table, $id, $contentTable==$table?$row['pid']:0); // Locking the pid if the table edited is the content table.
200 }
201 $GLOBALS['TYPO3_DB']->sql_free_result($res);
202 }
203 }
204 }
205 }
206 }
207
208 /**
209 * This function performs processing on the input $row array and stores internally a corresponding array which contains processed values, ready to pass on to the TCEforms rendering in the frontend!
210 * The objective with this function is to prepare the content for handling in TCEforms.
211 * Default values from outside/TSconfig is added by fetchRecord(). In this function default values from TCA is used if a field is NOT defined in $row.
212 * The resulting, processed row is stored in $this->regTableItems_data[$uniqueItemRef], where $uniqueItemRef is "[tablename]_[id-value]"
213 *
214 * @param string The table name
215 * @param string The uid value of the record (integer). Can also be a string (NEW-something) if the record is a NEW record.
216 * @param integer The pid integer. For existing records this is of course the row's "pid" field. For new records it can be either a page id (positive) or a pointer to another record from the SAME table (negative) after which the record should be inserted (or on same page)
217 * @param array The row of the current record. If NEW record, then it may be loaded with default values (by eg. fetchRecord()).
218 * @return void
219 * @see fetchRecord()
220 */
221 function renderRecord($table, $id, $pid, $row) {
222 global $TCA;
223
224 // Init:
225 $uniqueItemRef = $table.'_'.$id;
226 t3lib_div::loadTCA($table);
227
228 // Fetches the true PAGE TSconfig pid to use later, if needed. (Until now, only for the RTE, but later..., who knows?)
229 list($tscPID)=t3lib_BEfunc::getTSCpid($table,$id,$pid);
230 $TSconfig = t3lib_BEfunc::getTCEFORM_TSconfig($table,array_merge($row,array('uid'=>$id,'pid'=>$pid)));
231
232 // If the record has not already been loaded (in which case we DON'T do it again)...
233 if (!$this->regTableItems[$uniqueItemRef]) {
234 $this->regTableItems[$uniqueItemRef] = 1; // set "loaded" flag.
235
236 // If the table is pages, set the previous page id internally.
237 if ($table == 'pages') {$this->prevPageID = $id;}
238
239 // Create blank accumulation array:
240 $totalRecordContent=array();
241
242 // Traverse the configured columns for the table (TCA):
243 // For each column configured, we will perform processing if needed based on the type (eg. for "group" and "select" types this is needed)
244 $copyOfColumns = $TCA[$table]['columns'];
245 foreach($copyOfColumns as $field => $fieldConfig) {
246 // Set $data variable for the field, either inputted value from $row - or if not found, the default value as defined in the "config" array
247 if (isset($row[$field])) {
248 $data = $row[$field];
249 } else {
250 $data = $fieldConfig['config']['default'];
251 }
252
253 $data = $this->renderRecord_SW($data,$fieldConfig,$TSconfig,$table,$row,$field);
254
255 // Set the field in the accumulation array IF the $data variabel is set:
256 $totalRecordContent[$field]=isset($data)?$data:'';
257 }
258
259 // Further processing may apply for each field in the record depending on the settings in the "types" configuration (the list of fields to currently display for a record in TCEforms).
260 // For instance this could be processing instructions for the Rich Text Editor.
261 $types_fieldConfig = t3lib_BEfunc::getTCAtypes($table,$totalRecordContent);
262 if (is_array($types_fieldConfig)) {
263 $totalRecordContent = $this->renderRecord_typesProc($totalRecordContent,$types_fieldConfig,$tscPID,$table,$pid);
264 }
265
266 // Register items, mostly for external use (overriding the regItem() function)
267 foreach($totalRecordContent as $field => $data) {
268 $this->regItem($table,$id,$field,$data);
269 }
270
271 // Finally, store the result:
272 reset($totalRecordContent);
273 $this->regTableItems_data[$uniqueItemRef]=$totalRecordContent;
274 }
275 }
276
277 /**
278 * Function with the switch() construct which triggers functions for processing of the data value depending on the TCA-config field type.
279 *
280 * @param string Value to process
281 * @param array TCA/columns array for field (independant of TCA for flexforms - coming from XML then)
282 * @param array TSconfig (blank for flexforms for now)
283 * @param string Table name
284 * @param array The row array, always of the real record (also for flexforms)
285 * @param string The field (empty for flexforms!)
286 * @return string Modified $value
287 */
288 function renderRecord_SW($data,$fieldConfig,$TSconfig,$table,$row,$field) {
289
290 switch((string)$fieldConfig['config']['type']) {
291 case 'group':
292 $data = $this->renderRecord_groupProc($data,$fieldConfig,$TSconfig,$table,$row,$field);
293 break;
294 case 'select':
295 $data = $this->renderRecord_selectProc($data,$fieldConfig,$TSconfig,$table,$row,$field);
296 break;
297 case 'flex':
298 $data = $this->renderRecord_flexProc($data,$fieldConfig,$TSconfig,$table,$row,$field);
299 break;
300 }
301
302 return $data;
303 }
304
305 /**
306 * Processing of the data value in case the field type is "group"
307 *
308 * @param string The field value
309 * @param array TCA field config
310 * @param array TCEform TSconfig for the record
311 * @param string Table name
312 * @param array The row
313 * @param string Field name
314 * @return string The processed input field value ($data)
315 * @access private
316 * @see renderRecord()
317 */
318 function renderRecord_groupProc($data,$fieldConfig,$TSconfig,$table,$row,$field) {
319 switch ($fieldConfig['config']['internal_type']) {
320 case 'file':
321 // Init array used to accumulate the files:
322 $dataAcc=array();
323
324 // Now, load the files into the $dataAcc array, whether stored by MM or as a list of filenames:
325 if ($fieldConfig['config']['MM']) {
326 $loadDB = t3lib_div::makeInstance('t3lib_loadDBGroup');
327 $loadDB->start('', 'files', $fieldConfig['config']['MM'], $row['uid']); // Setting dummy startup
328
329 foreach($loadDB->itemArray as $value) {
330 if ($value['id']) {
331 $dataAcc[]=rawurlencode($value['id']).'|'.rawurlencode($value['id']);
332 }
333 }
334 } else {
335 $fileList = t3lib_div::trimExplode(',',$data,1);
336 foreach($fileList as $value) {
337 if ($value) {
338 $dataAcc[]=rawurlencode($value).'|'.rawurlencode($value);
339 }
340 }
341 }
342 // Implode the accumulation array to a comma separated string:
343 $data = implode(',',$dataAcc);
344 break;
345 case 'db':
346 $loadDB = t3lib_div::makeInstance('t3lib_loadDBGroup');
347 $loadDB->start($data, $fieldConfig['config']['allowed'], $fieldConfig['config']['MM'], $row['uid']);
348 $loadDB->getFromDB();
349 $data = $loadDB->readyForInterface();
350 break;
351 }
352
353 return $data;
354 }
355
356 /**
357 * Processing of the data value in case the field type is "select"
358 *
359 * @param string The field value
360 * @param array TCA field config
361 * @param array TCEform TSconfig for the record
362 * @param string Table name
363 * @param array The row
364 * @param string Field name
365 * @return string The processed input field value ($data)
366 * @access private
367 * @see renderRecord()
368 */
369 function renderRecord_selectProc($data,$fieldConfig,$TSconfig,$table,$row,$field) {
370 global $TCA;
371
372 // Initialize:
373 $elements = t3lib_div::trimExplode(',',$data,1); // Current data set.
374 $dataAcc=array(); // New data set, ready for interface (list of values, rawurlencoded)
375
376 // For list selectors (multi-value):
377 if (intval($fieldConfig['config']['maxitems'])>1) {
378
379 // Add regular elements:
380 if (is_array($fieldConfig['config']['items'])) {
381 $fieldConfig['config']['items'] = $this->procesItemArray($fieldConfig['config']['items'], $fieldConfig['config'], $TSconfig[$field], $table, $row, $field);
382 foreach($fieldConfig['config']['items'] as $pvpv) {
383 foreach($elements as $eKey => $value) {
384 if (!strcmp($value,$pvpv[1])) {
385 $dataAcc[$eKey]=rawurlencode($pvpv[1]).'|'.rawurlencode($pvpv[0]);
386 }
387 }
388 }
389 }
390
391 // Add "special"
392 if ($fieldConfig['config']['special']) {
393 $dataAcc = $this->selectAddSpecial($dataAcc, $elements, $fieldConfig['config']['special']);
394 }
395
396 // Add "foreign table" stuff:
397 if ($TCA[$fieldConfig['config']['foreign_table']]) {
398 $dataAcc = $this->selectAddForeign($dataAcc, $elements, $fieldConfig, $field, $TSconfig, $row);
399 }
400
401 // Always keep the native order for display in interface:
402 ksort($dataAcc);
403 } else { // Normal, <= 1 -> value without title on it
404 if ($TCA[$fieldConfig['config']['foreign_table']]) {
405 // Getting the data
406 $dataIds = $this->getDataIdList($elements, $fieldConfig, $row);
407
408 if (!count($dataIds)) $dataIds = array(0);
409 $dataAcc[]=$dataIds[0];
410 } else {
411 $dataAcc[]=$elements[0];
412 }
413 }
414
415 return implode(',',$dataAcc);
416 }
417
418 /**
419 * Processing of the data value in case the field type is "flex"
420 * MUST NOT be called in case of already INSIDE a flexform!
421 *
422 * @param string The field value
423 * @param array TCA field config
424 * @param array TCEform TSconfig for the record
425 * @param string Table name
426 * @param array The row
427 * @param string Field name
428 * @return string The processed input field value ($data)
429 * @access private
430 * @see renderRecord()
431 */
432 function renderRecord_flexProc($data,$fieldConfig,$TSconfig,$table,$row,$field) {
433 global $TCA;
434
435 // Convert the XML data to PHP array:
436 $currentValueArray = t3lib_div::xml2array($data);
437 if (is_array($currentValueArray)) {
438
439 // Get current value array:
440 $dataStructArray = t3lib_BEfunc::getFlexFormDS($fieldConfig['config'],$row,$table);
441 if (is_array($dataStructArray)) {
442 $currentValueArray['data'] = $this->renderRecord_flexProc_procInData($currentValueArray['data'],$dataStructArray,array($data,$fieldConfig,$TSconfig,$table,$row,$field));
443 $data = t3lib_div::array2xml($currentValueArray);
444 }
445 }
446
447 return $data;
448 }
449
450 /**
451 * Processing of the content in $totalRecordcontent based on settings in the types-configuration
452 *
453 * @param array The array of values which has been processed according to their type (eg. "group" or "select")
454 * @param array The "types" configuration for the current display of fields.
455 * @param integer PAGE TSconfig PID
456 * @param string Table name
457 * @param integer PID value
458 * @return array The processed version of $totalRecordContent
459 * @access private
460 */
461 function renderRecord_typesProc($totalRecordContent,$types_fieldConfig,$tscPID,$table,$pid) {
462 foreach($types_fieldConfig as $vconf) {
463
464 // Find file to write to, if configured:
465 $eFile=t3lib_parsehtml_proc::evalWriteFile($vconf['spec']['static_write'],$totalRecordContent);
466
467 // Write file configuration:
468 if (is_array($eFile)) {
469 if ($eFile['loadFromFileField'] && $totalRecordContent[$eFile['loadFromFileField']]) {
470 // Read the external file, and insert the content between the ###TYPO3_STATICFILE_EDIT### markers:
471 $SW_fileContent = t3lib_div::getUrl($eFile['editFile']);
472 $parseHTML = t3lib_div::makeInstance('t3lib_parsehtml_proc');
473 $parseHTML->init('','');
474
475 $totalRecordContent[$vconf['field']] = $parseHTML->getSubpart(
476 $SW_fileContent,
477 $eFile['markerField']&&trim($totalRecordContent[$eFile['markerField']])
478 ? trim($totalRecordContent[$eFile['markerField']])
479 : '###TYPO3_STATICFILE_EDIT###',
480 chr(10).$totalRecordContent[$eFile['contentField']].chr(10),
481 1,1);
482 }
483 }
484
485 // RTE transformation
486 if ($vconf['spec']['rte_transform'] && !$this->disableRTE) {
487 $p=t3lib_BEfunc::getSpecConfParametersFromArray($vconf['spec']['rte_transform']['parameters']);
488 if ($p['mode']) { // There must be a mode set for transformation
489 if (isset($totalRecordContent[$vconf['field']])) {
490 if ($tscPID>=0) {
491
492 // Get Rich Text Editor configuration from Page TSconfig:
493 $RTEsetup = $GLOBALS['BE_USER']->getTSConfig('RTE',t3lib_BEfunc::getPagesTSconfig($tscPID));
494 $thisConfig = t3lib_BEfunc::RTEsetup($RTEsetup['properties'],$table,$vconf['field'],t3lib_BEfunc::getTCAtypeValue($table,$totalRecordContent));
495
496 // ... and any disable flag should not be set!
497 if (!$thisConfig['disabled'] && (!$p['flag'] || !$totalRecordContent[$p['flag']]) && $GLOBALS['BE_USER']->isRTE()) {
498 // Initialize transformation:
499 $parseHTML = t3lib_div::makeInstance('t3lib_parsehtml_proc');
500 $parseHTML->init($table.':'.$vconf['field'],$pid);
501 if (is_array($eFile)) {
502 $parseHTML->setRelPath(dirname($eFile['relEditFile']));
503 }
504 // Perform transformation:
505 $totalRecordContent[$vconf['field']]=$parseHTML->RTE_transform($totalRecordContent[$vconf['field']],$vconf['spec'],'rte',$thisConfig);
506 }
507 }
508 }
509 }
510 }
511 }
512
513 return $totalRecordContent;
514 }
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529 /***********************************************
530 *
531 * FlexForm processing functions
532 *
533 ***********************************************/
534
535 /**
536 * Function traversing sheets/languages for flex form data structures
537 *
538 * @param array Data array
539 * @param array Data Structure array
540 * @param array Various parameters to pass-through
541 * @return array Modified $dataPart array.
542 * @access private
543 * @see t3lib_TCEmain::checkValue_flex_procInData(), renderRecord_flexProc_procInData_travDS()
544 */
545 function renderRecord_flexProc_procInData($dataPart,$dataStructArray,$pParams) {
546 if (is_array($dataPart)) {
547 foreach($dataPart as $sKey => $sheetDef) {
548 list ($dataStruct,$actualSheet) = t3lib_div::resolveSheetDefInDS($dataStructArray,$sKey);
549
550 if (is_array($dataStruct) && $actualSheet==$sKey && is_array($sheetDef)) {
551 foreach($sheetDef as $lKey => $lData) {
552 $this->renderRecord_flexProc_procInData_travDS(
553 $dataPart[$sKey][$lKey],
554 $dataStruct['ROOT']['el'],
555 $pParams
556 );
557 }
558 }
559 }
560 }
561
562 return $dataPart;
563 }
564
565 /**
566 * Traverse data array / structure
567 *
568 * @param array Data array passed by reference.
569 * @param array Data structure
570 * @param array Various parameters pass-through.
571 * @return void
572 * @see renderRecord_flexProc_procInData(), t3lib_TCEmain::checkValue_flex_procInData_travDS()
573 */
574 function renderRecord_flexProc_procInData_travDS(&$dataValues,$DSelements,$pParams) {
575 if (is_array($DSelements)) {
576
577 // For each DS element:
578 foreach($DSelements as $key => $dsConf) {
579
580 // Array/Section:
581 if ($DSelements[$key]['type']=='array') {
582 if (is_array($dataValues[$key]['el'])) {
583 if ($DSelements[$key]['section']) {
584 foreach($dataValues[$key]['el'] as $ik => $el) {
585 $theKey = key($el);
586 if (is_array($dataValues[$key]['el'][$ik][$theKey]['el'])) {
587 $this->renderRecord_flexProc_procInData_travDS(
588 $dataValues[$key]['el'][$ik][$theKey]['el'],
589 $DSelements[$key]['el'][$theKey]['el'],
590 $pParams
591 );
592 }
593 }
594 } else {
595 if (!isset($dataValues[$key]['el'])) $dataValues[$key]['el']=array();
596 $this->renderRecord_flexProc_procInData_travDS(
597 $dataValues[$key]['el'],
598 $DSelements[$key]['el'],
599 $pParams
600 );
601 }
602 }
603 } else {
604 if (is_array($dsConf['TCEforms']['config']) && is_array($dataValues[$key])) {
605 foreach($dataValues[$key] as $vKey => $data) {
606
607 // $data,$fieldConfig,$TSconfig,$table,$row,$field
608 list(,,$CVTSconfig,$CVtable,$CVrow,$CVfield) = $pParams;
609 ;
610 // Set default value:
611 if (!isset($dataValues[$key][$vKey])) {
612 $dataValues[$key][$vKey] = $dsConf['TCEforms']['config']['default'];
613 }
614
615 // Process value:
616 $dataValues[$key][$vKey] = $this->renderRecord_SW($dataValues[$key][$vKey],$dsConf['TCEforms'],$CVTSconfig,$CVtable,$CVrow,'');
617 }
618 }
619 }
620 }
621 }
622 }
623
624
625
626
627
628
629
630
631
632
633
634
635 /***********************************************
636 *
637 * Selector box processing functions
638 *
639 ***********************************************/
640
641 /**
642 * Adding "special" types to the $dataAcc array of selector items
643 *
644 * @param array Array with numeric keys, containing values for the selector box, prepared for interface. We are going to add elements to this array as needed.
645 * @param array The array of original elements - basically the field value exploded by ","
646 * @param string The "special" key from the TCA config of the field. Determines the type of processing in here.
647 * @return array Modified $dataAcc array
648 * @access private
649 * @see renderRecord_selectProc()
650 */
651 function selectAddSpecial($dataAcc, $elements, $specialKey) {
652 global $TCA;
653
654 // Special select types:
655 switch ((string)$specialKey) {
656 case 'tables': // Listing all tables from $TCA:
657 $tNames = array_keys($TCA);
658 foreach($tNames as $tableName) {
659 foreach($elements as $eKey => $value) {
660 if (!strcmp($tableName,$value)) {
661 $dataAcc[$eKey]=rawurlencode($value).'|'.rawurlencode($this->sL($TCA[$value]['ctrl']['title']));
662 }
663 }
664 }
665 break;
666 case 'pagetypes': // Listing all page types (doktype)
667 $theTypes = $TCA['pages']['columns']['doktype']['config']['items'];
668 if (is_array($theTypes)) {
669 foreach($theTypes as $theTypesArrays) {
670 foreach($elements as $eKey => $value) {
671 if (!strcmp($theTypesArrays[1],$value)) {
672 $dataAcc[$eKey]=rawurlencode($value).'|'.rawurlencode($this->sL($theTypesArrays[0]));
673 }
674 }
675 }
676 }
677 break;
678 case 'exclude': // Listing exclude fields.
679 $theExcludeFields = t3lib_BEfunc::getExcludeFields();
680 if (is_array($theExcludeFields)) {
681 foreach($theExcludeFields as $theExcludeFieldsArrays) {
682 foreach($elements as $eKey => $value) {
683 if (!strcmp($theExcludeFieldsArrays[1],$value)) {
684 $dataAcc[$eKey]=rawurlencode($value).'|'.rawurlencode(ereg_replace(':$','',$theExcludeFieldsArrays[0]));
685 }
686 }
687 }
688 }
689 break;
690 case 'modListGroup': // Listing modules for GROUPS
691 case 'modListUser': // Listing modules for USERS:
692 if (!$this->loadModules) {
693 $this->loadModules = t3lib_div::makeInstance('t3lib_loadModules');
694 $this->loadModules->load($GLOBALS['TBE_MODULES']);
695 }
696 $modList = ($specialKey=='modListUser') ? $this->loadModules->modListUser : $this->loadModules->modListGroup;
697
698 foreach($modList as $theModName) {
699 foreach($elements as $eKey => $value) {
700 $label = '';
701 // Add label for main module:
702 $pp = explode('_',$value);
703 if (count($pp)>1) $label.=$GLOBALS['LANG']->moduleLabels['tabs'][$pp[0].'_tab'].'>';
704 // Add modules own label now:
705 $label.= $GLOBALS['LANG']->moduleLabels['tabs'][$value.'_tab'];
706
707 if (!strcmp($theModName,$value)) {
708 $dataAcc[$eKey]=rawurlencode($value).'|'.rawurlencode($label);
709 }
710 }
711 }
712 break;
713 }
714
715 return $dataAcc;
716 }
717
718 /**
719 * Adds the foreign record elements to $dataAcc, if any
720 *
721 * @param array Array with numeric keys, containing values for the selector box, prepared for interface. We are going to add elements to this array as needed.
722 * @param array The array of original elements - basically the field value exploded by ","
723 * @param array Field configuration from TCA
724 * @param string The field name
725 * @param array TSconfig for the record
726 * @param array The record
727 * @return array Modified $dataAcc array
728 * @access private
729 * @see renderRecord_selectProc()
730 */
731 function selectAddForeign($dataAcc, $elements, $fieldConfig, $field, $TSconfig, $row) {
732 global $TCA;
733
734 // Init:
735 $recordList = Array();
736
737 // foreign_table
738 $subres = t3lib_BEfunc::exec_foreign_table_where_query($fieldConfig,$field,$TSconfig);
739 while ($subrow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($subres)) {
740 $recordList[$subrow['uid']] = t3lib_BEfunc::getRecordTitle($fieldConfig['config']['foreign_table'],$subrow);
741 }
742
743 // neg_foreign_table
744 if (is_array($TCA[$fieldConfig['config']['neg_foreign_table']])) {
745 $subres = t3lib_BEfunc::exec_foreign_table_where_query($fieldConfig,$field,$TSconfig,'neg_');
746 while ($subrow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($subres)) {
747 $recordList[-$subrow['uid']] = t3lib_BEfunc::getRecordTitle($fieldConfig['config']['neg_foreign_table'],$subrow);
748 }
749 }
750
751 // At this point all records that CAN be selected is found in $recordList
752 // Now, get the data from loadDBgroup based on the input list of values.
753 $dataIds = $this->getDataIdList($elements, $fieldConfig, $row);
754 if ($fieldConfig['config']['MM']) $dataAcc=array(); // Reset, if MM (which cannot bear anything but real relations!)
755
756 // After this we can traverse the loadDBgroup values and match values with the list of possible values in $recordList:
757 foreach($dataIds as $theId) {
758 if (isset($recordList[$theId])) {
759 $lPrefix = $this->sL($fieldConfig['config'][($theId>0?'':'neg_').'foreign_table_prefix']);
760 if ($fieldConfig['config']['MM']) {
761 $dataAcc[]=rawurlencode($theId).'|'.rawurlencode(t3lib_div::fixed_lgd($lPrefix.strip_tags($recordList[$theId]),$GLOBALS['BE_USER']->uc['titleLen']));
762 } else {
763 foreach($elements as $eKey => $value) {
764 if (!strcmp($theId,$value)) {
765 $dataAcc[$eKey]=rawurlencode($theId).'|'.rawurlencode(t3lib_div::fixed_lgd($lPrefix.strip_tags($recordList[$theId]),$GLOBALS['BE_USER']->uc['titleLen']));
766 }
767 }
768 }
769 }
770 }
771
772 return $dataAcc;
773 }
774
775 /**
776 * Returning the id-list processed by loadDBgroup for the foreign tables.
777 *
778 * @param array The array of original elements - basically the field value exploded by ","
779 * @param array Field configuration from TCA
780 * @param array The data array, currently. Used to set the "local_uid" for selecting MM relation records.
781 * @return array An array with ids of the records from the input elements array.
782 * @access private
783 */
784 function getDataIdList($elements, $fieldConfig, $row) {
785 $loadDB = t3lib_div::makeInstance('t3lib_loadDBGroup');
786 $loadDB->registerNonTableValues=$fieldConfig['config']['allowNonIdValues'] ? 1 : 0;
787 $loadDB->start(implode(',',$elements), $fieldConfig['config']['foreign_table'].','.$fieldConfig['config']['neg_foreign_table'], $fieldConfig['config']['MM'], $row['uid']);
788
789 $idList = $loadDB->convertPosNeg($loadDB->getValueArray(),$fieldConfig['config']['foreign_table'],$fieldConfig['config']['neg_foreign_table']);
790
791 return $idList;
792 }
793
794 /**
795 * Processing of selector box items. This includes the automated adding of elements plus user-function processing.
796 *
797 * @param array The elements to process
798 * @param array TCA/columns configuration
799 * @param array TSconfig for the field
800 * @param string The table name
801 * @param array The current row
802 * @param string The field name
803 * @return array The modified input $selItems array
804 * @access private
805 * @see renderRecord_selectProc()
806 */
807 function procesItemArray($selItems,$config,$fieldTSConfig,$table,$row,$field) {
808 $selItems = $this->addItems($selItems,$fieldTSConfig['addItems.']);
809 if ($config['itemsProcFunc']) $selItems = $this->procItems($selItems,$fieldTSConfig['itemsProcFunc.'],$config,$table,$row,$field);
810 return $selItems;
811 }
812
813 /**
814 * Adding items from $iArray to $items array
815 *
816 * @param array The array of selector box items to which key(value) / value(label) pairs from $iArray will be added.
817 * @param array The array of elements to add. The keys will become values. The value will become the label.
818 * @return array The modified input $items array
819 * @access private
820 * @see procesItemArray()
821 */
822 function addItems($items,$iArray) {
823 if (is_array($iArray)) {
824 foreach($iArray as $value => $label) {
825 $items[]=array($label,$value);
826 }
827 }
828 return $items;
829 }
830
831 /**
832 * User processing of a selector box array of values.
833 *
834 * @param array The array of selector box items
835 * @param array TSconfig for the fields itemProcFunc
836 * @param array TCA/columns configuration
837 * @param string The table name
838 * @param array The current row
839 * @param string The field name
840 * @return array The modified input $items array
841 * @access private
842 * @see procesItemArray()
843 */
844 function procItems($items,$itemsProcFuncTSconfig,$config,$table,$row,$field) {
845 $params=array();
846 $params['items'] = &$items;
847 $params['config'] = $config;
848 $params['TSconfig'] = $itemsProcFuncTSconfig;
849 $params['table'] = $table;
850 $params['row'] = $row;
851 $params['field'] = $field;
852
853 t3lib_div::callUserFunction($config['itemsProcFunc'],$params,$this);
854 return $items;
855 }
856
857
858
859
860
861
862
863
864
865 /***********************************************
866 *
867 * Helper functions
868 *
869 ***********************************************/
870
871 /**
872 * Sets the lock for a record from table/id, IF $this->lockRecords is set!
873 *
874 * @param string The table name
875 * @param integer The id of the record
876 * @param integer The pid of the record
877 * @return void
878 */
879 function lockRecord($table, $id, $pid=0) {
880 if ($this->lockRecords) {
881 t3lib_BEfunc::lockRecords($table,$id,$pid);
882 }
883 }
884
885 /**
886 * Dummy function, can be used to "register" records. Used by eg. the "show_item" script.
887 *
888 * @param string Table name
889 * @param integer Record id
890 * @param string Field name
891 * @param string Field content.
892 * @return void
893 * @access private
894 * @see renderRecord()
895 */
896 function regItem($table, $id, $field, $content) {
897 }
898
899 /**
900 * Local wrapper function for LANG->sL (returning language labels)
901 *
902 * @param string Language label key
903 * @return string Localized label value.
904 * @access private
905 */
906 function sL($in) {
907 return $GLOBALS['LANG']->sL($in);
908 }
909 }
910
911
912 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_transferdata.php']) {
913 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_transferdata.php']);
914 }
915 ?>