32d6dbdde65e2ba3b2f872ec0fe28f5e9e33336e
[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:310px;'; // 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 * Initialize various internal variables.
235 *
236 * @return void
237 */
238 function initDefaultBEmode() {
239 $this->prependFormFieldNames = 'data';
240 $this->formName = 'editform';
241 $this->setNewBEDesign();
242 $this->docLarge = ($GLOBALS['BE_USER']->uc['edit_wideDocument'] ? 1 : 0);
243 $this->edit_showFieldHelp = $GLOBALS['BE_USER']->uc['edit_showFieldHelp'];
244
245 $this->edit_docModuleUpload = $GLOBALS['BE_USER']->uc['edit_docModuleUpload'];
246
247 $this->inline->init($this);
248 $this->suggest->init($this);
249 }
250
251
252 /*******************************************************
253 *
254 * Rendering the forms, fields etc
255 *
256 *******************************************************/
257
258 /**
259 * Will return the TCEform element for just a single field from a record.
260 * The field must be listed in the currently displayed fields (as found in [types][showitem]) for the record.
261 * This also means that the $table/$row supplied must be complete so the list of fields to show can be found correctly
262 *
263 * @param string The table name
264 * @param array The record from the table for which to render a field.
265 * @param string The field name to return the TCEform element for.
266 * @return string HTML output
267 * @see getMainFields()
268 */
269 function getSoloField($table, $row, $theFieldToReturn) {
270 if ($GLOBALS['TCA'][$table]) {
271 t3lib_div::loadTCA($table);
272 $typeNum = $this->getRTypeNum($table, $row);
273 if ($GLOBALS['TCA'][$table]['types'][$typeNum]) {
274 $itemList = $GLOBALS['TCA'][$table]['types'][$typeNum]['showitem'];
275 if ($itemList) {
276 $fields = t3lib_div::trimExplode(',', $itemList, 1);
277 $excludeElements = $this->excludeElements = $this->getExcludeElements($table, $row, $typeNum);
278
279 foreach ($fields as $fieldInfo) {
280 $parts = explode(';', $fieldInfo);
281
282 $theField = trim($parts[0]);
283 if (!in_array($theField, $excludeElements) && !strcmp($theField, $theFieldToReturn)) {
284 if ($GLOBALS['TCA'][$table]['columns'][$theField]) {
285 $sField = $this->getSingleField($table, $theField, $row, $parts[1], 1, $parts[3], $parts[2]);
286 return $sField['ITEM'];
287 }
288 }
289 }
290 }
291 }
292 }
293 }
294
295 /**
296 * Based on the $table and $row of content, this displays the complete TCEform for the record.
297 * 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.
298 *
299 * @param string $table The table name
300 * @param array $row The record from the table for which to render a field.
301 * @param integer $depth Depth level
302 * @param array $overruleTypesArray Overrule types array. Can be used to override the showitem etc. configuration for the TCA types of the table. Can contain all settings which are possible in the TCA 'types' section. See e.g. $TCA['tt_content']['types'].
303 * @return string HTML output
304 * @see getSoloField()
305 */
306 function getMainFields($table, array $row, $depth = 0, array $overruleTypesArray = array()) {
307 $this->renderDepth = $depth;
308
309 // Init vars:
310 $out_array = array(array());
311 $out_array_meta = array(array(
312 'title' => $this->getLL('l_generalTab')
313 ));
314
315 $out_pointer = 0;
316 $out_sheet = 0;
317 $this->palettesRendered = array();
318 $this->palettesRendered[$this->renderDepth][$table] = array();
319
320 // Hook: getMainFields_preProcess (requested by Thomas Hempel for use with the "dynaflex" extension)
321 foreach ($this->hookObjectsMainFields as $hookObj) {
322 if (method_exists($hookObj, 'getMainFields_preProcess')) {
323 $hookObj->getMainFields_preProcess($table, $row, $this);
324 }
325 }
326
327 if ($GLOBALS['TCA'][$table]) {
328
329 // Load the full TCA for the table.
330 t3lib_div::loadTCA($table);
331
332 // Get dividers2tabs setting from TCA of the current table:
333 $dividers2tabs =& $GLOBALS['TCA'][$table]['ctrl']['dividers2tabs'];
334
335 // Load the description content for the table.
336 if ($this->edit_showFieldHelp || $this->doLoadTableDescr($table)) {
337 $GLOBALS['LANG']->loadSingleTableDescription($table);
338 }
339 // Get the current "type" value for the record.
340 $typeNum = $this->getRTypeNum($table, $row);
341
342 // Find the list of fields to display:
343 if ($GLOBALS['TCA'][$table]['types'][$typeNum]) {
344 $itemList = $GLOBALS['TCA'][$table]['types'][$typeNum]['showitem'];
345 if (is_array($overruleTypesArray) && isset($overruleTypesArray[$typeNum]['showitem'])) {
346 $itemList = $overruleTypesArray[$typeNum]['showitem'];
347 }
348 if ($itemList) { // If such a list existed...
349 // Explode the field list and possibly rearrange the order of the fields, if configured for
350 $fields = t3lib_div::trimExplode(',', $itemList, 1);
351 if ($this->fieldOrder) {
352 $fields = $this->rearrange($fields);
353 }
354
355 // Get excluded fields, added fiels and put it together:
356 $excludeElements = $this->excludeElements = $this->getExcludeElements($table, $row, $typeNum);
357 $fields = $this->mergeFieldsWithAddedFields($fields, $this->getFieldsToAdd($table, $row, $typeNum));
358
359 // If TCEforms will render a tab menu in the next step, push the name to the tab stack:
360 $tabIdentString = '';
361 $tabIdentStringMD5 = '';
362 if (strstr($itemList, '--div--') !== FALSE && $this->enableTabMenu && $dividers2tabs) {
363 $tabIdentString = 'TCEforms:' . $table . ':' . $row['uid'];
364 $tabIdentStringMD5 = $GLOBALS['TBE_TEMPLATE']->getDynTabMenuId($tabIdentString);
365 // Remember that were currently working on the general tab:
366 if (isset($fields[0]) && strpos($fields[0], '--div--') !== 0) {
367 $this->pushToDynNestedStack('tab', $tabIdentStringMD5 . '-1');
368 }
369 }
370
371 // Traverse the fields to render:
372 $cc = 0;
373 foreach ($fields as $fieldInfo) {
374 // Exploding subparts of the field configuration:
375 $parts = explode(';', $fieldInfo);
376
377 // Getting the style information out:
378 $color_style_parts = t3lib_div::trimExplode('-', $parts[4]);
379 if (strcmp($color_style_parts[0], '')) {
380 $this->setColorScheme($GLOBALS['TBE_STYLES']['colorschemes'][intval($color_style_parts[0])]);
381 }
382 if (strcmp($color_style_parts[1], '')) {
383 $this->fieldStyle = $GLOBALS['TBE_STYLES']['styleschemes'][intval($color_style_parts[1])];
384 if (!isset($this->fieldStyle)) {
385 $this->fieldStyle = $GLOBALS['TBE_STYLES']['styleschemes'][0];
386 }
387 }
388 if (strcmp($color_style_parts[2], '')) {
389 $this->wrapBorder($out_array[$out_sheet], $out_pointer);
390 $this->borderStyle = $GLOBALS['TBE_STYLES']['borderschemes'][intval($color_style_parts[2])];
391 if (!isset($this->borderStyle)) {
392 $this->borderStyle = $GLOBALS['TBE_STYLES']['borderschemes'][0];
393 }
394 }
395
396 // Render the field:
397 $theField = $parts[0];
398 if (!in_array($theField, $excludeElements)) {
399 if ($GLOBALS['TCA'][$table]['columns'][$theField]) {
400 $sFieldPal = '';
401
402 if ($parts[2] && !isset($this->palettesRendered[$this->renderDepth][$table][$parts[2]])) {
403 $sFieldPal = $this->getPaletteFields($table, $row, $parts[2]);
404 $this->palettesRendered[$this->renderDepth][$table][$parts[2]] = 1;
405 }
406 $sField = $this->getSingleField($table, $theField, $row, $parts[1], 0, $parts[3], $parts[2]);
407 if ($sField) {
408 $sField .= $sFieldPal;
409 }
410
411 $out_array[$out_sheet][$out_pointer] .= $sField;
412 } elseif ($theField == '--div--') {
413 if ($cc > 0) {
414 $out_array[$out_sheet][$out_pointer] .= $this->getDivider();
415
416 if ($this->enableTabMenu && $dividers2tabs) {
417 $this->wrapBorder($out_array[$out_sheet], $out_pointer);
418 // Remove last tab entry from the dynNestedStack:
419 $out_sheet++;
420 // Remove the previous sheet from stack (if any):
421 $this->popFromDynNestedStack('tab', $tabIdentStringMD5 . '-' . ($out_sheet));
422 // Remember on which sheet we're currently working:
423 $this->pushToDynNestedStack('tab', $tabIdentStringMD5 . '-' . ($out_sheet + 1));
424 $out_array[$out_sheet] = array();
425 $out_array_meta[$out_sheet]['title'] = $this->sL($parts[1]);
426 // Register newline for Tab
427 $out_array_meta[$out_sheet]['newline'] = ($parts[2] == "newline");
428 }
429 } else { // Setting alternative title for "General" tab if "--div--" is the very first element.
430 $out_array_meta[$out_sheet]['title'] = $this->sL($parts[1]);
431 // Only add the first tab to the dynNestedStack if there are more tabs:
432 if ($tabIdentString && strpos($itemList, '--div--', strlen($fieldInfo))) {
433 $this->pushToDynNestedStack('tab', $tabIdentStringMD5 . '-1');
434 }
435 }
436 } elseif ($theField == '--palette--') {
437 if ($parts[2] && !isset($this->palettesRendered[$this->renderDepth][$table][$parts[2]])) {
438 // render a 'header' if not collapsed
439 if ($GLOBALS['TCA'][$table]['palettes'][$parts[2]]['canNotCollapse'] && $parts[1]) {
440 $out_array[$out_sheet][$out_pointer] .= $this->getPaletteFields($table, $row, $parts[2], $this->sL($parts[1]));
441 } else {
442 $out_array[$out_sheet][$out_pointer] .= $this->getPaletteFields($table, $row, $parts[2], '', '', $this->sL($parts[1]));
443 }
444 $this->palettesRendered[$this->renderDepth][$table][$parts[2]] = 1;
445 }
446 }
447 }
448
449 $cc++;
450 }
451 }
452 }
453 }
454
455 // Hook: getMainFields_postProcess (requested by Thomas Hempel for use with the "dynaflex" extension)
456 foreach ($this->hookObjectsMainFields as $hookObj) {
457 if (method_exists($hookObj, 'getMainFields_postProcess')) {
458 $hookObj->getMainFields_postProcess($table, $row, $this);
459 }
460 }
461
462 // Wrapping a border around it all:
463 $this->wrapBorder($out_array[$out_sheet], $out_pointer);
464
465 // Resetting styles:
466 $this->resetSchemes();
467
468 // Rendering Main palettes, if any
469 $mParr = t3lib_div::trimExplode(',', $GLOBALS['TCA'][$table]['ctrl']['mainpalette']);
470 $i = 0;
471 if (count($mParr)) {
472 foreach ($mParr as $mP) {
473 if (!isset($this->palettesRendered[$this->renderDepth][$table][$mP])) {
474 $temp_palettesCollapsed = $this->palettesCollapsed;
475 $this->palettesCollapsed = 0;
476 $label = ($i == 0 ? $this->getLL('l_generalOptions') : $this->getLL('l_generalOptions_more'));
477 $out_array[$out_sheet][$out_pointer] .= $this->getPaletteFields($table, $row, $mP, $label);
478 $this->palettesCollapsed = $temp_palettesCollapsed;
479 $this->palettesRendered[$this->renderDepth][$table][$mP] = 1;
480 }
481 $this->wrapBorder($out_array[$out_sheet], $out_pointer);
482 $i++;
483 if ($this->renderDepth) {
484 $this->renderDepth--;
485 }
486 }
487 }
488
489 // Return the imploded $out_array:
490 if ($out_sheet > 0) { // There were --div-- dividers around...
491
492 // Create parts array for the tab menu:
493 $parts = array();
494 foreach ($out_array as $idx => $sheetContent) {
495 $content = implode('', $sheetContent);
496 if ($content) {
497 // Wrap content (row) with table-tag, otherwise tab/sheet will be disabled (see getdynTabMenu() )
498 $content = '<table border="0" cellspacing="0" cellpadding="0" width="100%">' . $content . '</table>';
499 }
500 $parts[$idx] = array(
501 'label' => $out_array_meta[$idx]['title'],
502 'content' => $content,
503 'newline' => $out_array_meta[$idx]['newline'], // Newline for this tab/sheet
504 );
505 }
506
507 if (count($parts) > 1) {
508 // Unset the current level of tab menus:
509 $this->popFromDynNestedStack('tab', $tabIdentStringMD5 . '-' . ($out_sheet + 1));
510 $dividersToTabsBehaviour = (isset($GLOBALS['TCA'][$table]['ctrl']['dividers2tabs'])
511 ? $GLOBALS['TCA'][$table]['ctrl']['dividers2tabs']
512 : 1);
513 $output = $this->getDynTabMenu($parts, $tabIdentString, $dividersToTabsBehaviour);
514
515 } else {
516 // If there is only one tab/part there is no need to wrap it into the dynTab code
517 $output = isset($parts[0]) ? trim($parts[0]['content']) : '';
518 }
519
520 $output = '
521 <tr>
522 <td colspan="2">
523 ' . $output . '
524 </td>
525 </tr>';
526
527 } else {
528 // Only one, so just implode:
529 $output = implode('', $out_array[$out_sheet]);
530 }
531
532 return $output;
533 }
534
535 /**
536 * Will return the TCEform elements for a pre-defined list of fields.
537 * 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.
538 * Used for displaying forms for the frontend edit icons for instance.
539 *
540 * @param string The table name
541 * @param array The record array.
542 * @param string Commalist of fields from the table. These will be shown in the specified order in a form.
543 * @return string TCEform elements in a string.
544 */
545 function getListedFields($table, $row, $list) {
546 t3lib_div::loadTCA($table);
547 if ($this->edit_showFieldHelp || $this->doLoadTableDescr($table)) {
548 $GLOBALS['LANG']->loadSingleTableDescription($table);
549 }
550
551 $out = '';
552 $types_fieldConfig = t3lib_BEfunc::getTCAtypes($table, $row, 1);
553
554 $editFieldList = array_unique(t3lib_div::trimExplode(',', $list, 1));
555 foreach ($editFieldList as $theFieldC) {
556 list($theField, $palFields) = preg_split('/\[|\]/', $theFieldC);
557 $theField = trim($theField);
558 $palFields = trim($palFields);
559 if ($GLOBALS['TCA'][$table]['columns'][$theField]) {
560 $parts = t3lib_div::trimExplode(';', $types_fieldConfig[$theField]['origString']);
561 $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.
562 $out .= $sField;
563 } elseif ($theField == '--div--') {
564 $out .= $this->getDivider();
565 }
566 if ($palFields) {
567 $out .= $this->getPaletteFields($table, $row, '', '', implode(',', t3lib_div::trimExplode('|', $palFields, 1)));
568 }
569 }
570
571 return $out;
572 }
573
574 /**
575 * Creates a palette (collection of secondary options).
576 *
577 * @param string The table name
578 * @param array The row array
579 * @param string The palette number/pointer
580 * @param string Header string for the palette (used when in-form). If not set, no header item is made.
581 * @param string Optional alternative list of fields for the palette
582 * @param string Optional Link text for activating a palette (when palettes does not have another form element to belong to).
583 * @return string HTML code.
584 */
585 function getPaletteFields($table, $row, $palette, $header = '', $itemList = '', $collapsedHeader = NULL) {
586 if (!$this->doPrintPalette) {
587 return '';
588 }
589
590 $out = '';
591 $parts = $this->loadPaletteElements($table, $row, $palette, $itemList);
592
593 // Put palette together if there are fields in it:
594 if (count($parts)) {
595
596 $realFields = 0;
597
598 foreach ($parts as $part) {
599 if ($part['NAME'] !== '--linebreak--') {
600 $realFields++;
601 }
602 }
603
604 if ($realFields > 0) {
605
606 if ($header) {
607 $out .= $this->intoTemplate(
608 array('HEADER' => htmlspecialchars($header)),
609 $this->palFieldTemplateHeader
610 );
611 }
612
613 $collapsed = $this->isPalettesCollapsed($table, $palette);
614
615 // check if the palette is a hidden palette
616 $isHiddenPalette = !empty($GLOBALS['TCA'][$table]['palettes'][$palette]['isHiddenPalette']);
617
618 $thePalIcon = '';
619 if ($collapsed && $collapsedHeader !== NULL && !$isHiddenPalette) {
620 list($thePalIcon,) = $this->wrapOpenPalette(
621 t3lib_iconWorks::getSpriteIcon(
622 'actions-system-options-view',
623 array('title' => htmlspecialchars($this->getLL('l_moreOptions')))
624 ), $table, $row, $palette, 1);
625 $thePalIcon = '<span style="margin-left: 20px;">' . $thePalIcon . $collapsedHeader . '</span>';
626 }
627
628 $paletteHtml = $this->wrapPaletteField($this->printPalette($parts), $table, $row, $palette, $collapsed);
629
630 $out .= $this->intoTemplate(
631 array('PALETTE' => $thePalIcon . $paletteHtml),
632 $this->palFieldTemplate
633 );
634 }
635 }
636 return $out;
637 }
638
639 /**
640 * Returns the form HTML code for a database table field.
641 *
642 * @param string The table name
643 * @param string The field name
644 * @param array The record to edit from the database table.
645 * @param string Alternative field name label to show.
646 * @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).
647 * @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.
648 * @param integer The palette pointer.
649 * @return mixed String (normal) or array (palettes)
650 */
651 function getSingleField($table, $field, $row, $altName = '', $palette = 0, $extra = '', $pal = 0) {
652
653 // Hook: getSingleField_preProcess
654 foreach ($this->hookObjectsSingleField as $hookObj) {
655 if (method_exists($hookObj, 'getSingleField_preProcess')) {
656 $hookObj->getSingleField_preProcess($table, $field, $row, $altName, $palette, $extra, $pal, $this);
657 }
658 }
659
660 $out = '';
661 $PA = array();
662 $PA['altName'] = $altName;
663 $PA['palette'] = $palette;
664 $PA['extra'] = $extra;
665 $PA['pal'] = $pal;
666
667 // Make sure to load full $GLOBALS['TCA'] array for the table:
668 t3lib_div::loadTCA($table);
669
670 // Get the TCA configuration for the current field:
671 $PA['fieldConf'] = $GLOBALS['TCA'][$table]['columns'][$field];
672 $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
673
674 $skipThisField = $this->inline->skipField($table, $field, $row, $PA['fieldConf']['config']);
675
676 // Now, check if this field is configured and editable (according to excludefields + other configuration)
677 if (is_array($PA['fieldConf']) &&
678 !$skipThisField &&
679 (!$PA['fieldConf']['exclude'] || $GLOBALS['BE_USER']->check('non_exclude_fields', $table . ':' . $field)) &&
680 $PA['fieldConf']['config']['form_type'] != 'passthrough' &&
681 ($this->RTEenabled || !$PA['fieldConf']['config']['showIfRTE']) &&
682 (!$PA['fieldConf']['displayCond'] || $this->isDisplayCondition($PA['fieldConf']['displayCond'], $row)) &&
683 (!$GLOBALS['TCA'][$table]['ctrl']['languageField'] || $PA['fieldConf']['l10n_display'] || strcmp($PA['fieldConf']['l10n_mode'], 'exclude') || $row[$GLOBALS['TCA'][$table]['ctrl']['languageField']] <= 0) &&
684 (!$GLOBALS['TCA'][$table]['ctrl']['languageField'] || !$this->localizationMode || $this->localizationMode === $PA['fieldConf']['l10n_cat'])
685 ) {
686
687
688 // Fetching the TSconfig for the current table/field. This includes the $row which means that
689 $PA['fieldTSConfig'] = $this->setTSconfig($table, $row, $field);
690
691 // If the field is NOT disabled from TSconfig (which it could have been) then render it
692 if (!$PA['fieldTSConfig']['disabled']) {
693 // Override fieldConf by fieldTSconfig:
694 $PA['fieldConf']['config'] = $this->overrideFieldConf($PA['fieldConf']['config'], $PA['fieldTSConfig']);
695
696 // Init variables:
697 $PA['itemFormElName'] = $this->prependFormFieldNames . '[' . $table . '][' . $row['uid'] . '][' . $field . ']'; // Form field name
698 $PA['itemFormElName_file'] = $this->prependFormFieldNames_file . '[' . $table . '][' . $row['uid'] . '][' . $field . ']'; // Form field name, in case of file uploads
699 $PA['itemFormElValue'] = $row[$field]; // The value to show in the form field.
700 $PA['itemFormElID'] = $this->prependFormFieldNames . '_' . $table . '_' . $row['uid'] . '_' . $field;
701
702 // set field to read-only if configured for translated records to show default language content as readonly
703 if ($PA['fieldConf']['l10n_display']
704 && t3lib_div::inList($PA['fieldConf']['l10n_display'], 'defaultAsReadonly')
705 && $row[$GLOBALS['TCA'][$table]['ctrl']['languageField']] > 0) {
706 $PA['fieldConf']['config']['readOnly'] = TRUE;
707 $PA['itemFormElValue'] = $this->defaultLanguageData[$table . ':' . $row['uid']][$field];
708 }
709
710 if(strpos($GLOBALS['TCA'][$table]['ctrl']['type'], ':') === FALSE) {
711 $typeField = $GLOBALS['TCA'][$table]['ctrl']['type'];
712 } else {
713 $typeField = substr($GLOBALS['TCA'][$table]['ctrl']['type'], 0, strpos($GLOBALS['TCA'][$table]['ctrl']['type'],':'));
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, $typeField))
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 $cssClasses[] = 'hasDefaultValue';
1055 $item .= '<input type="text" ' .
1056 $this->getPlaceholderAttribute($table, $field, $config, $row) .
1057 'id="' . $inputId . '" ' .
1058 'class="' . implode(' ', $cssClasses) . '" ' .
1059 'name="' . $PA['itemFormElName'] . '_hr" ' .
1060 'value=""' .
1061 'style="' . $cssStyle . '" ' .
1062 'maxlength="' . $mLgd . '" ' .
1063 'onchange="' . htmlspecialchars($iOnChange) . '"' .
1064 $PA['onFocus'] .
1065 ' />'; // This is the EDITABLE form field.
1066 $item .= '<input type="hidden" name="' . $PA['itemFormElName'] . '" value="' .
1067 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.
1068 $item .= $fieldAppendix . '</span><div style="clear:both;"></div>';
1069 $this->extJSCODE .= 'typo3form.fieldSet(' . $paramsList . ');';
1070
1071 // going through all custom evaluations configured for this field
1072 foreach ($evalList as $evalData) {
1073 if (t3lib_div::hasValidClassPrefix($evalData)) {
1074 $evalObj = t3lib_div::getUserObj($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tce']['formevals'][$evalData] . ':&' . $evalData);
1075 if (is_object($evalObj) && method_exists($evalObj, 'returnFieldJS')) {
1076 $this->extJSCODE .= "\n\nfunction " . $evalData . "(value) {\n" . $evalObj->returnFieldJS() . "\n}\n";
1077 }
1078 }
1079 }
1080
1081 // Creating an alternative item without the JavaScript handlers.
1082 $altItem = '<input type="hidden" name="' . $PA['itemFormElName'] . '_hr" value="" />';
1083 $altItem .= '<input type="hidden" name="' . $PA['itemFormElName'] . '" value="' . htmlspecialchars($PA['itemFormElValue']) . '" />';
1084
1085 // Wrap a wizard around the item?
1086 $item = $this->renderWizards(array($item, $altItem), $config['wizards'], $table, $row, $field, $PA, $PA['itemFormElName'] . '_hr', $specConf);
1087
1088 return $item;
1089 }
1090
1091 /**
1092 * Generation of TCEform elements of the type "text"
1093 * This will render a <textarea> OR RTE area form field, possibly with various control/validation features
1094 *
1095 * @param string The table name of the record
1096 * @param string The field name which this element is supposed to edit
1097 * @param array The record data array where the value(s) for the field can be found
1098 * @param array An array with additional configuration options.
1099 * @return string The HTML code for the TCEform field
1100 */
1101 function getSingleField_typeText($table, $field, $row, &$PA) {
1102
1103 // Init config:
1104 $config = $PA['fieldConf']['config'];
1105 $evalList = t3lib_div::trimExplode(',', $config['eval'], 1);
1106
1107 if ($this->renderReadonly || $config['readOnly']) {
1108 return $this->getSingleField_typeNone_render($config, $PA['itemFormElValue']);
1109 }
1110
1111 // Setting columns number:
1112 $cols = t3lib_utility_Math::forceIntegerInRange($config['cols'] ? $config['cols'] : 30, 5, $this->maxTextareaWidth);
1113
1114 // Setting number of rows:
1115 $origRows = $rows = t3lib_utility_Math::forceIntegerInRange($config['rows'] ? $config['rows'] : 5, 1, 20);
1116 if (strlen($PA['itemFormElValue']) > $this->charsPerRow * 2) {
1117 $cols = $this->maxTextareaWidth;
1118 $rows = t3lib_utility_Math::forceIntegerInRange(round(strlen($PA['itemFormElValue']) / $this->charsPerRow), count(explode(LF, $PA['itemFormElValue'])), 20);
1119 if ($rows < $origRows) {
1120 $rows = $origRows;
1121 }
1122 }
1123
1124 if (in_array('required', $evalList)) {
1125 $this->requiredFields[$table . '_' . $row['uid'] . '_' . $field] = $PA['itemFormElName'];
1126 }
1127
1128 // Init RTE vars:
1129 $RTEwasLoaded = 0; // Set TRUE, if the RTE is loaded; If not a normal textarea is shown.
1130 $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...
1131
1132 // "Extra" configuration; Returns configuration for the field based on settings found in the "types" fieldlist. Traditionally, this is where RTE configuration has been found.
1133 $specConf = $this->getSpecConfFromString($PA['extra'], $PA['fieldConf']['defaultExtras']);
1134
1135 // Setting up the altItem form field, which is a hidden field containing the value
1136 $altItem = '<input type="hidden" name="' . htmlspecialchars($PA['itemFormElName']) . '" value="' . htmlspecialchars($PA['itemFormElValue']) . '" />';
1137
1138 // If RTE is generally enabled (TYPO3_CONF_VARS and user settings)
1139 if ($this->RTEenabled) {
1140 $p = t3lib_BEfunc::getSpecConfParametersFromArray($specConf['rte_transform']['parameters']);
1141 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.
1142 t3lib_BEfunc::fixVersioningPid($table, $row);
1143 list($tscPID, $thePidValue) = $this->getTSCpid($table, $row['uid'], $row['pid']);
1144
1145 // If the pid-value is not negative (that is, a pid could NOT be fetched)
1146 if ($thePidValue >= 0) {
1147 $RTEsetup = $GLOBALS['BE_USER']->getTSConfig('RTE', t3lib_BEfunc::getPagesTSconfig($tscPID));
1148 $RTEtypeVal = t3lib_BEfunc::getTCAtypeValue($table, $row);
1149 $thisConfig = t3lib_BEfunc::RTEsetup($RTEsetup['properties'], $table, $field, $RTEtypeVal);
1150
1151 if (!$thisConfig['disabled']) {
1152 if (!$this->disableRTE) {
1153 $this->RTEcounter++;
1154
1155 // Find alternative relative path for RTE images/links:
1156 $eFile = t3lib_parsehtml_proc::evalWriteFile($specConf['static_write'], $row);
1157 $RTErelPath = is_array($eFile) ? dirname($eFile['relEditFile']) : '';
1158
1159 // Get RTE object, draw form and set flag:
1160 $RTEobj = t3lib_BEfunc::RTEgetObj();
1161 $item = $RTEobj->drawRTE($this, $table, $field, $row, $PA, $specConf, $thisConfig, $RTEtypeVal, $RTErelPath, $thePidValue);
1162
1163 // Wizard:
1164 $item = $this->renderWizards(array($item, $altItem), $config['wizards'], $table, $row, $field, $PA, $PA['itemFormElName'], $specConf, 1);
1165
1166 $RTEwasLoaded = 1;
1167 } else {
1168 $RTEwouldHaveBeenLoaded = 1;
1169 $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!)';
1170 }
1171 } else {
1172 $this->commentMessages[] = $PA['itemFormElName'] . ': RTE is disabled by the Page TSconfig, "RTE"-key (eg. by RTE.default.disabled=0 or such)';
1173 }
1174 } else {
1175 $this->commentMessages[] = $PA['itemFormElName'] . ': PID value could NOT be fetched. Rare error, normally with new records.';
1176 }
1177 } else {
1178 if (!isset($specConf['richtext'])) {
1179 $this->commentMessages[] = $PA['itemFormElName'] . ': RTE was not configured for this field in TCA-types';
1180 }
1181 if (!(!$p['flag'] || !$row[$p['flag']])) {
1182 $this->commentMessages[] = $PA['itemFormElName'] . ': Field-flag (' . $PA['flag'] . ') has been set to disable RTE!';
1183 }
1184 }
1185 }
1186
1187 // Display ordinary field if RTE was not loaded.
1188 if (!$RTEwasLoaded) {
1189 if ($specConf['rte_only']) { // Show message, if no RTE (field can only be edited with RTE!)
1190 $item = '<p><em>' . htmlspecialchars($this->getLL('l_noRTEfound')) . '</em></p>';
1191 } else {
1192 if ($specConf['nowrap']) {
1193 $wrap = 'off';
1194 } else {
1195 $wrap = ($config['wrap'] ? $config['wrap'] : 'virtual');
1196 }
1197
1198 $classes = array();
1199 if ($specConf['fixed-font']) {
1200 $classes[] = 'fixed-font';
1201 }
1202 if ($specConf['enable-tab']) {
1203 $classes[] = 'enable-tab';
1204 }
1205
1206 $formWidthText = $this->formWidthText($cols, $wrap);
1207
1208 // Extract class attributes from $formWidthText (otherwise it would be added twice to the output)
1209 $res = array();
1210 if (preg_match('/ class="(.+?)"/', $formWidthText, $res)) {
1211 $formWidthText = str_replace(' class="' . $res[1] . '"', '', $formWidthText);
1212 $classes = array_merge($classes, explode(' ', $res[1]));
1213 }
1214
1215 if (count($classes)) {
1216 $class = ' class="tceforms-textarea ' . implode(' ', $classes) . '"';
1217 } else {
1218 $class = 'tceforms-textarea';
1219 }
1220
1221 $evalList = t3lib_div::trimExplode(',', $config['eval'], 1);
1222 foreach ($evalList as $func) {
1223 switch ($func) {
1224 case 'required':
1225 $this->registerRequiredProperty('field', $table . '_' . $row['uid'] . '_' . $field, $PA['itemFormElName']);
1226 break;
1227 default:
1228 if (t3lib_div::hasValidClassPrefix($func)) {
1229 // Pair hook to the one in t3lib_TCEmain::checkValue_input_Eval() and t3lib_TCEmain::checkValue_text_Eval()
1230 $evalObj = t3lib_div::getUserObj($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tce']['formevals'][$func] . ':&' . $func);
1231 if (is_object($evalObj) && method_exists($evalObj, 'deevaluateFieldValue')) {
1232 $_params = array(
1233 'value' => $PA['itemFormElValue']
1234 );
1235 $PA['itemFormElValue'] = $evalObj->deevaluateFieldValue($_params);
1236 }
1237 }
1238 break;
1239 }
1240 }
1241
1242 $iOnChange = implode('', $PA['fieldChangeFunc']);
1243 $item .= '
1244 <textarea ' .
1245 'id="' . uniqid('tceforms-textarea-') . '" ' .
1246 'name="' . $PA['itemFormElName'] . '"' .
1247 $formWidthText .
1248 $class . ' ' .
1249 'rows="' . $rows . '" ' .
1250 'wrap="' . $wrap . '" ' .
1251 'onchange="' . htmlspecialchars($iOnChange) . '"' .
1252 $this->getPlaceholderAttribute($table, $field, $config, $row) .
1253 $PA['onFocus'] . '>' .
1254 t3lib_div::formatForTextarea($PA['itemFormElValue']) .
1255 '</textarea>';
1256 $item = $this->renderWizards(array($item, $altItem), $config['wizards'], $table, $row, $field, $PA, $PA['itemFormElName'], $specConf, $RTEwouldHaveBeenLoaded);
1257 }
1258 }
1259
1260 // Return field HTML:
1261 return $item;
1262 }
1263
1264 /**
1265 * Generation of TCEform elements of the type "check"
1266 * This will render a check-box OR an array of checkboxes
1267 *
1268 * @param string The table name of the record
1269 * @param string The field name which this element is supposed to edit
1270 * @param array The record data array where the value(s) for the field can be found
1271 * @param array An array with additional configuration options.
1272 * @return string The HTML code for the TCEform field
1273 */
1274 function getSingleField_typeCheck($table, $field, $row, &$PA) {
1275 $config = $PA['fieldConf']['config'];
1276
1277 $item = '';
1278 $disabled = '';
1279 if ($this->renderReadonly || $config['readOnly']) {
1280 $disabled = ' disabled="disabled"';
1281 }
1282
1283 // Traversing the array of items:
1284 $selItems = $this->initItemArray($PA['fieldConf']);
1285 if ($config['itemsProcFunc']) {
1286 $selItems = $this->procItems($selItems, $PA['fieldTSConfig']['itemsProcFunc.'], $config, $table, $row, $field);
1287 }
1288
1289 if (!count($selItems)) {
1290 $selItems[] = array('', '');
1291 }
1292 $thisValue = intval($PA['itemFormElValue']);
1293
1294 $cols = intval($config['cols']);
1295 if ($cols > 1) {
1296 $item .= '<table border="0" cellspacing="0" cellpadding="0" class="typo3-TCEforms-checkboxArray">';
1297 for ($c = 0; $c < count($selItems); $c++) {
1298 $p = $selItems[$c];
1299 if (!($c % $cols)) {
1300 $item .= '<tr>';
1301 }
1302 $cBP = $this->checkBoxParams($PA['itemFormElName'], $thisValue, $c, count($selItems), implode('', $PA['fieldChangeFunc']));
1303 $cBName = $PA['itemFormElName'] . '_' . $c;
1304 $cBID = $PA['itemFormElID'] . '_' . $c;
1305 $item .= '<td nowrap="nowrap">' .
1306 '<input type="checkbox"' . $this->insertDefStyle('check') . ' value="1" name="' . $cBName . '"' . $cBP . $disabled . ' id="' . $cBID . '" />' .
1307 $this->wrapLabels('<label for="' . $cBID . '">' . htmlspecialchars($p[0]) . '</label>&nbsp;') .
1308 '</td>';
1309 if (($c % $cols) + 1 == $cols) {
1310 $item .= '</tr>';
1311 }
1312 }
1313 if ($c % $cols) {
1314 $rest = $cols - ($c % $cols);
1315 for ($c = 0; $c < $rest; $c++) {
1316 $item .= '<td></td>';
1317 }
1318 if ($c > 0) {
1319 $item .= '</tr>';
1320 }
1321 }
1322 $item .= '</table>';
1323 } else {
1324 for ($c = 0; $c < count($selItems); $c++) {
1325 $p = $selItems[$c];
1326 $cBP = $this->checkBoxParams($PA['itemFormElName'], $thisValue, $c, count($selItems), implode('', $PA['fieldChangeFunc']));
1327 $cBName = $PA['itemFormElName'] . '_' . $c;
1328 $cBID = $PA['itemFormElID'] . '_' . $c;
1329 $item .= ($c > 0 ? '<br />' : '') .
1330 '<input type="checkbox"' . $this->insertDefStyle('check') . ' value="1" name="' . $cBName . '"' . $cBP . $PA['onFocus'] . $disabled . ' id="' . $cBID . '" />' .
1331 $this->wrapLabels('<label for="' . $cBID . '">' . htmlspecialchars($p[0]) . '</label>');
1332 }
1333 }
1334 if (!$disabled) {
1335 $item .= '<input type="hidden" name="' . $PA['itemFormElName'] . '" value="' . htmlspecialchars($thisValue) . '" />';
1336 }
1337
1338 return $item;
1339 }
1340
1341 /**
1342 * Generation of TCEform elements of the type "radio"
1343 * This will render a series of radio buttons.
1344 *
1345 * @param string The table name of the record
1346 * @param string The field name which this element is supposed to edit
1347 * @param array The record data array where the value(s) for the field can be found
1348 * @param array An array with additional configuration options.
1349 * @return string The HTML code for the TCEform field
1350 */
1351 function getSingleField_typeRadio($table, $field, $row, &$PA) {
1352 $config = $PA['fieldConf']['config'];
1353
1354 $item = '';
1355 $disabled = '';
1356 if ($this->renderReadonly || $config['readOnly']) {
1357 $disabled = ' disabled="disabled"';
1358 }
1359
1360 // Get items for the array:
1361 $selItems = $this->initItemArray($PA['fieldConf']);
1362 if ($config['itemsProcFunc']) {
1363 $selItems = $this->procItems($selItems, $PA['fieldTSConfig']['itemsProcFunc.'], $config, $table, $row, $field);
1364 }
1365
1366 // Traverse the items, making the form elements:
1367 for ($c = 0; $c < count($selItems); $c++) {
1368 $p = $selItems[$c];
1369 $rID = $PA['itemFormElID'] . '_' . $c;
1370 $rOnClick = implode('', $PA['fieldChangeFunc']);
1371 $rChecked = (!strcmp($p[1], $PA['itemFormElValue']) ? ' checked="checked"' : '');
1372 $item .= '<input type="radio"' . $this->insertDefStyle('radio') . ' name="' . $PA['itemFormElName'] . '" value="' . htmlspecialchars($p[1]) . '" onclick="' . htmlspecialchars($rOnClick) . '"' . $rChecked . $PA['onFocus'] . $disabled . ' id="' . $rID . '" />
1373 <label for="' . $rID . '">' . htmlspecialchars($p[0]) . '</label>
1374 <br />';
1375 }
1376
1377 return $item;
1378 }
1379
1380 /**
1381 * Generation of TCEform elements of the type "select"
1382 * This will render a selector box element, or possibly a special construction with two selector boxes. That depends on configuration.
1383 *
1384 * @param string The table name of the record
1385 * @param string The field name which this element is supposed to edit
1386 * @param array The record data array where the value(s) for the field can be found
1387 * @param array An array with additional configuration options.
1388 * @return string The HTML code for the TCEform field
1389 */
1390 function getSingleField_typeSelect($table, $field, $row, &$PA) {
1391
1392 // Field configuration from TCA:
1393 $config = $PA['fieldConf']['config'];
1394
1395 $disabled = '';
1396 if ($this->renderReadonly || $config['readOnly']) {
1397 $disabled = ' disabled="disabled"';
1398 }
1399
1400 // "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/.
1401 $specConf = $this->getSpecConfFromString($PA['extra'], $PA['fieldConf']['defaultExtras']);
1402
1403 // Getting the selector box items from the system
1404 $selItems = $this->addSelectOptionsToItemArray(
1405 $this->initItemArray($PA['fieldConf']),
1406 $PA['fieldConf'],
1407 $this->setTSconfig($table, $row),
1408 $field
1409 );
1410 // Possibly filter some items:
1411 $keepItemsFunc = create_function('$value', 'return $value[1];');
1412 $selItems = t3lib_div::keepItemsInArray($selItems, $PA['fieldTSConfig']['keepItems'], $keepItemsFunc);
1413 // Possibly add some items:
1414 $selItems = $this->addItems($selItems, $PA['fieldTSConfig']['addItems.']);
1415 // Process items by a user function:
1416 if (isset($config['itemsProcFunc']) && $config['itemsProcFunc']) {
1417 $selItems = $this->procItems($selItems, $PA['fieldTSConfig']['itemsProcFunc.'], $config, $table, $row, $field);
1418 }
1419
1420 // Possibly remove some items:
1421 $removeItems = t3lib_div::trimExplode(',', $PA['fieldTSConfig']['removeItems'], 1);
1422 foreach ($selItems as $tk => $p) {
1423
1424 // Checking languages and authMode:
1425 $languageDeny = $GLOBALS['TCA'][$table]['ctrl']['languageField']
1426 && !strcmp($GLOBALS['TCA'][$table]['ctrl']['languageField'], $field)
1427 && !$GLOBALS['BE_USER']->checkLanguageAccess($p[1]);
1428 $authModeDeny = $config['form_type'] == 'select' && $config['authMode'] && !$GLOBALS['BE_USER']->checkAuthMode($table, $field, $p[1], $config['authMode']);
1429 if (in_array($p[1], $removeItems) || $languageDeny || $authModeDeny) {
1430 unset($selItems[$tk]);
1431 } elseif (isset($PA['fieldTSConfig']['altLabels.'][$p[1]])) {
1432 $selItems[$tk][0] = $this->sL($PA['fieldTSConfig']['altLabels.'][$p[1]]);
1433 }
1434
1435 // Removing doktypes with no access:
1436 if (($table === 'pages' || $table === 'pages_language_overlay') && $field === 'doktype') {
1437 if (!($GLOBALS['BE_USER']->isAdmin() || t3lib_div::inList($GLOBALS['BE_USER']->groupData['pagetypes_select'], $p[1]))) {
1438 unset($selItems[$tk]);
1439 }
1440 }
1441 }
1442
1443 // Creating the label for the "No Matching Value" entry.
1444 $nMV_label = isset($PA['fieldTSConfig']['noMatchingValue_label']) ? $this->sL($PA['fieldTSConfig']['noMatchingValue_label']) : '[ ' . $this->getLL('l_noMatchingValue') . ' ]';
1445
1446 // Prepare some values:
1447 $maxitems = intval($config['maxitems']);
1448
1449 // If a SINGLE selector box...
1450 if ($maxitems <= 1 && $config['renderMode'] !== 'tree') {
1451 $item = $this->getSingleField_typeSelect_single($table, $field, $row, $PA, $config, $selItems, $nMV_label);
1452 } elseif (!strcmp($config['renderMode'], 'checkbox')) { // Checkbox renderMode
1453 $item = $this->getSingleField_typeSelect_checkbox($table, $field, $row, $PA, $config, $selItems, $nMV_label);
1454 } elseif (!strcmp($config['renderMode'], 'singlebox')) { // Single selector box renderMode
1455 $item = $this->getSingleField_typeSelect_singlebox($table, $field, $row, $PA, $config, $selItems, $nMV_label);
1456 } elseif (!strcmp($config['renderMode'], 'tree')) { // Tree renderMode
1457 $treeClass = t3lib_div::makeInstance('t3lib_TCEforms_Tree', $this);
1458 $item = $treeClass->renderField($table, $field, $row, $PA, $config, $selItems, $nMV_label);
1459
1460 // Register the required number of elements
1461 $minitems = t3lib_utility_Math::forceIntegerInRange($config['minitems'], 0);
1462 $this->registerRequiredProperty('range', $PA['itemFormElName'], array($minitems, $maxitems, 'imgName' => $table . '_' . $row['uid'] . '_' . $field));
1463 } else { // Traditional multiple selector box:
1464 $item = $this->getSingleField_typeSelect_multiple($table, $field, $row, $PA, $config, $selItems, $nMV_label);
1465 }
1466
1467 // Wizards:
1468 if (!$disabled) {
1469 $altItem = '<input type="hidden" name="' . $PA['itemFormElName'] . '" value="' . htmlspecialchars($PA['itemFormElValue']) . '" />';
1470 $item = $this->renderWizards(array($item, $altItem), $config['wizards'], $table, $row, $field, $PA, $PA['itemFormElName'], $specConf);
1471 }
1472
1473 return $item;
1474 }
1475
1476 /**
1477 * Creates a single-selector box
1478 * (Render function for getSingleField_typeSelect())
1479 *
1480 * @param string See getSingleField_typeSelect()
1481 * @param string See getSingleField_typeSelect()
1482 * @param array See getSingleField_typeSelect()
1483 * @param array See getSingleField_typeSelect()
1484 * @param array (Redundant) content of $PA['fieldConf']['config'] (for convenience)
1485 * @param array Items available for selection
1486 * @param string Label for no-matching-value
1487 * @return string The HTML code for the item
1488 * @see getSingleField_typeSelect()
1489 */
1490 function getSingleField_typeSelect_single($table, $field, $row, &$PA, $config, $selItems, $nMV_label) {
1491 // check against inline uniqueness
1492 $inlineParent = $this->inline->getStructureLevel(-1);
1493 if (is_array($inlineParent) && $inlineParent['uid']) {
1494 if ($inlineParent['config']['foreign_table'] == $table && $inlineParent['config']['foreign_unique'] == $field) {
1495 $uniqueIds = $this->inline->inlineData['unique'][$this->inline->inlineNames['object'] . t3lib_TCEforms_inline::Structure_Separator . $table]['used'];
1496 $PA['fieldChangeFunc']['inlineUnique'] = "inline.updateUnique(this,'" . $this->inline->inlineNames['object'] . t3lib_TCEforms_inline::Structure_Separator . $table . "','" . $this->inline->inlineNames['form'] . "','" . $row['uid'] . "');";
1497 }
1498 // hide uid of parent record for symmetric relations
1499 if ($inlineParent['config']['foreign_table'] == $table && ($inlineParent['config']['foreign_field'] == $field || $inlineParent['config']['symmetric_field'] == $field)) {
1500 $uniqueIds[] = $inlineParent['uid'];
1501 }
1502 }
1503
1504 // Initialization:
1505 $c = 0;
1506 $sI = 0;
1507 $noMatchingValue = 1;
1508 $opt = array();
1509 $selicons = array();
1510 $onlySelectedIconShown = 0;
1511 $size = intval($config['size']);
1512 $selectedStyle = ''; // Style set on <select/>
1513
1514 $item = '';
1515 $disabled = '';
1516 $onChangeIcon = ''; // TODO: icon is used but never assigned
1517
1518 if ($this->renderReadonly || $config['readOnly']) {
1519 $disabled = ' disabled="disabled"';
1520 $onlySelectedIconShown = 1;
1521 }
1522
1523 // Icon configuration:
1524 if ($config['suppress_icons'] == 'IF_VALUE_FALSE') {
1525 $suppressIcons = !$PA['itemFormElValue'] ? 1 : 0;
1526 } elseif ($config['suppress_icons'] == 'ONLY_SELECTED') {
1527 $suppressIcons = 0;
1528 $onlySelectedIconShown = 1;
1529 } elseif ($config['suppress_icons']) {
1530 $suppressIcons = 1;
1531 } else {
1532 $suppressIcons = 0;
1533 }
1534
1535 // Traverse the Array of selector box items:
1536 $optGroupStart = array();
1537 $optGroupOpen = FALSE;
1538 $classesForSelectTag = array();
1539 foreach ($selItems as $p) {
1540 $sM = (!strcmp($PA['itemFormElValue'], $p[1]) ? ' selected="selected"' : '');
1541 if ($sM) {
1542 $sI = $c;
1543 $noMatchingValue = 0;
1544 }
1545
1546 // Getting style attribute value (for icons):
1547 if ($config['iconsInOptionTags']) {
1548 $styleAttrValue = $this->optionTagStyle($p[2]);
1549 if ($sM) {
1550 list($selectIconFile, $selectIconInfo) = $this->getIcon($p[2]);
1551 if (!empty($selectIconInfo)) {
1552 $selectedStyle = ' style="background-image:url(' . $selectIconFile . ');"';
1553 $classesForSelectTag[] = 'typo3-TCEforms-select-selectedItemWithBackgroundImage';
1554 }
1555 }
1556 }
1557
1558 // Compiling the <option> tag:
1559 if (!($p[1] != $PA['itemFormElValue'] && is_array($uniqueIds) && in_array($p[1], $uniqueIds))) {
1560 if (!strcmp($p[1], '--div--')) {
1561 $optGroupStart[0] = $p[0];
1562 if ($config['iconsInOptionTags']) {
1563 $optGroupStart[1] = $this->optgroupTagStyle($p[2]);
1564 } else {
1565 $optGroupStart[1] = $styleAttrValue;
1566 }
1567
1568 } else {
1569 if (count($optGroupStart)) {
1570 if ($optGroupOpen) { // Closing last optgroup before next one starts
1571 $opt[] = '</optgroup>' . LF;
1572 }
1573 $opt[] = '<optgroup label="' . t3lib_div::deHSCentities(htmlspecialchars($optGroupStart[0])) . '"' .
1574 ($optGroupStart[1] ? ' style="' . htmlspecialchars($optGroupStart[1]) . '"' : '') .
1575 ' class="c-divider">' . LF;
1576 $optGroupOpen = TRUE;
1577 $c--;
1578 $optGroupStart = array();
1579 }
1580 $opt[] = '<option value="' . htmlspecialchars($p[1]) . '"' .
1581 $sM .
1582 ($styleAttrValue ? ' style="' . htmlspecialchars($styleAttrValue) . '"' : '') .
1583 '>' . t3lib_div::deHSCentities(($p[0])) . '</option>' . LF;
1584 }
1585 }
1586
1587 // If there is an icon for the selector box (rendered in selicon-table below)...:
1588 // if there is an icon ($p[2]), icons should be shown, and, if only selected are visible, is it selected
1589 if ($p[2] && !$suppressIcons && (!$onlySelectedIconShown || $sM)) {
1590 list($selIconFile, $selIconInfo) = $this->getIcon($p[2]);
1591 if (!empty($selIconInfo)) {
1592 $iOnClick = $this->elName($PA['itemFormElName']) . '.selectedIndex=' . $c . '; ' .
1593 $this->elName($PA['itemFormElName']) . '.style.backgroundImage=' . $this->elName($PA['itemFormElName']) . '.options[' . $c . '].style.backgroundImage; ' .
1594 implode('', $PA['fieldChangeFunc']) . $this->blur() . 'return false;';
1595 } else {
1596 $iOnClick = $this->elName($PA['itemFormElName']) . '.selectedIndex=' . $c . '; ' .
1597 $this->elName($PA['itemFormElName']) . '.className=' . $this->elName($PA['itemFormElName']) . '.options[' . $c . '].className; ' .
1598 implode('', $PA['fieldChangeFunc']) . $this->blur() . 'return false;';
1599 }
1600 $selicons[] = array(
1601 (!$onlySelectedIconShown ? '<a href="#" onclick="' . htmlspecialchars($iOnClick) . '">' : '') .
1602 $this->getIconHtml($p[2], htmlspecialchars($p[0]), htmlspecialchars($p[0])) .
1603 (!$onlySelectedIconShown ? '</a>' : ''),
1604 $c, $sM);
1605 }
1606 $c++;
1607 }
1608
1609 if ($optGroupOpen) { // Closing optgroup if open
1610 $opt[] = '</optgroup>';
1611 $optGroupOpen = FALSE;
1612 }
1613
1614 // No-matching-value:
1615 if ($PA['itemFormElValue'] && $noMatchingValue && !$PA['fieldTSConfig']['disableNoMatchingValueElement'] && !$config['disableNoMatchingValueElement']) {
1616 $nMV_label = @sprintf($nMV_label, $PA['itemFormElValue']);
1617 $opt[] = '<option value="' . htmlspecialchars($PA['itemFormElValue']) . '" selected="selected">' . htmlspecialchars($nMV_label) . '</option>';
1618 }
1619
1620 // Create item form fields:
1621 $sOnChange = 'if (this.options[this.selectedIndex].value==\'--div--\') {this.selectedIndex=' . $sI . ';} ' . implode('', $PA['fieldChangeFunc']);
1622 if (!$disabled) {
1623 $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...
1624 }
1625 if ($config['iconsInOptionTags']) {
1626 $classesForSelectTag[] = 'icon-select';
1627 }
1628 $item .= '<select' . $selectedStyle . ' id="' . uniqid('tceforms-select-') . '" name="' . $PA['itemFormElName'] . '"' .
1629 $this->insertDefStyle('select', implode(' ', $classesForSelectTag)) .
1630 ($size ? ' size="' . $size . '"' : '') .
1631 ' onchange="' . htmlspecialchars($onChangeIcon . $sOnChange) . '"' .
1632 $PA['onFocus'] . $disabled . '>';
1633 $item .= implode('', $opt);
1634 $item .= '</select>';
1635
1636 // Create icon table:
1637 if (count($selicons) && !$config['noIconsBelowSelect']) {
1638 $item .= '<table border="0" cellpadding="0" cellspacing="0" class="typo3-TCEforms-selectIcons">';
1639 $selicon_cols = intval($config['selicon_cols']);
1640 if (!$selicon_cols) {
1641 $selicon_cols = count($selicons);
1642 }
1643 $sR = ceil(count($selicons) / $selicon_cols);
1644 $selicons = array_pad($selicons, $sR * $selicon_cols, '');
1645 for ($sa = 0; $sa < $sR; $sa++) {
1646 $item .= '<tr>';
1647 for ($sb = 0; $sb < $selicon_cols; $sb++) {
1648 $sk = ($sa * $selicon_cols + $sb);
1649 $imgN = 'selIcon_' . $table . '_' . $row['uid'] . '_' . $field . '_' . $selicons[$sk][1];
1650 $imgS = ($selicons[$sk][2] ? $this->backPath . 'gfx/content_selected.gif' : 'clear.gif');
1651 $item .= '<td><img name="' . htmlspecialchars($imgN) . '" src="' . $imgS . '" width="7" height="10" alt="" /></td>';
1652 $item .= '<td>' . $selicons[$sk][0] . '</td>';
1653 }
1654 $item .= '</tr>';
1655 }
1656 $item .= '</table>';
1657 }
1658
1659 return $item;
1660 }
1661
1662 /**
1663 * Creates a checkbox list (renderMode = "checkbox")
1664 * (Render function for getSingleField_typeSelect())
1665 *
1666 * @param string See getSingleField_typeSelect()
1667 * @param string See getSingleField_typeSelect()
1668 * @param array See getSingleField_typeSelect()
1669 * @param array See getSingleField_typeSelect()
1670 * @param array (Redundant) content of $PA['fieldConf']['config'] (for convenience)
1671 * @param array Items available for selection
1672 * @param string Label for no-matching-value
1673 * @return string The HTML code for the item
1674 * @see getSingleField_typeSelect()
1675 */
1676 function getSingleField_typeSelect_checkbox($table, $field, $row, &$PA, $config, $selItems, $nMV_label) {
1677
1678 if (empty($selItems)) {
1679 return '';
1680 }
1681
1682 // Get values in an array (and make unique, which is fine because there can be no duplicates anyway):
1683 $itemArray = array_flip($this->extractValuesOnlyFromValueLabelList($PA['itemFormElValue']));
1684
1685 $item = '';
1686 $disabled = '';
1687 if ($this->renderReadonly || $config['readOnly']) {
1688 $disabled = ' disabled="disabled"';
1689 }
1690
1691 // Traverse the Array of selector box items:
1692 $tRows = array();
1693 $c = 0;
1694 if (!$disabled) {
1695 $sOnChange = implode('', $PA['fieldChangeFunc']);
1696 $setAll = array(); // Used to accumulate the JS needed to restore the original selection.
1697 $unSetAll = array();
1698 foreach ($selItems as $p) {
1699 // Non-selectable element:
1700 if (!strcmp($p[1], '--div--')) {
1701 $selIcon = '';
1702 if (isset($p[2]) && $p[2] != 'empty-emtpy') {
1703 $selIcon = $this->getIconHtml($p[2]) ;
1704 }
1705 $tRows[] = '
1706 <tr class="c-header">
1707 <td colspan="3">' . $selIcon . htmlspecialchars($p[0]) . '</td>
1708 </tr>';
1709 } else {
1710 // Selected or not by default:
1711 $sM = '';
1712 if (isset($itemArray[$p[1]])) {
1713 $sM = ' checked="checked"';
1714 unset($itemArray[$p[1]]);
1715 }
1716
1717 // Icon:
1718 if ($p[2]) {
1719 $selIcon = $p[2];
1720 } else {
1721 $selIcon = t3lib_iconWorks::getSpriteIcon('empty-empty');
1722 }
1723
1724 // Compile row:
1725 $rowId = uniqid('select_checkbox_row_');
1726 $onClickCell = $this->elName($PA['itemFormElName'] . '[' . $c . ']') . '.checked=!' . $this->elName($PA['itemFormElName'] . '[' . $c . ']') . '.checked;';
1727 $onClick = 'this.attributes.getNamedItem("class").nodeValue = ' . $this->elName($PA['itemFormElName'] . '[' . $c . ']') . '.checked ? "c-selectedItem" : "c-unselectedItem";';
1728 $setAll[] = $this->elName($PA['itemFormElName'] . '[' . $c . ']') . '.checked=1;';
1729 $setAll[] .= '$(\'' . $rowId . '\').removeClassName(\'c-unselectedItem\');$(\'' . $rowId . '\').addClassName(\'c-selectedItem\');';
1730 $unSetAll[] = $this->elName($PA['itemFormElName'] . '[' . $c . ']') . '.checked=0;';
1731 $unSetAll[] .= '$(\'' . $rowId . '\').removeClassName(\'c-selectedItem\');$(\'' . $rowId . '\').addClassName(\'c-unselectedItem\');';
1732 $restoreCmd[] = $this->elName($PA['itemFormElName'] . '[' . $c . ']') . '.checked=' . ($sM ? 1 : 0) . ';' .
1733 '$(\'' . $rowId . '\').removeClassName(\'c-selectedItem\');$(\'' . $rowId . '\').removeClassName(\'c-unselectedItem\');' .
1734 '$(\'' . $rowId . '\').addClassName(\'c-' . ($sM ? '' : 'un') . 'selectedItem\');';
1735
1736 // Check if some help text is available
1737 // Since TYPO3 4.5 help text is expected to be an associative array
1738 // with two key, "title" and "description"
1739 // For the sake of backwards compatibility, we test if the help text
1740 // is a string and use it as a description (this could happen if items
1741 // are modified with an itemProcFunc)
1742 $hasHelp = FALSE;
1743 $help = '';
1744 $helpArray = array();
1745 if ((is_array($p[3]) && count($p[3]) > 0) || !empty($p[3])) {
1746 $hasHelp = TRUE;
1747 if (is_array($p[3])) {
1748 $helpArray = $p[3];
1749 } else {
1750 $helpArray['description'] = $p[3];
1751 }
1752 }
1753
1754 $label = t3lib_div::deHSCentities(htmlspecialchars($p[0]));
1755 if ($hasHelp) {
1756 $help = t3lib_BEfunc::wrapInHelp('', '', '', $helpArray);
1757 }
1758
1759 $tRows[] = '
1760 <tr id="' . $rowId . '" class="' . ($sM ? 'c-selectedItem' : 'c-unselectedItem') . '" onclick="' . htmlspecialchars($onClick) . '" style="cursor: pointer;">
1761 <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>
1762 <td class="c-labelCell" onclick="' . htmlspecialchars($onClickCell) . '">' .
1763 $this->getIconHtml($selIcon) .
1764 $label .
1765 '</td>
1766 <td class="c-descr" onclick="' . htmlspecialchars($onClickCell) . '">' . ((empty($help)) ? '' : $help) . '</td>
1767 </tr>';
1768 $c++;
1769 }
1770 }
1771 }
1772
1773 // Remaining values (invalid):
1774 if (count($itemArray) && !$PA['fieldTSConfig']['disableNoMatchingValueElement'] && !$config['disableNoMatchingValueElement']) {
1775 foreach ($itemArray as $theNoMatchValue => $temp) {
1776 // Compile <checkboxes> tag:
1777 array_unshift($tRows, '
1778 <tr class="c-invalidItem">
1779 <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>
1780 <td class="c-labelCell">' .
1781 t3lib_div::deHSCentities(htmlspecialchars(@sprintf($nMV_label, $theNoMatchValue))) .
1782 '</td><td>&nbsp;</td>
1783 </tr>');
1784 $c++;
1785 }
1786 }
1787
1788 // Add an empty hidden field which will send a blank value if all items are unselected.
1789 $item .= '<input type="hidden" name="' . htmlspecialchars($PA['itemFormElName']) . '" value="" />';
1790
1791 // Remaining checkboxes will get their set-all link:
1792 if (count($setAll)) {
1793 $tableHead = '<thead>
1794 <tr class="c-header-checkbox-controls t3-row-header">
1795 <td class="c-checkbox">
1796 <input type="checkbox" class="checkbox" onclick="if (checked) {' . htmlspecialchars(implode('', $setAll) . '} else {' . implode('', $unSetAll) . '}') . '">
1797 </td>
1798 <td colspan="2">
1799 </td>
1800 </tr></thead>';
1801 }
1802 // Implode rows in table:
1803 $item .= '
1804 <table border="0" cellpadding="0" cellspacing="0" class="typo3-TCEforms-select-checkbox">' .
1805 $tableHead .
1806 '<tbody>' . implode('', $tRows) . '</tbody>
1807 </table>
1808 ';
1809
1810 // Add revert icon
1811 if (is_array($restoreCmd)) {
1812 $item .= '<a href="#" onclick="' . implode('', $restoreCmd) . ' return false;' . '">' .
1813 t3lib_iconWorks::getSpriteIcon('actions-edit-undo', array('title' => htmlspecialchars($this->getLL('l_revertSelection')))) . '</a>';
1814 }
1815
1816 return $item;
1817 }
1818
1819 /**
1820 * Creates a selectorbox list (renderMode = "singlebox")
1821 * (Render function for getSingleField_typeSelect())
1822 *
1823 * @param string See getSingleField_typeSelect()
1824 * @param string See getSingleField_typeSelect()
1825 * @param array See getSingleField_typeSelect()
1826 * @param array See getSingleField_typeSelect()
1827 * @param array (Redundant) content of $PA['fieldConf']['config'] (for convenience)
1828 * @param array Items available for selection
1829 * @param string Label for no-matching-value
1830 * @return string The HTML code for the item
1831 * @see getSingleField_typeSelect()
1832 */
1833 function getSingleField_typeSelect_singlebox($table, $field, $row, &$PA, $config, $selItems, $nMV_label) {
1834
1835 // Get values in an array (and make unique, which is fine because there can be no duplicates anyway):
1836 $itemArray = array_flip($this->extractValuesOnlyFromValueLabelList($PA['itemFormElValue']));
1837
1838 $item = '';
1839 $disabled = '';
1840 if ($this->renderReadonly || $config['readOnly']) {
1841 $disabled = ' disabled="disabled"';
1842 }
1843
1844 // Traverse the Array of selector box items:
1845 $opt = array();
1846 $restoreCmd = array(); // Used to accumulate the JS needed to restore the original selection.
1847 $c = 0;
1848 foreach ($selItems as $p) {
1849 // Selected or not by default:
1850 $sM = '';
1851 if (isset($itemArray[$p[1]])) {
1852 $sM = ' selected="selected"';
1853 $restoreCmd[] = $this->elName($PA['itemFormElName'] . '[]') . '.options[' . $c . '].selected=1;';
1854 unset($itemArray[$p[1]]);
1855 }
1856
1857 // Non-selectable element:
1858 $nonSel = '';
1859 if (!strcmp($p[1], '--div--')) {
1860 $nonSel = ' onclick="this.selected=0;" class="c-divider"';
1861 }
1862
1863 // Icon style for option tag:
1864 if ($config['iconsInOptionTags']) {
1865 $styleAttrValue = $this->optionTagStyle($p[2]);
1866 }
1867
1868 // Compile <option> tag:
1869 $opt[] = '<option value="' . htmlspecialchars($p[1]) . '"' .
1870 $sM .
1871 $nonSel .
1872 ($styleAttrValue ? ' style="' . htmlspecialchars($styleAttrValue) . '"' : '') .
1873 '>' . t3lib_div::deHSCentities(htmlspecialchars($p[0])) . '</option>';
1874 $c++;
1875 }
1876
1877 // Remaining values:
1878 if (count($itemArray) && !$PA['fieldTSConfig']['disableNoMatchingValueElement'] && !$config['disableNoMatchingValueElement']) {
1879 foreach ($itemArray as $theNoMatchValue => $temp) {
1880 // Compile <option> tag:
1881 array_unshift($opt, '<option value="' . htmlspecialchars($theNoMatchValue) . '" selected="selected">' . t3lib_div::deHSCentities(htmlspecialchars(@sprintf($nMV_label, $theNoMatchValue))) . '</option>');
1882 }
1883 }
1884
1885 // Compile selector box:
1886 $sOnChange = implode('', $PA['fieldChangeFunc']);
1887 $selector_itemListStyle = isset($config['itemListStyle']) ? ' style="' . htmlspecialchars($config['itemListStyle']) . '"' : ' style="' . $this->defaultMultipleSelectorStyle . '"';
1888 $size = intval($config['size']);
1889 $cssPrefix = ($size === 1) ? 'tceforms-select' : 'tceforms-multiselect';
1890 $size = $config['autoSizeMax'] ? t3lib_utility_Math::forceIntegerInRange(count($selItems) + 1, t3lib_utility_Math::forceIntegerInRange($size, 1), $config['autoSizeMax']) : $size;
1891 $selectBox = '<select id="' . uniqid($cssPrefix) . '" name="' . $PA['itemFormElName'] . '[]"' .
1892 $this->insertDefStyle('select', $cssPrefix) .
1893 ($size ? ' size="' . $size . '"' : '') .
1894 ' multiple="multiple" onchange="' . htmlspecialchars($sOnChange) . '"' .
1895 $PA['onFocus'] .
1896 $selector_itemListStyle .
1897 $disabled . '>
1898 ' .
1899 implode('
1900 ', $opt) . '
1901 </select>';
1902
1903 // Add an empty hidden field which will send a blank value if all items are unselected.
1904 if (!$disabled) {
1905 $item .= '<input type="hidden" name="' . htmlspecialchars($PA['itemFormElName']) . '" value="" />';
1906 }
1907
1908 // Put it all into a table:
1909 $item .= '
1910 <table border="0" cellspacing="0" cellpadding="0" width="1" class="typo3-TCEforms-select-singlebox">
1911 <tr>
1912 <td>
1913 ' . $selectBox . '
1914 <br/>
1915 <em>' .
1916 htmlspecialchars($this->getLL('l_holdDownCTRL')) .
1917 '</em>
1918 </td>
1919 <td valign="top">
1920 <a href="#" onclick="' . htmlspecialchars($this->elName($PA['itemFormElName'] . '[]') . '.selectedIndex=-1;' . implode('', $restoreCmd) . ' return false;') . '" title="' . htmlspecialchars($this->getLL('l_revertSelection')) . '">' .
1921 t3lib_iconWorks::getSpriteIcon('actions-edit-undo') .
1922 '</a>
1923 </td>
1924 </tr>
1925 </table>
1926 ';
1927
1928 return $item;
1929 }
1930
1931 /**
1932 * Creates a multiple-selector box (two boxes, side-by-side)
1933 * (Render function for getSingleField_typeSelect())
1934 *
1935 * @param string See getSingleField_typeSelect()
1936 * @param string See getSingleField_typeSelect()
1937 * @param array See getSingleField_typeSelect()
1938 * @param array See getSingleField_typeSelect()
1939 * @param array (Redundant) content of $PA['fieldConf']['config'] (for convenience)
1940 * @param array Items available for selection
1941 * @param string Label for no-matching-value
1942 * @return string The HTML code for the item
1943 * @see getSingleField_typeSelect()
1944 */
1945 function getSingleField_typeSelect_multiple($table, $field, $row, &$PA, $config, $selItems, $nMV_label) {
1946
1947 $item = '';
1948 $disabled = '';
1949 if ($this->renderReadonly || $config['readOnly']) {
1950 $disabled = ' disabled="disabled"';
1951 }
1952
1953 // Setting this hidden field (as a flag that JavaScript can read out)
1954 if (!$disabled) {
1955 $item .= '<input type="hidden" name="' . $PA['itemFormElName'] . '_mul" value="' . ($config['multiple'] ? 1 : 0) . '" />';
1956 }
1957
1958 // Set max and min items:
1959 $maxitems = t3lib_utility_Math::forceIntegerInRange($config['maxitems'], 0);
1960 if (!$maxitems) {
1961 $maxitems = 100000;
1962 }
1963 $minitems = t3lib_utility_Math::forceIntegerInRange($config['minitems'], 0);
1964
1965 // Register the required number of elements:
1966 $this->registerRequiredProperty('range', $PA['itemFormElName'], array($minitems, $maxitems, 'imgName' => $table . '_' . $row['uid'] . '_' . $field));
1967
1968 // Get "removeItems":
1969 $removeItems = t3lib_div::trimExplode(',', $PA['fieldTSConfig']['removeItems'], 1);
1970
1971 // Get the array with selected items:
1972 $itemArray = t3lib_div::trimExplode(',', $PA['itemFormElValue'], 1);
1973
1974 // Possibly filter some items:
1975 $keepItemsFunc = create_function('$value', '$parts=explode(\'|\',$value,2); return rawurldecode($parts[0]);');
1976 $itemArray = t3lib_div::keepItemsInArray($itemArray, $PA['fieldTSConfig']['keepItems'], $keepItemsFunc);
1977
1978 // Perform modification of the selected items array:
1979 foreach ($itemArray as $tk => $tv) {
1980 $tvP = explode('|', $tv, 2);
1981 $evalValue = $tvP[0];
1982 $isRemoved = in_array($evalValue, $removeItems) || ($config['form_type'] == 'select' && $config['authMode'] && !$GLOBALS['BE_USER']->checkAuthMode($table, $field, $evalValue, $config['authMode']));
1983 if ($isRemoved && !$PA['fieldTSConfig']['disableNoMatchingValueElement'] && !$config['disableNoMatchingValueElement']) {
1984 $tvP[1] = rawurlencode(@sprintf($nMV_label, $evalValue));
1985 } elseif (isset($PA['fieldTSConfig']['altLabels.'][$evalValue])) {
1986 $tvP[1] = rawurlencode($this->sL($PA['fieldTSConfig']['altLabels.'][$evalValue]));
1987 }
1988 if ($tvP[1] == '') {
1989 // Case: flexform, default values supplied, no label provided (bug #9795)
1990 foreach ($selItems as $selItem) {
1991 if ($selItem[1] == $tvP[0]) {
1992 $tvP[1] = html_entity_decode($selItem[0]);
1993 break;
1994 }
1995 }
1996 }
1997 $itemArray[$tk] = implode('|', $tvP);
1998 }
1999 $itemsToSelect = '';
2000
2001 if (!$disabled) {
2002 // Create option tags:
2003 $opt = array();
2004 $styleAttrValue = '';
2005 foreach ($selItems as $p) {
2006 if ($config['iconsInOptionTags']) {
2007 $styleAttrValue = $this->optionTagStyle($p[2]);
2008 }
2009 $opt[] = '<option value="' . htmlspecialchars($p[1]) . '"' .
2010 ($styleAttrValue ? ' style="' . htmlspecialchars($styleAttrValue) . '"' : '') .
2011 ' title="' . $p[0] . '">' . $p[0] . '</option>';
2012 }
2013
2014 // Put together the selector box:
2015 $selector_itemListStyle = isset($config['itemListStyle']) ? ' style="' . htmlspecialchars($config['itemListStyle']) . '"' : ' style="' . $this->defaultMultipleSelectorStyle . '"';
2016 $size = intval($config['size']);
2017 $size = $config['autoSizeMax'] ? t3lib_utility_Math::forceIntegerInRange(count($itemArray) + 1, t3lib_utility_Math::forceIntegerInRange($size, 1), $config['autoSizeMax']) : $size;
2018 if ($config['exclusiveKeys']) {
2019 $sOnChange = 'setFormValueFromBrowseWin(\'' . $PA['itemFormElName']
2020 . '\',this.options[this.selectedIndex].value, this.options[this.selectedIndex].text, this.options[this.selectedIndex].title,\''
2021 . $config['exclusiveKeys'] . '\'); ';
2022 } else {
2023 $sOnChange = 'setFormValueFromBrowseWin(\'' . $PA['itemFormElName']
2024 . '\',this.options[this.selectedIndex].value, this.options[this.selectedIndex].text, this.options[this.selectedIndex].title); ';
2025 }
2026 $sOnChange .= implode('', $PA['fieldChangeFunc']);
2027 $itemsToSelect = '
2028 <select id="' . uniqid('tceforms-multiselect-') . '" name="' . $PA['itemFormElName'] . '_sel"' .
2029 $this->insertDefStyle('select', 'tceforms-multiselect tceforms-itemstoselect') .
2030 ($size ? ' size="' . $size . '"' : '') .
2031 ' onchange="' . htmlspecialchars($sOnChange) . '"' .
2032 $PA['onFocus'] .
2033 $selector_itemListStyle . '>
2034 ' . implode('
2035 ', $opt) . '
2036 </select>';
2037 }
2038
2039 // Pass to "dbFileIcons" function:
2040 $params = array(
2041 'size' => $size,
2042 'autoSizeMax' => t3lib_utility_Math::forceIntegerInRange($config['autoSizeMax'], 0),
2043 'style' => isset($config['selectedListStyle']) ? ' style="' . htmlspecialchars($config['selectedListStyle']) . '"' : ' style="' . $this->defaultMultipleSelectorStyle . '"',
2044 'dontShowMoveIcons' => ($maxitems <= 1),
2045 'maxitems' => $maxitems,
2046 'info' => '',
2047 'headers' => array(
2048 'selector' => $this->getLL('l_selected') . ':<br />',
2049 'items' => $this->getLL('l_items') . ':<br />'
2050 ),
2051 'noBrowser' => 1,
2052 'thumbnails' => $itemsToSelect,
2053 'readOnly' => $disabled
2054 );
2055 $item .= $this->dbFileIcons($PA['itemFormElName'], '', '', $itemArray, '', $params, $PA['onFocus']);
2056
2057 return $item;
2058 }
2059
2060 /**
2061 * Generation of TCEform elements of the type "group"
2062 * This will render a selectorbox into which elements from either the file system or database can be inserted. Relations.
2063 *
2064 * @param string The table name of the record
2065 * @param string The field name which this element is supposed to edit
2066 * @param array The record data array where the value(s) for the field can be found
2067 * @param array An array with additional configuration options.
2068 * @return string The HTML code for the TCEform field
2069 */
2070 function getSingleField_typeGroup($table, $field, $row, &$PA) {
2071 // Init:
2072 $config = $PA['fieldConf']['config'];
2073 $internal_type = $config['internal_type'];
2074 $show_thumbs = $config['show_thumbs'];
2075 $size = intval($config['size']);
2076 $maxitems = t3lib_utility_Math::forceIntegerInRange($config['maxitems'], 0);
2077 if (!$maxitems) {
2078 $maxitems = 100000;
2079 }
2080 $minitems = t3lib_utility_Math::forceIntegerInRange($config['minitems'], 0);
2081 $allowed = trim($config['allowed']);
2082 $disallowed = trim($config['disallowed']);
2083
2084 $item = '';
2085 $disabled = '';
2086 if ($this->renderReadonly || $config['readOnly']) {
2087 $disabled = ' disabled="disabled"';
2088 }
2089
2090 $item .= '<input type="hidden" name="' . $PA['itemFormElName'] . '_mul" value="' . ($config['multiple'] ? 1 : 0) . '"' . $disabled . ' />';
2091 $this->registerRequiredProperty('range', $PA['itemFormElName'], array($minitems, $maxitems, 'imgName' => $table . '_' . $row['uid'] . '_' . $field));
2092 $info = '';
2093
2094 // "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/.
2095 $specConf = $this->getSpecConfFromString($PA['extra'], $PA['fieldConf']['defaultExtras']);
2096
2097 $PA['itemFormElID_file'] = $PA['itemFormElID'] . '_files';
2098
2099 // whether the list and delete controls should be disabled
2100 $noList = isset($config['disable_controls']) && t3lib_div::inList($config['disable_controls'], 'list');
2101 $noDelete = isset($config['disable_controls']) && t3lib_div::inList($config['disable_controls'], 'delete');
2102
2103 // if maxitems==1 then automatically replace the current item (in list and file selector)
2104 if ($maxitems === 1) {
2105 $this->additionalJS_post[] = "TBE_EDITOR.clearBeforeSettingFormValueFromBrowseWin['" . $PA['itemFormElName'] . "'] = {
2106 itemFormElID_file: '" . $PA['itemFormElID_file'] . "'
2107 }";
2108 $PA['fieldChangeFunc']['TBE_EDITOR_fieldChanged'] = "setFormValueManipulate('" . $PA['itemFormElName'] . "', 'Remove'); " . $PA['fieldChangeFunc']['TBE_EDITOR_fieldChanged'];
2109 } elseif ($noList) {
2110 // if the list controls have been removed and the maximum number is reached, remove the first entry to avoid "write once" field
2111 $PA['fieldChangeFunc']['TBE_EDITOR_fieldChanged'] = "setFormValueManipulate('" . $PA['itemFormElName'] . "', 'RemoveFirstIfFull', '" . $maxitems . "'); " . $PA['fieldChangeFunc']['TBE_EDITOR_fieldChanged'];
2112 }
2113
2114 // Acting according to either "file" or "db" type:
2115 switch ((string) $config['internal_type']) {
2116 case 'file_reference':
2117 $config['uploadfolder'] = '';
2118 // Fall through
2119 case 'file': // If the element is of the internal type "file":
2120
2121 // Creating string showing allowed types:
2122 $tempFT = t3lib_div::trimExplode(',', $allowed, TRUE);
2123 if (!count($tempFT)) {
2124 $info .= '*';
2125 }
2126 foreach ($tempFT as $ext) {
2127 if ($ext) {
2128 $info .= strtoupper($ext) . ' ';
2129 }
2130 }
2131 // Creating string, showing disallowed types:
2132 $tempFT_dis = t3lib_div::trimExplode(',', $disallowed, TRUE);
2133 if (count($tempFT_dis)) {
2134 $info .= '<br />';
2135 }
2136 foreach ($tempFT_dis as $ext) {
2137 if ($ext) {
2138 $info .= '-' . strtoupper($ext) . ' ';
2139 }
2140 }
2141
2142 // Making the array of file items:
2143 $itemArray = t3lib_div::trimExplode(',', $PA['itemFormElValue'], TRUE);
2144
2145 // Showing thumbnails:
2146 $thumbsnail = '';
2147 if ($show_thumbs) {
2148 $imgs = array();
2149 foreach ($itemArray as $imgRead) {
2150 $imgP = explode('|', $imgRead);
2151 $imgPath = rawurldecode($imgP[0]);
2152
2153 $rowCopy = array();
2154 $rowCopy[$field] = $imgPath;
2155
2156 $imgs[] = '<span class="nobr">' . t3lib_BEfunc::thumbCode($rowCopy, $table, $field, $this->backPath, 'thumbs.php', $config['uploadfolder'], 0, ' align="middle"') .
2157 $imgPath .
2158 '</span>';
2159 }
2160 $thumbsnail = implode('<br />', $imgs);
2161 }
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']) ? ' style="' . htmlspecialchars($config['selectedListStyle']) . '"' : ' style="' . $this->defaultMultipleSelectorStyle . '"',
2170 'info' => $info,
2171 'thumbnails' => $thumbsnail,
2172 'readOnly' => $disabled,
2173 'noBrowser' => $noList || (isset($config['disable_controls']) && t3lib_div::inList($config['disable_controls'], 'browser')),
2174 'noList' => $noList,
2175 'noDelete' => $noDelete,
2176 );
2177 $item .= $this->dbFileIcons($PA['itemFormElName'], 'file', implode(',', $tempFT), $itemArray, '', $params, $PA['onFocus']);
2178
2179 if (!$disabled && !(isset($config['disable_controls']) && t3lib_div::inList($config['disable_controls'], 'upload'))) {
2180 // Adding the upload field:
2181 if ($this->edit_docModuleUpload && $config['uploadfolder']) {
2182
2183 // Insert the multiple attribute to enable HTML5 multiple file upload
2184 $multipleAttribute = '';
2185 $multipleFilenameSuffix = '';
2186 if (isset($config['maxitems']) && $config['maxitems'] > 1) {
2187 $multipleAttribute = ' multiple="multiple"';
2188 $multipleFilenameSuffix = '[]';
2189 }
2190
2191 $item .= '<div id="' . $PA['itemFormElID_file'] . '"><input type="file"'. $multipleAttribute .' name="' . $PA['itemFormElName_file'] . $multipleFilenameSuffix . '" size="35" onchange="' . implode('', $PA['fieldChangeFunc']) . '" /></div>';
2192
2193 }
2194 }
2195 break;
2196 case 'folder': // If the element is of the internal type "folder":
2197
2198 // array of folder items:
2199 $itemArray = t3lib_div::trimExplode(',', $PA['itemFormElValue'], 1);
2200
2201 // Creating the element:
2202 $params = array(
2203 'size' => $size,
2204 'dontShowMoveIcons' => ($maxitems <= 1),
2205 'autoSizeMax' => t3lib_utility_Math::forceIntegerInRange($config['autoSizeMax'], 0),
2206 'maxitems' => $maxitems,
2207 'style' => isset($config['selectedListStyle']) ?
2208 ' style="' . htmlspecialchars($config['selectedListStyle']) . '"'
2209 : ' style="' . $this->defaultMultipleSelectorStyle . '"',
2210 'info' => $info,
2211 'readOnly' => $disabled,
2212 'noBrowser' => $noList || (isset($config['disable_controls']) && t3lib_div::inList($config['disable_controls'], 'browser')),
2213 'noList' => $noList,
2214 );
2215
2216 $item .= $this->dbFileIcons(
2217 $PA['itemFormElName'],
2218 'folder',
2219 '',
2220 $itemArray,
2221 '',
2222 $params,
2223 $PA['onFocus']
2224 );
2225 break;
2226 case 'db': // If the element is of the internal type "db":
2227
2228 // Creating string showing allowed types:
2229 $tempFT = t3lib_div::trimExplode(',', $allowed, TRUE);
2230 if (!strcmp(trim($tempFT[0]), '*')) {
2231 $onlySingleTableAllowed = FALSE;
2232 $info .= '<span class="nobr">' .
2233 htmlspecialchars($this->getLL('l_allTables')) .
2234 '</span><br />';
2235 } elseif ($tempFT) {
2236 $onlySingleTableAllowed = (count($tempFT) == 1);
2237 foreach ($tempFT as $theT) {
2238 $info .= '<span class="nobr">' .
2239 t3lib_iconWorks::getSpriteIconForRecord($theT, array()) .
2240 htmlspecialchars($this->sL($GLOBALS['TCA'][$theT]['ctrl']['title'])) .
2241 '</span><br />';
2242 }
2243 }
2244
2245 $perms_clause = $GLOBALS['BE_USER']->getPagePermsClause(1);
2246 $itemArray = array();
2247 $imgs = array();
2248
2249 // Thumbnails:
2250 $temp_itemArray = t3lib_div::trimExplode(',', $PA['itemFormElValue'], 1);
2251 foreach ($temp_itemArray as $dbRead) {
2252 $recordParts = explode('|', $dbRead);
2253 list($this_table, $this_uid) = t3lib_BEfunc::splitTable_Uid($recordParts[0]);
2254 // For the case that no table was found and only a single table is defined to be allowed, use that one:
2255 if (!$this_table && $onlySingleTableAllowed) {
2256 $this_table = $allowed;
2257 }
2258 $itemArray[] = array('table' => $this_table, 'id' => $this_uid);
2259 if (!$disabled && $show_thumbs) {
2260 $rr = t3lib_BEfunc::getRecordWSOL($this_table, $this_uid);
2261 $imgs[] = '<span class="nobr">' .
2262 $this->getClickMenu(
2263 t3lib_iconWorks::getSpriteIconForRecord(
2264 $this_table,
2265 $rr,
2266 array(
2267 'style' => 'vertical-align:top',
2268 'title' => htmlspecialchars(t3lib_BEfunc::getRecordPath($rr['pid'], $perms_clause, 15) . ' [UID: ' . $rr['uid'] . ']')
2269 )
2270 ),
2271 $this_table,
2272 $this_uid
2273 ) .
2274 '&nbsp;' .
2275 t3lib_BEfunc::getRecordTitle($this_table, $rr, TRUE) . ' <span class="typo3-dimmed"><em>[' . $rr['uid'] . ']</em></span>' .
2276 '</span>';
2277 }
2278 }
2279 $thumbsnail = '';
2280 if (!$disabled && $show_thumbs) {
2281 $thumbsnail = implode('<br />', $imgs);
2282 }
2283
2284 // Creating the element:
2285 $params = array(
2286 'size' => $size,
2287 'dontShowMoveIcons' => ($maxitems <= 1),
2288 'autoSizeMax' => t3lib_utility_Math::forceIntegerInRange($config['autoSizeMax'], 0),
2289 'maxitems' => $maxitems,
2290 'style' => isset($config['selectedListStyle']) ? ' style="' . htmlspecialchars($config['selectedListStyle']) . '"' : ' style="' . $this->defaultMultipleSelectorStyle . '"',
2291 'info' => $info,
2292 'thumbnails' => $thumbsnail,
2293 'readOnly' => $disabled,
2294 'noBrowser' => $noList || (isset($config['disable_controls']) && t3lib_div::inList($config['disable_controls'], 'browser')),
2295 'noList' => $noList,
2296 );
2297 $item .= $this->dbFileIcons($PA['itemFormElName'], 'db', implode(',', $tempFT), $itemArray, '', $params, $PA['onFocus'], $table, $field, $row['uid']);
2298
2299 break;
2300 }
2301
2302 // Wizards:
2303 $altItem = '<input type="hidden" name="' . $PA['itemFormElName'] . '" value="' . htmlspecialchars($PA['itemFormElValue']) . '" />';
2304 if (!$disabled) {
2305 $item = $this->renderWizards(array($item, $altItem), $config['wizards'], $table, $row, $field, $PA, $PA['itemFormElName'], $specConf);
2306 }
2307
2308 return $item;
2309 }
2310
2311 /**
2312 * Generation of TCEform elements of the type "none"
2313 * This will render a non-editable display of the content of the field.
2314 *
2315 * @param string The table name of the record
2316 * @param string The field name which this element is supposed to edit
2317 * @param array The record data array where the value(s) for the field can be found
2318 * @param array An array with additional configuration options.
2319 * @return string The HTML code for the TCEform field
2320 */
2321 function getSingleField_typeNone($table, $field, $row, &$PA) {
2322 // Init:
2323 $config = $PA['fieldConf']['config'];
2324 $itemValue = $PA['itemFormElValue'];
2325
2326 return $this->getSingleField_typeNone_render($config, $itemValue);
2327 }
2328
2329 /**
2330 * HTML rendering of a value which is not editable.
2331 *
2332 * @param array Configuration for the display
2333 * @param string The value to display
2334 * @return string The HTML code for the display
2335 * @see getSingleField_typeNone();
2336 */
2337 function getSingleField_typeNone_render($config, $itemValue) {
2338
2339 // is colorScheme[0] the right value?
2340 $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;';
2341
2342 if ($config['format']) {
2343 $itemValue = $this->formatValue($config, $itemValue);
2344 }
2345
2346 $rows = intval($config['rows']);
2347 if ($rows > 1) {
2348 if (!$config['pass_content']) {
2349 $itemValue = nl2br(htmlspecialchars($itemValue));
2350 }
2351 // like textarea
2352 $cols = t3lib_utility_Math::forceIntegerInRange($config['cols'] ? $config['cols'] : 30, 5, $this->maxTextareaWidth);
2353 if (!$config['fixedRows']) {
2354 $origRows = $rows = t3lib_utility_Math::forceIntegerInRange($rows, 1, 20);
2355 if (strlen($itemValue) > $this->charsPerRow * 2) {
2356 $cols = $this->maxTextareaWidth;
2357 $rows = t3lib_utility_Math::forceIntegerInRange(round(strlen($itemValue) / $this->charsPerRow), count(explode(LF, $itemValue)), 20);
2358 if ($rows < $origRows) {
2359 $rows = $origRows;
2360 }
2361 }
2362 }
2363
2364 if ($this->docLarge) {
2365 $cols = round($cols * $this->form_largeComp);
2366 }
2367 $width = ceil($cols * $this->form_rowsToStylewidth);
2368 // hardcoded: 12 is the height of the font
2369 $height = $rows * 12;
2370
2371 $item = '
2372 <div style="' . htmlspecialchars($divStyle . ' overflow:auto; height:' . $height . 'px; width:' . $width . 'px;') . '" class="' . htmlspecialchars($this->formElClass('none')) . '">' .
2373 $itemValue .
2374 '</div>';
2375 } else {
2376 if (!$config['pass_content']) {
2377 $itemValue = htmlspecialchars($itemValue);
2378 }
2379
2380 $cols = $config['cols'] ? $config['cols'] : ($config['size'] ? $config['size'] : $this->maxInputWidth);
2381 if ($this->docLarge) {
2382 $cols = round($cols * $this->form_largeComp);
2383 }
2384 $width = ceil($cols * $this->form_rowsToStylewidth);
2385
2386 // overflow:auto crashes mozilla here. Title tag is usefull when text is longer than the div box (overflow:hidden).
2387 $item = '
2388 <div style="' . htmlspecialchars($divStyle . ' overflow:hidden; width:' . $width . 'px;') . '" class="' . htmlspecialchars($this->formElClass('none')) . '" title="' . $itemValue . '">' .
2389 '<span class="nobr">' . (strcmp($itemValue, '') ? $itemValue : '&nbsp;') . '</span>' .
2390 '</div>';
2391 }
2392
2393 return $item;
2394 }
2395
2396 /**
2397 * Handler for Flex Forms
2398 *
2399 * @param string The table name of the record
2400 * @param string The field name which this element is supposed to edit
2401 * @param array The record data array where the value(s) for the field can be found
2402 * @param array An array with additional configuration options.
2403 * @return string The HTML code for the TCEform field
2404 */
2405 function getSingleField_typeFlex($table, $field, $row, &$PA) {
2406
2407 // Data Structure:
2408 $dataStructArray = t3lib_BEfunc::getFlexFormDS($PA['fieldConf']['config'], $row, $table);
2409 $item = '';
2410
2411 // Manipulate Flexform DS via TSConfig and group access lists
2412 if (is_array($dataStructArray)) {
2413 $flexFormHelper = t3lib_div::makeInstance('t3lib_TCEforms_Flexforms');
2414 $dataStructArray = $flexFormHelper->modifyFlexFormDS($dataStructArray, $table, $field, $row, $PA['fieldConf']);
2415 unset($flexFormHelper);
2416 }
2417
2418 // Get data structure:
2419 if (is_array($dataStructArray)) {
2420
2421 // Get data:
2422 $xmlData = $PA['itemFormElValue'];
2423 $xmlHeaderAttributes = t3lib_div::xmlGetHeaderAttribs($xmlData);
2424 $storeInCharset = strtolower($xmlHeaderAttributes['encoding']);
2425 if ($storeInCharset) {
2426 $currentCharset = $GLOBALS['LANG']->charSet;
2427 $xmlData = $GLOBALS['LANG']->csConvObj->conv($xmlData, $storeInCharset, $currentCharset, 1);
2428 }
2429 $editData = t3lib_div::xml2array($xmlData);
2430 if (!is_array($editData)) { // Must be XML parsing error...
2431 $editData = array();
2432 } elseif (!isset($editData['meta']) || !is_array($editData['meta'])) {
2433 $editData['meta'] = array();
2434 }
2435
2436 // Find the data structure if sheets are found:
2437 $sheet = $editData['meta']['currentSheetId'] ? $editData['meta']['currentSheetId'] : 'sDEF'; // Sheet to display
2438
2439 // Create sheet menu:
2440 //TODO; Why is this commented out?
2441 // if (is_array($dataStructArray['sheets'])) {
2442 // #$item.=$this->getSingleField_typeFlex_sheetMenu($dataStructArray['sheets'], $PA['itemFormElName'].'[meta][currentSheetId]', $sheet).'<br />';
2443 // }
2444
2445 // Create language menu:
2446 $langChildren = $dataStructArray['meta']['langChildren'] ? 1 : 0;
2447 $langDisabled = $dataStructArray['meta']['langDisable'] ? 1 : 0;
2448
2449 $editData['meta']['currentLangId'] = array();
2450
2451 // Look up page overlays:
2452 $checkPageLanguageOverlay = $GLOBALS['BE_USER']->getTSConfigVal('options.checkPageLanguageOverlay') ? TRUE : FALSE;
2453 if ($checkPageLanguageOverlay) {
2454 $pageOverlays = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
2455 '*',
2456 'pages_language_overlay',
2457 'pid=' . intval($row['pid']) .
2458 t3lib_BEfunc::deleteClause('pages_language_overlay') .
2459 t3lib_BEfunc::versioningPlaceholderClause('pages_language_overlay'),
2460 '',
2461 '',
2462 '',
2463 'sys_language_uid'
2464 );
2465 }
2466 $languages = $this->getAvailableLanguages();
2467
2468 foreach ($languages as $lInfo) {
2469 if ($GLOBALS['BE_USER']->checkLanguageAccess($lInfo['uid']) && (!$checkPageLanguageOverlay || $lInfo['uid'] <= 0 || is_array($pageOverlays[$lInfo['uid']]))) {
2470 $editData['meta']['currentLangId'][] = $lInfo['ISOcode'];
2471 }
2472 }
2473 if (!is_array($editData['meta']['currentLangId']) || !count($editData['meta']['currentLangId'])) {
2474 $editData['meta']['currentLangId'] = array('DEF');
2475 }
2476
2477 $editData['meta']['currentLangId'] = array_unique($editData['meta']['currentLangId']);
2478
2479 //TODO: Why is this commented out?
2480 // if (!$langDisabled && count($languages) > 1) {
2481 // $item.=$this->getSingleField_typeFlex_langMenu($languages, $PA['itemFormElName'].'[meta][currentLangId]', $editData['meta']['currentLangId']).'<br />';
2482 // }
2483
2484 $PA['_noEditDEF'] = FALSE;
2485 if ($langChildren || $langDisabled) {
2486 $rotateLang = array('DEF');
2487 } else {
2488 if (!in_array('DEF', $editData['meta']['currentLangId'])) {
2489 array_unshift($editData['meta']['currentLangId'], 'DEF');
2490 $PA['_noEditDEF'] = TRUE;
2491 }
2492 $rotateLang = $editData['meta']['currentLangId'];
2493 }
2494
2495 // Tabs sheets
2496 if (is_array($dataStructArray['sheets'])) {
2497 $tabsToTraverse = array_keys($dataStructArray['sheets']);
2498 } else {
2499 $tabsToTraverse = array($sheet);
2500 }
2501
2502 foreach ($rotateLang as $lKey) {
2503 if (!$langChildren && !$langDisabled) {
2504 $item .= '<strong>' . $this->getLanguageIcon($table, $row, 'v' . $lKey) . $lKey . ':</strong>';
2505 }
2506 $lang = 'l' . $lKey; // Default language, other options are "lUK" or whatever country code (independant of system!!!)
2507
2508 $tabParts = array();
2509 foreach ($tabsToTraverse as $sheet) {
2510 list ($dataStruct, $sheet) = t3lib_div::resolveSheetDefInDS($dataStructArray, $sheet);
2511
2512 // If sheet has displayCond
2513 if ($dataStruct['ROOT']['TCEforms']['displayCond']) {
2514 $splittedCondition = t3lib_div::trimExplode(':', $dataStruct['ROOT']['TCEforms']['displayCond']);
2515 $skipCondition = FALSE;
2516 $fakeRow = array();
2517 switch ($splittedCondition[0]) {
2518 case 'FIELD':
2519 list($sheetName, $fieldName) = t3lib_div::trimExplode('.', $splittedCondition[1]);
2520 $fieldValue = $editData['data'][$sheetName][$lang][$fieldName];
2521 $splittedCondition[1] = $fieldName;
2522 $dataStruct['ROOT']['TCEforms']['displayCond'] = join(':', $splittedCondition);
2523 $fakeRow = array($fieldName => $fieldValue);
2524 break;
2525 case 'HIDE_FOR_NON_ADMINS':
2526 case 'VERSION':
2527 case 'HIDE_L10N_SIBLINGS':
2528 case 'EXT':
2529 break;
2530 case 'REC':
2531 $fakeRow = array('uid' => $row['uid']);
2532 break;
2533 default:
2534 $skipCondition = TRUE;
2535 break;
2536 }
2537
2538 // If sheets displayCond leads to false
2539 if (!$skipCondition && !$this->isDisplayCondition($dataStruct['ROOT']['TCEforms']['displayCond'], $fakeRow, 'vDEF')) {
2540 // don't create this sheet
2541 continue;
2542 }
2543 }
2544
2545 // Render sheet:
2546 if (is_array($dataStruct['ROOT']) && is_array($dataStruct['ROOT']['el'])) {
2547 $PA['_valLang'] = $langChildren && !$langDisabled ? $editData['meta']['currentLangId'] : 'DEF'; // Default language, other options are "lUK" or whatever country code (independant of system!!!)
2548 $PA['_lang'] = $lang;
2549 // Assemble key for loading the correct CSH file
2550 $dsPointerFields = t3lib_div::trimExplode(',', $GLOBALS['TCA'][$table]['columns'][$field]['config']['ds_pointerField'], TRUE);
2551 $PA['_cshKey'] = $table . '.' . $field;
2552 foreach ($dsPointerFields as $key) {
2553 $PA['_cshKey'] .= '.' . $row[$key];
2554 }
2555
2556 // Push the sheet level tab to DynNestedStack
2557 if (is_array($dataStructArray['sheets'])) {
2558 $tabIdentString = $GLOBALS['TBE_TEMPLATE']->getDynTabMenuId('TCEFORMS:flexform:' . $PA['itemFormElName'] . $PA['_lang']);
2559 $this->pushToDynNestedStack('tab', $tabIdentString . '-' . (count($tabParts) + 1));
2560 }
2561 // Render flexform:
2562 $tRows = $this->getSingleField_typeFlex_draw(
2563 $dataStruct['ROOT']['el'],
2564 $editData['data'][$sheet][$lang],
2565 $table,
2566 $field,
2567 $row,
2568 $PA,
2569 '[data][' . $sheet . '][' . $lang . ']'
2570 );
2571 $sheetContent = '<div class="typo3-TCEforms-flexForm">' . $tRows . '</div>';
2572
2573
2574 // Pop the sheet level tab from DynNestedStack
2575 if (is_array($dataStructArray['sheets'])) {
2576 $this->popFromDynNestedStack('tab', $tabIdentString . '-' . (count($tabParts) + 1));
2577 }
2578 } else {
2579 $sheetContent = 'Data Structure ERROR: No ROOT element found for sheet "' . $sheet . '".';
2580 }
2581
2582 // Add to tab:
2583 $tabParts[] = array(
2584 'label' => ($dataStruct['ROOT']['TCEforms']['sheetTitle'] ? $this->sL($dataStruct['ROOT']['TCEforms']['sheetTitle']) : $sheet),
2585 'description' => ($dataStruct['ROOT']['TCEforms']['sheetDescription'] ? $this->sL($dataStruct['ROOT']['TCEforms']['sheetDescription']) : ''),
2586 'linkTitle' => ($dataStruct['ROOT']['TCEforms']['sheetShortDescr'