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