00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00203
00204
00205
00206 require_once (PATH_t3lib.'class.t3lib_loaddbgroup.php');
00207 require_once (PATH_t3lib.'class.t3lib_parsehtml_proc.php');
00208 require_once (PATH_t3lib.'class.t3lib_stdgraphic.php');
00209 require_once (PATH_t3lib.'class.t3lib_basicfilefunc.php');
00210 require_once (PATH_t3lib.'class.t3lib_refindex.php');
00211 require_once (PATH_t3lib.'class.t3lib_flexformtools.php');
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00237 class t3lib_TCEmain {
00238
00239
00240
00241
00242
00243
00244 var $storeLogMessages = TRUE;
00245 var $enableLogging = TRUE;
00246 var $reverseOrder = FALSE;
00247 var $checkSimilar = TRUE;
00248 var $stripslashes_values = TRUE;
00249 var $checkStoredRecords = TRUE;
00250 var $checkStoredRecords_loose = TRUE;
00251 var $deleteTree = FALSE;
00252 var $neverHideAtCopy = FALSE;
00253 var $dontProcessTransformations = FALSE;
00254 var $bypassWorkspaceRestrictions = FALSE;
00255 var $bypassFileHandling = FALSE;
00256 var $bypassAccessCheckForRecords = FALSE;
00257
00258 var $copyWhichTables = '*';
00259 var $generalComment = '';
00260
00261 var $copyTree = 0;
00262
00263 var $defaultValues = array();
00264 var $overrideValues = array();
00265 var $alternativeFileName = array();
00266 var $data_disableFields=array();
00267 var $suggestedInsertUids=array();
00268
00269 var $callBackObj;
00270
00271
00272
00273
00274
00275
00276
00277 var $autoVersionIdMap = Array();
00278 var $substNEWwithIDs = Array();
00279 var $substNEWwithIDs_table = Array();
00280 var $newRelatedIDs = Array();
00281 var $copyMappingArray_merged = Array();
00282 var $copiedFileMap = Array();
00283 var $errorLog = Array();
00284
00285
00286
00287
00288
00289
00290
00291
00292 var $BE_USER;
00293 var $userid;
00294 var $username;
00295 var $admin;
00296
00297 var $defaultPermissions = array(
00298 'user' => 'show,edit,delete,new,editcontent',
00299 'group' => 'show,edit,new,editcontent',
00300 'everybody' => ''
00301 );
00302
00303 var $exclude_array;
00304 var $datamap = Array();
00305 var $cmdmap = Array();
00306
00307
00308 var $pMap = Array(
00309 'show' => 1,
00310 'edit' => 2,
00311 'delete' => 4,
00312 'new' => 8,
00313 'editcontent' => 16
00314 );
00315 var $sortIntervals = 256;
00316
00317
00318 var $recUpdateAccessCache = Array();
00319 var $recInsertAccessCache = Array();
00320 var $isRecordInWebMount_Cache=array();
00321 var $isInWebMount_Cache=array();
00322 var $cachedTSconfig = array();
00323 var $pageCache = Array();
00324 var $checkWorkspaceCache = Array();
00325
00326
00327 var $dbAnalysisStore=array();
00328 var $removeFilesStore=array();
00329 var $uploadedFileArray = array();
00330 var $registerDBList=array();
00331 var $copyMappingArray = Array();
00332 var $remapStack = array();
00333 var $updateRefIndexStack = array();
00334 var $callFromImpExp = false;
00335
00336
00337 var $fileFunc;
00338 var $checkValue_currentRecord=array();
00339 var $autoVersioningUpdate = FALSE;
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00362 function start($data,$cmd,$altUserObject='') {
00363
00364
00365 $this->BE_USER = is_object($altUserObject) ? $altUserObject : $GLOBALS['BE_USER'];
00366 $this->userid = $this->BE_USER->user['uid'];
00367 $this->username = $this->BE_USER->user['username'];
00368 $this->admin = $this->BE_USER->user['admin'];
00369
00370 if ($GLOBALS['BE_USER']->uc['recursiveDelete']) {
00371 $this->deleteTree = 1;
00372 }
00373
00374
00375 $defaultPermissions = $GLOBALS['TYPO3_CONF_VARS']['BE']['defaultPermissions'];
00376 if (isset($defaultPermissions['user'])) {$this->defaultPermissions['user'] = $defaultPermissions['user'];}
00377 if (isset($defaultPermissions['group'])) {$this->defaultPermissions['group'] = $defaultPermissions['group'];}
00378 if (isset($defaultPermissions['everybody'])) {$this->defaultPermissions['everybody'] = $defaultPermissions['everybody'];}
00379
00380
00381 $this->exclude_array = $this->admin ? array() : $this->getExcludeListArray();
00382
00383
00384 if (is_array($data)) {
00385 reset($data);
00386 $this->datamap = $data;
00387 }
00388 if (is_array($cmd)) {
00389 reset($cmd);
00390 $this->cmdmap = $cmd;
00391 }
00392 }
00393
00401 function setMirror($mirror) {
00402 if (is_array($mirror)) {
00403 reset($mirror);
00404 while(list($table,$uid_array)=each($mirror)) {
00405 if (isset($this->datamap[$table])) {
00406 reset($uid_array);
00407 while (list($id,$uidList) = each($uid_array)) {
00408 if (isset($this->datamap[$table][$id])) {
00409 $theIdsInArray = t3lib_div::trimExplode(',',$uidList,1);
00410 while(list(,$copyToUid)=each($theIdsInArray)) {
00411 $this->datamap[$table][$copyToUid] = $this->datamap[$table][$id];
00412 }
00413 }
00414 }
00415 }
00416 }
00417 }
00418 }
00419
00426 function setDefaultsFromUserTS($userTS) {
00427 global $TCA;
00428 if (is_array($userTS)) {
00429 foreach($userTS as $k => $v) {
00430 $k = substr($k,0,-1);
00431 if ($k && is_array($v) && isset($TCA[$k])) {
00432 if (is_array($this->defaultValues[$k])) {
00433 $this->defaultValues[$k] = array_merge($this->defaultValues[$k],$v);
00434 } else {
00435 $this->defaultValues[$k] = $v;
00436 }
00437 }
00438 }
00439 }
00440 }
00441
00449 function process_uploads($postFiles) {
00450
00451 if (is_array($postFiles)) {
00452
00453
00454 if ($this->BE_USER->workspace!==0 && $this->BE_USER->workspaceRec['freeze']) {
00455 $this->newlog('All editing in this workspace has been frozen!',1);
00456 return FALSE;
00457 }
00458
00459 reset($postFiles);
00460 $subA = current($postFiles);
00461 if (is_array($subA)) {
00462 if (is_array($subA['name']) && is_array($subA['type']) && is_array($subA['tmp_name']) && is_array($subA['size'])) {
00463
00464 $this->uploadedFileArray=array();
00465
00466
00467 foreach($subA as $key => $values) {
00468 $this->process_uploads_traverseArray($this->uploadedFileArray,$values,$key);
00469 }
00470 } else {
00471 $this->uploadedFileArray=$subA;
00472 }
00473 }
00474 }
00475 }
00476
00487 function process_uploads_traverseArray(&$outputArr,$inputArr,$keyToSet) {
00488 if (is_array($inputArr)) {
00489 foreach($inputArr as $key => $value) {
00490 $this->process_uploads_traverseArray($outputArr[$key],$inputArr[$key],$keyToSet);
00491 }
00492 } else {
00493 $outputArr[$keyToSet]=$inputArr;
00494 }
00495 }
00496
00497
00498
00499
00500
00501
00502
00503
00504
00505
00506
00507
00508
00509
00510
00511
00512
00513
00514
00515
00516
00523 function process_datamap() {
00524 global $TCA, $TYPO3_CONF_VARS;
00525
00526
00527 if ($this->BE_USER->workspace!==0 && $this->BE_USER->workspaceRec['freeze']) {
00528 $this->newlog('All editing in this workspace has been frozen!',1);
00529 return FALSE;
00530 }
00531
00532
00533 $hookObjectsArr = array();
00534 if (is_array ($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processDatamapClass'])) {
00535 foreach ($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processDatamapClass'] as $classRef) {
00536 $hookObjectsArr[] = &t3lib_div::getUserObj($classRef);
00537 }
00538 }
00539
00540
00541 $orderOfTables = Array();
00542 if (isset($this->datamap['pages'])) {
00543 $orderOfTables[]='pages';
00544 }
00545 reset($this->datamap);
00546 while (list($table,) = each($this->datamap)) {
00547 if ($table!='pages') {
00548 $orderOfTables[]=$table;
00549 }
00550 }
00551
00552
00553 foreach($orderOfTables as $table) {
00554
00555
00556
00557
00558
00559
00560 $modifyAccessList = $this->checkModifyAccessList($table);
00561 if (!$modifyAccessList) {
00562 $id = 0;
00563 $this->log($table,$id,2,0,1,"Attempt to modify table '%s' without permission",1,array($table));
00564 }
00565 if (isset($TCA[$table]) && !$this->tableReadOnly($table) && is_array($this->datamap[$table]) && $modifyAccessList) {
00566 if ($this->reverseOrder) {
00567 $this->datamap[$table] = array_reverse($this->datamap[$table], 1);
00568 }
00569
00570
00571
00572
00573 foreach($this->datamap[$table] as $id => $incomingFieldArray) {
00574 if (is_array($incomingFieldArray)) {
00575
00576
00577 foreach($hookObjectsArr as $hookObj) {
00578 if (method_exists($hookObj, 'processDatamap_preProcessFieldArray')) {
00579 $hookObj->processDatamap_preProcessFieldArray($incomingFieldArray, $table, $id, $this);
00580 }
00581 }
00582
00583
00584
00585
00586 $createNewVersion = FALSE;
00587 $recordAccess = FALSE;
00588 $old_pid_value = '';
00589 $resetRejected = FALSE;
00590 $this->autoVersioningUpdate = FALSE;
00591
00592 if (!t3lib_div::testInt($id)) {
00593 $fieldArray = $this->newFieldArray($table);
00594 if (isset($incomingFieldArray['pid'])) {
00595
00596 $pid_value = $incomingFieldArray['pid'];
00597
00598
00599 $OK = 1;
00600 if (strstr($pid_value,'NEW')) {
00601 if (substr($pid_value,0,1)=='-') {$negFlag=-1;$pid_value=substr($pid_value,1);} else {$negFlag=1;}
00602 if (isset($this->substNEWwithIDs[$pid_value])) {
00603 $old_pid_value = $pid_value;
00604 $pid_value=intval($negFlag*$this->substNEWwithIDs[$pid_value]);
00605 } else {$OK = 0;}
00606 } elseif ($pid_value>=0 && $this->BE_USER->workspace!==0 && $TCA[$table]['ctrl']['versioning_followPages']) {
00607 if ($WSdestPage = t3lib_BEfunc::getWorkspaceVersionOfRecord($this->BE_USER->workspace, 'pages', $pid_value, 'uid,t3ver_swapmode')) {
00608 if ($WSdestPage['t3ver_swapmode']==0) {
00609 $pid_value = $WSdestPage['uid'];
00610 }
00611 }
00612 }
00613 $pid_value = intval($pid_value);
00614
00615
00616 if ($OK) {
00617 $sortRow = $TCA[$table]['ctrl']['sortby'];
00618 if ($pid_value>=0) {
00619 if ($sortRow) {
00620 $fieldArray[$sortRow] = $this->getSortNumber($table,0,$pid_value);
00621 }
00622 $fieldArray['pid'] = $pid_value;
00623 } else {
00624 if ($sortRow) {
00625 $tempArray=$this->getSortNumber($table,0,$pid_value);
00626 $fieldArray['pid'] = $tempArray['pid'];
00627 $fieldArray[$sortRow] = $tempArray['sortNumber'];
00628 } else {
00629 $tempdata = $this->recordInfo($table,abs($pid_value),'pid');
00630 $fieldArray['pid']=$tempdata['pid'];
00631 }
00632 }
00633 }
00634 }
00635 $theRealPid = $fieldArray['pid'];
00636
00637
00638 if ($theRealPid>=0) {
00639 $recordAccess = $this->checkRecordInsertAccess($table,$theRealPid);
00640 if ($recordAccess) {
00641 $this->addDefaultPermittedLanguageIfNotSet($table,$incomingFieldArray);
00642 $recordAccess = $this->BE_USER->recordEditAccessInternals($table,$incomingFieldArray,TRUE);
00643 if (!$recordAccess) {
00644 $this->newlog("recordEditAccessInternals() check failed. [".$this->BE_USER->errorMsg."]",1);
00645 } elseif(!$this->bypassWorkspaceRestrictions) {
00646
00647 if ($res = $this->BE_USER->workspaceAllowLiveRecordsInPID($theRealPid,$table)) {
00648 if ($res<0) {
00649 $recordAccess = FALSE;
00650 $this->newlog('Stage for versioning root point and users access level did not allow for editing',1);
00651 }
00652 } else {
00653 if ($TCA[$table]['ctrl']['versioningWS']) {
00654 $createNewVersion = TRUE;
00655 } else {
00656 $recordAccess = FALSE;
00657 $this->newlog('Record could not be created in this workspace in this branch',1);
00658 }
00659 }
00660 }
00661 }
00662 } else {
00663 debug('Internal ERROR: pid should not be less than zero!');
00664 }
00665 $status = 'new';
00666 } else {
00667 $fieldArray = array();
00668 $recordAccess = $this->checkRecordUpdateAccess($table,$id);
00669 if (!$recordAccess) {
00670 $propArr = $this->getRecordProperties($table,$id);
00671 $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']);
00672 } else {
00673 $recordAccess = $this->BE_USER->recordEditAccessInternals($table,$id);
00674 if (!$recordAccess) {
00675 $propArr = $this->getRecordProperties($table,$id);
00676 $this->newlog("recordEditAccessInternals() check failed. [".$this->BE_USER->errorMsg."]",1);
00677 } else {
00678 $tempdata = $this->recordInfo($table,$id,'pid'.($TCA[$table]['ctrl']['versioningWS']?',t3ver_wsid,t3ver_stage':''));
00679 $theRealPid = $tempdata['pid'];
00680
00681
00682 if ($TCA[$table]['ctrl']['versioningWS'] && $tempdata['t3ver_stage']<0) {
00683 $resetRejected = TRUE;
00684 }
00685
00686
00687 if (!$this->bypassWorkspaceRestrictions && $errorCode = $this->BE_USER->workspaceCannotEditRecord($table,$tempdata)) {
00688 $recordAccess = FALSE;
00689
00690
00691 if ($this->BE_USER->workspaceAllowAutoCreation($table,$id,$theRealPid)) {
00692 $tce = t3lib_div::makeInstance('t3lib_TCEmain');
00693 $tce->stripslashes_values = 0;
00694
00695
00696 $cmd = array();
00697 $cmd[$table][$id]['version'] = array(
00698 'action' => 'new',
00699 'treeLevels' => -1,
00700 'label' => 'Auto-created for WS #'.$this->BE_USER->workspace
00701 );
00702 $tce->start(array(),$cmd);
00703 $tce->process_cmdmap();
00704 $this->errorLog = array_merge($this->errorLog,$tce->errorLog);
00705
00706 if ($tce->copyMappingArray[$table][$id]) {
00707 $this->uploadedFileArray[$table][$tce->copyMappingArray[$table][$id]] = $this->uploadedFileArray[$table][$id];
00708 $id = $this->autoVersionIdMap[$table][$id] = $tce->copyMappingArray[$table][$id];
00709 $recordAccess = TRUE;
00710 $this->autoVersioningUpdate = TRUE;
00711 } else $this->newlog("Could not be edited in offline workspace in the branch where found (failure state: '".$errorCode."'). Auto-creation of version failed!",1);
00712 } 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);
00713 }
00714 }
00715 }
00716 $status = 'update';
00717 }
00718
00719
00720 if ($recordAccess) {
00721
00722 list($tscPID) = t3lib_BEfunc::getTSCpid($table,$id,$old_pid_value ? $old_pid_value : $fieldArray['pid']);
00723 $TSConfig = $this->getTCEMAIN_TSconfig($tscPID);
00724 if ($status=='new' && $table=='pages' && is_array($TSConfig['permissions.'])) {
00725 $fieldArray = $this->setTSconfigPermissions($fieldArray,$TSConfig['permissions.']);
00726 }
00727 if ($createNewVersion) {
00728 $newVersion_placeholderFieldArray = $fieldArray;
00729 }
00730
00731
00732 $fieldArray = $this->fillInFieldArray($table,$id,$fieldArray,$incomingFieldArray,$theRealPid,$status,$tscPID);
00733
00734
00735
00736
00737 $fieldArray = $this->overrideFieldArray($table,$fieldArray);
00738 if ($createNewVersion) {
00739 $newVersion_placeholderFieldArray = $this->overrideFieldArray($table,$newVersion_placeholderFieldArray);
00740 }
00741
00742
00743 if ($status=='new') {
00744 if ($TCA[$table]['ctrl']['crdate']) {
00745 $fieldArray[$TCA[$table]['ctrl']['crdate']]=time();
00746 if ($createNewVersion) $newVersion_placeholderFieldArray[$TCA[$table]['ctrl']['crdate']]=time();
00747 }
00748 if ($TCA[$table]['ctrl']['cruser_id']) {
00749 $fieldArray[$TCA[$table]['ctrl']['cruser_id']]=$this->userid;
00750 if ($createNewVersion) $newVersion_placeholderFieldArray[$TCA[$table]['ctrl']['cruser_id']]=$this->userid;
00751 }
00752 } elseif ($this->checkSimilar) {
00753 $fieldArray = $this->compareFieldArrayWithCurrentAndUnset($table,$id,$fieldArray);
00754 }
00755 if ($TCA[$table]['ctrl']['tstamp'] && count($fieldArray)) {
00756 $fieldArray[$TCA[$table]['ctrl']['tstamp']]=time();
00757 if ($createNewVersion) $newVersion_placeholderFieldArray[$TCA[$table]['ctrl']['tstamp']]=time();
00758 }
00759 if ($resetRejected) {
00760 $fieldArray['t3ver_stage'] = 0;
00761 }
00762
00763
00764 foreach($hookObjectsArr as $hookObj) {
00765 if (method_exists($hookObj, 'processDatamap_postProcessFieldArray')) {
00766 $hookObj->processDatamap_postProcessFieldArray($status, $table, $id, $fieldArray, $this);
00767 }
00768 }
00769
00770
00771
00772 if (is_array($fieldArray)) {
00773 if ($status=='new') {
00774 if ($createNewVersion) {
00775 $versioningType = $table==='pages' ? $this->BE_USER->workspaceVersioningTypeGetClosest(t3lib_div::intInRange($TYPO3_CONF_VARS['BE']['newPagesVersioningType'],-1,1)) : -1;
00776 if ($this->BE_USER->workspaceVersioningTypeAccess($versioningType)) {
00777 $newVersion_placeholderFieldArray['t3ver_label'] = 'INITIAL PLACEHOLDER';
00778 $newVersion_placeholderFieldArray['t3ver_state'] = 1;
00779 $newVersion_placeholderFieldArray['t3ver_wsid'] = $this->BE_USER->workspace;
00780 $newVersion_placeholderFieldArray[$TCA[$table]['ctrl']['label']] = '[PLACEHOLDER, WS#'.$this->BE_USER->workspace.']';
00781 $this->insertDB($table,$id,$newVersion_placeholderFieldArray,FALSE);
00782
00783
00784 $fieldArray['pid'] = -1;
00785 $fieldArray['t3ver_oid'] = $this->substNEWwithIDs[$id];
00786 $fieldArray['t3ver_id'] = 1;
00787 $fieldArray['t3ver_state'] = -1;
00788 $fieldArray['t3ver_label'] = 'First draft version';
00789 $fieldArray['t3ver_wsid'] = $this->BE_USER->workspace;
00790 if ($table==='pages') {
00791 $fieldArray['t3ver_swapmode'] = $versioningType;
00792 }
00793 $phShadowId = $this->insertDB($table,$id,$fieldArray,TRUE,0,TRUE);
00794 if ($phShadowId) {
00795 $this->placeholderShadowing($table,$phShadowId);
00796 }
00797 } else $this->newlog('Versioning type "'.$versioningType.'" was not allowed, so could not create new record.',1);
00798 } else {
00799 $this->insertDB($table,$id,$fieldArray,FALSE,$incomingFieldArray['uid']);
00800 }
00801 } else {
00802 $this->updateDB($table,$id,$fieldArray);
00803 $this->placeholderShadowing($table,$id);
00804 }
00805 }
00806
00807
00808
00809
00810
00811
00812
00813 foreach($hookObjectsArr as $hookObj) {
00814 if (method_exists($hookObj, 'processDatamap_afterDatabaseOperations')) {
00815 $hookObj->processDatamap_afterDatabaseOperations($status, $table, $id, $fieldArray, $this);
00816 }
00817 }
00818 }
00819 }
00820 }
00821 }
00822 }
00823
00824
00825
00826
00827 if(is_array($this->remapStack)) {
00828 foreach($this->remapStack as $remapAction) {
00829
00830 if (!is_array($remapAction['pos'])) continue;
00831
00832
00833 $field = $remapAction['field'];
00834 $id = $remapAction['args'][$remapAction['pos']['id']];
00835 $table = $remapAction['args'][$remapAction['pos']['table']];
00836 $valueArray = $remapAction['args'][$remapAction['pos']['valueArray']];
00837 $tcaFieldConf = $remapAction['args'][$remapAction['pos']['tcaFieldConf']];
00838
00839
00840 if(strpos($id, 'NEW') !== false) {
00841 $id = $this->substNEWwithIDs[$id];
00842 $remapAction['args'][$remapAction['pos']['id']] = $id;
00843 }
00844
00845
00846 if(is_array($valueArray)) {
00847 foreach($valueArray as $key => $value) {
00848 if(strpos($value, 'NEW') !== false) {
00849
00850 $valueArray[$key] = $this->substNEWwithIDs[$value];
00851
00852 $this->newRelatedIDs[$table][] = $valueArray[$key];
00853 }
00854 }
00855 $remapAction['args'][$remapAction['pos']['valueArray']] = $valueArray;
00856 }
00857
00858
00859 $remapAction['args'][$remapAction['pos']['valueArray']] = call_user_func_array(
00860 array($this, $remapAction['func']),
00861 $remapAction['args']
00862 );
00863
00864
00865 $newVal = $this->checkValue_checkMax($tcaFieldConf, $remapAction['args'][$remapAction['pos']['valueArray']]);
00866 $this->updateDB($table,$id,array($field => implode(',', $newVal)));
00867 }
00868 }
00869
00870 $this->dbAnalysisStoreExec();
00871 $this->removeRegisteredFiles();
00872 }
00873
00881 function placeholderShadowing($table,$id) {
00882 global $TCA;
00883
00884 t3lib_div::loadTCA($table);
00885 if ($liveRec = t3lib_BEfunc::getLiveVersionOfRecord($table,$id,'*')) {
00886 if ((int)$liveRec['t3ver_state']===1) {
00887 $justStoredRecord = t3lib_BEfunc::getRecord($table,$id);
00888 $newRecord = array();
00889
00890 $shadowCols = $TCA[$table]['ctrl']['shadowColumnsForNewPlaceholders'];
00891 $shadowCols.= ','.$TCA[$table]['ctrl']['languageField'];
00892 $shadowCols.= ','.$TCA[$table]['ctrl']['transOrigPointerField'];
00893 $shadowCols.= ','.$TCA[$table]['ctrl']['type'];
00894 $shadowCols.= ','.$TCA[$table]['ctrl']['label'];
00895
00896 $shadowColumns = array_unique(t3lib_div::trimExplode(',', $shadowCols,1));
00897 foreach($shadowColumns as $fieldName) {
00898 if (strcmp($justStoredRecord[$fieldName],$liveRec[$fieldName]) && isset($TCA[$table]['columns'][$fieldName]) && $fieldName!=='uid' && $fieldName!=='pid') {
00899 $newRecord[$fieldName] = $justStoredRecord[$fieldName];
00900 }
00901 }
00902
00903 if (count($newRecord)) {
00904 $this->newlog('Shadowing done on fields '.implode(',',array_keys($newRecord)).' in Placeholder record '.$table.':'.$liveRec['uid'].' (offline version UID='.$id.')');
00905 $this->updateDB($table,$liveRec['uid'],$newRecord);
00906 }
00907 }
00908 }
00909 }
00910
00924 function fillInFieldArray($table,$id,$fieldArray,$incomingFieldArray,$realPid,$status,$tscPID) {
00925 global $TCA;
00926
00927
00928 t3lib_div::loadTCA($table);
00929 $originalLanguageRecord = NULL;
00930 $originalLanguage_diffStorage = NULL;
00931 $diffStorageFlag = FALSE;
00932
00933
00934 if (strstr($id,'NEW')) {
00935 $currentRecord = $checkValueRecord = $fieldArray;
00936
00937
00938
00939 if (is_array($incomingFieldArray) && is_array($checkValueRecord)) {
00940 $checkValueRecord = t3lib_div::array_merge_recursive_overrule($checkValueRecord, $incomingFieldArray);
00941 }
00942 } else {
00943 $currentRecord = $checkValueRecord = $this->recordInfo($table,$id,'*');
00944
00945 t3lib_BEfunc::fixVersioningPid($table,$currentRecord);
00946
00947
00948 if (is_array($currentRecord)
00949 && $TCA[$table]['ctrl']['transOrigDiffSourceField']
00950 && $TCA[$table]['ctrl']['languageField']
00951 && $currentRecord[$TCA[$table]['ctrl']['languageField']] > 0
00952 && $TCA[$table]['ctrl']['transOrigPointerField']
00953 && intval($currentRecord[$TCA[$table]['ctrl']['transOrigPointerField']]) > 0) {
00954
00955 $lookUpTable = $TCA[$table]['ctrl']['transOrigPointerTable'] ? $TCA[$table]['ctrl']['transOrigPointerTable'] : $table;
00956 $originalLanguageRecord = $this->recordInfo($lookUpTable,$currentRecord[$TCA[$table]['ctrl']['transOrigPointerField']],'*');
00957 t3lib_BEfunc::workspaceOL($lookUpTable,$originalLanguageRecord);
00958 $originalLanguage_diffStorage = unserialize($currentRecord[$TCA[$table]['ctrl']['transOrigDiffSourceField']]);
00959 }
00960 }
00961 $this->checkValue_currentRecord = $checkValueRecord;
00962
00963
00964
00965
00966
00967
00968
00969
00970
00971
00972 foreach($incomingFieldArray as $field => $fieldValue) {
00973 if (!in_array($table.'-'.$field, $this->exclude_array) && !$this->data_disableFields[$table][$id][$field]) {
00974
00975
00976 $languageDeny = $TCA[$table]['ctrl']['languageField'] && !strcmp($TCA[$table]['ctrl']['languageField'], $field) && !$this->BE_USER->checkLanguageAccess($fieldValue);
00977
00978 if (!$languageDeny) {
00979
00980 if ($this->stripslashes_values) {
00981 if (is_array($fieldValue)) {
00982 t3lib_div::stripSlashesOnArray($fieldValue);
00983 } else $fieldValue = stripslashes($fieldValue);
00984 }
00985
00986 switch ($field) {
00987 case 'uid':
00988 case 'pid':
00989
00990 break;
00991 case 'perms_userid':
00992 case 'perms_groupid':
00993 case 'perms_user':
00994 case 'perms_group':
00995 case 'perms_everybody':
00996
00997 if ($table=='pages' && ($this->admin || $status=='new' || $this->pageInfo($id,'perms_userid')==$this->userid) ) {
00998 $value=intval($fieldValue);
00999 switch($field) {
01000 case 'perms_userid':
01001 $fieldArray[$field]=$value;
01002 break;
01003 case 'perms_groupid':
01004 $fieldArray[$field]=$value;
01005 break;
01006 default:
01007 if ($value>=0 && $value<pow(2,5)) {
01008 $fieldArray[$field]=$value;
01009 }
01010 break;
01011 }
01012 }
01013 break;
01014 case 't3ver_oid':
01015 case 't3ver_id':
01016 case 't3ver_wsid':
01017 case 't3ver_state':
01018 case 't3ver_swapmode':
01019 case 't3ver_count':
01020 case 't3ver_stage':
01021 case 't3ver_tstamp':
01022
01023 break;
01024 default:
01025 if (isset($TCA[$table]['columns'][$field])) {
01026
01027 $res = $this->checkValue($table,$field,$fieldValue,$id,$status,$realPid,$tscPID);
01028 if (isset($res['value'])) {
01029 $fieldArray[$field]=$res['value'];
01030
01031
01032 if ($TCA[$table]['ctrl']['transOrigDiffSourceField']) {
01033 $originalLanguage_diffStorage[$field] = $originalLanguageRecord[$field];
01034 $diffStorageFlag = TRUE;
01035 }
01036 }
01037 } elseif ($TCA[$table]['ctrl']['origUid']===$field) {
01038 $fieldArray[$field] = $fieldValue;
01039 }
01040 break;
01041 }
01042 }
01043 }
01044 }
01045
01046
01047 if ($diffStorageFlag && !isset($fieldArray[$TCA[$table]['ctrl']['transOrigDiffSourceField']])) {
01048 $fieldArray[$TCA[$table]['ctrl']['transOrigDiffSourceField']] = serialize($originalLanguage_diffStorage);
01049 }
01050
01051
01052 $types_fieldConfig = t3lib_BEfunc::getTCAtypes($table,$currentRecord);
01053 $theTypeString = t3lib_BEfunc::getTCAtypeValue($table,$currentRecord);
01054 if (is_array($types_fieldConfig)) {
01055 reset($types_fieldConfig);
01056 while(list(,$vconf) = each($types_fieldConfig)) {
01057
01058 $eFile = t3lib_parsehtml_proc::evalWriteFile($vconf['spec']['static_write'],array_merge($currentRecord,$fieldArray));
01059
01060
01061 if (!$this->dontProcessTransformations) {
01062 if (isset($fieldArray[$vconf['field']])) {
01063
01064 switch((string)$incomingFieldArray['_TRANSFORM_'.$vconf['field']]) {
01065 case 'RTE':
01066 $RTEsetup = $this->BE_USER->getTSConfig('RTE',t3lib_BEfunc::getPagesTSconfig($tscPID));
01067 $thisConfig = t3lib_BEfunc::RTEsetup($RTEsetup['properties'],$table,$vconf['field'],$theTypeString);
01068
01069
01070 $RTErelPath = is_array($eFile) ? dirname($eFile['relEditFile']) : '';
01071
01072
01073 $RTEobj = &t3lib_BEfunc::RTEgetObj();
01074 if (is_object($RTEobj)) {
01075 $fieldArray[$vconf['field']] = $RTEobj->transformContent('db',$fieldArray[$vconf['field']],$table,$vconf['field'],$currentRecord,$vconf['spec'],$thisConfig,$RTErelPath,$currentRecord['pid']);
01076 } else {
01077 debug('NO RTE OBJECT FOUND!');
01078 }
01079 break;
01080 }
01081 }
01082 }
01083
01084
01085 if (is_array($eFile)) {
01086 $mixedRec = array_merge($currentRecord,$fieldArray);
01087 $SW_fileContent = t3lib_div::getUrl($eFile['editFile']);
01088 $parseHTML = t3lib_div::makeInstance('t3lib_parsehtml_proc');
01089 $parseHTML->init('','');
01090
01091 $eFileMarker = $eFile['markerField']&&trim($mixedRec[$eFile['markerField']]) ? trim($mixedRec[$eFile['markerField']]) : '###TYPO3_STATICFILE_EDIT###';
01092 $insertContent = str_replace($eFileMarker,'',$mixedRec[$eFile['contentField']]);
01093
01094 $SW_fileNewContent = $parseHTML->substituteSubpart($SW_fileContent, $eFileMarker, chr(10).$insertContent.chr(10), 1, 1);
01095 t3lib_div::writeFile($eFile['editFile'],$SW_fileNewContent);
01096
01097
01098 if (!strstr($id,'NEW') && $eFile['statusField']) {
01099 $GLOBALS['TYPO3_DB']->exec_UPDATEquery(
01100 $table,
01101 'uid='.intval($id),
01102 array(
01103 $eFile['statusField'] => $eFile['relEditFile'].' updated '.date('d-m-Y H:i:s').', bytes '.strlen($mixedRec[$eFile['contentField']])
01104 )
01105 );
01106 }
01107 } elseif ($eFile && is_string($eFile)) {
01108 $this->log($table,$id,2,0,1,"Write-file error: '%s'",13,array($eFile),$realPid);
01109 }
01110 }
01111 }
01112
01113 return $fieldArray;
01114 }
01115
01116
01117
01118
01119
01120
01121
01122
01123
01124
01125
01126
01127
01128
01129
01130
01131
01132
01147 function checkValue($table,$field,$value,$id,$status,$realPid,$tscPID) {
01148 global $TCA, $PAGES_TYPES;
01149 t3lib_div::loadTCA($table);
01150
01151 $res = Array();
01152 $recFID = $table.':'.$id.':'.$field;
01153
01154
01155 if ($table=='pages' && $field=='doktype') {
01156
01157 if (! ($this->admin || t3lib_div::inList($this->BE_USER->groupData['pagetypes_select'],$value))) {
01158 $propArr = $this->getRecordProperties($table,$id);
01159 $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']);
01160 return $res;
01161 };
01162 if ($status=='update') {
01163
01164 $onlyAllowedTables = isset($PAGES_TYPES[$value]['onlyAllowedTables']) ? $PAGES_TYPES[$value]['onlyAllowedTables'] : $PAGES_TYPES['default']['onlyAllowedTables'];
01165 if ($onlyAllowedTables) {
01166 $theWrongTables = $this->doesPageHaveUnallowedTables($id,$value);
01167 if ($theWrongTables) {
01168 $propArr = $this->getRecordProperties($table,$id);
01169 $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']);
01170 return $res;
01171 }
01172 }
01173 }
01174 }
01175
01176
01177 $curValueRec = $this->recordInfo($table,$id,$field);
01178 $curValue = $curValueRec[$field];
01179
01180
01181 $tcaFieldConf = $TCA[$table]['columns'][$field]['config'];
01182
01183
01184 $res = $this->checkValue_SW($res,$value,$tcaFieldConf,$table,$id,$curValue,$status,$realPid,$recFID,$field,$this->uploadedFileArray[$table][$id][$field],$tscPID);
01185
01186 return $res;
01187 }
01188
01207 function checkValue_SW($res,$value,$tcaFieldConf,$table,$id,$curValue,$status,$realPid,$recFID,$field,$uploadedFiles,$tscPID) {
01208
01209 $PP = array($table,$id,$curValue,$status,$realPid,$recFID,$tscPID);
01210
01211 switch ($tcaFieldConf['type']) {
01212 case 'text':
01213 case 'passthrough':
01214 case 'user':
01215 $res['value'] = $value;
01216 break;
01217 case 'input':
01218 $res = $this->checkValue_input($res,$value,$tcaFieldConf,$PP,$field);
01219 break;
01220 case 'check':
01221 $res = $this->checkValue_check($res,$value,$tcaFieldConf,$PP);
01222 break;
01223 case 'radio':
01224 $res = $this->checkValue_radio($res,$value,$tcaFieldConf,$PP);
01225 break;
01226 case 'group':
01227 case 'select':
01228 $res = $this->checkValue_group_select($res,$value,$tcaFieldConf,$PP,$uploadedFiles,$field);
01229 break;
01230 case 'inline':
01231 $res = $this->checkValue_inline($res,$value,$tcaFieldConf,$PP,$field);
01232 break;
01233 case 'flex':
01234 if ($field) {
01235 $res = $this->checkValue_flex($res,$value,$tcaFieldConf,$PP,$uploadedFiles,$field);
01236 }
01237 break;
01238 default:
01239 #debug(array($tcaFieldConf,$res,$value),'NON existing field type:');
01240 break;
01241 }
01242
01243 return $res;
01244 }
01245
01256 function checkValue_input($res,$value,$tcaFieldConf,$PP,$field='') {
01257 list($table,$id,$curValue,$status,$realPid,$recFID) = $PP;
01258
01259
01260 if (intval($tcaFieldConf['max'])>0) {$value = substr($value,0,intval($tcaFieldConf['max']));}
01261
01262
01263 if ($tcaFieldConf['range'] && $value!=$tcaFieldConf['checkbox']) {
01264 if (isset($tcaFieldConf['range']['upper'])&&$value>$tcaFieldConf['range']['upper']) {$value=$tcaFieldConf['range']['upper'];}
01265 if (isset($tcaFieldConf['range']['lower'])&&$value<$tcaFieldConf['range']['lower']) {$value=$tcaFieldConf['range']['lower'];}
01266 }
01267
01268
01269 $evalCodesArray = t3lib_div::trimExplode(',',$tcaFieldConf['eval'],1);
01270 $res = $this->checkValue_input_Eval($value,$evalCodesArray,$tcaFieldConf['is_in']);
01271
01272
01273 if ($field && $realPid>=0) {
01274 if ($res['value'] && in_array('uniqueInPid',$evalCodesArray)) {
01275 $res['value'] = $this->getUnique($table,$field,$res['value'],$id,$realPid);
01276 }
01277 if ($res['value'] && in_array('unique',$evalCodesArray)) {
01278 $res['value'] = $this->getUnique($table,$field,$res['value'],$id);
01279 }
01280 }
01281
01282 return $res;
01283 }
01284
01294 function checkValue_check($res,$value,$tcaFieldConf,$PP) {
01295 list($table,$id,$curValue,$status,$realPid,$recFID) = $PP;
01296
01297 $itemC = count($tcaFieldConf['items']);
01298 if (!$itemC) {$itemC=1;}
01299 $maxV = pow(2,$itemC);
01300
01301 if ($value<0) {$value=0;}
01302 if ($value>$maxV) {$value=$maxV;}
01303 $res['value'] = $value;
01304
01305 return $res;
01306 }
01307
01317 function checkValue_radio($res,$value,$tcaFieldConf,$PP) {
01318 list($table,$id,$curValue,$status,$realPid,$recFID) = $PP;
01319
01320 if (is_array($tcaFieldConf['items'])) {
01321 foreach($tcaFieldConf['items'] as $set) {
01322 if (!strcmp($set[1],$value)) {
01323 $res['value'] = $value;
01324 break;
01325 }
01326 }
01327 }
01328
01329 return $res;
01330 }
01331
01343 function checkValue_group_select($res,$value,$tcaFieldConf,$PP,$uploadedFiles,$field) {
01344
01345 list($table,$id,$curValue,$status,$realPid,$recFID) = $PP;
01346
01347
01348 if (is_array($value)) {
01349 $value = implode(',',$value);
01350 }
01351
01352
01353
01354 $value = $this->convNumEntityToByteValue($value);
01355
01356
01357 $valueArray = $this->checkValue_group_select_explodeSelectGroupValue($value);
01358
01359
01360 if (!$tcaFieldConf['multiple']) {
01361 $valueArray = array_unique($valueArray);
01362 }
01363
01364
01365 if ($tcaFieldConf['type']=='select' && $tcaFieldConf['exclusiveKeys']) {
01366 $exclusiveKeys = t3lib_div::trimExplode(',', $tcaFieldConf['exclusiveKeys']);
01367 foreach($valueArray as $kk => $vv) {
01368 if (in_array($vv, $exclusiveKeys)) {
01369 $valueArray = Array($kk => $vv);
01370 break;
01371 }
01372 }
01373 }
01374
01375
01376
01377
01378
01379 if ($tcaFieldConf['type']=='select' && $tcaFieldConf['authMode']) {
01380 $preCount = count($valueArray);
01381 foreach($valueArray as $kk => $vv) {
01382 if (!$this->BE_USER->checkAuthMode($table,$field,$vv,$tcaFieldConf['authMode'])) {
01383 unset($valueArray[$kk]);
01384 }
01385 }
01386
01387
01388 if ($preCount && !count($valueArray)) {
01389 return array();
01390 }
01391 }
01392
01393
01394 if ($tcaFieldConf['type']=='group') {
01395 switch($tcaFieldConf['internal_type']) {
01396 case 'file':
01397 $valueArray = $this->checkValue_group_select_file(
01398 $valueArray,
01399 $tcaFieldConf,
01400 $curValue,
01401 $uploadedFiles,
01402 $status,
01403 $table,
01404 $id,
01405 $recFID
01406 );
01407 break;
01408 case 'db':
01409 $valueArray = $this->checkValue_group_select_processDBdata($valueArray,$tcaFieldConf,$id,$status,'group', $table);
01410 break;
01411 }
01412 }
01413
01414 if ($tcaFieldConf['type']=='select' && $tcaFieldConf['foreign_table']) {
01415
01416 if (strpos($value, 'NEW') !== false) {
01417 $this->remapStack[] = array(
01418 'func' => 'checkValue_group_select_processDBdata',
01419 'args' => array($valueArray,$tcaFieldConf,$id,$status,'select',$table),
01420 'pos' => array('valueArray' => 0, 'tcaFieldConf' => 1, 'id' => 2, 'table' => 5),
01421 'field' => $field
01422 );
01423 $unsetResult = true;
01424 } else {
01425 $valueArray = $this->checkValue_group_select_processDBdata($valueArray,$tcaFieldConf,$id,$status,'select', $table);
01426 }
01427 }
01428
01429 if (!$unsetResult) {
01430 $newVal=$this->checkValue_checkMax($tcaFieldConf, $valueArray);
01431 $res['value'] = implode(',',$newVal);
01432 } else {
01433 unset($res['value']);
01434 }
01435
01436 return $res;
01437 }
01438
01453 function checkValue_group_select_file($valueArray,$tcaFieldConf,$curValue,$uploadedFileArray,$status,$table,$id,$recFID) {
01454
01455 if (!$this->bypassFileHandling) {
01456
01457
01458 if (is_array($uploadedFileArray) &&
01459 $uploadedFileArray['name'] &&
01460 strcmp($uploadedFileArray['tmp_name'],'none')) {
01461 $valueArray[]=$uploadedFileArray['tmp_name'];
01462 $this->alternativeFileName[$uploadedFileArray['tmp_name']] = $uploadedFileArray['name'];
01463 }
01464
01465
01466 if (!$this->fileFunc) {
01467 $this->fileFunc = t3lib_div::makeInstance('t3lib_basicFileFunctions');
01468 $this->include_filefunctions=1;
01469 }
01470
01471 $all_files = Array();
01472 $all_files['webspace']['allow'] = $tcaFieldConf['allowed'];
01473 $all_files['webspace']['deny'] = $tcaFieldConf['disallowed'] ? $tcaFieldConf['disallowed'] : '*';
01474 $all_files['ftpspace'] = $all_files['webspace'];
01475 $this->fileFunc->init('', $all_files);
01476 }
01477
01478
01479 if ($tcaFieldConf['uploadfolder']) {
01480 if (!$this->bypassFileHandling) {
01481
01482 $propArr = $this->getRecordProperties($table,$id);
01483
01484
01485 $dest = $this->destPathFromUploadFolder($tcaFieldConf['uploadfolder']);
01486
01487
01488 if ($status=='update') {
01489
01490
01491
01492
01493
01494
01495
01496
01497
01498
01499 if ($this->autoVersioningUpdate===TRUE) {
01500 foreach($valueArray as $key => $theFile) {
01501 if ($theFile===basename($theFile)) {
01502 $valueArray[$key] = PATH_site.$tcaFieldConf['uploadfolder'].'/'.$theFile;
01503 }
01504 }
01505 }
01506
01507
01508 $theFileValues=array();
01509 if ($tcaFieldConf['MM']) {
01510 $dbAnalysis = t3lib_div::makeInstance('t3lib_loadDBGroup');
01511 $dbAnalysis->start('','files',$tcaFieldConf['MM'],$id);
01512 reset($dbAnalysis->itemArray);
01513 while (list($somekey,$someval)=each($dbAnalysis->itemArray)) {
01514 if ($someval['id']) {
01515 $theFileValues[]=$someval['id'];
01516 }
01517 }
01518 } else {
01519 $theFileValues=t3lib_div::trimExplode(',',$curValue,1);
01520 }
01521
01522
01523 if (count($theFileValues)) {
01524
01525 foreach($valueArray as $key => $theFile) {
01526 if ($theFile && !strstr(t3lib_div::fixWindowsFilePath($theFile),'/')) {
01527 $theFileValues = t3lib_div::removeArrayEntryByValue($theFileValues,$theFile);
01528 }
01529 }
01530
01531
01532 foreach($theFileValues as $key => $theFile) {
01533 $theFile = trim($theFile);
01534 if (@is_file($dest.'/'.$theFile)) {
01535 $this->removeFilesStore[]=$dest.'/'.$theFile;
01536 } elseif ($theFile) {
01537 $this->log($table,$id,5,0,1,"Could not delete file '%s' (does not exist). (%s)",10,array($dest.'/'.$theFile, $recFID),$propArr['event_pid']);
01538 }
01539 }
01540 }
01541 }
01542
01543
01544 foreach($valueArray as $key => $theFile) {
01545
01546 if (strstr(t3lib_div::fixWindowsFilePath($theFile),'/')) {
01547
01548 $maxSize = intval($tcaFieldConf['max_size']);
01549 $cmd='';
01550 $theDestFile='';
01551
01552
01553 if (@is_dir($dest) && (@is_file($theFile) || @is_uploaded_file($theFile))) {
01554
01555
01556 if (is_uploaded_file($theFile) && $theFile==$uploadedFileArray['tmp_name']) {
01557 $fileSize = $uploadedFileArray['size'];
01558 } else {
01559 $fileSize = filesize($theFile);
01560 }
01561
01562 if (!$maxSize || $fileSize<=($maxSize*1024)) {
01563
01564 $theEndFileName = isset($this->alternativeFileName[$theFile]) ? $this->alternativeFileName[$theFile] : $theFile;
01565 $fI = t3lib_div::split_fileref($theEndFileName);
01566
01567
01568 if ($this->fileFunc->checkIfAllowed($fI['fileext'], $dest, $theEndFileName)) {
01569 $theDestFile = $this->fileFunc->getUniqueName($this->fileFunc->cleanFileName($fI['file']), $dest);
01570
01571
01572 if ($theDestFile) {
01573 t3lib_div::upload_copy_move($theFile,$theDestFile);
01574 $this->copiedFileMap[$theFile] = $theDestFile;
01575 clearstatcache();
01576 if (!@is_file($theDestFile)) $this->log($table,$id,5,0,1,"Copying file '%s' failed!: The destination path (%s) may be write protected. Please make it write enabled!. (%s)",16,array($theFile, dirname($theDestFile), $recFID),$propArr['event_pid']);
01577 } else $this->log($table,$id,5,0,1,"Copying file '%s' failed!: No destination file (%s) possible!. (%s)",11,array($theFile, $theDestFile, $recFID),$propArr['event_pid']);
01578 } else $this->log($table,$id,5,0,1,"Fileextension '%s' not allowed. (%s)",12,array($fI['fileext'], $recFID),$propArr['event_pid']);
01579 } else $this->log($table,$id,5,0,1,"Filesize (%s) of file '%s' exceeds limit (%s). (%s)",13,array(t3lib_div::formatSize($fileSize),$theFile,t3lib_div::formatSize($maxSize*1024),$recFID),$propArr['event_pid']);
01580 } else $this->log($table,$id,5,0,1,'The destination (%s) or the source file (%s) does not exist. (%s)',14,array($dest, $theFile, $recFID),$propArr['event_pid']);
01581
01582
01583 if (@is_file($theDestFile)) {
01584 $info = t3lib_div::split_fileref($theDestFile);
01585 $valueArray[$key]=$info['file'];
01586 } else {
01587 unset($valueArray[$key]);
01588 }
01589 }
01590 }
01591 }
01592
01593
01594 if ($tcaFieldConf['MM']) {
01595 $dbAnalysis = t3lib_div::makeInstance('t3lib_loadDBGroup');
01596 $dbAnalysis->tableArray['files']=array();
01597
01598 reset($valueArray);
01599 while (list($key,$theFile)=each($valueArray)) {
01600
01601 $dbAnalysis->itemArray[]['id']=$theFile;
01602 }
01603 if ($status=='update') {
01604 $dbAnalysis->writeMM($tcaFieldConf['MM'],$id,0);
01605 } else {
01606 $this->dbAnalysisStore[] = array($dbAnalysis, $tcaFieldConf['MM'], $id, 0);
01607 }
01608 $valueArray = $dbAnalysis->countItems();
01609 }
01610 }
01611
01612 return $valueArray;
01613 }
01614
01627 function checkValue_flex($res,$value,$tcaFieldConf,$PP,$uploadedFiles,$field) {
01628 list($table,$id,$curValue,$status,$realPid,$recFID) = $PP;
01629
01630 if (is_array($value)) {
01631
01632
01633
01634 $newRecordPidValue = $status=='new' ? $realPid : 0;
01635
01636
01637 $dataStructArray = t3lib_BEfunc::getFlexFormDS($tcaFieldConf,$this->checkValue_currentRecord,$table,'',TRUE,$newRecordPidValue);
01638
01639 $currentValueArray = t3lib_div::xml2array($curValue);
01640 if (!is_array($currentValueArray)) $currentValueArray = array();
01641 if (is_array($currentValueArray['meta']['currentLangId'])) unset($currentValueArray['meta']['currentLangId']);
01642
01643
01644 $value['data'] = $this->checkValue_flex_procInData($value['data'],$currentValueArray['data'],$uploadedFiles['data'],$dataStructArray,$PP);
01645
01646
01647 $xmlValue = $this->checkValue_flexArray2Xml($value,TRUE);
01648
01649
01650
01651
01652
01653 $storeInCharset=$GLOBALS['LANG']->charSet;
01654
01655
01656
01657 if (is_array($currentValueArray)) {
01658 $arrValue = t3lib_div::xml2array($xmlValue);
01659 $arrValue = t3lib_div::array_merge_recursive_overrule($currentValueArray,$arrValue);
01660 $xmlValue = $this->checkValue_flexArray2Xml($arrValue,TRUE);
01661 }
01662
01663
01664 $deleteCMDs = t3lib_div::_GP('_DELETE_FLEX_FORMdata');
01665 if (is_array($deleteCMDs[$table][$id][$field]['data'])) {
01666 $arrValue = t3lib_div::xml2array($xmlValue);
01667 $this->_DELETE_FLEX_FORMdata($arrValue['data'],$deleteCMDs[$table][$id][$field]['data']);
01668 $xmlValue = $this->checkValue_flexArray2Xml($arrValue,TRUE);
01669 }
01670
01671
01672 $moveCMDs = t3lib_div::_GP('_MOVEUP_FLEX_FORMdata');
01673 if (is_array($moveCMDs[$table][$id][$field]['data'])) {
01674 $arrValue = t3lib_div::xml2array($xmlValue);
01675 $this->_MOVE_FLEX_FORMdata($arrValue['data'],$moveCMDs[$table][$id][$field]['data'], 'up');
01676 $xmlValue = $this->checkValue_flexArray2Xml($arrValue,TRUE);
01677 }
01678
01679
01680 $moveCMDs = t3lib_div::_GP('_MOVEDOWN_FLEX_FORMdata');
01681 if (is_array($moveCMDs[$table][$id][$field]['data'])) {
01682 $arrValue = t3lib_div::xml2array($xmlValue);
01683 $this->_MOVE_FLEX_FORMdata($arrValue['data'],$moveCMDs[$table][$id][$field]['data'], 'down');
01684 $xmlValue = $this->checkValue_flexArray2Xml($arrValue,TRUE);
01685 }
01686
01687
01688 $res['value']='';
01689 $res['value'].=$xmlValue;
01690 } else {
01691 $res['value']=$value;
01692 }
01693
01694 return $res;
01695 }
01696
01704 function checkValue_flexArray2Xml($array, $addPrologue=FALSE) {
01705 $flexObj = t3lib_div::makeInstance('t3lib_flexformtools');
01706 return $flexObj->flexArray2Xml($array, $addPrologue);
01707 }
01708
01716 function _DELETE_FLEX_FORMdata(&$valueArrayToRemoveFrom,$deleteCMDS) {
01717 if (is_array($valueArrayToRemoveFrom) && is_array($deleteCMDS)) {
01718 foreach($deleteCMDS as $key => $value) {
01719 if (is_array($deleteCMDS[$key])) {
01720 $this->_DELETE_FLEX_FORMdata($valueArrayToRemoveFrom[$key],$deleteCMDS[$key]);
01721 } else {
01722 unset($valueArrayToRemoveFrom[$key]);
01723 }
01724 }
01725 }
01726 }
01727
01738 function _MOVE_FLEX_FORMdata(&$valueArrayToMoveIn, $moveCMDS, $direction) {
01739 if (is_array($valueArrayToMoveIn) && is_array($moveCMDS)) {
01740
01741
01742 list ($key, $value) = each ($moveCMDS);
01743
01744 if (is_array($moveCMDS[$key])) {
01745 $this->_MOVE_FLEX_FORMdata($valueArrayToMoveIn[$key],$moveCMDS[$key], $direction);
01746 } else {
01747 switch ($direction) {
01748 case 'up':
01749 if ($key > 1) {
01750 $tmpArr = $valueArrayToMoveIn[$key];
01751 $valueArrayToMoveIn[$key] = $valueArrayToMoveIn[$key-1];
01752 $valueArrayToMoveIn[$key-1] = $tmpArr;
01753 }
01754 break;
01755 case 'down':
01756 if ($key < count($valueArrayToMoveIn)) {
01757 $tmpArr = $valueArrayToMoveIn[$key];
01758 $valueArrayToMoveIn[$key] = $valueArrayToMoveIn[$key+1];
01759 $valueArrayToMoveIn[$key+1] = $tmpArr;
01760 }
01761 break;
01762 }
01763 }
01764 }
01765 }
01766
01778 function checkValue_inline($res,$value,$tcaFieldConf,$PP,$field) {
01779 list($table,$id,$curValue,$status,$realPid,$recFID) = $PP;
01780
01781 if (!$tcaFieldConf['foreign_table']) {
01782 return false;
01783 }
01784
01785
01786 $valueArray = t3lib_div::trimExplode(',', $value);
01787
01788
01789 $valueArray = array_unique($valueArray);
01790
01791
01792
01793
01794 if(strpos($value, 'NEW') !== false || !t3lib_div::testInt($id)) {
01795 $this->remapStack[] = array(
01796 'func' => 'checkValue_group_select_processDBdata',
01797 'args' => array($valueArray,$tcaFieldConf,$id,$status,'inline',$table),
01798 'pos' => array('valueArray' => 0, 'tcaFieldConf' => 1, 'id' => 2, 'table' => 5),
01799 'field' => $field
01800 );
01801 unset($res['value']);
01802 } elseif($value || t3lib_div::testInt($id)) {
01803 $newValueArray = $this->checkValue_group_select_processDBdata($valueArray,$tcaFieldConf,$id,$status,'inline', $table);
01804
01805
01806 $newVal = $this->checkValue_checkMax($tcaFieldConf, $newValueArray);
01807 $res['value'] = implode(',',$newVal);
01808 }
01809
01810 return $res;
01811 }
01812
01821 function checkValue_checkMax($tcaFieldConf, $valueArray) {
01822
01823
01824 $valueArrayC = count($valueArray);
01825
01826
01827 $maxI = isset($tcaFieldConf['maxitems']) ? intval($tcaFieldConf['maxitems']):1;
01828 if ($valueArrayC > $maxI) {$valueArrayC=$maxI;}
01829
01830
01831 $newVal=array();
01832 foreach($valueArray as $nextVal) {
01833 if ($valueArrayC==0) {break;}
01834 $valueArrayC--;
01835 $newVal[]=$nextVal;
01836 }
01837
01838 return $newVal;
01839 }
01840
01841
01842
01843
01844
01845
01846
01847
01848
01849
01850
01851
01852
01853
01854
01855
01856
01857
01858
01859
01860
01861
01862
01873 function getUnique($table,$field,$value,$id,$newPid=0) {
01874 global $TCA;
01875
01876
01877 t3lib_div::loadTCA($table);
01878 $whereAdd='';
01879 $newValue='';
01880 if (intval($newPid)) { $whereAdd.=' AND pid='.intval($newPid); } else { $whereAdd.=' AND pid>=0'; }
01881 $whereAdd.=$this->deleteClause($table);
01882
01883
01884 if (is_array($TCA[$table]) && is_array($TCA[$table]['columns'][$field])) {
01885
01886
01887 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid', $table, $field.'='.$GLOBALS['TYPO3_DB']->fullQuoteStr($value, $table).' AND uid!='.intval($id).$whereAdd);
01888 $counter = 0;
01889
01890
01891 while ($GLOBALS['TYPO3_DB']->sql_num_rows($res)) {
01892 $newValue = $value.$counter;
01893 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid', $table, $field.'='.$GLOBALS['TYPO3_DB']->fullQuoteStr($newValue, $table).' AND uid!='.intval($id).$whereAdd);
01894 $counter++;
01895 if ($counter>100) { break; }
01896 }
01897
01898 $value = strlen($newValue) ? $newValue : $value;
01899 }
01900 return $value;
01901 }
01902
01911 function checkValue_input_Eval($value,$evalArray,$is_in) {
01912 $res = Array();
01913 $newValue = $value;
01914 $set = true;
01915
01916 foreach($evalArray as $func) {
01917 switch($func) {
01918 case 'int':
01919 case 'year':
01920 case 'date':
01921 case 'datetime':
01922 case 'time':
01923 case 'timesec':
01924 $value = intval($value);
01925 break;
01926 case 'double2':
01927 $theDec = 0;
01928 for ($a=strlen($value); $a>0; $a--) {
01929 if (substr($value,$a-1,1)=='.' || substr($value,$a-1,1)==',') {
01930 $theDec = substr($value,$a);
01931 $value = substr($value,0,$a-1);
01932 break;
01933 }
01934 }
01935 $theDec = ereg_replace('[^0-9]','',$theDec).'00';
01936 $value = intval(str_replace(' ','',$value)).'.'.substr($theDec,0,2);
01937 break;
01938 case 'md5':
01939 if (strlen($value)!=32){$set=false;}
01940 break;
01941 case 'trim':
01942 $value = trim($value);
01943 break;
01944 case 'upper':
01945 $value = strtoupper($value);
01946 # $value = strtr($value, '', ''); // WILL make trouble with other charsets than ISO-8859-1, so what do we do here? PHP-function which can handle this for other charsets? Currently the browsers JavaScript will fix it.
01947 break;
01948 case 'lower':
01949 $value = strtolower($value);
01950 # $value = strtr($value, '', ''); // WILL make trouble with other charsets than ISO-8859-1, so what do we do here? PHP-function which can handle this for other charsets? Currently the browsers JavaScript will fix it.
01951 break;
01952 case 'required':
01953 if (!$value) {$set=0;}
01954 break;
01955 case 'is_in':
01956 $c=strlen($value);
01957 if ($c) {
01958 $newVal = '';
01959 for ($a=0;$a<$c;$a++) {
01960 $char = substr($value,$a,1);
01961 if (strstr($is_in,$char)) {
01962 $newVal.=$char;
01963 }
01964 }
01965 $value = $newVal;
01966 }
01967 break;
01968 case 'nospace':
01969 $value = str_replace(' ','',$value);
01970 break;
01971 case 'alpha':
01972 $value = ereg_replace('[^a-zA-Z]','',$value);
01973 break;
01974 case 'num':
01975 $value = ereg_replace('[^0-9]','',$value);
01976 break;
01977 case 'alphanum':
01978 $value = ereg_replace('[^a-zA-Z0-9]','',$value);
01979 break;
01980 case 'alphanum_x':
01981 $value = ereg_replace('[^a-zA-Z0-9_-]','',$value);
01982 break;
01983 default:
01984 if (substr($func, 0, 3) == 'tx_') {
01985 $evalObj = t3lib_div::getUserObj($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tce']['formevals'][$func].':&'.$func);
01986 if (is_object($evalObj) && method_exists($evalObj, 'evaluateFieldValue')) {
01987 $value = $evalObj->evaluateFieldValue($value, $is_in, $set);
01988 }
01989 }
01990 break;
01991 }
01992 }
01993 if ($set) {$res['value'] = $value;}
01994 return $res;
01995 }
01996
02008 function checkValue_group_select_processDBdata($valueArray,$tcaFieldConf,$id,$status,$type,$currentTable) {
02009 $tables = $type=='group'?$tcaFieldConf['allowed']:$tcaFieldConf['foreign_table'].','.$tcaFieldConf['neg_foreign_table'];
02010 $prep = $type=='group'?$tcaFieldConf['prepend_tname']:$tcaFieldConf['neg_foreign_table'];
02011
02012 $dbAnalysis = t3lib_div::makeInstance('t3lib_loadDBGroup');
02013 $dbAnalysis->registerNonTableValues=$tcaFieldConf['allowNonIdValues'] ? 1 : 0;
02014 $dbAnalysis->start(implode(',',$valueArray),$tables, '', 0, $currentTable, $tcaFieldConf);
02015
02016 if ($tcaFieldConf['MM']) {
02017 if ($status=='update') {
02018 $dbAnalysis->writeMM($tcaFieldConf['MM'],$id,$prep);
02019 } else {
02020 $this->dbAnalysisStore[] = array($dbAnalysis,$tcaFieldConf['MM'],$id,$prep);
02021 }
02022 $valueArray = $dbAnalysis->countItems();
02023 } elseif ($type == 'inline') {
02024 if ($tcaFieldConf['foreign_field']) {
02025
02026 $skipSorting = $this->callFromImpExp ? true : false;
02027
02028 $dbAnalysis->writeForeignField($tcaFieldConf, $id, 0, $skipSorting);
02029 $valueArray = $dbAnalysis->countItems();
02030 } else {
02031 $valueArray = $dbAnalysis->getValueArray($prep);
02032 if ($prep) {
02033
02034 $valueArray = $dbAnalysis->convertPosNeg($valueArray,$tcaFieldConf['foreign_table'],$tcaFieldConf['neg_foreign_table']);
02035 }
02036 }
02037 } else {
02038 $valueArray = $dbAnalysis->getValueArray($prep);
02039 if ($type=='select' && $prep) {
02040 $valueArray = $dbAnalysis->convertPosNeg($valueArray,$tcaFieldConf['foreign_table'],$tcaFieldConf['neg_foreign_table']);
02041 }
02042 }
02043
02044
02045 return $valueArray;
02046 }
02047
02054 function checkValue_group_select_explodeSelectGroupValue($value) {
02055 $valueArray = t3lib_div::trimExplode(',',$value,1);
02056 reset($valueArray);
02057 while(list($key,$newVal)=each($valueArray)) {
02058 $temp=explode('|',$newVal,2);
02059 $valueArray[$key] = str_replace(',','',str_replace('|','',rawurldecode($temp[0])));
02060 }
02061 return $valueArray;
02062 }
02063
02078 function checkValue_flex_procInData($dataPart,$dataPart_current,$uploadedFiles,$dataStructArray,$pParams,$callBackFunc='') {
02079 #debug(array($dataPart,$dataPart_current,$dataStructArray));
02080 if (is_array($dataPart)) {
02081 foreach($dataPart as $sKey => $sheetDef) {
02082 list ($dataStruct,$actualSheet) = t3lib_div::resolveSheetDefInDS($dataStructArray,$sKey);
02083 #debug(array($dataStruct,$actualSheet,$sheetDef,$actualSheet,$sKey));
02084 if (is_array($dataStruct) && $actualSheet==$sKey && is_array($sheetDef)) {
02085 foreach($sheetDef as $lKey => $lData) {
02086 $this->checkValue_flex_procInData_travDS(
02087 $dataPart[$sKey][$lKey],
02088 $dataPart_current[$sKey][$lKey],
02089 $uploadedFiles[$sKey][$lKey],
02090 $dataStruct['ROOT']['el'],
02091 $pParams,
02092 $callBackFunc,
02093 $sKey.'/'.$lKey.'/'
02094 );
02095 }
02096 }
02097 }
02098 }
02099
02100 return $dataPart;
02101 }
02102
02117 function checkValue_flex_procInData_travDS(&$dataValues,$dataValues_current,$uploadedFiles,$DSelements,$pParams,$callBackFunc,$structurePath) {
02118 if (is_array($DSelements)) {
02119
02120
02121 foreach($DSelements as $key => $dsConf) {
02122
02123
02124 if ($DSelements[$key]['type']=='array') {
02125 if (is_array($dataValues[$key]['el'])) {
02126 if ($DSelements[$key]['section']) {
02127 foreach($dataValues[$key]['el'] as $ik => $el) {
02128 $theKey = key($el);
02129 if (is_array($dataValues[$key]['el'][$ik][$theKey]['el'])) {
02130 $this->checkValue_flex_procInData_travDS(
02131 $dataValues[$key]['el'][$ik][$theKey]['el'],
02132 $dataValues_current[$key]['el'][$ik][$theKey]['el'],
02133 $uploadedFiles[$key]['el'][$ik][$theKey]['el'],
02134 $DSelements[$key]['el'][$theKey]['el'],
02135 $pParams,
02136 $callBackFunc,
02137 $structurePath.$key.'/el/'.$ik.'/'.$theKey.'/el/'
02138 );
02139 }
02140 }
02141 } else {
02142 if (!isset($dataValues[$key]['el'])) $dataValues[$key]['el']=array();
02143 $this->checkValue_flex_procInData_travDS(
02144 $dataValues[$key]['el'],
02145 $dataValues_current[$key]['el'],
02146 $uploadedFiles[$key]['el'],
02147 $DSelements[$key]['el'],
02148 $pParams,
02149 $callBackFunc,
02150 $structurePath.$key.'/el/'
02151 );
02152 }
02153 }
02154 } else {
02155 if (is_array($dsConf['TCEforms']['config']) && is_array($dataValues[$key])) {
02156 foreach($dataValues[$key] as $vKey => $data) {
02157
02158 if ($callBackFunc) {
02159 if (is_object($this->callBackObj)) {
02160 $res = $this->callBackObj->$callBackFunc(
02161 $pParams,
02162 $dsConf['TCEforms']['config'],
02163 $dataValues[$key][$vKey],
02164 $dataValues_current[$key][$vKey],
02165 $uploadedFiles[$key][$vKey],
02166 $structurePath.$key.'/'.$vKey.'/'
02167 );
02168 } else {
02169 $res = $this->$callBackFunc(
02170 $pParams,
02171 $dsConf['TCEforms']['config'],
02172 $dataValues[$key][$vKey],
02173 $dataValues_current[$key][$vKey],
02174 $uploadedFiles[$key][$vKey]
02175 );
02176 }
02177 } else {
02178 list($CVtable,$CVid,$CVcurValue,$CVstatus,$CVrealPid,$CVrecFID,$CVtscPID) = $pParams;
02179
02180 $res = $this->checkValue_SW(
02181 array(),
02182 $dataValues[$key][$vKey],
02183 $dsConf['TCEforms']['config'],
02184 $CVtable,
02185 $CVid,
02186 $dataValues_current[$key][$vKey],
02187 $CVstatus,
02188 $CVrealPid,
02189 $CVrecFID,
02190 '',
02191 $uploadedFiles[$key][$vKey],
02192 array(),
02193 $CVtscPID
02194 );
02195
02196
02197 if ($dataValues[$key]['_TRANSFORM_'.$vKey] == 'RTE' && !$this->dontProcessTransformations) {
02198
02199
02200 unset($dataValues[$key]['_TRANSFORM_'.$vKey]);
02201
02202 if (isset($res['value'])) {
02203
02204
02205 list(,,$recFieldName) = explode(':', $CVrecFID);
02206 $theTypeString = t3lib_BEfunc::getTCAtypeValue($CVtable,$this->checkValue_currentRecord);
02207 $specConf = t3lib_BEfunc::getSpecConfParts('',$dsConf['TCEforms']['defaultExtras']);
02208
02209
02210 $RTEsetup = $this->BE_USER->getTSConfig('RTE',t3lib_BEfunc::getPagesTSconfig($CVtscPID));
02211 $thisConfig = t3lib_BEfunc::RTEsetup($RTEsetup['properties'],$CVtable,$recFieldName,$theTypeString);
02212
02213
02214 $RTEobj = &t3lib_BEfunc::RTEgetObj();
02215 if (is_object($RTEobj)) {
02216 $res['value'] = $RTEobj->transformContent('db',$res['value'],$CVtable,$recFieldName,$this->checkValue_currentRecord,$specConf,$thisConfig,'',$CVrealPid);
02217 } else {
02218 debug('NO RTE OBJECT FOUND!');
02219 }
02220 }
02221 }
02222 }
02223
02224
02225 if (isset($res['value'])) {
02226 $dataValues[$key][$vKey] = $res['value'];
02227 }
02228 }
02229 }
02230 }
02231 }
02232 }
02233 }
02234
02235
02236
02237
02238
02239
02240
02241
02242
02243
02244
02245
02246
02247
02248
02249
02250
02251
02252
02253
02254
02255
02256
02263 function process_cmdmap() {
02264 global $TCA, $TYPO3_CONF_VARS;
02265
02266
02267 if ($this->BE_USER->workspace!==0 && $this->BE_USER->workspaceRec['freeze']) {
02268 $this->newlog('All editing in this workspace has been frozen!',1);
02269 return FALSE;
02270 }
02271
02272
02273 $hookObjectsArr = array();
02274 if (is_array ($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processCmdmapClass'])) {
02275 foreach ($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processCmdmapClass'] as $classRef) {
02276 $hookObjectsArr[] = &t3lib_div::getUserObj($classRef);
02277 }
02278 }
02279
02280
02281 reset($this->cmdmap);
02282 while(list($table,) = each($this->cmdmap)) {
02283
02284
02285 $modifyAccessList = $this->checkModifyAccessList($table);
02286 if (!$modifyAccessList) {
02287 $id = 0;
02288 $this->log($table,$id,2,0,1,"Attempt to modify table '%s' without permission",1,array($table));
02289 }
02290
02291
02292 if (isset($TCA[$table]) && !$this->tableReadOnly($table) && is_array($this->cmdmap[$table]) && $modifyAccessList) {
02293
02294
02295 foreach($this->cmdmap[$table] as $id => $incomingCmdArray) {
02296 if (is_array($incomingCmdArray)) {
02297
02298
02299 reset($incomingCmdArray);
02300 $command = key($incomingCmdArray);
02301 $value = current($incomingCmdArray);
02302
02303 foreach($hookObjectsArr as $hookObj) {
02304 if (method_exists($hookObj, 'processCmdmap_preProcess')) {
02305 $hookObj->processCmdmap_preProcess($command, $table, $id, $value, $this);
02306 }
02307 }
02308
02309
02310 $this->copyMappingArray = Array();
02311
02312
02313 switch ($command) {
02314 case 'move':
02315 $this->moveRecord($table,$id,$value);
02316 break;
02317 case 'copy':
02318 if ($table === 'pages') {
02319 $this->copyPages($id,$value);
02320 } else {
02321 $this->copyRecord($table,$id,$value,1);
02322 }
02323 break;
02324 case 'localize':
02325 $this->localize($table,$id,$value);
02326 break;
02327 case 'version':
02328 switch ((string)$value['action']) {
02329 case 'new':
02330 $versionizeTree = t3lib_div::intInRange(!isset($value['treeLevels'])?-1:$value['treeLevels'],-1,100);
02331 if ($table == 'pages' && $versionizeTree>=0) {
02332 $this->versionizePages($id,$value['label'],$versionizeTree);
02333 } else {
02334 $this->versionizeRecord($table,$id,$value['label']);
02335 }
02336 break;
02337 case 'swap':
02338 $this->version_swap($table,$id,$value['swapWith'],$value['swapIntoWS']);
02339 break;
02340 case 'clearWSID':
02341 $this->version_clearWSID($table,$id);
02342 break;
02343 case 'setStage':
02344 $idList = t3lib_div::trimExplode(',',$id,1);
02345 foreach($idList as $id) {
02346 $this->version_setStage($table,$id,$value['stageId'],$value['comment']?$value['comment']:$this->generalComment);
02347 }
02348 break;
02349 }
02350 break;
02351 case 'delete':
02352 $this->deleteAction($table, $id);
02353 break;
02354 case 'undelete':
02355 $this->undeleteRecord($table, $id);
02356 break;
02357 }
02358
02359 foreach($hookObjectsArr as $hookObj) {
02360 if (method_exists($hookObj, 'processCmdmap_postProcess')) {
02361 $hookObj->processCmdmap_postProcess($command, $table, $id, $value, $this);
02362 }
02363 }
02364
02365
02366 $this->copyMappingArray_merged= t3lib_div::array_merge_recursive_overrule($this->copyMappingArray_merged,$this->copyMappingArray);
02367 }
02368 }
02369 }
02370 }
02371
02372
02373 $this->remapListedDBRecords();
02374 }
02375
02376
02377
02378
02379
02380
02381
02382
02383
02384
02385
02386
02387
02388
02389
02390
02391
02403 function copyRecord($table,$uid,$destPid,$first=0,$overrideValues=array(),$excludeFields='') {
02404 global $TCA;
02405
02406 $uid = $origUid = intval($uid);
02407 if ($TCA[$table] && $uid) {
02408 t3lib_div::loadTCA($table);
02409
02410
02411
02412
02413
02414
02415
02416
02417
02418
02419
02420 if ($this->doesRecordExist($table,$uid,'show')) {
02421 $data = Array();
02422
02423 $nonFields = array_unique(t3lib_div::trimExplode(',','uid,perms_userid,perms_groupid,perms_user,perms_group,perms_everybody,t3ver_oid,t3ver_wsid,t3ver_id,t3ver_label,t3ver_state,t3ver_swapmode,t3ver_count,t3ver_stage,t3ver_tstamp,'.$excludeFields,1));
02424
02425
02426 $row = t3lib_BEfunc::getRecordWSOL($table,$uid);
02427 if (is_array($row)) {
02428
02429
02430 $theNewID = uniqid('NEW');
02431 $enableField = isset($TCA[$table]['ctrl']['enablecolumns']) ? $TCA[$table]['ctrl']['enablecolumns']['disabled'] : '';
02432 $headerField = $TCA[$table]['ctrl']['label'];
02433
02434
02435 $defaultData = $this->newFieldArray($table);
02436
02437
02438
02439 $copyAfterFields = $destPid<0 ? $this->fixCopyAfterDuplFields($table,$uid,abs($destPid),0) : array();
02440
02441
02442 $tscPID = t3lib_BEfunc::getTSconfig_pidValue($table,$uid,$destPid);
02443 $TSConfig = $this->getTCEMAIN_TSconfig($tscPID);
02444 $tE = $this->getTableEntries($table,$TSConfig);
02445
02446
02447 foreach($row as $field => $value) {
02448 if (!in_array($field,$nonFields)) {
02449
02450
02451 $conf = $TCA[$table]['columns'][$field]['config'];
02452
02453
02454 if ($field=='pid') {
02455 $value = $destPid;
02456 } elseif (isset($overrideValues[$field])) {
02457 $value = $overrideValues[$field];
02458 } elseif (isset($copyAfterFields[$field])) {
02459 $value = $copyAfterFields[$field];
02460 } elseif ($TCA[$table]['ctrl']['setToDefaultOnCopy'] && t3lib_div::inList($TCA[$table]['ctrl']['setToDefaultOnCopy'],$field)) {
02461 $value = $defaultData[$field];
02462 } else {
02463
02464 if ($first && $field==$enableField && $TCA[$table]['ctrl']['hideAtCopy'] && !$this->neverHideAtCopy && !$tE['disableHideAtCopy']) {
02465 $value=1;
02466 }
02467
02468 if ($first && $field==$headerField && $TCA[$table]['ctrl']['prependAtCopy'] && !$tE['disablePrependAtCopy']) {
02469 $value = $this->getCopyHeader($table,$this->resolvePid($table,$destPid),$field,$this->clearPrefixFromValue($table,$value),0);
02470 }
02471
02472 $value = $this->copyRecord_procBasedOnFieldType($table,$uid,$field,$value,$row,$conf,$tscPID);
02473 }
02474
02475
02476 $data[$table][$theNewID][$field] = $value;
02477 }
02478 }
02479
02480
02481 if ($TCA[$table]['ctrl']['editlock']) {
02482 $data[$table][$theNewID][$TCA[$table]['ctrl']['editlock']] = 0;
02483 }
02484
02485
02486 if ($TCA[$table]['ctrl']['origUid']) {
02487 $data[$table][$theNewID][$TCA[$table]['ctrl']['origUid']] = $uid;
02488 }
02489
02490
02491 $copyTCE = t3lib_div::makeInstance('t3lib_TCEmain');
02492 $copyTCE->stripslashes_values = 0;
02493 $copyTCE->copyTree = $this->copyTree;
02494 $copyTCE->cachedTSconfig = $this->cachedTSconfig;
02495 $copyTCE->dontProcessTransformations=1;
02496
02497 $copyTCE->start($data,'',$this->BE_USER);
02498 $copyTCE->process_datamap();
02499
02500
02501 $theNewSQLID = $copyTCE->substNEWwithIDs[$theNewID];
02502 if ($theNewSQLID) {
02503 $this->copyMappingArray[$table][$origUid] = $theNewSQLID;
02504 }
02505
02506
02507 $this->cachedTSconfig = $copyTCE->cachedTSconfig;
02508 $this->errorLog = array_merge($this->errorLog,$copyTCE->errorLog);
02509 unset($copyTCE);
02510
02511 return $theNewSQLID;
02512 } else $this->log($table,$uid,3,0,1,'Attempt to copy record that did not exist!');
02513 } else $this->log($table,$uid,3,0,1,'Attempt to copy record without permission');
02514 }
02515 }
02516
02525 function copyPages($uid,$destPid) {
02526
02527
02528 $uid = intval($uid);
02529 $destPid = intval($destPid);
02530
02531
02532 $copyTablesArray = $this->admin ? $this->compileAdminTables() : explode(',',$this->BE_USER->groupData['tables_modify']);
02533 if (!strstr($this->copyWhichTables,'*')) {
02534 foreach($copyTablesArray as $k => $table) {
02535 if (!$table || !t3lib_div::inList($this->copyWhichTables.',pages',$table)) {
02536 unset($copyTablesArray[$k]);
02537 }
02538 }
02539 }
02540 $copyTablesArray = array_unique($copyTablesArray);
02541
02542
02543 if ($this->admin || in_array('pages',$copyTablesArray)) {
02544
02545
02546 $theNewRootID = $this->copySpecificPage($uid,$destPid,$copyTablesArray,1);
02547
02548
02549 if ($theNewRootID && $this->copyTree) {
02550
02551
02552 $CPtable = $this->int_pageTreeInfo(Array(), $uid, intval($this->copyTree), $theNewRootID);
02553
02554
02555 foreach($CPtable as $thePageUid => $thePagePid) {
02556 $newPid = $this->copyMappingArray['pages'][$thePagePid];
02557 if (isset($newPid)) {
02558 $this->copySpecificPage($thePageUid,$newPid,$copyTablesArray);
02559 } else {
02560 $this->log('pages',$uid,5,0,1,'Something went wrong during copying branch');
02561 break;
02562 }
02563 }
02564 }
02565 } else {
02566 $this->log('pages',$uid,5,0,1,'Attempt to copy page without permission to this table');
02567 }
02568 }
02569
02579 function copySpecificPage($uid,$destPid,$copyTablesArray,$first=0) {
02580 global $TCA;
02581
02582
02583 $theNewRootID = $this->copyRecord('pages',$uid,$destPid,$first);
02584
02585
02586 if ($theNewRootID) {
02587 foreach($copyTablesArray as $table) {
02588 if ($table && is_array($TCA[$table]) && $table!='pages') {
02589 $mres = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid', $table, 'pid='.intval($uid).$this->deleteClause($table), '', ($TCA[$table]['ctrl']['sortby'] ? $TCA[$table]['ctrl']['sortby'].' DESC' : ''));
02590 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($mres)) {
02591 $this->copyRecord($table,$row['uid'], $theNewRootID);
02592 }
02593 }
02594 }
02595 return $theNewRootID;
02596 }
02597 }
02598
02613 function copyRecord_raw($table,$uid,$pid,$overrideArray=array()) {
02614 global $TCA;
02615
02616 $uid = intval($uid);
02617 if ($TCA[$table] && $uid) {
02618 t3lib_div::loadTCA($table);
02619 if ($this->doesRecordExist($table,$uid,'show')) {
02620
02621
02622 $nonFields = array('uid','pid','t3ver_id','t3ver_oid','t3ver_wsid','t3ver_label','t3ver_state','t3ver_swapmode','t3ver_count','t3ver_stage','t3ver_tstamp','perms_userid','perms_groupid','perms_user','perms_group','perms_everybody');
02623
02624
02625 $row = $this->recordInfo($table,$uid,'*');
02626 if (is_array($row)) {
02627
02628
02629 $row = array_merge($row,$overrideArray);
02630
02631
02632 foreach($row as $field => $value) {
02633 if (!in_array($field,$nonFields)) {
02634
02635
02636 $conf = $TCA[$table]['columns'][$field]['config'];
02637 if (is_array($conf)) {
02638
02639 $value = $this->copyRecord_procBasedOnFieldType($table,$uid,$field,$value,$row,$conf,$pid);
02640 }
02641
02642
02643 $row[$field] = $value;
02644 }
02645 }
02646
02647
02648 $row['pid'] = $pid;
02649
02650
02651 if ($TCA[$table]['ctrl']['origUid']) {
02652 $row[$TCA[$table]['ctrl']['origUid']] = $uid;
02653 }
02654
02655
02656 $theNewSQLID = $this->insertNewCopyVersion($table,$row,$pid);
02657 if ($theNewSQLID) {
02658 $this->dbAnalysisStoreExec();
02659 $this->dbAnalysisStore = array();
02660 return $this->copyMappingArray[$table][$uid] = $theNewSQLID;
02661 }
02662 } else $this->log($table,$uid,3,0,1,'Attempt to rawcopy/versionize record that did not exist!');
02663 } else $this->log($table,$uid,3,0,1,'Attempt to rawcopy/versionize record without copy permission');
02664 }
02665 }
02666
02677 function rawCopyPageContent($old_pid,$new_pid,$copyTablesArray) {
02678 global $TCA;
02679
02680 if ($new_pid) {
02681 foreach($copyTablesArray as $table) {
02682 if ($table && is_array($TCA[$table]) && $table!='pages') {
02683 $mres = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid', $table, 'pid='.intval($old_pid).$this->deleteClause($table));
02684 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($mres)) {
02685 $this->copyRecord_raw($table,$row['uid'],$new_pid);
02686 }
02687 }
02688 }
02689 }
02690 }
02691
02701 function insertNewCopyVersion($table,$fieldArray,$realPid) {
02702 global $TCA;
02703
02704 $id = uniqid('NEW');
02705
02706
02707
02708 $this->checkValue_currentRecord = $fieldArray;
02709
02710
02711 foreach($fieldArray as $field => $fieldValue) {
02712 if (isset($TCA[$table]['columns'][$field])) {
02713
02714 $res = $this->checkValue($table,$field,$fieldValue,$id,'new',$realPid,0);
02715 if (isset($res['value'])) {
02716 $fieldArray[$field] = $res['value'];
02717 }
02718 }
02719 }
02720
02721
02722 if ($TCA[$table]['ctrl']['crdate']) {
02723 $fieldArray[$TCA[$table]['ctrl']['crdate']]=time();
02724 }
02725 if ($TCA[$table]['ctrl']['cruser_id']) {
02726 $fieldArray[$TCA[$table]['ctrl']['cruser_id']]=$this->userid;
02727 }
02728 if ($TCA[$table]['ctrl']['tstamp']) {
02729 $fieldArray[$TCA[$table]['ctrl']['tstamp']]=time();
02730 }
02731
02732
02733 $this->insertDB($table,$id,$fieldArray, TRUE);
02734
02735
02736 return $this->substNEWwithIDs[$id];
02737 }
02738
02753 function copyRecord_procBasedOnFieldType($table,$uid,$field,$value,$row,$conf,$realDestPid) {
02754 global $TCA;
02755
02756
02757 $value = $this->copyRecord_procFilesRefs($conf, $uid, $value);
02758 $inlineSubType = $this->getInlineFieldType($conf);
02759
02760
02761 if ($this->isReferenceField($conf) || $inlineSubType == 'mm') {
02762 $allowedTables = $conf['type']=='group' ? $conf['allowed'] : $conf['foreign_table'].','.$conf['neg_foreign_table'];
02763 $prependName = $conf['type']=='group' ? $conf['prepend_tname'] : $conf['neg_foreign_table'];
02764 if ($conf['MM']) {
02765 $dbAnalysis = t3lib_div::makeInstance('t3lib_loadDBGroup');
02766 $dbAnalysis->start('', $allowedTables, $conf['MM'], $uid, $table, $conf);
02767 $value = implode(',',$dbAnalysis->getValueArray($prependName));
02768 }
02769 if ($value) {
02770 $this->registerDBList[$table][$uid][$field] = $value;
02771 }
02772
02773
02774 } elseif ($inlineSubType !== false) {
02775 $dbAnalysis = t3lib_div::makeInstance('t3lib_loadDBGroup');
02776 $dbAnalysis->start($value, $conf['foreign_table'], $conf['MM'], $uid, $table, $conf);
02777
02778
02779 foreach ($dbAnalysis->itemArray as $k => $v) {
02780
02781 if (t3lib_div::testInt($realDestPid) && $realDestPid >= 0) {
02782 $childDestPid = $realDestPid;
02783
02784
02785 } else {
02786 $childDestPid = -$v['id'];
02787 }
02788 $newId = $this->copyRecord($v['table'], $v['id'], $childDestPid);
02789 $dbAnalysis->itemArray[$k]['id'] = $newId;
02790 }
02791
02792
02793 $value = implode(',',$dbAnalysis->getValueArray());
02794 $this->registerDBList[$table][$uid][$field] = $value;
02795 }
02796
02797
02798 if ($conf['type']=='flex') {
02799
02800
02801 $dataStructArray = t3lib_BEfunc::getFlexFormDS($conf, $row, $table);
02802 $currentValueArray = t3lib_div::xml2array($value);
02803
02804
02805 if (is_array($currentValueArray)) {
02806 $currentValueArray['data'] = $this->checkValue_flex_procInData(
02807 $currentValueArray['data'],
02808 array(),
02809 array(),
02810 $dataStructArray,
02811 array($table,$uid,$field),
02812 'copyRecord_flexFormCallBack'
02813 );
02814 $value = $currentValueArray;
02815 }
02816 }
02817
02818 return $value;
02819 }
02820
02832 function copyRecord_flexFormCallBack($pParams, $dsConf, $dataValue, $dataValue_ext1, $dataValue_ext2) {
02833
02834
02835 list($table, $uid, $field) = $pParams;
02836
02837
02838 $dataValue = $this->copyRecord_procFilesRefs($dsConf, $uid, $dataValue);
02839
02840
02841 if ($this->isReferenceField($dsConf) && strlen($dataValue)) {
02842 $this->registerDBList[$table][$uid][$field] = 'FlexForm_reference';
02843 }
02844
02845
02846 return array('value' => $dataValue);
02847 }
02848
02860 function copyRecord_procFilesRefs($conf, $uid, $value) {
02861
02862
02863 if ($conf['type']=='group' && $conf['internal_type']=='file') {
02864
02865
02866 if ($conf['MM']) {
02867 $theFileValues = array();
02868
02869 $dbAnalysis = t3lib_div::makeInstance('t3lib_loadDBGroup');
02870 $dbAnalysis->start('', 'files', $conf['MM'], $uid);
02871
02872 foreach($dbAnalysis->itemArray as $somekey => $someval) {
02873 if ($someval['id']) {
02874 $theFileValues[] = $someval['id'];
02875 }
02876 }
02877 } else {
02878 $theFileValues = t3lib_div::trimExplode(',',$value,1);
02879 }
02880
02881
02882 $uploadFolder = $conf['uploadfolder'];
02883 $dest = $this->destPathFromUploadFolder($uploadFolder);
02884 $newValue = array();
02885
02886 foreach($theFileValues as $file) {
02887 if (trim($file)) {
02888 $realFile = $dest.'/'.trim($file);
02889 if (@is_file($realFile)) {
02890 $newValue[] = $realFile;
02891 }
02892 }
02893 }
02894
02895
02896 $value = implode(',',$newValue);
02897 }
02898
02899
02900 return $value;
02901 }
02902
02903
02904
02905
02906
02907
02908
02909
02910
02911
02912
02913
02914
02915
02916
02917
02918
02919
02920
02929 function moveRecord($table,$uid,$destPid) {
02930 global $TCA, $TYPO3_CONF_VARS;
02931
02932 if ($TCA[$table]) {
02933
02934
02935 $hookObjectsArr = array();
02936 if (is_array ($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['moveRecordClass'])) {
02937 foreach ($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['moveRecordClass'] as $classRef) {
02938 $hookObjectsArr[] = &t3lib_div::getUserObj($classRef);
02939 }
02940 }
02941
02942
02943 if ($lookForLiveVersion = t3lib_BEfunc::getLiveVersionOfRecord($table,$uid,'uid')) {
02944 $uid = $lookForLiveVersion['uid'];
02945 }
02946
02947
02948 $WSversion = t3lib_BEfunc::getWorkspaceVersionOfRecord($this->BE_USER->workspace, $table, $uid, 'uid,t3ver_oid');
02949
02950
02951 $sortRow = $TCA[$table]['ctrl']['sortby'];
02952 $destPid = intval($destPid);
02953 $origDestPid = $destPid;
02954
02955 $propArr = $this->getRecordProperties($table,$uid);
02956 $moveRec = $this->getRecordProperties($table,$uid,TRUE);
02957 $resolvedPid = $this->resolvePid($table,$destPid);
02958
02959
02960
02961 if ($table!='pages' || $resolvedPid==$moveRec['pid']) {
02962 $mayMoveAccess = $this->checkRecordUpdateAccess($table,$uid);
02963 } else {
02964 $mayMoveAccess = $this->doesRecordExist($table,$uid,'delete');
02965 }
02966
02967
02968 if ($table!='pages' || $resolvedPid!=$moveRec['pid']) {
02969 $mayInsertAccess = $this->checkRecordInsertAccess($table,$resolvedPid,4);
02970 } else {
02971 $mayInsertAccess = $this->checkRecordUpdateAccess($table,$uid);
02972 }
02973
02974
02975 $workspaceAccessBlocked = array();
02976 $recIsNewVersion = !strcmp($moveRec['_ORIG_pid'],'') && (int)$moveRec['t3ver_state']==1;
02977 $destRes = $this->BE_USER->workspaceAllowLiveRecordsInPID($resolvedPid,$table);
02978
02979 if ($errorCode = $this->BE_USER->workspaceCannotEditRecord($table, $WSversion['uid'] ? $WSversion['uid'] : $uid)) {
02980 $workspaceAccessBlocked['src1']='Record could not be edited in workspace: '.$errorCode.' ';
02981 } else {
02982 if (!$recIsNewVersion && $this->BE_USER->workspaceAllowLiveRecordsInPID($moveRec['pid'],$table)<=0) {
02983 $workspaceAccessBlocked['src2']='Could not remove record from table "'.$table.'" from its page "'.$moveRec['pid'].'" ';
02984 }
02985 }
02986
02987 if (!($destRes>0 || ($recIsNewVersion && !$destRes))) {
02988 $workspaceAccessBlocked['dest1']='Could not insert record from table "'.$table.'" in destination PID "'.$resolvedPid.'" ';
02989 } elseif ($destRes==1 && $WSversion['uid']) {
02990 $workspaceAccessBlocked['dest2']='Could not insert other versions in destination PID ';
02991 }
02992
02993
02994 if (($destPid<0 && !$sortRow) || $destPid>=0) {
02995 $destPid = $resolvedPid;
02996 }
02997
02998
02999 $updateFields = array();
03000 if ($TCA[$table]['ctrl']['tstamp']) {
03001 $updateFields[$TCA[$table]['ctrl']['tstamp']] = time();
03002 }
03003
03004
03005 if (!count($workspaceAccessBlocked)) {
03006 if ($mayMoveAccess) {
03007 if ($destPid>=0) {
03008 if ($mayInsertAccess) {
03009 if ($table!='pages' || $this->destNotInsideSelf($destPid,$uid)) {
03010 $this->clear_cache($table,$uid);
03011
03012 $updateFields['pid'] = $destPid;
03013
03014
03015 if ($sortRow) {
03016 $sortNumber = $this->getSortNumber($table,$uid,$destPid);
03017 $updateFields[$sortRow] = $sortNumber;
03018 }
03019
03020
03021 $this->moveRecord_procFields($table,$uid,$destPid);
03022
03023 $GLOBALS['TYPO3_DB']->exec_UPDATEquery($table, 'uid='.intval($uid), $updateFields);
03024
03025
03026 foreach($hookObjectsArr as $hookObj) {
03027 if (method_exists($hookObj, 'moveRecord_firstElementPostProcess')) {
03028 $hookObj->moveRecord_firstElementPostProcess($table, $uid, $destPid, $moveRec, $updateFields, $this);
03029 }
03030 }
03031
03032
03033 $newPropArr = $this->getRecordProperties($table,$uid);
03034 $oldpagePropArr = $this->getRecordProperties('pages',$propArr['pid']);
03035 $newpagePropArr = $this->getRecordProperties('pages',$destPid);
03036
03037 if ($destPid!=$propArr['pid']) {
03038 $this->log($table,$uid,4,$destPid,0,"Moved record '%s' (%s) to page '%s' (%s)",2,array($propArr['header'],$table.':'.$uid, $newpagePropArr['header'], $newPropArr['pid']),$propArr['pid']);
03039 $this->log($table,$uid,4,$destPid,0,"Moved record '%s' (%s) from page '%s' (%s)",3,array($propArr['header'],$table.':'.$uid, $oldpagePropArr['header'], $propArr['pid']),$destPid);
03040 } else {
03041 $this->log($table,$uid,4,$destPid,0,"Moved record '%s' (%s) on page '%s' (%s)",4,array($propArr['header'],$table.':'.$uid, $oldpagePropArr['header'], $propArr['pid']),$destPid);
03042 }
03043 $this->clear_cache($table,$uid);
03044 $this->fixUniqueInPid($table,$uid);
03045
03046 if ($origDestPid<0) {$this->fixCopyAfterDuplFields($table,$uid,abs($origDestPid),1);}
03047 } else {
03048 $destPropArr = $this->getRecordProperties('pages',$destPid);
03049 $this->log($table,$uid,4,0,1,"Attempt to move page '%s' (%s) to inside of its own rootline (at page '%s' (%s))",10,array($propArr['header'],$uid, $destPropArr['header'], $destPid),$propArr['pid']);
03050 }
03051 }
03052 } else {
03053 if ($sortRow) {
03054 $sortInfo = $this->getSortNumber($table,$uid,$destPid);
03055 $destPid = $sortInfo['pid'];
03056 if (is_array($sortInfo)) {
03057 if ($mayInsertAccess) {
03058 if ($table!='pages' || $this->destNotInsideSelf($destPid,$uid)) {
03059 $this->clear_cache($table,$uid);
03060
03061
03062 $updateFields['pid'] = $destPid;
03063 $updateFields[$sortRow] = $sortInfo['sortNumber'];
03064
03065
03066 $this->moveRecord_procFields($table,$uid,$destPid);
03067
03068 $GLOBALS['TYPO3_DB']->exec_UPDATEquery($table, 'uid='.intval($uid), $updateFields);
03069
03070
03071 foreach($hookObjectsArr as $hookObj) {
03072 if (method_exists($hookObj, 'moveRecord_afterAnotherElementPostProcess')) {
03073 $hookObj->moveRecord_afterAnotherElementPostProcess($table, $uid, $destPid, $origDestPid, $moveRec, $updateFields, $this);
03074 }
03075 }
03076
03077
03078 $newPropArr = $this->getRecordProperties($table,$uid);
03079 $oldpagePropArr = $this->getRecordProperties('pages',$propArr['pid']);
03080 if ($destPid!=$propArr['pid']) {
03081 $newpagePropArr = $this->getRecordProperties('pages',$destPid);
03082 $this->log($table,$uid,4,0,0,"Moved record '%s' (%s) to page '%s' (%s)",2,array($propArr['header'],$table.':'.$uid, $newpagePropArr['header'], $newPropArr['pid']),$propArr['pid']);
03083 $this->log($table,$uid,4,0,0,"Moved record '%s' (%s) from page '%s' (%s)",3,array($propArr['header'],$table.':'.$uid, $oldpagePropArr['header'], $propArr['pid']),$destPid);
03084 } else {
03085 $this->log($table,$uid,4,0,0,"Moved record '%s' (%s) on page '%s' (%s)",4,array($propArr['header'],$table.':'.$uid, $oldpagePropArr['header'], $propArr['pid']),$destPid);
03086 }
03087
03088
03089 $this->clear_cache($table,$uid);
03090
03091
03092 $this->fixUniqueInPid($table,$uid);
03093
03094
03095 if ($origDestPid<0) {$this->fixCopyAfterDuplFields($table,$uid,abs($origDestPid),1);}
03096 } else {
03097 $destPropArr = $this->getRecordProperties('pages',$destPid);
03098 $this->log($table,$uid,4,0,1,"Attempt to move page '%s' (%s) to inside of its own rootline (at page '%s' (%s))",10,array($propArr['header'],$uid, $destPropArr['header'], $destPid),$propArr['pid']);
03099 }
03100 }
03101 }
03102 } else {
03103 $this->log($table,$uid,4,0,1,"Attempt to move record '%s' (%s) to after another record, although the table has no sorting row.",13,array($propArr['header'],$table.':'.$uid),$propArr['event_pid']);
03104 }
03105 }
03106 } else {
03107 $this->log($table,$uid,4,0,1,"Attempt to move record '%s' (%s) without having permissions to do so",14,array($propArr['header'],$table.':'.$uid),$propArr['event_pid']);
03108 }
03109 } else {
03110 $this->newlog("Move attempt failed due to workspace restrictions: ".implode(' ',$workspaceAccessBlocked),1);
03111 }
03112 }
03113 }
03114
03124 function moveRecord_procFields($table,$uid,$destPid) {
03125 t3lib_div::loadTCA($table);
03126 $conf = $GLOBALS['TCA'][$table]['columns'];
03127 $row = t3lib_BEfunc::getRecordWSOL($table,$uid);
03128 foreach ($row as $field => $value) {
03129 $this->moveRecord_procBasedOnFieldType($table,$uid,$destPid,$field,$value,$conf[$field]['config']);
03130 }
03131 }
03132
03144 function moveRecord_procBasedOnFieldType($table,$uid,$destPid,$field,$value,$conf) {
03145 $moveTable = '';
03146 $moveIds = array();
03147
03148 if ($conf['type'] == 'inline') {
03149 $foreign_table = $conf['foreign_table'];
03150
03151 if ($foreign_table) {
03152 $inlineType = $this->getInlineFieldType($conf);
03153 if ($inlineType == 'list' || $inlineType == 'field') {
03154 $moveTable = $foreign_table;
03155 $dbAnalysis = t3lib_div::makeInstance('t3lib_loadDBGroup');
03156 $dbAnalysis->start($value, $conf['foreign_table'], '', $uid, $table, $conf);
03157 }
03158 }
03159 }
03160
03161
03162 if (isset($dbAnalysis)) {
03163 foreach ($dbAnalysis->itemArray as $v) {
03164 $this->moveRecord($v['table'],$v['id'],$destPid);
03165 }
03166 }
03167 }
03168
03178 function localize($table,$uid,$language) {
03179 global $TCA;
03180
03181 $uid = intval($uid);
03182
03183 if ($TCA[$table] && $uid) {
03184 t3lib_div::loadTCA($table);
03185
03186 if (($TCA[$table]['ctrl']['languageField'] && $TCA[$table]['ctrl']['transOrigPointerField'] && !$TCA[$table]['ctrl']['transOrigPointerTable']) || $table==='pages') {
03187 if ($langRec = t3lib_BEfunc::getRecord('sys_language',intval($language),'uid,title')) {
03188 if ($this->doesRecordExist($table,$uid,'show')) {
03189
03190 $row = t3lib_BEfunc::getRecordWSOL($table,$uid);
03191 if (is_array($row)) {
03192 if ($row[$TCA[$table]['ctrl']['languageField']] <= 0 || $table==='pages') {
03193 if ($row[$TCA[$table]['ctrl']['transOrigPointerField']] == 0 || $table==='pages') {
03194 if ($table==='pages') {
03195 $pass = $TCA[$table]['ctrl']['transForeignTable']==='pages_language_overlay' && !t3lib_BEfunc::getRecordsByField('pages_language_overlay','pid',$uid,' AND '.$TCA['pages_language_overlay']['ctrl']['languageField'].'='.intval($langRec['uid']));
03196 $Ttable = 'pages_language_overlay';
03197 t3lib_div::loadTCA($Ttable);
03198 } else {
03199 $pass = !t3lib_BEfunc::getRecordsByField($table,$TCA[$table]['ctrl']['transOrigPointerField'],$uid,'AND pid='.intval($row['pid']).' AND '.$TCA[$table]['ctrl']['languageField'].'='.intval($langRec['uid']));
03200 $Ttable = $table;
03201 }
03202
03203 if ($pass) {
03204
03205
03206 $overrideValues = array();
03207 $excludeFields = array();
03208
03209
03210 $overrideValues[$TCA[$Ttable]['ctrl']['languageField']] = $langRec['uid'];
03211 $overrideValues[$TCA[$Ttable]['ctrl']['transOrigPointerField']] = $uid;
03212
03213
03214 foreach($TCA[$Ttable]['columns'] as $fN => $fCfg) {
03215 if ($fCfg['l10n_mode']=='prefixLangTitle') {
03216 if (($fCfg['config']['type']=='text' || $fCfg['config']['type']=='input') && strlen($row[$fN])) {
03217 list($tscPID) = t3lib_BEfunc::getTSCpid($table,$uid,'');
03218 $TSConfig = $this->getTCEMAIN_TSconfig($tscPID);
03219
03220 if (isset($TSConfig['translateToMessage']) && strlen($TSConfig['translateToMessage'])) {
03221 $translateToMsg = @sprintf($TSConfig['translateToMessage'], $langRec['title']);
03222 }
03223 if (!strlen($translateToMsg)) {
03224 $translateToMsg = 'Translate to '.$langRec['title'].':';
03225 }
03226
03227 $overrideValues[$fN] = '['.$translateToMsg.'] '.$row[$fN];
03228 }
03229 } elseif (t3lib_div::inList('exclude,noCopy,mergeIfNotBlank',$fCfg['l10n_mode']) && $fN!=$TCA[$Ttable]['ctrl']['languageField'] && $fN!=$TCA[$Ttable]['ctrl']['transOrigPointerField']) {
03230 $excludeFields[] = $fN;
03231 }
03232 }
03233
03234 if ($Ttable === $table) {
03235
03236
03237 $this->copyRecord($table,$uid,-$uid,1,$overrideValues,implode(',',$excludeFields));
03238 } else {
03239
03240
03241 $copyTCE = t3lib_div::makeInstance('t3lib_TCEmain');
03242 $copyTCE->stripslashes_values = 0;
03243 $copyTCE->cachedTSconfig = $this->cachedTSconfig;
03244 $copyTCE->dontProcessTransformations=1;
03245
03246 $copyTCE->start(array($Ttable=>array('NEW'=>$overrideValues)),'',$this->BE_USER);
03247 $copyTCE->process_datamap();
03248
03249
03250 $theNewSQLID = $copyTCE->substNEWwithIDs['NEW'];
03251 if ($theNewSQLID) {
03252
03253 $this->copyMappingArray[$Ttable][$uid] = $theNewSQLID;
03254 }
03255 }
03256 } else $this->newlog('Localization failed; There already was a localization for this language of the record!',1);
03257 } else $this->newlog('Localization failed; Source record contained a reference to an original default record (which is strange)!',1);
03258 } else $this->newlog('Localization failed; Source record had another language than "Default" or "All" defined!',1);
03259 } else $this->newlog('Attempt to localize record that did not exist!',1);
03260 } else $this->newlog('Attempt to localize record without permission',1);
03261 } else $this->newlog('Sys language UID "'.$language.'" not found valid!',1);
03262 } else $this->newlog('Localization failed; "languageField" and "transOrigPointerField" must be defined for the table!',1);
03263 }
03264 }
03265
03266
03267
03268
03269
03270
03271
03272
03273
03274
03275
03276
03277
03278
03279
03280
03281
03282
03283
03284
03292 function deleteAction($table, $id) {
03293 global $TCA;
03294
03295 $delRec = t3lib_BEfunc::getRecord($table, $id);
03296
03297 if (is_array($delRec)) {
03298
03299
03300 if ($delRec['pid']!=-1) {
03301 if ($wsVersion = t3lib_BEfunc::getWorkspaceVersionOfRecord($this->BE_USER->workspace, $table, $id)) {
03302 $delRec = $wsVersion;
03303 $id = $delRec['uid'];
03304 }
03305 }
03306
03307 if ($delRec['pid']==-1) {
03308 if ($TCA[$table]['ctrl']['versioningWS']) {
03309 if ($this->BE_USER->workspace==0 || (int)$delRec['t3ver_wsid']==$this->BE_USER->workspace) {
03310 $liveRec = t3lib_BEfunc::getLiveVersionOfRecord($table,$id,'uid,t3ver_state');
03311
03312 if ($delRec['t3ver_wsid']==0 || (int)$liveRec['t3ver_state']!==1) {
03313 $this->deleteEl($table, $id);
03314 } else {
03315 $this->version_clearWSID($table,$id);
03316 }
03317 } else $this->newlog('Tried to delete record from another workspace',1);
03318 } else $this->newlog('Versioning not enabled for record with PID = -1!',2);
03319 } elseif ($res = $this->BE_USER->workspaceAllowLiveRecordsInPID($delRec['pid'], $table)) {
03320 if ($res>0) {
03321 $this->deleteEl($table, $id);
03322 } else $this->newlog('Stage of root point did not allow for deletion',1);
03323 } else {
03324
03325 $this->versionizeRecord($table,$id,'DELETED!',TRUE);
03326 }
03327 }
03328 }
03329
03339 function deleteEl($table, $uid, $noRecordCheck=FALSE, $forceHardDelete=FALSE) {
03340 if ($table == 'pages') {
03341 $this->deletePages($uid, $noRecordCheck, $forceHardDelete);
03342 } else {
03343 $this->deleteVersionsForRecord($table,$uid,$forceHardDelete);
03344 $this->deleteRecord($table, $uid, $noRecordCheck, $forceHardDelete);
03345 }
03346 }
03347
03356 function deleteVersionsForRecord($table, $uid, $forceHardDelete) {
03357 $versions = t3lib_BEfunc::selectVersionsOfRecord($table, $uid, 'uid,pid');
03358 if (is_array($versions)) {
03359 foreach($versions as $verRec) {
03360 if (!$verRec['_CURRENT_VERSION']) {
03361 if ($table == 'pages') {
03362 $this->deletePages($verRec['uid'], TRUE, $forceHardDelete);
03363 } else {
03364 $this->deleteRecord($table, $verRec['uid'], TRUE, $forceHardDelete);
03365 }
03366 }
03367 }
03368 }
03369 }
03370
03378 function undeleteRecord($table,$uid) {
03379 $this->deleteRecord($table,$uid,TRUE,FALSE,TRUE);
03380 }
03381
03395 function deleteRecord($table,$uid, $noRecordCheck=FALSE, $forceHardDelete=FALSE,$undeleteRecord=FALSE) {
03396 global $TCA;
03397
03398 $uid = intval($uid);
03399 if ($TCA[$table] && $uid) {
03400 if ($noRecordCheck || $this->doesRecordExist($table,$uid,'delete')) {
03401 $this->clear_cache($table,$uid);
03402
03403 $propArr = $this->getRecordProperties($table, $uid);
03404 $pagePropArr = $this->getRecordProperties('pages', $propArr['pid']);
03405
03406 $deleteRow = $TCA[$table]['ctrl']['delete'];
03407 if ($deleteRow && !$forceHardDelete) {
03408 $value = $undeleteRecord ? 0 : 1;
03409 $updateFields = array(
03410 $deleteRow => $value
03411 );
03412
03413 if ($TCA[$table]['ctrl']['tstamp']) {
03414 $updateFields[$TCA[$table]['ctrl']['tstamp']] = time();
03415 }
03416
03417
03418 if ($TCA[$table]['ctrl']['sortby'] && !$undeleteRecord) {
03419 $updateFields[$TCA[$table]['ctrl']['sortby']] = 1000000000;
03420 }
03421
03422
03423 $this->deleteRecord_procFields($table, $uid, $undeleteRecord);
03424 $GLOBALS['TYPO3_DB']->exec_UPDATEquery($table, 'uid='.intval($uid), $updateFields);
03425 } else {
03426
03427
03428 t3lib_div::loadTCA($table);
03429 foreach($TCA[$table]['columns'] as $fieldName => $cfg) {
03430 $conf = $cfg['config'];
03431
03432 switch($conf['type']) {
03433 case 'flex':
03434 $flexObj = t3lib_div::makeInstance('t3lib_flexformtools');
03435 $flexObj->traverseFlexFormXMLData($table,$fieldName,t3lib_BEfunc::getRecordRaw($table,'uid='.intval($uid)),$this,'deleteRecord_flexFormCallBack');
03436 break;
03437 }
03438 }
03439
03440
03441 $fileFieldArr = $this->extFileFields($table);
03442 if (count($fileFieldArr)) {
03443 $mres = $GLOBALS['TYPO3_DB']->exec_SELECTquery(implode(',',$fileFieldArr), $table, 'uid='.intval($uid));
03444 if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($mres)) {
03445 $fArray = $fileFieldArr;
03446 foreach($fArray as $theField) {
03447 $this->extFileFunctions($table,$theField,$row[$theField],'deleteAll');
03448 }
03449 } else {
03450 $this->log($table,$uid,3,0,100,'Delete: Zero rows in result when trying to read filenames from record which should be deleted');
03451 }
03452 }
03453
03454
03455 $GLOBALS['TYPO3_DB']->exec_DELETEquery($table, 'uid='.intval($uid));
03456 }
03457
03458 $state = $undeleteRecord ? 1 : 3;
03459 if (!$GLOBALS['TYPO3_DB']->sql_error()) {
03460 if ($forceHardDelete) {
03461 $message = "Record '%s' (%s) was deleted unrecoverable from page '%s' (%s)";
03462 }
03463 else {
03464 $message = $state == 1 ?
03465 "Record '%s' (%s) was restored on page '%s' (%s)" :
03466 "Record '%s' (%s) was deleted from page '%s' (%s)";
03467 }
03468 $this->log($table, $uid, $state, 0, 0,
03469 $message, 0,
03470 array(
03471 $propArr['header'],
03472 $table.':'.$uid,
03473 $pagePropArr['header'],
03474 $propArr['pid']
03475 ),
03476 $propArr['pid']);
03477
03478 } else {
03479 $this->log($table,$uid,$state,0,100,$GLOBALS['TYPO3_DB']->sql_error());
03480 }
03481
03482
03483 $this->updateRefIndex($table,$uid);
03484
03485
03486 if (is_array($this->updateRefIndexStack[$table]) && is_array($this->updateRefIndexStack[$table][$uid])) {
03487 while ($args = array_pop($this->updateRefIndexStack[$table][$uid])) {
03488
03489 $this->updateRefIndex($args[0], $args[1]);
03490 }
03491 unset($this->updateRefIndexStack[$table][$uid]);
03492 }
03493
03494 } else $this->log($table,$uid,3,0,1,'Attempt to delete record without delete-permissions');
03495 }
03496 }
03497
03501 function deleteRecord_flexFormCallBack($dsArr, $dataValue, $PA, $structurePath, &$pObj) {
03502
03503
03504 $refIndexObj = t3lib_div::makeInstance('t3lib_refindex');
03505 $files = $refIndexObj->getRelations_procFiles($dataValue, $dsArr['TCEforms']['config'], $PA['uid']);
03506
03507
03508 if (is_array($files)) {
03509 foreach($files as $dat) {
03510 if (@is_file($dat['ID_absFile'])) {
03511 unlink ($dat['ID_absFile']);
03512 #echo 'DELETE FlexFormFile:'.$dat['ID_absFile'].chr(10);
03513 } else {
03514 $this->log($table,0,3,0,100,"Delete: Referenced file '".$dat['ID_absFile']."' that was supposed to be deleted together with it's record didn't exist");
03515 }
03516 }
03517 }
03518 }
03519
03528 function deletePages($uid,$force=FALSE,$forceHardDelete=FALSE) {
03529
03530 if ($force) {
03531 $brExist = $this->doesBranchExist('',$uid,0,1);
03532 $res = t3lib_div::trimExplode(',',$brExist.$uid,1);
03533 } else {
03534 $res = $this->canDeletePage($uid);
03535 }
03536
03537
03538 if (is_array($res)) {
03539 foreach($res as $deleteId) {
03540 $this->deleteSpecificPage($deleteId,$forceHardDelete);
03541 }
03542 } else {
03543 $this->newlog($res,1);
03544 }
03545 }
03546
03556 function deleteSpecificPage($uid,$forceHardDelete=FALSE) {
03557 global $TCA;
03558 reset ($TCA);
03559 $uid = intval($uid);
03560 if ($uid) {
03561 while (list($table)=each($TCA)) {
03562 if ($table!='pages') {
03563 $mres = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid', $table, 'pid='.intval($uid).$this->deleteClause($table));
03564 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($mres)) {
03565 $this->deleteVersionsForRecord($table,$row['uid'],$forceHardDelete);
03566 $this->deleteRecord($table,$row['uid'], TRUE, $forceHardDelete);
03567 }
03568 }
03569 }
03570 $this->deleteVersionsForRecord('pages',$uid,$forceHardDelete);
03571 $this->deleteRecord('pages',$uid, TRUE, $forceHardDelete);
03572 }
03573 }
03574
03581 function canDeletePage($uid) {
03582 if ($this->doesRecordExist('pages',$uid,'delete')) {
03583 if ($this->deleteTree) {
03584 $brExist = $this->doesBranchExist('',$uid,$this->pMap['delete'],1);
03585 if ($brExist != -1) {
03586 if ($this->noRecordsFromUnallowedTables($brExist.$uid)) {
03587 return t3lib_div::trimExplode(',',$brExist.$uid,1);
03588 } else return 'Attempt to delete records from disallowed tables';
03589 } else return 'Attempt to delete pages in branch without permissions';
03590 } else {
03591 $brExist = $this->doesBranchExist('',$uid,$this->pMap['delete'],1);
03592 if ($brExist == '') {
03593 if ($this->noRecordsFromUnallowedTables($uid)) {
03594 return array($uid);
03595 } else return 'Attempt to delete records from disallowed tables';
03596 } else return 'Attempt to delete page which has subpages';
03597 }
03598 } else return 'Attempt to delete page without permissions';
03599 }
03600
03608 function cannotDeleteRecord($table,$id) {
03609 if ($table==='pages') {
03610 $res = $this->canDeletePage($id);
03611 return is_array($res) ? FALSE : $res;
03612 } else {
03613 return $this->doesRecordExist($table,$id,'delete') ? FALSE : 'No permission to delete record';
03614 }
03615 }
03616
03627 function deleteRecord_procFields($table, $uid, $undeleteRecord = false) {
03628 t3lib_div::loadTCA($table);
03629 $conf = $GLOBALS['TCA'][$table]['columns'];
03630 $row = t3lib_BEfunc::getRecord($table, $uid, '*', '', false);
03631
03632 foreach ($row as $field => $value) {
03633 $this->deleteRecord_procBasedOnFieldType($table, $uid, $field, $value, $conf[$field]['config'], $undeleteRecord);
03634 }
03635 }
03636
03650 function deleteRecord_procBasedOnFieldType($table, $uid, $field, $value, $conf, $undeleteRecord = false) {
03651 if ($conf['type'] == 'inline') {
03652 $foreign_table = $conf['foreign_table'];
03653
03654 if ($foreign_table) {
03655 $inlineType = $this->getInlineFieldType($conf);
03656 if ($inlineType == 'list' || $inlineType == 'field') {
03657 $dbAnalysis = t3lib_div::makeInstance('t3lib_loadDBGroup');
03658 $dbAnalysis->start($value, $conf['foreign_table'], '', $uid, $table, $conf);
03659 $dbAnalysis->undeleteRecord = true;
03660
03661
03662 foreach ($dbAnalysis->itemArray as $v) {
03663 if (!$undeleteRecord) {
03664 $this->deleteAction($v['table'], $v['id']);
03665 } else {
03666 $this->undeleteRecord($v['table'], $v['id']);
03667 }
03668 }
03669 }
03670 }
03671
03672
03673 } elseif ($this->isReferenceField($conf)) {
03674 $allowedTables = $conf['type']=='group' ? $conf['allowed'] : $conf['foreign_table'].','.$conf['neg_foreign_table'];
03675 $prependName = $conf['type']=='group' ? $conf['prepend_tname'] : $conf['neg_foreign_table'];
03676
03677 $dbAnalysis = t3lib_div::makeInstance('t3lib_loadDBGroup');
03678 $dbAnalysis->start($value, $allowedTables, $conf['MM'], $uid, $table, $conf);
03679
03680 foreach ($dbAnalysis->itemArray as $v) {
03681 $this->updateRefIndexStack[$table][$uid][] = array($v['table'], $v['id']);
03682 }
03683 }
03684 }
03685
03686
03687
03688
03689
03690
03691
03692
03693
03694
03695
03696
03697
03698
03711 function versionizeRecord($table,$id,$label,$delete=FALSE,$versionizeTree=-1) {
03712 global $TCA;
03713
03714 $id = intval($id);
03715
03716 if ($TCA[$table] && $TCA[$table]['ctrl']['versioningWS'] && $id>0) {
03717 if ($this->doesRecordExist($table,$id,'show')) {
03718 if ($this->BE_USER->workspaceVersioningTypeAccess($versionizeTree)) {
03719
03720
03721 $row = $this->recordInfo($table,$id,'pid,t3ver_id');
03722 if (is_array($row)) {
03723 if ($row['pid']>=0) {
03724 if (!$delete || !$this->cannotDeleteRecord($table,$id)) {
03725
03726
03727 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
03728 't3ver_id',
03729 $table,
03730 '(t3ver_oid='.$id.' OR uid='.$id.')'.$this->deleteClause($table),
03731 '',
03732 't3ver_id DESC',
03733 '1'
03734 );
03735 list($highestVerNumber) = $GLOBALS['TYPO3_DB']->sql_fetch_row($res);
03736
03737
03738 $subVer = $row['t3ver_id'].'.'.($highestVerNumber+1);
03739
03740
03741 $overrideArray = array(
03742 't3ver_id' => $highestVerNumber+1,
03743 't3ver_oid' => $id,
03744 't3ver_label' => ($label ? $label : $subVer.' / '.date('d-m-Y H:m:s')),
03745 't3ver_wsid' => $this->BE_USER->workspace,
03746 't3ver_state' => $delete ? 2 : 0,
03747 't3ver_count' => 0,
03748 't3ver_stage' => 0,
03749 't3ver_tstamp' => 0
03750 );
03751 if ($TCA[$table]['ctrl']['editlock']) {
03752 $overrideArray[$TCA[$table]['ctrl']['editlock']] = 0;
03753 }
03754 if ($table==='pages') {
03755 $overrideArray['t3ver_swapmode'] = $versionizeTree;
03756 }
03757
03758
03759 $workspaceCheck = TRUE;
03760 if ($this->BE_USER->workspace!==0) {
03761
03762 $workspaceCheck = t3lib_BEfunc::getWorkspaceVersionOfRecord($this->BE_USER->workspace,$table,$id,'uid') ? FALSE : TRUE;
03763 }
03764
03765 if ($workspaceCheck) {
03766
03767
03768 return $this->copyRecord_raw($table,$id,-1,$overrideArray);
03769 } else $this->newlog('Record you wanted to versionize was already a version in the workspace (wsid='.$this->BE_USER->workspace.')!',1);
03770 } else $this->newlog('Record cannot be deleted: '.$this->cannotDeleteRecord($table,$id),1);
03771 } else $this->newlog('Record you wanted to versionize was already a version in archive (pid=-1)!',1);
03772 } else $this->newlog('Record you wanted to versionize did not exist!',1);
03773 } else $this->newlog('The versioning type '.$versionizeTree.' mode you requested was not allowed',1);
03774 } else $this->newlog('You didnt have correct permissions to make a new version (copy) of this record "'.$table.'" / '.$id,1);
03775 } else $this->newlog('Versioning is not supported for this table "'.$table.'" / '.$id,1);
03776 }
03777
03787 function versionizePages($uid,$label,$versionizeTree) {
03788 global $TCA;
03789
03790 $uid = intval($uid);
03791 $brExist = $this->doesBranchExist('',$uid,$this->pMap['show'],1);
03792
03793 if ($brExist != -1) {
03794
03795
03796 $allowedTablesArray = $this->admin ? $this->compileAdminTables() : explode(',',$this->BE_USER->groupData['tables_modify']);
03797 $allowedTablesArray = $this->compileAdminTables();
03798
03799
03800 $verTablesArray = array();
03801 $allTables = array_keys($TCA);
03802 foreach($allTables as $tN) {
03803 if ($tN!='pages' && ($versionizeTree>0 || $TCA[$tN]['ctrl']['versioning_followPages']) && ($this->admin || in_array($tN, $allowedTablesArray))) {
03804 $verTablesArray[] = $tN;
03805 }
03806 }
03807
03808
03809 if ($this->admin || in_array('pages',$allowedTablesArray)) {
03810 if ($this->BE_USER->workspaceVersioningTypeAccess($versionizeTree)) {
03811
03812 $theNewRootID = $this->versionizeRecord('pages',$uid,$label,FALSE,$versionizeTree);
03813 if ($theNewRootID) {
03814 $this->rawCopyPageContent($uid,$theNewRootID,$verTablesArray);
03815
03816
03817 if ($versionizeTree>0) {
03818
03819
03820 $CPtable = $this->int_pageTreeInfo(Array(), $uid, intval($versionizeTree), $theNewRootID);
03821
03822
03823 foreach($CPtable as $thePageUid => $thePagePid) {
03824 $newPid = $this->copyMappingArray['pages'][$thePagePid];
03825 if (isset($newPid)) {
03826 $theNewRootID = $this->copyRecord_raw('pages',$thePageUid,$newPid);
03827 $this->rawCopyPageContent($thePageUid,$theNewRootID,$verTablesArray);
03828 } else {
03829 $this->newlog('Something went wrong during copying branch (for versioning)',1);
03830 break;
03831 }
03832 }
03833 }
03834 } else $this->newlog('The root version could not be created!',1);
03835 } else $this->newlog('Versioning type "'.$versionizeTree.'" was not allowed in workspace',1);
03836 } else $this->newlog('Attempt to versionize page without permission to this table',1);
03837 } else $this->newlog('Could not read all subpages to versionize.',1);
03838 }
03839
03850 function version_swap($table,$id,$swapWith,$swapIntoWS=0) {
03851 global $TCA;
03852
03853
03854
03855
03856
03857
03858
03859
03860
03861
03862
03863
03864
03865
03866
03867
03868
03869
03870
03871
03872
03873
03874
03875
03876
03877 if ($this->checkRecordUpdateAccess($table,$id)) {
03878
03879
03880 $curVersion = t3lib_BEfunc::getRecord($table,$id,'*');
03881 $swapVersion = t3lib_BEfunc::getRecord($table,$swapWith,'*');
03882
03883 if (is_array($curVersion) && is_array($swapVersion)) {
03884 if ($this->BE_USER->workspacePublishAccess($swapVersion['t3ver_wsid'])) {
03885 $wsAccess = $this->BE_USER->checkWorkspace($swapVersion['t3ver_wsid']);
03886 if ($swapVersion['t3ver_wsid']<=0 || !($wsAccess['publish_access']&1) || (int)$swapVersion['t3ver_stage']===10) {
03887 if ($this->doesRecordExist($table,$swapWith,'show') && $this->checkRecordUpdateAccess($table,$swapWith)) {
03888 if (!$swapIntoWS || $this->BE_USER->workspaceSwapAccess()) {
03889
03890
03891 if ((int)$swapVersion['pid']==-1 && (int)$curVersion['pid']>=0 && !strcmp($swapVersion['t3ver_oid'],$id)) {
03892
03893
03894 $lockFileName = PATH_site.'typo3temp/swap_locking/'.$table.':'.$id.'.ser';
03895
03896 if (!@is_file($lockFileName)) {
03897
03898
03899 t3lib_div::writeFileToTypo3tempDir($lockFileName,serialize(array(
03900 'tstamp'=>time(),
03901 'user'=>$GLOBALS['BE_USER']->user['username'],
03902 'curVersion'=>$curVersion,
03903 'swapVersion'=>$swapVersion
03904 )));
03905
03906
03907 $keepFields = $this->getUniqueFields($table);
03908 if ($TCA[$table]['ctrl']['sortby']) {
03909 $keepFields[] = $TCA[$table]['ctrl']['sortby'];
03910 }
03911
03912
03913 foreach($keepFields as $fN) {
03914 $tmp = $swapVersion[$fN];
03915 $swapVersion[$fN] = $curVersion[$fN];
03916 $curVersion[$fN] = $tmp;
03917 }
03918
03919
03920 $t3ver_state = array();
03921 $t3ver_state['swapVersion'] = $swapVersion['t3ver_state'];
03922 $t3ver_state['curVersion'] = $curVersion['t3ver_state'];
03923
03924
03925 $tmp_wsid = $swapVersion['t3ver_wsid'];
03926 unset($swapVersion['uid']);
03927 $swapVersion['pid'] = intval($curVersion['pid']);
03928 $swapVersion['t3ver_oid'] = intval($id);
03929 $swapVersion['t3ver_wsid'] = $swapIntoWS ? intval($curVersion['t3ver_wsid']) : 0;
03930 $swapVersion['t3ver_tstamp'] = time();
03931 $swapVersion['t3ver_stage'] = $swapVersion['t3ver_state'] = 0;
03932
03933
03934 unset($curVersion['uid']);
03935 $curVersion['pid'] = -1;
03936 $curVersion['t3ver_oid'] = intval($id);
03937 $curVersion['t3ver_wsid'] = $swapIntoWS ? intval($tmp_wsid) : 0;
03938 $curVersion['t3ver_tstamp'] = time();
03939 $curVersion['t3ver_count'] = $curVersion['t3ver_count']+1;
03940 $curVersion['t3ver_stage'] = $curVersion['t3ver_state'] = 0;
03941
03942 if ($table==='pages') {
03943 $curVersion['t3ver_swapmode'] = $swapVersion['t3ver_swapmode'];
03944 }
03945
03946
03947 $sqlErrors = array();
03948 $GLOBALS['TYPO3_DB']->exec_UPDATEquery($table,'uid='.intval($id),$swapVersion);
03949 if ($GLOBALS['TYPO3_DB']->sql_error()) {
03950 $sqlErrors[] = $GLOBALS['TYPO3_DB']->sql_error();
03951 } else {
03952 $GLOBALS['TYPO3_DB']->exec_UPDATEquery($table,'uid='.intval($swapWith),$curVersion);
03953 if ($GLOBALS['TYPO3_DB']->sql_error()) {
03954 $sqlErrors[]=$GLOBALS['TYPO3_DB']->sql_error();
03955 } else {
03956 unlink($lockFileName);
03957 }
03958 }
03959
03960 if (!count($sqlErrors)) {
03961
03962
03963 if ($t3ver_state['swapVersion']==2) {
03964 $this->deleteEl($table,$id,TRUE);
03965 }
03966
03967 $this->newlog('Swapping successful for table "'.$table.'" uid '.$id.'=>'.$swapWith);
03968
03969
03970 $this->updateRefIndex($table,$id);
03971 $this->updateRefIndex($table,$swapWith);
03972
03973
03974 if ($table=='pages' && $swapVersion['t3ver_swapmode']>=0) {
03975
03976
03977 foreach($TCA as $tN => $tCfg) {
03978 if ($swapVersion['t3ver_swapmode']>0 || $TCA[$tN]['ctrl']['versioning_followPages']) {
03979 $temporaryPid = -($id+1000000);
03980
03981 $GLOBALS['TYPO3_DB']->exec_UPDATEquery($tN,'pid='.intval($id),array('pid'=>$temporaryPid));
03982 if ($GLOBALS['TYPO3_DB']->sql_error()) $sqlErrors[]=$GLOBALS['TYPO3_DB']->sql_error();
03983
03984 $GLOBALS['TYPO3_DB']->exec_UPDATEquery($tN,'pid='.intval($swapWith),array('pid'=>$id));
03985 if ($GLOBALS['TYPO3_DB']->sql_error()) $sqlErrors[]=$GLOBALS['TYPO3_DB']->sql_error();
03986
03987 $GLOBALS['TYPO3_DB']->exec_UPDATEquery($tN,'pid='.intval($temporaryPid),array('pid'=>$swapWith));
03988 if ($GLOBALS['TYPO3_DB']->sql_error()) $sqlErrors[]=$GLOBALS['TYPO3_DB']->sql_error();
03989
03990 if (count($sqlErrors)) {
03991 $this->newlog('During Swapping: SQL errors happend: '.implode('; ',$sqlErrors),2);
03992 }
03993 }
03994 }
03995 }
03996
03997 $this->clear_cache($table,$id);
03998
03999
04000 if ($t3ver_state['curVersion']==1) {
04001 $this->deleteEl($table, $swapWith, TRUE, TRUE);
04002 }
04003 } else $this->newlog('During Swapping: SQL errors happend: '.implode('; ',$sqlErrors),2);
04004 } else $this->newlog('A swapping lock file was present. Either another swap process is already running or a previous swap process failed. Ask your administrator to handle the situation.',2);
04005 } else $this->newlog('In swap version, either pid was not -1 or the t3ver_oid didn\'t match the id of the online version as it must!',2);
04006 } else $this->newlog('Workspace #'.$swapVersion['t3ver_wsid'].' does not support swapping.',1);
04007 } else $this->newlog('You cannot publish a record you do not have edit and show permissions for',1);
04008 } else $this->newlog('Records in workspace #'.$swapVersion['t3ver_wsid'].' can only be published when in "Publish" stage.',1);
04009 } else $this->newlog('User could not publish records from workspace #'.$swapVersion['t3ver_wsid'],1);
04010 } else $this->newlog('Error: Either online or swap version could not be selected!',2);
04011 } else $this->newlog('Error: You cannot swap versions for a record you do not have access to edit!',1);
04012 }
04013
04021 function version_clearWSID($table,$id) {
04022 if ($errorCode = $this->BE_USER->workspaceCannotEditOfflineVersion($table, $id)) {
04023 $this->newlog('Attempt to reset workspace for record failed: '.$errorCode,1);
04024 } elseif ($this->checkRecordUpdateAccess($table,$id)) {
04025 if ($liveRec = t3lib_BEfunc::getLiveVersionOfRecord($table,$id,'uid,t3ver_state')) {
04026
04027 $sArray = array();
04028 $sArray['t3ver_wsid'] = 0;
04029 $GLOBALS['TYPO3_DB']->exec_UPDATEquery($table,'uid='.intval($id),$sArray);
04030
04031
04032 if ((int)$liveRec['t3ver_state']===1) {
04033 $GLOBALS['TYPO3_DB']->exec_UPDATEquery($table,'uid='.intval($liveRec['uid']),$sArray);
04034 $this->deleteEl($table, $liveRec['uid'], TRUE);
04035 }
04036
04037
04038 $wsRec = t3lib_BEfunc::getRecord($table,$id);
04039 if ((int)$wsRec['t3ver_state']===2) {
04040 $this->deleteEl($table, $id, TRUE, TRUE);
04041 }
04042 }
04043 } else $this->newlog('Attempt to reset workspace for record failed because you do not have edit access',1);
04044 }
04045
04055 function version_setStage($table,$id,$stageId,$comment='') {
04056 if ($errorCode = $this->BE_USER->workspaceCannotEditOfflineVersion($table, $id)) {
04057 $this->newlog('Attempt to set stage for record failed: '.$errorCode,1);
04058 } elseif ($this->checkRecordUpdateAccess($table,$id)) {
04059 $stat = $this->BE_USER->checkWorkspaceCurrent();
04060 if (t3lib_div::inList('admin,online,offline,reviewer,owner', $stat['_ACCESS']) || ($stageId<=1 && $stat['_ACCESS']==='member')) {
04061
04062
04063 $sArray = array();
04064 $sArray['t3ver_stage'] = $stageId;
04065 $GLOBALS['TYPO3_DB']->exec_UPDATEquery($table, 'uid='.intval($id), $sArray);
04066 $this->newlog('Stage for record was changed to '.$stageId.'. Comment was: "'.substr($comment,0,100).'"');
04067
04068 $this->log($table,$id,6,0,0,'Stage raised...',30,array('comment'=>$comment,'stage'=>$stageId));
04069
04070 if ((int)$stat['stagechg_notification']>0) {
04071 $this->notifyStageChange($stat,$stageId,$table,$id,$comment);
04072 }
04073 } else $this->newlog('The member user tried to set a stage value "'.$stageId.'" that was not allowed',1);
04074 } else $this->newlog('Attempt to set stage for record failed because you do not have edit access',1);
04075 }
04076
04077
04078
04079
04080
04081
04082
04083
04084
04085
04086
04087
04088
04089
04090
04091
04092
04093
04094
04100 function remapListedDBRecords() {
04101 global $TCA;
04102
04103 if (count($this->registerDBList)) {
04104 reset($this->registerDBList);
04105 while(list($table,$records)=each($this->registerDBList)) {
04106 t3lib_div::loadTCA($table);
04107 reset($records);
04108 while(list($uid,$fields)=each($records)) {
04109 $newData = array();
04110 $theUidToUpdate = $this->copyMappingArray_merged[$table][$uid];
04111 $theUidToUpdate_saveTo = t3lib_BEfunc::wsMapId($table,$theUidToUpdate);
04112
04113 foreach($fields as $fieldName => $value) {
04114 $conf = $TCA[$table]['columns'][$fieldName]['config'];
04115
04116 switch($conf['type']) {
04117 case 'group':
04118 case 'select':
04119 $vArray = $this->remapListedDBRecords_procDBRefs($conf, $value, $theUidToUpdate, $table);
04120 if (is_array($vArray)) {
04121 $newData[$fieldName] = implode(',',$vArray);
04122 }
04123 break;
04124 case 'flex':
04125 if ($value=='FlexForm_reference') {
04126 $origRecordRow = $this->recordInfo($table,$theUidToUpdate,'*');
04127
04128 if (is_array($origRecordRow)) {
04129 t3lib_BEfunc::workspaceOL($table,$origRecordRow);
04130
04131
04132 $dataStructArray = t3lib_BEfunc::getFlexFormDS($conf, $origRecordRow, $table);
04133 $currentValueArray = t3lib_div::xml2array($origRecordRow[$fieldName]);
04134
04135
04136 $currentValueArray['data'] = $this->checkValue_flex_procInData(
04137 $currentValueArray['data'],
04138 array(),
04139 array(),
04140 $dataStructArray,
04141 array($table,$theUidToUpdate,$fieldName),
04142 'remapListedDBRecords_flexFormCallBack'
04143 );
04144
04145
04146 if (is_array($currentValueArray['data'])) {
04147 $newData[$fieldName] =
04148 $this->checkValue_flexArray2Xml($currentValueArray,TRUE);
04149 }
04150 }
04151 }
04152 break;
04153 case 'inline':
04154 $this->remapListedDBRecords_procInline($conf, $value, $uid, $table);
04155 break;
04156 default:
04157 debug('Field type should not appear here: '. $conf['type']);
04158 break;
04159 }
04160 }
04161
04162 if (count($newData)) {
04163 $this->updateDB($table,$theUidToUpdate_saveTo,$newData);
04164 }
04165 }
04166 }
04167 }
04168 }
04169
04181 function remapListedDBRecords_flexFormCallBack($pParams, $dsConf, $dataValue, $dataValue_ext1, $dataValue_ext2) {
04182
04183
04184 list($table,$uid,$field) = $pParams;
04185
04186
04187 if ($this->isReferenceField($dsConf) && strlen($dataValue)) {
04188 $vArray = $this->remapListedDBRecords_procDBRefs($dsConf, $dataValue, $uid, $table);
04189 if (is_array($vArray)) {
04190 $dataValue = implode(',',$vArray);
04191 }
04192 }
04193
04194
04195 return array('value' => $dataValue);
04196 }
04197
04208 function remapListedDBRecords_procDBRefs($conf, $value, $MM_localUid, $table) {
04209
04210
04211 $set = FALSE;
04212 $allowedTables = $conf['type']=='group' ? $conf['allowed'] : $conf['foreign_table'].','.$conf['neg_foreign_table'];
04213 $prependName = $conf['type']=='group' ? $conf['prepend_tname'] : '';
04214 $dontRemapTables = t3lib_div::trimExplode(',',$conf['dontRemapTablesOnCopy'],1);
04215
04216
04217 $dbAnalysis = t3lib_div::makeInstance('t3lib_loadDBGroup');
04218 $dbAnalysis->registerNonTableValues = ($conf['type']=='select' && $conf['allowNonIdValues']) ? 1 : 0;
04219 $dbAnalysis->start($value, $allowedTables, $conf['MM'], $MM_localUid, $table, $conf);
04220
04221
04222 foreach($dbAnalysis->itemArray as $k => $v) {
04223 $mapID = $this->copyMappingArray_merged[$v['table']][$v['id']];
04224 if ($mapID && !in_array($v['table'],$dontRemapTables)) {
04225 $dbAnalysis->itemArray[$k]['id'] = $mapID;
04226 $set = TRUE;
04227 }
04228 }
04229
04230
04231 if ($set) {
04232 if ($conf['MM']) {
04233
04234 $dbAnalysis->writeMM($conf['MM'], $theUidToUpdate, $prependName);
04235 } else {
04236 $vArray = $dbAnalysis->getValueArray($prependName);
04237 if ($conf['type']=='select') {
04238 $vArray = $dbAnalysis->convertPosNeg($vArray, $conf['foreign_table'], $conf['neg_foreign_table']);
04239 }
04240 return $vArray;
04241 }
04242 }
04243 }
04244
04254 function remapListedDBRecords_procInline($conf, $value, $uid, $table) {
04255 $theUidToUpdate = $this->copyMappingArray_merged[$table][$uid];
04256
04257 if ($conf['foreign_table']) {
04258 $inlineType = $this->getInlineFieldType($conf);
04259
04260 if ($inlineType == 'field') {
04261 $dbAnalysis = t3lib_div::makeInstance('t3lib_loadDBGroup');
04262 $dbAnalysis->start($value, $conf['foreign_table'], $conf['MM'], 0, $table, $conf);
04263
04264 $dbAnalysis->writeForeignField($conf, $uid, $theUidToUpdate);
04265 } elseif ($inlineType == 'mm') {
04266 $vArray = $this->remapListedDBRecords_procDBRefs($conf, $value, $theUidToUpdate, $table);
04267 }
04268 }
04269 }
04270
04271
04272
04273
04274
04275
04276
04277
04278
04279
04280
04281
04282
04283
04284
04285
04286
04287
04288
04289
04290
04297 function checkModifyAccessList($table) {
04298 $res = ($this->admin || (!$this->tableAdminOnly($table) && t3lib_div::inList($this->BE_USER->groupData['tables_modify'],$table)));
04299 return $res;
04300 }
04301
04309 function isRecordInWebMount($table,$id) {
04310 if (!isset($this->isRecordInWebMount_Cache[$table.':'.$id])) {
04311 $recP=$this->getRecordProperties($table,$id);
04312 $this->isRecordInWebMount_Cache[$table.':'.$id]=$this->isInWebMount($recP['event_pid']);
04313 }
04314 return $this->isRecordInWebMount_Cache[$table.':'.$id];
04315 }
04316
04323 function isInWebMount($pid) {
04324 if (!isset($this->isInWebMount_Cache[$pid])) {
04325 $this->isInWebMount_Cache[$pid]=$this->BE_USER->isInWebMount($pid);
04326 }
04327 return $this->isInWebMount_Cache[$pid];
04328 }
04329
04337 function checkRecordUpdateAccess($table,$id) {
04338 global $TCA;
04339 $res = 0;
04340 if ($TCA[$table] && intval($id)>0) {
04341 if (isset($this->recUpdateAccessCache[$table][$id])) {
04342 return $this->recUpdateAccessCache[$table][$id];
04343
04344 } elseif ($this->doesRecordExist($table,$id,'edit')) {
04345 $res = 1;
04346 }
04347 $this->recUpdateAccessCache[$table][$id]=$res;
04348 }
04349 return $res;
04350 }
04351
04361 function checkRecordInsertAccess($insertTable,$pid,$action=1) {
04362 global $TCA;
04363
04364 $res = 0;
04365 $pid = intval($pid);
04366 if ($pid>=0) {
04367 if (isset($this->recInsertAccessCache[$insertTable][$pid])) {
04368 return $this->recInsertAccessCache[$insertTable][$pid];
04369 } else {
04370
04371 if ( (!$pid && $this->admin) || $this->doesRecordExist('pages',$pid,($insertTable=='pages'?$this->pMap['new']:$this->pMap['editcontent'])) ) {
04372 if ($this->isTableAllowedForThisPage($pid, $insertTable)) {
04373 $res = 1;
04374 $this->recInsertAccessCache[$insertTable][$pid]=$res;
04375 } else {
04376 $propArr = $this->getRecordProperties('pages',$pid);
04377 $this->log($insertTable,$pid,$action,0,1,"Attempt to insert record on page '%s' (%s) where this table, %s, is not allowed",11,array($propArr['header'],$pid,$insertTable),$propArr['event_pid']);
04378 }
04379 } else {
04380 $propArr = $this->getRecordProperties('pages',$pid);
04381 $this->log($insertTable,$pid,$action,0,1,"Attempt to insert a record on page '%s' (%s) from table '%s' without permissions. Or non-existing page.",12,array($propArr['header'],$pid,$insertTable),$propArr['event_pid']);
04382 }
04383 }
04384 }
04385 return $res;
04386 }
04387
04395 function isTableAllowedForThisPage($page_uid, $checkTable) {
04396 global $TCA, $PAGES_TYPES;
04397 $page_uid = intval($page_uid);
04398
04399
04400 if (($TCA[$checkTable]['ctrl']['rootLevel'] xor !$page_uid) && $TCA[$checkTable]['ctrl']['rootLevel']!=-1 && $checkTable!='pages') {
04401 return false;
04402 }
04403
04404
04405 if (!$page_uid) {
04406 if ($this->admin) {
04407 return true;
04408 }
04409 } else {
04410
04411 $doktype = $this->pageInfo($page_uid,'doktype');
04412 $allowedTableList = isset($PAGES_TYPES[$doktype]['allowedTables']) ? $PAGES_TYPES[$doktype]['allowedTables'] : $PAGES_TYPES['default']['allowedTables'];
04413 $allowedArray = t3lib_div::trimExplode(',',$allowedTableList,1);
04414 if (strstr($allowedTableList,'*') || in_array($checkTable,$allowedArray)) {
04415 return true;
04416 }
04417 }
04418 }
04419
04428 function doesRecordExist($table,$id,$perms) {
04429 global $TCA;
04430
04431 if ($this->bypassAccessCheckForRecords) {
04432 return is_array(t3lib_BEfunc::getRecordRaw($table,'uid='.intval($id),'uid'));
04433 }
04434
04435 $res = 0;
04436 $id = intval($id);
04437
04438
04439 if (!t3lib_div::testInt($perms)) {
04440 if ($table!='pages') {
04441 switch($perms) {
04442 case 'edit':
04443 case 'delete':
04444 case 'new':
04445 $perms = 'editcontent';
04446 break;
04447 }
04448 }
04449 $perms = intval($this->pMap[$perms]);
04450 } else {
04451 $perms = intval($perms);
04452 }
04453
04454 if (!$perms) {die('Internal ERROR: no permissions to check for non-admin user.');}
04455
04456
04457 if (is_array($TCA[$table]) && $id>0 && ($this->isRecordInWebMount($table,$id) || $this->admin)) {
04458 if ($table != 'pages') {
04459
04460
04461 $mres = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid,pid', $table, 'uid='.intval($id).$this->deleteClause($table));
04462 $output = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($mres);
04463 t3lib_BEfunc::fixVersioningPid($table,$output,TRUE);
04464
04465
04466 if (is_array($output)) {
04467
04468
04469 $mres = $this->doesRecordExist_pageLookUp($output['pid'], $perms);
04470 $pageRec = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($mres);
04471
04472 if (is_array($pageRec) || (!$output['pid'] && $this->admin)) {
04473 return TRUE;
04474 }
04475 }
04476 return FALSE;
04477 } else {
04478 $mres = $this->doesRecordExist_pageLookUp($id, $perms);
04479 return $GLOBALS['TYPO3_DB']->sql_num_rows($mres);
04480 }
04481 }
04482 }
04483
04493 function doesRecordExist_pageLookUp($id, $perms) {
04494 global $TCA;
04495
04496 return $GLOBALS['TYPO3_DB']->exec_SELECTquery(
04497 'uid',
04498 'pages',
04499 'uid='.intval($id).
04500 $this->deleteClause('pages').
04501 ($perms && !$this->admin ? ' AND '.$this->BE_USER->getPagePermsClause($perms) : '').
04502 (!$this->admin && $TCA['pages']['ctrl']['editlock'] && ($perms & (2+4+16)) ? ' AND '.$TCA['pages']['ctrl']['editlock'].'=0':'')
04503 );
04504 }
04505
04519 function doesBranchExist($inList,$pid,$perms,$recurse) {
04520 global $TCA;
04521 $pid = intval($pid);
04522 $perms = intval($perms);
04523
04524 if ($pid>=0) {
04525 $mres = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
04526 'uid, perms_userid, perms_groupid, perms_user, perms_group, perms_everybody',
04527 'pages',
04528 'pid='.intval($pid).$this->deleteClause('pages'),
04529 '',
04530 'sorting'
04531 );
04532 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($mres)) {
04533 if ($this->admin || $this->BE_USER->doesUserHaveAccess($row,$perms)) {
04534 $inList.=$row['uid'].',';
04535 if ($recurse) {
04536 $inList = $this->doesBranchExist($inList, $row['uid'], $perms, $recurse);
04537 if ($inList == -1) {return -1;}
04538 }
04539 } else {
04540 return -1;
04541 }
04542 }
04543 }
04544 return $inList;
04545 }
04546
04553 function tableReadOnly($table) {
04554
04555 global $TCA;
04556 return ($TCA[$table]['ctrl']['readOnly'] ? 1 : 0);
04557 }
04558
04565 function tableAdminOnly($table) {
04566
04567 global $TCA;
04568 return ($TCA[$table]['ctrl']['adminOnly'] ? 1 : 0);
04569 }
04570
04579 function destNotInsideSelf($dest,$id) {
04580 $loopCheck = 100;
04581 $dest = intval($dest);
04582 $id = intval($id);
04583
04584 if ($dest==$id) {
04585 return FALSE;
04586 }
04587
04588 while ($dest!=0 && $loopCheck>0) {
04589 $loopCheck--;
04590 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('pid, uid, t3ver_oid,t3ver_wsid', 'pages', 'uid='.intval($dest).$this->deleteClause('pages'));
04591 if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
04592 t3lib_BEfunc::fixVersioningPid('pages',$row);
04593 if ($row['pid']==$id) {
04594 return FALSE;
04595 } else {
04596 $dest = $row['pid'];
04597 }
04598 } else {
04599 return FALSE;
04600 }
04601 }
04602 return TRUE;
04603 }
04604
04611 function getExcludeListArray() {
04612 global $TCA;
04613
04614 $list = array();
04615 reset($TCA);
04616 while (list($table)=each($TCA)) {
04617 t3lib_div::loadTCA($table);
04618 while (list($field,$config)=each($TCA[$table]['columns'])) {
04619 if ($config['exclude'] && !t3lib_div::inList($this->BE_USER->groupData['non_exclude_fields'],$table.':'.$field)) {
04620 $list[]=$table.'-'.$field;
04621 }
04622 }
04623 }
04624 return $list;
04625 }
04626
04634 function doesPageHaveUnallowedTables($page_uid,$doktype) {
04635 global $TCA, $PAGES_TYPES;
04636
04637 $page_uid = intval($page_uid);
04638 if (!$page_uid) {
04639 return FALSE;
04640 }
04641
04642 $allowedTableList = isset($PAGES_TYPES[$doktype]['allowedTables']) ? $PAGES_TYPES[$doktype]['allowedTables'] : $PAGES_TYPES['default']['allowedTables'];
04643 $allowedArray = t3lib_div::trimExplode(',',$allowedTableList,1);
04644 if (strstr($allowedTableList,'*')) {
04645 return FALSE;
04646 }
04647
04648 reset ($TCA);
04649 $tableList = array();
04650 while (list($table)=each($TCA)) {
04651 if (!in_array($table,$allowedArray)) {
04652 $mres = $GLOBALS['TYPO3_DB']->exec_SELECTquery('count(*)', $table, 'pid='.intval($page_uid));
04653 $count = $GLOBALS['TYPO3_DB']->sql_fetch_row($mres);
04654 if ($count[0]) {
04655 $tableList[]=$table;
04656 }
04657 }
04658 }
04659 return implode(',',$tableList);
04660 }
04661
04662
04663
04664
04665
04666
04667
04668
04669
04670
04671
04672
04673
04674
04683 function pageInfo($id,$field) {
04684 if (!isset($this->pageCache[$id])) {
04685 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'pages', 'uid='.intval($id));
04686 if ($GLOBALS['TYPO3_DB']->sql_num_rows($res)) {
04687 $this->pageCache[$id] = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
04688 }
04689 $GLOBALS['TYPO3_DB']->sql_free_result($res);
04690 }
04691 return $this->pageCache[$id][$field];
04692 }
04693
04703 function recordInfo($table,$id,$fieldList) {
04704 global $TCA;
04705 if (is_array($TCA[$table])) {
04706 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($fieldList, $table, 'uid='.intval($id));
04707 if ($GLOBALS['TYPO3_DB']->sql_num_rows($res)) {
04708 return $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
04709 }
04710 }
04711 }
04712
04724 function getRecordProperties($table,$id,$noWSOL=FALSE) {
04725 $row = ($table=='pages' && !$id) ? array('title'=>'[root-level]', 'uid' => 0, 'pid' => 0) :$this->recordInfo($table,$id,'*');
04726 if (!$noWSOL) {
04727 t3lib_BEfunc::workspaceOL($table,$row);
04728 }
04729 t3lib_BEfunc::fixVersioningPid($table,$row);
04730 return $this->getRecordPropertiesFromRow($table,$row);
04731 }
04732
04740 function getRecordPropertiesFromRow($table,$row) {
04741 global $TCA;
04742 if ($TCA[$table]) {
04743 $out = array(
04744 'header' => $row[$TCA[$table]['ctrl']['label']],
04745 'pid' => $row['pid'],
04746 'event_pid' => ($table=='pages'?$row['uid']:$row['pid']),
04747 't3ver_state' => $TCA[$table]['ctrl']['versioningWS'] ? $row['t3ver_state'] : '',
04748 '_ORIG_pid' => $row['_ORIG_pid']
04749 );
04750 return $out;
04751 }
04752 }
04753
04754
04755
04756
04757
04758
04759
04760
04761
04762
04763
04764
04765
04766
04767
04768
04769
04770
04771
04772
04773
04783 function updateDB($table,$id,$fieldArray) {
04784 global $TCA;
04785
04786 if (is_array($fieldArray) && is_array($TCA[$table]) && intval($id)) {
04787 unset($fieldArray['uid']);
04788
04789 if (count($fieldArray)) {
04790
04791
04792 $GLOBALS['TYPO3_DB']->exec_UPDATEquery($table, 'uid='.intval($id), $fieldArray);
04793
04794
04795 if (!$GLOBALS['TYPO3_DB']->sql_error()) {
04796
04797 if ($this->checkStoredRecords) {
04798 $newRow = $this->checkStoredRecord($table,$id,$fieldArray,2);
04799 }
04800
04801
04802 $this->updateRefIndex($table,$id);
04803
04804
04805 $propArr = $this->getRecordPropertiesFromRow($table,$newRow);
04806 $theLogId = $this->log($table,$id,2,$propArr['pid'],0,"Record '%s' (%s) was updated.",10,array($propArr['header'],$table.':'.$id),$propArr['event_pid']);
04807
04808
04809 $this->setHistory($table,$id,$theLogId);
04810
04811
04812 $this->clear_cache($table,$id);
04813
04814
04815 if ($table=='pages') unset($this->pageCache[$id]);
04816 } else {
04817 $this->log($table,$id,2,0,2,"SQL error: '%s' (%s)",12,array($GLOBALS['TYPO3_DB']->sql_error(),$table.':'.$id));
04818 }
04819 }
04820 }
04821 }
04822
04835 function insertDB($table,$id,$fieldArray,$newVersion=FALSE,$suggestedUid=0,$dontSetNewIdIndex=FALSE) {
04836 global $TCA;
04837
04838 if (is_array($fieldArray) && is_array($TCA[$table]) && isset($fieldArray['pid'])) {
04839 unset($fieldArray['uid']);
04840
04841 if (count($fieldArray)) {
04842
04843
04844
04845
04846
04847 $suggestedUid = intval($suggestedUid);
04848 if ($this->BE_USER->isAdmin() && $suggestedUid && $this->suggestedInsertUids[$table.':'.$suggestedUid]) {
04849
04850 if ($this->suggestedInsertUids[$table.':'.$suggestedUid]==='DELETE') {
04851
04852 $GLOBALS['TYPO3_DB']->exec_DELETEquery($table, 'uid='.intval($suggestedUid));
04853 }
04854 $fieldArray['uid'] = $suggestedUid;
04855 }
04856
04857
04858 $GLOBALS['TYPO3_DB']->exec_INSERTquery($table, $fieldArray);
04859
04860
04861 if (!$GLOBALS['TYPO3_DB']->sql_error()) {
04862
04863
04864 $NEW_id = $id;
04865 $id = $GLOBALS['TYPO3_DB']->sql_insert_id();
04866 if (!$dontSetNewIdIndex) {
04867 $this->substNEWwithIDs[$NEW_id] = $id;
04868 $this->substNEWwithIDs_table[$NEW_id] = $table;
04869 }
04870
04871
04872 if ($this->checkStoredRecords) {
04873 $newRow = $this->checkStoredRecord($table,$id,$fieldArray,1);
04874 }
04875
04876
04877 $this->updateRefIndex($table,$id);
04878
04879 if ($newVersion) {
04880 $this->log($table,$id,1,0,0,"New version created of table '%s', uid '%s'",10,array($table,$fieldArray['t3ver_oid']),$newRow['pid'],$NEW_id);
04881 } else {
04882 $propArr = $this->getRecordPropertiesFromRow($table,$newRow);
04883 $page_propArr = $this->getRecordProperties('pages',$propArr['pid']);
04884 $this->log($table,$id,1,0,0,"Record '%s' (%s) was inserted on page '%s' (%s)",10,array($propArr['header'],$table.':'.$id,$page_propArr['header'],$newRow['pid']),$newRow['pid'],$NEW_id);
04885
04886
04887 $this->clear_cache($table,$id);
04888 }
04889
04890 return $id;
04891 } else {
04892 $this->log($table,$id,1,0,2,"SQL error: '%s' (%s)",12,array($GLOBALS['TYPO3_DB']->sql_error(),$table.':'.$id));
04893 }
04894 }
04895 }
04896 }
04897
04908 function checkStoredRecord($table,$id,$fieldArray,$action) {
04909 global $TCA;
04910
04911 $id = intval($id);
04912 if (is_array($TCA[$table]) && $id) {
04913 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', $table, 'uid='.intval($id));
04914 if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
04915
04916 $errorString = array();
04917 foreach($fieldArray as $key => $value) {
04918 if ($this->checkStoredRecords_loose && !$value && !$row[$key]) {
04919
04920 } elseif (strcmp($value,$row[$key])) {
04921 $errorString[] = $key;
04922 }
04923 }
04924
04925
04926 if (count($errorString)) {
04927 $this->log($table,$id,$action,0,102,'These fields are not properly updated in database: ('.implode(',',$errorString).') Probably value mismatch with fieldtype.');
04928 }
04929
04930
04931 return $row;
04932 }
04933 $GLOBALS['TYPO3_DB']->sql_free_result($res);
04934 }
04935 }
04936
04945 function setHistory($table,$id,$logId) {
04946 if (isset($this->historyRecords[$table.':'.$id])) {
04947
04948
04949 list($tscPID) = t3lib_BEfunc::getTSCpid($table,$id,'');
04950 $TSConfig = $this->getTCEMAIN_TSconfig($tscPID);
04951
04952 $tE = $this->getTableEntries($table,$TSConfig);
04953 $maxAgeSeconds = 60*60*24*(strcmp($tE['history.']['maxAgeDays'],'') ? t3lib_div::intInRange($tE['history.']['maxAgeDays'],0,365) : 30);
04954
04955
04956 $this->clearHistory($maxAgeSeconds, $table);
04957
04958
04959 $fields_values = array();
04960 $fields_values['history_data'] = serialize($this->historyRecords[$table.':'.$id]);
04961 $fields_values['fieldlist'] = implode(',',array_keys($this->historyRecords[$table.':'.$id]['newRecord']));
04962 $fields_values['tstamp'] = time();
04963 $fields_values['tablename'] = $table;
04964 $fields_values['recuid'] = $id;
04965 $fields_values['sys_log_uid'] = $logId;
04966
04967 $GLOBALS['TYPO3_DB']->exec_INSERTquery('sys_history', $fields_values);
04968 }
04969 }
04970
04978 function clearHistory($maxAgeSeconds=604800,$table) {
04979 $tstampLimit = $maxAgeSeconds ? time()-$maxAgeSeconds : 0;
04980
04981 $GLOBALS['TYPO3_DB']->exec_DELETEquery('sys_history', 'tstamp<'.intval($tstampLimit).' AND tablename='.$GLOBALS['TYPO3_DB']->fullQuoteStr($table, 'sys_history'));
04982 }
04983
04992 function updateRefIndex($table,$id) {
04993 $refIndexObj = t3lib_div::makeInstance('t3lib_refindex');
04994 $result = $refIndexObj->updateRefIndexTable($table,$id);
04995 }
04996
04997
04998
04999
05000
05001
05002
05003
05004
05005
05006
05007
05008
05009
05010
05011
05012
05013
05014
05024 function getSortNumber($table,$uid,$pid) {
05025 global $TCA;
05026 if ($TCA[$table] && $TCA[$table]['ctrl']['sortby']) {
05027 $sortRow = $TCA[$table]['ctrl']['sortby'];
05028 if ($pid>=0) {
05029 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($sortRow.',pid,uid', $table, 'pid='.intval($pid).$this->deleteClause($table), '', $sortRow.' ASC', '1');
05030 if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
05031 if ($row['uid']==$uid) {
05032 return $row[$sortRow];
05033 }
05034 if ($row[$sortRow] < 1) {
05035 $this->resorting($table,$pid,$sortRow,0);
05036 return $this->sortIntervals;
05037 } else {
05038 return floor($row[$sortRow]/2);
05039 }
05040 } else {
05041 return $this->sortIntervals;
05042 }
05043 } else {
05044 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($sortRow.',pid,uid', $table, 'uid='.abs($pid).$this->deleteClause($table));
05045 if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
05046
05047
05048 if ($lookForLiveVersion = t3lib_BEfunc::getLiveVersionOfRecord($table,$row['uid'],$sortRow.',pid,uid')) {
05049 $row = $lookForLiveVersion;
05050 }
05051
05052
05053 if ($row['uid']==$uid) {
05054 $sortNumber = $row[$sortRow];
05055 } else {
05056 $subres = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
05057 $sortRow.',pid,uid',
05058 $table,
05059 'pid='.intval($row['pid']).' AND '.$sortRow.'>='.intval($row[$sortRow]).$this->deleteClause($table),
05060 '',
05061 $sortRow.' ASC',
05062 '2'
05063 );
05064 if ($GLOBALS['TYPO3_DB']->sql_num_rows($subres)==2) {
05065 $GLOBALS['TYPO3_DB']->sql_fetch_assoc($subres);
05066 $subrow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($subres);
05067 $sortNumber = $row[$sortRow]+ floor(($subrow[$sortRow]-$row[$sortRow])/2);
05068 if ($sortNumber<=$row[$sortRow] || $sortNumber>=$subrow[$sortRow]) {
05069 $sortNumber = $this->resorting($table,$row['pid'],$sortRow, $row['uid']);
05070 }
05071 } else {
05072 $sortNumber = $row[$sortRow]+$this->sortIntervals;
05073 }
05074 }
05075 return Array('pid' => $row['pid'], 'sortNumber' => $sortNumber);
05076 } else {
05077 $propArr = $this->getRecordProperties($table,$uid);
05078 $this->log($table,$uid,4,0,1,"Attempt to move record '%s' (%s) to after a non-existing record (uid=%s)",1,array($propArr['header'],$table.':'.$uid,abs($pid)),$propArr['pid']);
05079 return false;
05080 }
05081 }
05082 }
05083 }
05084
05097 function resorting($table,$pid,$sortRow, $return_SortNumber_After_This_Uid) {
05098 global $TCA;
05099 if ($TCA[$table] && $sortRow && $TCA[$table]['ctrl']['sortby']==$sortRow) {
05100 $returnVal = 0;
05101 $intervals = $this->sortIntervals;
05102 $i = $intervals*2;
05103
05104 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid', $table, 'pid='.intval($pid).$this->deleteClause($table), '', $sortRow.' ASC');
05105 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
05106 $uid=intval($row['uid']);
05107 if ($uid) {
05108 $GLOBALS['TYPO3_DB']->exec_UPDATEquery($table, 'uid='.intval($uid), array($sortRow=>$i));
05109 if ($uid==$return_SortNumber_After_This_Uid) {
05110 $i = $i+$intervals;
05111 $returnVal=$i;
05112 }
05113 } else {die ('Fatal ERROR!! No Uid at resorting.');}
05114 $i = $i+$intervals;
05115 }
05116 return $returnVal;
05117 }
05118 }
05119
05128 function setTSconfigPermissions($fieldArray,$TSConfig_p) {
05129 if (strcmp($TSConfig_p['userid'],'')) $fieldArray['perms_userid']=intval($TSConfig_p['userid']);
05130 if (strcmp($TSConfig_p['groupid'],'')) $fieldArray['perms_groupid']=intval($TSConfig_p['groupid']);
05131 if (strcmp($TSConfig_p['user'],'')) $fieldArray['perms_user']=t3lib_div::testInt($TSConfig_p['user']) ? $TSConfig_p['user'] : $this->assemblePermissions($TSConfig_p['user']);
05132 if (strcmp($TSConfig_p['group'],'')) $fieldArray['perms_group']=t3lib_div::testInt($TSConfig_p['group']) ? $TSConfig_p['group'] : $this->assemblePermissions($TSConfig_p['group']);
05133 if (strcmp($TSConfig_p['everybody'],'')) $fieldArray['perms_everybody']=t3lib_div::testInt($TSConfig_p['everybody']) ? $TSConfig_p['everybody'] : $this->assemblePermissions($TSConfig_p['everybody']);
05134
05135 return $fieldArray;
05136 }
05137
05145 function newFieldArray($table) {
05146 global $TCA;
05147
05148 t3lib_div::loadTCA($table);
05149 $fieldArray=Array();
05150 if (is_array($TCA[$table]['columns'])) {
05151 reset ($TCA[$table]['columns']);
05152 while (list($field,$content)=each($TCA[$table]['columns'])) {
05153 if (isset($this->defaultValues[$table][$field])) {
05154 $fieldArray[$field] = $this->defaultValues[$table][$field];
05155 } elseif (isset($content['config']['default'])) {
05156 $fieldArray[$field] = $content['config']['default'];
05157 }
05158 }
05159 }
05160 if ($table==='pages') {
05161 $fieldArray['perms_userid'] = $this->userid;
05162 $fieldArray['perms_groupid'] = intval($this->BE_USER->firstMainGroup);
05163 $fieldArray['perms_user'] = $this->assemblePermissions($this->defaultPermissions['user']);
05164 $fieldArray['perms_group'] = $this->assemblePermissions($this->defaultPermissions['group']);
05165 $fieldArray['perms_everybody'] = $this->assemblePermissions($this->defaultPermissions['everybody']);
05166 }
05167 return $fieldArray;
05168 }
05169
05177 function addDefaultPermittedLanguageIfNotSet($table,&$incomingFieldArray) {
05178 global $TCA;
05179
05180
05181 if ($TCA[$table]['ctrl']['languageField']) {
05182 if (!isset($incomingFieldArray[$TCA[$table]['ctrl']['languageField']])) {
05183 $rows = array_merge(array(array('uid'=>0)),$GLOBALS['TYPO3_DB']->exec_SELECTgetRows('uid','sys_language','pid=0'.t3lib_BEfunc::deleteClause('sys_language')),array(array('uid'=>-1)));
05184 foreach($rows as $r) {
05185 if ($this->BE_USER->checkLanguageAccess($r['uid'])) {
05186 $incomingFieldArray[$TCA[$table]['ctrl']['languageField']] = $r['uid'];
05187 break;
05188 }
05189 }
05190 }
05191 }
05192 }
05193
05201 function overrideFieldArray($table,$data) {
05202 if (is_array($this->overrideValues[$table])) {
05203 $data = array_merge($data,$this->overrideValues[$table]);
05204 }
05205 return $data;
05206 }
05207
05217 function compareFieldArrayWithCurrentAndUnset($table,$id,$fieldArray) {
05218
05219
05220 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', $table, 'uid='.intval($id));
05221 $currentRecord = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
05222
05223
05224 if (is_array($currentRecord)) {
05225
05226
05227 $c = 0;
05228 $cRecTypes = array();
05229 foreach($currentRecord as $col => $val) {
05230 $cRecTypes[$col] = $GLOBALS['TYPO3_DB']->sql_field_type($res,$c);
05231 $c++;
05232 }
05233
05234
05235 $GLOBALS['TYPO3_DB']->sql_free_result($res);
05236
05237
05238 foreach($fieldArray as $col => $val) {
05239 if (
05240 !strcmp($val,$currentRecord[$col]) ||
05241 ($cRecTypes[$col]=='int' && $currentRecord[$col]==0 && !strcmp($val,''))
05242 ) {
05243 unset($fieldArray[$col]);
05244 } else {
05245 $this->historyRecords[$table.':'.$id]['oldRecord'][$col] = $currentRecord[$col];
05246 $this->historyRecords[$table.':'.$id]['newRecord'][$col] = $fieldArray[$col];
05247 }
05248 }
05249 } else {
05250 $fieldArray = array();
05251 }
05252
05253 return $fieldArray;
05254 }
05255
05263 function assemblePermissions($string) {
05264 $keyArr = t3lib_div::trimExplode(',',$string,1);
05265 $value=0;
05266 while(list(,$key)=each($keyArr)) {
05267 if ($key && isset($this->pMap[$key])) {
05268 $value |= $this->pMap[$key];
05269 }
05270 }
05271 return $value;
05272 }
05273
05280 function rmComma($input) {
05281 return ereg_replace(',$','',$input);
05282 }
05283
05290 function convNumEntityToByteValue($input) {
05291 $token = md5(microtime());
05292 $parts = explode($token,ereg_replace('(&#([0-9]+);)',$token.'\2'.$token,$input));
05293
05294 foreach($parts as $k => $v) {
05295 if ($k%2) {
05296 $v = intval($v);
05297 if ($v > 32) {
05298 $parts[$k] =chr(intval($v));
05299 }
05300 }
05301 }
05302
05303 return implode('',$parts);
05304 }
05305
05312 function destPathFromUploadFolder($folder) {
05313 return PATH_site.$folder;
05314 }
05315
05322 function deleteClause($table) {
05323
05324 global $TCA;
05325 if ($TCA[$table]['ctrl']['delete']) {
05326 return ' AND '.$table.'.'.$TCA[$table]['ctrl']['delete'].'=0';
05327 } else {
05328 return '';
05329 }
05330 }
05331
05338 function getTCEMAIN_TSconfig($tscPID) {
05339 if (!isset($this->cachedTSconfig[$tscPID])) {
05340 $this->cachedTSconfig[$tscPID] = $this->BE_USER->getTSConfig('TCEMAIN',t3lib_BEfunc::getPagesTSconfig($tscPID));
05341 }
05342 return $this->cachedTSconfig[$tscPID]['properties'];
05343 }
05344
05353 function getTableEntries($table,$TSconfig) {
05354 $tA = is_array($TSconfig['table.'][$table.'.']) ? $TSconfig['table.'][$table.'.'] : array();;
05355 $dA = is_array($TSconfig['default.']) ? $TSconfig['default.'] : array();
05356 return t3lib_div::array_merge_recursive_overrule($dA,$tA);
05357 }
05358
05366 function getPID($table,$uid) {
05367 $res_tmp = $GLOBALS['TYPO3_DB']->exec_SELECTquery('pid', $table, 'uid='.intval($uid));
05368 if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res_tmp)) {
05369 return $row['pid'];
05370 }
05371 }
05372
05379 function dbAnalysisStoreExec() {
05380 reset($this->dbAnalysisStore);
05381 while(list($k,$v)=each($this->dbAnalysisStore)) {
05382 $id = $this->substNEWwithIDs[$v[2]];
05383 if ($id) {
05384 $v[2] = $id;
05385 $v[0]->writeMM($v[1],$v[2],$v[3]);
05386 }
05387 }
05388 }
05389
05395 function removeRegisteredFiles() {
05396 reset($this->removeFilesStore);
05397 while(list($k,$v)=each($this->removeFilesStore)) {
05398 unlink($v);
05399 }
05400 }
05401
05407 function removeCacheFiles() {
05408 return t3lib_extMgm::removeCacheFiles();
05409 }
05410
05421 function int_pageTreeInfo($CPtable,$pid,$counter, $rootID) {
05422 if ($counter) {
05423 $addW = !$this->admin ? ' AND '.$this->BE_USER->getPagePermsClause($this->pMap['show']) : '';
05424 $mres = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid', 'pages', 'pid='.intval($pid).$this->deleteClause('pages').$addW, '', 'sorting DESC');
05425 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($mres)) {
05426 if ($row['uid']!=$rootID) {
05427 $CPtable[$row['uid']] = $pid;
05428 if ($counter-1) {
05429 $CPtable = $this->int_pageTreeInfo($CPtable,$row['uid'],$counter-1, $rootID);
05430 }
05431 }
05432 }
05433 }
05434 return $CPtable;
05435 }
05436
05442 function compileAdminTables() {
05443 global $TCA;
05444 reset ($TCA);
05445 $listArr = array();
05446 while (list($table)=each($TCA)) {
05447 $listArr[]=$table;
05448 }
05449 return $listArr;
05450 }
05451
05459 function fixUniqueInPid($table,$uid) {
05460 global $TCA;
05461 if ($TCA[$table]) {
05462 t3lib_div::loadTCA($table);
05463 reset ($TCA[$table]['columns']);
05464 $curData=$this->recordInfo($table,$uid,'*');
05465 $newData=array();
05466 while (list($field,$conf)=each($TCA[$table]['columns'])) {
05467 if ($conf['config']['type']=='input') {
05468 $evalCodesArray = t3lib_div::trimExplode(',',$conf['config']['eval'],1);
05469 if (in_array('uniqueInPid',$evalCodesArray)) {
05470 $newV = $this->getUnique($table,$field,$curData[$field],$uid,$curData['pid']);
05471 if (strcmp($newV,$curData[$field])) {
05472 $newData[$field]=$newV;
05473 }
05474 }
05475 }
05476 }
05477
05478 if (count($newData)) {
05479 $this->updateDB($table,$uid,$newData);
05480 }
05481 }
05482 }
05483
05495 function fixCopyAfterDuplFields($table,$uid,$prevUid,$update, $newData=array()) {
05496 global $TCA;
05497 if ($TCA[$table] && $TCA[$table]['ctrl']['copyAfterDuplFields']) {
05498 t3lib_div::loadTCA($table);
05499 $prevData=$this->recordInfo($table,$prevUid,'*');
05500 $theFields = t3lib_div::trimExplode(',',$TCA[$table]['ctrl']['copyAfterDuplFields'],1);
05501 reset($theFields);
05502 while(list(,$field)=each($theFields)) {
05503 if ($TCA[$table]['columns'][$field] && ($update || !isset($newData[$field]))) {
05504 $newData[$field]=$prevData[$field];
05505 }
05506 }
05507 if ($update && count($newData)) {
05508 $this->updateDB($table,$uid,$newData);
05509 }
05510 }
05511 return $newData;
05512 }
05513
05520 function extFileFields($table) {
05521 global $TCA;
05522 $listArr=array();
05523 t3lib_div::loadTCA($table);
05524 if ($TCA[$table]['columns']) {
05525 reset($TCA[$table]['columns']);
05526 while (list($field,$configArr)=each($TCA[$table]['columns'])) {
05527 if ($configArr['config']['type']=='group' && $configArr['config']['internal_type']=='file') {
05528 $listArr[]=$field;
05529 }
05530 }
05531 }
05532 return $listArr;
05533 }
05534
05541 function getUniqueFields($table) {
05542 global $TCA;
05543
05544 $listArr=array();
05545 t3lib_div::loadTCA($table);
05546 if ($TCA[$table]['columns']) {
05547 reset($TCA[$table]['columns']);
05548 while (list($field,$configArr)=each($TCA[$table]['columns'])) {
05549 if ($configArr['config']['type']==='input') {
05550 $evalCodesArray = t3lib_div::trimExplode(',',$configArr['config']['eval'],1);
05551 if (in_array('uniqueInPid',$evalCodesArray) || in_array('unique',$evalCodesArray)) {
05552 $listArr[]=$field;
05553 }
05554 }
05555 }
05556 }
05557 return $listArr;
05558 }
05559
05566 function isReferenceField($conf) {
05567 return ($conf['type']=='group' && $conf['internal_type']=='db') || ($conf['type']=='select' && $conf['foreign_table']);
05568 }
05569
05577 function getInlineFieldType($conf) {
05578 if ($conf['type'] == 'inline' && $conf['foreign_table']) {
05579 if ($conf['foreign_field'])
05580 return 'field';
05581 elseif ($conf['MM'])
05582 return 'mm';
05583 else
05584 return 'list';
05585 }
05586 return false;
05587 }
05588
05600 function getCopyHeader($table,$pid,$field,$value,$count,$prevTitle='') {
05601 global $TCA;
05602
05603
05604 if ($count) {
05605 $checkTitle = $value.rtrim(' '.sprintf($this->prependLabel($table),$count));
05606 } else {
05607 $checkTitle = $value;
05608 }
05609
05610
05611 if ($prevTitle != $checkTitle || $count<100) {
05612 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid', $table, 'pid='.intval($pid).' AND '.$field.'='.$GLOBALS['TYPO3_DB']->fullQuoteStr($checkTitle, $table).$this->deleteClause($table), '', '', '1');
05613 if ($GLOBALS['TYPO3_DB']->sql_num_rows($res)) {
05614 return $this->getCopyHeader($table,$pid,$field,$value,$count+1,$checkTitle);
05615 }
05616 }
05617
05618
05619 return $checkTitle;
05620 }
05621
05629 function prependLabel($table) {
05630 global $TCA;
05631 if (is_object($GLOBALS['LANG'])) {
05632 $label = $GLOBALS['LANG']->sL($TCA[$table]['ctrl']['prependAtCopy']);
05633 } else {
05634 list($label) = explode('|',$TCA[$table]['ctrl']['prependAtCopy']);
05635 }
05636 return $label;
05637 }
05638
05646 function resolvePid($table,$pid) {
05647 global $TCA;
05648 $pid = intval($pid);
05649 if ($pid < 0) {
05650 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('pid', $table, 'uid='.abs($pid));
05651 $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
05652
05653
05654 if ($lookForLiveVersion = t3lib_BEfunc::getLiveVersionOfRecord($table,abs($pid),'pid')) {
05655 $row = $lookForLiveVersion;
05656 }
05657
05658 $pid = intval($row['pid']);
05659 } elseif ($this->BE_USER->workspace!==0 && $TCA[$table]['ctrl']['versioning_followPages']) {
05660 if ($WSdestPage = t3lib_BEfunc::getWorkspaceVersionOfRecord($this->BE_USER->workspace, 'pages', $pid, 'uid,t3ver_swapmode')) {
05661 if ($WSdestPage['t3ver_swapmode']==0) {
05662 $pid = $WSdestPage['uid'];
05663 }
05664 }
05665 }
05666 return $pid;
05667 }
05668
05676 function clearPrefixFromValue($table,$value) {
05677 global $TCA;
05678 $regex = sprintf(quotemeta($this->prependLabel($table)),'[0-9]*').'$';
05679 return @ereg_replace($regex,'',$value);
05680 }
05681
05691 function extFileFunctions($table,$field,$filelist,$func) {
05692 global $TCA;
05693 t3lib_div::loadTCA($table);
05694 $uploadFolder = $TCA[$table]['columns'][$field]['config']['uploadfolder'];
05695 if ($uploadFolder && trim($filelist)) {
05696 $uploadPath = $this->destPathFromUploadFolder($uploadFolder);
05697 $fileArray = explode(',',$filelist);
05698 while (list(,$theFile)=each($fileArray)) {
05699 $theFile=trim($theFile);
05700 if ($theFile) {
05701 switch($func) {
05702 case 'deleteAll':
05703 if (@is_file($uploadPath.'/'.$theFile)) {
05704 unlink ($uploadPath.'/'.$theFile);
05705 } else {
05706 $this->log($table,0,3,0,100,"Delete: Referenced file that was supposed to be deleted together with it's record didn't exist");
05707 }
05708 break;
05709 }
05710 }
05711 }
05712 }
05713 }
05714
05721 function noRecordsFromUnallowedTables($inList) {
05722 global $TCA;
05723 reset ($TCA);
05724 $inList = trim($this->rmComma(trim($inList)));
05725 if ($inList && !$this->admin) {
05726 while (list($table) = each($TCA)) {
05727 $mres = $GLOBALS['TYPO3_DB']->exec_SELECTquery('count(*)', $table, 'pid IN ('.$inList.')'.t3lib_BEfunc::deleteClause($table));
05728 $count = $GLOBALS['TYPO3_DB']->sql_fetch_row($mres);
05729 if ($count[0] && ($this->tableReadOnly($table) || !$this->checkModifyAccessList($table))) {
05730 return FALSE;
05731 }
05732 }
05733 }
05734 return TRUE;
05735 }
05736
05747 function notifyStageChange($stat,$stageId,$table,$id,$comment) {
05748 $workspaceRec = t3lib_BEfunc::getRecord('sys_workspace', $stat['uid']);
05749
05750 if (is_array($workspaceRec)) {
05751
05752
05753 switch((int)$stageId) {
05754 case 1:
05755 $newStage = 'Ready for review';
05756 break;
05757 case 10:
05758 $newStage = 'Ready for publishing';
05759 break;
05760 case -1:
05761 $newStage = 'Element was rejected!';
05762 break;
05763 case 0:
05764 $newStage = 'Rejected element was noticed and edited';
05765 break;
05766 default:
05767 $newStage = 'Unknown state change!?';
05768 break;
05769 }
05770
05771
05772 $emails = array();
05773 switch((int)$stat['stagechg_notification']) {
05774 case 1:
05775 switch((int)$stageId) {
05776 case 1:
05777 $emails = $this->notifyStageChange_getEmails($workspaceRec['reviewers']);
05778 break;
05779 case 10:
05780 $emails = $this->notifyStageChange_getEmails($workspaceRec['adminusers'], TRUE);
05781 break;
05782 case -1:
05783 $emails = $this->notifyStageChange_getEmails($workspaceRec['reviewers']);
05784 $emails = array_merge($emails,$this->notifyStageChange_getEmails($workspaceRec['members']));
05785 break;
05786 case 0:
05787 $emails = $this->notifyStageChange_getEmails($workspaceRec['members']);
05788 break;
05789 default:
05790 $emails = $this->notifyStageChange_getEmails($workspaceRec['adminusers'], TRUE);
05791 break;
05792 }
05793 break;
05794 case 10:
05795 $emails = $this->notifyStageChange_getEmails($workspaceRec['adminusers'], TRUE);
05796 $emails = array_merge($emails,$this->notifyStageChange_getEmails($workspaceRec['reviewers']));
05797 $emails = array_merge($emails,$this->notifyStageChange_getEmails($workspaceRec['members']));
05798 break;
05799 }
05800 $emails = array_unique($emails);
05801
05802
05803 if (count($emails)) {
05804 $message = sprintf('
05805 At the TYPO3 site "%s" (%s)
05806 in workspace "%s" (#%s)
05807 the stage has changed for the element "%s":
05808
05809 ==> %s
05810
05811 User Comment:
05812 "%s"
05813
05814 State was change by %s (username: %s)
05815 ',
05816 $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'],
05817 t3lib_div::getIndpEnv('TYPO3_SITE_URL').TYPO3_mainDir,
05818 $workspaceRec['title'],
05819 $workspaceRec['uid'],
05820 $table.':'.$id,
05821 $newStage,
05822 $comment,
05823 $this->BE_USER->user['realName'],
05824 $this->BE_USER->user['username']);
05825
05826 t3lib_div::plainMailEncoded(
05827 implode(',',$emails),
05828 'TYPO3 Workspace Note: Stage Change for '.$table.':'.$id,
05829 trim($message)
05830 );
05831 }
05832 }
05833 }
05834
05842 function notifyStageChange_getEmails($listOfUsers,$noTablePrefix=FALSE) {
05843 $users = t3lib_div::trimExplode(',',$listOfUsers,1);
05844 $emails = array();
05845 foreach($users as $userIdent) {
05846 if ($noTablePrefix) {
05847 $id = intval($userIdent);
05848 } else {
05849 list($table,$id) = t3lib_div::revExplode('_',$userIdent,2);
05850 }
05851 if ($table==='be_users' || $noTablePrefix) {
05852 if ($userRecord = t3lib_BEfunc::getRecord('be_users', $id, 'email')) {
05853 if (strlen(trim($userRecord['email']))) {
05854 $emails[$id] = $userRecord['email'];
05855 }
05856 }
05857 }
05858 }
05859 return $emails;
05860 }
05861
05862
05863
05864
05865
05866
05867
05868
05869
05870
05871
05872
05873
05874
05875
05876
05877
05878
05888 function clear_cache($table,$uid) {
05889 global $TCA, $TYPO3_CONF_VARS;
05890
05891 $uid = intval($uid);
05892 if (is_array($TCA[$table]) && $uid > 0) {
05893
05894
05895 list($tscPID) = t3lib_BEfunc::getTSCpid($table,$uid,'');
05896 $TSConfig = $this->getTCEMAIN_TSconfig($tscPID);
05897
05898 if (!$TSConfig['clearCache_disable']) {
05899
05900
05901 if (t3lib_extMgm::isLoaded('cms')) {
05902 $list_cache = array();
05903 if ($table=='pages') {
05904
05905
05906 $res_tmp = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
05907 'A.pid AS pid, B.uid AS uid',
05908 'pages A, pages B',
05909 'A.uid='.intval($uid).' AND B.pid=A.pid AND B.deleted=0'
05910 );
05911
05912 $pid_tmp = 0;
05913 while ($row_tmp = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res_tmp)) {
05914 $list_cache[] = $row_tmp['uid'];
05915 $pid_tmp = $row_tmp['pid'];
05916
05917
05918 if ($TSConfig['clearCache_pageSiblingChildren']) {
05919 $res_tmp2 = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
05920 'uid',
05921 'pages',
05922 'pid='.intval($row_tmp['uid']).' AND deleted=0'
05923 );
05924 while ($row_tmp2 = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res_tmp2)) {
05925 $list_cache[] = $row_tmp2['uid'];
05926 }
05927 }
05928 }
05929
05930
05931 $list_cache[] = $pid_tmp;
05932
05933
05934 if ($TSConfig['clearCache_pageGrandParent']) {
05935 $res_tmp = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
05936 'pid',
05937 'pages',
05938 'uid='.intval($pid_tmp)
05939 );
05940 if ($row_tmp = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res_tmp)) {
05941 $list_cache[] = $row_tmp['pid'];
05942 }
05943 }
05944 } else {
05945 $list_cache[] = intval($this->getPID($table,$uid));
05946 }
05947
05948
05949 if (is_array($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['clearPageCacheEval'])) {
05950 foreach($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['clearPageCacheEval'] as $funcName) {
05951 $_params = array('pageIdArray' => &$list_cache, 'table' => $table, 'uid' => $uid, 'functionID' => 'clear_cache()');
05952
05953 t3lib_div::callUserFunction($funcName,$_params,$this);
05954 }
05955 }
05956
05957
05958 if (is_array($list_cache)) {
05959 $GLOBALS['TYPO3_DB']->exec_DELETEquery('cache_pages','page_id IN ('.implode(',',$GLOBALS['TYPO3_DB']->cleanIntArray($list_cache)).')');
05960 $GLOBALS['TYPO3_DB']->exec_DELETEquery('cache_pagesection', 'page_id IN ('.implode(',',$GLOBALS['TYPO3_DB']->cleanIntArray($list_cache)).')');
05961 }
05962 }
05963 }
05964
05965
05966 if ($TSConfig['clearCacheCmd']) {
05967 $Commands = t3lib_div::trimExplode(',',strtolower($TSConfig['clearCacheCmd']),1);
05968 $Commands = array_unique($Commands);
05969 foreach($Commands as $cmdPart) {
05970 $this->clear_cacheCmd($cmdPart);
05971 }
05972 }
05973
05974
05975 global $TYPO3_CONF_VARS;
05976 if (is_array($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['clearCachePostProc'])) {
05977
05978 $_params = array('table' => $table,'uid' => $uid,'uid_page' => $uid_page,'TSConfig' => $TSConfig);
05979 foreach($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['clearCachePostProc'] as $_funcRef) {
05980 t3lib_div::callUserFunction($_funcRef,$_params,$this);
05981 }
05982 }
05983 }
05984 }
05985
05998 function clear_cacheCmd($cacheCmd) {
05999 global $TYPO3_CONF_VARS;
06000
06001
06002 switch($cacheCmd) {
06003 case 'pages':
06004 if ($this->admin || $this->BE_USER->getTSConfigVal('options.clearCache.pages')) {
06005 if (t3lib_extMgm::isLoaded('cms')) {
06006 $GLOBALS['TYPO3_DB']->exec_DELETEquery('cache_pages','');
06007 }
06008 }
06009 break;
06010 case 'all':
06011 if ($this->admin || $this->BE_USER->getTSConfigVal('options.clearCache.all')) {
06012 if (t3lib_extMgm::isLoaded('cms')) {
06013 $GLOBALS['TYPO3_DB']->exec_DELETEquery('cache_pages','');
06014 $GLOBALS['TYPO3_DB']->exec_DELETEquery('cache_pagesection','');
06015 }
06016 $GLOBALS['TYPO3_DB']->exec_DELETEquery('cache_hash','');
06017
06018
06019 if (is_array($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['clearAllCache_additionalTables'])) {
06020 foreach($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['clearAllCache_additionalTables'] as $tableName) {
06021 if (!ereg('[^[:alnum:]_]',$tableName) && substr($tableName,-5)=='cache') {
06022 $GLOBALS['TYPO3_DB']->exec_DELETEquery($tableName,'');
06023 } else {
06024 die('Fatal Error: Trying to flush table "'.$tableName.'" with "Clear All Cache"');
06025 }
06026 }
06027 }
06028 }
06029 break;
06030 case 'temp_CACHED':
06031 if ($this->admin && $TYPO3_CONF_VARS['EXT']['extCache']) {
06032 $this->removeCacheFiles();
06033 }
06034 break;
06035 }
06036
06037
06038 if (t3lib_div::testInt($cacheCmd)) {
06039 if (t3lib_extMgm::isLoaded('cms')) {
06040
06041 $list_cache = array($cacheCmd);
06042
06043
06044 if (is_array($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['clearPageCacheEval'])) {
06045 foreach($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['clearPageCacheEval'] as $funcName) {
06046 $_params = array('pageIdArray' => &$list_cache, 'cacheCmd' => $cacheCmd, 'functionID' => 'clear_cacheCmd()');
06047
06048 t3lib_div::callUserFunction($funcName,$_params,$this);
06049 }
06050 }
06051
06052
06053 if (is_array($list_cache)) {
06054 $GLOBALS['TYPO3_DB']->exec_DELETEquery('cache_pages','page_id IN ('.implode(',',$GLOBALS['TYPO3_DB']->cleanIntArray($list_cache)).')');
06055 $GLOBALS['TYPO3_DB']->exec_DELETEquery('cache_pagesection', 'page_id IN ('.implode(',',$GLOBALS['TYPO3_DB']->cleanIntArray($list_cache)).')');
06056 }
06057 }
06058 }
06059
06060
06061 if (is_array($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['clearCachePostProc'])) {
06062 $_params = array('cacheCmd'=>$cacheCmd);
06063 foreach($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['clearCachePostProc'] as $_funcRef) {
06064 t3lib_div::callUserFunction($_funcRef,$_params,$this);
06065 }
06066 }
06067 }
06068
06069
06070
06071
06072
06073
06074
06075
06076
06077
06078
06079
06080
06081
06082
06083
06084
06085
06086
06087
06104 function log($table,$recuid,$action,$recpid,$error,$details,$details_nr=-1,$data=array(),$event_pid=-1,$NEWid='') {
06105 if ($this->enableLogging) {
06106 $type=1;
06107 if (!$this->storeLogMessages) {$details='';}
06108 if ($error>0) $this->errorLog[] = '['.$type.'.'.$action.'.'.$details_nr.']: '.$details;
06109 return $this->BE_USER->writelog($type,$action,$error,$details_nr,$details,$data,$table,$recuid,$recpid,$event_pid,$NEWid);
06110 }
06111 }
06112
06121 function newlog($message, $error=0) {
06122 return $this->log('',0,0,0,$error,$message,-1);
06123 }
06124
06131 function printLogErrorMessages($redirect) {
06132
06133 $res_log = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
06134 '*',
06135 'sys_log',
06136 'type=1 AND userid='.intval($this->BE_USER->user['uid']).' AND tstamp='.intval($GLOBALS['EXEC_TIME']).' AND error!=0'
06137 );
06138 $errorJS = array();
06139 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res_log)) {
06140 $log_data = unserialize($row['log_data']);
06141 $errorJS[] = $row['error'].': '.sprintf($row['details'], $log_data[0],$log_data[1],$log_data[2],$log_data[3],$log_data[4]);
06142 }
06143
06144 if (count($errorJS)) {
06145 $error_doc = t3lib_div::makeInstance('template');
06146 $error_doc->backPath = $GLOBALS['BACK_PATH'];
06147
06148 $content.= $error_doc->startPage('tce_db.php Error output');
06149
06150 $lines[] = '
06151 <tr class="bgColor5">
06152 <td colspan="2" align="center"><strong>Errors:</strong></td>
06153 </tr>';
06154
06155 foreach($errorJS as $line) {
06156 $lines[] = '
06157 <tr class="bgColor4">
06158 <td valign="top"><img'.t3lib_iconWorks::skinImg($error_doc->backPath,'gfx/icon_fatalerror.gif','width="18" height="16"').' alt="" /></td>
06159 <td>'.htmlspecialchars($line).'</td>
06160 </tr>';
06161 }
06162
06163 $lines[] = '
06164 <tr>
06165 <td colspan="2" align="center"><br />'.
06166 '<form action=""><input type="submit" value="Continue" onclick="'.htmlspecialchars('window.location.href=\''.$redirect.'\';return false;').'"></form>'.
06167 '</td>
06168 </tr>';
06169
06170 $content.= '
06171 <br/><br/>
06172 <table border="0" cellpadding="1" cellspacing="1" width="300" align="center">
06173 '.implode('',$lines).'
06174 </table>';
06175
06176 $content.= $error_doc->endPage();
06177 echo $content;
06178 exit;
06179 }
06180 }
06181 }
06182
06183
06184
06185 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_tcemain.php']) {
06186 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_tcemain.php']);
06187 }
06188 ?>