Documentation TYPO3 par Ameos

fe_adminLib.inc

00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 1999-2004 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 
00198                 $this->nc = $this->conf['no_cache'] ? '&no_cache=1' : $this->nc;
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                         // Initialize markerArray, setting FORM_URL and HIDDENFIELDS
00216                 $this->markerArray['###FORM_URL###'] = 'index.php?id='.$GLOBALS['TSFE']->id.'&type='.$GLOBALS['TSFE']->type.$this->nc.$this->conf['addParams'];
00217                 $this->markerArray['###FORM_URL_ENC###'] = rawurlencode($this->markerArray['###FORM_URL###']);
00218                 $this->markerArray['###FORM_URL_HSC###'] = htmlspecialchars($this->markerArray['###FORM_URL###']);
00219 
00220                 $this->markerArray['###BACK_URL###'] = $this->backURL;
00221                 $this->markerArray['###BACK_URL_ENC###'] = rawurlencode($this->markerArray['###BACK_URL###']);
00222                 $this->markerArray['###BACK_URL_HSC###'] = htmlspecialchars($this->markerArray['###BACK_URL###']);
00223 
00224                 $this->markerArray['###THE_PID###'] = $this->thePid;
00225                 $this->markerArray['###REC_UID###'] = $this->recUid;
00226                 $this->markerArray['###AUTH_CODE###'] = $this->authCode;
00227                 $this->markerArray['###THIS_ID###'] = $GLOBALS['TSFE']->id;
00228                 $this->markerArray['###THIS_URL###'] = htmlspecialchars(t3lib_div::getIndpEnv('TYPO3_REQUEST_DIR'));
00229                 $this->markerArray['###HIDDENFIELDS###'] =
00230                         ($this->cmd?'<input type="hidden" name="cmd" value="'.htmlspecialchars($this->cmd).'" />':'').
00231                         ($this->authCode?'<input type="hidden" name="aC" value="'.htmlspecialchars($this->authCode).'" />':'').
00232                         ($this->backURL?'<input type="hidden" name="backURL" value="'.htmlspecialchars($this->backURL).'" />':'');
00233 
00234 
00235                         // Setting cmdKey which is either 'edit' or 'create'
00236                 switch($this->cmd)      {
00237                         case 'edit':
00238                                 $this->cmdKey='edit';
00239                         break;
00240                         default:
00241                                 $this->cmdKey='create';
00242                         break;
00243                 }
00244                         // Setting requiredArr to the fields in 'required' intersected field the total field list in order to remove invalid fields.
00245                 $this->requiredArr = array_intersect(
00246                         t3lib_div::trimExplode(',',$this->conf[$this->cmdKey.'.']['required'],1),
00247                         t3lib_div::trimExplode(',',$this->conf[$this->cmdKey.'.']['fields'],1)
00248                 );
00249 
00250                         // Setting incoming data. Non-stripped
00251                 $fe=t3lib_div::_GP('FE');
00252                 $this->dataArr = $fe[$this->theTable];  // Incoming data.
00253 
00254                         // Checking template file and table value
00255                 if (!$this->templateCode)       {
00256                         $content = 'No template file found: '.$this->conf['templateFile'];
00257                         return $content;
00258                 }
00259 
00260                 if (!$this->theTable || !$this->fieldList)      {
00261                         $content = 'Wrong table: '.$this->theTable;
00262                         return $content;                // Not listed or editable table!
00263                 }
00264 
00265                 // *****************
00266                 // If data is submitted, we take care of it here.
00267                 // *******************
00268                 if ($this->cmd=='delete' && !$this->preview && !t3lib_div::_GP('doNotSave'))    {       // Delete record if delete command is sent + the preview flag is NOT set.
00269                         $this->deleteRecord();
00270                 }
00271                         // If incoming data is seen...
00272                 if (is_array($this->dataArr))   {
00273                                 // Evaluation of data:
00274                         $this->parseValues();
00275                         $this->overrideValues();
00276                         $this->evalValues();
00277                         if ($this->conf['evalFunc'])    {
00278                                 $this->dataArr = $this->userProcess('evalFunc',$this->dataArr);
00279                         }
00280 
00281                 /*
00282                 debug($this->dataArr);
00283                 debug($this->failure);
00284                 debug($this->preview);
00285                 */
00286                                 // if not preview and no failures, then set data...
00287                         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
00288                                 $this->save();
00289                         } else {
00290                                 if ($this->conf['debug'])               debug($this->failure);
00291                         }
00292                 } else {
00293                         $this->defaultValues(); // If no incoming data, this will set the default values.
00294                         $this->preview = 0;     // No preview if data is not received
00295                 }
00296                 if ($this->failure)     {$this->preview=0;}     // No preview flag if a evaluation failure has occured
00297                 $this->previewLabel = $this->preview ? '_PREVIEW' : ''; // Setting preview label prefix.
00298 
00299 
00300                         // *********************
00301                         // DISPLAY FORMS:
00302                         // ***********************
00303                 if ($this->saved) {
00304                                 // Clear page cache
00305                         $this->clearCacheIfSet();
00306 
00307                                 // Displaying the page here that says, the record has been saved. You're able to include the saved values by markers.
00308                         switch($this->cmd)      {
00309                                 case 'delete':
00310                                         $key='DELETE';
00311                                 break;
00312                                 case 'edit':
00313                                         $key='EDIT';
00314                                 break;
00315                                 default:
00316                                         $key='CREATE';
00317                                 break;
00318                         }
00319                                 // Output message
00320                         $templateCode = $this->cObj->getSubpart($this->templateCode, '###TEMPLATE_'.$key.'_SAVED###');
00321                         $this->setCObjects($templateCode,$this->currentArr);
00322                         $markerArray = $this->cObj->fillInMarkerArray($this->markerArray, $this->currentArr, '', TRUE, 'FIELD_', $this->recInMarkersHSC);
00323                         $content = $this->cObj->substituteMarkerArray($templateCode, $markerArray);
00324 
00325                                 // email message:
00326                         $this->compileMail(
00327                                 $key.'_SAVED',
00328                                 array($this->currentArr),
00329                                 $this->currentArr[$this->conf['email.']['field']],
00330                                 $this->conf['setfixed.']
00331                         );
00332 
00333                 } elseif ($this->error) {       // If there was an error, we return the template-subpart with the error message
00334                         $templateCode = $this->cObj->getSubpart($this->templateCode, $this->error);
00335                         $this->setCObjects($templateCode);
00336                         $content = $this->cObj->substituteMarkerArray($templateCode, $this->markerArray);
00337                 } else {
00338                                 // Finally, if there has been no attempt to save. That is either preview or just displaying and empty or not correctly filled form:
00339                         if (!$this->cmd)        {
00340                                 $this->cmd=$this->conf['defaultCmd'];
00341                         }
00342                         if ($this->conf['debug'])               debug('Display form: '.$this->cmd,1);
00343                         switch($this->cmd)      {
00344                                 case 'setfixed':
00345                                         $content = $this->procesSetFixed();
00346                                 break;
00347                                 case 'infomail':
00348                                         $content = $this->sendInfoMail();
00349                                 break;
00350                                 case 'delete':
00351                                         $content = $this->displayDeleteScreen();
00352                                 break;
00353                                 case 'edit':
00354                                         $content = $this->displayEditScreen();
00355                                 break;
00356                                 case 'create':
00357                                         $content = $this->displayCreateScreen();
00358                                 break;
00359                         }
00360                 }
00361 
00362                         // Delete temp files:
00363                 foreach($this->unlinkTempFiles as $tempFileName)        {
00364                         t3lib_div::unlink_tempfile($tempFileName);
00365                 }
00366 
00367                         // Return content:
00368                 return $content;
00369         }
00370 
00371 
00372 
00373 
00374 
00375 
00376 
00377 
00378 
00379 
00380 
00381 
00382 
00383 
00384 
00385 
00386 
00387 
00388 
00389 
00390 
00391 
00392 
00393         /*****************************************
00394          *
00395          * Data processing
00396          *
00397          *****************************************/
00398 
00408         function parseValues()  {
00409                 if (is_array($this->conf['parseValues.']))      {
00410                         reset($this->conf['parseValues.']);
00411                         while(list($theField,$theValue)=each($this->conf['parseValues.']))      {
00412                                 $listOfCommands = t3lib_div::trimExplode(',',$theValue,1);
00413                                 while(list(,$cmd)=each($listOfCommands))        {
00414                                         $cmdParts = split('\[|\]',$cmd);        // Point is to enable parameters after each command enclosed in brackets [..]. These will be in position 1 in the array.
00415                                         $theCmd=trim($cmdParts[0]);
00416                                         switch($theCmd) {
00417                                                 case 'int':
00418                                                         $this->dataArr[$theField]=intval($this->dataArr[$theField]);
00419                                                 break;
00420                                                 case 'lower':
00421                                                 case 'upper':
00422                                                         $this->dataArr[$theField] = $this->cObj->caseshift($this->dataArr[$theField],$theCmd);
00423                                                 break;
00424                                                 case 'nospace':
00425                                                         $this->dataArr[$theField] = str_replace(' ', '', $this->dataArr[$theField]);
00426                                                 break;
00427                                                 case 'alpha':
00428                                                         $this->dataArr[$theField] = ereg_replace('[^a-zA-Z]','',$this->dataArr[$theField]);
00429                                                 break;
00430                                                 case 'num':
00431                                                         $this->dataArr[$theField] = ereg_replace('[^0-9]','',$this->dataArr[$theField]);
00432                                                 break;
00433                                                 case 'alphanum':
00434                                                         $this->dataArr[$theField] = ereg_replace('[^a-zA-Z0-9]','',$this->dataArr[$theField]);
00435                                                 break;
00436                                                 case 'alphanum_x':
00437                                                         $this->dataArr[$theField] = ereg_replace('[^a-zA-Z0-9_-]','',$this->dataArr[$theField]);
00438                                                 break;
00439                                                 case 'trim':
00440                                                         $this->dataArr[$theField] = trim($this->dataArr[$theField]);
00441                                                 break;
00442                                                 case 'random':
00443                                                         $this->dataArr[$theField] = substr(md5(uniqid(microtime(),1)),0,intval($cmdParts[1]));
00444                                                 break;
00445                                                 case 'files':
00446                                                         if ($this->cmdKey=='create' && !t3lib_div::_GP('doNotSave'))    {
00447                                                                 $this->processFiles($cmdParts,$theField);
00448                                                         } else unset($this->dataArr[$theField]);        // Fields with files cannot be edited - only created.
00449                                                 break;
00450                                                 case 'setEmptyIfAbsent':
00451                                                         if (!isset($this->dataArr[$theField]))  {
00452                                                                 $this->dataArr[$theField]='';
00453                                                         }
00454                                                 break;
00455                                                 case 'multiple':
00456                                                         if (is_array($this->dataArr[$theField]))        {
00457                                                                 $this->dataArr[$theField] = implode(',',$this->dataArr[$theField]);
00458                                                         }
00459                                                 break;
00460                                                 case 'checkArray':
00461                                                         if (is_array($this->dataArr[$theField]))        {
00462                                                                 reset($this->dataArr[$theField]);
00463                                                                 $val = 0;
00464                                                                 while(list($kk,$vv)=each($this->dataArr[$theField]))    {
00465                                                                         $kk = t3lib_div::intInRange($kk,0);
00466                                                                         if ($kk<=30)    {
00467                                                                                 if ($vv)        {
00468                                                                                         $val|=pow(2,$kk);
00469                                                                                 }
00470                                                                         }
00471                                                                 }
00472                                                                 $this->dataArr[$theField] = $val;
00473                                                         } else {$this->dataArr[$theField]=0;}
00474                                                 break;
00475                                                 case 'uniqueHashInt':
00476                                                         $otherFields = t3lib_div::trimExplode(';',$cmdParts[1],1);
00477                                                         $hashArray=array();
00478                                                         while(list(,$fN)=each($otherFields))    {
00479                                                                 $vv = $this->dataArr[$fN];
00480                                                                 $vv = ereg_replace('[[:space:]]','',$vv);
00481                                                                 $vv = ereg_replace('[^[:alnum:]]','',$vv);
00482                                                                 $vv = strtolower($vv);
00483                                                                 $hashArray[]=$vv;
00484                                                         }
00485                                                         $this->dataArr[$theField]=hexdec(substr(md5(serialize($hashArray)),0,8));
00486                                                 break;
00487                                         }
00488                                 }
00489                         }
00490                 }
00491         }
00492 
00503         function processFiles($cmdParts,$theField)      {
00504 //debug($_FILES);
00505                         // First, make an array with the filename and file reference, whether the file is just uploaded or a preview
00506                 $filesArr = array();
00507 
00508                 if (is_string($this->dataArr[$theField]))       {               // files from preview.
00509                         $tmpArr = explode(',',$this->dataArr[$theField]);
00510                         reset($tmpArr);
00511                         while(list(,$val)=each($tmpArr))        {
00512                                 $valParts = explode('|',$val);
00513                                 $filesArr[] = array (
00514                                         'name'=>$valParts[1],
00515                                         'tmp_name'=>PATH_site.'typo3temp/'.$valParts[0]
00516                                 );
00517                         }
00518                 } elseif (is_array($_FILES['FE'][$this->theTable][$theField]['name']))  {       // Files from upload
00519                         reset($_FILES['FE'][$this->theTable][$theField]['name']);
00520                         while(list($kk,$vv)=each($_FILES['FE'][$this->theTable][$theField]['name']))    {
00521                                 if ($vv)        {
00522                                         $tmpFile = t3lib_div::upload_to_tempfile($_FILES['FE'][$this->theTable][$theField]['tmp_name'][$kk]);
00523                                         if ($tmpFile)   {
00524                                                 $this->unlinkTempFiles[]=$tmpFile;
00525                                                 $filesArr[] = array (
00526                                                         'name'=>$vv,
00527                                                         'tmp_name'=>$tmpFile
00528                                                 );
00529                                         }
00530                                 }
00531                         }
00532                 } elseif (is_array($_FILES['FE']['name'][$this->theTable][$theField]))  {       // Files from upload
00533                         reset($_FILES['FE']['name'][$this->theTable][$theField]);
00534                         while(list($kk,$vv)=each($_FILES['FE']['name'][$this->theTable][$theField]))    {
00535                                 if ($vv)        {
00536                                         $tmpFile = t3lib_div::upload_to_tempfile($_FILES['FE']['tmp_name'][$this->theTable][$theField][$kk]);
00537                                         if ($tmpFile)   {
00538                                                 $this->unlinkTempFiles[]=$tmpFile;
00539                                                 $filesArr[] = array (
00540                                                         'name'=>$vv,
00541                                                         'tmp_name'=>$tmpFile
00542                                                 );
00543                                         }
00544                                 }
00545                         }
00546                 }
00547 
00548                         // Then verify the files in that array; check existence, extension and size
00549                 $this->dataArr[$theField]='';
00550                 $finalFilesArr=array();
00551                 if (count($filesArr))   {
00552                         $extArray = t3lib_div::trimExplode(';',strtolower($cmdParts[1]),1);
00553                         $maxSize = intval($cmdParts[3]);
00554                         reset($filesArr);
00555                         while(list(,$infoArr)=each($filesArr))  {
00556                                 $fI = pathinfo($infoArr['name']);
00557                                 if (t3lib_div::verifyFilenameAgainstDenyPattern($fI['name']))   {
00558                                         if (!count($extArray) || in_array(strtolower($fI['extension']), $extArray))     {
00559                                                 $tmpFile = $infoArr['tmp_name'];
00560                                                 if (@is_file($tmpFile)) {
00561                                                         if (!$maxSize || filesize($tmpFile)<$maxSize*1024)      {
00562                                                                 $finalFilesArr[]=$infoArr;
00563                                                         } elseif ($this->conf['debug']) {debug('Size is beyond '.$maxSize.' kb ('.filesize($tmpFile).' bytes) and the file cannot be saved.');}
00564                                                 } elseif ($this->conf['debug']) {debug('Surprisingly there was no file for '.$vv.' in '.$tmpFile);}
00565                                         } elseif ($this->conf['debug']) {debug('Extension "'.$fI['extension'].'" not allowed');}
00566                                 } elseif ($this->conf['debug']) {debug('Filename matched illegal pattern.');}
00567                         }
00568                 }
00569                         // Copy the files in the resulting array to the proper positions based on preview/non-preview.
00570                 reset($finalFilesArr);
00571                 $fileNameList=array();
00572                 while(list(,$infoArr)=each($finalFilesArr))     {
00573                         if ($this->isPreview()) {               // If the form is a preview form (and data is therefore not going into the database...) do this.
00574                                 $this->createFileFuncObj();
00575                                 $fI = pathinfo($infoArr['name']);
00576                                 $tmpFilename = $this->theTable.'_'.t3lib_div::shortmd5(uniqid($infoArr['name'])).'.'.$fI['extension'];
00577                                 $theDestFile = $this->fileFunc->getUniqueName($this->fileFunc->cleanFileName($tmpFilename), PATH_site.'typo3temp/');
00578                                 t3lib_div::upload_copy_move($infoArr['tmp_name'],$theDestFile);
00579                                         // Setting the filename in the list
00580                                 $fI2 = pathinfo($theDestFile);
00581                                 $fileNameList[] = $fI2['basename'].'|'.$infoArr['name'];
00582                         } else {
00583                                 $this->createFileFuncObj();
00584                                 $GLOBALS['TSFE']->includeTCA();
00585                                 t3lib_div::loadTCA($this->theTable);
00586                                 if (is_array($GLOBALS['TCA'][$this->theTable]['columns'][$theField]))   {
00587                                         $uploadPath = $GLOBALS['TCA'][$this->theTable]['columns'][$theField]['config']['uploadfolder'];
00588                                 }
00589                                 if ($uploadPath)        {
00590                                         $theDestFile = $this->fileFunc->getUniqueName($this->fileFunc->cleanFileName($infoArr['name']), PATH_site.$uploadPath);
00591                                         t3lib_div::upload_copy_move($infoArr['tmp_name'],$theDestFile);
00592                                                 // Setting the filename in the list
00593                                         $fI2 = pathinfo($theDestFile);
00594                                         $fileNameList[] = $fI2['basename'];
00595                                         $this->filesStoredInUploadFolders[]=$theDestFile;
00596                                 }
00597                         }
00598                                 // Implode the list of filenames
00599                         $this->dataArr[$theField] = implode(',',$fileNameList);
00600                 }
00601         }
00602 
00609         function overrideValues()       {
00610                 // Addition of overriding values
00611                 if (is_array($this->conf[$this->cmdKey.'.']['overrideValues.']))        {
00612                         reset($this->conf[$this->cmdKey.'.']['overrideValues.']);
00613                         while(list($theField,$theValue)=each($this->conf[$this->cmdKey.'.']['overrideValues.']))        {
00614                                 $this->dataArr[$theField] = $theValue;
00615                         }
00616                 }
00617         }
00618 
00625         function defaultValues()        {
00626                         // Addition of default values
00627                 if (is_array($this->conf[$this->cmdKey.'.']['defaultValues.'])) {
00628                         reset($this->conf[$this->cmdKey.'.']['defaultValues.']);
00629                         while(list($theField,$theValue)=each($this->conf[$this->cmdKey.'.']['defaultValues.'])) {
00630                                 $this->dataArr[$theField] = $theValue;
00631                         }
00632                 }
00633         }
00634 
00644         function evalValues()   {
00645                 // Check required, set failure if not ok.
00646                 reset($this->requiredArr);
00647                 $tempArr=array();
00648                 while(list(,$theField)=each($this->requiredArr))        {
00649                         if (!trim($this->dataArr[$theField]))   {
00650                                 $tempArr[]=$theField;
00651                         }
00652                 }
00653 
00654                 // 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!
00655                 $recExist=0;
00656                 if (is_array($this->conf[$this->cmdKey.'.']['evalValues.']))    {
00657                         switch($this->cmd)      {
00658                                 case 'edit':
00659                                         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.
00660                                                 $recordTestPid = intval($this->dataArr['pid']);
00661                                         } else {
00662                                                 $tempRecArr = $GLOBALS['TSFE']->sys_page->getRawRecord($this->theTable,$this->dataArr['uid']);
00663                                                 $recordTestPid = intval($tempRecArr['pid']);
00664                                         }
00665                                         $recExist=1;
00666                                 break;
00667                                 default:
00668                                         $recordTestPid = $this->thePid ? $this->thePid : t3lib_div::intval_positive($this->dataArr['pid']);
00669                                 break;
00670                         }
00671 
00672                         reset($this->conf[$this->cmdKey.'.']['evalValues.']);
00673                         while(list($theField,$theValue)=each($this->conf[$this->cmdKey.'.']['evalValues.']))    {
00674                                 $listOfCommands = t3lib_div::trimExplode(',',$theValue,1);
00675                                 while(list(,$cmd)=each($listOfCommands))        {
00676                                         $cmdParts = split('\[|\]',$cmd);        // Point is to enable parameters after each command enclosed in brackets [..]. These will be in position 1 in the array.
00677                                         $theCmd = trim($cmdParts[0]);
00678                                         switch($theCmd) {
00679                                                 case 'uniqueGlobal':
00680                                                         if ($DBrows = $GLOBALS['TSFE']->sys_page->getRecordsByField($this->theTable,$theField,$this->dataArr[$theField],'','','','1'))  {
00681                                                                 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.
00682                                                                         $tempArr[]=$theField;
00683                                                                         $this->failureMsg[$theField][] = $this->getFailure($theField, $theCmd, 'The value existed already. Enter a new value.');
00684                                                                 }
00685                                                         }
00686                                                 break;
00687                                                 case 'uniqueLocal':
00688                                                         if ($DBrows = $GLOBALS['TSFE']->sys_page->getRecordsByField($this->theTable,$theField,$this->dataArr[$theField], 'AND pid IN ('.$recordTestPid.')','','','1'))  {
00689                                                                 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.
00690                                                                         $tempArr[]=$theField;
00691                                                                         $this->failureMsg[$theField][] = $this->getFailure($theField, $theCmd, 'The value existed already. Enter a new value.');
00692                                                                 }
00693                                                         }
00694                                                 break;
00695                                                 case 'twice':
00696                                                         if (strcmp($this->dataArr[$theField], $this->dataArr[$theField.'_again']))      {
00697                                                                 $tempArr[]=$theField;
00698                                                                 $this->failureMsg[$theField][] = $this->getFailure($theField, $theCmd, 'You must enter the same value twice');
00699                                                         }
00700                                                 break;
00701                                                 case 'email':
00702                                                         if (!$this->cObj->checkEmail($this->dataArr[$theField]))        {
00703                                                                 $tempArr[]=$theField;
00704                                                                 $this->failureMsg[$theField][] = $this->getFailure($theField, $theCmd, 'You must enter a valid email address');
00705                                                         }
00706                                                 break;
00707                                                 case 'required':
00708                                                         if (!trim($this->dataArr[$theField]))   {
00709                                                                 $tempArr[]=$theField;
00710                                                                 $this->failureMsg[$theField][] = $this->getFailure($theField, $theCmd, 'You must enter a value!');
00711                                                         }
00712                                                 break;
00713                                                 case 'atLeast':
00714                                                         $chars=intval($cmdParts[1]);
00715                                                         if (strlen($this->dataArr[$theField])<$chars)   {
00716                                                                 $tempArr[]=$theField;
00717                                                                 $this->failureMsg[$theField][] = sprintf($this->getFailure($theField, $theCmd, 'You must enter at least %s characters!'), $chars);
00718                                                         }
00719                                                 break;
00720                                                 case 'atMost':
00721                                                         $chars=intval($cmdParts[1]);
00722                                                         if (strlen($this->dataArr[$theField])>$chars)   {
00723                                                                 $tempArr[]=$theField;
00724                                                                 $this->failureMsg[$theField][] = sprintf($this->getFailure($theField, $theCmd, 'You must enter at most %s characters!'), $chars);
00725                                                         }
00726                                                 break;
00727                                                 case 'inBranch':
00728                                                         $pars = explode(';',$cmdParts[1]);
00729                                                         if (intval($pars[0]))   {
00730                                                                 $pid_list = $this->cObj->getTreeList(
00731                                                                         intval($pars[0]),
00732                                                                         intval($pars[1]) ? intval($pars[1]) : 999,
00733                                                                         intval($pars[2])
00734                                                                 );
00735                                                                 if (!$pid_list || !t3lib_div::inList($pid_list,$this->dataArr[$theField]))      {
00736                                                                         $tempArr[]=$theField;
00737                                                                         $this->failureMsg[$theField][] = sprintf($this->getFailure($theField, $theCmd, 'The value was not a valid valud from this list: %s'), $pid_list);
00738                                                                 }
00739                                                         }
00740                                                 break;
00741                                                 case 'unsetEmpty':
00742                                                         if (!$this->dataArr[$theField]) {
00743                                                                 $hash = array_flip($tempArr);
00744                                                                 unset($hash[$theField]);
00745                                                                 $tempArr = array_keys($hash);
00746                                                                 unset($this->failureMsg[$theField]);
00747                                                                 unset($this->dataArr[$theField]);       // This should prevent the field from entering the database.
00748                                                         }
00749                                                 break;
00750                                         }
00751                                 }
00752                                 $this->markerArray['###EVAL_ERROR_FIELD_'.$theField.'###'] = is_array($this->failureMsg[$theField]) ? implode('<br />',$this->failureMsg[$theField]) : '';
00753                         }
00754                 }
00755                 $this->failure=implode(',',$tempArr);    //$failure will show which fields were not OK
00756         }
00757 
00766         function userProcess($mConfKey,$passVar)        {
00767                 if ($this->conf[$mConfKey])     {
00768                         $funcConf = $this->conf[$mConfKey.'.'];
00769                         $funcConf['parentObj']=&$this;
00770                         $passVar = $GLOBALS['TSFE']->cObj->callUserFunction($this->conf[$mConfKey], $funcConf, $passVar);
00771                 }
00772                 return $passVar;
00773         }
00774 
00784         function userProcess_alt($confVal,$confArr,$passVar)    {
00785                 if ($confVal)   {
00786                         $funcConf = $confArr;
00787                         $funcConf['parentObj']=&$this;
00788                         $passVar = $GLOBALS['TSFE']->cObj->callUserFunction($confVal, $funcConf, $passVar);
00789                 }
00790                 return $passVar;
00791         }
00792 
00793 
00794 
00795 
00796 
00797 
00798 
00799 
00800 
00801 
00802 
00803 
00804 
00805 
00806 
00807 
00808 
00809 
00810 
00811 
00812 
00813 
00814         /*****************************************
00815          *
00816          * Database manipulation functions
00817          *
00818          *****************************************/
00819 
00826         function save() {
00827                 switch($this->cmd)      {
00828                         case 'edit':
00829                                 $theUid = $this->dataArr['uid'];
00830                                 $origArr = $GLOBALS['TSFE']->sys_page->getRawRecord($this->theTable,$theUid);           // Fetches the original record to check permissions
00831                                 if ($this->conf['edit'] && ($GLOBALS['TSFE']->loginUser || $this->aCAuth($origArr)))    {       // Must be logged in in order to edit  (OR be validated by email)
00832                                         $newFieldList = implode(',',array_intersect(explode(',',$this->fieldList),t3lib_div::trimExplode(',',$this->conf['edit.']['fields'],1)));
00833                                         if ($this->aCAuth($origArr) || $this->cObj->DBmayFEUserEdit($this->theTable,$origArr,$GLOBALS['TSFE']->fe_user->user,$this->conf['allowedGroups'],$this->conf['fe_userEditSelf']))      {
00834                                                 $this->cObj->DBgetUpdate($this->theTable, $theUid, $this->dataArr, $newFieldList, TRUE);
00835                                                 $this->currentArr = $GLOBALS['TSFE']->sys_page->getRawRecord($this->theTable,$theUid);
00836                                                 $this->userProcess_alt($this->conf['edit.']['userFunc_afterSave'],$this->conf['edit.']['userFunc_afterSave.'],array('rec'=>$this->currentArr, 'origRec'=>$origArr));
00837                                                 $this->saved=1;
00838                                         } else {
00839                                                 $this->error='###TEMPLATE_NO_PERMISSIONS###';
00840                                         }
00841                                 }
00842                         break;
00843                         default:
00844                                 if ($this->conf['create'])      {
00845                                         $newFieldList = implode(',',array_intersect(explode(',',$this->fieldList),t3lib_div::trimExplode(',',$this->conf['create.']['fields'],1)));
00846                                         $this->cObj->DBgetInsert($this->theTable, $this->thePid, $this->dataArr, $newFieldList, TRUE);
00847                                         $newId = $GLOBALS['TYPO3_DB']->sql_insert_id();
00848 
00849                                         if ($this->theTable=='fe_users' && $this->conf['fe_userOwnSelf'])       {               // enables users, creating logins, to own them self.
00850                                                 $extraList='';
00851                                                 $dataArr = array();
00852                                                 if ($GLOBALS['TCA'][$this->theTable]['ctrl']['fe_cruser_id'])           {
00853                                                         $field=$GLOBALS['TCA'][$this->theTable]['ctrl']['fe_cruser_id'];
00854                                                         $dataArr[$field]=$newId;
00855                                                         $extraList.=','.$field;
00856                                                 }
00857                                                 if ($GLOBALS['TCA'][$this->theTable]['ctrl']['fe_crgroup_id'])  {
00858                                                         $field=$GLOBALS['TCA'][$this->theTable]['ctrl']['fe_crgroup_id'];
00859                                                         list($dataArr[$field])=explode(',',$this->dataArr['usergroup']);
00860                                                         $dataArr[$field]=intval($dataArr[$field]);
00861                                                         $extraList.=','.$field;
00862                                                 }
00863                                                 if (count($dataArr))    {
00864                                                         $this->cObj->DBgetUpdate($this->theTable, $newId, $dataArr, $extraList, TRUE);
00865                                                 }
00866                                         }
00867 
00868                                         $this->currentArr = $GLOBALS['TSFE']->sys_page->getRawRecord($this->theTable,$newId);
00869                                         $this->userProcess_alt($this->conf['create.']['userFunc_afterSave'],$this->conf['create.']['userFunc_afterSave.'],array('rec'=>$this->currentArr));
00870                                         $this->saved=1;
00871                                 }
00872                         break;
00873                 }
00874         }
00875 
00884         function deleteRecord() {
00885                 if ($this->conf['delete'])      {       // If deleting is enabled
00886                         $origArr = $GLOBALS['TSFE']->sys_page->getRawRecord($this->theTable,  $this->recUid);
00887                         if ($GLOBALS['TSFE']->loginUser || $this->aCAuth($origArr))     {       // Must be logged in OR be authenticated by the aC code in order to delete
00888                                         // If the recUid selects a record.... (no check here)
00889                                 if (is_array($origArr)) {
00890                                         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.
00891                                                 if (!$GLOBALS['TCA'][$this->theTable]['ctrl']['delete'])        {       // If the record is fully deleted... then remove the image (or any file) attached.
00892                                                         $this->deleteFilesFromRecord($this->recUid);
00893                                                 }
00894                                                 $this->cObj->DBgetDelete($this->theTable, $this->recUid, TRUE);
00895                                                 $this->currentArr = $origArr;
00896                                                 $this->saved = 1;
00897                                         } else {
00898                                                 $this->error = '###TEMPLATE_NO_PERMISSIONS###';
00899                                         }
00900                                 }
00901                         }
00902                 }
00903         }
00904 
00914         function deleteFilesFromRecord($uid)    {
00915                 $table = $this->theTable;
00916                 $rec = $GLOBALS['TSFE']->sys_page->getRawRecord($table,$uid);
00917 
00918                 $GLOBALS['TSFE']->includeTCA();
00919                 t3lib_div::loadTCA($table);
00920                 reset($GLOBALS['TCA'][$table]['columns']);
00921                 $iFields=array();
00922                 while(list($field,$conf)=each($GLOBALS['TCA'][$table]['columns']))      {
00923                         if ($conf['config']['type']=='group' && $conf['config']['internal_type']=='file')       {
00924 
00925                                 $GLOBALS['TYPO3_DB']->exec_UPDATEquery($table, 'uid='.intval($uid), array($field => ''));
00926 
00927                                 $delFileArr = explode(',',$rec[$field]);
00928                                 reset($delFileArr);
00929                                 while(list(,$n)=each($delFileArr))      {
00930                                         if ($n) {
00931                                                 $fpath = $conf['config']['uploadfolder'].'/'.$n;
00932                                                 unlink($fpath);
00933                                         }
00934                                 }
00935                         }
00936                 }
00937         }
00938 
00939 
00940 
00941 
00942 
00943 
00944 
00945 
00946 
00947 
00948 
00949 
00950 
00951 
00952 
00953 
00954 
00955 
00956 
00957 
00958 
00959         /*****************************************
00960          *
00961          * Command "display" functions
00962          *
00963          *****************************************/
00964 
00971         function displayDeleteScreen()  {
00972                 if ($this->conf['delete'])      {       // If deleting is enabled
00973                         $origArr = $GLOBALS['TSFE']->sys_page->getRawRecord($this->theTable,  $this->recUid);
00974                         if ($GLOBALS['TSFE']->loginUser || $this->aCAuth($origArr))     {       // Must be logged in OR be authenticated by the aC code in order to delete
00975                                         // If the recUid selects a record.... (no check here)
00976                                 if (is_array($origArr)) {
00977                                         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.
00978                                                 $this->markerArray['###HIDDENFIELDS###'].= '<input type="hidden" name="rU" value="'.$this->recUid.'" />';
00979                                                 $content = $this->getPlainTemplate('###TEMPLATE_DELETE_PREVIEW###', $origArr);
00980                                         } else {        // Else display error, that you could not edit that particular record...
00981                                                 $content = $this->getPlainTemplate('###TEMPLATE_NO_PERMISSIONS###');
00982                                         }
00983                                 }
00984                         } 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.
00985                                 $content = $this->getPlainTemplate('###TEMPLATE_AUTH###');
00986                         }
00987                 } else {
00988                         $content.='Delete-option is not set in TypoScript';
00989                 }
00990                 return $content;
00991         }
00992 
00999         function displayCreateScreen()  {
01000                 if ($this->conf['create'])      {
01001                         $templateCode = $this->cObj->getSubpart($this->templateCode, ((!$GLOBALS['TSFE']->loginUser||$this->conf['create.']['noSpecialLoginForm'])?'###TEMPLATE_CREATE'.$this->previewLabel.'###':'###TEMPLATE_CREATE_LOGIN'.$this->previewLabel.'###'));
01002                         $failure = t3lib_div::_GP('noWarnings')?'':$this->failure;
01003                         if (!$failure)  $templateCode = $this->cObj->substituteSubpart($templateCode, '###SUB_REQUIRED_FIELDS_WARNING###', '');
01004 
01005                         $templateCode = $this->removeRequired($templateCode,$failure);
01006                         $this->setCObjects($templateCode);
01007 
01008                         $markerArray = $this->cObj->fillInMarkerArray($this->markerArray, $this->dataArr, '', TRUE, 'FIELD_', $this->recInMarkersHSC);
01009                         if ($this->conf['create.']['preview'] && !$this->previewLabel)  {$markerArray['###HIDDENFIELDS###'].= '<input type="hidden" name="preview" value="1" />';}
01010                         $content = $this->cObj->substituteMarkerArray($templateCode, $markerArray);
01011                         $content.=$this->cObj->getUpdateJS($this->modifyDataArrForFormUpdate($this->dataArr), $this->theTable.'_form', 'FE['.$this->theTable.']', $this->fieldList.$this->additionalUpdateFields);
01012                 }
01013                 return $content;
01014         }
01015 
01022         function displayEditScreen()    {
01023                 if ($this->conf['edit'])        {       // If editing is enabled
01024                         $origArr = $GLOBALS['TSFE']->sys_page->getRawRecord($this->theTable,  $this->dataArr['uid']?$this->dataArr['uid']:$this->recUid);
01025 
01026                         if ($GLOBALS['TSFE']->loginUser || $this->aCAuth($origArr))     {       // Must be logged in OR be authenticated by the aC code in order to edit
01027                                         // If the recUid selects a record.... (no check here)
01028                                 if (is_array($origArr)) {
01029                                         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.
01030                                                 $content=$this->displayEditForm($origArr);
01031                                         } else {        // Else display error, that you could not edit that particular record...
01032                                                 $content = $this->getPlainTemplate('###TEMPLATE_NO_PERMISSIONS###');
01033                                         }
01034                                 } elseif ($GLOBALS['TSFE']->loginUser) {        // If the recUid did not select a record, we display a menu of records. (eg. if no recUid)
01035                                         $lockPid = $this->conf['edit.']['menuLockPid'] ? ' AND pid='.intval($this->thePid) : '';
01036 
01037                                         $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));
01038 
01039                                         if ($GLOBALS['TYPO3_DB']->sql_num_rows($res))   {       // If there are menu-items ...
01040                                                 $templateCode = $this->getPlainTemplate('###TEMPLATE_EDITMENU###');
01041                                                 $out='';
01042                                                 $itemCode = $this->cObj->getSubpart($templateCode, '###ITEM###');
01043                                                 while($menuRow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))   {
01044                                                         $markerArray = $this->cObj->fillInMarkerArray(array(), $menuRow, '', TRUE, 'FIELD_', $this->recInMarkersHSC);
01045                                                         $markerArray = $this->setCObjects($itemCode,$menuRow,$markerArray,'ITEM_');
01046                                                         $out.= $this->cObj->substituteMarkerArray($itemCode, $markerArray);
01047                                                 }
01048                                                 $content=$this->cObj->substituteSubpart($templateCode, '###ALLITEMS###', $out);
01049                                         } else {        // If there are not menu items....
01050                                                 $content = $this->getPlainTemplate('###TEMPLATE_EDITMENU_NOITEMS###');
01051                                         }
01052                                 } else {
01053                                         $content = $this->getPlainTemplate('###TEMPLATE_AUTH###');
01054                                 }
01055                         } 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.
01056                                 $content = $this->getPlainTemplate('###TEMPLATE_AUTH###');
01057                         }
01058                 } else {
01059                         $content.='Edit-option is not set in TypoScript';
01060                 }
01061                 return $content;
01062         }
01063 
01073         function displayEditForm($origArr)      {
01074                 $currentArr = is_array($this->dataArr) ? $this->dataArr+$origArr : $origArr;
01075 
01076                 if ($this->conf['debug'])       debug('displayEditForm(): '.'###TEMPLATE_EDIT'.$this->previewLabel.'###',1);
01077                 $templateCode = $this->cObj->getSubpart($this->templateCode, '###TEMPLATE_EDIT'.$this->previewLabel.'###');
01078                 $failure = t3lib_div::_GP('noWarnings')?'':$this->failure;
01079                 if (!$failure)  {$templateCode = $this->cObj->substituteSubpart($templateCode, '###SUB_REQUIRED_FIELDS_WARNING###', '');}
01080 
01081                 $templateCode = $this->removeRequired($templateCode,$failure);
01082 
01083                 $this->setCObjects($templateCode,$currentArr);
01084 
01085                 $markerArray = $this->cObj->fillInMarkerArray($this->markerArray, $currentArr, '', TRUE, 'FIELD_', $this->recInMarkersHSC);
01086 
01087                 $markerArray['###HIDDENFIELDS###'].= '<input type="hidden" name="FE['.$this->theTable.'][uid]" value="'.$currentArr['uid'].'" />';
01088                 if ($this->conf['edit.']['preview'] && !$this->previewLabel)    {$markerArray['###HIDDENFIELDS###'].= '<input type="hidden" name="preview" value="1" />';}
01089                 $content = $this->cObj->substituteMarkerArray($templateCode, $markerArray);
01090                 $content.=$this->cObj->getUpdateJS($this->modifyDataArrForFormUpdate($currentArr), $this->theTable.'_form',  'FE['.$this->theTable.']', $this->fieldList.$this->additionalUpdateFields);
01091 
01092                 return $content;
01093         }
01094 
01101         function procesSetFixed()       {
01102                 if ($this->conf['setfixed'])    {
01103                         $theUid = intval($this->recUid);
01104                         $origArr = $GLOBALS['TSFE']->sys_page->getRawRecord($this->theTable,  $theUid);
01105                         $fD = t3lib_div::_GP('fD');
01106                         $sFK = t3lib_div::_GP('sFK');
01107 
01108                         $fieldArr=array();
01109                         if (is_array($fD) || $sFK=='DELETE')    {
01110                                 if (is_array($fD))      {
01111                                         reset($fD);
01112                                         while(list($field,$value)=each($fD))    {
01113                                                 $origArr[$field]=$value;
01114                                                 $fieldArr[]=$field;
01115                                         }
01116                                 }
01117                                 $theCode = $this->setfixedHash($origArr,$origArr['_FIELDLIST']);
01118                                 if (!strcmp($this->authCode,$theCode))  {
01119                                         if ($sFK=='DELETE')     {
01120                                                 $this->cObj->DBgetDelete($this->theTable, $theUid, TRUE);
01121                                         } else {
01122                                                 $newFieldList = implode(',',array_intersect(t3lib_div::trimExplode(',',$this->fieldList),t3lib_div::trimExplode(',',implode($fieldArr,','),1)));
01123                                                 $this->cObj->DBgetUpdate($this->theTable, $theUid, $fD, $newFieldList, TRUE);
01124                                         }
01125 
01126                                                 // Outputting template
01127                                         $this->markerArray = $this->cObj->fillInMarkerArray($this->markerArray, $origArr, '', TRUE, 'FIELD_', $this->recInMarkersHSC);
01128                                         $content = $this->getPlainTemplate('###TEMPLATE_SETFIXED_OK_'.$sFK.'###');
01129                                         if (!$content)  {$content = $this->getPlainTemplate('###TEMPLATE_SETFIXED_OK###');}
01130 
01131                                                 // Compiling email
01132                                         $this->compileMail(
01133                                                 'SETFIXED_'.$sFK,
01134                                                 array($origArr),
01135                                                 $origArr[$this->conf['email.']['field']],
01136                                                 $this->conf['setfixed.']
01137                                         );
01138                                                 // Clearing cache if set:
01139                                         $this->clearCacheIfSet();
01140                                 } else $content = $this->getPlainTemplate('###TEMPLATE_SETFIXED_FAILED###');
01141                         } else $content = $this->getPlainTemplate('###TEMPLATE_SETFIXED_FAILED###');
01142                 }
01143                 return $content;
01144         }
01145 
01146 
01147 
01148 
01149 
01150 
01151 
01152 
01153 
01154 
01155 
01156 
01157 
01158 
01159 
01160 
01161 
01162 
01163 
01164 
01165 
01166 
01167 
01168         /*****************************************
01169          *
01170          * Template processing functions
01171          *
01172          *****************************************/
01173 
01174 
01175 
01188         function removeRequired($templateCode,$failure) {
01189                 reset($this->requiredArr);
01190                 while(list(,$theField)=each($this->requiredArr))        {
01191                         if (!t3lib_div::inList($failure,$theField))     {
01192                                 $templateCode = $this->cObj->substituteSubpart($templateCode, '###SUB_REQUIRED_FIELD_'.$theField.'###', '');
01193                         }
01194                 }
01195                 return $templateCode;
01196         }
01197 
01206         function getPlainTemplate($key,$r='')   {
01207                 if ($this->conf['debug'])       debug('getPlainTemplate(): '.$key,1);
01208                 $templateCode = $this->cObj->getSubpart($this->templateCode, $key);
01209                 $this->setCObjects($templateCode,is_array($r)?$r:array());
01210                 return  $this->cObj->substituteMarkerArray(
01211                                 $templateCode,
01212                                 is_array($r) ? $this->cObj->fillInMarkerArray($this->markerArray, $r, '', TRUE, 'FIELD_', $this->recInMarkersHSC) : $this->markerArray
01213                         );
01214         }
01215 
01223         function modifyDataArrForFormUpdate($inputArr)  {
01224                 if (is_array($this->conf[$this->cmdKey.'.']['evalValues.']))    {
01225                         reset($this->conf[$this->cmdKey.'.']['evalValues.']);
01226                         while(list($theField,$theValue)=each($this->conf[$this->cmdKey.'.']['evalValues.']))    {
01227                                 $listOfCommands = t3lib_div::trimExplode(',',$theValue,1);
01228                                 while(list(,$cmd)=each($listOfCommands))        {
01229                                         $cmdParts = split('\[|\]',$cmd);        // Point is to enable parameters after each command enclosed in brackets [..]. These will be in position 1 in the array.
01230                                         $theCmd = trim($cmdParts[0]);
01231                                         switch($theCmd) {
01232                                                 case 'twice':
01233                                                         if (isset($inputArr[$theField]))        {
01234                                                                 if (!isset($inputArr[$theField.'_again']))      {
01235                                                                         $inputArr[$theField.'_again'] = $inputArr[$theField];
01236                                                                 }
01237                                                                 $this->additionalUpdateFields.=','.$theField.'_again';
01238                                                         }
01239                                                 break;
01240                                         }
01241                                 }
01242                         }
01243                 }
01244                 if (is_array($this->conf['parseValues.']))      {
01245                         reset($this->conf['parseValues.']);
01246                         while(list($theField,$theValue)=each($this->conf['parseValues.']))      {
01247                                 $listOfCommands = t3lib_div::trimExplode(',',$theValue,1);
01248                                 while(list(,$cmd)=each($listOfCommands))        {
01249                                         $cmdParts = split('\[|\]',$cmd);        // Point is to enable parameters after each command enclosed in brackets [..]. These will be in position 1 in the array.
01250                                         $theCmd = trim($cmdParts[0]);
01251                                         switch($theCmd) {
01252                                                 case 'multiple':
01253                                                         if (isset($inputArr[$theField]) && !$this->isPreview()) {
01254                                                                 $inputArr[$theField] = explode(',',$inputArr[$theField]);
01255                                                         }
01256                                                 break;
01257                                                 case 'checkArray':
01258                                                         if ($inputArr[$theField] && !$this->isPreview())        {
01259                                                                 for($a=0;$a<=30;$a++)   {
01260                                                                         if ($inputArr[$theField] & pow(2,$a))   {
01261                                                                                 $alt_theField = $theField.']['.$a;
01262                                                                                 $inputArr[$alt_theField] = 1;
01263                                                                                 $this->additionalUpdateFields.=','.$alt_theField;
01264                                                                         }
01265                                                                 }
01266                                                         }
01267                                                 break;
01268                                         }
01269                                 }
01270                         }
01271                 }
01272 
01273 
01274                 $inputArr = $this->userProcess_alt(
01275                         $this->conf['userFunc_updateArray'],
01276                         $this->conf['userFunc_updateArray.'],
01277                         $inputArr
01278                 );
01279 
01280                 return $inputArr;
01281         }
01282 
01292         function setCObjects($templateCode,$currentArr=array(),$markerArray='',$specialPrefix='')       {
01293                 if (is_array($this->conf['cObjects.'])) {
01294                         reset($this->conf['cObjects.']);
01295 
01296                         while(list($theKey,$theConf)=each($this->conf['cObjects.']))    {
01297                                 if (!strstr($theKey,'.'))       {
01298                                         if (strstr($templateCode,'###'.$specialPrefix.'CE_'.$theKey.'###'))     {
01299                                                 $cObjCode = $this->cObj->cObjGetSingle($this->conf['cObjects.'][$theKey], $this->conf['cObjects.'][$theKey.'.'], 'cObjects.'.$theKey);
01300 
01301                                                 if (!is_array($markerArray))    {
01302                                                         $this->markerArray['###'.$specialPrefix.'CE_'.$theKey.'###'] = $cObjCode;
01303                                                 } else {
01304                                                         $markerArray['###'.$specialPrefix.'CE_'.$theKey.'###'] = $cObjCode;
01305                                                 }
01306                                         }
01307                                         if (strstr($templateCode,'###'.$specialPrefix.'PCE_'.$theKey.'###'))    {
01308                                                 $local_cObj =t3lib_div::makeInstance('tslib_cObj');
01309                                                 $local_cObj->start(count($currentArr)?$currentArr:$this->dataArr,$this->theTable);
01310                                                 $cObjCode = $local_cObj->cObjGetSingle($this->conf['cObjects.'][$theKey], $this->conf['cObjects.'][$theKey.'.'], 'cObjects.'.$theKey);
01311 
01312                                                 if (!is_array($markerArray))    {
01313                                                         $this->markerArray['###'.$specialPrefix.'PCE_'.$theKey.'###'] = $cObjCode;
01314                                                 } else {
01315                                                         $markerArray['###'.$specialPrefix.'PCE_'.$theKey.'###'] = $cObjCode;
01316                                                 }
01317                                         }
01318                                 }
01319                         }
01320                 }
01321                 return $markerArray;
01322         }
01323 
01324 
01325 
01326 
01327 
01328 
01329 
01330 
01331 
01332 
01333 
01334 
01335 
01336 
01337 
01338 
01339 
01340 
01341 
01342         /*****************************************
01343          *
01344          * Emailing
01345          *
01346          *****************************************/
01347 
01354         function sendInfoMail() {
01355                 if ($this->conf['infomail'] && $this->conf['email.']['field'])  {
01356                         $fetch = t3lib_div::_GP('fetch');
01357                         if ($fetch)     {
01358                                         // Getting infomail config.
01359                                 $key= trim(t3lib_div::_GP('key'));
01360                                 if (is_array($this->conf['infomail.'][$key.'.']))               {
01361                                         $config = $this->conf['infomail.'][$key.'.'];
01362                                 } else {
01363                                         $config = $this->conf['infomail.']['default.'];
01364                                 }
01365                                 $pidLock='';
01366                                 if (!$config['dontLockPid'])    {
01367                                         $pidLock='AND pid IN ('.$this->thePid.') ';
01368                                 }
01369 
01370                                         // Getting records
01371                                 if (t3lib_div::testInt($fetch)) {
01372                                         $DBrows = $GLOBALS['TSFE']->sys_page->getRecordsByField($this->theTable,'uid',$fetch,$pidLock,'','','1');
01373                                 } elseif ($fetch) {     // $this->conf['email.']['field'] must be a valid field in the table!
01374                                         $DBrows = $GLOBALS['TSFE']->sys_page->getRecordsByField($this->theTable,$this->conf['email.']['field'],$fetch,$pidLock,'','','100');
01375                                 }
01376 
01377                                         // Processing records
01378                                 if (is_array($DBrows))  {
01379                                         $recipient = $DBrows[0][$this->conf['email.']['field']];
01380                                         $this->compileMail($config['label'], $DBrows, $recipient, $this->conf['setfixed.']);
01381                                 } elseif ($this->cObj->checkEmail($fetch)) {
01382                                         $this->sendMail($fetch, '', trim($this->cObj->getSubpart($this->templateCode, '###'.$this->emailMarkPrefix.'NORECORD###')));
01383                                 }
01384 
01385                                 $content = $this->getPlainTemplate('###TEMPLATE_INFOMAIL_SENT###');
01386                         } else {
01387                                 $content = $this->getPlainTemplate('###TEMPLATE_INFOMAIL###');
01388                         }
01389                 } else $content='Error: infomail option is not available or emailField is not setup in TypoScript';
01390                 return $content;
01391         }
01392 
01402         function compileMail($key, $DBrows, $recipient, $setFixedConfig=array())        {
01403                 $GLOBALS['TT']->push('compileMail');
01404                 $mailContent='';
01405                 $key = $this->emailMarkPrefix.$key;
01406 
01407                 $userContent['all'] = trim($this->cObj->getSubpart($this->templateCode, '###'.$key.'###'));
01408                 $adminContent['all'] = trim($this->cObj->getSubpart($this->templateCode, '###'.$key.'-ADMIN###'));
01409                 $userContent['rec'] = $this->cObj->getSubpart($userContent['all'], '###SUB_RECORD###');
01410                 $adminContent['rec'] = $this->cObj->getSubpart($adminContent['all'], '###SUB_RECORD###');
01411 
01412                 reset($DBrows);
01413                 while(list(,$r)=each($DBrows))  {
01414                         $markerArray = $this->cObj->fillInMarkerArray($this->markerArray, $r,'',0);
01415                         $markerArray = $this->setCObjects($userContent['rec'].$adminContent['rec'],$r,$markerArray,'ITEM_');
01416                         $markerArray['###SYS_AUTHCODE###'] = $this->authCode($r);
01417                         $markerArray = $this->setfixed($markerArray, $setFixedConfig, $r);
01418 
01419                         if ($userContent['rec'])        $userContent['accum'] .=$this->cObj->substituteMarkerArray($userContent['rec'], $markerArray);
01420                         if ($adminContent['rec'])       $adminContent['accum'].=$this->cObj->substituteMarkerArray($adminContent['rec'], $markerArray);
01421                 }
01422 
01423                 if ($userContent['all'])        $userContent['final'] .=$this->cObj->substituteSubpart($userContent['all'], '###SUB_RECORD###', $userContent['accum']);
01424                 if ($adminContent['all'])       $adminContent['final'].=$this->cObj->substituteSubpart($adminContent['all'], '###SUB_RECORD###', $adminContent['accum']);
01425 
01426                 if (t3lib_div::testInt($recipient))     {
01427                         $fe_userRec = $GLOBALS['TSFE']->sys_page->getRawRecord('fe_users',$recipient);
01428                         $recipient=$fe_userRec['email'];
01429                 }
01430 
01431                 $GLOBALS['TT']->setTSlogMessage('Template key: ###'.$key.'###, userContentLength: '.strlen($userContent['final']).', adminContentLength: '.strlen($adminContent['final']));
01432 
01433                 $this->sendMail($recipient, $this->conf['email.']['admin'], $userContent['final'], $adminContent['final']);
01434                 $GLOBALS['TT']->pull();
01435         }
01436 
01448         function sendMail($recipient, $admin, $content='', $adminContent='')    {
01449                         // Admin mail:
01450                 if ($admin && $adminContent)    {
01451                         if (!$this->isHTMLContent($adminContent))       {
01452                                 $admMail = $this->cObj->sendNotifyEmail($adminContent,
01453                                                                         $admin,
01454                                                                         '',
01455                                                                         $this->conf['email.']['from'],
01456                                                                         $this->conf['email.']['fromName'],
01457                                                                         $recipient
01458                                                         );
01459                         } else {
01460                                 $this->sendHTMLMail($adminContent,
01461                                                                         $admin,
01462                                                                         '',
01463                                                                         $this->conf['email.']['from'],
01464                                                                         $this->conf['email.']['fromName'],
01465                                                                         $recipient
01466                                                         );
01467                         }
01468                 }
01469                         // user mail:
01470                 if (!$this->isHTMLContent($content))    {
01471                         $this->cObj->sendNotifyEmail($content,
01472                                                                 $recipient,
01473                                                                 '',                     // ($admMail ? '' : $admin),            // If the special administration mail was not found and send, the regular is...
01474                                                                 $this->conf['email.']['from'],
01475                                                                 $this->conf['email.']['fromName']
01476                                                 );
01477                 } else {
01478                         $this->sendHTMLMail($content,
01479                                                                 $recipient,
01480                                                                 '',                     // ($admMail ? '' : $admin),            // If the special administration mail was not found and send, the regular is...
01481                                                                 $this->conf['email.']['from'],
01482                                                                 $this->conf['email.']['fromName']
01483                                                 );
01484                 }
01485         }
01486 
01493         function isHTMLContent($c)      {
01494                 $c = trim($c);
01495                 $first = strtolower(substr($c,0,6));
01496                 $last = strtolower(substr($c,-7));
01497                 if ($first.$last=='<html></html>')      return 1;
01498         }
01499 
01514         function sendHTMLMail($content,$recipient,$dummy,$fromEmail,$fromName,$replyTo='')      {
01515                 if (trim($recipient) && trim($content)) {
01516                         $cls=t3lib_div::makeInstanceClassName('t3lib_htmlmail');
01517                         if (class_exists($cls)) {       // If htmlmail lib is included, then generate a nice HTML-email
01518                                 $parts = spliti('<title>|</title>',$content,3);
01519                                 $subject = trim($parts[1]) ? trim($parts[1]) : 'TYPO3 FE Admin message';
01520 
01521                                 $Typo3_htmlmail = t3lib_div::makeInstance('t3lib_htmlmail');
01522                                 $Typo3_htmlmail->start();
01523                                 $Typo3_htmlmail->useBase64();
01524 
01525                                 $Typo3_htmlmail->subject = $subject;
01526                                 $Typo3_htmlmail->from_email = $fromEmail;
01527                                 $Typo3_htmlmail->from_name = $fromName;
01528                                 $Typo3_htmlmail->replyto_email = $replyTo ? $replyTo : $fromEmail;
01529                                 $Typo3_htmlmail->replyto_name = $replyTo ? '' : $fromName;
01530                                 $Typo3_htmlmail->organisation = '';
01531                                 $Typo3_htmlmail->priority = 3;
01532 
01533                                         // HTML
01534                                 $Typo3_htmlmail->theParts['html']['content'] = $content;        // Fetches the content of the page
01535                                 $Typo3_htmlmail->theParts['html']['path'] = '';
01536                                 $Typo3_htmlmail->extractMediaLinks();
01537                                 $Typo3_htmlmail->extractHyperLinks();
01538                                 $Typo3_htmlmail->fetchHTMLMedia();
01539                                 $Typo3_htmlmail->substMediaNamesInHTML(0);      // 0 = relative
01540                                 $Typo3_htmlmail->substHREFsInHTML();
01541                                 $Typo3_htmlmail->setHTML($Typo3_htmlmail->encodeMsg($Typo3_htmlmail->theParts['html']['content']));
01542 
01543                                         // PLAIN
01544                                 $Typo3_htmlmail->addPlain('');
01545 
01546                                         // SET Headers and Content
01547                                 $Typo3_htmlmail->setHeaders();
01548                                 $Typo3_htmlmail->setContent();
01549                                 $Typo3_htmlmail->setRecipient($recipient);
01550 
01551                 //              debug($Typo3_htmlmail->theParts);
01552                                 $Typo3_htmlmail->sendtheMail();
01553                         } else {
01554                                 debug('SYSTEM ERROR: No HTML-mail library loaded. Set "page.config.incT3Lib_htmlmail = 1" is your TypoScript template.');
01555                         }
01556                 }
01557         }
01558 
01559 
01560 
01561 
01562 
01563 
01564 
01565 
01566 
01567 
01568 
01569 
01570 
01571 
01572 
01573 
01574 
01575 
01576 
01577 
01578 
01579 
01580 
01581 
01582         /*****************************************
01583          *
01584          * Various helper functions
01585          *
01586          *****************************************/
01587 
01588 
01598         function aCAuth($r)     {
01599                 if ($this->authCode && !strcmp($this->authCode,$this->authCode($r)))    {
01600                         return true;
01601                 }
01602         }
01603 
01612         function authCode($r,$extra='') {
01613                 $l=$this->codeLength;
01614                 if ($this->conf['authcodeFields'])      {
01615                         $fieldArr = t3lib_div::trimExplode(',', $this->conf['authcodeFields'], 1);
01616                         $value='';
01617                         while(list(,$field)=each($fieldArr))    {
01618                                 $value.=$r[$field].'|';
01619                         }
01620                         $value.=$extra.'|'.$this->conf['authcodeFields.']['addKey'];
01621                         if ($this->conf['authcodeFields.']['addDate'])  {
01622                                 $value.='|'.date($this->conf['authcodeFields.']['addDate']);
01623                         }
01624                         $value.=$GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'];
01625                         return substr(md5($value), 0,$l);
01626                 }
01627         }
01628 
01638         function setfixed($markerArray, $setfixed, $r)  {
01639                 if (is_array($setfixed))        {
01640                         reset($setfixed);
01641                         while(list($theKey,$data)=each($setfixed))      {
01642                                 if (!strcmp($theKey,'DELETE'))  {
01643                                         $recCopy = $r;
01644                                         $string='&cmd=setfixed&sFK='.rawurlencode($theKey).'&rU='.$r['uid'];
01645                                         $string.='&aC='.$this->setfixedHash($recCopy,$data['_FIELDLIST']);
01646                                         $markerArray['###SYS_SETFIXED_DELETE###'] = $string;
01647                                         $markerArray['###SYS_SETFIXED_HSC_DELETE###'] = htmlspecialchars($string);
01648                                 } elseif (strstr($theKey,'.'))  {
01649                                         $theKey = substr($theKey,0,-1);
01650                                         if (is_array($data))    {
01651                                                 reset($data);
01652                                                 $recCopy = $r;
01653                                                 $string='&cmd=setfixed&sFK='.rawurlencode($theKey).'&rU='.$r['uid'];
01654                                                 while(list($fieldName,$fieldValue)=each($data)) {
01655                                                         $string.='&fD['.$fieldName.']='.rawurlencode($fieldValue);
01656                                                         $recCopy[$fieldName]=$fieldValue;
01657                                                 }
01658                                                 $string.='&aC='.$this->setfixedHash($recCopy,$data['_FIELDLIST']);
01659                                                 $markerArray['###SYS_SETFIXED_'.$theKey.'###'] = $string;
01660                                                 $markerArray['###SYS_SETFIXED_HSC_'.$theKey.'###'] = htmlspecialchars($string);
01661                                         }
01662                                 }
01663                         }
01664                 }
01665                 return $markerArray;
01666         }
01667 
01676         function setfixedHash($recCopy,$fields='')      {
01677                 if ($fields)    {
01678                         $fieldArr = t3lib_div::trimExplode(',',$fields,1);
01679                         reset($fieldArr);
01680                         while(list($k,$v)=each($fieldArr))      {
01681                                 $recCopy_temp[$k]=$recCopy[$v];
01682                         }
01683                 } else {
01684                         $recCopy_temp=$recCopy;
01685                 }
01686                 $encStr = implode('|',$recCopy_temp).'|'.$this->conf['authcodeFields.']['addKey'].'|'.$GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'];
01687                 $hash = substr(md5($encStr),0,$this->codeLength);
01688                 return $hash;
01689         }
01690 
01691 
01697         function isPreview()    {
01698                 return ($this->conf[$this->cmdKey.'.']['preview'] && $this->preview);
01699         }
01700 
01706         function createFileFuncObj()    {
01707                 if (!$this->fileFunc)   {
01708                         $this->fileFunc = t3lib_div::makeInstance('t3lib_basicFileFunctions');
01709                 }
01710         }
01711 
01717         function clearCacheIfSet()      {
01718                 if ($this->conf['clearCacheOfPages'])   {
01719                         $cc_pidList = $GLOBALS['TYPO3_DB']->cleanIntList($this->conf['clearCacheOfPages']);
01720                         $GLOBALS['TSFE']->clearPageCacheContent_pidList($cc_pidList);
01721                 }
01722         }
01723 
01732         function getFailure($theField, $theCmd, $label) {
01733                 return isset($this->conf['evalErrors.'][$theField.'.'][$theCmd]) ? $this->conf['evalErrors.'][$theField.'.'][$theCmd] : $label;
01734         }
01735 }
01736 
01737 
01738 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['media/scripts/fe_adminLib.inc'])   {
01739         include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['media/scripts/fe_adminLib.inc']);
01740 }
01741 ?>


Généré par Le spécialiste TYPO3 avec  doxygen 1.4.6