Documentation TYPO3 par Ameos

class.t3lib_transferdata.php

00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 1999-2006 Kasper Skaarhoj (kasperYYYY@typo3.com)
00006 *  All rights reserved
00007 *
00008 *  This script is part of the TYPO3 project. The TYPO3 project is
00009 *  free software; you can redistribute it and/or modify
00010 *  it under the terms of the GNU General Public License as published by
00011 *  the Free Software Foundation; either version 2 of the License, or
00012 *  (at your option) any later version.
00013 *
00014 *  The GNU General Public License can be found at
00015 *  http://www.gnu.org/copyleft/gpl.html.
00016 *  A copy is found in the textfile GPL.txt and important notices to the license
00017 *  from the author is found in LICENSE.txt distributed with these scripts.
00018 *
00019 *
00020 *  This script is distributed in the hope that it will be useful,
00021 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00022 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023 *  GNU General Public License for more details.
00024 *
00025 *  This copyright notice MUST APPEAR in all copies of the script!
00026 ***************************************************************/
00076 require_once (PATH_t3lib.'class.t3lib_loaddbgroup.php');
00077 require_once (PATH_t3lib.'class.t3lib_loadmodules.php');
00078 require_once (PATH_t3lib.'class.t3lib_parsehtml_proc.php');
00079 require_once (PATH_t3lib.'class.t3lib_flexformtools.php');
00080 
00081 
00082 
00083 
00084 
00085 
00086 
00087 
00088 
00089 
00090 
00091 
00099 class t3lib_transferData {
00100                 // External, static:
00101         var $lockRecords=0;                                     // If set, the records requested are locked.
00102         var $disableRTE=0;                                      // Is set externally if RTE is disabled.
00103         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.
00104         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.
00105         var $addRawData = FALSE;                        // If set, the processed data is overlaid the raw record.
00106 
00107                 // Internal, dynamic
00108         var $regTableItems = Array();           // Used to register, which items are already loaded!!
00109         var $regTableItems_data = Array();      // This stores the record data of the loaded records
00110         var $loadModules='';                            // Contains loadModules object, if used. (for reuse internally)
00111 
00112 
00113 
00114 
00115 
00116 
00117 
00118 
00119 
00120 
00121         /***********************************************
00122          *
00123          * Getting record content, ready for display in TCEforms
00124          *
00125          ***********************************************/
00126 
00138         function fetchRecord($table,$idList,$operation) {
00139                 global $TCA;
00140 
00141                 if ((string)$idList == 'prev')  {$idList = $this->prevPageID;}
00142 
00143                 if ($TCA[$table])       {
00144                         t3lib_div::loadTCA($table);
00145 
00146                                 // For each ID value (integer) we
00147                         $ids = t3lib_div::trimExplode(',',$idList,1);
00148                         foreach($ids as $id)    {
00149                                 if (strcmp($id,''))     {       // If ID is not blank:
00150 
00151                                                 // For new records to be created, find default values:
00152                                         if ($operation=='new')  {
00153 
00154                                                         // Default values:
00155                                                 $newRow = Array();      // Used to store default values as found here:
00156 
00157                                                         // Default values as set in userTS:
00158                                                 $TCAdefaultOverride = $GLOBALS['BE_USER']->getTSConfigProp('TCAdefaults');
00159                                                 if (is_array($TCAdefaultOverride[$table.'.']))  {
00160                                                         foreach($TCAdefaultOverride[$table.'.'] as $theF => $theV)      {
00161                                                                 if (isset($TCA[$table]['columns'][$theF]))      {
00162                                                                         $newRow[$theF]=$theV;
00163                                                                 }
00164                                                         }
00165                                                 }
00166 
00167                                                         // Default values as submitted:
00168                                                 if (is_array($this->defVals[$table]))   {
00169                                                         foreach($this->defVals[$table] as $theF => $theV)       {
00170                                                                 if (isset($TCA[$table]['columns'][$theF]))      {
00171                                                                         $newRow[$theF]=$theV;
00172                                                                 }
00173                                                         }
00174                                                 }
00175 
00176                                                         // Fetch default values if a previous record exists
00177                                                 if ($id<0 && $TCA[$table]['ctrl']['useColumnsForDefaultValues'])        {
00178                                                                 // Fetches the previous record:
00179                                                         $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', $table, 'uid='.abs($id).t3lib_BEfunc::deleteClause($table));
00180                                                         if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00181                                                                         // Gets the list of fields to copy from the previous record.
00182                                                                 $fArr=t3lib_div::trimExplode(',',$TCA[$table]['ctrl']['useColumnsForDefaultValues'],1);
00183                                                                 while(list(,$theF)=each($fArr)) {
00184                                                                         if (isset($TCA[$table]['columns'][$theF]))      {
00185                                                                                 $newRow[$theF]=$row[$theF];
00186                                                                         }
00187                                                                 }
00188                                                         }
00189                                                         $GLOBALS['TYPO3_DB']->sql_free_result($res);
00190                                                 }
00191 
00192                                                         // Finally, call renderRecord:
00193                                                 $this->renderRecord($table, uniqid('NEW'), $id, $newRow);
00194                                         } else {
00195                                                 $id=intval($id);
00196 
00197                                                         // Fetch database values
00198                                                 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', $table, 'uid='.intval($id).t3lib_BEfunc::deleteClause($table));
00199                                                 if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00200                                                         t3lib_BEfunc::fixVersioningPid($table,$row);
00201                                                         $this->renderRecord($table, $id, $row['pid'], $row);
00202                                                         $contentTable = $GLOBALS['TYPO3_CONF_VARS']['SYS']['contentTable'];
00203                                                         $this->lockRecord($table, $id, $contentTable==$table?$row['pid']:0);    // Locking the pid if the table edited is the content table.
00204                                                 }
00205                                                 $GLOBALS['TYPO3_DB']->sql_free_result($res);
00206                                         }
00207                                 }
00208                         }
00209                 }
00210         }
00211 
00225         function renderRecord($table, $id, $pid, $row)  {
00226                 global $TCA;
00227 
00228                         // Init:
00229                 $uniqueItemRef = $table.'_'.$id;
00230                 t3lib_div::loadTCA($table);
00231 
00232                         // Fetches the true PAGE TSconfig pid to use later, if needed. (Until now, only for the RTE, but later..., who knows?)
00233                 list($tscPID)=t3lib_BEfunc::getTSCpid($table,$id,$pid);
00234                 $TSconfig = t3lib_BEfunc::getTCEFORM_TSconfig($table,array_merge($row,array('uid'=>$id,'pid'=>$pid)));
00235 
00236                         // If the record has not already been loaded (in which case we DON'T do it again)...
00237                 if (!$this->regTableItems[$uniqueItemRef])      {
00238                         $this->regTableItems[$uniqueItemRef] = 1;       // set "loaded" flag.
00239 
00240                                 // If the table is pages, set the previous page id internally.
00241                         if ($table == 'pages')  {$this->prevPageID = $id;}
00242 
00243                         $this->regTableItems_data[$uniqueItemRef] = $this->renderRecordRaw($table, $id, $pid, $row, $TSconfig, $tscPID);
00244 
00245                                 // 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!
00246                         if ($this->addRawData && is_array($row) && is_array($this->regTableItems_data[$uniqueItemRef])) {
00247                                 $this->regTableItems_data[$uniqueItemRef] = array_merge($row, $this->regTableItems_data[$uniqueItemRef]);
00248                         }
00249                 }
00250         }
00251 
00252 
00253 
00269         function renderRecordRaw($table, $id, $pid, $row, $TSconfig='', $tscPID=0)      {
00270                 global $TCA;
00271 
00272                 if(!is_array($TSconfig)) {
00273                         $TSconfig = array();
00274                 }
00275 
00276                         // Create blank accumulation array:
00277                 $totalRecordContent=array();
00278 
00279                         // Traverse the configured columns for the table (TCA):
00280                         // For each column configured, we will perform processing if needed based on the type (eg. for "group" and "select" types this is needed)
00281                 t3lib_div::loadTCA($table);
00282                 $copyOfColumns = $TCA[$table]['columns'];
00283                 foreach($copyOfColumns as $field => $fieldConfig)       {
00284                                 // Set $data variable for the field, either inputted value from $row - or if not found, the default value as defined in the "config" array
00285                         if (isset($row[$field]))        {
00286                                 $data = $row[$field];
00287                         } else {
00288                                 $data = $fieldConfig['config']['default'];
00289                         }
00290 
00291                         $data = $this->renderRecord_SW($data,$fieldConfig,$TSconfig,$table,$row,$field);
00292 
00293                                 // Set the field in the accumulation array IF the $data variabel is set:
00294                         $totalRecordContent[$field] = isset($data) ? $data : '';
00295                 }
00296 
00297                         // 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).
00298                         // For instance this could be processing instructions for the Rich Text Editor.
00299                 $types_fieldConfig = t3lib_BEfunc::getTCAtypes($table,$totalRecordContent);
00300                 if (is_array($types_fieldConfig))       {
00301                         $totalRecordContent = $this->renderRecord_typesProc($totalRecordContent,$types_fieldConfig,$tscPID,$table,$pid);
00302                 }
00303 
00304                         // Register items, mostly for external use (overriding the regItem() function)
00305                 foreach($totalRecordContent as $field => $data) {
00306                         $this->regItem($table,$id,$field,$data);
00307                 }
00308 
00309                         // Finally, store the result:
00310                 reset($totalRecordContent);
00311 
00312                 return $totalRecordContent;
00313 
00314         }
00315 
00327         function renderRecord_SW($data,$fieldConfig,$TSconfig,$table,$row,$field)       {
00328                 switch((string)$fieldConfig['config']['type'])  {
00329                         case 'group':
00330                                 $data = $this->renderRecord_groupProc($data,$fieldConfig,$TSconfig,$table,$row,$field);
00331                         break;
00332                         case 'select':
00333                                 $data = $this->renderRecord_selectProc($data,$fieldConfig,$TSconfig,$table,$row,$field);
00334                         break;
00335                         case 'flex':
00336                                 $data = $this->renderRecord_flexProc($data,$fieldConfig,$TSconfig,$table,$row,$field);
00337                         break;
00338                         case 'inline':
00339                                 $data = $this->renderRecord_inlineProc($data,$fieldConfig,$TSconfig,$table,$row,$field);
00340                         break;
00341                 }
00342 
00343                 return $data;
00344         }
00345 
00359         function renderRecord_groupProc($data,$fieldConfig,$TSconfig,$table,$row,$field)        {
00360                 switch ($fieldConfig['config']['internal_type'])        {
00361                         case 'file':
00362                                         // Init array used to accumulate the files:
00363                                 $dataAcc=array();
00364 
00365                                         // Now, load the files into the $dataAcc array, whether stored by MM or as a list of filenames:
00366                                 if ($fieldConfig['config']['MM'])       {
00367                                         $loadDB = t3lib_div::makeInstance('t3lib_loadDBGroup');
00368                                         $loadDB->start('', 'files', $fieldConfig['config']['MM'], $row['uid']); // Setting dummy startup
00369 
00370                                         foreach($loadDB->itemArray as $value)   {
00371                                                 if ($value['id'])       {
00372                                                         $dataAcc[]=rawurlencode($value['id']).'|'.rawurlencode($value['id']);
00373                                                 }
00374                                         }
00375                                 } else {
00376                                         $fileList = t3lib_div::trimExplode(',',$data,1);
00377                                         foreach($fileList as $value)    {
00378                                                 if ($value)     {
00379                                                         $dataAcc[]=rawurlencode($value).'|'.rawurlencode($value);
00380                                                 }
00381                                         }
00382                                 }
00383                                         // Implode the accumulation array to a comma separated string:
00384                                 $data = implode(',',$dataAcc);
00385                         break;
00386                         case 'db':
00387                                 $loadDB = t3lib_div::makeInstance('t3lib_loadDBGroup');
00388                                 $loadDB->start($data, $fieldConfig['config']['allowed'], $fieldConfig['config']['MM'], $row['uid'], $table, $fieldConfig['config']);
00389                                 $loadDB->getFromDB();
00390                                 $data = $loadDB->readyForInterface();
00391                         break;
00392                 }
00393 
00394                 return $data;
00395         }
00396 
00410         function renderRecord_selectProc($data,$fieldConfig,$TSconfig,$table,$row,$field)       {
00411                 global $TCA;
00412 
00413                         // Initialize:
00414                 $elements = t3lib_div::trimExplode(',',$data,1);        // Current data set.
00415                 $dataAcc=array();       // New data set, ready for interface (list of values, rawurlencoded)
00416 
00417                         // For list selectors (multi-value):
00418                 if (intval($fieldConfig['config']['maxitems'])>1)       {
00419 
00420                                 // Add regular elements:
00421                         if (is_array($fieldConfig['config']['items']))  {
00422                                 $fieldConfig['config']['items'] = $this->procesItemArray($fieldConfig['config']['items'], $fieldConfig['config'], $TSconfig[$field], $table, $row, $field);
00423                                 foreach($fieldConfig['config']['items'] as $pvpv)       {
00424                                         foreach($elements as $eKey => $value)   {
00425                                                 if (!strcmp($value,$pvpv[1]))   {
00426                                                         $dataAcc[$eKey]=rawurlencode($pvpv[1]).'|'.rawurlencode($this->sL($pvpv[0]));
00427                                                 }
00428                                         }
00429                                 }
00430                         }
00431 
00432                                 // Add "special"
00433                         if ($fieldConfig['config']['special'])  {
00434                                 $dataAcc = $this->selectAddSpecial($dataAcc, $elements, $fieldConfig['config']['special']);
00435                         }
00436 
00437                                 // Add "foreign table" stuff:
00438                         if ($TCA[$fieldConfig['config']['foreign_table']])      {
00439                                 $dataAcc = $this->selectAddForeign($dataAcc, $elements, $fieldConfig, $field, $TSconfig, $row, $table);
00440                         }
00441 
00442                                 // Always keep the native order for display in interface:
00443                         ksort($dataAcc);
00444                 } else {        // Normal, <= 1 -> value without title on it
00445                         if ($TCA[$fieldConfig['config']['foreign_table']])      {
00446                                 // Getting the data
00447                                 $dataIds = $this->getDataIdList($elements, $fieldConfig, $row, $table);
00448 
00449                                 if (!count($dataIds))   $dataIds = array(0);
00450                                 $dataAcc[]=$dataIds[0];
00451                         } else {
00452                                 $dataAcc[]=$elements[0];
00453                         }
00454                 }
00455 
00456                 return implode(',',$dataAcc);
00457         }
00458 
00473         function renderRecord_flexProc($data,$fieldConfig,$TSconfig,$table,$row,$field) {
00474                 global $TCA;
00475 
00476                         // Convert the XML data to PHP array:
00477                 $currentValueArray = t3lib_div::xml2array($data);
00478                 if (is_array($currentValueArray))       {
00479 
00480                                 // Get current value array:
00481                         $dataStructArray = t3lib_BEfunc::getFlexFormDS($fieldConfig['config'],$row,$table);
00482                         if (is_array($dataStructArray)) {
00483                                 $currentValueArray['data'] = $this->renderRecord_flexProc_procInData($currentValueArray['data'],$dataStructArray,array($data,$fieldConfig,$TSconfig,$table,$row,$field));
00484 
00485                                 $flexObj = t3lib_div::makeInstance('t3lib_flexformtools');
00486                                 $data = $flexObj->flexArray2Xml($currentValueArray, TRUE);
00487                         }
00488                 }
00489 
00490                 return $data;
00491         }
00492 
00504         function renderRecord_typesProc($totalRecordContent,$types_fieldConfig,$tscPID,$table,$pid)     {
00505                 foreach($types_fieldConfig as $vconf)   {
00506 
00507                                 // Find file to write to, if configured:
00508                         $eFile = t3lib_parsehtml_proc::evalWriteFile($vconf['spec']['static_write'],$totalRecordContent);
00509 
00510                                 // Write file configuration:
00511                         if (is_array($eFile))   {
00512                                 if ($eFile['loadFromFileField'] && $totalRecordContent[$eFile['loadFromFileField']])    {
00513                                                 // Read the external file, and insert the content between the ###TYPO3_STATICFILE_EDIT### markers:
00514                                         $SW_fileContent = t3lib_div::getUrl($eFile['editFile']);
00515                                         $parseHTML = t3lib_div::makeInstance('t3lib_parsehtml_proc');
00516                                         $parseHTML->init('','');
00517 
00518                                         $totalRecordContent[$vconf['field']] = $parseHTML->getSubpart(
00519                                                 $SW_fileContent,
00520                                                 $eFile['markerField']&&trim($totalRecordContent[$eFile['markerField']])
00521                                                         ? trim($totalRecordContent[$eFile['markerField']])
00522                                                         : '###TYPO3_STATICFILE_EDIT###'
00523                                         );
00524                                 }
00525                         }
00526                 }
00527 
00528                 return $totalRecordContent;
00529         }
00530 
00545         function renderRecord_inlineProc($data,$fieldConfig,$TSconfig,$table,$row,$field)       {
00546                 global $TCA;
00547 
00548                         // Initialize:
00549                 $elements = t3lib_div::trimExplode(',',$data);  // Current data set.
00550                 $dataAcc=array();       // New data set, ready for interface (list of values, rawurlencoded)
00551         
00552                 $dataAcc = $this->selectAddForeign($dataAcc, $elements, $fieldConfig, $field, $TSconfig, $row, $table);
00553                 
00554                 return implode(',',$dataAcc);
00555         }
00556 
00557 
00558 
00559 
00560 
00561 
00562 
00563 
00564 
00565 
00566 
00567 
00568         /***********************************************
00569          *
00570          * FlexForm processing functions
00571          *
00572          ***********************************************/
00573 
00584         function renderRecord_flexProc_procInData($dataPart,$dataStructArray,$pParams)  {
00585                 if (is_array($dataPart))        {
00586                         foreach($dataPart as $sKey => $sheetDef)        {
00587                                 list ($dataStruct,$actualSheet) = t3lib_div::resolveSheetDefInDS($dataStructArray,$sKey);
00588 
00589                                 if (is_array($dataStruct) && $actualSheet==$sKey && is_array($sheetDef))        {
00590                                         foreach($sheetDef as $lKey => $lData)   {
00591                                                 $this->renderRecord_flexProc_procInData_travDS(
00592                                                         $dataPart[$sKey][$lKey],
00593                                                         $dataStruct['ROOT']['el'],
00594                                                         $pParams
00595                                                 );
00596                                         }
00597                                 }
00598                         }
00599                 }
00600 
00601                 return $dataPart;
00602         }
00603 
00613         function renderRecord_flexProc_procInData_travDS(&$dataValues,$DSelements,$pParams)             {
00614                 if (is_array($DSelements))      {
00615 
00616                                 // For each DS element:
00617                         foreach($DSelements as $key => $dsConf) {
00618 
00619                                                 // Array/Section:
00620                                 if ($DSelements[$key]['type']=='array') {
00621                                         if (is_array($dataValues[$key]['el']))  {
00622                                                 if ($DSelements[$key]['section'])       {
00623                                                         foreach($dataValues[$key]['el'] as $ik => $el)  {
00624                                                                 $theKey = key($el);
00625                                                                 if (is_array($dataValues[$key]['el'][$ik][$theKey]['el']))      {
00626                                                                         $this->renderRecord_flexProc_procInData_travDS(
00627                                                                                         $dataValues[$key]['el'][$ik][$theKey]['el'],
00628                                                                                         $DSelements[$key]['el'][$theKey]['el'],
00629                                                                                         $pParams
00630                                                                                 );
00631                                                                 }
00632                                                         }
00633                                                 } else {
00634                                                         if (!isset($dataValues[$key]['el']))    $dataValues[$key]['el']=array();
00635                                                         $this->renderRecord_flexProc_procInData_travDS(
00636                                                                         $dataValues[$key]['el'],
00637                                                                         $DSelements[$key]['el'],
00638                                                                         $pParams
00639                                                                 );
00640                                                 }
00641                                         }
00642                                 } else {
00643                                         if (is_array($dsConf['TCEforms']['config']) && is_array($dataValues[$key]))     {
00644                                                 foreach($dataValues[$key] as $vKey => $data)    {
00645 
00646                                                                 // $data,$fieldConfig,$TSconfig,$table,$row,$field
00647                                                         list(,,$CVTSconfig,$CVtable,$CVrow,$CVfield) = $pParams;
00648 ;
00649                                                                 // Set default value:
00650                                                         if (!isset($dataValues[$key][$vKey]))   {
00651                                                                 $dataValues[$key][$vKey] = $dsConf['TCEforms']['config']['default'];
00652                                                         }
00653 
00654                                                                 // Process value:
00655                                                         $dataValues[$key][$vKey] = $this->renderRecord_SW($dataValues[$key][$vKey],$dsConf['TCEforms'],$CVTSconfig,$CVtable,$CVrow,'');
00656                                                 }
00657                                         }
00658                                 }
00659                         }
00660                 }
00661         }
00662 
00663 
00664 
00665 
00666 
00667 
00668 
00669 
00670 
00671 
00672 
00673 
00674         /***********************************************
00675          *
00676          * Selector box processing functions
00677          *
00678          ***********************************************/
00679 
00690         function selectAddSpecial($dataAcc, $elements, $specialKey)     {
00691                 global $TCA;
00692 
00693                         // Special select types:
00694                 switch ((string)$specialKey)    {
00695                         case 'tables':          // Listing all tables from $TCA:
00696                                 $tNames = array_keys($TCA);
00697                                 foreach($tNames as $tableName)  {
00698                                         foreach($elements as $eKey => $value)   {
00699                                                 if (!strcmp($tableName,$value)) {
00700                                                         $dataAcc[$eKey]=rawurlencode($value).'|'.rawurlencode($this->sL($TCA[$value]['ctrl']['title']));
00701                                                 }
00702                                         }
00703                                 }
00704                         break;
00705                         case 'pagetypes':       // Listing all page types (doktype)
00706                                 $theTypes = $TCA['pages']['columns']['doktype']['config']['items'];
00707                                 if (is_array($theTypes))        {
00708                                         foreach($theTypes as $theTypesArrays)   {
00709                                                 foreach($elements as $eKey => $value)   {
00710                                                         if (!strcmp($theTypesArrays[1],$value)) {
00711                                                                 $dataAcc[$eKey]=rawurlencode($value).'|'.rawurlencode($this->sL($theTypesArrays[0]));
00712                                                         }
00713                                                 }
00714                                         }
00715                                 }
00716                         break;
00717                         case 'exclude':         // Listing exclude fields.
00718                                 $theExcludeFields = t3lib_BEfunc::getExcludeFields();
00719 
00720                                 if (is_array($theExcludeFields))        {
00721                                         foreach($theExcludeFields as $theExcludeFieldsArrays)   {
00722                                                 foreach($elements as $eKey => $value)   {
00723                                                         if (!strcmp($theExcludeFieldsArrays[1],$value)) {
00724                                                                 $dataAcc[$eKey]=rawurlencode($value).'|'.rawurlencode(ereg_replace(':$','',$theExcludeFieldsArrays[0]));
00725                                                         }
00726                                                 }
00727                                         }
00728                                 }
00729                         break;
00730                         case 'explicitValues':
00731                                 $theTypes = t3lib_BEfunc::getExplicitAuthFieldValues();
00732 
00733                                 foreach($theTypes as $tableFieldKey => $theTypeArrays)  {
00734                                         if (is_array($theTypeArrays['items']))  {
00735                                                 foreach($theTypeArrays['items'] as $itemValue => $itemContent)  {
00736                                                         foreach($elements as $eKey => $value)   {
00737                                                                 if (!strcmp($tableFieldKey.':'.$itemValue.':'.$itemContent[0], $value)) {
00738                                                                         $dataAcc[$eKey] = rawurlencode($value).'|'.rawurlencode('['.$itemContent[2].'] '.$itemContent[1]);
00739                                                                 }
00740                                                         }
00741                                                 }
00742                                         }
00743                                 }
00744                         break;
00745                         case 'languages':
00746                                 $theLangs = t3lib_BEfunc::getSystemLanguages();
00747                                 foreach($theLangs as $lCfg)     {
00748                                         foreach($elements as $eKey => $value)   {
00749                                                 if (!strcmp($lCfg[1], $value))  {
00750                                                         $dataAcc[$eKey] = rawurlencode($value).'|'.rawurlencode($lCfg[0]);
00751                                                 }
00752                                         }
00753                                 }
00754                         break;
00755                         case 'custom':
00756                                 $customOptions = $GLOBALS['TYPO3_CONF_VARS']['BE']['customPermOptions'];
00757 
00758                                 if (is_array($customOptions))   {
00759                                         foreach($customOptions as $coKey => $coValue) {
00760                                                 if (is_array($coValue['items']))        {
00761                                                                 // Traverse items:
00762                                                         foreach($coValue['items'] as $itemKey => $itemCfg)      {
00763                                                                 foreach($elements as $eKey => $value)   {
00764                                                                         if (!strcmp($coKey.':'.$itemKey, $value))       {
00765                                                                                 $dataAcc[$eKey] = rawurlencode($value).'|'.rawurlencode($this->sL($itemCfg[0]));
00766                                                                         }
00767                                                                 }
00768                                                         }
00769                                                 }
00770                                         }
00771                                 }
00772                         break;
00773                         case 'modListGroup':    // Listing modules for GROUPS
00774                         case 'modListUser':             // Listing modules for USERS:
00775                                 if (!$this->loadModules)        {
00776                                         $this->loadModules = t3lib_div::makeInstance('t3lib_loadModules');
00777                                         $this->loadModules->load($GLOBALS['TBE_MODULES']);
00778                                 }
00779                                 $modList = ($specialKey=='modListUser') ? $this->loadModules->modListUser : $this->loadModules->modListGroup;
00780 
00781                                 foreach($modList as $theModName)        {
00782                                         foreach($elements as $eKey => $value)   {
00783                                                 $label = '';
00784                                                         // Add label for main module:
00785                                                 $pp = explode('_',$value);
00786                                                 if (count($pp)>1)       $label.=$GLOBALS['LANG']->moduleLabels['tabs'][$pp[0].'_tab'].'>';
00787                                                         // Add modules own label now:
00788                                                 $label.= $GLOBALS['LANG']->moduleLabels['tabs'][$value.'_tab'];
00789 
00790                                                 if (!strcmp($theModName,$value))        {
00791                                                         $dataAcc[$eKey]=rawurlencode($value).'|'.rawurlencode($label);
00792                                                 }
00793                                         }
00794                                 }
00795                         break;
00796                 }
00797 
00798                 return $dataAcc;
00799         }
00800 
00815         function selectAddForeign($dataAcc, $elements, $fieldConfig, $field, $TSconfig, $row, $table)   {
00816                 global $TCA;
00817 
00818                         // Init:
00819                 $recordList = Array();
00820 
00821                         // foreign_table
00822                 $subres = t3lib_BEfunc::exec_foreign_table_where_query($fieldConfig,$field,$TSconfig);
00823                 while ($subrow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($subres))        {
00824                         $recordList[$subrow['uid']] = t3lib_BEfunc::getRecordTitle($fieldConfig['config']['foreign_table'],$subrow);
00825                 }
00826 
00827                         // neg_foreign_table
00828                 if (is_array($TCA[$fieldConfig['config']['neg_foreign_table']]))        {
00829                         $subres = t3lib_BEfunc::exec_foreign_table_where_query($fieldConfig,$field,$TSconfig,'neg_');
00830                         while ($subrow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($subres))        {
00831                                 $recordList[-$subrow['uid']] = t3lib_BEfunc::getRecordTitle($fieldConfig['config']['neg_foreign_table'],$subrow);
00832                         }
00833                 }
00834 
00835                         // At this point all records that CAN be selected is found in $recordList
00836                         // Now, get the data from loadDBgroup based on the input list of values.
00837                 $dataIds = $this->getDataIdList($elements, $fieldConfig, $row, $table);
00838                 if ($fieldConfig['config']['MM'])       $dataAcc=array();       // Reset, if MM (which cannot bear anything but real relations!)
00839 
00840                         // After this we can traverse the loadDBgroup values and match values with the list of possible values in $recordList:
00841                 foreach($dataIds as $theId)     {
00842                         if (isset($recordList[$theId])) {
00843                                 $lPrefix = $this->sL($fieldConfig['config'][($theId>0?'':'neg_').'foreign_table_prefix']);
00844                                 if ($fieldConfig['config']['MM'] || $fieldConfig['config']['foreign_field'])    {
00845                                         $dataAcc[]=rawurlencode($theId).'|'.rawurlencode(t3lib_div::fixed_lgd_cs($lPrefix.strip_tags($recordList[$theId]),$GLOBALS['BE_USER']->uc['titleLen']));
00846                                 } else {
00847                                         foreach($elements as $eKey => $value)   {
00848                                                 if (!strcmp($theId,$value))     {
00849                                                         $dataAcc[$eKey]=rawurlencode($theId).'|'.rawurlencode(t3lib_div::fixed_lgd_cs($lPrefix.strip_tags($recordList[$theId]),$GLOBALS['BE_USER']->uc['titleLen']));
00850                                                 }
00851                                         }
00852                                 }
00853                         }
00854                 }
00855 
00856                 return $dataAcc;
00857         }
00858 
00869         function getDataIdList($elements, $fieldConfig, $row, $table)   {
00870                 $loadDB = t3lib_div::makeInstance('t3lib_loadDBGroup');
00871                 $loadDB->registerNonTableValues=$fieldConfig['config']['allowNonIdValues'] ? 1 : 0;
00872                 $loadDB->start(implode(',',$elements),
00873                         $fieldConfig['config']['foreign_table'].','.$fieldConfig['config']['neg_foreign_table'],
00874                         $fieldConfig['config']['MM'],
00875                         $row['uid'],
00876                         $table,
00877                         $fieldConfig['config']
00878                 );
00879 
00880                 $idList = $loadDB->convertPosNeg($loadDB->getValueArray(),$fieldConfig['config']['foreign_table'],$fieldConfig['config']['neg_foreign_table']);
00881 
00882                 return $idList;
00883         }
00884 
00898         function procesItemArray($selItems,$config,$fieldTSConfig,$table,$row,$field)   {
00899                 $selItems = $this->addItems($selItems,$fieldTSConfig['addItems.']);
00900                 if ($config['itemsProcFunc']) $selItems = $this->procItems($selItems,$fieldTSConfig['itemsProcFunc.'],$config,$table,$row,$field);
00901                 return $selItems;
00902         }
00903 
00913         function addItems($items,$iArray)       {
00914                 if (is_array($iArray))  {
00915                         foreach($iArray as $value => $label)    {
00916                                 $items[]=array($label,$value);
00917                         }
00918                 }
00919                 return $items;
00920         }
00921 
00935         function procItems($items,$itemsProcFuncTSconfig,$config,$table,$row,$field)    {
00936                 $params=array();
00937                 $params['items'] = &$items;
00938                 $params['config'] = $config;
00939                 $params['TSconfig'] = $itemsProcFuncTSconfig;
00940                 $params['table'] = $table;
00941                 $params['row'] = $row;
00942                 $params['field'] = $field;
00943 
00944                 t3lib_div::callUserFunction($config['itemsProcFunc'],$params,$this);
00945                 return $items;
00946         }
00947 
00948 
00949 
00950 
00951 
00952 
00953 
00954 
00955 
00956         /***********************************************
00957          *
00958          * Helper functions
00959          *
00960          ***********************************************/
00961 
00970         function lockRecord($table, $id, $pid=0)        {
00971                 if ($this->lockRecords) {
00972                         t3lib_BEfunc::lockRecords($table,$id,$pid);
00973                 }
00974         }
00975 
00987         function regItem($table, $id, $field, $content) {
00988         }
00989 
00997         function sL($in)        {
00998                 return $GLOBALS['LANG']->sL($in);
00999         }
01000 }
01001 
01002 
01003 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_transferdata.php'])      {
01004         include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_transferdata.php']);
01005 }
01006 ?>


Généré par Les experts TYPO3 avec  doxygen 1.4.6