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