Fixed bug #10735: Wrong returnUrl with clipboard actions
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_transferdata.php
old mode 100755 (executable)
new mode 100644 (file)
index 4b161c2..448e53e
@@ -2,7 +2,7 @@
 /***************************************************************
 *  Copyright notice
 *
-*  (c) 1999-2004 Kasper Skaarhoj (kasper@typo3.com)
+*  (c) 1999-2009 Kasper Skaarhoj (kasperYYYY@typo3.com)
 *  All rights reserved
 *
 *  This script is part of the TYPO3 project. The TYPO3 project is
  * $Id$
  * Revised for TYPO3 3.6 September/2003 by Kasper Skaarhoj
  *
- * @author     Kasper Skaarhoj <kasper@typo3.com>
+ * @author     Kasper Skaarhoj <kasperYYYY@typo3.com>
  */
 /**
  * [CLASS/FUNCTION INDEX of SCRIPT]
  *
  *
  *
- *   97: class t3lib_transferData
+ *   99: class t3lib_transferData
  *
  *              SECTION: Getting record content, ready for display in TCEforms
- *  135:     function fetchRecord($table,$idList,$operation)
- *  221:     function renderRecord($table, $id, $pid, $row)
- *  288:     function renderRecord_SW($data,$fieldConfig,$TSconfig,$table,$row,$field)
- *  318:     function renderRecord_groupProc($data,$fieldConfig,$TSconfig,$table,$row,$field)
- *  369:     function renderRecord_selectProc($data,$fieldConfig,$TSconfig,$table,$row,$field)
- *  432:     function renderRecord_flexProc($data,$fieldConfig,$TSconfig,$table,$row,$field)
- *  461:     function renderRecord_typesProc($totalRecordContent,$types_fieldConfig,$tscPID,$table,$pid)
+ *  138:     function fetchRecord($table,$idList,$operation)
+ *  225:     function renderRecord($table, $id, $pid, $row)
+ *  269:     function renderRecordRaw($table, $id, $pid, $row, $TSconfig='', $tscPID=0)
+ *  327:     function renderRecord_SW($data,$fieldConfig,$TSconfig,$table,$row,$field)
+ *  359:     function renderRecord_groupProc($data,$fieldConfig,$TSconfig,$table,$row,$field)
+ *  410:     function renderRecord_selectProc($data,$fieldConfig,$TSconfig,$table,$row,$field)
+ *  473:     function renderRecord_flexProc($data,$fieldConfig,$TSconfig,$table,$row,$field)
+ *  504:     function renderRecord_typesProc($totalRecordContent,$types_fieldConfig,$tscPID,$table,$pid)
+ *  545:     function renderRecord_inlineProc($data,$fieldConfig,$TSconfig,$table,$row,$field)
  *
  *              SECTION: FlexForm processing functions
- *  549:     function renderRecord_flexProc_procInData($dataPart,$dataStructArray,$pParams)
- *  578:     function renderRecord_flexProc_procInData_travDS(&$dataValues,$DSelements,$pParams)
+ *  632:     function renderRecord_flexProc_procInData($dataPart,$dataStructArray,$pParams)
+ *  661:     function renderRecord_flexProc_procInData_travDS(&$dataValues,$DSelements,$pParams)
  *
  *              SECTION: Selector box processing functions
- *  655:     function selectAddSpecial($dataAcc, $elements, $specialKey)
- *  735:     function selectAddForeign($dataAcc, $elements, $fieldConfig, $field, $TSconfig, $row)
- *  788:     function getDataIdList($elements, $fieldConfig, $row)
- *  811:     function procesItemArray($selItems,$config,$fieldTSConfig,$table,$row,$field)
- *  826:     function addItems($items,$iArray)
- *  848:     function procItems($items,$itemsProcFuncTSconfig,$config,$table,$row,$field)
+ *  738:     function selectAddSpecial($dataAcc, $elements, $specialKey)
+ *  863:     function selectAddForeign($dataAcc, $elements, $fieldConfig, $field, $TSconfig, $row, $table)
+ *  917:     function getDataIdList($elements, $fieldConfig, $row, $table)
+ *  946:     function procesItemArray($selItems,$config,$fieldTSConfig,$table,$row,$field)
+ *  961:     function addItems($items,$iArray)
+ *  983:     function procItems($items,$itemsProcFuncTSconfig,$config,$table,$row,$field)
  *
  *              SECTION: Helper functions
- *  883:     function lockRecord($table, $id, $pid=0)
- *  900:     function regItem($table, $id, $field, $content)
- *  910:     function sL($in)
+ * 1018:     function lockRecord($table, $id, $pid=0)
+ * 1035:     function regItem($table, $id, $field, $content)
+ * 1045:     function sL($in)
  *
- * TOTAL FUNCTIONS: 18
+ * TOTAL FUNCTIONS: 20
  * (This index is automatically created/updated by the extension "extdeveval")
  *
  */
@@ -74,7 +76,7 @@
 require_once (PATH_t3lib.'class.t3lib_loaddbgroup.php');
 require_once (PATH_t3lib.'class.t3lib_loadmodules.php');
 require_once (PATH_t3lib.'class.t3lib_parsehtml_proc.php');
-
+require_once (PATH_t3lib.'class.t3lib_flexformtools.php');
 
 
 
@@ -90,7 +92,7 @@ require_once (PATH_t3lib.'class.t3lib_parsehtml_proc.php');
 /**
  * Class for getting and transforming data for display in backend forms (TCEforms)
  *
- * @author     Kasper Skaarhoj <kasper@typo3.com>
+ * @author     Kasper Skaarhoj <kasperYYYY@typo3.com>
  * @package TYPO3
  * @subpackage t3lib
  */
@@ -100,6 +102,7 @@ class t3lib_transferData {
        var $disableRTE=0;                                      // Is set externally if RTE is disabled.
        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.
        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.
+       var $addRawData = FALSE;                        // If set, the processed data is overlaid the raw record.
 
                // Internal, dynamic
        var $regTableItems = Array();           // Used to register, which items are already loaded!!
@@ -161,6 +164,18 @@ class t3lib_transferData {
                                                        }
                                                }
 
+                                               $pageTS = t3lib_beFunc::getPagesTSconfig($id, true);
+                                               if (isset($pageTS['TCAdefaults.'])) {
+                                                       $TCAPageTSOverride  = $pageTS['TCAdefaults.'];
+                                                       if (is_array($TCAPageTSOverride[$table.'.']))   {
+                                                               foreach($TCAPageTSOverride[$table.'.'] as $theF => $theV)       {
+                                                                       if (isset($TCA[$table]['columns'][$theF]))      {
+                                                                               $newRow[$theF]=$theV;
+                                                                       }
+                                                               }
+                                                       }
+                                               }
+
                                                        // Default values as submitted:
                                                if (is_array($this->defVals[$table]))   {
                                                        foreach($this->defVals[$table] as $theF => $theV)       {
@@ -194,6 +209,7 @@ class t3lib_transferData {
                                                        // Fetch database values
                                                $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', $table, 'uid='.intval($id).t3lib_BEfunc::deleteClause($table));
                                                if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
+                                                       t3lib_BEfunc::fixVersioningPid($table,$row);
                                                        $this->renderRecord($table, $id, $row['pid'], $row);
                                                        $contentTable = $GLOBALS['TYPO3_CONF_VARS']['SYS']['contentTable'];
                                                        $this->lockRecord($table, $id, $contentTable==$table?$row['pid']:0);    // Locking the pid if the table edited is the content table.
@@ -237,6 +253,11 @@ class t3lib_transferData {
                        if ($table == 'pages')  {$this->prevPageID = $id;}
 
                        $this->regTableItems_data[$uniqueItemRef] = $this->renderRecordRaw($table, $id, $pid, $row, $TSconfig, $tscPID);
+
+                               // 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!
+                       if ($this->addRawData && is_array($row) && is_array($this->regTableItems_data[$uniqueItemRef])) {
+                               $this->regTableItems_data[$uniqueItemRef] = array_merge($row, $this->regTableItems_data[$uniqueItemRef]);
+                       }
                }
        }
 
@@ -282,7 +303,7 @@ class t3lib_transferData {
                        $data = $this->renderRecord_SW($data,$fieldConfig,$TSconfig,$table,$row,$field);
 
                                // Set the field in the accumulation array IF the $data variabel is set:
-                       $totalRecordContent[$field]=isset($data)?$data:'';
+                       $totalRecordContent[$field] = isset($data) ? $data : '';
                }
 
                        // 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).
@@ -316,7 +337,6 @@ class t3lib_transferData {
         * @return      string          Modified $value
         */
        function renderRecord_SW($data,$fieldConfig,$TSconfig,$table,$row,$field)       {
-
                switch((string)$fieldConfig['config']['type'])  {
                        case 'group':
                                $data = $this->renderRecord_groupProc($data,$fieldConfig,$TSconfig,$table,$row,$field);
@@ -327,6 +347,9 @@ class t3lib_transferData {
                        case 'flex':
                                $data = $this->renderRecord_flexProc($data,$fieldConfig,$TSconfig,$table,$row,$field);
                        break;
+                       case 'inline':
+                               $data = $this->renderRecord_inlineProc($data,$fieldConfig,$TSconfig,$table,$row,$field);
+                       break;
                }
 
                return $data;
@@ -374,7 +397,8 @@ class t3lib_transferData {
                        break;
                        case 'db':
                                $loadDB = t3lib_div::makeInstance('t3lib_loadDBGroup');
-                               $loadDB->start($data, $fieldConfig['config']['allowed'], $fieldConfig['config']['MM'], $row['uid']);
+                               /* @var $loadDB t3lib_loadDBGroup */
+                               $loadDB->start($data, $fieldConfig['config']['allowed'], $fieldConfig['config']['MM'], $row['uid'], $table, $fieldConfig['config']);
                                $loadDB->getFromDB();
                                $data = $loadDB->readyForInterface();
                        break;
@@ -407,13 +431,14 @@ class t3lib_transferData {
                if (intval($fieldConfig['config']['maxitems'])>1)       {
 
                                // Add regular elements:
-                       if (is_array($fieldConfig['config']['items']))  {
-                               $fieldConfig['config']['items'] = $this->procesItemArray($fieldConfig['config']['items'], $fieldConfig['config'], $TSconfig[$field], $table, $row, $field);
-                               foreach($fieldConfig['config']['items'] as $pvpv)       {
-                                       foreach($elements as $eKey => $value)   {
-                                               if (!strcmp($value,$pvpv[1]))   {
-                                                       $dataAcc[$eKey]=rawurlencode($pvpv[1]).'|'.rawurlencode($pvpv[0]);
-                                               }
+                       if (!is_array($fieldConfig['config']['items'])) {
+                               $fieldConfig['config']['items'] = array();
+                       }
+                       $fieldConfig['config']['items'] = $this->procesItemArray($fieldConfig['config']['items'], $fieldConfig['config'], $TSconfig[$field], $table, $row, $field);
+                       foreach($fieldConfig['config']['items'] as $pvpv)       {
+                               foreach($elements as $eKey => $value)   {
+                                       if (!strcmp($value,$pvpv[1]))   {
+                                               $dataAcc[$eKey]=rawurlencode($pvpv[1]).'|'.rawurlencode($this->sL($pvpv[0]));
                                        }
                                }
                        }
@@ -425,7 +450,7 @@ class t3lib_transferData {
 
                                // Add "foreign table" stuff:
                        if ($TCA[$fieldConfig['config']['foreign_table']])      {
-                               $dataAcc = $this->selectAddForeign($dataAcc, $elements, $fieldConfig, $field, $TSconfig, $row);
+                               $dataAcc = $this->selectAddForeign($dataAcc, $elements, $fieldConfig, $field, $TSconfig, $row, $table);
                        }
 
                                // Always keep the native order for display in interface:
@@ -433,7 +458,7 @@ class t3lib_transferData {
                } else {        // Normal, <= 1 -> value without title on it
                        if ($TCA[$fieldConfig['config']['foreign_table']])      {
                                // Getting the data
-                               $dataIds = $this->getDataIdList($elements, $fieldConfig, $row);
+                               $dataIds = $this->getDataIdList($elements, $fieldConfig, $row, $table);
 
                                if (!count($dataIds))   $dataIds = array(0);
                                $dataAcc[]=$dataIds[0];
@@ -470,7 +495,9 @@ class t3lib_transferData {
                        $dataStructArray = t3lib_BEfunc::getFlexFormDS($fieldConfig['config'],$row,$table);
                        if (is_array($dataStructArray)) {
                                $currentValueArray['data'] = $this->renderRecord_flexProc_procInData($currentValueArray['data'],$dataStructArray,array($data,$fieldConfig,$TSconfig,$table,$row,$field));
-                               $data = t3lib_div::array2xml($currentValueArray);
+
+                               $flexObj = t3lib_div::makeInstance('t3lib_flexformtools');
+                               $data = $flexObj->flexArray2Xml($currentValueArray, TRUE);
                        }
                }
 
@@ -515,7 +542,46 @@ class t3lib_transferData {
                return $totalRecordContent;
        }
 
+       /**
+        * Processing of the data value in case the field type is "inline"
+        * In some parts nearly the same as type "select"
+        *
+        * @param       string          The field value
+        * @param       array           TCA field config
+        * @param       array           TCEform TSconfig for the record
+        * @param       string          Table name
+        * @param       array           The row
+        * @param       string          Field name
+        * @return      string          The processed input field value ($data)
+        * @access private
+        * @see renderRecord()
+        */
+       function renderRecord_inlineProc($data,$fieldConfig,$TSconfig,$table,$row,$field)       {
+               global $TCA;
+
+                       // Initialize:
+               $elements = t3lib_div::trimExplode(',',$data);  // Current data set.
+               $dataAcc=array();       // New data set, ready for interface (list of values, rawurlencoded)
+
+                       // At this point all records that CAN be selected is found in $recordList
+                       // Now, get the data from loadDBgroup based on the input list of values.
+               $dataIds = $this->getDataIdList($elements, $fieldConfig, $row, $table);
+
+                       // After this we can traverse the loadDBgroup values and match values with the list of possible values in $recordList:
+               foreach($dataIds as $theId)     {
+                       if ($fieldConfig['config']['MM'] || $fieldConfig['config']['foreign_field'])    {
+                               $dataAcc[]=$theId;
+                       } else {
+                               foreach($elements as $eKey => $value)   {
+                                       if (!strcmp($theId,$value))     {
+                                               $dataAcc[$eKey]=$theId;
+                                       }
+                               }
+                       }
+               }
 
+               return implode(',',$dataAcc);
+       }
 
 
 
@@ -584,13 +650,15 @@ class t3lib_transferData {
                                        if (is_array($dataValues[$key]['el']))  {
                                                if ($DSelements[$key]['section'])       {
                                                        foreach($dataValues[$key]['el'] as $ik => $el)  {
-                                                               $theKey = key($el);
-                                                               if (is_array($dataValues[$key]['el'][$ik][$theKey]['el']))      {
-                                                                       $this->renderRecord_flexProc_procInData_travDS(
-                                                                                       $dataValues[$key]['el'][$ik][$theKey]['el'],
-                                                                                       $DSelements[$key]['el'][$theKey]['el'],
-                                                                                       $pParams
-                                                                               );
+                                                               if (is_array($el))      {
+                                                                       $theKey = key($el);
+                                                                       if (is_array($dataValues[$key]['el'][$ik][$theKey]['el']))      {
+                                                                               $this->renderRecord_flexProc_procInData_travDS(
+                                                                                               $dataValues[$key]['el'][$ik][$theKey]['el'],
+                                                                                               $DSelements[$key]['el'][$theKey]['el'],
+                                                                                               $pParams
+                                                                                       );
+                                                                       }
                                                                }
                                                        }
                                                } else {
@@ -608,7 +676,7 @@ class t3lib_transferData {
 
                                                                // $data,$fieldConfig,$TSconfig,$table,$row,$field
                                                        list(,,$CVTSconfig,$CVtable,$CVrow,$CVfield) = $pParams;
-;
+
                                                                // Set default value:
                                                        if (!isset($dataValues[$key][$vKey]))   {
                                                                $dataValues[$key][$vKey] = $dsConf['TCEforms']['config']['default'];
@@ -725,7 +793,7 @@ class t3lib_transferData {
                                                        foreach($coValue['items'] as $itemKey => $itemCfg)      {
                                                                foreach($elements as $eKey => $value)   {
                                                                        if (!strcmp($coKey.':'.$itemKey, $value))       {
-                                                                               $dataAcc[$eKey] = rawurlencode($value).'|'.rawurlencode($GLOBALS['LANG']->sl($itemCfg[0]));
+                                                                               $dataAcc[$eKey] = rawurlencode($value).'|'.rawurlencode($this->sL($itemCfg[0]));
                                                                        }
                                                                }
                                                        }
@@ -770,11 +838,12 @@ class t3lib_transferData {
         * @param       string          The field name
         * @param       array           TSconfig for the record
         * @param       array           The record
+        * @param       array           The current table
         * @return      array           Modified $dataAcc array
         * @access private
         * @see renderRecord_selectProc()
         */
-       function selectAddForeign($dataAcc, $elements, $fieldConfig, $field, $TSconfig, $row)   {
+       function selectAddForeign($dataAcc, $elements, $fieldConfig, $field, $TSconfig, $row, $table)   {
                global $TCA;
 
                        // Init:
@@ -796,14 +865,14 @@ class t3lib_transferData {
 
                        // At this point all records that CAN be selected is found in $recordList
                        // Now, get the data from loadDBgroup based on the input list of values.
-               $dataIds = $this->getDataIdList($elements, $fieldConfig, $row);
+               $dataIds = $this->getDataIdList($elements, $fieldConfig, $row, $table);
                if ($fieldConfig['config']['MM'])       $dataAcc=array();       // Reset, if MM (which cannot bear anything but real relations!)
 
                        // After this we can traverse the loadDBgroup values and match values with the list of possible values in $recordList:
                foreach($dataIds as $theId)     {
                        if (isset($recordList[$theId])) {
                                $lPrefix = $this->sL($fieldConfig['config'][($theId>0?'':'neg_').'foreign_table_prefix']);
-                               if ($fieldConfig['config']['MM'])       {
+                               if ($fieldConfig['config']['MM'] || $fieldConfig['config']['foreign_field'])    {
                                        $dataAcc[]=rawurlencode($theId).'|'.rawurlencode(t3lib_div::fixed_lgd_cs($lPrefix.strip_tags($recordList[$theId]),$GLOBALS['BE_USER']->uc['titleLen']));
                                } else {
                                        foreach($elements as $eKey => $value)   {
@@ -824,13 +893,20 @@ class t3lib_transferData {
         * @param       array           The array of original elements - basically the field value exploded by ","
         * @param       array           Field configuration from TCA
         * @param       array           The data array, currently. Used to set the "local_uid" for selecting MM relation records.
+        * @param       string          Current table name. passed on to t3lib_loadDBGroup
         * @return      array           An array with ids of the records from the input elements array.
         * @access private
         */
-       function getDataIdList($elements, $fieldConfig, $row)   {
+       function getDataIdList($elements, $fieldConfig, $row, $table)   {
                $loadDB = t3lib_div::makeInstance('t3lib_loadDBGroup');
                $loadDB->registerNonTableValues=$fieldConfig['config']['allowNonIdValues'] ? 1 : 0;
-               $loadDB->start(implode(',',$elements), $fieldConfig['config']['foreign_table'].','.$fieldConfig['config']['neg_foreign_table'], $fieldConfig['config']['MM'], $row['uid']);
+               $loadDB->start(implode(',',$elements),
+                       $fieldConfig['config']['foreign_table'].','.$fieldConfig['config']['neg_foreign_table'],
+                       $fieldConfig['config']['MM'],
+                       $row['uid'],
+                       $table,
+                       $fieldConfig['config']
+               );
 
                $idList = $loadDB->convertPosNeg($loadDB->getValueArray(),$fieldConfig['config']['foreign_table'],$fieldConfig['config']['neg_foreign_table']);
 
@@ -958,4 +1034,5 @@ class t3lib_transferData {
 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_transferdata.php'])     {
        include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_transferdata.php']);
 }
-?>
+
+?>
\ No newline at end of file