[BUGFIX] TCEforms draws huge empty icon row which on select-fields
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_tceforms.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2011 Kasper Skårhøj (kasperYYYY@typo3.com)
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
18 *
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27 /**
28 * Contains TYPO3 Core Form generator - AKA "TCEforms"
29 *
30 * Revised for TYPO3 3.6 August/2003 by Kasper Skårhøj
31 * XHTML compliant
32 *
33 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
34 */
35
36
37 /**
38 * 'TCEforms' - Class for creating the backend editing forms.
39 *
40 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
41 * @coauthor René Fritz <r.fritz@colorcube.de>
42 * @package TYPO3
43 * @subpackage t3lib
44 */
45 class t3lib_TCEforms {
46
47 // variables not commented yet.... (do so...)
48 var $palFieldArr = array();
49 var $disableWizards = 0;
50 var $isPalettedoc = 0;
51 var $paletteMargin = 1;
52 var $defStyle = ''; // 'font-family:Verdana;font-size:10px;';
53 var $cachedTSconfig = array();
54 var $cachedTSconfig_fieldLevel = array();
55 var $cachedLanguageFlag = array();
56 var $cachedAdditionalPreviewLanguages = NULL;
57 var $transformedRow = array();
58 var $extJSCODE = '';
59 var $printNeededJS = array();
60 var $hiddenFieldAccum = array();
61 var $TBE_EDITOR_fieldChanged_func = '';
62 var $loadMD5_JS = 1;
63 var $prevBorderStyle = '[nothing here...]'; // Something unique...
64 var $allowUpload = 0; // If set direct upload fields will be shown
65 var $defaultLanguageData = array(); // Array where records in the default language is stored. (processed by transferdata)
66 var $defaultLanguageData_diff = array(); // Array where records in the default language is stored (raw without any processing. used for making diff)
67 var $additionalPreviewLanguageData = array();
68
69
70 // EXTERNAL, static
71 var $backPath = ''; // Set this to the 'backPath' pointing back to the typo3 admin directory from the script where this form is displayed.
72 var $returnUrl = ''; // Alternative return URL path (default is t3lib_div::linkThisScript())
73 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.
74 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.
75 var $disableRTE = 0; // If set, the RTE is disabled (from form display, eg. by checkbox in the bottom of the page!)
76 var $globalShowHelp = 1; // If FALSE, then all CSH will be disabled, regardless of settings in $this->edit_showFieldHelp
77 var $localizationMode = ''; // If TRUE, the forms are rendering only localization relevant fields of the records.
78 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.
79 var $doPrintPalette = 1; // If set to FALSE, palettes will NEVER be rendered.
80
81 /**
82 * Set to initialized clipboard object; Then the element browser will offer a link to paste in records from clipboard.
83 *
84 * @var t3lib_clipboard
85 */
86 var $clipObj = FALSE;
87 var $enableClickMenu = FALSE; // Enable click menu on reference icons.
88 var $enableTabMenu = FALSE; // Enable Tab Menus.
89 var $renderReadonly = FALSE; // When enabled all fields are rendered non-editable.
90
91 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 $GLOBALS['CLIENT']['FORMSTYLE'] value set)
92 var $form_largeComp = 1.33; // Form field width compensation: Compensation for large documents, doc-tab (editing)
93 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.
94 var $maxTextareaWidth = 48; // The maximum abstract value for textareas
95 var $maxInputWidth = 48; // The maximum abstract value for input fields
96 var $defaultMultipleSelectorStyle = 'width:250px;'; // Default style for the selector boxes used for multiple items in "select" and "group" types.
97
98
99 // INTERNAL, static
100 var $prependFormFieldNames = 'data'; // The string to prepend formfield names with.
101 var $prependCmdFieldNames = 'cmd'; // The string to prepend commands for tcemain::process_cmdmap with.
102 var $prependFormFieldNames_file = 'data_files'; // The string to prepend FILE form field names with.
103 var $formName = 'editform'; // The name attribute of the form.
104 var $allowOverrideMatrix = array(); // Whitelist that allows TCA field configuration to be overridden by TSconfig, @see overrideFieldConf()
105
106
107 // INTERNAL, dynamic
108 var $perms_clause = ''; // Set by readPerms() (caching)
109 var $perms_clause_set = 0; // Set by readPerms() (caching-flag)
110 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).
111 var $docLarge = 0; // If set, the forms will be rendered a little wider, more precisely with a factor of $this->form_largeComp.
112 var $clientInfo = array(); // Loaded with info about the browser when class is instantiated.
113 var $RTEenabled = 0; // TRUE, if RTE is possible for the current user (based on result from BE_USER->isRTE())
114 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)
115 var $RTEcounter = 0; // Counter that is incremented before an RTE is created. Can be used for unique ids etc.
116
117 var $colorScheme; // Contains current color scheme
118 var $classScheme; // Contains current class scheme
119 var $defColorScheme; // Contains the default color scheme
120 var $defClassScheme; // Contains the default class scheme
121 var $fieldStyle; // Contains field style values
122 var $borderStyle; // Contains border style values.
123
124 var $commentMessages = array(); // An accumulation of messages from the class.
125
126 // INTERNAL, templates
127 var $totalWrap = '<hr />|<hr />'; // Total wrapping for the table rows.
128 var $fieldTemplate = '<strong>###FIELD_NAME###</strong><br />###FIELD_ITEM###<hr />'; // Field template
129 var $sectionWrap = ''; // Wrapping template code for a section
130 var $palFieldTemplateHeader = ''; // Template for palette headers
131 var $palFieldTemplate = ''; // Template for palettes
132
133 // INTERNAL, working memory
134 var $excludeElements = ''; // Set to the fields NOT to display, if any.
135 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)
136 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!
137 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.
138 var $requiredAdditional = array(); // Used to register input-field names, which are required an have additional requirements (e.g. like a date/time must be positive integer). The information of this array is merged with $this->requiredFields later.
139 var $requiredElements = array(); // Used to register the min and max number of elements for selectorboxes where that apply (in the "group" type for instance)
140 var $requiredNested = array(); // Used to determine where $requiredFields or $requiredElements are nested (in Tabs or IRRE)
141 var $renderDepth = 0; // Keeps track of the rendering depth of nested records.
142 var $savedSchemes = array(); // Color scheme buffer.
143 var $dynNestedStack = array(); // holds the path an element is nested in (e.g. required for RTEhtmlarea)
144
145 // Internal, registers for user defined functions etc.
146 var $additionalCode_pre = array(); // Additional HTML code, printed before the form.
147 var $additionalJS_pre = array(); // Additional JavaScript, printed before the form
148 var $additionalJS_post = array(); // Additional JavaScript printed after the form
149 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.
150 var $additionalJS_delete = array(); // Additional JavaScript executed when section element is deleted. This is neceessary, for example, to correctly clean up HTMLArea RTE (bug #8232)
151
152 /**
153 * Instance of t3lib_tceforms_inline
154 *
155 * @var t3lib_TCEforms_inline
156 */
157 var $inline;
158 var $hookObjectsMainFields = array(); // Array containing hook class instances called once for a form
159 var $hookObjectsSingleField = array(); // Array containing hook class instances called for each field
160 var $extraFormHeaders = array(); // Rows gettings inserted into the alt_doc headers (when called from alt_doc.php)
161
162 public $templateFile = ''; // Form templates, relative to typo3 directory
163
164
165 /**
166 * Constructor function, setting internal variables, loading the styles used.
167 *
168 * @return void
169 */
170 function __construct() {
171 $this->clientInfo = t3lib_div::clientInfo();
172
173 $this->RTEenabled = $GLOBALS['BE_USER']->isRTE();
174 if (!$this->RTEenabled) {
175 $this->RTEenabled_notReasons = implode(LF, $GLOBALS['BE_USER']->RTE_errors);
176 $this->commentMessages[] = 'RTE NOT ENABLED IN SYSTEM due to:' . LF . $this->RTEenabled_notReasons;
177 }
178
179 // Default color+class scheme
180 $this->defColorScheme = array(
181 $GLOBALS['SOBE']->doc->bgColor, // Background for the field AND palette
182 t3lib_div::modifyHTMLColorAll($GLOBALS['SOBE']->doc->bgColor, -20), // Background for the field header
183 t3lib_div::modifyHTMLColorAll($GLOBALS['SOBE']->doc->bgColor, -10), // Background for the palette field header
184 'black', // Field header font color
185 '#666666' // Palette field header font color
186 );
187 $this->defColorScheme = array();
188
189 // Override / Setting defaults from TBE_STYLES array
190 $this->resetSchemes();
191
192 // Setting the current colorScheme to default.
193 $this->defColorScheme = $this->colorScheme;
194 $this->defClassScheme = $this->classScheme;
195
196 // Define whitelist that allows TCA field configuration to be overridden by TSconfig, @see overrideFieldConf():
197 $this->allowOverrideMatrix = array(
198 'input' => array('size', 'max'),
199 'text' => array('cols', 'rows', 'wrap'),
200 'check' => array('cols', 'showIfRTE'),
201 'select' => array('size', 'autoSizeMax', 'maxitems', 'minitems'),
202 'group' => array('size', 'autoSizeMax', 'max_size', 'show_thumbs', 'maxitems', 'minitems', 'disable_controls'),
203 'inline' => array('appearance', 'behaviour', 'foreign_label', 'foreign_selector', 'foreign_unique', 'maxitems', 'minitems', 'size', 'autoSizeMax', 'symmetric_label'),
204 );
205
206 // Create instance of t3lib_TCEforms_inline only if this a non-IRRE-AJAX call:
207 if (!isset($GLOBALS['ajaxID']) || strpos($GLOBALS['ajaxID'], 't3lib_TCEforms_inline::') !== 0) {
208 $this->inline = t3lib_div::makeInstance('t3lib_TCEforms_inline');
209 }
210 // Create instance of t3lib_TCEforms_suggest only if this a non-Suggest-AJAX call:
211 if (!isset($GLOBALS['ajaxID']) || strpos($GLOBALS['ajaxID'], 't3lib_TCEforms_suggest::') !== 0) {
212 $this->suggest = t3lib_div::makeInstance('t3lib_TCEforms_suggest');
213 }
214
215 // Prepare user defined objects (if any) for hooks which extend this function:
216 $this->hookObjectsMainFields = array();
217 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tceforms.php']['getMainFieldsClass'])) {
218 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tceforms.php']['getMainFieldsClass'] as $classRef) {
219 $this->hookObjectsMainFields[] = t3lib_div::getUserObj($classRef);
220 }
221 }
222 $this->hookObjectsSingleField = array();
223 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tceforms.php']['getSingleFieldClass'])) {
224 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tceforms.php']['getSingleFieldClass'] as $classRef) {
225 $this->hookObjectsSingleField[] = t3lib_div::getUserObj($classRef);
226 }
227 }
228
229 $this->templateFile = 'templates/tceforms.html';
230
231 }
232
233 /**
234 * Compatibility constructor.
235 *
236 * @deprecated since TYPO3 4.6 and will be removed in TYPO3 4.8. Use __construct() instead.
237 */
238 public function t3lib_TCEforms() {
239 t3lib_div::logDeprecatedFunction();
240 // Note: we cannot call $this->__construct() here because it would call the derived class constructor and cause recursion
241 // This code uses official PHP behaviour (http://www.php.net/manual/en/language.oop5.basic.php) when $this in the
242 // statically called non-static method inherits $this from the caller's scope.
243 t3lib_TCEforms::__construct();
244 }
245
246 /**
247 * Initialize various internal variables.
248 *
249 * @return void
250 */
251 function initDefaultBEmode() {
252 $this->prependFormFieldNames = 'data';
253 $this->formName = 'editform';
254 $this->setNewBEDesign();
255 $this->docLarge = ($GLOBALS['BE_USER']->uc['edit_wideDocument'] ? 1 : 0);
256 $this->edit_showFieldHelp = $GLOBALS['BE_USER']->uc['edit_showFieldHelp'];
257
258 $this->edit_docModuleUpload = $GLOBALS['BE_USER']->uc['edit_docModuleUpload'];
259
260 $this->inline->init($this);
261 $this->suggest->init($this);
262 }
263
264
265 /*******************************************************
266 *
267 * Rendering the forms, fields etc
268 *
269 *******************************************************/
270
271 /**
272 * Will return the TCEform element for just a single field from a record.
273 * The field must be listed in the currently displayed fields (as found in [types][showitem]) for the record.
274 * This also means that the $table/$row supplied must be complete so the list of fields to show can be found correctly
275 *
276 * @param string The table name
277 * @param array The record from the table for which to render a field.
278 * @param string The field name to return the TCEform element for.
279 * @return string HTML output
280 * @see getMainFields()
281 */
282 function getSoloField($table, $row, $theFieldToReturn) {
283 if ($GLOBALS['TCA'][$table]) {
284 t3lib_div::loadTCA($table);
285 $typeNum = $this->getRTypeNum($table, $row);
286 if ($GLOBALS['TCA'][$table]['types'][$typeNum]) {
287 $itemList = $GLOBALS['TCA'][$table]['types'][$typeNum]['showitem'];
288 if ($itemList) {
289 $fields = t3lib_div::trimExplode(',', $itemList, 1);
290 $excludeElements = $this->excludeElements = $this->getExcludeElements($table, $row, $typeNum);
291
292 foreach ($fields as $fieldInfo) {
293 $parts = explode(';', $fieldInfo);
294
295 $theField = trim($parts[0]);
296 if (!in_array($theField, $excludeElements) && !strcmp($theField, $theFieldToReturn)) {
297 if ($GLOBALS['TCA'][$table]['columns'][$theField]) {
298 $sField = $this->getSingleField($table, $theField, $row, $parts[1], 1, $parts[3], $parts[2]);
299 return $sField['ITEM'];
300 }
301 }
302 }
303 }
304 }
305 }
306 }
307
308 /**
309 * Based on the $table and $row of content, this displays the complete TCEform for the record.
310 * 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.
311 *
312 * @param string The table name
313 * @param array The record from the table for which to render a field.
314 * @param integer Depth level
315 * @return string HTML output
316 * @see getSoloField()
317 */
318 function getMainFields($table, $row, $depth = 0) {
319 $this->renderDepth = $depth;
320
321 // Init vars:
322 $out_array = array(array());
323 $out_array_meta = array(array(
324 'title' => $this->getLL('l_generalTab')
325 ));
326
327 $out_pointer = 0;
328 $out_sheet = 0;
329 $this->palettesRendered = array();
330 $this->palettesRendered[$this->renderDepth][$table] = array();
331
332 // Hook: getMainFields_preProcess (requested by Thomas Hempel for use with the "dynaflex" extension)
333 foreach ($this->hookObjectsMainFields as $hookObj) {
334 if (method_exists($hookObj, 'getMainFields_preProcess')) {
335 $hookObj->getMainFields_preProcess($table, $row, $this);
336 }
337 }
338
339 if ($GLOBALS['TCA'][$table]) {
340
341 // Load the full TCA for the table.
342 t3lib_div::loadTCA($table);
343
344 // Get dividers2tabs setting from TCA of the current table:
345 $dividers2tabs =& $GLOBALS['TCA'][$table]['ctrl']['dividers2tabs'];
346
347 // Load the description content for the table.
348 if ($this->edit_showFieldHelp || $this->doLoadTableDescr($table)) {
349 $GLOBALS['LANG']->loadSingleTableDescription($table);
350 }
351 // Get the current "type" value for the record.
352 $typeNum = $this->getRTypeNum($table, $row);
353
354 // Find the list of fields to display:
355 if ($GLOBALS['TCA'][$table]['types'][$typeNum]) {
356 $itemList = $GLOBALS['TCA'][$table]['types'][$typeNum]['showitem'];
357 if ($itemList) { // If such a list existed...
358 // Explode the field list and possibly rearrange the order of the fields, if configured for
359 $fields = t3lib_div::trimExplode(',', $itemList, 1);
360 if ($this->fieldOrder) {
361 $fields = $this->rearrange($fields);
362 }
363
364 // Get excluded fields, added fiels and put it together:
365 $excludeElements = $this->excludeElements = $this->getExcludeElements($table, $row, $typeNum);
366 $fields = $this->mergeFieldsWithAddedFields($fields, $this->getFieldsToAdd($table, $row, $typeNum));
367
368 // If TCEforms will render a tab menu in the next step, push the name to the tab stack:
369 $tabIdentString = '';
370 $tabIdentStringMD5 = '';
371 if (strstr($itemList, '--div--') !== FALSE && $this->enableTabMenu && $dividers2tabs) {
372 $tabIdentString = 'TCEforms:' . $table . ':' . $row['uid'];
373 $tabIdentStringMD5 = $GLOBALS['TBE_TEMPLATE']->getDynTabMenuId($tabIdentString);
374 // Remember that were currently working on the general tab:
375 if (isset($fields[0]) && strpos($fields[0], '--div--') !== 0) {
376 $this->pushToDynNestedStack('tab', $tabIdentStringMD5 . '-1');
377 }
378 }
379
380 // Traverse the fields to render:
381 $cc = 0;
382 foreach ($fields as $fieldInfo) {
383 // Exploding subparts of the field configuration:
384 $parts = explode(';', $fieldInfo);
385
386 // Getting the style information out:
387 $color_style_parts = t3lib_div::trimExplode('-', $parts[4]);
388 if (strcmp($color_style_parts[0], '')) {
389 $this->setColorScheme($GLOBALS['TBE_STYLES']['colorschemes'][intval($color_style_parts[0])]);
390 }
391 if (strcmp($color_style_parts[1], '')) {
392 $this->fieldStyle = $GLOBALS['TBE_STYLES']['styleschemes'][intval($color_style_parts[1])];
393 if (!isset($this->fieldStyle)) {
394 $this->fieldStyle = $GLOBALS['TBE_STYLES']['styleschemes'][0];
395 }
396 }
397 if (strcmp($color_style_parts[2], '')) {
398 $this->wrapBorder($out_array[$out_sheet], $out_pointer);
399 $this->borderStyle = $GLOBALS['TBE_STYLES']['borderschemes'][intval($color_style_parts[2])];
400 if (!isset($this->borderStyle)) {
401 $this->borderStyle = $GLOBALS['TBE_STYLES']['borderschemes'][0];
402 }
403 }
404
405 // Render the field:
406 $theField = $parts[0];
407 if (!in_array($theField, $excludeElements)) {
408 if ($GLOBALS['TCA'][$table]['columns'][$theField]) {
409 $sFieldPal = '';
410
411 if ($parts[2] && !isset($this->palettesRendered[$this->renderDepth][$table][$parts[2]])) {
412 $sFieldPal = $this->getPaletteFields($table, $row, $parts[2]);
413 $this->palettesRendered[$this->renderDepth][$table][$parts[2]] = 1;
414 }
415 $sField = $this->getSingleField($table, $theField, $row, $parts[1], 0, $parts[3], $parts[2]);
416 if ($sField) {
417 $sField .= $sFieldPal;
418 }
419
420 $out_array[$out_sheet][$out_pointer] .= $sField;
421 } elseif ($theField == '--div--') {
422 if ($cc > 0) {
423 $out_array[$out_sheet][$out_pointer] .= $this->getDivider();
424
425 if ($this->enableTabMenu && $dividers2tabs) {
426 $this->wrapBorder($out_array[$out_sheet], $out_pointer);
427 // Remove last tab entry from the dynNestedStack:
428 $out_sheet++;
429 // Remove the previous sheet from stack (if any):
430 $this->popFromDynNestedStack('tab', $tabIdentStringMD5 . '-' . ($out_sheet));
431 // Remember on which sheet we're currently working:
432 $this->pushToDynNestedStack('tab', $tabIdentStringMD5 . '-' . ($out_sheet + 1));
433 $out_array[$out_sheet] = array();
434 $out_array_meta[$out_sheet]['title'] = $this->sL($parts[1]);
435 // Register newline for Tab
436 $out_array_meta[$out_sheet]['newline'] = ($parts[2] == "newline");
437 }
438 } else { // Setting alternative title for "General" tab if "--div--" is the very first element.
439 $out_array_meta[$out_sheet]['title'] = $this->sL($parts[1]);
440 // Only add the first tab to the dynNestedStack if there are more tabs:
441 if ($tabIdentString && strpos($itemList, '--div--', strlen($fieldInfo))) {
442 $this->pushToDynNestedStack('tab', $tabIdentStringMD5 . '-1');
443 }
444 }
445 } elseif ($theField == '--palette--') {
446 if ($parts[2] && !isset($this->palettesRendered[$this->renderDepth][$table][$parts[2]])) {
447 // render a 'header' if not collapsed
448 if ($GLOBALS['TCA'][$table]['palettes'][$parts[2]]['canNotCollapse'] && $parts[1]) {
449 $out_array[$out_sheet][$out_pointer] .= $this->getPaletteFields($table, $row, $parts[2], $this->sL($parts[1]));
450 } else {
451 $out_array[$out_sheet][$out_pointer] .= $this->getPaletteFields($table, $row, $parts[2], '', '', $this->sL($parts[1]));
452 }
453 $this->palettesRendered[$this->renderDepth][$table][$parts[2]] = 1;
454 }
455 }
456 }
457
458 $cc++;
459 }
460 }
461 }
462 }
463
464 // Hook: getMainFields_postProcess (requested by Thomas Hempel for use with the "dynaflex" extension)
465 foreach ($this->hookObjectsMainFields as $hookObj) {
466 if (method_exists($hookObj, 'getMainFields_postProcess')) {
467 $hookObj->getMainFields_postProcess($table, $row, $this);
468 }
469 }
470
471 // Wrapping a border around it all:
472 $this->wrapBorder($out_array[$out_sheet], $out_pointer);
473
474 // Resetting styles:
475 $this->resetSchemes();
476
477 // Rendering Main palettes, if any
478 $mParr = t3lib_div::trimExplode(',', $GLOBALS['TCA'][$table]['ctrl']['mainpalette']);
479 $i = 0;
480 if (count($mParr)) {
481 foreach ($mParr as $mP) {
482 if (!isset($this->palettesRendered[$this->renderDepth][$table][$mP])) {
483 $temp_palettesCollapsed = $this->palettesCollapsed;
484 $this->palettesCollapsed = 0;
485 $label = ($i == 0 ? $this->getLL('l_generalOptions') : $this->getLL('l_generalOptions_more'));
486 $out_array[$out_sheet][$out_pointer] .= $this->getPaletteFields($table, $row, $mP, $label);
487 $this->palettesCollapsed = $temp_palettesCollapsed;
488 $this->palettesRendered[$this->renderDepth][$table][$mP] = 1;
489 }
490 $this->wrapBorder($out_array[$out_sheet], $out_pointer);
491 $i++;
492 if ($this->renderDepth) {
493 $this->renderDepth--;
494 }
495 }
496 }
497
498 // Return the imploded $out_array:
499 if ($out_sheet > 0) { // There were --div-- dividers around...
500
501 // Create parts array for the tab menu:
502 $parts = array();
503 foreach ($out_array as $idx => $sheetContent) {
504 $content = implode('', $sheetContent);
505 if ($content) {
506 // Wrap content (row) with table-tag, otherwise tab/sheet will be disabled (see getdynTabMenu() )
507 $content = '<table border="0" cellspacing="0" cellpadding="0" width="100%">' . $content . '</table>';
508 }
509 $parts[$idx] = array(
510 'label' => $out_array_meta[$idx]['title'],
511 'content' => $content,
512 'newline' => $out_array_meta[$idx]['newline'], // Newline for this tab/sheet
513 );
514 }
515
516 if (count($parts) > 1) {
517 // Unset the current level of tab menus:
518 $this->popFromDynNestedStack('tab', $tabIdentStringMD5 . '-' . ($out_sheet + 1));
519 $dividersToTabsBehaviour = (isset($GLOBALS['TCA'][$table]['ctrl']['dividers2tabs'])
520 ? $GLOBALS['TCA'][$table]['ctrl']['dividers2tabs']
521 : 1);
522 $output = $this->getDynTabMenu($parts, $tabIdentString, $dividersToTabsBehaviour);
523
524 } else {
525 // If there is only one tab/part there is no need to wrap it into the dynTab code
526 $output = isset($parts[0]) ? trim($parts[0]['content']) : '';
527 }
528
529 $output = '
530 <tr>
531 <td colspan="2">
532 ' . $output . '
533 </td>
534 </tr>';
535
536 } else {
537 // Only one, so just implode:
538 $output = implode('', $out_array[$out_sheet]);
539 }
540
541 return $output;
542 }
543
544 /**
545 * Will return the TCEform elements for a pre-defined list of fields.
546 * 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.
547 * Used for displaying forms for the frontend edit icons for instance.
548 *
549 * @param string The table name
550 * @param array The record array.
551 * @param string Commalist of fields from the table. These will be shown in the specified order in a form.
552 * @return string TCEform elements in a string.
553 */
554 function getListedFields($table, $row, $list) {
555 t3lib_div::loadTCA($table);
556 if ($this->edit_showFieldHelp || $this->doLoadTableDescr($table)) {
557 $GLOBALS['LANG']->loadSingleTableDescription($table);
558 }
559
560 $out = '';
561 $types_fieldConfig = t3lib_BEfunc::getTCAtypes($table, $row, 1);
562
563 $editFieldList = array_unique(t3lib_div::trimExplode(',', $list, 1));
564 foreach ($editFieldList as $theFieldC) {
565 list($theField, $palFields) = preg_split('/\[|\]/', $theFieldC);
566 $theField = trim($theField);
567 $palFields = trim($palFields);
568 if ($GLOBALS['TCA'][$table]['columns'][$theField]) {
569 $parts = t3lib_div::trimExplode(';', $types_fieldConfig[$theField]['origString']);
570 $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.
571 $out .= $sField;
572 } elseif ($theField == '--div--') {
573 $out .= $this->getDivider();
574 }
575 if ($palFields) {
576 $out .= $this->getPaletteFields($table, $row, '', '', implode(',', t3lib_div::trimExplode('|', $palFields, 1)));
577 }
578 }
579
580 return $out;
581 }
582
583 /**
584 * Creates a palette (collection of secondary options).
585 *
586 * @param string The table name
587 * @param array The row array
588 * @param string The palette number/pointer
589 * @param string Header string for the palette (used when in-form). If not set, no header item is made.
590 * @param string Optional alternative list of fields for the palette
591 * @param string Optional Link text for activating a palette (when palettes does not have another form element to belong to).
592 * @return string HTML code.
593 */
594 function getPaletteFields($table, $row, $palette, $header = '', $itemList = '', $collapsedHeader = NULL) {
595 if (!$this->doPrintPalette) {
596 return '';
597 }
598
599 $out = '';
600 $parts = $this->loadPaletteElements($table, $row, $palette, $itemList);
601
602 // Put palette together if there are fields in it:
603 if (count($parts)) {
604
605 $realFields = 0;
606
607 foreach ($parts as $part) {
608 if ($part['NAME'] !== '--linebreak--') {
609 $realFields++;
610 }
611 }
612
613 if ($realFields > 0) {
614
615 if ($header) {
616 $out .= $this->intoTemplate(
617 array('HEADER' => htmlspecialchars($header)),
618 $this->palFieldTemplateHeader
619 );
620 }
621
622 $collapsed = $this->isPalettesCollapsed($table, $palette);
623
624 $thePalIcon = '';
625 if ($collapsed && $collapsedHeader !== NULL) {
626 list($thePalIcon,) = $this->wrapOpenPalette(
627 t3lib_iconWorks::getSpriteIcon(
628 'actions-system-options-view',
629 array('title' => htmlspecialchars($this->getLL('l_moreOptions')))
630 ), $table, $row, $palette, 1);
631 $thePalIcon = '<span style="margin-left: 20px;">' . $thePalIcon . $collapsedHeader . '</span>';
632 }
633
634 $paletteHtml = $this->wrapPaletteField($this->printPalette($parts), $table, $row, $palette, $collapsed);
635
636 $out .= $this->intoTemplate(
637 array('PALETTE' => $thePalIcon . $paletteHtml),
638 $this->palFieldTemplate
639 );
640 }
641 }
642 return $out;
643 }
644
645 /**
646 * Returns the form HTML code for a database table field.
647 *
648 * @param string The table name
649 * @param string The field name
650 * @param array The record to edit from the database table.
651 * @param string Alternative field name label to show.
652 * @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).
653 * @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.
654 * @param integer The palette pointer.
655 * @return mixed String (normal) or array (palettes)
656 */
657 function getSingleField($table, $field, $row, $altName = '', $palette = 0, $extra = '', $pal = 0) {
658
659 // Hook: getSingleField_preProcess
660 foreach ($this->hookObjectsSingleField as $hookObj) {
661 if (method_exists($hookObj, 'getSingleField_preProcess')) {
662 $hookObj->getSingleField_preProcess($table, $field, $row, $altName, $palette, $extra, $pal, $this);
663 }
664 }
665
666 $out = '';
667 $PA = array();
668 $PA['altName'] = $altName;
669 $PA['palette'] = $palette;
670 $PA['extra'] = $extra;
671 $PA['pal'] = $pal;
672
673 // Make sure to load full $GLOBALS['TCA'] array for the table:
674 t3lib_div::loadTCA($table);
675
676 // Get the TCA configuration for the current field:
677 $PA['fieldConf'] = $GLOBALS['TCA'][$table]['columns'][$field];
678 $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
679
680 $skipThisField = $this->inline->skipField($table, $field, $row, $PA['fieldConf']['config']);
681
682 // Now, check if this field is configured and editable (according to excludefields + other configuration)
683 if (is_array($PA['fieldConf']) &&
684 !$skipThisField &&
685 (!$PA['fieldConf']['exclude'] || $GLOBALS['BE_USER']->check('non_exclude_fields', $table . ':' . $field)) &&
686 $PA['fieldConf']['config']['form_type'] != 'passthrough' &&
687 ($this->RTEenabled || !$PA['fieldConf']['config']['showIfRTE']) &&
688 (!$PA['fieldConf']['displayCond'] || $this->isDisplayCondition($PA['fieldConf']['displayCond'], $row)) &&
689 (!$GLOBALS['TCA'][$table]['ctrl']['languageField'] || $PA['fieldConf']['l10n_display'] || strcmp($PA['fieldConf']['l10n_mode'], 'exclude') || $row[$GLOBALS['TCA'][$table]['ctrl']['languageField']] <= 0) &&
690 (!$GLOBALS['TCA'][$table]['ctrl']['languageField'] || !$this->localizationMode || $this->localizationMode === $PA['fieldConf']['l10n_cat'])
691 ) {
692
693
694 // Fetching the TSconfig for the current table/field. This includes the $row which means that
695 $PA['fieldTSConfig'] = $this->setTSconfig($table, $row, $field);
696
697 // If the field is NOT disabled from TSconfig (which it could have been) then render it
698 if (!$PA['fieldTSConfig']['disabled']) {
699 // Override fieldConf by fieldTSconfig:
700 $PA['fieldConf']['config'] = $this->overrideFieldConf($PA['fieldConf']['config'], $PA['fieldTSConfig']);
701
702 // Init variables:
703 $PA['itemFormElName'] = $this->prependFormFieldNames . '[' . $table . '][' . $row['uid'] . '][' . $field . ']'; // Form field name
704 $PA['itemFormElName_file'] = $this->prependFormFieldNames_file . '[' . $table . '][' . $row['uid'] . '][' . $field . ']'; // Form field name, in case of file uploads
705 $PA['itemFormElValue'] = $row[$field]; // The value to show in the form field.
706 $PA['itemFormElID'] = $this->prependFormFieldNames . '_' . $table . '_' . $row['uid'] . '_' . $field;
707
708 // set field to read-only if configured for translated records to show default language content as readonly
709 if ($PA['fieldConf']['l10n_display']
710 && t3lib_div::inList($PA['fieldConf']['l10n_display'], 'defaultAsReadonly')
711 && $row[$GLOBALS['TCA'][$table]['ctrl']['languageField']] > 0) {
712 $PA['fieldConf']['config']['readOnly'] = TRUE;
713 $PA['itemFormElValue'] = $this->defaultLanguageData[$table . ':' . $row['uid']][$field];
714 }
715
716 // 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"
717 if (
718 ($GLOBALS['TCA'][$table]['ctrl']['type'] && !strcmp($field, $GLOBALS['TCA'][$table]['ctrl']['type']))
719 || ($GLOBALS['TCA'][$table]['ctrl']['requestUpdate']
720 && t3lib_div::inList($GLOBALS['TCA'][$table]['ctrl']['requestUpdate'], $field))) {
721 if ($GLOBALS['BE_USER']->jsConfirmation(1)) {
722 $alertMsgOnChange = 'if (confirm(TBE_EDITOR.labels.onChangeAlert) && TBE_EDITOR.checkSubmit(-1)){ TBE_EDITOR.submitForm() };';
723 } else {
724 $alertMsgOnChange = 'if (TBE_EDITOR.checkSubmit(-1)){ TBE_EDITOR.submitForm() };';
725 }
726 } else {
727 $alertMsgOnChange = '';
728 }
729
730 // Render as a hidden field?
731 if (in_array($field, $this->hiddenFieldListArr)) {
732 $this->hiddenFieldAccum[] = '<input type="hidden" name="' . $PA['itemFormElName'] . '" value="' . htmlspecialchars($PA['itemFormElValue']) . '" />';
733 } else { // Render as a normal field:
734
735 // 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.
736 if (!$PA['palette']) {
737 $paletteFields = $this->loadPaletteElements($table, $row, $PA['pal']);
738 if ($PA['pal'] && $this->isPalettesCollapsed($table, $PA['pal']) && count($paletteFields)) {
739 list($thePalIcon, $palJSfunc) = $this->wrapOpenPalette(t3lib_iconWorks::getSpriteIcon('actions-system-options-view', array('title' => htmlspecialchars($this->getLL('l_moreOptions')))), $table, $row, $PA['pal'], 1);
740 } else {
741 $thePalIcon = '';
742 $palJSfunc = '';
743 }
744 }
745 // onFocus attribute to add to the field:
746 $PA['onFocus'] = (($palJSfunc && !$GLOBALS['BE_USER']->uc['dontShowPalettesOnFocusInAB'])
747 ? ' onfocus="' . htmlspecialchars($palJSfunc) . '"'
748 : '');
749
750 // Find item
751 $item = '';
752 $PA['label'] = ($PA['altName'] ? $PA['altName'] : $PA['fieldConf']['label']);
753 $PA['label'] = ($PA['fieldTSConfig']['label'] ? $PA['fieldTSConfig']['label'] : $PA['label']);
754 $PA['label'] = ($PA['fieldTSConfig']['label.'][$GLOBALS['LANG']->lang] ? $PA['fieldTSConfig']['label.'][$GLOBALS['LANG']->lang] : $PA['label']);
755 $PA['label'] = $this->sL($PA['label']);
756 // JavaScript code for event handlers:
757 $PA['fieldChangeFunc'] = array();
758 $PA['fieldChangeFunc']['TBE_EDITOR_fieldChanged'] = "TBE_EDITOR.fieldChanged('" . $table . "','" . $row['uid'] . "','" . $field . "','" . $PA['itemFormElName'] . "');";
759 $PA['fieldChangeFunc']['alert'] = $alertMsgOnChange;
760 // if this is the child of an inline type and it is the field creating the label
761 if ($this->inline->isInlineChildAndLabelField($table, $field)) {
762 $inlineObjectId = implode(
763 t3lib_TCEforms_inline::Structure_Separator,
764 array(
765 $this->inline->inlineNames['object'],
766 $table,
767 $row['uid']
768 )
769 );
770 $PA['fieldChangeFunc']['inline'] = "inline.handleChangedField('" . $PA['itemFormElName'] . "','" . $inlineObjectId . "');";
771 }
772
773 // Based on the type of the item, call a render function:
774 $item = $this->getSingleField_SW($table, $field, $row, $PA);
775
776 // Add language + diff
777 if ($PA['fieldConf']['l10n_display'] && (t3lib_div::inList($PA['fieldConf']['l10n_display'], 'hideDiff') || t3lib_div::inList($PA['fieldConf']['l10n_display'], 'defaultAsReadonly'))) {
778 $renderLanguageDiff = FALSE;
779 } else {
780 $renderLanguageDiff = TRUE;
781 }
782
783 if ($renderLanguageDiff) {
784 $item = $this->renderDefaultLanguageContent($table, $field, $row, $item);
785 $item = $this->renderDefaultLanguageDiff($table, $field, $row, $item);
786 }
787
788 // 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
789 $label = t3lib_div::deHSCentities(htmlspecialchars($PA['label']));
790 if (t3lib_utility_Math::canBeInterpretedAsInteger($row['uid']) && $PA['fieldTSConfig']['linkTitleToSelf'] && !t3lib_div::_GP('columnsOnly')) {
791 $lTTS_url = $this->backPath . 'alt_doc.php?edit[' . $table . '][' . $row['uid'] . ']=edit&columnsOnly=' . $field . '&returnUrl=' . rawurlencode($this->thisReturnUrl());
792 $label = '<a href="' . htmlspecialchars($lTTS_url) . '">' . $label . '</a>';
793 }
794
795 // wrap the label with help text
796 $PA['label'] = $label = t3lib_BEfunc::wrapInHelp($table, $field, $label);
797
798 // Create output value:
799 if ($PA['fieldConf']['config']['form_type'] == 'user' && $PA['fieldConf']['config']['noTableWrapping']) {
800 $out = $item;
801 } elseif ($PA['palette']) {
802 // Array:
803 $out = array(
804 'NAME' => $label,
805 'ID' => $row['uid'],
806 'FIELD' => $field,
807 'TABLE' => $table,
808 'ITEM' => $item
809 );
810 $out = $this->addUserTemplateMarkers($out, $table, $field, $row, $PA);
811 } else {
812 // String:
813 $out = array(
814 'NAME' => $label,
815 'ITEM' => $item,
816 'TABLE' => $table,
817 'ID' => $row['uid'],
818 'PAL_LINK_ICON' => $thePalIcon,
819 'FIELD' => $field
820 );
821 $out = $this->addUserTemplateMarkers($out, $table, $field, $row, $PA);
822 // String:
823 $out = $this->intoTemplate($out);
824 }
825 }
826 } else {
827 $this->commentMessages[] = $this->prependFormFieldNames . '[' . $table . '][' . $row['uid'] . '][' . $field . ']: Disabled by TSconfig';
828 }
829 }
830 // Hook: getSingleField_postProcess
831 foreach ($this->hookObjectsSingleField as $hookObj) {
832 if (method_exists($hookObj, 'getSingleField_postProcess')) {
833 $hookObj->getSingleField_postProcess($table, $field, $row, $out, $PA, $this);
834 }
835 }
836 // Return value (string or array)
837 return $out;
838 }
839
840 /**
841 * Rendering a single item for the form
842 *
843 * @param string Table name of record
844 * @param string Fieldname to render
845 * @param array The record
846 * @param array parameters array containing a lot of stuff. Value by Reference!
847 * @return string Returns the item as HTML code to insert
848 * @access private
849 * @see getSingleField(), getSingleField_typeFlex_draw()
850 */
851 function getSingleField_SW($table, $field, $row, &$PA) {
852 $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
853
854 // Hook: getSingleField_beforeRender
855 foreach ($this->hookObjectsSingleField as $hookObject) {
856 if (method_exists($hookObject, 'getSingleField_beforeRender')) {
857 $hookObject->getSingleField_beforeRender($table, $field, $row, $PA);
858 }
859 }
860
861 switch ($PA['fieldConf']['config']['form_type']) {
862 case 'input':
863 $item = $this->getSingleField_typeInput($table, $field, $row, $PA);
864 break;
865 case 'text':
866 $item = $this->getSingleField_typeText($table, $field, $row, $PA);
867 break;
868 case 'check':
869 $item = $this->getSingleField_typeCheck($table, $field, $row, $PA);
870 break;
871 case 'radio':
872 $item = $this->getSingleField_typeRadio($table, $field, $row, $PA);
873 break;
874 case 'select':
875 $item = $this->getSingleField_typeSelect($table, $field, $row, $PA);
876 break;
877 case 'group':
878 $item = $this->getSingleField_typeGroup($table, $field, $row, $PA);
879 break;
880 case 'inline':
881 $item = $this->inline->getSingleField_typeInline($table, $field, $row, $PA);
882 break;
883 case 'none':
884 $item = $this->getSingleField_typeNone($table, $field, $row, $PA);
885 break;
886 case 'user':
887 $item = $this->getSingleField_typeUser($table, $field, $row, $PA);
888 break;
889 case 'flex':
890 $item = $this->getSingleField_typeFlex($table, $field, $row, $PA);
891 break;
892 default:
893 $item = $this->getSingleField_typeUnknown($table, $field, $row, $PA);
894 break;
895 }
896
897 return $item;
898 }
899
900
901 /**********************************************************
902 *
903 * Rendering of each TCEform field type
904 *
905 ************************************************************/
906
907 /**
908 * Generation of TCEform elements of the type "input"
909 * This will render a single-line input form field, possibly with various control/validation features
910 *
911 * @param string The table name of the record
912 * @param string The field name which this element is supposed to edit
913 * @param array The record data array where the value(s) for the field can be found
914 * @param array An array with additional configuration options.
915 * @return string The HTML code for the TCEform field
916 */
917 function getSingleField_typeInput($table, $field, $row, &$PA) {
918 $config = $PA['fieldConf']['config'];
919
920 $specConf = $this->getSpecConfFromString($PA['extra'], $PA['fieldConf']['defaultExtras']);
921 $size = t3lib_utility_Math::forceIntegerInRange($config['size'] ? $config['size'] : 30, 5, $this->maxInputWidth);
922 $evalList = t3lib_div::trimExplode(',', $config['eval'], 1);
923 $classAndStyleAttributes = $this->formWidthAsArray($size);
924
925 $fieldAppendix = '';
926 $item = '';
927 $cssClasses = array($classAndStyleAttributes['class']);
928 $cssStyle = $classAndStyleAttributes['style'];
929
930 if (!isset($config['checkbox'])) {
931 $config['checkbox'] = '0';
932 $checkboxIsset = FALSE;
933 } else {
934 $checkboxIsset = TRUE;
935 }
936
937 if (in_array('date', $evalList) || in_array('datetime', $evalList)) {
938 if (in_array('datetime', $evalList)) {
939 $class = 'datetime';
940 } else {
941 $class = 'date';
942 }
943 $dateRange = '';
944 if (isset($config['range']['lower'])) {
945 $dateRange .= ' lower-' . intval($config['range']['lower']);
946 }
947 if (isset($config['range']['upper'])) {
948 $dateRange .= ' upper-' . intval($config['range']['upper']);
949 }
950 $inputId = uniqid('tceforms-' . $class . 'field-');
951 $cssClasses[] = 'tceforms-textfield tceforms-' . $class . 'field' . $dateRange;
952 $fieldAppendix = t3lib_iconWorks::getSpriteIcon(
953 'actions-edit-pick-date',
954 array(
955 'style' => 'cursor:pointer;',
956 'id' => 'picker-' . $inputId
957 )
958 );
959 } elseif (in_array('timesec', $evalList)) {
960 $inputId = uniqid('tceforms-timesecfield-');
961 $cssClasses[] = 'tceforms-textfield tceforms-timesecfield';
962 } elseif (in_array('year', $evalList)) {
963 $inputId = uniqid('tceforms-yearfield-');
964 $cssClasses[] = 'tceforms-textfield tceforms-yearfield';
965 } elseif (in_array('time', $evalList)) {
966 $inputId = uniqid('tceforms-timefield-');
967 $cssClasses[] = 'tceforms-textfield tceforms-timefield';
968 } elseif (in_array('int', $evalList)) {
969 $inputId = uniqid('tceforms-intfield-');
970 $cssClasses[] = 'tceforms-textfield tceforms-intfield';
971 } elseif (in_array('double2', $evalList)) {
972 $inputId = uniqid('tceforms-double2field-');
973 $cssClasses[] = 'tceforms-textfield tceforms-double2field';
974 } else {
975 $inputId = uniqid('tceforms-textfield-');
976 $cssClasses[] = 'tceforms-textfield';
977 if ($checkboxIsset === FALSE) {
978 $config['checkbox'] = '';
979 }
980 }
981 if (isset($config['wizards']['link'])) {
982 $inputId = uniqid('tceforms-linkfield-');
983 $cssClasses[] = 'tceforms-textfield tceforms-linkfield';
984
985 } elseif (isset($config['wizards']['color'])) {
986 $inputId = uniqid('tceforms-colorfield-');
987 $cssClasses[] = 'tceforms-textfield tceforms-colorfield';
988 }
989
990 if ($this->renderReadonly || $config['readOnly']) {
991 $itemFormElValue = $PA['itemFormElValue'];
992 if (in_array('date', $evalList)) {
993 $config['format'] = 'date';
994 } elseif (in_array('datetime', $evalList)) {
995 $config['format'] = 'datetime';
996 } elseif (in_array('time', $evalList)) {
997 $config['format'] = 'time';
998 }
999 if (in_array('password', $evalList)) {
1000 $itemFormElValue = $itemFormElValue ? '*********' : '';
1001 }
1002 return $this->getSingleField_typeNone_render($config, $itemFormElValue);
1003 }
1004
1005 foreach ($evalList as $func) {
1006 switch ($func) {
1007 case 'required':
1008 $this->registerRequiredProperty('field', $table . '_' . $row['uid'] . '_' . $field, $PA['itemFormElName']);
1009 // Mark this field for date/time disposal:
1010 if (array_intersect($evalList, array('date', 'datetime', 'time'))) {
1011 $this->requiredAdditional[$PA['itemFormElName']]['isPositiveNumber'] = TRUE;
1012 }
1013 break;
1014 default:
1015 if (t3lib_div::hasValidClassPrefix($func)) {
1016 // Pair hook to the one in t3lib_TCEmain::checkValue_input_Eval()
1017 $evalObj = t3lib_div::getUserObj($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tce']['formevals'][$func] . ':&' . $func);
1018 if (is_object($evalObj) && method_exists($evalObj, 'deevaluateFieldValue')) {
1019 $_params = array(
1020 'value' => $PA['itemFormElValue']
1021 );
1022 $PA['itemFormElValue'] = $evalObj->deevaluateFieldValue($_params);
1023 }
1024 }
1025 break;
1026 }
1027 }
1028
1029 $paramsList = "'" . $PA['itemFormElName'] . "','" . implode(',', $evalList) . "','" . trim($config['is_in']) . "'," . (isset($config['checkbox']) ? 1 : 0) . ",'" . $config['checkbox'] . "'";
1030 if ((in_array('date', $evalList) || in_array('datetime', $evalList))) {
1031 $item .= '<span class="t3-tceforms-input-wrapper-datetime" onmouseOver="if (document.getElementById(\'' .
1032 $inputId . '\').value) {this.className=\'t3-tceforms-input-wrapper-datetime-hover\';} else {this.className=\'t3-tceforms-input-wrapper-datetime\';};" onmouseOut="this.className=\'t3-tceforms-input-wrapper-datetime\';">';
1033
1034 // Add server timezone offset to UTC to our stored date
1035 if ($PA['itemFormElValue'] > 0) {
1036 $PA['itemFormElValue'] += date('Z', $PA['itemFormElValue']);
1037 }
1038 } else {
1039 $item .= '<span class="t3-tceforms-input-wrapper" onmouseOver="if (document.getElementById(\'' . $inputId .
1040 '\').value) {this.className=\'t3-tceforms-input-wrapper-hover\';} else {this.className=\'t3-tceforms-input-wrapper\';};" onmouseOut="this.className=\'t3-tceforms-input-wrapper\';">';
1041 }
1042
1043 $PA['fieldChangeFunc'] = array_merge(
1044 array('typo3form.fieldGet' => 'typo3form.fieldGet(' . $paramsList . ');'),
1045 $PA['fieldChangeFunc']
1046 );
1047 // old function "checkbox" now the option to set the date / remove the date
1048 if (isset($config['checkbox'])) {
1049 $item .= t3lib_iconWorks::getSpriteIcon('actions-input-clear', array('tag' => 'a', 'class' => 't3-tceforms-input-clearer', 'onclick' => 'document.getElementById(\'' . $inputId . '\').value=\'\';document.getElementById(\'' . $inputId . '\').focus();' . implode('', $PA['fieldChangeFunc'])));
1050 }
1051 $mLgd = ($config['max'] ? $config['max'] : 256);
1052 $iOnChange = implode('', $PA['fieldChangeFunc']);
1053
1054 $item .= '<input type="text" id="' . $inputId .
1055 '" class="' . implode(' ', $cssClasses) . '" name="' . $PA['itemFormElName'] .
1056 '_hr" value="" style="' . $cssStyle . '" maxlength="' . $mLgd . '" onchange="' .
1057 htmlspecialchars($iOnChange) . '"' . $PA['onFocus'] . ' />'; // This is the EDITABLE form field.
1058 $item .= '<input type="hidden" name="' . $PA['itemFormElName'] . '" value="' .
1059 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.
1060 $item .= $fieldAppendix . '</span><div style="clear:both;"></div>';
1061 $this->extJSCODE .= 'typo3form.fieldSet(' . $paramsList . ');';
1062
1063 // going through all custom evaluations configured for this field
1064 foreach ($evalList as $evalData) {
1065 if (t3lib_div::hasValidClassPrefix($evalData)) {
1066 $evalObj = t3lib_div::getUserObj($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tce']['formevals'][$evalData] . ':&' . $evalData);
1067 if (is_object($evalObj) && method_exists($evalObj, 'returnFieldJS')) {
1068 $this->extJSCODE .= "\n\nfunction " . $evalData . "(value) {\n" . $evalObj->returnFieldJS() . "\n}\n";
1069 }
1070 }
1071 }
1072
1073 // Creating an alternative item without the JavaScript handlers.
1074 $altItem = '<input type="hidden" name="' . $PA['itemFormElName'] . '_hr" value="" />';
1075 $altItem .= '<input type="hidden" name="' . $PA['itemFormElName'] . '" value="' . htmlspecialchars($PA['itemFormElValue']) . '" />';
1076
1077 // Wrap a wizard around the item?
1078 $item = $this->renderWizards(array($item, $altItem), $config['wizards'], $table, $row, $field, $PA, $PA['itemFormElName'] . '_hr', $specConf);
1079
1080 return $item;
1081 }
1082
1083 /**
1084 * Generation of TCEform elements of the type "text"
1085 * This will render a <textarea> OR RTE area form field, possibly with various control/validation features
1086 *
1087 * @param string The table name of the record
1088 * @param string The field name which this element is supposed to edit
1089 * @param array The record data array where the value(s) for the field can be found
1090 * @param array An array with additional configuration options.
1091 * @return string The HTML code for the TCEform field
1092 */
1093 function getSingleField_typeText($table, $field, $row, &$PA) {
1094
1095 // Init config:
1096 $config = $PA['fieldConf']['config'];
1097 $evalList = t3lib_div::trimExplode(',', $config['eval'], 1);
1098
1099 if ($this->renderReadonly || $config['readOnly']) {
1100 return $this->getSingleField_typeNone_render($config, $PA['itemFormElValue']);
1101 }
1102
1103 // Setting columns number:
1104 $cols = t3lib_utility_Math::forceIntegerInRange($config['cols'] ? $config['cols'] : 30, 5, $this->maxTextareaWidth);
1105
1106 // Setting number of rows:
1107 $origRows = $rows = t3lib_utility_Math::forceIntegerInRange($config['rows'] ? $config['rows'] : 5, 1, 20);
1108 if (strlen($PA['itemFormElValue']) > $this->charsPerRow * 2) {
1109 $cols = $this->maxTextareaWidth;
1110 $rows = t3lib_utility_Math::forceIntegerInRange(round(strlen($PA['itemFormElValue']) / $this->charsPerRow), count(explode(LF, $PA['itemFormElValue'])), 20);
1111 if ($rows < $origRows) {
1112 $rows = $origRows;
1113 }
1114 }
1115
1116 if (in_array('required', $evalList)) {
1117 $this->requiredFields[$table . '_' . $row['uid'] . '_' . $field] = $PA['itemFormElName'];
1118 }
1119
1120 // Init RTE vars:
1121 $RTEwasLoaded = 0; // Set TRUE, if the RTE is loaded; If not a normal textarea is shown.
1122 $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...
1123
1124 // "Extra" configuration; Returns configuration for the field based on settings found in the "types" fieldlist. Traditionally, this is where RTE configuration has been found.
1125 $specConf = $this->getSpecConfFromString($PA['extra'], $PA['fieldConf']['defaultExtras']);
1126
1127 // Setting up the altItem form field, which is a hidden field containing the value
1128 $altItem = '<input type="hidden" name="' . htmlspecialchars($PA['itemFormElName']) . '" value="' . htmlspecialchars($PA['itemFormElValue']) . '" />';
1129
1130 // If RTE is generally enabled (TYPO3_CONF_VARS and user settings)
1131 if ($this->RTEenabled) {
1132 $p = t3lib_BEfunc::getSpecConfParametersFromArray($specConf['rte_transform']['parameters']);
1133 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.
1134 t3lib_BEfunc::fixVersioningPid($table, $row);
1135 list($tscPID, $thePidValue) = $this->getTSCpid($table, $row['uid'], $row['pid']);
1136
1137 // If the pid-value is not negative (that is, a pid could NOT be fetched)
1138 if ($thePidValue >= 0) {
1139 $RTEsetup = $GLOBALS['BE_USER']->getTSConfig('RTE', t3lib_BEfunc::getPagesTSconfig($tscPID));
1140 $RTEtypeVal = t3lib_BEfunc::getTCAtypeValue($table, $row);
1141 $thisConfig = t3lib_BEfunc::RTEsetup($RTEsetup['properties'], $table, $field, $RTEtypeVal);
1142
1143 if (!$thisConfig['disabled']) {
1144 if (!$this->disableRTE) {
1145 $this->RTEcounter++;
1146
1147 // Find alternative relative path for RTE images/links:
1148 $eFile = t3lib_parsehtml_proc::evalWriteFile($specConf['static_write'], $row);
1149 $RTErelPath = is_array($eFile) ? dirname($eFile['relEditFile']) : '';
1150
1151 // Get RTE object, draw form and set flag:
1152 $RTEobj = t3lib_BEfunc::RTEgetObj();
1153 $item = $RTEobj->drawRTE($this, $table, $field, $row, $PA, $specConf, $thisConfig, $RTEtypeVal, $RTErelPath, $thePidValue);
1154
1155 // Wizard:
1156 $item = $this->renderWizards(array($item, $altItem), $config['wizards'], $table, $row, $field, $PA, $PA['itemFormElName'], $specConf, 1);
1157
1158 $RTEwasLoaded = 1;
1159 } else {
1160 $RTEwouldHaveBeenLoaded = 1;
1161 $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!)';
1162 }
1163 } else {
1164 $this->commentMessages[] = $PA['itemFormElName'] . ': RTE is disabled by the Page TSconfig, "RTE"-key (eg. by RTE.default.disabled=0 or such)';
1165 }
1166 } else {
1167 $this->commentMessages[] = $PA['itemFormElName'] . ': PID value could NOT be fetched. Rare error, normally with new records.';
1168 }
1169 } else {
1170 if (!isset($specConf['richtext'])) {
1171 $this->commentMessages[] = $PA['itemFormElName'] . ': RTE was not configured for this field in TCA-types';
1172 }
1173 if (!(!$p['flag'] || !$row[$p['flag']])) {
1174 $this->commentMessages[] = $PA['itemFormElName'] . ': Field-flag (' . $PA['flag'] . ') has been set to disable RTE!';
1175 }
1176 }
1177 }
1178
1179 // Display ordinary field if RTE was not loaded.
1180 if (!$RTEwasLoaded) {
1181 if ($specConf['rte_only']) { // Show message, if no RTE (field can only be edited with RTE!)
1182 $item = '<p><em>' . htmlspecialchars($this->getLL('l_noRTEfound')) . '</em></p>';
1183 } else {
1184 if ($specConf['nowrap']) {
1185 $wrap = 'off';
1186 } else {
1187 $wrap = ($config['wrap'] ? $config['wrap'] : 'virtual');
1188 }
1189
1190 $classes = array();
1191 if ($specConf['fixed-font']) {
1192 $classes[] = 'fixed-font';
1193 }
1194 if ($specConf['enable-tab']) {
1195 $classes[] = 'enable-tab';
1196 }
1197
1198 $formWidthText = $this->formWidthText($cols, $wrap);
1199
1200 // Extract class attributes from $formWidthText (otherwise it would be added twice to the output)
1201 $res = array();
1202 if (preg_match('/ class="(.+?)"/', $formWidthText, $res)) {
1203 $formWidthText = str_replace(' class="' . $res[1] . '"', '', $formWidthText);
1204 $classes = array_merge($classes, explode(' ', $res[1]));
1205 }
1206
1207 if (count($classes)) {
1208 $class = ' class="tceforms-textarea ' . implode(' ', $classes) . '"';
1209 } else {
1210 $class = 'tceforms-textarea';
1211 }
1212
1213 $evalList = t3lib_div::trimExplode(',', $config['eval'], 1);
1214 foreach ($evalList as $func) {
1215 switch ($func) {
1216 case 'required':
1217 $this->registerRequiredProperty('field', $table . '_' . $row['uid'] . '_' . $field, $PA['itemFormElName']);
1218 break;
1219 default:
1220 if (t3lib_div::hasValidClassPrefix($func)) {
1221 // Pair hook to the one in t3lib_TCEmain::checkValue_input_Eval() and t3lib_TCEmain::checkValue_text_Eval()
1222 $evalObj = t3lib_div::getUserObj($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tce']['formevals'][$func] . ':&' . $func);
1223 if (is_object($evalObj) && method_exists($evalObj, 'deevaluateFieldValue')) {
1224 $_params = array(
1225 'value' => $PA['itemFormElValue']
1226 );
1227 $PA['itemFormElValue'] = $evalObj->deevaluateFieldValue($_params);
1228 }
1229 }
1230 break;
1231 }
1232 }
1233
1234 $iOnChange = implode('', $PA['fieldChangeFunc']);
1235 $item .= '
1236 <textarea id="' . uniqid('tceforms-textarea-') . '" name="' . $PA['itemFormElName'] . '"' . $formWidthText . $class . ' rows="' . $rows . '" wrap="' . $wrap . '" onchange="' . htmlspecialchars($iOnChange) . '"' . $PA['onFocus'] . '>' .
1237 t3lib_div::formatForTextarea($PA['itemFormElValue']) .
1238 '</textarea>';
1239 $item = $this->renderWizards(array($item, $altItem), $config['wizards'], $table, $row, $field, $PA, $PA['itemFormElName'], $specConf, $RTEwouldHaveBeenLoaded);
1240 }
1241 }
1242
1243 // Return field HTML:
1244 return $item;
1245 }
1246
1247 /**
1248 * Generation of TCEform elements of the type "check"
1249 * This will render a check-box OR an array of checkboxes
1250 *
1251 * @param string The table name of the record
1252 * @param string The field name which this element is supposed to edit
1253 * @param array The record data array where the value(s) for the field can be found
1254 * @param array An array with additional configuration options.
1255 * @return string The HTML code for the TCEform field
1256 */
1257 function getSingleField_typeCheck($table, $field, $row, &$PA) {
1258 $config = $PA['fieldConf']['config'];
1259
1260 $item = '';
1261 $disabled = '';
1262 if ($this->renderReadonly || $config['readOnly']) {
1263 $disabled = ' disabled="disabled"';
1264 }
1265
1266 // Traversing the array of items:
1267 $selItems = $this->initItemArray($PA['fieldConf']);
1268 if ($config['itemsProcFunc']) {
1269 $selItems = $this->procItems($selItems, $PA['fieldTSConfig']['itemsProcFunc.'], $config, $table, $row, $field);
1270 }
1271
1272 if (!count($selItems)) {
1273 $selItems[] = array('', '');
1274 }
1275 $thisValue = intval($PA['itemFormElValue']);
1276
1277 $cols = intval($config['cols']);
1278 if ($cols > 1) {
1279 $item .= '<table border="0" cellspacing="0" cellpadding="0" class="typo3-TCEforms-checkboxArray">';
1280 for ($c = 0; $c < count($selItems); $c++) {
1281 $p = $selItems[$c];
1282 if (!($c % $cols)) {
1283 $item .= '<tr>';
1284 }
1285 $cBP = $this->checkBoxParams($PA['itemFormElName'], $thisValue, $c, count($selItems), implode('', $PA['fieldChangeFunc']));
1286 $cBName = $PA['itemFormElName'] . '_' . $c;
1287 $cBID = $PA['itemFormElID'] . '_' . $c;
1288 $item .= '<td nowrap="nowrap">' .
1289 '<input type="checkbox"' . $this->insertDefStyle('check') . ' value="1" name="' . $cBName . '"' . $cBP . $disabled . ' id="' . $cBID . '" />' .
1290 $this->wrapLabels('<label for="' . $cBID . '">' . htmlspecialchars($p[0]) . '</label>&nbsp;') .
1291 '</td>';
1292 if (($c % $cols) + 1 == $cols) {
1293 $item .= '</tr>';
1294 }
1295 }
1296 if ($c % $cols) {
1297 $rest = $cols - ($c % $cols);
1298 for ($c = 0; $c < $rest; $c++) {
1299 $item .= '<td></td>';
1300 }
1301 if ($c > 0) {
1302 $item .= '</tr>';
1303 }
1304 }
1305 $item .= '</table>';
1306 } else {
1307 for ($c = 0; $c < count($selItems); $c++) {
1308 $p = $selItems[$c];
1309 $cBP = $this->checkBoxParams($PA['itemFormElName'], $thisValue, $c, count($selItems), implode('', $PA['fieldChangeFunc']));
1310 $cBName = $PA['itemFormElName'] . '_' . $c;
1311 $cBID = $PA['itemFormElID'] . '_' . $c;
1312 $item .= ($c > 0 ? '<br />' : '') .
1313 '<input type="checkbox"' . $this->insertDefStyle('check') . ' value="1" name="' . $cBName . '"' . $cBP . $PA['onFocus'] . $disabled . ' id="' . $cBID . '" />' .
1314 $this->wrapLabels('<label for="' . $cBID . '">' . htmlspecialchars($p[0]) . '</label>');
1315 }
1316 }
1317 if (!$disabled) {
1318 $item .= '<input type="hidden" name="' . $PA['itemFormElName'] . '" value="' . htmlspecialchars($thisValue) . '" />';
1319 }
1320
1321 return $item;
1322 }
1323
1324 /**
1325 * Generation of TCEform elements of the type "radio"
1326 * This will render a series of radio buttons.
1327 *
1328 * @param string The table name of the record
1329 * @param string The field name which this element is supposed to edit
1330 * @param array The record data array where the value(s) for the field can be found
1331 * @param array An array with additional configuration options.
1332 * @return string The HTML code for the TCEform field
1333 */
1334 function getSingleField_typeRadio($table, $field, $row, &$PA) {
1335 $config = $PA['fieldConf']['config'];
1336
1337 $item = '';
1338 $disabled = '';
1339 if ($this->renderReadonly || $config['readOnly']) {
1340 $disabled = ' disabled="disabled"';
1341 }
1342
1343 // Get items for the array:
1344 $selItems = $this->initItemArray($PA['fieldConf']);
1345 if ($config['itemsProcFunc']) {
1346 $selItems = $this->procItems($selItems, $PA['fieldTSConfig']['itemsProcFunc.'], $config, $table, $row, $field);
1347 }
1348
1349 // Traverse the items, making the form elements:
1350 for ($c = 0; $c < count($selItems); $c++) {
1351 $p = $selItems[$c];
1352 $rID = $PA['itemFormElID'] . '_' . $c;
1353 $rOnClick = implode('', $PA['fieldChangeFunc']);
1354 $rChecked = (!strcmp($p[1], $PA['itemFormElValue']) ? ' checked="checked"' : '');
1355 $item .= '<input type="radio"' . $this->insertDefStyle('radio') . ' name="' . $PA['itemFormElName'] . '" value="' . htmlspecialchars($p[1]) . '" onclick="' . htmlspecialchars($rOnClick) . '"' . $rChecked . $PA['onFocus'] . $disabled . ' id="' . $rID . '" />
1356 <label for="' . $rID . '">' . htmlspecialchars($p[0]) . '</label>
1357 <br />';
1358 }
1359
1360 return $item;
1361 }
1362
1363 /**
1364 * Generation of TCEform elements of the type "select"
1365 * This will render a selector box element, or possibly a special construction with two selector boxes. That depends on configuration.
1366 *
1367 * @param string The table name of the record
1368 * @param string The field name which this element is supposed to edit
1369 * @param array The record data array where the value(s) for the field can be found
1370 * @param array An array with additional configuration options.
1371 * @return string The HTML code for the TCEform field
1372 */
1373 function getSingleField_typeSelect($table, $field, $row, &$PA) {
1374
1375 // Field configuration from TCA:
1376 $config = $PA['fieldConf']['config'];
1377
1378 $disabled = '';
1379 if ($this->renderReadonly || $config['readOnly']) {
1380 $disabled = ' disabled="disabled"';
1381 }
1382
1383 // "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/.
1384 $specConf = $this->getSpecConfFromString($PA['extra'], $PA['fieldConf']['defaultExtras']);
1385
1386 // Getting the selector box items from the system
1387 $selItems = $this->addSelectOptionsToItemArray(
1388 $this->initItemArray($PA['fieldConf']),
1389 $PA['fieldConf'],
1390 $this->setTSconfig($table, $row),
1391 $field
1392 );
1393 // Possibly filter some items:
1394 $keepItemsFunc = create_function('$value', 'return $value[1];');
1395 $selItems = t3lib_div::keepItemsInArray($selItems, $PA['fieldTSConfig']['keepItems'], $keepItemsFunc);
1396 // Possibly add some items:
1397 $selItems = $this->addItems($selItems, $PA['fieldTSConfig']['addItems.']);
1398 // Process items by a user function:
1399 if (isset($config['itemsProcFunc']) && $config['itemsProcFunc']) {
1400 $selItems = $this->procItems($selItems, $PA['fieldTSConfig']['itemsProcFunc.'], $config, $table, $row, $field);
1401 }
1402
1403 // Possibly remove some items:
1404 $removeItems = t3lib_div::trimExplode(',', $PA['fieldTSConfig']['removeItems'], 1);
1405 foreach ($selItems as $tk => $p) {
1406
1407 // Checking languages and authMode:
1408 $languageDeny = $GLOBALS['TCA'][$table]['ctrl']['languageField']
1409 && !strcmp($GLOBALS['TCA'][$table]['ctrl']['languageField'], $field)
1410 && !$GLOBALS['BE_USER']->checkLanguageAccess($p[1]);
1411 $authModeDeny = $config['form_type'] == 'select' && $config['authMode'] && !$GLOBALS['BE_USER']->checkAuthMode($table, $field, $p[1], $config['authMode']);
1412 if (in_array($p[1], $removeItems) || $languageDeny || $authModeDeny) {
1413 unset($selItems[$tk]);
1414 } elseif (isset($PA['fieldTSConfig']['altLabels.'][$p[1]])) {
1415 $selItems[$tk][0] = $this->sL($PA['fieldTSConfig']['altLabels.'][$p[1]]);
1416 }
1417
1418 // Removing doktypes with no access:
1419 if (($table === 'pages' || $table === 'pages_language_overlay') && $field === 'doktype') {
1420 if (!($GLOBALS['BE_USER']->isAdmin() || t3lib_div::inList($GLOBALS['BE_USER']->groupData['pagetypes_select'], $p[1]))) {
1421 unset($selItems[$tk]);
1422 }
1423 }
1424 }
1425
1426 // Creating the label for the "No Matching Value" entry.
1427 $nMV_label = isset($PA['fieldTSConfig']['noMatchingValue_label']) ? $this->sL($PA['fieldTSConfig']['noMatchingValue_label']) : '[ ' . $this->getLL('l_noMatchingValue') . ' ]';
1428
1429 // Prepare some values:
1430 $maxitems = intval($config['maxitems']);
1431
1432 // If a SINGLE selector box...
1433 if ($maxitems <= 1 && $config['renderMode'] !== 'tree') {
1434 $item = $this->getSingleField_typeSelect_single($table, $field, $row, $PA, $config, $selItems, $nMV_label);
1435 } elseif (!strcmp($config['renderMode'], 'checkbox')) { // Checkbox renderMode
1436 $item = $this->getSingleField_typeSelect_checkbox($table, $field, $row, $PA, $config, $selItems, $nMV_label);
1437 } elseif (!strcmp($config['renderMode'], 'singlebox')) { // Single selector box renderMode
1438 $item = $this->getSingleField_typeSelect_singlebox($table, $field, $row, $PA, $config, $selItems, $nMV_label);
1439 } elseif (!strcmp($config['renderMode'], 'tree')) { // Tree renderMode
1440 $treeClass = t3lib_div::makeInstance('t3lib_TCEforms_Tree', $this);
1441 $item = $treeClass->renderField($table, $field, $row, $PA, $config, $selItems, $nMV_label);
1442 } else { // Traditional multiple selector box:
1443 $item = $this->getSingleField_typeSelect_multiple($table, $field, $row, $PA, $config, $selItems, $nMV_label);
1444 }
1445
1446 // Wizards:
1447 if (!$disabled) {
1448 $altItem = '<input type="hidden" name="' . $PA['itemFormElName'] . '" value="' . htmlspecialchars($PA['itemFormElValue']) . '" />';
1449 $item = $this->renderWizards(array($item, $altItem), $config['wizards'], $table, $row, $field, $PA, $PA['itemFormElName'], $specConf);
1450 }
1451
1452 return $item;
1453 }
1454
1455 /**
1456 * Creates a single-selector box
1457 * (Render function for getSingleField_typeSelect())
1458 *
1459 * @param string See getSingleField_typeSelect()
1460 * @param string See getSingleField_typeSelect()
1461 * @param array See getSingleField_typeSelect()
1462 * @param array See getSingleField_typeSelect()
1463 * @param array (Redundant) content of $PA['fieldConf']['config'] (for convenience)
1464 * @param array Items available for selection
1465 * @param string Label for no-matching-value
1466 * @return string The HTML code for the item
1467 * @see getSingleField_typeSelect()
1468 */
1469 function getSingleField_typeSelect_single($table, $field, $row, &$PA, $config, $selItems, $nMV_label) {
1470 // check against inline uniqueness
1471 $inlineParent = $this->inline->getStructureLevel(-1);
1472 if (is_array($inlineParent) && $inlineParent['uid']) {
1473 if ($inlineParent['config']['foreign_table'] == $table && $inlineParent['config']['foreign_unique'] == $field) {
1474 $uniqueIds = $this->inline->inlineData['unique'][$this->inline->inlineNames['object'] . '[' . $table . ']']['used'];
1475 $PA['fieldChangeFunc']['inlineUnique'] = "inline.updateUnique(this,'" . $this->inline->inlineNames['object'] . '[' . $table . "]','" . $this->inline->inlineNames['form'] . "','" . $row['uid'] . "');";
1476 }
1477 // hide uid of parent record for symmetric relations
1478 if ($inlineParent['config']['foreign_table'] == $table && ($inlineParent['config']['foreign_field'] == $field || $inlineParent['config']['symmetric_field'] == $field)) {
1479 $uniqueIds[] = $inlineParent['uid'];
1480 }
1481 }
1482
1483 // Initialization:
1484 $c = 0;
1485 $sI = 0;
1486 $noMatchingValue = 1;
1487 $opt = array();
1488 $selicons = array();
1489 $onlySelectedIconShown = 0;
1490 $size = intval($config['size']);
1491 $selectedStyle = ''; // Style set on <select/>
1492
1493 $item = '';
1494 $disabled = '';
1495 $onChangeIcon = ''; // TODO: icon is used but never assigned
1496
1497 if ($this->renderReadonly || $config['readOnly']) {
1498 $disabled = ' disabled="disabled"';
1499 $onlySelectedIconShown = 1;
1500 }
1501
1502 // Icon configuration:
1503 if ($config['suppress_icons'] == 'IF_VALUE_FALSE') {
1504 $suppressIcons = !$PA['itemFormElValue'] ? 1 : 0;
1505 } elseif ($config['suppress_icons'] == 'ONLY_SELECTED') {
1506 $suppressIcons = 0;
1507 $onlySelectedIconShown = 1;
1508 } elseif ($config['suppress_icons']) {
1509 $suppressIcons = 1;
1510 } else {
1511 $suppressIcons = 0;
1512 }
1513
1514 // Traverse the Array of selector box items:
1515 $optGroupStart = array();
1516 $optGroupOpen = FALSE;
1517 $classesForSelectTag = array();
1518 foreach ($selItems as $p) {
1519 $sM = (!strcmp($PA['itemFormElValue'], $p[1]) ? ' selected="selected"' : '');
1520 if ($sM) {
1521 $sI = $c;
1522 $noMatchingValue = 0;
1523 }
1524
1525 // Getting style attribute value (for icons):
1526 if ($config['iconsInOptionTags']) {
1527 $styleAttrValue = $this->optionTagStyle($p[2]);
1528 if ($sM) {
1529 list($selectIconFile, $selectIconInfo) = $this->getIcon($p[2]);
1530 if (!empty($selectIconInfo)) {
1531 $selectedStyle = ' style="background-image:url(' . $selectIconFile . ');"';
1532 $classesForSelectTag[] = 'typo3-TCEforms-select-selectedItemWithBackgroundImage';
1533 }
1534 }
1535 }
1536
1537 // Compiling the <option> tag:
1538 if (!($p[1] != $PA['itemFormElValue'] && is_array($uniqueIds) && in_array($p[1], $uniqueIds))) {
1539 if (!strcmp($p[1], '--div--')) {
1540 $optGroupStart[0] = $p[0];
1541 if ($config['iconsInOptionTags']) {
1542 $optGroupStart[1] = $this->optgroupTagStyle($p[2]);
1543 } else {
1544 $optGroupStart[1] = $styleAttrValue;
1545 }
1546
1547 } else {
1548 if (count($optGroupStart)) {
1549 if ($optGroupOpen) { // Closing last optgroup before next one starts
1550 $opt[] = '</optgroup>' . LF;
1551 }
1552 $opt[] = '<optgroup label="' . t3lib_div::deHSCentities(htmlspecialchars($optGroupStart[0])) . '"' .
1553 ($optGroupStart[1] ? ' style="' . htmlspecialchars($optGroupStart[1]) . '"' : '') .
1554 ' class="c-divider">' . LF;
1555 $optGroupOpen = TRUE;
1556 $c--;
1557 $optGroupStart = array();
1558 }
1559 $opt[] = '<option value="' . htmlspecialchars($p[1]) . '"' .
1560 $sM .
1561 ($styleAttrValue ? ' style="' . htmlspecialchars($styleAttrValue) . '"' : '') .
1562 '>' . t3lib_div::deHSCentities(($p[0])) . '</option>' . LF;
1563 }
1564 }
1565
1566 // If there is an icon for the selector box (rendered in selicon-table below)...:
1567 // if there is an icon ($p[2]), icons should be shown, and, if only selected are visible, is it selected
1568 if ($p[2] && !$suppressIcons && (!$onlySelectedIconShown || $sM)) {
1569 list($selIconFile, $selIconInfo) = $this->getIcon($p[2]);
1570 if (!empty($selIconInfo)) {
1571 $iOnClick = $this->elName($PA['itemFormElName']) . '.selectedIndex=' . $c . '; ' .
1572 $this->elName($PA['itemFormElName']) . '.style.backgroundImage=' . $this->elName($PA['itemFormElName']) . '.options[' . $c . '].style.backgroundImage; ' .
1573 implode('', $PA['fieldChangeFunc']) . $this->blur() . 'return false;';
1574 } else {
1575 $iOnClick = $this->elName($PA['itemFormElName']) . '.selectedIndex=' . $c . '; ' .
1576 $this->elName($PA['itemFormElName']) . '.className=' . $this->elName($PA['itemFormElName']) . '.options[' . $c . '].className; ' .
1577 implode('', $PA['fieldChangeFunc']) . $this->blur() . 'return false;';
1578 }
1579 $selicons[] = array(
1580 (!$onlySelectedIconShown ? '<a href="#" onclick="' . htmlspecialchars($iOnClick) . '">' : '') .
1581 $this->getIconHtml($p[2], htmlspecialchars($p[0]), htmlspecialchars($p[0])) .
1582 (!$onlySelectedIconShown ? '</a>' : ''),
1583 $c, $sM);
1584 }
1585 $c++;
1586 }
1587
1588 if ($optGroupOpen) { // Closing optgroup if open
1589 $opt[] = '</optgroup>';
1590 $optGroupOpen = FALSE;
1591 }
1592
1593 // No-matching-value:
1594 if ($PA['itemFormElValue'] && $noMatchingValue && !$PA['fieldTSConfig']['disableNoMatchingValueElement'] && !$config['disableNoMatchingValueElement']) {
1595 $nMV_label = @sprintf($nMV_label, $PA['itemFormElValue']);
1596 $opt[] = '<option value="' . htmlspecialchars($PA['itemFormElValue']) . '" selected="selected">' . htmlspecialchars($nMV_label) . '</option>';
1597 }
1598
1599 // Create item form fields:
1600 $sOnChange = 'if (this.options[this.selectedIndex].value==\'--div--\') {this.selectedIndex=' . $sI . ';} ' . implode('', $PA['fieldChangeFunc']);
1601 if (!$disabled) {
1602 $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...
1603 }
1604 if ($config['iconsInOptionTags']) {
1605 $classesForSelectTag[] = 'icon-select';
1606 }
1607 $item .= '<select' . $selectedStyle . ' id="' . uniqid('tceforms-select-') . '" name="' . $PA['itemFormElName'] . '"' .
1608 $this->insertDefStyle('select', implode(' ', $classesForSelectTag)) .
1609 ($size ? ' size="' . $size . '"' : '') .
1610 ' onchange="' . htmlspecialchars($onChangeIcon . $sOnChange) . '"' .
1611 $PA['onFocus'] . $disabled . '>';
1612 $item .= implode('', $opt);
1613 $item .= '</select>';
1614
1615 // Create icon table:
1616 if (count($selicons) && !$config['noIconsBelowSelect']) {
1617 $item .= '<table border="0" cellpadding="0" cellspacing="0" class="typo3-TCEforms-selectIcons">';
1618 $selicon_cols = intval($config['selicon_cols']);
1619 if (!$selicon_cols) {
1620 $selicon_cols = count($selicons);
1621 }
1622 $sR = ceil(count($selicons) / $selicon_cols);
1623 $selicons = array_pad($selicons, $sR * $selicon_cols, '');
1624 for ($sa = 0; $sa < $sR; $sa++) {
1625 $item .= '<tr>';
1626 for ($sb = 0; $sb < $selicon_cols; $sb++) {
1627 $sk = ($sa * $selicon_cols + $sb);
1628 $imgN = 'selIcon_' . $table . '_' . $row['uid'] . '_' . $field . '_' . $selicons[$sk][1];
1629 $imgS = ($selicons[$sk][2] ? $this->backPath . 'gfx/content_selected.gif' : 'clear.gif');
1630 $item .= '<td><img name="' . htmlspecialchars($imgN) . '" src="' . $imgS . '" width="7" height="10" alt="" /></td>';
1631 $item .= '<td>' . $selicons[$sk][0] . '</td>';
1632 }
1633 $item .= '</tr>';
1634 }
1635 $item .= '</table>';
1636 }
1637
1638 return $item;
1639 }
1640
1641 /**
1642 * Creates a checkbox list (renderMode = "checkbox")
1643 * (Render function for getSingleField_typeSelect())
1644 *
1645 * @param string See getSingleField_typeSelect()
1646 * @param string See getSingleField_typeSelect()
1647 * @param array See getSingleField_typeSelect()
1648 * @param array See getSingleField_typeSelect()
1649 * @param array (Redundant) content of $PA['fieldConf']['config'] (for convenience)
1650 * @param array Items available for selection
1651 * @param string Label for no-matching-value
1652 * @return string The HTML code for the item
1653 * @see getSingleField_typeSelect()
1654 */
1655 function getSingleField_typeSelect_checkbox($table, $field, $row, &$PA, $config, $selItems, $nMV_label) {
1656
1657 if (empty($selItems)) {
1658 return '';
1659 }
1660
1661 // Get values in an array (and make unique, which is fine because there can be no duplicates anyway):
1662 $itemArray = array_flip($this->extractValuesOnlyFromValueLabelList($PA['itemFormElValue']));
1663
1664 $item = '';
1665 $disabled = '';
1666 if ($this->renderReadonly || $config['readOnly']) {
1667 $disabled = ' disabled="disabled"';
1668 }
1669
1670 // Traverse the Array of selector box items:
1671 $tRows = array();
1672 $c = 0;
1673 if (!$disabled) {
1674 $sOnChange = implode('', $PA['fieldChangeFunc']);
1675 $setAll = array(); // Used to accumulate the JS needed to restore the original selection.
1676 $unSetAll = array();
1677 foreach ($selItems as $p) {
1678 // Non-selectable element:
1679 if (!strcmp($p[1], '--div--')) {
1680 $tRows[] = '
1681 <tr class="c-header">
1682 <td colspan="3">' . htmlspecialchars($p[0]) . '</td>
1683 </tr>';
1684 } else {
1685 // Selected or not by default:
1686 $sM = '';
1687 if (isset($itemArray[$p[1]])) {
1688 $sM = ' checked="checked"';
1689 unset($itemArray[$p[1]]);
1690 }
1691
1692 // Icon:
1693 if ($p[2]) {
1694 $selIcon = $p[2];
1695 } else {
1696 $selIcon = t3lib_iconWorks::getSpriteIcon('empty-empty');
1697 }
1698
1699 // Compile row:
1700 $rowId = uniqid('select_checkbox_row_');
1701 $onClickCell = $this->elName($PA['itemFormElName'] . '[' . $c . ']') . '.checked=!' . $this->elName($PA['itemFormElName'] . '[' . $c . ']') . '.checked;';
1702 $onClick = 'this.attributes.getNamedItem("class").nodeValue = ' . $this->elName($PA['itemFormElName'] . '[' . $c . ']') . '.checked ? "c-selectedItem" : "c-unselectedItem";';
1703 $setAll[] = $this->elName($PA['itemFormElName'] . '[' . $c . ']') . '.checked=1;';
1704 $setAll[] .= '$(\'' . $rowId . '\').removeClassName(\'c-unselectedItem\');$(\'' . $rowId . '\').addClassName(\'c-selectedItem\');';
1705 $unSetAll[] = $this->elName($PA['itemFormElName'] . '[' . $c . ']') . '.checked=0;';
1706 $unSetAll[] .= '$(\'' . $rowId . '\').removeClassName(\'c-selectedItem\');$(\'' . $rowId . '\').addClassName(\'c-unselectedItem\');';
1707 $restoreCmd[] = $this->elName($PA['itemFormElName'] . '[' . $c . ']') . '.checked=' . ($sM ? 1 : 0) . ';' .
1708 '$(\'' . $rowId . '\').removeClassName(\'c-selectedItem\');$(\'' . $rowId . '\').removeClassName(\'c-unselectedItem\');' .
1709 '$(\'' . $rowId . '\').addClassName(\'c-' . ($sM ? '' : 'un') . 'selectedItem\');';
1710
1711 // Check if some help text is available
1712 // Since TYPO3 4.5 help text is expected to be an associative array
1713 // with two key, "title" and "description"
1714 // For the sake of backwards compatibility, we test if the help text
1715 // is a string and use it as a description (this could happen if items
1716 // are modified with an itemProcFunc)
1717 $hasHelp = FALSE;
1718 $help = '';
1719 $helpArray = array();
1720 if ((is_array($p[3]) && count($p[3]) > 0) || !empty($p[3])) {
1721 $hasHelp = TRUE;
1722 if (is_array($p[3])) {
1723 $helpArray = $p[3];
1724 } else {
1725 $helpArray['description'] = $p[3];
1726 }
1727 }
1728
1729 $label = t3lib_div::deHSCentities(htmlspecialchars($p[0]));
1730 if ($hasHelp) {
1731 $help = t3lib_BEfunc::wrapInHelp('', '', '', $helpArray);
1732 }
1733
1734 $tRows[] = '
1735 <tr id="' . $rowId . '" class="' . ($sM ? 'c-selectedItem' : 'c-unselectedItem') . '" onclick="' . htmlspecialchars($onClick) . '" style="cursor: pointer;">
1736 <td class="c-checkbox"><input type="checkbox"' . $this->insertDefStyle('check') . ' name="' . htmlspecialchars($PA['itemFormElName'] . '[' . $c . ']') . '" value="' . htmlspecialchars($p[1]) . '"' . $sM . ' onclick="' . htmlspecialchars($sOnChange) . '"' . $PA['onFocus'] . ' /></td>
1737 <td class="c-labelCell" onclick="' . htmlspecialchars($onClickCell) . '">' .
1738 $this->getIconHtml($selIcon) .
1739 $label .
1740 '</td>
1741 <td class="c-descr" onclick="' . htmlspecialchars($onClickCell) . '">' . ((empty($help)) ? '' : $help) . '</td>
1742 </tr>';
1743 $c++;
1744 }
1745 }
1746 }
1747
1748 // Remaining values (invalid):
1749 if (count($itemArray) && !$PA['fieldTSConfig']['disableNoMatchingValueElement'] && !$config['disableNoMatchingValueElement']) {
1750 foreach ($itemArray as $theNoMatchValue => $temp) {
1751 // Compile <checkboxes> tag:
1752 array_unshift($tRows, '
1753 <tr class="c-invalidItem">
1754 <td class="c-checkbox"><input type="checkbox"' . $this->insertDefStyle('check') . ' name="' . htmlspecialchars($PA['itemFormElName'] . '[' . $c . ']') . '" value="' . htmlspecialchars($theNoMatchValue) . '" checked="checked" onclick="' . htmlspecialchars($sOnChange) . '"' . $PA['onFocus'] . $disabled . ' /></td>
1755 <td class="c-labelCell">' .
1756 t3lib_div::deHSCentities(htmlspecialchars(@sprintf($nMV_label, $theNoMatchValue))) .
1757 '</td><td>&nbsp;</td>
1758 </tr>');
1759 $c++;
1760 }
1761 }
1762
1763 // Add an empty hidden field which will send a blank value if all items are unselected.
1764 $item .= '<input type="hidden" name="' . htmlspecialchars($PA['itemFormElName']) . '" value="" />';
1765
1766 // Remaining checkboxes will get their set-all link:
1767 if (count($setAll)) {
1768 $tableHead = '<thead>
1769 <tr class="c-header-checkbox-controls t3-row-header">
1770 <td class="c-checkbox">
1771 <input type="checkbox" class="checkbox" onclick="if (checked) {' . htmlspecialchars(implode('', $setAll) . '} else {' . implode('', $unSetAll) . '}') . '">
1772 </td>
1773 <td colspan="2">
1774 </td>
1775 </tr></thead>';
1776 }
1777 // Implode rows in table:
1778 $item .= '
1779 <table border="0" cellpadding="0" cellspacing="0" class="typo3-TCEforms-select-checkbox">' .
1780 $tableHead .
1781 '<tbody>' . implode('', $tRows) . '</tbody>
1782 </table>
1783 ';
1784
1785 // Add revert icon
1786 if (is_array($restoreCmd)) {
1787 $item .= '<a href="#" onclick="' . implode('', $restoreCmd) . ' return false;' . '">' .
1788 t3lib_iconWorks::getSpriteIcon('actions-edit-undo', array('title' => htmlspecialchars($this->getLL('l_revertSelection')))) . '</a>';
1789 }
1790
1791 return $item;
1792 }
1793
1794 /**
1795 * Creates a selectorbox list (renderMode = "singlebox")
1796 * (Render function for getSingleField_typeSelect())
1797 *
1798 * @param string See getSingleField_typeSelect()
1799 * @param string See getSingleField_typeSelect()
1800 * @param array See getSingleField_typeSelect()
1801 * @param array See getSingleField_typeSelect()
1802 * @param array (Redundant) content of $PA['fieldConf']['config'] (for convenience)
1803 * @param array Items available for selection
1804 * @param string Label for no-matching-value
1805 * @return string The HTML code for the item
1806 * @see getSingleField_typeSelect()
1807 */
1808 function getSingleField_typeSelect_singlebox($table, $field, $row, &$PA, $config, $selItems, $nMV_label) {
1809
1810 // Get values in an array (and make unique, which is fine because there can be no duplicates anyway):
1811 $itemArray = array_flip($this->extractValuesOnlyFromValueLabelList($PA['itemFormElValue']));
1812
1813 $item = '';
1814 $disabled = '';
1815 if ($this->renderReadonly || $config['readOnly']) {
1816 $disabled = ' disabled="disabled"';
1817 }
1818
1819 // Traverse the Array of selector box items:
1820 $opt = array();
1821 $restoreCmd = array(); // Used to accumulate the JS needed to restore the original selection.
1822 $c = 0;
1823 foreach ($selItems as $p) {
1824 // Selected or not by default:
1825 $sM = '';
1826 if (isset($itemArray[$p[1]])) {
1827 $sM = ' selected="selected"';
1828 $restoreCmd[] = $this->elName($PA['itemFormElName'] . '[]') . '.options[' . $c . '].selected=1;';
1829 unset($itemArray[$p[1]]);
1830 }
1831
1832 // Non-selectable element:
1833 $nonSel = '';
1834 if (!strcmp($p[1], '--div--')) {
1835 $nonSel = ' onclick="this.selected=0;" class="c-divider"';
1836 }
1837
1838 // Icon style for option tag:
1839 if ($config['iconsInOptionTags']) {
1840 $styleAttrValue = $this->optionTagStyle($p[2]);
1841 }
1842
1843 // Compile <option> tag:
1844 $opt[] = '<option value="' . htmlspecialchars($p[1]) . '"' .
1845 $sM .
1846 $nonSel .
1847 ($styleAttrValue ? ' style="' . htmlspecialchars($styleAttrValue) . '"' : '') .
1848 '>' . t3lib_div::deHSCentities(htmlspecialchars($p[0])) . '</option>';
1849 $c++;
1850 }
1851
1852 // Remaining values:
1853 if (count($itemArray) && !$PA['fieldTSConfig']['disableNoMatchingValueElement'] && !$config['disableNoMatchingValueElement']) {
1854 foreach ($itemArray as $theNoMatchValue => $temp) {
1855 // Compile <option> tag:
1856 array_unshift($opt, '<option value="' . htmlspecialchars($theNoMatchValue) . '" selected="selected">' . t3lib_div::deHSCentities(htmlspecialchars(@sprintf($nMV_label, $theNoMatchValue))) . '</option>');
1857 }
1858 }
1859
1860 // Compile selector box:
1861 $sOnChange = implode('', $PA['fieldChangeFunc']);
1862 $selector_itemListStyle = isset($config['itemListStyle']) ? ' style="' . htmlspecialchars($config['itemListStyle']) . '"' : ' style="' . $this->defaultMultipleSelectorStyle . '"';
1863 $size = intval($config['size']);
1864 $cssPrefix = ($size === 1) ? 'tceforms-select' : 'tceforms-multiselect';
1865 $size = $config['autoSizeMax'] ? t3lib_utility_Math::forceIntegerInRange(count($selItems) + 1, t3lib_utility_Math::forceIntegerInRange($size, 1), $config['autoSizeMax']) : $size;
1866 $selectBox = '<select id="' . uniqid($cssPrefix) . '" name="' . $PA['itemFormElName'] . '[]"' .
1867 $this->insertDefStyle('select', $cssPrefix) .
1868 ($size ? ' size="' . $size . '"' : '') .
1869 ' multiple="multiple" onchange="' . htmlspecialchars($sOnChange) . '"' .
1870 $PA['onFocus'] .
1871 $selector_itemListStyle .
1872 $disabled . '>
1873 ' .
1874 implode('
1875 ', $opt) . '
1876 </select>';
1877
1878 // Add an empty hidden field which will send a blank value if all items are unselected.
1879 if (!$disabled) {
1880 $item .= '<input type="hidden" name="' . htmlspecialchars($PA['itemFormElName']) . '" value="" />';
1881 }
1882
1883 // Put it all into a table:
1884 $item .= '
1885 <table border="0" cellspacing="0" cellpadding="0" width="1" class="typo3-TCEforms-select-singlebox">
1886 <tr>
1887 <td>
1888 ' . $selectBox . '
1889 <br/>
1890 <em>' .
1891 htmlspecialchars($this->getLL('l_holdDownCTRL')) .
1892 '</em>
1893 </td>
1894 <td valign="top">
1895 <a href="#" onclick="' . htmlspecialchars($this->elName($PA['itemFormElName'] . '[]') . '.selectedIndex=-1;' . implode('', $restoreCmd) . ' return false;') . '" title="' . htmlspecialchars($this->getLL('l_revertSelection')) . '">' .
1896 t3lib_iconWorks::getSpriteIcon('actions-edit-undo') .
1897 '</a>
1898 </td>
1899 </tr>
1900 </table>
1901 ';
1902
1903 return $item;
1904 }
1905
1906 /**
1907 * Creates a multiple-selector box (two boxes, side-by-side)
1908 * (Render function for getSingleField_typeSelect())
1909 *
1910 * @param string See getSingleField_typeSelect()
1911 * @param string See getSingleField_typeSelect()
1912 * @param array See getSingleField_typeSelect()
1913 * @param array See getSingleField_typeSelect()
1914 * @param array (Redundant) content of $PA['fieldConf']['config'] (for convenience)
1915 * @param array Items available for selection
1916 * @param string Label for no-matching-value
1917 * @return string The HTML code for the item
1918 * @see getSingleField_typeSelect()
1919 */
1920 function getSingleField_typeSelect_multiple($table, $field, $row, &$PA, $config, $selItems, $nMV_label) {
1921
1922 $item = '';
1923 $disabled = '';
1924 if ($this->renderReadonly || $config['readOnly']) {
1925 $disabled = ' disabled="disabled"';
1926 }
1927
1928 // Setting this hidden field (as a flag that JavaScript can read out)
1929 if (!$disabled) {
1930 $item .= '<input type="hidden" name="' . $PA['itemFormElName'] . '_mul" value="' . ($config['multiple'] ? 1 : 0) . '" />';
1931 }
1932
1933 // Set max and min items:
1934 $maxitems = t3lib_utility_Math::forceIntegerInRange($config['maxitems'], 0);
1935 if (!$maxitems) {
1936 $maxitems = 100000;
1937 }
1938 $minitems = t3lib_utility_Math::forceIntegerInRange($config['minitems'], 0);
1939
1940 // Register the required number of elements:
1941 $this->registerRequiredProperty('range', $PA['itemFormElName'], array($minitems, $maxitems, 'imgName' => $table . '_' . $row['uid'] . '_' . $field));
1942
1943 // Get "removeItems":
1944 $removeItems = t3lib_div::trimExplode(',', $PA['fieldTSConfig']['removeItems'], 1);
1945
1946 // Get the array with selected items:
1947 $itemArray = t3lib_div::trimExplode(',', $PA['itemFormElValue'], 1);
1948
1949 // Possibly filter some items:
1950 $keepItemsFunc = create_function('$value', '$parts=explode(\'|\',$value,2); return rawurldecode($parts[0]);');
1951 $itemArray = t3lib_div::keepItemsInArray($itemArray, $PA['fieldTSConfig']['keepItems'], $keepItemsFunc);
1952
1953 // Perform modification of the selected items array:
1954 foreach ($itemArray as $tk => $tv) {
1955 $tvP = explode('|', $tv, 2);
1956 $evalValue = $tvP[0];
1957 $isRemoved = in_array($evalValue, $removeItems) || ($config['form_type'] == 'select' && $config['authMode'] && !$GLOBALS['BE_USER']->checkAuthMode($table, $field, $evalValue, $config['authMode']));
1958 if ($isRemoved && !$PA['fieldTSConfig']['disableNoMatchingValueElement'] && !$config['disableNoMatchingValueElement']) {
1959 $tvP[1] = rawurlencode(@sprintf($nMV_label, $evalValue));
1960 } elseif (isset($PA['fieldTSConfig']['altLabels.'][$evalValue])) {
1961 $tvP[1] = rawurlencode($this->sL($PA['fieldTSConfig']['altLabels.'][$evalValue]));
1962 }
1963 if ($tvP[1] == '') {
1964 // Case: flexform, default values supplied, no label provided (bug #9795)
1965 foreach ($selItems as $selItem) {
1966 if ($selItem[1] == $tvP[0]) {
1967 $tvP[1] = html_entity_decode($selItem[0]);
1968 break;
1969 }
1970 }
1971 }
1972 $itemArray[$tk] = implode('|', $tvP);
1973 }
1974 $itemsToSelect = '';
1975
1976 if (!$disabled) {
1977 // Create option tags:
1978 $opt = array();
1979 $styleAttrValue = '';
1980 foreach ($selItems as $p) {
1981 if ($config['iconsInOptionTags']) {
1982 $styleAttrValue = $this->optionTagStyle($p[2]);
1983 }
1984 $opt[] = '<option value="' . htmlspecialchars($p[1]) . '"' .
1985 ($styleAttrValue ? ' style="' . htmlspecialchars($styleAttrValue) . '"' : '') .
1986 '>' . $p[0] . '</option>';
1987 }
1988
1989 // Put together the selector box:
1990 $selector_itemListStyle = isset($config['itemListStyle']) ? ' style="' . htmlspecialchars($config['itemListStyle']) . '"' : ' style="' . $this->defaultMultipleSelectorStyle . '"';
1991 $size = intval($config['size']);
1992 $size = $config['autoSizeMax'] ? t3lib_utility_Math::forceIntegerInRange(count($itemArray) + 1, t3lib_utility_Math::forceIntegerInRange($size, 1), $config['autoSizeMax']) : $size;
1993 if ($config['exclusiveKeys']) {
1994 $sOnChange = 'setFormValueFromBrowseWin(\'' . $PA['itemFormElName'] . '\',this.options[this.selectedIndex].value,this.options[this.selectedIndex].text,\'' . $config['exclusiveKeys'] . '\'); ';
1995 } else {
1996 $sOnChange = 'setFormValueFromBrowseWin(\'' . $PA['itemFormElName'] . '\',this.options[this.selectedIndex].value,this.options[this.selectedIndex].text); ';
1997 }
1998 $sOnChange .= implode('', $PA['fieldChangeFunc']);
1999 $itemsToSelect = '
2000 <select id="' . uniqid('tceforms-multiselect-') . '" name="' . $PA['itemFormElName'] . '_sel"' .
2001 $this->insertDefStyle('select', 'tceforms-multiselect tceforms-itemstoselect') .
2002 ($size ? ' size="' . $size . '"' : '') .
2003 ' onchange="' . htmlspecialchars($sOnChange) . '"' .
2004 $PA['onFocus'] .
2005 $selector_itemListStyle . '>
2006 ' . implode('
2007 ', $opt) . '
2008 </select>';
2009 }
2010
2011 // Pass to "dbFileIcons" function:
2012 $params = array(
2013 'size' => $size,
2014 'autoSizeMax' => t3lib_utility_Math::forceIntegerInRange($config['autoSizeMax'], 0),
2015 'style' => isset($config['selectedListStyle']) ? ' style="' . htmlspecialchars($config['selectedListStyle']) . '"' : ' style="' . $this->defaultMultipleSelectorStyle . '"',
2016 'dontShowMoveIcons' => ($maxitems <= 1),
2017 'maxitems' => $maxitems,
2018 'info' => '',
2019 'headers' => array(
2020 'selector' => $this->getLL('l_selected') . ':<br />',
2021 'items' => $this->getLL('l_items') . ':<br />'
2022 ),
2023 'noBrowser' => 1,
2024 'thumbnails' => $itemsToSelect,
2025 'readOnly' => $disabled
2026 );
2027 $item .= $this->dbFileIcons($PA['itemFormElName'], '', '', $itemArray, '', $params, $PA['onFocus']);
2028
2029 return $item;
2030 }
2031
2032 /**
2033 * Generation of TCEform elements of the type "group"
2034 * This will render a selectorbox into which elements from either the file system or database can be inserted. Relations.
2035 *
2036 * @param string The table name of the record
2037 * @param string The field name which this element is supposed to edit
2038 * @param array The record data array where the value(s) for the field can be found
2039 * @param array An array with additional configuration options.
2040 * @return string The HTML code for the TCEform field
2041 */
2042 function getSingleField_typeGroup($table, $field, $row, &$PA) {
2043 // Init:
2044 $config = $PA['fieldConf']['config'];
2045 $internal_type = $config['internal_type'];
2046 $show_thumbs = $config['show_thumbs'];
2047 $size = intval($config['size']);
2048 $maxitems = t3lib_utility_Math::forceIntegerInRange($config['maxitems'], 0);
2049 if (!$maxitems) {
2050 $maxitems = 100000;
2051 }
2052 $minitems = t3lib_utility_Math::forceIntegerInRange($config['minitems'], 0);
2053 $allowed = trim($config['allowed']);
2054 $disallowed = trim($config['disallowed']);
2055
2056 $item = '';
2057 $disabled = '';
2058 if ($this->renderReadonly || $config['readOnly']) {
2059 $disabled = ' disabled="disabled"';
2060 }
2061
2062 $item .= '<input type="hidden" name="' . $PA['itemFormElName'] . '_mul" value="' . ($config['multiple'] ? 1 : 0) . '"' . $disabled . ' />';
2063 $this->registerRequiredProperty('range', $PA['itemFormElName'], array($minitems, $maxitems, 'imgName' => $table . '_' . $row['uid'] . '_' . $field));
2064 $info = '';
2065
2066 // "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/.
2067 $specConf = $this->getSpecConfFromString($PA['extra'], $PA['fieldConf']['defaultExtras']);
2068
2069 $PA['itemFormElID_file'] = $PA['itemFormElID'] . '_files';
2070
2071 // whether the list and delete controls should be disabled
2072 $noList = isset($config['disable_controls']) && t3lib_div::inList($config['disable_controls'], 'list');
2073 $noDelete = isset($config['disable_controls']) && t3lib_div::inList($config['disable_controls'], 'delete');
2074
2075 // if maxitems==1 then automatically replace the current item (in list and file selector)
2076 if ($maxitems === 1) {
2077 $this->additionalJS_post[] = "TBE_EDITOR.clearBeforeSettingFormValueFromBrowseWin['" . $PA['itemFormElName'] . "'] = {
2078 itemFormElID_file: '" . $PA['itemFormElID_file'] . "'
2079 }";
2080 $PA['fieldChangeFunc']['TBE_EDITOR_fieldChanged'] = "setFormValueManipulate('" . $PA['itemFormElName'] . "', 'Remove'); " . $PA['fieldChangeFunc']['TBE_EDITOR_fieldChanged'];
2081 } elseif ($noList) {
2082 // if the list controls have been removed and the maximum number is reached, remove the first entry to avoid "write once" field
2083 $PA['fieldChangeFunc']['TBE_EDITOR_fieldChanged'] = "setFormValueManipulate('" . $PA['itemFormElName'] . "', 'RemoveFirstIfFull', '" . $maxitems . "'); " . $PA['fieldChangeFunc']['TBE_EDITOR_fieldChanged'];
2084 }
2085
2086 // Acting according to either "file" or "db" type:
2087 switch ((string) $config['internal_type']) {
2088 case 'file_reference':
2089 $config['uploadfolder'] = '';
2090 // Fall through
2091 case 'file': // If the element is of the internal type "file":
2092
2093 // Creating string showing allowed types:
2094 $tempFT = t3lib_div::trimExplode(',', $allowed, TRUE);
2095 if (!count($tempFT)) {
2096 $info .= '*';
2097 }
2098 foreach ($tempFT as $ext) {
2099 if ($ext) {
2100 $info .= strtoupper($ext) . ' ';
2101 }
2102 }
2103 // Creating string, showing disallowed types:
2104 $tempFT_dis = t3lib_div::trimExplode(',', $disallowed, TRUE);
2105 if (count($tempFT_dis)) {
2106 $info .= '<br />';
2107 }
2108 foreach ($tempFT_dis as $ext) {
2109 if ($ext) {
2110 $info .= '-' . strtoupper($ext) . ' ';
2111 }
2112 }
2113
2114 // Making the array of file items:
2115 $itemArray = t3lib_div::trimExplode(',', $PA['itemFormElValue'], TRUE);
2116
2117 // Showing thumbnails:
2118 $thumbsnail = '';
2119 if ($show_thumbs) {
2120 $imgs = array();
2121 foreach ($itemArray as $imgRead) {
2122 $imgP = explode('|', $imgRead);
2123 $imgPath = rawurldecode($imgP[0]);
2124
2125 $rowCopy = array();
2126 $rowCopy[$field] = $imgPath;
2127
2128 $imgs[] = '<span class="nobr">' . t3lib_BEfunc::thumbCode($rowCopy, $table, $field, $this->backPath, 'thumbs.php', $config['uploadfolder'], 0, ' align="middle"') .
2129 $imgPath .
2130 '</span>';
2131 }
2132 $thumbsnail = implode('<br />', $imgs);
2133 }
2134
2135 // Creating the element:
2136 $params = array(
2137 'size' => $size,
2138 'dontShowMoveIcons' => ($maxitems <= 1),
2139 'autoSizeMax' => t3lib_utility_Math::forceIntegerInRange($config['autoSizeMax'], 0),
2140 'maxitems' => $maxitems,
2141 'style' => isset($config['selectedListStyle']) ? ' style="' . htmlspecialchars($config['selectedListStyle']) . '"' : ' style="' . $this->defaultMultipleSelectorStyle . '"',
2142 'info' => $info,
2143 'thumbnails' => $thumbsnail,
2144 'readOnly' => $disabled,
2145 'noBrowser' => $noList || (isset($config['disable_controls']) && t3lib_div::inList($config['disable_controls'], 'browser')),
2146 'noList' => $noList,
2147 'noDelete' => $noDelete,
2148 );
2149 $item .= $this->dbFileIcons($PA['itemFormElName'], 'file', implode(',', $tempFT), $itemArray, '', $params, $PA['onFocus']);
2150
2151 if (!$disabled && !(isset($config['disable_controls']) && t3lib_div::inList($config['disable_controls'], 'upload'))) {
2152 // Adding the upload field:
2153 if ($this->edit_docModuleUpload && $config['uploadfolder']) {
2154 $item .= '<div id="' . $PA['itemFormElID_file'] . '"><input type="file" name="' . $PA['itemFormElName_file'] . '" size="35" onchange="' . implode('', $PA['fieldChangeFunc']) . '" /></div>';
2155 }
2156 }
2157 break;
2158 case 'folder': // If the element is of the internal type "folder":
2159
2160 // array of folder items:
2161 $itemArray = t3lib_div::trimExplode(',', $PA['itemFormElValue'], 1);
2162
2163 // Creating the element:
2164 $params = array(
2165 'size' => $size,
2166 'dontShowMoveIcons' => ($maxitems <= 1),
2167 'autoSizeMax' => t3lib_utility_Math::forceIntegerInRange($config['autoSizeMax'], 0),
2168 'maxitems' => $maxitems,
2169 'style' => isset($config['selectedListStyle']) ?
2170 ' style="' . htmlspecialchars($config['selectedListStyle']) . '"'
2171 : ' style="' . $this->defaultMultipleSelectorStyle . '"',
2172 'info' => $info,
2173 'readOnly' => $disabled,
2174 'noBrowser' => $noList || (isset($config['disable_controls']) && t3lib_div::inList($config['disable_controls'], 'browser')),
2175 'noList' => $noList,
2176 );
2177
2178 $item .= $this->dbFileIcons(
2179 $PA['itemFormElName'],
2180 'folder',
2181 '',
2182 $itemArray,
2183 '',
2184 $params,
2185 $PA['onFocus']
2186 );
2187 break;
2188 case 'db': // If the element is of the internal type "db":
2189
2190 // Creating string showing allowed types:
2191 $tempFT = t3lib_div::trimExplode(',', $allowed, TRUE);
2192 if (!strcmp(trim($tempFT[0]), '*')) {
2193 $onlySingleTableAllowed = FALSE;
2194 $info .= '<span class="nobr">' .
2195 htmlspecialchars($this->getLL('l_allTables')) .
2196 '</span><br />';
2197 } elseif ($tempFT) {
2198 $onlySingleTableAllowed = (count($tempFT) == 1);
2199 foreach ($tempFT as $theT) {
2200 $info .= '<span class="nobr">' .
2201 t3lib_iconWorks::getSpriteIconForRecord($theT, array()) .
2202 htmlspecialchars($this->sL($GLOBALS['TCA'][$theT]['ctrl']['title'])) .
2203 '</span><br />';
2204 }
2205 }
2206
2207 $perms_clause = $GLOBALS['BE_USER']->getPagePermsClause(1);
2208 $itemArray = array();
2209 $imgs = array();
2210
2211 // Thumbnails:
2212 $temp_itemArray = t3lib_div::trimExplode(',', $PA['itemFormElValue'], 1);
2213 foreach ($temp_itemArray as $dbRead) {
2214 $recordParts = explode('|', $dbRead);
2215 list($this_table, $this_uid) = t3lib_BEfunc::splitTable_Uid($recordParts[0]);
2216 // For the case that no table was found and only a single table is defined to be allowed, use that one:
2217 if (!$this_table && $onlySingleTableAllowed) {
2218 $this_table = $allowed;
2219 }
2220 $itemArray[] = array('table' => $this_table, 'id' => $this_uid);
2221 if (!$disabled && $show_thumbs) {
2222 $rr = t3lib_BEfunc::getRecordWSOL($this_table, $this_uid);
2223 $imgs[] = '<span class="nobr">' .
2224 $this->getClickMenu(
2225 t3lib_iconWorks::getSpriteIconForRecord(
2226 $this_table,
2227 $rr,
2228 array(
2229 'style' => 'vertical-align:top',
2230 'title' => htmlspecialchars(t3lib_BEfunc::getRecordPath($rr['pid'], $perms_clause, 15) . ' [UID: ' . $rr['uid'] . ']')
2231 )
2232 ),
2233 $this_table,
2234 $this_uid
2235 ) .
2236 '&nbsp;' .
2237 t3lib_BEfunc::getRecordTitle($this_table, $rr, TRUE) . ' <span class="typo3-dimmed"><em>[' . $rr['uid'] . ']</em></span>' .
2238 '</span>';
2239 }
2240 }
2241 $thumbsnail = '';
2242 if (!$disabled && $show_thumbs) {
2243 $thumbsnail = implode('<br />', $imgs);
2244 }
2245
2246 // Creating the element:
2247 $params = array(
2248 'size' => $size,
2249 'dontShowMoveIcons' => ($maxitems <= 1),
2250 'autoSizeMax' => t3lib_utility_Math::forceIntegerInRange($config['autoSizeMax'], 0),
2251 'maxitems' => $maxitems,
2252 'style' => isset($config['selectedListStyle']) ? ' style="' . htmlspecialchars($config['selectedListStyle']) . '"' : ' style="' . $this->defaultMultipleSelectorStyle . '"',
2253 'info' => $info,
2254 'thumbnails' => $thumbsnail,
2255 'readOnly' => $disabled,
2256 'noBrowser' => $noList || (isset($config['disable_controls']) && t3lib_div::inList($config['disable_controls'], 'browser')),
2257 'noList' => $noList,
2258 );
2259 $item .= $this->dbFileIcons($PA['itemFormElName'], 'db', implode(',', $tempFT), $itemArray, '', $params, $PA['onFocus'], $table, $field, $row['uid']);
2260
2261 break;
2262 }
2263
2264 // Wizards:
2265 $altItem = '<input type="hidden" name="' . $PA['itemFormElName'] . '" value="' . htmlspecialchars($PA['itemFormElValue']) . '" />';
2266 if (!$disabled) {
2267 $item = $this->renderWizards(array($item, $altItem), $config['wizards'], $table, $row, $field, $PA, $PA['itemFormElName'], $specConf);
2268 }
2269
2270 return $item;
2271 }
2272
2273 /**
2274 * Generation of TCEform elements of the type "none"
2275 * This will render a non-editable display of the content of the field.
2276 *
2277 * @param string The table name of the record
2278 * @param string The field name which this element is supposed to edit
2279 * @param array The record data array where the value(s) for the field can be found
2280 * @param array An array with additional configuration options.
2281 * @return string The HTML code for the TCEform field
2282 */
2283 function getSingleField_typeNone($table, $field, $row, &$PA) {
2284 // Init:
2285 $config = $PA['fieldConf']['config'];
2286 $itemValue = $PA['itemFormElValue'];
2287
2288 return $this->getSingleField_typeNone_render($config, $itemValue);
2289 }
2290
2291 /**
2292 * HTML rendering of a value which is not editable.
2293 *
2294 * @param array Configuration for the display
2295 * @param string The value to display
2296 * @return string The HTML code for the display
2297 * @see getSingleField_typeNone();
2298 */
2299 function getSingleField_typeNone_render($config, $itemValue) {
2300
2301 // is colorScheme[0] the right value?
2302 $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;';
2303
2304 if ($config['format']) {
2305 $itemValue = $this->formatValue($config, $itemValue);
2306 }
2307
2308 $rows = intval($config['rows']);
2309 if ($rows > 1) {
2310 if (!$config['pass_content']) {
2311 $itemValue = nl2br(htmlspecialchars($itemValue));
2312 }
2313 // like textarea
2314 $cols = t3lib_utility_Math::forceIntegerInRange($config['cols'] ? $config['cols'] : 30, 5, $this->maxTextareaWidth);
2315 if (!$config['fixedRows']) {
2316 $origRows = $rows = t3lib_utility_Math::forceIntegerInRange($rows, 1, 20);
2317 if (strlen($itemValue) > $this->charsPerRow * 2) {
2318 $cols = $this->maxTextareaWidth;
2319 $rows = t3lib_utility_Math::forceIntegerInRange(round(strlen($itemValue) / $this->charsPerRow), count(explode(LF, $itemValue)), 20);
2320 if ($rows < $origRows) {
2321 $rows = $origRows;
2322 }
2323 }
2324 }
2325
2326 if ($this->docLarge) {
2327 $cols = round($cols * $this->form_largeComp);
2328 }
2329 $width = ceil($cols * $this->form_rowsToStylewidth);
2330 // hardcoded: 12 is the height of the font
2331 $height = $rows * 12;
2332
2333 $item = '
2334 <div style="' . htmlspecialchars($divStyle . ' overflow:auto; height:' . $height . 'px; width:' . $width . 'px;') . '" class="' . htmlspecialchars($this->formElClass('none')) . '">' .
2335 $itemValue .
2336 '</div>';
2337 } else {
2338 if (!$config['pass_content']) {
2339 $itemValue = htmlspecialchars($itemValue);
2340 }
2341
2342 $cols = $config['cols'] ? $config['cols'] : ($config['size'] ? $config['size'] : $this->maxInputWidth);
2343 if ($this->docLarge) {
2344 $cols = round($cols * $this->form_largeComp);
2345 }
2346 $width = ceil($cols * $this->form_rowsToStylewidth);
2347
2348 // overflow:auto crashes mozilla here. Title tag is usefull when text is longer than the div box (overflow:hidden).
2349 $item = '
2350 <div style="' . htmlspecialchars($divStyle . ' overflow:hidden; width:' . $width . 'px;') . '" class="' . htmlspecialchars($this->formElClass('none')) . '" title="' . $itemValue . '">' .
2351 '<span class="nobr">' . (strcmp($itemValue, '') ? $itemValue : '&nbsp;') . '</span>' .
2352 '</div>';
2353 }
2354
2355 return $item;
2356 }
2357
2358 /**
2359 * Handler for Flex Forms
2360 *
2361 * @param string The table name of the record
2362 * @param string The field name which this element is supposed to edit
2363 * @param array The record data array where the value(s) for the field can be found
2364 * @param array An array with additional configuration options.
2365 * @return string The HTML code for the TCEform field
2366 */
2367 function getSingleField_typeFlex($table, $field, $row, &$PA) {
2368
2369 // Data Structure:
2370 $dataStructArray = t3lib_BEfunc::getFlexFormDS($PA['fieldConf']['config'], $row, $table);
2371 $item = '';
2372
2373 // Manipulate Flexform DS via TSConfig and group access lists
2374 if (is_array($dataStructArray)) {
2375 $flexFormHelper = t3lib_div::makeInstance('t3lib_TCEforms_Flexforms');
2376 $dataStructArray = $flexFormHelper->modifyFlexFormDS($dataStructArray, $table, $field, $row, $PA['fieldConf']);
2377 unset($flexFormHelper);
2378 }
2379
2380 // Get data structure:
2381 if (is_array($dataStructArray)) {
2382
2383 // Get data:
2384 $xmlData = $PA['itemFormElValue'];
2385 $xmlHeaderAttributes = t3lib_div::xmlGetHeaderAttribs($xmlData);
2386 $storeInCharset = strtolower($xmlHeaderAttributes['encoding']);
2387 if ($storeInCharset) {
2388 $currentCharset = $GLOBALS['LANG']->charSet;
2389 $xmlData = $GLOBALS['LANG']->csConvObj->conv($xmlData, $storeInCharset, $currentCharset, 1);
2390 }
2391 $editData = t3lib_div::xml2array($xmlData);
2392 if (!is_array($editData)) { // Must be XML parsing error...
2393 $editData = array();
2394 } elseif (!isset($editData['meta']) || !is_array($editData['meta'])) {
2395 $editData['meta'] = array();
2396 }
2397
2398 // Find the data structure if sheets are found:
2399 $sheet = $editData['meta']['currentSheetId'] ? $editData['meta']['currentSheetId'] : 'sDEF'; // Sheet to display
2400
2401 // Create sheet menu:
2402 //TODO; Why is this commented out?
2403 // if (is_array($dataStructArray['sheets'])) {
2404 // #$item.=$this->getSingleField_typeFlex_sheetMenu($dataStructArray['sheets'], $PA['itemFormElName'].'[meta][currentSheetId]', $sheet).'<br />';
2405 // }
2406
2407 // Create language menu:
2408 $langChildren = $dataStructArray['meta']['langChildren'] ? 1 : 0;
2409 $langDisabled = $dataStructArray['meta']['langDisable'] ? 1 : 0;
2410
2411 $editData['meta']['currentLangId'] = array();
2412
2413 // Look up page overlays:
2414 $checkPageLanguageOverlay = $GLOBALS['BE_USER']->getTSConfigVal('options.checkPageLanguageOverlay') ? TRUE : FALSE;
2415 if ($checkPageLanguageOverlay) {
2416 $pageOverlays = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
2417 '*',
2418 'pages_language_overlay',
2419 'pid=' . intval($row['pid']) .
2420 t3lib_BEfunc::deleteClause('pages_language_overlay') .
2421 t3lib_BEfunc::versioningPlaceholderClause('pages_language_overlay'),
2422 '',
2423 '',
2424 '',
2425 'sys_language_uid'
2426 );
2427 }
2428 $languages = $this->getAvailableLanguages();
2429
2430 foreach ($languages as $lInfo) {
2431 if ($GLOBALS['BE_USER']->checkLanguageAccess($lInfo['uid']) && (!$checkPageLanguageOverlay || $lInfo['uid'] <= 0 || is_array($pageOverlays[$lInfo['uid']]))) {
2432 $editData['meta']['currentLangId'][] = $lInfo['ISOcode'];
2433 }
2434 }
2435 if (!is_array($editData['meta']['currentLangId']) || !count($editData['meta']['currentLangId'])) {
2436 $editData['meta']['currentLangId'] = array('DEF');
2437 }
2438
2439 $editData['meta']['currentLangId'] = array_unique($editData['meta']['currentLangId']);
2440
2441 //TODO: Why is this commented out?
2442 // if (!$langDisabled && count($languages) > 1) {
2443 // $item.=$this->getSingleField_typeFlex_langMenu($languages, $PA['itemFormElName'].'[meta][currentLangId]', $editData['meta']['currentLangId']).'<br />';
2444 // }
2445
2446 $PA['_noEditDEF'] = FALSE;
2447 if ($langChildren || $langDisabled) {
2448 $rotateLang = array('DEF');
2449 } else {
2450 if (!in_array('DEF', $editData['meta']['currentLangId'])) {
2451 array_unshift($editData['meta']['currentLangId'], 'DEF');
2452 $PA['_noEditDEF'] = TRUE;
2453 }
2454 $rotateLang = $editData['meta']['currentLangId'];
2455 }
2456
2457 // Tabs sheets
2458 if (is_array($dataStructArray['sheets'])) {
2459 $tabsToTraverse = array_keys($dataStructArray['sheets']);
2460 } else {
2461 $tabsToTraverse = array($sheet);
2462 }
2463
2464 foreach ($rotateLang as $lKey) {
2465 if (!$langChildren && !$langDisabled) {
2466 $item .= '<strong>' . $this->getLanguageIcon($table, $row, 'v' . $lKey) . $lKey . ':</strong>';
2467 }
2468
2469 $tabParts = array();
2470 foreach ($tabsToTraverse as $sheet) {
2471 list ($dataStruct, $sheet) = t3lib_div::resolveSheetDefInDS($dataStructArray, $sheet);
2472
2473 // Render sheet:
2474 if (is_array($dataStruct['ROOT']) && is_array($dataStruct['ROOT']['el'])) {
2475 $lang = 'l' . $lKey; // Default language, other options are "lUK" or whatever country code (independant of system!!!)
2476 $PA['_valLang'] = $langChildren && !$langDisabled ? $editData['meta']['currentLangId'] : 'DEF'; // Default language, other options are "lUK" or whatever country code (independant of system!!!)
2477 $PA['_lang'] = $lang;
2478 // Assemble key for loading the correct CSH file
2479 $dsPointerFields = t3lib_div::trimExplode(',', $GLOBALS['TCA'][$table]['columns'][$field]['config']['ds_pointerField'], TRUE);
2480 $PA['_cshKey'] = $table . '.' . $field;
2481 foreach ($dsPointerFields as $key) {
2482 $PA['_cshKey'] .= '.' . $row[$key];
2483 }
2484
2485 // Push the sheet level tab to DynNestedStack
2486 if (is_array($dataStructArray['sheets'])) {
2487 $tabIdentString = $GLOBALS['TBE_TEMPLATE']->getDynTabMenuId('TCEFORMS:flexform:' . $PA['itemFormElName'] . $PA['_lang']);
2488 $this->pushToDynNestedStack('tab', $tabIdentString . '-' . (count($tabParts) + 1));
2489 }
2490 // Render flexform:
2491 $tRows = $this->getSingleField_typeFlex_draw(
2492 $dataStruct['ROOT']['el'],
2493 $editData['data'][$sheet][$lang],
2494 $table,
2495 $field,
2496 $row,
2497 $PA,
2498 '[data][' . $sheet . '][' . $lang . ']'
2499 );
2500 $sheetContent = '<div class="typo3-TCEforms-flexForm">' . $tRows . '</div>';
2501
2502
2503 // Pop the sheet level tab from DynNestedStack
2504 if (is_array($dataStructArray['sheets'])) {
2505 $this->popFromDynNestedStack('tab', $tabIdentString . '-' . (count($tabParts) + 1));
2506 }
2507 } else {
2508 $sheetContent = 'Data Structure ERROR: No ROOT element found for sheet "' . $sheet . '".';
2509 }
2510
2511 // Add to tab:
2512 $tabParts[] = array(
2513 'label' => ($dataStruct['ROOT']['TCEforms']['sheetTitle'] ? $this->sL($dataStruct['ROOT']['TCEforms']['sheetTitle']) : $sheet),
2514 'description' => ($dataStruct['ROOT']['TCEforms']['sheetDescription'] ? $this->sL($dataStruct['ROOT']['TCEforms']['sheetDescription']) : ''),
2515 'linkTitle' => ($dataStruct['ROOT']['TCEforms']['sheetShortDescr'] ? $this->sL($dataStruct['ROOT']['TCEforms']['sheetShortDescr']) : ''),
2516 'content' => $sheetContent
2517 );
2518 }
2519
2520 if (is_array($dataStructArray['sheets'])) {
2521 $dividersToTabsBehaviour = (isset($GLOBALS['TCA'][$table]['ctrl']['dividers2tabs']) ? $GLOBALS['TCA'][$table]['ctrl']['dividers2tabs'] : 1);
2522 $item .= $this->getDynTabMenu($tabParts, 'TCEFORMS:flexform:' . $PA['itemFormElName'] . $PA['_lang'], $dividersToTabsBehaviour);
2523 } else {
2524 $item .= $sheetContent;
2525 }
2526 }
2527 } else {
2528 $item = 'Data Structure ERROR: ' . $dataStructArray;
2529 }
2530
2531 return $item;
2532 }
2533
2534 /**
2535 * Creates the language menu for FlexForms:
2536 *
2537 * @param [type] $languages: ...
2538 * @param [type] $elName: ...
2539 * @param [type] $selectedLanguage: ...
2540 * @param [type] $multi: ...
2541 * @return string HTML for menu
2542 */
2543 function getSingleField_typeFlex_langMenu($languages, $elName, $selectedLanguage, $multi = 1) {
2544 $opt = array();
2545 foreach ($languages as $lArr) {
2546 $opt[] = '<option value="' . htmlspecialchars($lArr['ISOcode']) . '"' . (in_array($lArr['ISOcode'], $selectedLanguage) ? ' selected="selected"' : '') . '>' . htmlspecialchars($lArr['title']) . '</option>';
2547 }
2548
2549 $output = '<select id="' . uniqid('tceforms-multiselect-') . ' class="tceforms-select tceforms-multiselect tceforms-flexlangmenu" name="' . $elName . '[]"' . ($multi ? ' multiple="multiple" size="' . count($languages) . '"' : '') . '>' . implode('', $opt) . '</select>';
2550
2551 return $output;
2552 }
2553
2554 /**
2555 * Creates the menu for selection of the sheets:
2556 *
2557 * @param array Sheet array for which to render the menu
2558 * @param string Form element name of the field containing the sheet pointer
2559 * @param string Current sheet key
2560 * @return string HTML for menu
2561 */
2562 function getSingleField_typeFlex_sheetMenu($sArr, $elName, $sheetKey) {
2563
2564 $tCells = array();
2565 $pct = round(100 / count($sArr));
2566 foreach ($sArr as $sKey => $sheetCfg) {
2567 if ($GLOBALS['BE_USER']->jsConfirmation(1)) {
2568 $onClick = 'if (confirm(TBE_EDITOR.labels.onChangeAlert) && TBE_EDITOR.checkSubmit(-1)){' . $this->elName($elName) . ".value='" . $sKey . "'; TBE_EDITOR.submitForm()};";
2569 } else {
2570 $onClick = 'if(TBE_EDITOR.checkSubmit(-1)){ ' . $this->elName($elName) . ".value='" . $sKey . "'; TBE_EDITOR.submitForm();}";
2571 }
2572
2573
2574 $tCells[] = '<td width="' . $pct . '%" style="' . ($sKey == $sheetKey ? 'background-color: #9999cc; font-weight: bold;' : 'background-color: #aaaaaa;') . ' cursor: hand;" onclick="' . htmlspecialchars($onClick) . '" align="center">' .
2575 ($sheetCfg['ROOT']['TCEforms']['sheetTitle'] ? $this->sL($sheetCfg['ROOT']['TCEforms']['sheetTitle']) : $sKey) .
2576 '</td>';
2577 }
2578
2579 return '<table border="0" cellpadding="0" cellspacing="2" class="typo3-TCEforms-flexForm-sheetMenu"><tr>' . implode('', $tCells) . '</tr></table>';
2580 }
2581
2582 /**
2583 * Recursive rendering of flexforms
2584 *
2585 * @param array (part of) Data Structure for which to render. Keys on first level is flex-form fields
2586 * @param array (part of) Data array of flexform corresponding to the input DS. Keys on first level is flex-form field names
2587 * @param string Table name, eg. tt_content
2588 * @param string Field name, eg. tx_templavoila_flex
2589 * @param array The particular record from $table in which the field $field is found
2590 * @param array Array of standard information for rendering of a form field in TCEforms, see other rendering functions too
2591 * @param string Form field prefix, eg. "[data][sDEF][lDEF][...][...]"
2592 * @param integer Indicates nesting level for the function call
2593 * @param string Prefix for ID-values
2594 * @param boolean Defines whether the next flexform level is open or closed. Comes from _TOGGLE pseudo field in FlexForm xml.
2595 * @return string HTMl code for form.
2596 */
2597 function getSingleField_typeFlex_draw($dataStruct, $editData, $table, $field, $row, &$PA, $formPrefix = '', $level = 0, $idPrefix = 'ID', $toggleClosed = FALSE) {
2598
2599 $output = '';
2600 $mayRestructureFlexforms = $GLOBALS['BE_USER']->checkLanguageAccess(0);
2601
2602 // Data Structure array must be ... and array of course...
2603 if (is_array($dataStruct)) {
2604 foreach ($dataStruct as $key => $value) { // Traversing fields in structure:
2605 if (is_array($value)) { // The value of each entry must be an array.
2606
2607 // ********************
2608 // Making the row:
2609 // ********************
2610 // Title of field:
2611 $theTitle = htmlspecialchars(t3lib_div::fixed_lgd_cs($this->sL($value['tx_templavoila']['title']), 30));
2612
2613 // If it's a "section" or "container":
2614 if ($value['type'] == 'array') {
2615
2616 // Creating IDs for form fields:
2617 // It's important that the IDs "cascade" - otherwise we can't dynamically expand the flex form because this relies on simple string substitution of the first parts of the id values.
2618 $thisId = t3lib_div::shortMd5(uniqid('id', TRUE)); // This is a suffix used for forms on this level
2619 $idTagPrefix = $idPrefix . '-' . $thisId; // $idPrefix is the prefix for elements on lower levels in the hierarchy and we combine this with the thisId value to form a new ID on this level.
2620
2621 // If it's a "section" containing other elements:
2622 if ($value['section']) {
2623
2624 // Load script.aculo.us if flexform sections can be moved by drag'n'drop:
2625 $GLOBALS['SOBE']->doc->getPageRenderer()->loadScriptaculous();
2626 // Render header of section:
2627 $output .= '<div class="t3-form-field-label-flexsection"><strong>' . $theTitle . '</strong></div>';
2628
2629 // Render elements in data array for section:
2630 $tRows = array();
2631 $cc = 0;
2632 if (is_array($editData[$key]['el'])) {
2633 foreach ($editData[$key]['el'] as $k3 => $v3) {
2634 $cc = $k3;
2635 if (is_array($v3)) {
2636 $theType = key($v3);
2637 $theDat = $v3[$theType];
2638 $newSectionEl = $value['el'][$theType];
2639 if (is_array($newSectionEl)) {
2640 $tRows[] = $this->getSingleField_typeFlex_draw(
2641 array($theType => $newSectionEl),
2642 array($theType => $theDat),
2643 $table,
2644 $field,
2645 $row,
2646 $PA,
2647 $formPrefix . '[' . $key . '][el][' . $cc . ']',
2648 $level + 1,