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