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