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