* Added a checkbox for be-users to disable IP locking. This is useful if you have...
[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 "select"
420 *
421 * @param string The field value
422 * @param array TCA field config
423 * @param array TCEform TSconfig for the record
424 * @param string Table name
425 * @param array The row
426 * @param string Field name
427 * @return string The processed input field value ($data)
428 * @access private
429 * @see renderRecord()
430 */
431 function renderRecord_flexProc($data,$fieldConfig,$TSconfig,$table,$row,$field) {
432 global $TCA;
433
434 // Convert the XML data to PHP array:
435 $currentValueArray = t3lib_div::xml2array($data);
436 if (is_array($currentValueArray)) {
437
438 // Get current value array:
439 $dataStructArray = t3lib_BEfunc::getFlexFormDS($fieldConfig['config'],$row,$table);
440 if (is_array($dataStructArray)) {
441 $currentValueArray['data'] = $this->renderRecord_flexProc_procInData($currentValueArray['data'],$dataStructArray,array($data,$fieldConfig,$TSconfig,$table,$row,$field));
442 $data = t3lib_div::array2xml($currentValueArray);
443 }
444 }
445
446 return $data;
447 }
448
449 /**
450 * Processing of the content in $totalRecordcontent based on settings in the types-configuration
451 *
452 * @param array The array of values which has been processed according to their type (eg. "group" or "select")
453 * @param array The "types" configuration for the current display of fields.
454 * @param integer PAGE TSconfig PID
455 * @param string Table name
456 * @param integer PID value
457 * @return array The processed version of $totalRecordContent
458 * @access private
459 */
460 function renderRecord_typesProc($totalRecordContent,$types_fieldConfig,$tscPID,$table,$pid) {
461 foreach($types_fieldConfig as $vconf) {
462
463 // Find file to write to, if configured:
464 $eFile=t3lib_parsehtml_proc::evalWriteFile($vconf['spec']['static_write'],$totalRecordContent);
465
466 // Write file configuration:
467 if (is_array($eFile)) {
468 if ($eFile['loadFromFileField'] && $totalRecordContent[$eFile['loadFromFileField']]) {
469 // Read the external file, and insert the content between the ###TYPO3_STATICFILE_EDIT### markers:
470 $SW_fileContent = t3lib_div::getUrl($eFile['editFile']);
471 $parseHTML = t3lib_div::makeInstance('t3lib_parsehtml_proc');
472 $parseHTML->init('','');
473
474 $totalRecordContent[$vconf['field']] = $parseHTML->getSubpart(
475 $SW_fileContent,
476 $eFile['markerField']&&trim($totalRecordContent[$eFile['markerField']])
477 ? trim($totalRecordContent[$eFile['markerField']])
478 : '###TYPO3_STATICFILE_EDIT###',
479 chr(10).$totalRecordContent[$eFile['contentField']].chr(10),
480 1,1);
481 }
482 }
483
484 // RTE transformation
485 if ($vconf['spec']['rte_transform'] && !$this->disableRTE) {
486 $p=t3lib_BEfunc::getSpecConfParametersFromArray($vconf['spec']['rte_transform']['parameters']);
487 if ($p['mode']) { // There must be a mode set for transformation
488 if (isset($totalRecordContent[$vconf['field']])) {
489 if ($tscPID>=0) {
490
491 // Get Rich Text Editor configuration from Page TSconfig:
492 $RTEsetup = $GLOBALS['BE_USER']->getTSConfig('RTE',t3lib_BEfunc::getPagesTSconfig($tscPID));
493 $thisConfig = t3lib_BEfunc::RTEsetup($RTEsetup['properties'],$table,$vconf['field'],t3lib_BEfunc::getTCAtypeValue($table,$totalRecordContent));
494
495 // ... and any disable flag should not be set!
496 if (!$thisConfig['disabled'] && (!$p['flag'] || !$totalRecordContent[$p['flag']]) && $GLOBALS['BE_USER']->isRTE()) {
497 // Initialize transformation:
498 $parseHTML = t3lib_div::makeInstance('t3lib_parsehtml_proc');
499 $parseHTML->init($table.':'.$vconf['field'],$pid);
500 if (is_array($eFile)) {
501 $parseHTML->setRelPath(dirname($eFile['relEditFile']));
502 }
503 // Perform transformation:
504 $totalRecordContent[$vconf['field']]=$parseHTML->RTE_transform($totalRecordContent[$vconf['field']],$vconf['spec'],'rte',$thisConfig);
505 }
506 }
507 }
508 }
509 }
510 }
511
512 return $totalRecordContent;
513 }
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528 /***********************************************
529 *
530 * FlexForm processing functions
531 *
532 ***********************************************/
533
534 /**
535 * Function traversing sheets/languages for flex form data structures
536 *
537 * @param array Data array
538 * @param array Data Structure array
539 * @param array Various parameters to pass-through
540 * @return array Modified $dataPart array.
541 * @access private
542 * @see t3lib_TCEmain::checkValue_flex_procInData(), renderRecord_flexProc_procInData_travDS()
543 */
544 function renderRecord_flexProc_procInData($dataPart,$dataStructArray,$pParams) {
545 if (is_array($dataPart)) {
546 foreach($dataPart as $sKey => $sheetDef) {
547 list ($dataStruct,$actualSheet) = t3lib_div::resolveSheetDefInDS($dataStructArray,$sKey);
548
549 if (is_array($dataStruct) && $actualSheet==$sKey && is_array($sheetDef)) {
550 foreach($sheetDef as $lKey => $lData) {
551 $this->renderRecord_flexProc_procInData_travDS(
552 $dataPart[$sKey][$lKey],
553 $dataStruct['ROOT']['el'],
554 $pParams
555 );
556 }
557 }
558 }
559 }
560
561 return $dataPart;
562 }
563
564 /**
565 * Traverse data array / structure
566 *
567 * @param array Data array passed by reference.
568 * @param array Data structure
569 * @param array Various parameters pass-through.
570 * @return void
571 * @see renderRecord_flexProc_procInData(), t3lib_TCEmain::checkValue_flex_procInData_travDS()
572 */
573 function renderRecord_flexProc_procInData_travDS(&$dataValues,$DSelements,$pParams) {
574 if (is_array($DSelements)) {
575
576 // For each DS element:
577 foreach($DSelements as $key => $dsConf) {
578
579 // Array/Section:
580 if ($DSelements[$key]['type']=='array') {
581 if (is_array($dataValues[$key]['el'])) {
582 if ($DSelements[$key]['section']) {
583 foreach($dataValues[$key]['el'] as $ik => $el) {
584 $theKey = key($el);
585 if (is_array($dataValues[$key]['el'][$ik][$theKey]['el'])) {
586 $this->renderRecord_flexProc_procInData_travDS(
587 $dataValues[$key]['el'][$ik][$theKey]['el'],
588 $DSelements[$key]['el'][$theKey]['el'],
589 $pParams
590 );
591 }
592 }
593 } else {
594 if (!isset($dataValues[$key]['el'])) $dataValues[$key]['el']=array();
595 $this->renderRecord_flexProc_procInData_travDS(
596 $dataValues[$key]['el'],
597 $DSelements[$key]['el'],
598 $pParams
599 );
600 }
601 }
602 } else {
603 if (is_array($dsConf['TCEforms']['config']) && is_array($dataValues[$key])) {
604 foreach($dataValues[$key] as $vKey => $data) {
605 list($CVtable,$CVrow,$CVfield) = $pParams;
606
607 // Set default value:
608 if (!isset($dataValues[$key][$vKey])) {
609 $dataValues[$key][$vKey] = $dsConf['TCEforms']['config']['default'];
610 }
611
612 // Process value:
613 $dataValues[$key][$vKey] = $this->renderRecord_SW($dataValues[$key][$vKey],$dsConf['TCEforms'],array(),$CVtable,$CVrow,'');
614 }
615 }
616 }
617 }
618 }
619 }
620
621
622
623
624
625
626
627
628
629
630
631
632 /***********************************************
633 *
634 * Selector box processing functions
635 *
636 ***********************************************/
637
638 /**
639 * Adding "special" types to the $dataAcc array of selector items
640 *
641 * @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.
642 * @param array The array of original elements - basically the field value exploded by ","
643 * @param string The "special" key from the TCA config of the field. Determines the type of processing in here.
644 * @return array Modified $dataAcc array
645 * @access private
646 * @see renderRecord_selectProc()
647 */
648 function selectAddSpecial($dataAcc, $elements, $specialKey) {
649 global $TCA;
650
651 // Special select types:
652 switch ((string)$specialKey) {
653 case 'tables': // Listing all tables from $TCA:
654 $tNames = array_keys($TCA);
655 foreach($tNames as $tableName) {
656 foreach($elements as $eKey => $value) {
657 if (!strcmp($tableName,$value)) {
658 $dataAcc[$eKey]=rawurlencode($value).'|'.rawurlencode($this->sL($TCA[$value]['ctrl']['title']));
659 }
660 }
661 }
662 break;
663 case 'pagetypes': // Listing all page types (doktype)
664 $theTypes = $TCA['pages']['columns']['doktype']['config']['items'];
665 if (is_array($theTypes)) {
666 foreach($theTypes as $theTypesArrays) {
667 foreach($elements as $eKey => $value) {
668 if (!strcmp($theTypesArrays[1],$value)) {
669 $dataAcc[$eKey]=rawurlencode($value).'|'.rawurlencode($this->sL($theTypesArrays[0]));
670 }
671 }
672 }
673 }
674 break;
675 case 'exclude': // Listing exclude fields.
676 $theExcludeFields = t3lib_BEfunc::getExcludeFields();
677 if (is_array($theExcludeFields)) {
678 foreach($theExcludeFields as $theExcludeFieldsArrays) {
679 foreach($elements as $eKey => $value) {
680 if (!strcmp($theExcludeFieldsArrays[1],$value)) {
681 $dataAcc[$eKey]=rawurlencode($value).'|'.rawurlencode(ereg_replace(':$','',$theExcludeFieldsArrays[0]));
682 }
683 }
684 }
685 }
686 break;
687 case 'modListGroup': // Listing modules for GROUPS
688 case 'modListUser': // Listing modules for USERS:
689 if (!$this->loadModules) {
690 $this->loadModules = t3lib_div::makeInstance('t3lib_loadModules');
691 $this->loadModules->load($GLOBALS['TBE_MODULES']);
692 }
693 $modList = ($specialKey=='modListUser') ? $this->loadModules->modListUser : $this->loadModules->modListGroup;
694
695 foreach($modList as $theModName) {
696 foreach($elements as $eKey => $value) {
697 $label = '';
698 // Add label for main module:
699 $pp = explode('_',$value);
700 if (count($pp)>1) $label.=$GLOBALS['LANG']->moduleLabels['tabs'][$pp[0].'_tab'].'>';
701 // Add modules own label now:
702 $label.= $GLOBALS['LANG']->moduleLabels['tabs'][$value.'_tab'];
703
704 if (!strcmp($theModName,$value)) {
705 $dataAcc[$eKey]=rawurlencode($value).'|'.rawurlencode($label);
706 }
707 }
708 }
709 break;
710 }
711
712 return $dataAcc;
713 }
714
715 /**
716 * Adds the foreign record elements to $dataAcc, if any
717 *
718 * @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.
719 * @param array The array of original elements - basically the field value exploded by ","
720 * @param array Field configuration from TCA
721 * @param string The field name
722 * @param array TSconfig for the record
723 * @param array The record
724 * @return array Modified $dataAcc array
725 * @access private
726 * @see renderRecord_selectProc()
727 */
728 function selectAddForeign($dataAcc, $elements, $fieldConfig, $field, $TSconfig, $row) {
729 global $TCA;
730
731 // Init:
732 $recordList = Array();
733
734 // foreign_table
735 $subres = t3lib_BEfunc::exec_foreign_table_where_query($fieldConfig,$field,$TSconfig);
736 while ($subrow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($subres)) {
737 $recordList[$subrow['uid']] = t3lib_BEfunc::getRecordTitle($fieldConfig['config']['foreign_table'],$subrow);
738 }
739
740 // neg_foreign_table
741 if (is_array($TCA[$fieldConfig['config']['neg_foreign_table']])) {
742 $subres = t3lib_BEfunc::exec_foreign_table_where_query($fieldConfig,$field,$TSconfig,'neg_');
743 while ($subrow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($subres)) {
744 $recordList[-$subrow['uid']] = t3lib_BEfunc::getRecordTitle($fieldConfig['config']['neg_foreign_table'],$subrow);
745 }
746 }
747
748 // At this point all records that CAN be selected is found in $recordList
749 // Now, get the data from loadDBgroup based on the input list of values.
750 $dataIds = $this->getDataIdList($elements, $fieldConfig, $row);
751 if ($fieldConfig['config']['MM']) $dataAcc=array(); // Reset, if MM (which cannot bear anything but real relations!)
752
753 // After this we can traverse the loadDBgroup values and match values with the list of possible values in $recordList:
754 foreach($dataIds as $theId) {
755 if (isset($recordList[$theId])) {
756 $lPrefix = $this->sL($fieldConfig['config'][($theId>0?'':'neg_').'foreign_table_prefix']);
757 if ($fieldConfig['config']['MM']) {
758 $dataAcc[]=rawurlencode($theId).'|'.rawurlencode(t3lib_div::fixed_lgd($lPrefix.strip_tags($recordList[$theId]),$GLOBALS['BE_USER']->uc['titleLen']));
759 } else {
760 foreach($elements as $eKey => $value) {
761 if (!strcmp($theId,$value)) {
762 $dataAcc[$eKey]=rawurlencode($theId).'|'.rawurlencode(t3lib_div::fixed_lgd($lPrefix.strip_tags($recordList[$theId]),$GLOBALS['BE_USER']->uc['titleLen']));
763 }
764 }
765 }
766 }
767 }
768
769 return $dataAcc;
770 }
771
772 /**
773 * Returning the id-list processed by loadDBgroup for the foreign tables.
774 *
775 * @param array The array of original elements - basically the field value exploded by ","
776 * @param array Field configuration from TCA
777 * @param array The data array, currently. Used to set the "local_uid" for selecting MM relation records.
778 * @return array An array with ids of the records from the input elements array.
779 * @access private
780 */
781 function getDataIdList($elements, $fieldConfig, $row) {
782 $loadDB = t3lib_div::makeInstance('t3lib_loadDBGroup');
783 $loadDB->registerNonTableValues=$fieldConfig['config']['allowNonIdValues'] ? 1 : 0;
784 $loadDB->start(implode(',',$elements), $fieldConfig['config']['foreign_table'].','.$fieldConfig['config']['neg_foreign_table'], $fieldConfig['config']['MM'], $row['uid']);
785
786 $idList = $loadDB->convertPosNeg($loadDB->getValueArray(),$fieldConfig['config']['foreign_table'],$fieldConfig['config']['neg_foreign_table']);
787
788 return $idList;
789 }
790
791 /**
792 * Processing of selector box items. This includes the automated adding of elements plus user-function processing.
793 *
794 * @param array The elements to process
795 * @param array TCA/columns configuration
796 * @param array TSconfig for the field
797 * @param string The table name
798 * @param array The current row
799 * @param string The field name
800 * @return array The modified input $selItems array
801 * @access private
802 * @see renderRecord_selectProc()
803 */
804 function procesItemArray($selItems,$config,$fieldTSConfig,$table,$row,$field) {
805 $selItems = $this->addItems($selItems,$fieldTSConfig['addItems.']);
806 if ($config['itemsProcFunc']) $selItems = $this->procItems($selItems,$fieldTSConfig['itemsProcFunc.'],$config,$table,$row,$field);
807 return $selItems;
808 }
809
810 /**
811 * Adding items from $iArray to $items array
812 *
813 * @param array The array of selector box items to which key(value) / value(label) pairs from $iArray will be added.
814 * @param array The array of elements to add. The keys will become values. The value will become the label.
815 * @return array The modified input $items array
816 * @access private
817 * @see procesItemArray()
818 */
819 function addItems($items,$iArray) {
820 if (is_array($iArray)) {
821 foreach($iArray as $value => $label) {
822 $items[]=array($label,$value);
823 }
824 }
825 return $items;
826 }
827
828 /**
829 * User processing of a selector box array of values.
830 *
831 * @param array The array of selector box items
832 * @param array TSconfig for the fields itemProcFunc
833 * @param array TCA/columns configuration
834 * @param string The table name
835 * @param array The current row
836 * @param string The field name
837 * @return array The modified input $items array
838 * @access private
839 * @see procesItemArray()
840 */
841 function procItems($items,$itemsProcFuncTSconfig,$config,$table,$row,$field) {
842 $params=array();
843 $params['items'] = &$items;
844 $params['config'] = $config;
845 $params['TSconfig'] = $itemsProcFuncTSconfig;
846 $params['table'] = $table;
847 $params['row'] = $row;
848 $params['field'] = $field;
849
850 t3lib_div::callUserFunction($config['itemsProcFunc'],$params,$this);
851 return $items;
852 }
853
854
855
856
857
858
859
860
861
862 /***********************************************
863 *
864 * Helper functions
865 *
866 ***********************************************/
867
868 /**
869 * Sets the lock for a record from table/id, IF $this->lockRecords is set!
870 *
871 * @param string The table name
872 * @param integer The id of the record
873 * @param integer The pid of the record
874 * @return void
875 */
876 function lockRecord($table, $id, $pid=0) {
877 if ($this->lockRecords) {
878 t3lib_BEfunc::lockRecords($table,$id,$pid);
879 }
880 }
881
882 /**
883 * Dummy function, can be used to "register" records. Used by eg. the "show_item" script.
884 *
885 * @param string Table name
886 * @param integer Record id
887 * @param string Field name
888 * @param string Field content.
889 * @return void
890 * @access private
891 * @see renderRecord()
892 */
893 function regItem($table, $id, $field, $content) {
894 }
895
896 /**
897 * Local wrapper function for LANG->sL (returning language labels)
898 *
899 * @param string Language label key
900 * @return string Localized label value.
901 * @access private
902 */
903 function sL($in) {
904 return $GLOBALS['LANG']->sL($in);
905 }
906 }
907
908
909 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_transferdata.php']) {
910 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_transferdata.php']);
911 }
912 ?>