[TASK] CGL FunctionCallArgumentSpacingTooMuchSpaceAfterComma
[Packages/TYPO3.CMS.git] / typo3 / sysext / cms / tslib / media / scripts / fe_adminLib.inc
1 <?php
2 /***************************************************************
3 *  Copyright notice
4 *
5 *  (c) 1999-2009 Kasper Skårhøj (kasperYYYY@typo3.com)
6 *  All rights reserved
7 *
8 *  This script is part of the TYPO3 project. The TYPO3 project is
9 *  free software; you can redistribute it and/or modify
10 *  it under the terms of the GNU General Public License as published by
11 *  the Free Software Foundation; either version 2 of the License, or
12 *  (at your option) any later version.
13 *
14 *  The GNU General Public License can be found at
15 *  http://www.gnu.org/copyleft/gpl.html.
16 *  A copy is found in the textfile GPL.txt and important notices to the license
17 *  from the author is found in LICENSE.txt distributed with these scripts.
18 *
19 *
20 *  This script is distributed in the hope that it will be useful,
21 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
22 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23 *  GNU General Public License for more details.
24 *
25 *  This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27 /**
28  * FE admin lib
29  *
30  * Revised for TYPO3 3.6 June/2003 by Kasper Skårhøj
31  *
32  * @author      Kasper Skårhøj <kasperYYYY@typo3.com>
33  */
34 /**
35  * This library provides a HTML-template file based framework for Front End creating/editing/deleting records authenticated by email or fe_user login.
36  * It is used in the extensions "direct_mail_subscription" and "feuser_admin" (and the deprecated(!) static template "plugin.feadmin.dmailsubscription" and "plugin.feadmin.fe_users" which are the old versions of these two extensions)
37  * Further the extensions "t3consultancies" and "t3references" also uses this library but contrary to the "direct_mail_subscription" and "feuser_admin" extensions which relies on external HTML templates which must be adapted these two extensions delivers the HTML template code from inside.
38  * Generally the fe_adminLib appears to be hard to use. Personally I feel turned off by all the template-file work involved and since it is very feature rich (and for that sake pretty stable!) there are lots of things that can go wrong - you feel. Therefore I like the concept used by "t3consultancies"/"t3references" since those extensions uses the library by supplying the HTML-template code automatically.
39  * Suggestions for improvement and streamlining is welcome so this powerful class could be used more and effectively.
40  *
41  * @author      Kasper Skårhøj <kasperYYYY@typo3.com>
42  * @package TYPO3
43  * @subpackage tslib
44  */
45 class user_feAdmin      {
46
47                 // External, static:
48         var $recInMarkersHSC = TRUE;            // If TRUE, values from the record put into markers going out into HTML will be passed through htmlspecialchars()!
49
50         var $dataArr = array();
51         var $failureMsg = array();
52         var $theTable = '';
53         var $thePid = 0;
54         var $markerArray = array();
55         var $templateCode='';
56         var $cObj;
57
58         var $cmd;
59         var $preview;
60         var $backURL;
61         var $recUid;
62         var $failure=0;         // is set if data did not have the required fields set.
63         var $error='';
64         var $saved=0;           // is set if data is saved
65         var $requiredArr;
66         var $currentArr = array();
67         var $previewLabel='';
68         var $nc = '';           // '&no_cache=1' if you want that parameter sent.
69         var $additionalUpdateFields='';
70         var $emailMarkPrefix = 'EMAIL_TEMPLATE_';
71         var $codeLength;
72         var $cmdKey;
73         var $fileFunc='';       // Set to a basic_filefunc object
74         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!
75
76                 // Internal vars, dynamic:
77         var $unlinkTempFiles = array();                 // Is loaded with all temporary filenames used for upload which should be deleted before exit...
78
79         /**
80          * Main function. Called from TypoScript.
81          * This
82          * - initializes internal variables,
83          * - fills in the markerArray with default substitution string
84          * - saves/emails if such commands are sent
85          * - calls functions for display of the screen for editing/creation/deletion etc.
86          *
87          * @param       string          Empty string, ignore.
88          * @param       array           TypoScript properties following the USER_INT object which uses this library
89          * @return      string          HTML content
90          */
91         function init($content,$conf) {
92                 $this->conf = $conf;
93
94                         // template file is fetched.
95                 $this->templateCode = $this->conf['templateContent'] ? $this->conf['templateContent'] : $this->cObj->fileResource($this->conf['templateFile']);
96
97                         // Getting the cmd var
98                 $this->cmd = (string)t3lib_div::_GP('cmd');
99                         // Getting the preview var
100                 $this->preview = (string)t3lib_div::_GP('preview');
101                         // backURL is a given URL to return to when login is performed
102                 $this->backURL = t3lib_div::_GP('backURL');
103                 if (strstr($this->backURL, '"') || strstr($this->backURL, "'") || preg_match('/(javascript|vbscript):/i', $this->backURL) || stristr($this->backURL, "fromcharcode") || strstr($this->backURL, "<") || strstr($this->backURL, ">")) {
104                         $this->backURL = '';    // Clear backURL if it seems to contain XSS code - only URLs are allowed
105                 }
106                         // Remove host from URL: Make sure that $this->backURL maps to the current site
107                 $this->backURL = preg_replace('|[A-Za-z]+://[^/]+|', '', $this->backURL);
108                         // Uid to edit:
109                 $this->recUid = t3lib_div::_GP('rU');
110                         // Authentication code:
111                 $this->authCode = t3lib_div::_GP('aC');
112                         // get table
113                 $this->theTable = $this->conf['table'];
114                         // link configuration
115                 $linkConf = is_array($this->conf['formurl.']) ? $this->conf['formurl.'] : array();
116                         // pid
117                 $this->thePid = intval($this->conf['pid']) ? intval($this->conf['pid']) : $GLOBALS['TSFE']->id;
118                         //
119                 $this->codeLength = intval($this->conf['authcodeFields.']['codeLength']) ? intval($this->conf['authcodeFields.']['codeLength']) : 8;
120
121                         // Setting the hardcoded lists of fields allowed for editing and creation.
122                 $this->fieldList=implode(',',t3lib_div::trimExplode(',',$GLOBALS['TCA'][$this->theTable]['feInterface']['fe_admin_fieldList'],1));
123
124                         // globally substituted markers, fonts and colors.
125                 $splitMark = md5(microtime());
126                 list($this->markerArray['###GW1B###'],$this->markerArray['###GW1E###']) = explode($splitMark,$this->cObj->stdWrap($splitMark,$this->conf['wrap1.']));
127                 list($this->markerArray['###GW2B###'],$this->markerArray['###GW2E###']) = explode($splitMark,$this->cObj->stdWrap($splitMark,$this->conf['wrap2.']));
128                 $this->markerArray['###GC1###'] = $this->cObj->stdWrap($this->conf['color1'],$this->conf['color1.']);
129                 $this->markerArray['###GC2###'] = $this->cObj->stdWrap($this->conf['color2'],$this->conf['color2.']);
130                 $this->markerArray['###GC3###'] = $this->cObj->stdWrap($this->conf['color3'],$this->conf['color3.']);
131
132                 if (intval($this->conf['no_cache']) && !isset($linkConf['no_cache']))   {       // needed for backwards compatibility
133                         $linkConf['no_cache'] = 1;
134                 }
135                 if(!$linkConf['parameter']) {
136                         $linkConf['parameter'] = $GLOBALS['TSFE']->id;
137                 }
138                 if(!$linkConf['additionalParams'])      {       // needed for backwards compatibility
139                         $linkConf['additionalParams'] = $this->conf['addParams'];
140                 }
141
142                 $formURL = $this->cObj->typoLink_URL($linkConf);
143                 if(!strstr($formURL,'?')) {
144                         $formURL .= '?';
145                 }
146
147                         // Initialize markerArray, setting FORM_URL and HIDDENFIELDS
148                 $this->markerArray['###FORM_URL###'] = $formURL;
149                 $this->markerArray['###FORM_URL_ENC###'] = rawurlencode($this->markerArray['###FORM_URL###']);
150                 $this->markerArray['###FORM_URL_HSC###'] = htmlspecialchars($this->markerArray['###FORM_URL###']);
151
152                 $this->markerArray['###BACK_URL###'] = $this->backURL;
153                 $this->markerArray['###BACK_URL_ENC###'] = rawurlencode($this->markerArray['###BACK_URL###']);
154                 $this->markerArray['###BACK_URL_HSC###'] = htmlspecialchars($this->markerArray['###BACK_URL###']);
155
156                 $this->markerArray['###THE_PID###'] = $this->thePid;
157                 $this->markerArray['###REC_UID###'] = $this->recUid;
158                 $this->markerArray['###AUTH_CODE###'] = $this->authCode;
159                 $this->markerArray['###THIS_ID###'] = $GLOBALS['TSFE']->id;
160                 $this->markerArray['###THIS_URL###'] = htmlspecialchars(t3lib_div::getIndpEnv('TYPO3_REQUEST_DIR'));
161                 $this->markerArray['###HIDDENFIELDS###'] =
162                         ($this->cmd?'<input type="hidden" name="cmd" value="'.htmlspecialchars($this->cmd).'" />':'').
163                         ($this->authCode?'<input type="hidden" name="aC" value="'.htmlspecialchars($this->authCode).'" />':'').
164                         ($this->backURL?'<input type="hidden" name="backURL" value="'.htmlspecialchars($this->backURL).'" />':'');
165
166
167                         // Setting cmdKey which is either 'edit' or 'create'
168                 switch($this->cmd) {
169                         case 'edit':
170                                 $this->cmdKey='edit';
171                         break;
172                         default:
173                                 $this->cmdKey='create';
174                         break;
175                 }
176                         // Setting requiredArr to the fields in 'required' intersected field the total field list in order to remove invalid fields.
177                 $this->requiredArr = array_intersect(
178                         t3lib_div::trimExplode(',',$this->conf[$this->cmdKey.'.']['required'],1),
179                         t3lib_div::trimExplode(',',$this->conf[$this->cmdKey.'.']['fields'],1)
180                 );
181
182                         // Setting incoming data. Non-stripped
183                 $fe=t3lib_div::_GP('FE');
184                 $this->dataArr = $fe[$this->theTable];  // Incoming data.
185
186                         // Checking template file and table value
187                 if (!$this->templateCode) {
188                         $content = 'No template file found: '.$this->conf['templateFile'];
189                         return $content;
190                 }
191
192                 if (!$this->theTable || !$this->fieldList) {
193                         $content = 'Wrong table: '.$this->theTable;
194                         return $content;                // Not listed or editable table!
195                 }
196
197                 // *****************
198                 // If data is submitted, we take care of it here.
199                 // *******************
200                 if ($this->cmd=='delete' && !$this->preview && !t3lib_div::_GP('doNotSave'))    {       // Delete record if delete command is sent + the preview flag is NOT set.
201                         $this->deleteRecord();
202                 }
203                         // If incoming data is seen...
204                 if (is_array($this->dataArr)) {
205                                 // Evaluation of data:
206                         $this->parseValues();
207                         $this->overrideValues();
208                         $this->evalValues();
209                         if ($this->conf['evalFunc']) {
210                                 $this->dataArr = $this->userProcess('evalFunc',$this->dataArr);
211                         }
212
213                                 // if not preview and no failures, then set data...
214                         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
215                                 $this->save();
216                         } else {
217                                 if ($this->conf['debug'])               debug($this->failure);
218                         }
219                 } else {
220                         $this->defaultValues(); // If no incoming data, this will set the default values.
221                         $this->preview = 0;     // No preview if data is not received
222                 }
223                 if ($this->failure)     {$this->preview=0;}     // No preview flag if a evaluation failure has occured
224                 $this->previewLabel = $this->preview ? '_PREVIEW' : ''; // Setting preview label prefix.
225
226
227                         // *********************
228                         // DISPLAY FORMS:
229                         // ***********************
230                 if ($this->saved) {
231                                 // Clear page cache
232                         $this->clearCacheIfSet();
233
234                                 // Displaying the page here that says, the record has been saved. You're able to include the saved values by markers.
235                         switch($this->cmd) {
236                                 case 'delete':
237                                         $key='DELETE';
238                                 break;
239                                 case 'edit':
240                                         $key='EDIT';
241                                 break;
242                                 default:
243                                         $key='CREATE';
244                                 break;
245                         }
246                                 // Output message
247                         $templateCode = $this->cObj->getSubpart($this->templateCode, '###TEMPLATE_'.$key.'_SAVED###');
248                         $this->setCObjects($templateCode,$this->currentArr);
249                         $markerArray = $this->cObj->fillInMarkerArray($this->markerArray, $this->currentArr, '', TRUE, 'FIELD_', $this->recInMarkersHSC);
250                         $content = $this->cObj->substituteMarkerArray($templateCode, $markerArray);
251
252                                 // email message:
253                         $this->compileMail(
254                                 $key.'_SAVED',
255                                 array($this->currentArr),
256                                 $this->currentArr[$this->conf['email.']['field']],
257                                 $this->conf['setfixed.']
258                         );
259
260                 } elseif ($this->error) {       // If there was an error, we return the template-subpart with the error message
261                         $templateCode = $this->cObj->getSubpart($this->templateCode, $this->error);
262                         $this->setCObjects($templateCode);
263                         $content = $this->cObj->substituteMarkerArray($templateCode, $this->markerArray);
264                 } else {
265                                 // Finally, if there has been no attempt to save. That is either preview or just displaying and empty or not correctly filled form:
266                         if (!$this->cmd) {
267                                 $this->cmd=$this->conf['defaultCmd'];
268                         }
269                         if ($this->conf['debug'])               debug('Display form: '.$this->cmd,1);
270                         switch($this->cmd) {
271                                 case 'setfixed':
272                                         $content = $this->procesSetFixed();
273                                 break;
274                                 case 'infomail':
275                                         $content = $this->sendInfoMail();
276                                 break;
277                                 case 'delete':
278                                         $content = $this->displayDeleteScreen();
279                                 break;
280                                 case 'edit':
281                                         $content = $this->displayEditScreen();
282                                 break;
283                                 case 'create':
284                                         $content = $this->displayCreateScreen();
285                                 break;
286                         }
287                 }
288
289                         // Delete temp files:
290                 foreach($this->unlinkTempFiles as $tempFileName) {
291                         t3lib_div::unlink_tempfile($tempFileName);
292                 }
293
294                         // Return content:
295                 return $content;
296         }
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320         /*****************************************
321          *
322          * Data processing
323          *
324          *****************************************/
325
326         /**
327          * Performs processing on the values found in the input data array, $this->dataArr.
328          * The processing is done according to configuration found in TypoScript
329          * Examples of this could be to force a value to an integer, remove all non-alphanumeric characters, trimming a value, upper/lowercase it, or process it due to special types like files submitted etc.
330          * Called from init() if the $this->dataArr is found to be an array
331          *
332          * @return      void
333          * @see init()
334          */
335         function parseValues() {
336                 if (is_array($this->conf['parseValues.'])) {
337                         foreach ($this->conf['parseValues.'] as $theField => $theValue) {
338                                 $listOfCommands = t3lib_div::trimExplode(',',$theValue,1);
339                                 foreach ($listOfCommands as $cmd) {
340                                         $cmdParts = preg_split('/\[|\]/', $cmd);        // Point is to enable parameters after each command enclosed in brackets [..]. These will be in position 1 in the array.
341                                         $theCmd=trim($cmdParts[0]);
342                                         switch($theCmd) {
343                                                 case 'int':
344                                                         $this->dataArr[$theField]=intval($this->dataArr[$theField]);
345                                                 break;
346                                                 case 'lower':
347                                                 case 'upper':
348                                                         $this->dataArr[$theField] = $this->cObj->caseshift($this->dataArr[$theField],$theCmd);
349                                                 break;
350                                                 case 'nospace':
351                                                         $this->dataArr[$theField] = str_replace(' ', '', $this->dataArr[$theField]);
352                                                 break;
353                                                 case 'alpha':
354                                                         $this->dataArr[$theField] = preg_replace('/[^a-zA-Z]/','',$this->dataArr[$theField]);
355                                                 break;
356                                                 case 'num':
357                                                         $this->dataArr[$theField] = preg_replace('/[^0-9]/','',$this->dataArr[$theField]);
358                                                 break;
359                                                 case 'alphanum':
360                                                         $this->dataArr[$theField] = preg_replace('/[^a-zA-Z0-9]/','',$this->dataArr[$theField]);
361                                                 break;
362                                                 case 'alphanum_x':
363                                                         $this->dataArr[$theField] = preg_replace('/[^a-zA-Z0-9_-]/','',$this->dataArr[$theField]);
364                                                 break;
365                                                 case 'trim':
366                                                         $this->dataArr[$theField] = trim($this->dataArr[$theField]);
367                                                 break;
368                                                 case 'random':
369                                                         $this->dataArr[$theField] = substr(md5(uniqid(microtime(),1)),0,intval($cmdParts[1]));
370                                                 break;
371                                                 case 'files':
372                                                         if ($this->cmdKey=='create' && !t3lib_div::_GP('doNotSave')) {
373                                                                 $this->processFiles($cmdParts,$theField);
374                                                         } else unset($this->dataArr[$theField]);        // Fields with files cannot be edited - only created.
375                                                 break;
376                                                 case 'setEmptyIfAbsent':
377                                                         if (!isset($this->dataArr[$theField])) {
378                                                                 $this->dataArr[$theField]='';
379                                                         }
380                                                 break;
381                                                 case 'multiple':
382                                                         if (is_array($this->dataArr[$theField])) {
383                                                                 $this->dataArr[$theField] = implode(',',$this->dataArr[$theField]);
384                                                         }
385                                                 break;
386                                                 case 'checkArray':
387                                                         if (is_array($this->dataArr[$theField])) {
388                                                                 $val = 0;
389                                                                 foreach ($this->dataArr[$theField] as $kk => $vv) {
390                                                                         $kk = t3lib_utility_Math::forceIntegerInRange($kk,0);
391                                                                         if ($kk<=30) {
392                                                                                 if ($vv) {
393                                                                                         $val|=pow(2,$kk);
394                                                                                 }
395                                                                         }
396                                                                 }
397                                                                 $this->dataArr[$theField] = $val;
398                                                         } else {$this->dataArr[$theField]=0;}
399                                                 break;
400                                                 case 'uniqueHashInt':
401                                                         $otherFields = t3lib_div::trimExplode(';',$cmdParts[1],1);
402                                                         $hashArray=array();
403                                                         foreach ($otherFields as $fN) {
404                                                                 $vv = $this->dataArr[$fN];
405                                                                 $vv = preg_replace('/[[:space:]]/','',$vv);
406                                                                 $vv = preg_replace('/[^[:alnum:]]/','',$vv);
407                                                                 $vv = strtolower($vv);
408                                                                 $hashArray[]=$vv;
409                                                         }
410                                                         $this->dataArr[$theField]=hexdec(substr(md5(serialize($hashArray)),0,8));
411                                                 break;
412                                         }
413                                 }
414                         }
415                 }
416         }
417
418         /**
419          * Processing of files.
420          * NOTICE: for now files can be handled only on creation of records. But a more advanced feature is that PREVIEW of files is handled.
421          *
422          * @param       array           Array with cmd-parts (from parseValues()). This will for example contain information about allowed file extensions and max size of uploaded files.
423          * @param       string          The fieldname with the files.
424          * @return      void
425          * @access private
426          * @see parseValues()
427          */
428         function processFiles($cmdParts,$theField) {
429                         // First, make an array with the filename and file reference, whether the file is just uploaded or a preview
430                 $filesArr = array();
431
432                 if (is_string($this->dataArr[$theField]))       {               // files from preview.
433                         $tmpArr = explode(',',$this->dataArr[$theField]);
434                         foreach ($tmpArr as $val) {
435                                 $valParts = explode('|',$val);
436                                 $filesArr[] = array (
437                                         'name'=>$valParts[1],
438                                         'tmp_name'=>PATH_site.'typo3temp/'.$valParts[0]
439                                 );
440                         }
441                 } elseif (is_array($_FILES['FE'][$this->theTable][$theField]['name']))  {       // Files from upload
442                         foreach ($_FILES['FE'][$this->theTable][$theField]['name'] as $kk => $vv) {
443                                 if ($vv) {
444                                         $tmpFile = t3lib_div::upload_to_tempfile($_FILES['FE'][$this->theTable][$theField]['tmp_name'][$kk]);
445                                         if ($tmpFile) {
446                                                 $this->unlinkTempFiles[]=$tmpFile;
447                                                 $filesArr[] = array (
448                                                         'name'=>$vv,
449                                                         'tmp_name'=>$tmpFile
450                                                 );
451                                         }
452                                 }
453                         }
454                 } elseif (is_array($_FILES['FE']['name'][$this->theTable][$theField]))  {       // Files from upload
455                         foreach ($_FILES['FE']['name'][$this->theTable][$theField] as $kk => $vv) {
456                                 if ($vv) {
457                                         $tmpFile = t3lib_div::upload_to_tempfile($_FILES['FE']['tmp_name'][$this->theTable][$theField][$kk]);
458                                         if ($tmpFile) {
459                                                 $this->unlinkTempFiles[]=$tmpFile;
460                                                 $filesArr[] = array (
461                                                         'name'=>$vv,
462                                                         'tmp_name'=>$tmpFile
463                                                 );
464                                         }
465                                 }
466                         }
467                 }
468
469                         // Then verify the files in that array; check existence, extension and size
470                 $this->dataArr[$theField]='';
471                 $finalFilesArr=array();
472                 if (count($filesArr)) {
473                         $extArray = t3lib_div::trimExplode(';',strtolower($cmdParts[1]),1);
474                         $maxSize = intval($cmdParts[3]);
475                         foreach ($filesArr as $infoArr) {
476                                 $fI = pathinfo($infoArr['name']);
477                                 if (t3lib_div::verifyFilenameAgainstDenyPattern($fI['name'])) {
478                                         if (!count($extArray) || in_array(strtolower($fI['extension']), $extArray)) {
479                                                 $tmpFile = $infoArr['tmp_name'];
480                                                 if (@is_file($tmpFile)) {
481                                                         if (!$maxSize || filesize($tmpFile)<$maxSize*1024) {
482                                                                 $finalFilesArr[]=$infoArr;
483                                                         } elseif ($this->conf['debug']) {debug('Size is beyond '.$maxSize.' kb ('.filesize($tmpFile).' bytes) and the file cannot be saved.');}
484                                                 } elseif ($this->conf['debug']) {debug('Surprisingly there was no file for '.$vv.' in '.$tmpFile);}
485                                         } elseif ($this->conf['debug']) {debug('Extension "'.$fI['extension'].'" not allowed');}
486                                 } elseif ($this->conf['debug']) {debug('Filename matched illegal pattern.');}
487                         }
488                 }
489                         // Copy the files in the resulting array to the proper positions based on preview/non-preview.
490                 $fileNameList=array();
491                 foreach ($finalFilesArr as $infoArr) {
492                         if ($this->isPreview()) {               // If the form is a preview form (and data is therefore not going into the database...) do this.
493                                 $this->createFileFuncObj();
494                                 $fI = pathinfo($infoArr['name']);
495                                 $tmpFilename = $this->theTable.'_'.t3lib_div::shortmd5(uniqid($infoArr['name'])).'.'.$fI['extension'];
496                                 $theDestFile = $this->fileFunc->getUniqueName($this->fileFunc->cleanFileName($tmpFilename), PATH_site.'typo3temp/');
497                                 t3lib_div::upload_copy_move($infoArr['tmp_name'],$theDestFile);
498                                         // Setting the filename in the list
499                                 $fI2 = pathinfo($theDestFile);
500                                 $fileNameList[] = $fI2['basename'].'|'.$infoArr['name'];
501                         } else {
502                                 $this->createFileFuncObj();
503                                 $GLOBALS['TSFE']->includeTCA();
504                                 t3lib_div::loadTCA($this->theTable);
505                                 if (is_array($GLOBALS['TCA'][$this->theTable]['columns'][$theField])) {
506                                         $uploadPath = $GLOBALS['TCA'][$this->theTable]['columns'][$theField]['config']['uploadfolder'];
507                                 }
508                                 if ($uploadPath) {
509                                         $theDestFile = $this->fileFunc->getUniqueName($this->fileFunc->cleanFileName($infoArr['name']), PATH_site.$uploadPath);
510                                         t3lib_div::upload_copy_move($infoArr['tmp_name'],$theDestFile);
511                                                 // Setting the filename in the list
512                                         $fI2 = pathinfo($theDestFile);
513                                         $fileNameList[] = $fI2['basename'];
514                                         $this->filesStoredInUploadFolders[]=$theDestFile;
515                                 }
516                         }
517                                 // Implode the list of filenames
518                         $this->dataArr[$theField] = implode(',',$fileNameList);
519                 }
520         }
521
522         /**
523          * Overriding values in $this->dataArr if configured for that in TypoScript ([edit/create].overrideValues)
524          *
525          * @return      void
526          * @see init()
527          */
528         function overrideValues() {
529                 // Addition of overriding values
530                 if (is_array($this->conf[$this->cmdKey.'.']['overrideValues.'])) {
531                         foreach ($this->conf[$this->cmdKey.'.']['overrideValues.'] as $theField => $theValue) {
532                                 $this->dataArr[$theField] = $theValue;
533                         }
534                 }
535         }
536
537         /**
538          * Called if there is no input array in $this->dataArr. Then this function sets the default values configured in TypoScript
539          *
540          * @return      void
541          * @see init()
542          */
543         function defaultValues() {
544                         // Addition of default values
545                 if (is_array($this->conf[$this->cmdKey.'.']['defaultValues.'])) {
546                         foreach ($this->conf[$this->cmdKey.'.']['defaultValues.'] as $theField => $theValue) {
547                                 $this->dataArr[$theField] = $theValue;
548                         }
549                 }
550         }
551
552         /**
553          * This will evaluate the input values from $this->dataArr to see if they conforms with the requirements configured in TypoScript per field.
554          * For example this could be checking if a field contains a valid email address, a unique value, a value within a certain range etc.
555          * It will populate arrays like $this->failure and $this->failureMsg with error messages (which can later be displayed in the template). Mostly it does NOT alter $this->dataArr (such parsing of values was done by parseValues())
556          * Works based on configuration in TypoScript key [create/edit].evalValues
557          *
558          * @return      void
559          * @see init(), parseValues()
560          */
561         function evalValues() {
562                 // Check required, set failure if not ok.
563                 $tempArr=array();
564                 foreach ($this->requiredArr as $theField) {
565                         if (!trim($this->dataArr[$theField])) {
566                                 $tempArr[]=$theField;
567                         }
568                 }
569
570                 // 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!
571                 $recExist=0;
572                 if (is_array($this->conf[$this->cmdKey.'.']['evalValues.'])) {
573                         switch($this->cmd) {
574                                 case 'edit':
575                                         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.
576                                                 $recordTestPid = intval($this->dataArr['pid']);
577                                         } else {
578                                                 $tempRecArr = $GLOBALS['TSFE']->sys_page->getRawRecord($this->theTable,$this->dataArr['uid']);
579                                                 $recordTestPid = intval($tempRecArr['pid']);
580                                         }
581                                         $recExist=1;
582                                 break;
583                                 default:
584                                         $recordTestPid = $this->thePid ? $this->thePid : t3lib_utility_Math::convertToPositiveInteger($this->dataArr['pid']);
585                                 break;
586                         }
587
588                         foreach ($this->conf[$this->cmdKey.'.']['evalValues.'] as $theField => $theValue) {
589                                 $listOfCommands = t3lib_div::trimExplode(',',$theValue,1);
590                                 foreach ($listOfCommands as $cmd) {
591                                         $cmdParts = preg_split('/\[|\]/', $cmd);        // Point is to enable parameters after each command enclosed in brackets [..]. These will be in position 1 in the array.
592                                         $theCmd = trim($cmdParts[0]);
593                                         switch($theCmd) {
594                                                 case 'uniqueGlobal':
595                                                         if ($DBrows = $GLOBALS['TSFE']->sys_page->getRecordsByField($this->theTable,$theField,$this->dataArr[$theField],'','','','1')) {
596                                                                 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.
597                                                                         $tempArr[]=$theField;
598                                                                         $this->failureMsg[$theField][] = $this->getFailure($theField, $theCmd, 'The value existed already. Enter a new value.');
599                                                                 }
600                                                         }
601                                                 break;
602                                                 case 'uniqueLocal':
603                                                         if ($DBrows = $GLOBALS['TSFE']->sys_page->getRecordsByField($this->theTable,$theField,$this->dataArr[$theField], 'AND pid IN ('.$recordTestPid.')','','','1')) {
604                                                                 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.
605                                                                         $tempArr[]=$theField;
606                                                                         $this->failureMsg[$theField][] = $this->getFailure($theField, $theCmd, 'The value existed already. Enter a new value.');
607                                                                 }
608                                                         }
609                                                 break;
610                                                 case 'twice':
611                                                         if (strcmp($this->dataArr[$theField], $this->dataArr[$theField.'_again'])) {
612                                                                 $tempArr[]=$theField;
613                                                                 $this->failureMsg[$theField][] = $this->getFailure($theField, $theCmd, 'You must enter the same value twice');
614                                                         }
615                                                 break;
616                                                 case 'email':
617                                                         if (!t3lib_div::validEmail($this->dataArr[$theField])) {
618                                                                 $tempArr[]=$theField;
619                                                                 $this->failureMsg[$theField][] = $this->getFailure($theField, $theCmd, 'You must enter a valid email address');
620                                                         }
621                                                 break;
622                                                 case 'required':
623                                                         if (!trim($this->dataArr[$theField])) {
624                                                                 $tempArr[]=$theField;
625                                                                 $this->failureMsg[$theField][] = $this->getFailure($theField, $theCmd, 'You must enter a value!');
626                                                         }
627                                                 break;
628                                                 case 'atLeast':
629                                                         $chars=intval($cmdParts[1]);
630                                                         if (strlen($this->dataArr[$theField])<$chars) {
631                                                                 $tempArr[]=$theField;
632                                                                 $this->failureMsg[$theField][] = sprintf($this->getFailure($theField, $theCmd, 'You must enter at least %s characters!'), $chars);
633                                                         }
634                                                 break;
635                                                 case 'atMost':
636                                                         $chars=intval($cmdParts[1]);
637                                                         if (strlen($this->dataArr[$theField])>$chars) {
638                                                                 $tempArr[]=$theField;
639                                                                 $this->failureMsg[$theField][] = sprintf($this->getFailure($theField, $theCmd, 'You must enter at most %s characters!'), $chars);
640                                                         }
641                                                 break;
642                                                 case 'inBranch':
643                                                         $pars = explode(';',$cmdParts[1]);
644                                                         if (intval($pars[0])) {
645                                                                 $pid_list = $this->cObj->getTreeList(
646                                                                         intval($pars[0]),
647                                                                         intval($pars[1]) ? intval($pars[1]) : 999,
648                                                                         intval($pars[2])
649                                                                 );
650                                                                 if (!$pid_list || !t3lib_div::inList($pid_list,$this->dataArr[$theField])) {
651                                                                         $tempArr[]=$theField;
652                                                                         $this->failureMsg[$theField][] = sprintf($this->getFailure($theField, $theCmd, 'The value was not a valid valud from this list: %s'), $pid_list);
653                                                                 }
654                                                         }
655                                                 break;
656                                                 case 'unsetEmpty':
657                                                         if (!$this->dataArr[$theField]) {
658                                                                 $hash = array_flip($tempArr);
659                                                                 unset($hash[$theField]);
660                                                                 $tempArr = array_keys($hash);
661                                                                 unset($this->failureMsg[$theField]);
662                                                                 unset($this->dataArr[$theField]);       // This should prevent the field from entering the database.
663                                                         }
664                                                 break;
665                                         }
666                                 }
667                                 $this->markerArray['###EVAL_ERROR_FIELD_'.$theField.'###'] = is_array($this->failureMsg[$theField]) ? implode('<br />',$this->failureMsg[$theField]) : '';
668                         }
669                 }
670                 $this->failure=implode(',',$tempArr);    //$failure will show which fields were not OK
671         }
672
673         /**
674          * Preforms user processing of input array - triggered right after the function call to evalValues() IF TypoScript property "evalFunc" was set.
675          *
676          * @param       string          Key pointing to the property in TypoScript holding the configuration for this processing (here: "evalFunc.*"). Well: at least its safe to say that "parentObj" in this array passed to the function is a reference back to this object.
677          * @param       array           The $this->dataArr passed for processing
678          * @return      array           The processed $passVar ($this->dataArr)
679          * @see init(), evalValues()
680          */
681         function userProcess($mConfKey,$passVar) {
682                 if ($this->conf[$mConfKey]) {
683                         $funcConf = $this->conf[$mConfKey.'.'];
684                         $funcConf['parentObj'] = $this;
685                         $passVar = $GLOBALS['TSFE']->cObj->callUserFunction($this->conf[$mConfKey], $funcConf, $passVar);
686                 }
687                 return $passVar;
688         }
689
690         /**
691          * User processing of contnet
692          *
693          * @param       string          Value of the TypoScript object triggering the processing.
694          * @param       array           Properties of the TypoScript object triggering the processing. The key "parentObj" in this array is passed to the function as a reference back to this object.
695          * @param       mixed           Input variable to process
696          * @return      mixed           Processed input variable, $passVar
697          * @see userProcess(), save(), modifyDataArrForFormUpdate()
698          */
699         function userProcess_alt($confVal,$confArr,$passVar) {
700                 if ($confVal) {
701                         $funcConf = $confArr;
702                         $funcConf['parentObj'] = $this;
703                         $passVar = $GLOBALS['TSFE']->cObj->callUserFunction($confVal, $funcConf, $passVar);
704                 }
705                 return $passVar;
706         }
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729         /*****************************************
730          *
731          * Database manipulation functions
732          *
733          *****************************************/
734
735         /**
736          * Performs the saving of records, either edited or created.
737          *
738          * @return      void
739          * @see init()
740          */
741         function save() {
742                 switch($this->cmd) {
743                         case 'edit':
744                                 $theUid = $this->dataArr['uid'];
745                                 $origArr = $GLOBALS['TSFE']->sys_page->getRawRecord($this->theTable,$theUid);           // Fetches the original record to check permissions
746                                 if ($this->conf['edit'] && ($GLOBALS['TSFE']->loginUser || $this->aCAuth($origArr)))    {       // Must be logged in in order to edit  (OR be validated by email)
747                                         $newFieldList = implode(',',array_intersect(explode(',',$this->fieldList),t3lib_div::trimExplode(',',$this->conf['edit.']['fields'],1)));
748                                         if ($this->aCAuth($origArr) || $this->cObj->DBmayFEUserEdit($this->theTable,$origArr,$GLOBALS['TSFE']->fe_user->user,$this->conf['allowedGroups'],$this->conf['fe_userEditSelf'])) {
749                                                 $this->cObj->DBgetUpdate($this->theTable, $theUid, $this->dataArr, $newFieldList, TRUE);
750                                                 $this->currentArr = $GLOBALS['TSFE']->sys_page->getRawRecord($this->theTable,$theUid);
751                                                 $this->userProcess_alt($this->conf['edit.']['userFunc_afterSave'],$this->conf['edit.']['userFunc_afterSave.'],array('rec'=>$this->currentArr, 'origRec'=>$origArr));
752                                                 $this->saved=1;
753                                         } else {
754                                                 $this->error='###TEMPLATE_NO_PERMISSIONS###';
755                                         }
756                                 }
757                         break;
758                         default:
759                                 if ($this->conf['create']) {
760                                         $newFieldList = implode(',',array_intersect(explode(',',$this->fieldList),t3lib_div::trimExplode(',',$this->conf['create.']['fields'],1)));
761                                         $this->cObj->DBgetInsert($this->theTable, $this->thePid, $this->dataArr, $newFieldList, TRUE);
762                                         $newId = $GLOBALS['TYPO3_DB']->sql_insert_id();
763
764                                         if ($this->theTable=='fe_users' && $this->conf['fe_userOwnSelf'])       {               // enables users, creating logins, to own them self.
765                                                 $extraList='';
766                                                 $dataArr = array();
767                                                 if ($GLOBALS['TCA'][$this->theTable]['ctrl']['fe_cruser_id'])           {
768                                                         $field=$GLOBALS['TCA'][$this->theTable]['ctrl']['fe_cruser_id'];
769                                                         $dataArr[$field]=$newId;
770                                                         $extraList.=','.$field;
771                                                 }
772                                                 if ($GLOBALS['TCA'][$this->theTable]['ctrl']['fe_crgroup_id']) {
773                                                         $field=$GLOBALS['TCA'][$this->theTable]['ctrl']['fe_crgroup_id'];
774                                                         list($dataArr[$field])=explode(',',$this->dataArr['usergroup']);
775                                                         $dataArr[$field]=intval($dataArr[$field]);
776                                                         $extraList.=','.$field;
777                                                 }
778                                                 if (count($dataArr)) {
779                                                         $this->cObj->DBgetUpdate($this->theTable, $newId, $dataArr, $extraList, TRUE);
780                                                 }
781                                         }
782
783                                         $this->currentArr = $GLOBALS['TSFE']->sys_page->getRawRecord($this->theTable,$newId);
784                                         $this->userProcess_alt($this->conf['create.']['userFunc_afterSave'],$this->conf['create.']['userFunc_afterSave.'],array('rec'=>$this->currentArr));
785                                         $this->saved=1;
786                                 }
787                         break;
788                 }
789         }
790
791         /**
792          * Deletes the record from table/uid, $this->theTable/$this->recUid, IF the fe-user has permission to do so.
793          * If the deleted flag should just be set, then it is done so. Otherwise the record truely is deleted along with any attached files.
794          * Called from init() if "cmd" was set to "delete" (and some other conditions)
795          *
796          * @return      string          void
797          * @see init()
798          */
799         function deleteRecord() {
800                 if ($this->conf['delete'])      {       // If deleting is enabled
801                         $origArr = $GLOBALS['TSFE']->sys_page->getRawRecord($this->theTable, $this->recUid);
802                         if ($GLOBALS['TSFE']->loginUser || $this->aCAuth($origArr))     {       // Must be logged in OR be authenticated by the aC code in order to delete
803                                         // If the recUid selects a record.... (no check here)
804                                 if (is_array($origArr)) {
805                                         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.
806                                                 if (!$GLOBALS['TCA'][$this->theTable]['ctrl']['delete'])        {       // If the record is fully deleted... then remove the image (or any file) attached.
807                                                         $this->deleteFilesFromRecord($this->recUid);
808                                                 }
809                                                 $this->cObj->DBgetDelete($this->theTable, $this->recUid, TRUE);
810                                                 $this->currentArr = $origArr;
811                                                 $this->saved = 1;
812                                         } else {
813                                                 $this->error = '###TEMPLATE_NO_PERMISSIONS###';
814                                         }
815                                 }
816                         }
817                 }
818         }
819
820         /**
821          * Deletes the files attached to a record and updates the record.
822          * Table/uid is $this->theTable/$uid
823          *
824          * @param       integer         Uid number of the record to delete from $this->theTable
825          * @return      void
826          * @access private
827          * @see deleteRecord()
828          */
829         function deleteFilesFromRecord($uid) {
830                 $table = $this->theTable;
831                 $rec = $GLOBALS['TSFE']->sys_page->getRawRecord($table,$uid);
832
833                 $GLOBALS['TSFE']->includeTCA();
834                 t3lib_div::loadTCA($table);
835                 $iFields=array();
836                 foreach ($GLOBALS['TCA'][$table]['columns'] as $field => $conf) {
837                         if ($conf['config']['type']=='group' && $conf['config']['internal_type']=='file') {
838
839                                 $GLOBALS['TYPO3_DB']->exec_UPDATEquery($table, 'uid='.intval($uid), array($field => ''));
840
841                                 $delFileArr = explode(',',$rec[$field]);
842                                 foreach ($delFileArr as $n) {
843                                         if ($n) {
844                                                 $fpath = $conf['config']['uploadfolder'].'/'.$n;
845                                                 unlink($fpath);
846                                         }
847                                 }
848                         }
849                 }
850         }
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872         /*****************************************
873          *
874          * Command "display" functions
875          *
876          *****************************************/
877
878         /**
879          * Creates the preview display of delete actions
880          *
881          * @return      string          HTML content
882          * @see init()
883          */
884         function displayDeleteScreen() {
885                 if ($this->conf['delete'])      {       // If deleting is enabled
886                         $origArr = $GLOBALS['TSFE']->sys_page->getRawRecord($this->theTable, $this->recUid);
887                         if ($GLOBALS['TSFE']->loginUser || $this->aCAuth($origArr))     {       // Must be logged in OR be authenticated by the aC code in order to delete
888                                         // If the recUid selects a record.... (no check here)
889                                 if (is_array($origArr)) {
890                                         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.
891                                                 $this->markerArray['###HIDDENFIELDS###'].= '<input type="hidden" name="rU" value="'.$this->recUid.'" />';
892                                                 $content = $this->getPlainTemplate('###TEMPLATE_DELETE_PREVIEW###', $origArr);
893                                         } else {        // Else display error, that you could not edit that particular record...
894                                                 $content = $this->getPlainTemplate('###TEMPLATE_NO_PERMISSIONS###');
895                                         }
896                                 }
897                         } 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.
898                                 $content = $this->getPlainTemplate('###TEMPLATE_AUTH###');
899                         }
900                 } else {
901                         $content.='Delete-option is not set in TypoScript';
902                 }
903                 return $content;
904         }
905
906         /**
907          * Creates the "create" screen for records
908          *
909          * @return      string          HTML content
910          * @see init()
911          */
912         function displayCreateScreen() {
913                 if ($this->conf['create']) {
914                         $templateCode = $this->cObj->getSubpart($this->templateCode, ((!$GLOBALS['TSFE']->loginUser || $this->conf['create.']['noSpecialLoginForm'])?'###TEMPLATE_CREATE'.$this->previewLabel.'###':'###TEMPLATE_CREATE_LOGIN'.$this->previewLabel.'###'));
915                         $failure = t3lib_div::_GP('noWarnings')?'':$this->failure;
916                         if (!$failure)  $templateCode = $this->cObj->substituteSubpart($templateCode, '###SUB_REQUIRED_FIELDS_WARNING###', '');
917
918                         $templateCode = $this->removeRequired($templateCode,$failure);
919                         $this->setCObjects($templateCode);
920
921                         if (!is_array($this->dataArr)) {
922                                 $this->dataArr = array();
923                         }
924
925                         $markerArray = $this->cObj->fillInMarkerArray($this->markerArray, $this->dataArr, '', TRUE, 'FIELD_', $this->recInMarkersHSC);
926                         if ($this->conf['create.']['preview'] && !$this->previewLabel)  {$markerArray['###HIDDENFIELDS###'].= '<input type="hidden" name="preview" value="1" />';}
927                         $content = $this->cObj->substituteMarkerArray($templateCode, $markerArray);
928                         $content.=$this->cObj->getUpdateJS($this->modifyDataArrForFormUpdate($this->dataArr), $this->theTable.'_form', 'FE['.$this->theTable.']', $this->fieldList.$this->additionalUpdateFields);
929                 }
930                 return $content;
931         }
932
933         /**
934          * Creates the edit-screen for records
935          *
936          * @return      string          HTML content
937          * @see init()
938          */
939         function displayEditScreen() {
940                 if ($this->conf['edit'])        {       // If editing is enabled
941                         $origArr = $GLOBALS['TSFE']->sys_page->getRawRecord($this->theTable, $this->dataArr['uid']?$this->dataArr['uid']:$this->recUid);
942
943                         if ($GLOBALS['TSFE']->loginUser || $this->aCAuth($origArr))     {       // Must be logged in OR be authenticated by the aC code in order to edit
944                                         // If the recUid selects a record.... (no check here)
945                                 if (is_array($origArr)) {
946                                         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.
947                                                 $content=$this->displayEditForm($origArr);
948                                         } else {        // Else display error, that you could not edit that particular record...
949                                                 $content = $this->getPlainTemplate('###TEMPLATE_NO_PERMISSIONS###');
950                                         }
951                                 } elseif ($GLOBALS['TSFE']->loginUser) {        // If the recUid did not select a record, we display a menu of records. (eg. if no recUid)
952                                         $lockPid = $this->conf['edit.']['menuLockPid'] ? ' AND pid='.intval($this->thePid) : '';
953
954                                         $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));
955
956                                         if ($GLOBALS['TYPO3_DB']->sql_num_rows($res))   {       // If there are menu-items ...
957                                                 $templateCode = $this->getPlainTemplate('###TEMPLATE_EDITMENU###');
958                                                 $out='';
959                                                 $itemCode = $this->cObj->getSubpart($templateCode, '###ITEM###');
960                                                 while($menuRow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
961                                                         $markerArray = $this->cObj->fillInMarkerArray(array(), $menuRow, '', TRUE, 'FIELD_', $this->recInMarkersHSC);
962                                                         $markerArray = $this->setCObjects($itemCode,$menuRow,$markerArray,'ITEM_');
963                                                         $out.= $this->cObj->substituteMarkerArray($itemCode, $markerArray);
964                                                 }
965                                                 $content=$this->cObj->substituteSubpart($templateCode, '###ALLITEMS###', $out);
966                                         } else {        // If there are not menu items....
967                                                 $content = $this->getPlainTemplate('###TEMPLATE_EDITMENU_NOITEMS###');
968                                         }
969                                 } else {
970                                         $content = $this->getPlainTemplate('###TEMPLATE_AUTH###');
971                                 }
972                         } 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.
973                                 $content = $this->getPlainTemplate('###TEMPLATE_AUTH###');
974                         }
975                 } else {
976                         $content.='Edit-option is not set in TypoScript';
977                 }
978                 return $content;
979         }
980
981         /**
982          * Subfunction for displayEditScreen(); Takes a record and creates an edit form based on the template code for it.
983          * This function is called if the user is editing a record and permitted to do so. Checked in displayEditScreen()
984          *
985          * @param       array           The array with the record to edit
986          * @return      string          HTML content
987          * @access private
988          * @see displayEditScreen()
989          */
990         function displayEditForm($origArr) {
991                 $currentArr = is_array($this->dataArr) ? $this->dataArr+$origArr : $origArr;
992
993                 if ($this->conf['debug'])       debug('displayEditForm(): '.'###TEMPLATE_EDIT'.$this->previewLabel.'###',1);
994                 $templateCode = $this->cObj->getSubpart($this->templateCode, '###TEMPLATE_EDIT'.$this->previewLabel.'###');
995                 $failure = t3lib_div::_GP('noWarnings')?'':$this->failure;
996                 if (!$failure)  {$templateCode = $this->cObj->substituteSubpart($templateCode, '###SUB_REQUIRED_FIELDS_WARNING###', '');}
997
998                 $templateCode = $this->removeRequired($templateCode,$failure);
999
1000                 $this->setCObjects($templateCode,$currentArr);
1001
1002                 $markerArray = $this->cObj->fillInMarkerArray($this->markerArray, $currentArr, '', TRUE, 'FIELD_', $this->recInMarkersHSC);
1003
1004                 $markerArray['###HIDDENFIELDS###'].= '<input type="hidden" name="FE['.$this->theTable.'][uid]" value="'.$currentArr['uid'].'" />';
1005                 if ($this->conf['edit.']['preview'] && !$this->previewLabel)    {$markerArray['###HIDDENFIELDS###'].= '<input type="hidden" name="preview" value="1" />';}
1006                 $content = $this->cObj->substituteMarkerArray($templateCode, $markerArray);
1007                 $content.=$this->cObj->getUpdateJS($this->modifyDataArrForFormUpdate($currentArr), $this->theTable.'_form', 'FE['.$this->theTable.']', $this->fieldList.$this->additionalUpdateFields);
1008
1009                 return $content;
1010         }
1011
1012         /**
1013          * Processes socalled "setfixed" commands. These are commands setting a certain field in a certain record to a certain value. Like a link you can click in an email which will unhide a record to enable something. Or likewise a link which can delete a record by a single click.
1014          * The idea is that only some allowed actions like this is allowed depending on the configured TypoScript.
1015          *
1016          * @return      string          HTML content displaying the status of the action
1017          */
1018         function procesSetFixed() {
1019                 if ($this->conf['setfixed']) {
1020                         $theUid = intval($this->recUid);
1021                         $origArr = $GLOBALS['TSFE']->sys_page->getRawRecord($this->theTable, $theUid);
1022                         $fD = t3lib_div::_GP('fD');
1023                         $sFK = t3lib_div::_GP('sFK');
1024
1025                         $fieldArr=array();
1026                         if (is_array($fD) || $sFK=='DELETE') {
1027                                 if (is_array($fD)) {
1028                                         foreach ($fD as $field => $value) {
1029                                                 $origArr[$field]=$value;
1030                                                 $fieldArr[]=$field;
1031                                         }
1032                                 }
1033                                 $theCode = $this->setfixedHash($origArr,$origArr['_FIELDLIST']);
1034                                 if (!strcmp($this->authCode,$theCode)) {
1035                                         if ($sFK=='DELETE') {
1036                                                 $this->cObj->DBgetDelete($this->theTable, $theUid, TRUE);
1037                                         } else {
1038                                                 $newFieldList = implode(',',array_intersect(t3lib_div::trimExplode(',',$this->fieldList),t3lib_div::trimExplode(',',implode($fieldArr,','),1)));
1039                                                 $this->cObj->DBgetUpdate($this->theTable, $theUid, $fD, $newFieldList, TRUE);
1040                                                 $this->currentArr = $GLOBALS['TSFE']->sys_page->getRawRecord($this->theTable,$theUid);
1041                                                 $this->userProcess_alt($this->conf['setfixed.']['userFunc_afterSave'],$this->conf['setfixed.']['userFunc_afterSave.'],array('rec'=>$this->currentArr, 'origRec'=>$origArr));
1042                                         }
1043
1044                                                 // Outputting template
1045                                         $this->markerArray = $this->cObj->fillInMarkerArray($this->markerArray, $origArr, '', TRUE, 'FIELD_', $this->recInMarkersHSC);
1046                                         $content = $this->getPlainTemplate('###TEMPLATE_SETFIXED_OK_'.$sFK.'###');
1047                                         if (!$content)  {$content = $this->getPlainTemplate('###TEMPLATE_SETFIXED_OK###');}
1048
1049                                                 // Compiling email
1050                                         $this->compileMail(
1051                                                 'SETFIXED_'.$sFK,
1052                                                 array($origArr),
1053                                                 $origArr[$this->conf['email.']['field']],
1054                                                 $this->conf['setfixed.']
1055                                         );
1056                                                 // Clearing cache if set:
1057                                         $this->clearCacheIfSet();
1058                                 } else $content = $this->getPlainTemplate('###TEMPLATE_SETFIXED_FAILED###');
1059                         } else $content = $this->getPlainTemplate('###TEMPLATE_SETFIXED_FAILED###');
1060                 }
1061                 return $content;
1062         }
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086         /*****************************************
1087          *
1088          * Template processing functions
1089          *
1090          *****************************************/
1091
1092
1093
1094         /**
1095          * Remove required parts from template code string
1096          *       Works like this:
1097          *               - You insert subparts like this ###SUB_REQUIRED_FIELD_'.$theField.'### in the template that tells what is required for the field, if it's not correct filled in.
1098          *               - These subparts are all removed, except if the field is listed in $failure string!
1099          *
1100          *              Only fields that are found in $this->requiredArr is processed.
1101          *
1102          * @param       string          The template HTML code
1103          * @param       string          Comma list of fields which has errors (and therefore should not be removed)
1104          * @return      string          The processed template HTML code
1105          */
1106         function removeRequired($templateCode,$failure) {
1107                 foreach ($this->requiredArr as $theField) {
1108                         if (!t3lib_div::inList($failure,$theField)) {
1109                                 $templateCode = $this->cObj->substituteSubpart($templateCode, '###SUB_REQUIRED_FIELD_'.$theField.'###', '');
1110                         }
1111                 }
1112                 return $templateCode;
1113         }
1114
1115         /**
1116          * Returns template subpart HTML code for the key given
1117          *
1118          * @param       string          Subpart marker to return subpart for.
1119          * @param       array           Optional data record array. If set, then all fields herein will also be substituted if found as markers in the template
1120          * @return      string          The subpart with all markers found in current $this->markerArray substituted.
1121          * @see tslib_cObj::fillInMarkerArray()
1122          */
1123         function getPlainTemplate($key,$r='') {
1124                 if ($this->conf['debug'])       debug('getPlainTemplate(): '.$key,1);
1125                 $templateCode = $this->cObj->getSubpart($this->templateCode, $key);
1126                 $this->setCObjects($templateCode,is_array($r)?$r:array());
1127                 return  $this->cObj->substituteMarkerArray(
1128                                 $templateCode,
1129                                 is_array($r) ? $this->cObj->fillInMarkerArray($this->markerArray, $r, '', TRUE, 'FIELD_', $this->recInMarkersHSC) : $this->markerArray
1130                         );
1131         }
1132
1133         /**
1134          * Modifies input array for passing on to tslib_cObj::getUpdateJS() which produces some JavaScript for form evaluation or the like.
1135          *
1136          * @param       array           The data array
1137          * @return      array           The processed input array
1138          * @see displayCreateScreen(), displayEditForm(), tslib_cObj::getUpdateJS()
1139          */
1140         function modifyDataArrForFormUpdate($inputArr) {
1141                 if (is_array($this->conf[$this->cmdKey.'.']['evalValues.'])) {
1142                         foreach ($this->conf[$this->cmdKey.'.']['evalValues.'] as $theField => $theValue) {
1143                                 $listOfCommands = t3lib_div::trimExplode(',',$theValue,1);
1144                                 foreach ($listOfCommands as $cmd) {
1145                                         $cmdParts = preg_split('/\[|\]/', $cmd);        // Point is to enable parameters after each command enclosed in brackets [..]. These will be in position 1 in the array.
1146                                         $theCmd = trim($cmdParts[0]);
1147                                         switch($theCmd) {
1148                                                 case 'twice':
1149                                                         if (isset($inputArr[$theField])) {
1150                                                                 if (!isset($inputArr[$theField.'_again'])) {
1151                                                                         $inputArr[$theField.'_again'] = $inputArr[$theField];
1152                                                                 }
1153                                                                 $this->additionalUpdateFields.=','.$theField.'_again';
1154                                                         }
1155                                                 break;
1156                                         }
1157                                 }
1158                         }
1159                 }
1160                 if (is_array($this->conf['parseValues.'])) {
1161                         foreach ($this->conf['parseValues.'] as $theField => $theValue) {
1162                                 $listOfCommands = t3lib_div::trimExplode(',',$theValue,1);
1163                                 foreach ($listOfCommands as $cmd) {
1164                                         $cmdParts = preg_split('/\[|\]/', $cmd);        // Point is to enable parameters after each command enclosed in brackets [..]. These will be in position 1 in the array.
1165                                         $theCmd = trim($cmdParts[0]);
1166                                         switch($theCmd) {
1167                                                 case 'multiple':
1168                                                         if (isset($inputArr[$theField]) && !$this->isPreview()) {
1169                                                                 $inputArr[$theField] = explode(',',$inputArr[$theField]);
1170                                                         }
1171                                                 break;
1172                                                 case 'checkArray':
1173                                                         if ($inputArr[$theField] && !$this->isPreview()) {
1174                                                                 for($a=0;$a<=30;$a++) {
1175                                                                         if ($inputArr[$theField] & pow(2,$a)) {
1176                                                                                 $alt_theField = $theField.']['.$a;
1177                                                                                 $inputArr[$alt_theField] = 1;
1178                                                                                 $this->additionalUpdateFields.=','.$alt_theField;
1179                                                                         }
1180                                                                 }
1181                                                         }
1182                                                 break;
1183                                         }
1184                                 }
1185                         }
1186                 }
1187
1188
1189                 $inputArr = $this->userProcess_alt(
1190                         $this->conf['userFunc_updateArray'],
1191                         $this->conf['userFunc_updateArray.'],
1192                         $inputArr
1193                 );
1194
1195                 return $this->escapeHTML($inputArr);
1196         }
1197
1198         /**
1199          * Will render TypoScript cObjects (configured in $this->conf['cObjects.']) and add their content to keys in a markerArray, either the array passed to the function or the internal one ($this->markerArray) if the input $markerArray is not set.
1200          *
1201          * @param       string          The current template code string. Is used to check if the marker string is found and if not, the content object is not rendered!
1202          * @param       array           An alternative data record array (if empty then $this->dataArr is used)
1203          * @param       mixed           An alternative markerArray to fill in (instead of $this->markerArray). If you want to set the cobjects in the internal $this->markerArray, then just set this to non-array value.
1204          * @param       string          Optional prefix to set for the marker strings.
1205          * @return      array           The processed $markerArray (if given).
1206          */
1207         function setCObjects($templateCode,$currentArr=array(),$markerArray='',$specialPrefix='') {
1208                 if (is_array($this->conf['cObjects.'])) {
1209
1210                         foreach ($this->conf['cObjects.'] as $theKey => $theConf) {
1211                                 if (!strstr($theKey,'.')) {
1212                                         if (strstr($templateCode,'###'.$specialPrefix.'CE_'.$theKey.'###')) {
1213                                                 $cObjCode = $this->cObj->cObjGetSingle($this->conf['cObjects.'][$theKey], $this->conf['cObjects.'][$theKey.'.'], 'cObjects.'.$theKey);
1214
1215                                                 if (!is_array($markerArray)) {
1216                                                         $this->markerArray['###'.$specialPrefix.'CE_'.$theKey.'###'] = $cObjCode;
1217                                                 } else {
1218                                                         $markerArray['###'.$specialPrefix.'CE_'.$theKey.'###'] = $cObjCode;
1219                                                 }
1220                                         }
1221                                         if (strstr($templateCode,'###'.$specialPrefix.'PCE_'.$theKey.'###')) {
1222                                                 $local_cObj =t3lib_div::makeInstance('tslib_cObj');
1223                                                 $local_cObj->start(count($currentArr)?$currentArr:$this->dataArr,$this->theTable);
1224                                                 $cObjCode = $local_cObj->cObjGetSingle($this->conf['cObjects.'][$theKey], $this->conf['cObjects.'][$theKey.'.'], 'cObjects.'.$theKey);
1225
1226                                                 if (!is_array($markerArray)) {
1227                                                         $this->markerArray['###'.$specialPrefix.'PCE_'.$theKey.'###'] = $cObjCode;
1228                                                 } else {
1229                                                         $markerArray['###'.$specialPrefix.'PCE_'.$theKey.'###'] = $cObjCode;
1230                                                 }
1231                                         }
1232                                 }
1233                         }
1234                 }
1235                 return $markerArray;
1236         }
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256         /*****************************************
1257          *
1258          * Emailing
1259          *
1260          *****************************************/
1261
1262         /**
1263          * Sends info mail to user
1264          *
1265          * @return      string          HTML content message
1266          * @see init(),compileMail(), sendMail()
1267          */
1268         function sendInfoMail() {
1269                 if ($this->conf['infomail'] && $this->conf['email.']['field']) {
1270                         $fetch = t3lib_div::_GP('fetch');
1271                         if ($fetch) {
1272                                         // Getting infomail config.
1273                                 $key= trim(t3lib_div::_GP('key'));
1274                                 if (is_array($this->conf['infomail.'][$key.'.']))               {
1275                                         $config = $this->conf['infomail.'][$key.'.'];
1276                                 } else {
1277                                         $config = $this->conf['infomail.']['default.'];
1278                                 }
1279                                 $pidLock='';
1280                                 if (!$config['dontLockPid']) {
1281                                         $pidLock='AND pid IN ('.$this->thePid.') ';
1282                                 }
1283
1284                                         // Getting records
1285                                 if (t3lib_utility_Math::canBeInterpretedAsInteger($fetch)) {
1286                                         $DBrows = $GLOBALS['TSFE']->sys_page->getRecordsByField($this->theTable,'uid',$fetch,$pidLock,'','','1');
1287                                 } elseif ($fetch) {     // $this->conf['email.']['field'] must be a valid field in the table!
1288                                         $DBrows = $GLOBALS['TSFE']->sys_page->getRecordsByField($this->theTable,$this->conf['email.']['field'],$fetch,$pidLock,'','','100');
1289                                 }
1290
1291                                         // Processing records
1292                                 if (is_array($DBrows)) {
1293                                         $recipient = $DBrows[0][$this->conf['email.']['field']];
1294                                         $this->compileMail($config['label'], $DBrows, $recipient, $this->conf['setfixed.']);
1295                                 } elseif (t3lib_div::validEmail($fetch)) {
1296                                         $this->sendMail($fetch, '', trim($this->cObj->getSubpart($this->templateCode, '###'.$this->emailMarkPrefix.'NORECORD###')));
1297                                 }
1298
1299                                 $content = $this->getPlainTemplate('###TEMPLATE_INFOMAIL_SENT###');
1300                         } else {
1301                                 $content = $this->getPlainTemplate('###TEMPLATE_INFOMAIL###');
1302                         }
1303                 } else $content='Error: infomail option is not available or emailField is not setup in TypoScript';
1304                 return $content;
1305         }
1306
1307         /**
1308          * Compiles and sends a mail based on input values + template parts. Looks for a normal and an "-admin" template and may send both kinds of emails. See documentation in TSref.
1309          *
1310          * @param       string          A key which together with $this->emailMarkPrefix will identify the part from the template code to use for the email.
1311          * @param       array           An array of records which fields are substituted in the templates
1312          * @param       mixed           Mail recipient. If string then its supposed to be an email address. If integer then its a uid of a fe_users record which is looked up and the email address from here is used for sending the mail.
1313          * @param       array           Additional fields to set in the markerArray used in the substitution process
1314          * @return      void
1315          */
1316         function compileMail($key, $DBrows, $recipient, $setFixedConfig=array()) {
1317                 $GLOBALS['TT']->push('compileMail');
1318                 $mailContent='';
1319                 $key = $this->emailMarkPrefix.$key;
1320
1321                 $userContent['all'] = trim($this->cObj->getSubpart($this->templateCode, '###'.$key.'###'));
1322                 $adminContent['all'] = trim($this->cObj->getSubpart($this->templateCode, '###'.$key.'-ADMIN###'));
1323                 $userContent['rec'] = $this->cObj->getSubpart($userContent['all'], '###SUB_RECORD###');
1324                 $adminContent['rec'] = $this->cObj->getSubpart($adminContent['all'], '###SUB_RECORD###');
1325
1326                 foreach ($DBrows as $r) {
1327                         $markerArray = $this->cObj->fillInMarkerArray($this->markerArray, $r,'',0);
1328                         $markerArray = $this->setCObjects($userContent['rec'].$adminContent['rec'],$r,$markerArray,'ITEM_');
1329                         $markerArray['###SYS_AUTHCODE###'] = $this->authCode($r);
1330                         $markerArray = $this->setfixed($markerArray, $setFixedConfig, $r);
1331
1332                         if ($userContent['rec'])        $userContent['accum'] .=$this->cObj->substituteMarkerArray($userContent['rec'], $markerArray);
1333                         if ($adminContent['rec'])       $adminContent['accum'].=$this->cObj->substituteMarkerArray($adminContent['rec'], $markerArray);
1334                 }
1335
1336                 if ($userContent['all'])        $userContent['final'] .=$this->cObj->substituteSubpart($userContent['all'], '###SUB_RECORD###', $userContent['accum']);
1337                 if ($adminContent['all'])       $adminContent['final'].=$this->cObj->substituteSubpart($adminContent['all'], '###SUB_RECORD###', $adminContent['accum']);
1338
1339                 if (t3lib_utility_Math::canBeInterpretedAsInteger($recipient)) {
1340                         $fe_userRec = $GLOBALS['TSFE']->sys_page->getRawRecord('fe_users',$recipient);
1341                         $recipient=$fe_userRec['email'];
1342                 }
1343
1344                 $GLOBALS['TT']->setTSlogMessage('Template key: ###'.$key.'###, userContentLength: '.strlen($userContent['final']).', adminContentLength: '.strlen($adminContent['final']));
1345
1346                 $this->sendMail($recipient, $this->conf['email.']['admin'], $userContent['final'], $adminContent['final']);
1347                 $GLOBALS['TT']->pull();
1348         }
1349
1350         /**
1351          * Actually sends the requested mails (through $this->cObj->sendNotifyEmail or through $this->sendHTMLMail).
1352          * As of TYPO3 v4.3 with autoloader, a check for $GLOBALS['TSFE']->config['config']['incT3Lib_htmlmail'] has been included for backwards compatibility.
1353          *
1354          * @param       string          Recipient email address (or list)
1355          * @param       string          Possible "admin" email address. Will enable sending of admin emails if also $adminContent is provided
1356          * @param       string          Content for the regular email to user
1357          * @param       string          Content for the admin email to administrator
1358          * @return      void
1359          * @access private
1360          * @see compileMail(), sendInfoMail()
1361          */
1362         function sendMail($recipient, $admin, $content='', $adminContent='') {
1363                         // Admin mail:
1364                 if ($admin && $adminContent) {
1365                         if (!$this->isHTMLContent($adminContent) || !$GLOBALS['TSFE']->config['config']['incT3Lib_htmlmail']) {
1366                                 $admMail = $this->cObj->sendNotifyEmail(
1367                                                                         strip_tags($adminContent),
1368                                                                         $admin,
1369                                                                         '',
1370                                                                         $this->conf['email.']['from'],
1371                                                                         $this->conf['email.']['fromName'],
1372                                                                         $recipient
1373                                                         );
1374                         } else {
1375                                 $this->sendHTMLMail($adminContent,
1376                                                                         $admin,
1377                                                                         '',
1378                                                                         $this->conf['email.']['from'],
1379                                                                         $this->conf['email.']['fromName'],
1380                                                                         $recipient
1381                                                         );
1382                         }
1383                 }
1384                         // user mail:
1385                 if (!$this->isHTMLContent($content) || !$GLOBALS['TSFE']->config['config']['incT3Lib_htmlmail']) {
1386                         $this->cObj->sendNotifyEmail(
1387                                                                 strip_tags($content),
1388                                                                 $recipient,
1389                                                                 '',
1390                                                                 $this->conf['email.']['from'],
1391                                                                 $this->conf['email.']['fromName']
1392                                                 );
1393                 } else {
1394                         $this->sendHTMLMail($content,
1395                                                                 $recipient,
1396                                                                 '',
1397                                                                 $this->conf['email.']['from'],
1398                                                                 $this->conf['email.']['fromName']
1399                                                 );
1400                 }
1401         }
1402
1403         /**
1404          * Detects if content is HTML (looking for <html> tag as first and last in string)
1405          *
1406          * @param       string          Content string to test
1407          * @return      boolean         Returns TRUE if the content begins and ends with <html></html>-tags
1408          */
1409         function isHTMLContent($c) {
1410                 $c = trim($c);
1411                 $first = strtolower(substr($c,0,6));
1412                 $last = strtolower(substr($c,-7));
1413                 if ($first.$last=='<html></html>')      return 1;
1414         }
1415
1416         /**
1417          * Sending HTML email, using same parameters as tslib_cObj::sendNotifyEmail()
1418          *
1419          * @param       string          The message content. If blank, no email is sent.
1420          * @param       string          Comma list of recipient email addresses
1421          * @param       string          IGNORE this parameter
1422          * @param       string          "From" email address
1423          * @param       string          Optional "From" name
1424          * @param       string          Optional "Reply-To" header email address.
1425          * @return      void
1426          * @access private
1427          * @see sendMail(), tslib_cObj::sendNotifyEmail()
1428          */
1429         function sendHTMLMail($content,$recipient,$dummy,$fromEmail,$fromName,$replyTo='') {
1430                 if (trim($recipient) && trim($content)) {
1431                         $parts = preg_split('/<title>|<\/title>/i', $content, 3);
1432                         $subject = trim($parts[1]) ? trim($parts[1]) : 'TYPO3 FE Admin message';
1433
1434                         $Typo3_htmlmail = t3lib_div::makeInstance('t3lib_htmlmail');
1435                         $Typo3_htmlmail->start();
1436                         $Typo3_htmlmail->useBase64();
1437
1438                         $Typo3_htmlmail->subject = $subject;
1439                         $Typo3_htmlmail->from_email = $fromEmail;
1440                         $Typo3_htmlmail->from_name = $fromName;
1441                         $Typo3_htmlmail->replyto_email = $replyTo ? $replyTo : $fromEmail;
1442                         $Typo3_htmlmail->replyto_name = $replyTo ? '' : $fromName;
1443                         $Typo3_htmlmail->organisation = '';
1444                         $Typo3_htmlmail->priority = 3;
1445
1446                                 // HTML
1447                         $Typo3_htmlmail->theParts['html']['content'] = $content;        // Fetches the content of the page
1448                         $Typo3_htmlmail->theParts['html']['path'] = '';
1449                         $Typo3_htmlmail->extractMediaLinks();
1450                         $Typo3_htmlmail->extractHyperLinks();
1451                         $Typo3_htmlmail->fetchHTMLMedia();
1452                         $Typo3_htmlmail->substMediaNamesInHTML(0);      // 0 = relative
1453                         $Typo3_htmlmail->substHREFsInHTML();
1454                         $Typo3_htmlmail->setHTML($Typo3_htmlmail->encodeMsg($Typo3_htmlmail->theParts['html']['content']));
1455
1456                                 // PLAIN
1457                         $Typo3_htmlmail->addPlain('');
1458
1459                                 // SET Headers and Content
1460                         $Typo3_htmlmail->setHeaders();
1461                         $Typo3_htmlmail->setContent();
1462                         $Typo3_htmlmail->setRecipient($recipient);
1463
1464                         $Typo3_htmlmail->sendtheMail();
1465                 }
1466         }
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491         /*****************************************
1492          *
1493          * Various helper functions
1494          *
1495          *****************************************/
1496
1497
1498         /**
1499          * Returns TRUE if authentication is OK based on the "aC" code which is a GET parameter set from outside with a hash string which must match some internal hash string.
1500          * This allows to authenticate editing without having a fe_users login
1501          * Uses $this->authCode which is set in init() by "t3lib_div::_GP('aC');"
1502          *
1503          * @param       array           The data array for which to evaluate authentication
1504          * @return      boolean         TRUE if authenticated OK
1505          * @see authCode(), init()
1506          */
1507         function aCAuth($r) {
1508                 if ($this->authCode && !strcmp($this->authCode,$this->authCode($r))) {
1509                         return TRUE;
1510                 }
1511         }
1512
1513         /**
1514          * Creating authentication hash string based on input record and the fields listed in TypoScript property "authcodeFields"
1515          *
1516          * @param       array           The data record
1517          * @param       string          Additional string to include in the hash
1518          * @return      string          Hash string of $this->codeLength (if TypoScript "authcodeFields" was set)
1519          * @see aCAuth()
1520          */
1521         function authCode($r,$extra='') {
1522                 $l=$this->codeLength;
1523                 if ($this->conf['authcodeFields']) {
1524                         $fieldArr = t3lib_div::trimExplode(',', $this->conf['authcodeFields'], 1);
1525                         $value='';
1526                         foreach ($fieldArr as $field) {
1527                                 $value.=$r[$field].'|';
1528                         }
1529                         $value.=$extra.'|'.$this->conf['authcodeFields.']['addKey'];
1530                         if ($this->conf['authcodeFields.']['addDate']) {
1531                                 $value.='|'.date($this->conf['authcodeFields.']['addDate']);
1532                         }
1533                         $value.=$GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'];
1534                         return substr(md5($value), 0,$l);
1535                 }
1536         }
1537
1538         /**
1539          * Adding keys to the marker array with "setfixed" GET parameters
1540          *
1541          * @param       array           Marker-array to modify/add a key to.
1542          * @param       array           TypoScript properties configuring "setfixed" for the plugin. Basically this is $this->conf['setfixed.'] passed along.
1543          * @param       array           The data record
1544          * @return      array           Processed $markerArray
1545          * @see compileMail()
1546          */
1547         function setfixed($markerArray, $setfixed, $r) {
1548                 if (is_array($setfixed)) {
1549                         foreach ($setfixed as $theKey => $data) {
1550                                 if (!strcmp($theKey,'DELETE')) {
1551                                         $recCopy = $r;
1552                                         $string='&cmd=setfixed&sFK='.rawurlencode($theKey).'&rU='.$r['uid'];
1553                                         $string.='&aC='.$this->setfixedHash($recCopy,$data['_FIELDLIST']);
1554                                         $markerArray['###SYS_SETFIXED_DELETE###'] = $string;
1555                                         $markerArray['###SYS_SETFIXED_HSC_DELETE###'] = htmlspecialchars($string);
1556                                 } elseif (strstr($theKey,'.')) {
1557                                         $theKey = substr($theKey,0,-1);
1558                                         if (is_array($data)) {
1559                                                 $recCopy = $r;
1560                                                 $string='&cmd=setfixed&sFK='.rawurlencode($theKey).'&rU='.$r['uid'];
1561                                                 foreach ($data as $fieldName => $fieldValue) {
1562                                                         $string.='&fD%5B'.$fieldName.'%5D='.rawurlencode($fieldValue);
1563                                                         $recCopy[$fieldName]=$fieldValue;
1564                                                 }
1565                                                 $string.='&aC='.$this->setfixedHash($recCopy,$data['_FIELDLIST']);
1566                                                 $markerArray['###SYS_SETFIXED_'.$theKey.'###'] = $string;
1567                                                 $markerArray['###SYS_SETFIXED_HSC_'.$theKey.'###'] = htmlspecialchars($string);
1568                                         }
1569                                 }
1570                         }
1571                 }
1572                 return $markerArray;
1573         }
1574
1575         /**
1576          * Creating hash string for setFixed. Much similar to authCode()
1577          *
1578          * @param       array           The data record
1579          * @param       string          List of fields to use
1580          * @return      string          Hash string of $this->codeLength (if TypoScript "authcodeFields" was set)
1581          * @see setfixed(),authCode()
1582          */
1583         function setfixedHash($recCopy,$fields='') {
1584                 if ($fields) {
1585                         $fieldArr = t3lib_div::trimExplode(',',$fields,1);
1586                         foreach ($fieldArr as $k => $v) {
1587                                 $recCopy_temp[$k]=$recCopy[$v];
1588                         }
1589                 } else {
1590                         $recCopy_temp=$recCopy;
1591                 }
1592                 $encStr = implode('|',$recCopy_temp).'|'.$this->conf['authcodeFields.']['addKey'].'|'.$GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'];
1593                 $hash = substr(md5($encStr),0,$this->codeLength);
1594                 return $hash;
1595         }
1596
1597
1598         /**
1599          * Returns TRUE if preview display is on.
1600          *
1601          * @return      boolean
1602          */
1603         function isPreview() {
1604                 return ($this->conf[$this->cmdKey.'.']['preview'] && $this->preview);
1605         }
1606
1607         /**
1608          * Creates an instance of class "t3lib_basicFileFunctions" in $this->fileFunc (if not already done)
1609          *
1610          * @return      void
1611          */
1612         function createFileFuncObj() {
1613                 if (!$this->fileFunc) {
1614                         $this->fileFunc = t3lib_div::makeInstance('t3lib_basicFileFunctions');
1615                 }
1616         }
1617
1618         /**
1619          * If TypoScript property clearCacheOfPages is set then all page ids in this value will have their cache cleared
1620          *
1621          * @return      void
1622          */
1623         function clearCacheIfSet() {
1624                 if ($this->conf['clearCacheOfPages']) {
1625                         $cc_pidList = $GLOBALS['TYPO3_DB']->cleanIntList($this->conf['clearCacheOfPages']);
1626                         $GLOBALS['TSFE']->clearPageCacheContent_pidList($cc_pidList);
1627                 }
1628         }
1629
1630         /**
1631          * Returns an error message for the field/command combination inputted. The error message is looked up in the TypoScript properties (evalErrors.[fieldname].[command]) and if empty then the $label value is returned
1632          *
1633          * @param       string          Field name
1634          * @param       string          Command identifier string
1635          * @param       string          Alternative label, shown if no other error string was found
1636          * @return      string          The error message string
1637          */
1638         function getFailure($theField, $theCmd, $label) {
1639                 return isset($this->conf['evalErrors.'][$theField.'.'][$theCmd]) ? $this->conf['evalErrors.'][$theField.'.'][$theCmd] : $label;
1640         }
1641
1642         /**
1643          * Will escape HTML-tags
1644          *
1645          * @param       mixed           The unescaped data
1646          * @return      mixed           The processed input data
1647          */
1648         function escapeHTML($var) {
1649                 if (is_array($var)) {
1650                         foreach ($var as $k => $value) {
1651                                 $var[$k] = $this->escapeHTML($var[$k]);
1652                         }
1653                 } else {
1654                         $var = htmlspecialchars($var, ENT_NOQUOTES);
1655                 }
1656                 return $var;
1657         }
1658 }
1659
1660
1661 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['media/scripts/fe_adminLib.inc'])) {
1662         include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['media/scripts/fe_adminLib.inc']);
1663 }
1664 ?>