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