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