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