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