Documentation TYPO3 par Ameos

fe_adminLib.inc

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                 if (strstr($this->backURL, '"') || strstr($this->backURL, "'") || preg_match('/(javascript|vbscript):/i', $this->backURL)  || stristr($this->backURL, "fromcharcode") || strstr($this->backURL, "<") || strstr($this->backURL, ">"))    {
00192                         $this->backURL = '';    // Clear backURL if it seems to contain XSS code - only URLs are allowed
00193                 }
00194                         // Remove host from URL: Make sure that $this->backURL maps to the current site
00195                 $this->backURL = preg_replace('|[A-Za-z]+://[^/]+|', '', $this->backURL);
00196                         // Uid to edit:
00197                 $this->recUid = t3lib_div::_GP('rU');
00198                         // Authentication code:
00199                 $this->authCode = t3lib_div::_GP('aC');
00200                         // get table
00201                 $this->theTable = $this->conf['table'];
00202                         // link configuration
00203                 $linkConf = is_array($this->conf['formurl.']) ? $this->conf['formurl.'] : array();
00204                         // pid
00205                 $this->thePid = intval($this->conf['pid']) ? intval($this->conf['pid']) : $GLOBALS['TSFE']->id;
00206                         //
00207                 $this->codeLength = intval($this->conf['authcodeFields.']['codeLength']) ? intval($this->conf['authcodeFields.']['codeLength']) : 8;
00208 
00209                         // Setting the hardcoded lists of fields allowed for editing and creation.
00210                 $this->fieldList=implode(',',t3lib_div::trimExplode(',',$GLOBALS['TCA'][$this->theTable]['feInterface']['fe_admin_fieldList'],1));
00211 
00212                         // globally substituted markers, fonts and colors.
00213                 $splitMark = md5(microtime());
00214                 list($this->markerArray['###GW1B###'],$this->markerArray['###GW1E###']) = explode($splitMark,$this->cObj->stdWrap($splitMark,$this->conf['wrap1.']));
00215                 list($this->markerArray['###GW2B###'],$this->markerArray['###GW2E###']) = explode($splitMark,$this->cObj->stdWrap($splitMark,$this->conf['wrap2.']));
00216                 $this->markerArray['###GC1###'] = $this->cObj->stdWrap($this->conf['color1'],$this->conf['color1.']);
00217                 $this->markerArray['###GC2###'] = $this->cObj->stdWrap($this->conf['color2'],$this->conf['color2.']);
00218                 $this->markerArray['###GC3###'] = $this->cObj->stdWrap($this->conf['color3'],$this->conf['color3.']);
00219 
00220                 if (intval($this->conf['no_cache']) && !isset($linkConf['no_cache']))   {       // needed for backwards compatibility
00221                         $linkConf['no_cache'] = 1;
00222                 }
00223                 if(!$linkConf['parameter'])     {
00224                         $linkConf['parameter'] = $GLOBALS['TSFE']->id;
00225                 }
00226                 if(!$linkConf['additionalParams'])      {       // needed for backwards compatibility
00227                         $linkConf['additionalParams'] = $this->conf['addParams'];
00228                 }
00229 
00230                 $formURL = $this->cObj->typoLink_URL($linkConf);
00231                 if(!strstr($formURL,'?')) {
00232                         $formURL .= '?';
00233                 }
00234 
00235                         // Initialize markerArray, setting FORM_URL and HIDDENFIELDS
00236                 $this->markerArray['###FORM_URL###'] = $formURL;
00237                 $this->markerArray['###FORM_URL_ENC###'] = rawurlencode($this->markerArray['###FORM_URL###']);
00238                 $this->markerArray['###FORM_URL_HSC###'] = htmlspecialchars($this->markerArray['###FORM_URL###']);
00239 
00240                 $this->markerArray['###BACK_URL###'] = $this->backURL;
00241                 $this->markerArray['###BACK_URL_ENC###'] = rawurlencode($this->markerArray['###BACK_URL###']);
00242                 $this->markerArray['###BACK_URL_HSC###'] = htmlspecialchars($this->markerArray['###BACK_URL###']);
00243 
00244                 $this->markerArray['###THE_PID###'] = $this->thePid;
00245                 $this->markerArray['###REC_UID###'] = $this->recUid;
00246                 $this->markerArray['###AUTH_CODE###'] = $this->authCode;
00247                 $this->markerArray['###THIS_ID###'] = $GLOBALS['TSFE']->id;
00248                 $this->markerArray['###THIS_URL###'] = htmlspecialchars(t3lib_div::getIndpEnv('TYPO3_REQUEST_DIR'));
00249                 $this->markerArray['###HIDDENFIELDS###'] =
00250                         ($this->cmd?'<input type="hidden" name="cmd" value="'.htmlspecialchars($this->cmd).'" />':'').
00251                         ($this->authCode?'<input type="hidden" name="aC" value="'.htmlspecialchars($this->authCode).'" />':'').
00252                         ($this->backURL?'<input type="hidden" name="backURL" value="'.htmlspecialchars($this->backURL).'" />':'');
00253 
00254 
00255                         // Setting cmdKey which is either 'edit' or 'create'
00256                 switch($this->cmd)      {
00257                         case 'edit':
00258                                 $this->cmdKey='edit';
00259                         break;
00260                         default:
00261                                 $this->cmdKey='create';
00262                         break;
00263                 }
00264                         // Setting requiredArr to the fields in 'required' intersected field the total field list in order to remove invalid fields.
00265                 $this->requiredArr = array_intersect(
00266                         t3lib_div::trimExplode(',',$this->conf[$this->cmdKey.'.']['required'],1),
00267                         t3lib_div::trimExplode(',',$this->conf[$this->cmdKey.'.']['fields'],1)
00268                 );
00269 
00270                         // Setting incoming data. Non-stripped
00271                 $fe=t3lib_div::_GP('FE');
00272                 $this->dataArr = $fe[$this->theTable];  // Incoming data.
00273 
00274                         // Checking template file and table value
00275                 if (!$this->templateCode)       {
00276                         $content = 'No template file found: '.$this->conf['templateFile'];
00277                         return $content;
00278                 }
00279 
00280                 if (!$this->theTable || !$this->fieldList)      {
00281                         $content = 'Wrong table: '.$this->theTable;
00282                         return $content;                // Not listed or editable table!
00283                 }
00284 
00285                 // *****************
00286                 // If data is submitted, we take care of it here.
00287                 // *******************
00288                 if ($this->cmd=='delete' && !$this->preview && !t3lib_div::_GP('doNotSave'))    {       // Delete record if delete command is sent + the preview flag is NOT set.
00289                         $this->deleteRecord();
00290                 }
00291                         // If incoming data is seen...
00292                 if (is_array($this->dataArr))   {
00293                                 // Evaluation of data:
00294                         $this->parseValues();
00295                         $this->overrideValues();
00296                         $this->evalValues();
00297                         if ($this->conf['evalFunc'])    {
00298                                 $this->dataArr = $this->userProcess('evalFunc',$this->dataArr);
00299                         }
00300 
00301                 /*
00302                 debug($this->dataArr);
00303                 debug($this->failure);
00304                 debug($this->preview);
00305                 */
00306                                 // if not preview and no failures, then set data...
00307                         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
00308                                 $this->save();
00309                         } else {
00310                                 if ($this->conf['debug'])               debug($this->failure);
00311                         }
00312                 } else {
00313                         $this->defaultValues(); // If no incoming data, this will set the default values.
00314                         $this->preview = 0;     // No preview if data is not received
00315                 }
00316                 if ($this->failure)     {$this->preview=0;}     // No preview flag if a evaluation failure has occured
00317                 $this->previewLabel = $this->preview ? '_PREVIEW' : ''; // Setting preview label prefix.
00318 
00319 
00320                         // *********************
00321                         // DISPLAY FORMS:
00322                         // ***********************
00323                 if ($this->saved) {
00324                                 // Clear page cache
00325                         $this->clearCacheIfSet();
00326 
00327                                 // Displaying the page here that says, the record has been saved. You're able to include the saved values by markers.
00328                         switch($this->cmd)      {
00329                                 case 'delete':
00330                                         $key='DELETE';
00331                                 break;
00332                                 case 'edit':
00333                                         $key='EDIT';
00334                                 break;
00335                                 default:
00336                                         $key='CREATE';
00337                                 break;
00338                         }
00339                                 // Output message
00340                         $templateCode = $this->cObj->getSubpart($this->templateCode, '###TEMPLATE_'.$key.'_SAVED###');
00341                         $this->setCObjects($templateCode,$this->currentArr);
00342                         $markerArray = $this->cObj->fillInMarkerArray($this->markerArray, $this->currentArr, '', TRUE, 'FIELD_', $this->recInMarkersHSC);
00343                         $content = $this->cObj->substituteMarkerArray($templateCode, $markerArray);
00344 
00345                                 // email message:
00346                         $this->compileMail(
00347                                 $key.'_SAVED',
00348                                 array($this->currentArr),
00349                                 $this->currentArr[$this->conf['email.']['field']],
00350                                 $this->conf['setfixed.']
00351                         );
00352 
00353                 } elseif ($this->error) {       // If there was an error, we return the template-subpart with the error message
00354                         $templateCode = $this->cObj->getSubpart($this->templateCode, $this->error);
00355                         $this->setCObjects($templateCode);
00356                         $content = $this->cObj->substituteMarkerArray($templateCode, $this->markerArray);
00357                 } else {
00358                                 // Finally, if there has been no attempt to save. That is either preview or just displaying and empty or not correctly filled form:
00359                         if (!$this->cmd)        {
00360                                 $this->cmd=$this->conf['defaultCmd'];
00361                         }
00362                         if ($this->conf['debug'])               debug('Display form: '.$this->cmd,1);
00363                         switch($this->cmd)      {
00364                                 case 'setfixed':
00365                                         $content = $this->procesSetFixed();
00366                                 break;
00367                                 case 'infomail':
00368                                         $content = $this->sendInfoMail();
00369                                 break;
00370                                 case 'delete':
00371                                         $content = $this->displayDeleteScreen();
00372                                 break;
00373                                 case 'edit':
00374                                         $content = $this->displayEditScreen();
00375                                 break;
00376                                 case 'create':
00377                                         $content = $this->displayCreateScreen();
00378                                 break;
00379                         }
00380                 }
00381 
00382                         // Delete temp files:
00383                 foreach($this->unlinkTempFiles as $tempFileName)        {
00384                         t3lib_div::unlink_tempfile($tempFileName);
00385                 }
00386 
00387                         // Return content:
00388                 return $content;
00389         }
00390 
00391 
00392 
00393 
00394 
00395 
00396 
00397 
00398 
00399 
00400 
00401 
00402 
00403 
00404 
00405 
00406 
00407 
00408 
00409 
00410 
00411 
00412 
00413         /*****************************************
00414          *
00415          * Data processing
00416          *
00417          *****************************************/
00418 
00428         function parseValues()  {
00429                 if (is_array($this->conf['parseValues.']))      {
00430                         reset($this->conf['parseValues.']);
00431                         while(list($theField,$theValue)=each($this->conf['parseValues.']))      {
00432                                 $listOfCommands = t3lib_div::trimExplode(',',$theValue,1);
00433                                 while(list(,$cmd)=each($listOfCommands))        {
00434                                         $cmdParts = split('\[|\]',$cmd);        // Point is to enable parameters after each command enclosed in brackets [..]. These will be in position 1 in the array.
00435                                         $theCmd=trim($cmdParts[0]);
00436                                         switch($theCmd) {
00437                                                 case 'int':
00438                                                         $this->dataArr[$theField]=intval($this->dataArr[$theField]);
00439                                                 break;
00440                                                 case 'lower':
00441                                                 case 'upper':
00442                                                         $this->dataArr[$theField] = $this->cObj->caseshift($this->dataArr[$theField],$theCmd);
00443                                                 break;
00444                                                 case 'nospace':
00445                                                         $this->dataArr[$theField] = str_replace(' ', '', $this->dataArr[$theField]);
00446                                                 break;
00447                                                 case 'alpha':
00448                                                         $this->dataArr[$theField] = ereg_replace('[^a-zA-Z]','',$this->dataArr[$theField]);
00449                                                 break;
00450                                                 case 'num':
00451                                                         $this->dataArr[$theField] = ereg_replace('[^0-9]','',$this->dataArr[$theField]);
00452                                                 break;
00453                                                 case 'alphanum':
00454                                                         $this->dataArr[$theField] = ereg_replace('[^a-zA-Z0-9]','',$this->dataArr[$theField]);
00455                                                 break;
00456                                                 case 'alphanum_x':
00457                                                         $this->dataArr[$theField] = ereg_replace('[^a-zA-Z0-9_-]','',$this->dataArr[$theField]);
00458                                                 break;
00459                                                 case 'trim':
00460                                                         $this->dataArr[$theField] = trim($this->dataArr[$theField]);
00461                                                 break;
00462                                                 case 'random':
00463                                                         $this->dataArr[$theField] = substr(md5(uniqid(microtime(),1)),0,intval($cmdParts[1]));
00464                                                 break;
00465                                                 case 'files':
00466                                                         if ($this->cmdKey=='create' && !t3lib_div::_GP('doNotSave'))    {
00467                                                                 $this->processFiles($cmdParts,$theField);
00468                                                         } else unset($this->dataArr[$theField]);        // Fields with files cannot be edited - only created.
00469                                                 break;
00470                                                 case 'setEmptyIfAbsent':
00471                                                         if (!isset($this->dataArr[$theField]))  {
00472                                                                 $this->dataArr[$theField]='';
00473                                                         }
00474                                                 break;
00475                                                 case 'multiple':
00476                                                         if (is_array($this->dataArr[$theField]))        {
00477                                                                 $this->dataArr[$theField] = implode(',',$this->dataArr[$theField]);
00478                                                         }
00479                                                 break;
00480                                                 case 'checkArray':
00481                                                         if (is_array($this->dataArr[$theField]))        {
00482                                                                 reset($this->dataArr[$theField]);
00483                                                                 $val = 0;
00484                                                                 while(list($kk,$vv)=each($this->dataArr[$theField]))    {
00485                                                                         $kk = t3lib_div::intInRange($kk,0);
00486                                                                         if ($kk<=30)    {
00487                                                                                 if ($vv)        {
00488                                                                                         $val|=pow(2,$kk);
00489                                                                                 }
00490                                                                         }
00491                                                                 }
00492                                                                 $this->dataArr[$theField] = $val;
00493                                                         } else {$this->dataArr[$theField]=0;}
00494                                                 break;
00495                                                 case 'uniqueHashInt':
00496                                                         $otherFields = t3lib_div::trimExplode(';',$cmdParts[1],1);
00497                                                         $hashArray=array();
00498                                                         while(list(,$fN)=each($otherFields))    {
00499                                                                 $vv = $this->dataArr[$fN];
00500                                                                 $vv = ereg_replace('[[:space:]]','',$vv);
00501                                                                 $vv = ereg_replace('[^[:alnum:]]','',$vv);
00502                                                                 $vv = strtolower($vv);
00503                                                                 $hashArray[]=$vv;
00504                                                         }
00505                                                         $this->dataArr[$theField]=hexdec(substr(md5(serialize($hashArray)),0,8));
00506                                                 break;
00507                                         }
00508                                 }
00509                         }
00510                 }
00511         }
00512 
00523         function processFiles($cmdParts,$theField)      {
00524 //debug($_FILES);
00525                         // First, make an array with the filename and file reference, whether the file is just uploaded or a preview
00526                 $filesArr = array();
00527 
00528                 if (is_string($this->dataArr[$theField]))       {               // files from preview.
00529                         $tmpArr = explode(',',$this->dataArr[$theField]);
00530                         reset($tmpArr);
00531                         while(list(,$val)=each($tmpArr))        {
00532                                 $valParts = explode('|',$val);
00533                                 $filesArr[] = array (
00534                                         'name'=>$valParts[1],
00535                                         'tmp_name'=>PATH_site.'typo3temp/'.$valParts[0]
00536                                 );
00537                         }
00538                 } elseif (is_array($_FILES['FE'][$this->theTable][$theField]['name']))  {       // Files from upload
00539                         reset($_FILES['FE'][$this->theTable][$theField]['name']);
00540                         while(list($kk,$vv)=each($_FILES['FE'][$this->theTable][$theField]['name']))    {
00541                                 if ($vv)        {
00542                                         $tmpFile = t3lib_div::upload_to_tempfile($_FILES['FE'][$this->theTable][$theField]['tmp_name'][$kk]);
00543                                         if ($tmpFile)   {
00544                                                 $this->unlinkTempFiles[]=$tmpFile;
00545                                                 $filesArr[] = array (
00546                                                         'name'=>$vv,
00547                                                         'tmp_name'=>$tmpFile
00548                                                 );
00549                                         }
00550                                 }
00551                         }
00552                 } elseif (is_array($_FILES['FE']['name'][$this->theTable][$theField]))  {       // Files from upload
00553                         reset($_FILES['FE']['name'][$this->theTable][$theField]);
00554                         while(list($kk,$vv)=each($_FILES['FE']['name'][$this->theTable][$theField]))    {
00555                                 if ($vv)        {
00556                                         $tmpFile = t3lib_div::upload_to_tempfile($_FILES['FE']['tmp_name'][$this->theTable][$theField][$kk]);
00557                                         if ($tmpFile)   {
00558                                                 $this->unlinkTempFiles[]=$tmpFile;
00559                                                 $filesArr[] = array (
00560                                                         'name'=>$vv,
00561                                                         'tmp_name'=>$tmpFile
00562                                                 );
00563                                         }
00564                                 }
00565                         }
00566                 }
00567 
00568                         // Then verify the files in that array; check existence, extension and size
00569                 $this->dataArr[$theField]='';
00570                 $finalFilesArr=array();
00571                 if (count($filesArr))   {
00572                         $extArray = t3lib_div::trimExplode(';',strtolower($cmdParts[1]),1);
00573                         $maxSize = intval($cmdParts[3]);
00574                         reset($filesArr);
00575                         while(list(,$infoArr)=each($filesArr))  {
00576                                 $fI = pathinfo($infoArr['name']);
00577                                 if (t3lib_div::verifyFilenameAgainstDenyPattern($fI['name']))   {
00578                                         if (!count($extArray) || in_array(strtolower($fI['extension']), $extArray))     {
00579                                                 $tmpFile = $infoArr['tmp_name'];
00580                                                 if (@is_file($tmpFile)) {
00581                                                         if (!$maxSize || filesize($tmpFile)<$maxSize*1024)      {
00582                                                                 $finalFilesArr[]=$infoArr;
00583                                                         } elseif ($this->conf['debug']) {debug('Size is beyond '.$maxSize.' kb ('.filesize($tmpFile).' bytes) and the file cannot be saved.');}
00584                                                 } elseif ($this->conf['debug']) {debug('Surprisingly there was no file for '.$vv.' in '.$tmpFile);}
00585                                         } elseif ($this->conf['debug']) {debug('Extension "'.$fI['extension'].'" not allowed');}
00586                                 } elseif ($this->conf['debug']) {debug('Filename matched illegal pattern.');}
00587                         }
00588                 }
00589                         // Copy the files in the resulting array to the proper positions based on preview/non-preview.
00590                 reset($finalFilesArr);
00591                 $fileNameList=array();
00592                 while(list(,$infoArr)=each($finalFilesArr))     {
00593                         if ($this->isPreview()) {               // If the form is a preview form (and data is therefore not going into the database...) do this.
00594                                 $this->createFileFuncObj();
00595                                 $fI = pathinfo($infoArr['name']);
00596                                 $tmpFilename = $this->theTable.'_'.t3lib_div::shortmd5(uniqid($infoArr['name'])).'.'.$fI['extension'];
00597                                 $theDestFile = $this->fileFunc->getUniqueName($this->fileFunc->cleanFileName($tmpFilename), PATH_site.'typo3temp/');
00598                                 t3lib_div::upload_copy_move($infoArr['tmp_name'],$theDestFile);
00599                                         // Setting the filename in the list
00600                                 $fI2 = pathinfo($theDestFile);
00601                                 $fileNameList[] = $fI2['basename'].'|'.$infoArr['name'];
00602                         } else {
00603                                 $this->createFileFuncObj();
00604                                 $GLOBALS['TSFE']->includeTCA();
00605                                 t3lib_div::loadTCA($this->theTable);
00606                                 if (is_array($GLOBALS['TCA'][$this->theTable]['columns'][$theField]))   {
00607                                         $uploadPath = $GLOBALS['TCA'][$this->theTable]['columns'][$theField]['config']['uploadfolder'];
00608                                 }
00609                                 if ($uploadPath)        {
00610                                         $theDestFile = $this->fileFunc->getUniqueName($this->fileFunc->cleanFileName($infoArr['name']), PATH_site.$uploadPath);
00611                                         t3lib_div::upload_copy_move($infoArr['tmp_name'],$theDestFile);
00612                                                 // Setting the filename in the list
00613                                         $fI2 = pathinfo($theDestFile);
00614                                         $fileNameList[] = $fI2['basename'];
00615                                         $this->filesStoredInUploadFolders[]=$theDestFile;
00616                                 }
00617                         }
00618                                 // Implode the list of filenames
00619                         $this->dataArr[$theField] = implode(',',$fileNameList);
00620                 }
00621         }
00622 
00629         function overrideValues()       {
00630                 // Addition of overriding values
00631                 if (is_array($this->conf[$this->cmdKey.'.']['overrideValues.']))        {
00632                         reset($this->conf[$this->cmdKey.'.']['overrideValues.']);
00633                         while(list($theField,$theValue)=each($this->conf[$this->cmdKey.'.']['overrideValues.']))        {
00634                                 $this->dataArr[$theField] = $theValue;
00635                         }
00636                 }
00637         }
00638 
00645         function defaultValues()        {
00646                         // Addition of default values
00647                 if (is_array($this->conf[$this->cmdKey.'.']['defaultValues.'])) {
00648                         reset($this->conf[$this->cmdKey.'.']['defaultValues.']);
00649                         while(list($theField,$theValue)=each($this->conf[$this->cmdKey.'.']['defaultValues.'])) {
00650                                 $this->dataArr[$theField] = $theValue;
00651                         }
00652                 }
00653         }
00654 
00664         function evalValues()   {
00665                 // Check required, set failure if not ok.
00666                 reset($this->requiredArr);
00667                 $tempArr=array();
00668                 while(list(,$theField)=each($this->requiredArr))        {
00669                         if (!trim($this->dataArr[$theField]))   {
00670                                 $tempArr[]=$theField;
00671                         }
00672                 }
00673 
00674                 // 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!
00675                 $recExist=0;
00676                 if (is_array($this->conf[$this->cmdKey.'.']['evalValues.']))    {
00677                         switch($this->cmd)      {
00678                                 case 'edit':
00679                                         if (isset($this->dataArr['pid']))       {                       // 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.
00680                                                 $recordTestPid = intval($this->dataArr['pid']);
00681                                         } else {
00682                                                 $tempRecArr = $GLOBALS['TSFE']->sys_page->getRawRecord($this->theTable,$this->dataArr['uid']);
00683                                                 $recordTestPid = intval($tempRecArr['pid']);
00684                                         }
00685                                         $recExist=1;
00686                                 break;
00687                                 default:
00688                                         $recordTestPid = $this->thePid ? $this->thePid : t3lib_div::intval_positive($this->dataArr['pid']);
00689                                 break;
00690                         }
00691 
00692                         reset($this->conf[$this->cmdKey.'.']['evalValues.']);
00693                         while(list($theField,$theValue)=each($this->conf[$this->cmdKey.'.']['evalValues.']))    {
00694                                 $listOfCommands = t3lib_div::trimExplode(',',$theValue,1);
00695                                 while(list(,$cmd)=each($listOfCommands))        {
00696                                         $cmdParts = split('\[|\]',$cmd);        // Point is to enable parameters after each command enclosed in brackets [..]. These will be in position 1 in the array.
00697                                         $theCmd = trim($cmdParts[0]);
00698                                         switch($theCmd) {
00699                                                 case 'uniqueGlobal':
00700                                                         if ($DBrows = $GLOBALS['TSFE']->sys_page->getRecordsByField($this->theTable,$theField,$this->dataArr[$theField],'','','','1'))  {
00701                                                                 if (!$recExist || $DBrows[0]['uid']!=$this->dataArr['uid'])     {       // 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.
00702                                                                         $tempArr[]=$theField;
00703                                                                         $this->failureMsg[$theField][] = $this->getFailure($theField, $theCmd, 'The value existed already. Enter a new value.');
00704                                                                 }
00705                                                         }
00706                                                 break;
00707                                                 case 'uniqueLocal':
00708                                                         if ($DBrows = $GLOBALS['TSFE']->sys_page->getRecordsByField($this->theTable,$theField,$this->dataArr[$theField], 'AND pid IN ('.$recordTestPid.')','','','1'))  {
00709                                                                 if (!$recExist || $DBrows[0]['uid']!=$this->dataArr['uid'])     {       // 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.
00710                                                                         $tempArr[]=$theField;
00711                                                                         $this->failureMsg[$theField][] = $this->getFailure($theField, $theCmd, 'The value existed already. Enter a new value.');
00712                                                                 }
00713                                                         }
00714                                                 break;
00715                                                 case 'twice':
00716                                                         if (strcmp($this->dataArr[$theField], $this->dataArr[$theField.'_again']))      {
00717                                                                 $tempArr[]=$theField;
00718                                                                 $this->failureMsg[$theField][] = $this->getFailure($theField, $theCmd, 'You must enter the same value twice');
00719                                                         }
00720                                                 break;
00721                                                 case 'email':
00722                                                         if (!$this->cObj->checkEmail($this->dataArr[$theField]))        {
00723                                                                 $tempArr[]=$theField;
00724                                                                 $this->failureMsg[$theField][] = $this->getFailure($theField, $theCmd, 'You must enter a valid email address');
00725                                                         }
00726                                                 break;
00727                                                 case 'required':
00728                                                         if (!trim($this->dataArr[$theField]))   {
00729                                                                 $tempArr[]=$theField;
00730                                                                 $this->failureMsg[$theField][] = $this->getFailure($theField, $theCmd, 'You must enter a value!');
00731                                                         }
00732                                                 break;
00733                                                 case 'atLeast':
00734                                                         $chars=intval($cmdParts[1]);
00735                                                         if (strlen($this->dataArr[$theField])<$chars)   {
00736                                                                 $tempArr[]=$theField;
00737                                                                 $this->failureMsg[$theField][] = sprintf($this->getFailure($theField, $theCmd, 'You must enter at least %s characters!'), $chars);
00738                                                         }
00739                                                 break;
00740                                                 case 'atMost':
00741                                                         $chars=intval($cmdParts[1]);
00742                                                         if (strlen($this->dataArr[$theField])>$chars)   {
00743                                                                 $tempArr[]=$theField;
00744                                                                 $this->failureMsg[$theField][] = sprintf($this->getFailure($theField, $theCmd, 'You must enter at most %s characters!'), $chars);
00745                                                         }
00746                                                 break;
00747                                                 case 'inBranch':
00748                                                         $pars = explode(';',$cmdParts[1]);
00749                                                         if (intval($pars[0]))   {
00750                                                                 $pid_list = $this->cObj->getTreeList(
00751                                                                         intval($pars[0]),
00752                                                                         intval($pars[1]) ? intval($pars[1]) : 999,
00753                                                                         intval($pars[2])
00754                                                                 );
00755                                                                 if (!$pid_list || !t3lib_div::inList($pid_list,$this->dataArr[$theField]))      {
00756                                                                         $tempArr[]=$theField;
00757                                                                         $this->failureMsg[$theField][] = sprintf($this->getFailure($theField, $theCmd, 'The value was not a valid valud from this list: %s'), $pid_list);
00758                                                                 }
00759                                                         }
00760                                                 break;
00761                                                 case 'unsetEmpty':
00762                                                         if (!$this->dataArr[$theField]) {
00763                                                                 $hash = array_flip($tempArr);
00764                                                                 unset($hash[$theField]);
00765                                                                 $tempArr = array_keys($hash);
00766                                                                 unset($this->failureMsg[$theField]);
00767                                                                 unset($this->dataArr[$theField]);       // This should prevent the field from entering the database.
00768                                                         }
00769                                                 break;
00770                                         }
00771                                 }
00772                                 $this->markerArray['###EVAL_ERROR_FIELD_'.$theField.'###'] = is_array($this->failureMsg[$theField]) ? implode('<br />',$this->failureMsg[$theField]) : '';
00773                         }
00774                 }
00775                 $this->failure=implode(',',$tempArr);    //$failure will show which fields were not OK
00776         }
00777 
00786         function userProcess($mConfKey,$passVar)        {
00787                 if ($this->conf[$mConfKey])     {
00788                         $funcConf = $this->conf[$mConfKey.'.'];
00789                         $funcConf['parentObj']=&$this;
00790                         $passVar = $GLOBALS['TSFE']->cObj->callUserFunction($this->conf[$mConfKey], $funcConf, $passVar);
00791                 }
00792                 return $passVar;
00793         }
00794 
00804         function userProcess_alt($confVal,$confArr,$passVar)    {
00805                 if ($confVal)   {
00806                         $funcConf = $confArr;
00807                         $funcConf['parentObj']=&$this;
00808                         $passVar = $GLOBALS['TSFE']->cObj->callUserFunction($confVal, $funcConf, $passVar);
00809                 }
00810                 return $passVar;
00811         }
00812 
00813 
00814 
00815 
00816 
00817 
00818 
00819 
00820 
00821 
00822 
00823 
00824 
00825 
00826 
00827 
00828 
00829 
00830 
00831 
00832 
00833 
00834         /*****************************************
00835          *
00836          * Database manipulation functions
00837          *
00838          *****************************************/
00839 
00846         function save() {
00847                 switch($this->cmd)      {
00848                         case 'edit':
00849                                 $theUid = $this->dataArr['uid'];
00850                                 $origArr = $GLOBALS['TSFE']->sys_page->getRawRecord($this->theTable,$theUid);           // Fetches the original record to check permissions
00851                                 if ($this->conf['edit'] && ($GLOBALS['TSFE']->loginUser || $this->aCAuth($origArr)))    {       // Must be logged in in order to edit  (OR be validated by email)
00852                                         $newFieldList = implode(',',array_intersect(explode(',',$this->fieldList),t3lib_div::trimExplode(',',$this->conf['edit.']['fields'],1)));
00853                                         if ($this->aCAuth($origArr) || $this->cObj->DBmayFEUserEdit($this->theTable,$origArr,$GLOBALS['TSFE']->fe_user->user,$this->conf['allowedGroups'],$this->conf['fe_userEditSelf']))      {
00854                                                 $this->cObj->DBgetUpdate($this->theTable, $theUid, $this->dataArr, $newFieldList, TRUE);
00855                                                 $this->currentArr = $GLOBALS['TSFE']->sys_page->getRawRecord($this->theTable,$theUid);
00856                                                 $this->userProcess_alt($this->conf['edit.']['userFunc_afterSave'],$this->conf['edit.']['userFunc_afterSave.'],array('rec'=>$this->currentArr, 'origRec'=>$origArr));
00857                                                 $this->saved=1;
00858                                         } else {
00859                                                 $this->error='###TEMPLATE_NO_PERMISSIONS###';
00860                                         }
00861                                 }
00862                         break;
00863                         default:
00864                                 if ($this->conf['create'])      {
00865                                         $newFieldList = implode(',',array_intersect(explode(',',$this->fieldList),t3lib_div::trimExplode(',',$this->conf['create.']['fields'],1)));
00866                                         $this->cObj->DBgetInsert($this->theTable, $this->thePid, $this->dataArr, $newFieldList, TRUE);
00867                                         $newId = $GLOBALS['TYPO3_DB']->sql_insert_id();
00868 
00869                                         if ($this->theTable=='fe_users' && $this->conf['fe_userOwnSelf'])       {               // enables users, creating logins, to own them self.
00870                                                 $extraList='';
00871                                                 $dataArr = array();
00872                                                 if ($GLOBALS['TCA'][$this->theTable]['ctrl']['fe_cruser_id'])           {
00873                                                         $field=$GLOBALS['TCA'][$this->theTable]['ctrl']['fe_cruser_id'];
00874                                                         $dataArr[$field]=$newId;
00875                                                         $extraList.=','.$field;
00876                                                 }
00877                                                 if ($GLOBALS['TCA'][$this->theTable]['ctrl']['fe_crgroup_id'])  {
00878                                                         $field=$GLOBALS['TCA'][$this->theTable]['ctrl']['fe_crgroup_id'];
00879                                                         list($dataArr[$field])=explode(',',$this->dataArr['usergroup']);
00880                                                         $dataArr[$field]=intval($dataArr[$field]);
00881                                                         $extraList.=','.$field;
00882                                                 }
00883                                                 if (count($dataArr))    {
00884                                                         $this->cObj->DBgetUpdate($this->theTable, $newId, $dataArr, $extraList, TRUE);
00885                                                 }
00886                                         }
00887 
00888                                         $this->currentArr = $GLOBALS['TSFE']->sys_page->getRawRecord($this->theTable,$newId);
00889                                         $this->userProcess_alt($this->conf['create.']['userFunc_afterSave'],$this->conf['create.']['userFunc_afterSave.'],array('rec'=>$this->currentArr));
00890                                         $this->saved=1;
00891                                 }
00892                         break;
00893                 }
00894         }
00895 
00904         function deleteRecord() {
00905                 if ($this->conf['delete'])      {       // If deleting is enabled
00906                         $origArr = $GLOBALS['TSFE']->sys_page->getRawRecord($this->theTable,  $this->recUid);
00907                         if ($GLOBALS['TSFE']->loginUser || $this->aCAuth($origArr))     {       // Must be logged in OR be authenticated by the aC code in order to delete
00908                                         // If the recUid selects a record.... (no check here)
00909                                 if (is_array($origArr)) {
00910                                         if ($this->aCAuth($origArr) || $this->cObj->DBmayFEUserEdit($this->theTable,$origArr, $GLOBALS['TSFE']->fe_user->user,$this->conf['allowedGroups'],$this->conf['fe_userEditSelf']))     {       // Display the form, if access granted.
00911                                                 if (!$GLOBALS['TCA'][$this->theTable]['ctrl']['delete'])        {       // If the record is fully deleted... then remove the image (or any file) attached.
00912                                                         $this->deleteFilesFromRecord($this->recUid);
00913                                                 }
00914                                                 $this->cObj->DBgetDelete($this->theTable, $this->recUid, TRUE);
00915                                                 $this->currentArr = $origArr;
00916                                                 $this->saved = 1;
00917                                         } else {
00918                                                 $this->error = '###TEMPLATE_NO_PERMISSIONS###';
00919                                         }
00920                                 }
00921                         }
00922                 }
00923         }
00924 
00934         function deleteFilesFromRecord($uid)    {
00935                 $table = $this->theTable;
00936                 $rec = $GLOBALS['TSFE']->sys_page->getRawRecord($table,$uid);
00937 
00938                 $GLOBALS['TSFE']->includeTCA();
00939                 t3lib_div::loadTCA($table);
00940                 reset($GLOBALS['TCA'][$table]['columns']);
00941                 $iFields=array();
00942                 while(list($field,$conf)=each($GLOBALS['TCA'][$table]['columns']))      {
00943                         if ($conf['config']['type']=='group' && $conf['config']['internal_type']=='file')       {
00944 
00945                                 $GLOBALS['TYPO3_DB']->exec_UPDATEquery($table, 'uid='.intval($uid), array($field => ''));
00946 
00947                                 $delFileArr = explode(',',$rec[$field]);
00948                                 reset($delFileArr);
00949                                 while(list(,$n)=each($delFileArr))      {
00950                                         if ($n) {
00951                                                 $fpath = $conf['config']['uploadfolder'].'/'.$n;
00952                                                 unlink($fpath);
00953                                         }
00954                                 }
00955                         }
00956                 }
00957         }
00958 
00959 
00960 
00961 
00962 
00963 
00964 
00965 
00966 
00967 
00968 
00969 
00970 
00971 
00972 
00973 
00974 
00975 
00976 
00977 
00978 
00979         /*****************************************
00980          *
00981          * Command "display" functions
00982          *
00983          *****************************************/
00984 
00991         function displayDeleteScreen()  {
00992                 if ($this->conf['delete'])      {       // If deleting is enabled
00993                         $origArr = $GLOBALS['TSFE']->sys_page->getRawRecord($this->theTable,  $this->recUid);
00994                         if ($GLOBALS['TSFE']->loginUser || $this->aCAuth($origArr))     {       // Must be logged in OR be authenticated by the aC code in order to delete
00995                                         // If the recUid selects a record.... (no check here)
00996                                 if (is_array($origArr)) {
00997                                         if ($this->aCAuth($origArr) || $this->cObj->DBmayFEUserEdit($this->theTable,$origArr, $GLOBALS['TSFE']->fe_user->user,$this->conf['allowedGroups'],$this->conf['fe_userEditSelf']))     {       // Display the form, if access granted.
00998                                                 $this->markerArray['###HIDDENFIELDS###'].= '<input type="hidden" name="rU" value="'.$this->recUid.'" />';
00999                                                 $content = $this->getPlainTemplate('###TEMPLATE_DELETE_PREVIEW###', $origArr);
01000                                         } else {        // Else display error, that you could not edit that particular record...
01001                                                 $content = $this->getPlainTemplate('###TEMPLATE_NO_PERMISSIONS###');
01002                                         }
01003                                 }
01004                         } 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.
01005                                 $content = $this->getPlainTemplate('###TEMPLATE_AUTH###');
01006                         }
01007                 } else {
01008                         $content.='Delete-option is not set in TypoScript';
01009                 }
01010                 return $content;
01011         }
01012 
01019         function displayCreateScreen()  {
01020                 if ($this->conf['create'])      {
01021                         $templateCode = $this->cObj->getSubpart($this->templateCode, ((!$GLOBALS['TSFE']->loginUser||$this->conf['create.']['noSpecialLoginForm'])?'###TEMPLATE_CREATE'.$this->previewLabel.'###':'###TEMPLATE_CREATE_LOGIN'.$this->previewLabel.'###'));
01022                         $failure = t3lib_div::_GP('noWarnings')?'':$this->failure;
01023                         if (!$failure)  $templateCode = $this->cObj->substituteSubpart($templateCode, '###SUB_REQUIRED_FIELDS_WARNING###', '');
01024 
01025                         $templateCode = $this->removeRequired($templateCode,$failure);
01026                         $this->setCObjects($templateCode);
01027 
01028                         $markerArray = $this->cObj->fillInMarkerArray($this->markerArray, $this->dataArr, '', TRUE, 'FIELD_', $this->recInMarkersHSC);
01029                         if ($this->conf['create.']['preview'] && !$this->previewLabel)  {$markerArray['###HIDDENFIELDS###'].= '<input type="hidden" name="preview" value="1" />';}
01030                         $content = $this->cObj->substituteMarkerArray($templateCode, $markerArray);
01031                         $content.=$this->cObj->getUpdateJS($this->modifyDataArrForFormUpdate($this->dataArr), $this->theTable.'_form', 'FE['.$this->theTable.']', $this->fieldList.$this->additionalUpdateFields);
01032                 }
01033                 return $content;
01034         }
01035 
01042         function displayEditScreen()    {
01043                 if ($this->conf['edit'])        {       // If editing is enabled
01044                         $origArr = $GLOBALS['TSFE']->sys_page->getRawRecord($this->theTable,  $this->dataArr['uid']?$this->dataArr['uid']:$this->recUid);
01045 
01046                         if ($GLOBALS['TSFE']->loginUser || $this->aCAuth($origArr))     {       // Must be logged in OR be authenticated by the aC code in order to edit
01047                                         // If the recUid selects a record.... (no check here)
01048                                 if (is_array($origArr)) {
01049                                         if ($this->aCAuth($origArr) || $this->cObj->DBmayFEUserEdit($this->theTable,$origArr, $GLOBALS['TSFE']->fe_user->user,$this->conf['allowedGroups'],$this->conf['fe_userEditSelf']))     {       // Display the form, if access granted.
01050                                                 $content=$this->displayEditForm($origArr);
01051                                         } else {        // Else display error, that you could not edit that particular record...
01052                                                 $content = $this->getPlainTemplate('###TEMPLATE_NO_PERMISSIONS###');
01053                                         }
01054                                 } elseif ($GLOBALS['TSFE']->loginUser) {        // If the recUid did not select a record, we display a menu of records. (eg. if no recUid)
01055                                         $lockPid = $this->conf['edit.']['menuLockPid'] ? ' AND pid='.intval($this->thePid) : '';
01056 
01057                                         $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', $this->theTable, '1 '.$lockPid.$this->cObj->DBmayFEUserEditSelect($this->theTable,$GLOBALS['TSFE']->fe_user->user, $this->conf['allowedGroups'],$this->conf['fe_userEditSelf']).$GLOBALS['TSFE']->sys_page->deleteClause($this->theTable));
01058 
01059                                         if ($GLOBALS['TYPO3_DB']->sql_num_rows($res))   {       // If there are menu-items ...
01060                                                 $templateCode = $this->getPlainTemplate('###TEMPLATE_EDITMENU###');
01061                                                 $out='';
01062                                                 $itemCode = $this->cObj->getSubpart($templateCode, '###ITEM###');
01063                                                 while($menuRow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))   {
01064                                                         $markerArray = $this->cObj->fillInMarkerArray(array(), $menuRow, '', TRUE, 'FIELD_', $this->recInMarkersHSC);
01065                                                         $markerArray = $this->setCObjects($itemCode,$menuRow,$markerArray,'ITEM_');
01066                                                         $out.= $this->cObj->substituteMarkerArray($itemCode, $markerArray);
01067                                                 }
01068                                                 $content=$this->cObj->substituteSubpart($templateCode, '###ALLITEMS###', $out);
01069                                         } else {        // If there are not menu items....
01070                                                 $content = $this->getPlainTemplate('###TEMPLATE_EDITMENU_NOITEMS###');
01071                                         }
01072                                 } else {
01073                                         $content = $this->getPlainTemplate('###TEMPLATE_AUTH###');
01074                                 }
01075                         } 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.
01076                                 $content = $this->getPlainTemplate('###TEMPLATE_AUTH###');
01077                         }
01078                 } else {
01079                         $content.='Edit-option is not set in TypoScript';
01080                 }
01081                 return $content;
01082         }
01083 
01093         function displayEditForm($origArr)      {
01094                 $currentArr = is_array($this->dataArr) ? $this->dataArr+$origArr : $origArr;
01095 
01096                 if ($this->conf['debug'])       debug('displayEditForm(): '.'###TEMPLATE_EDIT'.$this->previewLabel.'###',1);
01097                 $templateCode = $this->cObj->getSubpart($this->templateCode, '###TEMPLATE_EDIT'.$this->previewLabel.'###');
01098                 $failure = t3lib_div::_GP('noWarnings')?'':$this->failure;
01099                 if (!$failure)  {$templateCode = $this->cObj->substituteSubpart($templateCode, '###SUB_REQUIRED_FIELDS_WARNING###', '');}
01100 
01101                 $templateCode = $this->removeRequired($templateCode,$failure);
01102 
01103                 $this->setCObjects($templateCode,$currentArr);
01104 
01105                 $markerArray = $this->cObj->fillInMarkerArray($this->markerArray, $currentArr, '', TRUE, 'FIELD_', $this->recInMarkersHSC);
01106 
01107                 $markerArray['###HIDDENFIELDS###'].= '<input type="hidden" name="FE['.$this->theTable.'][uid]" value="'.$currentArr['uid'].'" />';
01108                 if ($this->conf['edit.']['preview'] && !$this->previewLabel)    {$markerArray['###HIDDENFIELDS###'].= '<input type="hidden" name="preview" value="1" />';}
01109                 $content = $this->cObj->substituteMarkerArray($templateCode, $markerArray);
01110                 $content.=$this->cObj->getUpdateJS($this->modifyDataArrForFormUpdate($currentArr), $this->theTable.'_form',  'FE['.$this->theTable.']', $this->fieldList.$this->additionalUpdateFields);
01111 
01112                 return $content;
01113         }
01114 
01121         function procesSetFixed()       {
01122                 if ($this->conf['setfixed'])    {
01123                         $theUid = intval($this->recUid);
01124                         $origArr = $GLOBALS['TSFE']->sys_page->getRawRecord($this->theTable,  $theUid);
01125                         $fD = t3lib_div::_GP('fD');
01126                         $sFK = t3lib_div::_GP('sFK');
01127 
01128                         $fieldArr=array();
01129                         if (is_array($fD) || $sFK=='DELETE')    {
01130                                 if (is_array($fD))      {
01131                                         reset($fD);
01132                                         while(list($field,$value)=each($fD))    {
01133                                                 $origArr[$field]=$value;
01134                                                 $fieldArr[]=$field;
01135                                         }
01136                                 }
01137                                 $theCode = $this->setfixedHash($origArr,$origArr['_FIELDLIST']);
01138                                 if (!strcmp($this->authCode,$theCode))  {
01139                                         if ($sFK=='DELETE')     {
01140                                                 $this->cObj->DBgetDelete($this->theTable, $theUid, TRUE);
01141                                         } else {
01142                                                 $newFieldList = implode(',',array_intersect(t3lib_div::trimExplode(',',$this->fieldList),t3lib_div::trimExplode(',',implode($fieldArr,','),1)));
01143                                                 $this->cObj->DBgetUpdate($this->theTable, $theUid, $fD, $newFieldList, TRUE);
01144                                                 $this->currentArr = $GLOBALS['TSFE']->sys_page->getRawRecord($this->theTable,$theUid);
01145                                                 $this->userProcess_alt($this->conf['setfixed.']['userFunc_afterSave'],$this->conf['setfixed.']['userFunc_afterSave.'],array('rec'=>$this->currentArr, 'origRec'=>$origArr));
01146                                         }
01147 
01148                                                 // Outputting template
01149                                         $this->markerArray = $this->cObj->fillInMarkerArray($this->markerArray, $origArr, '', TRUE, 'FIELD_', $this->recInMarkersHSC);
01150                                         $content = $this->getPlainTemplate('###TEMPLATE_SETFIXED_OK_'.$sFK.'###');
01151                                         if (!$content)  {$content = $this->getPlainTemplate('###TEMPLATE_SETFIXED_OK###');}
01152 
01153                                                 // Compiling email
01154                                         $this->compileMail(
01155                                                 'SETFIXED_'.$sFK,
01156                                                 array($origArr),
01157                                                 $origArr[$this->conf['email.']['field']],
01158                                                 $this->conf['setfixed.']
01159                                         );
01160                                                 // Clearing cache if set:
01161                                         $this->clearCacheIfSet();
01162                                 } else $content = $this->getPlainTemplate('###TEMPLATE_SETFIXED_FAILED###');
01163                         } else $content = $this->getPlainTemplate('###TEMPLATE_SETFIXED_FAILED###');
01164                 }
01165                 return $content;
01166         }
01167 
01168 
01169 
01170 
01171 
01172 
01173 
01174 
01175 
01176 
01177 
01178 
01179 
01180 
01181 
01182 
01183 
01184 
01185 
01186 
01187 
01188 
01189 
01190         /*****************************************
01191          *
01192          * Template processing functions
01193          *
01194          *****************************************/
01195 
01196 
01197 
01210         function removeRequired($templateCode,$failure) {
01211                 reset($this->requiredArr);
01212                 while(list(,$theField)=each($this->requiredArr))        {
01213                         if (!t3lib_div::inList($failure,$theField))     {
01214                                 $templateCode = $this->cObj->substituteSubpart($templateCode, '###SUB_REQUIRED_FIELD_'.$theField.'###', '');
01215                         }
01216                 }
01217                 return $templateCode;
01218         }
01219 
01228         function getPlainTemplate($key,$r='')   {
01229                 if ($this->conf['debug'])       debug('getPlainTemplate(): '.$key,1);
01230                 $templateCode = $this->cObj->getSubpart($this->templateCode, $key);
01231                 $this->setCObjects($templateCode,is_array($r)?$r:array());
01232                 return  $this->cObj->substituteMarkerArray(
01233                                 $templateCode,
01234                                 is_array($r) ? $this->cObj->fillInMarkerArray($this->markerArray, $r, '', TRUE, 'FIELD_', $this->recInMarkersHSC) : $this->markerArray
01235                         );
01236         }
01237 
01245         function modifyDataArrForFormUpdate($inputArr)  {
01246                 if (is_array($this->conf[$this->cmdKey.'.']['evalValues.']))    {
01247                         reset($this->conf[$this->cmdKey.'.']['evalValues.']);
01248                         while(list($theField,$theValue)=each($this->conf[$this->cmdKey.'.']['evalValues.']))    {
01249                                 $listOfCommands = t3lib_div::trimExplode(',',$theValue,1);
01250                                 while(list(,$cmd)=each($listOfCommands))        {
01251                                         $cmdParts = split('\[|\]',$cmd);        // Point is to enable parameters after each command enclosed in brackets [..]. These will be in position 1 in the array.
01252                                         $theCmd = trim($cmdParts[0]);
01253                                         switch($theCmd) {
01254                                                 case 'twice':
01255                                                         if (isset($inputArr[$theField]))        {
01256                                                                 if (!isset($inputArr[$theField.'_again']))      {
01257                                                                         $inputArr[$theField.'_again'] = $inputArr[$theField];
01258                                                                 }
01259                                                                 $this->additionalUpdateFields.=','.$theField.'_again';
01260                                                         }
01261                                                 break;
01262                                         }
01263                                 }
01264                         }
01265                 }
01266                 if (is_array($this->conf['parseValues.']))      {
01267                         reset($this->conf['parseValues.']);
01268                         while(list($theField,$theValue)=each($this->conf['parseValues.']))      {
01269                                 $listOfCommands = t3lib_div::trimExplode(',',$theValue,1);
01270                                 while(list(,$cmd)=each($listOfCommands))        {
01271                                         $cmdParts = split('\[|\]',$cmd);        // Point is to enable parameters after each command enclosed in brackets [..]. These will be in position 1 in the array.
01272                                         $theCmd = trim($cmdParts[0]);
01273                                         switch($theCmd) {
01274                                                 case 'multiple':
01275                                                         if (isset($inputArr[$theField]) && !$this->isPreview()) {
01276                                                                 $inputArr[$theField] = explode(',',$inputArr[$theField]);
01277                                                         }
01278                                                 break;
01279                                                 case 'checkArray':
01280                                                         if ($inputArr[$theField] && !$this->isPreview())        {
01281                                                                 for($a=0;$a<=30;$a++)   {
01282                                                                         if ($inputArr[$theField] & pow(2,$a))   {
01283                                                                                 $alt_theField = $theField.']['.$a;
01284                                                                                 $inputArr[$alt_theField] = 1;
01285                                                                                 $this->additionalUpdateFields.=','.$alt_theField;
01286                                                                         }
01287                                                                 }
01288                                                         }
01289                                                 break;
01290                                         }
01291                                 }
01292                         }
01293                 }
01294 
01295 
01296                 $inputArr = $this->userProcess_alt(
01297                         $this->conf['userFunc_updateArray'],
01298                         $this->conf['userFunc_updateArray.'],
01299                         $inputArr
01300                 );
01301 
01302                 return $inputArr;
01303         }
01304 
01314         function setCObjects($templateCode,$currentArr=array(),$markerArray='',$specialPrefix='')       {
01315                 if (is_array($this->conf['cObjects.'])) {
01316                         reset($this->conf['cObjects.']);
01317 
01318                         while(list($theKey,$theConf)=each($this->conf['cObjects.']))    {
01319                                 if (!strstr($theKey,'.'))       {
01320                                         if (strstr($templateCode,'###'.$specialPrefix.'CE_'.$theKey.'###'))     {
01321                                                 $cObjCode = $this->cObj->cObjGetSingle($this->conf['cObjects.'][$theKey], $this->conf['cObjects.'][$theKey.'.'], 'cObjects.'.$theKey);
01322 
01323                                                 if (!is_array($markerArray))    {
01324                                                         $this->markerArray['###'.$specialPrefix.'CE_'.$theKey.'###'] = $cObjCode;
01325                                                 } else {
01326                                                         $markerArray['###'.$specialPrefix.'CE_'.$theKey.'###'] = $cObjCode;
01327                                                 }
01328                                         }
01329                                         if (strstr($templateCode,'###'.$specialPrefix.'PCE_'.$theKey.'###'))    {
01330                                                 $local_cObj =t3lib_div::makeInstance('tslib_cObj');
01331                                                 $local_cObj->start(count($currentArr)?$currentArr:$this->dataArr,$this->theTable);
01332                                                 $cObjCode = $local_cObj->cObjGetSingle($this->conf['cObjects.'][$theKey], $this->conf['cObjects.'][$theKey.'.'], 'cObjects.'.$theKey);
01333 
01334                                                 if (!is_array($markerArray))    {
01335                                                         $this->markerArray['###'.$specialPrefix.'PCE_'.$theKey.'###'] = $cObjCode;
01336                                                 } else {
01337                                                         $markerArray['###'.$specialPrefix.'PCE_'.$theKey.'###'] = $cObjCode;
01338                                                 }
01339                                         }
01340                                 }
01341                         }
01342                 }
01343                 return $markerArray;
01344         }
01345 
01346 
01347 
01348 
01349 
01350 
01351 
01352 
01353 
01354 
01355 
01356 
01357 
01358 
01359 
01360 
01361 
01362 
01363 
01364         /*****************************************
01365          *
01366          * Emailing
01367          *
01368          *****************************************/
01369 
01376         function sendInfoMail() {
01377                 if ($this->conf['infomail'] && $this->conf['email.']['field'])  {
01378                         $fetch = t3lib_div::_GP('fetch');
01379                         if ($fetch)     {
01380                                         // Getting infomail config.
01381                                 $key= trim(t3lib_div::_GP('key'));
01382                                 if (is_array($this->conf['infomail.'][$key.'.']))               {
01383                                         $config = $this->conf['infomail.'][$key.'.'];
01384                                 } else {
01385                                         $config = $this->conf['infomail.']['default.'];
01386                                 }
01387                                 $pidLock='';
01388                                 if (!$config['dontLockPid'])    {
01389                                         $pidLock='AND pid IN ('.$this->thePid.') ';
01390                                 }
01391 
01392                                         // Getting records
01393                                 if (t3lib_div::testInt($fetch)) {
01394                                         $DBrows = $GLOBALS['TSFE']->sys_page->getRecordsByField($this->theTable,'uid',$fetch,$pidLock,'','','1');
01395                                 } elseif ($fetch) {     // $this->conf['email.']['field'] must be a valid field in the table!
01396                                         $DBrows = $GLOBALS['TSFE']->sys_page->getRecordsByField($this->theTable,$this->conf['email.']['field'],$fetch,$pidLock,'','','100');
01397                                 }
01398 
01399                                         // Processing records
01400                                 if (is_array($DBrows))  {
01401                                         $recipient = $DBrows[0][$this->conf['email.']['field']];
01402                                         $this->compileMail($config['label'], $DBrows, $recipient, $this->conf['setfixed.']);
01403                                 } elseif ($this->cObj->checkEmail($fetch)) {
01404                                         $this->sendMail($fetch, '', trim($this->cObj->getSubpart($this->templateCode, '###'.$this->emailMarkPrefix.'NORECORD###')));
01405                                 }
01406 
01407                                 $content = $this->getPlainTemplate('###TEMPLATE_INFOMAIL_SENT###');
01408                         } else {
01409                                 $content = $this->getPlainTemplate('###TEMPLATE_INFOMAIL###');
01410                         }
01411                 } else $content='Error: infomail option is not available or emailField is not setup in TypoScript';
01412                 return $content;
01413         }
01414 
01424         function compileMail($key, $DBrows, $recipient, $setFixedConfig=array())        {
01425                 $GLOBALS['TT']->push('compileMail');
01426                 $mailContent='';
01427                 $key = $this->emailMarkPrefix.$key;
01428 
01429                 $userContent['all'] = trim($this->cObj->getSubpart($this->templateCode, '###'.$key.'###'));
01430                 $adminContent['all'] = trim($this->cObj->getSubpart($this->templateCode, '###'.$key.'-ADMIN###'));
01431                 $userContent['rec'] = $this->cObj->getSubpart($userContent['all'], '###SUB_RECORD###');
01432                 $adminContent['rec'] = $this->cObj->getSubpart($adminContent['all'], '###SUB_RECORD###');
01433 
01434                 reset($DBrows);
01435                 while(list(,$r)=each($DBrows))  {
01436                         $markerArray = $this->cObj->fillInMarkerArray($this->markerArray, $r,'',0);
01437                         $markerArray = $this->setCObjects($userContent['rec'].$adminContent['rec'],$r,$markerArray,'ITEM_');
01438                         $markerArray['###SYS_AUTHCODE###'] = $this->authCode($r);
01439                         $markerArray = $this->setfixed($markerArray, $setFixedConfig, $r);
01440 
01441                         if ($userContent['rec'])        $userContent['accum'] .=$this->cObj->substituteMarkerArray($userContent['rec'], $markerArray);
01442                         if ($adminContent['rec'])       $adminContent['accum'].=$this->cObj->substituteMarkerArray($adminContent['rec'], $markerArray);
01443                 }
01444 
01445                 if ($userContent['all'])        $userContent['final'] .=$this->cObj->substituteSubpart($userContent['all'], '###SUB_RECORD###', $userContent['accum']);
01446                 if ($adminContent['all'])       $adminContent['final'].=$this->cObj->substituteSubpart($adminContent['all'], '###SUB_RECORD###', $adminContent['accum']);
01447 
01448                 if (t3lib_div::testInt($recipient))     {
01449                         $fe_userRec = $GLOBALS['TSFE']->sys_page->getRawRecord('fe_users',$recipient);
01450                         $recipient=$fe_userRec['email'];
01451                 }
01452 
01453                 $GLOBALS['TT']->setTSlogMessage('Template key: ###'.$key.'###, userContentLength: '.strlen($userContent['final']).', adminContentLength: '.strlen($adminContent['final']));
01454 
01455                 $this->sendMail($recipient, $this->conf['email.']['admin'], $userContent['final'], $adminContent['final']);
01456                 $GLOBALS['TT']->pull();
01457         }
01458 
01470         function sendMail($recipient, $admin, $content='', $adminContent='')    {
01471                         // Admin mail:
01472                 if ($admin && $adminContent)    {
01473                         if (!$this->isHTMLContent($adminContent))       {
01474                                 $admMail = $this->cObj->sendNotifyEmail($adminContent,
01475                                                                         $admin,
01476                                                                         '',
01477                                                                         $this->conf['email.']['from'],
01478                                                                         $this->conf['email.']['fromName'],
01479                                                                         $recipient
01480                                                         );
01481                         } else {
01482                                 $this->sendHTMLMail($adminContent,
01483                                                                         $admin,
01484                                                                         '',
01485                                                                         $this->conf['email.']['from'],
01486                                                                         $this->conf['email.']['fromName'],
01487                                                                         $recipient
01488                                                         );
01489                         }
01490                 }
01491                         // user mail:
01492                 if (!$this->isHTMLContent($content))    {
01493                         $this->cObj->sendNotifyEmail($content,
01494                                                                 $recipient,
01495                                                                 '',                     // ($admMail ? '' : $admin),            // If the special administration mail was not found and send, the regular is...
01496                                                                 $this->conf['email.']['from'],
01497                                                                 $this->conf['email.']['fromName']
01498                                                 );
01499                 } else {
01500                         $this->sendHTMLMail($content,
01501                                                                 $recipient,
01502                                                                 '',                     // ($admMail ? '' : $admin),            // If the special administration mail was not found and send, the regular is...
01503                                                                 $this->conf['email.']['from'],
01504                                                                 $this->conf['email.']['fromName']
01505                                                 );
01506                 }
01507         }
01508 
01515         function isHTMLContent($c)      {
01516                 $c = trim($c);
01517                 $first = strtolower(substr($c,0,6));
01518                 $last = strtolower(substr($c,-7));
01519                 if ($first.$last=='<html></html>')      return 1;
01520         }
01521 
01536         function sendHTMLMail($content,$recipient,$dummy,$fromEmail,$fromName,$replyTo='')      {
01537                 if (trim($recipient) && trim($content)) {
01538                         $cls=t3lib_div::makeInstanceClassName('t3lib_htmlmail');
01539                         if (class_exists($cls)) {       // If htmlmail lib is included, then generate a nice HTML-email
01540                                 $parts = spliti('<title>|</title>',$content,3);
01541                                 $subject = trim($parts[1]) ? trim($parts[1]) : 'TYPO3 FE Admin message';
01542 
01543                                 $Typo3_htmlmail = t3lib_div::makeInstance('t3lib_htmlmail');
01544                                 $Typo3_htmlmail->start();
01545                                 $Typo3_htmlmail->useBase64();
01546 
01547                                 $Typo3_htmlmail->subject = $subject;
01548                                 $Typo3_htmlmail->from_email = $fromEmail;
01549                                 $Typo3_htmlmail->from_name = $fromName;
01550                                 $Typo3_htmlmail->replyto_email = $replyTo ? $replyTo : $fromEmail;
01551                                 $Typo3_htmlmail->replyto_name = $replyTo ? '' : $fromName;
01552                                 $Typo3_htmlmail->organisation = '';
01553                                 $Typo3_htmlmail->priority = 3;
01554 
01555                                         // HTML
01556                                 $Typo3_htmlmail->theParts['html']['content'] = $content;        // Fetches the content of the page
01557                                 $Typo3_htmlmail->theParts['html']['path'] = '';
01558                                 $Typo3_htmlmail->extractMediaLinks();
01559                                 $Typo3_htmlmail->extractHyperLinks();
01560                                 $Typo3_htmlmail->fetchHTMLMedia();
01561                                 $Typo3_htmlmail->substMediaNamesInHTML(0);      // 0 = relative
01562                                 $Typo3_htmlmail->substHREFsInHTML();
01563                                 $Typo3_htmlmail->setHTML($Typo3_htmlmail->encodeMsg($Typo3_htmlmail->theParts['html']['content']));
01564 
01565                                         // PLAIN
01566                                 $Typo3_htmlmail->addPlain('');
01567 
01568                                         // SET Headers and Content
01569                                 $Typo3_htmlmail->setHeaders();
01570                                 $Typo3_htmlmail->setContent();
01571                                 $Typo3_htmlmail->setRecipient($recipient);
01572 
01573                 //              debug($Typo3_htmlmail->theParts);
01574                                 $Typo3_htmlmail->sendtheMail();
01575                         } else {
01576                                 debug('SYSTEM ERROR: No HTML-mail library loaded. Set "page.config.incT3Lib_htmlmail = 1" is your TypoScript template.');
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 
01602 
01603 
01604         /*****************************************
01605          *
01606          * Various helper functions
01607          *
01608          *****************************************/
01609 
01610 
01620         function aCAuth($r)     {
01621                 if ($this->authCode && !strcmp($this->authCode,$this->authCode($r)))    {
01622                         return true;
01623                 }
01624         }
01625 
01634         function authCode($r,$extra='') {
01635                 $l=$this->codeLength;
01636                 if ($this->conf['authcodeFields'])      {
01637                         $fieldArr = t3lib_div::trimExplode(',', $this->conf['authcodeFields'], 1);
01638                         $value='';
01639                         while(list(,$field)=each($fieldArr))    {
01640                                 $value.=$r[$field].'|';
01641                         }
01642                         $value.=$extra.'|'.$this->conf['authcodeFields.']['addKey'];
01643                         if ($this->conf['authcodeFields.']['addDate'])  {
01644                                 $value.='|'.date($this->conf['authcodeFields.']['addDate']);
01645                         }
01646                         $value.=$GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'];
01647                         return substr(md5($value), 0,$l);
01648                 }
01649         }
01650 
01660         function setfixed($markerArray, $setfixed, $r)  {
01661                 if (is_array($setfixed))        {
01662                         reset($setfixed);
01663                         while(list($theKey,$data)=each($setfixed))      {
01664                                 if (!strcmp($theKey,'DELETE'))  {
01665                                         $recCopy = $r;
01666                                         $string='&cmd=setfixed&sFK='.rawurlencode($theKey).'&rU='.$r['uid'];
01667                                         $string.='&aC='.$this->setfixedHash($recCopy,$data['_FIELDLIST']);
01668                                         $markerArray['###SYS_SETFIXED_DELETE###'] = $string;
01669                                         $markerArray['###SYS_SETFIXED_HSC_DELETE###'] = htmlspecialchars($string);
01670                                 } elseif (strstr($theKey,'.'))  {
01671                                         $theKey = substr($theKey,0,-1);
01672                                         if (is_array($data))    {
01673                                                 reset($data);
01674                                                 $recCopy = $r;
01675                                                 $string='&cmd=setfixed&sFK='.rawurlencode($theKey).'&rU='.$r['uid'];
01676                                                 while(list($fieldName,$fieldValue)=each($data)) {
01677                                                         $string.='&fD%5B'.$fieldName.'%5D='.rawurlencode($fieldValue);
01678                                                         $recCopy[$fieldName]=$fieldValue;
01679                                                 }
01680                                                 $string.='&aC='.$this->setfixedHash($recCopy,$data['_FIELDLIST']);
01681                                                 $markerArray['###SYS_SETFIXED_'.$theKey.'###'] = $string;
01682                                                 $markerArray['###SYS_SETFIXED_HSC_'.$theKey.'###'] = htmlspecialchars($string);
01683                                         }
01684                                 }
01685                         }
01686                 }
01687                 return $markerArray;
01688         }
01689 
01698         function setfixedHash($recCopy,$fields='')      {
01699                 if ($fields)    {
01700                         $fieldArr = t3lib_div::trimExplode(',',$fields,1);
01701                         reset($fieldArr);
01702                         while(list($k,$v)=each($fieldArr))      {
01703                                 $recCopy_temp[$k]=$recCopy[$v];
01704                         }
01705                 } else {
01706                         $recCopy_temp=$recCopy;
01707                 }
01708                 $encStr = implode('|',$recCopy_temp).'|'.$this->conf['authcodeFields.']['addKey'].'|'.$GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'];
01709                 $hash = substr(md5($encStr),0,$this->codeLength);
01710                 return $hash;
01711         }
01712 
01713 
01719         function isPreview()    {
01720                 return ($this->conf[$this->cmdKey.'.']['preview'] && $this->preview);
01721         }
01722 
01728         function createFileFuncObj()    {
01729                 if (!$this->fileFunc)   {
01730                         $this->fileFunc = t3lib_div::makeInstance('t3lib_basicFileFunctions');
01731                 }
01732         }
01733 
01739         function clearCacheIfSet()      {
01740                 if ($this->conf['clearCacheOfPages'])   {
01741                         $cc_pidList = $GLOBALS['TYPO3_DB']->cleanIntList($this->conf['clearCacheOfPages']);
01742                         $GLOBALS['TSFE']->clearPageCacheContent_pidList($cc_pidList);
01743                 }
01744         }
01745 
01754         function getFailure($theField, $theCmd, $label) {
01755                 return isset($this->conf['evalErrors.'][$theField.'.'][$theCmd]) ? $this->conf['evalErrors.'][$theField.'.'][$theCmd] : $label;
01756         }
01757 }
01758 
01759 
01760 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['media/scripts/fe_adminLib.inc'])   {
01761         include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['media/scripts/fe_adminLib.inc']);
01762 }
01763 ?>


Généré par L'expert TYPO3 avec  doxygen 1.4.6