Added feature #11648: Feature: Add datepicker to date and datetime 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 $fieldAppendix = '';
1067
1068 // cssclass and id will show the kind of field
1069 if (in_array('date', $evalList)) {
1070 $inputId = uniqid('tceforms-datefield-');
1071 $cssClass = 'tceforms-textfield tceforms-datefield';
1072 $fieldAppendix = '<img' . t3lib_iconWorks::skinImg(
1073 $this->backPath, 'gfx/datepicker.gif', '', 0)
1074 . ' style="cursor:pointer; vertical-align:middle;" alt=""'
1075 . ' id="picker-' . $inputId . '" />';
1076 } elseif (in_array('datetime', $evalList)) {
1077 $inputId = uniqid('tceforms-datetimefield-');
1078 $cssClass = 'tceforms-textfield tceforms-datetimefield';
1079 $fieldAppendix = '<img' . t3lib_iconWorks::skinImg(
1080 $this->backPath, 'gfx/datepicker.gif', '', 0)
1081 . ' style="cursor:pointer; vertical-align:middle;" alt=""'
1082 . ' id="picker-' . $inputId . '" />';
1083 } elseif (in_array('timesec', $evalList)) {
1084 $inputId = uniqid('tceforms-timesecfield-');
1085 $cssClass = 'tceforms-textfield tceforms-timesecfield';
1086 } elseif (in_array('year', $evalList)) {
1087 $inputId = uniqid('tceforms-yearfield-');
1088 $cssClass = 'tceforms-textfield tceforms-yearfield';
1089 } elseif (in_array('time', $evalList)) {
1090 $inputId = uniqid('tceforms-timefield-');
1091 $cssClass = 'tceforms-textfield tceforms-timefield';
1092 } elseif (in_array('int', $evalList)) {
1093 $inputId = uniqid('tceforms-intfield-');
1094 $cssClass = 'tceforms-textfield tceforms-intfield';
1095 } elseif (in_array('double2', $evalList)) {
1096 $inputId = uniqid('tceforms-double2field-');
1097 $cssClass = 'tceforms-textfield tceforms-double2field';
1098 } else {
1099 $inputId = uniqid('tceforms-textfield-');
1100 $cssClass = 'tceforms-textfield';
1101 }
1102 if (isset($config['wizards']['link'])) {
1103 $inputId = uniqid('tceforms-linkfield-');
1104 $cssClass = 'tceforms-textfield tceforms-linkfield';
1105 } elseif (isset($config['wizards']['color'])) {
1106 $inputId = uniqid('tceforms-colorfield-');
1107 $cssClass = 'tceforms-textfield tceforms-colorfield';
1108 }
1109
1110
1111 if($this->renderReadonly || $config['readOnly']) {
1112 $itemFormElValue = $PA['itemFormElValue'];
1113 if (in_array('date',$evalList)) {
1114 $config['format'] = 'date';
1115 } elseif (in_array('datetime',$evalList)) {
1116 $config['format'] = 'datetime';
1117 } elseif (in_array('time',$evalList)) {
1118 $config['format'] = 'time';
1119 }
1120 if (in_array('password',$evalList)) {
1121 $itemFormElValue = $itemFormElValue ? '*********' : '';
1122 }
1123 return $this->getSingleField_typeNone_render($config, $itemFormElValue);
1124 }
1125
1126 foreach ($evalList as $func) {
1127 switch ($func) {
1128 case 'required':
1129 $this->registerRequiredProperty('field', $table.'_'.$row['uid'].'_'.$field, $PA['itemFormElName']);
1130 // Mark this field for date/time disposal:
1131 if (array_intersect($evalList, array('date', 'datetime', 'time'))) {
1132 $this->requiredAdditional[$PA['itemFormElName']]['isPositiveNumber'] = true;
1133 }
1134 break;
1135 default:
1136 if (substr($func, 0, 3) == 'tx_') {
1137 // Pair hook to the one in t3lib_TCEmain::checkValue_input_Eval()
1138 $evalObj = t3lib_div::getUserObj($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tce']['formevals'][$func].':&'.$func);
1139 if (is_object($evalObj) && method_exists($evalObj, 'deevaluateFieldValue')) {
1140 $_params = array(
1141 'value' => $PA['itemFormElValue']
1142 );
1143 $PA['itemFormElValue'] = $evalObj->deevaluateFieldValue($_params);
1144 }
1145 }
1146 break;
1147 }
1148 }
1149
1150 $paramsList = "'".$PA['itemFormElName']."','".implode(',',$evalList)."','".trim($config['is_in'])."',".(isset($config['checkbox'])?1:0).",'".$config['checkbox']."'";
1151 if (isset($config['checkbox'])) {
1152 // Setting default "click-checkbox" values for eval types "date" and "datetime":
1153 $thisMidnight = gmmktime(0,0,0);
1154 if (in_array('date',$evalList)) {
1155 $checkSetValue = $thisMidnight;
1156 } elseif (in_array('datetime',$evalList)) {
1157 $checkSetValue = $GLOBALS['EXEC_TIME'];
1158 } elseif (in_array('year',$evalList)) {
1159 $checkSetValue = gmdate('Y');
1160 }
1161 $cOnClick = 'typo3form.fieldGet('.$paramsList.',1,\''.$checkSetValue.'\');'.implode('',$PA['fieldChangeFunc']);
1162 $item .= '<input type="checkbox" id="' . uniqid('tceforms-check-') . '" class="' . $this->formElStyleClassValue('check', TRUE) . ' alignToInputText" name="' . $PA['itemFormElName'] . '_cb" onclick="' . htmlspecialchars($cOnClick) . '" />';
1163 }
1164 if ((in_array('date',$evalList) || in_array('datetime',$evalList)) && $PA['itemFormElValue']>0){
1165 // Add server timezone offset to UTC to our stored date
1166 $PA['itemFormElValue'] += date('Z', $PA['itemFormElValue']);
1167 }
1168
1169 $PA['fieldChangeFunc'] = array_merge(array('typo3form.fieldGet'=>'typo3form.fieldGet('.$paramsList.');'), $PA['fieldChangeFunc']);
1170 $mLgd = ($config['max']?$config['max']:256);
1171 $iOnChange = implode('',$PA['fieldChangeFunc']);
1172
1173 $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.
1174 $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.
1175 $item .= $fieldAppendix;
1176 $this->extJSCODE.='typo3form.fieldSet('.$paramsList.');';
1177
1178 // going through all custom evaluations configured for this field
1179 foreach ($evalList as $evalData) {
1180 if (substr($evalData, 0, 3) == 'tx_') {
1181 $evalObj = t3lib_div::getUserObj($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tce']['formevals'][$evalData].':&'.$evalData);
1182 if(is_object($evalObj) && method_exists($evalObj, 'returnFieldJS')) {
1183 $this->extJSCODE .= "\n\nfunction ".$evalData."(value) {\n".$evalObj->returnFieldJS()."\n}\n";
1184 }
1185 }
1186 }
1187
1188 // Creating an alternative item without the JavaScript handlers.
1189 $altItem = '<input type="hidden" name="'.$PA['itemFormElName'].'_hr" value="" />';
1190 $altItem.= '<input type="hidden" name="'.$PA['itemFormElName'].'" value="'.htmlspecialchars($PA['itemFormElValue']).'" />';
1191
1192 // Wrap a wizard around the item?
1193 $item= $this->renderWizards(array($item,$altItem),$config['wizards'],$table,$row,$field,$PA,$PA['itemFormElName'].'_hr',$specConf);
1194
1195 return $item;
1196 }
1197
1198 /**
1199 * Generation of TCEform elements of the type "text"
1200 * This will render a <textarea> OR RTE area form field, possibly with various control/validation features
1201 *
1202 * @param string The table name of the record
1203 * @param string The field name which this element is supposed to edit
1204 * @param array The record data array where the value(s) for the field can be found
1205 * @param array An array with additional configuration options.
1206 * @return string The HTML code for the TCEform field
1207 */
1208 function getSingleField_typeText($table,$field,$row,&$PA) {
1209
1210 // Init config:
1211 $config = $PA['fieldConf']['config'];
1212
1213 if($this->renderReadonly || $config['readOnly']) {
1214 return $this->getSingleField_typeNone_render($config, $PA['itemFormElValue']);
1215 }
1216
1217 // Setting columns number:
1218 $cols = t3lib_div::intInRange($config['cols'] ? $config['cols'] : 30, 5, $this->maxTextareaWidth);
1219
1220 // Setting number of rows:
1221 $origRows = $rows = t3lib_div::intInRange($config['rows'] ? $config['rows'] : 5, 1, 20);
1222 if (strlen($PA['itemFormElValue']) > $this->charsPerRow*2) {
1223 $cols = $this->maxTextareaWidth;
1224 $rows = t3lib_div::intInRange(round(strlen($PA['itemFormElValue'])/$this->charsPerRow), count(explode(chr(10),$PA['itemFormElValue'])), 20);
1225 if ($rows<$origRows) $rows = $origRows;
1226 }
1227
1228 // Init RTE vars:
1229 $RTEwasLoaded = 0; // Set true, if the RTE is loaded; If not a normal textarea is shown.
1230 $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...
1231
1232 // "Extra" configuration; Returns configuration for the field based on settings found in the "types" fieldlist. Traditionally, this is where RTE configuration has been found.
1233 $specConf = $this->getSpecConfFromString($PA['extra'], $PA['fieldConf']['defaultExtras']);
1234
1235 // Setting up the altItem form field, which is a hidden field containing the value
1236 $altItem = '<input type="hidden" name="'.htmlspecialchars($PA['itemFormElName']).'" value="'.htmlspecialchars($PA['itemFormElValue']).'" />';
1237
1238 // If RTE is generally enabled (TYPO3_CONF_VARS and user settings)
1239 if ($this->RTEenabled) {
1240 $p = t3lib_BEfunc::getSpecConfParametersFromArray($specConf['rte_transform']['parameters']);
1241 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.
1242 t3lib_BEfunc::fixVersioningPid($table,$row);
1243 list($tscPID,$thePidValue) = $this->getTSCpid($table,$row['uid'],$row['pid']);
1244
1245 // If the pid-value is not negative (that is, a pid could NOT be fetched)
1246 if ($thePidValue >= 0) {
1247 $RTEsetup = $GLOBALS['BE_USER']->getTSConfig('RTE',t3lib_BEfunc::getPagesTSconfig($tscPID));
1248 $RTEtypeVal = t3lib_BEfunc::getTCAtypeValue($table,$row);
1249 $thisConfig = t3lib_BEfunc::RTEsetup($RTEsetup['properties'],$table,$field,$RTEtypeVal);
1250
1251 if (!$thisConfig['disabled']) {
1252 if (!$this->disableRTE) {
1253 $this->RTEcounter++;
1254
1255 // Find alternative relative path for RTE images/links:
1256 $eFile = t3lib_parsehtml_proc::evalWriteFile($specConf['static_write'], $row);
1257 $RTErelPath = is_array($eFile) ? dirname($eFile['relEditFile']) : '';
1258
1259 // Get RTE object, draw form and set flag:
1260 $RTEobj = &t3lib_BEfunc::RTEgetObj();
1261 $item = $RTEobj->drawRTE($this,$table,$field,$row,$PA,$specConf,$thisConfig,$RTEtypeVal,$RTErelPath,$thePidValue);
1262
1263 // Wizard:
1264 $item = $this->renderWizards(array($item,$altItem),$config['wizards'],$table,$row,$field,$PA,$PA['itemFormElName'],$specConf,1);
1265
1266 $RTEwasLoaded = 1;
1267 } else {
1268 $RTEwouldHaveBeenLoaded = 1;
1269 $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!)';
1270 }
1271 } else $this->commentMessages[] = $PA['itemFormElName'].': RTE is disabled by the Page TSconfig, "RTE"-key (eg. by RTE.default.disabled=0 or such)';
1272 } else $this->commentMessages[] = $PA['itemFormElName'].': PID value could NOT be fetched. Rare error, normally with new records.';
1273 } else {
1274 if (!isset($specConf['richtext'])) $this->commentMessages[] = $PA['itemFormElName'].': RTE was not configured for this field in TCA-types';
1275 if (!(!$p['flag'] || !$row[$p['flag']])) $this->commentMessages[] = $PA['itemFormElName'].': Field-flag ('.$PA['flag'].') has been set to disable RTE!';
1276 }
1277 }
1278
1279 // Display ordinary field if RTE was not loaded.
1280 if (!$RTEwasLoaded) {
1281 if ($specConf['rte_only']) { // Show message, if no RTE (field can only be edited with RTE!)
1282 $item = '<p><em>'.htmlspecialchars($this->getLL('l_noRTEfound')).'</em></p>';
1283 } else {
1284 if ($specConf['nowrap']) {
1285 $wrap = 'off';
1286 } else {
1287 $wrap = ($config['wrap'] ? $config['wrap'] : 'virtual');
1288 }
1289
1290 $classes = array();
1291 if ($specConf['fixed-font']) { $classes[] = 'fixed-font'; }
1292 if ($specConf['enable-tab']) { $classes[] = 'enable-tab'; }
1293
1294 $formWidthText = $this->formWidthText($cols,$wrap);
1295
1296 // Extract class attributes from $formWidthText (otherwise it would be added twice to the output)
1297 $res = array();
1298 if (preg_match('/ class="(.+?)"/',$formWidthText,$res)) {
1299 $formWidthText = str_replace(' class="'.$res[1].'"','',$formWidthText);
1300 $classes = array_merge($classes, explode(' ',$res[1]));
1301 }
1302
1303 if (count($classes)) {
1304 $class = ' class="tceforms-textarea '.implode(' ',$classes).'"';
1305 } else $class='tceforms-textarea';
1306
1307 $evalList = t3lib_div::trimExplode(',',$config['eval'],1);
1308 foreach ($evalList as $func) {
1309 switch ($func) {
1310 case 'required':
1311 $this->registerRequiredProperty('field', $table.'_'.$row['uid'].'_'.$field, $PA['itemFormElName']);
1312 break;
1313 default:
1314 if (substr($func, 0, 3) == 'tx_') {
1315 // Pair hook to the one in t3lib_TCEmain::checkValue_input_Eval() and t3lib_TCEmain::checkValue_text_Eval()
1316 $evalObj = t3lib_div::getUserObj($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tce']['formevals'][$func].':&'.$func);
1317 if (is_object($evalObj) && method_exists($evalObj, 'deevaluateFieldValue')) {
1318 $_params = array(
1319 'value' => $PA['itemFormElValue']
1320 );
1321 $PA['itemFormElValue'] = $evalObj->deevaluateFieldValue($_params);
1322 }
1323 }
1324 break;
1325 }
1326 }
1327
1328 $iOnChange = implode('',$PA['fieldChangeFunc']);
1329 $item.= '
1330 <textarea id="' . uniqid('tceforms-textarea-') . '" name="'.$PA['itemFormElName'].'"'.$formWidthText.$class.' rows="'.$rows.'" wrap="'.$wrap.'" onchange="'.htmlspecialchars($iOnChange).'"'.$PA['onFocus'].'>'.
1331 t3lib_div::formatForTextarea($PA['itemFormElValue']).
1332 '</textarea>';
1333 $item = $this->renderWizards(array($item,$altItem),$config['wizards'],$table,$row,$field,$PA,$PA['itemFormElName'],$specConf,$RTEwouldHaveBeenLoaded);
1334 }
1335 }
1336
1337 // Return field HTML:
1338 return $item;
1339 }
1340
1341 /**
1342 * Generation of TCEform elements of the type "check"
1343 * This will render a check-box OR an array of checkboxes
1344 *
1345 * @param string The table name of the record
1346 * @param string The field name which this element is supposed to edit
1347 * @param array The record data array where the value(s) for the field can be found
1348 * @param array An array with additional configuration options.
1349 * @return string The HTML code for the TCEform field
1350 */
1351 function getSingleField_typeCheck($table,$field,$row,&$PA) {
1352 $config = $PA['fieldConf']['config'];
1353
1354 $disabled = '';
1355 if($this->renderReadonly || $config['readOnly']) {
1356 $disabled = ' disabled="disabled"';
1357 }
1358
1359 // Traversing the array of items:
1360 $selItems = $this->initItemArray($PA['fieldConf']);
1361 if ($config['itemsProcFunc']) $selItems = $this->procItems($selItems,$PA['fieldTSConfig']['itemsProcFunc.'],$config,$table,$row,$field);
1362
1363 if (!count($selItems)) {
1364 $selItems[]=array('','');
1365 }
1366 $thisValue = intval($PA['itemFormElValue']);
1367
1368 $cols = intval($config['cols']);
1369 if ($cols > 1) {
1370 $item.= '<table border="0" cellspacing="0" cellpadding="0" class="typo3-TCEforms-checkboxArray">';
1371 for ($c=0;$c<count($selItems);$c++) {
1372 $p = $selItems[$c];
1373 if(!($c%$cols)) { $item.='<tr>'; }
1374 $cBP = $this->checkBoxParams($PA['itemFormElName'],$thisValue,$c,count($selItems),implode('',$PA['fieldChangeFunc']));
1375 $cBName = $PA['itemFormElName'].'_'.$c;
1376 $cBID = $PA['itemFormElID'].'_'.$c;
1377 $item.= '<td nowrap="nowrap">'.
1378 '<input type="checkbox"'.$this->insertDefStyle('check').' value="1" name="'.$cBName.'"'.$cBP.$disabled.' id="'.$cBID.'" />'.
1379 $this->wrapLabels('<label for="'.$cBID.'">'.htmlspecialchars($p[0]).'</label>&nbsp;').
1380 '</td>';
1381 if(($c%$cols)+1==$cols) {$item.='</tr>';}
1382 }
1383 if ($c%$cols) {
1384 $rest=$cols-($c%$cols);
1385 for ($c=0;$c<$rest;$c++) {
1386 $item.= '<td></td>';
1387 }
1388 if ($c>0) { $item.= '</tr>'; }
1389 }
1390 $item.= '</table>';
1391 } else {
1392 for ($c=0;$c<count($selItems);$c++) {
1393 $p = $selItems[$c];
1394 $cBP = $this->checkBoxParams($PA['itemFormElName'],$thisValue,$c,count($selItems),implode('',$PA['fieldChangeFunc']));
1395 $cBName = $PA['itemFormElName'].'_'.$c;
1396 $cBID = $PA['itemFormElID'].'_'.$c;
1397 $item.= ($c>0?'<br />':'').
1398 '<input type="checkbox"'.$this->insertDefStyle('check').' value="1" name="'.$cBName.'"'.$cBP.$PA['onFocus'].$disabled.' id="'.$cBID.'" />'.
1399 $this->wrapLabels('<label for="'.$cBID.'">'.htmlspecialchars($p[0]).'</label>');
1400 }
1401 }
1402 if (!$disabled) {
1403 $item.= '<input type="hidden" name="'.$PA['itemFormElName'].'" value="'.htmlspecialchars($thisValue).'" />';
1404 }
1405
1406 return $item;
1407 }
1408
1409 /**
1410 * Generation of TCEform elements of the type "radio"
1411 * This will render a series of radio buttons.
1412 *
1413 * @param string The table name of the record
1414 * @param string The field name which this element is supposed to edit
1415 * @param array The record data array where the value(s) for the field can be found
1416 * @param array An array with additional configuration options.
1417 * @return string The HTML code for the TCEform field
1418 */
1419 function getSingleField_typeRadio($table,$field,$row,&$PA) {
1420 $config = $PA['fieldConf']['config'];
1421
1422 $disabled = '';
1423 if($this->renderReadonly || $config['readOnly']) {
1424 $disabled = ' disabled="disabled"';
1425 }
1426
1427 // Get items for the array:
1428 $selItems = $this->initItemArray($PA['fieldConf']);
1429 if ($config['itemsProcFunc']) $selItems = $this->procItems($selItems,$PA['fieldTSConfig']['itemsProcFunc.'],$config,$table,$row,$field);
1430
1431 // Traverse the items, making the form elements:
1432 for ($c=0;$c<count($selItems);$c++) {
1433 $p = $selItems[$c];
1434 $rID = $PA['itemFormElID'].'_'.$c;
1435 $rOnClick = implode('',$PA['fieldChangeFunc']);
1436 $rChecked = (!strcmp($p[1],$PA['itemFormElValue'])?' checked="checked"':'');
1437 $item.= '<input type="radio"'.$this->insertDefStyle('radio').' name="'.$PA['itemFormElName'].'" value="'.htmlspecialchars($p[1]).'" onclick="'.htmlspecialchars($rOnClick).'"'.$rChecked.$PA['onFocus'].$disabled.' id="'.$rID.'" />
1438 <label for="'.$rID.'">'.htmlspecialchars($p[0]).'</label>
1439 <br />';
1440 }
1441
1442 return $item;
1443 }
1444
1445 /**
1446 * Generation of TCEform elements of the type "select"
1447 * This will render a selector box element, or possibly a special construction with two selector boxes. That depends on configuration.
1448 *
1449 * @param string The table name of the record
1450 * @param string The field name which this element is supposed to edit
1451 * @param array The record data array where the value(s) for the field can be found
1452 * @param array An array with additional configuration options.
1453 * @return string The HTML code for the TCEform field
1454 */
1455 function getSingleField_typeSelect($table,$field,$row,&$PA) {
1456 global $TCA;
1457
1458 // Field configuration from TCA:
1459 $config = $PA['fieldConf']['config'];
1460
1461 $disabled = '';
1462 if($this->renderReadonly || $config['readOnly']) {
1463 $disabled = ' disabled="disabled"';
1464 }
1465
1466 // "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/.
1467 $specConf = $this->getSpecConfFromString($PA['extra'], $PA['fieldConf']['defaultExtras']);
1468
1469 // Getting the selector box items from the system
1470 $selItems = $this->addSelectOptionsToItemArray(
1471 $this->initItemArray($PA['fieldConf']),
1472 $PA['fieldConf'],
1473 $this->setTSconfig($table, $row),
1474 $field
1475 );
1476 // Possibly filter some items:
1477 $keepItemsFunc = create_function('$value', 'return $value[1];');
1478 $selItems = t3lib_div::keepItemsInArray($selItems, $PA['fieldTSConfig']['keepItems'], $keepItemsFunc);
1479 // Possibly add some items:
1480 $selItems = $this->addItems($selItems, $PA['fieldTSConfig']['addItems.']);
1481 // Process items by a user function:
1482 if (isset($config['itemsProcFunc']) && $config['itemsProcFunc']) {
1483 $selItems = $this->procItems($selItems, $PA['fieldTSConfig']['itemsProcFunc.'], $config, $table, $row, $field);
1484 }
1485
1486 // Possibly remove some items:
1487 $removeItems = t3lib_div::trimExplode(',',$PA['fieldTSConfig']['removeItems'],1);
1488 foreach($selItems as $tk => $p) {
1489
1490 // Checking languages and authMode:
1491 $languageDeny = $TCA[$table]['ctrl']['languageField'] && !strcmp($TCA[$table]['ctrl']['languageField'], $field) && !$GLOBALS['BE_USER']->checkLanguageAccess($p[1]);
1492 $authModeDeny = $config['form_type']=='select' && $config['authMode'] && !$GLOBALS['BE_USER']->checkAuthMode($table,$field,$p[1],$config['authMode']);
1493 if (in_array($p[1],$removeItems) || $languageDeny || $authModeDeny) {
1494 unset($selItems[$tk]);
1495 } elseif (isset($PA['fieldTSConfig']['altLabels.'][$p[1]])) {
1496 $selItems[$tk][0]=$this->sL($PA['fieldTSConfig']['altLabels.'][$p[1]]);
1497 }
1498
1499 // Removing doktypes with no access:
1500 if ($table.'.'.$field == 'pages.doktype') {
1501 if (!($GLOBALS['BE_USER']->isAdmin() || t3lib_div::inList($GLOBALS['BE_USER']->groupData['pagetypes_select'],$p[1]))) {
1502 unset($selItems[$tk]);
1503 }
1504 }
1505 }
1506
1507 // Creating the label for the "No Matching Value" entry.
1508 $nMV_label = isset($PA['fieldTSConfig']['noMatchingValue_label']) ? $this->sL($PA['fieldTSConfig']['noMatchingValue_label']) : '[ '.$this->getLL('l_noMatchingValue').' ]';
1509
1510 // Prepare some values:
1511 $maxitems = intval($config['maxitems']);
1512
1513 // If a SINGLE selector box...
1514 if ($maxitems<=1) {
1515 $item = $this->getSingleField_typeSelect_single($table,$field,$row,$PA,$config,$selItems,$nMV_label);
1516 } elseif (!strcmp($config['renderMode'],'checkbox')) { // Checkbox renderMode
1517 $item = $this->getSingleField_typeSelect_checkbox($table,$field,$row,$PA,$config,$selItems,$nMV_label);
1518 } elseif (!strcmp($config['renderMode'],'singlebox')) { // Single selector box renderMode
1519 $item = $this->getSingleField_typeSelect_singlebox($table,$field,$row,$PA,$config,$selItems,$nMV_label);
1520 } else { // Traditional multiple selector box:
1521 $item = $this->getSingleField_typeSelect_multiple($table,$field,$row,$PA,$config,$selItems,$nMV_label);
1522 }
1523
1524 // Wizards:
1525 if (!$disabled) {
1526 $altItem = '<input type="hidden" name="'.$PA['itemFormElName'].'" value="'.htmlspecialchars($PA['itemFormElValue']).'" />';
1527 $item = $this->renderWizards(array($item,$altItem),$config['wizards'],$table,$row,$field,$PA,$PA['itemFormElName'],$specConf);
1528 }
1529
1530 return $item;
1531 }
1532
1533 /**
1534 * Creates a single-selector box
1535 * (Render function for getSingleField_typeSelect())
1536 *
1537 * @param string See getSingleField_typeSelect()
1538 * @param string See getSingleField_typeSelect()
1539 * @param array See getSingleField_typeSelect()
1540 * @param array See getSingleField_typeSelect()
1541 * @param array (Redundant) content of $PA['fieldConf']['config'] (for convenience)
1542 * @param array Items available for selection
1543 * @param string Label for no-matching-value
1544 * @return string The HTML code for the item
1545 * @see getSingleField_typeSelect()
1546 */
1547 function getSingleField_typeSelect_single($table,$field,$row,&$PA,$config,$selItems,$nMV_label) {
1548 // check against inline uniqueness
1549 $inlineParent = $this->inline->getStructureLevel(-1);
1550 if(is_array($inlineParent) && $inlineParent['uid']) {
1551 if ($inlineParent['config']['foreign_table'] == $table && $inlineParent['config']['foreign_unique'] == $field) {
1552 $uniqueIds = $this->inline->inlineData['unique'][$this->inline->inlineNames['object'].'['.$table.']']['used'];
1553 $PA['fieldChangeFunc']['inlineUnique'] = "inline.updateUnique(this,'".$this->inline->inlineNames['object'].'['.$table."]','".$this->inline->inlineNames['form']."','".$row['uid']."');";
1554 }
1555 // hide uid of parent record for symmetric relations
1556 if ($inlineParent['config']['foreign_table'] == $table && ($inlineParent['config']['foreign_field'] == $field || $inlineParent['config']['symmetric_field'] == $field)) {
1557 $uniqueIds[] = $inlineParent['uid'];
1558 }
1559 }
1560
1561 // Initialization:
1562 $c = 0;
1563 $sI = 0;
1564 $noMatchingValue = 1;
1565 $opt = array();
1566 $selicons = array();
1567 $onlySelectedIconShown = 0;
1568 $size = intval($config['size']);
1569 $selectedStyle = ''; // Style set on <select/>
1570
1571 $disabled = '';
1572 if($this->renderReadonly || $config['readOnly']) {
1573 $disabled = ' disabled="disabled"';
1574 $onlySelectedIconShown = 1;
1575 }
1576
1577 // Icon configuration:
1578 if ($config['suppress_icons']=='IF_VALUE_FALSE') {
1579 $suppressIcons = !$PA['itemFormElValue'] ? 1 : 0;
1580 } elseif ($config['suppress_icons']=='ONLY_SELECTED') {
1581 $suppressIcons=0;
1582 $onlySelectedIconShown=1;
1583 } elseif ($config['suppress_icons']) {
1584 $suppressIcons = 1;
1585 } else $suppressIcons = 0;
1586
1587 // Traverse the Array of selector box items:
1588 $optGroupStart = array();
1589 foreach($selItems as $p) {
1590 $sM = (!strcmp($PA['itemFormElValue'],$p[1])?' selected="selected"':'');
1591 if ($sM) {
1592 $sI = $c;
1593 $noMatchingValue = 0;
1594 }
1595
1596 // Getting style attribute value (for icons):
1597 if ($config['iconsInOptionTags']) {
1598 $styleAttrValue = $this->optionTagStyle($p[2]);
1599 if ($sM) {
1600 list($selectIconFile,$selectIconInfo) = $this->getIcon($p[2]);
1601 if (!empty($selectIconInfo)) {
1602 $selectedStyle = ' style="background-image: url('.$selectIconFile.'); background-repeat: no-repeat; background-position: 0% 50%; padding: 1px; padding-left: 24px; -webkit-background-size: 0;"';
1603 }
1604 }
1605 }
1606
1607 // Compiling the <option> tag:
1608 if (!($p[1] != $PA['itemFormElValue'] && is_array($uniqueIds) && in_array($p[1], $uniqueIds))) {
1609 if(!strcmp($p[1],'--div--')) {
1610 $optGroupStart[0] = $p[0];
1611 $optGroupStart[1] = $styleAttrValue;
1612
1613 } else {
1614 if (count($optGroupStart)) {
1615 if($optGroupOpen) { // Closing last optgroup before next one starts
1616 $opt[]='</optgroup>' . "\n";
1617 }
1618 $opt[]= '<optgroup label="'.t3lib_div::deHSCentities(htmlspecialchars($optGroupStart[0])).'"'.
1619 ($optGroupStart[1] ? ' style="'.htmlspecialchars($optGroupStart[1]).'"' : '').
1620 ' class="c-divider">' . "\n";
1621 $optGroupOpen = true;
1622 $c--;
1623 $optGroupStart = array();
1624 }
1625 $opt[]= '<option value="'.htmlspecialchars($p[1]).'"'.
1626 $sM.
1627 ($styleAttrValue ? ' style="'.htmlspecialchars($styleAttrValue).'"' : '').
1628 '>'.t3lib_div::deHSCentities(htmlspecialchars($p[0])).'</option>' . "\n";
1629 }
1630 }
1631
1632 // If there is an icon for the selector box (rendered in table under)...:
1633 if ($p[2] && !$suppressIcons && (!$onlySelectedIconShown || $sM)) {
1634 list($selIconFile,$selIconInfo)=$this->getIcon($p[2]);
1635 $iOnClick = $this->elName($PA['itemFormElName']) . '.selectedIndex=' . $c . '; ' .
1636 $this->elName($PA['itemFormElName']) . '.style.backgroundImage=' . $this->elName($PA['itemFormElName']) . '.options[' . $c .'].style.backgroundImage; ' .
1637 implode('',$PA['fieldChangeFunc']).$this->blur().'return false;';
1638 $selicons[]=array(
1639 (!$onlySelectedIconShown ? '<a href="#" onclick="'.htmlspecialchars($iOnClick).'">' : '').
1640 '<img src="'.$selIconFile.'" '.$selIconInfo[3].' vspace="2" border="0" title="'.htmlspecialchars($p[0]).'" alt="'.htmlspecialchars($p[0]).'" />'.
1641 (!$onlySelectedIconShown ? '</a>' : ''),
1642 $c,$sM);
1643 $onChangeIcon = 'this.style.backgroundImage=this.options[this.selectedIndex].style.backgroundImage;';
1644 }
1645 $c++;
1646 }
1647
1648 if($optGroupOpen) { // Closing optgroup if open
1649 $opt[]='</optgroup>';
1650 $optGroupOpen = false;
1651 }
1652
1653 // No-matching-value:
1654 if ($PA['itemFormElValue'] && $noMatchingValue && !$PA['fieldTSConfig']['disableNoMatchingValueElement'] && !$config['disableNoMatchingValueElement']) {
1655 $nMV_label = @sprintf($nMV_label, $PA['itemFormElValue']);
1656 $opt[]= '<option value="'.htmlspecialchars($PA['itemFormElValue']).'" selected="selected">'.htmlspecialchars($nMV_label).'</option>';
1657 }
1658
1659 // Create item form fields:
1660 $sOnChange = 'if (this.options[this.selectedIndex].value==\'--div--\') {this.selectedIndex='.$sI.';} '.implode('',$PA['fieldChangeFunc']);
1661 if(!$disabled) {
1662 $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...
1663 }
1664 $item .= '<select' . $selectedStyle . ' id="' . uniqid('tceforms-select-') . '" name="' . $PA['itemFormElName'] . '"' .
1665 ($config['iconsInOptionTags'] ? $this->insertDefStyle('select', 'icon-select') : $this->insertDefStyle('select')) .
1666 ($size ? ' size="' . $size . '"' : '') .
1667 ' onchange="' . htmlspecialchars($onChangeIcon . $sOnChange) . '"' .
1668 $PA['onFocus'] . $disabled . '>';
1669 $item.= implode('',$opt);
1670 $item.= '</select>';
1671
1672 // Create icon table:
1673 if (count($selicons) && !$config['noIconsBelowSelect']) {
1674 $item.='<table border="0" cellpadding="0" cellspacing="0" class="typo3-TCEforms-selectIcons">';
1675 $selicon_cols = intval($config['selicon_cols']);
1676 if (!$selicon_cols) $selicon_cols=count($selicons);
1677 $sR = ceil(count($selicons)/$selicon_cols);
1678 $selicons = array_pad($selicons,$sR*$selicon_cols,'');
1679 for($sa=0;$sa<$sR;$sa++) {
1680 $item.='<tr>';
1681 for($sb=0;$sb<$selicon_cols;$sb++) {
1682 $sk=($sa*$selicon_cols+$sb);
1683 $imgN = 'selIcon_'.$table.'_'.$row['uid'].'_'.$field.'_'.$selicons[$sk][1];
1684 $imgS = ($selicons[$sk][2]?$this->backPath.'gfx/content_selected.gif':'clear.gif');
1685 $item.='<td><img name="'.htmlspecialchars($imgN).'" src="'.$imgS.'" width="7" height="10" alt="" /></td>';
1686 $item.='<td>'.$selicons[$sk][0].'</td>';
1687 }
1688 $item.='</tr>';
1689 }
1690 $item.='</table>';
1691 }
1692
1693 return $item;
1694 }
1695
1696 /**
1697 * Creates a checkbox list (renderMode = "checkbox")
1698 * (Render function for getSingleField_typeSelect())
1699 *
1700 * @param string See getSingleField_typeSelect()
1701 * @param string See getSingleField_typeSelect()
1702 * @param array See getSingleField_typeSelect()
1703 * @param array See getSingleField_typeSelect()
1704 * @param array (Redundant) content of $PA['fieldConf']['config'] (for convenience)
1705 * @param array Items available for selection
1706 * @param string Label for no-matching-value
1707 * @return string The HTML code for the item
1708 * @see getSingleField_typeSelect()
1709 */
1710 function getSingleField_typeSelect_checkbox($table,$field,$row,&$PA,$config,$selItems,$nMV_label) {
1711
1712 // Get values in an array (and make unique, which is fine because there can be no duplicates anyway):
1713 $itemArray = array_flip($this->extractValuesOnlyFromValueLabelList($PA['itemFormElValue']));
1714
1715 $disabled = '';
1716 if($this->renderReadonly || $config['readOnly']) {
1717 $disabled = ' disabled="disabled"';
1718 }
1719
1720 // Traverse the Array of selector box items:
1721 $tRows = array();
1722 $c=0;
1723 if (!$disabled) {
1724 $sOnChange = implode('',$PA['fieldChangeFunc']);
1725 $setAll = array(); // Used to accumulate the JS needed to restore the original selection.
1726 foreach($selItems as $p) {
1727 // Non-selectable element:
1728 if (!strcmp($p[1],'--div--')) {
1729 if (count($setAll)) {
1730 $tRows[] = '
1731 <tr class="c-header-checkbox-controls">
1732 <td colspan="3">' .
1733 '<a href="#" onclick="' . htmlspecialchars(implode('', $setAll).' return false;') . '">' .
1734 htmlspecialchars($this->getLL('l_checkAll')) .
1735 '</a>
1736 <a href="#" onclick="' . htmlspecialchars(implode('', $unSetAll).' return false;').'">' .
1737 htmlspecialchars($this->getLL('l_uncheckAll')) .
1738 '</a>
1739 </td>
1740 </tr>';
1741 $setAll = array();
1742 }
1743
1744 $tRows[] = '
1745 <tr class="c-header">
1746 <td colspan="3">'.htmlspecialchars($p[0]).'</td>
1747 </tr>';
1748 } else {
1749 // Selected or not by default:
1750 $sM = '';
1751 if (isset($itemArray[$p[1]])) {
1752 $sM = ' checked="checked"';
1753 unset($itemArray[$p[1]]);
1754 }
1755
1756 // Icon:
1757 $selIconFile = '';
1758 if ($p[2]) {
1759 list($selIconFile,$selIconInfo) = $this->getIcon($p[2]);
1760 }
1761
1762 // Compile row:
1763 $rowId = uniqid('select_checkbox_row_');
1764 $onClickCell = $this->elName($PA['itemFormElName'] . '[' . $c . ']') . '.checked=!' . $this->elName($PA['itemFormElName'] . '[' . $c . ']') . '.checked;';
1765 $onClick = 'this.attributes.getNamedItem("class").nodeValue = ' . $this->elName($PA['itemFormElName'] . '[' . $c . ']') . '.checked ? "c-selectedItem" : "c-unselectedItem";';
1766 $setAll[] = $this->elName($PA['itemFormElName'] . '[' . $c . ']') . '.checked=1;';
1767 $setAll[] .= '$(\'' . $rowId . '\').removeClassName(\'c-unselectedItem\');$(\'' . $rowId . '\').addClassName(\'c-selectedItem\');';
1768 $unSetAll[] = $this->elName($PA['itemFormElName'].'['.$c.']').'.checked=0;';
1769 $unSetAll[] .= '$(\'' . $rowId . '\').removeClassName(\'c-selectedItem\');$(\'' . $rowId . '\').addClassName(\'c-unselectedItem\');';
1770 $restoreCmd[] = $this->elName($PA['itemFormElName'] . '[' . $c . ']') . '.checked=' . ($sM ? 1 : 0) . ';' .
1771 '$(\'' . $rowId . '\').removeClassName(\'c-selectedItem\');$(\'' . $rowId . '\').removeClassName(\'c-unselectedItem\');' .
1772 '$(\'' . $rowId . '\').addClassName(\'c-' . ($sM ? '' : 'un') . 'selectedItem\');';
1773
1774 $hasHelp = ($p[3] !='');
1775
1776 $label = t3lib_div::deHSCentities(htmlspecialchars($p[0]));
1777 $help = $hasHelp ? '<span class="typo3-csh-inline show-right"><span class="header">' . $label . '</span>' .
1778 '<span class="paragraph">' . $GLOBALS['LANG']->hscAndCharConv(nl2br(trim(htmlspecialchars($p[3]))), false) . '</span></span>' : '';
1779
1780 if ($hasHelp && $this->edit_showFieldHelp == 'icon') {
1781 $helpIcon = '<a class="typo3-csh-link" href="#">';
1782 $helpIcon .= '<img' . t3lib_iconWorks::skinImg($this->backPath, 'gfx/helpbubble.gif', 'width="14" height="14"');
1783 $helpIcon .= ' hspace="2" border="0" class="absmiddle"' . ($GLOBALS['CLIENT']['FORMSTYLE'] ? ' style="cursor:help;"' : '') . ' alt="" />' . $help;
1784 $helpIcon .= '</a>';
1785 $help = $helpIcon;
1786 }
1787
1788 $tRows[] = '
1789 <tr id="' . $rowId . '" class="'.($sM ? 'c-selectedItem' : 'c-unselectedItem').'" onclick="'.htmlspecialchars($onClick).'" style="cursor: pointer;">
1790 <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>
1791 <td class="c-labelCell" onclick="'.htmlspecialchars($onClickCell).'">'.
1792 ($selIconFile ? '<img src="'.$selIconFile.'" '.$selIconInfo[3].' vspace="2" border="0" class="absmiddle" style="margin-right: 4px;" alt="" />' : '').
1793 $label .
1794 '</td>
1795 <td class="c-descr" onclick="'.htmlspecialchars($onClickCell).'">' . (strcmp($p[3],'') ? $help : '') . '</td>
1796 </tr>';
1797 $c++;
1798 }
1799 }
1800
1801 // Remaining checkboxes will get their set-all link:
1802 if (count($setAll)) {
1803 $tRows[] = '
1804 <tr class="c-header-checkbox-controls">
1805 <td colspan="3">'.
1806 '<a href="#" onclick="' . htmlspecialchars(implode('', $setAll).' return false;') . '">' .
1807 htmlspecialchars($this->getLL('l_checkAll')) .
1808 '</a>
1809 <a href="#" onclick="' . htmlspecialchars(implode('', $unSetAll).' return false;') . '">' .
1810 htmlspecialchars($this->getLL('l_uncheckAll')) .
1811 '</a>
1812 </td>
1813 </tr>';
1814 }
1815 }
1816
1817 // Remaining values (invalid):
1818 if (count($itemArray) && !$PA['fieldTSConfig']['disableNoMatchingValueElement'] && !$config['disableNoMatchingValueElement']) {
1819 foreach($itemArray as $theNoMatchValue => $temp) {
1820 // Compile <checkboxes> tag:
1821 array_unshift($tRows,'
1822 <tr class="c-invalidItem">
1823 <td><input type="checkbox"'.$this->insertDefStyle('check').' name="'.htmlspecialchars($PA['itemFormElName'].'['.$c.']').'" value="'.htmlspecialchars($theNoMatchValue).'" checked="checked" onclick="'.htmlspecialchars($sOnChange).'"'.$PA['onFocus'].$disabled.' /></td>
1824 <td class="c-labelCell">'.
1825 t3lib_div::deHSCentities(htmlspecialchars(@sprintf($nMV_label, $theNoMatchValue))).
1826 '</td><td>&nbsp;</td>
1827 </tr>');
1828 $c++;
1829 }
1830 }
1831
1832 // Add an empty hidden field which will send a blank value if all items are unselected.
1833 $item .= '<input type="hidden" name="'.htmlspecialchars($PA['itemFormElName']) . '" value="" />';
1834
1835 // Add revert icon
1836 if (is_array($restoreCmd)) {
1837 $item .= '<a href="#" onclick="' . implode('', $restoreCmd).' return false;' . '">' .
1838 '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/undo.gif','width="13" height="12"') . ' title="' .
1839 htmlspecialchars($this->getLL('l_revertSelection')) . '" alt="" />' .'</a>';
1840 }
1841 // Implode rows in table:
1842 $item .= '
1843 <table border="0" cellpadding="0" cellspacing="0" class="typo3-TCEforms-select-checkbox">'.
1844 implode('',$tRows).'
1845 </table>
1846 ';
1847
1848 return $item;
1849 }
1850
1851 /**
1852 * Creates a selectorbox list (renderMode = "singlebox")
1853 * (Render function for getSingleField_typeSelect())
1854 *
1855 * @param string See getSingleField_typeSelect()
1856 * @param string See getSingleField_typeSelect()
1857 * @param array See getSingleField_typeSelect()
1858 * @param array See getSingleField_typeSelect()
1859 * @param array (Redundant) content of $PA['fieldConf']['config'] (for convenience)
1860 * @param array Items available for selection
1861 * @param string Label for no-matching-value
1862 * @return string The HTML code for the item
1863 * @see getSingleField_typeSelect()
1864 */
1865 function getSingleField_typeSelect_singlebox($table,$field,$row,&$PA,$config,$selItems,$nMV_label) {
1866
1867 // Get values in an array (and make unique, which is fine because there can be no duplicates anyway):
1868 $itemArray = array_flip($this->extractValuesOnlyFromValueLabelList($PA['itemFormElValue']));
1869
1870 $disabled = '';
1871 if($this->renderReadonly || $config['readOnly']) {
1872 $disabled = ' disabled="disabled"';
1873 }
1874
1875 // Traverse the Array of selector box items:
1876 $opt = array();
1877 $restoreCmd = array(); // Used to accumulate the JS needed to restore the original selection.
1878 $c = 0;
1879 foreach($selItems as $p) {
1880 // Selected or not by default:
1881 $sM = '';
1882 if (isset($itemArray[$p[1]])) {
1883 $sM = ' selected="selected"';
1884 $restoreCmd[] = $this->elName($PA['itemFormElName'].'[]').'.options['.$c.'].selected=1;';
1885 unset($itemArray[$p[1]]);
1886 }
1887
1888 // Non-selectable element:
1889 $nonSel = '';
1890 if (!strcmp($p[1],'--div--')) {
1891 $nonSel = ' onclick="this.selected=0;" class="c-divider"';
1892 }
1893
1894 // Icon style for option tag:
1895 if ($config['iconsInOptionTags']) {
1896 $styleAttrValue = $this->optionTagStyle($p[2]);
1897 }
1898
1899 // Compile <option> tag:
1900 $opt[] = '<option value="'.htmlspecialchars($p[1]).'"'.
1901 $sM.
1902 $nonSel.
1903 ($styleAttrValue ? ' style="'.htmlspecialchars($styleAttrValue).'"' : '').
1904 '>'.t3lib_div::deHSCentities(htmlspecialchars($p[0])).'</option>';
1905 $c++;
1906 }
1907
1908 // Remaining values:
1909 if (count($itemArray) && !$PA['fieldTSConfig']['disableNoMatchingValueElement'] && !$config['disableNoMatchingValueElement']) {
1910 foreach($itemArray as $theNoMatchValue => $temp) {
1911 // Compile <option> tag:
1912 array_unshift($opt,'<option value="'.htmlspecialchars($theNoMatchValue).'" selected="selected">'.t3lib_div::deHSCentities(htmlspecialchars(@sprintf($nMV_label, $theNoMatchValue))).'</option>');
1913 }
1914 }
1915
1916 // Compile selector box:
1917 $sOnChange = implode('',$PA['fieldChangeFunc']);
1918 $selector_itemListStyle = isset($config['itemListStyle']) ? ' style="'.htmlspecialchars($config['itemListStyle']).'"' : ' style="'.$this->defaultMultipleSelectorStyle.'"';
1919 $size = intval($config['size']);
1920 $size = $config['autoSizeMax'] ? t3lib_div::intInRange(count($selItems)+1,t3lib_div::intInRange($size,1),$config['autoSizeMax']) : $size;
1921 $selectBox = '<select id="' . uniqid('tceforms-multiselect-') . '" name="'.$PA['itemFormElName'].'[]"'.
1922 $this->insertDefStyle('select', 'tceforms-multiselect').
1923 ($size ? ' size="'.$size.'"' : '').
1924 ' multiple="multiple" onchange="'.htmlspecialchars($sOnChange).'"'.
1925 $PA['onFocus'].
1926 $selector_itemListStyle.
1927 $disabled.'>
1928 '.
1929 implode('
1930 ',$opt).'
1931 </select>';
1932
1933 // Add an empty hidden field which will send a blank value if all items are unselected.
1934 if (!$disabled) {
1935 $item.='<input type="hidden" name="'.htmlspecialchars($PA['itemFormElName']).'" value="" />';
1936 }
1937
1938 // Put it all into a table:
1939 $item.= '
1940 <table border="0" cellspacing="0" cellpadding="0" width="1" class="typo3-TCEforms-select-singlebox">
1941 <tr>
1942 <td>
1943 '.$selectBox.'
1944 <br/>
1945 <em>'.
1946 htmlspecialchars($this->getLL('l_holdDownCTRL')).
1947 '</em>
1948 </td>
1949 <td valign="top">
1950 <a href="#" onclick="'.htmlspecialchars($this->elName($PA['itemFormElName'].'[]').'.selectedIndex=-1;'.implode('',$restoreCmd).' return false;').'">'.
1951 '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/undo.gif','width="13" height="12"').' title="'.htmlspecialchars($this->getLL('l_revertSelection')).'" alt="" />'.
1952 '</a>
1953 </td>
1954 </tr>
1955 </table>
1956 ';
1957
1958 return $item;
1959 }
1960
1961 /**
1962 * Creates a multiple-selector box (two boxes, side-by-side)
1963 * (Render function for getSingleField_typeSelect())
1964 *
1965 * @param string See getSingleField_typeSelect()
1966 * @param string See getSingleField_typeSelect()
1967 * @param array See getSingleField_typeSelect()
1968 * @param array See getSingleField_typeSelect()
1969 * @param array (Redundant) content of $PA['fieldConf']['config'] (for convenience)
1970 * @param array Items available for selection
1971 * @param string Label for no-matching-value
1972 * @return string The HTML code for the item
1973 * @see getSingleField_typeSelect()
1974 */
1975 function getSingleField_typeSelect_multiple($table,$field,$row,&$PA,$config,$selItems,$nMV_label) {
1976
1977 $disabled = '';
1978 if($this->renderReadonly || $config['readOnly']) {
1979 $disabled = ' disabled="disabled"';
1980 }
1981
1982 // Setting this hidden field (as a flag that JavaScript can read out)
1983 if (!$disabled) {
1984 $item.= '<input type="hidden" name="'.$PA['itemFormElName'].'_mul" value="'.($config['multiple']?1:0).'" />';
1985 }
1986
1987 // Set max and min items:
1988 $maxitems = t3lib_div::intInRange($config['maxitems'],0);
1989 if (!$maxitems) $maxitems=100000;
1990 $minitems = t3lib_div::intInRange($config['minitems'],0);
1991
1992 // Register the required number of elements:
1993 $this->registerRequiredProperty('range', $PA['itemFormElName'], array($minitems,$maxitems,'imgName'=>$table.'_'.$row['uid'].'_'.$field));
1994
1995 // Get "removeItems":
1996 $removeItems = t3lib_div::trimExplode(',',$PA['fieldTSConfig']['removeItems'],1);
1997
1998 // Get the array with selected items:
1999 $itemArray = t3lib_div::trimExplode(',', $PA['itemFormElValue'], 1);
2000
2001 // Possibly filter some items:
2002 $keepItemsFunc = create_function('$value', '$parts=explode(\'|\',$value,2); return rawurldecode($parts[0]);');
2003 $itemArray = t3lib_div::keepItemsInArray($itemArray, $PA['fieldTSConfig']['keepItems'], $keepItemsFunc);
2004
2005 // Perform modification of the selected items array:
2006 foreach($itemArray as $tk => $tv) {
2007 $tvP = explode('|',$tv,2);
2008 $evalValue = rawurldecode($tvP[0]);
2009 $isRemoved = in_array($evalValue,$removeItems) || ($config['form_type']=='select' && $config['authMode'] && !$GLOBALS['BE_USER']->checkAuthMode($table,$field,$evalValue,$config['authMode']));
2010 if ($isRemoved && !$PA['fieldTSConfig']['disableNoMatchingValueElement'] && !$config['disableNoMatchingValueElement']) {
2011 $tvP[1] = rawurlencode(@sprintf($nMV_label, $evalValue));
2012 } elseif (isset($PA['fieldTSConfig']['altLabels.'][$evalValue])) {
2013 $tvP[1] = rawurlencode($this->sL($PA['fieldTSConfig']['altLabels.'][$evalValue]));
2014 }
2015 $itemArray[$tk] = implode('|',$tvP);
2016 }
2017 $itemsToSelect = '';
2018
2019 if(!$disabled) {
2020 // Create option tags:
2021 $opt = array();
2022 $styleAttrValue = '';
2023 foreach($selItems as $p) {
2024 if ($config['iconsInOptionTags']) {
2025 $styleAttrValue = $this->optionTagStyle($p[2]);
2026 }
2027 $opt[]= '<option value="'.htmlspecialchars($p[1]).'"'.
2028 ($styleAttrValue ? ' style="'.htmlspecialchars($styleAttrValue).'"' : '').
2029 '>'.htmlspecialchars($p[0]).'</option>';
2030 }
2031
2032 // Put together the selector box:
2033 $selector_itemListStyle = isset($config['itemListStyle']) ? ' style="'.htmlspecialchars($config['itemListStyle']).'"' : ' style="'.$this->defaultMultipleSelectorStyle.'"';
2034 $size = intval($config['size']);
2035 $size = $config['autoSizeMax'] ? t3lib_div::intInRange(count($itemArray)+1,t3lib_div::intInRange($size,1),$config['autoSizeMax']) : $size;
2036 if ($config['exclusiveKeys']) {
2037 $sOnChange = 'setFormValueFromBrowseWin(\''.$PA['itemFormElName'].'\',this.options[this.selectedIndex].value,this.options[this.selectedIndex].text,\''.$config['exclusiveKeys'].'\'); ';
2038 } else {
2039 $sOnChange = 'setFormValueFromBrowseWin(\''.$PA['itemFormElName'].'\',this.options[this.selectedIndex].value,this.options[this.selectedIndex].text); ';
2040 }
2041 $sOnChange .= implode('',$PA['fieldChangeFunc']);
2042 $itemsToSelect = '
2043 <select id="' . uniqid('tceforms-multiselect-') . '" name="'.$PA['itemFormElName'].'_sel"'.
2044 $this->insertDefStyle('select', 'tceforms-multiselect tceforms-itemstoselect').
2045 ($size ? ' size="'.$size.'"' : '').
2046 ' onchange="'.htmlspecialchars($sOnChange).'"'.
2047 $PA['onFocus'].
2048 $selector_itemListStyle.'>
2049 '.implode('
2050 ',$opt).'
2051 </select>';
2052 }
2053
2054 // Pass to "dbFileIcons" function:
2055 $params = array(
2056 'size' => $size,
2057 'autoSizeMax' => t3lib_div::intInRange($config['autoSizeMax'],0),
2058 'style' => isset($config['selectedListStyle']) ? ' style="'.htmlspecialchars($config['selectedListStyle']).'"' : ' style="'.$this->defaultMultipleSelectorStyle.'"',
2059 'dontShowMoveIcons' => ($maxitems<=1),
2060 'maxitems' => $maxitems,
2061 'info' => '',
2062 'headers' => array(
2063 'selector' => $this->getLL('l_selected').':<br />',
2064 'items' => $this->getLL('l_items').':<br />'
2065 ),
2066 'noBrowser' => 1,
2067 'thumbnails' => $itemsToSelect,
2068 'readOnly' => $disabled
2069 );
2070 $item.= $this->dbFileIcons($PA['itemFormElName'],'','',$itemArray,'',$params,$PA['onFocus']);
2071
2072 return $item;
2073 }
2074
2075 /**
2076 * Generation of TCEform elements of the type "group"
2077 * This will render a selectorbox into which elements from either the file system or database can be inserted. Relations.
2078 *
2079 * @param string The table name of the record
2080 * @param string The field name which this element is supposed to edit
2081 * @param array The record data array where the value(s) for the field can be found
2082 * @param array An array with additional configuration options.
2083 * @return string The HTML code for the TCEform field
2084 */
2085 function getSingleField_typeGroup($table,$field,$row,&$PA) {
2086 // Init:
2087 $config = $PA['fieldConf']['config'];
2088 $internal_type = $config['internal_type'];
2089 $show_thumbs = $config['show_thumbs'];
2090 $size = intval($config['size']);
2091 $maxitems = t3lib_div::intInRange($config['maxitems'],0);
2092 if (!$maxitems) $maxitems=100000;
2093 $minitems = t3lib_div::intInRange($config['minitems'],0);
2094 $allowed = trim($config['allowed']);
2095 $disallowed = trim($config['disallowed']);
2096
2097 $disabled = '';
2098 if($this->renderReadonly || $config['readOnly']) {
2099 $disabled = ' disabled="disabled"';
2100 }
2101
2102 $item.= '<input type="hidden" name="'.$PA['itemFormElName'].'_mul" value="'.($config['multiple']?1:0).'"'.$disabled.' />';
2103 $this->registerRequiredProperty('range', $PA['itemFormElName'], array($minitems,$maxitems,'imgName'=>$table.'_'.$row['uid'].'_'.$field));
2104 $info='';
2105
2106 // "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/.
2107 $specConf = $this->getSpecConfFromString($PA['extra'], $PA['fieldConf']['defaultExtras']);
2108
2109 // Acting according to either "file" or "db" type:
2110 switch((string)$config['internal_type']) {
2111 case 'file_reference':
2112 $config['uploadfolder'] = '';
2113 // Fall through
2114 case 'file': // If the element is of the internal type "file":
2115
2116 // Creating string showing allowed types:
2117 $tempFT = t3lib_div::trimExplode(',',$allowed,1);
2118 if (!count($tempFT)) {$info.='*';}
2119 foreach($tempFT as $ext) {
2120 if ($ext) {
2121 $info.=strtoupper($ext).' ';
2122 }
2123 }
2124 // Creating string, showing disallowed types:
2125 $tempFT_dis = t3lib_div::trimExplode(',',$disallowed,1);
2126 if (count($tempFT_dis)) {$info.='<br />';}
2127 foreach($tempFT_dis as $ext) {
2128 if ($ext) {
2129 $info.='-'.strtoupper($ext).' ';
2130 }
2131 }
2132
2133 // Making the array of file items:
2134 $itemArray = t3lib_div::trimExplode(',',$PA['itemFormElValue'],1);
2135
2136 // Showing thumbnails:
2137 $thumbsnail = '';
2138 if ($show_thumbs) {
2139 $imgs = array();
2140 foreach($itemArray as $imgRead) {
2141 $imgP = explode('|',$imgRead);
2142 $imgPath = rawurldecode($imgP[0]);
2143
2144 $rowCopy = array();
2145 $rowCopy[$field] = $imgPath;
2146
2147 // Icon + clickmenu:
2148 $absFilePath = t3lib_div::getFileAbsFileName($config['uploadfolder'] ? $config['uploadfolder'] . '/' . $imgPath : $imgPath);
2149
2150 $fI = pathinfo($imgPath);
2151 $fileIcon = t3lib_BEfunc::getFileIcon(strtolower($fI['extension']));
2152 $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="" />';
2153
2154 $imgs[] = '<span class="nobr">'.t3lib_BEfunc::thumbCode($rowCopy,$table,$field,$this->backPath,'thumbs.php',$config['uploadfolder'],0,' align="middle"').
2155 ($absFilePath ? $this->getClickMenu($fileIcon, $absFilePath) : $fileIcon).
2156 $imgPath.
2157 '</span>';
2158 }
2159 $thumbsnail = implode('<br />',$imgs);
2160 }
2161
2162 // Creating the element:
2163 $noList = isset($config['disable_controls']) && t3lib_div::inList($config['disable_controls'], 'list');
2164 $params = array(
2165 'size' => $size,
2166 'dontShowMoveIcons' => ($maxitems<=1),
2167 'autoSizeMax' => t3lib_div::intInRange($config['autoSizeMax'],0),
2168 'maxitems' => $maxitems,
2169 'style' => isset($config['selectedListStyle']) ? ' style="'.htmlspecialchars($config['selectedListStyle']).'"' : ' style="'.$this->defaultMultipleSelectorStyle.'"',
2170 'info' => $info,
2171 'thumbnails' => $thumbsnail,
2172 'readOnly' => $disabled,
2173 'noBrowser' => $noList || isset($config['disable_controls']) && t3lib_div::inList($config['disable_controls'], 'browser'),
2174 'noList' => $noList,
2175 );
2176 $item.= $this->dbFileIcons($PA['itemFormElName'],'file',implode(',',$tempFT),$itemArray,'',$params,$PA['onFocus']);
2177
2178 if(!$disabled && !(isset($config['disable_controls']) && t3lib_div::inList($config['disable_controls'], 'upload'))) {
2179 // Adding the upload field:
2180 if ($this->edit_docModuleUpload && $config['uploadfolder']) {
2181 $item .= '<input type="file" name="' . $PA['itemFormElName_file'] . '"' . $this->formWidth() . ' size="60" />';
2182 }
2183 }
2184 break;
2185 case 'folder': // If the element is of the internal type "folder":
2186
2187 // array of folder items:
2188 $itemArray = t3lib_div::trimExplode(',', $PA['itemFormElValue'], 1);
2189
2190 // Creating the element:
2191 $params = array(
2192 'size' => $size,
2193 'dontShowMoveIcons' => ($maxitems <= 1),
2194 'autoSizeMax' => t3lib_div::intInRange($config['autoSizeMax'], 0),
2195 'maxitems' => $maxitems,
2196 'style' => isset($config['selectedListStyle']) ?
2197 ' style="'.htmlspecialchars($config['selectedListStyle']).'"'
2198 : ' style="'.$this->defaultMultipleSelectorStyle.'"',
2199 'info' => $info,
2200 'readOnly' => $disabled
2201 );
2202
2203 $item.= $this->dbFileIcons(
2204 $PA['itemFormElName'],
2205 'folder',
2206 '',
2207 $itemArray,
2208 '',
2209 $params,
2210 $PA['onFocus']
2211 );
2212 break;
2213 case 'db': // If the element is of the internal type "db":
2214
2215 // Creating string showing allowed types:
2216 $tempFT = t3lib_div::trimExplode(',', $allowed, true);
2217 if (!strcmp(trim($tempFT[0]), '*')) {
2218 $onlySingleTableAllowed = false;
2219 $info.='<span class="nobr">&nbsp;&nbsp;&nbsp;&nbsp;'.
2220 htmlspecialchars($this->getLL('l_allTables')).
2221 '</span><br />';
2222 } elseif ($tempFT) {
2223 $onlySingleTableAllowed = (count($tempFT) == 1);
2224 foreach ($tempFT as $theT) {
2225 $info.= '<span class="nobr">&nbsp;&nbsp;&nbsp;&nbsp;' .
2226 t3lib_iconWorks::getIconImage($theT, array(), $this->backPath, 'align="top"') .
2227 htmlspecialchars($this->sL($GLOBALS['TCA'][$theT]['ctrl']['title'])) .
2228 '</span><br />';
2229 }
2230 }
2231
2232 $perms_clause = $GLOBALS['BE_USER']->getPagePermsClause(1);
2233 $itemArray = array();
2234 $imgs = array();
2235
2236 // Thumbnails:
2237 $temp_itemArray = t3lib_div::trimExplode(',',$PA['itemFormElValue'],1);
2238 foreach($temp_itemArray as $dbRead) {
2239 $recordParts = explode('|',$dbRead);
2240 list($this_table,$this_uid) = t3lib_BEfunc::splitTable_Uid($recordParts[0]);
2241 // For the case that no table was found and only a single table is defined to be allowed, use that one:
2242 if (!$this_table && $onlySingleTableAllowed) {
2243 $this_table = $allowed;
2244 }
2245 $itemArray[] = array('table'=>$this_table, 'id'=>$this_uid);
2246 if (!$disabled && $show_thumbs) {
2247 $rr = t3lib_BEfunc::getRecordWSOL($this_table,$this_uid);
2248 $imgs[] = '<span class="nobr">'.
2249 $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).
2250 '&nbsp;'.
2251 t3lib_BEfunc::getRecordTitle($this_table,$rr,TRUE).' <span class="typo3-dimmed"><em>['.$rr['uid'].']</em></span>'.
2252 '</span>';
2253 }
2254 }
2255 $thumbsnail='';
2256 if (!$disabled && $show_thumbs) {
2257 $thumbsnail = implode('<br />',$imgs);
2258 }
2259
2260 // Creating the element:
2261 $params = array(
2262 'size' => $size,
2263 'dontShowMoveIcons' => ($maxitems<=1),
2264 'autoSizeMax' => t3lib_div::intInRange($config['autoSizeMax'],0),
2265 'maxitems' => $maxitems,
2266 'style' => isset($config['selectedListStyle']) ? ' style="'.htmlspecialchars($config['selectedListStyle']).'"' : ' style="'.$this->defaultMultipleSelectorStyle.'"',
2267 'info' => $info,
2268 'thumbnails' => $thumbsnail,
2269 'readOnly' => $disabled
2270 );
2271 $item.= $this->dbFileIcons($PA['itemFormElName'],'db',implode(',',$tempFT),$itemArray,'',$params,$PA['onFocus'],$table,$field,$row['uid']);
2272
2273 break;
2274 }
2275
2276 // Wizards:
2277 $altItem = '<input type="hidden" name="'.$PA['itemFormElName'].'" value="'.htmlspecialchars($PA['itemFormElValue']).'" />';
2278 if (!$disabled) {
2279 $item = $this->renderWizards(array($item,$altItem),$config['wizards'],$table,$row,$field,$PA,$PA['itemFormElName'],$specConf);
2280 }
2281
2282 return $item;
2283 }
2284
2285 /**
2286 * Generation of TCEform elements of the type "none"
2287 * This will render a non-editable display of the content of the field.
2288 *
2289 * @param string The table name of the record
2290 * @param string The field name which this element is supposed to edit
2291 * @param array The record data array where the value(s) for the field can be found
2292 * @param array An array with additional configuration options.
2293 * @return string The HTML code for the TCEform field
2294 */
2295 function getSingleField_typeNone($table,$field,$row,&$PA) {
2296 // Init:
2297 $config = $PA['fieldConf']['config'];
2298 $itemValue = $PA['itemFormElValue'];
2299
2300 return $this->getSingleField_typeNone_render($config,$itemValue);
2301 }
2302
2303 /**
2304 * HTML rendering of a value which is not editable.
2305 *
2306 * @param array Configuration for the display
2307 * @param string The value to display
2308 * @return string The HTML code for the display
2309 * @see getSingleField_typeNone();
2310 */
2311 function getSingleField_typeNone_render($config,$itemValue) {
2312
2313 // is colorScheme[0] the right value?
2314 $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;';
2315
2316 if ($config['format']) {
2317 $itemValue = $this->formatValue($config, $itemValue);
2318 }
2319
2320 $rows = intval($config['rows']);
2321 if ($rows > 1) {
2322 if(!$config['pass_content']) {
2323 $itemValue = nl2br(htmlspecialchars($itemValue));
2324 }
2325 // like textarea
2326 $cols = t3lib_div::intInRange($config['cols'] ? $config['cols'] : 30, 5, $this->maxTextareaWidth);
2327 if (!$config['fixedRows']) {
2328 $origRows = $rows = t3lib_div::intInRange($rows, 1, 20);
2329 if (strlen($itemValue)>$this->charsPerRow*2) {
2330 $cols = $this->maxTextareaWidth;
2331 $rows = t3lib_div::intInRange(round(strlen($itemValue)/$this->charsPerRow),count(explode(chr(10),$itemValue)),20);
2332 if ($rows<$origRows) $rows=$origRows;
2333 }
2334 }
2335
2336 if ($this->docLarge) $cols = round($cols*$this->form_largeComp);
2337 $width = ceil($cols*$this->form_rowsToStylewidth);
2338 // hardcoded: 12 is the height of the font
2339 $height=$rows*12;
2340
2341 $item='
2342 <div style="'.htmlspecialchars($divStyle.' overflow:auto; height:'.$height.'px; width:'.$width.'px;').'" class="'.htmlspecialchars($this->formElClass('none')).'">'.
2343 $itemValue.
2344 '</div>';
2345 } else {
2346 if(!$config['pass_content']) {
2347 $itemValue = htmlspecialchars($itemValue);
2348 }
2349
2350 $cols = $config['cols']?$config['cols']:($config['size']?$config['size']:$this->maxInputWidth);
2351 if ($this->docLarge) $cols = round($cols*$this->form_largeComp);
2352 $width = ceil($cols*$this->form_rowsToStylewidth);
2353
2354 // overflow:auto crashes mozilla here. Title tag is usefull when text is longer than the div box (overflow:hidden).
2355 $item = '
2356 <div style="'.htmlspecialchars($divStyle.' overflow:hidden; width:'.$width.'px;').'" class="'.htmlspecialchars($this->formElClass('none')).'" title="'.$itemValue.'">'.
2357 '<span class="nobr">'.(strcmp($itemValue,'')?$itemValue:'&nbsp;').'</span>'.
2358 '</div>';
2359 }
2360
2361 return $item;
2362 }
2363
2364 /**
2365 * Handler for Flex Forms
2366 *
2367 * @param string The table name of the record
2368 * @param string The field name which this element is supposed to edit
2369 * @param array The record data array where the value(s) for the field can be found
2370 * @param array An array with additional configuration options.
2371 * @return string The HTML code for the TCEform field
2372 */
2373 function getSingleField_typeFlex($table,$field,$row,&$PA) {
2374
2375 // Data Structure:
2376 $dataStructArray = t3lib_BEfunc::getFlexFormDS($PA['fieldConf']['config'],$row,$table);
2377
2378 // Get data structure:
2379 if (is_array($dataStructArray)) {
2380
2381 // Get data:
2382 $xmlData = $PA['itemFormElValue'];
2383 $xmlHeaderAttributes = t3lib_div::xmlGetHeaderAttribs($xmlData);
2384 $storeInCharset = strtolower($xmlHeaderAttributes['encoding']);
2385 if ($storeInCharset) {
2386 $currentCharset=$GLOBALS['LANG']->charSet;
2387 $xmlData = $GLOBALS['LANG']->csConvObj->conv($xmlData,$storeInCharset,$currentCharset,1);
2388 }
2389 $editData=t3lib_div::xml2array($xmlData);
2390 if (!is_array($editData)) { // Must be XML parsing error...
2391 $editData=array();
2392 } elseif (!isset($editData['meta']) || !is_array($editData['meta'])) {
2393 $editData['meta'] = array();
2394 }
2395
2396 // Find the data structure if sheets are found:
2397 $sheet = $editData['meta']['currentSheetId'] ? $editData['meta']['currentSheetId'] : 'sDEF'; // Sheet to display
2398
2399 // Create sheet menu:
2400 // if (is_array($dataStructArray['sheets'])) {
2401 // #$item.=$this->getSingleField_typeFlex_sheetMenu($dataStructArray['sheets'], $PA['itemFormElName'].'[meta][currentSheetId]', $sheet).'<br />';
2402 // }
2403
2404 // Create language menu:
2405 $langChildren = $dataStructArray['meta']['langChildren'] ? 1 : 0;
2406 $langDisabled = $dataStructArray['meta']['langDisable'] ? 1 : 0;
2407
2408 $editData['meta']['currentLangId']=array();
2409 $languages = $this->getAvailableLanguages();
2410
2411 foreach($languages as $lInfo) {
2412 if ($GLOBALS['BE_USER']->checkLanguageAccess($lInfo['uid'])) {
2413 $editData['meta']['currentLangId'][] = $lInfo['ISOcode'];
2414 }
2415 }
2416 if (!is_array($editData['meta']['currentLangId']) || !count($editData['meta']['currentLangId'])) {
2417 $editData['meta']['currentLangId']=array('DEF');
2418 }
2419
2420 $editData['meta']['currentLangId'] = array_unique($editData['meta']['currentLangId']);
2421
2422
2423 // if (!$langDisabled && count($languages) > 1) {
2424 // $item.=$this->getSingleField_typeFlex_langMenu($languages, $PA['itemFormElName'].'[meta][currentLangId]', $editData['meta']['currentLangId']).'<br />';
2425 // }
2426
2427 $PA['_noEditDEF'] = FALSE;
2428 if ($langChildren || $langDisabled) {
2429 $rotateLang = array('DEF');
2430 } else {
2431 if (!in_array('DEF',$editData['meta']['currentLangId'])) {
2432 array_unshift($editData['meta']['currentLangId'],'DEF');
2433 $PA['_noEditDEF'] = TRUE;
2434 }
2435 $rotateLang = $editData['meta']['currentLangId'];
2436 }
2437
2438 // Tabs sheets
2439 if (is_array($dataStructArray['sheets'])) {
2440 $tabsToTraverse = array_keys($dataStructArray['sheets']);
2441 } else {
2442 $tabsToTraverse = array($sheet);
2443 }
2444
2445 foreach ($rotateLang as $lKey) {
2446 if (!$langChildren && !$langDisabled) {
2447 $item.= '<b>'.$this->getLanguageIcon($table,$row,'v'.$lKey).$lKey.':</b>';
2448 }
2449
2450 $tabParts = array();
2451 foreach ($tabsToTraverse as $sheet) {
2452 list ($dataStruct, $sheet) = t3lib_div::resolveSheetDefInDS($dataStructArray,$sheet);
2453
2454 // Render sheet:
2455 if (is_array($dataStruct['ROOT']) && is_array($dataStruct['ROOT']['el'])) {
2456 $lang = 'l'.$lKey; // Default language, other options are "lUK" or whatever country code (independant of system!!!)
2457 $PA['_valLang'] = $langChildren && !$langDisabled ? $editData['meta']['currentLangId'] : 'DEF'; // Default language, other options are "lUK" or whatever country code (independant of system!!!)
2458 $PA['_lang'] = $lang;
2459 $PA['_cshFile'] = ((isset($dataStruct['ROOT']['TCEforms']) && isset($dataStruct['ROOT']['TCEforms']['cshFile'])) ? $dataStruct['ROOT']['TCEforms']['cshFile'] : '');
2460
2461 // Render flexform:
2462 $tRows = $this->getSingleField_typeFlex_draw(
2463 $dataStruct['ROOT']['el'],
2464 $editData['data'][$sheet][$lang],
2465 $table,
2466 $field,
2467 $row,
2468 $PA,
2469 '[data]['.$sheet.']['.$lang.']'
2470 );
2471 #$sheetContent= '<table border="0" cellpadding="1" cellspacing="1" class="typo3-TCEforms-flexForm">'.implode('',$tRows).'</table>';
2472 $sheetContent = '<div class="typo3-TCEforms-flexForm">'.$tRows.'</div>';
2473
2474 # $item = '<div style=" position:absolute;">'.$item.'</div>';
2475 //visibility:hidden;
2476 } else $sheetContent='Data Structure ERROR: No ROOT element found for sheet "'.$sheet.'".';
2477
2478 // Add to tab:
2479 $tabParts[] = array(
2480 'label' => ($dataStruct['ROOT']['TCEforms']['sheetTitle'] ? $this->sL($dataStruct['ROOT']['TCEforms']['sheetTitle']) : $sheet),
2481 'description' => ($dataStruct['ROOT']['TCEforms']['sheetDescription'] ? $this->sL($dataStruct['ROOT']['TCEforms']['sheetDescription']) : ''),
2482 'linkTitle' => ($dataStruct['ROOT']['TCEforms']['sheetShortDescr'] ? $this->sL($dataStruct['ROOT']['TCEforms']['sheetShortDescr']) : ''),
2483 'content' => $sheetContent
2484 );
2485 }
2486
2487 if (is_array($dataStructArray['sheets'])) {
2488 $dividersToTabsBehaviour = (isset($GLOBALS['TCA'][$table]['ctrl']['dividers2tabs']) ? $GLOBALS['TCA'][$table]['ctrl']['dividers2tabs'] : 1);
2489 $item.= $this->getDynTabMenu($tabParts, 'TCEFORMS:flexform:'.$PA['itemFormElName'].$PA['_lang'], $dividersToTabsBehaviour);
2490 } else {
2491 $item.= $sheetContent;
2492 }
2493 }
2494 } else $item='Data Structure ERROR: '.$dataStructArray;
2495
2496 return $item;
2497 }
2498
2499 /**
2500 * Creates the language menu for FlexForms:
2501 *
2502 * @param [type] $languages: ...
2503 * @param [type] $elName: ...
2504 * @param [type] $selectedLanguage: ...
2505 * @param [type] $multi: ...
2506 * @return string HTML for menu
2507 */
2508 function getSingleField_typeFlex_langMenu($languages,$elName,$selectedLanguage,$multi=1) {
2509 $opt=array();
2510 foreach($languages as $lArr) {
2511 $opt[]='<option value="'.htmlspecialchars($lArr['ISOcode']).'"'.(in_array($lArr['ISOcode'],$selectedLanguage)?' selected="selected"':'').'>'.htmlspecialchars($lArr['title']).'</option>';
2512 }
2513
2514 $output = '<select id="' . uniqid('tceforms-multiselect-') . ' class="tceforms-select tceforms-multiselect tceforms-flexlangmenu" name="'.$elName.'[]"'.($multi ? ' multiple="multiple" size="'.count($languages).'"' : '').'>'.implode('',$opt).'</select>';
2515
2516 return $output;
2517 }
2518
2519 /**
2520 * Creates the menu for selection of the sheets:
2521 *
2522 * @param array Sheet array for which to render the menu
2523 * @param string Form element name of the field containing the sheet pointer
2524 * @param string Current sheet key
2525 * @return string HTML for menu
2526 */
2527 function getSingleField_typeFlex_sheetMenu($sArr,$elName,$sheetKey) {
2528
2529 $tCells =array();
2530 $pct = round(100/count($sArr));
2531 foreach($sArr as $sKey => $sheetCfg) {
2532 if ($GLOBALS['BE_USER']->jsConfirmation(1)) {
2533 $onClick = 'if (confirm(TBE_EDITOR.labels.onChangeAlert) && TBE_EDITOR.checkSubmit(-1)){'.$this->elName($elName).".value='".$sKey."'; TBE_EDITOR.submitForm()};";
2534 } else {
2535 $onClick = 'if(TBE_EDITOR.checkSubmit(-1)){ '.$this->elName($elName).".value='".$sKey."'; TBE_EDITOR.submitForm();}";
2536 }
2537
2538
2539 $tCells[]='<td width="'.$pct.'%" style="'.($sKey==$sheetKey ? 'background-color: #9999cc; font-weight: bold;' : 'background-color: #aaaaaa;').' cursor: hand;" onclick="'.htmlspecialchars($onClick).'" align="center">'.
2540 ($sheetCfg['ROOT']['TCEforms']['sheetTitle'] ? $this->sL($sheetCfg['ROOT']['TCEforms']['sheetTitle']) : $sKey).
2541 '</td>';
2542 }
2543
2544 return '<table border="0" cellpadding="0" cellspacing="2" class="typo3-TCEforms-flexForm-sheetMenu"><tr>'.implode('',$tCells).'</tr></table>';
2545 }
2546
2547 /**
2548 * Recursive rendering of flexforms
2549 *
2550 * @param array (part of) Data Structure for which to render. Keys on first level is flex-form fields
2551 * @param array (part of) Data array of flexform corresponding to the input DS. Keys on first level is flex-form field names
2552 * @param string Table name, eg. tt_content
2553 * @param string Field name, eg. tx_templavoila_flex
2554 * @param array The particular record from $table in which the field $field is found
2555 * @param array Array of standard information for rendering of a form field in TCEforms, see other rendering functions too
2556 * @param string Form field prefix, eg. "[data][sDEF][lDEF][...][...]"
2557 * @param integer Indicates nesting level for the function call
2558 * @param string Prefix for ID-values
2559 * @param boolean Defines whether the next flexform level is open or closed. Comes from _TOGGLE pseudo field in FlexForm xml.
2560 * @return string HTMl code for form.
2561 */
2562 function getSingleField_typeFlex_draw($dataStruct,$editData,$table,$field,$row,&$PA,$formPrefix='',$level=0,$idPrefix='ID',$toggleClosed=FALSE) {
2563
2564 $output = '';
2565 $mayRestructureFlexforms = $GLOBALS['BE_USER']->checkLanguageAccess(0);
2566
2567 // Data Structure array must be ... and array of course...
2568 if (is_array($dataStruct)) {
2569 foreach($dataStruct as $key => $value) { // Traversing fields in structure:
2570 if (is_array($value)) { // The value of each entry must be an array.
2571
2572 // ********************
2573 // Making the row:
2574 // ********************
2575 // Title of field:
2576 $theTitle = htmlspecialchars(t3lib_div::fixed_lgd_cs($this->sL($value['tx_templavoila']['title']),30));
2577
2578 // If it's a "section" or "container":
2579 if ($value['type']=='array') {
2580
2581 // Creating IDs for form fields:
2582 // 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.
2583 $thisId = t3lib_div::shortMd5(uniqid('id',true)); // This is a suffix used for forms on this level
2584 $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.
2585
2586 // If it's a "section" containing other elements:
2587 if ($value['section']) {
2588
2589 // Load script.aculo.us if flexform sections can be moved by drag'n'drop:
2590 $GLOBALS['SOBE']->doc->loadScriptaculous();
2591 // Render header of section:
2592 $output.= '<div class="bgColor2"><strong>'.$theTitle.'</strong></div>';
2593
2594 // Render elements in data array for section:
2595 $tRows = array();
2596 $cc=0;
2597 if (is_array($editData[$key]['el'])) {
2598 foreach ($editData[$key]['el'] as $k3 => $v3) {
2599 $cc=$k3;
2600 if (is_array($v3)) {
2601 $theType = key($v3);
2602 $theDat = $v3[$theType];
2603 $newSectionEl = $value['el'][$theType];
2604 if (is_array($newSectionEl)) {
2605 $tRows[]= $this->getSingleField_typeFlex_draw(
2606 array($theType => $newSectionEl),
2607 array($theType => $theDat),
2608 $table,
2609 $field,
2610 $row,
2611 $PA,
2612 $formPrefix.'['.$key.'][el]['.$cc.']',
2613 $level+1,
2614 $idTagPrefix,
2615 $v3['_TOGGLE']
2616 );
2617 }
2618 }
2619 }
2620 }
2621
2622 // Now, we generate "templates" for new elements that could be added to this section by traversing all possible types of content inside the section:
2623 // 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...
2624
2625 // Preserving internal variables we don't want to change:
2626 $TEMP_requiredElements = $this->requiredElements;
2627
2628 // Traversing possible types of new content in the section:
2629 $newElementsLinks = array();
2630 foreach($value['el'] as $nnKey => $nCfg) {
2631 $additionalJS_post_saved = $this->additionalJS_post;
2632 $this->additionalJS_post = array();
2633 $additionalJS_submit_saved = $this->additionalJS_submit;
2634 $this->additionalJS_submit = array();
2635 $newElementTemplate = $this->getSingleField_typeFlex_draw(
2636 array($nnKey => $nCfg),
2637 array(),
2638 $table,
2639 $field,
2640 $row,
2641 $PA,
2642 $formPrefix.'['.$key.'][el]['.$idTagPrefix.'-form]',
2643 $level+1,
2644 $idTagPrefix
2645 );
2646
2647 // Makes a "Add new" link:
2648 $var = uniqid('idvar');
2649 $replace = 'replace(/' . $idTagPrefix . '-/g,"' . $idTagPrefix . '"+' . $var . '+"-")';
2650 $onClickInsert = 'var ' . $var . ' = "' . $idTagPrefix . '-idx"+(new Date()).getTime();';
2651 // Do not replace $isTagPrefix in setActionStatus() because it needs section id!
2652 $onClickInsert .= 'new Insertion.Bottom($("'.$idTagPrefix.'"), unescape("'.rawurlencode($newElementTemplate).'").' . $replace . '); setActionStatus("'.$idTagPrefix.'");';
2653 $onClickInsert .= 'eval(unescape("' . rawurlencode(implode(';', $this->additionalJS_post)) . '").' . $replace . ');';
2654 $onClickInsert .= 'TBE_EDITOR.addActionChecks("submit", unescape("' . rawurlencode(implode(';', $this->additionalJS_submit)) . '").' . $replace . ');';
2655 $onClickInsert .= 'return false;';
2656 // 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...
2657 $this->additionalJS_post = $additionalJS_post_saved;
2658 $this->additionalJS_submit = $additionalJS_submit_saved;
2659 $new = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:cm.new', 1);
2660 $newElementsLinks[]= '<a href="#" onclick="'.htmlspecialchars($onClickInsert).'">
2661 <img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/new_el.gif','width="11" height="12"').' alt="' . $new . '" title="' . $new . '" align="absmiddle" />' .
2662 htmlspecialchars(t3lib_div::fixed_lgd_cs($this->sL($nCfg['tx_templavoila']['title']),30)) . '</a>'