* Merging all changes from TYPO3_4-0 branch back into HEAD
[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 $sOnChange = 'setFormValueFromBrowseWin(\''.$PA['itemFormElName'].'\',this.options[this.selectedIndex].value,this.options[this.selectedIndex].text); '.implode('',$PA['fieldChangeFunc']);
1736 $itemsToSelect = '
1737 <select name="'.$PA['itemFormElName'].'_sel"'.
1738 $this->insertDefStyle('select').
1739 ($size ? ' size="'.$size.'"' : '').
1740 ' onchange="'.htmlspecialchars($sOnChange).'"'.
1741 $PA['onFocus'].
1742 $selector_itemListStyle.'>
1743 '.implode('
1744 ',$opt).'
1745 </select>';
1746 }
1747
1748 // Pass to "dbFileIcons" function:
1749 $params = array(
1750 'size' => $size,
1751 'autoSizeMax' => t3lib_div::intInRange($config['autoSizeMax'],0),
1752 'style' => isset($config['selectedListStyle']) ? ' style="'.htmlspecialchars($config['selectedListStyle']).'"' : ' style="'.$this->defaultMultipleSelectorStyle.'"',
1753 'dontShowMoveIcons' => ($maxitems<=1),
1754 'maxitems' => $maxitems,
1755 'info' => '',
1756 'headers' => array(
1757 'selector' => $this->getLL('l_selected').':<br />',
1758 'items' => $this->getLL('l_items').':<br />'
1759 ),
1760 'noBrowser' => 1,
1761 'thumbnails' => $itemsToSelect,
1762 'readOnly' => $disabled
1763 );
1764 $item.= $this->dbFileIcons($PA['itemFormElName'],'','',$itemArray,'',$params,$PA['onFocus']);
1765
1766 return $item;
1767 }
1768
1769 /**
1770 * Generation of TCEform elements of the type "group"
1771 * This will render a selectorbox into which elements from either the file system or database can be inserted. Relations.
1772 *
1773 * @param string The table name of the record
1774 * @param string The field name which this element is supposed to edit
1775 * @param array The record data array where the value(s) for the field can be found
1776 * @param array An array with additional configuration options.
1777 * @return string The HTML code for the TCEform field
1778 */
1779 function getSingleField_typeGroup($table,$field,$row,&$PA) {
1780 // Init:
1781 $config = $PA['fieldConf']['config'];
1782 $internal_type = $config['internal_type'];
1783 $show_thumbs = $config['show_thumbs'];
1784 $size = intval($config['size']);
1785 $maxitems = t3lib_div::intInRange($config['maxitems'],0);
1786 if (!$maxitems) $maxitems=100000;
1787 $minitems = t3lib_div::intInRange($config['minitems'],0);
1788 $allowed = $config['allowed'];
1789 $disallowed = $config['disallowed'];
1790
1791 $disabled = '';
1792 if($this->renderReadonly || $config['readOnly']) {
1793 $disabled = ' disabled="disabled"';
1794 }
1795
1796 $item.= '<input type="hidden" name="'.$PA['itemFormElName'].'_mul" value="'.($config['multiple']?1:0).'"'.$disabled.' />';
1797 $this->requiredElements[$PA['itemFormElName']] = array($minitems,$maxitems,'imgName'=>$table.'_'.$row['uid'].'_'.$field);
1798 $info='';
1799
1800 // "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/.
1801 $specConf = $this->getSpecConfFromString($PA['extra'], $PA['fieldConf']['defaultExtras']);
1802
1803 // Acting according to either "file" or "db" type:
1804 switch((string)$config['internal_type']) {
1805 case 'file': // If the element is of the internal type "file":
1806
1807 // Creating string showing allowed types:
1808 $tempFT = t3lib_div::trimExplode(',',$allowed,1);
1809 if (!count($tempFT)) {$info.='*';}
1810 foreach($tempFT as $ext) {
1811 if ($ext) {
1812 $info.=strtoupper($ext).' ';
1813 }
1814 }
1815 // Creating string, showing disallowed types:
1816 $tempFT_dis = t3lib_div::trimExplode(',',$disallowed,1);
1817 if (count($tempFT_dis)) {$info.='<br />';}
1818 foreach($tempFT_dis as $ext) {
1819 if ($ext) {
1820 $info.='-'.strtoupper($ext).' ';
1821 }
1822 }
1823
1824 // Making the array of file items:
1825 $itemArray = t3lib_div::trimExplode(',',$PA['itemFormElValue'],1);
1826
1827 // Showing thumbnails:
1828 $thumbsnail = '';
1829 if ($show_thumbs) {
1830 $imgs = array();
1831 foreach($itemArray as $imgRead) {
1832 $imgP = explode('|',$imgRead);
1833
1834 $rowCopy = array();
1835 $rowCopy[$field] = $imgP[0];
1836
1837 // Icon + clickmenu:
1838 $absFilePath = t3lib_div::getFileAbsFileName($config['uploadfolder'].'/'.$imgP[0]);
1839
1840 $fI = pathinfo($imgP[0]);
1841 $fileIcon = t3lib_BEfunc::getFileIcon(strtolower($fI['extension']));
1842 $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="" />';
1843
1844 $imgs[] = '<span class="nobr">'.t3lib_BEfunc::thumbCode($rowCopy,$table,$field,$this->backPath,'thumbs.php',$config['uploadfolder'],0,' align="middle"').
1845 ($absFilePath ? $this->getClickMenu($fileIcon, $absFilePath) : $fileIcon).
1846 $imgP[0].
1847 '</span>';
1848 }
1849 $thumbsnail = implode('<br />',$imgs);
1850 }
1851
1852 // Creating the element:
1853 $params = array(
1854 'size' => $size,
1855 'dontShowMoveIcons' => ($maxitems<=1),
1856 'autoSizeMax' => t3lib_div::intInRange($config['autoSizeMax'],0),
1857 'maxitems' => $maxitems,
1858 'style' => isset($config['selectedListStyle']) ? ' style="'.htmlspecialchars($config['selectedListStyle']).'"' : ' style="'.$this->defaultMultipleSelectorStyle.'"',
1859 'info' => $info,
1860 'thumbnails' => $thumbsnail,
1861 'readOnly' => $disabled
1862 );
1863 $item.= $this->dbFileIcons($PA['itemFormElName'],'file',implode(',',$tempFT),$itemArray,'',$params,$PA['onFocus']);
1864
1865 if(!$disabled) {
1866 // Adding the upload field:
1867 if ($this->edit_docModuleUpload) $item.='<input type="file" name="'.$PA['itemFormElName_file'].'"'.$this->formWidth().' size="60" />';
1868 }
1869 break;
1870 case 'db': // If the element is of the internal type "db":
1871
1872 // Creating string showing allowed types:
1873 $tempFT = t3lib_div::trimExplode(',',$allowed,1);
1874 if (!strcmp(trim($tempFT[0]),'*')) {
1875 $info.='<span class="nobr">&nbsp;&nbsp;&nbsp;&nbsp;'.
1876 htmlspecialchars($this->getLL('l_allTables')).
1877 '</span><br />';
1878 } else {
1879 while(list(,$theT)=each($tempFT)) {
1880 if ($theT) {
1881 $info.='<span class="nobr">&nbsp;&nbsp;&nbsp;&nbsp;'.
1882 t3lib_iconWorks::getIconImage($theT,array(),$this->backPath,'align="top"').
1883 htmlspecialchars($this->sL($GLOBALS['TCA'][$theT]['ctrl']['title'])).
1884 '</span><br />';
1885 }
1886 }
1887 }
1888
1889 $perms_clause = $GLOBALS['BE_USER']->getPagePermsClause(1);
1890 $itemArray = array();
1891 $imgs = array();
1892
1893 // Thumbnails:
1894 $temp_itemArray = t3lib_div::trimExplode(',',$PA['itemFormElValue'],1);
1895 foreach($temp_itemArray as $dbRead) {
1896 $recordParts = explode('|',$dbRead);
1897 list($this_table,$this_uid) = t3lib_BEfunc::splitTable_Uid($recordParts[0]);
1898 $itemArray[] = array('table'=>$this_table, 'id'=>$this_uid);
1899 if (!$disabled && $show_thumbs) {
1900 $rr = t3lib_BEfunc::getRecordWSOL($this_table,$this_uid);
1901 $imgs[] = '<span class="nobr">'.
1902 $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).
1903 '&nbsp;'.
1904 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>'.
1905 '</span>';
1906 }
1907 }
1908 $thumbsnail='';
1909 if (!$disabled && $show_thumbs) {
1910 $thumbsnail = implode('<br />',$imgs);
1911 }
1912
1913 // Creating the element:
1914 $params = array(
1915 'size' => $size,
1916 'dontShowMoveIcons' => ($maxitems<=1),
1917 'autoSizeMax' => t3lib_div::intInRange($config['autoSizeMax'],0),
1918 'maxitems' => $maxitems,
1919 'style' => isset($config['selectedListStyle']) ? ' style="'.htmlspecialchars($config['selectedListStyle']).'"' : ' style="'.$this->defaultMultipleSelectorStyle.'"',
1920 'info' => $info,
1921 'thumbnails' => $thumbsnail,
1922 'readOnly' => $disabled
1923 );
1924 $item.= $this->dbFileIcons($PA['itemFormElName'],'db',implode(',',$tempFT),$itemArray,'',$params,$PA['onFocus']);
1925
1926 break;
1927 }
1928
1929 // Wizards:
1930 $altItem = '<input type="hidden" name="'.$PA['itemFormElName'].'" value="'.htmlspecialchars($PA['itemFormElValue']).'" />';
1931 if (!$disabled) {
1932 $item = $this->renderWizards(array($item,$altItem),$config['wizards'],$table,$row,$field,$PA,$PA['itemFormElName'],$specConf);
1933 }
1934
1935 return $item;
1936 }
1937
1938 /**
1939 * Generation of TCEform elements of the type "none"
1940 * This will render a non-editable display of the content of the field.
1941 *
1942 * @param string The table name of the record
1943 * @param string The field name which this element is supposed to edit
1944 * @param array The record data array where the value(s) for the field can be found
1945 * @param array An array with additional configuration options.
1946 * @return string The HTML code for the TCEform field
1947 */
1948 function getSingleField_typeNone($table,$field,$row,&$PA) {
1949 // Init:
1950 $config = $PA['fieldConf']['config'];
1951 $itemValue = $PA['itemFormElValue'];
1952
1953 return $this->getSingleField_typeNone_render($config,$itemValue);
1954 }
1955
1956 /**
1957 * HTML rendering of a value which is not editable.
1958 *
1959 * @param array Configuration for the display
1960 * @param string The value to display
1961 * @return string The HTML code for the display
1962 * @see getSingleField_typeNone();
1963 */
1964 function getSingleField_typeNone_render($config,$itemValue) {
1965
1966 // is colorScheme[0] the right value?
1967 $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;';
1968
1969 if ($config['format']) {
1970 $itemValue = $this->formatValue($config, $itemValue);
1971 }
1972
1973 $rows = intval($config['rows']);
1974 if ($rows > 1) {
1975 if(!$config['pass_content']) {
1976 $itemValue = nl2br(htmlspecialchars($itemValue));
1977 }
1978 // like textarea
1979 $cols = t3lib_div::intInRange($config['cols'] ? $config['cols'] : 30, 5, $this->maxTextareaWidth);
1980 if (!$config['fixedRows']) {
1981 $origRows = $rows = t3lib_div::intInRange($rows, 1, 20);
1982 if (strlen($itemValue)>$this->charsPerRow*2) {
1983 $cols = $this->maxTextareaWidth;
1984 $rows = t3lib_div::intInRange(round(strlen($itemValue)/$this->charsPerRow),count(explode(chr(10),$itemValue)),20);
1985 if ($rows<$origRows) $rows=$origRows;
1986 }
1987 }
1988
1989 if ($this->docLarge) $cols = round($cols*$this->form_largeComp);
1990 $width = ceil($cols*$this->form_rowsToStylewidth);
1991 // hardcoded: 12 is the height of the font
1992 $height=$rows*12;
1993
1994 $item='
1995 <div style="'.htmlspecialchars($divStyle.' overflow:auto; height:'.$height.'px; width:'.$width.'px;').'" class="'.htmlspecialchars($this->formElClass('none')).'">'.
1996 $itemValue.
1997 '</div>';
1998 } else {
1999 if(!$config['pass_content']) {
2000 $itemValue = htmlspecialchars($itemValue);
2001 }
2002
2003 $cols = $config['cols']?$config['cols']:($config['size']?$config['size']:$this->maxInputWidth);
2004 if ($this->docLarge) $cols = round($cols*$this->form_largeComp);
2005 $width = ceil($cols*$this->form_rowsToStylewidth);
2006
2007 // overflow:auto crashes mozilla here. Title tag is usefull when text is longer than the div box (overflow:hidden).
2008 $item = '
2009 <div style="'.htmlspecialchars($divStyle.' overflow:hidden; width:'.$width.'px;').'" class="'.htmlspecialchars($this->formElClass('none')).'" title="'.$itemValue.'">'.
2010 '<span class="nobr">'.(strcmp($itemValue,'')?$itemValue:'&nbsp;').'</span>'.
2011 '</div>';
2012 }
2013
2014 return $item;
2015 }
2016
2017 /**
2018 * Handler for Flex Forms
2019 *
2020 * @param string The table name of the record
2021 * @param string The field name which this element is supposed to edit
2022 * @param array The record data array where the value(s) for the field can be found
2023 * @param array An array with additional configuration options.
2024 * @return string The HTML code for the TCEform field
2025 */
2026 function getSingleField_typeFlex($table,$field,$row,&$PA) {
2027
2028 // Data Structure:
2029 $dataStructArray = t3lib_BEfunc::getFlexFormDS($PA['fieldConf']['config'],$row,$table);
2030 #debug($dataStructArray);
2031 // Get data structure:
2032 if (is_array($dataStructArray)) {
2033 #debug(array(str_replace(' ',chr(160),$PA['itemFormElValue'])));
2034
2035 // Get data:
2036 $xmlData = $PA['itemFormElValue'];
2037 $xmlHeaderAttributes = t3lib_div::xmlGetHeaderAttribs($xmlData);
2038 $storeInCharset = strtolower($xmlHeaderAttributes['encoding']);
2039 if ($storeInCharset) {
2040 $currentCharset=$GLOBALS['LANG']->charSet;
2041 $xmlData = $GLOBALS['LANG']->csConvObj->conv($xmlData,$storeInCharset,$currentCharset,1);
2042 }
2043 $editData=t3lib_div::xml2array($xmlData);
2044 if (!is_array($editData)) { // Must be XML parsing error...
2045 #debug(array($editData,$xmlData));
2046 $editData=array();
2047 }
2048
2049 // Find the data structure if sheets are found:
2050 $sheet = $editData['meta']['currentSheetId'] ? $editData['meta']['currentSheetId'] : 'sDEF'; // Sheet to display
2051 # $item.= '<input type="hidden" name="'.$PA['itemFormElName'].'[meta][currentSheetId]" value="'.$sheet.'">';
2052
2053 // Create sheet menu:
2054 if (is_array($dataStructArray['sheets'])) {
2055 #$item.=$this->getSingleField_typeFlex_sheetMenu($dataStructArray['sheets'], $PA['itemFormElName'].'[meta][currentSheetId]', $sheet).'<br />';
2056 }
2057 #debug($editData);
2058
2059 // Create language menu:
2060 $langChildren = $dataStructArray['meta']['langChildren'] ? 1 : 0;
2061 $langDisabled = $dataStructArray['meta']['langDisable'] ? 1 : 0;
2062
2063 $editData['meta']['currentLangId']=array();
2064 $languages = $this->getAvailableLanguages();
2065
2066 foreach($languages as $lInfo) {
2067 if ($GLOBALS['BE_USER']->checkLanguageAccess($lInfo['uid'])) {
2068 $editData['meta']['currentLangId'][] = $lInfo['ISOcode'];
2069 }
2070 }
2071 if (!is_array($editData['meta']['currentLangId']) || !count($editData['meta']['currentLangId'])) {
2072 $editData['meta']['currentLangId']=array('DEF');
2073 }
2074
2075 $editData['meta']['currentLangId'] = array_unique($editData['meta']['currentLangId']);
2076
2077
2078 // if (!$langDisabled && count($languages) > 1) {
2079 // $item.=$this->getSingleField_typeFlex_langMenu($languages, $PA['itemFormElName'].'[meta][currentLangId]', $editData['meta']['currentLangId']).'<br />';
2080 // }
2081
2082 $PA['_noEditDEF'] = FALSE;
2083 if ($langChildren || $langDisabled) {
2084 $rotateLang = array('DEF');
2085 } else {
2086 if (!in_array('DEF',$editData['meta']['currentLangId'])) {
2087 array_unshift($editData['meta']['currentLangId'],'DEF');
2088 $PA['_noEditDEF'] = TRUE;
2089 }
2090 $rotateLang = $editData['meta']['currentLangId'];
2091 }
2092
2093 // Tabs sheets
2094 if (is_array($dataStructArray['sheets'])) {
2095 $tabsToTraverse = array_keys($dataStructArray['sheets']);
2096 } else {
2097 $tabsToTraverse = array($sheet);
2098 }
2099
2100 foreach($rotateLang as $lKey) {
2101 if (!$langChildren && !$langDisabled) {
2102 $item.= '<b>'.$lKey.':</b>';
2103 }
2104
2105 $tabParts = array();
2106 foreach($tabsToTraverse as $sheet) {
2107 $sheetCfg = $dataStructArray['sheets'][$sheet];
2108 list ($dataStruct, $sheet) = t3lib_div::resolveSheetDefInDS($dataStructArray,$sheet);
2109
2110 // Render sheet:
2111 if (is_array($dataStruct['ROOT']) && is_array($dataStruct['ROOT']['el'])) {
2112 $cmdData = t3lib_div::_GP('flexFormsCmdData');
2113 $lang = 'l'.$lKey; // Default language, other options are "lUK" or whatever country code (independant of system!!!)
2114 $PA['_valLang'] = $langChildren && !$langDisabled ? $editData['meta']['currentLangId'] : 'DEF'; // Default language, other options are "lUK" or whatever country code (independant of system!!!)
2115 $PA['_lang'] = $lang;
2116
2117 // Render flexform:
2118 $tRows = $this->getSingleField_typeFlex_draw(
2119 $dataStruct['ROOT']['el'],
2120 $editData['data'][$sheet][$lang],
2121 $cmdData['data'][$sheet][$lang],
2122 $table,
2123 $field,
2124 $row,
2125 $PA,
2126 '[data]['.$sheet.']['.$lang.']'
2127 );
2128 $sheetContent= '<table border="0" cellpadding="1" cellspacing="1" class="typo3-TCEforms-flexForm">'.implode('',$tRows).'</table>';
2129
2130 # $item = '<div style=" position:absolute;">'.$item.'</div>';
2131 //visibility:hidden;
2132 } else $sheetContent='Data Structure ERROR: No ROOT element found for sheet "'.$sheet.'".';
2133
2134 // Add to tab:
2135 $tabParts[] = array(
2136 'label' => ($sheetCfg['ROOT']['TCEforms']['sheetTitle'] ? $this->sL($sheetCfg['ROOT']['TCEforms']['sheetTitle']) : $sheet),
2137 'description' => ($sheetCfg['ROOT']['TCEforms']['sheetDescription'] ? $this->sL($sheetCfg['ROOT']['TCEforms']['sheetDescription']) : ''),
2138 'linkTitle' => ($sheetCfg['ROOT']['TCEforms']['sheetShortDescr'] ? $this->sL($sheetCfg['ROOT']['TCEforms']['sheetShortDescr']) : ''),
2139 'content' => $sheetContent
2140 );
2141 }
2142
2143 if (is_array($dataStructArray['sheets'])) {
2144 $item.= $this->getDynTabMenu($tabParts,'TCEFORMS:flexform:'.$PA['itemFormElName']);
2145 } else {
2146 $item.= $sheetContent;
2147 }
2148 }
2149 } else $item='Data Structure ERROR: '.$dataStructArray;
2150
2151 return $item;
2152 }
2153
2154 /**
2155 * Creates the language menu for FlexForms:
2156 *
2157 * @param [type] $languages: ...
2158 * @param [type] $elName: ...
2159 * @param [type] $selectedLanguage: ...
2160 * @param [type] $multi: ...
2161 * @return string HTML for menu
2162 */
2163 function getSingleField_typeFlex_langMenu($languages,$elName,$selectedLanguage,$multi=1) {
2164 $opt=array();
2165 foreach($languages as $lArr) {
2166 $opt[]='<option value="'.htmlspecialchars($lArr['ISOcode']).'"'.(in_array($lArr['ISOcode'],$selectedLanguage)?' selected="selected"':'').'>'.htmlspecialchars($lArr['title']).'</option>';
2167 }
2168
2169 $output = '<select name="'.$elName.'[]"'.($multi ? ' multiple="multiple" size="'.count($languages).'"' : '').'>'.implode('',$opt).'</select>';
2170
2171 return $output;
2172 }
2173
2174 /**
2175 * Creates the menu for selection of the sheets:
2176 *
2177 * @param array Sheet array for which to render the menu
2178 * @param string Form element name of the field containing the sheet pointer
2179 * @param string Current sheet key
2180 * @return string HTML for menu
2181 */
2182 function getSingleField_typeFlex_sheetMenu($sArr,$elName,$sheetKey) {
2183
2184 $tCells =array();
2185 $pct = round(100/count($sArr));
2186 foreach($sArr as $sKey => $sheetCfg) {
2187 if ($GLOBALS['BE_USER']->jsConfirmation(1)) {
2188 $onClick = 'if (confirm('.$GLOBALS['LANG']->JScharCode($this->getLL('m_onChangeAlert')).') && TBE_EDITOR_checkSubmit(-1)){'.$this->elName($elName).".value='".$sKey."'; TBE_EDITOR_submitForm()};";
2189 } else {
2190 $onClick = 'if(TBE_EDITOR_checkSubmit(-1)){ '.$this->elName($elName).".value='".$sKey."'; TBE_EDITOR_submitForm();}";
2191 }
2192
2193
2194 $tCells[]='<td width="'.$pct.'%" style="'.($sKey==$sheetKey ? 'background-color: #9999cc; font-weight: bold;' : 'background-color: #aaaaaa;').' cursor: hand;" onclick="'.htmlspecialchars($onClick).'" align="center">'.
2195 ($sheetCfg['ROOT']['TCEforms']['sheetTitle'] ? $this->sL($sheetCfg['ROOT']['TCEforms']['sheetTitle']) : $sKey).
2196 '</td>';
2197 }
2198
2199 return '<table border="0" cellpadding="0" cellspacing="2" class="typo3-TCEforms-flexForm-sheetMenu"><tr>'.implode('',$tCells).'</tr></table>';
2200 }
2201
2202 /**
2203 * [Describe function...]
2204 *
2205 * @param [type] $dataStruct: ...
2206 * @param [type] $editData: ...
2207 * @param [type] $cmdData: ...
2208 * @param [type] $table: ...
2209 * @param [type] $field: ...
2210 * @param [type] $row: ...
2211 * @param [type] $PA: ...
2212 * @param [type] $formPrefix: ...
2213 * @param [type] $level: ...
2214 * @param [type] $tRows: ...
2215 * @return [type] ...
2216 */
2217 function getSingleField_typeFlex_draw($dataStruct,$editData,$cmdData,$table,$field,$row,&$PA,$formPrefix='',$level=0,$tRows=array()) {
2218
2219 // Data Structure array must be ... and array of course...
2220 if (is_array($dataStruct)) {
2221 foreach($dataStruct as $key => $value) {
2222 if (is_array($value)) { // The value of each entry must be an array.
2223
2224 // ********************
2225 // Making the row:
2226 // ********************
2227 $rowCells=array();
2228
2229 // Icon:
2230 $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>';;
2231
2232 $rowCells['formEl']='';
2233 if ($value['type']=='array') {
2234 if ($value['section']) {
2235 // Render "NEW [container]" selectorbox:
2236 if (is_array($value['el'])) {
2237 $opt=array();
2238 $opt[]='<option value=""></option>';
2239 foreach($value['el'] as $kk => $vv) {
2240 $opt[]='<option value="'.$kk.'">'.htmlspecialchars('NEW "'.$value['el'][$kk]['tx_templavoila']['title'].'"').'</option>';
2241 }
2242 $rowCells['formEl']='<select name="flexFormsCmdData'.$formPrefix.'['.$key.'][value]">'.implode('',$opt).'</select>';
2243 }
2244
2245 // Put row together
2246 $tRows[]='<tr class="bgColor2">
2247 <td nowrap="nowrap" valign="top">'.$rowCells['title'].'</td>
2248 <td>'.$rowCells['formEl'].'</td>
2249 </tr>';
2250
2251 $cc=0;
2252 if (is_array($editData[$key]['el'])) {
2253 foreach($editData[$key]['el'] as $k3 => $v3) {
2254 $cc=$k3;
2255 $theType = key($v3);
2256 $theDat = $v3[$theType];
2257 $newSectionEl = $value['el'][$theType];
2258 if (is_array($newSectionEl)) {
2259 $tRows = $this->getSingleField_typeFlex_draw(
2260 array($theType => $newSectionEl),
2261 array($theType => $theDat),
2262 $cmdData[$key]['el'][$cc],
2263 $table,
2264 $field,
2265 $row,
2266 $PA,
2267 $formPrefix.'['.$key.'][el]['.$cc.']',
2268 $level+1,
2269 $tRows
2270 );
2271 }
2272 }
2273 }
2274
2275
2276
2277 // New form?
2278 if ($cmdData[$key]['value']) {
2279 $newSectionEl = $value['el'][$cmdData[$key]['value']];
2280 if (is_array($newSectionEl)) {
2281 $tRows = $this->getSingleField_typeFlex_draw(
2282 array($cmdData[$key]['value'] => $newSectionEl),
2283 array(),
2284 array(),
2285 $table,
2286 $field,
2287 $row,
2288 $PA,
2289 $formPrefix.'['.$key.'][el]['.($cc+1).']',
2290 $level+1,
2291 $tRows
2292 );
2293 }
2294 }
2295 } else {
2296 $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
2297
2298 // Put row together
2299 $tRows[]='<tr class="bgColor2">
2300 <td nowrap="nowrap" valign="top">'.
2301 '<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>'.
2302 '<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>'.
2303 '<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>'.
2304 $rowCells['title'].'</td>
2305 <td>'.$rowCells['formEl'].'</td>
2306 </tr>';
2307
2308 $tRows = $this->getSingleField_typeFlex_draw(
2309 $value['el'],
2310 $editData[$key]['el'],
2311 $cmdData[$key]['el'],
2312 $table,
2313 $field,
2314 $row,
2315 $PA,
2316 $formPrefix.'['.$key.'][el]',
2317 $level+1,
2318 $tRows
2319 );
2320 }
2321
2322 } elseif (is_array($value['TCEforms']['config'])) { // Rendering a single form element:
2323
2324 if (is_array($PA['_valLang'])) {
2325 $rotateLang = $PA['_valLang'];
2326 } else {
2327 $rotateLang = array($PA['_valLang']);
2328 }
2329
2330 foreach($rotateLang as $vDEFkey) {
2331 $vDEFkey = 'v'.$vDEFkey;
2332
2333 if (!$value['TCEforms']['displayCond'] || $this->isDisplayCondition($value['TCEforms']['displayCond'],$editData,$vDEFkey)) {
2334 $fakePA=array();
2335 $fakePA['fieldConf']=array(
2336 'label' => $this->sL(trim($value['TCEforms']['label'])),
2337 'config' => $value['TCEforms']['config'],
2338 'defaultExtras' => $value['TCEforms']['defaultExtras'],
2339 'onChange' => $value['TCEforms']['onChange']
2340 );
2341 if ($PA['_noEditDEF'] && $PA['_lang']==='lDEF') {
2342 $fakePA['fieldConf']['config'] = array(
2343 'type' => 'none',
2344 'rows' => 2
2345 );
2346 }
2347
2348 if (
2349 $fakePA['fieldConf']['onChange'] == 'reload' ||
2350 ($GLOBALS['TCA'][$table]['ctrl']['type'] && !strcmp($key,$GLOBALS['TCA'][$table]['ctrl']['type'])) ||
2351 ($GLOBALS['TCA'][$table]['ctrl']['requestUpdate'] && t3lib_div::inList($GLOBALS['TCA'][$table]['ctrl']['requestUpdate'],$key))) {
2352 if ($GLOBALS['BE_USER']->jsConfirmation(1)) {
2353 $alertMsgOnChange = 'if (confirm('.$GLOBALS['LANG']->JScharCode($this->getLL('m_onChangeAlert')).') && TBE_EDITOR_checkSubmit(-1)){ TBE_EDITOR_submitForm() };';
2354 } else {
2355 $alertMsgOnChange = 'if(TBE_EDITOR_checkSubmit(-1)){ TBE_EDITOR_submitForm();}';
2356 }
2357 } else {
2358 $alertMsgOnChange = '';
2359 }
2360
2361 $fakePA['fieldChangeFunc']=$PA['fieldChangeFunc'];
2362 if (strlen($alertMsgOnChange)) {
2363 $fakePA['fieldChangeFunc']['alert']=$alertMsgOnChange;
2364 }
2365 $fakePA['onFocus']=$PA['onFocus'];
2366 $fakePA['label']=$PA['label'];
2367
2368 $fakePA['itemFormElName']=$PA['itemFormElName'].$formPrefix.'['.$key.']['.$vDEFkey.']';
2369 $fakePA['itemFormElName_file']=$PA['itemFormElName_file'].$formPrefix.'['.$key.']['.$vDEFkey.']';
2370
2371 if(isset($editData[$key][$vDEFkey])) {
2372 $fakePA['itemFormElValue']=$editData[$key][$vDEFkey];
2373 } else {
2374 $fakePA['itemFormElValue']=$fakePA['fieldConf']['config']['default'];
2375 }
2376
2377 $rowCells['formEl']= $this->getSingleField_SW($table,$field,$row,$fakePA);
2378 $rowCells['title']= htmlspecialchars($fakePA['fieldConf']['label']);
2379
2380 if (!in_array('DEF',$rotateLang)) {
2381 $defInfo = '<div class="typo3-TCEforms-originalLanguageValue">'.nl2br(htmlspecialchars($editData[$key]['vDEF'])).'&nbsp;</div>';
2382 } else {
2383 $defInfo = '';
2384 }
2385
2386 // Put row together
2387 $tRows[]='<tr>
2388 <td nowrap="nowrap" valign="top" class="bgColor5">'.$rowCells['title'].($vDEFkey=='vDEF' ? '' : ' ('.$vDEFkey.')').'</td>
2389 <td class="bgColor4">'.$rowCells['formEl'].$defInfo.'</td>
2390 </tr>';
2391 }
2392 }
2393 }
2394 }
2395 }
2396 }
2397
2398 return $tRows;
2399 }
2400
2401 /**
2402 * Handler for unknown types.
2403 *
2404 * @param string The table name of the record
2405 * @param string The field name which this element is supposed to edit
2406 * @param array The record data array where the value(s) for the field can be found
2407 * @param array An array with additional configuration options.
2408 * @return string The HTML code for the TCEform field
2409 */
2410 function getSingleField_typeUnknown($table,$field,$row,&$PA) {
2411 $item='Unknown type: '.$PA['fieldConf']['config']['form_type'].'<br />';
2412
2413 return $item;
2414 }
2415
2416 /**
2417 * User defined field type
2418 *
2419 * @param string The table name of the record
2420 * @param string The field name which this element is supposed to edit
2421 * @param array The record data array where the value(s) for the field can be found
2422 * @param array An array with additional configuration options.
2423 * @return string The HTML code for the TCEform field
2424 */
2425 function getSingleField_typeUser($table,$field,$row,&$PA) {
2426 $PA['table']=$table;
2427 $PA['field']=$field;
2428 $PA['row']=$row;
2429
2430 $PA['pObj']=&$this;
2431
2432 return t3lib_div::callUserFunction($PA['fieldConf']['config']['userFunc'],$PA,$this);
2433 }
2434
2435
2436
2437
2438
2439
2440 /************************************************************
2441 *
2442 * Field content processing
2443 *
2444 ************************************************************/
2445
2446 /**
2447 * Format field content of various types if $config['format'] is set to date, filesize, ..., user
2448 * This is primarily for the field type none but can be used for user field types for example
2449 *
2450 * @param array Configuration for the display
2451 * @param string The value to display
2452 * @return string Formatted Field content
2453 */
2454 function formatValue ($config, $itemValue) {
2455 $format = trim($config['format']);
2456 switch($format) {
2457 case 'date':
2458 $option = trim($config['format.']['option']);
2459 if ($option) {
2460 if ($config['format.']['strftime']) {
2461 $value = strftime($option,$itemValue);
2462 } else {
2463 $value = date($option,$itemValue);
2464 }
2465 } else {
2466 $value = date('d-m-Y',$itemValue);
2467 }
2468 if ($config['format.']['appendAge']) {
2469 $value .= ' ('.t3lib_BEfunc::calcAge((time()-$itemValue), $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.minutesHoursDaysYears')).')';
2470 }
2471 $itemValue = $value;
2472 break;
2473 case 'datetime': // compatibility with "eval" (type "input")
2474 $itemValue = date('H:i d-m-Y',$itemValue);
2475 break;
2476 case 'time': // compatibility with "eval" (type "input")
2477 $itemValue = date('H:i',$itemValue);
2478 break;
2479 case 'timesec': // compatibility with "eval" (type "input")
2480 $itemValue = date('H:i:s',$itemValue);
2481 break;
2482 case 'year': // compatibility with "eval" (type "input")
2483 $itemValue = date('Y',$itemValue);
2484 break;
2485 case 'int':
2486 $baseArr = array('dec'=>'d','hex'=>'x','HEX'=>'X','oct'=>'o','bin'=>'b');
2487 $base = trim($config['format.']['base']);
2488 $format = $baseArr[$base] ? $baseArr[$base] : 'd';
2489 $itemValue = sprintf('%'.$format,$itemValue);
2490 break;
2491 case 'float':
2492 $precision = t3lib_div::intInRange($config['format.']['precision'],1,10,2);
2493 $itemValue = sprintf('%.'.$precision.'f',$itemValue);
2494 break;
2495 case 'number':
2496 $format = trim($config['format.']['option']);
2497 $itemValue = sprintf('%'.$format,$itemValue);
2498 break;
2499 case 'md5':
2500 $itemValue = md5($itemValue);
2501 break;
2502 case 'filesize':
2503 $value = t3lib_div::formatSize(intval($itemValue));
2504 if ($config['format.']['appendByteSize']) {
2505 $value .= ' ('.$itemValue.')';
2506 }
2507 $itemValue = $value;
2508 break;
2509 case 'user':
2510 $func = trim($config['format.']['userFunc']);
2511 if ($func) {
2512 $params = array(
2513 'value' => $itemValue,
2514 'args' => $config['format.']['userFunc'],
2515 'config' => $config,
2516 'pObj' => &$this
2517 );
2518 $itemValue = t3lib_div::callUserFunction($func,$params,$this);
2519 }
2520 break;
2521 default:
2522 break;
2523 }
2524
2525 return $itemValue;
2526 }
2527
2528
2529
2530
2531
2532
2533 /************************************************************
2534 *
2535 * "Configuration" fetching/processing functions
2536 *
2537 ************************************************************/
2538
2539 /**
2540 * Calculate and return the current "types" pointer value for a record
2541 *
2542 * @param string The table name. MUST be in $TCA
2543 * @param array The row from the table, should contain at least the "type" field, if applicable.
2544 * @return string Return the "type" value for this record, ready to pick a "types" configuration from the $TCA array.
2545 */
2546 function getRTypeNum($table,$row) {
2547 global $TCA;
2548 // If there is a "type" field configured...
2549 if ($TCA[$table]['ctrl']['type']) {
2550 $typeFieldName = $TCA[$table]['ctrl']['type'];
2551 $typeNum=$row[$typeFieldName]; // Get value of the row from the record which contains the type value.
2552 if (!strcmp($typeNum,'')) $typeNum=0; // If that value is an empty string, set it to "0" (zero)
2553 } else {
2554 $typeNum = 0; // If no "type" field, then set to "0" (zero)
2555 }
2556
2557 $typeNum = (string)$typeNum; // Force to string. Necessary for eg '-1' to be recognized as a type value.
2558 if (!$TCA[$table]['types'][$typeNum]) { // However, if the type "0" is not found in the "types" array, then default to "1" (for historical reasons)
2559 $typeNum = 1;
2560 }
2561
2562 return $typeNum;
2563 }
2564
2565 /**
2566 * Used to adhoc-rearrange the field order normally set in the [types][showitem] list
2567 *
2568 * @param array A [types][showitem] list of fields, exploded by ","
2569 * @return array Returns rearranged version (keys are changed around as well.)
2570 * @see getMainFields()
2571 */
2572 function rearrange($fields) {
2573 $fO = array_flip(t3lib_div::trimExplode(',',$this->fieldOrder,1));
2574 reset($fields);
2575 $newFields=array();
2576 while(list($cc,$content)=each($fields)) {
2577 $cP = t3lib_div::trimExplode(';',$content);
2578 if (isset($fO[$cP[0]])) {
2579 $newFields[$fO[$cP[0]]] = $content;
2580 unset($fields[$cc]);
2581 }
2582 }
2583 ksort($newFields);
2584 $fields=array_merge($newFields,$fields); // Candidate for t3lib_div::array_merge() if integer-keys will some day make trouble...
2585 return $fields;
2586 }
2587
2588 /**
2589 * Producing an array of field names NOT to display in the form, based on settings from subtype_value_field, bitmask_excludelist_bits etc.
2590 * Notice, this list is in NO way related to the "excludeField" flag
2591 *
2592 * @param string Table name, MUST be in $TCA
2593 * @param array A record from table.
2594 * @param string A "type" pointer value, probably the one calculated based on the record array.
2595 * @return array Array with fieldnames as values. The fieldnames are those which should NOT be displayed "anyways"
2596 * @see getMainFields()
2597 */
2598 function getExcludeElements($table,$row,$typeNum) {
2599 global $TCA;
2600
2601 // Init:
2602 $excludeElements=array();
2603
2604 // If a subtype field is defined for the type
2605 if ($TCA[$table]['types'][$typeNum]['subtype_value_field']) {
2606 $sTfield = $TCA[$table]['types'][$typeNum]['subtype_value_field'];
2607 if (trim($TCA[$table]['types'][$typeNum]['subtypes_excludelist'][$row[$sTfield]])) {
2608 $excludeElements=t3lib_div::trimExplode(',',$TCA[$table]['types'][$typeNum]['subtypes_excludelist'][$row[$sTfield]],1);
2609 }
2610 }
2611
2612 // If a bitmask-value field has been configured, then find possible fields to exclude based on that:
2613 if ($TCA[$table]['types'][$typeNum]['bitmask_value_field']) {
2614 $sTfield = $TCA[$table]['types'][$typeNum]['bitmask_value_field'];
2615 $sTValue = t3lib_div::intInRange($row[$sTfield],0);
2616 if (is_array($TCA[$table]['types'][$typeNum]['bitmask_excludelist_bits'])) {
2617 reset($TCA[$table]['types'][$typeNum]['bitmask_excludelist_bits']);
2618 while(list($bitKey,$eList)=each($TCA[$table]['types'][$typeNum]['bitmask_excludelist_bits'])) {
2619 $bit=substr($bitKey,1);
2620 if (t3lib_div::testInt($bit)) {
2621 $bit = t3lib_div::intInRange($bit,0,30);
2622 if (
2623 (substr($bitKey,0,1)=='-' && !($sTValue&pow(2,$bit))) ||
2624 (substr($bitKey,0,1)=='+' && ($sTValue&pow(2,$bit)))
2625 ) {
2626 $excludeElements = array_merge($excludeElements,t3lib_div::trimExplode(',',$eList,1));
2627 }
2628 }
2629 }
2630 }
2631 }
2632
2633 // Return the array of elements:
2634 return $excludeElements;
2635 }
2636
2637 /**
2638 * Finds possible field to add to the form, based on subtype fields.
2639 *
2640 * @param string Table name, MUST be in $TCA
2641 * @param array A record from table.
2642 * @param string A "type" pointer value, probably the one calculated based on the record array.
2643 * @return array An array containing two values: 1) Another array containing fieldnames to add and 2) the subtype value field.
2644 * @see getMainFields()
2645 */
2646 function getFieldsToAdd($table,$row,$typeNum) {
2647 global $TCA;
2648
2649 // Init:
2650 $addElements=array();
2651
2652 // If a subtype field is defined for the type
2653 if ($TCA[$table]['types'][$typeNum]['subtype_value_field']) {
2654 $sTfield = $TCA[$table]['types'][$typeNum]['subtype_value_field'];
2655 if (trim($TCA[$table]['types'][$typeNum]['subtypes_addlist'][$row[$sTfield]])) {
2656 $addElements=t3lib_div::trimExplode(',',$TCA[$table]['types'][$typeNum]['subtypes_addlist'][$row[$sTfield]],1);
2657 }
2658 }
2659 // Return the return
2660 return array($addElements,$sTfield);
2661 }
2662
2663 /**
2664 * Merges the current [types][showitem] array with the array of fields to add for the current subtype field of the "type" value.
2665 *
2666 * @param array A [types][showitem] list of fields, exploded by ","
2667 * @param array The output from getFieldsToAdd()
2668 * @return array Return the modified $fields array.
2669 * @see getMainFields(),getFieldsToAdd()
2670 */
2671 function mergeFieldsWithAddedFields($fields,$fieldsToAdd) {
2672 if (count($fieldsToAdd[0])) {
2673 reset($fields);
2674 $c=0;
2675 while(list(,$fieldInfo)=each($fields)) {
2676 $parts = explode(';',$fieldInfo);
2677 if (!strcmp(trim($parts[0]),$fieldsToAdd[1])) {
2678 array_splice(
2679 $fields,
2680 $c+1,
2681 0,
2682 $fieldsToAdd[0]
2683 );
2684 break;
2685 }
2686 $c++;
2687 }
2688 }
2689 return $fields;
2690 }
2691
2692
2693 /**
2694 * Returns TSconfig for table/row
2695 * 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.
2696 *
2697 * @param string The table name
2698 * @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.)
2699 * @param string Optionally you can specify the field name as well. In that case the TSconfig for the field is returned.
2700 * @return mixed The TSconfig values (probably in an array)
2701 * @see t3lib_BEfunc::getTCEFORM_TSconfig()
2702 */
2703 function setTSconfig($table,$row,$field='') {
2704 $mainKey = $table.':'.$row['uid'];
2705 if (!isset($this->cachedTSconfig[$mainKey])) {
2706 $this->cachedTSconfig[$mainKey]=t3lib_BEfunc::getTCEFORM_TSconfig($table,$row);
2707 }
2708 if ($field) {
2709 return $this->cachedTSconfig[$mainKey][$field];
2710 } else {
2711 return $this->cachedTSconfig[$mainKey];
2712 }
2713 }
2714
2715 /**
2716 * Returns the "special" configuration (from the "types" "showitem" list) for a fieldname based on input table/record
2717 * (Not used anywhere...?)
2718 *
2719 * @param string The table name
2720 * @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.)
2721 * @param string Specify the field name.
2722 * @return array
2723 * @see getSpecConfFromString(), t3lib_BEfunc::getTCAtypes()
2724 */
2725 function getSpecConfForField($table,$row,$field) {
2726 // Finds the current "types" configuration for the table/row:
2727 $types_fieldConfig = t3lib_BEfunc::getTCAtypes($table,$row);
2728
2729 // If this is an array, then traverse it:
2730 if (is_array($types_fieldConfig)) {
2731 foreach($types_fieldConfig as $vconf) {
2732 // If the input field name matches one found in the 'types' list, then return the 'special' configuration.
2733 if ($vconf['field']==$field) return $vconf['spec'];
2734 }
2735 }
2736 }
2737
2738 /**
2739 * Returns the "special" configuration of an "extra" string (non-parsed)
2740 *
2741 * @param string The "Part 4" of the fields configuration in "types" "showitem" lists.
2742 * @param string The ['defaultExtras'] value from field configuration
2743 * @return array An array with the special options in.
2744 * @see getSpecConfForField(), t3lib_BEfunc::getSpecConfParts()
2745 */
2746 function getSpecConfFromString($extraString, $defaultExtras) {
2747 return t3lib_BEfunc::getSpecConfParts($extraString, $defaultExtras);
2748 }
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759 /************************************************************
2760 *
2761 * Display of localized content etc.
2762 *
2763 ************************************************************/