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
00092 require_once (PATH_t3lib.'class.t3lib_basicfilefunc.php');
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00132 class user_feAdmin {
00133
00134
00135 var $recInMarkersHSC = TRUE;
00136
00137 var $dataArr = array();
00138 var $failureMsg = array();
00139 var $theTable = '';
00140 var $thePid = 0;
00141 var $markerArray = array();
00142 var $templateCode='';
00143 var $cObj;
00144
00145 var $cmd;
00146 var $preview;
00147 var $backURL;
00148 var $recUid;
00149 var $failure=0;
00150 var $error='';
00151 var $saved=0;
00152 var $requiredArr;
00153 var $currentArr = array();
00154 var $previewLabel='';
00155 var $nc = '';
00156 var $additionalUpdateFields='';
00157 var $emailMarkPrefix = 'EMAIL_TEMPLATE_';
00158 var $codeLength;
00159 var $cmdKey;
00160 var $fileFunc='';
00161 var $filesStoredInUploadFolders=array();
00162
00163
00164 var $unlinkTempFiles = array();
00165
00179 function init($content,$conf) {
00180 $this->conf = $conf;
00181
00182
00183 $this->templateCode = $this->conf['templateContent'] ? $this->conf['templateContent'] : $this->cObj->fileResource($this->conf['templateFile']);
00184
00185
00186 $this->cmd = (string)t3lib_div::_GP('cmd');
00187
00188 $this->preview = (string)t3lib_div::_GP('preview');
00189
00190 $this->backURL = t3lib_div::_GP('backURL');
00191 if (strstr($this->backURL, '"') || strstr($this->backURL, "'") || preg_match('/(javascript|vbscript):/i', $this->backURL) || stristr($this->backURL, "fromcharcode") || strstr($this->backURL, "<") || strstr($this->backURL, ">")) {
00192 $this->backURL = '';
00193 }
00194
00195 $this->backURL = preg_replace('|[A-Za-z]+:
00196
00197 $this->recUid = t3lib_div::_GP('rU');
00198
00199 $this->authCode = t3lib_div::_GP('aC');
00200
00201 $this->theTable = $this->conf['table'];
00202
00203 $linkConf = is_array($this->conf['formurl.']) ? $this->conf['formurl.'] : array();
00204
00205 $this->thePid = intval($this->conf['pid']) ? intval($this->conf['pid']) : $GLOBALS['TSFE']->id;
00206
00207 $this->codeLength = intval($this->conf['authcodeFields.']['codeLength']) ? intval($this->conf['authcodeFields.']['codeLength']) : 8;
00208
00209
00210 $this->fieldList=implode(',',t3lib_div::trimExplode(',',$GLOBALS['TCA'][$this->theTable]['feInterface']['fe_admin_fieldList'],1));
00211
00212
00213 $splitMark = md5(microtime());
00214 list($this->markerArray['###GW1B###'],$this->markerArray['###GW1E###']) = explode($splitMark,$this->cObj->stdWrap($splitMark,$this->conf['wrap1.']));
00215 list($this->markerArray['###GW2B###'],$this->markerArray['###GW2E###']) = explode($splitMark,$this->cObj->stdWrap($splitMark,$this->conf['wrap2.']));
00216 $this->markerArray['###GC1###'] = $this->cObj->stdWrap($this->conf['color1'],$this->conf['color1.']);
00217 $this->markerArray['###GC2###'] = $this->cObj->stdWrap($this->conf['color2'],$this->conf['color2.']);
00218 $this->markerArray['###GC3###'] = $this->cObj->stdWrap($this->conf['color3'],$this->conf['color3.']);
00219
00220 if (intval($this->conf['no_cache']) && !isset($linkConf['no_cache'])) {
00221 $linkConf['no_cache'] = 1;
00222 }
00223 if(!$linkConf['parameter']) {
00224 $linkConf['parameter'] = $GLOBALS['TSFE']->id;
00225 }
00226 if(!$linkConf['additionalParams']) {
00227 $linkConf['additionalParams'] = $this->conf['addParams'];
00228 }
00229
00230 $formURL = $this->cObj->typoLink_URL($linkConf);
00231 if(!strstr($formURL,'?')) {
00232 $formURL .= '?';
00233 }
00234
00235
00236 $this->markerArray['###FORM_URL###'] = $formURL;
00237 $this->markerArray['###FORM_URL_ENC###'] = rawurlencode($this->markerArray['###FORM_URL###']);
00238 $this->markerArray['###FORM_URL_HSC###'] = htmlspecialchars($this->markerArray['###FORM_URL###']);
00239
00240 $this->markerArray['###BACK_URL###'] = $this->backURL;
00241 $this->markerArray['###BACK_URL_ENC###'] = rawurlencode($this->markerArray['###BACK_URL###']);
00242 $this->markerArray['###BACK_URL_HSC###'] = htmlspecialchars($this->markerArray['###BACK_URL###']);
00243
00244 $this->markerArray['###THE_PID###'] = $this->thePid;
00245 $this->markerArray['###REC_UID###'] = $this->recUid;
00246 $this->markerArray['###AUTH_CODE###'] = $this->authCode;
00247 $this->markerArray['###THIS_ID###'] = $GLOBALS['TSFE']->id;
00248 $this->markerArray['###THIS_URL###'] = htmlspecialchars(t3lib_div::getIndpEnv('TYPO3_REQUEST_DIR'));
00249 $this->markerArray['###HIDDENFIELDS###'] =
00250 ($this->cmd?'<input type="hidden" name="cmd" value="'.htmlspecialchars($this->cmd).'" />':'').
00251 ($this->authCode?'<input type="hidden" name="aC" value="'.htmlspecialchars($this->authCode).'" />':'').
00252 ($this->backURL?'<input type="hidden" name="backURL" value="'.htmlspecialchars($this->backURL).'" />':'');
00253
00254
00255
00256 switch($this->cmd) {
00257 case 'edit':
00258 $this->cmdKey='edit';
00259 break;
00260 default:
00261 $this->cmdKey='create';
00262 break;
00263 }
00264
00265 $this->requiredArr = array_intersect(
00266 t3lib_div::trimExplode(',',$this->conf[$this->cmdKey.'.']['required'],1),
00267 t3lib_div::trimExplode(',',$this->conf[$this->cmdKey.'.']['fields'],1)
00268 );
00269
00270
00271 $fe=t3lib_div::_GP('FE');
00272 $this->dataArr = $fe[$this->theTable];
00273
00274
00275 if (!$this->templateCode) {
00276 $content = 'No template file found: '.$this->conf['templateFile'];
00277 return $content;
00278 }
00279
00280 if (!$this->theTable || !$this->fieldList) {
00281 $content = 'Wrong table: '.$this->theTable;
00282 return $content;
00283 }
00284
00285
00286
00287
00288 if ($this->cmd=='delete' && !$this->preview && !t3lib_div::_GP('doNotSave')) {
00289 $this->deleteRecord();
00290 }
00291
00292 if (is_array($this->dataArr)) {
00293
00294 $this->parseValues();
00295 $this->overrideValues();
00296 $this->evalValues();
00297 if ($this->conf['evalFunc']) {
00298 $this->dataArr = $this->userProcess('evalFunc',$this->dataArr);
00299 }
00300
00301
00302
00303
00304
00305
00306
00307 if (!$this->failure && !$this->preview && !t3lib_div::_GP('doNotSave')) {
00308 $this->save();
00309 } else {
00310 if ($this->conf['debug']) debug($this->failure);
00311 }
00312 } else {
00313 $this->defaultValues();
00314 $this->preview = 0;
00315 }
00316 if ($this->failure) {$this->preview=0;}
00317 $this->previewLabel = $this->preview ? '_PREVIEW' : '';
00318
00319
00320
00321
00322
00323 if ($this->saved) {
00324
00325 $this->clearCacheIfSet();
00326
00327
00328 switch($this->cmd) {
00329 case 'delete':
00330 $key='DELETE';
00331 break;
00332 case 'edit':
00333 $key='EDIT';
00334 break;
00335 default:
00336 $key='CREATE';
00337 break;
00338 }
00339
00340 $templateCode = $this->cObj->getSubpart($this->templateCode, '###TEMPLATE_'.$key.'_SAVED###');
00341 $this->setCObjects($templateCode,$this->currentArr);
00342 $markerArray = $this->cObj->fillInMarkerArray($this->markerArray, $this->currentArr, '', TRUE, 'FIELD_', $this->recInMarkersHSC);
00343 $content = $this->cObj->substituteMarkerArray($templateCode, $markerArray);
00344
00345
00346 $this->compileMail(
00347 $key.'_SAVED',
00348 array($this->currentArr),
00349 $this->currentArr[$this->conf['email.']['field']],
00350 $this->conf['setfixed.']
00351 );
00352
00353 } elseif ($this->error) {
00354 $templateCode = $this->cObj->getSubpart($this->templateCode, $this->error);
00355 $this->setCObjects($templateCode);
00356 $content = $this->cObj->substituteMarkerArray($templateCode, $this->markerArray);
00357 } else {
00358
00359 if (!$this->cmd) {
00360 $this->cmd=$this->conf['defaultCmd'];
00361 }
00362 if ($this->conf['debug']) debug('Display form: '.$this->cmd,1);
00363 switch($this->cmd) {
00364 case 'setfixed':
00365 $content = $this->procesSetFixed();
00366 break;
00367 case 'infomail':
00368 $content = $this->sendInfoMail();
00369 break;
00370 case 'delete':
00371 $content = $this->displayDeleteScreen();
00372 break;
00373 case 'edit':
00374 $content = $this->displayEditScreen();
00375 break;
00376 case 'create':
00377 $content = $this->displayCreateScreen();
00378 break;
00379 }
00380 }
00381
00382
00383 foreach($this->unlinkTempFiles as $tempFileName) {
00384 t3lib_div::unlink_tempfile($tempFileName);
00385 }
00386
00387
00388 return $content;
00389 }
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00428 function parseValues() {
00429 if (is_array($this->conf['parseValues.'])) {
00430 reset($this->conf['parseValues.']);
00431 while(list($theField,$theValue)=each($this->conf['parseValues.'])) {
00432 $listOfCommands = t3lib_div::trimExplode(',',$theValue,1);
00433 while(list(,$cmd)=each($listOfCommands)) {
00434 $cmdParts = split('\[|\]',$cmd);
00435 $theCmd=trim($cmdParts[0]);
00436 switch($theCmd) {
00437 case 'int':
00438 $this->dataArr[$theField]=intval($this->dataArr[$theField]);
00439 break;
00440 case 'lower':
00441 case 'upper':
00442 $this->dataArr[$theField] = $this->cObj->caseshift($this->dataArr[$theField],$theCmd);
00443 break;
00444 case 'nospace':
00445 $this->dataArr[$theField] = str_replace(' ', '', $this->dataArr[$theField]);
00446 break;
00447 case 'alpha':
00448 $this->dataArr[$theField] = ereg_replace('[^a-zA-Z]','',$this->dataArr[$theField]);
00449 break;
00450 case 'num':
00451 $this->dataArr[$theField] = ereg_replace('[^0-9]','',$this->dataArr[$theField]);
00452 break;
00453 case 'alphanum':
00454 $this->dataArr[$theField] = ereg_replace('[^a-zA-Z0-9]','',$this->dataArr[$theField]);
00455 break;
00456 case 'alphanum_x':
00457 $this->dataArr[$theField] = ereg_replace('[^a-zA-Z0-9_-]','',$this->dataArr[$theField]);
00458 break;
00459 case 'trim':
00460 $this->dataArr[$theField] = trim($this->dataArr[$theField]);
00461 break;
00462 case 'random':
00463 $this->dataArr[$theField] = substr(md5(uniqid(microtime(),1)),0,intval($cmdParts[1]));
00464 break;
00465 case 'files':
00466 if ($this->cmdKey=='create' && !t3lib_div::_GP('doNotSave')) {
00467 $this->processFiles($cmdParts,$theField);
00468 } else unset($this->dataArr[$theField]);
00469 break;
00470 case 'setEmptyIfAbsent':
00471 if (!isset($this->dataArr[$theField])) {
00472 $this->dataArr[$theField]='';
00473 }
00474 break;
00475 case 'multiple':
00476 if (is_array($this->dataArr[$theField])) {
00477 $this->dataArr[$theField] = implode(',',$this->dataArr[$theField]);
00478 }
00479 break;
00480 case 'checkArray':
00481 if (is_array($this->dataArr[$theField])) {
00482 reset($this->dataArr[$theField]);
00483 $val = 0;
00484 while(list($kk,$vv)=each($this->dataArr[$theField])) {
00485 $kk = t3lib_div::intInRange($kk,0);
00486 if ($kk<=30) {
00487 if ($vv) {
00488 $val|=pow(2,$kk);
00489 }
00490 }
00491 }
00492 $this->dataArr[$theField] = $val;
00493 } else {$this->dataArr[$theField]=0;}
00494 break;
00495 case 'uniqueHashInt':
00496 $otherFields = t3lib_div::trimExplode(';',$cmdParts[1],1);
00497 $hashArray=array();
00498 while(list(,$fN)=each($otherFields)) {
00499 $vv = $this->dataArr[$fN];
00500 $vv = ereg_replace('[[:space:]]','',$vv);
00501 $vv = ereg_replace('[^[:alnum:]]','',$vv);
00502 $vv = strtolower($vv);
00503 $hashArray[]=$vv;
00504 }
00505 $this->dataArr[$theField]=hexdec(substr(md5(serialize($hashArray)),0,8));
00506 break;
00507 }
00508 }
00509 }
00510 }
00511 }
00512
00523 function processFiles($cmdParts,$theField) {
00524
00525
00526 $filesArr = array();
00527
00528 if (is_string($this->dataArr[$theField])) {
00529 $tmpArr = explode(',',$this->dataArr[$theField]);
00530 reset($tmpArr);
00531 while(list(,$val)=each($tmpArr)) {
00532 $valParts = explode('|',$val);
00533 $filesArr[] = array (
00534 'name'=>$valParts[1],
00535 'tmp_name'=>PATH_site.'typo3temp/'.$valParts[0]
00536 );
00537 }
00538 } elseif (is_array($_FILES['FE'][$this->theTable][$theField]['name'])) {
00539 reset($_FILES['FE'][$this->theTable][$theField]['name']);
00540 while(list($kk,$vv)=each($_FILES['FE'][$this->theTable][$theField]['name'])) {
00541 if ($vv) {
00542 $tmpFile = t3lib_div::upload_to_tempfile($_FILES['FE'][$this->theTable][$theField]['tmp_name'][$kk]);
00543 if ($tmpFile) {
00544 $this->unlinkTempFiles[]=$tmpFile;
00545 $filesArr[] = array (
00546 'name'=>$vv,
00547 'tmp_name'=>$tmpFile
00548 );
00549 }
00550 }
00551 }
00552 } elseif (is_array($_FILES['FE']['name'][$this->theTable][$theField])) {
00553 reset($_FILES['FE']['name'][$this->theTable][$theField]);
00554 while(list($kk,$vv)=each($_FILES['FE']['name'][$this->theTable][$theField])) {
00555 if ($vv) {
00556 $tmpFile = t3lib_div::upload_to_tempfile($_FILES['FE']['tmp_name'][$this->theTable][$theField][$kk]);
00557 if ($tmpFile) {
00558 $this->unlinkTempFiles[]=$tmpFile;
00559 $filesArr[] = array (
00560 'name'=>$vv,
00561 'tmp_name'=>$tmpFile
00562 );
00563 }
00564 }
00565 }
00566 }
00567
00568
00569 $this->dataArr[$theField]='';
00570 $finalFilesArr=array();
00571 if (count($filesArr)) {
00572 $extArray = t3lib_div::trimExplode(';',strtolower($cmdParts[1]),1);
00573 $maxSize = intval($cmdParts[3]);
00574 reset($filesArr);
00575 while(list(,$infoArr)=each($filesArr)) {
00576 $fI = pathinfo($infoArr['name']);
00577 if (t3lib_div::verifyFilenameAgainstDenyPattern($fI['name'])) {
00578 if (!count($extArray) || in_array(strtolower($fI['extension']), $extArray)) {
00579 $tmpFile = $infoArr['tmp_name'];
00580 if (@is_file($tmpFile)) {
00581 if (!$maxSize || filesize($tmpFile)<$maxSize*1024) {
00582 $finalFilesArr[]=$infoArr;
00583 } elseif ($this->conf['debug']) {debug('Size is beyond '.$maxSize.' kb ('.filesize($tmpFile).' bytes) and the file cannot be saved.');}
00584 } elseif ($this->conf['debug']) {debug('Surprisingly there was no file for '.$vv.' in '.$tmpFile);}
00585 } elseif ($this->conf['debug']) {debug('Extension "'.$fI['extension'].'" not allowed');}
00586 } elseif ($this->conf['debug']) {debug('Filename matched illegal pattern.');}
00587 }
00588 }
00589
00590 reset($finalFilesArr);
00591 $fileNameList=array();
00592 while(list(,$infoArr)=each($finalFilesArr)) {
00593 if ($this->isPreview()) {
00594 $this->createFileFuncObj();
00595 $fI = pathinfo($infoArr['name']);
00596 $tmpFilename = $this->theTable.'_'.t3lib_div::shortmd5(uniqid($infoArr['name'])).'.'.$fI['extension'];
00597 $theDestFile = $this->fileFunc->getUniqueName($this->fileFunc->cleanFileName($tmpFilename), PATH_site.'typo3temp/');
00598 t3lib_div::upload_copy_move($infoArr['tmp_name'],$theDestFile);
00599
00600 $fI2 = pathinfo($theDestFile);
00601 $fileNameList[] = $fI2['basename'].'|'.$infoArr['name'];
00602 } else {
00603 $this->createFileFuncObj();
00604 $GLOBALS['TSFE']->includeTCA();
00605 t3lib_div::loadTCA($this->theTable);
00606 if (is_array($GLOBALS['TCA'][$this->theTable]['columns'][$theField])) {
00607 $uploadPath = $GLOBALS['TCA'][$this->theTable]['columns'][$theField]['config']['uploadfolder'];
00608 }
00609 if ($uploadPath) {
00610 $theDestFile = $this->fileFunc->getUniqueName($this->fileFunc->cleanFileName($infoArr['name']), PATH_site.$uploadPath);
00611 t3lib_div::upload_copy_move($infoArr['tmp_name'],$theDestFile);
00612
00613 $fI2 = pathinfo($theDestFile);
00614 $fileNameList[] = $fI2['basename'];
00615 $this->filesStoredInUploadFolders[]=$theDestFile;
00616 }
00617 }
00618
00619 $this->dataArr[$theField] = implode(',',$fileNameList);
00620 }
00621 }
00622
00629 function overrideValues() {
00630
00631 if (is_array($this->conf[$this->cmdKey.'.']['overrideValues.'])) {
00632 reset($this->conf[$this->cmdKey.'.']['overrideValues.']);
00633 while(list($theField,$theValue)=each($this->conf[$this->cmdKey.'.']['overrideValues.'])) {
00634 $this->dataArr[$theField] = $theValue;
00635 }
00636 }
00637 }
00638
00645 function defaultValues() {
00646
00647 if (is_array($this->conf[$this->cmdKey.'.']['defaultValues.'])) {
00648 reset($this->conf[$this->cmdKey.'.']['defaultValues.']);
00649 while(list($theField,$theValue)=each($this->conf[$this->cmdKey.'.']['defaultValues.'])) {
00650 $this->dataArr[$theField] = $theValue;
00651 }
00652 }
00653 }
00654
00664 function evalValues() {
00665
00666 reset($this->requiredArr);
00667 $tempArr=array();
00668 while(list(,$theField)=each($this->requiredArr)) {
00669 if (!trim($this->dataArr[$theField])) {
00670 $tempArr[]=$theField;
00671 }
00672 }
00673
00674
00675 $recExist=0;
00676 if (is_array($this->conf[$this->cmdKey.'.']['evalValues.'])) {
00677 switch($this->cmd) {
00678 case 'edit':
00679 if (isset($this->dataArr['pid'])) {
00680 $recordTestPid = intval($this->dataArr['pid']);
00681 } else {
00682 $tempRecArr = $GLOBALS['TSFE']->sys_page->getRawRecord($this->theTable,$this->dataArr['uid']);
00683 $recordTestPid = intval($tempRecArr['pid']);
00684 }
00685 $recExist=1;
00686 break;
00687 default:
00688 $recordTestPid = $this->thePid ? $this->thePid : t3lib_div::intval_positive($this->dataArr['pid']);
00689 break;
00690 }
00691
00692 reset($this->conf[$this->cmdKey.'.']['evalValues.']);
00693 while(list($theField,$theValue)=each($this->conf[$this->cmdKey.'.']['evalValues.'])) {
00694 $listOfCommands = t3lib_div::trimExplode(',',$theValue,1);
00695 while(list(,$cmd)=each($listOfCommands)) {
00696 $cmdParts = split('\[|\]',$cmd);
00697 $theCmd = trim($cmdParts[0]);
00698 switch($theCmd) {
00699 case 'uniqueGlobal':
00700 if ($DBrows = $GLOBALS['TSFE']->sys_page->getRecordsByField($this->theTable,$theField,$this->dataArr[$theField],'','','','1')) {
00701 if (!$recExist || $DBrows[0]['uid']!=$this->dataArr['uid']) {
00702 $tempArr[]=$theField;
00703 $this->failureMsg[$theField][] = $this->getFailure($theField, $theCmd, 'The value existed already. Enter a new value.');
00704 }
00705 }
00706 break;
00707 case 'uniqueLocal':
00708 if ($DBrows = $GLOBALS['TSFE']->sys_page->getRecordsByField($this->theTable,$theField,$this->dataArr[$theField], 'AND pid IN ('.$recordTestPid.')','','','1')) {
00709 if (!$recExist || $DBrows[0]['uid']!=$this->dataArr['uid']) {
00710 $tempArr[]=$theField;
00711 $this->failureMsg[$theField][] = $this->getFailure($theField, $theCmd, 'The value existed already. Enter a new value.');
00712 }
00713 }
00714 break;
00715 case 'twice':
00716 if (strcmp($this->dataArr[$theField], $this->dataArr[$theField.'_again'])) {
00717 $tempArr[]=$theField;
00718 $this->failureMsg[$theField][] = $this->getFailure($theField, $theCmd, 'You must enter the same value twice');
00719 }
00720 break;
00721 case 'email':
00722 if (!$this->cObj->checkEmail($this->dataArr[$theField])) {
00723 $tempArr[]=$theField;
00724 $this->failureMsg[$theField][] = $this->getFailure($theField, $theCmd, 'You must enter a valid email address');
00725 }
00726 break;
00727 case 'required':
00728 if (!trim($this->dataArr[$theField])) {
00729 $tempArr[]=$theField;
00730 $this->failureMsg[$theField][] = $this->getFailure($theField, $theCmd, 'You must enter a value!');
00731 }
00732 break;
00733 case 'atLeast':
00734 $chars=intval($cmdParts[1]);
00735 if (strlen($this->dataArr[$theField])<$chars) {
00736 $tempArr[]=$theField;
00737 $this->failureMsg[$theField][] = sprintf($this->getFailure($theField, $theCmd, 'You must enter at least %s characters!'), $chars);
00738 }
00739 break;
00740 case 'atMost':
00741 $chars=intval($cmdParts[1]);
00742 if (strlen($this->dataArr[$theField])>$chars) {
00743 $tempArr[]=$theField;
00744 $this->failureMsg[$theField][] = sprintf($this->getFailure($theField, $theCmd, 'You must enter at most %s characters!'), $chars);
00745 }
00746 break;
00747 case 'inBranch':
00748 $pars = explode(';',$cmdParts[1]);
00749 if (intval($pars[0])) {
00750 $pid_list = $this->cObj->getTreeList(
00751 intval($pars[0]),
00752 intval($pars[1]) ? intval($pars[1]) : 999,
00753 intval($pars[2])
00754 );
00755 if (!$pid_list || !t3lib_div::inList($pid_list,$this->dataArr[$theField])) {
00756 $tempArr[]=$theField;
00757 $this->failureMsg[$theField][] = sprintf($this->getFailure($theField, $theCmd, 'The value was not a valid valud from this list: %s'), $pid_list);
00758 }
00759 }
00760 break;
00761 case 'unsetEmpty':
00762 if (!$this->dataArr[$theField]) {
00763 $hash = array_flip($tempArr);
00764 unset($hash[$theField]);
00765 $tempArr = array_keys($hash);
00766 unset($this->failureMsg[$theField]);
00767 unset($this->dataArr[$theField]);
00768 }
00769 break;
00770 }
00771 }
00772 $this->markerArray['###EVAL_ERROR_FIELD_'.$theField.'###'] = is_array($this->failureMsg[$theField]) ? implode('<br />',$this->failureMsg[$theField]) : '';
00773 }
00774 }
00775 $this->failure=implode(',',$tempArr);
00776 }
00777
00786 function userProcess($mConfKey,$passVar) {
00787 if ($this->conf[$mConfKey]) {
00788 $funcConf = $this->conf[$mConfKey.'.'];
00789 $funcConf['parentObj']=&$this;
00790 $passVar = $GLOBALS['TSFE']->cObj->callUserFunction($this->conf[$mConfKey], $funcConf, $passVar);
00791 }
00792 return $passVar;
00793 }
00794
00804 function userProcess_alt($confVal,$confArr,$passVar) {
00805 if ($confVal) {
00806 $funcConf = $confArr;
00807 $funcConf['parentObj']=&$this;
00808 $passVar = $GLOBALS['TSFE']->cObj->callUserFunction($confVal, $funcConf, $passVar);
00809 }
00810 return $passVar;
00811 }
00812
00813
00814
00815
00816
00817
00818
00819
00820
00821
00822
00823
00824
00825
00826
00827
00828
00829
00830
00831
00832
00833
00834
00835
00836
00837
00838
00839
00846 function save() {
00847 switch($this->cmd) {
00848 case 'edit':
00849 $theUid = $this->dataArr['uid'];
00850 $origArr = $GLOBALS['TSFE']->sys_page->getRawRecord($this->theTable,$theUid);
00851 if ($this->conf['edit'] && ($GLOBALS['TSFE']->loginUser || $this->aCAuth($origArr))) {
00852 $newFieldList = implode(',',array_intersect(explode(',',$this->fieldList),t3lib_div::trimExplode(',',$this->conf['edit.']['fields'],1)));
00853 if ($this->aCAuth($origArr) || $this->cObj->DBmayFEUserEdit($this->theTable,$origArr,$GLOBALS['TSFE']->fe_user->user,$this->conf['allowedGroups'],$this->conf['fe_userEditSelf'])) {
00854 $this->cObj->DBgetUpdate($this->theTable, $theUid, $this->dataArr, $newFieldList, TRUE);
00855 $this->currentArr = $GLOBALS['TSFE']->sys_page->getRawRecord($this->theTable,$theUid);
00856 $this->userProcess_alt($this->conf['edit.']['userFunc_afterSave'],$this->conf['edit.']['userFunc_afterSave.'],array('rec'=>$this->currentArr, 'origRec'=>$origArr));
00857 $this->saved=1;
00858 } else {
00859 $this->error='###TEMPLATE_NO_PERMISSIONS###';
00860 }
00861 }
00862 break;
00863 default:
00864 if ($this->conf['create']) {
00865 $newFieldList = implode(',',array_intersect(explode(',',$this->fieldList),t3lib_div::trimExplode(',',$this->conf['create.']['fields'],1)));
00866 $this->cObj->DBgetInsert($this->theTable, $this->thePid, $this->dataArr, $newFieldList, TRUE);
00867 $newId = $GLOBALS['TYPO3_DB']->sql_insert_id();
00868
00869 if ($this->theTable=='fe_users' && $this->conf['fe_userOwnSelf']) {
00870 $extraList='';
00871 $dataArr = array();
00872 if ($GLOBALS['TCA'][$this->theTable]['ctrl']['fe_cruser_id']) {
00873 $field=$GLOBALS['TCA'][$this->theTable]['ctrl']['fe_cruser_id'];
00874 $dataArr[$field]=$newId;
00875 $extraList.=','.$field;
00876 }
00877 if ($GLOBALS['TCA'][$this->theTable]['ctrl']['fe_crgroup_id']) {
00878 $field=$GLOBALS['TCA'][$this->theTable]['ctrl']['fe_crgroup_id'];
00879 list($dataArr[$field])=explode(',',$this->dataArr['usergroup']);
00880 $dataArr[$field]=intval($dataArr[$field]);
00881 $extraList.=','.$field;
00882 }
00883 if (count($dataArr)) {
00884 $this->cObj->DBgetUpdate($this->theTable, $newId, $dataArr, $extraList, TRUE);
00885 }
00886 }
00887
00888 $this->currentArr = $GLOBALS['TSFE']->sys_page->getRawRecord($this->theTable,$newId);
00889 $this->userProcess_alt($this->conf['create.']['userFunc_afterSave'],$this->conf['create.']['userFunc_afterSave.'],array('rec'=>$this->currentArr));
00890 $this->saved=1;
00891 }
00892 break;
00893 }
00894 }
00895
00904 function deleteRecord() {
00905 if ($this->conf['delete']) {
00906 $origArr = $GLOBALS['TSFE']->sys_page->getRawRecord($this->theTable, $this->recUid);
00907 if ($GLOBALS['TSFE']->loginUser || $this->aCAuth($origArr)) {
00908
00909 if (is_array($origArr)) {
00910 if ($this->aCAuth($origArr) || $this->cObj->DBmayFEUserEdit($this->theTable,$origArr, $GLOBALS['TSFE']->fe_user->user,$this->conf['allowedGroups'],$this->conf['fe_userEditSelf'])) {
00911 if (!$GLOBALS['TCA'][$this->theTable]['ctrl']['delete']) {
00912 $this->deleteFilesFromRecord($this->recUid);
00913 }
00914 $this->cObj->DBgetDelete($this->theTable, $this->recUid, TRUE);
00915 $this->currentArr = $origArr;
00916 $this->saved = 1;
00917 } else {
00918 $this->error = '###TEMPLATE_NO_PERMISSIONS###';
00919 }
00920 }
00921 }
00922 }
00923 }
00924
00934 function deleteFilesFromRecord($uid) {
00935 $table = $this->theTable;
00936 $rec = $GLOBALS['TSFE']->sys_page->getRawRecord($table,$uid);
00937
00938 $GLOBALS['TSFE']->includeTCA();
00939 t3lib_div::loadTCA($table);
00940 reset($GLOBALS['TCA'][$table]['columns']);
00941 $iFields=array();
00942 while(list($field,$conf)=each($GLOBALS['TCA'][$table]['columns'])) {
00943 if ($conf['config']['type']=='group' && $conf['config']['internal_type']=='file') {
00944
00945 $GLOBALS['TYPO3_DB']->exec_UPDATEquery($table, 'uid='.intval($uid), array($field => ''));
00946
00947 $delFileArr = explode(',',$rec[$field]);
00948 reset($delFileArr);
00949 while(list(,$n)=each($delFileArr)) {
00950 if ($n) {
00951 $fpath = $conf['config']['uploadfolder'].'/'.$n;
00952 unlink($fpath);
00953 }
00954 }
00955 }
00956 }
00957 }
00958
00959
00960
00961
00962
00963
00964
00965
00966
00967
00968
00969
00970
00971
00972
00973
00974
00975
00976
00977
00978
00979
00980
00981
00982
00983
00984
00991 function displayDeleteScreen() {
00992 if ($this->conf['delete']) {
00993 $origArr = $GLOBALS['TSFE']->sys_page->getRawRecord($this->theTable, $this->recUid);
00994 if ($GLOBALS['TSFE']->loginUser || $this->aCAuth($origArr)) {
00995
00996 if (is_array($origArr)) {
00997 if ($this->aCAuth($origArr) || $this->cObj->DBmayFEUserEdit($this->theTable,$origArr, $GLOBALS['TSFE']->fe_user->user,$this->conf['allowedGroups'],$this->conf['fe_userEditSelf'])) {
00998 $this->markerArray['###HIDDENFIELDS###'].= '<input type="hidden" name="rU" value="'.$this->recUid.'" />';
00999 $content = $this->getPlainTemplate('###TEMPLATE_DELETE_PREVIEW###', $origArr);
01000 } else {
01001 $content = $this->getPlainTemplate('###TEMPLATE_NO_PERMISSIONS###');
01002 }
01003 }
01004 } else {
01005 $content = $this->getPlainTemplate('###TEMPLATE_AUTH###');
01006 }
01007 } else {
01008 $content.='Delete-option is not set in TypoScript';
01009 }
01010 return $content;
01011 }
01012
01019 function displayCreateScreen() {
01020 if ($this->conf['create']) {
01021 $templateCode = $this->cObj->getSubpart($this->templateCode, ((!$GLOBALS['TSFE']->loginUser||$this->conf['create.']['noSpecialLoginForm'])?'###TEMPLATE_CREATE'.$this->previewLabel.'###':'###TEMPLATE_CREATE_LOGIN'.$this->previewLabel.'###'));
01022 $failure = t3lib_div::_GP('noWarnings')?'':$this->failure;
01023 if (!$failure) $templateCode = $this->cObj->substituteSubpart($templateCode, '###SUB_REQUIRED_FIELDS_WARNING###', '');
01024
01025 $templateCode = $this->removeRequired($templateCode,$failure);
01026 $this->setCObjects($templateCode);
01027
01028 $markerArray = $this->cObj->fillInMarkerArray($this->markerArray, $this->dataArr, '', TRUE, 'FIELD_', $this->recInMarkersHSC);
01029 if ($this->conf['create.']['preview'] && !$this->previewLabel) {$markerArray['###HIDDENFIELDS###'].= '<input type="hidden" name="preview" value="1" />';}
01030 $content = $this->cObj->substituteMarkerArray($templateCode, $markerArray);
01031 $content.=$this->cObj->getUpdateJS($this->modifyDataArrForFormUpdate($this->dataArr), $this->theTable.'_form', 'FE['.$this->theTable.']', $this->fieldList.$this->additionalUpdateFields);
01032 }
01033 return $content;
01034 }
01035
01042 function displayEditScreen() {
01043 if ($this->conf['edit']) {
01044 $origArr = $GLOBALS['TSFE']->sys_page->getRawRecord($this->theTable, $this->dataArr['uid']?$this->dataArr['uid']:$this->recUid);
01045
01046 if ($GLOBALS['TSFE']->loginUser || $this->aCAuth($origArr)) {
01047
01048 if (is_array($origArr)) {
01049 if ($this->aCAuth($origArr) || $this->cObj->DBmayFEUserEdit($this->theTable,$origArr, $GLOBALS['TSFE']->fe_user->user,$this->conf['allowedGroups'],$this->conf['fe_userEditSelf'])) {
01050 $content=$this->displayEditForm($origArr);
01051 } else {
01052 $content = $this->getPlainTemplate('###TEMPLATE_NO_PERMISSIONS###');
01053 }
01054 } elseif ($GLOBALS['TSFE']->loginUser) {
01055 $lockPid = $this->conf['edit.']['menuLockPid'] ? ' AND pid='.intval($this->thePid) : '';
01056
01057 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', $this->theTable, '1 '.$lockPid.$this->cObj->DBmayFEUserEditSelect($this->theTable,$GLOBALS['TSFE']->fe_user->user, $this->conf['allowedGroups'],$this->conf['fe_userEditSelf']).$GLOBALS['TSFE']->sys_page->deleteClause($this->theTable));
01058
01059 if ($GLOBALS['TYPO3_DB']->sql_num_rows($res)) {
01060 $templateCode = $this->getPlainTemplate('###TEMPLATE_EDITMENU###');
01061 $out='';
01062 $itemCode = $this->cObj->getSubpart($templateCode, '###ITEM###');
01063 while($menuRow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
01064 $markerArray = $this->cObj->fillInMarkerArray(array(), $menuRow, '', TRUE, 'FIELD_', $this->recInMarkersHSC);
01065 $markerArray = $this->setCObjects($itemCode,$menuRow,$markerArray,'ITEM_');
01066 $out.= $this->cObj->substituteMarkerArray($itemCode, $markerArray);
01067 }
01068 $content=$this->cObj->substituteSubpart($templateCode, '###ALLITEMS###', $out);
01069 } else {
01070 $content = $this->getPlainTemplate('###TEMPLATE_EDITMENU_NOITEMS###');
01071 }
01072 } else {
01073 $content = $this->getPlainTemplate('###TEMPLATE_AUTH###');
01074 }
01075 } else {
01076 $content = $this->getPlainTemplate('###TEMPLATE_AUTH###');
01077 }
01078 } else {
01079 $content.='Edit-option is not set in TypoScript';
01080 }
01081 return $content;
01082 }
01083
01093 function displayEditForm($origArr) {
01094 $currentArr = is_array($this->dataArr) ? $this->dataArr+$origArr : $origArr;
01095
01096 if ($this->conf['debug']) debug('displayEditForm(): '.'###TEMPLATE_EDIT'.$this->previewLabel.'###',1);
01097 $templateCode = $this->cObj->getSubpart($this->templateCode, '###TEMPLATE_EDIT'.$this->previewLabel.'###');
01098 $failure = t3lib_div::_GP('noWarnings')?'':$this->failure;
01099 if (!$failure) {$templateCode = $this->cObj->substituteSubpart($templateCode, '###SUB_REQUIRED_FIELDS_WARNING###', '');}
01100
01101 $templateCode = $this->removeRequired($templateCode,$failure);
01102
01103 $this->setCObjects($templateCode,$currentArr);
01104
01105 $markerArray = $this->cObj->fillInMarkerArray($this->markerArray, $currentArr, '', TRUE, 'FIELD_', $this->recInMarkersHSC);
01106
01107 $markerArray['###HIDDENFIELDS###'].= '<input type="hidden" name="FE['.$this->theTable.'][uid]" value="'.$currentArr['uid'].'" />';
01108 if ($this->conf['edit.']['preview'] && !$this->previewLabel) {$markerArray['###HIDDENFIELDS###'].= '<input type="hidden" name="preview" value="1" />';}
01109 $content = $this->cObj->substituteMarkerArray($templateCode, $markerArray);
01110 $content.=$this->cObj->getUpdateJS($this->modifyDataArrForFormUpdate($currentArr), $this->theTable.'_form', 'FE['.$this->theTable.']', $this->fieldList.$this->additionalUpdateFields);
01111
01112 return $content;
01113 }
01114
01121 function procesSetFixed() {
01122 if ($this->conf['setfixed']) {
01123 $theUid = intval($this->recUid);
01124 $origArr = $GLOBALS['TSFE']->sys_page->getRawRecord($this->theTable, $theUid);
01125 $fD = t3lib_div::_GP('fD');
01126 $sFK = t3lib_div::_GP('sFK');
01127
01128 $fieldArr=array();
01129 if (is_array($fD) || $sFK=='DELETE') {
01130 if (is_array($fD)) {
01131 reset($fD);
01132 while(list($field,$value)=each($fD)) {
01133 $origArr[$field]=$value;
01134 $fieldArr[]=$field;
01135 }
01136 }
01137 $theCode = $this->setfixedHash($origArr,$origArr['_FIELDLIST']);
01138 if (!strcmp($this->authCode,$theCode)) {
01139 if ($sFK=='DELETE') {
01140 $this->cObj->DBgetDelete($this->theTable, $theUid, TRUE);
01141 } else {
01142 $newFieldList = implode(',',array_intersect(t3lib_div::trimExplode(',',$this->fieldList),t3lib_div::trimExplode(',',implode($fieldArr,','),1)));
01143 $this->cObj->DBgetUpdate($this->theTable, $theUid, $fD, $newFieldList, TRUE);
01144 $this->currentArr = $GLOBALS['TSFE']->sys_page->getRawRecord($this->theTable,$theUid);
01145 $this->userProcess_alt($this->conf['setfixed.']['userFunc_afterSave'],$this->conf['setfixed.']['userFunc_afterSave.'],array('rec'=>$this->currentArr, 'origRec'=>$origArr));
01146 }
01147
01148
01149 $this->markerArray = $this->cObj->fillInMarkerArray($this->markerArray, $origArr, '', TRUE, 'FIELD_', $this->recInMarkersHSC);
01150 $content = $this->getPlainTemplate('###TEMPLATE_SETFIXED_OK_'.$sFK.'###');
01151 if (!$content) {$content = $this->getPlainTemplate('###TEMPLATE_SETFIXED_OK###');}
01152
01153
01154 $this->compileMail(
01155 'SETFIXED_'.$sFK,
01156 array($origArr),
01157 $origArr[$this->conf['email.']['field']],
01158 $this->conf['setfixed.']
01159 );
01160
01161 $this->clearCacheIfSet();
01162 } else $content = $this->getPlainTemplate('###TEMPLATE_SETFIXED_FAILED###');
01163 } else $content = $this->getPlainTemplate('###TEMPLATE_SETFIXED_FAILED###');
01164 }
01165 return $content;
01166 }
01167
01168
01169
01170
01171
01172
01173
01174
01175
01176
01177
01178
01179
01180
01181
01182
01183
01184
01185
01186
01187
01188
01189
01190
01191
01192