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