*** empty log message ***
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_tceforms.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2005 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 * 1217: function getSingleField_typeSelect_single($table,$field,$row,&$PA,$config,$selItems,$nMV_label)
60 * 1326: function getSingleField_typeSelect_checkbox($table,$field,$row,&$PA,$config,$selItems,$nMV_label)
61 * 1438: function getSingleField_typeSelect_singlebox($table,$field,$row,&$PA,$config,$selItems,$nMV_label)
62 * 1540: function getSingleField_typeSelect_multiple($table,$field,$row,&$PA,$config,$selItems,$nMV_label)
63 * 1630: function getSingleField_typeGroup($table,$field,$row,&$PA)
64 * 1787: function getSingleField_typeNone($table,$field,$row,&$PA)
65 * 1803: function getSingleField_typeNone_render($config,$itemValue)
66 * 1862: function getSingleField_typeFlex($table,$field,$row,&$PA)
67 * 1986: function getSingleField_typeFlex_langMenu($languages,$elName,$selectedLanguage,$multi=1)
68 * 2005: function getSingleField_typeFlex_sheetMenu($sArr,$elName,$sheetKey)
69 * 2035: function getSingleField_typeFlex_draw($dataStruct,$editData,$cmdData,$table,$field,$row,&$PA,$formPrefix='',$level=0,$tRows=array())
70 * 2187: function getSingleField_typeUnknown($table,$field,$row,&$PA)
71 * 2202: function getSingleField_typeUser($table,$field,$row,&$PA)
72 *
73 * SECTION: "Configuration" fetching/processing functions
74 * 2236: function getRTypeNum($table,$row)
75 * 2262: function rearrange($fields)
76 * 2288: function getExcludeElements($table,$row,$typeNum)
77 * 2336: function getFieldsToAdd($table,$row,$typeNum)
78 * 2361: function mergeFieldsWithAddedFields($fields,$fieldsToAdd)
79 * 2393: function setTSconfig($table,$row,$field='')
80 * 2415: function getSpecConfForField($table,$row,$field)
81 * 2436: function getSpecConfFromString($extraString, $defaultExtras)
82 *
83 * SECTION: Display of localized content etc.
84 * 2464: function registerDefaultLanguageData($table,$rec)
85 * 2496: function renderDefaultLanguageContent($table,$field,$row,$item)
86 * 2519: function renderDefaultLanguageDiff($table,$field,$row,$item)
87 *
88 * SECTION: Form element helper functions
89 * 2575: function dbFileIcons($fName,$mode,$allowed,$itemArray,$selector='',$params=array(),$onFocus='')
90 * 2708: function getClipboardElements($allowed,$mode)
91 * 2757: function getClickMenu($str,$table,$uid='')
92 * 2778: function renderWizards($itemKinds,$wizConf,$table,$row,$field,&$PA,$itemName,$specConf,$RTE=0)
93 * 2982: function getIcon($icon)
94 * 3009: function optionTagStyle($iconString)
95 * 3025: function extractValuesOnlyFromValueLabelList($itemFormElValue)
96 * 3047: function wrapOpenPalette($header,$table,$row,$palette,$retFunc=0)
97 * 3071: function checkBoxParams($itemName,$thisValue,$c,$iCount,$addFunc='')
98 * 3085: function elName($itemName)
99 * 3096: function noTitle($str,$wrapParts=array())
100 * 3105: function blur()
101 * 3114: function thisReturnUrl()
102 * 3127: function getSingleHiddenField($table,$field,$row)
103 * 3149: function formWidth($size=48,$textarea=0)
104 * 3176: function formWidthText($size=48,$wrap='')
105 * 3192: function formElStyle($type)
106 * 3203: function formElClass($type)
107 * 3214: function formElStyleClassValue($type, $class=FALSE)
108 * 3236: function insertDefStyle($type)
109 * 3255: function getDynTabMenu($parts, $idString)
110 *
111 * SECTION: Item-array manipulation functions (check/select/radio)
112 * 3294: function initItemArray($fieldValue)
113 * 3312: function addItems($items,$iArray)
114 * 3334: function procItems($items,$iArray,$config,$table,$row,$field)
115 * 3358: function addSelectOptionsToItemArray($items,$fieldValue,$TSconfig,$field)
116 * 3580: function addSelectOptionsToItemArray_makeModuleData($value)
117 * 3602: function foreignTable($items,$fieldValue,$TSconfig,$field,$pFFlag=0)
118 *
119 * SECTION: Template functions
120 * 3682: function setNewBEDesign()
121 * 3737: function intoTemplate($inArr,$altTemplate='')
122 * 3761: function addUserTemplateMarkers($marker,$table,$field,$row,&$PA)
123 * 3772: function wrapLabels($str)
124 * 3785: function wrapTotal($c,$rec,$table)
125 * 3798: function replaceTableWrap($arr,$rec,$table)
126 * 3835: function wrapBorder(&$out_array,&$out_pointer)
127 * 3857: function rplColorScheme($inTemplate)
128 * 3877: function getDivider()
129 * 3887: function printPalette($palArr)
130 * 3938: function helpTextIcon($table,$field,$force=0)
131 * 3958: function helpText($table,$field)
132 * 3979: function setColorScheme($scheme)
133 * 4003: function resetSchemes()
134 * 4014: function storeSchemes()
135 * 4026: function restoreSchemes()
136 *
137 * SECTION: JavaScript related functions
138 * 4056: function JStop()
139 * 4107: function JSbottom($formname='forms[0]')
140 * 4420: function dbFileCon($formObj='document.forms[0]')
141 * 4528: function printNeededJSFunctions()
142 * 4555: function printNeededJSFunctions_top()
143 *
144 * SECTION: Various helper functions
145 * 4603: function getDefaultRecord($table,$pid=0)
146 * 4642: function getRecordPath($table,$rec)
147 * 4656: function readPerms()
148 * 4670: function sL($str)
149 * 4683: function getLL($str)
150 * 4701: function isPalettesCollapsed($table,$palette)
151 * 4716: function isDisplayCondition($displayCond,$row)
152 * 4797: function getTSCpid($table,$uid,$pid)
153 * 4811: function doLoadTableDescr($table)
154 * 4823: function getAvailableLanguages($onlyIsoCoded=1,$setDefault=1)
155 *
156 *
157 * 4865: class t3lib_TCEforms_FE extends t3lib_TCEforms
158 * 4873: function wrapLabels($str)
159 * 4883: function printPalette($palArr)
160 * 4908: 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']; // Using "form_type" locally in this script
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']; // Using "form_type" locally in this script
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 // "Extra" configuration; Returns configuration for the field based on settings found in the "types" fieldlist. See http://typo3.org/documentation/document-library/doc_core_api/Wizards_Configuratio/.
1150 $specConf = $this->getSpecConfFromString($PA['extra'], $PA['fieldConf']['defaultExtras']);
1151
1152 // Getting the selector box items from the system
1153 $selItems = $this->addSelectOptionsToItemArray($this->initItemArray($PA['fieldConf']),$PA['fieldConf'],$this->setTSconfig($table,$row),$field);
1154 $selItems = $this->addItems($selItems,$PA['fieldTSConfig']['addItems.']);
1155 if ($config['itemsProcFunc']) $selItems = $this->procItems($selItems,$PA['fieldTSConfig']['itemsProcFunc.'],$config,$table,$row,$field);
1156
1157 // Possibly remove some items:
1158 $removeItems = t3lib_div::trimExplode(',',$PA['fieldTSConfig']['removeItems'],1);
1159 foreach($selItems as $tk => $p) {
1160
1161 // Checking languages and authMode:
1162 $languageDeny = $TCA[$table]['ctrl']['languageField'] && !strcmp($TCA[$table]['ctrl']['languageField'], $field) && !$GLOBALS['BE_USER']->checkLanguageAccess($p[1]);
1163 $authModeDeny = $config['form_type']=='select' && $config['authMode'] && !$GLOBALS['BE_USER']->checkAuthMode($table,$field,$p[1],$config['authMode']);
1164 if (in_array($p[1],$removeItems) || $languageDeny || $authModeDeny) {
1165 unset($selItems[$tk]);
1166 } elseif (isset($PA['fieldTSConfig']['altLabels.'][$p[1]])) {
1167 $selItems[$tk][0]=$this->sL($PA['fieldTSConfig']['altLabels.'][$p[1]]);
1168 }
1169
1170 // Removing doktypes with no access:
1171 if ($table.'.'.$field == 'pages.doktype') {
1172 if (!($GLOBALS['BE_USER']->isAdmin() || t3lib_div::inList($GLOBALS['BE_USER']->groupData['pagetypes_select'],$p[1]))) {
1173 unset($selItems[$tk]);
1174 }
1175 }
1176 }
1177
1178 // Creating the label for the "No Matching Value" entry.
1179 $nMV_label = isset($PA['fieldTSConfig']['noMatchingValue_label']) ? $this->sL($PA['fieldTSConfig']['noMatchingValue_label']) : '[ '.$this->getLL('l_noMatchingValue').' ]';
1180
1181 // Prepare some values:
1182 $maxitems = intval($config['maxitems']);
1183
1184 // If a SINGLE selector box...
1185 if ($maxitems<=1) {
1186 $item = $this->getSingleField_typeSelect_single($table,$field,$row,$PA,$config,$selItems,$nMV_label);
1187 } elseif (!strcmp($config['renderMode'],'checkbox')) { // Checkbox renderMode
1188 $item = $this->getSingleField_typeSelect_checkbox($table,$field,$row,$PA,$config,$selItems,$nMV_label);
1189 } elseif (!strcmp($config['renderMode'],'singlebox')) { // Single selector box renderMode
1190 $item = $this->getSingleField_typeSelect_singlebox($table,$field,$row,$PA,$config,$selItems,$nMV_label);
1191 } else { // Traditional multiple selector box:
1192 $item = $this->getSingleField_typeSelect_multiple($table,$field,$row,$PA,$config,$selItems,$nMV_label);
1193 }
1194
1195 // Wizards:
1196 $altItem = '<input type="hidden" name="'.$PA['itemFormElName'].'" value="'.htmlspecialchars($PA['itemFormElValue']).'" />';
1197 $item = $this->renderWizards(array($item,$altItem),$config['wizards'],$table,$row,$field,$PA,$PA['itemFormElName'],$specConf);
1198
1199 return $item;
1200 }
1201
1202 /**
1203 * Creates a single-selector box
1204 * (Render function for getSingleField_typeSelect())
1205 *
1206 * @param string See getSingleField_typeSelect()
1207 * @param string See getSingleField_typeSelect()
1208 * @param array See getSingleField_typeSelect()
1209 * @param array See getSingleField_typeSelect()
1210 * @param array (Redundant) content of $PA['fieldConf']['config'] (for convenience)
1211 * @param array Items available for selection
1212 * @param string Label for no-matching-value
1213 * @return string The HTML code for the item
1214 * @see getSingleField_typeSelect()
1215 */
1216 function getSingleField_typeSelect_single($table,$field,$row,&$PA,$config,$selItems,$nMV_label) {
1217
1218 // Initialization:
1219 $c = 0;
1220 $sI = 0;
1221 $noMatchingValue = 1;
1222 $opt = array();
1223 $selicons = array();
1224 $onlySelectedIconShown = 0;
1225 $size = intval($config['size']);
1226
1227 // Icon configuration:
1228 if ($config['suppress_icons']=='IF_VALUE_FALSE') {
1229 $suppressIcons = !$PA['itemFormElValue'] ? 1 : 0;
1230 } elseif ($config['suppress_icons']=='ONLY_SELECTED') {
1231 $suppressIcons=0;
1232 $onlySelectedIconShown=1;
1233 } elseif ($config['suppress_icons']) {
1234 $suppressIcons = 1;
1235 } else $suppressIcons = 0;
1236
1237 // Traverse the Array of selector box items:
1238 foreach($selItems as $p) {
1239 $sM = (!strcmp($PA['itemFormElValue'],$p[1])?' selected="selected"':'');
1240 if ($sM) {
1241 $sI = $c;
1242 $noMatchingValue = 0;
1243 }
1244
1245 // Getting style attribute value (for icons):
1246 if ($config['iconsInOptionTags']) {
1247 $styleAttrValue = $this->optionTagStyle($p[2]);
1248 }
1249
1250 // Compiling the <option> tag:
1251 $opt[]= '<option value="'.htmlspecialchars($p[1]).'"'.
1252 $sM.
1253 ($styleAttrValue ? ' style="'.htmlspecialchars($styleAttrValue).'"' : '').
1254 (!strcmp($p[1],'--div--') ? ' class="c-divider"' : '').
1255 '>'.t3lib_div::deHSCentities(htmlspecialchars($p[0])).'</option>';
1256
1257 // If there is an icon for the selector box (rendered in table under)...:
1258 if ($p[2] && !$suppressIcons && (!$onlySelectedIconShown || $sM)) {
1259 list($selIconFile,$selIconInfo)=$this->getIcon($p[2]);
1260 $iOnClick = $this->elName($PA['itemFormElName']).'.selectedIndex='.$c.'; '.implode('',$PA['fieldChangeFunc']).$this->blur().'return false;';
1261 $selicons[]=array(
1262 (!$onlySelectedIconShown ? '<a href="#" onclick="'.htmlspecialchars($iOnClick).'">' : '').
1263 '<img src="'.$selIconFile.'" '.$selIconInfo[3].' vspace="2" border="0" title="'.htmlspecialchars($p[0]).'" alt="'.htmlspecialchars($p[0]).'" />'.
1264 (!$onlySelectedIconShown ? '</a>' : ''),
1265 $c,$sM);
1266 }
1267 $c++;
1268 }
1269
1270 // No-matching-value:
1271 if ($PA['itemFormElValue'] && $noMatchingValue && !$PA['fieldTSConfig']['disableNoMatchingValueElement'] && !$config['disableNoMatchingValueElement']) {
1272 $nMV_label = @sprintf($nMV_label, $PA['itemFormElValue']);
1273 $opt[]= '<option value="'.htmlspecialchars($PA['itemFormElValue']).'" selected="selected">'.htmlspecialchars($nMV_label).'</option>';
1274 }
1275
1276 // Create item form fields:
1277 $sOnChange = 'if (this.options[this.selectedIndex].value==\'--div--\') {this.selectedIndex='.$sI.';} '.implode('',$PA['fieldChangeFunc']);
1278 $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...
1279 $item.= '<select name="'.$PA['itemFormElName'].'"'.
1280 $this->insertDefStyle('select').
1281 ($size?' size="'.$size.'"':'').
1282 ' onchange="'.htmlspecialchars($sOnChange).'"'.
1283 $PA['onFocus'].'>';
1284 $item.= implode('',$opt);
1285 $item.= '</select>';
1286
1287 // Create icon table:
1288 if (count($selicons)) {
1289 $item.='<table border="0" cellpadding="0" cellspacing="0" class="typo3-TCEforms-selectIcons">';
1290 $selicon_cols = intval($config['selicon_cols']);
1291 if (!$selicon_cols) $selicon_cols=count($selicons);
1292 $sR = ceil(count($selicons)/$selicon_cols);
1293 $selicons = array_pad($selicons,$sR*$selicon_cols,'');
1294 for($sa=0;$sa<$sR;$sa++) {
1295 $item.='<tr>';
1296 for($sb=0;$sb<$selicon_cols;$sb++) {
1297 $sk=($sa*$selicon_cols+$sb);
1298 $imgN = 'selIcon_'.$table.'_'.$row['uid'].'_'.$field.'_'.$selicons[$sk][1];
1299 $imgS = ($selicons[$sk][2]?$this->backPath.'gfx/content_selected.gif':'clear.gif');
1300 $item.='<td><img name="'.htmlspecialchars($imgN).'" src="'.$imgS.'" width="7" height="10" alt="" /></td>';
1301 $item.='<td>'.$selicons[$sk][0].'</td>';
1302 }
1303 $item.='</tr>';
1304 }
1305 $item.='</table>';
1306 }
1307
1308 return $item;
1309 }
1310
1311 /**
1312 * Creates a checkbox list (renderMode = "checkbox")
1313 * (Render function for getSingleField_typeSelect())
1314 *
1315 * @param string See getSingleField_typeSelect()
1316 * @param string See getSingleField_typeSelect()
1317 * @param array See getSingleField_typeSelect()
1318 * @param array See getSingleField_typeSelect()
1319 * @param array (Redundant) content of $PA['fieldConf']['config'] (for convenience)
1320 * @param array Items available for selection
1321 * @param string Label for no-matching-value
1322 * @return string The HTML code for the item
1323 * @see getSingleField_typeSelect()
1324 */
1325 function getSingleField_typeSelect_checkbox($table,$field,$row,&$PA,$config,$selItems,$nMV_label) {
1326
1327 // Get values in an array (and make unique, which is fine because there can be no duplicates anyway):
1328 $itemArray = array_flip($this->extractValuesOnlyFromValueLabelList($PA['itemFormElValue']));
1329
1330 // Traverse the Array of selector box items:
1331 $tRows = array();
1332 $sOnChange = implode('',$PA['fieldChangeFunc']);
1333 $c=0;
1334 $setAll = array(); // Used to accumulate the JS needed to restore the original selection.
1335 foreach($selItems as $p) {
1336 // Non-selectable element:
1337 if (!strcmp($p[1],'--div--')) {
1338 if (count($setAll)) {
1339 $tRows[] = '
1340 <tr>
1341 <td colspan="2">'.
1342 '<a href="#" onclick="'.htmlspecialchars(implode('',$setAll).' return false;').'">'.
1343 htmlspecialchars($this->getLL('l_setAllCheckboxes')).
1344 '</a></td>
1345 </tr>';
1346 $setAll = array();
1347 }
1348
1349 $tRows[] = '
1350 <tr class="c-header">
1351 <td colspan="2">'.htmlspecialchars($p[0]).'</td>
1352 </tr>';
1353 } else {
1354 // Selected or not by default:
1355 $sM = '';
1356 if (isset($itemArray[$p[1]])) {
1357 $sM = ' checked="checked"';
1358 unset($itemArray[$p[1]]);
1359 }
1360
1361 // Icon:
1362 $selIconFile = '';
1363 if ($p[2]) {
1364 list($selIconFile,$selIconInfo) = $this->getIcon($p[2]);
1365 }
1366
1367 // Compile row:
1368 $onClickCell = $this->elName($PA['itemFormElName'].'['.$c.']').'.checked=!'.$this->elName($PA['itemFormElName'].'['.$c.']').'.checked;';
1369 $onClick = 'this.attributes.getNamedItem("class").nodeValue = '.$this->elName($PA['itemFormElName'].'['.$c.']').'.checked ? "c-selectedItem" : "";';
1370 $setAll[] = $this->elName($PA['itemFormElName'].'['.$c.']').'.checked=1;';
1371 $tRows[] = '
1372 <tr class="'.($sM ? 'c-selectedItem' : '').'" onclick="'.htmlspecialchars($onClick).'" style="cursor: pointer;">
1373 <td><input type="checkbox" name="'.htmlspecialchars($PA['itemFormElName'].'['.$c.']').'" value="'.htmlspecialchars($p[1]).'"'.$sM.' onclick="'.htmlspecialchars($sOnChange).'"'.$PA['onFocus'].' /></td>
1374 <td class="c-labelCell" onclick="'.htmlspecialchars($onClickCell).'">'.
1375 ($selIconFile ? '<img src="'.$selIconFile.'" '.$selIconInfo[3].' vspace="2" border="0" class="absmiddle" style="margin-right: 4px;" alt="" />' : '').
1376 t3lib_div::deHSCentities(htmlspecialchars($p[0])).
1377 (strcmp($p[3],'') ? '<br/><p class="c-descr">'.nl2br(trim(htmlspecialchars($p[3]))).'</p>' : '').
1378 '</td>
1379 </tr>';
1380 $c++;
1381 }
1382 }
1383
1384 // Remaining checkboxes will get their set-all link:
1385 if (count($setAll)) {
1386 $tRows[] = '
1387 <tr>
1388 <td colspan="2">'.
1389 '<a href="#" onclick="'.htmlspecialchars(implode('',$setAll).' return false;').'">'.
1390 htmlspecialchars($this->getLL('l_setAllCheckboxes')).
1391 '</a></td>
1392 </tr>';
1393 }
1394
1395 // Remaining values (invalid):
1396 if (count($itemArray) && !$PA['fieldTSConfig']['disableNoMatchingValueElement'] && !$config['disableNoMatchingValueElement']) {
1397 foreach($itemArray as $theNoMatchValue => $temp) {
1398 // Compile <checkboxes> tag:
1399 array_unshift($tRows,'
1400 <tr class="c-invalidItem">
1401 <td><input type="checkbox" name="'.htmlspecialchars($PA['itemFormElName'].'['.$c.']').'" value="'.htmlspecialchars($theNoMatchValue).'" checked="checked" onclick="'.htmlspecialchars($sOnChange).'"'.$PA['onFocus'].' /></td>
1402 <td class="c-labelCell">'.
1403 t3lib_div::deHSCentities(htmlspecialchars(@sprintf($nMV_label, $theNoMatchValue))).
1404 '</td>
1405 </tr>');
1406 $c++;
1407 }
1408 }
1409
1410 // Add an empty hidden field which will send a blank value if all items are unselected.
1411 $item.='<input type="hidden" name="'.htmlspecialchars($PA['itemFormElName']).'" value="" />';
1412
1413 // Implode rows in table:
1414 $item.= '
1415 <table border="0" cellpadding="0" cellspacing="0" class="typo3-TCEforms-select-checkbox">'.
1416 implode('',$tRows).'
1417 </table>
1418 ';
1419
1420 return $item;
1421 }
1422
1423 /**
1424 * Creates a selectorbox list (renderMode = "singlebox")
1425 * (Render function for getSingleField_typeSelect())
1426 *
1427 * @param string See getSingleField_typeSelect()
1428 * @param string See getSingleField_typeSelect()
1429 * @param array See getSingleField_typeSelect()
1430 * @param array See getSingleField_typeSelect()
1431 * @param array (Redundant) content of $PA['fieldConf']['config'] (for convenience)
1432 * @param array Items available for selection
1433 * @param string Label for no-matching-value
1434 * @return string The HTML code for the item
1435 * @see getSingleField_typeSelect()
1436 */
1437 function getSingleField_typeSelect_singlebox($table,$field,$row,&$PA,$config,$selItems,$nMV_label) {
1438
1439 // Get values in an array (and make unique, which is fine because there can be no duplicates anyway):
1440 $itemArray = array_flip($this->extractValuesOnlyFromValueLabelList($PA['itemFormElValue']));
1441
1442 // Traverse the Array of selector box items:
1443 $opt = array();
1444 $restoreCmd = array(); // Used to accumulate the JS needed to restore the original selection.
1445 $c = 0;
1446 foreach($selItems as $p) {
1447 // Selected or not by default:
1448 $sM = '';
1449 if (isset($itemArray[$p[1]])) {
1450 $sM = ' selected="selected"';
1451 $restoreCmd[] = $this->elName($PA['itemFormElName'].'[]').'.options['.$c.'].selected=1;';
1452 unset($itemArray[$p[1]]);
1453 }
1454
1455 // Non-selectable element:
1456 $nonSel = '';
1457 if (!strcmp($p[1],'--div--')) {
1458 $nonSel = ' onclick="this.selected=0;" class="c-divider"';
1459 }
1460
1461 // Icon style for option tag:
1462 if ($config['iconsInOptionTags']) {
1463 $styleAttrValue = $this->optionTagStyle($p[2]);
1464 }
1465
1466 // Compile <option> tag:
1467 $opt[] = '<option value="'.htmlspecialchars($p[1]).'"'.
1468 $sM.
1469 $nonSel.
1470 ($styleAttrValue ? ' style="'.htmlspecialchars($styleAttrValue).'"' : '').
1471 '>'.t3lib_div::deHSCentities(htmlspecialchars($p[0])).'</option>';
1472 $c++;
1473 }
1474
1475 // Remaining values:
1476 if (count($itemArray) && !$PA['fieldTSConfig']['disableNoMatchingValueElement'] && !$config['disableNoMatchingValueElement']) {
1477 foreach($itemArray as $theNoMatchValue => $temp) {
1478 // Compile <option> tag:
1479 array_unshift($opt,'<option value="'.htmlspecialchars($theNoMatchValue).'" selected="selected">'.t3lib_div::deHSCentities(htmlspecialchars(@sprintf($nMV_label, $theNoMatchValue))).'</option>');
1480 }
1481 }
1482
1483 // Compile selector box:
1484 $sOnChange = implode('',$PA['fieldChangeFunc']);
1485 $selector_itemListStyle = isset($config['itemListStyle']) ? ' style="'.htmlspecialchars($config['itemListStyle']).'"' : ' style="'.$this->defaultMultipleSelectorStyle.'"';
1486 $size = intval($config['size']);
1487 $size = $config['autoSizeMax'] ? t3lib_div::intInRange(count($selItems)+1,t3lib_div::intInRange($size,1),$config['autoSizeMax']) : $size;
1488 $selectBox = '<select name="'.$PA['itemFormElName'].'[]"'.
1489 $this->insertDefStyle('select').
1490 ($size ? ' size="'.$size.'"' : '').
1491 ' multiple="multiple" onchange="'.htmlspecialchars($sOnChange).'"'.
1492 $PA['onFocus'].
1493 $selector_itemListStyle.'>
1494 '.
1495 implode('
1496 ',$opt).'
1497 </select>';
1498
1499 // Add an empty hidden field which will send a blank value if all items are unselected.
1500 $item.='<input type="hidden" name="'.htmlspecialchars($PA['itemFormElName']).'" value="" />';
1501
1502 // Put it all into a table:
1503 $item.= '
1504 <table border="0" cellspacing="0" cellpadding="0" width="1" class="typo3-TCEforms-select-singlebox">
1505 <tr>
1506 <td>
1507 '.$selectBox.'
1508 <br/>
1509 <em>'.
1510 htmlspecialchars($this->getLL('l_holdDownCTRL')).
1511 '</em>
1512 </td>
1513 <td valign="top">
1514 <a href="#" onclick="'.htmlspecialchars($this->elName($PA['itemFormElName'].'[]').'.selectedIndex=-1;'.implode('',$restoreCmd).' return false;').'">'.
1515 '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/history.gif','width="13" height="12"').' title="'.htmlspecialchars($this->getLL('l_revertSelection')).'" alt="" />'.
1516 '</a>
1517 </td>
1518 </tr>
1519 </table>
1520 ';
1521
1522 return $item;
1523 }
1524
1525 /**
1526 * Creates a multiple-selector box (two boxes, side-by-side)
1527 * (Render function for getSingleField_typeSelect())
1528 *
1529 * @param string See getSingleField_typeSelect()
1530 * @param string See getSingleField_typeSelect()
1531 * @param array See getSingleField_typeSelect()
1532 * @param array See getSingleField_typeSelect()
1533 * @param array (Redundant) content of $PA['fieldConf']['config'] (for convenience)
1534 * @param array Items available for selection
1535 * @param string Label for no-matching-value
1536 * @return string The HTML code for the item
1537 * @see getSingleField_typeSelect()
1538 */
1539 function getSingleField_typeSelect_multiple($table,$field,$row,&$PA,$config,$selItems,$nMV_label) {
1540
1541 // Setting this hidden field (as a flag that JavaScript can read out)
1542 $item.= '<input type="hidden" name="'.$PA['itemFormElName'].'_mul" value="'.($config['multiple']?1:0).'" />';
1543
1544 // Set max and min items:
1545 $maxitems = t3lib_div::intInRange($config['maxitems'],0);
1546 if (!$maxitems) $maxitems=100000;
1547 $minitems = t3lib_div::intInRange($config['minitems'],0);
1548
1549 // Register the required number of elements:
1550 $this->requiredElements[$PA['itemFormElName']] = array($minitems,$maxitems,'imgName'=>$table.'_'.$row['uid'].'_'.$field);
1551
1552 // Get "removeItems":
1553 $removeItems = t3lib_div::trimExplode(',',$PA['fieldTSConfig']['removeItems'],1);
1554
1555 // Perform modification of the selected items array:
1556 $itemArray = t3lib_div::trimExplode(',',$PA['itemFormElValue'],1);
1557 foreach($itemArray as $tk => $tv) {
1558 $tvP = explode('|',$tv,2);
1559 $evalValue = rawurldecode($tvP[0]);
1560 $isRemoved = in_array($evalValue,$removeItems) || ($config['form_type']=='select' && $config['authMode'] && !$GLOBALS['BE_USER']->checkAuthMode($table,$field,$evalValue,$config['authMode']));
1561 if ($isRemoved && !$PA['fieldTSConfig']['disableNoMatchingValueElement'] && !$config['disableNoMatchingValueElement']) {
1562 $tvP[1] = rawurlencode(@sprintf($nMV_label, $evalValue));
1563 } elseif (isset($PA['fieldTSConfig']['altLabels.'][$evalValue])) {
1564 $tvP[1] = rawurlencode($this->sL($PA['fieldTSConfig']['altLabels.'][$evalValue]));
1565 } else {
1566 $tvP[1] = rawurlencode($this->sL(rawurldecode($tvP[1])));
1567 }
1568 $itemArray[$tk] = implode('|',$tvP);
1569 }
1570
1571 // Create option tags:
1572 $opt = array();
1573 $styleAttrValue = '';
1574 foreach($selItems as $p) {
1575 if ($config['iconsInOptionTags']) {
1576 $styleAttrValue = $this->optionTagStyle($p[2]);
1577 }
1578 $opt[]= '<option value="'.htmlspecialchars($p[1]).'"'.
1579 ($styleAttrValue ? ' style="'.htmlspecialchars($styleAttrValue).'"' : '').
1580 '>'.htmlspecialchars($p[0]).'</option>';
1581 }
1582
1583 // Put together the selector box:
1584 $selector_itemListStyle = isset($config['itemListStyle']) ? ' style="'.htmlspecialchars($config['itemListStyle']).'"' : ' style="'.$this->defaultMultipleSelectorStyle.'"';
1585 $size = intval($config['size']);
1586 $size = $config['autoSizeMax'] ? t3lib_div::intInRange(count($itemArray)+1,t3lib_div::intInRange($size,1),$config['autoSizeMax']) : $size;
1587 $sOnChange = 'setFormValueFromBrowseWin(\''.$PA['itemFormElName'].'\',this.options[this.selectedIndex].value,this.options[this.selectedIndex].text); '.implode('',$PA['fieldChangeFunc']);
1588 $itemsToSelect = '
1589 <select name="'.$PA['itemFormElName'].'_sel"'.
1590 $this->insertDefStyle('select').
1591 ($size ? ' size="'.$size.'"' : '').
1592 ' onchange="'.htmlspecialchars($sOnChange).'"'.
1593 $PA['onFocus'].
1594 $selector_itemListStyle.'>
1595 '.implode('
1596 ',$opt).'
1597 </select>';
1598
1599 // Pass to "dbFileIcons" function:
1600 $params = array(
1601 'size' => $size,
1602 'autoSizeMax' => t3lib_div::intInRange($config['autoSizeMax'],0),
1603 'style' => isset($config['selectedListStyle']) ? ' style="'.htmlspecialchars($config['selectedListStyle']).'"' : ' style="'.$this->defaultMultipleSelectorStyle.'"',
1604 'dontShowMoveIcons' => ($maxitems<=1),
1605 'maxitems' => $maxitems,
1606 'info' => '',
1607 'headers' => array(
1608 'selector' => $this->getLL('l_selected').':<br />',
1609 'items' => $this->getLL('l_items').':<br />'
1610 ),
1611 'noBrowser' => 1,
1612 'thumbnails' => $itemsToSelect
1613 );
1614 $item.= $this->dbFileIcons($PA['itemFormElName'],'','',$itemArray,'',$params,$PA['onFocus']);
1615
1616 return $item;
1617 }
1618
1619 /**
1620 * Generation of TCEform elements of the type "group"
1621 * This will render a selectorbox into which elements from either the file system or database can be inserted. Relations.
1622 *
1623 * @param string The table name of the record
1624 * @param string The field name which this element is supposed to edit
1625 * @param array The record data array where the value(s) for the field can be found
1626 * @param array An array with additional configuration options.
1627 * @return string The HTML code for the TCEform field
1628 */
1629 function getSingleField_typeGroup($table,$field,$row,&$PA) {
1630 // Init:
1631 $config = $PA['fieldConf']['config'];
1632 $internal_type = $config['internal_type'];
1633 $show_thumbs = $config['show_thumbs'];
1634 $size = intval($config['size']);
1635 $maxitems = t3lib_div::intInRange($config['maxitems'],0);
1636 if (!$maxitems) $maxitems=100000;
1637 $minitems = t3lib_div::intInRange($config['minitems'],0);
1638 $allowed = $config['allowed'];
1639 $disallowed = $config['disallowed'];
1640
1641 $item.= '<input type="hidden" name="'.$PA['itemFormElName'].'_mul" value="'.($config['multiple']?1:0).'" />';
1642 $this->requiredElements[$PA['itemFormElName']] = array($minitems,$maxitems,'imgName'=>$table.'_'.$row['uid'].'_'.$field);
1643 $info='';
1644
1645 // "Extra" configuration; Returns configuration for the field based on settings found in the "types" fieldlist. See http://typo3.org/documentation/document-library/doc_core_api/Wizards_Configuratio/.
1646 $specConf = $this->getSpecConfFromString($PA['extra'], $PA['fieldConf']['defaultExtras']);
1647
1648 // Acting according to either "file" or "db" type:
1649 switch((string)$config['internal_type']) {
1650 case 'file': // If the element is of the internal type "file":
1651
1652 // Creating string showing allowed types:
1653 $tempFT = t3lib_div::trimExplode(',',$allowed,1);
1654 if (!count($tempFT)) {$info.='*';}
1655 foreach($tempFT as $ext) {
1656 if ($ext) {
1657 $info.=strtoupper($ext).' ';
1658 }
1659 }
1660 // Creating string, showing disallowed types:
1661 $tempFT_dis = t3lib_div::trimExplode(',',$disallowed,1);
1662 if (count($tempFT_dis)) {$info.='<br />';}
1663 foreach($tempFT_dis as $ext) {
1664 if ($ext) {
1665 $info.='-'.strtoupper($ext).' ';
1666 }
1667 }
1668
1669 // Making the array of file items:
1670 $itemArray = t3lib_div::trimExplode(',',$PA['itemFormElValue'],1);
1671
1672 // Showing thumbnails:
1673 $thumbsnail = '';
1674 if ($show_thumbs) {
1675 $imgs = array();
1676 foreach($itemArray as $imgRead) {
1677 $imgP = explode('|',$imgRead);
1678
1679 $rowCopy = array();
1680 $rowCopy[$field] = $imgP[0];
1681
1682 // Icon + clickmenu:
1683 $absFilePath = t3lib_div::getFileAbsFileName($config['uploadfolder'].'/'.$imgP[0]);
1684
1685 $fI = pathinfo($imgP[0]);
1686 $fileIcon = t3lib_BEfunc::getFileIcon(strtolower($fI['extension']));
1687 $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="" />';
1688
1689 $imgs[] = '<span class="nobr">'.t3lib_BEfunc::thumbCode($rowCopy,$table,$field,$this->backPath,'thumbs.php',$config['uploadfolder'],0,' align="middle"').
1690 ($absFilePath ? $this->getClickMenu($fileIcon, $absFilePath) : $fileIcon).
1691 $imgP[0].
1692 '</span>';
1693 }
1694 $thumbsnail = implode('<br />',$imgs);
1695 }
1696
1697 // Creating the element:
1698 $params = array(
1699 'size' => $size,
1700 'dontShowMoveIcons' => ($maxitems<=1),
1701 'autoSizeMax' => t3lib_div::intInRange($config['autoSizeMax'],0),
1702 'maxitems' => $maxitems,
1703 'style' => isset($config['selectedListStyle']) ? ' style="'.htmlspecialchars($config['selectedListStyle']).'"' : ' style="'.$this->defaultMultipleSelectorStyle.'"',
1704 'info' => $info,
1705 'thumbnails' => $thumbsnail
1706 );
1707 $item.= $this->dbFileIcons($PA['itemFormElName'],'file',implode(',',$tempFT),$itemArray,'',$params,$PA['onFocus']);
1708
1709 // Adding the upload field:
1710 if ($this->edit_docModuleUpload) $item.='<input type="file" name="'.$PA['itemFormElName_file'].'"'.$this->formWidth().' size="60" />';
1711 break;
1712 case 'db': // If the element is of the internal type "db":
1713
1714 // Creating string showing allowed types:
1715 $tempFT = t3lib_div::trimExplode(',',$allowed,1);
1716 if (!strcmp(trim($tempFT[0]),'*')) {
1717 $info.='<span class="nobr">&nbsp;&nbsp;&nbsp;&nbsp;'.
1718 htmlspecialchars($this->getLL('l_allTables')).
1719 '</span><br />';
1720 } else {
1721 while(list(,$theT)=each($tempFT)) {
1722 if ($theT) {
1723 $info.='<span class="nobr">&nbsp;&nbsp;&nbsp;&nbsp;'.
1724 t3lib_iconWorks::getIconImage($theT,array(),$this->backPath,'align="top"').
1725 htmlspecialchars($this->sL($GLOBALS['TCA'][$theT]['ctrl']['title'])).
1726 '</span><br />';
1727 }
1728 }
1729 }
1730
1731 $perms_clause = $GLOBALS['BE_USER']->getPagePermsClause(1);
1732 $itemArray = array();
1733 $imgs = array();
1734
1735 // Thumbnails:
1736 $temp_itemArray = t3lib_div::trimExplode(',',$PA['itemFormElValue'],1);
1737 foreach($temp_itemArray as $dbRead) {
1738 $recordParts = explode('|',$dbRead);
1739 list($this_table,$this_uid) = t3lib_BEfunc::splitTable_Uid($recordParts[0]);
1740 $itemArray[] = array('table'=>$this_table, 'id'=>$this_uid);
1741 if ($show_thumbs) {
1742 $rr = t3lib_BEfunc::getRecord($this_table,$this_uid);
1743 $imgs[] = '<span class="nobr">'.
1744 $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).
1745 '&nbsp;'.
1746 $this->noTitle($rr[$GLOBALS['TCA'][$this_table]['ctrl']['label']],array('<em>','</em>')).' <span class="typo3-dimmed"><em>['.$rr['uid'].']</em></span>'.
1747 '</span>';
1748 }
1749 }
1750 $thumbsnail='';
1751 if ($show_thumbs) {
1752 $thumbsnail = implode('<br />',$imgs);
1753 }
1754
1755 // Creating the element:
1756 $params = array(
1757 'size' => $size,
1758 'dontShowMoveIcons' => ($maxitems<=1),
1759 'autoSizeMax' => t3lib_div::intInRange($config['autoSizeMax'],0),
1760 'maxitems' => $maxitems,
1761 'style' => isset($config['selectedListStyle']) ? ' style="'.htmlspecialchars($config['selectedListStyle']).'"' : ' style="'.$this->defaultMultipleSelectorStyle.'"',
1762 'info' => $info,
1763 'thumbnails' => $thumbsnail
1764 );
1765 $item.= $this->dbFileIcons($PA['itemFormElName'],'db',implode(',',$tempFT),$itemArray,'',$params,$PA['onFocus']);
1766 break;
1767 }
1768
1769 // Wizards:
1770 $altItem = '<input type="hidden" name="'.$PA['itemFormElName'].'" value="'.htmlspecialchars($PA['itemFormElValue']).'" />';
1771 $item = $this->renderWizards(array($item,$altItem),$config['wizards'],$table,$row,$field,$PA,$PA['itemFormElName'],$specConf);
1772
1773 return $item;
1774 }
1775
1776 /**
1777 * Generation of TCEform elements of the type "none"
1778 * This will render a non-editable display of the content of the field.
1779 *
1780 * @param string The table name of the record
1781 * @param string The field name which this element is supposed to edit
1782 * @param array The record data array where the value(s) for the field can be found
1783 * @param array An array with additional configuration options.
1784 * @return string The HTML code for the TCEform field
1785 */
1786 function getSingleField_typeNone($table,$field,$row,&$PA) {
1787 // Init:
1788 $config = $PA['fieldConf']['config'];
1789 $itemValue = $PA['itemFormElValue'];
1790
1791 return $this->getSingleField_typeNone_render($config,$itemValue);
1792 }
1793
1794 /**
1795 * HTML rendering of a value which is not editable.
1796 *
1797 * @param array Configuration for the display
1798 * @param string The value to display
1799 * @return string The HTML code for the display
1800 * @see getSingleField_typeNone();
1801 */
1802 function getSingleField_typeNone_render($config,$itemValue) {
1803
1804 // is colorScheme[0] the right value?
1805 $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;';
1806
1807 if ($config['rows']>1) {
1808 if(!$config['pass_content']) {
1809 $itemValue = nl2br(htmlspecialchars($itemValue));
1810 }
1811 // like textarea
1812 $cols = t3lib_div::intInRange($config['cols'] ? $config['cols'] : 30, 5, $this->maxTextareaWidth);
1813 if (!$config['fixedRows']) {
1814 $origRows = $rows = t3lib_div::intInRange($config['rows'] ? $config['rows'] : 5, 1, 20);
1815 if (strlen($itemValue)>$this->charsPerRow*2) {
1816 $cols = $this->maxTextareaWidth;
1817 $rows = t3lib_div::intInRange(round(strlen($itemValue)/$this->charsPerRow),count(explode(chr(10),$itemValue)),20);
1818 if ($rows<$origRows) $rows=$origRows;
1819 }
1820 } else {
1821 $rows = intval($config['rows']);
1822 }
1823
1824 if ($this->docLarge) $cols = round($cols*$this->form_largeComp);
1825 $width = ceil($cols*$this->form_rowsToStylewidth);
1826 // hardcoded: 12 is the height of the font
1827 $height=$rows*12;
1828
1829 $item='
1830 <div style="'.htmlspecialchars($divStyle.' overflow:auto; height:'.$height.'px; width:'.$width.'px;').'" class="'.htmlspecialchars($this->formElClass('none')).'">'.
1831 $itemValue.
1832 '</div>';
1833 } else {
1834 if(!$config['pass_content']) {
1835 $itemValue = htmlspecialchars($itemValue);
1836 }
1837
1838 $cols = $config['cols']?$config['cols']:($config['size']?$config['size']:$this->maxInputWidth);
1839 if ($this->docLarge) $cols = round($cols*$this->form_largeComp);
1840 $width = ceil($cols*$this->form_rowsToStylewidth);
1841
1842 // overflow:auto crashes mozilla here. Title tag is usefull when text is longer than the div box (overflow:hidden).
1843 $item = '
1844 <div style="'.htmlspecialchars($divStyle.' overflow:hidden; width:'.$width.'px;').'" class="'.htmlspecialchars($this->formElClass('none')).'" title="'.$itemValue.'">'.
1845 '<span class="nobr">'.(strcmp($itemValue,'')?$itemValue:'&nbsp;').'</span>'.
1846 '</div>';
1847 }
1848
1849 return $item;
1850 }
1851
1852 /**
1853 * Handler for Flex Forms
1854 *
1855 * @param string The table name of the record
1856 * @param string The field name which this element is supposed to edit
1857 * @param array The record data array where the value(s) for the field can be found
1858 * @param array An array with additional configuration options.
1859 * @return string The HTML code for the TCEform field
1860 */
1861 function getSingleField_typeFlex($table,$field,$row,&$PA) {
1862
1863 // Data Structure:
1864 $dataStructArray = t3lib_BEfunc::getFlexFormDS($PA['fieldConf']['config'],$row,$table);
1865 #debug($dataStructArray);
1866
1867 // Get data structure:
1868 if (is_array($dataStructArray)) {
1869 #debug(array(str_replace(' ',chr(160),$PA['itemFormElValue'])));
1870
1871 // Get data:
1872 $xmlData = $PA['itemFormElValue'];
1873 $xmlHeaderAttributes = t3lib_div::xmlGetHeaderAttribs($xmlData);
1874 $storeInCharset = strtolower($xmlHeaderAttributes['encoding']);
1875 if ($storeInCharset) {
1876 $currentCharset=$GLOBALS['LANG']->charSet;
1877 $xmlData = $GLOBALS['LANG']->csConvObj->conv($xmlData,$storeInCharset,$currentCharset,1);
1878 }
1879 $editData=t3lib_div::xml2array($xmlData);
1880 if (!is_array($editData)) { // Must be XML parsing error...
1881 #debug(array($editData,$xmlData));
1882 $editData=array();
1883 }
1884
1885 // Find the data structure if sheets are found:
1886 $sheet = $editData['meta']['currentSheetId'] ? $editData['meta']['currentSheetId'] : 'sDEF'; // Sheet to display
1887 # $item.= '<input type="hidden" name="'.$PA['itemFormElName'].'[meta][currentSheetId]" value="'.$sheet.'">';
1888
1889 // Create sheet menu:
1890 if (is_array($dataStructArray['sheets'])) {
1891 #$item.=$this->getSingleField_typeFlex_sheetMenu($dataStructArray['sheets'], $PA['itemFormElName'].'[meta][currentSheetId]', $sheet).'<br />';
1892 }
1893 #debug($editData);
1894
1895 // Create language menu:
1896 $langChildren = $dataStructArray['meta']['langChildren'] ? 1 : 0;
1897 $langDisabled = $dataStructArray['meta']['langDisable'] ? 1 : 0;
1898
1899 $languages = $this->getAvailableLanguages();
1900
1901 if (!is_array($editData['meta']['currentLangId']) || !count($editData['meta']['currentLangId'])) {
1902 $editData['meta']['currentLangId']=array('DEF');
1903 }
1904 $editData['meta']['currentLangId'] = array_unique($editData['meta']['currentLangId']);
1905
1906 if (!$langDisabled && count($languages) > 1) {
1907 $item.=$this->getSingleField_typeFlex_langMenu($languages, $PA['itemFormElName'].'[meta][currentLangId]', $editData['meta']['currentLangId']).'<br />';
1908 }
1909
1910 if ($langChildren || $langDisabled) {
1911 $rotateLang = array('DEF');
1912 } else {
1913 $rotateLang = $editData['meta']['currentLangId'];
1914 }
1915
1916 // Tabs sheets
1917 if (is_array($dataStructArray['sheets'])) {
1918 $tabsToTraverse = array_keys($dataStructArray['sheets']);
1919 } else {
1920 $tabsToTraverse = array($sheet);
1921 }
1922
1923 foreach($rotateLang as $lKey) {
1924 if (!$langChildren && !$langDisabled) {
1925 $item.= '<b>'.$lKey.':</b>';
1926 }
1927
1928 $tabParts = array();
1929 foreach($tabsToTraverse as $sheet) {
1930 $sheetCfg = $dataStructArray['sheets'][$sheet];
1931 list ($dataStruct, $sheet) = t3lib_div::resolveSheetDefInDS($dataStructArray,$sheet);
1932
1933 // Render sheet:
1934 if (is_array($dataStruct['ROOT']) && is_array($dataStruct['ROOT']['el'])) {
1935 $cmdData = t3lib_div::_GP('flexFormsCmdData');
1936 $lang = 'l'.$lKey; // Default language, other options are "lUK" or whatever country code (independant of system!!!)
1937 $PA['_valLang'] = $langChildren && !$langDisabled ? $editData['meta']['currentLangId'] : 'DEF'; // Default language, other options are "lUK" or whatever country code (independant of system!!!)
1938
1939 // Render flexform:
1940 $tRows = $this->getSingleField_typeFlex_draw(
1941 $dataStruct['ROOT']['el'],
1942 $editData['data'][$sheet][$lang],
1943 $cmdData['data'][$sheet][$lang],
1944 $table,
1945 $field,
1946 $row,
1947 $PA,
1948 '[data]['.$sheet.']['.$lang.']'
1949 );
1950 $sheetContent= '<table border="0" cellpadding="1" cellspacing="1" class="typo3-TCEforms-flexForm">'.implode('',$tRows).'</table>';
1951
1952 # $item = '<div style=" position:absolute;">'.$item.'</div>';
1953 //visibility:hidden;
1954 } else $sheetContent='Data Structure ERROR: No ROOT element found for sheet "'.$sheet.'".';
1955
1956 // Add to tab:
1957 $tabParts[] = array(
1958 'label' => ($sheetCfg['ROOT']['TCEforms']['sheetTitle'] ? $this->sL($sheetCfg['ROOT']['TCEforms']['sheetTitle']) : $sheet),
1959 'description' => ($sheetCfg['ROOT']['TCEforms']['sheetDescription'] ? $this->sL($sheetCfg['ROOT']['TCEforms']['sheetDescription']) : ''),
1960 'linkTitle' => ($sheetCfg['ROOT']['TCEforms']['sheetShortDescr'] ? $this->sL($sheetCfg['ROOT']['TCEforms']['sheetShortDescr']) : ''),
1961 'content' => $sheetContent
1962 );
1963 }
1964
1965 if (is_array($dataStructArray['sheets'])) {
1966 $item.= $this->getDynTabMenu($tabParts,'TCEFORMS:flexform:'.$PA['itemFormElName']);
1967 } else {
1968 $item.= $sheetContent;
1969 }
1970 }
1971 } else $item='Data Structure ERROR: '.$dataStructArray;
1972
1973 return $item;
1974 }
1975
1976 /**
1977 * Creates the language menu for FlexForms:
1978 *
1979 * @param [type] $languages: ...
1980 * @param [type] $elName: ...
1981 * @param [type] $selectedLanguage: ...
1982 * @param [type] $multi: ...
1983 * @return string HTML for menu
1984 */
1985 function getSingleField_typeFlex_langMenu($languages,$elName,$selectedLanguage,$multi=1) {
1986 $opt=array();
1987 foreach($languages as $lArr) {
1988 $opt[]='<option value="'.htmlspecialchars($lArr['ISOcode']).'"'.(in_array($lArr['ISOcode'],$selectedLanguage)?' selected="selected"':'').'>'.htmlspecialchars($lArr['title']).'</option>';
1989 }
1990
1991 $output = '<select name="'.$elName.'[]"'.($multi ? ' multiple="multiple" size="'.count($languages).'"' : '').'>'.implode('',$opt).'</select>';
1992
1993 return $output;
1994 }
1995
1996 /**
1997 * Creates the menu for selection of the sheets:
1998 *
1999 * @param array Sheet array for which to render the menu
2000 * @param string Form element name of the field containing the sheet pointer
2001 * @param string Current sheet key
2002 * @return string HTML for menu
2003 */
2004 function getSingleField_typeFlex_sheetMenu($sArr,$elName,$sheetKey) {
2005
2006 $tCells =array();
2007 $pct = round(100/count($sArr));
2008 foreach($sArr as $sKey => $sheetCfg) {
2009 $onClick = 'if (confirm('.$GLOBALS['LANG']->JScharCode($this->getLL('m_onChangeAlert')).') && TBE_EDITOR_checkSubmit(-1)){'.$this->elName($elName).".value='".$sKey."'; TBE_EDITOR_submitForm()};";
2010
2011 $tCells[]='<td width="'.$pct.'%" style="'.($sKey==$sheetKey ? 'background-color: #9999cc; font-weight: bold;' : 'background-color: #aaaaaa;').' cursor: hand;" onclick="'.htmlspecialchars($onClick).'" align="center">'.
2012 ($sheetCfg['ROOT']['TCEforms']['sheetTitle'] ? $this->sL($sheetCfg['ROOT']['TCEforms']['sheetTitle']) : $sKey).
2013 '</td>';
2014 }
2015
2016 return '<table border="0" cellpadding="0" cellspacing="2" class="typo3-TCEforms-flexForm-sheetMenu"><tr>'.implode('',$tCells).'</tr></table>';
2017 }
2018
2019 /**
2020 * [Describe function...]
2021 *
2022 * @param [type] $dataStruct: ...
2023 * @param [type] $editData: ...
2024 * @param [type] $cmdData: ...
2025 * @param [type] $table: ...
2026 * @param [type] $field: ...
2027 * @param [type] $row: ...
2028 * @param [type] $PA: ...
2029 * @param [type] $formPrefix: ...
2030 * @param [type] $level: ...
2031 * @param [type] $tRows: ...
2032 * @return [type] ...
2033 */
2034 function getSingleField_typeFlex_draw($dataStruct,$editData,$cmdData,$table,$field,$row,&$PA,$formPrefix='',$level=0,$tRows=array()) {
2035
2036 // Data Structure array must be ... and array of course...
2037 if (is_array($dataStruct)) {
2038 foreach($dataStruct as $key => $value) {
2039 if (is_array($value)) { // The value of each entry must be an array.
2040
2041 // ********************
2042 // Making the row:
2043 // ********************
2044 $rowCells=array();
2045
2046 // Icon:
2047 $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>';;
2048
2049 $rowCells['formEl']='';
2050 if ($value['type']=='array') {
2051 if ($value['section']) {
2052 // Render "NEW [container]" selectorbox:
2053 if (is_array($value['el'])) {
2054 $opt=array();
2055 $opt[]='<option value=""></option>';
2056 foreach($value['el'] as $kk => $vv) {
2057 $opt[]='<option value="'.$kk.'">'.htmlspecialchars('NEW "'.$value['el'][$kk]['tx_templavoila']['title'].'"').'</option>';
2058 }
2059 $rowCells['formEl']='<select name="flexFormsCmdData'.$formPrefix.'['.$key.'][value]">'.implode('',$opt).'</select>';
2060 }
2061
2062 // Put row together
2063 $tRows[]='<tr class="bgColor2">
2064 <td nowrap="nowrap" valign="top">'.$rowCells['title'].'</td>
2065 <td>'.$rowCells['formEl'].'</td>
2066 </tr>';
2067
2068 $cc=0;
2069 if (is_array($editData[$key]['el'])) {
2070 foreach($editData[$key]['el'] as $k3 => $v3) {
2071 $cc=$k3;
2072 $theType = key($v3);
2073 $theDat = $v3[$theType];
2074 $newSectionEl = $value['el'][$theType];
2075 if (is_array($newSectionEl)) {
2076 $tRows = $this->getSingleField_typeFlex_draw(
2077 array($theType => $newSectionEl),
2078 array($theType => $theDat),
2079 $cmdData[$key]['el'][$cc],
2080 $table,
2081 $field,
2082 $row,
2083 $PA,
2084 $formPrefix.'['.$key.'][el]['.$cc.']',
2085 $level+1,
2086 $tRows
2087 );
2088 }
2089 }
2090 }
2091
2092
2093
2094 // New form?
2095 if ($cmdData[$key]['value']) {
2096 $newSectionEl = $value['el'][$cmdData[$key]['value']];
2097 if (is_array($newSectionEl)) {
2098 $tRows = $this->getSingleField_typeFlex_draw(
2099 array($cmdData[$key]['value'] => $newSectionEl),
2100 array(),
2101 array(),
2102 $table,
2103 $field,
2104 $row,
2105 $PA,
2106 $formPrefix.'['.$key.'][el]['.($cc+1).']',
2107 $level+1,
2108 $tRows
2109 );
2110 }
2111 }
2112 } else {
2113 // Put row together
2114 $tRows[]='<tr class="bgColor2">
2115 <td nowrap="nowrap" valign="top">'.
2116 '<input name="_DELETE_FLEX_FORM'.$PA['itemFormElName'].$formPrefix.'" type="checkbox" value="1" /><img src="'.$this->backPath.'gfx/garbage.gif" border="0" alt="" />'.
2117 '<input name="_MOVEUP_FLEX_FORM'.$PA['itemFormElName'].$formPrefix.'" type="checkbox" value="1" /><img src="'.$this->backPath.'gfx/button_up.gif" border="0" alt="" />'.
2118 '<input name="_MOVEDOWN_FLEX_FORM'.$PA['itemFormElName'].$formPrefix.'" type="checkbox" value="1" /><img src="'.$this->backPath.'gfx/button_down.gif" border="0" alt="" />'.
2119 $rowCells['title'].'</td>
2120 <td>'.$rowCells['formEl'].'</td>
2121 </tr>';
2122
2123 $tRows = $this->getSingleField_typeFlex_draw(
2124 $value['el'],
2125 $editData[$key]['el'],
2126 $cmdData[$key]['el'],
2127 $table,
2128 $field,
2129 $row,
2130 $PA,
2131 $formPrefix.'['.$key.'][el]',
2132 $level+1,
2133 $tRows
2134 );
2135 }
2136
2137 } elseif (is_array($value['TCEforms']['config'])) { // Rendering a single form element:
2138
2139 if (is_array($PA['_valLang'])) {
2140 $rotateLang = $PA['_valLang'];
2141 } else {
2142 $rotateLang = array($PA['_valLang']);
2143 }
2144
2145 foreach($rotateLang as $vDEFkey) {
2146 $vDEFkey = 'v'.$vDEFkey;
2147
2148 $fakePA=array();
2149 $fakePA['fieldConf']=array(
2150 'label' => $this->sL($value['TCEforms']['label']),
2151 'config' => $value['TCEforms']['config'],
2152 'defaultExtras' => $value['TCEforms']['defaultExtras'],
2153 'displayCond' => $value['TCEforms']['displayCond'], // Haven't tested this...
2154 );
2155 $fakePA['fieldChangeFunc']=$PA['fieldChangeFunc'];
2156 $fakePA['onFocus']=$PA['onFocus'];
2157 $fakePA['label']==$PA['label'];
2158
2159 $fakePA['itemFormElName']=$PA['itemFormElName'].$formPrefix.'['.$key.']['.$vDEFkey.']';
2160 $fakePA['itemFormElName_file']=$PA['itemFormElName_file'].$formPrefix.'['.$key.']['.$vDEFkey.']';
2161 if(isset($editData[$key][$vDEFkey])) {
2162 $fakePA['itemFormElValue']=$editData[$key][$vDEFkey];
2163 }
2164 else {
2165 $fakePA['itemFormElValue']=$fakePA['fieldConf']['config']['default'];
2166 }
2167
2168 $rowCells['formEl']= $this->getSingleField_SW($table,$field,$row,$fakePA);
2169 $rowCells['title']= htmlspecialchars($fakePA['fieldConf']['label']);
2170
2171 // Put row together
2172 $tRows[]='<tr>
2173 <td nowrap="nowrap" valign="top" class="bgColor5">'.$rowCells['title'].($vDEFkey=='vDEF' ? '' : ' ('.$vDEFkey.')').'</td>
2174 <td class="bgColor4">'.$rowCells['formEl'].'</td>
2175 </tr>';
2176 }
2177 }
2178 }
2179 }
2180 }
2181
2182 return $tRows;
2183 }
2184
2185 /**
2186 * Handler for unknown types.
2187 *
2188 * @param string The table name of the record
2189 * @param string The field name which this element is supposed to edit
2190 * @param array The record data array where the value(s) for the field can be found
2191 * @param array An array with additional configuration options.
2192 * @return string The HTML code for the TCEform field
2193 */
2194 function getSingleField_typeUnknown($table,$field,$row,&$PA) {
2195 $item='Unknown type: '.$PA['fieldConf']['config']['form_type'].'<br />';
2196
2197 return $item;
2198 }
2199
2200 /**
2201 * User defined field type
2202 *
2203 * @param string The table name of the record
2204 * @param string The field name which this element is supposed to edit
2205 * @param array The record data array where the value(s) for the field can be found
2206 * @param array An array with additional configuration options.
2207 * @return string The HTML code for the TCEform field
2208 */
2209 function getSingleField_typeUser($table,$field,$row,&$PA) {
2210 $PA['table']=$table;
2211 $PA['field']=$field;
2212 $PA['row']=$row;
2213
2214 $PA['pObj']=&$this;
2215
2216 return t3lib_div::callUserFunction($PA['fieldConf']['config']['userFunc'],$PA,$this);
2217 }
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230 /************************************************************
2231 *
2232 * "Configuration" fetching/processing functions
2233 *
2234 ************************************************************/
2235
2236 /**
2237 * Calculate and return the current "types" pointer value for a record
2238 *
2239 * @param string The table name. MUST be in $TCA
2240 * @param array The row from the table, should contain at least the "type" field, if applicable.
2241 * @return string Return the "type" value for this record, ready to pick a "types" configuration from the $TCA array.
2242 */
2243 function getRTypeNum($table,$row) {
2244 global $TCA;
2245 // If there is a "type" field configured...
2246 if ($TCA[$table]['ctrl']['type']) {
2247 $typeFieldName = $TCA[$table]['ctrl']['type'];
2248 $typeNum=$row[$typeFieldName]; // Get value of the row from the record which contains the type value.
2249 if (!strcmp($typeNum,'')) $typeNum=0; // If that value is an empty string, set it to "0" (zero)
2250 } else {
2251 $typeNum = 0; // If no "type" field, then set to "0" (zero)
2252 }
2253
2254 $typeNum = (string)$typeNum; // Force to string. Necessary for eg '-1' to be recognized as a type value.
2255 if (!$TCA[$table]['types'][$typeNum]) { // However, if the type "0" is not found in the "types" array, then default to "1" (for historical reasons)
2256 $typeNum = 1;
2257 }
2258
2259 return $typeNum;
2260 }
2261
2262 /**
2263 * Used to adhoc-rearrange the field order normally set in the [types][showitem] list
2264 *
2265 * @param array A [types][showitem] list of fields, exploded by ","
2266 * @return array Returns rearranged version (keys are changed around as well.)
2267 * @see getMainFields()
2268 */
2269 function rearrange($fields) {
2270 $fO = array_flip(t3lib_div::trimExplode(',',$this->fieldOrder,1));
2271 reset($fields);
2272 $newFields=array();
2273 while(list($cc,$content)=each($fields)) {
2274 $cP = t3lib_div::trimExplode(';',$content);
2275 if (isset($fO[$cP[0]])) {
2276 $newFields[$fO[$cP[0]]] = $content;
2277 unset($fields[$cc]);
2278 }
2279 }
2280 ksort($newFields);
2281 $fields=array_merge($newFields,$fields); // Candidate for t3lib_div::array_merge() if integer-keys will some day make trouble...
2282 return $fields;
2283 }
2284
2285 /**
2286 * Producing an array of field names NOT to display in the form, based on settings from subtype_value_field, bitmask_excludelist_bits etc.
2287 * Notice, this list is in NO way related to the "excludeField" flag
2288 *
2289 * @param string Table name, MUST be in $TCA
2290 * @param array A record from table.
2291 * @param string A "type" pointer value, probably the one calculated based on the record array.
2292 * @return array Array with fieldnames as values. The fieldnames are those which should NOT be displayed "anyways"
2293 * @see getMainFields()
2294 */
2295 function getExcludeElements($table,$row,$typeNum) {
2296 global $TCA;
2297
2298 // Init:
2299 $excludeElements=array();
2300
2301 // If a subtype field is defined for the type
2302 if ($TCA[$table]['types'][$typeNum]['subtype_value_field']) {
2303 $sTfield = $TCA[$table]['types'][$typeNum]['subtype_value_field'];
2304 if (trim($TCA[$table]['types'][$typeNum]['subtypes_excludelist'][$row[$sTfield]])) {
2305 $excludeElements=t3lib_div::trimExplode(',',$TCA[$table]['types'][$typeNum]['subtypes_excludelist'][$row[$sTfield]],1);
2306 }
2307 }
2308
2309 // If a bitmask-value field has been configured, then find possible fields to exclude based on that:
2310 if ($TCA[$table]['types'][$typeNum]['bitmask_value_field']) {
2311 $sTfield = $TCA[$table]['types'][$typeNum]['bitmask_value_field'];
2312 $sTValue = t3lib_div::intInRange($row[$sTfield],0);
2313 if (is_array($TCA[$table]['types'][$typeNum]['bitmask_excludelist_bits'])) {
2314 reset($TCA[$table]['types'][$typeNum]['bitmask_excludelist_bits']);
2315 while(list($bitKey,$eList)=each($TCA[$table]['types'][$typeNum]['bitmask_excludelist_bits'])) {
2316 $bit=substr($bitKey,1);
2317 if (t3lib_div::testInt($bit)) {
2318 $bit = t3lib_div::intInRange($bit,0,30);
2319 if (
2320 (substr($bitKey,0,1)=='-' && !($sTValue&pow(2,$bit))) ||
2321 (substr($bitKey,0,1)=='+' && ($sTValue&pow(2,$bit)))
2322 ) {
2323 $excludeElements = array_merge($excludeElements,t3lib_div::trimExplode(',',$eList,1));
2324 }
2325 }
2326 }
2327 }
2328 }
2329
2330 // Return the array of elements:
2331 return $excludeElements;
2332 }
2333
2334 /**
2335 * Finds possible field to add to the form, based on subtype fields.
2336 *
2337 * @param string Table name, MUST be in $TCA
2338 * @param array A record from table.
2339 * @param string A "type" pointer value, probably the one calculated based on the record array.
2340 * @return array An array containing two values: 1) Another array containing fieldnames to add and 2) the subtype value field.
2341 * @see getMainFields()
2342 */
2343 function getFieldsToAdd($table,$row,$typeNum) {
2344 global $TCA;
2345
2346 // Init:
2347 $addElements=array();
2348
2349 // If a subtype field is defined for the type
2350 if ($TCA[$table]['types'][$typeNum]['subtype_value_field']) {
2351 $sTfield = $TCA[$table]['types'][$typeNum]['subtype_value_field'];
2352 if (trim($TCA[$table]['types'][$typeNum]['subtypes_addlist'][$row[$sTfield]])) {
2353 $addElements=t3lib_div::trimExplode(',',$TCA[$table]['types'][$typeNum]['subtypes_addlist'][$row[$sTfield]],1);
2354 }
2355 }
2356 // Return the return
2357 return array($addElements,$sTfield);
2358 }
2359
2360 /**
2361 * Merges the current [types][showitem] array with the array of fields to add for the current subtype field of the "type" value.
2362 *
2363 * @param array A [types][showitem] list of fields, exploded by ","
2364 * @param array The output from getFieldsToAdd()
2365 * @return array Return the modified $fields array.
2366 * @see getMainFields(),getFieldsToAdd()
2367 */
2368 function mergeFieldsWithAddedFields($fields,$fieldsToAdd) {
2369 if (count($fieldsToAdd[0])) {
2370 reset($fields);
2371 $c=0;
2372 while(list(,$fieldInfo)=each($fields)) {
2373 $parts = explode(';',$fieldInfo);
2374 if (!strcmp(trim($parts[0]),$fieldsToAdd[1])) {
2375 array_splice(
2376 $fields,
2377 $c+1,
2378 0,
2379 $fieldsToAdd[0]
2380 );
2381 break;
2382 }
2383 $c++;
2384 }
2385 }
2386 return $fields;
2387 }
2388
2389
2390 /**
2391 * Returns TSconfig for table/row
2392 * 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.
2393 *
2394 * @param string The table name
2395 * @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.)
2396 * @param string Optionally you can specify the field name as well. In that case the TSconfig for the field is returned.
2397 * @return mixed The TSconfig values (probably in an array)
2398 * @see t3lib_BEfunc::getTCEFORM_TSconfig()
2399 */
2400 function setTSconfig($table,$row,$field='') {
2401 $mainKey = $table.':'.$row['uid'];
2402 if (!isset($this->cachedTSconfig[$mainKey])) {
2403 $this->cachedTSconfig[$mainKey]=t3lib_BEfunc::getTCEFORM_TSconfig($table,$row);
2404 }
2405 if ($field) {
2406 return $this->cachedTSconfig[$mainKey][$field];
2407 } else {
2408 return $this->cachedTSconfig[$mainKey];
2409 }
2410 }
2411
2412 /**
2413 * Returns the "special" configuration (from the "types" "showitem" list) for a fieldname based on input table/record
2414 * (Not used anywhere...?)
2415 *
2416 * @param string The table name
2417 * @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.)
2418 * @param string Specify the field name.
2419 * @return array
2420 * @see getSpecConfFromString(), t3lib_BEfunc::getTCAtypes()
2421 */
2422 function getSpecConfForField($table,$row,$field) {
2423 // Finds the current "types" configuration for the table/row:
2424 $types_fieldConfig = t3lib_BEfunc::getTCAtypes($table,$row);
2425
2426 // If this is an array, then traverse it:
2427 if (is_array($types_fieldConfig)) {
2428 foreach($types_fieldConfig as $vconf) {
2429 // If the input field name matches one found in the 'types' list, then return the 'special' configuration.
2430 if ($vconf['field']==$field) return $vconf['spec'];
2431 }
2432 }
2433 }
2434
2435 /**
2436 * Returns the "special" configuration of an "extra" string (non-parsed)
2437 *
2438 * @param string The "Part 4" of the fields configuration in "types" "showitem" lists.
2439 * @param string The ['defaultExtras'] value from field configuration
2440 * @return array An array with the special options in.
2441 * @see getSpecConfForField(), t3lib_BEfunc::getSpecConfParts()
2442 */
2443 function getSpecConfFromString($extraString, $defaultExtras) {
2444 return t3lib_BEfunc::getSpecConfParts($extraString, $defaultExtras);
2445 }
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456 /************************************************************
2457 *
2458 * Display of localized content etc.
2459 *
2460 ************************************************************/
2461
2462 /**
2463 * Will register data from original language records if the current record is a translation of another.
2464 * 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.
2465 * Function called from outside (see alt_doc.php + quick edit) before rendering a form for a record
2466 *
2467 * @param string Table name of the record being edited
2468 * @param array Record array of the record being edited
2469 * @return void
2470 */
2471 function registerDefaultLanguageData($table,$rec) {
2472 global $TCA;
2473
2474 // Add default language:
2475 if ($TCA[$table]['ctrl']['languageField']
2476 && $rec[$TCA[$table]['ctrl']['languageField']] > 0
2477 && $TCA[$table]['ctrl']['transOrigPointerField']
2478 && intval($rec[$TCA[$table]['ctrl']['transOrigPointerField']]) > 0) {
2479
2480 $lookUpTable = $TCA[$table]['ctrl']['transOrigPointerTable'] ? $TCA[$table]['ctrl']['transOrigPointerTable'] : $table;
2481
2482 // Get data formatted:
2483 $this->defaultLanguageData[$table.':'.$rec['uid']] = t3lib_BEfunc::getRecord($lookUpTable, intval($rec[$TCA[$table]['ctrl']['transOrigPointerField']]));
2484
2485 // Get data for diff:
2486 if ($TCA[$table]['ctrl']['transOrigDiffSourceField']) {
2487 $this->defaultLanguageData_diff[$table.':'.$rec['uid']] = unserialize($rec[$TCA[$table]['ctrl']['transOrigDiffSourceField']]);
2488 }
2489 }
2490 }
2491
2492 /**
2493 * Renders the display of default language record content around current field.
2494 * Will render content if any is found in the internal array, $this->defaultLanguageData, depending on registerDefaultLanguageData() being called prior to this.
2495 *
2496 * @param string Table name of the record being edited
2497 * @param string Field name represented by $item
2498 * @param array Record array of the record being edited
2499 * @param string HTML of the form field. This is what we add the content to.
2500 * @return string Item string returned again, possibly with the original value added to.
2501 * @see getSingleField(), registerDefaultLanguageData()
2502 */
2503 function renderDefaultLanguageContent($table,$field,$row,$item) {
2504 if (is_array($this->defaultLanguageData[$table.':'.$row['uid']])) {
2505 $dLVal = t3lib_BEfunc::getProcessedValue($table,$field,$this->defaultLanguageData[$table.':'.$row['uid']][$field],0,1);
2506
2507 if (strcmp($dLVal,'')) {
2508 $item.='<div class="typo3-TCEforms-originalLanguageValue">'.nl2br(htmlspecialchars($dLVal)).'&nbsp;</div>';
2509 }
2510 }
2511
2512 return $item;
2513 }
2514
2515 /**
2516 * Renders the diff-view of default language record content compared with what the record was originally translated from.
2517 * Will render content if any is found in the internal array, $this->defaultLanguageData, depending on registerDefaultLanguageData() being called prior to this.
2518 *
2519 * @param string Table name of the record being edited
2520 * @param string Field name represented by $item
2521 * @param array Record array of the record being edited
2522 * @param string HTML of the form field. This is what we add the content to.
2523 * @return string Item string returned again, possibly with the original value added to.
2524 * @see getSingleField(), registerDefaultLanguageData()
2525 */
2526 function renderDefaultLanguageDiff($table,$field,$row,$item) {
2527 if (is_array($this->defaultLanguageData_diff[$table.':'.$row['uid']])) {
2528
2529 // Initialize:
2530 $dLVal = array(
2531 'old' => $this->defaultLanguageData_diff[$table.':'.$row['uid']],
2532 'new' => $this->defaultLanguageData[$table.':'.$row['uid']],
2533 );
2534
2535 if (isset($dLVal['old'][$field])) { // There must be diff-data:
2536 if (strcmp($dLVal['old'][$field],$dLVal['new'][$field])) {
2537
2538 // Create diff-result:
2539 $t3lib_diff_Obj = t3lib_div::makeInstance('t3lib_diff');
2540 $diffres = $t3lib_diff_Obj->makeDiffDisplay(
2541 t3lib_BEfunc::getProcessedValue($table,$field,$dLVal['old'][$field],0,1),
2542 t3lib_BEfunc::getProcessedValue($table,$field,$dLVal['new'][$field],0,1)
2543 );
2544
2545 $item.='<div class="typo3-TCEforms-diffBox">'.
2546 '<div class="typo3-TCEforms-diffBox-header">'.htmlspecialchars($this->getLL('l_changeInOrig')).':</div>'.
2547 $diffres.
2548 '</div>';
2549 }
2550 }
2551 }
2552
2553 return $item;
2554 }
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564 /************************************************************
2565 *
2566 * Form element helper functions
2567 *
2568 ************************************************************/
2569
2570 /**
2571 * Prints the selector box form-field for the db/file/select elements (multiple)
2572 *
2573 * @param string Form element name
2574 * @param string Mode "db", "file" (internal_type for the "group" type) OR blank (then for the "select" type)
2575 * @param string Commalist of "allowed"
2576 * @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.
2577 * @param string Alternative selector box.
2578 * @param array An array of additional parameters, eg: "size", "info", "headers" (array with "selector" and "items"), "noBrowser", "thumbnails"
2579 * @param string On focus attribute string
2580 * @return string The form fields for the selection.
2581 */
2582 function dbFileIcons($fName,$mode,$allowed,$itemArray,$selector='',$params=array(),$onFocus='') {
2583
2584 // Sets a flag which means some JavaScript is included on the page to support this element.
2585 $this->printNeededJS['dbFileIcons']=1;
2586
2587 // INIT
2588 $uidList=array();
2589 $opt=array();
2590 $itemArrayC=0;
2591
2592 // Creating <option> elements:
2593 if (is_array($itemArray)) {
2594 $itemArrayC=count($itemArray);
2595 reset($itemArray);
2596 switch($mode) {
2597 case 'db':
2598 while(list(,$pp)=each($itemArray)) {
2599 $pRec = t3lib_BEfunc::getRecord($pp['table'],$pp['id']);
2600 if (is_array($pRec)) {
2601 $pTitle = t3lib_div::fixed_lgd_cs($this->noTitle($pRec[$GLOBALS['TCA'][$pp['table']]['ctrl']['label']]),$this->titleLen);
2602 $pUid = $pp['table'].'_'.$pp['id'];
2603 $uidList[]=$pUid;
2604 $opt[]='<option value="'.htmlspecialchars($pUid).'">'.htmlspecialchars($pTitle).'</option>';
2605 }
2606 }
2607 break;
2608 case 'file':
2609 while(list(,$pp)=each($itemArray)) {
2610 $pParts = explode('|',$pp);
2611 $uidList[]=$pUid=$pTitle = $pParts[0];
2612 $opt[]='<option value="'.htmlspecialchars(rawurldecode($pParts[0])).'">'.htmlspecialchars(rawurldecode($pParts[0])).'</option>';
2613 }
2614 break;
2615 default:
2616 while(list(,$pp)=each($itemArray)) {
2617 $pParts = explode('|',$pp);
2618 $uidList[]=$pUid=$pParts[0];
2619 $pTitle = $pParts[1];
2620 $opt[]='<option value="'.htmlspecialchars(rawurldecode($pUid)).'">'.htmlspecialchars(rawurldecode($pTitle)).'</option>';
2621 }
2622 break;
2623 }
2624 }
2625
2626 // Create selector box of the options
2627 $sSize = $params['autoSizeMax'] ? t3lib_div::intInRange($itemArrayC+1,t3lib_div::intInRange($params['size'],1),$params['autoSizeMax']) : $params['size'];
2628 if (!$selector) {
2629 $selector = '<select size="'.$sSize.'"'.$this->insertDefStyle('group').' multiple="multiple" name="'.$fName.'_list" '.$onFocus.$params['style'].'>'.implode('',$opt).'</select>';
2630 }
2631
2632
2633 $icons = array(
2634 'L' => array(),
2635 'R' => array(),
2636 );
2637 if (!$params['noBrowser']) {
2638 $aOnClick='setFormValueOpenBrowser(\''.$mode.'\',\''.($fName.'|||'.$allowed.'|').'\'); return false;';
2639 $icons['R'][]='<a href="#" onclick="'.htmlspecialchars($aOnClick).'">'.
2640 '<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'))).' />'.
2641 '</a>';
2642 }
2643 if (!$params['dontShowMoveIcons']) {
2644 if ($sSize>=5) {
2645 $icons['L'][]='<a href="#" onclick="setFormValueManipulate(\''.$fName.'\',\'Top\'); return false;">'.
2646 '<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')).' />'.
2647 '</a>';
2648 }
2649 $icons['L'][]='<a href="#" onclick="setFormValueManipulate(\''.$fName.'\',\'Up\'); return false;">'.
2650 '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/up.gif','width="14" height="14"').' border="0" '.t3lib_BEfunc::titleAltAttrib($this->getLL('l_move_up')).' />'.
2651 '</a>';
2652 $icons['L'][]='<a href="#" onclick="setFormValueManipulate(\''.$fName.'\',\'Down\'); return false;">'.
2653 '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/down.gif','width="14" height="14"').' border="0" '.t3lib_BEfunc::titleAltAttrib($this->getLL('l_move_down')).' />'.
2654 '</a>';
2655 if ($sSize>=5) {
2656 $icons['L'][]='<a href="#" onclick="setFormValueManipulate(\''.$fName.'\',\'Bottom\'); return false;">'.
2657 '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/group_tobottom.gif','width="14" height="14"').' border="0" '.t3lib_BEfunc::titleAltAttrib($this->getLL('l_move_to_bottom')).' />'.
2658 '</a>';
2659 }
2660 }
2661
2662 $clipElements = $this->getClipboardElements($allowed,$mode);
2663 if (count($clipElements)) {
2664 $aOnClick = '';
2665 # $counter = 0;
2666 foreach($clipElements as $elValue) {
2667 if ($mode=='file') {
2668 $itemTitle = 'unescape(\''.rawurlencode(basename($elValue)).'\')';
2669 } else { // 'db' mode assumed
2670 list($itemTable,$itemUid) = explode('|', $elValue);
2671 $itemTitle = $GLOBALS['LANG']->JScharCode(t3lib_BEfunc::getRecordTitle($itemTable, t3lib_BEfunc::getRecord($itemTable,$itemUid)));
2672 $elValue = $itemTable.'_'.$itemUid;
2673 }
2674 $aOnClick.= 'setFormValueFromBrowseWin(\''.$fName.'\',unescape(\''.rawurlencode(str_replace('%20',' ',$elValue)).'\'),'.$itemTitle.');';
2675
2676 # $counter++;
2677 # if ($params['maxitems'] && $counter >= $params['maxitems']) { break; } // Makes sure that no more than the max items are inserted... for convenience.
2678 }
2679 $aOnClick.= 'return false;';
2680 $icons['R'][]='<a href="#" onclick="'.htmlspecialchars($aOnClick).'">'.
2681 '<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))).' />'.
2682 '</a>';
2683 }
2684
2685 $icons['L'][]='<a href="#" onclick="setFormValueManipulate(\''.$fName.'\',\'Remove\'); return false;">'.
2686 '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/group_clear.gif','width="14" height="14"').' border="0" '.t3lib_BEfunc::titleAltAttrib($this->getLL('l_remove_selected')).' />'.
2687 '</a>';
2688
2689 $str='<table border="0" cellpadding="0" cellspacing="0" width="1">
2690 '.($params['headers']?'
2691 <tr>
2692 <td>'.$this->wrapLabels($params['headers']['selector']).'</td>
2693 <td></td>
2694 <td></td>
2695 <td></td>
2696 <td>'.$this->wrapLabels($params['headers']['items']).'</td>
2697 </tr>':'').
2698 '
2699 <tr>
2700 <td valign="top">'.
2701 $selector.'<br />'.
2702 $this->wrapLabels($params['info']).
2703 '</td>
2704 <td valign="top">'.
2705 implode('<br />',$icons['L']).'</td>
2706 <td valign="top">'.
2707 implode('<br />',$icons['R']).'</td>
2708 <td><img src="clear.gif" width="5" height="1" alt="" /></td>
2709 <td valign="top">'.
2710 $this->wrapLabels($params['thumbnails']).
2711 '</td>
2712 </tr>
2713 </table>';
2714
2715 // Creating the hidden field which contains the actual value as a comma list.
2716 $str.='<input type="hidden" name="'.$fName.'" value="'.htmlspecialchars(implode(',',$uidList)).'" />';
2717
2718 return $str;
2719 }
2720
2721 /**
2722 * Returns array of elements from clipboard to insert into GROUP element box.
2723 *
2724 * @param string Allowed elements, Eg "pages,tt_content", "gif,jpg,jpeg,png"
2725 * @param string Mode of relations: "db" or "file"
2726 * @return array Array of elements in values (keys are insignificant), if none found, empty array.
2727 */
2728 function getClipboardElements($allowed,$mode) {
2729
2730 $output = array();
2731
2732 if (is_object($this->clipObj)) {
2733 switch($mode) {
2734 case 'file':
2735 $elFromTable = $this->clipObj->elFromTable('_FILE');
2736 $allowedExts = t3lib_div::trimExplode(',', $allowed, 1);
2737
2738 if ($allowedExts) { // If there are a set of allowed extensions, filter the content:
2739 foreach($elFromTable as $elValue) {
2740 $pI = pathinfo($elValue);
2741 $ext = strtolower($pI['extension']);
2742 if (in_array($ext, $allowedExts)) {
2743 $output[] = $elValue;
2744 }
2745 }
2746 } else { // If all is allowed, insert all: (This does NOT respect any disallowed extensions, but those will be filtered away by the backend TCEmain)
2747 $output = $elFromTable;
2748 }
2749 break;
2750 case 'db':
2751 $allowedTables = t3lib_div::trimExplode(',', $allowed, 1);
2752 if (!strcmp(trim($allowedTables[0]),'*')) { // All tables allowed for relation:
2753 $output = $this->clipObj->elFromTable('');
2754 } else { // Only some tables, filter them: