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
00163
00164
00165
00166 require_once (PATH_t3lib.'class.t3lib_loaddbgroup.php');
00167 require_once (PATH_t3lib.'class.t3lib_parsehtml_proc.php');
00168 require_once (PATH_t3lib.'class.t3lib_stdgraphic.php');
00169 require_once (PATH_t3lib.'class.t3lib_basicfilefunc.php');
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00199 class t3lib_TCEmain {
00200 var $log_table = 'sys_log';
00201
00202 var $checkStoredRecords = 1;
00203 var $checkStoredRecords_loose=1;
00204 var $sortIntervals = 256;
00205
00206 var $deleteTree = 0;
00207 var $copyTree = 0;
00208 var $versionizeTree = 0;
00209 var $neverHideAtCopy = 0;
00210 var $reverseOrder=0;
00211 var $copyWhichTables = '*';
00212 var $stripslashes_values=1;
00213 var $storeLogMessages=1;
00214 var $enableLogging=1;
00215
00216 var $callBackObj;
00217
00218
00219 var $checkSimilar=1;
00220 var $dontProcessTransformations=0;
00221 # var $disableRTE = 0; // Boolean: If set, the RTE is expected to have been disabled in the interface which submitted information. Thus transformations related to the RTE is not done.
00222
00223 var $pMap = Array(
00224 'show' => 1,
00225 'edit' => 2,
00226 'delete' => 4,
00227 'new' => 8,
00228 'editcontent' => 16
00229 );
00230 var $defaultPermissions = array(
00231 'user' => 'show,edit,delete,new,editcontent',
00232 'group' => 'show,edit,new,editcontent',
00233 'everybody' => ''
00234 );
00235
00236
00237 var $alternativeFileName=array();
00238 var $data_disableFields=array();
00239 var $defaultValues=array();
00240 var $overrideValues=array();
00241 var $suggestedInsertUids=array();
00242
00243
00244
00245
00246 var $fileFunc;
00247 var $last_log_id;
00248 var $BE_USER;
00249 var $userid;
00250 var $username;
00251 var $admin;
00252 var $exclude_array;
00253
00254 var $data = Array();
00255 var $datamap = Array();
00256 var $cmd = Array();
00257 var $cmdmap = Array();
00258 var $uploadedFileArray = array();
00259
00260 var $cachedTSconfig = array();
00261 var $substNEWwithIDs = Array();
00262 var $substNEWwithIDs_table = Array();
00263 var $recUpdateAccessCache = Array();
00264 var $recInsertAccessCache = Array();
00265 var $isRecordInWebMount_Cache=array();
00266 var $isInWebMount_Cache=array();
00267 var $pageCache = Array();
00268 var $copyMappingArray = Array();
00269 var $copyMappingArray_merged = Array();
00270 var $registerDBList=array();
00271 var $dbAnalysisStore=array();
00272 var $removeFilesStore=array();
00273 var $copiedFileMap=array();
00274
00275 var $checkValue_currentRecord=array();
00276
00277
00288 function start($data,$cmd,$altUserObject='') {
00289
00290 $this->BE_USER = is_object($altUserObject) ? $altUserObject : $GLOBALS['BE_USER'];
00291 $this->userid = $this->BE_USER->user['uid'];
00292 $this->username = $this->BE_USER->user['username'];
00293 $this->admin = $this->BE_USER->user['admin'];
00294
00295
00296 $defaultPermissions = $GLOBALS['TYPO3_CONF_VARS']['BE']['defaultPermissions'];
00297 if (isset($defaultPermissions['user'])) {$this->defaultPermissions['user'] = $defaultPermissions['user'];}
00298 if (isset($defaultPermissions['group'])) {$this->defaultPermissions['group'] = $defaultPermissions['group'];}
00299 if (isset($defaultPermissions['everybody'])) {$this->defaultPermissions['everybody'] = $defaultPermissions['everybody'];}
00300
00301
00302 $this->exclude_array = ($this->admin) ? array() : $this->getExcludeListArray();
00303
00304
00305 if (is_array($data)) {
00306 reset($data);
00307 $this->datamap = $data;
00308 }
00309 if (is_array($cmd)) {
00310 reset($cmd);
00311 $this->cmdmap = $cmd;
00312 }
00313 }
00314
00321 function setMirror($mirror) {
00322 if (is_array($mirror)) {
00323 reset($mirror);
00324 while(list($table,$uid_array)=each($mirror)) {
00325 if (isset($this->datamap[$table])) {
00326 reset($uid_array);
00327 while (list($id,$uidList) = each($uid_array)) {
00328 if (isset($this->datamap[$table][$id])) {
00329 $theIdsInArray = t3lib_div::trimExplode(',',$uidList,1);
00330 while(list(,$copyToUid)=each($theIdsInArray)) {
00331 $this->datamap[$table][$copyToUid] = $this->datamap[$table][$id];
00332 }
00333 }
00334 }
00335 }
00336 }
00337 }
00338 }
00339
00346 function setDefaultsFromUserTS($userTS) {
00347 global $TCA;
00348 if (is_array($userTS)) {
00349 foreach($userTS as $k => $v) {
00350 $k = substr($k,0,-1);
00351 if ($k && is_array($v) && isset($TCA[$k])) {
00352 if (is_array($this->defaultValues[$k])) {
00353 $this->defaultValues[$k] = array_merge($this->defaultValues[$k],$v);
00354 } else {
00355 $this->defaultValues[$k] = $v;
00356 }
00357 }
00358 }
00359 }
00360 }
00361
00369 function process_uploads($postFiles) {
00370 if (is_array($postFiles)) {
00371 reset($postFiles);
00372 $subA = current($postFiles);
00373 if (is_array($subA)) {
00374 if (is_array($subA['name']) && is_array($subA['type']) && is_array($subA['tmp_name']) && is_array($subA['size'])) {
00375
00376 $this->uploadedFileArray=array();
00377
00378
00379 foreach($subA as $key => $values) {
00380 $this->process_uploads_traverseArray($this->uploadedFileArray,$values,$key);
00381 }
00382 } else {
00383 $this->uploadedFileArray=$subA;
00384 }
00385 }
00386 }
00387 }
00388
00399 function process_uploads_traverseArray(&$outputArr,$inputArr,$keyToSet) {
00400 if (is_array($inputArr)) {
00401 foreach($inputArr as $key => $value) {
00402 $this->process_uploads_traverseArray($outputArr[$key],$inputArr[$key],$keyToSet);
00403 }
00404 } else {
00405 $outputArr[$keyToSet]=$inputArr;
00406 }
00407 }
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
00435 function process_datamap() {
00436
00437 global $TCA, $TYPO3_CONF_VARS;
00438
00439
00440 $hookObjectsArr = array();
00441 if (is_array ($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processDatamapClass'])) {
00442 foreach ($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processDatamapClass'] as $classRef) {
00443 $hookObjectsArr[] = &t3lib_div::getUserObj($classRef);
00444 }
00445 }
00446
00447
00448 $orderOfTables = Array();
00449 if (isset($this->datamap['pages'])) {
00450 $orderOfTables[]='pages';
00451 }
00452 reset($this->datamap);
00453 while (list($table,) = each($this->datamap)) {
00454 if ($table!='pages') {
00455 $orderOfTables[]=$table;
00456 }
00457 }
00458
00459
00460 foreach($orderOfTables as $table) {
00461
00462
00463
00464
00465
00466
00467 $modifyAccessList = $this->checkModifyAccessList($table);
00468 if (!$modifyAccessList) {
00469 $this->log($table,$id,2,0,1,"Attempt to modify table '%s' without permission",1,array($table));
00470 }
00471 if (isset($TCA[$table]) && !$this->tableReadOnly($table) && is_array($this->datamap[$table]) && $modifyAccessList) {
00472 if ($this->reverseOrder) {
00473 $this->datamap[$table] = array_reverse($this->datamap[$table], 1);
00474 }
00475
00476
00477
00478
00479 foreach($this->datamap[$table] as $id => $incomingFieldArray) {
00480 if (is_array($incomingFieldArray)) {
00481
00482
00483 foreach($hookObjectsArr as $hookObj) {
00484 if (method_exists($hookObj, 'processDatamap_preProcessFieldArray')) {
00485 $hookObj->processDatamap_preProcessFieldArray($incomingFieldArray, $table, $id, $this);
00486 }
00487 }
00488
00489
00490
00491
00492 $recordAccess = 0;
00493 $old_pid_value = '';
00494 if (!t3lib_div::testInt($id)) {
00495 $fieldArray = $this->newFieldArray($table);
00496 if (isset($incomingFieldArray['pid'])) {
00497
00498 $pid_value = $incomingFieldArray['pid'];
00499
00500
00501 $OK = 1;
00502 if (strstr($pid_value,'NEW')) {
00503 if (substr($pid_value,0,1)=='-') {$negFlag=-1;$pid_value=substr($pid_value,1);} else {$negFlag=1;}
00504 if (isset($this->substNEWwithIDs[$pid_value])) {
00505 $old_pid_value = $pid_value;
00506 $pid_value=intval($negFlag*$this->substNEWwithIDs[$pid_value]);
00507 } else {$OK = 0;}
00508 }
00509 $pid_value = intval($pid_value);
00510
00511
00512 if ($OK) {
00513 $sortRow = $TCA[$table]['ctrl']['sortby'];
00514 if ($pid_value>=0) {
00515 if ($sortRow) {
00516 $fieldArray[$sortRow] = $this->getSortNumber($table,0,$pid_value);
00517 }
00518 $fieldArray['pid'] = $pid_value;
00519 } else {
00520 if ($sortRow) {
00521 $tempArray=$this->getSortNumber($table,0,$pid_value);
00522 $fieldArray['pid'] = $tempArray['pid'];
00523 $fieldArray[$sortRow] = $tempArray['sortNumber'];
00524 } else {
00525 $tempdata = $this->recordInfo($table,abs($pid_value),'pid');
00526 $fieldArray['pid']=$tempdata['pid'];
00527 }
00528 }
00529 }
00530 }
00531 $theRealPid = $fieldArray['pid'];
00532
00533 if ($theRealPid>=0) {
00534 $recordAccess = $this->checkRecordInsertAccess($table,$theRealPid);
00535 } else {
00536 debug('Internal ERROR: pid should not be less than zero!');
00537 }
00538 $status = 'new';
00539 } else {
00540 $fieldArray = Array();
00541 $recordAccess = $this->checkRecordUpdateAccess($table,$id);
00542 if (!$recordAccess) {
00543 $propArr = $this->getRecordProperties($table,$id);
00544 $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']);
00545 } else {
00546 $recordAccess = $this->BE_USER->recordEditAccessInternals($table,$id);
00547 if (!$recordAccess) {
00548 $propArr = $this->getRecordProperties($table,$id);
00549 $this->log($table,$id,2,0,1,"recordEditAccessInternals() check failed. [".$this->BE_USER->errorMsg."]",2,array($propArr['header'],$table.':'.$id),$propArr['event_pid']);
00550 } else {
00551 $tempdata = $this->recordInfo($table,$id,'pid');
00552 $theRealPid = $tempdata['pid'];
00553 }
00554 }
00555 $status = 'update';
00556 }
00557
00558
00559
00560
00561 if ($recordAccess) {
00562
00563 list($tscPID) = t3lib_BEfunc::getTSCpid($table,$id,$old_pid_value ? $old_pid_value : $fieldArray['pid']);
00564 $TSConfig = $this->getTCEMAIN_TSconfig($tscPID);
00565 if ($status=='new' && $table=='pages' && is_array($TSConfig['permissions.'])) {
00566 $fieldArray = $this->setTSconfigPermissions($fieldArray,$TSConfig['permissions.']);
00567 }
00568
00569 $fieldArray = $this->fillInFieldArray($table,$id,$fieldArray,$incomingFieldArray,$theRealPid,$status,$tscPID);
00570
00571
00572
00573 $fieldArray = $this->overrideFieldArray($table,$fieldArray);
00574
00575
00576 if ($status=='new') {
00577 if ($TCA[$table]['ctrl']['crdate']) {
00578 $fieldArray[$TCA[$table]['ctrl']['crdate']]=time();
00579 }
00580 if ($TCA[$table]['ctrl']['cruser_id']) {
00581 $fieldArray[$TCA[$table]['ctrl']['cruser_id']]=$this->userid;
00582 }
00583 } elseif ($this->checkSimilar) {
00584 $fieldArray = $this->compareFieldArrayWithCurrentAndUnset($table,$id,$fieldArray);
00585 }
00586 if ($TCA[$table]['ctrl']['tstamp']) {
00587 $fieldArray[$TCA[$table]['ctrl']['tstamp']]=time();
00588 }
00589
00590
00591 foreach($hookObjectsArr as $hookObj) {
00592 if (method_exists($hookObj, 'processDatamap_postProcessFieldArray')) {
00593 $hookObj->processDatamap_postProcessFieldArray($status, $table, $id, $fieldArray, $this);
00594 }
00595 }
00596
00597
00598
00599 if (is_array($fieldArray)) {
00600 if ($status=='new') {
00601
00602 $this->insertDB($table,$id,$fieldArray,FALSE,$incomingFieldArray['uid']);
00603 } else {
00604 $this->updateDB($table,$id,$fieldArray);
00605 }
00606 }
00607
00608
00609 foreach($hookObjectsArr as $hookObj) {
00610 if (method_exists($hookObj, 'processDatamap_afterDatabaseOperations')) {
00611 $hookObj->processDatamap_afterDatabaseOperations($status, $table, $id, $fieldArray, $this);
00612 }
00613 }
00614 }
00615 }
00616 }
00617 }
00618 }
00619 $this->dbAnalysisStoreExec();
00620 $this->removeRegisteredFiles();
00621 }
00622
00636 function fillInFieldArray($table,$id,$fieldArray,$incomingFieldArray,$realPid,$status,$tscPID) {
00637 global $TCA;
00638
00639
00640 t3lib_div::loadTCA($table);
00641 unset($originalLanguageRecord);
00642 unset($originalLanguage_diffStorage);
00643 $diffStorageFlag = FALSE;
00644
00645
00646 if (strstr($id,'NEW')) {
00647 $currentRecord = $checkValueRecord = $fieldArray;
00648
00649
00650
00651 if (is_array($incomingFieldArray) && is_array($checkValueRecord)) {
00652 $checkValueRecord = t3lib_div::array_merge_recursive_overrule($checkValueRecord, $incomingFieldArray);
00653 }
00654 } else {
00655 $currentRecord = $checkValueRecord = $this->recordInfo($table,$id,'*');
00656
00657
00658 if (is_array($currentRecord)
00659 && $TCA[$table]['ctrl']['transOrigDiffSourceField']
00660 && $TCA[$table]['ctrl']['languageField']
00661 && $currentRecord[$TCA[$table]['ctrl']['languageField']] > 0
00662 && $TCA[$table]['ctrl']['transOrigPointerField']
00663 && intval($currentRecord[$TCA[$table]['ctrl']['transOrigPointerField']]) > 0) {
00664
00665 $lookUpTable = $TCA[$table]['ctrl']['transOrigPointerTable'] ? $TCA[$table]['ctrl']['transOrigPointerTable'] : $table;
00666 $originalLanguageRecord = $this->recordInfo($lookUpTable,$currentRecord[$TCA[$table]['ctrl']['transOrigPointerField']],'*');
00667 $originalLanguage_diffStorage = unserialize($currentRecord[$TCA[$table]['ctrl']['transOrigDiffSourceField']]);
00668 }
00669 }
00670 $this->checkValue_currentRecord = $checkValueRecord;
00671
00672
00673
00674
00675
00676
00677
00678
00679
00680
00681 foreach($incomingFieldArray as $field => $fieldValue) {
00682 if (!in_array($table.'-'.$field, $this->exclude_array) && !$this->data_disableFields[$table][$id][$field]) {
00683
00684
00685 $languageDeny = $TCA[$table]['ctrl']['languageField'] && !strcmp($TCA[$table]['ctrl']['languageField'], $field) && !$this->BE_USER->checkLanguageAccess($fieldValue);
00686
00687 if (!$languageDeny) {
00688
00689 if ($this->stripslashes_values) {
00690 if (is_array($fieldValue)) {
00691 t3lib_div::stripSlashesOnArray($fieldValue);
00692 } else $fieldValue = stripslashes($fieldValue);
00693 }
00694
00695 switch ($field) {
00696 case 'uid':
00697 case 'pid':
00698
00699 break;
00700 case 'perms_userid':
00701 case 'perms_groupid':
00702 case 'perms_user':
00703 case 'perms_group':
00704 case 'perms_everybody':
00705
00706 if ($table=='pages' && ($this->admin || $status=='new' || $this->pageInfo($id,'perms_userid')==$this->userid) ) {
00707 $value=intval($fieldValue);
00708 switch($field) {
00709 case 'perms_userid':
00710 $fieldArray[$field]=$value;
00711 break;
00712 case 'perms_groupid':
00713 $fieldArray[$field]=$value;
00714 break;
00715 default:
00716 if ($value>=0 && $value<pow(2,5)) {
00717 $fieldArray[$field]=$value;
00718 }
00719 break;
00720 }
00721 }
00722 break;
00723 case 't3ver_oid':
00724 case 't3ver_id':
00725
00726 break;
00727 default:
00728 if (isset($TCA[$table]['columns'][$field])) {
00729
00730 $res = $this->checkValue($table,$field,$fieldValue,$id,$status,$realPid,$tscPID);
00731 if (isset($res['value'])) {
00732 $fieldArray[$field]=$res['value'];
00733
00734
00735 if ($TCA[$table]['ctrl']['transOrigDiffSourceField']) {
00736 $originalLanguage_diffStorage[$field] = $originalLanguageRecord[$field];
00737 $diffStorageFlag = TRUE;
00738 }
00739 }
00740 }
00741
00742
00743 break;
00744 }
00745 }
00746 }
00747 }
00748
00749
00750 if ($diffStorageFlag && !isset($fieldArray[$TCA[$table]['ctrl']['transOrigDiffSourceField']])) {
00751 $fieldArray[$TCA[$table]['ctrl']['transOrigDiffSourceField']] = serialize($originalLanguage_diffStorage);
00752 }
00753
00754
00755 $types_fieldConfig = t3lib_BEfunc::getTCAtypes($table,$currentRecord);
00756 $theTypeString = t3lib_BEfunc::getTCAtypeValue($table,$currentRecord);
00757 if (is_array($types_fieldConfig)) {
00758 reset($types_fieldConfig);
00759 while(list(,$vconf) = each($types_fieldConfig)) {
00760
00761 $eFile = t3lib_parsehtml_proc::evalWriteFile($vconf['spec']['static_write'],array_merge($currentRecord,$fieldArray));
00762
00763
00764 if (!$this->dontProcessTransformations) {
00765 if (isset($fieldArray[$vconf['field']])) {
00766
00767 switch((string)$incomingFieldArray['_TRANSFORM_'.$vconf['field']]) {
00768 case 'RTE':
00769 $RTEsetup = $this->BE_USER->getTSConfig('RTE',t3lib_BEfunc::getPagesTSconfig($tscPID));
00770 $thisConfig = t3lib_BEfunc::RTEsetup($RTEsetup['properties'],$table,$vconf['field'],$theTypeString);
00771
00772
00773 $RTErelPath = is_array($eFile) ? dirname($eFile['relEditFile']) : '';
00774
00775
00776 $RTEobj = &t3lib_BEfunc::RTEgetObj();
00777 if (is_object($RTEobj)) {
00778 $fieldArray[$vconf['field']] = $RTEobj->transformContent('db',$fieldArray[$vconf['field']],$table,$vconf['field'],$currentRecord,$vconf['spec'],$thisConfig,$RTErelPath,$currentRecord['pid']);
00779 } else {
00780 debug('NO RTE OBJECT FOUND!');
00781 }
00782 break;
00783 }
00784 }
00785 }
00786
00787
00788 if (is_array($eFile)) {
00789 $mixedRec = array_merge($currentRecord,$fieldArray);
00790 $SW_fileContent = t3lib_div::getUrl($eFile['editFile']);
00791 $parseHTML = t3lib_div::makeInstance('t3lib_parsehtml_proc');
00792 $parseHTML->init('','');
00793
00794 $eFileMarker = $eFile['markerField']&&trim($mixedRec[$eFile['markerField']]) ? trim($mixedRec[$eFile['markerField']]) : '###TYPO3_STATICFILE_EDIT###';
00795 $insertContent = str_replace($eFileMarker,'',$mixedRec[$eFile['contentField']]);
00796
00797 $SW_fileNewContent = $parseHTML->substituteSubpart($SW_fileContent, $eFileMarker, chr(10).$insertContent.chr(10), 1, 1);
00798 t3lib_div::writeFile($eFile['editFile'],$SW_fileNewContent);
00799
00800
00801 if (!strstr($id,'NEW') && $eFile['statusField']) {
00802 $GLOBALS['TYPO3_DB']->exec_UPDATEquery(
00803 $table,
00804 'uid='.intval($id),
00805 array(
00806 $eFile['statusField'] => $eFile['relEditFile'].' updated '.date('d-m-Y H:i:s').', bytes '.strlen($mixedRec[$eFile['contentField']])
00807 )
00808 );
00809 }
00810 } elseif ($eFile && is_string($eFile)) {
00811 $this->log($insertTable,$id,2,0,1,"Write-file error: '%s'",13,array($eFile),$realPid);
00812 }
00813 }
00814 }
00815
00816 return $fieldArray;
00817 }
00818
00827 function checkModifyAccessList($table) {
00828 $res = ($this->admin || (!$this->tableAdminOnly($table) && t3lib_div::inList($this->BE_USER->groupData['tables_modify'],$table)));
00829 return $res;
00830 }
00831
00839 function isRecordInWebMount($table,$id) {
00840 if (!isset($this->isRecordInWebMount_Cache[$table.':'.$id])) {
00841 $recP=$this->getRecordProperties($table,$id);
00842 $this->isRecordInWebMount_Cache[$table.':'.$id]=$this->isInWebMount($recP['event_pid']);
00843 }
00844 return $this->isRecordInWebMount_Cache[$table.':'.$id];
00845 }
00846
00853 function isInWebMount($pid) {
00854 if (!isset($this->isInWebMount_Cache[$pid])) {
00855 $this->isInWebMount_Cache[$pid]=$this->BE_USER->isInWebMount($pid);
00856 }
00857
00858 return $this->isInWebMount_Cache[$pid];
00859 }
00860
00870 function checkRecordUpdateAccess($table,$id) {
00871 global $TCA;
00872 $res = 0;
00873 if ($TCA[$table] && intval($id)>0) {
00874 if (isset($this->recUpdateAccessCache[$table][$id])) {
00875 return $this->recUpdateAccessCache[$table][$id];
00876
00877 } elseif ($this->doesRecordExist($table,$id,'edit')) {
00878 $res = 1;
00879 }
00880 $this->recUpdateAccessCache[$table][$id]=$res;
00881 }
00882 return $res;
00883 }
00884
00895 function checkRecordInsertAccess($insertTable,$pid,$action=1) {
00896 global $TCA;
00897 $res = 0;
00898 $pid = intval($pid);
00899 if ($pid>=0) {
00900 if (isset($this->recInsertAccessCache[$insertTable][$pid])) {
00901 return $this->recInsertAccessCache[$insertTable][$pid];
00902 } else {
00903
00904 if ( (!$pid && $this->admin) || $this->doesRecordExist('pages',$pid,($insertTable=='pages'?$this->pMap['new']:$this->pMap['editcontent'])) ) {
00905 if ($this->isTableAllowedForThisPage($pid, $insertTable)) {
00906 $res = 1;
00907 $this->recInsertAccessCache[$insertTable][$pid]=$res;
00908 } else {
00909 $propArr = $this->getRecordProperties('pages',$pid);
00910 $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']);
00911 }
00912 } else {
00913 $propArr = $this->getRecordProperties('pages',$pid);
00914 $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']);
00915 }
00916 }
00917 }
00918 return $res;
00919 }
00920
00931 function isTableAllowedForThisPage($page_uid, $checkTable) {
00932 global $TCA, $PAGES_TYPES;
00933 $page_uid = intval($page_uid);
00934
00935
00936 if (($TCA[$checkTable]['ctrl']['rootLevel'] xor !$page_uid) && $TCA[$checkTable]['ctrl']['rootLevel']!=-1 && $checkTable!='pages') {
00937 return false;
00938 }
00939
00940
00941 if (!$page_uid) {
00942 if ($this->admin) {
00943 return true;
00944 }
00945 } else {
00946
00947 $doktype = $this->pageInfo($page_uid,'doktype');
00948 $allowedTableList = isset($PAGES_TYPES[$doktype]['allowedTables']) ? $PAGES_TYPES[$doktype]['allowedTables'] : $PAGES_TYPES['default']['allowedTables'];
00949 $allowedArray = t3lib_div::trimExplode(',',$allowedTableList,1);
00950 if (strstr($allowedTableList,'*') || in_array($checkTable,$allowedArray)) {
00951 return true;
00952 }
00953 }
00954 }
00955
00966 function doesRecordExist($table,$id,$perms) {
00967 global $TCA;
00968
00969 $res = 0;
00970 $id = intval($id);
00971
00972
00973 if (!t3lib_div::testInt($perms)) {
00974 if ($table!='pages') {
00975 switch($perms) {
00976 case 'edit':
00977 case 'delete':
00978 case 'new':
00979 $perms = 'editcontent';
00980 break;
00981 }
00982 }
00983 $perms = intval($this->pMap[$perms]);
00984 } else {
00985 $perms = intval($perms);
00986 }
00987
00988 if (!$perms) {debug('Internal ERROR: no permissions to check for non-admin user.');}
00989
00990
00991
00992 if (is_array($TCA[$table]) && $id>0 && ($this->isRecordInWebMount($table,$id) || $this->admin)) {
00993 if ($table != 'pages') {
00994
00995
00996 $mres = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid,pid', $table, 'uid='.intval($id).$this->deleteClause($table));
00997 $output = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($mres);
00998 t3lib_BEfunc::fixVersioningPid($table,$output);
00999
01000
01001 if (is_array($output)) {
01002
01003
01004 $mres = $this->doesRecordExist_pageLookUp($output['pid'], $perms);
01005 $pageRec = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($mres);
01006
01007
01008 if (is_array($pageRec) || (!$output['pid'] && $this->admin)) {
01009 return TRUE;
01010 }
01011 }
01012 return FALSE;
01013 } else {
01014 $mres = $this->doesRecordExist_pageLookUp($id, $perms);
01015 return $GLOBALS['TYPO3_DB']->sql_num_rows($mres);
01016 }
01017 }
01018 }
01019
01029 function doesRecordExist_pageLookUp($id, $perms) {
01030 global $TCA;
01031
01032 return $GLOBALS['TYPO3_DB']->exec_SELECTquery(
01033 'uid',
01034 'pages',
01035 'uid='.intval($id).
01036 $this->deleteClause('pages').
01037 ($perms && !$this->admin ? ' AND '.$this->BE_USER->getPagePermsClause($perms) : '').
01038 (!$this->admin && $TCA['pages']['ctrl']['editlock'] && ($perms & (2+4+16)) ? ' AND '.$TCA['pages']['ctrl']['editlock'].'=0':'')
01039 );
01040 }
01041
01055 function doesBranchExist($inList,$pid,$perms, $recurse) {
01056 global $TCA;
01057 $pid = intval($pid);
01058 $perms = intval($perms);
01059 if ($pid>=0) {
01060 $mres = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
01061 'uid, perms_userid, perms_groupid, perms_user, perms_group, perms_everybody',
01062 'pages',
01063 'pid='.intval($pid).$this->deleteClause('pages'),
01064 '',
01065 'sorting'
01066 );
01067 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($mres)) {
01068 if ($this->admin || $this->BE_USER->doesUserHaveAccess($row,$perms)) {
01069 $inList.=$row['uid'].',';
01070 if ($recurse) {
01071 $inList = $this->doesBranchExist($inList, $row['uid'], $perms, $recurse);
01072 if ($inList == -1) {return -1;}
01073 }
01074 } else {
01075 return -1;
01076 }
01077 }
01078 }
01079 return $inList;
01080 }
01081
01090 function pageInfo($id,$field) {
01091 if (!isset($this->pageCache[$id])) {
01092 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'pages', 'uid='.intval($id));
01093 if ($GLOBALS['TYPO3_DB']->sql_num_rows($res)) {
01094 $this->pageCache[$id] = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
01095 }
01096 $GLOBALS['TYPO3_DB']->sql_free_result($res);
01097 }
01098 return $this->pageCache[$id][$field];
01099 }
01100
01110 function recordInfo($table,$id,$fieldList) {
01111 global $TCA;
01112 if (is_array($TCA[$table])) {
01113 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($fieldList, $table, 'uid='.intval($id));
01114 if ($GLOBALS['TYPO3_DB']->sql_num_rows($res)) {
01115 return $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
01116 }
01117 }
01118 }
01119
01127 function getRecordProperties($table,$id) {
01128 $row = ($table=='pages' && !$id) ? array('title'=>'[root-level]', 'uid' => 0, 'pid' => 0) :$this->recordInfo($table,$id,'*');
01129 t3lib_BEfunc::fixVersioningPid($table,$row);
01130 return $this->getRecordPropertiesFromRow($table,$row);
01131 }
01132
01140 function getRecordPropertiesFromRow($table,$row) {
01141 global $TCA;
01142 if ($TCA[$table]) {
01143 $out = array(
01144 'header' => $row[$TCA[$table]['ctrl']['label']],
01145 'pid' => $row['pid'],
01146 'event_pid' => ($table=='pages'?$row['uid']:$row['pid'])
01147 );
01148 return $out;
01149 }
01150 }
01151
01159 function setTSconfigPermissions($fieldArray,$TSConfig_p) {
01160 if (strcmp($TSConfig_p['userid'],'')) $fieldArray['perms_userid']=intval($TSConfig_p['userid']);
01161 if (strcmp($TSConfig_p['groupid'],'')) $fieldArray['perms_groupid']=intval($TSConfig_p['groupid']);
01162 if (strcmp($TSConfig_p['user'],'')) $fieldArray['perms_user']=t3lib_div::testInt($TSConfig_p['user']) ? $TSConfig_p['user'] : $this->assemblePermissions($TSConfig_p['user']);
01163 if (strcmp($TSConfig_p['group'],'')) $fieldArray['perms_group']=t3lib_div::testInt($TSConfig_p['group']) ? $TSConfig_p['group'] : $this->assemblePermissions($TSConfig_p['group']);
01164 if (strcmp($TSConfig_p['everybody'],'')) $fieldArray['perms_everybody']=t3lib_div::testInt($TSConfig_p['everybody']) ? $TSConfig_p['everybody'] : $this->assemblePermissions($TSConfig_p['everybody']);
01165
01166 return $fieldArray;
01167 }
01168
01175 function newFieldArray($table) {
01176 global $TCA;
01177 t3lib_div::loadTCA($table);
01178 $fieldArray=Array();
01179 if (is_array($TCA[$table]['columns'])) {
01180 reset ($TCA[$table]['columns']);
01181 while (list($field,$content)=each($TCA[$table]['columns'])) {
01182 if (isset($this->defaultValues[$table][$field])) {
01183 $fieldArray[$field] = $this->defaultValues[$table][$field];
01184 } elseif (isset($content['config']['default'])) {
01185 $fieldArray[$field] = $content['config']['default'];
01186 }
01187 }
01188 }
01189 if ($table=='pages') {
01190 $fieldArray['perms_userid'] = $this->userid;
01191 $fieldArray['perms_groupid'] = intval($this->BE_USER->firstMainGroup);
01192 $fieldArray['perms_user'] = $this->assemblePermissions($this->defaultPermissions['user']);
01193 $fieldArray['perms_group'] = $this->assemblePermissions($this->defaultPermissions['group']);
01194 $fieldArray['perms_everybody'] = $this->assemblePermissions($this->defaultPermissions['everybody']);
01195 }
01196 return $fieldArray;
01197 }
01198
01206 function overrideFieldArray($table,$data) {
01207 if (is_array($this->overrideValues[$table])) {
01208 $data = array_merge($data,$this->overrideValues[$table]);
01209 }
01210 return $data;
01211 }
01212
01219 function assemblePermissions($string) {
01220 $keyArr = t3lib_div::trimExplode(',',$string,1);
01221 $value=0;
01222 while(list(,$key)=each($keyArr)) {
01223 if ($key && isset($this->pMap[$key])) {
01224 $value |= $this->pMap[$key];
01225 }
01226 }
01227 return $value;
01228 }
01229
01230
01231
01232
01233
01234
01235
01236
01237