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