[TASK] CGL FunctionCallArgumentSpacingNoSpaceAfterComma in sysext "cms"
[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']) {
270                                 debug('Display form: '.$this->cmd, 1);
271                         }
272                         switch($this->cmd) {
273                                 case 'setfixed':
274                                         $content = $this->procesSetFixed();
275                                 break;
276                                 case 'infomail':
277                                         $content = $this->sendInfoMail();
278                                 break;
279                                 case 'delete':
280                                         $content = $this->displayDeleteScreen();
281                                 break;
282                                 case 'edit':
283                                         $content = $this->displayEditScreen();
284                                 break;
285                                 case 'create':
286                                         $content = $this->displayCreateScreen();
287                                 break;
288                         }
289                 }
290
291                         // Delete temp files:
292                 foreach($this->unlinkTempFiles as $tempFileName) {
293                         t3lib_div::unlink_tempfile($tempFileName);
294                 }
295
296                         // Return content:
297                 return $content;
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         /*****************************************
323          *
324          * Data processing
325          *
326          *****************************************/
327
328         /**
329          * Performs processing on the values found in the input data array, $this->dataArr.
330          * The processing is done according to configuration found in TypoScript
331          * 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.
332          * Called from init() if the $this->dataArr is found to be an array
333          *
334          * @return      void
335          * @see init()
336          */
337         function parseValues() {
338                 if (is_array($this->conf['parseValues.'])) {
339                         foreach ($this->conf['parseValues.'] as $theField => $theValue) {
340                                 $listOfCommands = t3lib_div::trimExplode(',', $theValue, 1);
341                                 foreach ($listOfCommands as $cmd) {
342                                         $cmdParts = preg_split('/\[|\]/', $cmd);        // Point is to enable parameters after each command enclosed in brackets [..]. These will be in position 1 in the array.
343                                         $theCmd=trim($cmdParts[0]);
344                                         switch($theCmd) {
345                                                 case 'int':
346                                                         $this->dataArr[$theField]=intval($this->dataArr[$theField]);
347                                                 break;
348                                                 case 'lower':
349                                                 case 'upper':
350                                                         $this->dataArr[$theField] = $this->cObj->caseshift($this->dataArr[$theField], $theCmd);
351                                                 break;
352                                                 case 'nospace':
353                                                         $this->dataArr[$theField] = str_replace(' ', '', $this->dataArr[$theField]);
354                                                 break;
355                                                 case 'alpha':
356                                                         $this->dataArr[$theField] = preg_replace('/[^a-zA-Z]/', '', $this->dataArr[$theField]);
357                                                 break;
358                                                 case 'num':
359                                                         $this->dataArr[$theField] = preg_replace('/[^0-9]/', '', $this->dataArr[$theField]);
360                                                 break;
361                                                 case 'alphanum':
362                                                         $this->dataArr[$theField] = preg_replace('/[^a-zA-Z0-9]/', '', $this->dataArr[$theField]);
363                                                 break;
364                                                 case 'alphanum_x':
365                                                         $this->dataArr[$theField] = preg_replace('/[^a-zA-Z0-9_-]/', '', $this->dataArr[$theField]);
366                                                 break;
367                                                 case 'trim':
368                                                         $this->dataArr[$theField] = trim($this->dataArr[$theField]);
369                                                 break;
370                                                 case 'random':
371                                                         $this->dataArr[$theField] = substr(md5(uniqid(microtime(), 1)), 0, intval($cmdParts[1]));
372                                                 break;
373                                                 case 'files':
374                                                         if ($this->cmdKey=='create' && !t3lib_div::_GP('doNotSave')) {
375                                                                 $this->processFiles($cmdParts, $theField);
376                                                         } else unset($this->dataArr[$theField]);        // Fields with files cannot be edited - only created.
377                                                 break;
378                                                 case 'setEmptyIfAbsent':
379                                                         if (!isset($this->dataArr[$theField])) {
380                                                                 $this->dataArr[$theField]='';
381                                                         }
382                                                 break;
383                                                 case 'multiple':
384                                                         if (is_array($this->dataArr[$theField])) {
385                                                                 $this->dataArr[$theField] = implode(',', $this->dataArr[$theField]);
386                                                         }
387                                                 break;
388                                                 case 'checkArray':
389                                                         if (is_array($this->dataArr[$theField])) {
390                                                                 $val = 0;
391                                                                 foreach ($this->dataArr[$theField] as $kk => $vv) {
392                                                                         $kk = t3lib_utility_Math::forceIntegerInRange($kk, 0);
393                                                                         if ($kk<=30) {
394                                                                                 if ($vv) {
395                                                                                         $val|=pow(2, $kk);
396                                                                                 }
397                                                                         }
398                                                                 }
399                                                                 $this->dataArr[$theField] = $val;
400                                                         } else {$this->dataArr[$theField]=0;}
401                                                 break;
402                                                 case 'uniqueHashInt':
403                                                         $otherFields = t3lib_div::trimExplode(';', $cmdParts[1], 1);
404                                                         $hashArray=array();
405                                                         foreach ($otherFields as $fN) {
406                                                                 $vv = $this->dataArr[$fN];
407                                                                 $vv = preg_replace('/[[:space:]]/', '', $vv);
408                                                                 $vv = preg_replace('/[^[:alnum:]]/', '', $vv);
409                                                                 $vv = strtolower($vv);
410                                                                 $hashArray[]=$vv;
411                                                         }
412                                                         $this->dataArr[$theField]=hexdec(substr(md5(serialize($hashArray)), 0, 8));
413                                                 break;
414                                         }
415                                 }
416                         }
417                 }
418         }
419
420         /**
421          * Processing of files.
422          * NOTICE: for now files can be handled only on creation of records. But a more advanced feature is that PREVIEW of files is handled.
423          *
424          * @param       array           Array with cmd-parts (from parseValues()). This will for example contain information about allowed file extensions and max size of uploaded files.
425          * @param       string          The fieldname with the files.
426          * @return      void
427          * @access private
428          * @see parseValues()
429          */
430         function processFiles($cmdParts, $theField) {
431                         // First, make an array with the filename and file reference, whether the file is just uploaded or a preview
432                 $filesArr = array();
433
434                 if (is_string($this->dataArr[$theField]))       {               // files from preview.
435                         $tmpArr = explode(',', $this->dataArr[$theField]);
436                         foreach ($tmpArr as $val) {
437                                 $valParts = explode('|', $val);
438                                 $filesArr[] = array (
439                                         'name'=>$valParts[1],
440                                         'tmp_name'=>PATH_site.'typo3temp/'.$valParts[0]
441                                 );
442                         }
443                 } elseif (is_array($_FILES['FE'][$this->theTable][$theField]['name']))  {       // Files from upload
444                         foreach ($_FILES['FE'][$this->theTable][$theField]['name'] as $kk => $vv) {
445                                 if ($vv) {
446                                         $tmpFile = t3lib_div::upload_to_tempfile($_FILES['FE'][$this->theTable][$theField]['tmp_name'][$kk]);
447                                         if ($tmpFile) {
448                                                 $this->unlinkTempFiles[]=$tmpFile;
449                                                 $filesArr[] = array (
450                                                         'name'=>$vv,
451                                                         'tmp_name'=>$tmpFile
452                                                 );
453                                         }
454                                 }
455                         }
456                 } elseif (is_array($_FILES['FE']['name'][$this->theTable][$theField]))  {       // Files from upload
457                         foreach ($_FILES['FE']['name'][$this->theTable][$theField] as $kk => $vv) {
458                                 if ($vv) {
459                                         $tmpFile = t3lib_div::upload_to_tempfile($_FILES['FE']['tmp_name'][$this->theTable][$theField][$kk]);
460                                         if ($tmpFile) {
461                                                 $this->unlinkTempFiles[]=$tmpFile;
462                                                 $filesArr[] = array (
463                                                         'name'=>$vv,
464                                                         'tmp_name'=>$tmpFile
465                                                 );
466                                         }
467                                 }
468                         }
469                 }
470
471                         // Then verify the files in that array; check existence, extension and size
472                 $this->dataArr[$theField]='';
473                 $finalFilesArr=array();
474                 if (count($filesArr)) {
475                         $extArray = t3lib_div::trimExplode(';', strtolower($cmdParts[1]), 1);
476                         $maxSize = intval($cmdParts[3]);
477                         foreach ($filesArr as $infoArr) {
478                                 $fI = pathinfo($infoArr['name']);
479                                 if (t3lib_div::verifyFilenameAgainstDenyPattern($fI['name'])) {
480                                         if (!count($extArray) || in_array(strtolower($fI['extension']), $extArray)) {
481                                                 $tmpFile = $infoArr['tmp_name'];
482                                                 if (@is_file($tmpFile)) {
483                                                         if (!$maxSize || filesize($tmpFile)<$maxSize*1024) {
484                                                                 $finalFilesArr[]=$infoArr;
485                                                         } elseif ($this->conf['debug']) {debug('Size is beyond '.$maxSize.' kb ('.filesize($tmpFile).' bytes) and the file cannot be saved.');}
486                                                 } elseif ($this->conf['debug']) {debug('Surprisingly there was no file for '.$vv.' in '.$tmpFile);}
487                                         } elseif ($this->conf['debug']) {debug('Extension "'.$fI['extension'].'" not allowed');}
488                                 } elseif ($this->conf['debug']) {debug('Filename matched illegal pattern.');}
489                         }
490                 }
491                         // Copy the files in the resulting array to the proper positions based on preview/non-preview.
492                 $fileNameList=array();
493                 foreach ($finalFilesArr as $infoArr) {
494                         if ($this->isPreview()) {               // If the form is a preview form (and data is therefore not going into the database...) do this.
495                                 $this->createFileFuncObj();
496                                 $fI = pathinfo($infoArr['name']);
497                                 $tmpFilename = $this->theTable.'_'.t3lib_div::shortmd5(uniqid($infoArr['name'])).'.'.$fI['extension'];
498                                 $theDestFile = $this->fileFunc->getUniqueName($this->fileFunc->cleanFileName($tmpFilename), PATH_site.'typo3temp/');
499                                 t3lib_div::upload_copy_move($infoArr['tmp_name'], $theDestFile);
500                                         // Setting the filename in the list
501                                 $fI2 = pathinfo($theDestFile);
502                                 $fileNameList[] = $fI2['basename'].'|'.$infoArr['name'];
503                         } else {
504                                 $this->createFileFuncObj();
505                                 $GLOBALS['TSFE']->includeTCA();
506                                 t3lib_div::loadTCA($this->theTable);
507                                 if (is_array($GLOBALS['TCA'][$this->theTable]['columns'][$theField])) {
508                                         $uploadPath = $GLOBALS['TCA'][$this->theTable]['columns'][$theField]['config']['uploadfolder'];
509                                 }
510                                 if ($uploadPath) {
511                                         $theDestFile = $this->fileFunc->getUniqueName($this->fileFunc->cleanFileName($infoArr['name']), PATH_site.$uploadPath);
512                                         t3lib_div::upload_copy_move($infoArr['tmp_name'], $theDestFile);
513                                                 // Setting the filename in the list
514                                         $fI2 = pathinfo($theDestFile);
515                                         $fileNameList[] = $fI2['basename'];
516                                         $this->filesStoredInUploadFolders[]=$theDestFile;
517                                 }
518                         }
519                                 // Implode the list of filenames
520                         $this->dataArr[$theField] = implode(',', $fileNameList);
521                 }
522         }
523
524         /**
525          * Overriding values in $this->dataArr if configured for that in TypoScript ([edit/create].overrideValues)
526          *
527          * @return      void
528          * @see init()
529          */
530         function overrideValues() {
531                 // Addition of overriding values
532                 if (is_array($this->conf[$this->cmdKey.'.']['overrideValues.'])) {
533                         foreach ($this->conf[$this->cmdKey.'.']['overrideValues.'] as $theField => $theValue) {
534                                 $this->dataArr[$theField] = $theValue;
535                         }
536                 }
537         }
538
539         /**
540          * Called if there is no input array in $this->dataArr. Then this function sets the default values configured in TypoScript
541          *
542          * @return      void
543          * @see init()
544          */
545         function defaultValues() {
546                         // Addition of default values
547                 if (is_array($this->conf[$this->cmdKey.'.']['defaultValues.'])) {
548                         foreach ($this->conf[$this->cmdKey.'.']['defaultValues.'] as $theField => $theValue) {
549                                 $this->dataArr[$theField] = $theValue;
550                         }
551                 }
552         }
553
554         /**
555          * This will evaluate the input values from $this->dataArr to see if they conforms with the requirements configured in TypoScript per field.
556          * For example this could be checking if a field contains a valid email address, a unique value, a value within a certain range etc.
557          * 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())
558          * Works based on configuration in TypoScript key [create/edit].evalValues
559          *
560          * @return      void
561          * @see init(), parseValues()
562          */
563         function evalValues() {
564                 // Check required, set failure if not ok.
565                 $tempArr=array();
566                 foreach ($this->requiredArr as $theField) {
567                         if (!trim($this->dataArr[$theField])) {
568                                 $tempArr[]=$theField;
569                         }
570                 }
571
572                 // 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!
573                 $recExist=0;
574                 if (is_array($this->conf[$this->cmdKey.'.']['evalValues.'])) {
575                         switch($this->cmd) {
576                                 case 'edit':
577                                         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.
578                                                 $recordTestPid = intval($this->dataArr['pid']);
579                                         } else {
580                                                 $tempRecArr = $GLOBALS['TSFE']->sys_page->getRawRecord($this->theTable, $this->dataArr['uid']);
581                                                 $recordTestPid = intval($tempRecArr['pid']);
582                                         }
583                                         $recExist=1;
584                                 break;
585                                 default:
586                                         $recordTestPid = $this->thePid ? $this->thePid : t3lib_utility_Math::convertToPositiveInteger($this->dataArr['pid']);
587                                 break;
588                         }
589
590                         foreach ($this->conf[$this->cmdKey.'.']['evalValues.'] as $theField => $theValue) {
591                                 $listOfCommands = t3lib_div::trimExplode(',', $theValue, 1);
592                                 foreach ($listOfCommands as $cmd) {
593                                         $cmdParts = preg_split('/\[|\]/', $cmd);        // Point is to enable parameters after each command enclosed in brackets [..]. These will be in position 1 in the array.
594                                         $theCmd = trim($cmdParts[0]);
595                                         switch($theCmd) {
596                                                 case 'uniqueGlobal':
597                                                         if ($DBrows = $GLOBALS['TSFE']->sys_page->getRecordsByField($this->theTable, $theField, $this->dataArr[$theField], '', '', '', '1')) {
598                                                                 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.
599                                                                         $tempArr[]=$theField;
600                                                                         $this->failureMsg[$theField][] = $this->getFailure($theField, $theCmd, 'The value existed already. Enter a new value.');
601                                                                 }
602                                                         }
603                                                 break;
604                                                 case 'uniqueLocal':
605                                                         if ($DBrows = $GLOBALS['TSFE']->sys_page->getRecordsByField($this->theTable, $theField, $this->dataArr[$theField], 'AND pid IN ('.$recordTestPid.')', '', '', '1')) {
606                                                                 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.
607                                                                         $tempArr[]=$theField;
608                                                                         $this->failureMsg[$theField][] = $this->getFailure($theField, $theCmd, 'The value existed already. Enter a new value.');
609                                                                 }
610                                                         }
611                                                 break;
612                                                 case 'twice':
613                                                         if (strcmp($this->dataArr[$theField], $this->dataArr[$theField.'_again'])) {
614                                                                 $tempArr[]=$theField;
615                                                                 $this->failureMsg[$theField][] = $this->getFailure($theField, $theCmd, 'You must enter the same value twice');
616                                                         }
617                                                 break;
618                                                 case 'email':
619                                                         if (!t3lib_div::validEmail($this->dataArr[$theField])) {
620                                                                 $tempArr[]=$theField;
621                                                                 $this->failureMsg[$theField][] = $this->getFailure($theField, $theCmd, 'You must enter a valid email address');
622                                                         }
623                                                 break;
624                                                 case 'required':
625                                                         if (!trim($this->dataArr[$theField])) {
626                                                                 $tempArr[]=$theField;
627                                                                 $this->failureMsg[$theField][] = $this->getFailure($theField, $theCmd, 'You must enter a value!');
628                                                         }
629                                                 break;
630                                                 case 'atLeast':
631                                                         $chars=intval($cmdParts[1]);
632                                                         if (strlen($this->dataArr[$theField])<$chars) {
633                                                                 $tempArr[]=$theField;
634                                                                 $this->failureMsg[$theField][] = sprintf($this->getFailure($theField, $theCmd, 'You must enter at least %s characters!'), $chars);
635                                                         }
636                                                 break;
637                                                 case 'atMost':
638                                                         $chars=intval($cmdParts[1]);
639                                                         if (strlen($this->dataArr[$theField])>$chars) {
640                                                                 $tempArr[]=$theField;
641                                                                 $this->failureMsg[$theField][] = sprintf($this->getFailure($theField, $theCmd, 'You must enter at most %s characters!'), $chars);
642                                                         }
643                                                 break;
644                                                 case 'inBranch':
645                                                         $pars = explode(';', $cmdParts[1]);
646                                                         if (intval($pars[0])) {
647                                                                 $pid_list = $this->cObj->getTreeList(
648                                                                         intval($pars[0]),
649                                                                         intval($pars[1]) ? intval($pars[1]) : 999,
650                                                                         intval($pars[2])
651                                                                 );
652                                                                 if (!$pid_list || !t3lib_div::inList($pid_list, $this->dataArr[$theField])) {
653                                                                         $tempArr[]=$theField;
654                                                                         $this->failureMsg[$theField][] = sprintf($this->getFailure($theField, $theCmd, 'The value was not a valid valud from this list: %s'), $pid_list);
655                                                                 }
656                                                         }
657                                                 break;
658                                                 case 'unsetEmpty':
659                                                         if (!$this->dataArr[$theField]) {
660                                                                 $hash = array_flip($tempArr);
661                                                                 unset($hash[$theField]);
662                                                                 $tempArr = array_keys($hash);
663                                                                 unset($this->failureMsg[$theField]);
664                                                                 unset($this->dataArr[$theField]);       // This should prevent the field from entering the database.
665                                                         }
666                                                 break;
667                                         }
668                                 }
669                                 $this->markerArray['###EVAL_ERROR_FIELD_' . $theField . '###'] = is_array($this->failureMsg[$theField]) ? implode('<br />', $this->failureMsg[$theField]) : '';
670                         }
671                 }
672                         // $failure will show which fields were not OK
673                 $this->failure=implode(',', $tempArr);
674         }
675
676         /**
677          * Preforms user processing of input array - triggered right after the function call to evalValues() IF TypoScript property "evalFunc" was set.
678          *
679          * @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.
680          * @param       array           The $this->dataArr passed for processing
681          * @return      array           The processed $passVar ($this->dataArr)
682          * @see init(), evalValues()
683          */
684         function userProcess($mConfKey, $passVar) {
685                 if ($this->conf[$mConfKey]) {
686                         $funcConf = $this->conf[$mConfKey.'.'];
687                         $funcConf['parentObj'] = $this;
688                         $passVar = $GLOBALS['TSFE']->cObj->callUserFunction($this->conf[$mConfKey], $funcConf, $passVar);
689                 }
690                 return $passVar;
691         }
692
693         /**
694          * User processing of contnet
695          *
696          * @param       string          Value of the TypoScript object triggering the processing.
697          * @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.
698          * @param       mixed           Input variable to process
699          * @return      mixed           Processed input variable, $passVar
700          * @see userProcess(), save(), modifyDataArrForFormUpdate()
701          */
702         function userProcess_alt($confVal, $confArr, $passVar) {
703                 if ($confVal) {
704                         $funcConf = $confArr;
705                         $funcConf['parentObj'] = $this;
706                         $passVar = $GLOBALS['TSFE']->cObj->callUserFunction($confVal, $funcConf, $passVar);
707                 }
708                 return $passVar;
709         }
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732         /*****************************************
733          *
734          * Database manipulation functions
735          *
736          *****************************************/
737
738         /**
739          * Performs the saving of records, either edited or created.
740          *
741          * @return      void
742          * @see init()
743          */
744         function save() {
745                 switch($this->cmd) {
746                         case 'edit':
747                                 $theUid = $this->dataArr['uid'];
748                                 $origArr = $GLOBALS['TSFE']->sys_page->getRawRecord($this->theTable, $theUid);          // Fetches the original record to check permissions
749                                 if ($this->conf['edit'] && ($GLOBALS['TSFE']->loginUser || $this->aCAuth($origArr)))    {       // Must be logged in in order to edit  (OR be validated by email)
750                                         $newFieldList = implode(',', array_intersect(explode(',', $this->fieldList), t3lib_div::trimExplode(',', $this->conf['edit.']['fields'], 1)));
751                                         if ($this->aCAuth($origArr) || $this->cObj->DBmayFEUserEdit($this->theTable, $origArr, $GLOBALS['TSFE']->fe_user->user, $this->conf['allowedGroups'], $this->conf['fe_userEditSelf'])) {
752                                                 $this->cObj->DBgetUpdate($this->theTable, $theUid, $this->dataArr, $newFieldList, TRUE);
753                                                 $this->currentArr = $GLOBALS['TSFE']->sys_page->getRawRecord($this->theTable, $theUid);
754                                                 $this->userProcess_alt($this->conf['edit.']['userFunc_afterSave'], $this->conf['edit.']['userFunc_afterSave.'], array('rec'=>$this->currentArr, 'origRec'=>$origArr));
755                                                 $this->saved=1;
756                                         } else {
757                                                 $this->error='###TEMPLATE_NO_PERMISSIONS###';
758                                         }
759                                 }
760                         break;
761                         default:
762                                 if ($this->conf['create']) {
763                                         $newFieldList = implode(',', array_intersect(explode(',', $this->fieldList), t3lib_div::trimExplode(',', $this->conf['create.']['fields'], 1)));
764                                         $this->cObj->DBgetInsert($this->theTable, $this->thePid, $this->dataArr, $newFieldList, TRUE);
765                                         $newId = $GLOBALS['TYPO3_DB']->sql_insert_id();
766
767                                         if ($this->theTable=='fe_users' && $this->conf['fe_userOwnSelf'])       {               // enables users, creating logins, to own them self.
768                                                 $extraList='';
769                                                 $dataArr = array();
770                                                 if ($GLOBALS['TCA'][$this->theTable]['ctrl']['fe_cruser_id'])           {
771                                                         $field=$GLOBALS['TCA'][$this->theTable]['ctrl']['fe_cruser_id'];
772                                                         $dataArr[$field]=$newId;
773                                                         $extraList.=','.$field;
774                                                 }
775                                                 if ($GLOBALS['TCA'][$this->theTable]['ctrl']['fe_crgroup_id']) {
776                                                         $field=$GLOBALS['TCA'][$this->theTable]['ctrl']['fe_crgroup_id'];
777                                                         list($dataArr[$field])=explode(',', $this->dataArr['usergroup']);
778                                                         $dataArr[$field]=intval($dataArr[$field]);
779                                                         $extraList.=','.$field;
780                                                 }
781                                                 if (count($dataArr)) {
782                                                         $this->cObj->DBgetUpdate($this->theTable, $newId, $dataArr, $extraList, TRUE);
783                                                 }
784                                         }
785
786                                         $this->currentArr = $GLOBALS['TSFE']->sys_page->getRawRecord($this->theTable, $newId);
787                                         $this->userProcess_alt($this->conf['create.']['userFunc_afterSave'], $this->conf['create.']['userFunc_afterSave.'], array('rec'=>$this->currentArr));
788                                         $this->saved=1;
789                                 }
790                         break;
791                 }
792         }
793
794         /**
795          * Deletes the record from table/uid, $this->theTable/$this->recUid, IF the fe-user has permission to do so.
796          * If the deleted flag should just be set, then it is done so. Otherwise the record truely is deleted along with any attached files.
797          * Called from init() if "cmd" was set to "delete" (and some other conditions)
798          *
799          * @return      string          void
800          * @see init()
801          */
802         function deleteRecord() {
803                 if ($this->conf['delete'])      {       // If deleting is enabled
804                         $origArr = $GLOBALS['TSFE']->sys_page->getRawRecord($this->theTable, $this->recUid);
805                         if ($GLOBALS['TSFE']->loginUser || $this->aCAuth($origArr))     {       // Must be logged in OR be authenticated by the aC code in order to delete
806                                         // If the recUid selects a record.... (no check here)
807                                 if (is_array($origArr)) {
808                                         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.
809                                                 if (!$GLOBALS['TCA'][$this->theTable]['ctrl']['delete'])        {       // If the record is fully deleted... then remove the image (or any file) attached.
810                                                         $this->deleteFilesFromRecord($this->recUid);
811                                                 }
812                                                 $this->cObj->DBgetDelete($this->theTable, $this->recUid, TRUE);
813                                                 $this->currentArr = $origArr;
814                                                 $this->saved = 1;
815                                         } else {
816                                                 $this->error = '###TEMPLATE_NO_PERMISSIONS###';
817                                         }
818                                 }
819                         }
820                 }
821         }
822
823         /**
824          * Deletes the files attached to a record and updates the record.
825          * Table/uid is $this->theTable/$uid
826          *
827          * @param       integer         Uid number of the record to delete from $this->theTable
828          * @return      void
829          * @access private
830          * @see deleteRecord()
831          */
832         function deleteFilesFromRecord($uid) {
833                 $table = $this->theTable;
834                 $rec = $GLOBALS['TSFE']->sys_page->getRawRecord($table, $uid);
835
836                 $GLOBALS['TSFE']->includeTCA();
837                 t3lib_div::loadTCA($table);
838                 $iFields=array();
839                 foreach ($GLOBALS['TCA'][$table]['columns'] as $field => $conf) {
840                         if ($conf['config']['type']=='group' && $conf['config']['internal_type']=='file') {
841
842                                 $GLOBALS['TYPO3_DB']->exec_UPDATEquery($table, 'uid='.intval($uid), array($field => ''));
843
844                                 $delFileArr = explode(',', $rec[$field]);
845                                 foreach ($delFileArr as $n) {
846                                         if ($n) {
847                                                 $fpath = $conf['config']['uploadfolder'].'/'.$n;
848                                                 unlink($fpath);
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
875         /*****************************************
876          *
877          * Command "display" functions
878          *
879          *****************************************/
880
881         /**
882          * Creates the preview display of delete actions
883          *
884          * @return      string          HTML content
885          * @see init()
886          */
887         function displayDeleteScreen() {
888                 if ($this->conf['delete'])      {       // If deleting is enabled
889                         $origArr = $GLOBALS['TSFE']->sys_page->getRawRecord($this->theTable, $this->recUid);
890                         if ($GLOBALS['TSFE']->loginUser || $this->aCAuth($origArr))     {       // Must be logged in OR be authenticated by the aC code in order to delete
891                                         // If the recUid selects a record.... (no check here)
892                                 if (is_array($origArr)) {
893                                         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.
894                                                 $this->markerArray['###HIDDENFIELDS###'].= '<input type="hidden" name="rU" value="'.$this->recUid.'" />';
895                                                 $content = $this->getPlainTemplate('###TEMPLATE_DELETE_PREVIEW###', $origArr);
896                                         } else {        // Else display error, that you could not edit that particular record...
897                                                 $content = $this->getPlainTemplate('###TEMPLATE_NO_PERMISSIONS###');
898                                         }
899                                 }
900                         } 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.
901                                 $content = $this->getPlainTemplate('###TEMPLATE_AUTH###');
902                         }
903                 } else {
904                         $content.='Delete-option is not set in TypoScript';
905                 }
906                 return $content;
907         }
908
909         /**
910          * Creates the "create" screen for records
911          *
912          * @return      string          HTML content
913          * @see init()
914          */
915         function displayCreateScreen() {
916                 if ($this->conf['create']) {
917                         $templateCode = $this->cObj->getSubpart($this->templateCode, ((!$GLOBALS['TSFE']->loginUser || $this->conf['create.']['noSpecialLoginForm'])?'###TEMPLATE_CREATE'.$this->previewLabel.'###':'###TEMPLATE_CREATE_LOGIN'.$this->previewLabel.'###'));
918                         $failure = t3lib_div::_GP('noWarnings')?'':$this->failure;
919                         if (!$failure)  $templateCode = $this->cObj->substituteSubpart($templateCode, '###SUB_REQUIRED_FIELDS_WARNING###', '');
920
921                         $templateCode = $this->removeRequired($templateCode, $failure);
922                         $this->setCObjects($templateCode);
923
924                         if (!is_array($this->dataArr)) {
925                                 $this->dataArr = array();
926                         }
927
928                         $markerArray = $this->cObj->fillInMarkerArray($this->markerArray, $this->dataArr, '', TRUE, 'FIELD_', $this->recInMarkersHSC);
929                         if ($this->conf['create.']['preview'] && !$this->previewLabel)  {$markerArray['###HIDDENFIELDS###'].= '<input type="hidden" name="preview" value="1" />';}
930                         $content = $this->cObj->substituteMarkerArray($templateCode, $markerArray);
931                         $content.=$this->cObj->getUpdateJS($this->modifyDataArrForFormUpdate($this->dataArr), $this->theTable.'_form', 'FE['.$this->theTable.']', $this->fieldList.$this->additionalUpdateFields);
932                 }
933                 return $content;
934         }
935
936         /**
937          * Creates the edit-screen for records
938          *
939          * @return      string          HTML content
940          * @see init()
941          */
942         function displayEditScreen() {
943                 if ($this->conf['edit'])        {       // If editing is enabled
944                         $origArr = $GLOBALS['TSFE']->sys_page->getRawRecord($this->theTable, $this->dataArr['uid']?$this->dataArr['uid']:$this->recUid);
945
946                         if ($GLOBALS['TSFE']->loginUser || $this->aCAuth($origArr))     {       // Must be logged in OR be authenticated by the aC code in order to edit
947                                         // If the recUid selects a record.... (no check here)
948                                 if (is_array($origArr)) {
949                                         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.
950                                                 $content=$this->displayEditForm($origArr);
951                                         } else {        // Else display error, that you could not edit that particular record...
952                                                 $content = $this->getPlainTemplate('###TEMPLATE_NO_PERMISSIONS###');
953                                         }
954                                 } elseif ($GLOBALS['TSFE']->loginUser) {        // If the recUid did not select a record, we display a menu of records. (eg. if no recUid)
955                                         $lockPid = $this->conf['edit.']['menuLockPid'] ? ' AND pid='.intval($this->thePid) : '';
956
957                                         $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));
958
959                                         if ($GLOBALS['TYPO3_DB']->sql_num_rows($res))   {       // If there are menu-items ...
960                                                 $templateCode = $this->getPlainTemplate('###TEMPLATE_EDITMENU###');
961                                                 $out='';
962                                                 $itemCode = $this->cObj->getSubpart($templateCode, '###ITEM###');
963                                                 while($menuRow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
964                                                         $markerArray = $this->cObj->fillInMarkerArray(array(), $menuRow, '', TRUE, 'FIELD_', $this->recInMarkersHSC);
965                                                         $markerArray = $this->setCObjects($itemCode, $menuRow, $markerArray, 'ITEM_');
966                                                         $out.= $this->cObj->substituteMarkerArray($itemCode, $markerArray);
967                                                 }
968                                                 $content=$this->cObj->substituteSubpart($templateCode, '###ALLITEMS###', $out);
969                                         } else {        // If there are not menu items....
970                                                 $content = $this->getPlainTemplate('###TEMPLATE_EDITMENU_NOITEMS###');
971                                         }
972                                 } else {
973                                         $content = $this->getPlainTemplate('###TEMPLATE_AUTH###');
974                                 }
975                         } 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.
976                                 $content = $this->getPlainTemplate('###TEMPLATE_AUTH###');
977                         }
978                 } else {
979                         $content.='Edit-option is not set in TypoScript';
980                 }
981                 return $content;
982         }
983
984         /**
985          * Subfunction for displayEditScreen(); Takes a record and creates an edit form based on the template code for it.
986          * This function is called if the user is editing a record and permitted to do so. Checked in displayEditScreen()
987          *
988          * @param       array           The array with the record to edit
989          * @return      string          HTML content
990          * @access private
991          * @see displayEditScreen()
992          */
993         function displayEditForm($origArr) {
994                 $currentArr = is_array($this->dataArr) ? $this->dataArr+$origArr : $origArr;
995
996                 if ($this->conf['debug']) {
997                         debug('displayEditForm(): ###TEMPLATE_EDIT' . $this->previewLabel . '###', 1);
998                 }
999                 $templateCode = $this->cObj->getSubpart($this->templateCode, '###TEMPLATE_EDIT'.$this->previewLabel.'###');
1000                 $failure = t3lib_div::_GP('noWarnings')?'':$this->failure;
1001                 if (!$failure)  {$templateCode = $this->cObj->substituteSubpart($templateCode, '###SUB_REQUIRED_FIELDS_WARNING###', '');}
1002
1003                 $templateCode = $this->removeRequired($templateCode, $failure);
1004
1005                 $this->setCObjects($templateCode, $currentArr);
1006
1007                 $markerArray = $this->cObj->fillInMarkerArray($this->markerArray, $currentArr, '', TRUE, 'FIELD_', $this->recInMarkersHSC);
1008
1009                 $markerArray['###HIDDENFIELDS###'].= '<input type="hidden" name="FE['.$this->theTable.'][uid]" value="'.$currentArr['uid'].'" />';
1010                 if ($this->conf['edit.']['preview'] && !$this->previewLabel)    {$markerArray['###HIDDENFIELDS###'].= '<input type="hidden" name="preview" value="1" />';}
1011                 $content = $this->cObj->substituteMarkerArray($templateCode, $markerArray);
1012                 $content.=$this->cObj->getUpdateJS($this->modifyDataArrForFormUpdate($currentArr), $this->theTable.'_form', 'FE['.$this->theTable.']', $this->fieldList.$this->additionalUpdateFields);
1013
1014                 return $content;
1015         }
1016
1017         /**
1018          * 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.
1019          * The idea is that only some allowed actions like this is allowed depending on the configured TypoScript.
1020          *
1021          * @return      string          HTML content displaying the status of the action
1022          */
1023         function procesSetFixed() {
1024                 if ($this->conf['setfixed']) {
1025                         $theUid = intval($this->recUid);
1026                         $origArr = $GLOBALS['TSFE']->sys_page->getRawRecord($this->theTable, $theUid);
1027                         $fD = t3lib_div::_GP('fD');
1028                         $sFK = t3lib_div::_GP('sFK');
1029
1030                         $fieldArr=array();
1031                         if (is_array($fD) || $sFK=='DELETE') {
1032                                 if (is_array($fD)) {
1033                                         foreach ($fD as $field => $value) {
1034                                                 $origArr[$field]=$value;
1035                                                 $fieldArr[]=$field;
1036                                         }
1037                                 }
1038                                 $theCode = $this->setfixedHash($origArr, $origArr['_FIELDLIST']);
1039                                 if (!strcmp($this->authCode, $theCode)) {
1040                                         if ($sFK=='DELETE') {
1041                                                 $this->cObj->DBgetDelete($this->theTable, $theUid, TRUE);
1042                                         } else {
1043                                                 $newFieldList = implode(',', array_intersect(t3lib_div::trimExplode(',', $this->fieldList), t3lib_div::trimExplode(',', implode($fieldArr, ','), 1)));
1044                                                 $this->cObj->DBgetUpdate($this->theTable, $theUid, $fD, $newFieldList, TRUE);
1045                                                 $this->currentArr = $GLOBALS['TSFE']->sys_page->getRawRecord($this->theTable, $theUid);
1046                                                 $this->userProcess_alt($this->conf['setfixed.']['userFunc_afterSave'], $this->conf['setfixed.']['userFunc_afterSave.'], array('rec'=>$this->currentArr, 'origRec'=>$origArr));
1047                                         }
1048
1049                                                 // Outputting template
1050                                         $this->markerArray = $this->cObj->fillInMarkerArray($this->markerArray, $origArr, '', TRUE, 'FIELD_', $this->recInMarkersHSC);
1051                                         $content = $this->getPlainTemplate('###TEMPLATE_SETFIXED_OK_'.$sFK.'###');
1052                                         if (!$content)  {$content = $this->getPlainTemplate('###TEMPLATE_SETFIXED_OK###');}
1053
1054                                                 // Compiling email
1055                                         $this->compileMail(
1056                                                 'SETFIXED_'.$sFK,
1057                                                 array($origArr),
1058                                                 $origArr[$this->conf['email.']['field']],
1059                                                 $this->conf['setfixed.']
1060                                         );
1061                                                 // Clearing cache if set:
1062                                         $this->clearCacheIfSet();
1063                                 } else $content = $this->getPlainTemplate('###TEMPLATE_SETFIXED_FAILED###');
1064                         } else $content = $this->getPlainTemplate('###TEMPLATE_SETFIXED_FAILED###');
1065                 }
1066                 return $content;
1067         }
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091         /*****************************************
1092          *
1093          * Template processing functions
1094          *
1095          *****************************************/
1096
1097
1098
1099         /**
1100          * Remove required parts from template code string
1101          *       Works like this:
1102          *               - 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.
1103          *               - These subparts are all removed, except if the field is listed in $failure string!
1104          *
1105          *              Only fields that are found in $this->requiredArr is processed.
1106          *
1107          * @param       string          The template HTML code
1108          * @param       string          Comma list of fields which has errors (and therefore should not be removed)
1109          * @return      string          The processed template HTML code
1110          */
1111         function removeRequired($templateCode, $failure) {
1112                 foreach ($this->requiredArr as $theField) {
1113                         if (!t3lib_div::inList($failure, $theField)) {
1114                                 $templateCode = $this->cObj->substituteSubpart($templateCode, '###SUB_REQUIRED_FIELD_'.$theField.'###', '');
1115                         }
1116                 }
1117                 return $templateCode;
1118         }
1119
1120         /**
1121          * Returns template subpart HTML code for the key given
1122          *
1123          * @param       string          Subpart marker to return subpart for.
1124          * @param       array           Optional data record array. If set, then all fields herein will also be substituted if found as markers in the template
1125          * @return      string          The subpart with all markers found in current $this->markerArray substituted.
1126          * @see tslib_cObj::fillInMarkerArray()
1127          */
1128         function getPlainTemplate($key, $r='') {
1129                 if ($this->conf['debug'])       debug('getPlainTemplate(): '.$key, 1);
1130                 $templateCode = $this->cObj->getSubpart($this->templateCode, $key);
1131                 $this->setCObjects($templateCode, is_array($r) ? $r : array());
1132                 return  $this->cObj->substituteMarkerArray(
1133                                 $templateCode,
1134                                 is_array($r) ? $this->cObj->fillInMarkerArray($this->markerArray, $r, '', TRUE, 'FIELD_', $this->recInMarkersHSC) : $this->markerArray
1135                         );
1136         }
1137
1138         /**
1139          * Modifies input array for passing on to tslib_cObj::getUpdateJS() which produces some JavaScript for form evaluation or the like.
1140          *
1141          * @param       array           The data array
1142          * @return      array           The processed input array
1143          * @see displayCreateScreen(), displayEditForm(), tslib_cObj::getUpdateJS()
1144          */
1145         function modifyDataArrForFormUpdate($inputArr) {
1146                 if (is_array($this->conf[$this->cmdKey.'.']['evalValues.'])) {
1147                         foreach ($this->conf[$this->cmdKey.'.']['evalValues.'] as $theField => $theValue) {
1148                                 $listOfCommands = t3lib_div::trimExplode(',', $theValue, 1);
1149                                 foreach ($listOfCommands as $cmd) {
1150                                         $cmdParts = preg_split('/\[|\]/', $cmd);        // Point is to enable parameters after each command enclosed in brackets [..]. These will be in position 1 in the array.
1151                                         $theCmd = trim($cmdParts[0]);
1152                                         switch($theCmd) {
1153                                                 case 'twice':
1154                                                         if (isset($inputArr[$theField])) {
1155                                                                 if (!isset($inputArr[$theField.'_again'])) {
1156                                                                         $inputArr[$theField.'_again'] = $inputArr[$theField];
1157                                                                 }
1158                                                                 $this->additionalUpdateFields.=','.$theField.'_again';
1159                                                         }
1160                                                 break;
1161                                         }
1162                                 }
1163                         }
1164                 }
1165                 if (is_array($this->conf['parseValues.'])) {
1166                         foreach ($this->conf['parseValues.'] as $theField => $theValue) {
1167                                 $listOfCommands = t3lib_div::trimExplode(',', $theValue, 1);
1168                                 foreach ($listOfCommands as $cmd) {
1169                                         $cmdParts = preg_split('/\[|\]/', $cmd);        // Point is to enable parameters after each command enclosed in brackets [..]. These will be in position 1 in the array.
1170                                         $theCmd = trim($cmdParts[0]);
1171                                         switch($theCmd) {
1172                                                 case 'multiple':
1173                                                         if (isset($inputArr[$theField]) && !$this->isPreview()) {
1174                                                                 $inputArr[$theField] = explode(',', $inputArr[$theField]);
1175                                                         }
1176                                                 break;
1177                                                 case 'checkArray':
1178                                                         if ($inputArr[$theField] && !$this->isPreview()) {
1179                                                                 for($a=0;$a<=30;$a++) {
1180                                                                         if ($inputArr[$theField] & pow(2, $a)) {
1181                                                                                 $alt_theField = $theField.']['.$a;
1182                                                                                 $inputArr[$alt_theField] = 1;
1183                                                                                 $this->additionalUpdateFields.=','.$alt_theField;
1184                                                                         }
1185                                                                 }
1186                                                         }
1187                                                 break;
1188                                         }
1189                                 }
1190                         }
1191                 }
1192
1193
1194                 $inputArr = $this->userProcess_alt(
1195                         $this->conf['userFunc_updateArray'],
1196                         $this->conf['userFunc_updateArray.'],
1197                         $inputArr
1198                 );
1199
1200                 return $this->escapeHTML($inputArr);
1201         }
1202
1203         /**
1204          * 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.
1205          *
1206          * @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!
1207          * @param       array           An alternative data record array (if empty then $this->dataArr is used)
1208          * @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.
1209          * @param       string          Optional prefix to set for the marker strings.
1210          * @return      array           The processed $markerArray (if given).
1211          */
1212         function setCObjects($templateCode, $currentArr=array(), $markerArray='', $specialPrefix='') {
1213                 if (is_array($this->conf['cObjects.'])) {
1214
1215                         foreach ($this->conf['cObjects.'] as $theKey => $theConf) {
1216                                 if (!strstr($theKey, '.')) {
1217                                         if (strstr($templateCode, '###' . $specialPrefix . 'CE_' . $theKey . '###')) {
1218                                                 $cObjCode = $this->cObj->cObjGetSingle($this->conf['cObjects.'][$theKey], $this->conf['cObjects.'][$theKey.'.'], 'cObjects.'.$theKey);
1219
1220                                                 if (!is_array($markerArray)) {
1221                                                         $this->markerArray['###'.$specialPrefix.'CE_'.$theKey.'###'] = $cObjCode;
1222                                                 } else {
1223                                                         $markerArray['###'.$specialPrefix.'CE_'.$theKey.'###'] = $cObjCode;
1224                                                 }
1225                                         }
1226                                         if (strstr($templateCode, '###' . $specialPrefix . 'PCE_' . $theKey . '###')) {
1227                                                 $local_cObj =t3lib_div::makeInstance('tslib_cObj');
1228                                                 $local_cObj->start(count($currentArr) ? $currentArr : $this->dataArr, $this->theTable);
1229                                                 $cObjCode = $local_cObj->cObjGetSingle($this->conf['cObjects.'][$theKey], $this->conf['cObjects.'][$theKey.'.'], 'cObjects.'.$theKey);
1230
1231                                                 if (!is_array($markerArray)) {
1232                                                         $this->markerArray['###'.$specialPrefix.'PCE_'.$theKey.'###'] = $cObjCode;
1233                                                 } else {
1234                                                         $markerArray['###'.$specialPrefix.'PCE_'.$theKey.'###'] = $cObjCode;
1235                                                 }
1236                                         }
1237                                 }
1238                         }
1239                 }
1240                 return $markerArray;
1241         }
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261         /*****************************************
1262          *
1263          * Emailing
1264          *
1265          *****************************************/
1266
1267         /**
1268          * Sends info mail to user
1269          *
1270          * @return      string          HTML content message
1271          * @see init(), compileMail(), sendMail()
1272          */
1273         function sendInfoMail() {
1274                 if ($this->conf['infomail'] && $this->conf['email.']['field']) {
1275                         $fetch = t3lib_div::_GP('fetch');
1276                         if ($fetch) {
1277                                         // Getting infomail config.
1278                                 $key= trim(t3lib_div::_GP('key'));
1279                                 if (is_array($this->conf['infomail.'][$key.'.']))               {
1280                                         $config = $this->conf['infomail.'][$key.'.'];
1281                                 } else {
1282                                         $config = $this->conf['infomail.']['default.'];
1283                                 }
1284                                 $pidLock='';
1285                                 if (!$config['dontLockPid']) {
1286                                         $pidLock='AND pid IN ('.$this->thePid.') ';
1287                                 }
1288
1289                                         // Getting records
1290                                 if (t3lib_utility_Math::canBeInterpretedAsInteger($fetch)) {
1291                                         $DBrows = $GLOBALS['TSFE']->sys_page->getRecordsByField($this->theTable, 'uid', $fetch, $pidLock, '', '', '1');
1292                                 } elseif ($fetch) {     // $this->conf['email.']['field'] must be a valid field in the table!
1293                                         $DBrows = $GLOBALS['TSFE']->sys_page->getRecordsByField($this->theTable, $this->conf['email.']['field'], $fetch, $pidLock, '', '', '100');
1294                                 }
1295
1296                                         // Processing records
1297                                 if (is_array($DBrows)) {
1298                                         $recipient = $DBrows[0][$this->conf['email.']['field']];
1299                                         $this->compileMail($config['label'], $DBrows, $recipient, $this->conf['setfixed.']);
1300                                 } elseif (t3lib_div::validEmail($fetch)) {
1301                                         $this->sendMail($fetch, '', trim($this->cObj->getSubpart($this->templateCode, '###'.$this->emailMarkPrefix.'NORECORD###')));
1302                                 }
1303
1304                                 $content = $this->getPlainTemplate('###TEMPLATE_INFOMAIL_SENT###');
1305                         } else {
1306                                 $content = $this->getPlainTemplate('###TEMPLATE_INFOMAIL###');
1307                         }
1308                 } else $content='Error: infomail option is not available or emailField is not setup in TypoScript';
1309                 return $content;
1310         }
1311
1312         /**
1313          * 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.
1314          *
1315          * @param       string          A key which together with $this->emailMarkPrefix will identify the part from the template code to use for the email.
1316          * @param       array           An array of records which fields are substituted in the templates
1317          * @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.
1318          * @param       array           Additional fields to set in the markerArray used in the substitution process
1319          * @return      void
1320          */
1321         function compileMail($key, $DBrows, $recipient, $setFixedConfig=array()) {
1322                 $GLOBALS['TT']->push('compileMail');
1323                 $mailContent='';
1324                 $key = $this->emailMarkPrefix.$key;
1325
1326                 $userContent['all'] = trim($this->cObj->getSubpart($this->templateCode, '###'.$key.'###'));
1327                 $adminContent['all'] = trim($this->cObj->getSubpart($this->templateCode, '###'.$key.'-ADMIN###'));
1328                 $userContent['rec'] = $this->cObj->getSubpart($userContent['all'], '###SUB_RECORD###');
1329                 $adminContent['rec'] = $this->cObj->getSubpart($adminContent['all'], '###SUB_RECORD###');
1330
1331                 foreach ($DBrows as $r) {
1332                         $markerArray = $this->cObj->fillInMarkerArray($this->markerArray, $r, '', 0);
1333                         $markerArray = $this->setCObjects($userContent['rec'] . $adminContent['rec'], $r, $markerArray, 'ITEM_');
1334                         $markerArray['###SYS_AUTHCODE###'] = $this->authCode($r);
1335                         $markerArray = $this->setfixed($markerArray, $setFixedConfig, $r);
1336
1337                         if ($userContent['rec'])        $userContent['accum'] .=$this->cObj->substituteMarkerArray($userContent['rec'], $markerArray);
1338                         if ($adminContent['rec'])       $adminContent['accum'].=$this->cObj->substituteMarkerArray($adminContent['rec'], $markerArray);
1339                 }
1340
1341                 if ($userContent['all'])        $userContent['final'] .=$this->cObj->substituteSubpart($userContent['all'], '###SUB_RECORD###', $userContent['accum']);
1342                 if ($adminContent['all'])       $adminContent['final'].=$this->cObj->substituteSubpart($adminContent['all'], '###SUB_RECORD###', $adminContent['accum']);
1343
1344                 if (t3lib_utility_Math::canBeInterpretedAsInteger($recipient)) {
1345                         $fe_userRec = $GLOBALS['TSFE']->sys_page->getRawRecord('fe_users', $recipient);
1346                         $recipient=$fe_userRec['email'];
1347                 }
1348
1349                 $GLOBALS['TT']->setTSlogMessage('Template key: ###'.$key.'###, userContentLength: '.strlen($userContent['final']).', adminContentLength: '.strlen($adminContent['final']));
1350
1351                 $this->sendMail($recipient, $this->conf['email.']['admin'], $userContent['final'], $adminContent['final']);
1352                 $GLOBALS['TT']->pull();
1353         }
1354
1355         /**
1356          * Actually sends the requested mails (through $this->cObj->sendNotifyEmail or through $this->sendHTMLMail).
1357          * As of TYPO3 v4.3 with autoloader, a check for $GLOBALS['TSFE']->config['config']['incT3Lib_htmlmail'] has been included for backwards compatibility.
1358          *
1359          * @param       string          Recipient email address (or list)
1360          * @param       string          Possible "admin" email address. Will enable sending of admin emails if also $adminContent is provided
1361          * @param       string          Content for the regular email to user
1362          * @param       string          Content for the admin email to administrator
1363          * @return      void
1364          * @access private
1365          * @see compileMail(), sendInfoMail()
1366          */
1367         function sendMail($recipient, $admin, $content='', $adminContent='') {
1368                         // Admin mail:
1369                 if ($admin && $adminContent) {
1370                         if (!$this->isHTMLContent($adminContent) || !$GLOBALS['TSFE']->config['config']['incT3Lib_htmlmail']) {
1371                                 $admMail = $this->cObj->sendNotifyEmail(
1372                                                                         strip_tags($adminContent),
1373                                                                         $admin,
1374                                                                         '',
1375                                                                         $this->conf['email.']['from'],
1376                                                                         $this->conf['email.']['fromName'],
1377                                                                         $recipient
1378                                                         );
1379                         } else {
1380                                 $this->sendHTMLMail($adminContent,
1381                                                                         $admin,
1382                                                                         '',
1383                                                                         $this->conf['email.']['from'],
1384                                                                         $this->conf['email.']['fromName'],
1385                                                                         $recipient
1386                                                         );
1387                         }
1388                 }
1389                         // user mail:
1390                 if (!$this->isHTMLContent($content) || !$GLOBALS['TSFE']->config['config']['incT3Lib_htmlmail']) {
1391                         $this->cObj->sendNotifyEmail(
1392                                                                 strip_tags($content),
1393                                                                 $recipient,
1394                                                                 '',
1395                                                                 $this->conf['email.']['from'],
1396                                                                 $this->conf['email.']['fromName']
1397                                                 );
1398                 } else {
1399                         $this->sendHTMLMail($content,
1400                                                                 $recipient,
1401                                                                 '',
1402                                                                 $this->conf['email.']['from'],
1403                                                                 $this->conf['email.']['fromName']
1404                                                 );
1405                 }
1406         }
1407
1408         /**
1409          * Detects if content is HTML (looking for <html> tag as first and last in string)
1410          *
1411          * @param       string          Content string to test
1412          * @return      boolean         Returns TRUE if the content begins and ends with <html></html>-tags
1413          */
1414         function isHTMLContent($c) {
1415                 $c = trim($c);
1416                 $first = strtolower(substr($c, 0, 6));
1417                 $last = strtolower(substr($c, -7));
1418                 if ($first.$last=='<html></html>')      return 1;
1419         }
1420
1421         /**
1422          * Sending HTML email, using same parameters as tslib_cObj::sendNotifyEmail()
1423          *
1424          * @param       string          The message content. If blank, no email is sent.
1425          * @param       string          Comma list of recipient email addresses
1426          * @param       string          IGNORE this parameter
1427          * @param       string          "From" email address
1428          * @param       string          Optional "From" name
1429          * @param       string          Optional "Reply-To" header email address.
1430          * @return      void
1431          * @access private
1432          * @see sendMail(), tslib_cObj::sendNotifyEmail()
1433          */
1434         function sendHTMLMail($content, $recipient, $dummy, $fromEmail, $fromName, $replyTo = '') {
1435                 if (trim($recipient) && trim($content)) {
1436                         $parts = preg_split('/<title>|<\/title>/i', $content, 3);
1437                         $subject = trim($parts[1]) ? trim($parts[1]) : 'TYPO3 FE Admin message';
1438
1439                         $Typo3_htmlmail = t3lib_div::makeInstance('t3lib_htmlmail');
1440                         $Typo3_htmlmail->start();
1441                         $Typo3_htmlmail->useBase64();
1442
1443                         $Typo3_htmlmail->subject = $subject;
1444                         $Typo3_htmlmail->from_email = $fromEmail;
1445                         $Typo3_htmlmail->from_name = $fromName;
1446                         $Typo3_htmlmail->replyto_email = $replyTo ? $replyTo : $fromEmail;
1447                         $Typo3_htmlmail->replyto_name = $replyTo ? '' : $fromName;
1448                         $Typo3_htmlmail->organisation = '';
1449                         $Typo3_htmlmail->priority = 3;
1450
1451                                 // HTML
1452                         $Typo3_htmlmail->theParts['html']['content'] = $content;        // Fetches the content of the page
1453                         $Typo3_htmlmail->theParts['html']['path'] = '';
1454                         $Typo3_htmlmail->extractMediaLinks();
1455                         $Typo3_htmlmail->extractHyperLinks();
1456                         $Typo3_htmlmail->fetchHTMLMedia();
1457                         $Typo3_htmlmail->substMediaNamesInHTML(0);      // 0 = relative
1458                         $Typo3_htmlmail->substHREFsInHTML();
1459                         $Typo3_htmlmail->setHTML($Typo3_htmlmail->encodeMsg($Typo3_htmlmail->theParts['html']['content']));
1460
1461                                 // PLAIN
1462                         $Typo3_htmlmail->addPlain('');
1463
1464                                 // SET Headers and Content
1465                         $Typo3_htmlmail->setHeaders();
1466                         $Typo3_htmlmail->setContent();
1467                         $Typo3_htmlmail->setRecipient($recipient);
1468
1469                         $Typo3_htmlmail->sendtheMail();
1470                 }
1471         }
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496         /*****************************************
1497          *
1498          * Various helper functions
1499          *
1500          *****************************************/
1501
1502
1503         /**
1504          * 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.
1505          * This allows to authenticate editing without having a fe_users login
1506          * Uses $this->authCode which is set in init() by "t3lib_div::_GP('aC');"
1507          *
1508          * @param       array           The data array for which to evaluate authentication
1509          * @return      boolean         TRUE if authenticated OK
1510          * @see authCode(), init()
1511          */
1512         function aCAuth($r) {
1513                 if ($this->authCode && !strcmp($this->authCode, $this->authCode($r))) {
1514                         return TRUE;
1515                 }
1516         }
1517
1518         /**
1519          * Creating authentication hash string based on input record and the fields listed in TypoScript property "authcodeFields"
1520          *
1521          * @param       array           The data record
1522          * @param       string          Additional string to include in the hash
1523          * @return      string          Hash string of $this->codeLength (if TypoScript "authcodeFields" was set)
1524          * @see aCAuth()
1525          */
1526         function authCode($r, $extra = '') {
1527                 $l=$this->codeLength;
1528                 if ($this->conf['authcodeFields']) {
1529                         $fieldArr = t3lib_div::trimExplode(',', $this->conf['authcodeFields'], 1);
1530                         $value='';
1531                         foreach ($fieldArr as $field) {
1532                                 $value.=$r[$field].'|';
1533                         }
1534                         $value.=$extra.'|'.$this->conf['authcodeFields.']['addKey'];
1535                         if ($this->conf['authcodeFields.']['addDate']) {
1536                                 $value.='|'.date($this->conf['authcodeFields.']['addDate']);
1537                         }
1538                         $value.=$GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'];
1539                         return substr(md5($value), 0, $l);
1540                 }
1541         }
1542
1543         /**
1544          * Adding keys to the marker array with "setfixed" GET parameters
1545          *
1546          * @param       array           Marker-array to modify/add a key to.
1547          * @param       array           TypoScript properties configuring "setfixed" for the plugin. Basically this is $this->conf['setfixed.'] passed along.
1548          * @param       array           The data record
1549          * @return      array           Processed $markerArray
1550          * @see compileMail()
1551          */
1552         function setfixed($markerArray, $setfixed, $r) {
1553                 if (is_array($setfixed)) {
1554                         foreach ($setfixed as $theKey => $data) {
1555                                 if (!strcmp($theKey, 'DELETE')) {
1556                                         $recCopy = $r;
1557                                         $string='&cmd=setfixed&sFK='.rawurlencode($theKey).'&rU='.$r['uid'];
1558                                         $string.='&aC='.$this->setfixedHash($recCopy, $data['_FIELDLIST']);
1559                                         $markerArray['###SYS_SETFIXED_DELETE###'] = $string;
1560                                         $markerArray['###SYS_SETFIXED_HSC_DELETE###'] = htmlspecialchars($string);
1561                                 } elseif (strstr($theKey, '.')) {
1562                                         $theKey = substr($theKey, 0, -1);
1563                                         if (is_array($data)) {
1564                                                 $recCopy = $r;
1565                                                 $string='&cmd=setfixed&sFK='.rawurlencode($theKey).'&rU='.$r['uid'];
1566                                                 foreach ($data as $fieldName => $fieldValue) {
1567                                                         $string.='&fD%5B'.$fieldName.'%5D='.rawurlencode($fieldValue);
1568                                                         $recCopy[$fieldName]=$fieldValue;
1569                                                 }
1570                                                 $string.='&aC='.$this->setfixedHash($recCopy, $data['_FIELDLIST']);
1571                                                 $markerArray['###SYS_SETFIXED_'.$theKey.'###'] = $string;
1572                                                 $markerArray['###SYS_SETFIXED_HSC_'.$theKey.'###'] = htmlspecialchars($string);
1573                                         }
1574                                 }
1575                         }
1576                 }
1577                 return $markerArray;
1578         }
1579
1580         /**
1581          * Creating hash string for setFixed. Much similar to authCode()
1582          *
1583          * @param       array           The data record
1584          * @param       string          List of fields to use
1585          * @return      string          Hash string of $this->codeLength (if TypoScript "authcodeFields" was set)
1586          * @see setfixed(), authCode()
1587          */
1588         function setfixedHash($recCopy, $fields='') {
1589                 if ($fields) {
1590                         $fieldArr = t3lib_div::trimExplode(',', $fields, 1);
1591                         foreach ($fieldArr as $k => $v) {
1592                                 $recCopy_temp[$k]=$recCopy[$v];
1593                         }
1594                 } else {
1595                         $recCopy_temp=$recCopy;
1596                 }
1597                 $encStr = implode('|', $recCopy_temp) . '|' . $this->conf['authcodeFields.']['addKey'] . '|' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'];
1598                 $hash = substr(md5($encStr), 0, $this->codeLength);
1599                 return $hash;
1600         }
1601
1602
1603         /**
1604          * Returns TRUE if preview display is on.
1605          *
1606          * @return      boolean
1607          */
1608         function isPreview() {
1609                 return ($this->conf[$this->cmdKey.'.']['preview'] && $this->preview);
1610         }
1611
1612         /**
1613          * Creates an instance of class "t3lib_basicFileFunctions" in $this->fileFunc (if not already done)
1614          *
1615          * @return      void
1616          */
1617         function createFileFuncObj() {
1618                 if (!$this->fileFunc) {
1619                         $this->fileFunc = t3lib_div::makeInstance('t3lib_basicFileFunctions');
1620                 }
1621         }
1622
1623         /**
1624          * If TypoScript property clearCacheOfPages is set then all page ids in this value will have their cache cleared
1625          *
1626          * @return      void
1627          */
1628         function clearCacheIfSet() {
1629                 if ($this->conf['clearCacheOfPages']) {
1630                         $cc_pidList = $GLOBALS['TYPO3_DB']->cleanIntList($this->conf['clearCacheOfPages']);
1631                         $GLOBALS['TSFE']->clearPageCacheContent_pidList($cc_pidList);
1632                 }
1633         }
1634
1635         /**
1636          * 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
1637          *
1638          * @param       string          Field name
1639          * @param       string          Command identifier string
1640          * @param       string          Alternative label, shown if no other error string was found
1641          * @return      string          The error message string
1642          */
1643         function getFailure($theField, $theCmd, $label) {
1644                 return isset($this->conf['evalErrors.'][$theField.'.'][$theCmd]) ? $this->conf['evalErrors.'][$theField.'.'][$theCmd] : $label;
1645         }
1646
1647         /**
1648          * Will escape HTML-tags
1649          *
1650          * @param       mixed           The unescaped data
1651          * @return      mixed           The processed input data
1652          */
1653         function escapeHTML($var) {
1654                 if (is_array($var)) {
1655                         foreach ($var as $k => $value) {
1656                                 $var[$k] = $this->escapeHTML($var[$k]);
1657                         }
1658                 } else {
1659                         $var = htmlspecialchars($var, ENT_NOQUOTES);
1660                 }
1661                 return $var;
1662         }
1663 }
1664
1665
1666 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['media/scripts/fe_adminLib.inc'])) {
1667         include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['media/scripts/fe_adminLib.inc']);
1668 }
1669 ?>