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