* Fixed bug #4515: Input field with settings eval date and readOnly shows...
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_tceforms.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2006 Kasper Skaarhoj (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 * Contains TYPO3 Core Form generator - AKA "TCEforms"
29 *
30 * $Id$
31 * Revised for TYPO3 3.6 August/2003 by Kasper Skaarhoj
32 * XHTML compliant
33 *
34 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
35 */
36 /**
37 * [CLASS/FUNCTION INDEX of SCRIPT]
38 *
39 *
40 *
41 * 195: class t3lib_TCEforms
42 * 300: function t3lib_TCEforms()
43 * 334: function initDefaultBEmode()
44 *
45 * SECTION: Rendering the forms, fields etc
46 * 379: function getSoloField($table,$row,$theFieldToReturn)
47 * 418: function getMainFields($table,$row,$depth=0)
48 * 613: function getListedFields($table,$row,$list)
49 * 654: function getPaletteFields($table,$row,$palette,$header='',$itemList='',$collapsedHeader='')
50 * 730: function getSingleField($table,$field,$row,$altName='',$palette=0,$extra='',$pal=0)
51 * 886: function getSingleField_SW($table,$field,$row,&$PA)
52 *
53 * SECTION: Rendering of each TCEform field type
54 * 959: function getSingleField_typeInput($table,$field,$row,&$PA)
55 * 1040: function getSingleField_typeText($table,$field,$row,&$PA)
56 * 1153: function getSingleField_typeCheck($table,$field,$row,&$PA)
57 * 1219: function getSingleField_typeRadio($table,$field,$row,&$PA)
58 * 1254: function getSingleField_typeSelect($table,$field,$row,&$PA)
59 * 1334: function getSingleField_typeSelect_single($table,$field,$row,&$PA,$config,$selItems,$nMV_label)
60 * 1451: function getSingleField_typeSelect_checkbox($table,$field,$row,&$PA,$config,$selItems,$nMV_label)
61 * 1570: function getSingleField_typeSelect_singlebox($table,$field,$row,&$PA,$config,$selItems,$nMV_label)
62 * 1680: function getSingleField_typeSelect_multiple($table,$field,$row,&$PA,$config,$selItems,$nMV_label)
63 * 1779: function getSingleField_typeGroup($table,$field,$row,&$PA)
64 * 1948: function getSingleField_typeNone($table,$field,$row,&$PA)
65 * 1964: function getSingleField_typeNone_render($config,$itemValue)
66 * 2026: function getSingleField_typeFlex($table,$field,$row,&$PA)
67 * 2164: function getSingleField_typeFlex_langMenu($languages,$elName,$selectedLanguage,$multi=1)
68 * 2183: function getSingleField_typeFlex_sheetMenu($sArr,$elName,$sheetKey)
69 * 2218: function getSingleField_typeFlex_draw($dataStruct,$editData,$cmdData,$table,$field,$row,&$PA,$formPrefix='',$level=0,$tRows=array())
70 * 2411: function getSingleField_typeUnknown($table,$field,$row,&$PA)
71 * 2426: function getSingleField_typeUser($table,$field,$row,&$PA)
72 *
73 * SECTION: Field content processing
74 * 2455: function formatValue ($config, $itemValue)
75 *
76 * SECTION: "Configuration" fetching/processing functions
77 * 2547: function getRTypeNum($table,$row)
78 * 2573: function rearrange($fields)
79 * 2599: function getExcludeElements($table,$row,$typeNum)
80 * 2647: function getFieldsToAdd($table,$row,$typeNum)
81 * 2672: function mergeFieldsWithAddedFields($fields,$fieldsToAdd)
82 * 2704: function setTSconfig($table,$row,$field='')
83 * 2726: function getSpecConfForField($table,$row,$field)
84 * 2747: function getSpecConfFromString($extraString, $defaultExtras)
85 *
86 * SECTION: Display of localized content etc.
87 * 2775: function registerDefaultLanguageData($table,$rec)
88 * 2807: function getLanguageOverlayRawValue($table, $row, $field, $fieldConf)
89 * 2835: function renderDefaultLanguageContent($table,$field,$row,$item)
90 * 2858: function renderDefaultLanguageDiff($table,$field,$row,$item)
91 *
92 * SECTION: Form element helper functions
93 * 2914: function dbFileIcons($fName,$mode,$allowed,$itemArray,$selector='',$params=array(),$onFocus='')
94 * 3067: function getClipboardElements($allowed,$mode)
95 * 3116: function getClickMenu($str,$table,$uid='')
96 * 3137: function renderWizards($itemKinds,$wizConf,$table,$row,$field,&$PA,$itemName,$specConf,$RTE=0)
97 * 3341: function getIcon($icon)
98 * 3368: function optionTagStyle($iconString)
99 * 3384: function extractValuesOnlyFromValueLabelList($itemFormElValue)
100 * 3406: function wrapOpenPalette($header,$table,$row,$palette,$retFunc=0)
101 * 3430: function checkBoxParams($itemName,$thisValue,$c,$iCount,$addFunc='')
102 * 3444: function elName($itemName)
103 * 3455: function noTitle($str,$wrapParts=array())
104 * 3464: function blur()
105 * 3473: function thisReturnUrl()
106 * 3486: function getSingleHiddenField($table,$field,$row)
107 * 3508: function formWidth($size=48,$textarea=0)
108 * 3535: function formWidthText($size=48,$wrap='')
109 * 3551: function formElStyle($type)
110 * 3562: function formElClass($type)
111 * 3573: function formElStyleClassValue($type, $class=FALSE)
112 * 3595: function insertDefStyle($type)
113 * 3614: function getDynTabMenu($parts, $idString)
114 *
115 * SECTION: Item-array manipulation functions (check/select/radio)
116 * 3653: function initItemArray($fieldValue)
117 * 3671: function addItems($items,$iArray)
118 * 3693: function procItems($items,$iArray,$config,$table,$row,$field)
119 * 3717: function addSelectOptionsToItemArray($items,$fieldValue,$TSconfig,$field)
120 * 3937: function addSelectOptionsToItemArray_makeModuleData($value)
121 * 3959: function foreignTable($items,$fieldValue,$TSconfig,$field,$pFFlag=0)
122 *
123 * SECTION: Template functions
124 * 4040: function setNewBEDesign()
125 * 4095: function intoTemplate($inArr,$altTemplate='')
126 * 4119: function addUserTemplateMarkers($marker,$table,$field,$row,&$PA)
127 * 4130: function wrapLabels($str)
128 * 4143: function wrapTotal($c,$rec,$table)
129 * 4156: function replaceTableWrap($arr,$rec,$table)
130 * 4194: function wrapBorder(&$out_array,&$out_pointer)
131 * 4216: function rplColorScheme($inTemplate)
132 * 4236: function getDivider()
133 * 4246: function printPalette($palArr)
134 * 4297: function helpTextIcon($table,$field,$force=0)
135 * 4317: function helpText($table,$field)
136 * 4338: function setColorScheme($scheme)
137 * 4362: function resetSchemes()
138 * 4373: function storeSchemes()
139 * 4385: function restoreSchemes()
140 *
141 * SECTION: JavaScript related functions
142 * 4415: function JStop()
143 * 4466: function JSbottom($formname='forms[0]')
144 * 4780: function dbFileCon($formObj='document.forms[0]')
145 * 4982: function printNeededJSFunctions()
146 * 5009: function printNeededJSFunctions_top()
147 *
148 * SECTION: Various helper functions
149 * 5057: function getDefaultRecord($table,$pid=0)
150 * 5096: function getRecordPath($table,$rec)
151 * 5110: function readPerms()
152 * 5124: function sL($str)
153 * 5137: function getLL($str)
154 * 5158: function isPalettesCollapsed($table,$palette)
155 * 5174: function isDisplayCondition($displayCond,$row,$ffValueKey='')
156 * 5275: function getTSCpid($table,$uid,$pid)
157 * 5289: function doLoadTableDescr($table)
158 * 5301: function getAvailableLanguages($onlyIsoCoded=1,$setDefault=1)
159 *
160 *
161 * 5343: class t3lib_TCEforms_FE extends t3lib_TCEforms
162 * 5351: function wrapLabels($str)
163 * 5361: function printPalette($palArr)
164 * 5386: function setFancyDesign()
165 *
166 * TOTAL FUNCTIONS: 100
167 * (This index is automatically created/updated by the extension "extdeveval")
168 *
169 */
170
171
172
173
174
175
176
177
178
179
180
181
182
183 require_once(PATH_t3lib.'class.t3lib_diff.php');
184
185
186
187 /**
188 * 'TCEforms' - Class for creating the backend editing forms.
189 *
190 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
191 * @coauthor Rene Fritz <r.fritz@colorcube.de>
192 * @package TYPO3
193 * @subpackage t3lib
194 */
195 class t3lib_TCEforms {
196
197 // variables not commented yet.... (do so...)
198 var $palFieldArr = array();
199 var $disableWizards = 0;
200 var $isPalettedoc = 0;
201 var $paletteMargin = 1;
202 var $defStyle = ''; // 'font-family:Verdana;font-size:10px;';
203 var $cachedTSconfig = array();
204 var $cachedTSconfig_fieldLevel = array();
205 var $transformedRow = array();
206 var $extJSCODE = '';
207 var $printNeededJS = array();
208 var $hiddenFieldAccum=array();
209 var $TBE_EDITOR_fieldChanged_func='';
210 var $loadMD5_JS=1;
211 var $prevBorderStyle='[nothing here...]'; // Something unique...
212 var $allowUpload=0; // If set direct upload fields will be shown
213 var $titleLen=15; // $BE_USER->uc['titleLen'] but what is default??
214 var $defaultLanguageData = array(); // Array where records in the default language is stored. (processed by transferdata)
215 var $defaultLanguageData_diff = array(); // Array where records in the default language is stored (raw without any processing. used for making diff)
216
217
218 // EXTERNAL, static
219 var $backPath=''; // Set this to the 'backPath' pointing back to the typo3 admin directory from the script where this form is displayed.
220 var $returnUrl=''; // Alternative return URL path (default is t3lib_div::linkThisScript())
221 var $doSaveFieldName=''; // Can be set to point to a field name in the form which will be set to '1' when the form is submitted with a *save* button. This way the recipient script can determine that the form was submitted for save and not "close" for example.
222 var $palettesCollapsed=0; // Can be set true/false to whether palettes (secondary options) are in the topframe or in form. True means they are NOT IN-form. So a collapsed palette is one, which is shown in the top frame, not in the page.
223 var $disableRTE=0; // If set, the RTE is disabled (from form display, eg. by checkbox in the bottom of the page!)
224 var $globalShowHelp=1; // If false, then all CSH will be disabled, regardless of settings in $this->edit_showFieldHelp
225 var $localizationMode=''; // If true, the forms are rendering only localization relevant fields of the records.
226 var $fieldOrder=''; // Overrule the field order set in TCA[types][showitem], eg for tt_content this value, 'bodytext,image', would make first the 'bodytext' field, then the 'image' field (if set for display)... and then the rest in the old order.
227 var $doPrintPalette=1; // If set to false, palettes will NEVER be rendered.
228 var $clipObj=FALSE; // Set to initialized clipboard object; Then the element browser will offer a link to paste in records from clipboard.
229 var $enableClickMenu=FALSE; // Enable click menu on reference icons.
230 var $enableTabMenu = FALSE; // Enable Tab Menus. If set to true, the JavaScript content from template::getDynTabMenuJScode() must be included in the document.
231 var $renderReadonly = FALSE; // When enabled all fields are rendered non-editable.
232
233 var $form_rowsToStylewidth = 9.58; // Form field width compensation: Factor from NN4 form field widths to style-aware browsers (like NN6+ and MSIE, with the $CLIENT[FORMSTYLE] value set)
234 var $form_largeComp = 1.33; // Form field width compensation: Compensation for large documents, doc-tab (editing)
235 var $charsPerRow=40; // The number of chars expected per row when the height of a text area field is automatically calculated based on the number of characters found in the field content.
236 var $maxTextareaWidth=48; // The maximum abstract value for textareas
237 var $maxInputWidth=48; // The maximum abstract value for input fields
238 var $defaultMultipleSelectorStyle='width:250px;'; // Default style for the selector boxes used for multiple items in "select" and "group" types.
239
240
241 // INTERNAL, static
242 var $prependFormFieldNames = 'data'; // The string to prepend formfield names with.
243 var $prependFormFieldNames_file = 'data_files'; // The string to prepend FILE form field names with.
244 var $formName = 'editform'; // The name attribute of the form.
245
246
247
248 // INTERNAL, dynamic
249 var $perms_clause=''; // Set by readPerms() (caching)
250 var $perms_clause_set=0; // Set by readPerms() (caching-flag)
251 var $edit_showFieldHelp=''; // Used to indicate the mode of CSH (Context Sensitive Help), whether it should be icons-only ('icon'), full description ('text') or not at all (blank).
252 var $docLarge=0; // If set, the forms will be rendered a little wider, more precisely with a factor of $this->form_largeComp.
253 var $clientInfo=array(); // Loaded with info about the browser when class is instantiated.
254 var $RTEenabled=0; // True, if RTE is possible for the current user (based on result from BE_USER->isRTE())
255 var $RTEenabled_notReasons=''; // If $this->RTEenabled was false, you can find the reasons listed in this array which is filled with reasons why the RTE could not be loaded)
256 var $RTEcounter = 0; // Counter that is incremented before an RTE is created. Can be used for unique ids etc.
257
258 var $colorScheme; // Contains current color scheme
259 var $classScheme; // Contains current class scheme
260 var $defColorScheme; // Contains the default color scheme
261 var $defClassScheme; // Contains the default class scheme
262 var $fieldStyle; // Contains field style values
263 var $borderStyle; // Contains border style values.
264
265 var $commentMessages=array(); // An accumulation of messages from the class.
266
267 // INTERNAL, templates
268 var $totalWrap='<hr />|<hr />'; // Total wrapping for the table rows.
269 var $fieldTemplate='<b>###FIELD_NAME###</b><br />###FIELD_ITEM###<hr />'; // Field template
270 var $sectionWrap=''; // Wrapping template code for a section
271 var $palFieldTemplateHeader=''; // Template for palette headers
272 var $palFieldTemplate=''; // Template for palettes
273
274 // INTERNAL, working memory
275 var $excludeElements=''; // Set to the fields NOT to display, if any.
276 var $palettesRendered=array(); // During rendering of forms this will keep track of which palettes has already been rendered (so they are not rendered twice by mistake)
277 var $hiddenFieldListArr = array(); // This array of fields will be set as hidden-fields instead of rendered normally! For instance palette fields edited in the top frame are set as hidden fields since the main form has to submit the values. The top frame actually just sets the value in the main form!
278 var $requiredFields=array(); // Used to register input-field names, which are required. (Done during rendering of the fields). This information is then used later when the JavaScript is made.
279 var $requiredElements=array(); // Used to register the min and max number of elements for selectorboxes where that apply (in the "group" type for instance)
280 var $renderDepth=0; // Keeps track of the rendering depth of nested records.
281 var $savedSchemes=array(); // Color scheme buffer.
282
283 // Internal, registers for user defined functions etc.
284 var $additionalCode_pre = array(); // Additional HTML code, printed before the form.
285 var $additionalJS_pre = array(); // Additional JavaScript, printed before the form
286 var $additionalJS_post = array(); // Additional JavaScript printed after the form
287 var $additionalJS_submit = array(); // Additional JavaScript executed on submit; If you set "OK" variable it will raise an error about RTEs not being loaded and offer to block further submission.
288
289
290
291
292
293
294
295 /**
296 * Constructor function, setting internal variables, loading the styles used.
297 *
298 * @return void
299 */
300 function t3lib_TCEforms() {
301 global $CLIENT;
302
303 $this->clientInfo = t3lib_div::clientInfo();
304
305 $this->RTEenabled = $GLOBALS['BE_USER']->isRTE();
306 if (!$this->RTEenabled) {
307 $this->RTEenabled_notReasons = implode(chr(10),$GLOBALS['BE_USER']->RTE_errors);
308 $this->commentMessages[] = 'RTE NOT ENABLED IN SYSTEM due to:'.chr(10).$this->RTEenabled_notReasons;
309 }
310
311 // Default color+class scheme
312 $this->defColorScheme = array(
313 $GLOBALS['SOBE']->doc->bgColor, // Background for the field AND palette
314 t3lib_div::modifyHTMLColorAll($GLOBALS['SOBE']->doc->bgColor,-20), // Background for the field header
315 t3lib_div::modifyHTMLColorAll($GLOBALS['SOBE']->doc->bgColor,-10), // Background for the palette field header
316 'black', // Field header font color
317 '#666666' // Palette field header font color
318 );
319 $this->defColorScheme = array();
320
321 // Override / Setting defaults from TBE_STYLES array
322 $this->resetSchemes();
323
324 // Setting the current colorScheme to default.
325 $this->defColorScheme = $this->colorScheme;
326 $this->defClassScheme = $this->classScheme;
327 }
328
329 /**
330 * Initialize various internal variables.
331 *
332 * @return void
333 */
334 function initDefaultBEmode() {
335 global $BE_USER;
336 $this->prependFormFieldNames = 'data';
337 $this->formName = 'editform';
338 $this->setNewBEDesign();
339 $this->docLarge = $BE_USER->uc['edit_wideDocument'] ? 1 : 0;
340 $this->edit_showFieldHelp = $BE_USER->uc['edit_showFieldHelp'];
341
342 $this->edit_docModuleUpload = $BE_USER->uc['edit_docModuleUpload'];
343 $this->titleLen = $BE_USER->uc['titleLen'];
344 }
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362 /*******************************************************
363 *
364 * Rendering the forms, fields etc
365 *
366 *******************************************************/
367
368 /**
369 * Will return the TCEform element for just a single field from a record.
370 * The field must be listed in the currently displayed fields (as found in [types][showitem]) for the record.
371 * This also means that the $table/$row supplied must be complete so the list of fields to show can be found correctly
372 *
373 * @param string The table name
374 * @param array The record from the table for which to render a field.
375 * @param string The field name to return the TCEform element for.
376 * @return string HTML output
377 * @see getMainFields()
378 */
379 function getSoloField($table,$row,$theFieldToReturn) {
380 global $TCA;
381
382 if ($TCA[$table]) {
383 t3lib_div::loadTCA($table);
384 $typeNum = $this->getRTypeNum($table,$row);
385 if ($TCA[$table]['types'][$typeNum]) {
386 $itemList = $TCA[$table]['types'][$typeNum]['showitem'];
387 if ($itemList) {
388 $fields = t3lib_div::trimExplode(',',$itemList,1);
389 $excludeElements = $this->excludeElements = $this->getExcludeElements($table,$row,$typeNum);
390
391 reset($fields);
392 while(list(,$fieldInfo)=each($fields)) {
393 $parts = explode(';',$fieldInfo);
394
395 $theField = trim($parts[0]);
396 if (!in_array($theField,$excludeElements) && !strcmp($theField,$theFieldToReturn)) {
397 if ($TCA[$table]['columns'][$theField]) {
398 $sField = $this->getSingleField($table,$theField,$row,$parts[1],1,$parts[3],$parts[2]);
399 return $sField['ITEM'];
400 }
401 }
402 }
403 }
404 }
405 }
406 }
407
408 /**
409 * Based on the $table and $row of content, this displays the complete TCEform for the record.
410 * The input-$row is required to be preprocessed if necessary by eg. the t3lib_transferdata class. For instance the RTE content should be transformed through this class first.
411 *
412 * @param string The table name
413 * @param array The record from the table for which to render a field.
414 * @param integer Depth level
415 * @return string HTML output
416 * @see getSoloField()
417 */
418 function getMainFields($table,$row,$depth=0) {
419 global $TCA, $TYPO3_CONF_VARS;
420
421 $this->renderDepth=$depth;
422
423 // Init vars:
424 $out_array = array(array());
425 $out_array_meta = array(array(
426 'title' => $this->getLL('l_generalTab')
427 ));
428
429 $out_pointer=0;
430 $out_sheet=0;
431 $this->palettesRendered=array();
432 $this->palettesRendered[$this->renderDepth][$table]=array();
433
434 // First prepare user defined objects (if any) for hooks which extend this function:
435 $hookObjectsArr = array();
436 if (is_array ($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tceforms.php']['getMainFieldsClass'])) {
437 foreach ($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tceforms.php']['getMainFieldsClass'] as $classRef) {
438 $hookObjectsArr[] = &t3lib_div::getUserObj($classRef);
439 }
440 }
441
442 // Hook: getMainFields_preProcess (requested by Thomas Hempel for use with the "dynaflex" extension)
443 foreach ($hookObjectsArr as $hookObj) {
444 if (method_exists($hookObj,'getMainFields_preProcess')) {
445 $hookObj->getMainFields_preProcess($table,$row,$this);
446 }
447 }
448
449 if ($TCA[$table]) {
450
451 // Load the full TCA for the table.
452 t3lib_div::loadTCA($table);
453
454 // Load the description content for the table.
455 if ($this->edit_showFieldHelp || $this->doLoadTableDescr($table)) {
456 $GLOBALS['LANG']->loadSingleTableDescription($table);
457 }
458 // Get the current "type" value for the record.
459 $typeNum = $this->getRTypeNum($table,$row);
460
461 // Find the list of fields to display:
462 if ($TCA[$table]['types'][$typeNum]) {
463 $itemList = $TCA[$table]['types'][$typeNum]['showitem'];
464 if ($itemList) { // If such a list existed...
465
466 // Explode the field list and possibly rearrange the order of the fields, if configured for
467 $fields = t3lib_div::trimExplode(',',$itemList,1);
468 if ($this->fieldOrder) {
469 $fields = $this->rearrange($fields);
470 }
471
472 // Get excluded fields, added fiels and put it together:
473 $excludeElements = $this->excludeElements = $this->getExcludeElements($table,$row,$typeNum);
474 $fields = $this->mergeFieldsWithAddedFields($fields,$this->getFieldsToAdd($table,$row,$typeNum));
475
476 // Traverse the fields to render:
477 $cc=0;
478 foreach($fields as $fieldInfo) {
479 // Exploding subparts of the field configuration:
480 $parts = explode(';',$fieldInfo);
481
482 // Getting the style information out:
483 $color_style_parts = t3lib_div::trimExplode('-',$parts[4]);
484 if (strcmp($color_style_parts[0],'')) {
485 $this->setColorScheme($GLOBALS['TBE_STYLES']['colorschemes'][intval($color_style_parts[0])]);
486 }
487 if (strcmp($color_style_parts[1],'')) {
488 $this->fieldStyle = $GLOBALS['TBE_STYLES']['styleschemes'][intval($color_style_parts[1])];
489 if (!isset($this->fieldStyle)) $this->fieldStyle = $GLOBALS['TBE_STYLES']['styleschemes'][0];
490 }
491 if (strcmp($color_style_parts[2],'')) {
492 $this->wrapBorder($out_array[$out_sheet],$out_pointer);
493 $this->borderStyle = $GLOBALS['TBE_STYLES']['borderschemes'][intval($color_style_parts[2])];
494 if (!isset($this->borderStyle)) $this->borderStyle = $GLOBALS['TBE_STYLES']['borderschemes'][0];
495 }
496
497 // Render the field:
498 $theField = $parts[0];
499 if (!in_array($theField,$excludeElements)) {
500 if ($TCA[$table]['columns'][$theField]) {
501 $sFieldPal='';
502
503 if ($parts[2] && !isset($this->palettesRendered[$this->renderDepth][$table][$parts[2]])) {
504 $sFieldPal=$this->getPaletteFields($table,$row,$parts[2]);
505 $this->palettesRendered[$this->renderDepth][$table][$parts[2]] = 1;
506 }
507 $sField = $this->getSingleField($table,$theField,$row,$parts[1],0,$parts[3],$parts[2]);
508 if ($sField) { $sField.= $sFieldPal; }
509
510 $out_array[$out_sheet][$out_pointer].= $sField;
511 } elseif ($theField=='--div--') {
512 if ($cc>0) {
513 $out_array[$out_sheet][$out_pointer].=$this->getDivider();
514
515 if ($this->enableTabMenu && $TCA[$table]['ctrl']['dividers2tabs']) {
516 $this->wrapBorder($out_array[$out_sheet],$out_pointer);
517 $out_sheet++;
518 $out_array[$out_sheet] = array();
519 $out_array_meta[$out_sheet]['title'] = $this->sL($parts[1]);
520 }
521 } else { // Setting alternative title for "General" tab if "--div--" is the very first element.
522 $out_array_meta[$out_sheet]['title'] = $this->sL($parts[1]);
523 }
524 } elseif($theField=='--palette--') {
525 if ($parts[2] && !isset($this->palettesRendered[$this->renderDepth][$table][$parts[2]])) {
526 // render a 'header' if not collapsed
527 if ($TCA[$table]['palettes'][$parts[2]]['canNotCollapse'] AND $parts[1]) {
528 $out_array[$out_sheet][$out_pointer].=$this->getPaletteFields($table,$row,$parts[2],$this->sL($parts[1]));
529 } else {
530 $out_array[$out_sheet][$out_pointer].=$this->getPaletteFields($table,$row,$parts[2],'','',$this->sL($parts[1]));
531 }
532 $this->palettesRendered[$this->renderDepth][$table][$parts[2]] = 1;
533 }
534 }
535 }
536
537 $cc++;
538 }
539 }
540 }
541 }
542
543 // Hook: getMainFields_postProcess (requested by Thomas Hempel for use with the "dynaflex" extension)
544 foreach ($hookObjectsArr as $hookObj) {
545 if (method_exists($hookObj,'getMainFields_postProcess')) {
546 $hookObj->getMainFields_postProcess($table,$row,$this);
547 }
548 }
549
550 // Wrapping a border around it all:
551 $this->wrapBorder($out_array[$out_sheet],$out_pointer);
552
553 // Resetting styles:
554 $this->resetSchemes();
555
556 // Rendering Main palettes, if any
557 $mParr = t3lib_div::trimExplode(',',$TCA[$table]['ctrl']['mainpalette']);
558 $i = 0;
559 if (count($mParr)) {
560 foreach ($mParr as $mP) {
561 if (!isset($this->palettesRendered[$this->renderDepth][$table][$mP])) {
562 $temp_palettesCollapsed=$this->palettesCollapsed;
563 $this->palettesCollapsed=0;
564 $label = ($i==0?$this->getLL('l_generalOptions'):$this->getLL('l_generalOptions_more'));
565 $out_array[$out_sheet][$out_pointer].=$this->getPaletteFields($table,$row,$mP,$label);
566 $this->palettesCollapsed=$temp_palettesCollapsed;
567 $this->palettesRendered[$this->renderDepth][$table][$mP] = 1;
568 }
569 $this->wrapBorder($out_array[$out_sheet],$out_pointer);
570 $i++;
571 if ($this->renderDepth) {
572 $this->renderDepth--;
573 }
574 }
575 }
576
577 // Return the imploded $out_array:
578 if ($out_sheet>0) { // There were --div-- dividers around...
579
580 // Create parts array for the tab menu:
581 $parts = array();
582 foreach ($out_array as $idx => $sheetContent) {
583 $parts[] = array(
584 'label' => $out_array_meta[$idx]['title'],
585 'content' => '<table border="0" cellspacing="0" cellpadding="0" width="100%">'.
586 implode('',$sheetContent).
587 '</table>'
588 );
589 }
590
591 return '
592 <tr>
593 <td colspan="2">
594 '.$this->getDynTabMenu($parts, 'TCEforms:'.$table.':'.$row['uid']).'
595 </td>
596 </tr>';
597 } else { // Only one, so just implode:
598 return implode('',$out_array[$out_sheet]);
599 }
600 }
601
602 /**
603 * Will return the TCEform elements for a pre-defined list of fields.
604 * Notice that this will STILL use the configuration found in the list [types][showitem] for those fields which are found there. So ideally the list of fields given as argument to this function should also be in the current [types][showitem] list of the record.
605 * Used for displaying forms for the frontend edit icons for instance.
606 *
607 * @param string The table name
608 * @param array The record array.
609 * @param string Commalist of fields from the table. These will be shown in the specified order in a form.
610 * @return string TCEform elements in a string.
611 */
612 function getListedFields($table,$row,$list) {
613 global $TCA;
614
615 t3lib_div::loadTCA($table);
616 if ($this->edit_showFieldHelp || $this->doLoadTableDescr($table)) {
617 $GLOBALS['LANG']->loadSingleTableDescription($table);
618 }
619
620 $out = '';
621 $types_fieldConfig = t3lib_BEfunc::getTCAtypes($table,$row,1);
622
623 $editFieldList=array_unique(t3lib_div::trimExplode(',',$list,1));
624 foreach($editFieldList as $theFieldC) {
625 list($theField,$palFields) = split('\[|\]',$theFieldC);
626 $theField = trim($theField);
627 $palFields = trim($palFields);
628 if ($TCA[$table]['columns'][$theField]) {
629 $parts = t3lib_div::trimExplode(';',$types_fieldConfig[$theField]['origString']);
630 $sField = $this->getSingleField($table,$theField,$row,$parts[1],0,$parts[3],0); // Don't sent palette pointer - there are no options anyways for a field-list.
631 $out.= $sField;
632 } elseif($theField=='--div--') {
633 $out.= $this->getDivider();
634 }
635 if ($palFields) {
636 $out.= $this->getPaletteFields($table,$row,'','',implode(',',t3lib_div::trimExplode('|',$palFields,1)));
637 }
638 }
639
640 return $out;
641 }
642
643 /**
644 * Creates a palette (collection of secondary options).
645 *
646 * @param string The table name
647 * @param array The row array
648 * @param string The palette number/pointer
649 * @param string Header string for the palette (used when in-form). If not set, no header item is made.
650 * @param string Optional alternative list of fields for the palette
651 * @param string Optional Link text for activating a palette (when palettes does not have another form element to belong to).
652 * @return string HTML code.
653 */
654 function getPaletteFields($table,$row,$palette,$header='',$itemList='',$collapsedHeader='') {
655 global $TCA;
656 if (!$this->doPrintPalette) return '';
657
658 $out='';
659 $palParts = array();
660 t3lib_div::loadTCA($table);
661
662 // Getting excludeElements, if any.
663 if (!is_array($this->excludeElements)) {
664 $this->excludeElements = $this->getExcludeElements($table,$row,$this->getRTypeNum($table,$row));
665 }
666
667 // Render the palette TCEform elements.
668 if ($TCA[$table] && (is_array($TCA[$table]['palettes'][$palette]) || $itemList)) {
669 $itemList = $itemList?$itemList:$TCA[$table]['palettes'][$palette]['showitem'];
670 if ($itemList) {
671 $fields = t3lib_div::trimExplode(',',$itemList,1);
672 reset($fields);
673 while(list(,$fieldInfo)=each($fields)) {
674 $parts = t3lib_div::trimExplode(';',$fieldInfo);
675 $theField = $parts[0];
676
677 if (!in_array($theField,$this->excludeElements) && $TCA[$table]['columns'][$theField]) {
678 $this->palFieldArr[$palette][] = $theField;
679 if ($this->isPalettesCollapsed($table,$palette)) {
680 $this->hiddenFieldListArr[] = $theField;
681 }
682
683 $part = $this->getSingleField($table,$theField,$row,$parts[1],1,'',$parts[2]);
684 if (is_array($part)) {
685 $palParts[] = $part;
686 }
687 }
688 }
689 }
690 }
691 // Put palette together if there are fields in it:
692 if (count($palParts)) {
693 if ($header) {
694 $out.= $this->intoTemplate(array(
695 'HEADER' => htmlspecialchars($header)
696 ),
697 $this->palFieldTemplateHeader
698 );
699 }
700 $out.= $this->intoTemplate(array(
701 'PALETTE' => $this->printPalette($palParts)
702 ),
703 $this->palFieldTemplate
704 );
705 }
706 // If a palette is collapsed (not shown in form, but in top frame instead) AND a collapse header string is given, then make that string a link to activate the palette.
707 if ($this->isPalettesCollapsed($table,$palette) && $collapsedHeader) {
708 $pC = $this->intoTemplate(array(
709 'PALETTE' => $this->wrapOpenPalette('<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/options.gif','width="18" height="16"').' border="0" title="'.htmlspecialchars($this->getLL('l_moreOptions')).'" align="top" alt="" /><strong>'.$collapsedHeader.'</strong>',$table,$row,$palette),
710 ),
711 $this->palFieldTemplate
712 );
713 $out.= $pC;
714 }
715
716 return $out;
717 }
718
719 /**
720 * Returns the form HTML code for a database table field.
721 *
722 * @param string The table name
723 * @param string The field name
724 * @param array The record to edit from the database table.
725 * @param string Alternative field name label to show.
726 * @param boolean Set this if the field is on a palette (in top frame), otherwise not. (if set, field will render as a hidden field).
727 * @param string The "extra" options from "Part 4" of the field configurations found in the "types" "showitem" list. Typically parsed by $this->getSpecConfFromString() in order to get the options as an associative array.
728 * @param integer The palette pointer.
729 * @return mixed String (normal) or array (palettes)
730 */
731 function getSingleField($table,$field,$row,$altName='',$palette=0,$extra='',$pal=0) {
732 global $TCA,$BE_USER;
733
734 $out = '';
735 $PA = array();
736 $PA['altName'] = $altName;
737 $PA['palette'] = $palette;
738 $PA['extra'] = $extra;
739 $PA['pal'] = $pal;
740
741 // Make sure to load full $TCA array for the table:
742 t3lib_div::loadTCA($table);
743
744 // Get the TCA configuration for the current field:
745 $PA['fieldConf'] = $TCA[$table]['columns'][$field];
746 $PA['fieldConf']['config']['form_type'] = $PA['fieldConf']['config']['form_type'] ? $PA['fieldConf']['config']['form_type'] : $PA['fieldConf']['config']['type']; // Using "form_type" locally in this script
747
748 // Now, check if this field is configured and editable (according to excludefields + other configuration)
749 if ( is_array($PA['fieldConf']) &&
750 (!$PA['fieldConf']['exclude'] || $BE_USER->check('non_exclude_fields',$table.':'.$field)) &&
751 $PA['fieldConf']['config']['form_type']!='passthrough' &&
752 ($this->RTEenabled || !$PA['fieldConf']['config']['showIfRTE']) &&
753 (!$PA['fieldConf']['displayCond'] || $this->isDisplayCondition($PA['fieldConf']['displayCond'],$row)) &&
754 (!$TCA[$table]['ctrl']['languageField'] || $PA['fieldConf']['l10n_display'] || strcmp($PA['fieldConf']['l10n_mode'],'exclude') || $row[$TCA[$table]['ctrl']['languageField']]<=0) &&
755 (!$TCA[$table]['ctrl']['languageField'] || !$this->localizationMode || $this->localizationMode===$PA['fieldConf']['l10n_cat'])
756 ) {
757
758
759
760 // Fetching the TSconfig for the current table/field. This includes the $row which means that
761 $PA['fieldTSConfig'] = $this->setTSconfig($table,$row,$field);
762
763 // If the field is NOT disabled from TSconfig (which it could have been) then render it
764 if (!$PA['fieldTSConfig']['disabled']) {
765
766 // Init variables:
767 $PA['itemFormElName']=$this->prependFormFieldNames.'['.$table.']['.$row['uid'].']['.$field.']'; // Form field name
768 $PA['itemFormElName_file']=$this->prependFormFieldNames_file.'['.$table.']['.$row['uid'].']['.$field.']'; // Form field name, in case of file uploads
769 $PA['itemFormElValue']=$row[$field]; // The value to show in the form field.
770
771 // set field to read-only if configured for translated records to show default language content as readonly
772 if ($PA['fieldConf']['l10n_display'] AND t3lib_div::inList($PA['fieldConf']['l10n_display'], 'defaultAsReadonly') AND $row[$TCA[$table]['ctrl']['languageField']]) {
773 $PA['fieldConf']['config']['readOnly'] = true;
774 $PA['itemFormElValue'] = $this->defaultLanguageData[$table.':'.$row['uid']][$field];
775 }
776
777 // Create a JavaScript code line which will ask the user to save/update the form due to changing the element. This is used for eg. "type" fields and others configured with "requestUpdate"
778 if (
779 ($TCA[$table]['ctrl']['type'] && !strcmp($field,$TCA[$table]['ctrl']['type'])) ||
780 ($TCA[$table]['ctrl']['requestUpdate'] && t3lib_div::inList($TCA[$table]['ctrl']['requestUpdate'],$field))) {
781 if($GLOBALS['BE_USER']->jsConfirmation(1)) {
782 $alertMsgOnChange = 'if (confirm('.$GLOBALS['LANG']->JScharCode($this->getLL('m_onChangeAlert')).') && TBE_EDITOR_checkSubmit(-1)){ TBE_EDITOR_submitForm() };';
783 } else {
784 $alertMsgOnChange = 'if (TBE_EDITOR_checkSubmit(-1)){ TBE_EDITOR_submitForm() };';
785 }
786 } else {
787 $alertMsgOnChange = '';
788 }
789
790 // Render as a hidden field?
791 if (in_array($field,$this->hiddenFieldListArr)) {
792 $this->hiddenFieldAccum[]='<input type="hidden" name="'.$PA['itemFormElName'].'" value="'.htmlspecialchars($PA['itemFormElValue']).'" />';
793 } else { // Render as a normal field:
794
795 // If the field is NOT a palette field, then we might create an icon which links to a palette for the field, if one exists.
796 if (!$PA['palette']) {
797 if ($PA['pal'] && $this->isPalettesCollapsed($table,$PA['pal'])) {
798 list($thePalIcon,$palJSfunc) = $this->wrapOpenPalette('<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/options.gif','width="18" height="16"').' border="0" title="'.htmlspecialchars($this->getLL('l_moreOptions')).'" alt="" />',$table,$row,$PA['pal'],1);
799 } else {
800 $thePalIcon = '';
801 $palJSfunc = '';
802 }
803 }
804 // onFocus attribute to add to the field:
805 $PA['onFocus'] = ($palJSfunc && !$BE_USER->uc['dontShowPalettesOnFocusInAB']) ? ' onfocus="'.htmlspecialchars($palJSfunc).'"' : '';
806
807 // Find item
808 $item='';
809 $PA['label'] = $PA['altName'] ? $PA['altName'] : $PA['fieldConf']['label'];
810 $PA['label'] = $this->sL($PA['label']);
811 // JavaScript code for event handlers:
812 $PA['fieldChangeFunc']=array();
813 $PA['fieldChangeFunc']['TBE_EDITOR_fieldChanged'] = "TBE_EDITOR_fieldChanged('".$table."','".$row['uid']."','".$field."','".$PA['itemFormElName']."');";
814 $PA['fieldChangeFunc']['alert']=$alertMsgOnChange;
815
816 // Based on the type of the item, call a render function:
817 $item = $this->getSingleField_SW($table,$field,$row,$PA);
818
819 // Add language + diff
820 if ($PA['fieldConf']['l10n_display'] && (t3lib_div::inList($PA['fieldConf']['l10n_display'], 'hideDiff') || t3lib_div::inList($PA['fieldConf']['l10n_display'], 'defaultAsReadonly'))) {
821 $renderLanguageDiff = false;
822 } else {
823 $renderLanguageDiff = true;
824 }
825
826 if ($renderLanguageDiff) {
827 $item = $this->renderDefaultLanguageContent($table,$field,$row,$item);
828 $item = $this->renderDefaultLanguageDiff($table,$field,$row,$item);
829 }
830
831 // If the record has been saved and the "linkTitleToSelf" is set, we make the field name into a link, which will load ONLY this field in alt_doc.php
832 $PA['label'] = t3lib_div::deHSCentities(htmlspecialchars($PA['label']));
833 if (t3lib_div::testInt($row['uid']) && $PA['fieldTSConfig']['linkTitleToSelf']) {
834 $lTTS_url = $this->backPath.'alt_doc.php?edit['.$table.']['.$row['uid'].']=edit&columnsOnly='.$field.
835 ($PA['fieldTSConfig']['linkTitleToSelf.']['returnUrl']?'&returnUrl='.rawurlencode($this->thisReturnUrl()):'');
836 $PA['label'] = '<a href="'.htmlspecialchars($lTTS_url).'">'.$PA['label'].'</a>';
837 }
838
839 // Create output value:
840 if ($PA['fieldConf']['config']['form_type']=='user' && $PA['fieldConf']['config']['noTableWrapping']) {
841 $out = $item;
842 } elseif ($PA['palette']) {
843 // Array:
844 $out=array(
845 'NAME'=>$PA['label'],
846 'ID'=>$row['uid'],
847 'FIELD'=>$field,
848 'TABLE'=>$table,
849 'ITEM'=>$item,
850 'HELP_ICON' => $this->helpTextIcon($table,$field,1)
851 );
852 $out = $this->addUserTemplateMarkers($out,$table,$field,$row,$PA);
853 } else {
854 // String:
855 $out=array(
856 'NAME'=>$PA['label'],
857 'ITEM'=>$item,
858 'TABLE'=>$table,
859 'ID'=>$row['uid'],
860 'HELP_ICON'=>$this->helpTextIcon($table,$field),
861 'HELP_TEXT'=>$this->helpText($table,$field),
862 'PAL_LINK_ICON'=>$thePalIcon,
863 'FIELD'=>$field
864 );
865 $out = $this->addUserTemplateMarkers($out,$table,$field,$row,$PA);
866 // String:
867 $out=$this->intoTemplate($out);
868 }
869 }
870 } else $this->commentMessages[]=$this->prependFormFieldNames.'['.$table.']['.$row['uid'].']['.$field.']: Disabled by TSconfig';
871 }
872 // Return value (string or array)
873 return $out;
874 }
875
876 /**
877 * Rendering a single item for the form
878 *
879 * @param string Table name of record
880 * @param string Fieldname to render
881 * @param array The record
882 * @param array parameters array containing a lot of stuff. Value by Reference!
883 * @return string Returns the item as HTML code to insert
884 * @access private
885 * @see getSingleField(), getSingleField_typeFlex_draw()
886 */
887 function getSingleField_SW($table,$field,$row,&$PA) {
888 $PA['fieldConf']['config']['form_type'] = $PA['fieldConf']['config']['form_type'] ? $PA['fieldConf']['config']['form_type'] : $PA['fieldConf']['config']['type']; // Using "form_type" locally in this script
889
890 switch($PA['fieldConf']['config']['form_type']) {
891 case 'input':
892 $item = $this->getSingleField_typeInput($table,$field,$row,$PA);
893 break;
894 case 'text':
895 $item = $this->getSingleField_typeText($table,$field,$row,$PA);
896 break;
897 case 'check':
898 $item = $this->getSingleField_typeCheck($table,$field,$row,$PA);
899 break;
900 case 'radio':
901 $item = $this->getSingleField_typeRadio($table,$field,$row,$PA);
902 break;
903 case 'select':
904 $item = $this->getSingleField_typeSelect($table,$field,$row,$PA);
905 break;
906 case 'group':
907 $item = $this->getSingleField_typeGroup($table,$field,$row,$PA);
908 break;
909 case 'none':
910 $item = $this->getSingleField_typeNone($table,$field,$row,$PA);
911 break;
912 case 'user':
913 $item = $this->getSingleField_typeUser($table,$field,$row,$PA);
914 break;
915 case 'flex':
916 $item = $this->getSingleField_typeFlex($table,$field,$row,$PA);
917 break;
918 default:
919 $item = $this->getSingleField_typeUnknown($table,$field,$row,$PA);
920 break;
921 }
922
923 return $item;
924 }
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944 /**********************************************************
945 *
946 * Rendering of each TCEform field type
947 *
948 ************************************************************/
949
950 /**
951 * Generation of TCEform elements of the type "input"
952 * This will render a single-line input form field, possibly with various control/validation features
953 *
954 * @param string The table name of the record
955 * @param string The field name which this element is supposed to edit
956 * @param array The record data array where the value(s) for the field can be found
957 * @param array An array with additional configuration options.
958 * @return string The HTML code for the TCEform field
959 */
960 function getSingleField_typeInput($table,$field,$row,&$PA) {
961 // typo3FormFieldSet(theField, evallist, is_in, checkbox, checkboxValue)
962 // typo3FormFieldGet(theField, evallist, is_in, checkbox, checkboxValue, checkbox_off)
963
964 $config = $PA['fieldConf']['config'];
965
966 # $specConf = $this->getSpecConfForField($table,$row,$field);
967 $specConf = $this->getSpecConfFromString($PA['extra'], $PA['fieldConf']['defaultExtras']);
968 $size = t3lib_div::intInRange($config['size']?$config['size']:30,5,$this->maxInputWidth);
969 $evalList = t3lib_div::trimExplode(',',$config['eval'],1);
970
971
972 if($this->renderReadonly || $config['readOnly']) {
973 $itemFormElValue = $PA['itemFormElValue'];
974 if (in_array('date',$evalList)) {
975 $config['format'] = 'date';
976 } elseif (in_array('date',$evalList)) {
977 $config['format'] = 'date';
978 } elseif (in_array('datetime',$evalList)) {
979 $config['format'] = 'datetime';
980 } elseif (in_array('time',$evalList)) {
981 $config['format'] = 'time';
982 }
983 if (in_array('password',$evalList)) {
984 $itemFormElValue = $itemFormElValue ? '*********' : '';
985 }
986 return $this->getSingleField_typeNone_render($config, $itemFormElValue);
987 }
988
989 if (in_array('required',$evalList)) {
990 $this->requiredFields[$table.'_'.$row['uid'].'_'.$field]=$PA['itemFormElName'];
991 }
992
993 $paramsList = "'".$PA['itemFormElName']."','".implode(',',$evalList)."','".trim($config['is_in'])."',".(isset($config['checkbox'])?1:0).",'".$config['checkbox']."'";
994 if (isset($config['checkbox'])) {
995 // Setting default "click-checkbox" values for eval types "date" and "datetime":
996 $thisMidnight = mktime(0,0,0);
997 $checkSetValue = in_array('date',$evalList) ? $thisMidnight : '';
998 $checkSetValue = in_array('datetime',$evalList) ? time() : $checkSetValue;
999
1000 $cOnClick = 'typo3FormFieldGet('.$paramsList.',1,\''.$checkSetValue.'\');'.implode('',$PA['fieldChangeFunc']);
1001 $item.='<input type="checkbox"'.$this->insertDefStyle('check').' name="'.$PA['itemFormElName'].'_cb" onclick="'.htmlspecialchars($cOnClick).'" />';
1002 }
1003
1004 $PA['fieldChangeFunc'] = array_merge(array('typo3FormFieldGet'=>'typo3FormFieldGet('.$paramsList.');'), $PA['fieldChangeFunc']);
1005 $mLgd = ($config['max']?$config['max']:256);
1006 $iOnChange = implode('',$PA['fieldChangeFunc']);
1007 $item.='<input type="text" name="'.$PA['itemFormElName'].'_hr" value=""'.$this->formWidth($size).' maxlength="'.$mLgd.'" onchange="'.htmlspecialchars($iOnChange).'"'.$PA['onFocus'].' />'; // This is the EDITABLE form field.
1008 $item.='<input type="hidden" name="'.$PA['itemFormElName'].'" value="'.htmlspecialchars($PA['itemFormElValue']).'" />'; // This is the ACTUAL form field - values from the EDITABLE field must be transferred to this field which is the one that is written to the database.
1009 $this->extJSCODE.='typo3FormFieldSet('.$paramsList.');';
1010
1011 // going through all custom evaluations configured for this field
1012 foreach ($evalList as $evalData) {
1013 if (substr($evalData, 0, 3) == 'tx_') {
1014 $evalObj = t3lib_div::getUserObj($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tce']['formevals'][$evalData].':&'.$evalData);
1015 if(is_object($evalObj) && method_exists($evalObj, 'returnFieldJS')) {
1016 $this->extJSCODE .= "\n\nfunction ".$evalData."(value) {\n".$evalObj->returnFieldJS()."\n}\n";
1017 }
1018 }
1019 }
1020
1021 // Creating an alternative item without the JavaScript handlers.
1022 $altItem = '<input type="hidden" name="'.$PA['itemFormElName'].'_hr" value="" />';
1023 $altItem.= '<input type="hidden" name="'.$PA['itemFormElName'].'" value="'.htmlspecialchars($PA['itemFormElValue']).'" />';
1024
1025 // Wrap a wizard around the item?
1026 $item= $this->renderWizards(array($item,$altItem),$config['wizards'],$table,$row,$field,$PA,$PA['itemFormElName'].'_hr',$specConf);
1027
1028 return $item;
1029 }
1030
1031 /**
1032 * Generation of TCEform elements of the type "text"
1033 * This will render a <textarea> OR RTE area form field, possibly with various control/validation features
1034 *
1035 * @param string The table name of the record
1036 * @param string The field name which this element is supposed to edit
1037 * @param array The record data array where the value(s) for the field can be found
1038 * @param array An array with additional configuration options.
1039 * @return string The HTML code for the TCEform field
1040 */
1041 function getSingleField_typeText($table,$field,$row,&$PA) {
1042
1043 // Init config:
1044 $config = $PA['fieldConf']['config'];
1045
1046 if($this->renderReadonly || $config['readOnly']) {
1047 return $this->getSingleField_typeNone_render($config, $PA['itemFormElValue']);
1048 }
1049
1050 // Setting columns number:
1051 $cols = t3lib_div::intInRange($config['cols'] ? $config['cols'] : 30, 5, $this->maxTextareaWidth);
1052
1053 // Setting number of rows:
1054 $origRows = $rows = t3lib_div::intInRange($config['rows'] ? $config['rows'] : 5, 1, 20);
1055 if (strlen($PA['itemFormElValue']) > $this->charsPerRow*2) {
1056 $cols = $this->maxTextareaWidth;
1057 $rows = t3lib_div::intInRange(round(strlen($PA['itemFormElValue'])/$this->charsPerRow), count(explode(chr(10),$PA['itemFormElValue'])), 20);
1058 if ($rows<$origRows) $rows = $origRows;
1059 }
1060
1061 // Init RTE vars:
1062 $RTEwasLoaded = 0; // Set true, if the RTE is loaded; If not a normal textarea is shown.
1063 $RTEwouldHaveBeenLoaded = 0; // Set true, if the RTE would have been loaded if it wasn't for the disable-RTE flag in the bottom of the page...
1064
1065 // "Extra" configuration; Returns configuration for the field based on settings found in the "types" fieldlist. Traditionally, this is where RTE configuration has been found.
1066 $specConf = $this->getSpecConfFromString($PA['extra'], $PA['fieldConf']['defaultExtras']);
1067
1068 // Setting up the altItem form field, which is a hidden field containing the value
1069 $altItem = '<input type="hidden" name="'.htmlspecialchars($PA['itemFormElName']).'" value="'.htmlspecialchars($PA['itemFormElValue']).'" />';
1070
1071 // If RTE is generally enabled (TYPO3_CONF_VARS and user settings)
1072 if ($this->RTEenabled) {
1073 $p = t3lib_BEfunc::getSpecConfParametersFromArray($specConf['rte_transform']['parameters']);
1074 if (isset($specConf['richtext']) && (!$p['flag'] || !$row[$p['flag']])) { // If the field is configured for RTE and if any flag-field is not set to disable it.
1075 t3lib_BEfunc::fixVersioningPid($table,$row);
1076 list($tscPID,$thePidValue) = $this->getTSCpid($table,$row['uid'],$row['pid']);
1077
1078 // If the pid-value is not negative (that is, a pid could NOT be fetched)
1079 if ($thePidValue >= 0) {
1080 $RTEsetup = $GLOBALS['BE_USER']->getTSConfig('RTE',t3lib_BEfunc::getPagesTSconfig($tscPID));
1081 $RTEtypeVal = t3lib_BEfunc::getTCAtypeValue($table,$row);
1082 $thisConfig = t3lib_BEfunc::RTEsetup($RTEsetup['properties'],$table,$field,$RTEtypeVal);
1083
1084 if (!$thisConfig['disabled']) {
1085 if (!$this->disableRTE) {
1086 $this->RTEcounter++;
1087
1088 // Find alternative relative path for RTE images/links:
1089 $eFile = t3lib_parsehtml_proc::evalWriteFile($specConf['static_write'], $row);
1090 $RTErelPath = is_array($eFile) ? dirname($eFile['relEditFile']) : '';
1091
1092 // Get RTE object, draw form and set flag:
1093 $RTEobj = &t3lib_BEfunc::RTEgetObj();
1094 $item = $RTEobj->drawRTE($this,$table,$field,$row,$PA,$specConf,$thisConfig,$RTEtypeVal,$RTErelPath,$thePidValue);
1095
1096 // Wizard:
1097 $item = $this->renderWizards(array($item,$altItem),$config['wizards'],$table,$row,$field,$PA,$PA['itemFormElName'],$specConf,1);
1098
1099 $RTEwasLoaded = 1;
1100 } else {
1101 $RTEwouldHaveBeenLoaded = 1;
1102 $this->commentMessages[] = $PA['itemFormElName'].': RTE is disabled by the on-page RTE-flag (probably you can enable it by the check-box in the bottom of this page!)';
1103 }
1104 } else $this->commentMessages[] = $PA['itemFormElName'].': RTE is disabled by the Page TSconfig, "RTE"-key (eg. by RTE.default.disabled=0 or such)';
1105 } else $this->commentMessages[] = $PA['itemFormElName'].': PID value could NOT be fetched. Rare error, normally with new records.';
1106 } else {
1107 if (!isset($specConf['richtext'])) $this->commentMessages[] = $PA['itemFormElName'].': RTE was not configured for this field in TCA-types';
1108 if (!(!$p['flag'] || !$row[$p['flag']])) $this->commentMessages[] = $PA['itemFormElName'].': Field-flag ('.$PA['flag'].') has been set to disable RTE!';
1109 }
1110 }
1111
1112 // Display ordinary field if RTE was not loaded.
1113 if (!$RTEwasLoaded) {
1114 if ($specConf['rte_only']) { // Show message, if no RTE (field can only be edited with RTE!)
1115 $item = '<p><em>'.htmlspecialchars($this->getLL('l_noRTEfound')).'</em></p>';
1116 } else {
1117 if ($specConf['nowrap']) {
1118 $wrap = 'off';
1119 } else {
1120 $wrap = ($config['wrap'] ? $config['wrap'] : 'virtual');
1121 }
1122
1123 $classes = array();
1124 if ($specConf['fixed-font']) { $classes[] = 'fixed-font'; }
1125 if ($specConf['enable-tab']) { $classes[] = 'enable-tab'; }
1126
1127 $formWidthText = $this->formWidthText($cols,$wrap);
1128
1129 // Extract class attributes from $formWidthText (otherwise it would be added twice to the output)
1130 if (preg_match('/ class="(.+?)"/',$formWidthText,$res)) {
1131 $formWidthText = str_replace(' class="'.$res[1].'"','',$formWidthText);
1132 $classes = array_merge($classes, explode(' ',$res[1]));
1133 }
1134
1135 if (count($classes)) {
1136 $class = ' class="'.implode(' ',$classes).'"';
1137 } else $class='';
1138
1139 $iOnChange = implode('',$PA['fieldChangeFunc']);
1140 $item.= '
1141 <textarea name="'.$PA['itemFormElName'].'"'.$formWidthText.$class.' rows="'.$rows.'" wrap="'.$wrap.'" onchange="'.htmlspecialchars($iOnChange).'"'.$PA['onFocus'].'>'.
1142 t3lib_div::formatForTextarea($PA['itemFormElValue']).
1143 '</textarea>';
1144 $item = $this->renderWizards(array($item,$altItem),$config['wizards'],$table,$row,$field,$PA,$PA['itemFormElName'],$specConf,$RTEwouldHaveBeenLoaded);
1145 }
1146 }
1147
1148 // Return field HTML:
1149 return $item;
1150 }
1151
1152 /**
1153 * Generation of TCEform elements of the type "check"
1154 * This will render a check-box OR an array of checkboxes
1155 *
1156 * @param string The table name of the record
1157 * @param string The field name which this element is supposed to edit
1158 * @param array The record data array where the value(s) for the field can be found
1159 * @param array An array with additional configuration options.
1160 * @return string The HTML code for the TCEform field
1161 */
1162 function getSingleField_typeCheck($table,$field,$row,&$PA) {
1163 $config = $PA['fieldConf']['config'];
1164
1165 $disabled = '';
1166 if($this->renderReadonly || $config['readOnly']) {
1167 $disabled = ' disabled="disabled"';
1168 }
1169
1170 // Traversing the array of items:
1171 $selItems = $this->initItemArray($PA['fieldConf']);
1172 if ($config['itemsProcFunc']) $selItems = $this->procItems($selItems,$PA['fieldTSConfig']['itemsProcFunc.'],$config,$table,$row,$field);
1173
1174 if (!count($selItems)) {
1175 $selItems[]=array('','');
1176 }
1177 $thisValue = intval($PA['itemFormElValue']);
1178
1179 $cols = intval($config['cols']);
1180 if ($cols > 1) {
1181 $item.= '<table border="0" cellspacing="0" cellpadding="0" class="typo3-TCEforms-checkboxArray">';
1182 for ($c=0;$c<count($selItems);$c++) {
1183 $p = $selItems[$c];
1184 if(!($c%$cols)) { $item.='<tr>'; }
1185 $cBP = $this->checkBoxParams($PA['itemFormElName'],$thisValue,$c,count($selItems),implode('',$PA['fieldChangeFunc']));
1186 $cBName = $PA['itemFormElName'].'_'.$c;
1187 $item.= '<td nowrap="nowrap">'.
1188 '<input type="checkbox"'.$this->insertDefStyle('check').' value="1" name="'.$cBName.'"'.$cBP.$disabled.' />'.
1189 $this->wrapLabels(htmlspecialchars($p[0]).'&nbsp;').
1190 '</td>';
1191 if(($c%$cols)+1==$cols) {$item.='</tr>';}
1192 }
1193 if ($c%$cols) {
1194 $rest=$cols-($c%$cols);
1195 for ($c=0;$c<$rest;$c++) {
1196 $item.= '<td></td>';
1197 }
1198 if ($c>0) { $item.= '</tr>'; }
1199 }
1200 $item.= '</table>';
1201 } else {
1202 for ($c=0;$c<count($selItems);$c++) {
1203 $p = $selItems[$c];
1204 $cBP = $this->checkBoxParams($PA['itemFormElName'],$thisValue,$c,count($selItems),implode('',$PA['fieldChangeFunc']));
1205 $cBName = $PA['itemFormElName'].'_'.$c;
1206 $item.= ($c>0?'<br />':'').
1207 '<input type="checkbox"'.$this->insertDefStyle('check').' value="1" name="'.$cBName.'"'.$cBP.$PA['onFocus'].$disabled.' />'.
1208 htmlspecialchars($p[0]);
1209 }
1210 }
1211 if (!$disabled) {
1212 $item.= '<input type="hidden" name="'.$PA['itemFormElName'].'" value="'.htmlspecialchars($thisValue).'" />';
1213 }
1214
1215 return $item;
1216 }
1217
1218 /**
1219 * Generation of TCEform elements of the type "radio"
1220 * This will render a series of radio buttons.
1221 *
1222 * @param string The table name of the record
1223 * @param string The field name which this element is supposed to edit
1224 * @param array The record data array where the value(s) for the field can be found
1225 * @param array An array with additional configuration options.
1226 * @return string The HTML code for the TCEform field
1227 */
1228 function getSingleField_typeRadio($table,$field,$row,&$PA) {
1229 $config = $PA['fieldConf']['config'];
1230
1231 $disabled = '';
1232 if($this->renderReadonly || $config['readOnly']) {
1233 $disabled = ' disabled="disabled"';
1234 }
1235
1236 // Get items for the array:
1237 $selItems = $this->initItemArray($PA['fieldConf']);
1238 if ($config['itemsProcFunc']) $selItems = $this->procItems($selItems,$PA['fieldTSConfig']['itemsProcFunc.'],$config,$table,$row,$field);
1239
1240 // Traverse the items, making the form elements:
1241 for ($c=0;$c<count($selItems);$c++) {
1242 $p = $selItems[$c];
1243 $rOnClick = implode('',$PA['fieldChangeFunc']);
1244 $rChecked = (!strcmp($p[1],$PA['itemFormElValue'])?' checked="checked"':'');
1245 $item.= '<input type="radio"'.$this->insertDefStyle('radio').' name="'.$PA['itemFormElName'].'" value="'.htmlspecialchars($p[1]).'" onclick="'.htmlspecialchars($rOnClick).'"'.$rChecked.$PA['onFocus'].$disabled.' />'.
1246 htmlspecialchars($p[0]).
1247 '<br />';
1248 }
1249
1250 return $item;
1251 }
1252
1253 /**
1254 * Generation of TCEform elements of the type "select"
1255 * This will render a selector box element, or possibly a special construction with two selector boxes. That depends on configuration.
1256 *
1257 * @param string The table name of the record
1258 * @param string The field name which this element is supposed to edit
1259 * @param array The record data array where the value(s) for the field can be found
1260 * @param array An array with additional configuration options.
1261 * @return string The HTML code for the TCEform field
1262 */
1263 function getSingleField_typeSelect($table,$field,$row,&$PA) {
1264 global $TCA;
1265
1266 // Field configuration from TCA:
1267 $config = $PA['fieldConf']['config'];
1268
1269 $disabled = '';
1270 if($this->renderReadonly || $config['readOnly']) {
1271 $disabled = ' disabled="disabled"';
1272 }
1273
1274 // "Extra" configuration; Returns configuration for the field based on settings found in the "types" fieldlist. See http://typo3.org/documentation/document-library/doc_core_api/Wizards_Configuratio/.
1275 $specConf = $this->getSpecConfFromString($PA['extra'], $PA['fieldConf']['defaultExtras']);
1276
1277 // Getting the selector box items from the system
1278 $selItems = $this->addSelectOptionsToItemArray($this->initItemArray($PA['fieldConf']),$PA['fieldConf'],$this->setTSconfig($table,$row),$field);
1279 $selItems = $this->addItems($selItems,$PA['fieldTSConfig']['addItems.']);
1280 if ($config['itemsProcFunc']) $selItems = $this->procItems($selItems,$PA['fieldTSConfig']['itemsProcFunc.'],$config,$table,$row,$field);
1281
1282 // Possibly remove some items:
1283 $removeItems = t3lib_div::trimExplode(',',$PA['fieldTSConfig']['removeItems'],1);
1284 foreach($selItems as $tk => $p) {
1285
1286 // Checking languages and authMode:
1287 $languageDeny = $TCA[$table]['ctrl']['languageField'] && !strcmp($TCA[$table]['ctrl']['languageField'], $field) && !$GLOBALS['BE_USER']->checkLanguageAccess($p[1]);
1288 $authModeDeny = $config['form_type']=='select' && $config['authMode'] && !$GLOBALS['BE_USER']->checkAuthMode($table,$field,$p[1],$config['authMode']);
1289 if (in_array($p[1],$removeItems) || $languageDeny || $authModeDeny) {
1290 unset($selItems[$tk]);
1291 } elseif (isset($PA['fieldTSConfig']['altLabels.'][$p[1]])) {
1292 $selItems[$tk][0]=$this->sL($PA['fieldTSConfig']['altLabels.'][$p[1]]);
1293 }
1294
1295 // Removing doktypes with no access:
1296 if ($table.'.'.$field == 'pages.doktype') {
1297 if (!($GLOBALS['BE_USER']->isAdmin() || t3lib_div::inList($GLOBALS['BE_USER']->groupData['pagetypes_select'],$p[1]))) {
1298 unset($selItems[$tk]);
1299 }
1300 }
1301 }
1302
1303 // Creating the label for the "No Matching Value" entry.
1304 $nMV_label = isset($PA['fieldTSConfig']['noMatchingValue_label']) ? $this->sL($PA['fieldTSConfig']['noMatchingValue_label']) : '[ '.$this->getLL('l_noMatchingValue').' ]';
1305
1306 // Prepare some values:
1307 $maxitems = intval($config['maxitems']);
1308
1309 // If a SINGLE selector box...
1310 if ($maxitems<=1) {
1311 $item = $this->getSingleField_typeSelect_single($table,$field,$row,$PA,$config,$selItems,$nMV_label);
1312 } elseif (!strcmp($config['renderMode'],'checkbox')) { // Checkbox renderMode
1313 $item = $this->getSingleField_typeSelect_checkbox($table,$field,$row,$PA,$config,$selItems,$nMV_label);
1314 } elseif (!strcmp($config['renderMode'],'singlebox')) { // Single selector box renderMode
1315 $item = $this->getSingleField_typeSelect_singlebox($table,$field,$row,$PA,$config,$selItems,$nMV_label);
1316 } else { // Traditional multiple selector box:
1317 $item = $this->getSingleField_typeSelect_multiple($table,$field,$row,$PA,$config,$selItems,$nMV_label);
1318 }
1319
1320 // Wizards:
1321 if (!$disabled) {
1322 $altItem = '<input type="hidden" name="'.$PA['itemFormElName'].'" value="'.htmlspecialchars($PA['itemFormElValue']).'" />';
1323 $item = $this->renderWizards(array($item,$altItem),$config['wizards'],$table,$row,$field,$PA,$PA['itemFormElName'],$specConf);
1324 }
1325
1326 return $item;
1327 }
1328
1329 /**
1330 * Creates a single-selector box
1331 * (Render function for getSingleField_typeSelect())
1332 *
1333 * @param string See getSingleField_typeSelect()
1334 * @param string See getSingleField_typeSelect()
1335 * @param array See getSingleField_typeSelect()
1336 * @param array See getSingleField_typeSelect()
1337 * @param array (Redundant) content of $PA['fieldConf']['config'] (for convenience)
1338 * @param array Items available for selection
1339 * @param string Label for no-matching-value
1340 * @return string The HTML code for the item
1341 * @see getSingleField_typeSelect()
1342 */
1343 function getSingleField_typeSelect_single($table,$field,$row,&$PA,$config,$selItems,$nMV_label) {
1344
1345 // Initialization:
1346 $c = 0;
1347 $sI = 0;
1348 $noMatchingValue = 1;
1349 $opt = array();
1350 $selicons = array();
1351 $onlySelectedIconShown = 0;
1352 $size = intval($config['size']);
1353
1354 $disabled = '';
1355 if($this->renderReadonly || $config['readOnly']) {
1356 $disabled = ' disabled="disabled"';
1357 $onlySelectedIconShown = 1;
1358 }
1359
1360 // Icon configuration:
1361 if ($config['suppress_icons']=='IF_VALUE_FALSE') {
1362 $suppressIcons = !$PA['itemFormElValue'] ? 1 : 0;
1363 } elseif ($config['suppress_icons']=='ONLY_SELECTED') {
1364 $suppressIcons=0;
1365 $onlySelectedIconShown=1;
1366 } elseif ($config['suppress_icons']) {
1367 $suppressIcons = 1;
1368 } else $suppressIcons = 0;
1369
1370 // Traverse the Array of selector box items:
1371 foreach($selItems as $p) {
1372 $sM = (!strcmp($PA['itemFormElValue'],$p[1])?' selected="selected"':'');
1373 if ($sM) {
1374 $sI = $c;
1375 $noMatchingValue = 0;
1376 }
1377
1378 // Getting style attribute value (for icons):
1379 if ($config['iconsInOptionTags']) {
1380 $styleAttrValue = $this->optionTagStyle($p[2]);
1381 }
1382
1383 // Compiling the <option> tag:
1384 $opt[]= '<option value="'.htmlspecialchars($p[1]).'"'.
1385 $sM.
1386 ($styleAttrValue ? ' style="'.htmlspecialchars($styleAttrValue).'"' : '').
1387 (!strcmp($p[1],'--div--') ? ' class="c-divider"' : '').
1388 '>'.t3lib_div::deHSCentities(htmlspecialchars($p[0])).'</option>';
1389
1390 // If there is an icon for the selector box (rendered in table under)...:
1391 if ($p[2] && !$suppressIcons && (!$onlySelectedIconShown || $sM)) {
1392 list($selIconFile,$selIconInfo)=$this->getIcon($p[2]);
1393 $iOnClick = $this->elName($PA['itemFormElName']).'.selectedIndex='.$c.'; '.implode('',$PA['fieldChangeFunc']).$this->blur().'return false;';
1394 $selicons[]=array(
1395 (!$onlySelectedIconShown ? '<a href="#" onclick="'.htmlspecialchars($iOnClick).'">' : '').
1396 '<img src="'.$selIconFile.'" '.$selIconInfo[3].' vspace="2" border="0" title="'.htmlspecialchars($p[0]).'" alt="'.htmlspecialchars($p[0]).'" />'.
1397 (!$onlySelectedIconShown ? '</a>' : ''),
1398 $c,$sM);
1399 }
1400 $c++;
1401 }
1402
1403 // No-matching-value:
1404 if ($PA['itemFormElValue'] && $noMatchingValue && !$PA['fieldTSConfig']['disableNoMatchingValueElement'] && !$config['disableNoMatchingValueElement']) {
1405 $nMV_label = @sprintf($nMV_label, $PA['itemFormElValue']);
1406 $opt[]= '<option value="'.htmlspecialchars($PA['itemFormElValue']).'" selected="selected">'.htmlspecialchars($nMV_label).'</option>';
1407 }
1408
1409 // Create item form fields:
1410 $sOnChange = 'if (this.options[this.selectedIndex].value==\'--div--\') {this.selectedIndex='.$sI.';} '.implode('',$PA['fieldChangeFunc']);
1411 if(!$disabled) {
1412 $item.= '<input type="hidden" name="'.$PA['itemFormElName'].'_selIconVal" value="'.htmlspecialchars($sI).'" />'; // MUST be inserted before the selector - else is the value of the hiddenfield here mysteriously submitted...
1413 }
1414 $item.= '<select name="'.$PA['itemFormElName'].'"'.
1415 $this->insertDefStyle('select').
1416 ($size?' size="'.$size.'"':'').
1417 ' onchange="'.htmlspecialchars($sOnChange).'"'.
1418 $PA['onFocus'].$disabled.'>';
1419 $item.= implode('',$opt);
1420 $item.= '</select>';
1421
1422 // Create icon table:
1423 if (count($selicons)) {
1424 $item.='<table border="0" cellpadding="0" cellspacing="0" class="typo3-TCEforms-selectIcons">';
1425 $selicon_cols = intval($config['selicon_cols']);
1426 if (!$selicon_cols) $selicon_cols=count($selicons);
1427 $sR = ceil(count($selicons)/$selicon_cols);
1428 $selicons = array_pad($selicons,$sR*$selicon_cols,'');
1429 for($sa=0;$sa<$sR;$sa++) {
1430 $item.='<tr>';
1431 for($sb=0;$sb<$selicon_cols;$sb++) {
1432 $sk=($sa*$selicon_cols+$sb);
1433 $imgN = 'selIcon_'.$table.'_'.$row['uid'].'_'.$field.'_'.$selicons[$sk][1];
1434 $imgS = ($selicons[$sk][2]?$this->backPath.'gfx/content_selected.gif':'clear.gif');
1435 $item.='<td><img name="'.htmlspecialchars($imgN).'" src="'.$imgS.'" width="7" height="10" alt="" /></td>';
1436 $item.='<td>'.$selicons[$sk][0].'</td>';
1437 }
1438 $item.='</tr>';
1439 }
1440 $item.='</table>';
1441 }
1442
1443 return $item;
1444 }
1445
1446 /**
1447 * Creates a checkbox list (renderMode = "checkbox")
1448 * (Render function for getSingleField_typeSelect())
1449 *
1450 * @param string See getSingleField_typeSelect()
1451 * @param string See getSingleField_typeSelect()
1452 * @param array See getSingleField_typeSelect()
1453 * @param array See getSingleField_typeSelect()
1454 * @param array (Redundant) content of $PA['fieldConf']['config'] (for convenience)
1455 * @param array Items available for selection
1456 * @param string Label for no-matching-value
1457 * @return string The HTML code for the item
1458 * @see getSingleField_typeSelect()
1459 */
1460 function getSingleField_typeSelect_checkbox($table,$field,$row,&$PA,$config,$selItems,$nMV_label) {
1461
1462 // Get values in an array (and make unique, which is fine because there can be no duplicates anyway):
1463 $itemArray = array_flip($this->extractValuesOnlyFromValueLabelList($PA['itemFormElValue']));
1464
1465 $disabled = '';
1466 if($this->renderReadonly || $config['readOnly']) {
1467 $disabled = ' disabled="disabled"';
1468 }
1469
1470 // Traverse the Array of selector box items:
1471 $tRows = array();
1472 $c=0;
1473 if (!$disabled) {
1474 $sOnChange = implode('',$PA['fieldChangeFunc']);
1475 $setAll = array(); // Used to accumulate the JS needed to restore the original selection.
1476 foreach($selItems as $p) {
1477 // Non-selectable element:
1478 if (!strcmp($p[1],'--div--')) {
1479 if (count($setAll)) {
1480 $tRows[] = '
1481 <tr>
1482 <td colspan="2">'.
1483 '<a href="#" onclick="'.htmlspecialchars(implode('',$setAll).' return false;').'">'.
1484 htmlspecialchars($this->getLL('l_setAllCheckboxes')).
1485 '</a></td>
1486 </tr>';
1487 $setAll = array();
1488 }
1489
1490 $tRows[] = '
1491 <tr class="c-header">
1492 <td colspan="2">'.htmlspecialchars($p[0]).'</td>
1493 </tr>';
1494 } else {
1495 // Selected or not by default:
1496 $sM = '';
1497 if (isset($itemArray[$p[1]])) {
1498 $sM = ' checked="checked"';
1499 unset($itemArray[$p[1]]);
1500 }
1501
1502 // Icon:
1503 $selIconFile = '';
1504 if ($p[2]) {
1505 list($selIconFile,$selIconInfo) = $this->getIcon($p[2]);
1506 }
1507
1508 // Compile row:
1509 $onClickCell = $this->elName($PA['itemFormElName'].'['.$c.']').'.checked=!'.$this->elName($PA['itemFormElName'].'['.$c.']').'.checked;';
1510 $onClick = 'this.attributes.getNamedItem("class").nodeValue = '.$this->elName($PA['itemFormElName'].'['.$c.']').'.checked ? "c-selectedItem" : "";';
1511 $setAll[] = $this->elName($PA['itemFormElName'].'['.$c.']').'.checked=1;';
1512 $tRows[] = '
1513 <tr class="'.($sM ? 'c-selectedItem' : '').'" onclick="'.htmlspecialchars($onClick).'" style="cursor: pointer;">
1514 <td><input type="checkbox"'.$this->insertDefStyle('check').' name="'.htmlspecialchars($PA['itemFormElName'].'['.$c.']').'" value="'.htmlspecialchars($p[1]).'"'.$sM.' onclick="'.htmlspecialchars($sOnChange).'"'.$PA['onFocus'].' /></td>
1515 <td class="c-labelCell" onclick="'.htmlspecialchars($onClickCell).'">'.
1516 ($selIconFile ? '<img src="'.$selIconFile.'" '.$selIconInfo[3].' vspace="2" border="0" class="absmiddle" style="margin-right: 4px;" alt="" />' : '').
1517 t3lib_div::deHSCentities(htmlspecialchars($p[0])).
1518 (strcmp($p[3],'') ? '<br/><p class="c-descr">'.nl2br(trim(htmlspecialchars($p[3]))).'</p>' : '').
1519 '</td>
1520 </tr>';
1521 $c++;
1522 }
1523 }
1524
1525 // Remaining checkboxes will get their set-all link:
1526 if (count($setAll)) {
1527 $tRows[] = '
1528 <tr>
1529 <td colspan="2">'.
1530 '<a href="#" onclick="'.htmlspecialchars(implode('',$setAll).' return false;').'">'.
1531 htmlspecialchars($this->getLL('l_setAllCheckboxes')).
1532 '</a></td>
1533 </tr>';
1534 }
1535 }
1536
1537 // Remaining values (invalid):
1538 if (count($itemArray) && !$PA['fieldTSConfig']['disableNoMatchingValueElement'] && !$config['disableNoMatchingValueElement']) {
1539 foreach($itemArray as $theNoMatchValue => $temp) {
1540 // Compile <checkboxes> tag:
1541 array_unshift($tRows,'
1542 <tr class="c-invalidItem">
1543 <td><input type="checkbox"'.$this->insertDefStyle('check').' name="'.htmlspecialchars($PA['itemFormElName'].'['.$c.']').'" value="'.htmlspecialchars($theNoMatchValue).'" checked="checked" onclick="'.htmlspecialchars($sOnChange).'"'.$PA['onFocus'].$disabled.' /></td>
1544 <td class="c-labelCell">'.
1545 t3lib_div::deHSCentities(htmlspecialchars(@sprintf($nMV_label, $theNoMatchValue))).
1546 '</td>
1547 </tr>');
1548 $c++;
1549 }
1550 }
1551
1552 // Add an empty hidden field which will send a blank value if all items are unselected.
1553 $item.='<input type="hidden" name="'.htmlspecialchars($PA['itemFormElName']).'" value="" />';
1554
1555 // Implode rows in table:
1556 $item.= '
1557 <table border="0" cellpadding="0" cellspacing="0" class="typo3-TCEforms-select-checkbox">'.
1558 implode('',$tRows).'
1559 </table>
1560 ';
1561
1562 return $item;
1563 }
1564
1565 /**
1566 * Creates a selectorbox list (renderMode = "singlebox")
1567 * (Render function for getSingleField_typeSelect())
1568 *
1569 * @param string See getSingleField_typeSelect()
1570 * @param string See getSingleField_typeSelect()
1571 * @param array See getSingleField_typeSelect()
1572 * @param array See getSingleField_typeSelect()
1573 * @param array (Redundant) content of $PA['fieldConf']['config'] (for convenience)
1574 * @param array Items available for selection
1575 * @param string Label for no-matching-value
1576 * @return string The HTML code for the item
1577 * @see getSingleField_typeSelect()
1578 */
1579 function getSingleField_typeSelect_singlebox($table,$field,$row,&$PA,$config,$selItems,$nMV_label) {
1580
1581 // Get values in an array (and make unique, which is fine because there can be no duplicates anyway):
1582 $itemArray = array_flip($this->extractValuesOnlyFromValueLabelList($PA['itemFormElValue']));
1583
1584 $disabled = '';
1585 if($this->renderReadonly || $config['readOnly']) {
1586 $disabled = ' disabled="disabled"';
1587 }
1588
1589 // Traverse the Array of selector box items:
1590 $opt = array();
1591 $restoreCmd = array(); // Used to accumulate the JS needed to restore the original selection.
1592 $c = 0;
1593 foreach($selItems as $p) {
1594 // Selected or not by default:
1595 $sM = '';
1596 if (isset($itemArray[$p[1]])) {
1597 $sM = ' selected="selected"';
1598 $restoreCmd[] = $this->elName($PA['itemFormElName'].'[]').'.options['.$c.'].selected=1;';
1599 unset($itemArray[$p[1]]);
1600 }
1601
1602 // Non-selectable element:
1603 $nonSel = '';
1604 if (!strcmp($p[1],'--div--')) {
1605 $nonSel = ' onclick="this.selected=0;" class="c-divider"';
1606 }
1607
1608 // Icon style for option tag:
1609 if ($config['iconsInOptionTags']) {
1610 $styleAttrValue = $this->optionTagStyle($p[2]);
1611 }
1612
1613 // Compile <option> tag:
1614 $opt[] = '<option value="'.htmlspecialchars($p[1]).'"'.
1615 $sM.
1616 $nonSel.
1617 ($styleAttrValue ? ' style="'.htmlspecialchars($styleAttrValue).'"' : '').
1618 '>'.t3lib_div::deHSCentities(htmlspecialchars($p[0])).'</option>';
1619 $c++;
1620 }
1621
1622 // Remaining values:
1623 if (count($itemArray) && !$PA['fieldTSConfig']['disableNoMatchingValueElement'] && !$config['disableNoMatchingValueElement']) {
1624 foreach($itemArray as $theNoMatchValue => $temp) {
1625 // Compile <option> tag:
1626 array_unshift($opt,'<option value="'.htmlspecialchars($theNoMatchValue).'" selected="selected">'.t3lib_div::deHSCentities(htmlspecialchars(@sprintf($nMV_label, $theNoMatchValue))).'</option>');
1627 }
1628 }
1629
1630 // Compile selector box:
1631 $sOnChange = implode('',$PA['fieldChangeFunc']);
1632 $selector_itemListStyle = isset($config['itemListStyle']) ? ' style="'.htmlspecialchars($config['itemListStyle']).'"' : ' style="'.$this->defaultMultipleSelectorStyle.'"';
1633 $size = intval($config['size']);
1634 $size = $config['autoSizeMax'] ? t3lib_div::intInRange(count($selItems)+1,t3lib_div::intInRange($size,1),$config['autoSizeMax']) : $size;
1635 $selectBox = '<select name="'.$PA['itemFormElName'].'[]"'.
1636 $this->insertDefStyle('select').
1637 ($size ? ' size="'.$size.'"' : '').
1638 ' multiple="multiple" onchange="'.htmlspecialchars($sOnChange).'"'.
1639 $PA['onFocus'].
1640 $selector_itemListStyle.
1641 $disabled.'>
1642 '.
1643 implode('
1644 ',$opt).'
1645 </select>';
1646
1647 // Add an empty hidden field which will send a blank value if all items are unselected.
1648 if (!$disabled) {
1649 $item.='<input type="hidden" name="'.htmlspecialchars($PA['itemFormElName']).'" value="" />';
1650 }
1651
1652 // Put it all into a table:
1653 $item.= '
1654 <table border="0" cellspacing="0" cellpadding="0" width="1" class="typo3-TCEforms-select-singlebox">
1655 <tr>
1656 <td>
1657 '.$selectBox.'
1658 <br/>
1659 <em>'.
1660 htmlspecialchars($this->getLL('l_holdDownCTRL')).
1661 '</em>
1662 </td>
1663 <td valign="top">
1664 <a href="#" onclick="'.htmlspecialchars($this->elName($PA['itemFormElName'].'[]').'.selectedIndex=-1;'.implode('',$restoreCmd).' return false;').'">'.
1665 '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/history.gif','width="13" height="12"').' title="'.htmlspecialchars($this->getLL('l_revertSelection')).'" alt="" />'.
1666 '</a>
1667 </td>
1668 </tr>
1669 </table>
1670 ';
1671
1672 return $item;
1673 }
1674
1675 /**
1676 * Creates a multiple-selector box (two boxes, side-by-side)
1677 * (Render function for getSingleField_typeSelect())
1678 *
1679 * @param string See getSingleField_typeSelect()
1680 * @param string See getSingleField_typeSelect()
1681 * @param array See getSingleField_typeSelect()
1682 * @param array See getSingleField_typeSelect()
1683 * @param array (Redundant) content of $PA['fieldConf']['config'] (for convenience)
1684 * @param array Items available for selection
1685 * @param string Label for no-matching-value
1686 * @return string The HTML code for the item
1687 * @see getSingleField_typeSelect()
1688 */
1689 function getSingleField_typeSelect_multiple($table,$field,$row,&$PA,$config,$selItems,$nMV_label) {
1690
1691 $disabled = '';
1692 if($this->renderReadonly || $config['readOnly']) {
1693 $disabled = ' disabled="disabled"';
1694 }
1695
1696 // Setting this hidden field (as a flag that JavaScript can read out)
1697 if (!$disabled) {
1698 $item.= '<input type="hidden" name="'.$PA['itemFormElName'].'_mul" value="'.($config['multiple']?1:0).'" />';
1699 }
1700
1701 // Set max and min items:
1702 $maxitems = t3lib_div::intInRange($config['maxitems'],0);
1703 if (!$maxitems) $maxitems=100000;
1704 $minitems = t3lib_div::intInRange($config['minitems'],0);
1705
1706 // Register the required number of elements:
1707 $this->requiredElements[$PA['itemFormElName']] = array($minitems,$maxitems,'imgName'=>$table.'_'.$row['uid'].'_'.$field);
1708
1709 // Get "removeItems":
1710 $removeItems = t3lib_div::trimExplode(',',$PA['fieldTSConfig']['removeItems'],1);
1711
1712 // Perform modification of the selected items array:
1713 $itemArray = t3lib_div::trimExplode(',',$PA['itemFormElValue'],1);
1714 foreach($itemArray as $tk => $tv) {
1715 $tvP = explode('|',$tv,2);
1716 $evalValue = rawurldecode($tvP[0]);
1717 $isRemoved = in_array($evalValue,$removeItems) || ($config['form_type']=='select' && $config['authMode'] && !$GLOBALS['BE_USER']->checkAuthMode($table,$field,$evalValue,$config['authMode']));
1718 if ($isRemoved && !$PA['fieldTSConfig']['disableNoMatchingValueElement'] && !$config['disableNoMatchingValueElement']) {
1719 $tvP[1] = rawurlencode(@sprintf($nMV_label, $evalValue));
1720 } elseif (isset($PA['fieldTSConfig']['altLabels.'][$evalValue])) {
1721 $tvP[1] = rawurlencode($this->sL($PA['fieldTSConfig']['altLabels.'][$evalValue]));
1722 }
1723 $itemArray[$tk] = implode('|',$tvP);
1724 }
1725 $itemsToSelect = '';
1726
1727 if(!$disabled) {
1728 // Create option tags:
1729 $opt = array();
1730 $styleAttrValue = '';
1731 foreach($selItems as $p) {
1732 if ($config['iconsInOptionTags']) {
1733 $styleAttrValue = $this->optionTagStyle($p[2]);
1734 }
1735 $opt[]= '<option value="'.htmlspecialchars($p[1]).'"'.
1736 ($styleAttrValue ? ' style="'.htmlspecialchars($styleAttrValue).'"' : '').
1737 '>'.htmlspecialchars($p[0]).'</option>';
1738 }
1739
1740 // Put together the selector box:
1741 $selector_itemListStyle = isset($config['itemListStyle']) ? ' style="'.htmlspecialchars($config['itemListStyle']).'"' : ' style="'.$this->defaultMultipleSelectorStyle.'"';
1742 $size = intval($config['size']);
1743 $size = $config['autoSizeMax'] ? t3lib_div::intInRange(count($itemArray)+1,t3lib_div::intInRange($size,1),$config['autoSizeMax']) : $size;
1744 if ($config['exclusiveKeys']) {
1745 $sOnChange = 'setFormValueFromBrowseWin(\''.$PA['itemFormElName'].'\',this.options[this.selectedIndex].value,this.options[this.selectedIndex].text,\''.$config['exclusiveKeys'].'\'); ';
1746 } else {
1747 $sOnChange = 'setFormValueFromBrowseWin(\''.$PA['itemFormElName'].'\',this.options[this.selectedIndex].value,this.options[this.selectedIndex].text); ';
1748 }
1749 $sOnChange .= implode('',$PA['fieldChangeFunc']);
1750 $itemsToSelect = '
1751 <select name="'.$PA['itemFormElName'].'_sel"'.
1752 $this->insertDefStyle('select').
1753 ($size ? ' size="'.$size.'"' : '').
1754 ' onchange="'.htmlspecialchars($sOnChange).'"'.
1755 $PA['onFocus'].
1756 $selector_itemListStyle.'>
1757 '.implode('
1758 ',$opt).'
1759 </select>';
1760 }
1761
1762 // Pass to "dbFileIcons" function:
1763 $params = array(
1764 'size' => $size,
1765 'autoSizeMax' => t3lib_div::intInRange($config['autoSizeMax'],0),
1766 'style' => isset($config['selectedListStyle']) ? ' style="'.htmlspecialchars($config['selectedListStyle']).'"' : ' style="'.$this->defaultMultipleSelectorStyle.'"',
1767 'dontShowMoveIcons' => ($maxitems<=1),
1768 'maxitems' => $maxitems,
1769 'info' => '',
1770 'headers' => array(
1771 'selector' => $this->getLL('l_selected').':<br />',
1772 'items' => $this->getLL('l_items').':<br />'
1773 ),
1774 'noBrowser' => 1,
1775 'thumbnails' => $itemsToSelect,
1776 'readOnly' => $disabled
1777 );
1778 $item.= $this->dbFileIcons($PA['itemFormElName'],'','',$itemArray,'',$params,$PA['onFocus']);
1779
1780 return $item;
1781 }
1782
1783 /**
1784 * Generation of TCEform elements of the type "group"
1785 * This will render a selectorbox into which elements from either the file system or database can be inserted. Relations.
1786 *
1787 * @param string The table name of the record
1788 * @param string The field name which this element is supposed to edit
1789 * @param array The record data array where the value(s) for the field can be found
1790 * @param array An array with additional configuration options.
1791 * @return string The HTML code for the TCEform field
1792 */
1793 function getSingleField_typeGroup($table,$field,$row,&$PA) {
1794 // Init:
1795 $config = $PA['fieldConf']['config'];
1796 $internal_type = $config['internal_type'];
1797 $show_thumbs = $config['show_thumbs'];
1798 $size = intval($config['size']);
1799 $maxitems = t3lib_div::intInRange($config['maxitems'],0);
1800 if (!$maxitems) $maxitems=100000;
1801 $minitems = t3lib_div::intInRange($config['minitems'],0);
1802 $allowed = $config['allowed'];
1803 $disallowed = $config['disallowed'];
1804
1805 $disabled = '';
1806 if($this->renderReadonly || $config['readOnly']) {
1807 $disabled = ' disabled="disabled"';
1808 }
1809
1810 $item.= '<input type="hidden" name="'.$PA['itemFormElName'].'_mul" value="'.($config['multiple']?1:0).'"'.$disabled.' />';
1811 $this->requiredElements[$PA['itemFormElName']] = array($minitems,$maxitems,'imgName'=>$table.'_'.$row['uid'].'_'.$field);
1812 $info='';
1813
1814 // "Extra" configuration; Returns configuration for the field based on settings found in the "types" fieldlist. See http://typo3.org/documentation/document-library/doc_core_api/Wizards_Configuratio/.
1815 $specConf = $this->getSpecConfFromString($PA['extra'], $PA['fieldConf']['defaultExtras']);
1816
1817 // Acting according to either "file" or "db" type:
1818 switch((string)$config['internal_type']) {
1819 case 'file': // If the element is of the internal type "file":
1820
1821 // Creating string showing allowed types:
1822 $tempFT = t3lib_div::trimExplode(',',$allowed,1);
1823 if (!count($tempFT)) {$info.='*';}
1824 foreach($tempFT as $ext) {
1825 if ($ext) {
1826 $info.=strtoupper($ext).' ';
1827 }
1828 }
1829 // Creating string, showing disallowed types:
1830 $tempFT_dis = t3lib_div::trimExplode(',',$disallowed,1);
1831 if (count($tempFT_dis)) {$info.='<br />';}
1832 foreach($tempFT_dis as $ext) {
1833 if ($ext) {
1834 $info.='-'.strtoupper($ext).' ';
1835 }
1836 }
1837
1838 // Making the array of file items:
1839 $itemArray = t3lib_div::trimExplode(',',$PA['itemFormElValue'],1);
1840
1841 // Showing thumbnails:
1842 $thumbsnail = '';
1843 if ($show_thumbs) {
1844 $imgs = array();
1845 foreach($itemArray as $imgRead) {
1846 $imgP = explode('|',$imgRead);
1847
1848 $rowCopy = array();
1849 $rowCopy[$field] = $imgP[0];
1850
1851 // Icon + clickmenu:
1852 $absFilePath = t3lib_div::getFileAbsFileName($config['uploadfolder'].'/'.$imgP[0]);
1853
1854 $fI = pathinfo($imgP[0]);
1855 $fileIcon = t3lib_BEfunc::getFileIcon(strtolower($fI['extension']));
1856 $fileIcon = '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/fileicons/'.$fileIcon,'width="18" height="16"').' class="absmiddle" title="'.htmlspecialchars($fI['basename'].($absFilePath && @is_file($absFilePath) ? ' ('.t3lib_div::formatSize(filesize($absFilePath)).'bytes)' : ' - FILE NOT FOUND!')).'" alt="" />';
1857
1858 $imgs[] = '<span class="nobr">'.t3lib_BEfunc::thumbCode($rowCopy,$table,$field,$this->backPath,'thumbs.php',$config['uploadfolder'],0,' align="middle"').
1859 ($absFilePath ? $this->getClickMenu($fileIcon, $absFilePath) : $fileIcon).
1860 $imgP[0].
1861 '</span>';
1862 }
1863 $thumbsnail = implode('<br />',$imgs);
1864 }
1865
1866 // Creating the element:
1867 $params = array(
1868 'size' => $size,
1869 'dontShowMoveIcons' => ($maxitems<=1),
1870 'autoSizeMax' => t3lib_div::intInRange($config['autoSizeMax'],0),
1871 'maxitems' => $maxitems,
1872 'style' => isset($config['selectedListStyle']) ? ' style="'.htmlspecialchars($config['selectedListStyle']).'"' : ' style="'.$this->defaultMultipleSelectorStyle.'"',
1873 'info' => $info,
1874 'thumbnails' => $thumbsnail,
1875 'readOnly' => $disabled
1876 );
1877 $item.= $this->dbFileIcons($PA['itemFormElName'],'file',implode(',',$tempFT),$itemArray,'',$params,$PA['onFocus']);
1878
1879 if(!$disabled) {
1880 // Adding the upload field:
1881 if ($this->edit_docModuleUpload) $item.='<input type="file" name="'.$PA['itemFormElName_file'].'"'.$this->formWidth().' size="60" />';
1882 }
1883 break;
1884 case 'db': // If the element is of the internal type "db":
1885
1886 // Creating string showing allowed types:
1887 $tempFT = t3lib_div::trimExplode(',',$allowed,1);
1888 if (!strcmp(trim($tempFT[0]),'*')) {
1889 $info.='<span class="nobr">&nbsp;&nbsp;&nbsp;&nbsp;'.
1890 htmlspecialchars($this->getLL('l_allTables')).
1891 '</span><br />';
1892 } else {
1893 while(list(,$theT)=each($tempFT)) {
1894 if ($theT) {
1895 $info.='<span class="nobr">&nbsp;&nbsp;&nbsp;&nbsp;'.
1896 t3lib_iconWorks::getIconImage($theT,array(),$this->backPath,'align="top"').
1897 htmlspecialchars($this->sL($GLOBALS['TCA'][$theT]['ctrl']['title'])).
1898 '</span><br />';
1899 }
1900 }
1901 }
1902
1903 $perms_clause = $GLOBALS['BE_USER']->getPagePermsClause(1);
1904 $itemArray = array();
1905 $imgs = array();
1906
1907 // Thumbnails:
1908 $temp_itemArray = t3lib_div::trimExplode(',',$PA['itemFormElValue'],1);
1909 foreach($temp_itemArray as $dbRead) {
1910 $recordParts = explode('|',$dbRead);
1911 list($this_table,$this_uid) = t3lib_BEfunc::splitTable_Uid($recordParts[0]);
1912 $itemArray[] = array('table'=>$this_table, 'id'=>$this_uid);
1913 if (!$disabled && $show_thumbs) {
1914 $rr = t3lib_BEfunc::getRecordWSOL($this_table,$this_uid);
1915 $imgs[] = '<span class="nobr">'.
1916 $this->getClickMenu(t3lib_iconWorks::getIconImage($this_table,$rr,$this->backPath,'align="top" title="'.htmlspecialchars(t3lib_BEfunc::getRecordPath($rr['pid'],$perms_clause,15)).' [UID: '.$rr['uid'].']"'),$this_table, $this_uid).
1917 '&nbsp;'.
1918 htmlspecialchars(t3lib_div::fixed_lgd_cs($this->noTitle($rr[$GLOBALS['TCA'][$this_table]['ctrl']['label']],array('<em>','</em>')),$this->titleLen)).' <span class="typo3-dimmed"><em>['.$rr['uid'].']</em></span>'.
1919 '</span>';
1920 }
1921 }
1922 $thumbsnail='';
1923 if (!$disabled && $show_thumbs) {
1924 $thumbsnail = implode('<br />',$imgs);
1925 }
1926
1927 // Creating the element:
1928 $params = array(
1929 'size' => $size,
1930 'dontShowMoveIcons' => ($maxitems<=1),
1931 'autoSizeMax' => t3lib_div::intInRange($config['autoSizeMax'],0),
1932 'maxitems' => $maxitems,
1933 'style' => isset($config['selectedListStyle']) ? ' style="'.htmlspecialchars($config['selectedListStyle']).'"' : ' style="'.$this->defaultMultipleSelectorStyle.'"',
1934 'info' => $info,
1935 'thumbnails' => $thumbsnail,
1936 'readOnly' => $disabled
1937 );
1938 $item.= $this->dbFileIcons($PA['itemFormElName'],'db',implode(',',$tempFT),$itemArray,'',$params,$PA['onFocus']);
1939
1940 break;
1941 }
1942
1943 // Wizards:
1944 $altItem = '<input type="hidden" name="'.$PA['itemFormElName'].'" value="'.htmlspecialchars($PA['itemFormElValue']).'" />';
1945 if (!$disabled) {
1946 $item = $this->renderWizards(array($item,$altItem),$config['wizards'],$table,$row,$field,$PA,$PA['itemFormElName'],$specConf);
1947 }
1948
1949 return $item;
1950 }
1951
1952 /**
1953 * Generation of TCEform elements of the type "none"
1954 * This will render a non-editable display of the content of the field.
1955 *
1956 * @param string The table name of the record
1957 * @param string The field name which this element is supposed to edit
1958 * @param array The record data array where the value(s) for the field can be found
1959 * @param array An array with additional configuration options.
1960 * @return string The HTML code for the TCEform field
1961 */
1962 function getSingleField_typeNone($table,$field,$row,&$PA) {
1963 // Init:
1964 $config = $PA['fieldConf']['config'];
1965 $itemValue = $PA['itemFormElValue'];
1966
1967 return $this->getSingleField_typeNone_render($config,$itemValue);
1968 }
1969
1970 /**
1971 * HTML rendering of a value which is not editable.
1972 *
1973 * @param array Configuration for the display
1974 * @param string The value to display
1975 * @return string The HTML code for the display
1976 * @see getSingleField_typeNone();
1977 */
1978 function getSingleField_typeNone_render($config,$itemValue) {
1979
1980 // is colorScheme[0] the right value?
1981 $divStyle = 'border:solid 1px '.t3lib_div::modifyHTMLColorAll($this->colorScheme[0],-30).';'.$this->defStyle.$this->formElStyle('none').' background-color: '.$this->colorScheme[0].'; padding-left:1px;color:#555;';
1982
1983 if ($config['format']) {
1984 $itemValue = $this->formatValue($config, $itemValue);
1985 }
1986
1987 $rows = intval($config['rows']);
1988 if ($rows > 1) {
1989 if(!$config['pass_content']) {
1990 $itemValue = nl2br(htmlspecialchars($itemValue));
1991 }
1992 // like textarea
1993 $cols = t3lib_div::intInRange($config['cols'] ? $config['cols'] : 30, 5, $this->maxTextareaWidth);
1994 if (!$config['fixedRows']) {
1995 $origRows = $rows = t3lib_div::intInRange($rows, 1, 20);
1996 if (strlen($itemValue)>$this->charsPerRow*2) {
1997 $cols = $this->maxTextareaWidth;
1998 $rows = t3lib_div::intInRange(round(strlen($itemValue)/$this->charsPerRow),count(explode(chr(10),$itemValue)),20);
1999 if ($rows<$origRows) $rows=$origRows;
2000 }
2001 }
2002
2003 if ($this->docLarge) $cols = round($cols*$this->form_largeComp);
2004 $width = ceil($cols*$this->form_rowsToStylewidth);
2005 // hardcoded: 12 is the height of the font
2006 $height=$rows*12;
2007
2008 $item='
2009 <div style="'.htmlspecialchars($divStyle.' overflow:auto; height:'.$height.'px; width:'.$width.'px;').'" class="'.htmlspecialchars($this->formElClass('none')).'">'.
2010 $itemValue.
2011 '</div>';
2012 } else {
2013 if(!$config['pass_content']) {
2014 $itemValue = htmlspecialchars($itemValue);
2015 }
2016
2017 $cols = $config['cols']?$config['cols']:($config['size']?$config['size']:$this->maxInputWidth);
2018 if ($this->docLarge) $cols = round($cols*$this->form_largeComp);
2019 $width = ceil($cols*$this->form_rowsToStylewidth);
2020
2021 // overflow:auto crashes mozilla here. Title tag is usefull when text is longer than the div box (overflow:hidden).
2022 $item = '
2023 <div style="'.htmlspecialchars($divStyle.' overflow:hidden; width:'.$width.'px;').'" class="'.htmlspecialchars($this->formElClass('none')).'" title="'.$itemValue.'">'.
2024 '<span class="nobr">'.(strcmp($itemValue,'')?$itemValue:'&nbsp;').'</span>'.
2025 '</div>';
2026 }
2027
2028 return $item;
2029 }
2030
2031 /**
2032 * Handler for Flex Forms
2033 *
2034 * @param string The table name of the record
2035 * @param string The field name which this element is supposed to edit
2036 * @param array The record data array where the value(s) for the field can be found
2037 * @param array An array with additional configuration options.
2038 * @return string The HTML code for the TCEform field
2039 */
2040 function getSingleField_typeFlex($table,$field,$row,&$PA) {
2041
2042 // Data Structure:
2043 $dataStructArray = t3lib_BEfunc::getFlexFormDS($PA['fieldConf']['config'],$row,$table);
2044
2045 // Get data structure:
2046 if (is_array($dataStructArray)) {
2047
2048 // Get data:
2049 $xmlData = $PA['itemFormElValue'];
2050 $xmlHeaderAttributes = t3lib_div::xmlGetHeaderAttribs($xmlData);
2051 $storeInCharset = strtolower($xmlHeaderAttributes['encoding']);
2052 if ($storeInCharset) {
2053 $currentCharset=$GLOBALS['LANG']->charSet;
2054 $xmlData = $GLOBALS['LANG']->csConvObj->conv($xmlData,$storeInCharset,$currentCharset,1);
2055 }
2056 $editData=t3lib_div::xml2array($xmlData);
2057 if (!is_array($editData)) { // Must be XML parsing error...
2058 $editData=array();
2059 } elseif (!isset($editData['meta']) || !is_array($editData['meta'])) {
2060 $editData['meta'] = array();
2061 }
2062
2063 // Find the data structure if sheets are found:
2064 $sheet = $editData['meta']['currentSheetId'] ? $editData['meta']['currentSheetId'] : 'sDEF'; // Sheet to display
2065
2066 // Create sheet menu:
2067 // if (is_array($dataStructArray['sheets'])) {
2068 // #$item.=$this->getSingleField_typeFlex_sheetMenu($dataStructArray['sheets'], $PA['itemFormElName'].'[meta][currentSheetId]', $sheet).'<br />';
2069 // }
2070
2071 // Create language menu:
2072 $langChildren = $dataStructArray['meta']['langChildren'] ? 1 : 0;
2073 $langDisabled = $dataStructArray['meta']['langDisable'] ? 1 : 0;
2074
2075 $editData['meta']['currentLangId']=array();
2076 $languages = $this->getAvailableLanguages();
2077
2078 foreach($languages as $lInfo) {
2079 if ($GLOBALS['BE_USER']->checkLanguageAccess($lInfo['uid'])) {
2080 $editData['meta']['currentLangId'][] = $lInfo['ISOcode'];
2081 }
2082 }
2083 if (!is_array($editData['meta']['currentLangId']) || !count($editData['meta']['currentLangId'])) {
2084 $editData['meta']['currentLangId']=array('DEF');
2085 }
2086
2087 $editData['meta']['currentLangId'] = array_unique($editData['meta']['currentLangId']);
2088
2089
2090 // if (!$langDisabled && count($languages) > 1) {
2091 // $item.=$this->getSingleField_typeFlex_langMenu($languages, $PA['itemFormElName'].'[meta][currentLangId]', $editData['meta']['currentLangId']).'<br />';
2092 // }
2093
2094 $PA['_noEditDEF'] = FALSE;
2095 if ($langChildren || $langDisabled) {
2096 $rotateLang = array('DEF');
2097 } else {
2098 if (!in_array('DEF',$editData['meta']['currentLangId'])) {
2099 array_unshift($editData['meta']['currentLangId'],'DEF');
2100 $PA['_noEditDEF'] = TRUE;
2101 }
2102 $rotateLang = $editData['meta']['currentLangId'];
2103 }
2104
2105 // Tabs sheets
2106 if (is_array($dataStructArray['sheets'])) {
2107 $tabsToTraverse = array_keys($dataStructArray['sheets']);
2108 } else {
2109 $tabsToTraverse = array($sheet);
2110 }
2111
2112 foreach ($rotateLang as $lKey) {
2113 if (!$langChildren && !$langDisabled) {
2114 $item.= '<b>'.$lKey.':</b>';
2115 }
2116
2117 $tabParts = array();
2118 foreach ($tabsToTraverse as $sheet) {
2119 $sheetCfg = $dataStructArray['sheets'][$sheet];
2120 list ($dataStruct, $sheet) = t3lib_div::resolveSheetDefInDS($dataStructArray,$sheet);
2121
2122 // Render sheet:
2123 if (is_array($dataStruct['ROOT']) && is_array($dataStruct['ROOT']['el'])) {
2124 $cmdData = t3lib_div::_GP('flexFormsCmdData');
2125 $lang = 'l'.$lKey; // Default language, other options are "lUK" or whatever country code (independant of system!!!)
2126 $PA['_valLang'] = $langChildren && !$langDisabled ? $editData['meta']['currentLangId'] : 'DEF'; // Default language, other options are "lUK" or whatever country code (independant of system!!!)
2127 $PA['_lang'] = $lang;
2128
2129 // Render flexform:
2130 $tRows = $this->getSingleField_typeFlex_draw(
2131 $dataStruct['ROOT']['el'],
2132 $editData['data'][$sheet][$lang],
2133 $cmdData['data'][$sheet][$lang],
2134 $table,
2135 $field,
2136 $row,
2137 $PA,
2138 '[data]['.$sheet.']['.$lang.']'
2139 );
2140 $sheetContent= '<table border="0" cellpadding="1" cellspacing="1" class="typo3-TCEforms-flexForm">'.implode('',$tRows).'</table>';
2141
2142 # $item = '<div style=" position:absolute;">'.$item.'</div>';
2143 //visibility:hidden;
2144 } else $sheetContent='Data Structure ERROR: No ROOT element found for sheet "'.$sheet.'".';
2145
2146 // Add to tab:
2147 $tabParts[] = array(
2148 'label' => ($sheetCfg['ROOT']['TCEforms']['sheetTitle'] ? $this->sL($sheetCfg['ROOT']['TCEforms']['sheetTitle']) : $sheet),
2149 'description' => ($sheetCfg['ROOT']['TCEforms']['sheetDescription'] ? $this->sL($sheetCfg['ROOT']['TCEforms']['sheetDescription']) : ''),
2150 'linkTitle' => ($sheetCfg['ROOT']['TCEforms']['sheetShortDescr'] ? $this->sL($sheetCfg['ROOT']['TCEforms']['sheetShortDescr']) : ''),
2151 'content' => $sheetContent
2152 );
2153 }
2154
2155 if (is_array($dataStructArray['sheets'])) {
2156 $item.= $this->getDynTabMenu($tabParts,'TCEFORMS:flexform:'.$PA['itemFormElName'].$PA['_lang']);
2157 } else {
2158 $item.= $sheetContent;
2159 }
2160 }
2161 } else $item='Data Structure ERROR: '.$dataStructArray;
2162
2163 return $item;
2164 }
2165
2166 /**
2167 * Creates the language menu for FlexForms:
2168 *
2169 * @param [type] $languages: ...
2170 * @param [type] $elName: ...
2171 * @param [type] $selectedLanguage: ...
2172 * @param [type] $multi: ...
2173 * @return string HTML for menu
2174 */
2175 function getSingleField_typeFlex_langMenu($languages,$elName,$selectedLanguage,$multi=1) {
2176 $opt=array();
2177 foreach($languages as $lArr) {
2178 $opt[]='<option value="'.htmlspecialchars($lArr['ISOcode']).'"'.(in_array($lArr['ISOcode'],$selectedLanguage)?' selected="selected"':'').'>'.htmlspecialchars($lArr['title']).'</option>';
2179 }
2180
2181 $output = '<select name="'.$elName.'[]"'.($multi ? ' multiple="multiple" size="'.count($languages).'"' : '').'>'.implode('',$opt).'</select>';
2182
2183 return $output;
2184 }
2185
2186 /**
2187 * Creates the menu for selection of the sheets:
2188 *
2189 * @param array Sheet array for which to render the menu
2190 * @param string Form element name of the field containing the sheet pointer
2191 * @param string Current sheet key
2192 * @return string HTML for menu
2193 */
2194 function getSingleField_typeFlex_sheetMenu($sArr,$elName,$sheetKey) {
2195
2196 $tCells =array();
2197 $pct = round(100/count($sArr));
2198 foreach($sArr as $sKey => $sheetCfg) {
2199 if ($GLOBALS['BE_USER']->jsConfirmation(1)) {
2200 $onClick = 'if (confirm('.$GLOBALS['LANG']->JScharCode($this->getLL('m_onChangeAlert')).') && TBE_EDITOR_checkSubmit(-1)){'.$this->elName($elName).".value='".$sKey."'; TBE_EDITOR_submitForm()};";
2201 } else {
2202 $onClick = 'if(TBE_EDITOR_checkSubmit(-1)){ '.$this->elName($elName).".value='".$sKey."'; TBE_EDITOR_submitForm();}";
2203 }
2204
2205
2206 $tCells[]='<td width="'.$pct.'%" style="'.($sKey==$sheetKey ? 'background-color: #9999cc; font-weight: bold;' : 'background-color: #aaaaaa;').' cursor: hand;" onclick="'.htmlspecialchars($onClick).'" align="center">'.
2207 ($sheetCfg['ROOT']['TCEforms']['sheetTitle'] ? $this->sL($sheetCfg['ROOT']['TCEforms']['sheetTitle']) : $sKey).
2208 '</td>';
2209 }
2210
2211 return '<table border="0" cellpadding="0" cellspacing="2" class="typo3-TCEforms-flexForm-sheetMenu"><tr>'.implode('',$tCells).'</tr></table>';
2212 }
2213
2214 /**
2215 * [Describe function...]
2216 *
2217 * @param [type] $dataStruct: ...
2218 * @param [type] $editData: ...
2219 * @param [type] $cmdData: ...
2220 * @param [type] $table: ...
2221 * @param [type] $field: ...
2222 * @param [type] $row: ...
2223 * @param [type] $PA: ...
2224 * @param [type] $formPrefix: ...
2225 * @param [type] $level: ...
2226 * @param [type] $tRows: ...
2227 * @return [type] ...
2228 */
2229 function getSingleField_typeFlex_draw($dataStruct,$editData,$cmdData,$table,$field,$row,&$PA,$formPrefix='',$level=0,$tRows=array()) {
2230
2231 // Data Structure array must be ... and array of course...
2232 if (is_array($dataStruct)) {
2233 foreach($dataStruct as $key => $value) {
2234 if (is_array($value)) { // The value of each entry must be an array.
2235
2236 // ********************
2237 // Making the row:
2238 // ********************
2239 $rowCells=array();
2240
2241 // Icon:
2242 $rowCells['title'] = '<img src="clear.gif" width="'.($level*16).'" height="1" alt="" /><strong>'.htmlspecialchars(t3lib_div::fixed_lgd_cs($this->sL($value['tx_templavoila']['title']),30)).'</strong>';;
2243
2244 $rowCells['formEl']='';
2245 if ($value['type']=='array') {
2246 if ($value['section']) {
2247 // Render "NEW [container]" selectorbox:
2248 if (is_array($value['el'])) {
2249 $opt=array();
2250 $opt[]='<option value=""></option>';
2251 foreach($value['el'] as $kk => $vv) {
2252 $opt[]='<option value="'.$kk.'">'.htmlspecialchars($this->getLL('l_new') . ' "'.$this->sL($value['el'][$kk]['tx_templavoila']['title']).'"').'</option>';
2253 }
2254 $rowCells['formEl']='<select name="flexFormsCmdData'.$formPrefix.'['.$key.'][value]">'.implode('',$opt).'</select>';
2255 }
2256
2257 // Put row together
2258 $tRows[]='<tr class="bgColor2">
2259 <td nowrap="nowrap" valign="top">'.$rowCells['title'].'</td>
2260 <td>'.$rowCells['formEl'].'</td>
2261 </tr>';
2262
2263 $cc=0;
2264 if (is_array($editData[$key]['el'])) {
2265 foreach ($editData[$key]['el'] as $k3 => $v3) {
2266 $cc=$k3;
2267 $theType = key($v3);
2268 $theDat = $v3[$theType];
2269 $newSectionEl = $value['el'][$theType];
2270 if (is_array($newSectionEl)) {
2271 $tRows = $this->getSingleField_typeFlex_draw(
2272 array($theType => $newSectionEl),
2273 array($theType => $theDat),
2274 $cmdData[$key]['el'][$cc],
2275 $table,
2276 $field,
2277 $row,
2278 $PA,
2279 $formPrefix.'['.$key.'][el]['.$cc.']',
2280 $level+1,
2281 $tRows
2282 );
2283 }
2284 }
2285 }
2286
2287
2288
2289 // New form?
2290 if ($cmdData[$key]['value']) {
2291 $newSectionEl = $value['el'][$cmdData[$key]['value']];
2292 if (is_array($newSectionEl)) {
2293 $tRows = $this->getSingleField_typeFlex_draw(
2294 array($cmdData[$key]['value'] => $newSectionEl),
2295 array(),
2296 array(),
2297 $table,
2298 $field,
2299 $row,
2300 $PA,
2301 $formPrefix.'['.$key.'][el]['.($cc+1).']',
2302 $level+1,
2303 $tRows
2304 );
2305 }
2306 }
2307 } else {
2308 $idTagPrefix = uniqid('id',true); // ID attributes are used for the move and delete checkboxes for referencing to them in the label tag (<label for="the form field id">) that's rendered around the icons
2309
2310 // Put row together
2311 $tRows[]='<tr class="bgColor2">
2312 <td nowrap="nowrap" valign="top">'.
2313 '<input name="_DELETE_FLEX_FORM'.$PA['itemFormElName'].$formPrefix.'" id="'.$idTagPrefix.'-del" type="checkbox"'.$this->insertDefStyle('check').' value="1" /><label for="'.$idTagPrefix.'-del"><img src="'.$this->backPath.'gfx/garbage.gif" border="0" alt="" /></label>'.
2314 '<input name="_MOVEUP_FLEX_FORM'.$PA['itemFormElName'].$formPrefix.'" id="'.$idTagPrefix.'-mvup" type="checkbox"'.$this->insertDefStyle('check').' value="1" /><label for="'.$idTagPrefix.'-mvup"><img src="'.$this->backPath.'gfx/button_up.gif" border="0" alt="" /></label>'.
2315 '<input name="_MOVEDOWN_FLEX_FORM'.$PA['itemFormElName'].$formPrefix.'" id="'.$idTagPrefix.'-mvdown" type="checkbox"'.$this->insertDefStyle('check').' value="1" /><label for="'.$idTagPrefix.'-mvdown"><img src="'.$this->backPath.'gfx/button_down.gif" border="0" alt="" /></label>'.
2316 $rowCells['title'].'</td>
2317 <td>'.$rowCells['formEl'].'</td>
2318 </tr>';
2319
2320 $tRows = $this->getSingleField_typeFlex_draw(
2321 $value['el'],
2322 $editData[$key]['el'],
2323 $cmdData[$key]['el'],
2324 $table,
2325 $field,
2326 $row,
2327 $PA,
2328 $formPrefix.'['.$key.'][el]',
2329 $level+1,
2330 $tRows
2331 );
2332 }
2333
2334 } elseif (is_array($value['TCEforms']['config'])) { // Rendering a single form element:
2335
2336 if (is_array($PA['_valLang'])) {
2337 $rotateLang = $PA['_valLang'];
2338 } else {
2339 $rotateLang = array($PA['_valLang']);
2340 }
2341
2342 foreach($rotateLang as $vDEFkey) {
2343 $vDEFkey = 'v'.$vDEFkey;
2344
2345 if (!$value['TCEforms']['displayCond'] || $this->isDisplayCondition($value['TCEforms']['displayCond'],$editData,$vDEFkey)) {
2346 $fakePA=array();
2347 $fakePA['fieldConf']=array(
2348 'label' => $this->sL(trim($value['TCEforms']['label'])),
2349 'config' => $value['TCEforms']['config'],
2350 'defaultExtras' => $value['TCEforms']['defaultExtras'],
2351 'onChange' => $value['TCEforms']['onChange']
2352 );
2353 if ($PA['_noEditDEF'] && $PA['_lang']==='lDEF') {
2354 $fakePA['fieldConf']['config'] = array(
2355 'type' => 'none',
2356 'rows' => 2
2357 );
2358 }
2359
2360 if (
2361 $fakePA['fieldConf']['onChange'] == 'reload' ||
2362 ($GLOBALS['TCA'][$table]['ctrl']['type'] && !strcmp($key,$GLOBALS['TCA'][$table]['ctrl']['type'])) ||
2363 ($GLOBALS['TCA'][$table]['ctrl']['requestUpdate'] && t3lib_div::inList($GLOBALS['TCA'][$table]['ctrl']['requestUpdate'],$key))) {
2364 if ($GLOBALS['BE_USER']->jsConfirmation(1)) {
2365 $alertMsgOnChange = 'if (confirm('.$GLOBALS['LANG']->JScharCode($this->getLL('m_onChangeAlert')).') && TBE_EDITOR_checkSubmit(-1)){ TBE_EDITOR_submitForm() };';
2366 } else {
2367 $alertMsgOnChange = 'if(TBE_EDITOR_checkSubmit(-1)){ TBE_EDITOR_submitForm();}';
2368 }
2369 } else {
2370 $alertMsgOnChange = '';
2371 }
2372
2373 $fakePA['fieldChangeFunc']=$PA['fieldChangeFunc'];
2374 if (strlen($alertMsgOnChange)) {
2375 $fakePA['fieldChangeFunc']['alert']=$alertMsgOnChange;
2376 }
2377 $fakePA['onFocus']=$PA['onFocus'];
2378 $fakePA['label']=$PA['label'];
2379
2380 $fakePA['itemFormElName']=$PA['itemFormElName'].$formPrefix.'['.$key.']['.$vDEFkey.']';
2381 $fakePA['itemFormElName_file']=$PA['itemFormElName_file'].$formPrefix.'['.$key.']['.$vDEFkey.']';
2382
2383 if(isset($editData[$key][$vDEFkey])) {
2384 $fakePA['itemFormElValue']=$editData[$key][$vDEFkey];
2385 } else {
2386 $fakePA['itemFormElValue']=$fakePA['fieldConf']['config']['default'];
2387 }
2388
2389 $rowCells['formEl']= $this->getSingleField_SW($table,$field,$row,$fakePA);
2390 $rowCells['title']= htmlspecialchars($fakePA['fieldConf']['label']);
2391
2392 if (!in_array('DEF',$rotateLang)) {
2393 $defInfo = '<div class="typo3-TCEforms-originalLanguageValue">'.nl2br(htmlspecialchars($editData[$key]['vDEF'])).'&nbsp;</div>';
2394 } else {
2395 $defInfo = '';
2396 }
2397
2398 // Put row together
2399 $tRows[]='<tr>
2400 <td nowrap="nowrap" valign="top" class="bgColor5">'.$rowCells['title'].($vDEFkey=='vDEF' ? '' : ' ('.$vDEFkey.')').'</td>
2401 <td class="bgColor4">'.$rowCells['formEl'].$defInfo.'</td>
2402 </tr>';
2403 }
2404 }
2405 }
2406 }
2407 }
2408 }
2409
2410 return $tRows;
2411 }
2412
2413 /**
2414 * Handler for unknown types.
2415 *
2416 * @param string The table name of the record
2417 * @param string The field name which this element is supposed to edit
2418 * @param array The record data array where the value(s) for the field can be found
2419 * @param array An array with additional configuration options.
2420 * @return string The HTML code for the TCEform field
2421 */
2422 function getSingleField_typeUnknown($table,$field,$row,&$PA) {
2423 $item='Unknown type: '.$PA['fieldConf']['config']['form_type'].'<br />';
2424
2425 return $item;
2426 }
2427
2428 /**
2429 * User defined field type
2430 *
2431 * @param string The table name of the record
2432 * @param string The field name which this element is supposed to edit
2433 * @param array The record data array where the value(s) for the field can be found
2434 * @param array An array with additional configuration options.
2435 * @return string The HTML code for the TCEform field
2436 */
2437 function getSingleField_typeUser($table,$field,$row,&$PA) {
2438 $PA['table']=$table;
2439 $PA['field']=$field;
2440 $PA['row']=$row;
2441
2442 $PA['pObj']=&$this;
2443
2444 return t3lib_div::callUserFunction($PA['fieldConf']['config']['userFunc'],$PA,$this);
2445 }
2446
2447
2448
2449
2450
2451
2452 /************************************************************
2453 *
2454 * Field content processing
2455 *
2456 ************************************************************/
2457
2458 /**
2459 * Format field content of various types if $config['format'] is set to date, filesize, ..., user
2460 * This is primarily for the field type none but can be used for user field types for example
2461 *
2462 * @param array Configuration for the display
2463 * @param string The value to display
2464 * @return string Formatted Field content
2465 */
2466 function formatValue ($config, $itemValue) {
2467 $format = trim($config['format']);
2468 switch($format) {
2469 case 'date':
2470 if ($itemValue) {
2471 $option = trim($config['format.']['option']);
2472 if ($option) {
2473 if ($config['format.']['strftime']) {
2474 $value = strftime($option,$itemValue);
2475 } else {
2476 $value = date($option,$itemValue);
2477 }
2478 } else {
2479 $value = date('d-m-Y',$itemValue);
2480 }
2481 } else {
2482 $value = '';
2483 }
2484 if ($config['format.']['appendAge']) {
2485 $value .= ' ('.t3lib_BEfunc::calcAge((time()-$itemValue), $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.minutesHoursDaysYears')).')';
2486 }
2487 $itemValue = $value;
2488 break;
2489 case 'datetime': // compatibility with "eval" (type "input")
2490 $itemValue = date('H:i d-m-Y',$itemValue);
2491 break;
2492 case 'time': // compatibility with "eval" (type "input")
2493 $itemValue = date('H:i',$itemValue);
2494 break;
2495 case 'timesec': // compatibility with "eval" (type "input")
2496 $itemValue = date('H:i:s',$itemValue);
2497 break;
2498 case 'year': // compatibility with "eval" (type "input")
2499 $itemValue = date('Y',$itemValue);
2500 break;
2501 case 'int':
2502 $baseArr = array('dec'=>'d','hex'=>'x','HEX'=>'X','oct'=>'o','bin'=>'b');
2503 $base = trim($config['format.']['base']);
2504 $format = $baseArr[$base] ? $baseArr[$base] : 'd';
2505 $itemValue = sprintf('%'.$format,$itemValue);
2506 break;
2507 case 'float':
2508 $precision = t3lib_div::intInRange($config['format.']['precision'],1,10,2);
2509 $itemValue = sprintf('%.'.$precision.'f',$itemValue);
2510 break;
2511 case 'number':
2512 $format = trim($config['format.']['option']);
2513 $itemValue = sprintf('%'.$format,$itemValue);
2514 break;
2515 case 'md5':
2516 $itemValue = md5($itemValue);
2517 break;
2518 case 'filesize':
2519 $value = t3lib_div::formatSize(intval($itemValue));
2520 if ($config['format.']['appendByteSize']) {
2521 $value .= ' ('.$itemValue.')';
2522 }
2523 $itemValue = $value;
2524 break;
2525 case 'user':
2526 $func = trim($config['format.']['userFunc']);
2527 if ($func) {
2528 $params = array(
2529 'value' => $itemValue,
2530 'args' => $config['format.']['userFunc'],
2531 'config' => $config,
2532 'pObj' => &$this
2533 );
2534 $itemValue = t3lib_div::callUserFunction($func,$params,$this);
2535 }
2536 break;
2537 default:
2538 break;
2539 }
2540
2541 return $itemValue;
2542 }
2543
2544
2545
2546
2547
2548
2549 /************************************************************
2550 *
2551 * "Configuration" fetching/processing functions
2552 *
2553 ************************************************************/
2554
2555 /**
2556 * Calculate and return the current "types" pointer value for a record
2557 *
2558 * @param string The table name. MUST be in $TCA
2559 * @param array The row from the table, should contain at least the "type" field, if applicable.
2560 * @return string Return the "type" value for this record, ready to pick a "types" configuration from the $TCA array.
2561 */
2562 function getRTypeNum($table,$row) {
2563 global $TCA;
2564 // If there is a "type" field configured...
2565 if ($TCA[$table]['ctrl']['type']) {
2566 $typeFieldName = $TCA[$table]['ctrl']['type'];
2567 $typeNum=$row[$typeFieldName]; // Get value of the row from the record which contains the type value.
2568 if (!strcmp($typeNum,'')) $typeNum=0; // If that value is an empty string, set it to "0" (zero)
2569 } else {
2570 $typeNum = 0; // If no "type" field, then set to "0" (zero)
2571 }
2572
2573 $typeNum = (string)$typeNum; // Force to string. Necessary for eg '-1' to be recognized as a type value.
2574 if (!$TCA[$table]['types'][$typeNum]) { // However, if the type "0" is not found in the "types" array, then default to "1" (for historical reasons)
2575 $typeNum = 1;
2576 }
2577
2578 return $typeNum;
2579 }
2580
2581 /**
2582 * Used to adhoc-rearrange the field order normally set in the [types][showitem] list
2583 *
2584 * @param array A [types][showitem] list of fields, exploded by ","
2585 * @return array Returns rearranged version (keys are changed around as well.)
2586 * @see getMainFields()
2587 */
2588 function rearrange($fields) {
2589 $fO = array_flip(t3lib_div::trimExplode(',',$this->fieldOrder,1));
2590 reset($fields);
2591 $newFields=array();
2592 while(list($cc,$content)=each($fields)) {
2593 $cP = t3lib_div::trimExplode(';',$content);
2594 if (isset($fO[$cP[0]])) {
2595 $newFields[$fO[$cP[0]]] = $content;
2596 unset($fields[$cc]);
2597 }
2598 }
2599 ksort($newFields);
2600 $fields=array_merge($newFields,$fields); // Candidate for t3lib_div::array_merge() if integer-keys will some day make trouble...
2601 return $fields;
2602 }
2603
2604 /**
2605 * Producing an array of field names NOT to display in the form, based on settings from subtype_value_field, bitmask_excludelist_bits etc.
2606 * Notice, this list is in NO way related to the "excludeField" flag
2607 *
2608 * @param string Table name, MUST be in $TCA
2609 * @param array A record from table.
2610 * @param string A "type" pointer value, probably the one calculated based on the record array.
2611 * @return array Array with fieldnames as values. The fieldnames are those which should NOT be displayed "anyways"
2612 * @see getMainFields()
2613 */
2614 function getExcludeElements($table,$row,$typeNum) {
2615 global $TCA;
2616
2617 // Init:
2618 $excludeElements=array();
2619
2620 // If a subtype field is defined for the type
2621 if ($TCA[$table]['types'][$typeNum]['subtype_value_field']) {
2622 $sTfield = $TCA[$table]['types'][$typeNum]['subtype_value_field'];
2623 if (trim($TCA[$table]['types'][$typeNum]['subtypes_excludelist'][$row[$sTfield]])) {
2624 $excludeElements=t3lib_div::trimExplode(',',$TCA[$table]['types'][$typeNum]['subtypes_excludelist'][$row[$sTfield]],1);
2625 }
2626 }
2627
2628 // If a bitmask-value field has been configured, then find possible fields to exclude based on that:
2629 if ($TCA[$table]['types'][$typeNum]['bitmask_value_field']) {
2630 $sTfield = $TCA[$table]['types'][$typeNum]['bitmask_value_field'];
2631 $sTValue = t3lib_div::intInRange($row[$sTfield],0);
2632 if (is_array($TCA[$table]['types'][$typeNum]['bitmask_excludelist_bits'])) {
2633 reset($TCA[$table]['types'][$typeNum]['bitmask_excludelist_bits']);
2634 while(list($bitKey,$eList)=each($TCA[$table]['types'][$typeNum]['bitmask_excludelist_bits'])) {
2635 $bit=substr($bitKey,1);
2636 if (t3lib_div::testInt($bit)) {
2637 $bit = t3lib_div::intInRange($bit,0,30);
2638 if (
2639 (substr($bitKey,0,1)=='-' && !($sTValue&pow(2,$bit))) ||
2640 (substr($bitKey,0,1)=='+' && ($sTValue&pow(2,$bit)))
2641 ) {
2642 $excludeElements = array_merge($excludeElements,t3lib_div::trimExplode(',',$eList,1));
2643 }
2644 }
2645 }
2646 }
2647 }
2648
2649 // Return the array of elements:
2650 return $excludeElements;
2651 }
2652
2653 /**
2654 * Finds possible field to add to the form, based on subtype fields.
2655 *
2656 * @param string Table name, MUST be in $TCA
2657 * @param array A record from table.
2658 * @param string A "type" pointer value, probably the one calculated based on the record array.
2659 * @return array An array containing two values: 1) Another array containing fieldnames to add and 2) the subtype value field.
2660 * @see getMainFields()
2661 */
2662 function getFieldsToAdd($table,$row,$typeNum) {
2663 global $TCA;
2664
2665 // Init:
2666 $addElements=array();
2667
2668 // If a subtype field is defined for the type
2669 if ($TCA[$table]['types'][$typeNum]['subtype_value_field']) {
2670 $sTfield = $TCA[$table]['types'][$typeNum]['subtype_value_field'];
2671 if (trim($TCA[$table]['types'][$typeNum]['subtypes_addlist'][$row[$sTfield]])) {
2672 $addElements=t3lib_div::trimExplode(',',$TCA[$table]['types'][$typeNum]['subtypes_addlist'][$row[$sTfield]],1);
2673 }
2674 }
2675 // Return the return
2676 return array($addElements,$sTfield);
2677 }
2678
2679 /**
2680 * Merges the current [types][showitem] array with the array of fields to add for the current subtype field of the "type" value.
2681 *
2682 * @param array A [types][showitem] list of fields, exploded by ","
2683 * @param array The output from getFieldsToAdd()
2684 * @return array Return the modified $fields array.
2685 * @see getMainFields(),getFieldsToAdd()
2686 */
2687 function mergeFieldsWithAddedFields($fields,$fieldsToAdd) {
2688 if (count($fieldsToAdd[0])) {
2689 reset($fields);
2690 $c=0;
2691 while(list(,$fieldInfo)=each($fields)) {
2692 $parts = explode(';',$fieldInfo);
2693 if (!strcmp(trim($parts[0]),$fieldsToAdd[1])) {
2694 array_splice(
2695 $fields,
2696 $c+1,
2697 0,
2698 $fieldsToAdd[0]
2699 );
2700 break;
2701 }
2702 $c++;
2703 }
2704 }
2705 return $fields;
2706 }
2707
2708
2709 /**
2710 * Returns TSconfig for table/row
2711 * Multiple requests to this function will return cached content so there is no performance loss in calling this many times since the information is looked up only once.
2712 *
2713 * @param string The table name
2714 * @param array The table row (Should at least contain the "uid" value, even if "NEW..." string. The "pid" field is important as well, and negative values will be intepreted as pointing to a record from the same table.)
2715 * @param string Optionally you can specify the field name as well. In that case the TSconfig for the field is returned.
2716 * @return mixed The TSconfig values (probably in an array)
2717 * @see t3lib_BEfunc::getTCEFORM_TSconfig()
2718 */
2719 function setTSconfig($table,$row,$field='') {
2720 $mainKey = $table.':'.$row['uid'];
2721 if (!isset($this->cachedTSconfig[$mainKey])) {
2722 $this->cachedTSconfig[$mainKey]=t3lib_BEfunc::getTCEFORM_TSconfig($table,$row);
2723 }
2724 if ($field) {
2725 return $this->cachedTSconfig[$mainKey][$field];
2726 } else {
2727 return $this->cachedTSconfig[$mainKey];
2728 }
2729 }
2730
2731 /**
2732 * Returns the "special" configuration (from the "types" "showitem" list) for a fieldname based on input table/record
2733 * (Not used anywhere...?)
2734 *
2735 * @param string The table name
2736 * @param array The table row (Should at least contain the "uid" value, even if "NEW..." string. The "pid" field is important as well, and negative values will be intepreted as pointing to a record from the same table.)
2737 * @param string Specify the field name.
2738 * @return array
2739 * @see getSpecConfFromString(), t3lib_BEfunc::getTCAtypes()
2740 */
2741 function getSpecConfForField($table,$row,$field) {
2742 // Finds the current "types" configuration for the table/row:
2743 $types_fieldConfig = t3lib_BEfunc::getTCAtypes($table,$row);
2744
2745 // If this is an array, then traverse it:
2746 if (is_array($types_fieldConfig)) {
2747 foreach($types_fieldConfig as $vconf) {
2748 // If the input field name matches one found in the 'types' list, then return the 'special' configuration.
2749 if ($vconf['field']==$field) return $vconf[