* Created new function, t3lib_div::fixed_lgd_cs(), which should be used in the backen...
[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 * 432: function renderRecord_flexProc($data,$fieldConfig,$TSconfig,$table,$row,$field)
49 * 461: function renderRecord_typesProc($totalRecordContent,$types_fieldConfig,$tscPID,$table,$pid)
50 *
51 * SECTION: FlexForm processing functions
52 * 549: function renderRecord_flexProc_procInData($dataPart,$dataStructArray,$pParams)
53 * 578: function renderRecord_flexProc_procInData_travDS(&$dataValues,$DSelements,$pParams)
54 *
55 * SECTION: Selector box processing functions
56 * 655: function selectAddSpecial($dataAcc, $elements, $specialKey)
57 * 735: function selectAddForeign($dataAcc, $elements, $fieldConfig, $field, $TSconfig, $row)
58 * 788: function getDataIdList($elements, $fieldConfig, $row)
59 * 811: function procesItemArray($selItems,$config,$fieldTSConfig,$table,$row,$field)
60 * 826: function addItems($items,$iArray)
61 * 848: function procItems($items,$itemsProcFuncTSconfig,$config,$table,$row,$field)
62 *
63 * SECTION: Helper functions
64 * 883: function lockRecord($table, $id, $pid=0)
65 * 900: function regItem($table, $id, $field, $content)
66 * 910: function sL($in)
67 *
68 * TOTAL FUNCTIONS: 18
69 * (This index is automatically created/updated by the extension "extdeveval")
70 *
71 */
72
73
74 require_once (PATH_t3lib.'class.t3lib_loaddbgroup.php');
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 $this->regTableItems_data[$uniqueItemRef] = $this->renderRecordRaw($table, $id, $pid, $row, $TSconfig, $tscPID);
240 }
241 }
242
243
244
245 /**
246 * 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!
247 * The objective with this function is to prepare the content for handling in TCEforms.
248 * In opposite to renderRecord() this function do not prepare things like fetching TSconfig and others.
249 * The resulting, processed row will be returned.
250 *
251 * @param string The table name
252 * @param string The uid value of the record (integer). Can also be a string (NEW-something) if the record is a NEW record.
253 * @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)
254 * @param array The row of the current record. If NEW record, then it may be loaded with default values (by eg. fetchRecord()).
255 * @param array Tsconfig array
256 * @param integer PAGE TSconfig pid
257 * @return array Processed record data
258 * @see renderRecord()
259 */
260 function renderRecordRaw($table, $id, $pid, $row, $TSconfig='', $tscPID=0) {
261 global $TCA;
262
263 if(!is_array($TSconfig)) {
264 $TSconfig = array();
265 }
266
267 // Create blank accumulation array:
268 $totalRecordContent=array();
269
270 // Traverse the configured columns for the table (TCA):
271 // For each column configured, we will perform processing if needed based on the type (eg. for "group" and "select" types this is needed)
272 $copyOfColumns = $TCA[$table]['columns'];
273 foreach($copyOfColumns as $field => $fieldConfig) {
274 // Set $data variable for the field, either inputted value from $row - or if not found, the default value as defined in the "config" array
275 if (isset($row[$field])) {
276 $data = $row[$field];
277 } else {
278 $data = $fieldConfig['config']['default'];
279 }
280
281 $data = $this->renderRecord_SW($data,$fieldConfig,$TSconfig,$table,$row,$field);
282
283 // Set the field in the accumulation array IF the $data variabel is set:
284 $totalRecordContent[$field]=isset($data)?$data:'';
285 }
286
287 // 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).
288 // For instance this could be processing instructions for the Rich Text Editor.
289 $types_fieldConfig = t3lib_BEfunc::getTCAtypes($table,$totalRecordContent);
290 if (is_array($types_fieldConfig)) {
291 $totalRecordContent = $this->renderRecord_typesProc($totalRecordContent,$types_fieldConfig,$tscPID,$table,$pid);
292 }
293
294 // Register items, mostly for external use (overriding the regItem() function)
295 foreach($totalRecordContent as $field => $data) {
296 $this->regItem($table,$id,$field,$data);
297 }
298
299 // Finally, store the result:
300 reset($totalRecordContent);
301
302 return $totalRecordContent;
303
304 }
305
306 /**
307 * Function with the switch() construct which triggers functions for processing of the data value depending on the TCA-config field type.
308 *
309 * @param string Value to process
310 * @param array TCA/columns array for field (independant of TCA for flexforms - coming from XML then)
311 * @param array TSconfig (blank for flexforms for now)
312 * @param string Table name
313 * @param array The row array, always of the real record (also for flexforms)
314 * @param string The field (empty for flexforms!)
315 * @return string Modified $value
316 */
317 function renderRecord_SW($data,$fieldConfig,$TSconfig,$table,$row,$field) {
318
319 switch((string)$fieldConfig['config']['type']) {
320 case 'group':
321 $data = $this->renderRecord_groupProc($data,$fieldConfig,$TSconfig,$table,$row,$field);
322 break;
323 case 'select':
324 $data = $this->renderRecord_selectProc($data,$fieldConfig,$TSconfig,$table,$row,$field);
325 break;
326 case 'flex':
327 $data = $this->renderRecord_flexProc($data,$fieldConfig,$TSconfig,$table,$row,$field);
328 break;
329 }
330
331 return $data;
332 }
333
334 /**
335 * Processing of the data value in case the field type is "group"
336 *
337 * @param string The field value
338 * @param array TCA field config
339 * @param array TCEform TSconfig for the record
340 * @param string Table name
341 * @param array The row
342 * @param string Field name
343 * @return string The processed input field value ($data)
344 * @access private
345 * @see renderRecord()
346 */
347 function renderRecord_groupProc($data,$fieldConfig,$TSconfig,$table,$row,$field) {
348 switch ($fieldConfig['config']['internal_type']) {
349 case 'file':
350 // Init array used to accumulate the files:
351 $dataAcc=array();
352
353 // Now, load the files into the $dataAcc array, whether stored by MM or as a list of filenames:
354 if ($fieldConfig['config']['MM']) {
355 $loadDB = t3lib_div::makeInstance('t3lib_loadDBGroup');
356 $loadDB->start('', 'files', $fieldConfig['config']['MM'], $row['uid']); // Setting dummy startup
357
358 foreach($loadDB->itemArray as $value) {
359 if ($value['id']) {
360 $dataAcc[]=rawurlencode($value['id']).'|'.rawurlencode($value['id']);
361 }
362 }
363 } else {
364 $fileList = t3lib_div::trimExplode(',',$data,1);
365 foreach($fileList as $value) {
366 if ($value) {
367 $dataAcc[]=rawurlencode($value).'|'.rawurlencode($value);
368 }
369 }
370 }
371 // Implode the accumulation array to a comma separated string:
372 $data = implode(',',$dataAcc);
373 break;
374 case 'db':
375 $loadDB = t3lib_div::makeInstance('t3lib_loadDBGroup');
376 $loadDB->start($data, $fieldConfig['config']['allowed'], $fieldConfig['config']['MM'], $row['uid']);
377 $loadDB->getFromDB();
378 $data = $loadDB->readyForInterface();
379 break;
380 }
381
382 return $data;
383 }
384
385 /**
386 * Processing of the data value in case the field type is "select"
387 *
388 * @param string The field value
389 * @param array TCA field config
390 * @param array TCEform TSconfig for the record
391 * @param string Table name
392 * @param array The row
393 * @param string Field name
394 * @return string The processed input field value ($data)
395 * @access private
396 * @see renderRecord()
397 */
398 function renderRecord_selectProc($data,$fieldConfig,$TSconfig,$table,$row,$field) {
399 global $TCA;
400
401 // Initialize:
402 $elements = t3lib_div::trimExplode(',',$data,1); // Current data set.
403 $dataAcc=array(); // New data set, ready for interface (list of values, rawurlencoded)
404
405 // For list selectors (multi-value):
406 if (intval($fieldConfig['config']['maxitems'])>1) {
407
408 // Add regular elements:
409 if (is_array($fieldConfig['config']['items'])) {
410 $fieldConfig['config']['items'] = $this->procesItemArray($fieldConfig['config']['items'], $fieldConfig['config'], $TSconfig[$field], $table, $row, $field);
411 foreach($fieldConfig['config']['items'] as $pvpv) {
412 foreach($elements as $eKey => $value) {
413 if (!strcmp($value,$pvpv[1])) {
414 $dataAcc[$eKey]=rawurlencode($pvpv[1]).'|'.rawurlencode($pvpv[0]);
415 }
416 }
417 }
418 }
419
420 // Add "special"
421 if ($fieldConfig['config']['special']) {
422 $dataAcc = $this->selectAddSpecial($dataAcc, $elements, $fieldConfig['config']['special']);
423 }
424
425 // Add "foreign table" stuff:
426 if ($TCA[$fieldConfig['config']['foreign_table']]) {
427 $dataAcc = $this->selectAddForeign($dataAcc, $elements, $fieldConfig, $field, $TSconfig, $row);
428 }
429
430 // Always keep the native order for display in interface:
431 ksort($dataAcc);
432 } else { // Normal, <= 1 -> value without title on it
433 if ($TCA[$fieldConfig['config']['foreign_table']]) {
434 // Getting the data
435 $dataIds = $this->getDataIdList($elements, $fieldConfig, $row);
436
437 if (!count($dataIds)) $dataIds = array(0);
438 $dataAcc[]=$dataIds[0];
439 } else {
440 $dataAcc[]=$elements[0];
441 }
442 }
443
444 return implode(',',$dataAcc);
445 }
446
447 /**
448 * Processing of the data value in case the field type is "flex"
449 * MUST NOT be called in case of already INSIDE a flexform!
450 *
451 * @param string The field value
452 * @param array TCA field config
453 * @param array TCEform TSconfig for the record
454 * @param string Table name
455 * @param array The row
456 * @param string Field name
457 * @return string The processed input field value ($data)
458 * @access private
459 * @see renderRecord()
460 */
461 function renderRecord_flexProc($data,$fieldConfig,$TSconfig,$table,$row,$field) {
462 global $TCA;
463
464 // Convert the XML data to PHP array:
465 $currentValueArray = t3lib_div::xml2array($data);
466 if (is_array($currentValueArray)) {
467
468 // Get current value array:
469 $dataStructArray = t3lib_BEfunc::getFlexFormDS($fieldConfig['config'],$row,$table);
470 if (is_array($dataStructArray)) {
471 $currentValueArray['data'] = $this->renderRecord_flexProc_procInData($currentValueArray['data'],$dataStructArray,array($data,$fieldConfig,$TSconfig,$table,$row,$field));
472 $data = t3lib_div::array2xml($currentValueArray);
473 }
474 }
475
476 return $data;
477 }
478
479 /**
480 * Processing of the content in $totalRecordcontent based on settings in the types-configuration
481 *
482 * @param array The array of values which has been processed according to their type (eg. "group" or "select")
483 * @param array The "types" configuration for the current display of fields.
484 * @param integer PAGE TSconfig PID
485 * @param string Table name
486 * @param integer PID value
487 * @return array The processed version of $totalRecordContent
488 * @access private
489 */
490 function renderRecord_typesProc($totalRecordContent,$types_fieldConfig,$tscPID,$table,$pid) {
491 foreach($types_fieldConfig as $vconf) {
492
493 // Find file to write to, if configured:
494 $eFile=t3lib_parsehtml_proc::evalWriteFile($vconf['spec']['static_write'],$totalRecordContent);
495
496 // Write file configuration:
497 if (is_array($eFile)) {
498 if ($eFile['loadFromFileField'] && $totalRecordContent[$eFile['loadFromFileField']]) {
499 // Read the external file, and insert the content between the ###TYPO3_STATICFILE_EDIT### markers:
500 $SW_fileContent = t3lib_div::getUrl($eFile['editFile']);
501 $parseHTML = t3lib_div::makeInstance('t3lib_parsehtml_proc');
502 $parseHTML->init('','');
503
504 $totalRecordContent[$vconf['field']] = $parseHTML->getSubpart(
505 $SW_fileContent,
506 $eFile['markerField']&&trim($totalRecordContent[$eFile['markerField']])
507 ? trim($totalRecordContent[$eFile['markerField']])
508 : '###TYPO3_STATICFILE_EDIT###',
509 chr(10).$totalRecordContent[$eFile['contentField']].chr(10),
510 1,1);
511 }
512 }
513
514
515 // MOVED TO the individual extensions (see TCEforms)
516 /*
517 // RTE transformation
518 if ($vconf['spec']['rte_transform'] && !$this->disableRTE) {
519 $p=t3lib_BEfunc::getSpecConfParametersFromArray($vconf['spec']['rte_transform']['parameters']);
520 if ($p['mode']) { // There must be a mode set for transformation
521 if (isset($totalRecordContent[$vconf['field']])) {
522 if ($tscPID>=0) {
523
524 // Get Rich Text Editor configuration from Page TSconfig:
525 $RTEsetup = $GLOBALS['BE_USER']->getTSConfig('RTE',t3lib_BEfunc::getPagesTSconfig($tscPID));
526 $thisConfig = t3lib_BEfunc::RTEsetup($RTEsetup['properties'],$table,$vconf['field'],t3lib_BEfunc::getTCAtypeValue($table,$totalRecordContent));
527
528 // ... and any disable flag should not be set!
529 if (!$thisConfig['disabled'] && (!$p['flag'] || !$totalRecordContent[$p['flag']]) && $GLOBALS['BE_USER']->isRTE()) {
530 // Initialize transformation:
531 $parseHTML = t3lib_div::makeInstance('t3lib_parsehtml_proc');
532 $parseHTML->init($table.':'.$vconf['field'],$pid);
533 if (is_array($eFile)) {
534 $parseHTML->setRelPath(dirname($eFile['relEditFile']));
535 }
536 // Perform transformation:
537 $totalRecordContent[$vconf['field']]=$parseHTML->RTE_transform($totalRecordContent[$vconf['field']],$vconf['spec'],'rte',$thisConfig);
538 }
539 }
540 }
541 }
542 }
543 */
544 }
545
546 return $totalRecordContent;
547 }
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562 /***********************************************
563 *
564 * FlexForm processing functions
565 *
566 ***********************************************/
567
568 /**
569 * Function traversing sheets/languages for flex form data structures
570 *
571 * @param array Data array
572 * @param array Data Structure array
573 * @param array Various parameters to pass-through
574 * @return array Modified $dataPart array.
575 * @access private
576 * @see t3lib_TCEmain::checkValue_flex_procInData(), renderRecord_flexProc_procInData_travDS()
577 */
578 function renderRecord_flexProc_procInData($dataPart,$dataStructArray,$pParams) {
579 if (is_array($dataPart)) {
580 foreach($dataPart as $sKey => $sheetDef) {
581 list ($dataStruct,$actualSheet) = t3lib_div::resolveSheetDefInDS($dataStructArray,$sKey);
582
583 if (is_array($dataStruct) && $actualSheet==$sKey && is_array($sheetDef)) {
584 foreach($sheetDef as $lKey => $lData) {
585 $this->renderRecord_flexProc_procInData_travDS(
586 $dataPart[$sKey][$lKey],
587 $dataStruct['ROOT']['el'],
588 $pParams
589 );
590 }
591 }
592 }
593 }
594
595 return $dataPart;
596 }
597
598 /**
599 * Traverse data array / structure
600 *
601 * @param array Data array passed by reference.
602 * @param array Data structure
603 * @param array Various parameters pass-through.
604 * @return void
605 * @see renderRecord_flexProc_procInData(), t3lib_TCEmain::checkValue_flex_procInData_travDS()
606 */
607 function renderRecord_flexProc_procInData_travDS(&$dataValues,$DSelements,$pParams) {
608 if (is_array($DSelements)) {
609
610 // For each DS element:
611 foreach($DSelements as $key => $dsConf) {
612
613 // Array/Section:
614 if ($DSelements[$key]['type']=='array') {
615 if (is_array($dataValues[$key]['el'])) {
616 if ($DSelements[$key]['section']) {
617 foreach($dataValues[$key]['el'] as $ik => $el) {
618 $theKey = key($el);
619 if (is_array($dataValues[$key]['el'][$ik][$theKey]['el'])) {
620 $this->renderRecord_flexProc_procInData_travDS(
621 $dataValues[$key]['el'][$ik][$theKey]['el'],
622 $DSelements[$key]['el'][$theKey]['el'],
623 $pParams
624 );
625 }
626 }
627 } else {
628 if (!isset($dataValues[$key]['el'])) $dataValues[$key]['el']=array();
629 $this->renderRecord_flexProc_procInData_travDS(
630 $dataValues[$key]['el'],
631 $DSelements[$key]['el'],
632 $pParams
633 );
634 }
635 }
636 } else {
637 if (is_array($dsConf['TCEforms']['config']) && is_array($dataValues[$key])) {
638 foreach($dataValues[$key] as $vKey => $data) {
639
640 // $data,$fieldConfig,$TSconfig,$table,$row,$field
641 list(,,$CVTSconfig,$CVtable,$CVrow,$CVfield) = $pParams;
642 ;
643 // Set default value:
644 if (!isset($dataValues[$key][$vKey])) {
645 $dataValues[$key][$vKey] = $dsConf['TCEforms']['config']['default'];
646 }
647
648 // Process value:
649 $dataValues[$key][$vKey] = $this->renderRecord_SW($dataValues[$key][$vKey],$dsConf['TCEforms'],$CVTSconfig,$CVtable,$CVrow,'');
650 }
651 }
652 }
653 }
654 }
655 }
656
657
658
659
660
661
662
663
664
665
666
667
668 /***********************************************
669 *
670 * Selector box processing functions
671 *
672 ***********************************************/
673
674 /**
675 * Adding "special" types to the $dataAcc array of selector items
676 *
677 * @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.
678 * @param array The array of original elements - basically the field value exploded by ","
679 * @param string The "special" key from the TCA config of the field. Determines the type of processing in here.
680 * @return array Modified $dataAcc array
681 * @access private
682 * @see renderRecord_selectProc()
683 */
684 function selectAddSpecial($dataAcc, $elements, $specialKey) {
685 global $TCA;
686
687 // Special select types:
688 switch ((string)$specialKey) {
689 case 'tables': // Listing all tables from $TCA:
690 $tNames = array_keys($TCA);
691 foreach($tNames as $tableName) {
692 foreach($elements as $eKey => $value) {
693 if (!strcmp($tableName,$value)) {
694 $dataAcc[$eKey]=rawurlencode($value).'|'.rawurlencode($this->sL($TCA[$value]['ctrl']['title']));
695 }
696 }
697 }
698 break;
699 case 'pagetypes': // Listing all page types (doktype)
700 $theTypes = $TCA['pages']['columns']['doktype']['config']['items'];
701 if (is_array($theTypes)) {
702 foreach($theTypes as $theTypesArrays) {
703 foreach($elements as $eKey => $value) {
704 if (!strcmp($theTypesArrays[1],$value)) {
705 $dataAcc[$eKey]=rawurlencode($value).'|'.rawurlencode($this->sL($theTypesArrays[0]));
706 }
707 }
708 }
709 }
710 break;
711 case 'exclude': // Listing exclude fields.
712 $theExcludeFields = t3lib_BEfunc::getExcludeFields();
713 if (is_array($theExcludeFields)) {
714 foreach($theExcludeFields as $theExcludeFieldsArrays) {
715 foreach($elements as $eKey => $value) {
716 if (!strcmp($theExcludeFieldsArrays[1],$value)) {
717 $dataAcc[$eKey]=rawurlencode($value).'|'.rawurlencode(ereg_replace(':$','',$theExcludeFieldsArrays[0]));
718 }
719 }
720 }
721 }
722 break;
723 case 'modListGroup': // Listing modules for GROUPS
724 case 'modListUser': // Listing modules for USERS:
725 if (!$this->loadModules) {
726 $this->loadModules = t3lib_div::makeInstance('t3lib_loadModules');
727 $this->loadModules->load($GLOBALS['TBE_MODULES']);
728 }
729 $modList = ($specialKey=='modListUser') ? $this->loadModules->modListUser : $this->loadModules->modListGroup;
730
731 foreach($modList as $theModName) {
732 foreach($elements as $eKey => $value) {
733 $label = '';
734 // Add label for main module:
735 $pp = explode('_',$value);
736 if (count($pp)>1) $label.=$GLOBALS['LANG']->moduleLabels['tabs'][$pp[0].'_tab'].'>';
737 // Add modules own label now:
738 $label.= $GLOBALS['LANG']->moduleLabels['tabs'][$value.'_tab'];
739
740 if (!strcmp($theModName,$value)) {
741 $dataAcc[$eKey]=rawurlencode($value).'|'.rawurlencode($label);
742 }
743 }
744 }
745 break;
746 }
747
748 return $dataAcc;
749 }
750
751 /**
752 * Adds the foreign record elements to $dataAcc, if any
753 *
754 * @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.
755 * @param array The array of original elements - basically the field value exploded by ","
756 * @param array Field configuration from TCA
757 * @param string The field name
758 * @param array TSconfig for the record
759 * @param array The record
760 * @return array Modified $dataAcc array
761 * @access private
762 * @see renderRecord_selectProc()
763 */
764 function selectAddForeign($dataAcc, $elements, $fieldConfig, $field, $TSconfig, $row) {
765 global $TCA;
766
767 // Init:
768 $recordList = Array();
769
770 // foreign_table
771 $subres = t3lib_BEfunc::exec_foreign_table_where_query($fieldConfig,$field,$TSconfig);
772 while ($subrow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($subres)) {
773 $recordList[$subrow['uid']] = t3lib_BEfunc::getRecordTitle($fieldConfig['config']['foreign_table'],$subrow);
774 }
775
776 // neg_foreign_table
777 if (is_array($TCA[$fieldConfig['config']['neg_foreign_table']])) {
778 $subres = t3lib_BEfunc::exec_foreign_table_where_query($fieldConfig,$field,$TSconfig,'neg_');
779 while ($subrow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($subres)) {
780 $recordList[-$subrow['uid']] = t3lib_BEfunc::getRecordTitle($fieldConfig['config']['neg_foreign_table'],$subrow);
781 }
782 }
783
784 // At this point all records that CAN be selected is found in $recordList
785 // Now, get the data from loadDBgroup based on the input list of values.
786 $dataIds = $this->getDataIdList($elements, $fieldConfig, $row);
787 if ($fieldConfig['config']['MM']) $dataAcc=array(); // Reset, if MM (which cannot bear anything but real relations!)
788
789 // After this we can traverse the loadDBgroup values and match values with the list of possible values in $recordList:
790 foreach($dataIds as $theId) {
791 if (isset($recordList[$theId])) {
792 $lPrefix = $this->sL($fieldConfig['config'][($theId>0?'':'neg_').'foreign_table_prefix']);
793 if ($fieldConfig['config']['MM']) {
794 $dataAcc[]=rawurlencode($theId).'|'.rawurlencode(t3lib_div::fixed_lgd_cs($lPrefix.strip_tags($recordList[$theId]),$GLOBALS['BE_USER']->uc['titleLen']));
795 } else {
796 foreach($elements as $eKey => $value) {
797 if (!strcmp($theId,$value)) {
798 $dataAcc[$eKey]=rawurlencode($theId).'|'.rawurlencode(t3lib_div::fixed_lgd_cs($lPrefix.strip_tags($recordList[$theId]),$GLOBALS['BE_USER']->uc['titleLen']));
799 }
800 }
801 }
802 }
803 }
804
805 return $dataAcc;
806 }
807
808 /**
809 * Returning the id-list processed by loadDBgroup for the foreign tables.
810 *
811 * @param array The array of original elements - basically the field value exploded by ","
812 * @param array Field configuration from TCA
813 * @param array The data array, currently. Used to set the "local_uid" for selecting MM relation records.
814 * @return array An array with ids of the records from the input elements array.
815 * @access private
816 */
817 function getDataIdList($elements, $fieldConfig, $row) {
818 $loadDB = t3lib_div::makeInstance('t3lib_loadDBGroup');
819 $loadDB->registerNonTableValues=$fieldConfig['config']['allowNonIdValues'] ? 1 : 0;
820 $loadDB->start(implode(',',$elements), $fieldConfig['config']['foreign_table'].','.$fieldConfig['config']['neg_foreign_table'], $fieldConfig['config']['MM'], $row['uid']);
821
822 $idList = $loadDB->convertPosNeg($loadDB->getValueArray(),$fieldConfig['config']['foreign_table'],$fieldConfig['config']['neg_foreign_table']);
823
824 return $idList;
825 }
826
827 /**
828 * Processing of selector box items. This includes the automated adding of elements plus user-function processing.
829 *
830 * @param array The elements to process
831 * @param array TCA/columns configuration
832 * @param array TSconfig for the field
833 * @param string The table name
834 * @param array The current row
835 * @param string The field name
836 * @return array The modified input $selItems array
837 * @access private
838 * @see renderRecord_selectProc()
839 */
840 function procesItemArray($selItems,$config,$fieldTSConfig,$table,$row,$field) {
841 $selItems = $this->addItems($selItems,$fieldTSConfig['addItems.']);
842 if ($config['itemsProcFunc']) $selItems = $this->procItems($selItems,$fieldTSConfig['itemsProcFunc.'],$config,$table,$row,$field);
843 return $selItems;
844 }
845
846 /**
847 * Adding items from $iArray to $items array
848 *
849 * @param array The array of selector box items to which key(value) / value(label) pairs from $iArray will be added.
850 * @param array The array of elements to add. The keys will become values. The value will become the label.
851 * @return array The modified input $items array
852 * @access private
853 * @see procesItemArray()
854 */
855 function addItems($items,$iArray) {
856 if (is_array($iArray)) {
857 foreach($iArray as $value => $label) {
858 $items[]=array($label,$value);
859 }
860 }
861 return $items;
862 }
863
864 /**
865 * User processing of a selector box array of values.
866 *
867 * @param array The array of selector box items
868 * @param array TSconfig for the fields itemProcFunc
869 * @param array TCA/columns configuration
870 * @param string The table name
871 * @param array The current row
872 * @param string The field name
873 * @return array The modified input $items array
874 * @access private
875 * @see procesItemArray()
876 */
877 function procItems($items,$itemsProcFuncTSconfig,$config,$table,$row,$field) {
878 $params=array();
879 $params['items'] = &$items;
880 $params['config'] = $config;
881 $params['TSconfig'] = $itemsProcFuncTSconfig;
882 $params['table'] = $table;
883 $params['row'] = $row;
884 $params['field'] = $field;
885
886 t3lib_div::callUserFunction($config['itemsProcFunc'],$params,$this);
887 return $items;
888 }
889
890
891
892
893
894
895
896
897
898 /***********************************************
899 *
900 * Helper functions
901 *
902 ***********************************************/
903
904 /**
905 * Sets the lock for a record from table/id, IF $this->lockRecords is set!
906 *
907 * @param string The table name
908 * @param integer The id of the record
909 * @param integer The pid of the record
910 * @return void
911 */
912 function lockRecord($table, $id, $pid=0) {
913 if ($this->lockRecords) {
914 t3lib_BEfunc::lockRecords($table,$id,$pid);
915 }
916 }
917
918 /**
919 * Dummy function, can be used to "register" records. Used by eg. the "show_item" script.
920 *
921 * @param string Table name
922 * @param integer Record id
923 * @param string Field name
924 * @param string Field content.
925 * @return void
926 * @access private
927 * @see renderRecord()
928 */
929 function regItem($table, $id, $field, $content) {
930 }
931
932 /**
933 * Local wrapper function for LANG->sL (returning language labels)
934 *
935 * @param string Language label key
936 * @return string Localized label value.
937 * @access private
938 */
939 function sL($in) {
940 return $GLOBALS['LANG']->sL($in);
941 }
942 }
943
944
945 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_transferdata.php']) {
946 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_transferdata.php']);
947 }
948 ?>