PageRenderTime 99ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/t3lib/class.t3lib_tceforms.php

https://bitbucket.org/linxpinx/mercurial
PHP | 6382 lines | 4001 code | 798 blank | 1583 comment | 708 complexity | a04d5f4bb8b3f1feefb1b0ecf4a536a7 MD5 | raw file
Possible License(s): BSD-3-Clause, GPL-2.0, Unlicense, LGPL-2.1, Apache-2.0
  1. <?php
  2. /***************************************************************
  3. * Copyright notice
  4. *
  5. * (c) 1999-2010 Kasper Skaarhoj (kasperYYYY@typo3.com)
  6. * All rights reserved
  7. *
  8. * This script is part of the TYPO3 project. The TYPO3 project is
  9. * free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * The GNU General Public License can be found at
  15. * http://www.gnu.org/copyleft/gpl.html.
  16. * A copy is found in the textfile GPL.txt and important notices to the license
  17. * from the author is found in LICENSE.txt distributed with these scripts.
  18. *
  19. *
  20. * This script is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU General Public License for more details.
  24. *
  25. * This copyright notice MUST APPEAR in all copies of the script!
  26. ***************************************************************/
  27. /**
  28. * Contains TYPO3 Core Form generator - AKA "TCEforms"
  29. *
  30. * $Id: class.t3lib_tceforms.php 8493 2010-08-05 18:45:15Z ohader $
  31. * Revised for TYPO3 3.6 August/2003 by Kasper Skaarhoj
  32. * XHTML compliant
  33. *
  34. * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
  35. */
  36. /**
  37. * [CLASS/FUNCTION INDEX of SCRIPT]
  38. *
  39. *
  40. *
  41. * 196: class t3lib_TCEforms
  42. * 302: function t3lib_TCEforms()
  43. * 338: function initDefaultBEmode()
  44. *
  45. * SECTION: Rendering the forms, fields etc
  46. * 385: function getSoloField($table,$row,$theFieldToReturn)
  47. * 424: function getMainFields($table,$row,$depth=0)
  48. * 618: function getListedFields($table,$row,$list)
  49. * 660: function getPaletteFields($table,$row,$palette,$header='',$itemList='',$collapsedHeader='')
  50. * 737: function getSingleField($table,$field,$row,$altName='',$palette=0,$extra='',$pal=0)
  51. * 900: function getSingleField_SW($table,$field,$row,&$PA)
  52. *
  53. * SECTION: Rendering of each TCEform field type
  54. * 976: function getSingleField_typeInput($table,$field,$row,&$PA)
  55. * 1057: function getSingleField_typeText($table,$field,$row,&$PA)
  56. * 1178: function getSingleField_typeCheck($table,$field,$row,&$PA)
  57. * 1244: function getSingleField_typeRadio($table,$field,$row,&$PA)
  58. * 1279: function getSingleField_typeSelect($table,$field,$row,&$PA)
  59. * 1359: function getSingleField_typeSelect_single($table,$field,$row,&$PA,$config,$selItems,$nMV_label)
  60. * 1490: function getSingleField_typeSelect_checkbox($table,$field,$row,&$PA,$config,$selItems,$nMV_label)
  61. * 1609: function getSingleField_typeSelect_singlebox($table,$field,$row,&$PA,$config,$selItems,$nMV_label)
  62. * 1719: function getSingleField_typeSelect_multiple($table,$field,$row,&$PA,$config,$selItems,$nMV_label)
  63. * 1823: function getSingleField_typeGroup($table,$field,$row,&$PA)
  64. * 1992: function getSingleField_typeNone($table,$field,$row,&$PA)
  65. * 2008: function getSingleField_typeNone_render($config,$itemValue)
  66. * 2070: function getSingleField_typeFlex($table,$field,$row,&$PA)
  67. * 2205: function getSingleField_typeFlex_langMenu($languages,$elName,$selectedLanguage,$multi=1)
  68. * 2224: function getSingleField_typeFlex_sheetMenu($sArr,$elName,$sheetKey)
  69. * 2259: function getSingleField_typeFlex_draw($dataStruct,$editData,$cmdData,$table,$field,$row,&$PA,$formPrefix='',$level=0,$tRows=array())
  70. * 2452: function getSingleField_typeUnknown($table,$field,$row,&$PA)
  71. * 2467: function getSingleField_typeUser($table,$field,$row,&$PA)
  72. *
  73. * SECTION: Field content processing
  74. * 2496: function formatValue ($config, $itemValue)
  75. *
  76. * SECTION: "Configuration" fetching/processing functions
  77. * 2588: function getRTypeNum($table,$row)
  78. * 2614: function rearrange($fields)
  79. * 2640: function getExcludeElements($table,$row,$typeNum)
  80. * 2688: function getFieldsToAdd($table,$row,$typeNum)
  81. * 2713: function mergeFieldsWithAddedFields($fields,$fieldsToAdd)
  82. * 2745: function setTSconfig($table,$row,$field='')
  83. * 2767: function getSpecConfForField($table,$row,$field)
  84. * 2788: function getSpecConfFromString($extraString, $defaultExtras)
  85. * 3007: function loadPaletteElements($table, $row, $palette, $itemList='')
  86. *
  87. * SECTION: Display of localized content etc.
  88. * 2816: function registerDefaultLanguageData($table,$rec)
  89. * 2848: function getLanguageOverlayRawValue($table, $row, $field, $fieldConf)
  90. * 2876: function renderDefaultLanguageContent($table,$field,$row,$item)
  91. * 2899: function renderDefaultLanguageDiff($table,$field,$row,$item)
  92. *
  93. * SECTION: Form element helper functions
  94. * 2955: function dbFileIcons($fName,$mode,$allowed,$itemArray,$selector='',$params=array(),$onFocus='')
  95. * 3108: function getClipboardElements($allowed,$mode)
  96. * 3157: function getClickMenu($str,$table,$uid='')
  97. * 3178: function renderWizards($itemKinds,$wizConf,$table,$row,$field,&$PA,$itemName,$specConf,$RTE=0)
  98. * 3382: function getIcon($icon)
  99. * 3409: function optionTagStyle($iconString)
  100. * 3425: function extractValuesOnlyFromValueLabelList($itemFormElValue)
  101. * 3447: function wrapOpenPalette($header,$table,$row,$palette,$retFunc=0)
  102. * 3471: function checkBoxParams($itemName,$thisValue,$c,$iCount,$addFunc='')
  103. * 3485: function elName($itemName)
  104. * 3496: function noTitle($str,$wrapParts=array())
  105. * 3505: function blur()
  106. * 3514: function thisReturnUrl()
  107. * 3527: function getSingleHiddenField($table,$field,$row)
  108. * 3549: function formWidth($size=48,$textarea=0)
  109. * 3576: function formWidthText($size=48,$wrap='')
  110. * 3592: function formElStyle($type)
  111. * 3603: function formElClass($type)
  112. * 3614: function formElStyleClassValue($type, $class=FALSE)
  113. * 3638: function insertDefStyle($type)
  114. * 3657: function getDynTabMenu($parts, $idString)
  115. *
  116. * SECTION: Item-array manipulation functions (check/select/radio)
  117. * 3696: function initItemArray($fieldValue)
  118. * 3714: function addItems($items,$iArray)
  119. * 3736: function procItems($items,$iArray,$config,$table,$row,$field)
  120. * 3760: function addSelectOptionsToItemArray($items,$fieldValue,$TSconfig,$field)
  121. * 3980: function addSelectOptionsToItemArray_makeModuleData($value)
  122. * 4002: function foreignTable($items,$fieldValue,$TSconfig,$field,$pFFlag=0)
  123. *
  124. * SECTION: Template functions
  125. * 4083: function setNewBEDesign()
  126. * 4138: function intoTemplate($inArr,$altTemplate='')
  127. * 4162: function addUserTemplateMarkers($marker,$table,$field,$row,&$PA)
  128. * 4173: function wrapLabels($str)
  129. * 4186: function wrapTotal($c,$rec,$table)
  130. * 4199: function replaceTableWrap($arr,$rec,$table)
  131. * 4236: function wrapBorder(&$out_array,&$out_pointer)
  132. * 4258: function rplColorScheme($inTemplate)
  133. * 4278: function getDivider()
  134. * 4288: function printPalette($palArr)
  135. * 4339: function helpTextIcon($table,$field,$force=0)
  136. * 4359: function helpText($table,$field)
  137. * 4380: function setColorScheme($scheme)
  138. * 4404: function resetSchemes()
  139. * 4415: function storeSchemes()
  140. * 4427: function restoreSchemes()
  141. *
  142. * SECTION: JavaScript related functions
  143. * 4457: function JStop()
  144. * 4508: function JSbottom($formname='forms[0]')
  145. * 4835: function dbFileCon($formObj='document.forms[0]')
  146. * 5053: function printNeededJSFunctions()
  147. * 5080: function printNeededJSFunctions_top()
  148. *
  149. * SECTION: Various helper functions
  150. * 5128: function getDefaultRecord($table,$pid=0)
  151. * 5167: function getRecordPath($table,$rec)
  152. * 5181: function readPerms()
  153. * 5195: function sL($str)
  154. * 5208: function getLL($str)
  155. * 5229: function isPalettesCollapsed($table,$palette)
  156. * 5245: function isDisplayCondition($displayCond,$row,$ffValueKey='')
  157. * 5349: function getTSCpid($table,$uid,$pid)
  158. * 5363: function doLoadTableDescr($table)
  159. * 5375: function getAvailableLanguages($onlyIsoCoded=1,$setDefault=1)
  160. *
  161. *
  162. * 5417: class t3lib_TCEforms_FE extends t3lib_TCEforms
  163. * 5425: function wrapLabels($str)
  164. * 5435: function printPalette($palArr)
  165. * 5460: function setFancyDesign()
  166. *
  167. * TOTAL FUNCTIONS: 100
  168. * (This index is automatically created/updated by the extension "extdeveval")
  169. *
  170. */
  171. /**
  172. * 'TCEforms' - Class for creating the backend editing forms.
  173. *
  174. * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
  175. * @coauthor Rene Fritz <r.fritz@colorcube.de>
  176. * @package TYPO3
  177. * @subpackage t3lib
  178. */
  179. class t3lib_TCEforms {
  180. // variables not commented yet.... (do so...)
  181. var $palFieldArr = array();
  182. var $disableWizards = 0;
  183. var $isPalettedoc = 0;
  184. var $paletteMargin = 1;
  185. var $defStyle = ''; // 'font-family:Verdana;font-size:10px;';
  186. var $cachedTSconfig = array();
  187. var $cachedTSconfig_fieldLevel = array();
  188. var $cachedLanguageFlag = array();
  189. var $cachedAdditionalPreviewLanguages = NULL;
  190. var $transformedRow = array();
  191. var $extJSCODE = '';
  192. var $printNeededJS = array();
  193. var $hiddenFieldAccum=array();
  194. var $TBE_EDITOR_fieldChanged_func='';
  195. var $loadMD5_JS=1;
  196. var $prevBorderStyle='[nothing here...]'; // Something unique...
  197. var $allowUpload=0; // If set direct upload fields will be shown
  198. var $titleLen=15; // @deprecated since TYPO3 4.1: $BE_USER->uc['titleLen'] but what is default??
  199. var $defaultLanguageData = array(); // Array where records in the default language is stored. (processed by transferdata)
  200. var $defaultLanguageData_diff = array(); // Array where records in the default language is stored (raw without any processing. used for making diff)
  201. var $additionalPreviewLanguageData = array();
  202. // EXTERNAL, static
  203. var $backPath=''; // Set this to the 'backPath' pointing back to the typo3 admin directory from the script where this form is displayed.
  204. var $returnUrl=''; // Alternative return URL path (default is t3lib_div::linkThisScript())
  205. var $doSaveFieldName=''; // Can be set to point to a field name in the form which will be set to '1' when the form is submitted with a *save* button. This way the recipient script can determine that the form was submitted for save and not "close" for example.
  206. 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.
  207. var $disableRTE=0; // If set, the RTE is disabled (from form display, eg. by checkbox in the bottom of the page!)
  208. var $globalShowHelp=1; // If false, then all CSH will be disabled, regardless of settings in $this->edit_showFieldHelp
  209. var $localizationMode=''; // If true, the forms are rendering only localization relevant fields of the records.
  210. 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.
  211. var $doPrintPalette=1; // If set to false, palettes will NEVER be rendered.
  212. /**
  213. * Set to initialized clipboard object; Then the element browser will offer a link to paste in records from clipboard.
  214. *
  215. * @var t3lib_clipboard
  216. */
  217. var $clipObj=FALSE;
  218. var $enableClickMenu=FALSE; // Enable click menu on reference icons.
  219. var $enableTabMenu = FALSE; // Enable Tab Menus. If set to true, the JavaScript content from template::getDynTabMenuJScode() must be included in the document.
  220. var $renderReadonly = FALSE; // When enabled all fields are rendered non-editable.
  221. 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)
  222. var $form_largeComp = 1.33; // Form field width compensation: Compensation for large documents, doc-tab (editing)
  223. 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.
  224. var $maxTextareaWidth=48; // The maximum abstract value for textareas
  225. var $maxInputWidth=48; // The maximum abstract value for input fields
  226. var $defaultMultipleSelectorStyle='width:250px;'; // Default style for the selector boxes used for multiple items in "select" and "group" types.
  227. // INTERNAL, static
  228. var $prependFormFieldNames = 'data'; // The string to prepend formfield names with.
  229. var $prependCmdFieldNames = 'cmd'; // The string to prepend commands for tcemain::process_cmdmap with.
  230. var $prependFormFieldNames_file = 'data_files'; // The string to prepend FILE form field names with.
  231. var $formName = 'editform'; // The name attribute of the form.
  232. var $allowOverrideMatrix = array(); // Whitelist that allows TCA field configuration to be overridden by TSconfig, @see overrideFieldConf()
  233. // INTERNAL, dynamic
  234. var $perms_clause=''; // Set by readPerms() (caching)
  235. var $perms_clause_set=0; // Set by readPerms() (caching-flag)
  236. 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).
  237. var $docLarge=0; // If set, the forms will be rendered a little wider, more precisely with a factor of $this->form_largeComp.
  238. var $clientInfo=array(); // Loaded with info about the browser when class is instantiated.
  239. var $RTEenabled=0; // True, if RTE is possible for the current user (based on result from BE_USER->isRTE())
  240. 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)
  241. var $RTEcounter = 0; // Counter that is incremented before an RTE is created. Can be used for unique ids etc.
  242. var $colorScheme; // Contains current color scheme
  243. var $classScheme; // Contains current class scheme
  244. var $defColorScheme; // Contains the default color scheme
  245. var $defClassScheme; // Contains the default class scheme
  246. var $fieldStyle; // Contains field style values
  247. var $borderStyle; // Contains border style values.
  248. var $commentMessages=array(); // An accumulation of messages from the class.
  249. // INTERNAL, templates
  250. var $totalWrap='<hr />|<hr />'; // Total wrapping for the table rows.
  251. var $fieldTemplate='<strong>###FIELD_NAME###</strong><br />###FIELD_ITEM###<hr />'; // Field template
  252. var $sectionWrap=''; // Wrapping template code for a section
  253. var $palFieldTemplateHeader=''; // Template for palette headers
  254. var $palFieldTemplate=''; // Template for palettes
  255. // INTERNAL, working memory
  256. var $excludeElements=''; // Set to the fields NOT to display, if any.
  257. 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)
  258. 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!
  259. 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.
  260. var $requiredAdditional=array(); // Used to register input-field names, which are required an have additional requirements (e.g. like a date/time must be positive integer). The information of this array is merged with $this->requiredFields later.
  261. var $requiredElements=array(); // Used to register the min and max number of elements for selectorboxes where that apply (in the "group" type for instance)
  262. var $requiredNested=array(); // Used to determine where $requiredFields or $requiredElements are nested (in Tabs or IRRE)
  263. var $renderDepth=0; // Keeps track of the rendering depth of nested records.
  264. var $savedSchemes=array(); // Color scheme buffer.
  265. var $dynNestedStack = array(); // holds the path an element is nested in (e.g. required for RTEhtmlarea)
  266. // Internal, registers for user defined functions etc.
  267. var $additionalCode_pre = array(); // Additional HTML code, printed before the form.
  268. var $additionalJS_pre = array(); // Additional JavaScript, printed before the form
  269. var $additionalJS_post = array(); // Additional JavaScript printed after the form
  270. var $additionalJS_submit = array(); // Additional JavaScript executed on submit; If you set "OK" variable it will raise an error about RTEs not being loaded and offer to block further submission.
  271. var $additionalJS_delete = array(); // Additional JavaScript executed when section element is deleted. This is neceessary, for example, to correctly clean up HTMLArea RTE (bug #8232)
  272. /**
  273. * Instance of t3lib_tceforms_inline
  274. *
  275. * @var t3lib_TCEforms_inline
  276. */
  277. var $inline;
  278. var $hookObjectsMainFields = array(); // Array containing hook class instances called once for a form
  279. var $hookObjectsSingleField = array(); // Array containing hook class instances called for each field
  280. var $extraFormHeaders = array(); // Rows gettings inserted into the alt_doc headers (when called from alt_doc.php)
  281. /**
  282. * Constructor function, setting internal variables, loading the styles used.
  283. *
  284. * @return void
  285. */
  286. function t3lib_TCEforms() {
  287. global $CLIENT, $TYPO3_CONF_VARS;
  288. $this->clientInfo = t3lib_div::clientInfo();
  289. $this->RTEenabled = $GLOBALS['BE_USER']->isRTE();
  290. if (!$this->RTEenabled) {
  291. $this->RTEenabled_notReasons = implode(LF,$GLOBALS['BE_USER']->RTE_errors);
  292. $this->commentMessages[] = 'RTE NOT ENABLED IN SYSTEM due to:'.LF.$this->RTEenabled_notReasons;
  293. }
  294. // Default color+class scheme
  295. $this->defColorScheme = array(
  296. $GLOBALS['SOBE']->doc->bgColor, // Background for the field AND palette
  297. t3lib_div::modifyHTMLColorAll($GLOBALS['SOBE']->doc->bgColor,-20), // Background for the field header
  298. t3lib_div::modifyHTMLColorAll($GLOBALS['SOBE']->doc->bgColor,-10), // Background for the palette field header
  299. 'black', // Field header font color
  300. '#666666' // Palette field header font color
  301. );
  302. $this->defColorScheme = array();
  303. // Override / Setting defaults from TBE_STYLES array
  304. $this->resetSchemes();
  305. // Setting the current colorScheme to default.
  306. $this->defColorScheme = $this->colorScheme;
  307. $this->defClassScheme = $this->classScheme;
  308. // Define whitelist that allows TCA field configuration to be overridden by TSconfig, @see overrideFieldConf():
  309. $this->allowOverrideMatrix = array(
  310. 'input' => array('size', 'max'),
  311. 'text' => array('cols', 'rows', 'wrap'),
  312. 'check' => array('cols', 'showIfRTE'),
  313. 'select' => array('size', 'autoSizeMax', 'maxitems', 'minitems'),
  314. 'group' => array('size', 'autoSizeMax', 'max_size', 'show_thumbs', 'maxitems', 'minitems', 'disable_controls'),
  315. 'inline' => array('appearance', 'behaviour', 'foreign_label', 'foreign_selector', 'foreign_unique', 'maxitems', 'minitems', 'size', 'autoSizeMax', 'symmetric_label'),
  316. );
  317. // Create instance of t3lib_TCEforms_inline only if this a non-IRRE-AJAX call:
  318. if (!isset($GLOBALS['ajaxID']) || strpos($GLOBALS['ajaxID'], 't3lib_TCEforms_inline::')!==0) {
  319. $this->inline = t3lib_div::makeInstance('t3lib_TCEforms_inline');
  320. }
  321. // Create instance of t3lib_TCEforms_suggest only if this a non-Suggest-AJAX call:
  322. if (!isset($GLOBALS['ajaxID']) || strpos($GLOBALS['ajaxID'], 't3lib_TCEforms_suggest::')!==0) {
  323. $this->suggest = t3lib_div::makeInstance('t3lib_TCEforms_suggest');
  324. }
  325. // Prepare user defined objects (if any) for hooks which extend this function:
  326. $this->hookObjectsMainFields = array();
  327. if (is_array ($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tceforms.php']['getMainFieldsClass'])) {
  328. foreach ($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tceforms.php']['getMainFieldsClass'] as $classRef) {
  329. $this->hookObjectsMainFields[] = t3lib_div::getUserObj($classRef);
  330. }
  331. }
  332. $this->hookObjectsSingleField = array();
  333. if (is_array ($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tceforms.php']['getSingleFieldClass'])) {
  334. foreach ($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tceforms.php']['getSingleFieldClass'] as $classRef) {
  335. $this->hookObjectsSingleField[] = t3lib_div::getUserObj($classRef);
  336. }
  337. }
  338. }
  339. /**
  340. * Initialize various internal variables.
  341. *
  342. * @return void
  343. */
  344. function initDefaultBEmode() {
  345. global $BE_USER;
  346. $this->prependFormFieldNames = 'data';
  347. $this->formName = 'editform';
  348. $this->setNewBEDesign();
  349. $this->docLarge = $BE_USER->uc['edit_wideDocument'] ? 1 : 0;
  350. $this->edit_showFieldHelp = $BE_USER->uc['edit_showFieldHelp'];
  351. $this->edit_docModuleUpload = $BE_USER->uc['edit_docModuleUpload'];
  352. $this->titleLen = $BE_USER->uc['titleLen']; // @deprecated since TYPO3 4.1
  353. $this->inline->init($this);
  354. $this->suggest->init($this);
  355. }
  356. /*******************************************************
  357. *
  358. * Rendering the forms, fields etc
  359. *
  360. *******************************************************/
  361. /**
  362. * Will return the TCEform element for just a single field from a record.
  363. * The field must be listed in the currently displayed fields (as found in [types][showitem]) for the record.
  364. * This also means that the $table/$row supplied must be complete so the list of fields to show can be found correctly
  365. *
  366. * @param string The table name
  367. * @param array The record from the table for which to render a field.
  368. * @param string The field name to return the TCEform element for.
  369. * @return string HTML output
  370. * @see getMainFields()
  371. */
  372. function getSoloField($table,$row,$theFieldToReturn) {
  373. global $TCA;
  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. foreach($fields as $fieldInfo) {
  383. $parts = explode(';',$fieldInfo);
  384. $theField = trim($parts[0]);
  385. if (!in_array($theField,$excludeElements) && !strcmp($theField,$theFieldToReturn)) {
  386. if ($TCA[$table]['columns'][$theField]) {
  387. $sField = $this->getSingleField($table,$theField,$row,$parts[1],1,$parts[3],$parts[2]);
  388. return $sField['ITEM'];
  389. }
  390. }
  391. }
  392. }
  393. }
  394. }
  395. }
  396. /**
  397. * Based on the $table and $row of content, this displays the complete TCEform for the record.
  398. * 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.
  399. *
  400. * @param string The table name
  401. * @param array The record from the table for which to render a field.
  402. * @param integer Depth level
  403. * @return string HTML output
  404. * @see getSoloField()
  405. */
  406. function getMainFields($table,$row,$depth=0) {
  407. global $TCA, $TYPO3_CONF_VARS;
  408. $this->renderDepth=$depth;
  409. // Init vars:
  410. $out_array = array(array());
  411. $out_array_meta = array(array(
  412. 'title' => $this->getLL('l_generalTab')
  413. ));
  414. $out_pointer=0;
  415. $out_sheet=0;
  416. $this->palettesRendered=array();
  417. $this->palettesRendered[$this->renderDepth][$table]=array();
  418. // Hook: getMainFields_preProcess (requested by Thomas Hempel for use with the "dynaflex" extension)
  419. foreach ($this->hookObjectsMainFields as $hookObj) {
  420. if (method_exists($hookObj,'getMainFields_preProcess')) {
  421. $hookObj->getMainFields_preProcess($table,$row,$this);
  422. }
  423. }
  424. if ($TCA[$table]) {
  425. // Load the full TCA for the table.
  426. t3lib_div::loadTCA($table);
  427. // Get dividers2tabs setting from TCA of the current table:
  428. $dividers2tabs =& $TCA[$table]['ctrl']['dividers2tabs'];
  429. // Load the description content for the table.
  430. if ($this->edit_showFieldHelp || $this->doLoadTableDescr($table)) {
  431. $GLOBALS['LANG']->loadSingleTableDescription($table);
  432. }
  433. // Get the current "type" value for the record.
  434. $typeNum = $this->getRTypeNum($table,$row);
  435. // Find the list of fields to display:
  436. if ($TCA[$table]['types'][$typeNum]) {
  437. $itemList = $TCA[$table]['types'][$typeNum]['showitem'];
  438. if ($itemList) { // If such a list existed...
  439. // Explode the field list and possibly rearrange the order of the fields, if configured for
  440. $fields = t3lib_div::trimExplode(',',$itemList,1);
  441. if ($this->fieldOrder) {
  442. $fields = $this->rearrange($fields);
  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. // If TCEforms will render a tab menu in the next step, push the name to the tab stack:
  448. $tabIdentString = '';
  449. $tabIdentStringMD5 = '';
  450. if (strstr($itemList, '--div--') !== false && $this->enableTabMenu && $dividers2tabs) {
  451. $tabIdentString = 'TCEforms:'.$table.':'.$row['uid'];
  452. $tabIdentStringMD5 = $GLOBALS['TBE_TEMPLATE']->getDynTabMenuId($tabIdentString);
  453. // Remember that were currently working on the general tab:
  454. if (isset($fields[0]) && strpos($fields[0], '--div--') !== 0) {
  455. $this->pushToDynNestedStack('tab', $tabIdentStringMD5.'-1');
  456. }
  457. }
  458. // Traverse the fields to render:
  459. $cc=0;
  460. foreach($fields as $fieldInfo) {
  461. // Exploding subparts of the field configuration:
  462. $parts = explode(';',$fieldInfo);
  463. // Getting the style information out:
  464. $color_style_parts = t3lib_div::trimExplode('-',$parts[4]);
  465. if (strcmp($color_style_parts[0],'')) {
  466. $this->setColorScheme($GLOBALS['TBE_STYLES']['colorschemes'][intval($color_style_parts[0])]);
  467. }
  468. if (strcmp($color_style_parts[1],'')) {
  469. $this->fieldStyle = $GLOBALS['TBE_STYLES']['styleschemes'][intval($color_style_parts[1])];
  470. if (!isset($this->fieldStyle)) $this->fieldStyle = $GLOBALS['TBE_STYLES']['styleschemes'][0];
  471. }
  472. if (strcmp($color_style_parts[2],'')) {
  473. $this->wrapBorder($out_array[$out_sheet],$out_pointer);
  474. $this->borderStyle = $GLOBALS['TBE_STYLES']['borderschemes'][intval($color_style_parts[2])];
  475. if (!isset($this->borderStyle)) $this->borderStyle = $GLOBALS['TBE_STYLES']['borderschemes'][0];
  476. }
  477. // Render the field:
  478. $theField = $parts[0];
  479. if (!in_array($theField,$excludeElements)) {
  480. if ($TCA[$table]['columns'][$theField]) {
  481. $sFieldPal='';
  482. if ($parts[2] && !isset($this->palettesRendered[$this->renderDepth][$table][$parts[2]])) {
  483. $sFieldPal=$this->getPaletteFields($table,$row,$parts[2]);
  484. $this->palettesRendered[$this->renderDepth][$table][$parts[2]] = 1;
  485. }
  486. $sField = $this->getSingleField($table,$theField,$row,$parts[1],0,$parts[3],$parts[2]);
  487. if ($sField) { $sField.= $sFieldPal; }
  488. $out_array[$out_sheet][$out_pointer].= $sField;
  489. } elseif ($theField=='--div--') {
  490. if ($cc>0) {
  491. $out_array[$out_sheet][$out_pointer].=$this->getDivider();
  492. if ($this->enableTabMenu && $dividers2tabs) {
  493. $this->wrapBorder($out_array[$out_sheet],$out_pointer);
  494. // Remove last tab entry from the dynNestedStack:
  495. $out_sheet++;
  496. // Remove the previous sheet from stack (if any):
  497. $this->popFromDynNestedStack('tab', $tabIdentStringMD5.'-'.($out_sheet));
  498. // Remember on which sheet we're currently working:
  499. $this->pushToDynNestedStack('tab', $tabIdentStringMD5.'-'.($out_sheet+1));
  500. $out_array[$out_sheet] = array();
  501. $out_array_meta[$out_sheet]['title'] = $this->sL($parts[1]);
  502. // Register newline for Tab
  503. $out_array_meta[$out_sheet]['newline'] = ($parts[2] == "newline");
  504. }
  505. } else { // Setting alternative title for "General" tab if "--div--" is the very first element.
  506. $out_array_meta[$out_sheet]['title'] = $this->sL($parts[1]);
  507. // Only add the first tab to the dynNestedStack if there are more tabs:
  508. if ($tabIdentString && strpos($itemList, '--div--', strlen($fieldInfo))) {
  509. $this->pushToDynNestedStack('tab', $tabIdentStringMD5.'-1');
  510. }
  511. }
  512. } elseif($theField=='--palette--') {
  513. if ($parts[2] && !isset($this->palettesRendered[$this->renderDepth][$table][$parts[2]])) {
  514. // render a 'header' if not collapsed
  515. if ($TCA[$table]['palettes'][$parts[2]]['canNotCollapse'] AND $parts[1]) {
  516. $out_array[$out_sheet][$out_pointer].=$this->getPaletteFields($table,$row,$parts[2],$this->sL($parts[1]));
  517. } else {
  518. $out_array[$out_sheet][$out_pointer].=$this->getPaletteFields($table,$row,$parts[2],'','',$this->sL($parts[1]));
  519. }
  520. $this->palettesRendered[$this->renderDepth][$table][$parts[2]] = 1;
  521. }
  522. }
  523. }
  524. $cc++;
  525. }
  526. }
  527. }
  528. }
  529. // Hook: getMainFields_postProcess (requested by Thomas Hempel for use with the "dynaflex" extension)
  530. foreach ($this->hookObjectsMainFields as $hookObj) {
  531. if (method_exists($hookObj,'getMainFields_postProcess')) {
  532. $hookObj->getMainFields_postProcess($table,$row,$this);
  533. }
  534. }
  535. // Wrapping a border around it all:
  536. $this->wrapBorder($out_array[$out_sheet],$out_pointer);
  537. // Resetting styles:
  538. $this->resetSchemes();
  539. // Rendering Main palettes, if any
  540. $mParr = t3lib_div::trimExplode(',',$TCA[$table]['ctrl']['mainpalette']);
  541. $i = 0;
  542. if (count($mParr)) {
  543. foreach ($mParr as $mP) {
  544. if (!isset($this->palettesRendered[$this->renderDepth][$table][$mP])) {
  545. $temp_palettesCollapsed=$this->palettesCollapsed;
  546. $this->palettesCollapsed=0;
  547. $label = ($i==0?$this->getLL('l_generalOptions'):$this->getLL('l_generalOptions_more'));
  548. $out_array[$out_sheet][$out_pointer].=$this->getPaletteFields($table,$row,$mP,$label);
  549. $this->palettesCollapsed=$temp_palettesCollapsed;
  550. $this->palettesRendered[$this->renderDepth][$table][$mP] = 1;
  551. }
  552. $this->wrapBorder($out_array[$out_sheet],$out_pointer);
  553. $i++;
  554. if ($this->renderDepth) {
  555. $this->renderDepth--;
  556. }
  557. }
  558. }
  559. // Return the imploded $out_array:
  560. if ($out_sheet>0) { // There were --div-- dividers around...
  561. // Create parts array for the tab menu:
  562. $parts = array();
  563. foreach ($out_array as $idx => $sheetContent) {
  564. $content = implode('', $sheetContent);
  565. if ($content) {
  566. // Wrap content (row) with table-tag, otherwise tab/sheet will be disabled (see getdynTabMenu() )
  567. $content = '<table border="0" cellspacing="0" cellpadding="0" width="100%">'.$content.'</table>';
  568. }
  569. $parts[$idx] = array(
  570. 'label' => $out_array_meta[$idx]['title'],
  571. 'content' => $content,
  572. 'newline' => $out_array_meta[$idx]['newline'], // Newline for this tab/sheet
  573. );
  574. }
  575. if (count($parts) > 1) {
  576. // Unset the current level of tab menus:
  577. $this->popFromDynNestedStack('tab', $tabIdentStringMD5.'-'.($out_sheet+1));
  578. $dividersToTabsBehaviour = (isset($TCA[$table]['ctrl']['dividers2tabs']) ? $TCA[$table]['ctrl']['dividers2tabs'] : 1);
  579. $output = $this->getDynTabMenu($parts, $tabIdentString, $dividersToTabsBehaviour);
  580. } else {
  581. // If there is only one tab/part there is no need to wrap it into the dynTab code
  582. $output = isset($parts[0]) ? trim($parts[0]['content']) : '';
  583. }
  584. $output = '
  585. <tr>
  586. <td colspan="2">
  587. '.$output.'
  588. </td>
  589. </tr>';
  590. } else {
  591. // Only one, so just implode:
  592. $output = implode('',$out_array[$out_sheet]);
  593. }
  594. return $output;
  595. }
  596. /**
  597. * Will return the TCEform elements for a pre-defined list of fields.
  598. * 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.
  599. * Used for displaying forms for the frontend edit icons for instance.
  600. *
  601. * @param string The table name
  602. * @param array The record array.
  603. * @param string Commalist of fields from the table. These will be shown in the specified order in a form.
  604. * @return string TCEform elements in a string.
  605. */
  606. function getListedFields($table,$row,$list) {
  607. global $TCA;
  608. t3lib_div::loadTCA($table);
  609. if ($this->edit_showFieldHelp || $this->doLoadTableDescr($table)) {
  610. $GLOBALS['LANG']->loadSingleTableDescription($table);
  611. }
  612. $out = '';
  613. $types_fieldConfig = t3lib_BEfunc::getTCAtypes($table,$row,1);
  614. $editFieldList=array_unique(t3lib_div::trimExplode(',',$list,1));
  615. foreach($editFieldList as $theFieldC) {
  616. list($theField,$palFields) = preg_split('/\[|\]/', $theFieldC);
  617. $theField = trim($theField);
  618. $palFields = trim($palFields);
  619. if ($TCA[$table]['columns'][$theField]) {
  620. $parts = t3lib_div::trimExplode(';',$types_fieldConfig[$theField]['origString']);
  621. $sField = $this->getSingleField($table,$theField,$row,$parts[1],0,$parts[3],0); // Don't sent palette pointer - there are no options anyways for a field-list.
  622. $out.= $sField;
  623. } elseif($theField=='--div--') {
  624. $out.= $this->getDivider();
  625. }
  626. if ($palFields) {
  627. $out.= $this->getPaletteFields($table,$row,'','',implode(',',t3lib_div::trimExplode('|',$palFields,1)));
  628. }
  629. }
  630. return $out;
  631. }
  632. /**
  633. * Creates a palette (collection of secondary options).
  634. *
  635. * @param string The table name
  636. * @param array The row array
  637. * @param string The palette number/pointer
  638. * @param string Header string for the palette (used when in-form). If not set, no header item is made.
  639. * @param string Optional alternative list of fields for the palette
  640. * @param string Optional Link text for activating a palette (when palettes does not have another form element to belong to).
  641. * @return string HTML code.
  642. */
  643. function getPaletteFields($table,$row,$palette,$header='',$itemList='',$collapsedHeader=NULL) {
  644. if (!$this->doPrintPalette) {
  645. return '';
  646. }
  647. $out = '';
  648. $parts = $this->loadPaletteElements($table, $row, $palette, $itemList);
  649. // Put palette together if there are fields in it:
  650. if (count($parts)) {
  651. if ($header) {
  652. $out .= $this->intoTemplate(
  653. array('HEADER' => htmlspecialchars($header)),
  654. $this->palFieldTemplateHeader
  655. );
  656. }
  657. $collapsed = $this->isPalettesCollapsed($table,$palette);
  658. $thePalIcon = '';
  659. if ($collapsed && $collapsedHeader !== NULL) {
  660. list($thePalIcon,) = $this->wrapOpenPalette(t3lib_iconWorks::getSpriteIcon('actions-system-options-view', array('title' => htmlspecialchars($this->getLL('l_moreOptions')))), $table, $row, $palette, 1);
  661. $thePalIcon = '<span style="margin-left: 20px;">' . $thePalIcon . $collapsedHeader . '</span>';
  662. }
  663. $paletteHtml = $this->wrapPaletteField($this->printPalette($parts), $table, $row ,$palette, $collapsed);
  664. $out .= $this->intoTemplate(
  665. array('PALETTE' => $thePalIcon . $paletteHtml),
  666. $this->palFieldTemplate
  667. );
  668. }
  669. return $out;
  670. }
  671. /**
  672. * Returns the form HTML code for a database table field.
  673. *
  674. * @param string The table name
  675. * @param string The field name
  676. * @param array The record to edit from the database table.
  677. * @param string Alternative field name label to show.
  678. * @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).
  679. * @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.
  680. * @param integer The palette pointer.
  681. * @return mixed String (normal) or array (palettes)
  682. */
  683. function getSingleField($table,$field,$row,$altName='',$palette=0,$extra='',$pal=0) {
  684. global $TCA,$BE_USER;
  685. // Hook: getSingleField_preProcess
  686. foreach ($this->hookObjectsSingleField as $hookObj) {
  687. if (method_exists($hookObj,'getSingleField_preProcess')) {
  688. $hookObj->getSingleField_preProcess($table, $field, $row, $altName, $palette, $extra, $pal, $this);
  689. }
  690. }
  691. $out = '';
  692. $PA = array();
  693. $PA['altName'] = $altName;
  694. $PA['palette'] = $palette;
  695. $PA['extra'] = $extra;
  696. $PA['pal'] = $pal;
  697. // Make sure to load full $TCA array for the table:
  698. t3lib_div::loadTCA($table);
  699. // Get the TCA configuration for the current field:
  700. $PA['fieldConf'] = $TCA[$table]['columns'][$field];
  701. $PA['fieldConf']['config']['form_type'] = $PA['fieldConf']['config']['form_type'] ? $PA['fieldConf']['config']['form_type'] : $PA['fieldConf']['config']['type']; // Using "form_type" locally in this script
  702. $skipThisField = $this->inline->skipField($table, $field, $row, $PA['fieldConf']['config']);
  703. // Now, check if this field is configured and editable (according to excludefields + other configuration)
  704. if ( is_array($PA['fieldConf']) &&
  705. !$skipThisField &&
  706. (!$PA['fieldConf']['exclude'] || $BE_USER->check('non_exclude_fields',$table.':'.$field)) &&
  707. $PA['fieldConf']['config']['form_type']!='passthrough' &&
  708. ($this->RTEenabled || !$PA['fieldConf']['config']['showIfRTE']) &&
  709. (!$PA['fieldConf']['displayCond'] || $this->isDisplayCondition($PA['fieldConf']['displayCond'],$row)) &&
  710. (!$TCA[$table]['ctrl']['languageField'] || $PA['fieldConf']['l10n_display'] || strcmp($PA['fieldConf']['l10n_mode'],'exclude') || $row[$TCA[$table]['ctrl']['languageField']]<=0) &&
  711. (!$TCA[$table]['ctrl']['languageField'] || !$this->localizationMode || $this->localizationMode===$PA['fieldConf']['l10n_cat'])
  712. ) {
  713. // Fetching the TSconfig for the current table/field. This includes the $row which means that
  714. $PA['fieldTSConfig'] = $this->setTSconfig($table,$row,$field);
  715. // If the field is NOT disabled from TSconfig (which it could have been) then render it
  716. if (!$PA['fieldTSConfig']['disabled']) {
  717. // Override fieldConf by fieldTSconfig:
  718. $PA['fieldConf']['config'] = $this->overrideFieldConf($PA['fieldConf']['config'], $PA['fieldTSConfig']);
  719. // Init variables:
  720. $PA['itemFormElName']=$this->prependFormFieldNames.'['.$table.']['.$row['uid'].']['.$field.']'; // Form field name
  721. $PA['itemFormElName_file']=$this->prependFormFieldNames_file.'['.$table.']['.$row['uid'].']['.$field.']'; // Form field name, in case of file uploads
  722. $PA['itemFormElValue']=$row[$field]; // The value to show in the form field.
  723. $PA['itemFormElID']=$this->prependFormFieldNames.'_'.$table.'_'.$row['uid'].'_'.$field;
  724. // set field to read-only if configured for translated records to show default language content as readonly
  725. if ($PA['fieldConf']['l10n_display'] && t3lib_div::inList($PA['fieldConf']['l10n_display'], 'defaultAsReadonly') && $row[$TCA[$table]['ctrl']['languageField']] > 0) {
  726. $PA['fieldConf']['config']['readOnly'] = true;
  727. $PA['itemFormElValue'] = $this->defaultLanguageData[$table.':'.$row['uid']][$field];
  728. }
  729. // 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"
  730. if (
  731. ($TCA[$table]['ctrl']['type'] && !strcmp($field,$TCA[$table]['ctrl']['type'])) ||
  732. ($TCA[$table]['ctrl']['requestUpdate'] && t3lib_div::inList($TCA[$table]['ctrl']['requestUpdate'],$field))) {
  733. if($GLOBALS['BE_USER']->jsConfirmation(1)) {
  734. $alertMsgOnChange = 'if (confirm(TBE_EDITOR.labels.onChangeAlert) && TBE_EDITOR.checkSubmit(-1)){ TBE_EDITOR.submitForm() };';
  735. } else {
  736. $alertMsgOnChange = 'if (TBE_EDITOR.checkSubmit(-1)){ TBE_EDITOR.submitForm() };';
  737. }
  738. } else {
  739. $alertMsgOnChange = '';
  740. }
  741. // Render as a hidden field?
  742. if (in_array($field,$this->hiddenFieldListArr)) {
  743. $this->hiddenFieldAccum[]='<input type="hidden" name="'.$PA['itemFormElName'].'" value="'.htmlspecialchars($PA['itemFormElValue']).'" />';
  744. } else { // Render as a normal field:
  745. // 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.
  746. if (!$PA['palette']) {
  747. $paletteFields = $this->loadPaletteElements($table, $row, $PA['pal']);
  748. if ($PA['pal'] && $this->isPalettesCollapsed($table,$PA['pal']) && count($paletteFields)) {
  749. list($thePalIcon,$palJSfunc) = $this->wrapOpenPalette(t3lib_iconWorks::getSpriteIcon('actions-system-options-view', array('title' => htmlspecialchars($this->getLL('l_moreOptions')))),$table,$row,$PA['pal'],1);
  750. } else {
  751. $thePalIcon = '';
  752. $palJSfunc = '';
  753. }
  754. }
  755. // onFocus attribute to add to the field:
  756. $PA['onFocus'] = ($palJSfunc && !$BE_USER->uc['dontShowPalettesOnFocusInAB']) ? ' onfocus="'.htmlspecialchars($palJSfunc).'"' : '';
  757. // Find item
  758. $item='';
  759. $PA['label'] = ($PA['altName'] ? $PA['altName'] : $PA['fieldConf']['label']);
  760. $PA['label'] = ($PA['fieldTSConfig']['label'] ? $PA['fieldTSConfig']['label'] : $PA['label']);
  761. $PA['label'] = ($PA['fieldTSConfig']['label.'][$GLOBALS['LANG']->lang] ? $PA['fieldTSConfig']['label.'][$GLOBALS['LANG']->lang] : $PA['label']);
  762. $PA['label'] = $this->sL($PA['label']);
  763. // JavaScript code for event handlers:
  764. $PA['fieldChangeFunc']=array();
  765. $PA['fieldChangeFunc']['TBE_EDITOR_fieldChanged'] = "TBE_EDITOR.fieldChanged('".$table."','".$row['uid']."','".$field."','".$PA['itemFormElName']."');";
  766. $PA['fieldChangeFunc']['alert']=$alertMsgOnChange;
  767. // if this is the child of an inline type and it is the field creating the label
  768. if ($this->inline->isInlineChildAndLabelField($table, $field)) {
  769. $inlineObjectId = implode(
  770. t3lib_TCEforms_inline::Structure_Separator,
  771. array(
  772. $this->inline->inlineNames['object'],
  773. $table,
  774. $row['uid']
  775. )
  776. );
  777. $PA['fieldChangeFunc']['inline'] = "inline.handleChangedField('" . $PA['itemFormElName'] . "','" . $inlineObjectId . "');";
  778. }
  779. // Based on the type of the item, call a render function:
  780. $item = $this->getSingleField_SW($table,$field,$row,$PA);
  781. // Add language + diff
  782. if ($PA['fieldConf']['l10n_display'] && (t3lib_div::inList($PA['fieldConf']['l10n_display'], 'hideDiff') || t3lib_div::inList($PA['fieldConf']['l10n_display'], 'defaultAsReadonly'))) {
  783. $renderLanguageDiff = false;
  784. } else {
  785. $renderLanguageDiff = true;
  786. }
  787. if ($renderLanguageDiff) {
  788. $item = $this->renderDefaultLanguageContent($table,$field,$row,$item);
  789. $item = $this->renderDefaultLanguageDiff($table,$field,$row,$item);
  790. }
  791. // 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
  792. $PA['label'] = t3lib_div::deHSCentities(htmlspecialchars($PA['label']));
  793. if (t3lib_div::testInt($row['uid']) && $PA['fieldTSConfig']['linkTitleToSelf'] && !t3lib_div::_GP('columnsOnly')) {
  794. $lTTS_url = $this->backPath.'alt_doc.php?edit['.$table.']['.$row['uid'].']=edit&columnsOnly='.$field.'&returnUrl='.rawurlencode($this->thisReturnUrl());
  795. $PA['label'] = '<a href="'.htmlspecialchars($lTTS_url).'">'.$PA['label'].'</a>';
  796. }
  797. // Create output value:
  798. if ($PA['fieldConf']['config']['form_type']=='user' && $PA['fieldConf']['config']['noTableWrapping']) {
  799. $out = $item;
  800. } elseif ($PA['palette']) {
  801. // Array:
  802. $out=array(
  803. 'NAME'=>$PA['label'],
  804. 'ID'=>$row['uid'],
  805. 'FIELD'=>$field,
  806. 'TABLE'=>$table,
  807. 'ITEM'=>$item,
  808. 'HELP_ICON' => $this->helpTextIcon($table,$field,1)
  809. );
  810. $out = $this->addUserTemplateMarkers($out,$table,$field,$row,$PA);
  811. } else {
  812. // String:
  813. $out=array(
  814. 'NAME'=>$PA['label'],
  815. 'ITEM'=>$item,
  816. 'TABLE'=>$table,
  817. 'ID'=>$row['uid'],
  818. 'HELP_ICON'=>$this->helpTextIcon($table,$field),
  819. 'HELP_TEXT'=>$this->helpText($table,$field),
  820. 'PAL_LINK_ICON'=>$thePalIcon,
  821. 'FIELD'=>$field
  822. );
  823. $out = $this->addUserTemplateMarkers($out,$table,$field,$row,$PA);
  824. // String:
  825. $out=$this->intoTemplate($out);
  826. }
  827. }
  828. } else $this->commentMessages[]=$this->prependFormFieldNames.'['.$table.']['.$row['uid'].']['.$field.']: Disabled by TSconfig';
  829. }
  830. // Hook: getSingleField_postProcess
  831. foreach ($this->hookObjectsSingleField as $hookObj) {
  832. if (method_exists($hookObj,'getSingleField_postProcess')) {
  833. $hookObj->getSingleField_postProcess($table, $field, $row, $out, $PA, $this);
  834. }
  835. }
  836. // Return value (string or array)
  837. return $out;
  838. }
  839. /**
  840. * Rendering a single item for the form
  841. *
  842. * @param string Table name of record
  843. * @param string Fieldname to render
  844. * @param array The record
  845. * @param array parameters array containing a lot of stuff. Value by Reference!
  846. * @return string Returns the item as HTML code to insert
  847. * @access private
  848. * @see getSingleField(), getSingleField_typeFlex_draw()
  849. */
  850. function getSingleField_SW($table,$field,$row,&$PA) {
  851. $PA['fieldConf']['config']['form_type'] = $PA['fieldConf']['config']['form_type'] ? $PA['fieldConf']['config']['form_type'] : $PA['fieldConf']['config']['type']; // Using "form_type" locally in this script
  852. // Hook: getSingleField_beforeRender
  853. foreach ($this->hookObjectsSingleField as $hookObject) {
  854. if (method_exists($hookObject, 'getSingleField_beforeRender')) {
  855. $hookObject->getSingleField_beforeRender($table, $field, $row, $PA);
  856. }
  857. }
  858. switch($PA['fieldConf']['config']['form_type']) {
  859. case 'input':
  860. $item = $this->getSingleField_typeInput($table,$field,$row,$PA);
  861. break;
  862. case 'text':
  863. $item = $this->getSingleField_typeText($table,$field,$row,$PA);
  864. break;
  865. case 'check':
  866. $item = $this->getSingleField_typeCheck($table,$field,$row,$PA);
  867. break;
  868. case 'radio':
  869. $item = $this->getSingleField_typeRadio($table,$field,$row,$PA);
  870. break;
  871. case 'select':
  872. $item = $this->getSingleField_typeSelect($table,$field,$row,$PA);
  873. break;
  874. case 'group':
  875. $item = $this->getSingleField_typeGroup($table,$field,$row,$PA);
  876. break;
  877. case 'inline':
  878. $item = $this->inline->getSingleField_typeInline($table,$field,$row,$PA);
  879. break;
  880. case 'none':
  881. $item = $this->getSingleField_typeNone($table,$field,$row,$PA);
  882. break;
  883. case 'user':
  884. $item = $this->getSingleField_typeUser($table,$field,$row,$PA);
  885. break;
  886. case 'flex':
  887. $item = $this->getSingleField_typeFlex($table,$field,$row,$PA);
  888. break;
  889. default:
  890. $item = $this->getSingleField_typeUnknown($table,$field,$row,$PA);
  891. break;
  892. }
  893. return $item;
  894. }
  895. /**********************************************************
  896. *
  897. * Rendering of each TCEform field type
  898. *
  899. ************************************************************/
  900. /**
  901. * Generation of TCEform elements of the type "input"
  902. * This will render a single-line input form field, possibly with various control/validation features
  903. *
  904. * @param string The table name of the record
  905. * @param string The field name which this element is supposed to edit
  906. * @param array The record data array where the value(s) for the field can be found
  907. * @param array An array with additional configuration options.
  908. * @return string The HTML code for the TCEform field
  909. */
  910. function getSingleField_typeInput($table,$field,$row,&$PA) {
  911. $config = $PA['fieldConf']['config'];
  912. $specConf = $this->getSpecConfFromString($PA['extra'], $PA['fieldConf']['defaultExtras']);
  913. $size = t3lib_div::intInRange($config['size']?$config['size']:30,5,$this->maxInputWidth);
  914. $evalList = t3lib_div::trimExplode(',',$config['eval'],1);
  915. $classAndStyleAttributes = $this->formWidthAsArray($size);
  916. $fieldAppendix = '';
  917. $cssClasses = array($classAndStyleAttributes['class']);
  918. $cssStyle = $classAndStyleAttributes['style'];
  919. // css class and id will show the kind of field
  920. if (in_array('date', $evalList)) {
  921. $inputId = uniqid('tceforms-datefield-');
  922. $cssClasses[] = 'tceforms-textfield tceforms-datefield';
  923. $fieldAppendix = t3lib_iconWorks::getSpriteIcon(
  924. 'actions-edit-pick-date',
  925. array(
  926. 'style' => 'cursor:pointer;',
  927. 'id' => 'picker-' . $inputId
  928. )
  929. );
  930. } elseif (in_array('datetime', $evalList)) {
  931. $inputId = uniqid('tceforms-datetimefield-');
  932. $cssClasses[] = 'tceforms-textfield tceforms-datetimefield';
  933. $fieldAppendix = t3lib_iconWorks::getSpriteIcon(
  934. 'actions-edit-pick-date',
  935. array(
  936. 'style' => 'cursor:pointer;',
  937. 'id' => 'picker-' . $inputId
  938. )
  939. );
  940. } elseif (in_array('timesec', $evalList)) {
  941. $inputId = uniqid('tceforms-timesecfield-');
  942. $cssClasses[] = 'tceforms-textfield tceforms-timesecfield';
  943. } elseif (in_array('year', $evalList)) {
  944. $inputId = uniqid('tceforms-yearfield-');
  945. $cssClasses[] = 'tceforms-textfield tceforms-yearfield';
  946. } elseif (in_array('time', $evalList)) {
  947. $inputId = uniqid('tceforms-timefield-');
  948. $cssClasses[] = 'tceforms-textfield tceforms-timefield';
  949. } elseif (in_array('int', $evalList)) {
  950. $inputId = uniqid('tceforms-intfield-');
  951. $cssClasses[] = 'tceforms-textfield tceforms-intfield';
  952. } elseif (in_array('double2', $evalList)) {
  953. $inputId = uniqid('tceforms-double2field-');
  954. $cssClasses[] = 'tceforms-textfield tceforms-double2field';
  955. } else {
  956. $inputId = uniqid('tceforms-textfield-');
  957. $cssClasses[] = 'tceforms-textfield';
  958. }
  959. if (isset($config['wizards']['link'])) {
  960. $inputId = uniqid('tceforms-linkfield-');
  961. $cssClasses[] = 'tceforms-textfield tceforms-linkfield';
  962. } elseif (isset($config['wizards']['color'])) {
  963. $inputId = uniqid('tceforms-colorfield-');
  964. $cssClasses[] = 'tceforms-textfield tceforms-colorfield';
  965. }
  966. if($this->renderReadonly || $config['readOnly']) {
  967. $itemFormElValue = $PA['itemFormElValue'];
  968. if (in_array('date',$evalList)) {
  969. $config['format'] = 'date';
  970. } elseif (in_array('datetime',$evalList)) {
  971. $config['format'] = 'datetime';
  972. } elseif (in_array('time',$evalList)) {
  973. $config['format'] = 'time';
  974. }
  975. if (in_array('password',$evalList)) {
  976. $itemFormElValue = $itemFormElValue ? '*********' : '';
  977. }
  978. return $this->getSingleField_typeNone_render($config, $itemFormElValue);
  979. }
  980. foreach ($evalList as $func) {
  981. switch ($func) {
  982. case 'required':
  983. $this->registerRequiredProperty('field', $table.'_'.$row['uid'].'_'.$field, $PA['itemFormElName']);
  984. // Mark this field for date/time disposal:
  985. if (array_intersect($evalList, array('date', 'datetime', 'time'))) {
  986. $this->requiredAdditional[$PA['itemFormElName']]['isPositiveNumber'] = true;
  987. }
  988. break;
  989. default:
  990. if (substr($func, 0, 3) == 'tx_') {
  991. // Pair hook to the one in t3lib_TCEmain::checkValue_input_Eval()
  992. $evalObj = t3lib_div::getUserObj($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tce']['formevals'][$func].':&'.$func);
  993. if (is_object($evalObj) && method_exists($evalObj, 'deevaluateFieldValue')) {
  994. $_params = array(
  995. 'value' => $PA['itemFormElValue']
  996. );
  997. $PA['itemFormElValue'] = $evalObj->deevaluateFieldValue($_params);
  998. }
  999. }
  1000. break;
  1001. }
  1002. }
  1003. $paramsList = "'".$PA['itemFormElName']."','".implode(',',$evalList)."','".trim($config['is_in'])."',".(isset($config['checkbox'])?1:0).",'".$config['checkbox']."'";
  1004. if (isset($config['checkbox'])) {
  1005. // Setting default "click-checkbox" values for eval types "date" and "datetime":
  1006. $thisMidnight = gmmktime(0,0,0);
  1007. if (in_array('date',$evalList)) {
  1008. $checkSetValue = $thisMidnight;
  1009. } elseif (in_array('datetime',$evalList)) {
  1010. $checkSetValue = $GLOBALS['EXEC_TIME'];
  1011. } elseif (in_array('year',$evalList)) {
  1012. $checkSetValue = gmdate('Y');
  1013. }
  1014. $cOnClick = 'typo3form.fieldGet('.$paramsList.',1,\''.$checkSetValue.'\');'.implode('',$PA['fieldChangeFunc']);
  1015. $item .= '<input type="checkbox" id="' . uniqid('tceforms-check-') . '" class="' . $this->formElStyleClassValue('check', TRUE) . '" name="' . $PA['itemFormElName'] . '_cb" onclick="' . htmlspecialchars($cOnClick) . '" />';
  1016. }
  1017. if ((in_array('date',$evalList) || in_array('datetime',$evalList)) && $PA['itemFormElValue']>0){
  1018. // Add server timezone offset to UTC to our stored date
  1019. $PA['itemFormElValue'] += date('Z', $PA['itemFormElValue']);
  1020. }
  1021. $PA['fieldChangeFunc'] = array_merge(array('typo3form.fieldGet'=>'typo3form.fieldGet('.$paramsList.');'), $PA['fieldChangeFunc']);
  1022. $mLgd = ($config['max']?$config['max']:256);
  1023. $iOnChange = implode('',$PA['fieldChangeFunc']);
  1024. $item.='<input type="text" id="' . $inputId . '" class="' . implode(' ', $cssClasses) . '" name="'.$PA['itemFormElName'].'_hr" value="" style="' . $cssStyle . '" maxlength="'.$mLgd.'" onchange="'.htmlspecialchars($iOnChange).'"'.$PA['onFocus'].' />'; // This is the EDITABLE form field.
  1025. $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.
  1026. $item .= $fieldAppendix;
  1027. $this->extJSCODE.='typo3form.fieldSet('.$paramsList.');';
  1028. // going through all custom evaluations configured for this field
  1029. foreach ($evalList as $evalData) {
  1030. if (substr($evalData, 0, 3) == 'tx_') {
  1031. $evalObj = t3lib_div::getUserObj($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tce']['formevals'][$evalData].':&'.$evalData);
  1032. if(is_object($evalObj) && method_exists($evalObj, 'returnFieldJS')) {
  1033. $this->extJSCODE .= "\n\nfunction ".$evalData."(value) {\n".$evalObj->returnFieldJS()."\n}\n";
  1034. }
  1035. }
  1036. }
  1037. // Creating an alternative item without the JavaScript handlers.
  1038. $altItem = '<input type="hidden" name="'.$PA['itemFormElName'].'_hr" value="" />';
  1039. $altItem.= '<input type="hidden" name="'.$PA['itemFormElName'].'" value="'.htmlspecialchars($PA['itemFormElValue']).'" />';
  1040. // Wrap a wizard around the item?
  1041. $item= $this->renderWizards(array($item,$altItem),$config['wizards'],$table,$row,$field,$PA,$PA['itemFormElName'].'_hr',$specConf);
  1042. return $item;
  1043. }
  1044. /**
  1045. * Generation of TCEform elements of the type "text"
  1046. * This will render a <textarea> OR RTE area form field, possibly with various control/validation features
  1047. *
  1048. * @param string The table name of the record
  1049. * @param string The field name which this element is supposed to edit
  1050. * @param array The record data array where the value(s) for the field can be found
  1051. * @param array An array with additional configuration options.
  1052. * @return string The HTML code for the TCEform field
  1053. */
  1054. function getSingleField_typeText($table,$field,$row,&$PA) {
  1055. // Init config:
  1056. $config = $PA['fieldConf']['config'];
  1057. $evalList = t3lib_div::trimExplode(',', $config['eval'], 1);
  1058. if($this->renderReadonly || $config['readOnly']) {
  1059. return $this->getSingleField_typeNone_render($config, $PA['itemFormElValue']);
  1060. }
  1061. // Setting columns number:
  1062. $cols = t3lib_div::intInRange($config['cols'] ? $config['cols'] : 30, 5, $this->maxTextareaWidth);
  1063. // Setting number of rows:
  1064. $origRows = $rows = t3lib_div::intInRange($config['rows'] ? $config['rows'] : 5, 1, 20);
  1065. if (strlen($PA['itemFormElValue']) > $this->charsPerRow*2) {
  1066. $cols = $this->maxTextareaWidth;
  1067. $rows = t3lib_div::intInRange(round(strlen($PA['itemFormElValue'])/$this->charsPerRow), count(explode(LF,$PA['itemFormElValue'])), 20);
  1068. if ($rows<$origRows) $rows = $origRows;
  1069. }
  1070. if (in_array('required', $evalList)) {
  1071. $this->requiredFields[$table . '_' . $row['uid'] . '_' . $field] = $PA['itemFormElName'];
  1072. }
  1073. // Init RTE vars:
  1074. $RTEwasLoaded = 0; // Set true, if the RTE is loaded; If not a normal textarea is shown.
  1075. $RTEwouldHaveBeenLoaded = 0; // Set true, if the RTE would have been loaded if it wasn't for the disable-RTE flag in the bottom of the page...
  1076. // "Extra" configuration; Returns configuration for the field based on settings found in the "types" fieldlist. Traditionally, this is where RTE configuration has been found.
  1077. $specConf = $this->getSpecConfFromString($PA['extra'], $PA['fieldConf']['defaultExtras']);
  1078. // Setting up the altItem form field, which is a hidden field containing the value
  1079. $altItem = '<input type="hidden" name="'.htmlspecialchars($PA['itemFormElName']).'" value="'.htmlspecialchars($PA['itemFormElValue']).'" />';
  1080. // If RTE is generally enabled (TYPO3_CONF_VARS and user settings)
  1081. if ($this->RTEenabled) {
  1082. $p = t3lib_BEfunc::getSpecConfParametersFromArray($specConf['rte_transform']['parameters']);
  1083. 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.
  1084. t3lib_BEfunc::fixVersioningPid($table,$row);
  1085. list($tscPID,$thePidValue) = $this->getTSCpid($table,$row['uid'],$row['pid']);
  1086. // If the pid-value is not negative (that is, a pid could NOT be fetched)
  1087. if ($thePidValue >= 0) {
  1088. $RTEsetup = $GLOBALS['BE_USER']->getTSConfig('RTE',t3lib_BEfunc::getPagesTSconfig($tscPID));
  1089. $RTEtypeVal = t3lib_BEfunc::getTCAtypeValue($table,$row);
  1090. $thisConfig = t3lib_BEfunc::RTEsetup($RTEsetup['properties'],$table,$field,$RTEtypeVal);
  1091. if (!$thisConfig['disabled']) {
  1092. if (!$this->disableRTE) {
  1093. $this->RTEcounter++;
  1094. // Find alternative relative path for RTE images/links:
  1095. $eFile = t3lib_parsehtml_proc::evalWriteFile($specConf['static_write'], $row);
  1096. $RTErelPath = is_array($eFile) ? dirname($eFile['relEditFile']) : '';
  1097. // Get RTE object, draw form and set flag:
  1098. $RTEobj = t3lib_BEfunc::RTEgetObj();
  1099. $item = $RTEobj->drawRTE($this,$table,$field,$row,$PA,$specConf,$thisConfig,$RTEtypeVal,$RTErelPath,$thePidValue);
  1100. // Wizard:
  1101. $item = $this->renderWizards(array($item,$altItem),$config['wizards'],$table,$row,$field,$PA,$PA['itemFormElName'],$specConf,1);
  1102. $RTEwasLoaded = 1;
  1103. } else {
  1104. $RTEwouldHaveBeenLoaded = 1;
  1105. $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!)';
  1106. }
  1107. } else $this->commentMessages[] = $PA['itemFormElName'].': RTE is disabled by the Page TSconfig, "RTE"-key (eg. by RTE.default.disabled=0 or such)';
  1108. } else $this->commentMessages[] = $PA['itemFormElName'].': PID value could NOT be fetched. Rare error, normally with new records.';
  1109. } else {
  1110. if (!isset($specConf['richtext'])) $this->commentMessages[] = $PA['itemFormElName'].': RTE was not configured for this field in TCA-types';
  1111. if (!(!$p['flag'] || !$row[$p['flag']])) $this->commentMessages[] = $PA['itemFormElName'].': Field-flag ('.$PA['flag'].') has been set to disable RTE!';
  1112. }
  1113. }
  1114. // Display ordinary field if RTE was not loaded.
  1115. if (!$RTEwasLoaded) {
  1116. if ($specConf['rte_only']) { // Show message, if no RTE (field can only be edited with RTE!)
  1117. $item = '<p><em>'.htmlspecialchars($this->getLL('l_noRTEfound')).'</em></p>';
  1118. } else {
  1119. if ($specConf['nowrap']) {
  1120. $wrap = 'off';
  1121. } else {
  1122. $wrap = ($config['wrap'] ? $config['wrap'] : 'virtual');
  1123. }
  1124. $classes = array();
  1125. if ($specConf['fixed-font']) { $classes[] = 'fixed-font'; }
  1126. if ($specConf['enable-tab']) { $classes[] = 'enable-tab'; }
  1127. $formWidthText = $this->formWidthText($cols,$wrap);
  1128. // Extract class attributes from $formWidthText (otherwise it would be added twice to the output)
  1129. $res = array();
  1130. if (preg_match('/ class="(.+?)"/',$formWidthText,$res)) {
  1131. $formWidthText = str_replace(' class="'.$res[1].'"','',$formWidthText);
  1132. $classes = array_merge($classes, explode(' ',$res[1]));
  1133. }
  1134. if (count($classes)) {
  1135. $class = ' class="tceforms-textarea '.implode(' ',$classes).'"';
  1136. } else $class='tceforms-textarea';
  1137. $evalList = t3lib_div::trimExplode(',',$config['eval'],1);
  1138. foreach ($evalList as $func) {
  1139. switch ($func) {
  1140. case 'required':
  1141. $this->registerRequiredProperty('field', $table.'_'.$row['uid'].'_'.$field, $PA['itemFormElName']);
  1142. break;
  1143. default:
  1144. if (substr($func, 0, 3) == 'tx_') {
  1145. // Pair hook to the one in t3lib_TCEmain::checkValue_input_Eval() and t3lib_TCEmain::checkValue_text_Eval()
  1146. $evalObj = t3lib_div::getUserObj($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tce']['formevals'][$func].':&'.$func);
  1147. if (is_object($evalObj) && method_exists($evalObj, 'deevaluateFieldValue')) {
  1148. $_params = array(
  1149. 'value' => $PA['itemFormElValue']
  1150. );
  1151. $PA['itemFormElValue'] = $evalObj->deevaluateFieldValue($_params);
  1152. }
  1153. }
  1154. break;
  1155. }
  1156. }
  1157. $iOnChange = implode('',$PA['fieldChangeFunc']);
  1158. $item.= '
  1159. <textarea id="' . uniqid('tceforms-textarea-') . '" name="'.$PA['itemFormElName'].'"'.$formWidthText.$class.' rows="'.$rows.'" wrap="'.$wrap.'" onchange="'.htmlspecialchars($iOnChange).'"'.$PA['onFocus'].'>'.
  1160. t3lib_div::formatForTextarea($PA['itemFormElValue']).
  1161. '</textarea>';
  1162. $item = $this->renderWizards(array($item,$altItem),$config['wizards'],$table,$row,$field,$PA,$PA['itemFormElName'],$specConf,$RTEwouldHaveBeenLoaded);
  1163. }
  1164. }
  1165. // Return field HTML:
  1166. return $item;
  1167. }
  1168. /**
  1169. * Generation of TCEform elements of the type "check"
  1170. * This will render a check-box OR an array of checkboxes
  1171. *
  1172. * @param string The table name of the record
  1173. * @param string The field name which this element is supposed to edit
  1174. * @param array The record data array where the value(s) for the field can be found
  1175. * @param array An array with additional configuration options.
  1176. * @return string The HTML code for the TCEform field
  1177. */
  1178. function getSingleField_typeCheck($table,$field,$row,&$PA) {
  1179. $config = $PA['fieldConf']['config'];
  1180. $disabled = '';
  1181. if($this->renderReadonly || $config['readOnly']) {
  1182. $disabled = ' disabled="disabled"';
  1183. }
  1184. // Traversing the array of items:
  1185. $selItems = $this->initItemArray($PA['fieldConf']);
  1186. if ($config['itemsProcFunc']) $selItems = $this->procItems($selItems,$PA['fieldTSConfig']['itemsProcFunc.'],$config,$table,$row,$field);
  1187. if (!count($selItems)) {
  1188. $selItems[]=array('','');
  1189. }
  1190. $thisValue = intval($PA['itemFormElValue']);
  1191. $cols = intval($config['cols']);
  1192. if ($cols > 1) {
  1193. $item.= '<table border="0" cellspacing="0" cellpadding="0" class="typo3-TCEforms-checkboxArray">';
  1194. for ($c=0;$c<count($selItems);$c++) {
  1195. $p = $selItems[$c];
  1196. if(!($c%$cols)) { $item.='<tr>'; }
  1197. $cBP = $this->checkBoxParams($PA['itemFormElName'],$thisValue,$c,count($selItems),implode('',$PA['fieldChangeFunc']));
  1198. $cBName = $PA['itemFormElName'].'_'.$c;
  1199. $cBID = $PA['itemFormElID'].'_'.$c;
  1200. $item.= '<td nowrap="nowrap">'.
  1201. '<input type="checkbox"'.$this->insertDefStyle('check').' value="1" name="'.$cBName.'"'.$cBP.$disabled.' id="'.$cBID.'" />'.
  1202. $this->wrapLabels('<label for="'.$cBID.'">'.htmlspecialchars($p[0]).'</label>&nbsp;').
  1203. '</td>';
  1204. if(($c%$cols)+1==$cols) {$item.='</tr>';}
  1205. }
  1206. if ($c%$cols) {
  1207. $rest=$cols-($c%$cols);
  1208. for ($c=0;$c<$rest;$c++) {
  1209. $item.= '<td></td>';
  1210. }
  1211. if ($c>0) { $item.= '</tr>'; }
  1212. }
  1213. $item.= '</table>';
  1214. } else {
  1215. for ($c=0;$c<count($selItems);$c++) {
  1216. $p = $selItems[$c];
  1217. $cBP = $this->checkBoxParams($PA['itemFormElName'],$thisValue,$c,count($selItems),implode('',$PA['fieldChangeFunc']));
  1218. $cBName = $PA['itemFormElName'].'_'.$c;
  1219. $cBID = $PA['itemFormElID'].'_'.$c;
  1220. $item.= ($c>0?'<br />':'').
  1221. '<input type="checkbox"'.$this->insertDefStyle('check').' value="1" name="'.$cBName.'"'.$cBP.$PA['onFocus'].$disabled.' id="'.$cBID.'" />'.
  1222. $this->wrapLabels('<label for="'.$cBID.'">'.htmlspecialchars($p[0]).'</label>');
  1223. }
  1224. }
  1225. if (!$disabled) {
  1226. $item.= '<input type="hidden" name="'.$PA['itemFormElName'].'" value="'.htmlspecialchars($thisValue).'" />';
  1227. }
  1228. return $item;
  1229. }
  1230. /**
  1231. * Generation of TCEform elements of the type "radio"
  1232. * This will render a series of radio buttons.
  1233. *
  1234. * @param string The table name of the record
  1235. * @param string The field name which this element is supposed to edit
  1236. * @param array The record data array where the value(s) for the field can be found
  1237. * @param array An array with additional configuration options.
  1238. * @return string The HTML code for the TCEform field
  1239. */
  1240. function getSingleField_typeRadio($table,$field,$row,&$PA) {
  1241. $config = $PA['fieldConf']['config'];
  1242. $disabled = '';
  1243. if($this->renderReadonly || $config['readOnly']) {
  1244. $disabled = ' disabled="disabled"';
  1245. }
  1246. // Get items for the array:
  1247. $selItems = $this->initItemArray($PA['fieldConf']);
  1248. if ($config['itemsProcFunc']) $selItems = $this->procItems($selItems,$PA['fieldTSConfig']['itemsProcFunc.'],$config,$table,$row,$field);
  1249. // Traverse the items, making the form elements:
  1250. for ($c=0;$c<count($selItems);$c++) {
  1251. $p = $selItems[$c];
  1252. $rID = $PA['itemFormElID'].'_'.$c;
  1253. $rOnClick = implode('',$PA['fieldChangeFunc']);
  1254. $rChecked = (!strcmp($p[1],$PA['itemFormElValue'])?' checked="checked"':'');
  1255. $item.= '<input type="radio"'.$this->insertDefStyle('radio').' name="'.$PA['itemFormElName'].'" value="'.htmlspecialchars($p[1]).'" onclick="'.htmlspecialchars($rOnClick).'"'.$rChecked.$PA['onFocus'].$disabled.' id="'.$rID.'" />
  1256. <label for="'.$rID.'">'.htmlspecialchars($p[0]).'</label>
  1257. <br />';
  1258. }
  1259. return $item;
  1260. }
  1261. /**
  1262. * Generation of TCEform elements of the type "select"
  1263. * This will render a selector box element, or possibly a special construction with two selector boxes. That depends on configuration.
  1264. *
  1265. * @param string The table name of the record
  1266. * @param string The field name which this element is supposed to edit
  1267. * @param array The record data array where the value(s) for the field can be found
  1268. * @param array An array with additional configuration options.
  1269. * @return string The HTML code for the TCEform field
  1270. */
  1271. function getSingleField_typeSelect($table,$field,$row,&$PA) {
  1272. global $TCA;
  1273. // Field configuration from TCA:
  1274. $config = $PA['fieldConf']['config'];
  1275. $disabled = '';
  1276. if($this->renderReadonly || $config['readOnly']) {
  1277. $disabled = ' disabled="disabled"';
  1278. }
  1279. // "Extra" configuration; Returns configuration for the field based on settings found in the "types" fieldlist. See http://typo3.org/documentation/document-library/doc_core_api/Wizards_Configuratio/.
  1280. $specConf = $this->getSpecConfFromString($PA['extra'], $PA['fieldConf']['defaultExtras']);
  1281. // Getting the selector box items from the system
  1282. $selItems = $this->addSelectOptionsToItemArray(
  1283. $this->initItemArray($PA['fieldConf']),
  1284. $PA['fieldConf'],
  1285. $this->setTSconfig($table, $row),
  1286. $field
  1287. );
  1288. // Possibly filter some items:
  1289. $keepItemsFunc = create_function('$value', 'return $value[1];');
  1290. $selItems = t3lib_div::keepItemsInArray($selItems, $PA['fieldTSConfig']['keepItems'], $keepItemsFunc);
  1291. // Possibly add some items:
  1292. $selItems = $this->addItems($selItems, $PA['fieldTSConfig']['addItems.']);
  1293. // Process items by a user function:
  1294. if (isset($config['itemsProcFunc']) && $config['itemsProcFunc']) {
  1295. $selItems = $this->procItems($selItems, $PA['fieldTSConfig']['itemsProcFunc.'], $config, $table, $row, $field);
  1296. }
  1297. // Possibly remove some items:
  1298. $removeItems = t3lib_div::trimExplode(',',$PA['fieldTSConfig']['removeItems'],1);
  1299. foreach($selItems as $tk => $p) {
  1300. // Checking languages and authMode:
  1301. $languageDeny = $TCA[$table]['ctrl']['languageField'] && !strcmp($TCA[$table]['ctrl']['languageField'], $field) && !$GLOBALS['BE_USER']->checkLanguageAccess($p[1]);
  1302. $authModeDeny = $config['form_type']=='select' && $config['authMode'] && !$GLOBALS['BE_USER']->checkAuthMode($table,$field,$p[1],$config['authMode']);
  1303. if (in_array($p[1],$removeItems) || $languageDeny || $authModeDeny) {
  1304. unset($selItems[$tk]);
  1305. } elseif (isset($PA['fieldTSConfig']['altLabels.'][$p[1]])) {
  1306. $selItems[$tk][0]=$this->sL($PA['fieldTSConfig']['altLabels.'][$p[1]]);
  1307. }
  1308. // Removing doktypes with no access:
  1309. if ($table.'.'.$field == 'pages.doktype') {
  1310. if (!($GLOBALS['BE_USER']->isAdmin() || t3lib_div::inList($GLOBALS['BE_USER']->groupData['pagetypes_select'],$p[1]))) {
  1311. unset($selItems[$tk]);
  1312. }
  1313. }
  1314. }
  1315. // Creating the label for the "No Matching Value" entry.
  1316. $nMV_label = isset($PA['fieldTSConfig']['noMatchingValue_label']) ? $this->sL($PA['fieldTSConfig']['noMatchingValue_label']) : '[ '.$this->getLL('l_noMatchingValue').' ]';
  1317. // Prepare some values:
  1318. $maxitems = intval($config['maxitems']);
  1319. // If a SINGLE selector box...
  1320. if ($maxitems<=1) {
  1321. $item = $this->getSingleField_typeSelect_single($table,$field,$row,$PA,$config,$selItems,$nMV_label);
  1322. } elseif (!strcmp($config['renderMode'],'checkbox')) { // Checkbox renderMode
  1323. $item = $this->getSingleField_typeSelect_checkbox($table,$field,$row,$PA,$config,$selItems,$nMV_label);
  1324. } elseif (!strcmp($config['renderMode'],'singlebox')) { // Single selector box renderMode
  1325. $item = $this->getSingleField_typeSelect_singlebox($table,$field,$row,$PA,$config,$selItems,$nMV_label);
  1326. } else { // Traditional multiple selector box:
  1327. $item = $this->getSingleField_typeSelect_multiple($table,$field,$row,$PA,$config,$selItems,$nMV_label);
  1328. }
  1329. // Wizards:
  1330. if (!$disabled) {
  1331. $altItem = '<input type="hidden" name="'.$PA['itemFormElName'].'" value="'.htmlspecialchars($PA['itemFormElValue']).'" />';
  1332. $item = $this->renderWizards(array($item,$altItem),$config['wizards'],$table,$row,$field,$PA,$PA['itemFormElName'],$specConf);
  1333. }
  1334. return $item;
  1335. }
  1336. /**
  1337. * Creates a single-selector box
  1338. * (Render function for getSingleField_typeSelect())
  1339. *
  1340. * @param string See getSingleField_typeSelect()
  1341. * @param string See getSingleField_typeSelect()
  1342. * @param array See getSingleField_typeSelect()
  1343. * @param array See getSingleField_typeSelect()
  1344. * @param array (Redundant) content of $PA['fieldConf']['config'] (for convenience)
  1345. * @param array Items available for selection
  1346. * @param string Label for no-matching-value
  1347. * @return string The HTML code for the item
  1348. * @see getSingleField_typeSelect()
  1349. */
  1350. function getSingleField_typeSelect_single($table,$field,$row,&$PA,$config,$selItems,$nMV_label) {
  1351. // check against inline uniqueness
  1352. $inlineParent = $this->inline->getStructureLevel(-1);
  1353. if(is_array($inlineParent) && $inlineParent['uid']) {
  1354. if ($inlineParent['config']['foreign_table'] == $table && $inlineParent['config']['foreign_unique'] == $field) {
  1355. $uniqueIds = $this->inline->inlineData['unique'][$this->inline->inlineNames['object'].'['.$table.']']['used'];
  1356. $PA['fieldChangeFunc']['inlineUnique'] = "inline.updateUnique(this,'".$this->inline->inlineNames['object'].'['.$table."]','".$this->inline->inlineNames['form']."','".$row['uid']."');";
  1357. }
  1358. // hide uid of parent record for symmetric relations
  1359. if ($inlineParent['config']['foreign_table'] == $table && ($inlineParent['config']['foreign_field'] == $field || $inlineParent['config']['symmetric_field'] == $field)) {
  1360. $uniqueIds[] = $inlineParent['uid'];
  1361. }
  1362. }
  1363. // Initialization:
  1364. $c = 0;
  1365. $sI = 0;
  1366. $noMatchingValue = 1;
  1367. $opt = array();
  1368. $selicons = array();
  1369. $onlySelectedIconShown = 0;
  1370. $size = intval($config['size']);
  1371. $selectedStyle = ''; // Style set on <select/>
  1372. $disabled = '';
  1373. if($this->renderReadonly || $config['readOnly']) {
  1374. $disabled = ' disabled="disabled"';
  1375. $onlySelectedIconShown = 1;
  1376. }
  1377. // Icon configuration:
  1378. if ($config['suppress_icons']=='IF_VALUE_FALSE') {
  1379. $suppressIcons = !$PA['itemFormElValue'] ? 1 : 0;
  1380. } elseif ($config['suppress_icons']=='ONLY_SELECTED') {
  1381. $suppressIcons=0;
  1382. $onlySelectedIconShown=1;
  1383. } elseif ($config['suppress_icons']) {
  1384. $suppressIcons = 1;
  1385. } else $suppressIcons = 0;
  1386. // Traverse the Array of selector box items:
  1387. $optGroupStart = array();
  1388. $optGroupOpen = FALSE;
  1389. foreach($selItems as $p) {
  1390. $sM = (!strcmp($PA['itemFormElValue'],$p[1])?' selected="selected"':'');
  1391. if ($sM) {
  1392. $sI = $c;
  1393. $noMatchingValue = 0;
  1394. }
  1395. // Getting style attribute value (for icons):
  1396. if ($config['iconsInOptionTags']) {
  1397. $styleAttrValue = $this->optionTagStyle($p[2]);
  1398. if ($sM) {
  1399. list($selectIconFile,$selectIconInfo) = $this->getIcon($p[2]);
  1400. if (!empty($selectIconInfo)) {
  1401. $selectedStyle = ' style="background: #fff url(' . $selectIconFile . ') 0% 50% no-repeat; padding: 1px 1px 1px 24px; -webkit-background-size: 0;"';
  1402. }
  1403. }
  1404. }
  1405. // Compiling the <option> tag:
  1406. if (!($p[1] != $PA['itemFormElValue'] && is_array($uniqueIds) && in_array($p[1], $uniqueIds))) {
  1407. if(!strcmp($p[1],'--div--')) {
  1408. $optGroupStart[0] = $p[0];
  1409. $optGroupStart[1] = $styleAttrValue;
  1410. } else {
  1411. if (count($optGroupStart)) {
  1412. if($optGroupOpen) { // Closing last optgroup before next one starts
  1413. $opt[]='</optgroup>' . LF;
  1414. }
  1415. $opt[]= '<optgroup label="'.t3lib_div::deHSCentities(htmlspecialchars($optGroupStart[0])).'"'.
  1416. ($optGroupStart[1] ? ' style="'.htmlspecialchars($optGroupStart[1]).'"' : '').
  1417. ' class="c-divider">' . LF;
  1418. $optGroupOpen = true;
  1419. $c--;
  1420. $optGroupStart = array();
  1421. }
  1422. $opt[]= '<option value="'.htmlspecialchars($p[1]).'"'.
  1423. $sM.
  1424. ($styleAttrValue ? ' style="'.htmlspecialchars($styleAttrValue).'"' : '').
  1425. '>' . t3lib_div::deHSCentities(($p[0])) . '</option>' . LF;
  1426. }
  1427. }
  1428. // If there is an icon for the selector box (rendered in table under)...:
  1429. if ($p[2] && !$suppressIcons && (!$onlySelectedIconShown || $sM)) {
  1430. list($selIconFile,$selIconInfo)=$this->getIcon($p[2]);
  1431. $iOnClick = $this->elName($PA['itemFormElName']) . '.selectedIndex=' . $c . '; ' .
  1432. $this->elName($PA['itemFormElName']) . '.style.backgroundImage=' . $this->elName($PA['itemFormElName']) . '.options[' . $c .'].style.backgroundImage; ' .
  1433. implode('',$PA['fieldChangeFunc']).$this->blur().'return false;';
  1434. $selicons[]=array(
  1435. (!$onlySelectedIconShown ? '<a href="#" onclick="'.htmlspecialchars($iOnClick).'">' : '').
  1436. '<img src="'.$selIconFile.'" '.$selIconInfo[3].' vspace="2" border="0" title="'.htmlspecialchars($p[0]).'" alt="'.htmlspecialchars($p[0]).'" />'.
  1437. (!$onlySelectedIconShown ? '</a>' : ''),
  1438. $c,$sM);
  1439. $onChangeIcon = 'this.style.backgroundImage=this.options[this.selectedIndex].style.backgroundImage;';
  1440. }
  1441. $c++;
  1442. }
  1443. if($optGroupOpen) { // Closing optgroup if open
  1444. $opt[]='</optgroup>';
  1445. $optGroupOpen = false;
  1446. }
  1447. // No-matching-value:
  1448. if ($PA['itemFormElValue'] && $noMatchingValue && !$PA['fieldTSConfig']['disableNoMatchingValueElement'] && !$config['disableNoMatchingValueElement']) {
  1449. $nMV_label = @sprintf($nMV_label, $PA['itemFormElValue']);
  1450. $opt[]= '<option value="'.htmlspecialchars($PA['itemFormElValue']).'" selected="selected">'.htmlspecialchars($nMV_label).'</option>';
  1451. }
  1452. // Create item form fields:
  1453. $sOnChange = 'if (this.options[this.selectedIndex].value==\'--div--\') {this.selectedIndex='.$sI.';} '.implode('',$PA['fieldChangeFunc']);
  1454. if(!$disabled) {
  1455. $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...
  1456. }
  1457. $item .= '<select' . $selectedStyle . ' id="' . uniqid('tceforms-select-') . '" name="' . $PA['itemFormElName'] . '"' .
  1458. ($config['iconsInOptionTags'] ? $this->insertDefStyle('select', 'icon-select') : $this->insertDefStyle('select')) .
  1459. ($size ? ' size="' . $size . '"' : '') .
  1460. ' onchange="' . htmlspecialchars($onChangeIcon . $sOnChange) . '"' .
  1461. $PA['onFocus'] . $disabled . '>';
  1462. $item.= implode('',$opt);
  1463. $item.= '</select>';
  1464. // Create icon table:
  1465. if (count($selicons) && !$config['noIconsBelowSelect']) {
  1466. $item.='<table border="0" cellpadding="0" cellspacing="0" class="typo3-TCEforms-selectIcons">';
  1467. $selicon_cols = intval($config['selicon_cols']);
  1468. if (!$selicon_cols) $selicon_cols=count($selicons);
  1469. $sR = ceil(count($selicons)/$selicon_cols);
  1470. $selicons = array_pad($selicons,$sR*$selicon_cols,'');
  1471. for($sa=0;$sa<$sR;$sa++) {
  1472. $item.='<tr>';
  1473. for($sb=0;$sb<$selicon_cols;$sb++) {
  1474. $sk=($sa*$selicon_cols+$sb);
  1475. $imgN = 'selIcon_'.$table.'_'.$row['uid'].'_'.$field.'_'.$selicons[$sk][1];
  1476. $imgS = ($selicons[$sk][2]?$this->backPath.'gfx/content_selected.gif':'clear.gif');
  1477. $item.='<td><img name="'.htmlspecialchars($imgN).'" src="'.$imgS.'" width="7" height="10" alt="" /></td>';
  1478. $item.='<td>'.$selicons[$sk][0].'</td>';
  1479. }
  1480. $item.='</tr>';
  1481. }
  1482. $item.='</table>';
  1483. }
  1484. return $item;
  1485. }
  1486. /**
  1487. * Creates a checkbox list (renderMode = "checkbox")
  1488. * (Render function for getSingleField_typeSelect())
  1489. *
  1490. * @param string See getSingleField_typeSelect()
  1491. * @param string See getSingleField_typeSelect()
  1492. * @param array See getSingleField_typeSelect()
  1493. * @param array See getSingleField_typeSelect()
  1494. * @param array (Redundant) content of $PA['fieldConf']['config'] (for convenience)
  1495. * @param array Items available for selection
  1496. * @param string Label for no-matching-value
  1497. * @return string The HTML code for the item
  1498. * @see getSingleField_typeSelect()
  1499. */
  1500. function getSingleField_typeSelect_checkbox($table,$field,$row,&$PA,$config,$selItems,$nMV_label) {
  1501. // Get values in an array (and make unique, which is fine because there can be no duplicates anyway):
  1502. $itemArray = array_flip($this->extractValuesOnlyFromValueLabelList($PA['itemFormElValue']));
  1503. $disabled = '';
  1504. if($this->renderReadonly || $config['readOnly']) {
  1505. $disabled = ' disabled="disabled"';
  1506. }
  1507. // Traverse the Array of selector box items:
  1508. $tRows = array();
  1509. $c=0;
  1510. if (!$disabled) {
  1511. $sOnChange = implode('',$PA['fieldChangeFunc']);
  1512. $setAll = array(); // Used to accumulate the JS needed to restore the original selection.
  1513. $unSetAll = array();
  1514. foreach($selItems as $p) {
  1515. // Non-selectable element:
  1516. if (!strcmp($p[1],'--div--')) {
  1517. if (count($setAll)) {
  1518. $tRows[] = '
  1519. <tr class="c-header-checkbox-controls">
  1520. <td colspan="3">' .
  1521. '<a href="#" onclick="' . htmlspecialchars(implode('', $setAll).' return false;') . '">' .
  1522. htmlspecialchars($this->getLL('l_checkAll')) .
  1523. '</a>
  1524. <a href="#" onclick="' . htmlspecialchars(implode('', $unSetAll).' return false;').'">' .
  1525. htmlspecialchars($this->getLL('l_uncheckAll')) .
  1526. '</a>
  1527. </td>
  1528. </tr>';
  1529. $setAll = array();
  1530. $unSetAll = array();
  1531. }
  1532. $tRows[] = '
  1533. <tr class="c-header">
  1534. <td colspan="3">'.htmlspecialchars($p[0]).'</td>
  1535. </tr>';
  1536. } else {
  1537. // Selected or not by default:
  1538. $sM = '';
  1539. if (isset($itemArray[$p[1]])) {
  1540. $sM = ' checked="checked"';
  1541. unset($itemArray[$p[1]]);
  1542. }
  1543. // Icon:
  1544. $selIconFile = '';
  1545. if ($p[2]) {
  1546. list($selIconFile,$selIconInfo) = $this->getIcon($p[2]);
  1547. }
  1548. // Compile row:
  1549. $rowId = uniqid('select_checkbox_row_');
  1550. $onClickCell = $this->elName($PA['itemFormElName'] . '[' . $c . ']') . '.checked=!' . $this->elName($PA['itemFormElName'] . '[' . $c . ']') . '.checked;';
  1551. $onClick = 'this.attributes.getNamedItem("class").nodeValue = ' . $this->elName($PA['itemFormElName'] . '[' . $c . ']') . '.checked ? "c-selectedItem" : "c-unselectedItem";';
  1552. $setAll[] = $this->elName($PA['itemFormElName'] . '[' . $c . ']') . '.checked=1;';
  1553. $setAll[] .= '$(\'' . $rowId . '\').removeClassName(\'c-unselectedItem\');$(\'' . $rowId . '\').addClassName(\'c-selectedItem\');';
  1554. $unSetAll[] = $this->elName($PA['itemFormElName'].'['.$c.']').'.checked=0;';
  1555. $unSetAll[] .= '$(\'' . $rowId . '\').removeClassName(\'c-selectedItem\');$(\'' . $rowId . '\').addClassName(\'c-unselectedItem\');';
  1556. $restoreCmd[] = $this->elName($PA['itemFormElName'] . '[' . $c . ']') . '.checked=' . ($sM ? 1 : 0) . ';' .
  1557. '$(\'' . $rowId . '\').removeClassName(\'c-selectedItem\');$(\'' . $rowId . '\').removeClassName(\'c-unselectedItem\');' .
  1558. '$(\'' . $rowId . '\').addClassName(\'c-' . ($sM ? '' : 'un') . 'selectedItem\');';
  1559. $hasHelp = ($p[3] !='');
  1560. $label = t3lib_div::deHSCentities(htmlspecialchars($p[0]));
  1561. $help = $hasHelp ? '<span class="typo3-csh-inline show-right"><span class="header">' . $label . '</span>' .
  1562. '<span class="paragraph">' . $GLOBALS['LANG']->hscAndCharConv(nl2br(trim(htmlspecialchars($p[3]))), false) . '</span></span>' : '';
  1563. if ($hasHelp && $this->edit_showFieldHelp == 'icon') {
  1564. $helpIcon = '<a class="typo3-csh-link" href="#">';
  1565. $helpIcon .= t3lib_iconWorks::getSpriteIcon('actions-system-help-open');
  1566. $helpIcon .= $help;
  1567. $helpIcon .= '</a>';
  1568. $help = $helpIcon;
  1569. }
  1570. $tRows[] = '
  1571. <tr id="' . $rowId . '" class="'.($sM ? 'c-selectedItem' : 'c-unselectedItem').'" onclick="'.htmlspecialchars($onClick).'" style="cursor: pointer;">
  1572. <td width="12"><input type="checkbox"'.$this->insertDefStyle('check').' name="'.htmlspecialchars($PA['itemFormElName'].'['.$c.']').'" value="'.htmlspecialchars($p[1]).'"'.$sM.' onclick="'.htmlspecialchars($sOnChange).'"'.$PA['onFocus'].' /></td>
  1573. <td class="c-labelCell" onclick="'.htmlspecialchars($onClickCell).'">'.
  1574. ($selIconFile ? '<img src="'.$selIconFile.'" '.$selIconInfo[3].' vspace="2" border="0" class="absmiddle" style="margin-right: 4px;" alt="" />' : '').
  1575. $label .
  1576. '</td>
  1577. <td class="c-descr" onclick="'.htmlspecialchars($onClickCell).'">' . (strcmp($p[3],'') ? $help : '') . '</td>
  1578. </tr>';
  1579. $c++;
  1580. }
  1581. }
  1582. // Remaining checkboxes will get their set-all link:
  1583. if (count($setAll)) {
  1584. $tRows[] = '
  1585. <tr class="c-header-checkbox-controls">
  1586. <td colspan="3">'.
  1587. '<a href="#" onclick="' . htmlspecialchars(implode('', $setAll).' return false;') . '">' .
  1588. htmlspecialchars($this->getLL('l_checkAll')) .
  1589. '</a>
  1590. <a href="#" onclick="' . htmlspecialchars(implode('', $unSetAll).' return false;') . '">' .
  1591. htmlspecialchars($this->getLL('l_uncheckAll')) .
  1592. '</a>
  1593. </td>
  1594. </tr>';
  1595. }
  1596. }
  1597. // Remaining values (invalid):
  1598. if (count($itemArray) && !$PA['fieldTSConfig']['disableNoMatchingValueElement'] && !$config['disableNoMatchingValueElement']) {
  1599. foreach($itemArray as $theNoMatchValue => $temp) {
  1600. // Compile <checkboxes> tag:
  1601. array_unshift($tRows,'
  1602. <tr class="c-invalidItem">
  1603. <td><input type="checkbox"'.$this->insertDefStyle('check').' name="'.htmlspecialchars($PA['itemFormElName'].'['.$c.']').'" value="'.htmlspecialchars($theNoMatchValue).'" checked="checked" onclick="'.htmlspecialchars($sOnChange).'"'.$PA['onFocus'].$disabled.' /></td>
  1604. <td class="c-labelCell">'.
  1605. t3lib_div::deHSCentities(htmlspecialchars(@sprintf($nMV_label, $theNoMatchValue))).
  1606. '</td><td>&nbsp;</td>
  1607. </tr>');
  1608. $c++;
  1609. }
  1610. }
  1611. // Add an empty hidden field which will send a blank value if all items are unselected.
  1612. $item .= '<input type="hidden" name="'.htmlspecialchars($PA['itemFormElName']) . '" value="" />';
  1613. // Add revert icon
  1614. if (is_array($restoreCmd)) {
  1615. $item .= '<a href="#" onclick="' . implode('', $restoreCmd).' return false;' . '">' .
  1616. t3lib_iconWorks::getSpriteIcon('actions-edit-undo', array('title' => htmlspecialchars($this->getLL('l_revertSelection')))) . '</a>';
  1617. }
  1618. // Implode rows in table:
  1619. $item .= '
  1620. <table border="0" cellpadding="0" cellspacing="0" class="typo3-TCEforms-select-checkbox">'.
  1621. implode('',$tRows).'
  1622. </table>
  1623. ';
  1624. return $item;
  1625. }
  1626. /**
  1627. * Creates a selectorbox list (renderMode = "singlebox")
  1628. * (Render function for getSingleField_typeSelect())
  1629. *
  1630. * @param string See getSingleField_typeSelect()
  1631. * @param string See getSingleField_typeSelect()
  1632. * @param array See getSingleField_typeSelect()
  1633. * @param array See getSingleField_typeSelect()
  1634. * @param array (Redundant) content of $PA['fieldConf']['config'] (for convenience)
  1635. * @param array Items available for selection
  1636. * @param string Label for no-matching-value
  1637. * @return string The HTML code for the item
  1638. * @see getSingleField_typeSelect()
  1639. */
  1640. function getSingleField_typeSelect_singlebox($table,$field,$row,&$PA,$config,$selItems,$nMV_label) {
  1641. // Get values in an array (and make unique, which is fine because there can be no duplicates anyway):
  1642. $itemArray = array_flip($this->extractValuesOnlyFromValueLabelList($PA['itemFormElValue']));
  1643. $disabled = '';
  1644. if($this->renderReadonly || $config['readOnly']) {
  1645. $disabled = ' disabled="disabled"';
  1646. }
  1647. // Traverse the Array of selector box items:
  1648. $opt = array();
  1649. $restoreCmd = array(); // Used to accumulate the JS needed to restore the original selection.
  1650. $c = 0;
  1651. foreach($selItems as $p) {
  1652. // Selected or not by default:
  1653. $sM = '';
  1654. if (isset($itemArray[$p[1]])) {
  1655. $sM = ' selected="selected"';
  1656. $restoreCmd[] = $this->elName($PA['itemFormElName'].'[]').'.options['.$c.'].selected=1;';
  1657. unset($itemArray[$p[1]]);
  1658. }
  1659. // Non-selectable element:
  1660. $nonSel = '';
  1661. if (!strcmp($p[1],'--div--')) {
  1662. $nonSel = ' onclick="this.selected=0;" class="c-divider"';
  1663. }
  1664. // Icon style for option tag:
  1665. if ($config['iconsInOptionTags']) {
  1666. $styleAttrValue = $this->optionTagStyle($p[2]);
  1667. }
  1668. // Compile <option> tag:
  1669. $opt[] = '<option value="'.htmlspecialchars($p[1]).'"'.
  1670. $sM.
  1671. $nonSel.
  1672. ($styleAttrValue ? ' style="'.htmlspecialchars($styleAttrValue).'"' : '').
  1673. '>'.t3lib_div::deHSCentities(htmlspecialchars($p[0])).'</option>';
  1674. $c++;
  1675. }
  1676. // Remaining values:
  1677. if (count($itemArray) && !$PA['fieldTSConfig']['disableNoMatchingValueElement'] && !$config['disableNoMatchingValueElement']) {
  1678. foreach($itemArray as $theNoMatchValue => $temp) {
  1679. // Compile <option> tag:
  1680. array_unshift($opt,'<option value="'.htmlspecialchars($theNoMatchValue).'" selected="selected">'.t3lib_div::deHSCentities(htmlspecialchars(@sprintf($nMV_label, $theNoMatchValue))).'</option>');
  1681. }
  1682. }
  1683. // Compile selector box:
  1684. $sOnChange = implode('',$PA['fieldChangeFunc']);
  1685. $selector_itemListStyle = isset($config['itemListStyle']) ? ' style="'.htmlspecialchars($config['itemListStyle']).'"' : ' style="'.$this->defaultMultipleSelectorStyle.'"';
  1686. $size = intval($config['size']);
  1687. $size = $config['autoSizeMax'] ? t3lib_div::intInRange(count($selItems)+1,t3lib_div::intInRange($size,1),$config['autoSizeMax']) : $size;
  1688. $selectBox = '<select id="' . uniqid('tceforms-multiselect-') . '" name="'.$PA['itemFormElName'].'[]"'.
  1689. $this->insertDefStyle('select', 'tceforms-multiselect').
  1690. ($size ? ' size="'.$size.'"' : '').
  1691. ' multiple="multiple" onchange="'.htmlspecialchars($sOnChange).'"'.
  1692. $PA['onFocus'].
  1693. $selector_itemListStyle.
  1694. $disabled.'>
  1695. '.
  1696. implode('
  1697. ',$opt).'
  1698. </select>';
  1699. // Add an empty hidden field which will send a blank value if all items are unselected.
  1700. if (!$disabled) {
  1701. $item.='<input type="hidden" name="'.htmlspecialchars($PA['itemFormElName']).'" value="" />';
  1702. }
  1703. // Put it all into a table:
  1704. $item.= '
  1705. <table border="0" cellspacing="0" cellpadding="0" width="1" class="typo3-TCEforms-select-singlebox">
  1706. <tr>
  1707. <td>
  1708. '.$selectBox.'
  1709. <br/>
  1710. <em>'.
  1711. htmlspecialchars($this->getLL('l_holdDownCTRL')).
  1712. '</em>
  1713. </td>
  1714. <td valign="top">
  1715. <a href="#" onclick="'.htmlspecialchars($this->elName($PA['itemFormElName'].'[]').'.selectedIndex=-1;'.implode('',$restoreCmd).' return false;').'" title="' . htmlspecialchars($this->getLL('l_revertSelection')) . '">' .
  1716. t3lib_iconWorks::getSpriteIcon('actions-edit-undo') .
  1717. '</a>
  1718. </td>
  1719. </tr>
  1720. </table>
  1721. ';
  1722. return $item;
  1723. }
  1724. /**
  1725. * Creates a multiple-selector box (two boxes, side-by-side)
  1726. * (Render function for getSingleField_typeSelect())
  1727. *
  1728. * @param string See getSingleField_typeSelect()
  1729. * @param string See getSingleField_typeSelect()
  1730. * @param array See getSingleField_typeSelect()
  1731. * @param array See getSingleField_typeSelect()
  1732. * @param array (Redundant) content of $PA['fieldConf']['config'] (for convenience)
  1733. * @param array Items available for selection
  1734. * @param string Label for no-matching-value
  1735. * @return string The HTML code for the item
  1736. * @see getSingleField_typeSelect()
  1737. */
  1738. function getSingleField_typeSelect_multiple($table,$field,$row,&$PA,$config,$selItems,$nMV_label) {
  1739. $disabled = '';
  1740. if($this->renderReadonly || $config['readOnly']) {
  1741. $disabled = ' disabled="disabled"';
  1742. }
  1743. // Setting this hidden field (as a flag that JavaScript can read out)
  1744. if (!$disabled) {
  1745. $item.= '<input type="hidden" name="'.$PA['itemFormElName'].'_mul" value="'.($config['multiple']?1:0).'" />';
  1746. }
  1747. // Set max and min items:
  1748. $maxitems = t3lib_div::intInRange($config['maxitems'],0);
  1749. if (!$maxitems) $maxitems=100000;
  1750. $minitems = t3lib_div::intInRange($config['minitems'],0);
  1751. // Register the required number of elements:
  1752. $this->registerRequiredProperty('range', $PA['itemFormElName'], array($minitems,$maxitems,'imgName'=>$table.'_'.$row['uid'].'_'.$field));
  1753. // Get "removeItems":
  1754. $removeItems = t3lib_div::trimExplode(',',$PA['fieldTSConfig']['removeItems'],1);
  1755. // Get the array with selected items:
  1756. $itemArray = t3lib_div::trimExplode(',', $PA['itemFormElValue'], 1);
  1757. // Possibly filter some items:
  1758. $keepItemsFunc = create_function('$value', '$parts=explode(\'|\',$value,2); return rawurldecode($parts[0]);');
  1759. $itemArray = t3lib_div::keepItemsInArray($itemArray, $PA['fieldTSConfig']['keepItems'], $keepItemsFunc);
  1760. // Perform modification of the selected items array:
  1761. foreach($itemArray as $tk => $tv) {
  1762. $tvP = explode('|',$tv,2);
  1763. $evalValue = $tvP[0];
  1764. $isRemoved = in_array($evalValue,$removeItems) || ($config['form_type']=='select' && $config['authMode'] && !$GLOBALS['BE_USER']->checkAuthMode($table,$field,$evalValue,$config['authMode']));
  1765. if ($isRemoved && !$PA['fieldTSConfig']['disableNoMatchingValueElement'] && !$config['disableNoMatchingValueElement']) {
  1766. $tvP[1] = rawurlencode(@sprintf($nMV_label, $evalValue));
  1767. } elseif (isset($PA['fieldTSConfig']['altLabels.'][$evalValue])) {
  1768. $tvP[1] = rawurlencode($this->sL($PA['fieldTSConfig']['altLabels.'][$evalValue]));
  1769. }
  1770. if ($tvP[1] == '') {
  1771. // Case: flexform, default values supplied, no label provided (bug #9795)
  1772. foreach ($selItems as $selItem) {
  1773. if ($selItem[1] == $tvP[0]) {
  1774. $tvP[1] = html_entity_decode($selItem[0]);
  1775. break;
  1776. }
  1777. }
  1778. }
  1779. $itemArray[$tk] = implode('|',$tvP);
  1780. }
  1781. $itemsToSelect = '';
  1782. if(!$disabled) {
  1783. // Create option tags:
  1784. $opt = array();
  1785. $styleAttrValue = '';
  1786. foreach($selItems as $p) {
  1787. if ($config['iconsInOptionTags']) {
  1788. $styleAttrValue = $this->optionTagStyle($p[2]);
  1789. }
  1790. $opt[]= '<option value="'.htmlspecialchars($p[1]).'"'.
  1791. ($styleAttrValue ? ' style="'.htmlspecialchars($styleAttrValue).'"' : '').
  1792. '>' . $p[0] . '</option>';
  1793. }
  1794. // Put together the selector box:
  1795. $selector_itemListStyle = isset($config['itemListStyle']) ? ' style="'.htmlspecialchars($config['itemListStyle']).'"' : ' style="'.$this->defaultMultipleSelectorStyle.'"';
  1796. $size = intval($config['size']);
  1797. $size = $config['autoSizeMax'] ? t3lib_div::intInRange(count($itemArray)+1,t3lib_div::intInRange($size,1),$config['autoSizeMax']) : $size;
  1798. if ($config['exclusiveKeys']) {
  1799. $sOnChange = 'setFormValueFromBrowseWin(\''.$PA['itemFormElName'].'\',this.options[this.selectedIndex].value,this.options[this.selectedIndex].text,\''.$config['exclusiveKeys'].'\'); ';
  1800. } else {
  1801. $sOnChange = 'setFormValueFromBrowseWin(\''.$PA['itemFormElName'].'\',this.options[this.selectedIndex].value,this.options[this.selectedIndex].text); ';
  1802. }
  1803. $sOnChange .= implode('',$PA['fieldChangeFunc']);
  1804. $itemsToSelect = '
  1805. <select id="' . uniqid('tceforms-multiselect-') . '" name="'.$PA['itemFormElName'].'_sel"'.
  1806. $this->insertDefStyle('select', 'tceforms-multiselect tceforms-itemstoselect').
  1807. ($size ? ' size="'.$size.'"' : '').
  1808. ' onchange="'.htmlspecialchars($sOnChange).'"'.
  1809. $PA['onFocus'].
  1810. $selector_itemListStyle.'>
  1811. '.implode('
  1812. ',$opt).'
  1813. </select>';
  1814. }
  1815. // Pass to "dbFileIcons" function:
  1816. $params = array(
  1817. 'size' => $size,
  1818. 'autoSizeMax' => t3lib_div::intInRange($config['autoSizeMax'],0),
  1819. 'style' => isset($config['selectedListStyle']) ? ' style="'.htmlspecialchars($config['selectedListStyle']).'"' : ' style="'.$this->defaultMultipleSelectorStyle.'"',
  1820. 'dontShowMoveIcons' => ($maxitems<=1),
  1821. 'maxitems' => $maxitems,
  1822. 'info' => '',
  1823. 'headers' => array(
  1824. 'selector' => $this->getLL('l_selected').':<br />',
  1825. 'items' => $this->getLL('l_items').':<br />'
  1826. ),
  1827. 'noBrowser' => 1,
  1828. 'thumbnails' => $itemsToSelect,
  1829. 'readOnly' => $disabled
  1830. );
  1831. $item.= $this->dbFileIcons($PA['itemFormElName'],'','',$itemArray,'',$params,$PA['onFocus']);
  1832. return $item;
  1833. }
  1834. /**
  1835. * Generation of TCEform elements of the type "group"
  1836. * This will render a selectorbox into which elements from either the file system or database can be inserted. Relations.
  1837. *
  1838. * @param string The table name of the record
  1839. * @param string The field name which this element is supposed to edit
  1840. * @param array The record data array where the value(s) for the field can be found
  1841. * @param array An array with additional configuration options.
  1842. * @return string The HTML code for the TCEform field
  1843. */
  1844. function getSingleField_typeGroup($table,$field,$row,&$PA) {
  1845. // Init:
  1846. $config = $PA['fieldConf']['config'];
  1847. $internal_type = $config['internal_type'];
  1848. $show_thumbs = $config['show_thumbs'];
  1849. $size = intval($config['size']);
  1850. $maxitems = t3lib_div::intInRange($config['maxitems'],0);
  1851. if (!$maxitems) $maxitems=100000;
  1852. $minitems = t3lib_div::intInRange($config['minitems'],0);
  1853. $allowed = trim($config['allowed']);
  1854. $disallowed = trim($config['disallowed']);
  1855. $disabled = '';
  1856. if($this->renderReadonly || $config['readOnly']) {
  1857. $disabled = ' disabled="disabled"';
  1858. }
  1859. $item.= '<input type="hidden" name="'.$PA['itemFormElName'].'_mul" value="'.($config['multiple']?1:0).'"'.$disabled.' />';
  1860. $this->registerRequiredProperty('range', $PA['itemFormElName'], array($minitems,$maxitems,'imgName'=>$table.'_'.$row['uid'].'_'.$field));
  1861. $info='';
  1862. // "Extra" configuration; Returns configuration for the field based on settings found in the "types" fieldlist. See http://typo3.org/documentation/document-library/doc_core_api/Wizards_Configuratio/.
  1863. $specConf = $this->getSpecConfFromString($PA['extra'], $PA['fieldConf']['defaultExtras']);
  1864. // Acting according to either "file" or "db" type:
  1865. switch((string)$config['internal_type']) {
  1866. case 'file_reference':
  1867. $config['uploadfolder'] = '';
  1868. // Fall through
  1869. case 'file': // If the element is of the internal type "file":
  1870. // Creating string showing allowed types:
  1871. $tempFT = t3lib_div::trimExplode(',',$allowed,1);
  1872. if (!count($tempFT)) {$info.='*';}
  1873. foreach($tempFT as $ext) {
  1874. if ($ext) {
  1875. $info.=strtoupper($ext).' ';
  1876. }
  1877. }
  1878. // Creating string, showing disallowed types:
  1879. $tempFT_dis = t3lib_div::trimExplode(',',$disallowed,1);
  1880. if (count($tempFT_dis)) {$info.='<br />';}
  1881. foreach($tempFT_dis as $ext) {
  1882. if ($ext) {
  1883. $info.='-'.strtoupper($ext).' ';
  1884. }
  1885. }
  1886. // Making the array of file items:
  1887. $itemArray = t3lib_div::trimExplode(',',$PA['itemFormElValue'],1);
  1888. // Showing thumbnails:
  1889. $thumbsnail = '';
  1890. if ($show_thumbs) {
  1891. $imgs = array();
  1892. foreach($itemArray as $imgRead) {
  1893. $imgP = explode('|',$imgRead);
  1894. $imgPath = rawurldecode($imgP[0]);
  1895. $rowCopy = array();
  1896. $rowCopy[$field] = $imgPath;
  1897. // Icon + clickmenu:
  1898. $absFilePath = t3lib_div::getFileAbsFileName($config['uploadfolder'] ? $config['uploadfolder'] . '/' . $imgPath : $imgPath);
  1899. $fI = pathinfo($imgPath);
  1900. $fileIcon = t3lib_iconWorks::getSpriteIconForFile(
  1901. strtolower($fI['extension']),
  1902. array(
  1903. 'title' => htmlspecialchars(
  1904. $fI['basename'] .
  1905. ($absFilePath && @is_file($absFilePath)
  1906. ? ' (' . t3lib_div::formatSize(filesize($absFilePath)) . 'bytes)' :
  1907. ' - FILE NOT FOUND!'
  1908. )
  1909. )
  1910. )
  1911. );
  1912. $imgs[] = '<span class="nobr">'.t3lib_BEfunc::thumbCode($rowCopy,$table,$field,$this->backPath,'thumbs.php',$config['uploadfolder'],0,' align="middle"').
  1913. ($absFilePath ? $this->getClickMenu($fileIcon, $absFilePath) : $fileIcon).
  1914. $imgPath.
  1915. '</span>';
  1916. }
  1917. $thumbsnail = implode('<br />',$imgs);
  1918. }
  1919. // Creating the element:
  1920. $noList = isset($config['disable_controls']) && t3lib_div::inList($config['disable_controls'], 'list');
  1921. $params = array(
  1922. 'size' => $size,
  1923. 'dontShowMoveIcons' => ($maxitems<=1),
  1924. 'autoSizeMax' => t3lib_div::intInRange($config['autoSizeMax'],0),
  1925. 'maxitems' => $maxitems,
  1926. 'style' => isset($config['selectedListStyle']) ? ' style="'.htmlspecialchars($config['selectedListStyle']).'"' : ' style="'.$this->defaultMultipleSelectorStyle.'"',
  1927. 'info' => $info,
  1928. 'thumbnails' => $thumbsnail,
  1929. 'readOnly' => $disabled,
  1930. 'noBrowser' => $noList || (isset($config['disable_controls']) && t3lib_div::inList($config['disable_controls'], 'browser')),
  1931. 'noList' => $noList,
  1932. );
  1933. $item.= $this->dbFileIcons($PA['itemFormElName'],'file',implode(',',$tempFT),$itemArray,'',$params,$PA['onFocus']);
  1934. if(!$disabled && !(isset($config['disable_controls']) && t3lib_div::inList($config['disable_controls'], 'upload'))) {
  1935. // Adding the upload field:
  1936. if ($this->edit_docModuleUpload && $config['uploadfolder']) {
  1937. $item .= '<input type="file" name="' . $PA['itemFormElName_file'] . '"' . $this->formWidth() . ' size="60" onchange="' . implode('', $PA['fieldChangeFunc']) . '" />';
  1938. }
  1939. }
  1940. break;
  1941. case 'folder': // If the element is of the internal type "folder":
  1942. // array of folder items:
  1943. $itemArray = t3lib_div::trimExplode(',', $PA['itemFormElValue'], 1);
  1944. // Creating the element:
  1945. $noList = isset($config['disable_controls']) && t3lib_div::inList($config['disable_controls'], 'list');
  1946. $params = array(
  1947. 'size' => $size,
  1948. 'dontShowMoveIcons' => ($maxitems <= 1),
  1949. 'autoSizeMax' => t3lib_div::intInRange($config['autoSizeMax'], 0),
  1950. 'maxitems' => $maxitems,
  1951. 'style' => isset($config['selectedListStyle']) ?
  1952. ' style="'.htmlspecialchars($config['selectedListStyle']).'"'
  1953. : ' style="'.$this->defaultMultipleSelectorStyle.'"',
  1954. 'info' => $info,
  1955. 'readOnly' => $disabled,
  1956. 'noBrowser' => $noList || (isset($config['disable_controls']) && t3lib_div::inList($config['disable_controls'], 'browser')),
  1957. 'noList' => $noList,
  1958. );
  1959. $item.= $this->dbFileIcons(
  1960. $PA['itemFormElName'],
  1961. 'folder',
  1962. '',
  1963. $itemArray,
  1964. '',
  1965. $params,
  1966. $PA['onFocus']
  1967. );
  1968. break;
  1969. case 'db': // If the element is of the internal type "db":
  1970. // Creating string showing allowed types:
  1971. $tempFT = t3lib_div::trimExplode(',', $allowed, true);
  1972. if (!strcmp(trim($tempFT[0]), '*')) {
  1973. $onlySingleTableAllowed = false;
  1974. $info.='<span class="nobr">&nbsp;&nbsp;&nbsp;&nbsp;'.
  1975. htmlspecialchars($this->getLL('l_allTables')).
  1976. '</span><br />';
  1977. } elseif ($tempFT) {
  1978. $onlySingleTableAllowed = (count($tempFT) == 1);
  1979. foreach ($tempFT as $theT) {
  1980. $info.= '<span class="nobr">&nbsp;&nbsp;&nbsp;&nbsp;' .
  1981. t3lib_iconWorks::getSpriteIconForRecord($theT, array()) .
  1982. htmlspecialchars($this->sL($GLOBALS['TCA'][$theT]['ctrl']['title'])) .
  1983. '</span><br />';
  1984. }
  1985. }
  1986. $perms_clause = $GLOBALS['BE_USER']->getPagePermsClause(1);
  1987. $itemArray = array();
  1988. $imgs = array();
  1989. // Thumbnails:
  1990. $temp_itemArray = t3lib_div::trimExplode(',',$PA['itemFormElValue'],1);
  1991. foreach($temp_itemArray as $dbRead) {
  1992. $recordParts = explode('|',$dbRead);
  1993. list($this_table,$this_uid) = t3lib_BEfunc::splitTable_Uid($recordParts[0]);
  1994. // For the case that no table was found and only a single table is defined to be allowed, use that one:
  1995. if (!$this_table && $onlySingleTableAllowed) {
  1996. $this_table = $allowed;
  1997. }
  1998. $itemArray[] = array('table'=>$this_table, 'id'=>$this_uid);
  1999. if (!$disabled && $show_thumbs) {
  2000. $rr = t3lib_BEfunc::getRecordWSOL($this_table,$this_uid);
  2001. $imgs[] = '<span class="nobr">'.
  2002. $this->getClickMenu(
  2003. t3lib_iconWorks::getSpriteIconForRecord(
  2004. $this_table,
  2005. $rr,
  2006. array(
  2007. 'style' => 'vertical-align:top',
  2008. 'title' => htmlspecialchars(t3lib_BEfunc::getRecordPath($rr['pid'], $perms_clause, 15) . ' [UID: ' . $rr['uid'] . ']"')
  2009. )
  2010. ),
  2011. $this_table,
  2012. $this_uid
  2013. ) .
  2014. '&nbsp;'.
  2015. t3lib_BEfunc::getRecordTitle($this_table,$rr,TRUE).' <span class="typo3-dimmed"><em>['.$rr['uid'].']</em></span>'.
  2016. '</span>';
  2017. }
  2018. }
  2019. $thumbsnail='';
  2020. if (!$disabled && $show_thumbs) {
  2021. $thumbsnail = implode('<br />',$imgs);
  2022. }
  2023. // Creating the element:
  2024. $noList = isset($config['disable_controls']) && t3lib_div::inList($config['disable_controls'], 'list');
  2025. $params = array(
  2026. 'size' => $size,
  2027. 'dontShowMoveIcons' => ($maxitems<=1),
  2028. 'autoSizeMax' => t3lib_div::intInRange($config['autoSizeMax'],0),
  2029. 'maxitems' => $maxitems,
  2030. 'style' => isset($config['selectedListStyle']) ? ' style="'.htmlspecialchars($config['selectedListStyle']).'"' : ' style="'.$this->defaultMultipleSelectorStyle.'"',
  2031. 'info' => $info,
  2032. 'thumbnails' => $thumbsnail,
  2033. 'readOnly' => $disabled,
  2034. 'noBrowser' => $noList || (isset($config['disable_controls']) && t3lib_div::inList($config['disable_controls'], 'browser')),
  2035. 'noList' => $noList,
  2036. );
  2037. $item.= $this->dbFileIcons($PA['itemFormElName'],'db',implode(',',$tempFT),$itemArray,'',$params,$PA['onFocus'],$table,$field,$row['uid']);
  2038. break;
  2039. }
  2040. // Wizards:
  2041. $altItem = '<input type="hidden" name="'.$PA['itemFormElName'].'" value="'.htmlspecialchars($PA['itemFormElValue']).'" />';
  2042. if (!$disabled) {
  2043. $item = $this->renderWizards(array($item,$altItem),$config['wizards'],$table,$row,$field,$PA,$PA['itemFormElName'],$specConf);
  2044. }
  2045. return $item;
  2046. }
  2047. /**
  2048. * Generation of TCEform elements of the type "none"
  2049. * This will render a non-editable display of the content of the field.
  2050. *
  2051. * @param string The table name of the record
  2052. * @param string The field name which this element is supposed to edit
  2053. * @param array The record data array where the value(s) for the field can be found
  2054. * @param array An array with additional configuration options.
  2055. * @return string The HTML code for the TCEform field
  2056. */
  2057. function getSingleField_typeNone($table,$field,$row,&$PA) {
  2058. // Init:
  2059. $config = $PA['fieldConf']['config'];
  2060. $itemValue = $PA['itemFormElValue'];
  2061. return $this->getSingleField_typeNone_render($config,$itemValue);
  2062. }
  2063. /**
  2064. * HTML rendering of a value which is not editable.
  2065. *
  2066. * @param array Configuration for the display
  2067. * @param string The value to display
  2068. * @return string The HTML code for the display
  2069. * @see getSingleField_typeNone();
  2070. */
  2071. function getSingleField_typeNone_render($config,$itemValue) {
  2072. // is colorScheme[0] the right value?
  2073. $divStyle = 'border:solid 1px '.t3lib_div::modifyHTMLColorAll($this->colorScheme[0],-30).';'.$this->defStyle.$this->formElStyle('none').' background-color: '.$this->colorScheme[0].'; padding-left:1px;color:#555;';
  2074. if ($config['format']) {
  2075. $itemValue = $this->formatValue($config, $itemValue);
  2076. }
  2077. $rows = intval($config['rows']);
  2078. if ($rows > 1) {
  2079. if(!$config['pass_content']) {
  2080. $itemValue = nl2br(htmlspecialchars($itemValue));
  2081. }
  2082. // like textarea
  2083. $cols = t3lib_div::intInRange($config['cols'] ? $config['cols'] : 30, 5, $this->maxTextareaWidth);
  2084. if (!$config['fixedRows']) {
  2085. $origRows = $rows = t3lib_div::intInRange($rows, 1, 20);
  2086. if (strlen($itemValue)>$this->charsPerRow*2) {
  2087. $cols = $this->maxTextareaWidth;
  2088. $rows = t3lib_div::intInRange(round(strlen($itemValue)/$this->charsPerRow),count(explode(LF,$itemValue)),20);
  2089. if ($rows<$origRows) $rows=$origRows;
  2090. }
  2091. }
  2092. if ($this->docLarge) $cols = round($cols*$this->form_largeComp);
  2093. $width = ceil($cols*$this->form_rowsToStylewidth);
  2094. // hardcoded: 12 is the height of the font
  2095. $height=$rows*12;
  2096. $item='
  2097. <div style="'.htmlspecialchars($divStyle.' overflow:auto; height:'.$height.'px; width:'.$width.'px;').'" class="'.htmlspecialchars($this->formElClass('none')).'">'.
  2098. $itemValue.
  2099. '</div>';
  2100. } else {
  2101. if(!$config['pass_content']) {
  2102. $itemValue = htmlspecialchars($itemValue);
  2103. }
  2104. $cols = $config['cols']?$config['cols']:($config['size']?$config['size']:$this->maxInputWidth);
  2105. if ($this->docLarge) $cols = round($cols*$this->form_largeComp);
  2106. $width = ceil($cols*$this->form_rowsToStylewidth);
  2107. // overflow:auto crashes mozilla here. Title tag is usefull when text is longer than the div box (overflow:hidden).
  2108. $item = '
  2109. <div style="'.htmlspecialchars($divStyle.' overflow:hidden; width:'.$width.'px;').'" class="'.htmlspecialchars($this->formElClass('none')).'" title="'.$itemValue.'">'.
  2110. '<span class="nobr">'.(strcmp($itemValue,'')?$itemValue:'&nbsp;').'</span>'.
  2111. '</div>';
  2112. }
  2113. return $item;
  2114. }
  2115. /**
  2116. * Handler for Flex Forms
  2117. *
  2118. * @param string The table name of the record
  2119. * @param string The field name which this element is supposed to edit
  2120. * @param array The record data array where the value(s) for the field can be found
  2121. * @param array An array with additional configuration options.
  2122. * @return string The HTML code for the TCEform field
  2123. */
  2124. function getSingleField_typeFlex($table,$field,$row,&$PA) {
  2125. // Data Structure:
  2126. $dataStructArray = t3lib_BEfunc::getFlexFormDS($PA['fieldConf']['config'],$row,$table);
  2127. // Get data structure:
  2128. if (is_array($dataStructArray)) {
  2129. // Get data:
  2130. $xmlData = $PA['itemFormElValue'];
  2131. $xmlHeaderAttributes = t3lib_div::xmlGetHeaderAttribs($xmlData);
  2132. $storeInCharset = strtolower($xmlHeaderAttributes['encoding']);
  2133. if ($storeInCharset) {
  2134. $currentCharset=$GLOBALS['LANG']->charSet;
  2135. $xmlData = $GLOBALS['LANG']->csConvObj->conv($xmlData,$storeInCharset,$currentCharset,1);
  2136. }
  2137. $editData=t3lib_div::xml2array($xmlData);
  2138. if (!is_array($editData)) { // Must be XML parsing error...
  2139. $editData=array();
  2140. } elseif (!isset($editData['meta']) || !is_array($editData['meta'])) {
  2141. $editData['meta'] = array();
  2142. }
  2143. // Find the data structure if sheets are found:
  2144. $sheet = $editData['meta']['currentSheetId'] ? $editData['meta']['currentSheetId'] : 'sDEF'; // Sheet to display
  2145. // Create sheet menu:
  2146. // if (is_array($dataStructArray['sheets'])) {
  2147. // #$item.=$this->getSingleField_typeFlex_sheetMenu($dataStructArray['sheets'], $PA['itemFormElName'].'[meta][currentSheetId]', $sheet).'<br />';
  2148. // }
  2149. // Create language menu:
  2150. $langChildren = $dataStructArray['meta']['langChildren'] ? 1 : 0;
  2151. $langDisabled = $dataStructArray['meta']['langDisable'] ? 1 : 0;
  2152. $editData['meta']['currentLangId']=array();
  2153. // Look up page overlays:
  2154. $checkPageLanguageOverlay = $GLOBALS['BE_USER']->getTSConfigVal('options.checkPageLanguageOverlay')?TRUE:FALSE;
  2155. if ($checkPageLanguageOverlay) {
  2156. $pageOverlays = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
  2157. '*',
  2158. 'pages_language_overlay',
  2159. 'pid='.intval($row['pid']).
  2160. t3lib_BEfunc::deleteClause('pages_language_overlay').
  2161. t3lib_BEfunc::versioningPlaceholderClause('pages_language_overlay'),
  2162. '',
  2163. '',
  2164. '',
  2165. 'sys_language_uid'
  2166. );
  2167. }
  2168. $languages = $this->getAvailableLanguages();
  2169. foreach($languages as $lInfo) {
  2170. if ($GLOBALS['BE_USER']->checkLanguageAccess($lInfo['uid']) && (!$checkPageLanguageOverlay || $lInfo['uid']<=0 || is_array($pageOverlays[$lInfo['uid']]))) {
  2171. $editData['meta']['currentLangId'][] = $lInfo['ISOcode'];
  2172. }
  2173. }
  2174. if (!is_array($editData['meta']['currentLangId']) || !count($editData['meta']['currentLangId'])) {
  2175. $editData['meta']['currentLangId']=array('DEF');
  2176. }
  2177. $editData['meta']['currentLangId'] = array_unique($editData['meta']['currentLangId']);
  2178. // if (!$langDisabled && count($languages) > 1) {
  2179. // $item.=$this->getSingleField_typeFlex_langMenu($languages, $PA['itemFormElName'].'[meta][currentLangId]', $editData['meta']['currentLangId']).'<br />';
  2180. // }
  2181. $PA['_noEditDEF'] = FALSE;
  2182. if ($langChildren || $langDisabled) {
  2183. $rotateLang = array('DEF');
  2184. } else {
  2185. if (!in_array('DEF',$editData['meta']['currentLangId'])) {
  2186. array_unshift($editData['meta']['currentLangId'],'DEF');
  2187. $PA['_noEditDEF'] = TRUE;
  2188. }
  2189. $rotateLang = $editData['meta']['currentLangId'];
  2190. }
  2191. // Tabs sheets
  2192. if (is_array($dataStructArray['sheets'])) {
  2193. $tabsToTraverse = array_keys($dataStructArray['sheets']);
  2194. } else {
  2195. $tabsToTraverse = array($sheet);
  2196. }
  2197. foreach ($rotateLang as $lKey) {
  2198. if (!$langChildren && !$langDisabled) {
  2199. $item.= '<strong>'.$this->getLanguageIcon($table,$row,'v'.$lKey).$lKey.':</strong>';
  2200. }
  2201. $tabParts = array();
  2202. foreach ($tabsToTraverse as $sheet) {
  2203. list ($dataStruct, $sheet) = t3lib_div::resolveSheetDefInDS($dataStructArray,$sheet);
  2204. // Render sheet:
  2205. if (is_array($dataStruct['ROOT']) && is_array($dataStruct['ROOT']['el'])) {
  2206. $lang = 'l'.$lKey; // Default language, other options are "lUK" or whatever country code (independant of system!!!)
  2207. $PA['_valLang'] = $langChildren && !$langDisabled ? $editData['meta']['currentLangId'] : 'DEF'; // Default language, other options are "lUK" or whatever country code (independant of system!!!)
  2208. $PA['_lang'] = $lang;
  2209. $PA['_cshFile'] = ((isset($dataStruct['ROOT']['TCEforms']) && isset($dataStruct['ROOT']['TCEforms']['cshFile'])) ? $dataStruct['ROOT']['TCEforms']['cshFile'] : '');
  2210. // Render flexform:
  2211. $tRows = $this->getSingleField_typeFlex_draw(
  2212. $dataStruct['ROOT']['el'],
  2213. $editData['data'][$sheet][$lang],
  2214. $table,
  2215. $field,
  2216. $row,
  2217. $PA,
  2218. '[data]['.$sheet.']['.$lang.']'
  2219. );
  2220. #$sheetContent= '<table border="0" cellpadding="1" cellspacing="1" class="typo3-TCEforms-flexForm">'.implode('',$tRows).'</table>';
  2221. $sheetContent = '<div class="typo3-TCEforms-flexForm">'.$tRows.'</div>';
  2222. # $item = '<div style=" position:absolute;">'.$item.'</div>';
  2223. //visibility:hidden;
  2224. } else $sheetContent='Data Structure ERROR: No ROOT element found for sheet "'.$sheet.'".';
  2225. // Add to tab:
  2226. $tabParts[] = array(
  2227. 'label' => ($dataStruct['ROOT']['TCEforms']['sheetTitle'] ? $this->sL($dataStruct['ROOT']['TCEforms']['sheetTitle']) : $sheet),
  2228. 'description' => ($dataStruct['ROOT']['TCEforms']['sheetDescription'] ? $this->sL($dataStruct['ROOT']['TCEforms']['sheetDescription']) : ''),
  2229. 'linkTitle' => ($dataStruct['ROOT']['TCEforms']['sheetShortDescr'] ? $this->sL($dataStruct['ROOT']['TCEforms']['sheetShortDescr']) : ''),
  2230. 'content' => $sheetContent
  2231. );
  2232. }
  2233. if (is_array($dataStructArray['sheets'])) {
  2234. $dividersToTabsBehaviour = (isset($GLOBALS['TCA'][$table]['ctrl']['dividers2tabs']) ? $GLOBALS['TCA'][$table]['ctrl']['dividers2tabs'] : 1);
  2235. $item.= $this->getDynTabMenu($tabParts, 'TCEFORMS:flexform:'.$PA['itemFormElName'].$PA['_lang'], $dividersToTabsBehaviour);
  2236. } else {
  2237. $item.= $sheetContent;
  2238. }
  2239. }
  2240. } else $item='Data Structure ERROR: '.$dataStructArray;
  2241. return $item;
  2242. }
  2243. /**
  2244. * Creates the language menu for FlexForms:
  2245. *
  2246. * @param [type] $languages: ...
  2247. * @param [type] $elName: ...
  2248. * @param [type] $selectedLanguage: ...
  2249. * @param [type] $multi: ...
  2250. * @return string HTML for menu
  2251. */
  2252. function getSingleField_typeFlex_langMenu($languages,$elName,$selectedLanguage,$multi=1) {
  2253. $opt=array();
  2254. foreach($languages as $lArr) {
  2255. $opt[]='<option value="'.htmlspecialchars($lArr['ISOcode']).'"'.(in_array($lArr['ISOcode'],$selectedLanguage)?' selected="selected"':'').'>'.htmlspecialchars($lArr['title']).'</option>';
  2256. }
  2257. $output = '<select id="' . uniqid('tceforms-multiselect-') . ' class="tceforms-select tceforms-multiselect tceforms-flexlangmenu" name="'.$elName.'[]"'.($multi ? ' multiple="multiple" size="'.count($languages).'"' : '').'>'.implode('',$opt).'</select>';
  2258. return $output;
  2259. }
  2260. /**
  2261. * Creates the menu for selection of the sheets:
  2262. *
  2263. * @param array Sheet array for which to render the menu
  2264. * @param string Form element name of the field containing the sheet pointer
  2265. * @param string Current sheet key
  2266. * @return string HTML for menu
  2267. */
  2268. function getSingleField_typeFlex_sheetMenu($sArr,$elName,$sheetKey) {
  2269. $tCells =array();
  2270. $pct = round(100/count($sArr));
  2271. foreach($sArr as $sKey => $sheetCfg) {
  2272. if ($GLOBALS['BE_USER']->jsConfirmation(1)) {
  2273. $onClick = 'if (confirm(TBE_EDITOR.labels.onChangeAlert) && TBE_EDITOR.checkSubmit(-1)){'.$this->elName($elName).".value='".$sKey."'; TBE_EDITOR.submitForm()};";
  2274. } else {
  2275. $onClick = 'if(TBE_EDITOR.checkSubmit(-1)){ '.$this->elName($elName).".value='".$sKey."'; TBE_EDITOR.submitForm();}";
  2276. }
  2277. $tCells[]='<td width="'.$pct.'%" style="'.($sKey==$sheetKey ? 'background-color: #9999cc; font-weight: bold;' : 'background-color: #aaaaaa;').' cursor: hand;" onclick="'.htmlspecialchars($onClick).'" align="center">'.
  2278. ($sheetCfg['ROOT']['TCEforms']['sheetTitle'] ? $this->sL($sheetCfg['ROOT']['TCEforms']['sheetTitle']) : $sKey).
  2279. '</td>';
  2280. }
  2281. return '<table border="0" cellpadding="0" cellspacing="2" class="typo3-TCEforms-flexForm-sheetMenu"><tr>'.implode('',$tCells).'</tr></table>';
  2282. }
  2283. /**
  2284. * Recursive rendering of flexforms
  2285. *
  2286. * @param array (part of) Data Structure for which to render. Keys on first level is flex-form fields
  2287. * @param array (part of) Data array of flexform corresponding to the input DS. Keys on first level is flex-form field names
  2288. * @param string Table name, eg. tt_content
  2289. * @param string Field name, eg. tx_templavoila_flex
  2290. * @param array The particular record from $table in which the field $field is found
  2291. * @param array Array of standard information for rendering of a form field in TCEforms, see other rendering functions too
  2292. * @param string Form field prefix, eg. "[data][sDEF][lDEF][...][...]"
  2293. * @param integer Indicates nesting level for the function call
  2294. * @param string Prefix for ID-values
  2295. * @param boolean Defines whether the next flexform level is open or closed. Comes from _TOGGLE pseudo field in FlexForm xml.
  2296. * @return string HTMl code for form.
  2297. */
  2298. function getSingleField_typeFlex_draw($dataStruct,$editData,$table,$field,$row,&$PA,$formPrefix='',$level=0,$idPrefix='ID',$toggleClosed=FALSE) {
  2299. $output = '';
  2300. $mayRestructureFlexforms = $GLOBALS['BE_USER']->checkLanguageAccess(0);
  2301. // Data Structure array must be ... and array of course...
  2302. if (is_array($dataStruct)) {
  2303. foreach($dataStruct as $key => $value) { // Traversing fields in structure:
  2304. if (is_array($value)) { // The value of each entry must be an array.
  2305. // ********************
  2306. // Making the row:
  2307. // ********************
  2308. // Title of field:
  2309. $theTitle = htmlspecialchars(t3lib_div::fixed_lgd_cs($this->sL($value['tx_templavoila']['title']),30));
  2310. // If it's a "section" or "container":
  2311. if ($value['type']=='array') {
  2312. // Creating IDs for form fields:
  2313. // It's important that the IDs "cascade" - otherwise we can't dynamically expand the flex form because this relies on simple string substitution of the first parts of the id values.
  2314. $thisId = t3lib_div::shortMd5(uniqid('id',true)); // This is a suffix used for forms on this level
  2315. $idTagPrefix = $idPrefix.'-'.$thisId; // $idPrefix is the prefix for elements on lower levels in the hierarchy and we combine this with the thisId value to form a new ID on this level.
  2316. // If it's a "section" containing other elements:
  2317. if ($value['section']) {
  2318. // Load script.aculo.us if flexform sections can be moved by drag'n'drop:
  2319. $GLOBALS['SOBE']->doc->getPageRenderer()->loadScriptaculous();
  2320. // Render header of section:
  2321. $output .= '<div class="t3-form-field-label-flexsection"><strong>' . $theTitle . '</strong></div>';
  2322. // Render elements in data array for section:
  2323. $tRows = array();
  2324. $cc=0;
  2325. if (is_array($editData[$key]['el'])) {
  2326. foreach ($editData[$key]['el'] as $k3 => $v3) {
  2327. $cc=$k3;
  2328. if (is_array($v3)) {
  2329. $theType = key($v3);
  2330. $theDat = $v3[$theType];
  2331. $newSectionEl = $value['el'][$theType];
  2332. if (is_array($newSectionEl)) {
  2333. $tRows[]= $this->getSingleField_typeFlex_draw(
  2334. array($theType => $newSectionEl),
  2335. array($theType => $theDat),
  2336. $table,
  2337. $field,
  2338. $row,
  2339. $PA,
  2340. $formPrefix.'['.$key.'][el]['.$cc.']',
  2341. $level+1,
  2342. $idTagPrefix,
  2343. $v3['_TOGGLE']
  2344. );
  2345. }
  2346. }
  2347. }
  2348. }
  2349. // Now, we generate "templates" for new elements that could be added to this section by traversing all possible types of content inside the section:
  2350. // We have to handle the fact that requiredElements and such may be set during this rendering process and therefore we save and reset the state of some internal variables - little crude, but works...
  2351. // Preserving internal variables we don't want to change:
  2352. $TEMP_requiredElements = $this->requiredElements;
  2353. // Traversing possible types of new content in the section:
  2354. $newElementsLinks = array();
  2355. foreach($value['el'] as $nnKey => $nCfg) {
  2356. $additionalJS_post_saved = $this->additionalJS_post;
  2357. $this->additionalJS_post = array();
  2358. $additionalJS_submit_saved = $this->additionalJS_submit;
  2359. $this->additionalJS_submit = array();
  2360. $newElementTemplate = $this->getSingleField_typeFlex_draw(
  2361. array($nnKey => $nCfg),
  2362. array(),
  2363. $table,
  2364. $field,
  2365. $row,
  2366. $PA,
  2367. $formPrefix.'['.$key.'][el]['.$idTagPrefix.'-form]',
  2368. $level+1,
  2369. $idTagPrefix
  2370. );
  2371. // Makes a "Add new" link:
  2372. $var = uniqid('idvar');
  2373. $replace = 'replace(/' . $idTagPrefix . '-/g,"' . $idTagPrefix . '-"+' . $var . '+"-")';
  2374. $onClickInsert = 'var ' . $var . ' = "' . 'idx"+(new Date()).getTime();';
  2375. // Do not replace $isTagPrefix in setActionStatus() because it needs section id!
  2376. $onClickInsert .= 'new Insertion.Bottom($("'.$idTagPrefix.'"), unescape("'.rawurlencode($newElementTemplate).'").' . $replace . '); setActionStatus("'.$idTagPrefix.'");';
  2377. $onClickInsert .= 'eval(unescape("' . rawurlencode(implode(';', $this->additionalJS_post)) . '").' . $replace . ');';
  2378. $onClickInsert .= 'TBE_EDITOR.addActionChecks("submit", unescape("' . rawurlencode(implode(';', $this->additionalJS_submit)) . '").' . $replace . ');';
  2379. $onClickInsert .= 'return false;';
  2380. // Kasper's comment (kept for history): Maybe there is a better way to do this than store the HTML for the new element in rawurlencoded format - maybe it even breaks with certain charsets? But for now this works...
  2381. $this->additionalJS_post = $additionalJS_post_saved;
  2382. $this->additionalJS_submit = $additionalJS_submit_saved;
  2383. $new = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:cm.new', 1);
  2384. $newElementsLinks[]= '<a href="#" onclick="'.htmlspecialchars($onClickInsert).'">' .
  2385. t3lib_iconWorks::getSpriteIcon('actions-document-new') .
  2386. htmlspecialchars(t3lib_div::fixed_lgd_cs($this->sL($nCfg['tx_templavoila']['title']),30)) . '</a>';
  2387. }
  2388. // Reverting internal variables we don't want to change:
  2389. $this->requiredElements = $TEMP_requiredElements;
  2390. // Adding the sections:
  2391. $toggleAll = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.toggleall', 1);
  2392. $output.= '
  2393. <div class="t3-form-field-toggle-flexsection">
  2394. <a href="#" onclick="' . htmlspecialchars('flexFormToggleSubs("' . $idTagPrefix . '"); return false;') . '">'
  2395. . t3lib_iconWorks::getSpriteIcon('actions-move-right', array('title' => $toggleAll)) . $toggleAll . '
  2396. </a>
  2397. </div>
  2398. <div id="' . $idTagPrefix . '" class="t3-form-field-container-flexsection">' . implode('', $tRows) . '</div>';
  2399. $output.= $mayRestructureFlexforms ? '<div class="t3-form-field-add-flexsection"><strong>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.addnew', 1) . ':</strong> '.implode(' | ',$newElementsLinks).'</div>' : '';
  2400. } else {
  2401. // It is a container
  2402. $toggleIcon_open = t3lib_iconWorks::getSpriteIcon('actions-move-down');
  2403. $toggleIcon_close = t3lib_iconWorks::getSpriteIcon('actions-move-right');
  2404. // Create on-click actions.
  2405. //$onClickCopy = 'new Insertion.After($("'.$idTagPrefix.'"), getOuterHTML("'.$idTagPrefix.'").replace(/'.$idTagPrefix.'-/g,"'.$idTagPrefix.'-copy"+Math.floor(Math.random()*100000+1)+"-")); return false;'; // Copied elements doesn't work (well) in Safari while they do in Firefox and MSIE! UPDATE: It turned out that copying doesn't work for any browser, simply because the data from the copied form never gets submitted to the server for some reason! So I decided to simply disable copying for now. If it's requested by customers we can look to enable it again and fix the issue. There is one un-fixable problem though; Copying an element like this will violate integrity if files are attached inside that element because the file reference doesn't get an absolute path prefixed to it which would be required to have TCEmain generate a new copy of the file.
  2406. $onClickRemove = 'if (confirm("Are you sure?")){/*###REMOVE###*/;$("'.$idTagPrefix.'").hide();setActionStatus("'.$idPrefix.'");} return false;';
  2407. $onClickToggle = 'flexFormToggle("'.$idTagPrefix.'"); return false;';
  2408. $onMove = 'flexFormSortable("'.$idPrefix.'")';
  2409. // Notice: Creating "new" elements after others seemed to be too difficult to do and since moving new elements created in the bottom is now so easy with drag'n'drop I didn't see the need.
  2410. // Putting together header of a section. Sections can be removed, copied, opened/closed, moved up and down:
  2411. // I didn't know how to make something right-aligned without a table, so I put it in a table. can be made into <div>'s if someone like to.
  2412. // Notice: The fact that I make a "Sortable.create" right onmousedown is that if we initialize this when rendering the form in PHP new and copied elements will not be possible to move as a sortable. But this way a new sortable is initialized everytime someone tries to move and it will always work.
  2413. $ctrlHeader= '
  2414. <table class="t3-form-field-header-flexsection" onmousedown="' . ($mayRestructureFlexforms ? htmlspecialchars($onMove) : '') . '">
  2415. <tr>
  2416. <td>
  2417. <a href="#" onclick="'.htmlspecialchars($onClickToggle).'" id="'.$idTagPrefix.'-toggle">
  2418. '.($toggleClosed?$toggleIcon_close:$toggleIcon_open).'
  2419. </a>
  2420. <strong>'.$theTitle.'</strong> <em><span id="'.$idTagPrefix.'-preview"></span></em>
  2421. </td>
  2422. <td align="right">'.
  2423. ($mayRestructureFlexforms ? t3lib_iconWorks::getSpriteIcon('actions-move-move', array('title' => 'Drag to Move')) : '').
  2424. ($mayRestructureFlexforms ? '<a href="#" onclick="'.htmlspecialchars($onClickRemove).'">'.t3lib_iconWorks::getSpriteIcon('actions-edit-delete', array('title' => 'Delete')) : '').
  2425. '</td>
  2426. </tr>
  2427. </table>';
  2428. $s = t3lib_div::revExplode('[]',$formPrefix,2);
  2429. $actionFieldName = '_ACTION_FLEX_FORM'.$PA['itemFormElName'].$s[0].'][_ACTION]['.$s[1];
  2430. // Putting together the container:
  2431. $this->additionalJS_delete = array();
  2432. $output.= '
  2433. <div id="'.$idTagPrefix.'" class="t3-form-field-container-flexsections">
  2434. <input id="'.$idTagPrefix.'-action" type="hidden" name="'.htmlspecialchars($actionFieldName).'" value=""/>
  2435. '.$ctrlHeader.'
  2436. <div class="t3-form-field-record-flexsection" id="' . $idTagPrefix . '-content"' . ($toggleClosed ? ' style="display:none;"' : '') . '>' .
  2437. $this->getSingleField_typeFlex_draw(
  2438. $value['el'],
  2439. $editData[$key]['el'],
  2440. $table,
  2441. $field,
  2442. $row,
  2443. $PA,
  2444. $formPrefix.'['.$key.'][el]',
  2445. $level+1,
  2446. $idTagPrefix
  2447. ).'
  2448. </div>
  2449. <input id="'.$idTagPrefix.'-toggleClosed" type="hidden" name="'.htmlspecialchars('data['.$table.']['.$row['uid'].']['.$field.']'.$formPrefix.'[_TOGGLE]').'" value="'.($toggleClosed?1:0).'" />
  2450. </div>';
  2451. $output = str_replace('/*###REMOVE###*/', t3lib_div::slashJS(htmlspecialchars(implode('', $this->additionalJS_delete))), $output);
  2452. // NOTICE: We are saving the toggle-state directly in the flexForm XML and "unauthorized" according to the data structure. It means that flexform XML will report unclean and a cleaning operation will remove the recorded togglestates. This is not a fatal problem. Ideally we should save the toggle states in meta-data but it is much harder to do that. And this implementation was easy to make and with no really harmful impact.
  2453. }
  2454. // If it's a "single form element":
  2455. } elseif (is_array($value['TCEforms']['config'])) { // Rendering a single form element:
  2456. if (is_array($PA['_valLang'])) {
  2457. $rotateLang = $PA['_valLang'];
  2458. } else {
  2459. $rotateLang = array($PA['_valLang']);
  2460. }
  2461. $conditionData = is_array($editData) ? $editData : array();
  2462. // add current $row to data processed by isDisplayCondition()
  2463. $conditionData['parentRec'] = $row;
  2464. $tRows = array();
  2465. foreach($rotateLang as $vDEFkey) {
  2466. $vDEFkey = 'v'.$vDEFkey;
  2467. if (!$value['TCEforms']['displayCond'] || $this->isDisplayCondition($value['TCEforms']['displayCond'], $conditionData, $vDEFkey)) {
  2468. $fakePA=array();
  2469. $fakePA['fieldConf']=array(
  2470. 'label' => $this->sL(trim($value['TCEforms']['label'])),
  2471. 'config' => $value['TCEforms']['config'],
  2472. 'defaultExtras' => $value['TCEforms']['defaultExtras'],
  2473. 'onChange' => $value['TCEforms']['onChange']
  2474. );
  2475. if ($PA['_noEditDEF'] && $PA['_lang']==='lDEF') {
  2476. $fakePA['fieldConf']['config'] = array(
  2477. 'type' => 'none',
  2478. 'rows' => 2
  2479. );
  2480. }
  2481. if (
  2482. $fakePA['fieldConf']['onChange'] == 'reload' ||
  2483. ($GLOBALS['TCA'][$table]['ctrl']['type'] && !strcmp($key,$GLOBALS['TCA'][$table]['ctrl']['type'])) ||
  2484. ($GLOBALS['TCA'][$table]['ctrl']['requestUpdate'] && t3lib_div::inList($GLOBALS['TCA'][$table]['ctrl']['requestUpdate'],$key))) {
  2485. if ($GLOBALS['BE_USER']->jsConfirmation(1)) {
  2486. $alertMsgOnChange = 'if (confirm(TBE_EDITOR.labels.onChangeAlert) && TBE_EDITOR.checkSubmit(-1)){ TBE_EDITOR.submitForm() };';
  2487. } else {
  2488. $alertMsgOnChange = 'if(TBE_EDITOR.checkSubmit(-1)){ TBE_EDITOR.submitForm();}';
  2489. }
  2490. } else {
  2491. $alertMsgOnChange = '';
  2492. }
  2493. $fakePA['fieldChangeFunc']=$PA['fieldChangeFunc'];
  2494. if (strlen($alertMsgOnChange)) {
  2495. $fakePA['fieldChangeFunc']['alert']=$alertMsgOnChange;
  2496. }
  2497. $fakePA['onFocus']=$PA['onFocus'];
  2498. $fakePA['label']=$PA['label'];
  2499. $fakePA['itemFormElName']=$PA['itemFormElName'].$formPrefix.'['.$key.']['.$vDEFkey.']';
  2500. $fakePA['itemFormElName_file']=$PA['itemFormElName_file'].$formPrefix.'['.$key.']['.$vDEFkey.']';
  2501. if(isset($editData[$key][$vDEFkey])) {
  2502. $fakePA['itemFormElValue']=$editData[$key][$vDEFkey];
  2503. } else {
  2504. $fakePA['itemFormElValue']=$fakePA['fieldConf']['config']['default'];
  2505. }
  2506. $theFormEl= $this->getSingleField_SW($table,$field,$row,$fakePA);
  2507. $theTitle= htmlspecialchars($fakePA['fieldConf']['label']);
  2508. if (!in_array('DEF',$rotateLang)) {
  2509. $defInfo = '<div class="typo3-TCEforms-originalLanguageValue">' . $this->getLanguageIcon($table, $row, 0) .
  2510. $this->previewFieldValue($editData[$key]['vDEF'], $fakePA['fieldConf'], $field) . '&nbsp;</div>';
  2511. } else {
  2512. $defInfo = '';
  2513. }
  2514. if (!$PA['_noEditDEF']) {
  2515. $prLang = $this->getAdditionalPreviewLanguages();
  2516. foreach($prLang as $prL) {
  2517. $defInfo.= '<div class="typo3-TCEforms-originalLanguageValue">'.$this->getLanguageIcon($table, $row, 'v' . $prL['ISOcode']) .
  2518. $this->previewFieldValue($editData[$key]['v' . $prL['ISOcode']], $fakePA['fieldConf'], $field) . '&nbsp;</div>';
  2519. }
  2520. }
  2521. // Put row together
  2522. // possible linebreaks in the label through xml: \n => <br/>, usage of nl2br() not possible, so it's done through str_replace
  2523. $processedTitle = str_replace('\n', '<br />', $theTitle);
  2524. $helpText = $this->helpText_typeFlex($key, $processedTitle, $PA['_cshFile']);
  2525. $tRows[]='<div class="t3-form-field-container t3-form-field-container-flex">' .
  2526. '<div class="t3-form-field-label t3-form-field-label-flex">' .
  2527. ($helpText ?
  2528. ($vDEFkey=='vDEF' ? '' : $this->getLanguageIcon($table, $row, $vDEFkey)) . '<strong>' . $processedTitle . '</strong>' . $helpText :
  2529. $this->helpTextIcon_typeFlex($key, $processedTitle, $PA['_cshFile']) . ($vDEFkey == 'vDEF' ? '' : $this->getLanguageIcon($table, $row, $vDEFkey)) . $processedTitle
  2530. ) .
  2531. '</div>
  2532. <div class="t3-form-field t3-form-field-flex">'.$theFormEl.$defInfo.$this->renderVDEFDiff($editData[$key],$vDEFkey).'</div>
  2533. </div>';
  2534. }
  2535. }
  2536. if (count($tRows)) $output.= implode('',$tRows);
  2537. }
  2538. }
  2539. }
  2540. }
  2541. return $output;
  2542. }
  2543. /**
  2544. * Handler for unknown types.
  2545. *
  2546. * @param string The table name of the record
  2547. * @param string The field name which this element is supposed to edit
  2548. * @param array The record data array where the value(s) for the field can be found
  2549. * @param array An array with additional configuration options.
  2550. * @return string The HTML code for the TCEform field
  2551. */
  2552. function getSingleField_typeUnknown($table,$field,$row,&$PA) {
  2553. $item='Unknown type: '.$PA['fieldConf']['config']['form_type'].'<br />';
  2554. return $item;
  2555. }
  2556. /**
  2557. * User defined field type
  2558. *
  2559. * @param string The table name of the record
  2560. * @param string The field name which this element is supposed to edit
  2561. * @param array The record data array where the value(s) for the field can be found
  2562. * @param array An array with additional configuration options.
  2563. * @return string The HTML code for the TCEform field
  2564. */
  2565. function getSingleField_typeUser($table,$field,$row,&$PA) {
  2566. $PA['table']=$table;
  2567. $PA['field']=$field;
  2568. $PA['row']=$row;
  2569. $PA['pObj']=&$this;
  2570. return t3lib_div::callUserFunction($PA['fieldConf']['config']['userFunc'],$PA,$this);
  2571. }
  2572. /************************************************************
  2573. *
  2574. * Field content processing
  2575. *
  2576. ************************************************************/
  2577. /**
  2578. * Format field content of various types if $config['format'] is set to date, filesize, ..., user
  2579. * This is primarily for the field type none but can be used for user field types for example
  2580. *
  2581. * @param array Configuration for the display
  2582. * @param string The value to display
  2583. * @return string Formatted Field content
  2584. */
  2585. function formatValue ($config, $itemValue) {
  2586. $format = trim($config['format']);
  2587. switch($format) {
  2588. case 'date':
  2589. if ($itemValue) {
  2590. $option = trim($config['format.']['option']);
  2591. if ($option) {
  2592. if ($config['format.']['strftime']) {
  2593. $value = strftime($option,$itemValue);
  2594. } else {
  2595. $value = date($option,$itemValue);
  2596. }
  2597. } else {
  2598. $value = date('d-m-Y',$itemValue);
  2599. }
  2600. } else {
  2601. $value = '';
  2602. }
  2603. if ($config['format.']['appendAge']) {
  2604. $value .= ' (' .
  2605. t3lib_BEfunc::calcAge(($GLOBALS['EXEC_TIME'] - $itemValue), $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.minutesHoursDaysYears')) .
  2606. ')';
  2607. }
  2608. $itemValue = $value;
  2609. break;
  2610. case 'datetime': // compatibility with "eval" (type "input")
  2611. $itemValue = date('H:i d-m-Y',$itemValue);
  2612. break;
  2613. case 'time': // compatibility with "eval" (type "input")
  2614. $itemValue = date('H:i',$itemValue);
  2615. break;
  2616. case 'timesec': // compatibility with "eval" (type "input")
  2617. $itemValue = date('H:i:s',$itemValue);
  2618. break;
  2619. case 'year': // compatibility with "eval" (type "input")
  2620. $itemValue = date('Y',$itemValue);
  2621. break;
  2622. case 'int':
  2623. $baseArr = array('dec'=>'d','hex'=>'x','HEX'=>'X','oct'=>'o','bin'=>'b');
  2624. $base = trim($config['format.']['base']);
  2625. $format = $baseArr[$base] ? $baseArr[$base] : 'd';
  2626. $itemValue = sprintf('%'.$format,$itemValue);
  2627. break;
  2628. case 'float':
  2629. $precision = t3lib_div::intInRange($config['format.']['precision'],1,10,2);
  2630. $itemValue = sprintf('%.'.$precision.'f',$itemValue);
  2631. break;
  2632. case 'number':
  2633. $format = trim($config['format.']['option']);
  2634. $itemValue = sprintf('%'.$format,$itemValue);
  2635. break;
  2636. case 'md5':
  2637. $itemValue = md5($itemValue);
  2638. break;
  2639. case 'filesize':
  2640. $value = t3lib_div::formatSize(intval($itemValue));
  2641. if ($config['format.']['appendByteSize']) {
  2642. $value .= ' ('.$itemValue.')';
  2643. }
  2644. $itemValue = $value;
  2645. break;
  2646. case 'user':
  2647. $func = trim($config['format.']['userFunc']);
  2648. if ($func) {
  2649. $params = array(
  2650. 'value' => $itemValue,
  2651. 'args' => $config['format.']['userFunc'],
  2652. 'config' => $config,
  2653. 'pObj' => &$this
  2654. );
  2655. $itemValue = t3lib_div::callUserFunction($func,$params,$this);
  2656. }
  2657. break;
  2658. default:
  2659. break;
  2660. }
  2661. return $itemValue;
  2662. }
  2663. /************************************************************
  2664. *
  2665. * "Configuration" fetching/processing functions
  2666. *
  2667. ************************************************************/
  2668. /**
  2669. * Calculate and return the current "types" pointer value for a record
  2670. *
  2671. * @param string The table name. MUST be in $TCA
  2672. * @param array The row from the table, should contain at least the "type" field, if applicable.
  2673. * @return string Return the "type" value for this record, ready to pick a "types" configuration from the $TCA array.
  2674. */
  2675. function getRTypeNum($table,$row) {
  2676. global $TCA;
  2677. // If there is a "type" field configured...
  2678. if ($TCA[$table]['ctrl']['type']) {
  2679. $typeFieldName = $TCA[$table]['ctrl']['type'];
  2680. $typeFieldConfig = $TCA[$table]['columns'][$typeFieldName];
  2681. $typeNum = $this->getLanguageOverlayRawValue($table, $row, $typeFieldName, $typeFieldConfig);
  2682. if (!strcmp($typeNum,'')) $typeNum=0; // If that value is an empty string, set it to "0" (zero)
  2683. } else {
  2684. $typeNum = 0; // If no "type" field, then set to "0" (zero)
  2685. }
  2686. $typeNum = (string)$typeNum; // Force to string. Necessary for eg '-1' to be recognized as a type value.
  2687. if (!$TCA[$table]['types'][$typeNum]) { // However, if the type "0" is not found in the "types" array, then default to "1" (for historical reasons)
  2688. $typeNum = 1;
  2689. }
  2690. return $typeNum;
  2691. }
  2692. /**
  2693. * Used to adhoc-rearrange the field order normally set in the [types][showitem] list
  2694. *
  2695. * @param array A [types][showitem] list of fields, exploded by ","
  2696. * @return array Returns rearranged version (keys are changed around as well.)
  2697. * @see getMainFields()
  2698. */
  2699. function rearrange($fields) {
  2700. $fO = array_flip(t3lib_div::trimExplode(',',$this->fieldOrder,1));
  2701. $newFields=array();
  2702. foreach($fields as $cc => $content) {
  2703. $cP = t3lib_div::trimExplode(';',$content);
  2704. if (isset($fO[$cP[0]])) {
  2705. $newFields[$fO[$cP[0]]] = $content;
  2706. unset($fields[$cc]);
  2707. }
  2708. }
  2709. ksort($newFields);
  2710. $fields=array_merge($newFields,$fields); // Candidate for t3lib_div::array_merge() if integer-keys will some day make trouble...
  2711. return $fields;
  2712. }
  2713. /**
  2714. * Producing an array of field names NOT to display in the form, based on settings from subtype_value_field, bitmask_excludelist_bits etc.
  2715. * Notice, this list is in NO way related to the "excludeField" flag
  2716. *
  2717. * @param string Table name, MUST be in $TCA
  2718. * @param array A record from table.
  2719. * @param string A "type" pointer value, probably the one calculated based on the record array.
  2720. * @return array Array with fieldnames as values. The fieldnames are those which should NOT be displayed "anyways"
  2721. * @see getMainFields()
  2722. */
  2723. function getExcludeElements($table,$row,$typeNum) {
  2724. global $TCA;
  2725. // Init:
  2726. $excludeElements=array();
  2727. // If a subtype field is defined for the type
  2728. if ($TCA[$table]['types'][$typeNum]['subtype_value_field']) {
  2729. $sTfield = $TCA[$table]['types'][$typeNum]['subtype_value_field'];
  2730. if (trim($TCA[$table]['types'][$typeNum]['subtypes_excludelist'][$row[$sTfield]])) {
  2731. $excludeElements=t3lib_div::trimExplode(',',$TCA[$table]['types'][$typeNum]['subtypes_excludelist'][$row[$sTfield]],1);
  2732. }
  2733. }
  2734. // If a bitmask-value field has been configured, then find possible fields to exclude based on that:
  2735. if ($TCA[$table]['types'][$typeNum]['bitmask_value_field']) {
  2736. $sTfield = $TCA[$table]['types'][$typeNum]['bitmask_value_field'];
  2737. $sTValue = t3lib_div::intInRange($row[$sTfield],0);
  2738. if (is_array($TCA[$table]['types'][$typeNum]['bitmask_excludelist_bits'])) {
  2739. foreach($TCA[$table]['types'][$typeNum]['bitmask_excludelist_bits'] as $bitKey => $eList) {
  2740. $bit=substr($bitKey,1);
  2741. if (t3lib_div::testInt($bit)) {
  2742. $bit = t3lib_div::intInRange($bit,0,30);
  2743. if (
  2744. (substr($bitKey,0,1)=='-' && !($sTValue&pow(2,$bit))) ||
  2745. (substr($bitKey,0,1)=='+' && ($sTValue&pow(2,$bit)))
  2746. ) {
  2747. $excludeElements = array_merge($excludeElements,t3lib_div::trimExplode(',',$eList,1));
  2748. }
  2749. }
  2750. }
  2751. }
  2752. }
  2753. // Return the array of elements:
  2754. return $excludeElements;
  2755. }
  2756. /**
  2757. * Finds possible field to add to the form, based on subtype fields.
  2758. *
  2759. * @param string Table name, MUST be in $TCA
  2760. * @param array A record from table.
  2761. * @param string A "type" pointer value, probably the one calculated based on the record array.
  2762. * @return array An array containing two values: 1) Another array containing fieldnames to add and 2) the subtype value field.
  2763. * @see getMainFields()
  2764. */
  2765. function getFieldsToAdd($table,$row,$typeNum) {
  2766. global $TCA;
  2767. // Init:
  2768. $addElements=array();
  2769. // If a subtype field is defined for the type
  2770. if ($TCA[$table]['types'][$typeNum]['subtype_value_field']) {
  2771. $sTfield = $TCA[$table]['types'][$typeNum]['subtype_value_field'];
  2772. if (trim($TCA[$table]['types'][$typeNum]['subtypes_addlist'][$row[$sTfield]])) {
  2773. $addElements=t3lib_div::trimExplode(',',$TCA[$table]['types'][$typeNum]['subtypes_addlist'][$row[$sTfield]],1);
  2774. }
  2775. }
  2776. // Return the return
  2777. return array($addElements,$sTfield);
  2778. }
  2779. /**
  2780. * Merges the current [types][showitem] array with the array of fields to add for the current subtype field of the "type" value.
  2781. *
  2782. * @param array A [types][showitem] list of fields, exploded by ","
  2783. * @param array The output from getFieldsToAdd()
  2784. * @return array Return the modified $fields array.
  2785. * @see getMainFields(),getFieldsToAdd()
  2786. */
  2787. function mergeFieldsWithAddedFields($fields,$fieldsToAdd) {
  2788. if (count($fieldsToAdd[0])) {
  2789. $c=0;
  2790. foreach($fields as $fieldInfo) {
  2791. $parts = explode(';',$fieldInfo);
  2792. if (!strcmp(trim($parts[0]),$fieldsToAdd[1])) {
  2793. array_splice(
  2794. $fields,
  2795. $c+1,
  2796. 0,
  2797. $fieldsToAdd[0]
  2798. );
  2799. break;
  2800. }
  2801. $c++;
  2802. }
  2803. }
  2804. return $fields;
  2805. }
  2806. /**
  2807. * Returns TSconfig for table/row
  2808. * 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.
  2809. *
  2810. * @param string The table name
  2811. * @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.)
  2812. * @param string Optionally you can specify the field name as well. In that case the TSconfig for the field is returned.
  2813. * @return mixed The TSconfig values (probably in an array)
  2814. * @see t3lib_BEfunc::getTCEFORM_TSconfig()
  2815. */
  2816. function setTSconfig($table,$row,$field='') {
  2817. $mainKey = $table.':'.$row['uid'];
  2818. if (!isset($this->cachedTSconfig[$mainKey])) {
  2819. $this->cachedTSconfig[$mainKey]=t3lib_BEfunc::getTCEFORM_TSconfig($table,$row);
  2820. }
  2821. if ($field) {
  2822. return $this->cachedTSconfig[$mainKey][$field];
  2823. } else {
  2824. return $this->cachedTSconfig[$mainKey];
  2825. }
  2826. }
  2827. /**
  2828. * Overrides the TCA field configuration by TSconfig settings.
  2829. *
  2830. * Example TSconfig: TCEform.<table>.<field>.config.appearance.useSortable = 1
  2831. * This overrides the setting in $TCA[<table>]['columns'][<field>]['config']['appearance']['useSortable'].
  2832. *
  2833. * @param array $fieldConfig: TCA field configuration
  2834. * @param array $TSconfig: TSconfig
  2835. * @return array Changed TCA field configuration
  2836. */
  2837. function overrideFieldConf($fieldConfig, $TSconfig) {
  2838. if (is_array($TSconfig)) {
  2839. $TSconfig = t3lib_div::removeDotsFromTS($TSconfig);
  2840. $type = $fieldConfig['type'];
  2841. if (is_array($TSconfig['config']) && is_array($this->allowOverrideMatrix[$type])) {
  2842. // Check if the keys in TSconfig['config'] are allowed to override TCA field config:
  2843. foreach (array_keys($TSconfig['config']) as $key) {
  2844. if (!in_array($key, $this->allowOverrideMatrix[$type], true)) {
  2845. unset($TSconfig['config'][$key]);
  2846. }
  2847. }
  2848. // Override TCA field config by remaining TSconfig['config']:
  2849. if (count($TSconfig['config'])) {
  2850. $fieldConfig = t3lib_div::array_merge_recursive_overrule($fieldConfig, $TSconfig['config']);
  2851. }
  2852. }
  2853. }
  2854. return $fieldConfig;
  2855. }
  2856. /**
  2857. * Returns the "special" configuration (from the "types" "showitem" list) for a fieldname based on input table/record
  2858. * (Not used anywhere...?)
  2859. *
  2860. * @param string The table name
  2861. * @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.)
  2862. * @param string Specify the field name.
  2863. * @return array
  2864. * @see getSpecConfFromString(), t3lib_BEfunc::getTCAtypes()
  2865. */
  2866. function getSpecConfForField($table,$row,$field) {
  2867. // Finds the current "types" configuration for the table/row:
  2868. $types_fieldConfig = t3lib_BEfunc::getTCAtypes($table,$row);
  2869. // If this is an array, then traverse it:
  2870. if (is_array($types_fieldConfig)) {
  2871. foreach($types_fieldConfig as $vconf) {
  2872. // If the input field name matches one found in the 'types' list, then return the 'special' configuration.
  2873. if ($vconf['field']==$field) return $vconf['spec'];
  2874. }
  2875. }
  2876. }
  2877. /**
  2878. * Returns the "special" configuration of an "extra" string (non-parsed)
  2879. *
  2880. * @param string The "Part 4" of the fields configuration in "types" "showitem" lists.
  2881. * @param string The ['defaultExtras'] value from field configuration
  2882. * @return array An array with the special options in.
  2883. * @see getSpecConfForField(), t3lib_BEfunc::getSpecConfParts()
  2884. */
  2885. function getSpecConfFromString($extraString, $defaultExtras) {
  2886. return t3lib_BEfunc::getSpecConfParts($extraString, $defaultExtras);
  2887. }
  2888. /**
  2889. * Loads the elements of a palette (collection of secondary options) in an array.
  2890. *
  2891. * @param string The table name
  2892. * @param array The row array
  2893. * @param string The palette number/pointer
  2894. * @param string Optional alternative list of fields for the palette
  2895. * @return array The palette elements
  2896. */
  2897. public function loadPaletteElements($table, $row, $palette, $itemList='') {
  2898. global $TCA;
  2899. t3lib_div::loadTCA($table);
  2900. $parts = array();
  2901. // Getting excludeElements, if any.
  2902. if (!is_array($this->excludeElements)) {
  2903. $this->excludeElements = $this->getExcludeElements($table, $row, $this->getRTypeNum($table,$row));
  2904. }
  2905. // Load the palette TCEform elements
  2906. if ($TCA[$table] && (is_array($TCA[$table]['palettes'][$palette]) || $itemList)) {
  2907. $itemList = ($itemList ? $itemList : $TCA[$table]['palettes'][$palette]['showitem']);
  2908. if ($itemList) {
  2909. $fields = t3lib_div::trimExplode(',',$itemList,1);
  2910. foreach($fields as $info) {
  2911. $fieldParts = t3lib_div::trimExplode(';',$info);
  2912. $theField = $fieldParts[0];
  2913. if ($theField === '--linebreak--') {
  2914. $parts[]['NAME'] = '--linebreak--';
  2915. } elseif (!in_array($theField,$this->excludeElements) && $TCA[$table]['columns'][$theField]) {
  2916. $this->palFieldArr[$palette][] = $theField;
  2917. $elem = $this->getSingleField($table,$theField,$row,$fieldParts[1],1,'',$fieldParts[2]);
  2918. if (is_array($elem)) {
  2919. $parts[] = $elem;
  2920. }
  2921. }
  2922. }
  2923. }
  2924. }
  2925. return $parts;
  2926. }
  2927. /************************************************************
  2928. *
  2929. * Display of localized content etc.
  2930. *
  2931. ************************************************************/
  2932. /**
  2933. * Will register data from original language records if the current record is a translation of another.
  2934. * The original data is shown with the edited record in the form. The information also includes possibly diff-views of what changed in the original record.
  2935. * Function called from outside (see alt_doc.php + quick edit) before rendering a form for a record
  2936. *
  2937. * @param string Table name of the record being edited
  2938. * @param array Record array of the record being edited
  2939. * @return void
  2940. */
  2941. function registerDefaultLanguageData($table,$rec) {
  2942. global $TCA;
  2943. // Add default language:
  2944. if ($TCA[$table]['ctrl']['languageField']
  2945. && $rec[$TCA[$table]['ctrl']['languageField']] > 0
  2946. && $TCA[$table]['ctrl']['transOrigPointerField']
  2947. && intval($rec[$TCA[$table]['ctrl']['transOrigPointerField']]) > 0) {
  2948. $lookUpTable = $TCA[$table]['ctrl']['transOrigPointerTable'] ? $TCA[$table]['ctrl']['transOrigPointerTable'] : $table;
  2949. // Get data formatted:
  2950. $this->defaultLanguageData[$table.':'.$rec['uid']] = t3lib_BEfunc::getRecordWSOL($lookUpTable, intval($rec[$TCA[$table]['ctrl']['transOrigPointerField']]));
  2951. // Get data for diff:
  2952. if ($TCA[$table]['ctrl']['transOrigDiffSourceField']) {
  2953. $this->defaultLanguageData_diff[$table.':'.$rec['uid']] = unserialize($rec[$TCA[$table]['ctrl']['transOrigDiffSourceField']]);
  2954. }
  2955. // If there are additional preview languages, load information for them also:
  2956. $prLang = $this->getAdditionalPreviewLanguages();
  2957. foreach($prLang as $prL) {
  2958. $t8Tools = t3lib_div::makeInstance('t3lib_transl8tools');
  2959. $tInfo = $t8Tools->translationInfo($lookUpTable,intval($rec[$TCA[$table]['ctrl']['transOrigPointerField']]),$prL['uid']);
  2960. if (is_array($tInfo['translations'][$prL['uid']])) {
  2961. $this->additionalPreviewLanguageData[$table.':'.$rec['uid']][$prL['uid']] = t3lib_BEfunc::getRecordWSOL($table, intval($tInfo['translations'][$prL['uid']]['uid']));
  2962. }
  2963. }
  2964. }
  2965. }
  2966. /**
  2967. * Creates language-overlay for a field value
  2968. * This means the requested field value will be overridden with the data from the default language.
  2969. * Can be used to render read only fields for example.
  2970. *
  2971. * @param string Table name of the record being edited
  2972. * @param string Field name represented by $item
  2973. * @param array Record array of the record being edited in current language
  2974. * @param array Content of $PA['fieldConf']
  2975. * @return string Unprocessed field value merged with default language data if needed
  2976. */
  2977. function getLanguageOverlayRawValue($table, $row, $field, $fieldConf) {
  2978. global $TCA;
  2979. $value = $row[$field];
  2980. if (is_array($this->defaultLanguageData[$table.':'.$row['uid']])) {
  2981. if ($fieldConf['l10n_mode']=='exclude'
  2982. || ($fieldConf['l10n_mode']=='mergeIfNotBlank' && strcmp(trim($this->defaultLanguageData[$table.':'.$row['uid']][$field]),''))) {
  2983. $value = $this->defaultLanguageData[$table.':'.$row['uid']][$field];
  2984. }
  2985. }
  2986. return $value;
  2987. }
  2988. /**
  2989. * Renders the display of default language record content around current field.
  2990. * Will render content if any is found in the internal array, $this->defaultLanguageData, depending on registerDefaultLanguageData() being called prior to this.
  2991. *
  2992. * @param string Table name of the record being edited
  2993. * @param string Field name represented by $item
  2994. * @param array Record array of the record being edited
  2995. * @param string HTML of the form field. This is what we add the content to.
  2996. * @return string Item string returned again, possibly with the original value added to.
  2997. * @see getSingleField(), registerDefaultLanguageData()
  2998. */
  2999. function renderDefaultLanguageContent($table,$field,$row,$item) {
  3000. if (is_array($this->defaultLanguageData[$table.':'.$row['uid']])) {
  3001. $dLVal = t3lib_BEfunc::getProcessedValue($table,$field,$this->defaultLanguageData[$table.':'.$row['uid']][$field],0,1);
  3002. $fCfg = $GLOBALS['TCA'][$table]['columns'][$field];
  3003. // Don't show content if it's for IRRE child records:
  3004. if ($fCfg['config']['type']!='inline') {
  3005. if (strcmp($dLVal,'')) {
  3006. $item .= '<div class="typo3-TCEforms-originalLanguageValue">' . $this->getLanguageIcon($table, $row, 0) .
  3007. $this->previewFieldValue($dLVal, $fCfg, $field) . '&nbsp;</div>';
  3008. }
  3009. $prLang = $this->getAdditionalPreviewLanguages();
  3010. foreach($prLang as $prL) {
  3011. $dlVal = t3lib_BEfunc::getProcessedValue($table,$field,$this->additionalPreviewLanguageData[$table.':'.$row['uid']][$prL['uid']][$field],0,1);
  3012. if(strcmp($dlVal, '')) {
  3013. $item .= '<div class="typo3-TCEforms-originalLanguageValue">' . $this->getLanguageIcon($table, $row, 'v' . $prL['ISOcode']) .
  3014. $this->previewFieldValue($dlVal, $fCfg, $field) . '&nbsp;</div>';
  3015. }
  3016. }
  3017. }
  3018. }
  3019. return $item;
  3020. }
  3021. /**
  3022. * Renders the diff-view of default language record content compared with what the record was originally translated from.
  3023. * Will render content if any is found in the internal array, $this->defaultLanguageData, depending on registerDefaultLanguageData() being called prior to this.
  3024. *
  3025. * @param string Table name of the record being edited
  3026. * @param string Field name represented by $item
  3027. * @param array Record array of the record being edited
  3028. * @param string HTML of the form field. This is what we add the content to.
  3029. * @return string Item string returned again, possibly with the original value added to.
  3030. * @see getSingleField(), registerDefaultLanguageData()
  3031. */
  3032. function renderDefaultLanguageDiff($table,$field,$row,$item) {
  3033. if (is_array($this->defaultLanguageData_diff[$table.':'.$row['uid']])) {
  3034. // Initialize:
  3035. $dLVal = array(
  3036. 'old' => $this->defaultLanguageData_diff[$table.':'.$row['uid']],
  3037. 'new' => $this->defaultLanguageData[$table.':'.$row['uid']],
  3038. );
  3039. if (isset($dLVal['old'][$field])) { // There must be diff-data:
  3040. if (strcmp($dLVal['old'][$field],$dLVal['new'][$field])) {
  3041. // Create diff-result:
  3042. $t3lib_diff_Obj = t3lib_div::makeInstance('t3lib_diff');
  3043. $diffres = $t3lib_diff_Obj->makeDiffDisplay(
  3044. t3lib_BEfunc::getProcessedValue($table,$field,$dLVal['old'][$field],0,1),
  3045. t3lib_BEfunc::getProcessedValue($table,$field,$dLVal['new'][$field],0,1)
  3046. );
  3047. $item.='<div class="typo3-TCEforms-diffBox">'.
  3048. '<div class="typo3-TCEforms-diffBox-header">'.htmlspecialchars($this->getLL('l_changeInOrig')).':</div>'.
  3049. $diffres.
  3050. '</div>';
  3051. }
  3052. }
  3053. }
  3054. return $item;
  3055. }
  3056. /**
  3057. * Renders the diff-view of vDEF fields in flexforms
  3058. *
  3059. * @param string Table name of the record being edited
  3060. * @param string Field name represented by $item
  3061. * @param array Record array of the record being edited
  3062. * @param string HTML of the form field. This is what we add the content to.
  3063. * @return string Item string returned again, possibly with the original value added to.
  3064. * @see getSingleField(), registerDefaultLanguageData()
  3065. */
  3066. function renderVDEFDiff($vArray,$vDEFkey) {
  3067. if ($GLOBALS['TYPO3_CONF_VARS']['BE']['flexFormXMLincludeDiffBase'] && isset($vArray[$vDEFkey.'.vDEFbase']) && strcmp($vArray[$vDEFkey.'.vDEFbase'],$vArray['vDEF'])) {
  3068. // Create diff-result:
  3069. $t3lib_diff_Obj = t3lib_div::makeInstance('t3lib_diff');
  3070. $diffres = $t3lib_diff_Obj->makeDiffDisplay($vArray[$vDEFkey.'.vDEFbase'],$vArray['vDEF']);
  3071. $item.='<div class="typo3-TCEforms-diffBox">'.
  3072. '<div class="typo3-TCEforms-diffBox-header">'.htmlspecialchars($this->getLL('l_changeInOrig')).':</div>'.
  3073. $diffres.
  3074. '</div>';
  3075. }
  3076. return $item;
  3077. }
  3078. /************************************************************
  3079. *
  3080. * Form element helper functions
  3081. *
  3082. ************************************************************/
  3083. /**
  3084. * Prints the selector box form-field for the db/file/select elements (multiple)
  3085. *
  3086. * @param string Form element name
  3087. * @param string Mode "db", "file" (internal_type for the "group" type) OR blank (then for the "select" type)
  3088. * @param string Commalist of "allowed"
  3089. * @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.
  3090. * @param string Alternative selector box.
  3091. * @param array An array of additional parameters, eg: "size", "info", "headers" (array with "selector" and "items"), "noBrowser", "thumbnails"
  3092. * @param string On focus attribute string
  3093. * @param string $table: (optional) Table name processing for
  3094. * @param string $field: (optional) Field of table name processing for
  3095. * @param string $uid: (optional) uid of table record processing for
  3096. * @return string The form fields for the selection.
  3097. */
  3098. function dbFileIcons($fName,$mode,$allowed,$itemArray,$selector='',$params=array(),$onFocus='',$table='',$field='',$uid='') {
  3099. $disabled = '';
  3100. if($this->renderReadonly || $params['readOnly']) {
  3101. $disabled = ' disabled="disabled"';
  3102. }
  3103. // Sets a flag which means some JavaScript is included on the page to support this element.
  3104. $this->printNeededJS['dbFileIcons']=1;
  3105. // INIT
  3106. $uidList=array();
  3107. $opt=array();
  3108. $itemArrayC=0;
  3109. // Creating <option> elements:
  3110. if (is_array($itemArray)) {
  3111. $itemArrayC=count($itemArray);
  3112. switch($mode) {
  3113. case 'db':
  3114. foreach ($itemArray as $pp) {
  3115. $pRec = t3lib_BEfunc::getRecordWSOL($pp['table'],$pp['id']);
  3116. if (is_array($pRec)) {
  3117. $pTitle = t3lib_BEfunc::getRecordTitle($pp['table'], $pRec, FALSE, TRUE);
  3118. $pUid = $pp['table'].'_'.$pp['id'];
  3119. $uidList[]=$pUid;
  3120. $opt[]='<option value="'.htmlspecialchars($pUid).'">'.htmlspecialchars($pTitle).'</option>';
  3121. }
  3122. }
  3123. break;
  3124. case 'file_reference':
  3125. case 'file':
  3126. foreach ($itemArray as $item) {
  3127. $itemParts = explode('|', $item);
  3128. $uidList[] = $pUid = $pTitle = $itemParts[0];
  3129. $opt[] = '<option value="' . htmlspecialchars(rawurldecode($itemParts[0])) . '">' . htmlspecialchars(basename(rawurldecode($itemParts[0]))) . '</option>';
  3130. }
  3131. break;
  3132. case 'folder':
  3133. foreach ($itemArray as $pp) {
  3134. $pParts = explode('|',$pp);
  3135. $uidList[]=$pUid=$pTitle = $pParts[0];
  3136. $opt[]='<option value="'.htmlspecialchars(rawurldecode($pParts[0])).'">'.htmlspecialchars(rawurldecode($pParts[0])).'</option>';
  3137. }
  3138. break;
  3139. default:
  3140. foreach ($itemArray as $pp) {
  3141. $pParts = explode('|',$pp, 2);
  3142. $uidList[]=$pUid=$pParts[0];
  3143. $pTitle = $pParts[1];
  3144. $opt[]='<option value="'.htmlspecialchars(rawurldecode($pUid)).'">'.htmlspecialchars(rawurldecode($pTitle)).'</option>';
  3145. }
  3146. break;
  3147. }
  3148. }
  3149. // Create selector box of the options
  3150. $sSize = $params['autoSizeMax'] ? t3lib_div::intInRange($itemArrayC+1,t3lib_div::intInRange($params['size'],1),$params['autoSizeMax']) : $params['size'];
  3151. if (!$selector) {
  3152. $selector = '<select id="' . uniqid('tceforms-multiselect-') . '" ' . ($params['noList'] ? 'style="display: none"' : 'size="'.$sSize.'"'.$this->insertDefStyle('group', 'tceforms-multiselect')).' multiple="multiple" name="'.$fName.'_list" '.$onFocus.$params['style'].$disabled.'>'.implode('',$opt).'</select>';
  3153. }
  3154. $icons = array(
  3155. 'L' => array(),
  3156. 'R' => array(),
  3157. );
  3158. if (!$params['readOnly'] && !$params['noList']) {
  3159. if (!$params['noBrowser']) {
  3160. // check against inline uniqueness
  3161. $inlineParent = $this->inline->getStructureLevel(-1);
  3162. if(is_array($inlineParent) && $inlineParent['uid']) {
  3163. if ($inlineParent['config']['foreign_table'] == $table && $inlineParent['config']['foreign_unique'] == $field) {
  3164. $objectPrefix = $this->inline->inlineNames['object'].'['.$table.']';
  3165. $aOnClickInline = $objectPrefix.'|inline.checkUniqueElement|inline.setUniqueElement';
  3166. $rOnClickInline = 'inline.revertUnique(\''.$objectPrefix.'\',null,\''.$uid.'\');';
  3167. }
  3168. }
  3169. $aOnClick='setFormValueOpenBrowser(\''.$mode.'\',\''.($fName.'|||'.$allowed.'|'.$aOnClickInline).'\'); return false;';
  3170. $icons['R'][]='<a href="#" onclick="'.htmlspecialchars($aOnClick).'">'.
  3171. t3lib_iconWorks::getSpriteIcon('actions-insert-record', array('title' => htmlspecialchars($this->getLL('l_browse_' . ($mode == 'db' ? 'db' : 'file'))))) .
  3172. '</a>';
  3173. }
  3174. if (!$params['dontShowMoveIcons']) {
  3175. if ($sSize>=5) {
  3176. $icons['L'][]='<a href="#" onclick="setFormValueManipulate(\''.$fName.'\',\'Top\'); return false;">'.
  3177. t3lib_iconWorks::getSpriteIcon('actions-move-to-top', array('title' => htmlspecialchars($this->getLL('l_move_to_top')))) .
  3178. '</a>';
  3179. }
  3180. $icons['L'][]='<a href="#" onclick="setFormValueManipulate(\''.$fName.'\',\'Up\'); return false;">'.
  3181. t3lib_iconWorks::getSpriteIcon('actions-move-up', array('title' => htmlspecialchars($this->getLL('l_move_up')))) .
  3182. '</a>';
  3183. $icons['L'][]='<a href="#" onclick="setFormValueManipulate(\''.$fName.'\',\'Down\'); return false;">'.
  3184. t3lib_iconWorks::getSpriteIcon('actions-move-down', array('title' => htmlspecialchars($this->getLL('l_move_down')))) .
  3185. '</a>';
  3186. if ($sSize>=5) {
  3187. $icons['L'][]='<a href="#" onclick="setFormValueManipulate(\''.$fName.'\',\'Bottom\'); return false;">'.
  3188. t3lib_iconWorks::getSpriteIcon('actions-move-to-bottom', array('title' => htmlspecialchars($this->getLL('l_move_to_bottom')))) .
  3189. '</a>';
  3190. }
  3191. }
  3192. $clipElements = $this->getClipboardElements($allowed,$mode);
  3193. if (count($clipElements)) {
  3194. $aOnClick = '';
  3195. foreach($clipElements as $elValue) {
  3196. if ($mode == 'db') {
  3197. list($itemTable,$itemUid) = explode('|', $elValue);
  3198. $itemTitle = $GLOBALS['LANG']->JScharCode(t3lib_BEfunc::getRecordTitle($itemTable, t3lib_BEfunc::getRecordWSOL($itemTable,$itemUid)));
  3199. $elValue = $itemTable.'_'.$itemUid;
  3200. } else {
  3201. // 'file', 'file_reference' and 'folder' mode
  3202. $itemTitle = 'unescape(\'' . rawurlencode(basename($elValue)) . '\')';
  3203. }
  3204. $aOnClick.= 'setFormValueFromBrowseWin(\''.$fName.'\',unescape(\''.rawurlencode(str_replace('%20',' ',$elValue)).'\'),'.$itemTitle.');';
  3205. }
  3206. $aOnClick.= 'return false;';
  3207. $icons['R'][]='<a href="#" onclick="'.htmlspecialchars($aOnClick).'">'.
  3208. t3lib_iconWorks::getSpriteIcon('actions-document-paste-into', array('title' => htmlspecialchars(sprintf($this->getLL('l_clipInsert_' . ($mode == 'db' ? 'db' : 'file')), count($clipElements))))) .
  3209. '</a>';
  3210. }
  3211. $rOnClick = $rOnClickInline.'setFormValueManipulate(\''.$fName.'\',\'Remove\'); return false';
  3212. $icons['L'][]='<a href="#" onclick="'.htmlspecialchars($rOnClick).'">'.
  3213. t3lib_iconWorks::getSpriteIcon('actions-selection-delete', array('title' => htmlspecialchars($this->getLL('l_remove_selected')))) .
  3214. '</a>';
  3215. }
  3216. $str='<table border="0" cellpadding="0" cellspacing="0" width="1">
  3217. '.($params['headers']?'
  3218. <tr>
  3219. <td>'.$this->wrapLabels($params['headers']['selector']).'</td>
  3220. <td></td>
  3221. <td></td>
  3222. <td>'.($params['thumbnails'] ? $this->wrapLabels($params['headers']['items']) : '').'</td>
  3223. </tr>':'').
  3224. '
  3225. <tr>
  3226. <td valign="top">'.
  3227. $selector.
  3228. ($params['noList'] ? '' : '<br />'.$this->wrapLabels($params['info'])) .
  3229. '</td>
  3230. <td valign="top" class="icons">'.
  3231. implode('<br />',$icons['L']).'</td>
  3232. <td valign="top" class="icons">'.
  3233. implode('<br />',$icons['R']).'</td>
  3234. <td valign="top" class="thumbnails">'.
  3235. $this->wrapLabels($params['thumbnails']).
  3236. '</td>
  3237. </tr>
  3238. </table>';
  3239. // Creating the hidden field which contains the actual value as a comma list.
  3240. $str.='<input type="hidden" name="'.$fName.'" value="'.htmlspecialchars(implode(',',$uidList)).'" />';
  3241. return $str;
  3242. }
  3243. /**
  3244. * Returns array of elements from clipboard to insert into GROUP element box.
  3245. *
  3246. * @param string Allowed elements, Eg "pages,tt_content", "gif,jpg,jpeg,png"
  3247. * @param string Mode of relations: "db" or "file"
  3248. * @return array Array of elements in values (keys are insignificant), if none found, empty array.
  3249. */
  3250. function getClipboardElements($allowed,$mode) {
  3251. $output = array();
  3252. if (is_object($this->clipObj)) {
  3253. switch($mode) {
  3254. case 'file_reference':
  3255. case 'file':
  3256. $elFromTable = $this->clipObj->elFromTable('_FILE');
  3257. $allowedExts = t3lib_div::trimExplode(',', $allowed, 1);
  3258. if ($allowedExts) { // If there are a set of allowed extensions, filter the content:
  3259. foreach($elFromTable as $elValue) {
  3260. $pI = pathinfo($elValue);
  3261. $ext = strtolower($pI['extension']);
  3262. if (in_array($ext, $allowedExts)) {
  3263. $output[] = $elValue;
  3264. }
  3265. }
  3266. } else { // If all is allowed, insert all: (This does NOT respect any disallowed extensions, but those will be filtered away by the backend TCEmain)
  3267. $output = $elFromTable;
  3268. }
  3269. break;
  3270. case 'db':
  3271. $allowedTables = t3lib_div::trimExplode(',', $allowed, 1);
  3272. if (!strcmp(trim($allowedTables[0]),'*')) { // All tables allowed for relation:
  3273. $output = $this->clipObj->elFromTable('');
  3274. } else { // Only some tables, filter them:
  3275. foreach($allowedTables as $tablename) {
  3276. $elFromTable = $this->clipObj->elFromTable($tablename);
  3277. $output = array_merge($output,$elFromTable);
  3278. }
  3279. }
  3280. $output = array_keys($output);
  3281. break;
  3282. }
  3283. }
  3284. return $output;
  3285. }
  3286. /**
  3287. * Wraps the icon of a relation item (database record or file) in a link opening the context menu for the item.
  3288. * Icons will be wrapped only if $this->enableClickMenu is set. This must be done only if a global SOBE object exists and if the necessary JavaScript for displaying the context menus has been added to the page properties.
  3289. *
  3290. * @param string The icon HTML to wrap
  3291. * @param string Table name (eg. "pages" or "tt_content") OR the absolute path to the file
  3292. * @param integer The uid of the record OR if file, just blank value.
  3293. * @return string HTML
  3294. */
  3295. function getClickMenu($str,$table,$uid='') {
  3296. if ($this->enableClickMenu) {
  3297. $onClick = $GLOBALS['SOBE']->doc->wrapClickMenuOnIcon($str,$table,$uid,1,'','+copy,info,edit,view', TRUE);
  3298. return '<a href="#" onclick="'.htmlspecialchars($onClick).'">'.$str.'</a>';
  3299. }
  3300. }
  3301. /**
  3302. * Rendering wizards for form fields.
  3303. *
  3304. * @param array Array with the real item in the first value, and an alternative item in the second value.
  3305. * @param array The "wizard" key from the config array for the field (from TCA)
  3306. * @param string Table name
  3307. * @param array The record array
  3308. * @param string The field name
  3309. * @param array Additional configuration array. (passed by reference!)
  3310. * @param string The field name
  3311. * @param array Special configuration if available.
  3312. * @param boolean Whether the RTE could have been loaded.
  3313. * @return string The new item value.
  3314. */
  3315. function renderWizards($itemKinds,$wizConf,$table,$row,$field,&$PA,$itemName,$specConf,$RTE=0) {
  3316. // Init:
  3317. $fieldChangeFunc = $PA['fieldChangeFunc'];
  3318. $item = $itemKinds[0];
  3319. $outArr = array();
  3320. $colorBoxLinks = array();
  3321. $fName = '['.$table.']['.$row['uid'].']['.$field.']';
  3322. $md5ID = 'ID'.t3lib_div::shortmd5($itemName);
  3323. $listFlag = '_list';
  3324. $prefixOfFormElName = 'data['.$table.']['.$row['uid'].']['.$field.']';
  3325. if (t3lib_div::isFirstPartOfStr($PA['itemFormElName'],$prefixOfFormElName)) {
  3326. $flexFormPath = str_replace('][','/',substr($PA['itemFormElName'],strlen($prefixOfFormElName)+1,-1));
  3327. }
  3328. // Manipulate the field name (to be the true form field name) and remove a suffix-value if the item is a selector box with renderMode "singlebox":
  3329. if ($PA['fieldConf']['config']['form_type']=='select') {
  3330. if ($PA['fieldConf']['config']['maxitems']<=1) { // Single select situation:
  3331. $listFlag = '';
  3332. } elseif ($PA['fieldConf']['config']['renderMode']=='singlebox') {
  3333. $itemName.='[]';
  3334. $listFlag = '';
  3335. }
  3336. }
  3337. // traverse wizards:
  3338. if (is_array($wizConf) && !$this->disableWizards) {
  3339. $parametersOfWizards =& $specConf['wizards']['parameters'];
  3340. foreach($wizConf as $wid => $wConf) {
  3341. if (substr($wid,0,1)!='_'
  3342. && (!$wConf['enableByTypeConfig'] || is_array($parametersOfWizards) && in_array($wid, $parametersOfWizards))
  3343. && ($RTE || !$wConf['RTEonly'])
  3344. ) {
  3345. // Title / icon:
  3346. $iTitle = htmlspecialchars($this->sL($wConf['title']));
  3347. if ($wConf['icon']) {
  3348. $iDat = $this->getIcon($wConf['icon']);
  3349. $icon = '<img src="'.$iDat[0].'" '.$iDat[1][3].' border="0"'.t3lib_BEfunc::titleAltAttrib($iTitle).' />';
  3350. } else {
  3351. $icon = $iTitle;
  3352. }
  3353. //
  3354. switch((string)$wConf['type']) {
  3355. case 'userFunc':
  3356. case 'script':
  3357. case 'popup':
  3358. case 'colorbox':
  3359. if (!$wConf['notNewRecords'] || t3lib_div::testInt($row['uid'])) {
  3360. // Setting &P array contents:
  3361. $params = array();
  3362. $params['params'] = $wConf['params'];
  3363. $params['exampleImg'] = $wConf['exampleImg'];
  3364. $params['table'] = $table;
  3365. $params['uid'] = $row['uid'];
  3366. $params['pid'] = $row['pid'];
  3367. $params['field'] = $field;
  3368. $params['flexFormPath'] = $flexFormPath;
  3369. $params['md5ID'] = $md5ID;
  3370. $params['returnUrl'] = $this->thisReturnUrl();
  3371. // Resolving script filename and setting URL.
  3372. if (!strcmp(substr($wConf['script'],0,4), 'EXT:')) {
  3373. $wScript = t3lib_div::getFileAbsFileName($wConf['script']);
  3374. if ($wScript) {
  3375. $wScript = '../'.substr($wScript,strlen(PATH_site));
  3376. } else break;
  3377. } else {
  3378. $wScript = $wConf['script'];
  3379. }
  3380. $url = $this->backPath.$wScript.(strstr($wScript,'?') ? '' : '?');
  3381. // If there is no script and the type is "colorbox", break right away:
  3382. if ((string)$wConf['type']=='colorbox' && !$wConf['script']) { break; }
  3383. // If "script" type, create the links around the icon:
  3384. if ((string)$wConf['type']=='script') {
  3385. $aUrl = $url.t3lib_div::implodeArrayForUrl('',array('P'=>$params));
  3386. $outArr[]='<a href="'.htmlspecialchars($aUrl).'" onclick="'.$this->blur().'return !TBE_EDITOR.isFormChanged();">'.
  3387. $icon.
  3388. '</a>';
  3389. } else {
  3390. // ... else types "popup", "colorbox" and "userFunc" will need additional parameters:
  3391. $params['formName'] = $this->formName;
  3392. $params['itemName'] = $itemName;
  3393. $params['fieldChangeFunc'] = $fieldChangeFunc;
  3394. $params['fieldChangeFuncHash'] = t3lib_div::hmac(serialize($fieldChangeFunc));
  3395. switch((string)$wConf['type']) {
  3396. case 'popup':
  3397. case 'colorbox':
  3398. // Current form value is passed as P[currentValue]!
  3399. $addJS = $wConf['popup_onlyOpenIfSelected']?'if (!TBE_EDITOR.curSelected(\''.$itemName.$listFlag.'\')){alert('.$GLOBALS['LANG']->JScharCode($this->getLL('m_noSelItemForEdit')).'); return false;}':'';
  3400. $curSelectedValues='+\'&P[currentSelectedValues]=\'+TBE_EDITOR.curSelected(\''.$itemName.$listFlag.'\')';
  3401. $aOnClick= $this->blur().
  3402. $addJS.
  3403. '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'].'\');'.
  3404. 'vHWin.focus();return false;';
  3405. // Setting "colorBoxLinks" - user LATER to wrap around the color box as well:
  3406. $colorBoxLinks = Array('<a href="#" onclick="'.htmlspecialchars($aOnClick).'">','</a>');
  3407. if ((string)$wConf['type']=='popup') {
  3408. $outArr[] = $colorBoxLinks[0].$icon.$colorBoxLinks[1];
  3409. }
  3410. break;
  3411. case 'userFunc':
  3412. $params['item'] = &$item; // Reference set!
  3413. $params['icon'] = $icon;
  3414. $params['iTitle'] = $iTitle;
  3415. $params['wConf'] = $wConf;
  3416. $params['row'] = $row;
  3417. $outArr[] = t3lib_div::callUserFunction($wConf['userFunc'],$params,$this);
  3418. break;
  3419. }
  3420. }
  3421. // Hide the real form element?
  3422. if (is_array($wConf['hideParent']) || $wConf['hideParent']) {
  3423. $item = $itemKinds[1]; // Setting the item to a hidden-field.
  3424. if (is_array($wConf['hideParent'])) {
  3425. $item.= $this->getSingleField_typeNone_render($wConf['hideParent'], $PA['itemFormElValue']);
  3426. }
  3427. }
  3428. }
  3429. break;
  3430. case 'select':
  3431. $fieldValue = array('config' => $wConf);
  3432. $TSconfig = $this->setTSconfig($table, $row);
  3433. $TSconfig[$field] = $TSconfig[$field]['wizards.'][$wid.'.'];
  3434. $selItems = $this->addSelectOptionsToItemArray($this->initItemArray($fieldValue), $fieldValue, $TSconfig, $field);
  3435. $opt = array();
  3436. $opt[] = '<option>'.$iTitle.'</option>';
  3437. foreach($selItems as $p) {
  3438. $opt[] = '<option value="'.htmlspecialchars($p[1]).'">'.htmlspecialchars($p[0]).'</option>';
  3439. }
  3440. if ($wConf['mode']=='append') {
  3441. $assignValue = $this->elName($itemName).'.value=\'\'+this.options[this.selectedIndex].value+'.$this->elName($itemName).'.value';
  3442. } elseif ($wConf['mode']=='prepend') {
  3443. $assignValue = $this->elName($itemName).'.value+=\'\'+this.options[this.selectedIndex].value';
  3444. } else {
  3445. $assignValue = $this->elName($itemName).'.value=this.options[this.selectedIndex].value';
  3446. }
  3447. $sOnChange = $assignValue.';this.blur();this.selectedIndex=0;'.implode('',$fieldChangeFunc);
  3448. $outArr[] = '<select id="' . uniqid('tceforms-select-') . '" class="tceforms-select tceforms-wizardselect" name="_WIZARD'.$fName.'" onchange="'.htmlspecialchars($sOnChange).'">'.implode('',$opt).'</select>';
  3449. break;
  3450. case 'suggest':
  3451. if (isset($PA['fieldTSConfig']['suggest.']['default.']['hide']) &&
  3452. ((bool)$PA['fieldTSConfig']['suggest.']['default.']['hide'] == TRUE)) {
  3453. break;
  3454. }
  3455. $outArr[] = $this->suggest->renderSuggestSelector($PA['itemFormElName'], $table, $field, $row, $PA);
  3456. break;
  3457. }
  3458. // Color wizard colorbox:
  3459. if ((string)$wConf['type']=='colorbox') {
  3460. $dim = t3lib_div::intExplode('x',$wConf['dim']);
  3461. $dX = t3lib_div::intInRange($dim[0],1,200,20);
  3462. $dY = t3lib_div::intInRange($dim[1],1,200,20);
  3463. $color = $PA['itemFormElValue'] ? ' bgcolor="'.htmlspecialchars($PA['itemFormElValue']).'"' : '';
  3464. $outArr[] = '<table border="0" cellpadding="0" cellspacing="0" id="'.$md5ID.'"'.$color.' style="'.htmlspecialchars($wConf['tableStyle']).'">
  3465. <tr>
  3466. <td>'.
  3467. $colorBoxLinks[0].'<img '.
  3468. t3lib_iconWorks::skinImg($this->backPath,
  3469. (strlen(trim($color))==0 || strcmp(trim($color),'0')==0) ? 'gfx/colorpicker_empty.png' : 'gfx/colorpicker.png',
  3470. 'width="'.$dX.'" height="'.$dY.'"'.t3lib_BEfunc::titleAltAttrib(trim($iTitle.' '.$PA['itemFormElValue'])).' border="0"').
  3471. '>'.$colorBoxLinks[1].
  3472. '</td>
  3473. </tr>
  3474. </table>';
  3475. }
  3476. }
  3477. }
  3478. // For each rendered wizard, put them together around the item.
  3479. if (count($outArr)) {
  3480. if ($wizConf['_HIDDENFIELD']) $item = $itemKinds[1];
  3481. $outStr = '';
  3482. $vAlign = $wizConf['_VALIGN'] ? ' style="vertical-align:'.$wizConf['_VALIGN'].'"' : '';
  3483. if (count($outArr)>1 || $wizConf['_PADDING']) {
  3484. $dist = intval($wizConf['_DISTANCE']);
  3485. if ($wizConf['_VERTICAL']) {
  3486. $dist = $dist ? '<tr><td><img src="clear.gif" width="1" height="'.$dist.'" alt="" /></td></tr>' : '';
  3487. $outStr = '<tr><td>'.implode('</td></tr>'.$dist.'<tr><td>',$outArr).'</td></tr>';
  3488. } else {
  3489. $dist = $dist ? '<td><img src="clear.gif" height="1" width="'.$dist.'" alt="" /></td>' : '';
  3490. $outStr = '<tr><td'.$vAlign.'>'.implode('</td>'.$dist.'<td'.$vAlign.'>',$outArr).'</td></tr>';
  3491. }
  3492. $outStr = '<table border="0" cellpadding="'.intval($wizConf['_PADDING']).'" cellspacing="'.intval($wizConf['_PADDING']).'">'.$outStr.'</table>';
  3493. } else {
  3494. $outStr = implode('',$outArr);
  3495. }
  3496. if (!strcmp($wizConf['_POSITION'],'left')) {
  3497. $outStr = '<tr><td'.$vAlign.'>'.$outStr.'</td><td'.$vAlign.'>'.$item.'</td></tr>';
  3498. } elseif (!strcmp($wizConf['_POSITION'],'top')) {
  3499. $outStr = '<tr><td>'.$outStr.'</td></tr><tr><td>'.$item.'</td></tr>';
  3500. } elseif (!strcmp($wizConf['_POSITION'],'bottom')) {
  3501. $outStr = '<tr><td>'.$item.'</td></tr><tr><td>'.$outStr.'</td></tr>';
  3502. } else {
  3503. $outStr = '<tr><td'.$vAlign.'>'.$item.'</td><td'.$vAlign.'>'.$outStr.'</td></tr>';
  3504. }
  3505. $item = '<table border="0" cellpadding="0" cellspacing="0">'.$outStr.'</table>';
  3506. }
  3507. }
  3508. return $item;
  3509. }
  3510. /**
  3511. * Get icon (for example for selector boxes)
  3512. *
  3513. * @param string Icon reference
  3514. * @return array Array with two values; the icon file reference (relative to PATH_typo3 minus backPath), the icon file information array (getimagesize())
  3515. */
  3516. function getIcon($icon) {
  3517. if (substr($icon,0,4)=='EXT:') {
  3518. $file = t3lib_div::getFileAbsFileName($icon);
  3519. if ($file) {
  3520. $file = substr($file,strlen(PATH_site));
  3521. $selIconFile = $this->backPath.'../'.$file;
  3522. $selIconInfo = @getimagesize(PATH_site.$file);
  3523. }
  3524. } elseif (substr($icon,0,3)=='../') {
  3525. $selIconFile = $this->backPath.t3lib_div::resolveBackPath($icon);
  3526. $selIconInfo = @getimagesize(PATH_site.t3lib_div::resolveBackPath(substr($icon,3)));
  3527. } elseif (substr($icon,0,4)=='ext/' || substr($icon,0,7)=='sysext/') {
  3528. $selIconFile = $this->backPath.$icon;
  3529. $selIconInfo = @getimagesize(PATH_typo3.$icon);
  3530. } else {
  3531. $selIconFile = t3lib_iconWorks::skinImg($this->backPath,'gfx/'.$icon,'',1);
  3532. $iconPath = substr($selIconFile, strlen($this->backPath));
  3533. $selIconInfo = @getimagesize(PATH_typo3 . $iconPath);
  3534. }
  3535. return array($selIconFile,$selIconInfo);
  3536. }
  3537. /**
  3538. * Creates style attribute content for option tags in a selector box, primarily setting it up to show the icon of an element as background image (works in mozilla)
  3539. *
  3540. * @param string Icon string for option item
  3541. * @return string Style attribute content, if any
  3542. */
  3543. function optionTagStyle($iconString) {
  3544. if ($iconString) {
  3545. list($selIconFile,$selIconInfo) = $this->getIcon($iconString);
  3546. $padLeft = $selIconInfo[0]+4;
  3547. if($padLeft >= 18 && $padLeft <= 24) {
  3548. $padLeft = 22; // In order to get the same padding for all option tags even if icon sizes differ a little, set it to 22 if it was between 18 and 24 pixels
  3549. }
  3550. $padTop = t3lib_div::intInRange(($selIconInfo[1]-12)/2,0);
  3551. $styleAttr = 'background: #fff url(' . $selIconFile . ') 0% 50% no-repeat; height: ' . t3lib_div::intInRange(($selIconInfo[1] + 2) - $padTop, 0) . 'px; padding-top: ' . $padTop . 'px; padding-left: ' . $padLeft . 'px;';
  3552. return $styleAttr;
  3553. }
  3554. }
  3555. /**
  3556. * Extracting values from a value/label list (as made by transferData class)
  3557. *
  3558. * @param string Value string where values are comma separated, intermixed with labels and rawurlencoded (this is what is delivered to TCEforms normally!)
  3559. * @param array Values in an array
  3560. * @return array Input string exploded with comma and for each value only the label part is set in the array. Keys are numeric
  3561. */
  3562. function extractValuesOnlyFromValueLabelList($itemFormElValue) {
  3563. // Get values of selected items:
  3564. $itemArray = t3lib_div::trimExplode(',',$itemFormElValue,1);
  3565. foreach($itemArray as $tk => $tv) {
  3566. $tvP = explode('|',$tv,2);
  3567. $tvP[0] = rawurldecode($tvP[0]);
  3568. $itemArray[$tk] = $tvP[0];
  3569. }
  3570. return $itemArray;
  3571. }
  3572. /**
  3573. * Wraps a string with a link to the palette.
  3574. *
  3575. * @param string The string to wrap in an A-tag
  3576. * @param string The table name for which to open the palette.
  3577. * @param array The palette pointer.
  3578. * @param integer The record array
  3579. */
  3580. function wrapOpenPalette($header,$table,$row,$palette,$retFunc) {
  3581. $id = 'TCEFORMS_'.$table.'_'.$palette.'_'.$row['uid'];
  3582. $res = '<a href="#" onclick="TBE_EDITOR.toggle_display_states(\''.$id.'\',\'block\',\'none\'); return false;" >'.$header.'</a>';
  3583. return array($res,'');
  3584. }
  3585. /**
  3586. * Add the id and the style property to the field palette
  3587. *
  3588. * @param string Palette Code
  3589. * @param string The table name for which to open the palette.
  3590. * @param string Palette ID
  3591. * @param string The record array
  3592. * @return boolean is collapsed
  3593. */
  3594. function wrapPaletteField($code,$table,$row,$palette,$collapsed ) {
  3595. $display = $collapsed ? 'none' : 'block';
  3596. $id = 'TCEFORMS_'.$table.'_'.$palette.'_'.$row['uid'];
  3597. $code = '<div id="'.$id.'" style="display:'.$display.';" >'.$code.'</div>';
  3598. return $code;
  3599. }
  3600. /**
  3601. * Creates checkbox parameters
  3602. *
  3603. * @param string Form element name
  3604. * @param integer The value of the checkbox (representing checkboxes with the bits)
  3605. * @param integer Checkbox # (0-9?)
  3606. * @param integer Total number of checkboxes in the array.
  3607. * @param string Additional JavaScript for the onclick handler.
  3608. * @return string The onclick attribute + possibly the checked-option set.
  3609. */
  3610. function checkBoxParams($itemName,$thisValue,$c,$iCount,$addFunc='') {
  3611. $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)).');'.
  3612. $addFunc;
  3613. $str = ' onclick="'.htmlspecialchars($onClick).'"'.
  3614. (($thisValue&pow(2,$c))?' checked="checked"':'');
  3615. return $str;
  3616. }
  3617. /**
  3618. * Returns element reference for form element name
  3619. *
  3620. * @param string Form element name
  3621. * @return string Form element reference (JS)
  3622. */
  3623. function elName($itemName) {
  3624. return 'document.'.$this->formName."['".$itemName."']";
  3625. }
  3626. /**
  3627. * Returns the "No title" string if the input $str is empty.
  3628. *
  3629. * DEPRECATED: Use t3lib_BEfunc::getRecordTitle with the $forceResult flag set.
  3630. *
  3631. * @param string The string which - if empty - will become the no-title string.
  3632. * @param array Array with wrappin parts for the no-title output (in keys [0]/[1])
  3633. * @return string
  3634. * @deprecated since TYPO3 4.1, this function will be removed in TYPO3 4.5.
  3635. */
  3636. function noTitle($str,$wrapParts=array()) {
  3637. t3lib_div::logDeprecatedFunction();
  3638. return strcmp($str,'') ? $str : $wrapParts[0].'['.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.no_title').']'.$wrapParts[1];
  3639. }
  3640. /**
  3641. * Returns 'this.blur();' string, if supported.
  3642. *
  3643. * @return string If the current browser supports styles, the string 'this.blur();' is returned.
  3644. */
  3645. function blur() {
  3646. return $GLOBALS['CLIENT']['FORMSTYLE'] ? 'this.blur();':'';
  3647. }
  3648. /**
  3649. * Returns the "returnUrl" of the form. Can be set externally or will be taken from "t3lib_div::linkThisScript()"
  3650. *
  3651. * @return string Return URL of current script
  3652. */
  3653. function thisReturnUrl() {
  3654. return $this->returnUrl ? $this->returnUrl : t3lib_div::linkThisScript();
  3655. }
  3656. /**
  3657. * Returns the form field for a single HIDDEN field.
  3658. * (Not used anywhere...?)
  3659. *
  3660. * @param string Table name
  3661. * @param string Field name
  3662. * @param array The row
  3663. * @return string The hidden-field <input> tag.
  3664. */
  3665. function getSingleHiddenField($table,$field,$row) {
  3666. global $TCA;
  3667. $out='';
  3668. t3lib_div::loadTCA($table);
  3669. if ($TCA[$table]['columns'][$field]) {
  3670. $uid=$row['uid'];
  3671. $itemName=$this->prependFormFieldNames.'['.$table.']['.$uid.']['.$field.']';
  3672. $itemValue=$row[$field];
  3673. $item.='<input type="hidden" name="'.$itemName.'" value="'.htmlspecialchars($itemValue).'" />';
  3674. $out = $item;
  3675. }
  3676. return $out;
  3677. }
  3678. /**
  3679. * Returns parameters to set the width for a <input>/<textarea>-element
  3680. *
  3681. * @param integer The abstract size value (1-48)
  3682. * @param boolean If this is for a text area.
  3683. * @return string Either a "style" attribute string or "cols"/"size" attribute string.
  3684. */
  3685. function formWidth($size=48,$textarea=0) {
  3686. $widthAndStyleAttributes = '';
  3687. $fieldWidthAndStyle = $this->formWidthAsArray($size, $textarea);
  3688. if (!$GLOBALS['CLIENT']['FORMSTYLE']) {
  3689. // If not setting the width by style-attribute
  3690. $widthAndStyleAttributes = ' ' . $fieldWidthAndStyle['width'];
  3691. } else {
  3692. // Setting width by style-attribute. 'cols' MUST be avoided with NN6+
  3693. $widthAndStyleAttributes = ' style="' . htmlspecialchars($fieldWidthAndStyle['style']) . '"';
  3694. if ($fieldWidthAndStyle['class']) {
  3695. $widthAndStyleAttributes .= ' class="' . htmlspecialchars($fieldWidthAndStyle['class']) . '"';
  3696. }
  3697. }
  3698. return $widthAndStyleAttributes;
  3699. }
  3700. /**
  3701. * Returns parameters to set the width for a <input>/<textarea>-element
  3702. *
  3703. * @param integer The abstract size value (1-48)
  3704. * @param boolean If set, calculates sizes for a text area.
  3705. * @return array An array containing style, class, and width attributes.
  3706. */
  3707. protected function formWidthAsArray($size = 48, $textarea = false) {
  3708. $fieldWidthAndStyle = array('style' => '', 'class' => '', 'width' => '');
  3709. if ($this->docLarge) {
  3710. $size = round($size * $this->form_largeComp);
  3711. }
  3712. $widthAttribute = $textarea ? 'cols' : 'size';
  3713. if (!$GLOBALS['CLIENT']['FORMSTYLE']) {
  3714. // If not setting the width by style-attribute
  3715. $fieldWidthAndStyle['width'] = $widthAttribute . '="' . $size . '"';
  3716. } else {
  3717. // Setting width by style-attribute. 'cols' MUST be avoided with NN6+
  3718. $widthInPixels = ceil($size * $this->form_rowsToStylewidth);
  3719. $fieldWidthAndStyle['style'] = 'width: ' . $widthInPixels . 'px; '
  3720. . $this->defStyle
  3721. . $this->formElStyle($textarea ? 'text' : 'input');
  3722. $fieldWidthAndStyle['class'] = $this->formElClass($textarea ? 'text' : 'input');
  3723. }
  3724. return $fieldWidthAndStyle;
  3725. }
  3726. /**
  3727. * Returns parameters to set with for a textarea field
  3728. *
  3729. * @param integer The abstract width (1-48)
  3730. * @param string Empty or "off" (text wrapping in the field or not)
  3731. * @return string The "cols" attribute string (or style from formWidth())
  3732. * @see formWidth()
  3733. */
  3734. function formWidthText($size=48,$wrap='') {
  3735. $wTags = $this->formWidth($size,1);
  3736. // 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...
  3737. if (strtolower(trim($wrap))!='off' && $GLOBALS['CLIENT']['BROWSER']=='net' && $GLOBALS['CLIENT']['VERSION']>=5) {
  3738. $wTags.= ' cols="'.$size.'"';
  3739. }
  3740. return $wTags;
  3741. }
  3742. /**
  3743. * Get style CSS values for the current field type.
  3744. *
  3745. * @param string Field type (eg. "check", "radio", "select")
  3746. * @return string CSS attributes
  3747. * @see formElStyleClassValue()
  3748. */
  3749. function formElStyle($type) {
  3750. return $this->formElStyleClassValue($type);
  3751. }
  3752. /**
  3753. * Get class attribute value for the current field type.
  3754. *
  3755. * @param string Field type (eg. "check", "radio", "select")
  3756. * @return string CSS attributes
  3757. * @see formElStyleClassValue()
  3758. */
  3759. function formElClass($type) {
  3760. return $this->formElStyleClassValue($type, TRUE);
  3761. }
  3762. /**
  3763. * Get style CSS values for the current field type.
  3764. *
  3765. * @param string Field type (eg. "check", "radio", "select")
  3766. * @param boolean If set, will return value only if prefixed with CLASS, otherwise must not be prefixed "CLASS"
  3767. * @return string CSS attributes
  3768. */
  3769. function formElStyleClassValue($type, $class=FALSE) {
  3770. // Get value according to field:
  3771. if (isset($this->fieldStyle[$type])) {
  3772. $style = trim($this->fieldStyle[$type]);
  3773. } else {
  3774. $style = trim($this->fieldStyle['all']);
  3775. }
  3776. // Check class prefixed:
  3777. if (substr($style,0,6)=='CLASS:') {
  3778. $out = $class ? trim(substr($style,6)) : '';
  3779. } else {
  3780. $out = !$class ? $style : '';
  3781. }
  3782. return $out;
  3783. }
  3784. /**
  3785. * Return default "style" / "class" attribute line.
  3786. *
  3787. * @param string Field type (eg. "check", "radio", "select")
  3788. * @param string Additional class(es) to be added
  3789. * @return string CSS attributes
  3790. */
  3791. function insertDefStyle($type, $additionalClass = '') {
  3792. $out = '';
  3793. $style = trim($this->defStyle.$this->formElStyle($type));
  3794. $out.= $style?' style="'.htmlspecialchars($style).'"':'';
  3795. $class = $this->formElClass($type);
  3796. $classAttributeValue = join(' ', array_filter(array($class, $additionalClass)));
  3797. $out .= $classAttributeValue ? ' class="' . htmlspecialchars($classAttributeValue) . '"' : '';
  3798. return $out;
  3799. }
  3800. /**
  3801. * Create dynamic tab menu
  3802. *
  3803. * @param array Parts for the tab menu, fed to template::getDynTabMenu()
  3804. * @param string ID string for the tab menu
  3805. * @param integer If set to '1' empty tabs will be removed, If set to '2' empty tabs will be disabled
  3806. * @return string HTML for the menu
  3807. */
  3808. function getDynTabMenu($parts, $idString, $dividersToTabsBehaviour = 1) {
  3809. if (is_object($GLOBALS['TBE_TEMPLATE'])) {
  3810. $GLOBALS['TBE_TEMPLATE']->backPath = $this->backPath;
  3811. return $GLOBALS['TBE_TEMPLATE']->getDynTabMenu($parts, $idString, 0, false, 50, 1, false, 1, $dividersToTabsBehaviour);
  3812. } else {
  3813. $output = '';
  3814. foreach($parts as $singlePad) {
  3815. $output.='
  3816. <h3>'.htmlspecialchars($singlePad['label']).'</h3>
  3817. '.($singlePad['description'] ? '<p class="c-descr">'.nl2br(htmlspecialchars($singlePad['description'])).'</p>' : '').'
  3818. '.$singlePad['content'];
  3819. }
  3820. return '<div class="typo3-dyntabmenu-divs">'.$output.'</div>';
  3821. }
  3822. }
  3823. /************************************************************
  3824. *
  3825. * Item-array manipulation functions (check/select/radio)
  3826. *
  3827. ************************************************************/
  3828. /**
  3829. * Initialize item array (for checkbox, selectorbox, radio buttons)
  3830. * Will resolve the label value.
  3831. *
  3832. * @param array The "columns" array for the field (from TCA)
  3833. * @return array An array of arrays with three elements; label, value, icon
  3834. */
  3835. function initItemArray($fieldValue) {
  3836. $items = array();
  3837. if (is_array($fieldValue['config']['items'])) {
  3838. foreach ($fieldValue['config']['items'] as $itemValue) {
  3839. $items[] = array($this->sL($itemValue[0]), $itemValue[1], $itemValue[2]);
  3840. }
  3841. }
  3842. return $items;
  3843. }
  3844. /**
  3845. * Merges items into an item-array
  3846. *
  3847. * @param array The existing item array
  3848. * @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.
  3849. * @return array The updated $item array
  3850. */
  3851. function addItems($items,$iArray) {
  3852. global $TCA;
  3853. if (is_array($iArray)) {
  3854. foreach ($iArray as $value => $label) {
  3855. $items[]=array($this->sl($label),$value);
  3856. }
  3857. }
  3858. return $items;
  3859. }
  3860. /**
  3861. * Perform user processing of the items arrays of checkboxes, selectorboxes and radio buttons.
  3862. *
  3863. * @param array The array of items (label,value,icon)
  3864. * @param array The "itemsProcFunc." from fieldTSconfig of the field.
  3865. * @param array The config array for the field.
  3866. * @param string Table name
  3867. * @param array Record row
  3868. * @param string Field name
  3869. * @return array The modified $items array
  3870. */
  3871. function procItems($items,$iArray,$config,$table,$row,$field) {
  3872. global $TCA;
  3873. $params=array();
  3874. $params['items'] = &$items;
  3875. $params['config'] = $config;
  3876. $params['TSconfig'] = $iArray;
  3877. $params['table'] = $table;
  3878. $params['row'] = $row;
  3879. $params['field'] = $field;
  3880. t3lib_div::callUserFunction($config['itemsProcFunc'],$params,$this);
  3881. return $items;
  3882. }
  3883. /**
  3884. * Add selector box items of more exotic kinds.
  3885. *
  3886. * @param array The array of items (label,value,icon)
  3887. * @param array The "columns" array for the field (from TCA)
  3888. * @param array TSconfig for the table/row
  3889. * @param string The fieldname
  3890. * @return array The $items array modified.
  3891. */
  3892. function addSelectOptionsToItemArray($items,$fieldValue,$TSconfig,$field) {
  3893. global $TCA;
  3894. // Values from foreign tables:
  3895. if ($fieldValue['config']['foreign_table']) {
  3896. $items = $this->foreignTable($items,$fieldValue,$TSconfig,$field);
  3897. if ($fieldValue['config']['neg_foreign_table']) {
  3898. $items = $this->foreignTable($items,$fieldValue,$TSconfig,$field,1);
  3899. }
  3900. }
  3901. // Values from a file folder:
  3902. if ($fieldValue['config']['fileFolder']) {
  3903. $fileFolder = t3lib_div::getFileAbsFileName($fieldValue['config']['fileFolder']);
  3904. if (@is_dir($fileFolder)) {
  3905. // Configurations:
  3906. $extList = $fieldValue['config']['fileFolder_extList'];
  3907. $recursivityLevels = isset($fieldValue['config']['fileFolder_recursions']) ? t3lib_div::intInRange($fieldValue['config']['fileFolder_recursions'],0,99) : 99;
  3908. // Get files:
  3909. $fileFolder = rtrim($fileFolder, '/').'/';
  3910. $fileArr = t3lib_div::getAllFilesAndFoldersInPath(array(),$fileFolder,$extList,0,$recursivityLevels);
  3911. $fileArr = t3lib_div::removePrefixPathFromList($fileArr, $fileFolder);
  3912. foreach($fileArr as $fileRef) {
  3913. $fI = pathinfo($fileRef);
  3914. $icon = t3lib_div::inList('gif,png,jpeg,jpg', strtolower($fI['extension'])) ? '../'.substr($fileFolder,strlen(PATH_site)).$fileRef : '';
  3915. $items[] = array(
  3916. $fileRef,
  3917. $fileRef,
  3918. $icon
  3919. );
  3920. }
  3921. }
  3922. }
  3923. // If 'special' is configured:
  3924. if ($fieldValue['config']['special']) {
  3925. switch ($fieldValue['config']['special']) {
  3926. case 'tables':
  3927. $temp_tc = array_keys($TCA);
  3928. $descr = '';
  3929. foreach($temp_tc as $theTableNames) {
  3930. if (!$TCA[$theTableNames]['ctrl']['adminOnly']) {
  3931. // Icon:
  3932. $icon = '../'.TYPO3_mainDir.t3lib_iconWorks::skinImg($this->backPath,t3lib_iconWorks::getIcon($theTableNames, array()),'',1);
  3933. // Add description texts:
  3934. if ($this->edit_showFieldHelp) {
  3935. $GLOBALS['LANG']->loadSingleTableDescription($theTableNames);
  3936. $fDat = $GLOBALS['TCA_DESCR'][$theTableNames]['columns'][''];
  3937. $descr = $fDat['description'];
  3938. }
  3939. // Item configuration:
  3940. $items[] = array(
  3941. $this->sL($TCA[$theTableNames]['ctrl']['title']),
  3942. $theTableNames,
  3943. $icon,
  3944. $descr
  3945. );
  3946. }
  3947. }
  3948. break;
  3949. case 'pagetypes':
  3950. $theTypes = $TCA['pages']['columns']['doktype']['config']['items'];
  3951. foreach($theTypes as $theTypeArrays) {
  3952. // Icon:
  3953. $icon = $theTypeArrays[1]!='--div--' ? '../'.TYPO3_mainDir.t3lib_iconWorks::skinImg($this->backPath,t3lib_iconWorks::getIcon('pages', array('doktype' => $theTypeArrays[1])),'',1) : '';
  3954. // Item configuration:
  3955. $items[] = array(
  3956. $this->sL($theTypeArrays[0]),
  3957. $theTypeArrays[1],
  3958. $icon
  3959. );
  3960. }
  3961. break;
  3962. case 'exclude':
  3963. $theTypes = t3lib_BEfunc::getExcludeFields();
  3964. $descr = '';
  3965. foreach($theTypes as $theTypeArrays) {
  3966. list($theTable, $theField) = explode(':', $theTypeArrays[1]);
  3967. // Add description texts:
  3968. if ($this->edit_showFieldHelp) {
  3969. $GLOBALS['LANG']->loadSingleTableDescription($theTable);
  3970. $fDat = $GLOBALS['TCA_DESCR'][$theTable]['columns'][$theField];
  3971. $descr = $fDat['description'];
  3972. }
  3973. // Item configuration:
  3974. $items[] = array(
  3975. rtrim($theTypeArrays[0], ':'),
  3976. $theTypeArrays[1],
  3977. '',
  3978. $descr
  3979. );
  3980. }
  3981. break;
  3982. case 'explicitValues':
  3983. $theTypes = t3lib_BEfunc::getExplicitAuthFieldValues();
  3984. // Icons:
  3985. $icons = array(
  3986. 'ALLOW' => '../'.TYPO3_mainDir.t3lib_iconWorks::skinImg($this->backPath,'gfx/icon_ok2.gif','',1),
  3987. 'DENY' => '../'.TYPO3_mainDir.t3lib_iconWorks::skinImg($this->backPath,'gfx/icon_fatalerror.gif','',1),
  3988. );
  3989. // Traverse types:
  3990. foreach($theTypes as $tableFieldKey => $theTypeArrays) {
  3991. if (is_array($theTypeArrays['items'])) {
  3992. // Add header:
  3993. $items[] = array(
  3994. $theTypeArrays['tableFieldLabel'],
  3995. '--div--',
  3996. );
  3997. // Traverse options for this field:
  3998. foreach($theTypeArrays['items'] as $itemValue => $itemContent) {
  3999. // Add item to be selected:
  4000. $items[] = array(
  4001. '['.$itemContent[2].'] '.$itemContent[1],
  4002. $tableFieldKey.':'.preg_replace('/[:|,]/','',$itemValue).':'.$itemContent[0],
  4003. $icons[$itemContent[0]]
  4004. );
  4005. }
  4006. }
  4007. }
  4008. break;
  4009. case 'languages':
  4010. $items = array_merge($items,t3lib_BEfunc::getSystemLanguages());
  4011. break;
  4012. case 'custom':
  4013. // Initialize:
  4014. $customOptions = $GLOBALS['TYPO3_CONF_VARS']['BE']['customPermOptions'];
  4015. if (is_array($customOptions)) {
  4016. foreach($customOptions as $coKey => $coValue) {
  4017. if (is_array($coValue['items'])) {
  4018. // Add header:
  4019. $items[] = array(
  4020. $GLOBALS['LANG']->sl($coValue['header']),
  4021. '--div--',
  4022. );
  4023. // Traverse items:
  4024. foreach($coValue['items'] as $itemKey => $itemCfg) {
  4025. // Icon:
  4026. if ($itemCfg[1]) {
  4027. list($icon) = $this->getIcon($itemCfg[1]);
  4028. if ($icon) $icon = '../'.TYPO3_mainDir.$icon;
  4029. } else $icon = '';
  4030. // Add item to be selected:
  4031. $items[] = array(
  4032. $GLOBALS['LANG']->sl($itemCfg[0]),
  4033. $coKey.':'.preg_replace('/[:|,]/','',$itemKey),
  4034. $icon,
  4035. $GLOBALS['LANG']->sl($itemCfg[2]),
  4036. );
  4037. }
  4038. }
  4039. }
  4040. }
  4041. break;
  4042. case 'modListGroup':
  4043. case 'modListUser':
  4044. $loadModules = t3lib_div::makeInstance('t3lib_loadModules');
  4045. $loadModules->load($GLOBALS['TBE_MODULES']);
  4046. $modList = $fieldValue['config']['special']=='modListUser' ? $loadModules->modListUser : $loadModules->modListGroup;
  4047. if (is_array($modList)) {
  4048. $descr = '';
  4049. foreach($modList as $theMod) {
  4050. // Icon:
  4051. $icon = $GLOBALS['LANG']->moduleLabels['tabs_images'][$theMod.'_tab'];
  4052. if ($icon) {
  4053. $icon = '../'.substr($icon,strlen(PATH_site));
  4054. }
  4055. // Description texts:
  4056. if ($this->edit_showFieldHelp) {
  4057. $descr = $GLOBALS['LANG']->moduleLabels['labels'][$theMod.'_tablabel'].
  4058. LF.
  4059. $GLOBALS['LANG']->moduleLabels['labels'][$theMod.'_tabdescr'];
  4060. }
  4061. // Item configuration:
  4062. $items[] = array(
  4063. $this->addSelectOptionsToItemArray_makeModuleData($theMod),
  4064. $theMod,
  4065. $icon,
  4066. $descr
  4067. );
  4068. }
  4069. }
  4070. break;
  4071. }
  4072. }
  4073. // Return the items:
  4074. return $items;
  4075. }
  4076. /**
  4077. * Creates value/label pair for a backend module (main and sub)
  4078. *
  4079. * @param string The module key
  4080. * @return string The rawurlencoded 2-part string to transfer to interface
  4081. * @access private
  4082. * @see addSelectOptionsToItemArray()
  4083. */
  4084. function addSelectOptionsToItemArray_makeModuleData($value) {
  4085. $label = '';
  4086. // Add label for main module:
  4087. $pp = explode('_',$value);
  4088. if (count($pp)>1) $label.=$GLOBALS['LANG']->moduleLabels['tabs'][$pp[0].'_tab'].'>';
  4089. // Add modules own label now:
  4090. $label.= $GLOBALS['LANG']->moduleLabels['tabs'][$value.'_tab'];
  4091. return $label;
  4092. }
  4093. /**
  4094. * Adds records from a foreign table (for selector boxes)
  4095. *
  4096. * @param array The array of items (label,value,icon)
  4097. * @param array The 'columns' array for the field (from TCA)
  4098. * @param array TSconfig for the table/row
  4099. * @param string The fieldname
  4100. * @param boolean If set, then we are fetching the 'neg_' foreign tables.
  4101. * @return array The $items array modified.
  4102. * @see addSelectOptionsToItemArray(), t3lib_BEfunc::exec_foreign_table_where_query()
  4103. */
  4104. function foreignTable($items,$fieldValue,$TSconfig,$field,$pFFlag=0) {
  4105. global $TCA;
  4106. // Init:
  4107. $pF=$pFFlag?'neg_':'';
  4108. $f_table = $fieldValue['config'][$pF.'foreign_table'];
  4109. $uidPre = $pFFlag?'-':'';
  4110. // Get query:
  4111. $res = t3lib_BEfunc::exec_foreign_table_where_query($fieldValue,$field,$TSconfig,$pF);
  4112. // Perform lookup
  4113. if ($GLOBALS['TYPO3_DB']->sql_error()) {
  4114. echo($GLOBALS['TYPO3_DB']->sql_error()."\n\nThis may indicate a table defined in tables.php is not existing in the database!");
  4115. return array();
  4116. }
  4117. // Get label prefix.
  4118. $lPrefix = $this->sL($fieldValue['config'][$pF.'foreign_table_prefix']);
  4119. // Get icon field + path if any:
  4120. $iField = $TCA[$f_table]['ctrl']['selicon_field'];
  4121. $iPath = trim($TCA[$f_table]['ctrl']['selicon_field_path']);
  4122. // Traverse the selected rows to add them:
  4123. while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
  4124. t3lib_BEfunc::workspaceOL($f_table, $row);
  4125. if (is_array($row)) {
  4126. // Prepare the icon if available:
  4127. if ($iField && $iPath && $row[$iField]) {
  4128. $iParts = t3lib_div::trimExplode(',',$row[$iField],1);
  4129. $icon = '../'.$iPath.'/'.trim($iParts[0]);
  4130. } elseif (t3lib_div::inList('singlebox,checkbox',$fieldValue['config']['renderMode'])) {
  4131. $icon = '../'.TYPO3_mainDir.t3lib_iconWorks::skinImg($this->backPath,t3lib_iconWorks::getIcon($f_table, $row),'',1);
  4132. } else $icon = '';
  4133. // Add the item:
  4134. $items[] = array(
  4135. $lPrefix . htmlspecialchars(t3lib_BEfunc::getRecordTitle($f_table, $row)),
  4136. $uidPre . $row['uid'],
  4137. $icon
  4138. );
  4139. }
  4140. }
  4141. return $items;
  4142. }
  4143. /********************************************
  4144. *
  4145. * Template functions
  4146. *
  4147. ********************************************/
  4148. /**
  4149. * Sets the design to the backend design.
  4150. * Backend
  4151. *
  4152. * @return void
  4153. */
  4154. function setNewBEDesign() {
  4155. // Wrapping all table rows for a particular record being edited:
  4156. $this->totalWrap='
  4157. <h2>###PAGE_TITLE###</h2>
  4158. <table class="typo3-TCEforms">'.
  4159. '|'.
  4160. '
  4161. <tr>
  4162. <td><!-- --></td>
  4163. <td><img src="clear.gif" width="'.($this->docLarge ? 440+150 : 440).'" height="1" alt="" /></td>
  4164. </tr>
  4165. <tr class="typo3-TCEforms-recHeaderRow">
  4166. <td colspan="2">###RECORD_ICON### <span class="typo3-TCEforms-recHeader">###TABLE_TITLE###</span> ###ID_NEW_INDICATOR###</td>
  4167. </tr>
  4168. </table>';
  4169. // Wrapping a single field:
  4170. $this->fieldTemplate='
  4171. <tr ###BGCOLOR_HEAD######CLASSATTR_2###>
  4172. <td>###FIELD_HELP_ICON###</td>
  4173. <td width="99%"><span style="color:###FONTCOLOR_HEAD###;"###CLASSATTR_4###><strong>###FIELD_NAME###</strong></span>###FIELD_HELP_TEXT###</td>
  4174. </tr>
  4175. <tr ###BGCOLOR######CLASSATTR_1###>
  4176. <td nowrap="nowrap"><img name="req_###FIELD_TABLE###_###FIELD_ID###_###FIELD_FIELD###" src="clear.gif" class="t3-TCEforms-reqImg" alt="" /><img name="cm_###FIELD_TABLE###_###FIELD_ID###_###FIELD_FIELD###" src="clear.gif" class="t3-TCEforms-contentchangedImg" alt="" /></td>
  4177. <td valign="top">###FIELD_ITEM######FIELD_PAL_LINK_ICON###</td>
  4178. </tr>';
  4179. $this->palFieldTemplate='
  4180. <tr ###BGCOLOR######CLASSATTR_1###>
  4181. <td></td>
  4182. <td nowrap="nowrap" valign="top">###FIELD_PALETTE###</td>
  4183. </tr>';
  4184. $this->palFieldTemplateHeader='
  4185. <tr ###BGCOLOR_HEAD######CLASSATTR_2###>
  4186. <td><!-- --></td>
  4187. <td nowrap="nowrap" valign="top"><strong>###FIELD_HEADER###</strong></td>
  4188. </tr>';
  4189. $this->sectionWrap='
  4190. <tr>
  4191. <td colspan="2"><img src="clear.gif" width="1" height="###SPACE_BEFORE###" alt="" /></td>
  4192. </tr>
  4193. <tr>
  4194. <td colspan="2"><table ###TABLE_ATTRIBS###>###CONTENT###</table></td>
  4195. </tr>
  4196. ';
  4197. }
  4198. /**
  4199. * This inserts the content of $inArr into the field-template
  4200. *
  4201. * @param array Array with key/value pairs to insert in the template.
  4202. * @param string Alternative template to use instead of the default.
  4203. * @return string
  4204. */
  4205. function intoTemplate($inArr,$altTemplate='') {
  4206. // Put into template_
  4207. $fieldTemplateParts = explode('###FIELD_',$this->rplColorScheme($altTemplate?$altTemplate:$this->fieldTemplate));
  4208. $out=current($fieldTemplateParts);
  4209. foreach ($fieldTemplateParts as $part) {
  4210. list($key,$val)=explode('###',$part,2);
  4211. $out.=$inArr[$key];
  4212. $out.=$val;
  4213. }
  4214. return $out;
  4215. }
  4216. /**
  4217. * Overwrite this function in own extended class to add own markers for output
  4218. *
  4219. * @param array Array with key/value pairs to insert in the template.
  4220. * @param string The table name of the record
  4221. * @param string The field name which this element is supposed to edit
  4222. * @param array The record data array where the value(s) for the field can be found
  4223. * @param array An array with additional configuration options.
  4224. * @return array marker array for template output
  4225. * @see function intoTemplate()
  4226. */
  4227. function addUserTemplateMarkers($marker,$table,$field,$row,&$PA) {
  4228. return $marker;
  4229. }
  4230. /**
  4231. * Wrapping labels
  4232. * Currently not implemented - just returns input value.
  4233. *
  4234. * @param string Input string.
  4235. * @return string Output string.
  4236. */
  4237. function wrapLabels($str) {
  4238. return $str;
  4239. }
  4240. /**
  4241. * Wraps all the table rows into a single table.
  4242. * Used externally from scripts like alt_doc.php and db_layout.php (which uses TCEforms...)
  4243. *
  4244. * @param string Code to output between table-parts; table rows
  4245. * @param array The record
  4246. * @param string The table name
  4247. * @return string
  4248. */
  4249. function wrapTotal($c,$rec,$table) {
  4250. $parts = $this->replaceTableWrap(explode('|',$this->totalWrap,2),$rec,$table);
  4251. return $parts[0].$c.$parts[1].implode('',$this->hiddenFieldAccum);
  4252. }
  4253. /**
  4254. * This replaces markers in the total wrap
  4255. *
  4256. * @param array An array of template parts containing some markers.
  4257. * @param array The record
  4258. * @param string The table name
  4259. * @return string
  4260. */
  4261. function replaceTableWrap($arr,$rec,$table) {
  4262. global $TCA;
  4263. // Make "new"-label
  4264. if (strstr($rec['uid'],'NEW')) {
  4265. $newLabel = ' <span class="typo3-TCEforms-newToken">'.
  4266. $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.new',1).
  4267. '</span>';
  4268. // Kasper: Should not be used here because NEW records are not offline workspace versions...
  4269. #t3lib_BEfunc::fixVersioningPid($table,$rec);
  4270. $truePid = t3lib_BEfunc::getTSconfig_pidValue($table, $rec['uid'], $rec['pid']);
  4271. $prec = t3lib_BEfunc::getRecordWSOL('pages', $truePid, 'title');
  4272. $pageTitle = t3lib_BEfunc::getRecordTitle('pages', $prec, TRUE, FALSE);
  4273. $rLabel = '<em>[PID: ' . $truePid . '] ' . $pageTitle . '</em>';
  4274. // Fetch translated title of the table
  4275. $tableTitle = $GLOBALS['LANG']->sL($GLOBALS['TCA'][$table]['ctrl']['title']);
  4276. if ($table === 'pages') {
  4277. $label = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.createNewPage', TRUE);
  4278. $pageTitle = sprintf($label, $tableTitle);
  4279. } else {
  4280. $label = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.createNewRecord', TRUE);
  4281. if ($rec['pid'] == 0) {
  4282. $label = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.createNewRecordRootLevel', TRUE);
  4283. }
  4284. $pageTitle = sprintf($label, $tableTitle, $pageTitle);
  4285. }
  4286. } else {
  4287. $newLabel = ' <span class="typo3-TCEforms-recUid">['.$rec['uid'].']</span>';
  4288. $rLabel = t3lib_BEfunc::getRecordTitle($table, $rec, TRUE, FALSE);
  4289. $prec = t3lib_BEfunc::getRecordWSOL('pages', $rec['pid'], 'uid,title');
  4290. // Fetch translated title of the table
  4291. $tableTitle = $GLOBALS['LANG']->sL($GLOBALS['TCA'][$table]['ctrl']['title']);
  4292. if ($table === 'pages') {
  4293. $label = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.editPage', TRUE);
  4294. // Just take the record title and prepend an edit label.
  4295. $pageTitle = sprintf($label, $tableTitle, $rLabel);
  4296. } else {
  4297. $label = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.editRecord', TRUE);
  4298. $pageTitle = t3lib_BEfunc::getRecordTitle('pages', $prec, TRUE, FALSE);
  4299. if ($rLabel === t3lib_BEfunc::getNoRecordTitle(TRUE)) {
  4300. $label = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.editRecordNoTitle', TRUE);
  4301. }
  4302. if ($rec['pid'] == 0) {
  4303. $label = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.editRecordRootLevel', TRUE);
  4304. }
  4305. if ($rLabel !== t3lib_BEfunc::getNoRecordTitle(TRUE)) {
  4306. // Just take the record title and prepend an edit label.
  4307. $pageTitle = sprintf($label, $tableTitle, $rLabel, $pageTitle);
  4308. } else {
  4309. // Leave out the record title since it is not set.
  4310. $pageTitle = sprintf($label, $tableTitle, $pageTitle);
  4311. }
  4312. }
  4313. }
  4314. foreach ($arr as $k => $v) {
  4315. // Make substitutions:
  4316. $arr[$k] = str_replace('###PAGE_TITLE###', $pageTitle, $arr[$k]);
  4317. $arr[$k] = str_replace('###ID_NEW_INDICATOR###', $newLabel, $arr[$k]);
  4318. $arr[$k] = str_replace('###RECORD_LABEL###', $rLabel, $arr[$k]);
  4319. $arr[$k] = str_replace('###TABLE_TITLE###',htmlspecialchars($this->sL($TCA[$table]['ctrl']['title'])),$arr[$k]);
  4320. $arr[$k] = str_replace('###RECORD_ICON###', t3lib_iconWorks::getSpriteIconForRecord($table, $rec, array('title' => $this->getRecordPath($table, $rec))), $arr[$k]);
  4321. }
  4322. return $arr;
  4323. }
  4324. /**
  4325. * Wraps an element in the $out_array with the template row for a "section" ($this->sectionWrap)
  4326. *
  4327. * @param array The array with form elements stored in (passed by reference and changed!)
  4328. * @param integer The pointer to the entry in the $out_array (passed by reference and incremented!)
  4329. * @return void
  4330. */
  4331. function wrapBorder(&$out_array,&$out_pointer) {
  4332. if ($this->sectionWrap && $out_array[$out_pointer]) {
  4333. $tableAttribs='';
  4334. $tableAttribs.= $this->borderStyle[0] ? ' style="'.htmlspecialchars($this->borderStyle[0]).'"':'';
  4335. $tableAttribs.= $this->borderStyle[2] ? ' background="'.htmlspecialchars($this->backPath.$this->borderStyle[2]).'"':'';
  4336. $tableAttribs.= $this->borderStyle[3] ? ' class="'.htmlspecialchars($this->borderStyle[3]).'"':'';
  4337. if ($tableAttribs) {
  4338. $tableAttribs='border="0" cellspacing="0" cellpadding="0" width="100%"'.$tableAttribs;
  4339. $out_array[$out_pointer] = str_replace('###CONTENT###',$out_array[$out_pointer],
  4340. str_replace('###TABLE_ATTRIBS###',$tableAttribs,
  4341. str_replace('###SPACE_BEFORE###',intval($this->borderStyle[1]),$this->sectionWrap)));
  4342. }
  4343. $out_pointer++;
  4344. }
  4345. }
  4346. /**
  4347. * Replaces colorscheme markers in the template string
  4348. *
  4349. * @param string Template string with markers to be substituted.
  4350. * @return string
  4351. */
  4352. function rplColorScheme($inTemplate) {
  4353. // Colors:
  4354. $inTemplate = str_replace('###BGCOLOR###',$this->colorScheme[0]?' bgcolor="'.$this->colorScheme[0].'"':'',$inTemplate);
  4355. $inTemplate = str_replace('###BGCOLOR_HEAD###',$this->colorScheme[1]?' bgcolor="'.$this->colorScheme[1].'"':'',$inTemplate);
  4356. $inTemplate = str_replace('###FONTCOLOR_HEAD###',$this->colorScheme[3],$inTemplate);
  4357. // Classes:
  4358. $inTemplate = str_replace('###CLASSATTR_1###',$this->classScheme[0]?' class="'.$this->classScheme[0].'"':'',$inTemplate);
  4359. $inTemplate = str_replace('###CLASSATTR_2###',$this->classScheme[1]?' class="'.$this->classScheme[1].'"':'',$inTemplate);
  4360. $inTemplate = str_replace('###CLASSATTR_4###',$this->classScheme[3]?' class="'.$this->classScheme[3].'"':'',$inTemplate);
  4361. return $inTemplate;
  4362. }
  4363. /**
  4364. * Returns divider.
  4365. * Currently not implemented and returns only blank value.
  4366. *
  4367. * @return string Empty string
  4368. */
  4369. function getDivider() {
  4370. return '';
  4371. }
  4372. /**
  4373. * Creates HTML output for a palette
  4374. *
  4375. * @param array The palette array to print
  4376. * @return string HTML output
  4377. */
  4378. function printPalette($palArr) {
  4379. $fieldAttributes = $labelAttributes = '';
  4380. // Init color/class attributes:
  4381. if ($this->colorScheme[2]) {
  4382. $labelAttributes .= ' bgcolor="' . $this->colorScheme[2] . '"';
  4383. }
  4384. if ($this->classScheme[2]) {
  4385. $labelAttributes .= ' class="t3-form-palette-field-label ' . $this->classScheme[2] . '"';
  4386. } else {
  4387. $labelAttributes .= ' class="t3-form-palette-field-label"';
  4388. }
  4389. if ($this->colorScheme[4]) {
  4390. $fieldAttributes .= ' style="color: ' . $this->colorScheme[4] . '"';
  4391. }
  4392. if ($this->classScheme[4]) {
  4393. $fieldAttributes .= ' class="t3-form-palette-field' . $this->classScheme[4] . '"';
  4394. }
  4395. $row = 0;
  4396. $hRow = $iRow = array();
  4397. $lastLineWasLinebreak = FALSE;
  4398. // Traverse palette fields and render them into containers:
  4399. foreach ($palArr as $content) {
  4400. if ($content['NAME'] === '--linebreak--') {
  4401. if (!$lastLineWasLinebreak) {
  4402. $row++;
  4403. $lastLineWasLinebreak = TRUE;
  4404. }
  4405. } else {
  4406. $lastLineWasLinebreak = FALSE;
  4407. $fieldIdentifierForJs = $content['TABLE'] . '_' . $content['ID'] . '_' . $content['FIELD'];
  4408. $iRow[$row][] = '<span class="t3-form-palette-field-container">' .
  4409. '<label' . $labelAttributes . '>' .
  4410. $content['NAME'] .
  4411. '<img name="req_' . $fieldIdentifierForJs . '" src="clear.gif" class="t3-form-palette-icon-required" alt="" />' .
  4412. '<img name="cm_' . $fieldIdentifierForJs . '" src="clear.gif" class="t3-form-palette-icon-contentchanged" alt="" />' .
  4413. '</label>' .
  4414. '<span' . $fieldAttributes . '>' .
  4415. $content['ITEM'] .
  4416. $content['HELP_ICON'] .
  4417. '</span>' .
  4418. '</span>';
  4419. }
  4420. }
  4421. // Final wrapping into the fieldset:
  4422. $out = '<fieldset class="t3-form-palette-fieldset">';
  4423. for ($i = 0; $i <= $row; $i++) {
  4424. $out .= implode($iRow[$i]);
  4425. }
  4426. $out .= '</fieldset>';
  4427. return $out;
  4428. }
  4429. /**
  4430. * Returns help-text ICON if configured for.
  4431. *
  4432. * @param string The table name
  4433. * @param string The field name
  4434. * @param boolean Force the return of the help-text icon.
  4435. * @return string HTML, <a>-tag with
  4436. */
  4437. function helpTextIcon($table,$field,$force=0) {
  4438. if ($this->globalShowHelp && $GLOBALS['TCA_DESCR'][$table]['columns'][$field] && (($this->edit_showFieldHelp=='icon'&&!$this->doLoadTableDescr($table)) || $force)) {
  4439. return t3lib_BEfunc::helpTextIcon($table, $field, $this->backPath, $force);
  4440. } else {
  4441. // Detects fields with no CSH and outputs dummy line to insert into CSH locallang file:
  4442. return '<span class="nbsp">&nbsp;</span>';
  4443. }
  4444. }
  4445. /**
  4446. * Returns help text DESCRIPTION, if configured for.
  4447. *
  4448. * @param string The table name
  4449. * @param string The field name
  4450. * @return string
  4451. */
  4452. function helpText($table,$field) {
  4453. if ($this->globalShowHelp && $GLOBALS['TCA_DESCR'][$table]['columns'][$field] && ($this->edit_showFieldHelp=='text' || $this->doLoadTableDescr($table))) {
  4454. $fDat = $GLOBALS['TCA_DESCR'][$table]['columns'][$field];
  4455. return '<table border="0" cellpadding="2" cellspacing="0" width="90%"><tr><td valign="top" width="14">'.
  4456. $this->helpTextIcon(
  4457. $table,
  4458. $field,
  4459. $fDat['details']||$fDat['syntax']||$fDat['image_descr']||$fDat['image']||$fDat['seeAlso']
  4460. ).
  4461. '</td><td valign="top"><span class="typo3-TCEforms-helpText">'.
  4462. $GLOBALS['LANG']->hscAndCharConv(strip_tags($fDat['description']),1).
  4463. '</span></td></tr></table>';
  4464. }
  4465. }
  4466. /**
  4467. * Returns help-text ICON if configured for.
  4468. *
  4469. * @param string Field name
  4470. * @param string Field title
  4471. * @param string File name with CSH labels
  4472. * @return string HTML, <a>-tag with
  4473. */
  4474. function helpTextIcon_typeFlex($field, $fieldTitle, $cshFile) {
  4475. if ($this->globalShowHelp && $cshFile) {
  4476. $value = $GLOBALS['LANG']->sL($cshFile . ':' . $field . '.description');
  4477. if (trim($value)) {
  4478. if (substr($fieldTitle, -1, 1) == ':') {
  4479. $fieldTitle = substr($fieldTitle, 0, strlen($fieldTitle) - 1);
  4480. }
  4481. // Hover popup textbox with alttitle and description
  4482. if ($this->edit_showFieldHelp == 'icon') {
  4483. $arrow = t3lib_iconWorks::getSpriteIcon('actions-view-go-forward');
  4484. // add description text
  4485. $hoverText = '<span class="paragraph">' . nl2br(htmlspecialchars($value)) . $arrow . '</span>';
  4486. // put header before the rest of the text
  4487. $alttitle = $GLOBALS['LANG']->sL($cshFile . ':' . $field . '.alttitle');
  4488. if ($alttitle) {
  4489. $hoverText = '<span class="header">' . $alttitle . '</span><br />' . $hoverText;
  4490. }
  4491. $hoverText = '<span class="typo3-csh-inline">' . $GLOBALS['LANG']->hscAndCharConv($hoverText, false) . '</span>';
  4492. }
  4493. // CSH exists
  4494. $params = base64_encode(serialize(array(
  4495. 'cshFile' => $cshFile,
  4496. 'field' => $field,
  4497. 'title' => $fieldTitle
  4498. )));
  4499. $aOnClick = 'vHWin=window.open(\''.$this->backPath.'view_help.php?ffID=' . $params . '\',\'viewFieldHelp\',\'height=400,width=600,status=0,menubar=0,scrollbars=1\');vHWin.focus();return false;';
  4500. return '<a href="#" class="typo3-csh-link" onclick="'.htmlspecialchars($aOnClick).'">'.
  4501. t3lib_iconWorks::getSpriteIcon('actions-system-help-open') . $hoverText .
  4502. '</a>';
  4503. }
  4504. }
  4505. return '';
  4506. }
  4507. /**
  4508. * Returns help text DESCRIPTION, if configured for.
  4509. *
  4510. * @param string Field name
  4511. * @param string CSH file name
  4512. * @return string Description for the field with cion or empty string
  4513. */
  4514. function helpText_typeFlex($field, $fieldTitle, $cshFile) {
  4515. if ($this->globalShowHelp && $cshFile && $this->edit_showFieldHelp == 'text') {
  4516. $value = $GLOBALS['LANG']->sL($cshFile . ':' . $field . '.description');
  4517. if (trim($value)) {
  4518. return '<table border="0" cellpadding="2" cellspacing="0" width="90%"><tr><td valign="top" width="14">' .
  4519. $this->helpTextIcon_typeFlex(
  4520. $field,
  4521. $fieldTitle,
  4522. $cshFile
  4523. ).
  4524. '</td><td valign="top"><span class="typo3-TCEforms-helpText-flexform">' .
  4525. $GLOBALS['LANG']->hscAndCharConv(strip_tags($value), 1) .
  4526. '</span></td></tr></table>';
  4527. }
  4528. }
  4529. return '';
  4530. }
  4531. /**
  4532. * Setting the current color scheme ($this->colorScheme) based on $this->defColorScheme plus input string.
  4533. *
  4534. * @param string A color scheme string.
  4535. * @return void
  4536. */
  4537. function setColorScheme($scheme) {
  4538. $this->colorScheme = $this->defColorScheme;
  4539. $this->classScheme = $this->defClassScheme;
  4540. $parts = t3lib_div::trimExplode(',',$scheme);
  4541. foreach($parts as $key => $col) {
  4542. // Split for color|class:
  4543. list($color,$class) = t3lib_div::trimExplode('|',$col);
  4544. // Handle color values:
  4545. if ($color) $this->colorScheme[$key] = $color;
  4546. if ($color=='-') $this->colorScheme[$key] = '';
  4547. // Handle class values:
  4548. if ($class) $this->classScheme[$key] = $class;
  4549. if ($class=='-') $this->classScheme[$key] = '';
  4550. }
  4551. }
  4552. /**
  4553. * Reset color schemes.
  4554. *
  4555. * @return void
  4556. */
  4557. function resetSchemes() {
  4558. $this->setColorScheme($GLOBALS['TBE_STYLES']['colorschemes'][0]);
  4559. $this->fieldStyle = $GLOBALS['TBE_STYLES']['styleschemes'][0];
  4560. $this->borderStyle = $GLOBALS['TBE_STYLES']['borderschemes'][0];
  4561. }
  4562. /**
  4563. * Store current color scheme
  4564. *
  4565. * @return void
  4566. */
  4567. function storeSchemes() {
  4568. $this->savedSchemes['classScheme'] = $this->classScheme;
  4569. $this->savedSchemes['colorScheme'] = $this->colorScheme;
  4570. $this->savedSchemes['fieldStyle'] = $this->fieldStyle;
  4571. $this->savedSchemes['borderStyle'] = $this->borderStyle;
  4572. }
  4573. /**
  4574. * Restore the saved color scheme
  4575. *
  4576. * @return void
  4577. */
  4578. function restoreSchemes() {
  4579. $this->classScheme = $this->savedSchemes['classScheme'];
  4580. $this->colorScheme = $this->savedSchemes['colorScheme'];
  4581. $this->fieldStyle = $this->savedSchemes['fieldStyle'];
  4582. $this->borderStyle = $this->savedSchemes['borderStyle'];
  4583. }
  4584. /********************************************
  4585. *
  4586. * JavaScript related functions
  4587. *
  4588. ********************************************/
  4589. /**
  4590. * JavaScript code added BEFORE the form is drawn:
  4591. *
  4592. * @return string A <script></script> section with JavaScript.
  4593. */
  4594. function JStop() {
  4595. $out = '';
  4596. // Additional top HTML:
  4597. if (count($this->additionalCode_pre)) {
  4598. $out.= implode('
  4599. <!-- NEXT: -->
  4600. ',$this->additionalCode_pre);
  4601. }
  4602. // Additional top JavaScript
  4603. if (count($this->additionalJS_pre)) {
  4604. $out.='
  4605. <!--
  4606. JavaScript in top of page (before form):
  4607. -->
  4608. <script type="text/javascript">
  4609. /*<![CDATA[*/
  4610. '.implode('
  4611. // NEXT:
  4612. ',$this->additionalJS_pre).'
  4613. /*]]>*/
  4614. </script>
  4615. ';
  4616. }
  4617. // Return result:
  4618. return $out;
  4619. }
  4620. /**
  4621. * JavaScript code used for input-field evaluation.
  4622. *
  4623. * Example use:
  4624. *
  4625. * $msg .= 'Distribution time (hh:mm dd-mm-yy):<br /><input type="text" name="send_mail_datetime_hr" onchange="typo3form.fieldGet(\'send_mail_datetime\', \'datetime\', \'\', 0,0);"' . $GLOBALS['TBE_TEMPLATE']->formWidth(20) . ' /><input type="hidden" value="' . $GLOBALS['EXEC_TIME'] . '" name="send_mail_datetime" /><br />';
  4626. * $this->extJSCODE.='typo3form.fieldSet("send_mail_datetime", "datetime", "", 0,0);';
  4627. *
  4628. * ... and then include the result of this function after the form
  4629. *
  4630. * @param string $formname: The identification of the form on the page.
  4631. * @param boolean $update: Just extend/update existing settings, e.g. for AJAX call
  4632. * @return string A section with JavaScript - if $update is false, embedded in <script></script>
  4633. */
  4634. function JSbottom($formname='forms[0]', $update = false) {
  4635. $jsFile = array();
  4636. $elements = array();
  4637. // required:
  4638. foreach ($this->requiredFields as $itemImgName => $itemName) {
  4639. $match = array();
  4640. if (preg_match('/^(.+)\[((\w|\d|_)+)\]$/', $itemName, $match)) {
  4641. $record = $match[1];
  4642. $field = $match[2];
  4643. $elements[$record][$field]['required'] = 1;
  4644. $elements[$record][$field]['requiredImg'] = $itemImgName;
  4645. if (isset($this->requiredAdditional[$itemName]) && is_array($this->requiredAdditional[$itemName])) {
  4646. $elements[$record][$field]['additional'] = $this->requiredAdditional[$itemName];
  4647. }
  4648. }
  4649. }
  4650. // range:
  4651. foreach ($this->requiredElements as $itemName => $range) {
  4652. if (preg_match('/^(.+)\[((\w|\d|_)+)\]$/', $itemName, $match)) {
  4653. $record = $match[1];
  4654. $field = $match[2];
  4655. $elements[$record][$field]['range'] = array($range[0], $range[1]);
  4656. $elements[$record][$field]['rangeImg'] = $range['imgName'];
  4657. }
  4658. }
  4659. $this->TBE_EDITOR_fieldChanged_func='TBE_EDITOR.fieldChanged_fName(fName,formObj[fName+"_list"]);';
  4660. if (!$update) {
  4661. if ($this->loadMD5_JS) {
  4662. $this->loadJavascriptLib('md5.js');
  4663. }
  4664. /** @var $pageRenderer t3lib_PageRenderer */
  4665. $pageRenderer = $GLOBALS['SOBE']->doc->getPageRenderer();
  4666. $pageRenderer->loadPrototype();
  4667. $pageRenderer->loadExtJS();
  4668. // make textareas resizable and flexible
  4669. if (!($GLOBALS['BE_USER']->uc['resizeTextareas'] == '0' && $GLOBALS['BE_USER']->uc['resizeTextareas_Flexible'] == '0')) {
  4670. $pageRenderer->addCssFile($this->backPath . '../t3lib/js/extjs/ux/resize.css');
  4671. $this->loadJavascriptLib('../t3lib/js/extjs/ux/ext.resizable.js');
  4672. }
  4673. $resizableSettings = array(
  4674. 'textareaMaxHeight' => $GLOBALS['BE_USER']->uc['resizeTextareas_MaxHeight'] >0 ? $GLOBALS['BE_USER']->uc['resizeTextareas_MaxHeight'] : '600',
  4675. 'textareaFlexible' => (!$GLOBALS['BE_USER']->uc['resizeTextareas_Flexible'] == '0'),
  4676. 'textareaResize' => (!$GLOBALS['BE_USER']->uc['resizeTextareas'] == '0'),
  4677. );
  4678. $pageRenderer->addInlineSettingArray('', $resizableSettings);
  4679. $this->loadJavascriptLib('../t3lib/jsfunc.evalfield.js');
  4680. $this->loadJavascriptLib('jsfunc.tbe_editor.js');
  4681. // needed for tceform manipulation (date picker)
  4682. $typo3Settings = array(
  4683. 'datePickerUSmode' => $GLOBALS['TYPO3_CONF_VARS']['SYS']['USdateFormat'] ? 1 : 0,
  4684. 'dateFormat' => array('j-n-Y', 'G:i j-n-Y'),
  4685. 'dateFormatUS' => array('n-j-Y', 'G:i n-j-Y'),
  4686. );
  4687. $pageRenderer->addInlineSettingArray('', $typo3Settings);
  4688. $this->loadJavascriptLib('../t3lib/js/extjs/tceforms.js');
  4689. // if IRRE fields were processed, add the JavaScript functions:
  4690. if ($this->inline->inlineCount) {
  4691. $GLOBALS['SOBE']->doc->getPageRenderer()->loadScriptaculous();
  4692. $this->loadJavascriptLib('../t3lib/jsfunc.inline.js');
  4693. $out .= '
  4694. inline.setPrependFormFieldNames("'.$this->inline->prependNaming.'");
  4695. inline.setNoTitleString("'.addslashes(t3lib_BEfunc::getNoRecordTitle(true)).'");
  4696. ';
  4697. }
  4698. // if Suggest fields were processed, add the JS functions
  4699. if ($this->suggest->suggestCount > 0) {
  4700. $pageRenderer->loadScriptaculous();
  4701. $this->loadJavascriptLib('../t3lib/js/jsfunc.tceforms_suggest.js');
  4702. }
  4703. // Toggle icons:
  4704. $toggleIcon_open = t3lib_iconWorks::getSpriteIcon('actions-move-down', array('title' => 'Open'));
  4705. $toggleIcon_close = t3lib_iconWorks::getSpriteIcon('actions-move-right', array('title' => 'Close'));
  4706. $out .= '
  4707. function getOuterHTML(idTagPrefix) { // Function getting the outerHTML of an element with id
  4708. var str=($(idTagPrefix).inspect()+$(idTagPrefix).innerHTML+"</"+$(idTagPrefix).tagName.toLowerCase()+">");
  4709. return str;
  4710. }
  4711. function flexFormToggle(id) { // Toggling flexform elements on/off:
  4712. Element.toggle(""+id+"-content");
  4713. if (Element.visible(id+"-content")) {
  4714. $(id+"-toggle").update(\''.$toggleIcon_open.'\')
  4715. $(id+"-toggleClosed").value = 0;
  4716. } else {
  4717. $(id+"-toggle").update(\''.$toggleIcon_close.'\');
  4718. $(id+"-toggleClosed").value = 1;
  4719. }
  4720. var previewContent = "";
  4721. var children = $(id+"-content").getElementsByTagName("input");
  4722. for (var i = 0, length = children.length; i < length; i++) {
  4723. if (children[i].type=="text" && children[i].value) previewContent+= (previewContent?" / ":"")+children[i].value;
  4724. }
  4725. if (previewContent.length>80) {
  4726. previewContent = previewContent.substring(0,67)+"...";
  4727. }
  4728. $(id+"-preview").update(previewContent);
  4729. }
  4730. function flexFormToggleSubs(id) { // Toggling sub flexform elements on/off:
  4731. var descendants = $(id).immediateDescendants();
  4732. var isOpen=0;
  4733. var isClosed=0;
  4734. // Traverse and find how many are open or closed:
  4735. for (var i = 0, length = descendants.length; i < length; i++) {
  4736. if (descendants[i].id) {
  4737. if (Element.visible(descendants[i].id+"-content")) {isOpen++;} else {isClosed++;}
  4738. }
  4739. }
  4740. // Traverse and toggle
  4741. for (var i = 0, length = descendants.length; i < length; i++) {
  4742. if (descendants[i].id) {
  4743. if (isOpen!=0 && isClosed!=0) {
  4744. if (Element.visible(descendants[i].id+"-content")) {flexFormToggle(descendants[i].id);}
  4745. } else {
  4746. flexFormToggle(descendants[i].id);
  4747. }
  4748. }
  4749. }
  4750. }
  4751. function flexFormSortable(id) { // Create sortables for flexform sections
  4752. Position.includeScrollOffsets = true;
  4753. Sortable.create(id, {tag:\'div\',constraint: false, onChange:function(){
  4754. setActionStatus(id);
  4755. } });
  4756. }
  4757. function setActionStatus(id) { // Updates the "action"-status for a section. This is used to move and delete elements.
  4758. var descendants = $(id).immediateDescendants();
  4759. // Traverse and find how many are open or closed:
  4760. for (var i = 0, length = descendants.length; i < length; i++) {
  4761. if (descendants[i].id) {
  4762. $(descendants[i].id+"-action").value = descendants[i].visible() ? i : "DELETE";
  4763. }
  4764. }
  4765. }
  4766. TBE_EDITOR.images.req.src = "'.t3lib_iconWorks::skinImg($this->backPath,'gfx/required_h.gif','',1).'";
  4767. TBE_EDITOR.images.cm.src = "'.t3lib_iconWorks::skinImg($this->backPath,'gfx/content_client.gif','',1).'";
  4768. TBE_EDITOR.images.sel.src = "'.t3lib_iconWorks::skinImg($this->backPath,'gfx/content_selected.gif','',1).'";
  4769. TBE_EDITOR.images.clear.src = "'.$this->backPath.'clear.gif";
  4770. TBE_EDITOR.auth_timeout_field = '.intval($GLOBALS['BE_USER']->auth_timeout_field).';
  4771. TBE_EDITOR.formname = "'.$formname.'";
  4772. TBE_EDITOR.formnameUENC = "'.rawurlencode($formname).'";
  4773. TBE_EDITOR.backPath = "'.addslashes($this->backPath).'";
  4774. TBE_EDITOR.prependFormFieldNames = "'.$this->prependFormFieldNames.'";
  4775. TBE_EDITOR.prependFormFieldNamesUENC = "'.rawurlencode($this->prependFormFieldNames).'";
  4776. TBE_EDITOR.prependFormFieldNamesCnt = '.substr_count($this->prependFormFieldNames,'[').';
  4777. TBE_EDITOR.isPalettedoc = '.($this->isPalettedoc ? addslashes($this->isPalettedoc) : 'null').';
  4778. TBE_EDITOR.doSaveFieldName = "'.($this->doSaveFieldName ? addslashes($this->doSaveFieldName) : '').'";
  4779. TBE_EDITOR.labels.fieldsChanged = '.$GLOBALS['LANG']->JScharCode($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.fieldsChanged')).';
  4780. TBE_EDITOR.labels.fieldsMissing = '.$GLOBALS['LANG']->JScharCode($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.fieldsMissing')).';
  4781. TBE_EDITOR.labels.refresh_login = '.$GLOBALS['LANG']->JScharCode($this->getLL('m_refresh_login')).';
  4782. TBE_EDITOR.labels.onChangeAlert = '.$GLOBALS['LANG']->JScharCode($this->getLL('m_onChangeAlert')).';
  4783. evalFunc.USmode = '.($GLOBALS['TYPO3_CONF_VARS']['SYS']['USdateFormat']?'1':'0').';
  4784. TBE_EDITOR.backend_interface = "'.$GLOBALS['BE_USER']->uc['interfaceSetup'].'";
  4785. ';
  4786. }
  4787. // add JS required for inline fields
  4788. if (count($this->inline->inlineData)) {
  4789. $out .= '
  4790. inline.addToDataArray(' . json_encode($this->inline->inlineData) . ');
  4791. ';
  4792. }
  4793. // Registered nested elements for tabs or inline levels:
  4794. if (count($this->requiredNested)) {
  4795. $out .= '
  4796. TBE_EDITOR.addNested(' . json_encode($this->requiredNested) . ');
  4797. ';
  4798. }
  4799. // elements which are required or have a range definition:
  4800. if (count($elements)) {
  4801. $out .= '
  4802. TBE_EDITOR.addElements(' . json_encode($elements) . ');
  4803. TBE_EDITOR.initRequired();
  4804. ';
  4805. }
  4806. // $this->additionalJS_submit:
  4807. if ($this->additionalJS_submit) {
  4808. $additionalJS_submit = implode('', $this->additionalJS_submit);
  4809. $additionalJS_submit = str_replace(CR, '', $additionalJS_submit);
  4810. $additionalJS_submit = str_replace(LF, '', $additionalJS_submit);
  4811. $out .= '
  4812. TBE_EDITOR.addActionChecks("submit", "'.addslashes($additionalJS_submit).'");
  4813. ';
  4814. }
  4815. $out .= LF.implode(LF,$this->additionalJS_post).LF.$this->extJSCODE;
  4816. $out .= '
  4817. TBE_EDITOR.loginRefreshed();
  4818. ';
  4819. // Regular direct output:
  4820. if (!$update) {
  4821. $spacer = LF . TAB;
  4822. $out = $spacer . implode($spacer, $jsFile) . t3lib_div::wrapJS($out);
  4823. }
  4824. return $out;
  4825. }
  4826. /**
  4827. * Used to connect the db/file browser with this document and the formfields on it!
  4828. *
  4829. * @param string Form object reference (including "document.")
  4830. * @return string JavaScript functions/code (NOT contained in a <script>-element)
  4831. */
  4832. function dbFileCon($formObj='document.forms[0]') {
  4833. // @TODO: Export this to an own file, it is more static than dynamic JavaScript -- olly
  4834. $str='
  4835. // ***************
  4836. // Used to connect the db/file browser with this document and the formfields on it!
  4837. // ***************
  4838. var browserWin="";
  4839. function setFormValueOpenBrowser(mode,params) { //
  4840. var url = "'.$this->backPath.'browser.php?mode="+mode+"&bparams="+params;
  4841. browserWin = window.open(url,"Typo3WinBrowser","height=650,width="+(mode=="db"?650:600)+",status=0,menubar=0,resizable=1,scrollbars=1");
  4842. browserWin.focus();
  4843. }
  4844. function setFormValueFromBrowseWin(fName,value,label,exclusiveValues) { //
  4845. var formObj = setFormValue_getFObj(fName)
  4846. if (formObj && value!="--div--") {
  4847. fObj = formObj[fName+"_list"];
  4848. var len = fObj.length;
  4849. // Clear elements if exclusive values are found
  4850. if (exclusiveValues) {
  4851. var m = new RegExp("(^|,)"+value+"($|,)");
  4852. if (exclusiveValues.match(m)) {
  4853. // the new value is exclusive
  4854. for (a=len-1;a>=0;a--) fObj[a] = null;
  4855. len = 0;
  4856. } else if (len == 1) {
  4857. m = new RegExp("(^|,)"+fObj.options[0].value+"($|,)");
  4858. if (exclusiveValues.match(m)) {
  4859. // the old value is exclusive
  4860. fObj[0] = null;
  4861. len = 0;
  4862. }
  4863. }
  4864. }
  4865. // Inserting element
  4866. var setOK = 1;
  4867. if (!formObj[fName+"_mul"] || formObj[fName+"_mul"].value==0) {
  4868. for (a=0;a<len;a++) {
  4869. if (fObj.options[a].value==value) {
  4870. setOK = 0;
  4871. }
  4872. }
  4873. }
  4874. if (setOK) {
  4875. fObj.length++;
  4876. fObj.options[len].value = value;
  4877. fObj.options[len].text = unescape(label);
  4878. // Traversing list and set the hidden-field
  4879. setHiddenFromList(fObj,formObj[fName]);
  4880. '.$this->TBE_EDITOR_fieldChanged_func.'
  4881. }
  4882. }
  4883. }
  4884. function setHiddenFromList(fObjSel,fObjHid) { //
  4885. l=fObjSel.length;
  4886. fObjHid.value="";
  4887. for (a=0;a<l;a++) {
  4888. fObjHid.value+=fObjSel.options[a].value+",";
  4889. }
  4890. }
  4891. function setFormValueManipulate(fName,type) { //
  4892. var formObj = setFormValue_getFObj(fName)
  4893. if (formObj) {
  4894. var localArray_V = new Array();
  4895. var localArray_L = new Array();
  4896. var localArray_S = new Array();
  4897. var fObjSel = formObj[fName+"_list"];
  4898. var l=fObjSel.length;
  4899. var c=0;
  4900. if ((type=="Remove" && fObjSel.size > 1) || type=="Top" || type=="Bottom") {
  4901. if (type=="Top") {
  4902. for (a=0;a<l;a++) {
  4903. if (fObjSel.options[a].selected==1) {
  4904. localArray_V[c]=fObjSel.options[a].value;
  4905. localArray_L[c]=fObjSel.options[a].text;
  4906. localArray_S[c]=1;
  4907. c++;
  4908. }
  4909. }
  4910. }
  4911. for (a=0;a<l;a++) {
  4912. if (fObjSel.options[a].selected!=1) {
  4913. localArray_V[c]=fObjSel.options[a].value;
  4914. localArray_L[c]=fObjSel.options[a].text;
  4915. localArray_S[c]=0;
  4916. c++;
  4917. }
  4918. }
  4919. if (type=="Bottom") {
  4920. for (a=0;a<l;a++) {
  4921. if (fObjSel.options[a].selected==1) {
  4922. localArray_V[c]=fObjSel.options[a].value;
  4923. localArray_L[c]=fObjSel.options[a].text;
  4924. localArray_S[c]=1;
  4925. c++;
  4926. }
  4927. }
  4928. }
  4929. }
  4930. if (type=="Down") {
  4931. var tC = 0;
  4932. var tA = new Array();
  4933. for (a=0;a<l;a++) {
  4934. if (fObjSel.options[a].selected!=1) {
  4935. // Add non-selected element:
  4936. localArray_V[c]=fObjSel.options[a].value;
  4937. localArray_L[c]=fObjSel.options[a].text;
  4938. localArray_S[c]=0;
  4939. c++;
  4940. // Transfer any accumulated and reset:
  4941. if (tA.length > 0) {
  4942. for (aa=0;aa<tA.length;aa++) {
  4943. localArray_V[c]=fObjSel.options[tA[aa]].value;
  4944. localArray_L[c]=fObjSel.options[tA[aa]].text;
  4945. localArray_S[c]=1;
  4946. c++;
  4947. }
  4948. var tC = 0;
  4949. var tA = new Array();
  4950. }
  4951. } else {
  4952. tA[tC] = a;
  4953. tC++;
  4954. }
  4955. }
  4956. // Transfer any remaining:
  4957. if (tA.length > 0) {
  4958. for (aa=0;aa<tA.length;aa++) {
  4959. localArray_V[c]=fObjSel.options[tA[aa]].value;
  4960. localArray_L[c]=fObjSel.options[tA[aa]].text;
  4961. localArray_S[c]=1;
  4962. c++;
  4963. }
  4964. }
  4965. }
  4966. if (type=="Up") {
  4967. var tC = 0;
  4968. var tA = new Array();
  4969. var c = l-1;
  4970. for (a=l-1;a>=0;a--) {
  4971. if (fObjSel.options[a].selected!=1) {
  4972. // Add non-selected element:
  4973. localArray_V[c]=fObjSel.options[a].value;
  4974. localArray_L[c]=fObjSel.options[a].text;
  4975. localArray_S[c]=0;
  4976. c--;
  4977. // Transfer any accumulated and reset:
  4978. if (tA.length > 0) {
  4979. for (aa=0;aa<tA.length;aa++) {
  4980. localArray_V[c]=fObjSel.options[tA[aa]].value;
  4981. localArray_L[c]=fObjSel.options[tA[aa]].text;
  4982. localArray_S[c]=1;
  4983. c--;
  4984. }
  4985. var tC = 0;
  4986. var tA = new Array();
  4987. }
  4988. } else {
  4989. tA[tC] = a;
  4990. tC++;
  4991. }
  4992. }
  4993. // Transfer any remaining:
  4994. if (tA.length > 0) {
  4995. for (aa=0;aa<tA.length;aa++) {
  4996. localArray_V[c]=fObjSel.options[tA[aa]].value;
  4997. localArray_L[c]=fObjSel.options[tA[aa]].text;
  4998. localArray_S[c]=1;
  4999. c--;
  5000. }
  5001. }
  5002. c=l; // Restore length value in "c"
  5003. }
  5004. // Transfer items in temporary storage to list object:
  5005. fObjSel.length = c;
  5006. for (a=0;a<c;a++) {
  5007. fObjSel.options[a].value = localArray_V[a];
  5008. fObjSel.options[a].text = localArray_L[a];
  5009. fObjSel.options[a].selected = localArray_S[a];
  5010. }
  5011. setHiddenFromList(fObjSel,formObj[fName]);
  5012. '.$this->TBE_EDITOR_fieldChanged_func.'
  5013. }
  5014. }
  5015. function setFormValue_getFObj(fName) { //
  5016. var formObj = '.$formObj.';
  5017. if (formObj) {
  5018. if (formObj[fName] && formObj[fName+"_list"] && formObj[fName+"_list"].type=="select-multiple") {
  5019. return formObj;
  5020. } else {
  5021. alert("Formfields missing:\n fName: "+formObj[fName]+"\n fName_list:"+formObj[fName+"_list"]+"\n type:"+formObj[fName+"_list"].type+"\n fName:"+fName);
  5022. }
  5023. }
  5024. return "";
  5025. }
  5026. // END: dbFileCon parts.
  5027. ';
  5028. return $str;
  5029. }
  5030. /**
  5031. * Prints necessary JavaScript for TCEforms (after the form HTML).
  5032. *
  5033. * @return void
  5034. */
  5035. function printNeededJSFunctions() {
  5036. // JS evaluation:
  5037. $out = $this->JSbottom($this->formName);
  5038. // Integrate JS functions for the element browser if such fields or IRRE fields were processed:
  5039. if ($this->printNeededJS['dbFileIcons'] || $this->inline->inlineCount) {
  5040. $out.= '
  5041. <!--
  5042. JavaScript after the form has been drawn:
  5043. -->
  5044. <script type="text/javascript">
  5045. /*<![CDATA[*/
  5046. '.$this->dbFileCon('document.'.$this->formName).'
  5047. /*]]>*/
  5048. </script>';
  5049. }
  5050. return $out;
  5051. }
  5052. /**
  5053. * Returns necessary JavaScript for the top
  5054. *
  5055. * @return void
  5056. */
  5057. function printNeededJSFunctions_top() {
  5058. // JS evaluation:
  5059. $out = $this->JStop($this->formName);
  5060. return $out;
  5061. }
  5062. /**
  5063. * Includes a javascript library that exists in the core /typo3/ directory. The
  5064. * backpath is automatically applied.
  5065. * This method acts as wrapper for $GLOBALS['SOBE']->doc->loadJavascriptLib($lib).
  5066. *
  5067. * @param string $lib: Library name. Call it with the full path like "contrib/prototype/prototype.js" to load it
  5068. * @return void
  5069. */
  5070. public function loadJavascriptLib($lib) {
  5071. $GLOBALS['SOBE']->doc->loadJavascriptLib($lib);
  5072. }
  5073. /********************************************
  5074. *
  5075. * Various helper functions
  5076. *
  5077. ********************************************/
  5078. /**
  5079. * Gets default record. Maybe not used anymore. FE-editor?
  5080. *
  5081. * @param string Database Tablename
  5082. * @param integer PID value (positive / negative)
  5083. * @return array "default" row.
  5084. */
  5085. function getDefaultRecord($table,$pid=0) {
  5086. global $TCA;
  5087. if ($TCA[$table]) {
  5088. t3lib_div::loadTCA($table);
  5089. $row = array();
  5090. if ($pid<0 && $TCA[$table]['ctrl']['useColumnsForDefaultValues']) {
  5091. // Fetches the previous record:
  5092. $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', $table, 'uid='.abs($pid).t3lib_BEfunc::deleteClause($table));
  5093. if ($drow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
  5094. // Gets the list of fields to copy from the previous record.
  5095. $fArr = explode(',',$TCA[$table]['ctrl']['useColumnsForDefaultValues']);
  5096. foreach($fArr as $theF) {
  5097. if ($TCA[$table]['columns'][$theF]) {
  5098. $row[$theF] = $drow[$theF];
  5099. }
  5100. }
  5101. }
  5102. $GLOBALS['TYPO3_DB']->sql_free_result($res);
  5103. }
  5104. foreach($TCA[$table]['columns'] as $field => $info) {
  5105. if (isset($info['config']['default'])) {
  5106. $row[$field] = $info['config']['default'];
  5107. }
  5108. }
  5109. return $row;
  5110. }
  5111. }
  5112. /**
  5113. * Return record path (visually formatted, using t3lib_BEfunc::getRecordPath() )
  5114. *
  5115. * @param string Table name
  5116. * @param array Record array
  5117. * @return string The record path.
  5118. * @see t3lib_BEfunc::getRecordPath()
  5119. */
  5120. function getRecordPath($table,$rec) {
  5121. t3lib_BEfunc::fixVersioningPid($table,$rec);
  5122. list($tscPID,$thePidValue)=$this->getTSCpid($table,$rec['uid'],$rec['pid']);
  5123. if ($thePidValue>=0) {
  5124. return t3lib_BEfunc::getRecordPath($tscPID,$this->readPerms(),15);
  5125. }
  5126. }
  5127. /**
  5128. * Returns the select-page read-access SQL clause.
  5129. * Returns cached string, so you can call this function as much as you like without performance loss.
  5130. *
  5131. * @return string
  5132. */
  5133. function readPerms() {
  5134. if (!$this->perms_clause_set) {
  5135. $this->perms_clause = $GLOBALS['BE_USER']->getPagePermsClause(1);
  5136. $this->perms_clause_set=1;
  5137. }
  5138. return $this->perms_clause;
  5139. }
  5140. /**
  5141. * Fetches language label for key
  5142. *
  5143. * @param string Language label reference, eg. 'LLL:EXT:lang/locallang_core.php:labels.blablabla'
  5144. * @return string The value of the label, fetched for the current backend language.
  5145. */
  5146. function sL($str) {
  5147. return $GLOBALS['LANG']->sL($str);
  5148. }
  5149. /**
  5150. * Returns language label from locallang_core.php
  5151. * Labels must be prefixed with either "l_" or "m_".
  5152. * The prefix "l_" maps to the prefix "labels." inside locallang_core.php
  5153. * The prefix "m_" maps to the prefix "mess." inside locallang_core.php
  5154. *
  5155. * @param string The label key
  5156. * @return string The value of the label, fetched for the current backend language.
  5157. */
  5158. function getLL($str) {
  5159. $content = '';
  5160. switch(substr($str,0,2)) {
  5161. case 'l_':
  5162. $content = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.'.substr($str,2));
  5163. break;
  5164. case 'm_':
  5165. $content = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:mess.'.substr($str,2));
  5166. break;
  5167. }
  5168. return $content;
  5169. }
  5170. /**
  5171. * Returns true, if the palette, $palette, is collapsed (not shown, but found in top-frame) for the table.
  5172. *
  5173. * @param string The table name
  5174. * @param integer The palette pointer/number
  5175. * @return boolean
  5176. */
  5177. function isPalettesCollapsed($table,$palette) {
  5178. global $TCA;
  5179. if ($TCA[$table]['ctrl']['canNotCollapse']) return 0;
  5180. if (is_array($TCA[$table]['palettes'][$palette]) && $TCA[$table]['palettes'][$palette]['canNotCollapse']) return 0;
  5181. return $this->palettesCollapsed;
  5182. }
  5183. /**
  5184. * Returns true, if the evaluation of the required-field code is OK.
  5185. *
  5186. * @param string The required-field code
  5187. * @param array The record to evaluate
  5188. * @param string FlexForm value key, eg. vDEF
  5189. * @return boolean
  5190. */
  5191. function isDisplayCondition($displayCond,$row,$ffValueKey='') {
  5192. $output = FALSE;
  5193. $parts = explode(':',$displayCond);
  5194. switch((string)$parts[0]) { // Type of condition:
  5195. case 'FIELD':
  5196. if ($ffValueKey) {
  5197. if (strpos($parts[1], 'parentRec.') !== FALSE) {
  5198. $fParts = explode('.',$parts[1]);
  5199. $theFieldValue = $row['parentRec'][$fParts[1]];
  5200. } else {
  5201. $theFieldValue = $row[$parts[1]][$ffValueKey];
  5202. }
  5203. } else {
  5204. $theFieldValue = $row[$parts[1]];
  5205. }
  5206. switch((string)$parts[2]) {
  5207. case 'REQ':
  5208. if (strtolower($parts[3])=='true') {
  5209. $output = $theFieldValue ? TRUE : FALSE;
  5210. } elseif (strtolower($parts[3])=='false') {
  5211. $output = !$theFieldValue ? TRUE : FALSE;
  5212. }
  5213. break;
  5214. case '>':
  5215. $output = $theFieldValue > $parts[3];
  5216. break;
  5217. case '<':
  5218. $output = $theFieldValue < $parts[3];
  5219. break;
  5220. case '>=':
  5221. $output = $theFieldValue >= $parts[3];
  5222. break;
  5223. case '<=':
  5224. $output = $theFieldValue <= $parts[3];
  5225. break;
  5226. case '-':
  5227. case '!-':
  5228. $cmpParts = explode('-',$parts[3]);
  5229. $output = $theFieldValue >= $cmpParts[0] && $theFieldValue <= $cmpParts[1];
  5230. if ($parts[2]{0}=='!') $output = !$output;
  5231. break;
  5232. case 'IN':
  5233. case '!IN':
  5234. $output = t3lib_div::inList($parts[3],$theFieldValue);
  5235. if ($parts[2]{0}=='!') $output = !$output;
  5236. break;
  5237. case '=':
  5238. case '!=':
  5239. $output = t3lib_div::inList($parts[3],$theFieldValue);
  5240. if ($parts[2]{0}=='!') $output = !$output;
  5241. break;
  5242. }
  5243. break;
  5244. case 'EXT':
  5245. switch((string)$parts[2]) {
  5246. case 'LOADED':
  5247. if (strtolower($parts[3])=='true') {
  5248. $output = t3lib_extMgm::isLoaded($parts[1]) ? TRUE : FALSE;
  5249. } elseif (strtolower($parts[3])=='false') {
  5250. $output = !t3lib_extMgm::isLoaded($parts[1]) ? TRUE : FALSE;
  5251. }
  5252. break;
  5253. }
  5254. break;
  5255. case 'REC':
  5256. switch((string)$parts[1]) {
  5257. case 'NEW':
  5258. if (strtolower($parts[2])=='true') {
  5259. $output = !(intval($row['uid']) > 0) ? TRUE : FALSE;
  5260. } elseif (strtolower($parts[2])=='false') {
  5261. $output = (intval($row['uid']) > 0) ? TRUE : FALSE;
  5262. }
  5263. break;
  5264. }
  5265. break;
  5266. case 'HIDE_L10N_SIBLINGS':
  5267. if ($ffValueKey==='vDEF') {
  5268. $output = TRUE;
  5269. } elseif ($parts[1]==='except_admin' && $GLOBALS['BE_USER']->isAdmin()) {
  5270. $output = TRUE;
  5271. }
  5272. break;
  5273. case 'HIDE_FOR_NON_ADMINS':
  5274. $output = $GLOBALS['BE_USER']->isAdmin() ? TRUE : FALSE;
  5275. break;
  5276. case 'VERSION':
  5277. switch((string)$parts[1]) {
  5278. case 'IS':
  5279. if (strtolower($parts[2])=='true') {
  5280. $output = intval($row['pid'])==-1 ? TRUE : FALSE;
  5281. } elseif (strtolower($parts[2])=='false') {
  5282. $output = !(intval($row['pid'])==-1) ? TRUE : FALSE;
  5283. }
  5284. break;
  5285. }
  5286. break;
  5287. }
  5288. return $output;
  5289. }
  5290. /**
  5291. * Return TSCpid (cached)
  5292. * Using t3lib_BEfunc::getTSCpid()
  5293. *
  5294. * @param string Tablename
  5295. * @param string UID value
  5296. * @param string PID value
  5297. * @return integer Returns the REAL pid of the record, if possible. If both $uid and $pid is strings, then pid=-1 is returned as an error indication.
  5298. * @see t3lib_BEfunc::getTSCpid()
  5299. */
  5300. function getTSCpid($table,$uid,$pid) {
  5301. $key = $table.':'.$uid.':'.$pid;
  5302. if (!isset($this->cache_getTSCpid[$key])) {
  5303. $this->cache_getTSCpid[$key] = t3lib_BEfunc::getTSCpid($table,$uid,$pid);
  5304. }
  5305. return $this->cache_getTSCpid[$key];
  5306. }
  5307. /**
  5308. * Returns true if descriptions should be loaded always
  5309. *
  5310. * @param string Table for which to check
  5311. * @return boolean
  5312. */
  5313. function doLoadTableDescr($table) {
  5314. global $TCA;
  5315. return $TCA[$table]['interface']['always_description'];
  5316. }
  5317. /**
  5318. * Returns an array of available languages (to use for FlexForms)
  5319. *
  5320. * @param boolean If set, only languages which are paired with a static_info_table / static_language record will be returned.
  5321. * @param boolean If set, an array entry for a default language is set.
  5322. * @return array
  5323. */
  5324. function getAvailableLanguages($onlyIsoCoded=1,$setDefault=1) {
  5325. $isL = t3lib_extMgm::isLoaded('static_info_tables');
  5326. // Find all language records in the system:
  5327. $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('static_lang_isocode,title,uid', 'sys_language', 'pid=0 AND hidden=0'.t3lib_BEfunc::deleteClause('sys_language'), '', 'title');
  5328. // Traverse them:
  5329. $output=array();
  5330. if ($setDefault) {
  5331. $output[0]=array(
  5332. 'uid' => 0,
  5333. 'title' => 'Default language',
  5334. 'ISOcode' => 'DEF'
  5335. );
  5336. }
  5337. while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
  5338. $output[$row['uid']]=$row;
  5339. if ($isL && $row['static_lang_isocode']) {
  5340. $rr = t3lib_BEfunc::getRecord('static_languages',$row['static_lang_isocode'],'lg_iso_2');
  5341. if ($rr['lg_iso_2']) $output[$row['uid']]['ISOcode']=$rr['lg_iso_2'];
  5342. }
  5343. if ($onlyIsoCoded && !$output[$row['uid']]['ISOcode']) unset($output[$row['uid']]);
  5344. }
  5345. return $output;
  5346. }
  5347. /**
  5348. * Initializes language icons etc.
  5349. *
  5350. * param string Table name
  5351. * param array Record
  5352. * param string Sys language uid OR ISO language code prefixed with "v", eg. "vDA"
  5353. * @return void
  5354. */
  5355. function getLanguageIcon($table,$row,$sys_language_uid) {
  5356. global $TCA,$LANG;
  5357. $mainKey = $table.':'.$row['uid'];
  5358. if (!isset($this->cachedLanguageFlag[$mainKey])) {
  5359. t3lib_BEfunc::fixVersioningPid($table,$row);
  5360. list($tscPID,$thePidValue) = $this->getTSCpid($table,$row['uid'],$row['pid']);
  5361. $t8Tools = t3lib_div::makeInstance('t3lib_transl8tools');
  5362. $this->cachedLanguageFlag[$mainKey] = $t8Tools->getSystemLanguages($tscPID, $this->backPath);
  5363. }
  5364. // Convert sys_language_uid to sys_language_uid if input was in fact a string (ISO code expected then)
  5365. if (!t3lib_div::testInt($sys_language_uid)) {
  5366. foreach($this->cachedLanguageFlag[$mainKey] as $rUid => $cD) {
  5367. if ('v'.$cD['ISOcode']===$sys_language_uid) {
  5368. $sys_language_uid = $rUid;
  5369. }
  5370. }
  5371. }
  5372. return ($this->cachedLanguageFlag[$mainKey][$sys_language_uid]['flagIcon'] ? '<img src="'.$this->cachedLanguageFlag[$mainKey][$sys_language_uid]['flagIcon'].'" class="absmiddle" alt="" />' : ($this->cachedLanguageFlag[$mainKey][$sys_language_uid]['title'] ? '['.$this->cachedLanguageFlag[$mainKey][$sys_language_uid]['title'].']' : '')).'&nbsp;';
  5373. }
  5374. /**
  5375. * Rendering preview output of a field value which is not shown as a form field but just outputted.
  5376. *
  5377. * @param string The value to output
  5378. * @param array Configuration for field.
  5379. * @param string Name of field.
  5380. * @return string HTML formatted output
  5381. */
  5382. function previewFieldValue($value, $config, $field = '') {
  5383. if ($config['config']['type']==='group' &&
  5384. ($config['config']['internal_type'] === 'file' ||
  5385. $config['config']['internal_type'] === 'file_reference')) {
  5386. // Ignore uploadfolder if internal_type is file_reference
  5387. if ($config['config']['internal_type'] === 'file_reference') {
  5388. $config['config']['uploadfolder'] = '';
  5389. }
  5390. $show_thumbs = TRUE;
  5391. $table = 'tt_content';
  5392. // Making the array of file items:
  5393. $itemArray = t3lib_div::trimExplode(',',$value,1);
  5394. // Showing thumbnails:
  5395. $thumbsnail = '';
  5396. if ($show_thumbs) {
  5397. $imgs = array();
  5398. foreach($itemArray as $imgRead) {
  5399. $imgP = explode('|',$imgRead);
  5400. $imgPath = rawurldecode($imgP[0]);
  5401. $rowCopy = array();
  5402. $rowCopy[$field] = $imgPath;
  5403. // Icon + clickmenu:
  5404. $absFilePath = t3lib_div::getFileAbsFileName($config['config']['uploadfolder'] ? $config['config']['uploadfolder'] . '/' . $imgPath : $imgPath);
  5405. $fI = pathinfo($imgPath);
  5406. $fileIcon = t3lib_BEfunc::getFileIcon(strtolower($fI['extension']));
  5407. $fileIcon = '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/fileicons/'.$fileIcon,'width="18" height="16"').' class="absmiddle" title="'.htmlspecialchars($fI['basename'].($absFilePath && @is_file($absFilePath) ? ' ('.t3lib_div::formatSize(filesize($absFilePath)).'bytes)' : ' - FILE NOT FOUND!')).'" alt="" />';
  5408. $imgs[] = '<span class="nobr">'.t3lib_BEfunc::thumbCode($rowCopy,$table,$field,$this->backPath,'thumbs.php',$config['config']['uploadfolder'],0,' align="middle"').
  5409. ($absFilePath ? $this->getClickMenu($fileIcon, $absFilePath) : $fileIcon).
  5410. $imgPath.
  5411. '</span>';
  5412. }
  5413. $thumbsnail = implode('<br />',$imgs);
  5414. }
  5415. return $thumbsnail;
  5416. } else {
  5417. return nl2br(htmlspecialchars($value));
  5418. }
  5419. }
  5420. /**
  5421. * Generates and return information about which languages the current user should see in preview, configured by options.additionalPreviewLanguages
  5422. *
  5423. * return array Array of additional languages to preview
  5424. */
  5425. function getAdditionalPreviewLanguages() {
  5426. if (!isset($this->cachedAdditionalPreviewLanguages)) {
  5427. if ($GLOBALS['BE_USER']->getTSConfigVal('options.additionalPreviewLanguages')) {
  5428. $uids = t3lib_div::intExplode(',',$GLOBALS['BE_USER']->getTSConfigVal('options.additionalPreviewLanguages'));
  5429. foreach($uids as $uid) {
  5430. if ($sys_language_rec = t3lib_BEfunc::getRecord('sys_language',$uid)) {
  5431. $this->cachedAdditionalPreviewLanguages[$uid] = array('uid' => $uid);
  5432. if ($sys_language_rec['static_lang_isocode'] && t3lib_extMgm::isLoaded('static_info_tables')) {
  5433. $staticLangRow = t3lib_BEfunc::getRecord('static_languages',$sys_language_rec['static_lang_isocode'],'lg_iso_2');
  5434. if ($staticLangRow['lg_iso_2']) {
  5435. $this->cachedAdditionalPreviewLanguages[$uid]['uid'] = $uid;
  5436. $this->cachedAdditionalPreviewLanguages[$uid]['ISOcode'] = $staticLangRow['lg_iso_2'];
  5437. }
  5438. }
  5439. }
  5440. }
  5441. } else {
  5442. // None:
  5443. $this->cachedAdditionalPreviewLanguages = array();
  5444. }
  5445. }
  5446. return $this->cachedAdditionalPreviewLanguages;
  5447. }
  5448. /**
  5449. * Push a new element to the dynNestedStack. Thus, every object know, if it's
  5450. * nested in a tab or IRRE level and in which order this was processed.
  5451. *
  5452. * @param string $type: Type of the level, e.g. "tab" or "inline"
  5453. * @param string $ident: Identifier of the level
  5454. * @return void
  5455. */
  5456. function pushToDynNestedStack($type, $ident) {
  5457. $this->dynNestedStack[] = array($type, $ident);
  5458. }
  5459. /**
  5460. * Remove an element from the dynNestedStack. If $type and $ident
  5461. * are set, the last element will only be removed, if it matches
  5462. * what is expected to be removed.
  5463. *
  5464. * @param string $type: Type of the level, e.g. "tab" or "inline"
  5465. * @param string $ident: Identifier of the level
  5466. * @return void
  5467. */
  5468. function popFromDynNestedStack($type=null, $ident=null) {
  5469. if ($type!=null && $ident!=null) {
  5470. $last = end($this->dynNestedStack);
  5471. if ($type==$last[0] && $ident==$last[1]) {
  5472. array_pop($this->dynNestedStack);
  5473. }
  5474. } else {
  5475. array_pop($this->dynNestedStack);
  5476. }
  5477. }
  5478. /**
  5479. * Get the dynNestedStack as associative array.
  5480. * The result is e.g. ['tab','DTM-ABCD-1'], ['inline','data[13][table][uid][field]'], ['tab','DTM-DEFG-2'], ...
  5481. *
  5482. * @param boolean $json: Return a JSON string instead of an array - default: false
  5483. * @param boolean $skipFirst: Skip the first element in the dynNestedStack - default: false
  5484. * @return mixed Returns an associative array by default. If $json is true, it will be returned as JSON string.
  5485. */
  5486. function getDynNestedStack($json=false, $skipFirst=false) {
  5487. $result = $this->dynNestedStack;
  5488. if ($skipFirst) {
  5489. array_shift($result);
  5490. }
  5491. return ($json ? json_encode($result) : $result);
  5492. }
  5493. /**
  5494. * Takes care of registering properties in requiredFields and requiredElements.
  5495. * The current hierarchy of IRRE and/or Tabs is stored. Thus, it is possible to determine,
  5496. * which required field/element was filled incorrectly and show it, even if the Tab or IRRE
  5497. * level is hidden.
  5498. *
  5499. * @param string $type: Type of requirement ('field' or 'range')
  5500. * @param string $name: The name of the form field
  5501. * @param mixed $value: For type 'field' string, for type 'range' array
  5502. * @return void
  5503. */
  5504. protected function registerRequiredProperty($type, $name, $value) {
  5505. if ($type == 'field' && is_string($value)) {
  5506. $this->requiredFields[$name] = $value;
  5507. // requiredFields have name/value swapped! For backward compatibility we keep this:
  5508. $itemName = $value;
  5509. } elseif ($type == 'range' && is_array($value)) {
  5510. $this->requiredElements[$name] = $value;
  5511. $itemName = $name;
  5512. }
  5513. // Set the situation of nesting for the current field:
  5514. $this->registerNestedElement($itemName);
  5515. }
  5516. /**
  5517. * Sets the current situation of nested tabs and inline levels for a given element.
  5518. *
  5519. * @param string $itemName: The element the nesting should be stored for
  5520. * @param boolean $setLevel: Set the reverse level lookup - default: true
  5521. * @return void
  5522. */
  5523. protected function registerNestedElement($itemName, $setLevel=true) {
  5524. $dynNestedStack = $this->getDynNestedStack();
  5525. if (count($dynNestedStack) && preg_match('/^(.+\])\[(\w+)\]$/', $itemName, $match)) {
  5526. array_shift($match);
  5527. $this->requiredNested[$itemName] = array(
  5528. 'parts' => $match,
  5529. 'level' => $dynNestedStack,
  5530. );
  5531. }
  5532. }
  5533. /**
  5534. * Insert additional style sheet link
  5535. *
  5536. * @param string $key: some key identifying the style sheet
  5537. * @param string $href: uri to the style sheet file
  5538. * @param string $title: value for the title attribute of the link element
  5539. * @return string $relation: value for the rel attribute of the link element
  5540. * @return void
  5541. */
  5542. public function addStyleSheet($key, $href, $title='', $relation='stylesheet') {
  5543. $GLOBALS['SOBE']->doc->addStyleSheet($key, $href, $title, $relation);
  5544. }
  5545. }
  5546. if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_tceforms.php']) {
  5547. include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_tceforms.php']);
  5548. }
  5549. ?>