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