Documentation TYPO3 par Ameos |
00001 <?php 00002 /*************************************************************** 00003 * Copyright notice 00004 * 00005 * (c) 1999-2005 Kasper Skaarhoj (kasperYYYY@typo3.com) 00006 * All rights reserved 00007 * 00008 * This script is part of the TYPO3 project. The TYPO3 project is 00009 * free software; you can redistribute it and/or modify 00010 * it under the terms of the GNU General Public License as published by 00011 * the Free Software Foundation; either version 2 of the License, or 00012 * (at your option) any later version. 00013 * 00014 * The GNU General Public License can be found at 00015 * http://www.gnu.org/copyleft/gpl.html. 00016 * A copy is found in the textfile GPL.txt and important notices to the license 00017 * from the author is found in LICENSE.txt distributed with these scripts. 00018 * 00019 * 00020 * This script is distributed in the hope that it will be useful, 00021 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00022 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00023 * GNU General Public License for more details. 00024 * 00025 * This copyright notice MUST APPEAR in all copies of the script! 00026 ***************************************************************/ 00092 require_once (PATH_t3lib.'class.t3lib_basicfilefunc.php'); // For use with images. 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 // External, static: 00135 var $recInMarkersHSC = TRUE; // If true, values from the record put into markers going out into HTML will be passed through htmlspecialchars()! 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; // is set if data did not have the required fields set. 00150 var $error=''; 00151 var $saved=0; // is set if data is saved 00152 var $requiredArr; 00153 var $currentArr = array(); 00154 var $previewLabel=''; 00155 var $nc = ''; // '&no_cache=1' if you want that parameter sent. 00156 var $additionalUpdateFields=''; 00157 var $emailMarkPrefix = 'EMAIL_TEMPLATE_'; 00158 var $codeLength; 00159 var $cmdKey; 00160 var $fileFunc=''; // Set to a basic_filefunc object 00161 var $filesStoredInUploadFolders=array(); // This array will hold the names of files transferred to the uploads/* folder if any. If the records are NOT saved, these files should be deleted!! Currently this is not working! 00162 00163 // Internal vars, dynamic: 00164 var $unlinkTempFiles = array(); // Is loaded with all temporary filenames used for upload which should be deleted before exit... 00165 00179 function init($content,$conf) { 00180 $this->conf = $conf; 00181 00182 // template file is fetched. 00183 $this->templateCode = $this->conf['templateContent'] ? $this->conf['templateContent'] : $this->cObj->fileResource($this->conf['templateFile']); 00184 00185 // Getting the cmd var 00186 $this->cmd = (string)t3lib_div::_GP('cmd'); 00187 // Getting the preview var 00188 $this->preview = (string)t3lib_div::_GP('preview'); 00189 // backURL is a given URL to return to when login is performed 00190 $this->backURL = t3lib_div::_GP('backURL'); 00191 // Uid to edit: 00192 $this->recUid = t3lib_div::_GP('rU'); 00193 // Authentication code: 00194 $this->authCode = t3lib_div::_GP('aC'); 00195 // get table 00196 $this->theTable = $this->conf['table']; 00197 // link configuration 00198 $linkConf = is_array($this->conf['formurl.']) ? $this->conf['formurl.'] : array(); 00199 // pid 00200 $this->thePid = intval($this->conf['pid']) ? intval($this->conf['pid']) : $GLOBALS['TSFE']->id; 00201 // 00202 $this->codeLength = intval($this->conf['authcodeFields.']['codeLength']) ? intval($this->conf['authcodeFields.']['codeLength']) : 8; 00203 00204 // Setting the hardcoded lists of fields allowed for editing and creation. 00205 $this->fieldList=implode(',',t3lib_div::trimExplode(',',$GLOBALS['TCA'][$this->theTable]['feInterface']['fe_admin_fieldList'],1)); 00206 00207 // globally substituted markers, fonts and colors. 00208 $splitMark = md5(microtime()); 00209 list($this->markerArray['###GW1B###'],$this->markerArray['###GW1E###']) = explode($splitMark,$this->cObj->stdWrap($splitMark,$this->conf['wrap1.'])); 00210 list($this->markerArray['###GW2B###'],$this->markerArray['###GW2E###']) = explode($splitMark,$this->cObj->stdWrap($splitMark,$this->conf['wrap2.'])); 00211 $this->markerArray['###GC1###'] = $this->cObj->stdWrap($this->conf['color1'],$this->conf['color1.']); 00212 $this->markerArray['###GC2###'] = $this->cObj->stdWrap($this->conf['color2'],$this->conf['color2.']); 00213 $this->markerArray['###GC3###'] = $this->cObj->stdWrap($this->conf['color3'],$this->conf['color3.']); 00214 00215 if (intval($this->conf['no_cache']) && !isset($linkConf['no_cache'])) { // needed for backwards compatibility 00216 $linkConf['no_cache'] = 1; 00217 } 00218 if(!$linkConf['parameter']) { 00219 $linkConf['parameter'] = $GLOBALS['TSFE']->id; 00220 } 00221 if(!$linkConf['additionalParams']) { // needed for backwards compatibility 00222 $linkConf['additionalParams'] = $this->conf['addParams']; 00223 } 00224 00225 $formURL = $this->cObj->typoLink_URL($linkConf); 00226 if(!strstr($formURL,'?')) { 00227 $formURL .= '?'; 00228 } 00229 00230 // Initialize markerArray, setting FORM_URL and HIDDENFIELDS 00231 $this->markerArray['###FORM_URL###'] = $formURL; 00232 $this->markerArray['###FORM_URL_ENC###'] = rawurlencode($this->markerArray['###FORM_URL###']); 00233 $this->markerArray['###FORM_URL_HSC###'] = htmlspecialchars($this->markerArray['###FORM_URL###']); 00234 00235 $this->markerArray['###BACK_URL###'] = $this->backURL; 00236 $this->markerArray['###BACK_URL_ENC###'] = rawurlencode($this->markerArray['###BACK_URL###']); 00237 $this->markerArray['###BACK_URL_HSC###'] = htmlspecialchars($this->markerArray['###BACK_URL###']); 00238 00239 $this->markerArray['###THE_PID###'] = $this->thePid; 00240 $this->markerArray['###REC_UID###'] = $this->recUid; 00241 $this->markerArray['###AUTH_CODE###'] = $this->authCode; 00242 $this->markerArray['###THIS_ID###'] = $GLOBALS['TSFE']->id; 00243 $this->markerArray['###THIS_URL###'] = htmlspecialchars(t3lib_div::getIndpEnv('TYPO3_REQUEST_DIR')); 00244 $this->markerArray['###HIDDENFIELDS###'] = 00245 ($this->cmd?'<input type="hidden" name="cmd" value="'.htmlspecialchars($this->cmd).'" />':''). 00246 ($this->authCode?'<input type="hidden" name="aC" value="'.htmlspecialchars($this->authCode).'" />':''). 00247 ($this->backURL?'<input type="hidden" name="backURL" value="'.htmlspecialchars($this->backURL).'" />':''); 00248 00249 00250 // Setting cmdKey which is either 'edit' or 'create' 00251 switch($this->cmd) { 00252 case 'edit': 00253 $this->cmdKey='edit'; 00254 break; 00255 default: 00256 $this->cmdKey='create'; 00257 break; 00258 } 00259 // Setting requiredArr to the fields in 'required' intersected field the total field list in order to remove invalid fields. 00260 $this->requiredArr = array_intersect( 00261 t3lib_div::trimExplode(',',$this->conf[$this->cmdKey.'.']['required'],1), 00262 t3lib_div::trimExplode(',',$this->conf[$this->cmdKey.'.']['fields'],1) 00263 ); 00264 00265 // Setting incoming data. Non-stripped 00266 $fe=t3lib_div::_GP('FE'); 00267 $this->dataArr = $fe[$this->theTable]; // Incoming data. 00268 00269 // Checking template file and table value 00270 if (!$this->templateCode) { 00271 $content = 'No template file found: '.$this->conf['templateFile']; 00272 return $content; 00273 } 00274 00275 if (!$this->theTable || !$this->fieldList) { 00276 $content = 'Wrong table: '.$this->theTable; 00277 return $content; // Not listed or editable table! 00278 } 00279 00280 // ***************** 00281 // If data is submitted, we take care of it here. 00282 // ******************* 00283 if ($this->cmd=='delete' && !$this->preview && !t3lib_div::_GP('doNotSave')) { // Delete record if delete command is sent + the preview flag is NOT set. 00284 $this->deleteRecord(); 00285 } 00286 // If incoming data is seen... 00287 if (is_array($this->dataArr)) { 00288 // Evaluation of data: 00289 $this->parseValues(); 00290 $this->overrideValues(); 00291 $this->evalValues(); 00292 if ($this->conf['evalFunc']) { 00293 $this->dataArr = $this->userProcess('evalFunc',$this->dataArr); 00294 } 00295 00296 /* 00297 debug($this->dataArr); 00298 debug($this->failure); 00299 debug($this->preview); 00300 */ 00301 // if not preview and no failures, then set data... 00302 if (!$this->failure && !$this->preview && !t3lib_div::_GP('doNotSave')) { // doNotSave is a global var (eg a 'Cancel' submit button) that prevents the data from being processed 00303 $this->save(); 00304 } else { 00305 if ($this->conf['debug']) debug($this->failure); 00306 } 00307 } else { 00308 $this->defaultValues(); // If no incoming data, this will set the default values. 00309 $this->preview = 0; // No preview if data is not received 00310 } 00311 if ($this->failure) {$this->preview=0;} // No preview flag if a evaluation failure has occured 00312 $this->previewLabel = $this->preview ? '_PREVIEW' : ''; // Setting preview label prefix. 00313 00314 00315 // ********************* 00316 // DISPLAY FORMS: 00317 // *********************** 00318 if ($this->saved) { 00319 // Clear page cache 00320 $this->clearCacheIfSet(); 00321 00322 // Displaying the page here that says, the record has been saved. You're able to include the saved values by markers. 00323 switch($this->cmd) { 00324 case 'delete': 00325 $key='DELETE'; 00326 break; 00327 case 'edit': 00328 $key='EDIT'; 00329 break; 00330 default: 00331 $key='CREATE'; 00332 break; 00333 } 00334 // Output message 00335 $templateCode = $this->cObj->getSubpart($this->templateCode, '###TEMPLATE_'.$key.'_SAVED###'); 00336 $this->setCObjects($templateCode,$this->currentArr); 00337 $markerArray = $this->cObj->fillInMarkerArray($this->markerArray, $this->currentArr, '', TRUE, 'FIELD_', $this->recInMarkersHSC); 00338 $content = $this->cObj->substituteMarkerArray($templateCode, $markerArray); 00339 00340 // email message: 00341 $this->compileMail( 00342 $key.'_SAVED', 00343 array($this->currentArr), 00344 $this->currentArr[$this->conf['email.']['field']], 00345 $this->conf['setfixed.'] 00346 ); 00347 00348 } elseif ($this->error) { // If there was an error, we return the template-subpart with the error message 00349 $templateCode = $this->cObj->getSubpart($this->templateCode, $this->error); 00350 $this->setCObjects($templateCode); 00351 $content = $this->cObj->substituteMarkerArray($templateCode, $this->markerArray); 00352 } else { 00353 // Finally, if there has been no attempt to save. That is either preview or just displaying and empty or not correctly filled form: 00354 if (!$this->cmd) { 00355 $this->cmd=$this->conf['defaultCmd']; 00356 } 00357 if ($this->conf['debug']) debug('Display form: '.$this->cmd,1); 00358 switch($this->cmd) { 00359 case 'setfixed': 00360 $content = $this->procesSetFixed(); 00361 break; 00362 case 'infomail': 00363 $content = $this->sendInfoMail(); 00364 break; 00365 case 'delete': 00366 $content = $this->displayDeleteScreen(); 00367 break; 00368 case 'edit': 00369 $content = $this->displayEditScreen(); 00370 break; 00371 case 'create': 00372 $content = $this->displayCreateScreen(); 00373 break; 00374 } 00375 } 00376 00377 // Delete temp files: 00378 foreach($this->unlinkTempFiles as $tempFileName) { 00379 t3lib_div::unlink_tempfile($tempFileName); 00380 } 00381 00382 // Return content: 00383 return $content; 00384 } 00385 00386 00387 00388 00389 00390 00391 00392 00393 00394 00395 00396 00397 00398 00399 00400 00401 00402 00403 00404 00405 00406 00407 00408 /***************************************** 00409 * 00410 * Data processing 00411 * 00412 *****************************************/ 00413 00423 function parseValues() { 00424 if (is_array($this->conf['parseValues.'])) { 00425 reset($this->conf['parseValues.']); 00426 while(list($theField,$theValue)=each($this->conf['parseValues.'])) { 00427 $listOfCommands = t3lib_div::trimExplode(',',$theValue,1); 00428 while(list(,$cmd)=each($listOfCommands)) { 00429 $cmdParts = split('\[|\]',$cmd); // Point is to enable parameters after each command enclosed in brackets [..]. These will be in position 1 in the array. 00430 $theCmd=trim($cmdParts[0]); 00431 switch($theCmd) { 00432 case 'int': 00433 $this->dataArr[$theField]=intval($this->dataArr[$theField]); 00434 break; 00435 case 'lower': 00436 case 'upper': 00437 $this->dataArr[$theField] = $this->cObj->caseshift($this->dataArr[$theField],$theCmd); 00438 break; 00439 case 'nospace': 00440 $this->dataArr[$theField] = str_replace(' ', '', $this->dataArr[$theField]); 00441 break; 00442 case 'alpha': 00443 $this->dataArr[$theField] = ereg_replace('[^a-zA-Z]','',$this->dataArr[$theField]); 00444 break; 00445 case 'num': 00446 $this->dataArr[$theField] = ereg_replace('[^0-9]','',$this->dataArr[$theField]); 00447 break; 00448 case 'alphanum': 00449 $this->dataArr[$theField] = ereg_replace('[^a-zA-Z0-9]','',$this->dataArr[$theField]); 00450 break; 00451 case 'alphanum_x': 00452 $this->dataArr[$theField] = ereg_replace('[^a-zA-Z0-9_-]','',$this->dataArr[$theField]); 00453 break; 00454 case 'trim': 00455 $this->dataArr[$theField] = trim($this->dataArr[$theField]); 00456 break; 00457 case 'random': 00458 $this->dataArr[$theField] = substr(md5(uniqid(microtime(),1)),0,intval($cmdParts[1])); 00459 break; 00460 case 'files': 00461 if ($this->cmdKey=='create' && !t3lib_div::_GP('doNotSave')) { 00462 $this->processFiles($cmdParts,$theField); 00463 } else unset($this->dataArr[$theField]); // Fields with files cannot be edited - only created. 00464 break; 00465 case 'setEmptyIfAbsent': 00466 if (!isset($this->dataArr[$theField])) { 00467 $this->dataArr[$theField]=''; 00468 } 00469 break; 00470 case 'multiple': 00471 if (is_array($this->dataArr[$theField])) { 00472 $this->dataArr[$theField] = implode(',',$this->dataArr[$theField]); 00473 } 00474 break; 00475 case 'checkArray': 00476 if (is_array($this->dataArr[$theField])) { 00477 reset($this->dataArr[$theField]); 00478 $val = 0; 00479 while(list($kk,$vv)=each($this->dataArr[$theField])) { 00480 $kk = t3lib_div::intInRange($kk,0); 00481 if ($kk<=30) { 00482 if ($vv) { 00483 $val|=pow(2,$kk); 00484 } 00485 } 00486 } 00487 $this->dataArr[$theField] = $val; 00488 } else {$this->dataArr[$theField]=0;} 00489 break; 00490 case 'uniqueHashInt': 00491 $otherFields = t3lib_div::trimExplode(';',$cmdParts[1],1); 00492 $hashArray=array(); 00493 while(list(,$fN)=each($otherFields)) { 00494 $vv = $this->dataArr[$fN]; 00495 $vv = ereg_replace('[[:space:]]','',$vv); 00496 $vv = ereg_replace('[^[:alnum:]]','',$vv); 00497 $vv = strtolower($vv); 00498 $hashArray[]=$vv; 00499 } 00500 $this->dataArr[$theField]=hexdec(substr(md5(serialize($hashArray)),0,8)); 00501 break; 00502 } 00503 } 00504 } 00505 } 00506 } 00507 00518 function processFiles($cmdParts,$theField) { 00519 //debug($_FILES); 00520 // First, make an array with the filename and file reference, whether the file is just uploaded or a preview 00521 $filesArr = array(); 00522 00523 if (is_string($this->dataArr[$theField])) { // files from preview. 00524 $tmpArr = explode(',',$this->dataArr[$theField]); 00525 reset($tmpArr); 00526 while(list(,$val)=each($tmpArr)) { 00527 $valParts = explode('|',$val); 00528 $filesArr[] = array ( 00529 'name'=>$valParts[1], 00530 'tmp_name'=>PATH_site.'typo3temp/'.$valParts[0] 00531 ); 00532 } 00533 } elseif (is_array($_FILES['FE'][$this->theTable][$theField]['name'])) { // Files from upload 00534 reset($_FILES['FE'][$this->theTable][$theField]['name']); 00535 while(list($kk,$vv)=each($_FILES['FE'][$this->theTable][$theField]['name'])) { 00536 if ($vv) { 00537 $tmpFile = t3lib_div::upload_to_tempfile($_FILES['FE'][$this->theTable][$theField]['tmp_name'][$kk]); 00538 if ($tmpFile) { 00539 $this->unlinkTempFiles[]=$tmpFile; 00540 $filesArr[] = array ( 00541 'name'=>$vv, 00542 'tmp_name'=>$tmpFile 00543 ); 00544 } 00545 } 00546 } 00547 } elseif (is_array($_FILES['FE']['name'][$this->theTable][$theField])) { // Files from upload 00548 reset($_FILES['FE']['name'][$this->theTable][$theField]); 00549 while(list($kk,$vv)=each($_FILES['FE']['name'][$this->theTable][$theField])) { 00550 if ($vv) { 00551 $tmpFile = t3lib_div::upload_to_tempfile($_FILES['FE']['tmp_name'][$this->theTable][$theField][$kk]); 00552 if ($tmpFile) { 00553 $this->unlinkTempFiles[]=$tmpFile; 00554 $filesArr[] = array ( 00555 'name'=>$vv, 00556 'tmp_name'=>$tmpFile 00557 ); 00558 } 00559 } 00560 } 00561 } 00562 00563 // Then verify the files in that array; check existence, extension and size 00564 $this->dataArr[$theField]=''; 00565 $finalFilesArr=array(); 00566 if (count($filesArr)) { 00567 $extArray = t3lib_div::trimExplode(';',strtolower($cmdParts[1]),1); 00568 $maxSize = intval($cmdParts[3]); 00569 reset($filesArr); 00570 while(list(,$infoArr)=each($filesArr)) { 00571 $fI = pathinfo($infoArr['name']); 00572 if (t3lib_div::verifyFilenameAgainstDenyPattern($fI['name'])) { 00573 if (!count($extArray) || in_array(strtolower($fI['extension']), $extArray)) { 00574 $tmpFile = $infoArr['tmp_name']; 00575 if (@is_file($tmpFile)) { 00576 if (!$maxSize || filesize($tmpFile)<$maxSize*1024) { 00577 $finalFilesArr[]=$infoArr; 00578 } elseif ($this->conf['debug']) {debug('Size is beyond '.$maxSize.' kb ('.filesize($tmpFile).' bytes) and the file cannot be saved.');} 00579 } elseif ($this->conf['debug']) {debug('Surprisingly there was no file for '.$vv.' in '.$tmpFile);} 00580 } elseif ($this->conf['debug']) {debug('Extension "'.$fI['extension'].'" not allowed');} 00581 } elseif ($this->conf['debug']) {debug('Filename matched illegal pattern.');} 00582 } 00583 } 00584 // Copy the files in the resulting array to the proper positions based on preview/non-preview. 00585 reset($finalFilesArr); 00586 $fileNameList=array(); 00587 while(list(,$infoArr)=each($finalFilesArr)) { 00588 if ($this->isPreview()) { // If the form is a preview form (and data is therefore not going into the database...) do this. 00589 $this->createFileFuncObj(); 00590 $fI = pathinfo($infoArr['name']); 00591 $tmpFilename = $this->theTable.'_'.t3lib_div::shortmd5(uniqid($infoArr['name'])).'.'.$fI['extension']; 00592 $theDestFile = $this->fileFunc->getUniqueName($this->fileFunc->cleanFileName($tmpFilename), PATH_site.'typo3temp/'); 00593 t3lib_div::upload_copy_move($infoArr['tmp_name'],$theDestFile); 00594 // Setting the filename in the list 00595 $fI2 = pathinfo($theDestFile); 00596 $fileNameList[] = $fI2['basename'].'|'.$infoArr['name']; 00597 } else { 00598 $this->createFileFuncObj(); 00599 $GLOBALS['TSFE']->includeTCA(); 00600 t3lib_div::loadTCA($this->theTable); 00601 if (is_array($GLOBALS['TCA'][$this->theTable]['columns'][$theField])) { 00602 $uploadPath = $GLOBALS['TCA'][$this->theTable]['columns'][$theField]['config']['uploadfolder']; 00603 } 00604 if ($uploadPath) { 00605 $theDestFile = $this->fileFunc->getUniqueName($this->fileFunc->cleanFileName($infoArr['name']), PATH_site.$uploadPath); 00606 t3lib_div::upload_copy_move($infoArr['tmp_name'],$theDestFile); 00607 // Setting the filename in the list 00608 $fI2 = pathinfo($theDestFile); 00609 $fileNameList[] = $fI2['basename']; 00610 $this->filesStoredInUploadFolders[]=$theDestFile; 00611 } 00612 } 00613 // Implode the list of filenames 00614 $this->dataArr[$theField] = implode(',',$fileNameList); 00615 } 00616 } 00617 00624 function overrideValues() { 00625 // Addition of overriding values 00626 if (is_array($this->conf[$this->cmdKey.'.']['overrideValues.'])) { 00627 reset($this->conf[$this->cmdKey.'.']['overrideValues.']); 00628 while(list($theField,$theValue)=each($this->conf[$this->cmdKey.'.']['overrideValues.'])) { 00629 $this->dataArr[$theField] = $theValue; 00630 } 00631 } 00632 } 00633 00640 function defaultValues() { 00641 // Addition of default values 00642 if (is_array($this->conf[$this->cmdKey.'.']['defaultValues.'])) { 00643 reset($this->conf[$this->cmdKey.'.']['defaultValues.']); 00644 while(list($theField,$theValue)=each($this->conf[$this->cmdKey.'.']['defaultValues.'])) { 00645 $this->dataArr[$theField] = $theValue; 00646 } 00647 } 00648 } 00649 00659 function evalValues() { 00660 // Check required, set failure if not ok. 00661 reset($this->requiredArr); 00662 $tempArr=array(); 00663 while(list(,$theField)=each($this->requiredArr)) { 00664 if (!trim($this->dataArr[$theField])) { 00665 $tempArr[]=$theField; 00666 } 00667 } 00668 00669 // Evaluate: This evaluates for more advanced things than 'required' does. But it returns the same error code, so you must let the required-message tell, if further evaluation has failed! 00670 $recExist=0; 00671 if (is_array($this->conf[$this->cmdKey.'.']['evalValues.'])) { 00672 switch($this->cmd) { 00673 case 'edit': 00674 if (isset($this->dataArr['pid'])) { // This may be tricked if the input has the pid-field set but the edit-field list does NOT allow the pid to be edited. Then the pid may be false. 00675 $recordTestPid = intval($this->dataArr['pid']); 00676 } else { 00677 $tempRecArr = $GLOBALS['TSFE']->sys_page->getRawRecord($this->theTable,$this->dataArr['uid']); 00678 $recordTestPid = intval($tempRecArr['pid']); 00679 } 00680 $recExist=1; 00681 break; 00682 default: 00683 $recordTestPid = $this->thePid ? $this->thePid : t3lib_div::intval_positive($this->dataArr['pid']); 00684 break; 00685 } 00686 00687 reset($this->conf[$this->cmdKey.'.']['evalValues.']); 00688 while(list($theField,$theValue)=each($this->conf[$this->cmdKey.'.']['evalValues.'])) { 00689 $listOfCommands = t3lib_div::trimExplode(',',$theValue,1); 00690 while(list(,$cmd)=each($listOfCommands)) { 00691 $cmdParts = split('\[|\]',$cmd); // Point is to enable parameters after each command enclosed in brackets [..]. These will be in position 1 in the array. 00692 $theCmd = trim($cmdParts[0]); 00693 switch($theCmd) { 00694 case 'uniqueGlobal': 00695 if ($DBrows = $GLOBALS['TSFE']->sys_page->getRecordsByField($this->theTable,$theField,$this->dataArr[$theField],'','','','1')) { 00696 if (!$recExist || $DBrows[0]['uid']!=$this->dataArr['uid']) { // Only issue an error if the record is not existing (if new...) and if the record with the false value selected was not our self. 00697 $tempArr[]=$theField; 00698 $this->failureMsg[$theField][] = $this->getFailure($theField, $theCmd, 'The value existed already. Enter a new value.'); 00699 } 00700 } 00701 break; 00702 case 'uniqueLocal': 00703 if ($DBrows = $GLOBALS['TSFE']->sys_page->getRecordsByField($this->theTable,$theField,$this->dataArr[$theField], 'AND pid IN ('.$recordTestPid.')','','','1')) { 00704 if (!$recExist || $DBrows[0]['uid']!=$this->dataArr['uid']) { // Only issue an error if the record is not existing (if new...) and if the record with the false value selected was not our self. 00705 $tempArr[]=$theField; 00706 $this->failureMsg[$theField][] = $this->getFailure($theField, $theCmd, 'The value existed already. Enter a new value.'); 00707 } 00708 } 00709 break; 00710 case 'twice': 00711 if (strcmp($this->dataArr[$theField], $this->dataArr[$theField.'_again'])) { 00712 $tempArr[]=$theField; 00713 $this->failureMsg[$theField][] = $this->getFailure($theField, $theCmd, 'You must enter the same value twice'); 00714 } 00715 break; 00716 case 'email': 00717 if (!$this->cObj->checkEmail($this->dataArr[$theField])) { 00718 $tempArr[]=$theField; 00719 $this->failureMsg[$theField][] = $this->getFailure($theField, $theCmd, 'You must enter a valid email address'); 00720 } 00721 break; 00722 case 'required': 00723 if (!trim($this->dataArr[$theField])) { 00724 $tempArr[]=$theField; 00725 $this->failureMsg[$theField][] = $this->getFailure($theField, $theCmd, 'You must enter a value!'); 00726 } 00727 break; 00728 case 'atLeast': 00729 $chars=intval($cmdParts[1]); 00730 if (strlen($this->dataArr[$theField])<$chars) { 00731 $tempArr[]=$theField; 00732 $this->failureMsg[$theField][] = sprintf($this->getFailure($theField, $theCmd, 'You must enter at least %s characters!'), $chars); 00733 } 00734 break; 00735 case 'atMost': 00736 $chars=intval($cmdParts[1]); 00737 if (strlen($this->dataArr[$theField])>$chars) { 00738 $tempArr[]=$theField; 00739 $this->failureMsg[$theField][] = sprintf($this->getFailure($theField, $theCmd, 'You must enter at most %s characters!'), $chars); 00740 } 00741 break; 00742 case 'inBranch': 00743 $pars = explode(';',$cmdParts[1]); 00744 if (intval($pars[0])) { 00745 $pid_list = $this->cObj->getTreeList( 00746 intval($pars[0]), 00747 intval($pars[1]) ? intval($pars[1]) : 999, 00748 intval($pars[2]) 00749 ); 00750 if (!$pid_list || !t3lib_div::inList($pid_list,$this->dataArr[$theField])) { 00751 $tempArr[]=$theField; 00752 $this->failureMsg[$theField][] = sprintf($this->getFailure($theField, $theCmd, 'The value was not a valid valud from this list: %s'), $pid_list); 00753 } 00754 } 00755 break; 00756 case 'unsetEmpty': 00757 if (!$this->dataArr[$theField]) { 00758 $hash = array_flip($tempArr); 00759 unset($hash[$theField]); 00760 $tempArr = array_keys($hash); 00761 unset($this->failureMsg[$theField]); 00762 unset($this->dataArr[$theField]); // This should prevent the field from entering the database. 00763 } 00764 break; 00765 } 00766 } 00767 $this->markerArray['###EVAL_ERROR_FIELD_'.$theField.'###'] = is_array($this->failureMsg[$theField]) ? implode('<br />',$this->failureMsg[$theField]) : ''; 00768 } 00769 } 00770 $this->failure=implode(',',$tempArr); //$failure will show which fields were not OK 00771 } 00772 00781 function userProcess($mConfKey,$passVar) { 00782 if ($this->conf[$mConfKey]) { 00783 $funcConf = $this->conf[$mConfKey.'.']; 00784 $funcConf['parentObj']=&$this; 00785 $passVar = $GLOBALS['TSFE']->cObj->callUserFunction($this->conf[$mConfKey], $funcConf, $passVar); 00786 } 00787 return $passVar; 00788 } 00789 00799 function userProcess_alt($confVal,$confArr,$passVar) { 00800 if ($confVal) { 00801 $funcConf = $confArr; 00802 $funcConf['parentObj']=&$this; 00803 $passVar = $GLOBALS['TSFE']->cObj->callUserFunction($confVal, $funcConf, $passVar); 00804 } 00805 return $passVar; 00806 } 00807 00808 00809 00810 00811 00812 00813 00814 00815 00816 00817 00818 00819 00820 00821 00822 00823 00824 00825 00826 00827 00828 00829 /***************************************** 00830 * 00831 * Database manipulation functions 00832 * 00833 *****************************************/ 00834 00841 function save() { 00842 switch($this->cmd) { 00843 case 'edit': 00844 $theUid = $this->dataArr['uid']; 00845 $origArr = $GLOBALS['TSFE']->sys_page->getRawRecord($this->theTable,$theUid); // Fetches the original record to check permissions 00846 if ($this->conf['edit'] && ($GLOBALS['TSFE']->loginUser || $this->aCAuth($origArr))) { // Must be logged in in order to edit (OR be validated by email) 00847 $newFieldList = implode(',',array_intersect(explode(',',$this->fieldList),t3lib_div::trimExplode(',',$this->conf['edit.']['fields'],1))); 00848 if ($this->aCAuth($origArr) || $this->cObj->DBmayFEUserEdit($this->theTable,$origArr,$GLOBALS['TSFE']->fe_user->user,$this->conf['allowedGroups'],$this->conf['fe_userEditSelf'])) { 00849 $this->cObj->DBgetUpdate($this->theTable, $theUid, $this->dataArr, $newFieldList, TRUE); 00850 $this->currentArr = $GLOBALS['TSFE']->sys_page->getRawRecord($this->theTable,$theUid); 00851 $this->userProcess_alt($this->conf['edit.']['userFunc_afterSave'],$this->conf['edit.']['userFunc_afterSave.'],array('rec'=>$this->currentArr, 'origRec'=>$origArr)); 00852 $this->saved=1; 00853 } else { 00854 $this->error='###TEMPLATE_NO_PERMISSIONS###'; 00855 } 00856 } 00857 break; 00858 default: 00859 if ($this->conf['create']) { 00860 $newFieldList = implode(',',array_intersect(explode(',',$this->fieldList),t3lib_div::trimExplode(',',$this->conf['create.']['fields'],1))); 00861 $this->cObj->DBgetInsert($this->theTable, $this->thePid, $this->dataArr, $newFieldList, TRUE); 00862 $newId = $GLOBALS['TYPO3_DB']->sql_insert_id(); 00863 00864 if ($this->theTable=='fe_users' && $this->conf['fe_userOwnSelf']) { // enables users, creating logins, to own them self. 00865 $extraList=''; 00866 $dataArr = array(); 00867 if ($GLOBALS['TCA'][$this->theTable]['ctrl']['fe_cruser_id']) { 00868 $field=$GLOBALS['TCA'][$this->theTable]['ctrl']['fe_cruser_id']; 00869 $dataArr[$field]=$newId; 00870 $extraList.=','.$field; 00871 } 00872 if ($GLOBALS['TCA'][$this->theTable]['ctrl']['fe_crgroup_id']) { 00873 $field=$GLOBALS['TCA'][$this->theTable]['ctrl']['fe_crgroup_id']; 00874 list($dataArr[$field])=explode(',',$this->dataArr['usergroup']); 00875 $dataArr[$field]=intval($dataArr[$field]); 00876 $extraList.=','.$field; 00877 } 00878 if (count($dataArr)) { 00879 $this->cObj->DBgetUpdate($this->theTable, $newId, $dataArr, $extraList, TRUE); 00880 } 00881 } 00882 00883 $this->currentArr = $GLOBALS['TSFE']->sys_page->getRawRecord($this->theTable,$newId); 00884 $this->userProcess_alt($this->conf['create.']['userFunc_afterSave'],$this->conf['create.']['userFunc_afterSave.'],array('rec'=>$this->currentArr)); 00885 $this->saved=1; 00886 } 00887 break; 00888 } 00889 } 00890 00899 function deleteRecord() { 00900 if ($this->conf['delete']) { // If deleting is enabled 00901 $origArr = $GLOBALS['TSFE']->sys_page->getRawRecord($this->theTable, $this->recUid); 00902 if ($GLOBALS['TSFE']->loginUser || $this->aCAuth($origArr)) { // Must be logged in OR be authenticated by the aC code in order to delete 00903 // If the recUid selects a record.... (no check here) 00904 if (is_array($origArr)) { 00905 if ($this->aCAuth($origArr) || $this->cObj->DBmayFEUserEdit($this->theTable,$origArr, $GLOBALS['TSFE']->fe_user->user,$this->conf['allowedGroups'],$this->conf['fe_userEditSelf'])) { // Display the form, if access granted. 00906 if (!$GLOBALS['TCA'][$this->theTable]['ctrl']['delete']) { // If the record is fully deleted... then remove the image (or any file) attached. 00907 $this->deleteFilesFromRecord($this->recUid); 00908 } 00909 $this->cObj->DBgetDelete($this->theTable, $this->recUid, TRUE); 00910 $this->currentArr = $origArr; 00911 $this->saved = 1; 00912 } else { 00913 $this->error = '###TEMPLATE_NO_PERMISSIONS###'; 00914 } 00915 } 00916 } 00917 } 00918 } 00919 00929 function deleteFilesFromRecord($uid) { 00930 $table = $this->theTable; 00931 $rec = $GLOBALS['TSFE']->sys_page->getRawRecord($table,$uid); 00932 00933 $GLOBALS['TSFE']->includeTCA(); 00934 t3lib_div::loadTCA($table); 00935 reset($GLOBALS['TCA'][$table]['columns']); 00936 $iFields=array(); 00937 while(list($field,$conf)=each($GLOBALS['TCA'][$table]['columns'])) { 00938 if ($conf['config']['type']=='group' && $conf['config']['internal_type']=='file') { 00939 00940 $GLOBALS['TYPO3_DB']->exec_UPDATEquery($table, 'uid='.intval($uid), array($field => '')); 00941 00942 $delFileArr = explode(',',$rec[$field]); 00943 reset($delFileArr); 00944 while(list(,$n)=each($delFileArr)) { 00945 if ($n) { 00946 $fpath = $conf['config']['uploadfolder'].'/'.$n; 00947 unlink($fpath); 00948 } 00949 } 00950 } 00951 } 00952 } 00953 00954 00955 00956 00957 00958 00959 00960 00961 00962 00963 00964 00965 00966 00967 00968 00969 00970 00971 00972 00973 00974 /***************************************** 00975 * 00976 * Command "display" functions 00977 * 00978 *****************************************/ 00979 00986 function displayDeleteScreen() { 00987 if ($this->conf['delete']) { // If deleting is enabled 00988 $origArr = $GLOBALS['TSFE']->sys_page->getRawRecord($this->theTable, $this->recUid); 00989 if ($GLOBALS['TSFE']->loginUser || $this->aCAuth($origArr)) { // Must be logged in OR be authenticated by the aC code in order to delete 00990 // If the recUid selects a record.... (no check here) 00991 if (is_array($origArr)) { 00992 if ($this->aCAuth($origArr) || $this->cObj->DBmayFEUserEdit($this->theTable,$origArr, $GLOBALS['TSFE']->fe_user->user,$this->conf['allowedGroups'],$this->conf['fe_userEditSelf'])) { // Display the form, if access granted. 00993 $this->markerArray['###HIDDENFIELDS###'].= '<input type="hidden" name="rU" value="'.$this->recUid.'" />'; 00994 $content = $this->getPlainTemplate('###TEMPLATE_DELETE_PREVIEW###', $origArr); 00995 } else { // Else display error, that you could not edit that particular record... 00996 $content = $this->getPlainTemplate('###TEMPLATE_NO_PERMISSIONS###'); 00997 } 00998 } 00999 } else { // Finally this is if there is no login user. This must tell that you must login. Perhaps link to a page with create-user or login information. 01000 $content = $this->getPlainTemplate('###TEMPLATE_AUTH###'); 01001 } 01002 } else { 01003 $content.='Delete-option is not set in TypoScript'; 01004 } 01005 return $content; 01006 } 01007 01014 function displayCreateScreen() { 01015 if ($this->conf['create']) { 01016 $templateCode = $this->cObj->getSubpart($this->templateCode, ((!$GLOBALS['TSFE']->loginUser||$this->conf['create.']['noSpecialLoginForm'])?'###TEMPLATE_CREATE'.$this->previewLabel.'###':'###TEMPLATE_CREATE_LOGIN'.$this->previewLabel.'###')); 01017 $failure = t3lib_div::_GP('noWarnings')?'':$this->failure; 01018 if (!$failure) $templateCode = $this->cObj->substituteSubpart($templateCode, '###SUB_REQUIRED_FIELDS_WARNING###', ''); 01019 01020 $templateCode = $this->removeRequired($templateCode,$failure); 01021 $this->setCObjects($templateCode); 01022 01023 $markerArray = $this->cObj->fillInMarkerArray($this->markerArray, $this->dataArr, '', TRUE, 'FIELD_', $this->recInMarkersHSC); 01024 if ($this->conf['create.']['preview'] && !$this->previewLabel) {$markerArray['###HIDDENFIELDS###'].= '<input type="hidden" name="preview" value="1" />';} 01025 $content = $this->cObj->substituteMarkerArray($templateCode, $markerArray); 01026 $content.=$this->cObj->getUpdateJS($this->modifyDataArrForFormUpdate($this->dataArr), $this->theTable.'_form', 'FE['.$this->theTable.']', $this->fieldList.$this->additionalUpdateFields); 01027 } 01028 return $content; 01029 } 01030 01037 function displayEditScreen() { 01038 if ($this->conf['edit']) { // If editing is enabled 01039 $origArr = $GLOBALS['TSFE']->sys_page->getRawRecord($this->theTable, $this->dataArr['uid']?$this->dataArr['uid']:$this->recUid); 01040 01041 if ($GLOBALS['TSFE']->loginUser || $this->aCAuth($origArr)) { // Must be logged in OR be authenticated by the aC code in order to edit 01042 // If the recUid selects a record.... (no check here) 01043 if (is_array($origArr)) { 01044 if ($this->aCAuth($origArr) || $this->cObj->DBmayFEUserEdit($this->theTable,$origArr, $GLOBALS['TSFE']->fe_user->user,$this->conf['allowedGroups'],$this->conf['fe_userEditSelf'])) { // Display the form, if access granted. 01045 $content=$this->displayEditForm($origArr); 01046 } else { // Else display error, that you could not edit that particular record... 01047 $content = $this->getPlainTemplate('###TEMPLATE_NO_PERMISSIONS###'); 01048 } 01049 } elseif ($GLOBALS['TSFE']->loginUser) { // If the recUid did not select a record, we display a menu of records. (eg. if no recUid) 01050 $lockPid = $this->conf['edit.']['menuLockPid'] ? ' AND pid='.intval($this->thePid) : ''; 01051 01052 $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)); 01053 01054 if ($GLOBALS['TYPO3_DB']->sql_num_rows($res)) { // If there are menu-items ... 01055 $templateCode = $this->getPlainTemplate('###TEMPLATE_EDITMENU###'); 01056 $out=''; 01057 $itemCode = $this->cObj->getSubpart($templateCode, '###ITEM###'); 01058 while($menuRow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { 01059 $markerArray = $this->cObj->fillInMarkerArray(array(), $menuRow, '', TRUE, 'FIELD_', $this->recInMarkersHSC); 01060 $markerArray = $this->setCObjects($itemCode,$menuRow,$markerArray,'ITEM_'); 01061 $out.= $this->cObj->substituteMarkerArray($itemCode, $markerArray); 01062 } 01063 $content=$this->cObj->substituteSubpart($templateCode, '###ALLITEMS###', $out); 01064 } else { // If there are not menu items.... 01065 $content = $this->getPlainTemplate('###TEMPLATE_EDITMENU_NOITEMS###'); 01066 } 01067 } else { 01068 $content = $this->getPlainTemplate('###TEMPLATE_AUTH###'); 01069 } 01070 } else { // Finally this is if there is no login user. This must tell that you must login. Perhaps link to a page with create-user or login information. 01071 $content = $this->getPlainTemplate('###TEMPLATE_AUTH###'); 01072 } 01073 } else { 01074 $content.='Edit-option is not set in TypoScript'; 01075 } 01076 return $content; 01077 } 01078 01088 function displayEditForm($origArr) { 01089 $currentArr = is_array($this->dataArr) ? $this->dataArr+$origArr : $origArr; 01090 01091 if ($this->conf['debug']) debug('displayEditForm(): '.'###TEMPLATE_EDIT'.$this->previewLabel.'###',1); 01092 $templateCode = $this->cObj->getSubpart($this->templateCode, '###TEMPLATE_EDIT'.$this->previewLabel.'###'); 01093 $failure = t3lib_div::_GP('noWarnings')?'':$this->failure; 01094 if (!$failure) {$templateCode = $this->cObj->substituteSubpart($templateCode, '###SUB_REQUIRED_FIELDS_WARNING###', '');} 01095 01096 $templateCode = $this->removeRequired($templateCode,$failure); 01097 01098 $this->setCObjects($templateCode,$currentArr); 01099 01100 $markerArray = $this->cObj->fillInMarkerArray($this->markerArray, $currentArr, '', TRUE, 'FIELD_', $this->recInMarkersHSC); 01101 01102 $markerArray['###HIDDENFIELDS###'].= '<input type="hidden" name="FE['.$this->theTable.'][uid]" value="'.$currentArr['uid'].'" />'; 01103 if ($this->conf['edit.']['preview'] && !$this->previewLabel) {$markerArray['###HIDDENFIELDS###'].= '<input type="hidden" name="preview" value="1" />';} 01104 $content = $this->cObj->substituteMarkerArray($templateCode, $markerArray); 01105 $content.=$this->cObj->getUpdateJS($this->modifyDataArrForFormUpdate($currentArr), $this->theTable.'_form', 'FE['.$this->theTable.']', $this->fieldList.$this->additionalUpdateFields); 01106 01107 return $content; 01108 } 01109 01116 function procesSetFixed() { 01117 if ($this->conf['setfixed']) { 01118 $theUid = intval($this->recUid); 01119 $origArr = $GLOBALS['TSFE']->sys_page->getRawRecord($this->theTable, $theUid); 01120 $fD = t3lib_div::_GP('fD'); 01121 $sFK = t3lib_div::_GP('sFK'); 01122 01123 $fieldArr=array(); 01124 if (is_array($fD) || $sFK=='DELETE') { 01125 if (is_array($fD)) { 01126 reset($fD); 01127 while(list($field,$value)=each($fD)) { 01128 $origArr[$field]=$value; 01129 $fieldArr[]=$field; 01130 } 01131 } 01132 $theCode = $this->setfixedHash($origArr,$origArr['_FIELDLIST']); 01133 if (!strcmp($this->authCode,$theCode)) { 01134 if ($sFK=='DELETE') { 01135 $this->cObj->DBgetDelete($this->theTable, $theUid, TRUE); 01136 } else { 01137 $newFieldList = implode(',',array_intersect(t3lib_div::trimExplode(',',$this->fieldList),t3lib_div::trimExplode(',',implode($fieldArr,','),1))); 01138 $this->cObj->DBgetUpdate($this->theTable, $theUid, $fD, $newFieldList, TRUE); 01139 $this->currentArr = $GLOBALS['TSFE']->sys_page->getRawRecord($this->theTable,$theUid); 01140 $this->userProcess_alt($this->conf['setfixed.']['userFunc_afterSave'],$this->conf['setfixed.']['userFunc_afterSave.'],array('rec'=>$this->currentArr, 'origRec'=>$origArr)); 01141 } 01142 01143 // Outputting template 01144 $this->markerArray = $this->cObj->fillInMarkerArray($this->markerArray, $origArr, '', TRUE, 'FIELD_', $this->recInMarkersHSC); 01145 $content = $this->getPlainTemplate('###TEMPLATE_SETFIXED_OK_'.$sFK.'###'); 01146 if (!$content) {$content = $this->getPlainTemplate('###TEMPLATE_SETFIXED_OK###');} 01147 01148 // Compiling email 01149 $this->compileMail( 01150 'SETFIXED_'.$sFK, 01151 array($origArr), 01152 $origArr[$this->conf['email.']['field']], 01153 $this->conf['setfixed.'] 01154 ); 01155 // Clearing cache if set: 01156 $this->clearCacheIfSet(); 01157 } else $content = $this->getPlainTemplate('###TEMPLATE_SETFIXED_FAILED###'); 01158 } else $content = $this->getPlainTemplate('###TEMPLATE_SETFIXED_FAILED###'); 01159 } 01160 return $content; 01161 } 01162 01163 01164 01165 01166 01167 01168 01169 01170 01171 01172 01173 01174 01175 01176 01177 01178 01179 01180 01181 01182 01183 01184 01185 /***************************************** 01186 * 01187 * Template processing functions 01188 * 01189 *****************************************/ 01190 01191 01192 01205 function removeRequired($templateCode,$failure) { 01206 reset($this->requiredArr); 01207 while(list(,$theField)=each($this->requiredArr)) { 01208 if (!t3lib_div::inList($failure,$theField)) { 01209 $templateCode = $this->cObj->substituteSubpart($templateCode, '###SUB_REQUIRED_FIELD_'.$theField.'###', ''); 01210 } 01211 } 01212 return $templateCode; 01213 } 01214 01223 function getPlainTemplate($key,$r='') { 01224 if ($this->conf['debug']) debug('getPlainTemplate(): '.$key,1); 01225 $templateCode = $this->cObj->getSubpart($this->templateCode, $key); 01226 $this->setCObjects($templateCode,is_array($r)?$r:array()); 01227 return $this->cObj->substituteMarkerArray( 01228 $templateCode, 01229 is_array($r) ? $this->cObj->fillInMarkerArray($this->markerArray, $r, '', TRUE, 'FIELD_', $this->recInMarkersHSC) : $this->markerArray 01230 ); 01231 } 01232 01240 function modifyDataArrForFormUpdate($inputArr) { 01241 if (is_array($this->conf[$this->cmdKey.'.']['evalValues.'])) { 01242 reset($this->conf[$this->cmdKey.'.']['evalValues.']); 01243 while(list($theField,$theValue)=each($this->conf[$this->cmdKey.'.']['evalValues.'])) { 01244 $listOfCommands = t3lib_div::trimExplode(',',$theValue,1); 01245 while(list(,$cmd)=each($listOfCommands)) { 01246 $cmdParts = split('\[|\]',$cmd); // Point is to enable parameters after each command enclosed in brackets [..]. These will be in position 1 in the array. 01247 $theCmd = trim($cmdParts[0]); 01248 switch($theCmd) { 01249 case 'twice': 01250 if (isset($inputArr[$theField])) { 01251 if (!isset($inputArr[$theField.'_again'])) { 01252 $inputArr[$theField.'_again'] = $inputArr[$theField]; 01253 } 01254 $this->additionalUpdateFields.=','.$theField.'_again'; 01255 } 01256 break; 01257 } 01258 } 01259 } 01260 } 01261 if (is_array($this->conf['parseValues.'])) { 01262 reset($this->conf['parseValues.']); 01263 while(list($theField,$theValue)=each($this->conf['parseValues.'])) { 01264 $listOfCommands = t3lib_div::trimExplode(',',$theValue,1); 01265 while(list(,$cmd)=each($listOfCommands)) { 01266 $cmdParts = split('\[|\]',$cmd); // Point is to enable parameters after each command enclosed in brackets [..]. These will be in position 1 in the array. 01267 $theCmd = trim($cmdParts[0]); 01268 switch($theCmd) { 01269 case 'multiple': 01270 if (isset($inputArr[$theField]) && !$this->isPreview()) { 01271 $inputArr[$theField] = explode(',',$inputArr[$theField]); 01272 } 01273 break; 01274 case 'checkArray': 01275 if ($inputArr[$theField] && !$this->isPreview()) { 01276 for($a=0;$a<=30;$a++) { 01277 if ($inputArr[$theField] & pow(2,$a)) { 01278 $alt_theField = $theField.']['.$a; 01279 $inputArr[$alt_theField] = 1; 01280 $this->additionalUpdateFields.=','.$alt_theField; 01281 } 01282 } 01283 } 01284 break; 01285 } 01286 } 01287 } 01288 } 01289 01290 01291 $inputArr = $this->userProcess_alt( 01292 $this->conf['userFunc_updateArray'], 01293 $this->conf['userFunc_updateArray.'], 01294 $inputArr 01295 ); 01296 01297 return $inputArr; 01298 } 01299 01309 function setCObjects($templateCode,$currentArr=array(),$markerArray='',$specialPrefix='') { 01310 if (is_array($this->conf['cObjects.'])) { 01311 reset($this->conf['cObjects.']); 01312 01313 while(list($theKey,$theConf)=each($this->conf['cObjects.'])) { 01314 if (!strstr($theKey,'.')) { 01315 if (strstr($templateCode,'###'.$specialPrefix.'CE_'.$theKey.'###')) { 01316 $cObjCode = $this->cObj->cObjGetSingle($this->conf['cObjects.'][$theKey], $this->conf['cObjects.'][$theKey.'.'], 'cObjects.'.$theKey); 01317 01318 if (!is_array($markerArray)) { 01319 $this->markerArray['###'.$specialPrefix.'CE_'.$theKey.'###'] = $cObjCode; 01320 } else { 01321 $markerArray['###'.$specialPrefix.'CE_'.$theKey.'###'] = $cObjCode; 01322 } 01323 } 01324 if (strstr($templateCode,'###'.$specialPrefix.'PCE_'.$theKey.'###')) { 01325 $local_cObj =t3lib_div::makeInstance('tslib_cObj'); 01326 $local_cObj->start(count($currentArr)?$currentArr:$this->dataArr,$this->theTable); 01327 $cObjCode = $local_cObj->cObjGetSingle($this->conf['cObjects.'][$theKey], $this->conf['cObjects.'][$theKey.'.'], 'cObjects.'.$theKey); 01328 01329 if (!is_array($markerArray)) { 01330 $this->markerArray['###'.$specialPrefix.'PCE_'.$theKey.'###'] = $cObjCode; 01331 } else { 01332 $markerArray['###'.$specialPrefix.'PCE_'.$theKey.'###'] = $cObjCode; 01333 } 01334 } 01335 } 01336 } 01337 } 01338 return $markerArray; 01339 } 01340 01341 01342 01343 01344 01345 01346 01347 01348 01349 01350 01351 01352 01353 01354 01355 01356 01357 01358 01359 /***************************************** 01360 * 01361 * Emailing 01362 * 01363 *****************************************/ 01364 01371 function sendInfoMail() { 01372 if ($this->conf['infomail'] && $this->conf['email.']['field']) { 01373 $fetch = t3lib_div::_GP('fetch'); 01374 if ($fetch) { 01375 // Getting infomail config. 01376 $key= trim(t3lib_div::_GP('key')); 01377 if (is_array($this->conf['infomail.'][$key.'.'])) { 01378 $config = $this->conf['infomail.'][$key.'.']; 01379 } else { 01380 $config = $this->conf['infomail.']['default.']; 01381 } 01382 $pidLock=''; 01383 if (!$config['dontLockPid']) { 01384 $pidLock='AND pid IN ('.$this->thePid.') '; 01385 } 01386 01387 // Getting records 01388 if (t3lib_div::testInt($fetch)) { 01389 $DBrows = $GLOBALS['TSFE']->sys_page->getRecordsByField($this->theTable,'uid',$fetch,$pidLock,'','','1'); 01390 } elseif ($fetch) { // $this->conf['email.']['field'] must be a valid field in the table! 01391 $DBrows = $GLOBALS['TSFE']->sys_page->getRecordsByField($this->theTable,$this->conf['email.']['field'],$fetch,$pidLock,'','','100'); 01392 } 01393 01394 // Processing records 01395 if (is_array($DBrows)) { 01396 $recipient = $DBrows[0][$this->conf['email.']['field']]; 01397 $this->compileMail($config['label'], $DBrows, $recipient, $this->conf['setfixed.']); 01398 } elseif ($this->cObj->checkEmail($fetch)) { 01399 $this->sendMail($fetch, '', trim($this->cObj->getSubpart($this->templateCode, '###'.$this->emailMarkPrefix.'NORECORD###'))); 01400 } 01401 01402 $content = $this->getPlainTemplate('###TEMPLATE_INFOMAIL_SENT###'); 01403 } else { 01404 $content = $this->getPlainTemplate('###TEMPLATE_INFOMAIL###'); 01405 } 01406 } else $content='Error: infomail option is not available or emailField is not setup in TypoScript'; 01407 return $content; 01408 } 01409 01419 function compileMail($key, $DBrows, $recipient, $setFixedConfig=array()) { 01420 $GLOBALS['TT']->push('compileMail'); 01421 $mailContent=''; 01422 $key = $this->emailMarkPrefix.$key; 01423 01424 $userContent['all'] = trim($this->cObj->getSubpart($this->templateCode, '###'.$key.'###')); 01425 $adminContent['all'] = trim($this->cObj->getSubpart($this->templateCode, '###'.$key.'-ADMIN###')); 01426 $userContent['rec'] = $this->cObj->getSubpart($userContent['all'], '###SUB_RECORD###'); 01427 $adminContent['rec'] = $this->cObj->getSubpart($adminContent['all'], '###SUB_RECORD###'); 01428 01429 reset($DBrows); 01430 while(list(,$r)=each($DBrows)) { 01431 $markerArray = $this->cObj->fillInMarkerArray($this->markerArray, $r,'',0); 01432 $markerArray = $this->setCObjects($userContent['rec'].$adminContent['rec'],$r,$markerArray,'ITEM_'); 01433 $markerArray['###SYS_AUTHCODE###'] = $this->authCode($r); 01434 $markerArray = $this->setfixed($markerArray, $setFixedConfig, $r); 01435 01436 if ($userContent['rec']) $userContent['accum'] .=$this->cObj->substituteMarkerArray($userContent['rec'], $markerArray); 01437 if ($adminContent['rec']) $adminContent['accum'].=$this->cObj->substituteMarkerArray($adminContent['rec'], $markerArray); 01438 } 01439 01440 if ($userContent['all']) $userContent['final'] .=$this->cObj->substituteSubpart($userContent['all'], '###SUB_RECORD###', $userContent['accum']); 01441 if ($adminContent['all']) $adminContent['final'].=$this->cObj->substituteSubpart($adminContent['all'], '###SUB_RECORD###', $adminContent['accum']); 01442 01443 if (t3lib_div::testInt($recipient)) { 01444 $fe_userRec = $GLOBALS['TSFE']->sys_page->getRawRecord('fe_users',$recipient); 01445 $recipient=$fe_userRec['email']; 01446 } 01447 01448 $GLOBALS['TT']->setTSlogMessage('Template key: ###'.$key.'###, userContentLength: '.strlen($userContent['final']).', adminContentLength: '.strlen($adminContent['final'])); 01449 01450 $this->sendMail($recipient, $this->conf['email.']['admin'], $userContent['final'], $adminContent['final']); 01451 $GLOBALS['TT']->pull(); 01452 } 01453 01465 function sendMail($recipient, $admin, $content='', $adminContent='') { 01466 // Admin mail: 01467 if ($admin && $adminContent) { 01468 if (!$this->isHTMLContent($adminContent)) { 01469 $admMail = $this->cObj->sendNotifyEmail($adminContent, 01470 $admin, 01471 '', 01472 $this->conf['email.']['from'], 01473 $this->conf['email.']['fromName'], 01474 $recipient 01475 ); 01476 } else { 01477 $this->sendHTMLMail($adminContent, 01478 $admin, 01479 '', 01480 $this->conf['email.']['from'], 01481 $this->conf['email.']['fromName'], 01482 $recipient 01483 ); 01484 } 01485 } 01486 // user mail: 01487 if (!$this->isHTMLContent($content)) { 01488 $this->cObj->sendNotifyEmail($content, 01489 $recipient, 01490 '', // ($admMail ? '' : $admin), // If the special administration mail was not found and send, the regular is... 01491 $this->conf['email.']['from'], 01492 $this->conf['email.']['fromName'] 01493 ); 01494 } else { 01495 $this->sendHTMLMail($content, 01496 $recipient, 01497 '', // ($admMail ? '' : $admin), // If the special administration mail was not found and send, the regular is... 01498 $this->conf['email.']['from'], 01499 $this->conf['email.']['fromName'] 01500 ); 01501 } 01502 } 01503 01510 function isHTMLContent($c) { 01511 $c = trim($c); 01512 $first = strtolower(substr($c,0,6)); 01513 $last = strtolower(substr($c,-7)); 01514 if ($first.$last=='<html></html>') return 1; 01515 } 01516 01531 function sendHTMLMail($content,$recipient,$dummy,$fromEmail,$fromName,$replyTo='') { 01532 if (trim($recipient) && trim($content)) { 01533 $cls=t3lib_div::makeInstanceClassName('t3lib_htmlmail'); 01534 if (class_exists($cls)) { // If htmlmail lib is included, then generate a nice HTML-email 01535 $parts = spliti('<title>|</title>',$content,3); 01536 $subject = trim($parts[1]) ? trim($parts[1]) : 'TYPO3 FE Admin message'; 01537 01538 $Typo3_htmlmail = t3lib_div::makeInstance('t3lib_htmlmail'); 01539 $Typo3_htmlmail->start(); 01540 $Typo3_htmlmail->useBase64(); 01541 01542 $Typo3_htmlmail->subject = $subject; 01543 $Typo3_htmlmail->from_email = $fromEmail; 01544 $Typo3_htmlmail->from_name = $fromName; 01545 $Typo3_htmlmail->replyto_email = $replyTo ? $replyTo : $fromEmail; 01546 $Typo3_htmlmail->replyto_name = $replyTo ? '' : $fromName; 01547 $Typo3_htmlmail->organisation = ''; 01548 $Typo3_htmlmail->priority = 3; 01549 01550 // HTML 01551 $Typo3_htmlmail->theParts['html']['content'] = $content; // Fetches the content of the page 01552 $Typo3_htmlmail->theParts['html']['path'] = ''; 01553 $Typo3_htmlmail->extractMediaLinks(); 01554 $Typo3_htmlmail->extractHyperLinks(); 01555 $Typo3_htmlmail->fetchHTMLMedia(); 01556 $Typo3_htmlmail->substMediaNamesInHTML(0); // 0 = relative 01557 $Typo3_htmlmail->substHREFsInHTML(); 01558 $Typo3_htmlmail->setHTML($Typo3_htmlmail->encodeMsg($Typo3_htmlmail->theParts['html']['content'])); 01559 01560 // PLAIN 01561 $Typo3_htmlmail->addPlain(''); 01562 01563 // SET Headers and Content 01564 $Typo3_htmlmail->setHeaders(); 01565 $Typo3_htmlmail->setContent(); 01566 $Typo3_htmlmail->setRecipient($recipient); 01567 01568 // debug($Typo3_htmlmail->theParts); 01569 $Typo3_htmlmail->sendtheMail(); 01570 } else { 01571 debug('SYSTEM ERROR: No HTML-mail library loaded. Set "page.config.incT3Lib_htmlmail = 1" is your TypoScript template.'); 01572 } 01573 } 01574 } 01575 01576 01577 01578 01579 01580 01581 01582 01583 01584 01585 01586 01587 01588 01589 01590 01591 01592 01593 01594 01595 01596 01597 01598 01599 /***************************************** 01600 * 01601 * Various helper functions 01602 * 01603 *****************************************/ 01604 01605 01615 function aCAuth($r) { 01616 if ($this->authCode && !strcmp($this->authCode,$this->authCode($r))) { 01617 return true; 01618 } 01619 } 01620 01629 function authCode($r,$extra='') { 01630 $l=$this->codeLength; 01631 if ($this->conf['authcodeFields']) { 01632 $fieldArr = t3lib_div::trimExplode(',', $this->conf['authcodeFields'], 1); 01633 $value=''; 01634 while(list(,$field)=each($fieldArr)) { 01635 $value.=$r[$field].'|'; 01636 } 01637 $value.=$extra.'|'.$this->conf['authcodeFields.']['addKey']; 01638 if ($this->conf['authcodeFields.']['addDate']) { 01639 $value.='|'.date($this->conf['authcodeFields.']['addDate']); 01640 } 01641 $value.=$GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey']; 01642 return substr(md5($value), 0,$l); 01643 } 01644 } 01645 01655 function setfixed($markerArray, $setfixed, $r) { 01656 if (is_array($setfixed)) { 01657 reset($setfixed); 01658 while(list($theKey,$data)=each($setfixed)) { 01659 if (!strcmp($theKey,'DELETE')) { 01660 $recCopy = $r; 01661 $string='&cmd=setfixed&sFK='.rawurlencode($theKey).'&rU='.$r['uid']; 01662 $string.='&aC='.$this->setfixedHash($recCopy,$data['_FIELDLIST']); 01663 $markerArray['###SYS_SETFIXED_DELETE###'] = $string; 01664 $markerArray['###SYS_SETFIXED_HSC_DELETE###'] = htmlspecialchars($string); 01665 } elseif (strstr($theKey,'.')) { 01666 $theKey = substr($theKey,0,-1); 01667 if (is_array($data)) { 01668 reset($data); 01669 $recCopy = $r; 01670 $string='&cmd=setfixed&sFK='.rawurlencode($theKey).'&rU='.$r['uid']; 01671 while(list($fieldName,$fieldValue)=each($data)) { 01672 $string.='&fD['.$fieldName.']='.rawurlencode($fieldValue); 01673 $recCopy[$fieldName]=$fieldValue; 01674 } 01675 $string.='&aC='.$this->setfixedHash($recCopy,$data['_FIELDLIST']); 01676 $markerArray['###SYS_SETFIXED_'.$theKey.'###'] = $string; 01677 $markerArray['###SYS_SETFIXED_HSC_'.$theKey.'###'] = htmlspecialchars($string); 01678 } 01679 } 01680 } 01681 } 01682 return $markerArray; 01683 } 01684 01693 function setfixedHash($recCopy,$fields='') { 01694 if ($fields) { 01695 $fieldArr = t3lib_div::trimExplode(',',$fields,1); 01696 reset($fieldArr); 01697 while(list($k,$v)=each($fieldArr)) { 01698 $recCopy_temp[$k]=$recCopy[$v]; 01699 } 01700 } else { 01701 $recCopy_temp=$recCopy; 01702 } 01703 $encStr = implode('|',$recCopy_temp).'|'.$this->conf['authcodeFields.']['addKey'].'|'.$GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey']; 01704 $hash = substr(md5($encStr),0,$this->codeLength); 01705 return $hash; 01706 } 01707 01708 01714 function isPreview() { 01715 return ($this->conf[$this->cmdKey.'.']['preview'] && $this->preview); 01716 } 01717 01723 function createFileFuncObj() { 01724 if (!$this->fileFunc) { 01725 $this->fileFunc = t3lib_div::makeInstance('t3lib_basicFileFunctions'); 01726 } 01727 } 01728 01734 function clearCacheIfSet() { 01735 if ($this->conf['clearCacheOfPages']) { 01736 $cc_pidList = $GLOBALS['TYPO3_DB']->cleanIntList($this->conf['clearCacheOfPages']); 01737 $GLOBALS['TSFE']->clearPageCacheContent_pidList($cc_pidList); 01738 } 01739 } 01740 01749 function getFailure($theField, $theCmd, $label) { 01750 return isset($this->conf['evalErrors.'][$theField.'.'][$theCmd]) ? $this->conf['evalErrors.'][$theField.'.'][$theCmd] : $label; 01751 } 01752 } 01753 01754 01755 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['media/scripts/fe_adminLib.inc']) { 01756 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['media/scripts/fe_adminLib.inc']); 01757 } 01758 ?>