Documentation TYPO3 par Ameos

class.t3lib_tcemain.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 ***************************************************************/
00195 // *******************************
00196 // Including necessary libraries
00197 // *******************************
00198 require_once (PATH_t3lib.'class.t3lib_loaddbgroup.php');
00199 require_once (PATH_t3lib.'class.t3lib_parsehtml_proc.php');
00200 require_once (PATH_t3lib.'class.t3lib_stdgraphic.php');
00201 require_once (PATH_t3lib.'class.t3lib_basicfilefunc.php');
00202 require_once (PATH_t3lib.'class.t3lib_refindex.php');
00203 require_once (PATH_t3lib.'class.t3lib_flexformtools.php');
00204 
00205 
00206 
00207 
00208 
00209 
00210 
00211 
00212 
00213 
00214 
00229 class t3lib_TCEmain     {
00230 
00231 
00232                 // *********************
00233                 // Public variables you can configure before using the class:
00234                 // *********************
00235 
00236         var $storeLogMessages = TRUE;                   // Boolean: If true, the default log-messages will be stored. This should not be necessary if the locallang-file for the log-display is properly configured. So disabling this will just save some database-space as the default messages are not saved.
00237         var $enableLogging = TRUE;                              // Boolean: If true, actions are logged to sys_log.
00238         var $reverseOrder = FALSE;                              // Boolean: If true, the datamap array is reversed in the order, which is a nice thing if you're creating a whole new bunch of records.
00239         var $checkSimilar = TRUE;                               // Boolean: If true, only fields which are different from the database values are saved! In fact, if a whole input array is similar, it's not saved then.
00240         var $stripslashes_values = TRUE;                // Boolean: If true, incoming values in the data-array have their slashes stripped. ALWAYS SET THIS TO ZERO and supply an unescaped data array instead. This switch may totally disappear in future versions of this class!
00241         var $checkStoredRecords = TRUE;                 // Boolean: This will read the record after having updated or inserted it. If anything is not properly submitted an error is written to the log. This feature consumes extra time by selecting records
00242         var $checkStoredRecords_loose = TRUE;   // Boolean: If set, values '' and 0 will equal each other when the stored records are checked.
00243         var $deleteTree = FALSE;                                // Boolean. If this is set, then a page is deleted by deleting the whole branch under it (user must have deletepermissions to it all). If not set, then the page is deleted ONLY if it has no branch
00244         var $neverHideAtCopy = FALSE;                   // Boolean. If set, then the 'hideAtCopy' flag for tables will be ignored.
00245         var $dontProcessTransformations = FALSE;        // Boolean: If set, then transformations are NOT performed on the input.
00246         var $bypassWorkspaceRestrictions = FALSE;       // Boolean: If true, workspace restrictions are bypassed on edit an create actions (process_datamap()). YOU MUST KNOW what you do if you use this feature!
00247 
00248         var $copyWhichTables = '*';                             // String. Comma-list. This list of tables decides which tables will be copied. If empty then none will. If '*' then all will (that the user has permission to of course)
00249         var $generalComment = '';                               // General comment, eg. for staging in workspaces.
00250 
00251         var $copyTree = 0;                                              // Integer. If 0 then branch is NOT copied. If 1 then pages on the 1st level is copied. If 2 then pages on the second level is copied ... and so on
00252 
00253         var $defaultValues = array();                   // Array [table][fields]=value: New records are created with default values and you can set this array on the form $defaultValues[$table][$field] = $value to override the default values fetched from TCA. If ->setDefaultsFromUserTS is called UserTSconfig default values will overrule existing values in this array (thus UserTSconfig overrules externally set defaults which overrules TCA defaults)
00254         var $overrideValues = array();                  // Array [table][fields]=value: You can set this array on the form $overrideValues[$table][$field] = $value to override the incoming data. You must set this externally. You must make sure the fields in this array are also found in the table, because it's not checked. All columns can be set by this array!
00255         var $alternativeFileName = array();             // Array [filename]=alternative_filename: Use this array to force another name onto a file. Eg. if you set ['/tmp/blablabal'] = 'my_file.txt' and '/tmp/blablabal' is set for a certain file-field, then 'my_file.txt' will be used as the name instead.
00256         var $data_disableFields=array();                // If entries are set in this array corresponding to fields for update, they are ignored and thus NOT updated. You could set this array from a series of checkboxes with value=0 and hidden fields before the checkbox with 1. Then an empty checkbox will disable the field.
00257         var $suggestedInsertUids=array();               // Use this array to validate suggested uids for tables by setting [table]:[uid]. This is a dangerous option since it will force the inserted record to have a certain UID. The value just have to be true, but if you set it to "DELETE" it will make sure any record with that UID will be deleted first (raw delete). The option is used for import of T3D files when synchronizing between two mirrored servers. As a security measure this feature is available only for Admin Users (for now)
00258 
00259         var $callBackObj;                                               // Object. Call back object for flex form traversation. Useful when external classes wants to use the iteration functions inside tcemain for traversing a FlexForm structure.
00260 
00261 
00262 
00263 
00264                 // *********************
00265                 // Internal variables (mapping arrays) which can be used (read-only) from outside
00266                 // *********************
00267         var $autoVersionIdMap = Array();                        // Contains mapping of auto-versionized records.
00268         var $substNEWwithIDs = Array();                         // When new elements are created, this array contains a map between their "NEW..." string IDs and the eventual UID they got when stored in database
00269         var $substNEWwithIDs_table = Array();           // Like $substNEWwithIDs, but where each old "NEW..." id is mapped to the table it was from.
00270         var $copyMappingArray_merged = Array();         // This array is the sum of all copying operations in this class. May be READ from outside, thus partly public.
00271         var $copiedFileMap = Array();                           // A map between input file name and final destination for files being attached to records.
00272         var     $errorLog = Array();                                    // Errors are collected in this variable.
00273 
00274 
00275 
00276                 // *********************
00277                 // Internal Variables, do not touch.
00278                 // *********************
00279 
00280                 // Variables set in init() function:
00281         var $BE_USER;           // The user-object the script uses. If not set from outside, this is set to the current global $BE_USER.
00282         var $userid;            // will be set to uid of be_user executing this script
00283         var $username;          // will be set to username of be_user executing this script
00284         var $admin;                     // will be set if user is admin
00285 
00286         var $defaultPermissions = array(                // Can be overridden from $TYPO3_CONF_VARS
00287                 'user' => 'show,edit,delete,new,editcontent',
00288                 'group' => 'show,edit,new,editcontent',
00289                 'everybody' => ''
00290         );
00291 
00292         var $exclude_array;                     // The list of <table>-<fields> that cannot be edited by user. This is compiled from TCA/exclude-flag combined with non_exclude_fields for the user.
00293         var $datamap = Array();         // Set with incoming data array
00294         var $cmdmap = Array();          // Set with incoming cmd array
00295 
00296                 // Internal static:
00297         var $pMap = Array(              // Permission mapping
00298                 'show' => 1,                    // 1st bit
00299                 'edit' => 2,                    // 2nd bit
00300                 'delete' => 4,                  // 3rd bit
00301                 'new' => 8,                             // 4th bit
00302                 'editcontent' => 16             // 5th bit
00303         );
00304         var $sortIntervals = 256;                                       // Integer: The interval between sorting numbers used with tables with a 'sorting' field defined. Min 1
00305 
00306                 // Internal caching arrays
00307         var $recUpdateAccessCache = Array();            // Used by function checkRecordUpdateAccess() to store whether a record is updateable or not.
00308         var $recInsertAccessCache = Array();            // User by function checkRecordInsertAccess() to store whether a record can be inserted on a page id
00309         var $isRecordInWebMount_Cache=array();          // Caching array for check of whether records are in a webmount
00310         var $isInWebMount_Cache=array();                        // Caching array for page ids in webmounts
00311         var $cachedTSconfig = array();                          // Caching for collecting TSconfig for page ids
00312         var $pageCache = Array();                                       // Used for caching page records in pageInfo()
00313         var $checkWorkspaceCache = Array();                     // Array caching workspace access for BE_USER
00314 
00315                 // Other arrays:
00316         var $dbAnalysisStore=array();                           // For accumulation of MM relations that must be written after new records are created.
00317         var $removeFilesStore=array();                          // For accumulation of files which must be deleted after processing of all input content
00318         var $uploadedFileArray = array();                       // Uploaded files, set by process_uploads()
00319         var $registerDBList=array();                            // Used for tracking references that might need correction after operations
00320         var $copyMappingArray = Array();                        // Used by the copy action to track the ids of new pages so subpages are correctly inserted! THIS is internally cleared for each executed copy operation! DO NOT USE THIS FROM OUTSIDE! Read from copyMappingArray_merged instead which is accumulating this information.
00321 
00322                 // Various
00323         var $fileFunc;                                                          // For "singleTon" file-manipulation object
00324         var $checkValue_currentRecord=array();          // Set to "currentRecord" during checking of values.
00325         var $autoVersioningUpdate = FALSE;                      // A signal flag used to tell file processing that autoversioning has happend and hence certain action should be applied.
00326 
00327 
00328 
00329 
00330 
00331 
00332 
00333 
00334 
00335 
00336 
00337 
00348         function start($data,$cmd,$altUserObject='')    {
00349 
00350                         // Initializing BE_USER
00351                 $this->BE_USER = is_object($altUserObject) ? $altUserObject : $GLOBALS['BE_USER'];
00352                 $this->userid = $this->BE_USER->user['uid'];
00353                 $this->username = $this->BE_USER->user['username'];
00354                 $this->admin = $this->BE_USER->user['admin'];
00355 
00356                 if ($GLOBALS['BE_USER']->uc['recursiveDelete'])    {
00357                         $this->deleteTree = 1;
00358                 }
00359 
00360                         // Initializing default permissions for pages
00361                 $defaultPermissions = $GLOBALS['TYPO3_CONF_VARS']['BE']['defaultPermissions'];
00362                 if (isset($defaultPermissions['user']))         {$this->defaultPermissions['user'] = $defaultPermissions['user'];}
00363                 if (isset($defaultPermissions['group']))                {$this->defaultPermissions['group'] = $defaultPermissions['group'];}
00364                 if (isset($defaultPermissions['everybody']))            {$this->defaultPermissions['everybody'] = $defaultPermissions['everybody'];}
00365 
00366                         // generates the excludelist, based on TCA/exclude-flag and non_exclude_fields for the user:
00367                 $this->exclude_array = $this->admin ? array() : $this->getExcludeListArray();
00368 
00369                         // Setting the data and cmd arrays
00370                 if (is_array($data)) {
00371                         reset($data);
00372                         $this->datamap = $data;
00373                 }
00374                 if (is_array($cmd))     {
00375                         reset($cmd);
00376                         $this->cmdmap = $cmd;
00377                 }
00378         }
00379 
00387         function setMirror($mirror)     {
00388                 if (is_array($mirror))  {
00389                         reset($mirror);
00390                         while(list($table,$uid_array)=each($mirror))    {
00391                                 if (isset($this->datamap[$table]))      {
00392                                         reset($uid_array);
00393                                         while (list($id,$uidList) = each($uid_array))   {
00394                                                 if (isset($this->datamap[$table][$id])) {
00395                                                         $theIdsInArray = t3lib_div::trimExplode(',',$uidList,1);
00396                                                         while(list(,$copyToUid)=each($theIdsInArray))   {
00397                                                                 $this->datamap[$table][$copyToUid] = $this->datamap[$table][$id];
00398                                                         }
00399                                                 }
00400                                         }
00401                                 }
00402                         }
00403                 }
00404         }
00405 
00412         function setDefaultsFromUserTS($userTS) {
00413                 global $TCA;
00414                 if (is_array($userTS))  {
00415                         foreach($userTS as $k => $v)    {
00416                                 $k = substr($k,0,-1);
00417                                 if ($k && is_array($v) && isset($TCA[$k]))      {
00418                                         if (is_array($this->defaultValues[$k])) {
00419                                                 $this->defaultValues[$k] = array_merge($this->defaultValues[$k],$v);
00420                                         } else {
00421                                                 $this->defaultValues[$k] = $v;
00422                                         }
00423                                 }
00424                         }
00425                 }
00426         }
00427 
00435         function process_uploads($postFiles)    {
00436 
00437                 if (is_array($postFiles))       {
00438 
00439                                 // Editing frozen:
00440                         if ($this->BE_USER->workspace!==0 && $this->BE_USER->workspaceRec['freeze'])    {
00441                                 $this->newlog('All editing in this workspace has been frozen!',1);
00442                                 return FALSE;
00443                         }
00444 
00445                         reset($postFiles);
00446                         $subA = current($postFiles);
00447                         if (is_array($subA))    {
00448                                 if (is_array($subA['name']) && is_array($subA['type']) && is_array($subA['tmp_name']) && is_array($subA['size']))       {
00449                                                 // Initialize the uploadedFilesArray:
00450                                         $this->uploadedFileArray=array();
00451 
00452                                                 // For each entry:
00453                                         foreach($subA as $key => $values)       {
00454                                                 $this->process_uploads_traverseArray($this->uploadedFileArray,$values,$key);
00455                                         }
00456                                 } else {
00457                                         $this->uploadedFileArray=$subA;
00458                                 }
00459                         }
00460                 }
00461         }
00462 
00473         function process_uploads_traverseArray(&$outputArr,$inputArr,$keyToSet) {
00474                 if (is_array($inputArr))        {
00475                         foreach($inputArr as $key => $value)    {
00476                                 $this->process_uploads_traverseArray($outputArr[$key],$inputArr[$key],$keyToSet);
00477                         }
00478                 } else {
00479                         $outputArr[$keyToSet]=$inputArr;
00480                 }
00481         }
00482 
00483 
00484 
00485 
00486 
00487 
00488 
00489 
00490 
00491 
00492 
00493 
00494 
00495 
00496 
00497         /*********************************************
00498          *
00499          * PROCESSING DATA
00500          *
00501          *********************************************/
00502 
00509         function process_datamap() {
00510                 global $TCA, $TYPO3_CONF_VARS;
00511 
00512                         // Editing frozen:
00513                 if ($this->BE_USER->workspace!==0 && $this->BE_USER->workspaceRec['freeze'])    {
00514                         $this->newlog('All editing in this workspace has been frozen!',1);
00515                         return FALSE;
00516                 }
00517 
00518                         // First prepare user defined objects (if any) for hooks which extend this function:
00519                 $hookObjectsArr = array();
00520                 if (is_array ($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processDatamapClass'])) {
00521                         foreach ($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processDatamapClass'] as $classRef) {
00522                                 $hookObjectsArr[] = &t3lib_div::getUserObj($classRef);
00523                         }
00524                 }
00525 
00526                         // Organize tables so that the pages-table is always processed first. This is required if you want to make sure that content pointing to a new page will be created.
00527                 $orderOfTables = Array();
00528                 if (isset($this->datamap['pages']))     {               // Set pages first.
00529                         $orderOfTables[]='pages';
00530                 }
00531                 reset($this->datamap);
00532                 while (list($table,) = each($this->datamap))    {
00533                         if ($table!='pages')    {
00534                                 $orderOfTables[]=$table;
00535                         }
00536                 }
00537 
00538                         // Process the tables...
00539                 foreach($orderOfTables as $table)       {
00540                                 /* Check if
00541                                         - table is set in $TCA,
00542                                         - table is NOT readOnly
00543                                         - the table is set with content in the data-array (if not, there's nothing to process...)
00544                                         - permissions for tableaccess OK
00545                                 */
00546                         $modifyAccessList = $this->checkModifyAccessList($table);
00547                         if (!$modifyAccessList) {
00548                                 $id = 0;
00549                                 $this->log($table,$id,2,0,1,"Attempt to modify table '%s' without permission",1,array($table));
00550                         }
00551                         if (isset($TCA[$table]) && !$this->tableReadOnly($table) && is_array($this->datamap[$table]) && $modifyAccessList)      {
00552                                 if ($this->reverseOrder)        {
00553                                         $this->datamap[$table] = array_reverse($this->datamap[$table], 1);
00554                                 }
00555 
00556                                         // For each record from the table, do:
00557                                         // $id is the record uid, may be a string if new records...
00558                                         // $incomingFieldArray is the array of fields
00559                                 foreach($this->datamap[$table] as $id => $incomingFieldArray)   {
00560                                         if (is_array($incomingFieldArray))      {
00561 
00562                                                         // Hook: processDatamap_preProcessIncomingFieldArray
00563                                                 foreach($hookObjectsArr as $hookObj)    {
00564                                                         if (method_exists($hookObj, 'processDatamap_preProcessFieldArray')) {
00565                                                                 $hookObj->processDatamap_preProcessFieldArray($incomingFieldArray, $table, $id, $this);
00566                                                         }
00567                                                 }
00568 
00569                                                         // ******************************
00570                                                         // Checking access to the record
00571                                                         // ******************************
00572                                                 $createNewVersion = FALSE;
00573                                                 $recordAccess = FALSE;
00574                                                 $old_pid_value = '';
00575                                                 $resetRejected = FALSE;
00576                                                 $this->autoVersioningUpdate = FALSE;
00577 
00578                                                 if (!t3lib_div::testInt($id)) {               // Is it a new record? (Then Id is a string)
00579                                                         $fieldArray = $this->newFieldArray($table);     // Get a fieldArray with default values
00580                                                         if (isset($incomingFieldArray['pid']))  {       // A pid must be set for new records.
00581                                                                         // $value = the pid
00582                                                                 $pid_value = $incomingFieldArray['pid'];
00583 
00584                                                                         // Checking and finding numerical pid, it may be a string-reference to another value
00585                                                                 $OK = 1;
00586                                                                 if (strstr($pid_value,'NEW'))   {       // If a NEW... id
00587                                                                         if (substr($pid_value,0,1)=='-') {$negFlag=-1;$pid_value=substr($pid_value,1);} else {$negFlag=1;}
00588                                                                         if (isset($this->substNEWwithIDs[$pid_value]))  {       // Trying to find the correct numerical value as it should be mapped by earlier processing of another new record.
00589                                                                                 $old_pid_value = $pid_value;
00590                                                                                 $pid_value=intval($negFlag*$this->substNEWwithIDs[$pid_value]);
00591                                                                         } else {$OK = 0;}       // If not found in the substArray we must stop the process...
00592                                                                 } elseif ($pid_value>=0 && $this->BE_USER->workspace!==0 && $TCA[$table]['ctrl']['versioning_followPages'])     {       // PID points to page, the workspace is an offline space and the table follows page during versioning: This means we must check if the PID page has a version in the workspace with swapmode set to 0 (zero = page+content) and if so, change the pid to the uid of that version.
00593                                                                         if ($WSdestPage = t3lib_BEfunc::getWorkspaceVersionOfRecord($this->BE_USER->workspace, 'pages', $pid_value, 'uid,t3ver_swapmode'))      {       // Looks for workspace version of page.
00594                                                                                 if ($WSdestPage['t3ver_swapmode']==0)   {       // if swapmode is zero, then change pid value.
00595                                                                                         $pid_value = $WSdestPage['uid'];
00596                                                                                 }
00597                                                                         }
00598                                                                 }
00599                                                                 $pid_value = intval($pid_value);
00600 
00601                                                                         // The $pid_value is now the numerical pid at this point
00602                                                                 if ($OK)        {
00603                                                                         $sortRow = $TCA[$table]['ctrl']['sortby'];
00604                                                                         if ($pid_value>=0)      {       // Points to a page on which to insert the element, possibly in the top of the page
00605                                                                                 if ($sortRow)   {       // If this table is sorted we better find the top sorting number
00606                                                                                         $fieldArray[$sortRow] = $this->getSortNumber($table,0,$pid_value);
00607                                                                                 }
00608                                                                                 $fieldArray['pid'] = $pid_value;        // The numerical pid is inserted in the data array
00609                                                                         } else {        // points to another record before ifself
00610                                                                                 if ($sortRow)   {       // If this table is sorted we better find the top sorting number
00611                                                                                         $tempArray=$this->getSortNumber($table,0,$pid_value);   // Because $pid_value is < 0, getSortNumber returns an array
00612                                                                                         $fieldArray['pid'] = $tempArray['pid'];
00613                                                                                         $fieldArray[$sortRow] = $tempArray['sortNumber'];
00614                                                                                 } else {        // Here we fetch the PID of the record that we point to...
00615                                                                                         $tempdata = $this->recordInfo($table,abs($pid_value),'pid');
00616                                                                                         $fieldArray['pid']=$tempdata['pid'];
00617                                                                                 }
00618                                                                         }
00619                                                                 }
00620                                                         }
00621                                                         $theRealPid = $fieldArray['pid'];
00622 
00623                                                                 // Now, check if we may insert records on this pid.
00624                                                         if ($theRealPid>=0)     {
00625                                                                 $recordAccess = $this->checkRecordInsertAccess($table,$theRealPid);             // Checks if records can be inserted on this $pid.
00626                                                                 if ($recordAccess)      {
00627                                                                         $this->addDefaultPermittedLanguageIfNotSet($table,$incomingFieldArray);
00628                                                                         $recordAccess = $this->BE_USER->recordEditAccessInternals($table,$incomingFieldArray,TRUE);
00629                                                                         if (!$recordAccess)             {
00630                                                                                 $this->newlog("recordEditAccessInternals() check failed. [".$this->BE_USER->errorMsg."]",1);
00631                                                                         } elseif(!$this->bypassWorkspaceRestrictions)   {
00632                                                                                         // Workspace related processing:
00633                                                                                 if ($res = $this->BE_USER->workspaceAllowLiveRecordsInPID($theRealPid,$table))  {       // If LIVE records cannot be created in the current PID due to workspace restrictions, prepare creation of placeholder-record
00634                                                                                         if ($res<0)     {
00635                                                                                                 $recordAccess = FALSE;
00636                                                                                                 $this->newlog('Stage for versioning root point and users access level did not allow for editing',1);
00637                                                                                         }
00638                                                                                 } else {        // So, if no live records were allowed, we have to create a new version of this record:
00639                                                                                         if ($TCA[$table]['ctrl']['versioningWS'])       {
00640                                                                                                 $createNewVersion = TRUE;
00641                                                                                         } else {
00642                                                                                                 $recordAccess = FALSE;
00643                                                                                                 $this->newlog('Record could not be created in this workspace in this branch',1);
00644                                                                                         }
00645                                                                                 }
00646                                                                         }
00647                                                                 }
00648                                                         } else {
00649                                                                 debug('Internal ERROR: pid should not be less than zero!');
00650                                                         }
00651                                                         $status = 'new';                                                // Yes new record, change $record_status to 'insert'
00652                                                 } else {        // Nope... $id is a number
00653                                                         $fieldArray = array();
00654                                                         $recordAccess = $this->checkRecordUpdateAccess($table,$id);
00655                                                         if (!$recordAccess)             {
00656                                                                 $propArr = $this->getRecordProperties($table,$id);
00657                                                                 $this->log($table,$id,2,0,1,"Attempt to modify record '%s' (%s) without permission. Or non-existing page.",2,array($propArr['header'],$table.':'.$id),$propArr['event_pid']);
00658                                                         } else {        // Next check of the record permissions (internals)
00659                                                                 $recordAccess = $this->BE_USER->recordEditAccessInternals($table,$id);
00660                                                                 if (!$recordAccess)             {
00661                                                                         $propArr = $this->getRecordProperties($table,$id);
00662                                                                         $this->newlog("recordEditAccessInternals() check failed. [".$this->BE_USER->errorMsg."]",1);
00663                                                                 } else {        // Here we fetch the PID of the record that we point to...
00664                                                                         $tempdata = $this->recordInfo($table,$id,'pid'.($TCA[$table]['ctrl']['versioningWS']?',t3ver_wsid,t3ver_stage':''));
00665                                                                         $theRealPid = $tempdata['pid'];
00666 
00667                                                                                 // Prepare the reset of the rejected flag if set:
00668                                                                         if ($TCA[$table]['ctrl']['versioningWS'] && $tempdata['t3ver_stage']<0) {
00669                                                                                 $resetRejected = TRUE;
00670                                                                         }
00671 
00672                                                                                 // Checking access in case of offline workspace:
00673                                                                         if (!$this->bypassWorkspaceRestrictions && $errorCode = $this->BE_USER->workspaceCannotEditRecord($table,$tempdata))    {
00674                                                                                 $recordAccess = FALSE;          // Versioning is required and it must be offline version!
00675 
00676                                                                                         // Auto-creation of version: In offline workspace, test if versioning is enabled and look for workspace version of input record. If there is no versionized record found we will create one and save to that.
00677                                                                                 if ($this->BE_USER->workspaceAllowAutoCreation($table,$id,$theRealPid)) {
00678                                                                                         $tce = t3lib_div::makeInstance('t3lib_TCEmain');
00679                                                                                         $tce->stripslashes_values = 0;
00680 
00681                                                                                                 // Setting up command for creating a new version of the record:
00682                                                                                         $cmd = array();
00683                                                                                         $cmd[$table][$id]['version'] = array(
00684                                                                                                 'action' => 'new',
00685                                                                                                 'treeLevels' => -1,     // Default is to create a version of the individual records...
00686                                                                                                 'label' => 'Auto-created for WS #'.$this->BE_USER->workspace
00687                                                                                         );
00688                                                                                         $tce->start(array(),$cmd);
00689                                                                                         $tce->process_cmdmap();
00690                                                                                         $this->errorLog = array_merge($this->errorLog,$tce->errorLog);
00691 
00692                                                                                         if ($tce->copyMappingArray[$table][$id])        {
00693                                                                                                 $this->uploadedFileArray[$table][$tce->copyMappingArray[$table][$id]] = $this->uploadedFileArray[$table][$id];
00694                                                                                                 $id = $this->autoVersionIdMap[$table][$id] = $tce->copyMappingArray[$table][$id];
00695                                                                                                 $recordAccess = TRUE;
00696                                                                                                 $this->autoVersioningUpdate = TRUE;
00697                                                                                         } else $this->newlog("Could not be edited in offline workspace in the branch where found (failure state: '".$errorCode."'). Auto-creation of version failed!",1);
00698                                                                                 } else $this->newlog("Could not be edited in offline workspace in the branch where found (failure state: '".$errorCode."'). Auto-creation of version not allowed in workspace!",1);
00699                                                                         }
00700                                                                 }
00701                                                         }
00702                                                         $status = 'update';     // the default is 'update'
00703                                                 }
00704 
00705                                                         // If access was granted above, proceed to create or update record:
00706                                                 if ($recordAccess)      {
00707 
00708                                                         list($tscPID) = t3lib_BEfunc::getTSCpid($table,$id,$old_pid_value ? $old_pid_value : $fieldArray['pid']);       // Here the "pid" is set IF NOT the old pid was a string pointing to a place in the subst-id array.
00709                                                         $TSConfig = $this->getTCEMAIN_TSconfig($tscPID);
00710                                                         if ($status=='new' && $table=='pages' && is_array($TSConfig['permissions.']))   {
00711                                                                 $fieldArray = $this->setTSconfigPermissions($fieldArray,$TSConfig['permissions.']);
00712                                                         }
00713                                                         if ($createNewVersion)  {
00714                                                                 $newVersion_placeholderFieldArray = $fieldArray;
00715                                                         }
00716 
00717                                                                 // Processing of all fields in incomingFieldArray and setting them in $fieldArray
00718                                                         $fieldArray = $this->fillInFieldArray($table,$id,$fieldArray,$incomingFieldArray,$theRealPid,$status,$tscPID);
00719 
00720                                                                 // NOTICE! All manipulation beyond this point bypasses both "excludeFields" AND possible "MM" relations / file uploads to field!
00721 
00722                                                                 // Forcing some values unto field array:
00723                                                         $fieldArray = $this->overrideFieldArray($table,$fieldArray);    // NOTICE: This overriding is potentially dangerous; permissions per field is not checked!!!
00724                                                         if ($createNewVersion)  {
00725                                                                 $newVersion_placeholderFieldArray = $this->overrideFieldArray($table,$newVersion_placeholderFieldArray);
00726                                                         }
00727 
00728                                                                 // Setting system fields
00729                                                         if ($status=='new')     {
00730                                                                 if ($TCA[$table]['ctrl']['crdate'])     {
00731                                                                         $fieldArray[$TCA[$table]['ctrl']['crdate']]=time();
00732                                                                         if ($createNewVersion)  $newVersion_placeholderFieldArray[$TCA[$table]['ctrl']['crdate']]=time();
00733                                                                 }
00734                                                                 if ($TCA[$table]['ctrl']['cruser_id'])  {
00735                                                                         $fieldArray[$TCA[$table]['ctrl']['cruser_id']]=$this->userid;
00736                                                                         if ($createNewVersion)  $newVersion_placeholderFieldArray[$TCA[$table]['ctrl']['cruser_id']]=$this->userid;
00737                                                                 }
00738                                                         } elseif ($this->checkSimilar) {        // Removing fields which are equal to the current value:
00739                                                                 $fieldArray = $this->compareFieldArrayWithCurrentAndUnset($table,$id,$fieldArray);
00740                                                         }
00741                                                         if ($TCA[$table]['ctrl']['tstamp'] && count($fieldArray))       {
00742                                                                 $fieldArray[$TCA[$table]['ctrl']['tstamp']]=time();
00743                                                                 if ($createNewVersion)  $newVersion_placeholderFieldArray[$TCA[$table]['ctrl']['tstamp']]=time();
00744                                                         }
00745                                                         if ($resetRejected)     {
00746                                                                 $fieldArray['t3ver_stage'] = 0;
00747                                                         }
00748 
00749                                                                 // Hook: processDatamap_postProcessFieldArray
00750                                                         foreach($hookObjectsArr as $hookObj)    {
00751                                                                 if (method_exists($hookObj, 'processDatamap_postProcessFieldArray')) {
00752                                                                         $hookObj->processDatamap_postProcessFieldArray($status, $table, $id, $fieldArray, $this);
00753                                                                 }
00754                                                         }
00755 
00756                                                                 // Performing insert/update. If fieldArray has been unset by some userfunction (see hook above), don't do anything
00757                                                                 // Kasper: Unsetting the fieldArray is dangerous; MM relations might be saved already and files could have been uploaded that are now "lost"
00758                                                         if (is_array($fieldArray)) {
00759                                                                 if ($status=='new')     {
00760                                                                         if ($createNewVersion)  {       // This creates a new version of the record with online placeholder and offline version
00761                                                                                 $versioningType = $table==='pages' ? $this->BE_USER->workspaceVersioningTypeGetClosest(t3lib_div::intInRange($TYPO3_CONF_VARS['BE']['newPagesVersioningType'],-1,1)) : -1;
00762                                                                                 if ($this->BE_USER->workspaceVersioningTypeAccess($versioningType))     {
00763                                                                                         $newVersion_placeholderFieldArray['t3ver_label'] = 'INITIAL PLACEHOLDER';
00764                                                                                         $newVersion_placeholderFieldArray['t3ver_state'] = 1;   // Setting placeholder state value for temporary record
00765                                                                                         $newVersion_placeholderFieldArray['t3ver_wsid'] = $this->BE_USER->workspace;    // Setting workspace - only so display of place holders can filter out those from other workspaces.
00766                                                                                         $newVersion_placeholderFieldArray[$TCA[$table]['ctrl']['label']] = '[PLACEHOLDER, WS#'.$this->BE_USER->workspace.']';
00767                                                                                         $this->insertDB($table,$id,$newVersion_placeholderFieldArray,FALSE);    // Saving placeholder as 'original'
00768 
00769                                                                                                 // For the actual new offline version, set versioning values to point to placeholder:
00770                                                                                         $fieldArray['pid'] = -1;
00771                                                                                         $fieldArray['t3ver_oid'] = $this->substNEWwithIDs[$id];
00772                                                                                         $fieldArray['t3ver_id'] = 1;
00773                                                                                         $fieldArray['t3ver_state'] = -1;        // Setting placeholder state value for version (so it can know it is currently a new version...)
00774                                                                                         $fieldArray['t3ver_label'] = 'First draft version';
00775                                                                                         $fieldArray['t3ver_wsid'] = $this->BE_USER->workspace;
00776                                                                                         if ($table==='pages') {         // Swap mode set to "branch" so we can build branches for pages.
00777                                                                                                 $fieldArray['t3ver_swapmode'] = $versioningType;
00778                                                                                         }
00779                                                                                         $phShadowId = $this->insertDB($table,$id,$fieldArray,TRUE,0,TRUE);      // When inserted, $this->substNEWwithIDs[$id] will be changed to the uid of THIS version and so the interface will pick it up just nice!
00780                                                                                         if ($phShadowId)        {
00781                                                                                                 $this->placeholderShadowing($table,$phShadowId);
00782                                                                                         }
00783                                                                                 } else $this->newlog('Versioning type "'.$versioningType.'" was not allowed, so could not create new record.',1);
00784                                                                         } else {
00785                                                                                 $this->insertDB($table,$id,$fieldArray,FALSE,$incomingFieldArray['uid']);
00786                                                                         }
00787                                                                 } else {
00788                                                                         $this->updateDB($table,$id,$fieldArray);
00789                                                                         $this->placeholderShadowing($table,$id);
00790                                                                 }
00791                                                         }
00792 
00793                                                                 // Hook: processDatamap_afterDatabaseOperations
00794                                                         foreach($hookObjectsArr as $hookObj)    {
00795                                                                 if (method_exists($hookObj, 'processDatamap_afterDatabaseOperations')) {
00796                                                                         $hookObj->processDatamap_afterDatabaseOperations($status, $table, $id, $fieldArray, $this);
00797                                                                 }
00798                                                         }
00799                                                 }       // if ($recordAccess)   {
00800                                         }       // if (is_array($incomingFieldArray))   {
00801                                 }
00802                         }
00803                 }
00804                 $this->dbAnalysisStoreExec();
00805                 $this->removeRegisteredFiles();
00806         }
00807 
00815         function placeholderShadowing($table,$id)       {
00816                 global $TCA;
00817 
00818                 if ($liveRec = t3lib_BEfunc::getLiveVersionOfRecord($table,$id,'*'))    {
00819                         if ((int)$liveRec['t3ver_state']===1)   {
00820                                 $justStoredRecord = t3lib_BEfunc::getRecord($table,$id);
00821                                 $newRecord = array();
00822 
00823                                 $shadowColumns = t3lib_div::trimExplode(',', $TCA[$table]['ctrl']['shadowColumnsForNewPlaceholders'],1);
00824                                 foreach($shadowColumns as $fieldName)   {
00825                                         if (strcmp($justStoredRecord[$fieldName],$liveRec[$fieldName])) {
00826                                                 $newRecord[$fieldName] = $justStoredRecord[$fieldName];
00827                                         }
00828                                 }
00829 
00830                                 if (count($newRecord))  {
00831                                         $this->newlog('Shadowing done on fields '.implode(',',array_keys($newRecord)).' in Placeholder record '.$table.':'.$liveRec['uid'].' (offline version UID='.$id.')');
00832                                         $this->updateDB($table,$liveRec['uid'],$newRecord);
00833                                 }
00834                         }
00835                 }
00836         }
00837 
00851         function fillInFieldArray($table,$id,$fieldArray,$incomingFieldArray,$realPid,$status,$tscPID)  {
00852                 global $TCA;
00853 
00854                         // Initialize:
00855                 t3lib_div::loadTCA($table);
00856                 $originalLanguageRecord = NULL;
00857                 $originalLanguage_diffStorage = NULL;
00858                 $diffStorageFlag = FALSE;
00859 
00860                         // Setting 'currentRecord' and 'checkValueRecord':
00861                 if (strstr($id,'NEW'))  {
00862                         $currentRecord = $checkValueRecord = $fieldArray;       // must have the 'current' array - not the values after processing below...
00863 
00864                                 // IF $incomingFieldArray is an array, overlay it.
00865                                 // The point is that when new records are created as copies with flex type fields there might be a field containing information about which DataStructure to use and without that information the flexforms cannot be correctly processed.... This should be OK since the $checkValueRecord is used by the flexform evaluation only anyways...
00866                         if (is_array($incomingFieldArray) && is_array($checkValueRecord))       {
00867                                 $checkValueRecord = t3lib_div::array_merge_recursive_overrule($checkValueRecord, $incomingFieldArray);
00868                         }
00869                 } else {
00870                         $currentRecord = $checkValueRecord = $this->recordInfo($table,$id,'*'); // We must use the current values as basis for this!
00871 
00872                                 // Get original language record if available:
00873                         if (is_array($currentRecord)
00874                                         && $TCA[$table]['ctrl']['transOrigDiffSourceField']
00875                                         && $TCA[$table]['ctrl']['languageField']
00876                                         && $currentRecord[$TCA[$table]['ctrl']['languageField']] > 0
00877                                         && $TCA[$table]['ctrl']['transOrigPointerField']
00878                                         && intval($currentRecord[$TCA[$table]['ctrl']['transOrigPointerField']]) > 0)   {
00879 
00880                                 $lookUpTable = $TCA[$table]['ctrl']['transOrigPointerTable'] ? $TCA[$table]['ctrl']['transOrigPointerTable'] : $table;
00881                                 $originalLanguageRecord = $this->recordInfo($lookUpTable,$currentRecord[$TCA[$table]['ctrl']['transOrigPointerField']],'*');
00882                                 t3lib_BEfunc::workspaceOL($lookUpTable,$originalLanguageRecord);
00883                                 $originalLanguage_diffStorage = unserialize($currentRecord[$TCA[$table]['ctrl']['transOrigDiffSourceField']]);
00884                         }
00885                 }
00886                 $this->checkValue_currentRecord = $checkValueRecord;
00887 
00888                         /*
00889                                 In the following all incoming value-fields are tested:
00890                                 - Are the user allowed to change the field?
00891                                 - Is the field uid/pid (which are already set)
00892                                 - perms-fields for pages-table, then do special things...
00893                                 - If the field is nothing of the above and the field is configured in TCA, the fieldvalues are evaluated by ->checkValue
00894 
00895                                 If everything is OK, the field is entered into $fieldArray[]
00896                         */
00897                 foreach($incomingFieldArray as $field => $fieldValue)   {
00898                         if (!in_array($table.'-'.$field, $this->exclude_array) && !$this->data_disableFields[$table][$id][$field])      {       // The field must be editable.
00899 
00900                                         // Checking if a value for language can be changed:
00901                                 $languageDeny = $TCA[$table]['ctrl']['languageField'] && !strcmp($TCA[$table]['ctrl']['languageField'], $field) && !$this->BE_USER->checkLanguageAccess($fieldValue);
00902 
00903                                 if (!$languageDeny)     {
00904                                                 // Stripping slashes - will probably be removed the day $this->stripslashes_values is removed as an option...
00905                                         if ($this->stripslashes_values) {
00906                                                 if (is_array($fieldValue))      {
00907                                                         t3lib_div::stripSlashesOnArray($fieldValue);
00908                                                 } else $fieldValue = stripslashes($fieldValue);
00909                                         }
00910 
00911                                         switch ($field) {
00912                                                 case 'uid':
00913                                                 case 'pid':
00914                                                         // Nothing happens, already set
00915                                                 break;
00916                                                 case 'perms_userid':
00917                                                 case 'perms_groupid':
00918                                                 case 'perms_user':
00919                                                 case 'perms_group':
00920                                                 case 'perms_everybody':
00921                                                                 // Permissions can be edited by the owner or the administrator
00922                                                         if ($table=='pages' && ($this->admin || $status=='new' || $this->pageInfo($id,'perms_userid')==$this->userid) ) {
00923                                                                 $value=intval($fieldValue);
00924                                                                 switch($field)  {
00925                                                                         case 'perms_userid':
00926                                                                                 $fieldArray[$field]=$value;
00927                                                                         break;
00928                                                                         case 'perms_groupid':
00929                                                                                 $fieldArray[$field]=$value;
00930                                                                         break;
00931                                                                         default:
00932                                                                                 if ($value>=0 && $value<pow(2,5))       {
00933                                                                                         $fieldArray[$field]=$value;
00934                                                                                 }
00935                                                                         break;
00936                                                                 }
00937                                                         }
00938                                                 break;
00939                                                 case 't3ver_oid':
00940                                                 case 't3ver_id':
00941                                                 case 't3ver_wsid':
00942                                                 case 't3ver_state':
00943                                                 case 't3ver_swapmode':
00944                                                 case 't3ver_count':
00945                                                 case 't3ver_stage':
00946                                                 case 't3ver_tstamp':
00947                                                         // t3ver_label is not here because it CAN be edited as a regular field!
00948                                                 break;
00949                                                 default:
00950                                                         if (isset($TCA[$table]['columns'][$field]))     {
00951                                                                         // Evaluating the value.
00952                                                                 $res = $this->checkValue($table,$field,$fieldValue,$id,$status,$realPid,$tscPID);
00953                                                                 if (isset($res['value']))       {
00954                                                                         $fieldArray[$field]=$res['value'];
00955 
00956                                                                                 // Add the value of the original record to the diff-storage content:
00957                                                                         if ($TCA[$table]['ctrl']['transOrigDiffSourceField'])   {
00958                                                                                 $originalLanguage_diffStorage[$field] = $originalLanguageRecord[$field];
00959                                                                                 $diffStorageFlag = TRUE;
00960                                                                         }
00961                                                                 }
00962                                                         } elseif ($TCA[$table]['ctrl']['origUid']===$field) {   // Allow value for original UID to pass by...
00963                                                                 $fieldArray[$field] = $fieldValue;
00964                                                         }
00965                                                 break;
00966                                         }
00967                                 }       // Checking language.
00968                         }       // Check exclude fields / disabled fields...
00969                 }
00970 
00971                         // Add diff-storage information:
00972                 if ($diffStorageFlag && !isset($fieldArray[$TCA[$table]['ctrl']['transOrigDiffSourceField']]))  {       // If the field is set it would probably be because of an undo-operation - in which case we should not update the field of course...
00973                          $fieldArray[$TCA[$table]['ctrl']['transOrigDiffSourceField']] = serialize($originalLanguage_diffStorage);
00974                 }
00975 
00976                         // Checking for RTE-transformations of fields:
00977                 $types_fieldConfig = t3lib_BEfunc::getTCAtypes($table,$currentRecord);
00978                 $theTypeString = t3lib_BEfunc::getTCAtypeValue($table,$currentRecord);
00979                 if (is_array($types_fieldConfig))       {
00980                         reset($types_fieldConfig);
00981                         while(list(,$vconf) = each($types_fieldConfig)) {
00982                                         // Write file configuration:
00983                                 $eFile = t3lib_parsehtml_proc::evalWriteFile($vconf['spec']['static_write'],array_merge($currentRecord,$fieldArray));   // inserted array_merge($currentRecord,$fieldArray) 170502
00984 
00985                                         // RTE transformations:
00986                                 if (!$this->dontProcessTransformations) {
00987                                         if (isset($fieldArray[$vconf['field']]))        {
00988                                                         // Look for transformation flag:
00989                                                 switch((string)$incomingFieldArray['_TRANSFORM_'.$vconf['field']])      {
00990                                                         case 'RTE':
00991                                                                 $RTEsetup = $this->BE_USER->getTSConfig('RTE',t3lib_BEfunc::getPagesTSconfig($tscPID));
00992                                                                 $thisConfig = t3lib_BEfunc::RTEsetup($RTEsetup['properties'],$table,$vconf['field'],$theTypeString);
00993 
00994                                                                         // Set alternative relative path for RTE images/links:
00995                                                                 $RTErelPath = is_array($eFile) ? dirname($eFile['relEditFile']) : '';
00996 
00997                                                                         // Get RTE object, draw form and set flag:
00998                                                                 $RTEobj = &t3lib_BEfunc::RTEgetObj();
00999                                                                 if (is_object($RTEobj)) {
01000                                                                         $fieldArray[$vconf['field']] = $RTEobj->transformContent('db',$fieldArray[$vconf['field']],$table,$vconf['field'],$currentRecord,$vconf['spec'],$thisConfig,$RTErelPath,$currentRecord['pid']);
01001                                                                 } else {
01002                                                                         debug('NO RTE OBJECT FOUND!');
01003                                                                 }
01004                                                         break;
01005                                                 }
01006                                         }
01007                                 }
01008 
01009                                         // Write file configuration:
01010                                 if (is_array($eFile))   {
01011                                         $mixedRec = array_merge($currentRecord,$fieldArray);
01012                                         $SW_fileContent = t3lib_div::getUrl($eFile['editFile']);
01013                                         $parseHTML = t3lib_div::makeInstance('t3lib_parsehtml_proc');
01014                                         $parseHTML->init('','');
01015 
01016                                         $eFileMarker = $eFile['markerField']&&trim($mixedRec[$eFile['markerField']]) ? trim($mixedRec[$eFile['markerField']]) : '###TYPO3_STATICFILE_EDIT###';
01017                                         $insertContent = str_replace($eFileMarker,'',$mixedRec[$eFile['contentField']]);        // must replace the marker if present in content!
01018 
01019                                         $SW_fileNewContent = $parseHTML->substituteSubpart($SW_fileContent, $eFileMarker, chr(10).$insertContent.chr(10), 1, 1);
01020                                         t3lib_div::writeFile($eFile['editFile'],$SW_fileNewContent);
01021 
01022                                                 // Write status:
01023                                         if (!strstr($id,'NEW') && $eFile['statusField'])        {
01024                                                 $GLOBALS['TYPO3_DB']->exec_UPDATEquery(
01025                                                         $table,
01026                                                         'uid='.intval($id),
01027                                                         array(
01028                                                                 $eFile['statusField'] => $eFile['relEditFile'].' updated '.date('d-m-Y H:i:s').', bytes '.strlen($mixedRec[$eFile['contentField']])
01029                                                         )
01030                                                 );
01031                                         }
01032                                 } elseif ($eFile && is_string($eFile))  {
01033                                         $this->log($table,$id,2,0,1,"Write-file error: '%s'",13,array($eFile),$realPid);
01034                                 }
01035                         }
01036                 }
01037                         // Return fieldArray
01038                 return $fieldArray;
01039         }
01040 
01041 
01042 
01043 
01044 
01045 
01046 
01047 
01048 
01049 
01050 
01051 
01052         /*********************************************
01053          *
01054          * Evaluation of input values
01055          *
01056          ********************************************/
01057 
01072         function checkValue($table,$field,$value,$id,$status,$realPid,$tscPID)  {
01073                 global $TCA, $PAGES_TYPES;
01074                 t3lib_div::loadTCA($table);
01075 
01076                 $res = Array(); // result array
01077                 $recFID = $table.':'.$id.':'.$field;
01078 
01079                         // Processing special case of field pages.doktype
01080                 if ($table=='pages' && $field=='doktype')       {
01081                                 // If the user may not use this specific doktype, we issue a warning
01082                         if (! ($this->admin || t3lib_div::inList($this->BE_USER->groupData['pagetypes_select'],$value)))        {
01083                                 $propArr = $this->getRecordProperties($table,$id);
01084                                 $this->log($table,$id,5,0,1,"You cannot change the 'doktype' of page '%s' to the desired value.",1,array($propArr['header']),$propArr['event_pid']);
01085                                 return $res;
01086                         };
01087                         if ($status=='update')  {
01088                                         // This checks 1) if we should check for disallowed tables and 2) if there are records from disallowed tables on the current page
01089                                 $onlyAllowedTables = isset($PAGES_TYPES[$value]['onlyAllowedTables']) ? $PAGES_TYPES[$value]['onlyAllowedTables'] : $PAGES_TYPES['default']['onlyAllowedTables'];
01090                                 if ($onlyAllowedTables) {
01091                                         $theWrongTables = $this->doesPageHaveUnallowedTables($id,$value);
01092                                         if ($theWrongTables)    {
01093                                                 $propArr = $this->getRecordProperties($table,$id);
01094                                                 $this->log($table,$id,5,0,1,"'doktype' of page '%s' could not be changed because the page contains records from disallowed tables; %s",2,array($propArr['header'],$theWrongTables),$propArr['event_pid']);
01095                                                 return $res;
01096                                         }
01097                                 }
01098                         }
01099                 }
01100 
01101                         // Get current value:
01102                 $curValueRec = $this->recordInfo($table,$id,$field);
01103                 $curValue = $curValueRec[$field];
01104 
01105                         // Getting config for the field
01106                 $tcaFieldConf = $TCA[$table]['columns'][$field]['config'];
01107 
01108                         // Preform processing:
01109                 $res = $this->checkValue_SW($res,$value,$tcaFieldConf,$table,$id,$curValue,$status,$realPid,$recFID,$field,$this->uploadedFileArray[$table][$id][$field],$tscPID);
01110 
01111                 return $res;
01112         }
01113 
01132         function checkValue_SW($res,$value,$tcaFieldConf,$table,$id,$curValue,$status,$realPid,$recFID,$field,$uploadedFiles,$tscPID)   {
01133 
01134                 $PP = array($table,$id,$curValue,$status,$realPid,$recFID,$tscPID);
01135 
01136                 switch ($tcaFieldConf['type']) {
01137                         case 'text':
01138                         case 'passthrough':
01139                         case 'user':
01140                                 $res['value'] = $value;
01141                         break;
01142                         case 'input':
01143                                 $res = $this->checkValue_input($res,$value,$tcaFieldConf,$PP,$field);
01144                         break;
01145                         case 'check':
01146                                 $res = $this->checkValue_check($res,$value,$tcaFieldConf,$PP);
01147                         break;
01148                         case 'radio':
01149                                 $res = $this->checkValue_radio($res,$value,$tcaFieldConf,$PP);
01150                         break;
01151                         case 'group':
01152                         case 'select':
01153                                 $res = $this->checkValue_group_select($res,$value,$tcaFieldConf,$PP,$uploadedFiles,$field);
01154                         break;
01155                         case 'flex':
01156                                 if ($field)     {       // FlexForms are only allowed for real fields.
01157                                         $res = $this->checkValue_flex($res,$value,$tcaFieldConf,$PP,$uploadedFiles,$field);
01158                                 }
01159                         break;
01160                         default:
01161                                 #debug(array($tcaFieldConf,$res,$value),'NON existing field type:');
01162                         break;
01163                 }
01164 
01165                 return $res;
01166         }
01167 
01178         function checkValue_input($res,$value,$tcaFieldConf,$PP,$field='')      {
01179                 list($table,$id,$curValue,$status,$realPid,$recFID) = $PP;
01180 
01181                         // Secures the string-length to be less than max. Will probably make problems with multi-byte strings!
01182                 if (intval($tcaFieldConf['max'])>0)     {$value = substr($value,0,intval($tcaFieldConf['max']));}
01183 
01184                         // Checking range of value:
01185                 if ($tcaFieldConf['range'] && $value!=$tcaFieldConf['checkbox'])        {       // If value is not set to the allowed checkbox-value then it is checked against the ranges
01186                         if (isset($tcaFieldConf['r