PageRenderTime 56ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/mth_feedit_sm/class.tx_mthfeedit.php

https://github.com/michael-cannon/typo3-extensions
PHP | 1647 lines | 1477 code | 62 blank | 108 comment | 46 complexity | 87b55ec44d63c9d03dce16a506d5be9f MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. /***************************************************************
  3. * Copyright notice
  4. *
  5. * (c) 2005 Morten Tranberg Hansen (mth@daimi.au.dk)
  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. *
  17. * This script is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * This copyright notice MUST APPEAR in all copies of the script!
  23. ***************************************************************/
  24. /**
  25. * This is a API for crating and editing records in the frontend.
  26. * The API is build on top of fe_adminLib.
  27. * See documentation or extensions 'news_feedit' and 'joboffers_feedit' for examples how to use this API
  28. *
  29. * @author Morten Tranberg Hansen <mth@daimi.au.dk>
  30. */
  31. /* $Id: class.tx_mthfeedit.php,v 1.1.1.1 2010/04/15 10:03:51 peimic.comprock Exp $ */
  32. //Jaspreet Singh: This is a generic plugin for frontend editing that was modified adhoc just to get it
  33. //working fast for Savvy Miss blogs. There are some hacks. You have been warned.
  34. require_once(PATH_tslib.'class.tslib_pibase.php');
  35. require_once(PATH_site.TYPO3_mainDir.'sysext/lang/lang.php');
  36. require_once(PATH_t3lib.'class.t3lib_parsehtml_proc.php');
  37. define(PATH_typo3,PATH_site.TYPO3_mainDir); // used in template.php
  38. require_once(PATH_site.TYPO3_mainDir.'template.php');
  39. if(t3lib_extmgm::isLoaded('rtehtmlarea')) require_once(t3lib_extMgm::extPath('rtehtmlarea').'pi2/class.tx_rtehtmlarea_pi2.php');
  40. if(t3lib_extmgm::isLoaded('rlmp_dateselectlib')) require_once(t3lib_extMgm::extPath('rlmp_dateselectlib').'class.tx_rlmpdateselectlib.php');
  41. class tx_mthfeedit {
  42. // Private fields
  43. var $prefixId = 'tx_mthfeedit'; // Same as class name
  44. var $scriptRelPath = 'class.tx_mthfeedit.php'; // Path to this script relative to the extension dir.
  45. var $extKey = 'mth_feedit'; // The extension key.
  46. var $conf;
  47. var $cObj; // contains an initialized cObj, so we can use the cObj functions whenever we want to.
  48. var $templateObj; // contains an initialized templateObj, so we can use the template functions whenever we want to.(ex with dynamic tabs)
  49. var $caller; // the caller
  50. var $table; // the table
  51. var $TCA; // contains the complete TCA of the $table
  52. var $cmd; // this is 'hopefully' the same value as fe_adminLib's cmd.
  53. var $id_field = ''; // the field from a record witch will identify the record.
  54. var $additionalJS_end = array(); // JS to be added after the end of the content.
  55. # var $LANG; // language object, used to translate 'complicated' label strings to the single label.
  56. // Fields for the RTE API
  57. var $strEntryField;
  58. var $RTEObj;
  59. var $docLarge = 0;
  60. var $RTEcounter = 0;
  61. var $formName;
  62. var $additionalJS_initial = '';// Initial JavaScript to be printed before the form (should be in head, but cannot due to IE6 timing bug)
  63. var $additionalJS_pre = array();// Additional JavaScript to be printed before the form (works in Mozilla/Firefox when included in head, but not in IE6)
  64. var $additionalJS_post = array();// Additional JavaScript to be printed after the form
  65. var $additionalJS_submit = array();// Additional JavaScript to be executed on submit
  66. var $PA = array(
  67. 'itemFormElName' => '',
  68. 'itemFormElValue' => '',
  69. );
  70. var $specConf = array();
  71. var $thisConfig = array();
  72. var $RTEtypeVal = 'text';
  73. var $thePidValue;
  74. /**
  75. * [Put your description here]
  76. */
  77. function init($caller,$conf) {
  78. $GLOBALS['TSFE']->set_no_cache();
  79. /**** SET PRIVATE VARS ****/
  80. $this->conf = $this->array_merge_recursive2($this->getDefaultConfArray(),$conf);
  81. $this->cObj = t3lib_div::makeInstance('tslib_cObj');
  82. $this->templateObj = t3lib_div::makeInstance('mediumDoc');
  83. $this->table = $conf["table"];
  84. $this->caller = $caller;
  85. # debug($this->conf);
  86. $this->cmd = (string)t3lib_div::_GP('cmd') ? (string)t3lib_div::_GP('cmd') : $this->conf['defaultCmd'];
  87. if (!$this->cmd) debug("WARNING:: NO COMMAND SPECIFIED FOR THE SCRIPT","NO COMMAND");
  88. $this->id_field = $GLOBALS["TCA"][$this->table]["ctrl"]["label"];
  89. // init $this->RTEObj if rtehtmlarea is availiable
  90. if(t3lib_extmgm::isLoaded('rtehtmlarea') && !$this->RTEObj)
  91. $this->RTEObj = t3lib_div::makeInstance('tx_rtehtmlarea_pi2');//&t3lib_BEfunc::RTEgetObj();//
  92. /**** LOAD LOCALLANG ****/
  93. // loads default locallang
  94. $this->LOCAL_LANG = $GLOBALS['TSFE']->readLLfile(t3lib_extMgm::extPath($this->extKey).'locallang.php');
  95. // loads callers locallang
  96. $this->LOCAL_LANG = t3lib_div::array_merge_recursive_overrule($this->LOCAL_LANG,$caller->LOCAL_LANG);
  97. // if LANG object is there, loads it with the frontend language from TSFE object
  98. if(is_object($GLOBALS['LANG'])) {
  99. $GLOBALS['LANG']->init($GLOBALS['TSFE']->lang);
  100. }
  101. /**** LOAD TCA_DESCR ****/
  102. if($this->conf['help']) {
  103. t3lib_extMgm::addLLrefForTCAdescr($this->table,$this->conf['help.']['file']);
  104. $GLOBALS['LANG']->loadSingleTableDescription($this->table);
  105. // set default values.
  106. $this->conf['help.']['type_keys'] = $this->conf['help.']['type_keys'] ? $this->conf['help.']['type_keys'] : 'description';
  107. $this->conf['help.']['window.']['width'] = intval($this->conf['help.']['window.']['width'])?intval($this->conf['help.']['window.']['width']):'300';
  108. $this->conf['help.']['window.']['height'] = intval($this->conf['help.']['window.']['height'])?intval($this->conf['help.']['window.']['height']):'40';
  109. # debug($GLOBALS['TCA_DESCR']);
  110. }
  111. /**** LOAD TCA ****/
  112. $GLOBALS['TSFE']->includeTCA(); // THIS IS VERY IMPORTANT! If loaded here, it wont be loaded again and out extra TCA configurations will NOT be overriden
  113. t3lib_div::loadTCA($this->table);
  114. // Set private TCA var
  115. $this->TCA = &$GLOBALS["TCA"][$this->table];
  116. // MLC set blogs
  117. $this->TCA["ctrl"]["title"] = "Blog Entry";
  118. # debug($this->TCA,'TCA');
  119. /**** CONFIGURE TCA ****/
  120. $GLOBALS["TCA"][$this->table]["feInterface"]["fe_admin_fieldList"] = $this->conf['create.']['fields'] ? $this->conf['create.']['fields'].($this->conf['edit.']['fields']?','.$this->conf['edit.']['fields']:'') : $this->conf['edit.']['fields'];
  121. if($this->conf['fe_cruser_id'])
  122. $GLOBALS["TCA"][$this->table]['ctrl']['fe_cruser_id'] = $this->conf['fe_cruser_id'];
  123. if($this->conf['fe_crgroup_id'] && $this->conf['allowedGroups']) {
  124. $GLOBALS["TCA"][$this->table]['ctrl']['fe_crgroup_id'] = $this->conf['fe_crgroup_id'];
  125. }
  126. # debug($this->TCA);
  127. # debug(t3lib_div::_GP('FE'),'FE');
  128. # debug($_FILES,'$_FILES');
  129. # debug($this->conf);
  130. /**** Init language object (used for translation of labels) ****/
  131. $GLOBALS['TSFE']->initLLvars();
  132. /**** Init Robert Lemkes dateselectlib if it is loaded ****/
  133. if(t3lib_extmgm::isLoaded('rlmp_dateselectlib')) tx_rlmpdateselectlib::includeLib();
  134. /**** DO ADDITIONAL REQUIRED STUFF FOR THE FIELDS ****/
  135. $fieldArray = explode(',',$this->conf[$this->cmd.'.']['show_fields']);
  136. foreach((array)$fieldArray as $fN) { //runs through the different fields
  137. // make sure --div-- is in allowed fields list
  138. $parts = explode(";",$fN);
  139. if($parts[0]=='--div--') {
  140. $this->conf[$this->cmd.'.']['fields'] .= $this->conf[$this->cmd.'.']['fields'] ? $this->conf[$this->cmd.'.']['fields'].','.$fN : $fN;
  141. }
  142. // do stuff according to type from TCA
  143. switch((string)$this->TCA['columns'][$fN]['config']['type']) {
  144. case 'group':
  145. if($this->TCA['columns'][$fN]['config']['internal_type']=='file') {
  146. $this->conf[$this->cmd.'.']['fields'] .= ','.$fN.'_file'; // add the upload field to the allowed fields
  147. $GLOBALS['TCA'][$this->table]['columns'][$fN.'_file']['config']['uploadfolder'] = $GLOBALS['TCA'][$this->table]['columns'][$fN]['config']['uploadfolder']; // the new upload field should have the same upload folder as the original field
  148. $this->conf['parseValues.'][$fN.'_file'] = 'files['.ereg_replace(',',';',$this->TCA['columns'][$fN]['config']['allowed']).']['.$this->TCA['columns'][$fN]['config']['max_size'].']'; // adds the parse options for the new field, so it will be parsed as a file.
  149. }
  150. }
  151. }
  152. /**** CHECK IF LOGIN IS REQUIRED ****/
  153. if($this->conf['requireLogin'] && !$GLOBALS['TSFE']->loginUser) return $this->getLL("login_required_message");
  154. /**** FE ADMIN LIB ****/
  155. $feAConf = $this->conf;
  156. $feAConf["templateContent"]= $this->getDefaultTemplate(); // gets the default template
  157. # debug($feAConf);
  158. $content = $this->cObj->cObjGetSingle('USER_INT',$feAConf);
  159. /**** ADDS THE REQUIRED JAVASCRIPTS ****/
  160. $content = $this->getJSBefore() . $content;
  161. $content .= $this->getJSAfter();
  162. # debug($content,'content');
  163. return $content;
  164. }
  165. /*
  166. * Default configurations for fe_adminLib
  167. */
  168. function getDefaultConfArray() {
  169. return array(
  170. 'userFunc' => 'user_feAdmin->init',
  171. 'includeLibs' => 'media/scripts/fe_adminLib.inc',
  172. 'userFunc_updateArray' => 'tx_mthfeedit->updateArray',
  173. 'evalFunc' => 'tx_mthfeedit->processDataArray',
  174. 'create' => 1,
  175. 'create.' => array(
  176. 'preview' => 1,
  177. 'userFunc_afterSave' => 'tx_mthfeedit->afterSave',
  178. ),
  179. 'edit' => 1,
  180. 'edit.' => array(
  181. 'preview' => 1,
  182. 'menuLockPid' => 1,
  183. 'userFunc_afterSave' => 'tx_mthfeedit->afterSave',
  184. ),
  185. 'delete' => 1,
  186. 'delete.' => array(
  187. 'preview' => 1,
  188. ),
  189. 'setfixed' => 1,
  190. 'setfixed.' => array(
  191. 'approve.' => array(
  192. 'hidden' => 0,
  193. '_FIELDLIST' => 'uid,pid',
  194. ),
  195. 'DELETE' => 1,
  196. 'DELETE.' => array(
  197. '_FIELDLIST' => 'uid,pid',
  198. ),
  199. ),
  200. 'no_cache' => 1,
  201. 'no_header' => 0,
  202. 'keep_piVars' => '',
  203. 'defaultCmd' => 'edit',
  204. 'infomail' => 0,
  205. 'required_marker' => '*',
  206. 'clearCacheOfPages' => $GLOBALS['TSFE']->id,
  207. );
  208. }
  209. /**********************************************************************************************
  210. * TEMPLATE FUNCTIONS
  211. **********************************************************************************************/
  212. /**
  213. * Gets a default template made from the TCA.
  214. * The template there is returned depends on what $this->cmd is.
  215. */
  216. function getDefaultTemplate() {
  217. $callerMethods = get_class_methods(get_class($this->caller));
  218. $template = array_search('getrequiredtemplate',$callerMethods) || array_search('getRequiredTemplate',$callerMethods)?
  219. $this->caller->getRequiredTemplate() : $this->getRequiredTemplate();
  220. $template .= array_search('getemailtemplate',$callerMethods) || array_search('getEmailTemplate',$callerMethods)?
  221. $this->caller->getEmailTemplate() : $this->getEmailTemplate();
  222. switch((string)$this->cmd) {
  223. case 'edit':
  224. $template .= array_search('getedittemplate',$callerMethods) || array_search('getEditTemplate',$callerMethods)?
  225. $this->caller->getEditTemplate() : $this->getEditTemplate();
  226. $template .= array_search('geteditmenutemplate',$callerMethods) || array_search('getEditMenuTemplate',$callerMethods)?
  227. $this->caller->getEditMenuTemplate() : $this->getEditMenuTemplate();
  228. break;
  229. case 'create':
  230. $template .= array_search('getcreatetemplate',$callerMethods) || array_search('getCreateTemplate',$callerMethods)?
  231. $this->caller->getCreateTemplate() : $this->getCreateTemplate();
  232. break;
  233. case 'delete':
  234. $template .= array_search('getdeletetemplate',$callerMethods) || array_search('getDeleteTemplate',$callerMethods)?
  235. $this->caller->getDeleteTemplate() : $this->getDeleteTemplate();
  236. break;
  237. case 'setfixed':
  238. $template .= array_search('getsetfixedtemplate',$callerMethods) || array_search('getSetfixedTemplate',$callerMethods)?
  239. $this->caller->getSetfixedTemplate() : $this->getSetfixedTemplate();
  240. break;
  241. default:
  242. debug('mth_feedit->getDefaultTemplate():: No template found for cmd='.$this->cmd,'No Template');
  243. $template = '';
  244. }
  245. # debug(array($template));
  246. return $template;
  247. }
  248. /**
  249. * Makes the form content from the TCA according to the configuration for the $cmd
  250. * @param string The cmd. Should be 'edit' or 'create'.
  251. */
  252. function makeHTMLForm($cmd) {
  253. $fields = array_intersect( array_unique(t3lib_div::trimExplode(",",$this->conf[$cmd.'.']['show_fields'],1)) , array_unique(t3lib_div::trimExplode(",",$this->conf[$cmd.'.']['fields'],1)));
  254. $reqFields = array_intersect( array_unique(t3lib_div::trimExplode(",",$this->conf[$cmd.'.']["required"],1)) , array_unique(t3lib_div::trimExplode(",",$this->conf[$cmd.'.']['show_fields'],1)));
  255. $out_array = array();
  256. $out_sheet = 0;
  257. # debug($fields,'fields');
  258. while(list(,$fN)=each($fields)) {
  259. $parts = explode(';',$fN);
  260. $fN = $parts[0];
  261. if($fN=='--div--') {
  262. if($this->conf["divide2tabs"]) {
  263. $out_sheet++;
  264. $out_array[$out_sheet] = array();
  265. $out_array[$out_sheet]['title'] = $this->getLL($parts[1],'Tab '.$out_sheet);
  266. }
  267. } else {
  268. # debug(is_object($GLOBALS['TBE_TEMPLATE']));
  269. $fieldCode = $this->getFormFieldCode($cmd,$fN);
  270. if ($fieldCode) {
  271. // NOTE: There are two ways to make a field required. The new way is to include 'required' in evalValues for a field. The old one is to have the the field in the required list.
  272. // The new way take precedence over the old way. So if the new field has some evalValues, it makes no different if the field is in the required list or not.
  273. $feData=t3lib_div::_GP('FE');
  274. if($this->conf[$cmd.'.']['evalValues.'][$fN]) { // evalValues defined
  275. $msg = is_array($feData[$this->table]) ? '<div'.$this->caller->pi_classParam('form-error-field').'>###EVAL_ERROR_FIELD_'.$fN.'###</div>' : ''; // if no data is sent, no data is evaluated, and then no error msg should be displayed
  276. $reqMarker = in_array('required',t3lib_div::trimExplode(',',$this->conf[$cmd.'.']['evalValues.'][$fN])) ? $this->conf['required_marker'] : '';
  277. } elseif (in_array($fN,$reqFields)) { // No evalValues, but field listed in required list.
  278. $msg = '<!--###SUB_REQUIRED_FIELD_'.$fN.'###--><div'.$this->caller->pi_classParam('form-required-message').'>'.$this->getLL("required_message").'</div><!--###SUB_REQUIRED_FIELD_'.$fN.'###-->';
  279. $reqMarker = $this->conf['required_marker'];
  280. } else {
  281. $msg = '';
  282. $reqMarker = '';
  283. }
  284. $helpIcon = ($this->conf['help'] ? '<div'.$this->caller->pi_classParam('form-help-icon').'>'.$this->helpIcon($fN).'</div>' : '');
  285. $out_array[$out_sheet][]='<div class="'.$this->caller->pi_getClassName('form-row').' '.$this->caller->pi_getClassName('form-row-'.$fN).'">
  286. <div class="'.$this->caller->pi_getClassName('form-label').' '.$this->caller->pi_getClassName('form-label-'.$fN).'">
  287. <div'.$this->caller->pi_classParam('form-required-marker').'>'.$reqMarker.'</div>
  288. '.$this->getLLFromLabel($this->TCA["columns"][$fN]["label"]). '
  289. '.$helpIcon.'
  290. </div>
  291. <div'.$this->caller->pi_classParam('form-field').'>'.$fieldCode.'</div>
  292. '.$msg.'
  293. </div>';
  294. }
  295. }
  296. }
  297. if ($out_sheet>0) { // There were --div-- dividers around. Create parts array for the tab menu:
  298. $parts = array();
  299. foreach($out_array as $idx => $sheetContent) {
  300. unset($sheetContent['title']);
  301. $parts[] = array(
  302. 'label' => $out_array[$idx]['title'],
  303. 'content' => '<table border="0" cellspacing="0" cellpadding="0" width="100%">'.
  304. implode(chr(10),$sheetContent).
  305. '</table>'
  306. );
  307. }
  308. $content = $this->addCallersPiVars($this->templateObj->getDynTabMenu($parts, 'TCEforms:'.$table.':'.$row['uid']));
  309. } else { // Only one, so just implode:
  310. $content = is_array($out_array[$out_sheet]) ? $this->addCallersPiVars(implode(chr(10),$out_array[$out_sheet])) : 'makeHTMLForm() :: No form generated! (Proberly no fields defined in typoscript option show_fields)';
  311. }
  312. return $content;
  313. }
  314. /**
  315. * Returns a help icon for the field
  316. * @param string The field to get the help icon for
  317. * @param boolean The help icon with link to javascript popup, with help in.
  318. */
  319. function helpIcon($field) {
  320. // debug($this->conf);
  321. $cshArray = $GLOBALS['TCA_DESCR'][$this->table]['columns'][$field];
  322. if(!is_array($cshArray)) return '';
  323. $label = $this->getLLFromLabel($this->TCA['columns'][$field]['label']);
  324. $fieldDescription = '<p'.$this->caller->pi_classParam('help-header').'>'.$label. '</p>';
  325. foreach(t3lib_div::trimExplode(',',$this->conf['help.']['type_keys'],1) as $type_key) {
  326. $fieldDescription .= $cshArray[$type_key] ? '<p'.$this->caller->pi_classParam('help-description').'>'.$cshArray[$type_key] . '</p>' : '';
  327. }
  328. if(empty($fieldDescription)) return '';
  329. else {
  330. // $aOnClick = 'confirm(\''.$fieldDescription.'\');return false;';
  331. $fieldDescription = '<html><head><title>'.$label.'</title><style type="text/css">'.preg_replace("(\r)"," ",preg_replace("(\n)"," ",$this->conf['help.']['window.']['style'])).'</style></head><body'.$this->caller->pi_classParam('help-body').'><div'.$this->caller->pi_classParam('help-text').'>'.preg_replace("(\r)"," ",preg_replace("(\n)"," ",$fieldDescription)).'</div></body></html>';
  332. $script = '
  333. <script type="text/javascript">
  334. /*<![CDATA[*/
  335. function '.$this->caller->prefixId.'_helpWindow_'.$field.'() {
  336. top.vHWin=window.open(\'\',\'viewFieldHelpFE\',\'height='.$this->conf['help.']['window.']['height'].',width='.$this->conf['help.']['window.']['width'].',status=0,menubar=0,scrollbars=1\');
  337. top.vHWin.document.writeln(\''.$fieldDescription.'\');
  338. top.vHWin.document.close();
  339. top.vHWin.focus();
  340. }
  341. /*]]>*/
  342. </script>';
  343. require_once(PATH_t3lib . 'class.t3lib_iconworks.php');
  344. return
  345. $script.'<a href="#" onclick="'.htmlspecialchars($this->caller->prefixId.'_helpWindow_'.$field.'();return false;').'">'.
  346. '<img'.t3lib_iconWorks::skinImg('typo3/','gfx/helpbubble.gif','width="14" height="14"').' hspace="2" border="0" class="absmiddle"'.($GLOBALS['CLIENT']['FORMSTYLE']?' style="cursor:help;"':'').' alt="" />'.
  347. '</a>';
  348. }
  349. }
  350. /**
  351. * Makes a preview of the form content according to the configuration for the $cmd
  352. * @param string The cmd. Should be 'edit' or 'create' or 'all'.
  353. * @param boolean Should the output be wrapped in html or not.
  354. */
  355. function makeHTMLPreview($cmd, $withHTML = true) {
  356. $fields = (string)$cmd=='all' ? array_unique(t3lib_div::trimExplode(",",($this->conf['create.']['show_fields'] ? $this->conf['create.']['show_fields'].($this->conf['edit.']['show_fields']?','.$this->conf['edit.']['show_fields']:'') : $this->conf['edit.']['show_fields']))) : array_unique(t3lib_div::trimExplode(",",$this->conf[$cmd.'.']['show_fields']));
  357. $result = array();
  358. $hiddenFields = array();
  359. foreach((array)$fields as $fN) {
  360. $parts = explode(';',$fN);
  361. if(($parts[0]=='--div--')) continue;
  362. $label = $this->getLLFromLabel($this->TCA['columns'][$fN]['label']);
  363. $fieldCode = $this->getPreviewFieldCode($cmd, $fN, $withHTML);
  364. // filter out empty fields or replace empty values by a default label (this label is not saved to DB))
  365. $feData = t3lib_div::_POST('FE');
  366. if(empty($feData[$this->table][$fN]) && ($this->TCA["columns"][$fN]["config"]["type"]=='input' || $this->TCA["columns"][$fN]["config"]["type"]=='text')) {
  367. $fieldCode = $this->getLL('no_value'); // replace fieldcode with default label
  368. if($this->conf[$cmd.'.']['preview.']['dontDisplayEmptyFields'] // if dontDisplayEmptyFields is set, skib the field
  369. || ($cmd == 'all' && ($this->conf['create.']['preview.']['dontDisplayEmptyFields'] || $this->conf['edit.']['preview.']['dontDisplayEmptyFields']))) {
  370. continue;
  371. }
  372. }
  373. if(!$withHTML) {
  374. $result[] = $label.chr(10).$fieldCode.chr(10);
  375. } else {
  376. $result[] = '<div'.$this->caller->pi_classParam('preview-row').'>
  377. <div class="'.$this->caller->pi_getClassName('preview-label').' '.$this->caller->pi_getClassName('preview-label-'.$fN).'">
  378. '.$label.'
  379. </div>
  380. <div class="'.$this->caller->pi_getClassName('preview-value').' '.$this->caller->pi_getClassName('preview-value-'.$fN).'">
  381. '.$fieldCode.'
  382. </div>
  383. </div>';
  384. # $hiddenFields[] = '<input type="hidden" name="FE['.$this->table.']['.$fN.']" />';
  385. }
  386. }
  387. # $result[] = ''.implode(chr(10),$hiddenFields);
  388. //jsmodified
  389. $implodedResult = implode(chr(10),$result);
  390. // Keep callers piVars
  391. if($withHTML) {
  392. return $this->addCallersPiVars($implodedResult);
  393. }
  394. else {
  395. $plainText = $this->htmlToPlainText($implodedResult);
  396. return $plainText;
  397. }
  398. }
  399. /**
  400. * Converts HTML to plain text. Taken with thanks from PHP help.
  401. * @param HTML text
  402. * @return plain text
  403. */
  404. function htmlToPlainText( $htmlBody )
  405. {
  406. $search = array ("'<script[^>]*?>.*?</script>'si", // Strip out javascript
  407. "'<[\/\!]*?[^<>]*?>'si", // Strip out HTML tags
  408. "'([\r\n])[\s]+'", // Strip out white space
  409. "'&(quot|#34);'i", // Replace HTML entities
  410. "'&(amp|#38);'i",
  411. "'&(lt|#60);'i",
  412. "'&(gt|#62);'i",
  413. "'&(nbsp|#160);'i",
  414. "'&(iexcl|#161);'i",
  415. "'&(cent|#162);'i",
  416. "'&(pound|#163);'i",
  417. "'&(copy|#169);'i",
  418. "'&#(\d+);'e"); // evaluate as php
  419. $replace = array ("",
  420. "",
  421. "\\1",
  422. "\"",
  423. "&",
  424. "<",
  425. ">",
  426. " ",
  427. chr(161),
  428. chr(162),
  429. chr(163),
  430. chr(169),
  431. "chr(\\1)");
  432. $text = preg_replace($search, $replace, $htmlBody);
  433. return $text;
  434. }
  435. /**
  436. * A dummy methor for making a NON HTML preview of the form content according to the configurations for the $cmd
  437. * @param string The cmd. Should be 'edit' or 'create'.
  438. */
  439. function makeTEXTPreview($cmd) {
  440. //jsmod hardocode HTML
  441. //return $this->makeHTMLPreview($cmd,false);
  442. return $this->makeHTMLPreview($cmd,false);
  443. }
  444. /**
  445. * Add callers piVars as hidden input fields to the result array
  446. * @param string The string to add piVars as input fields to
  447. * @result string The result string with added piVars input fields
  448. */
  449. function addCallersPiVars($result) {
  450. $keep_piVars = t3lib_div::trimExplode(',',$this->conf['keep_piVars']);
  451. foreach($keep_piVars as $piVar) {
  452. if(!empty($piVar))
  453. $result .= '<input type="hidden" name="'.$this->caller->prefixId.'['.$piVar.']" value="'.$this->caller->piVars[$piVar].'" />';
  454. }
  455. return $result;
  456. }
  457. /**
  458. * Gets the PREVIEW fieldcode for field ($fN) of the form. This depends on the fields type.
  459. * @param string The field to get the fieldcode for.
  460. * @param boolean Should the output be with html (input fields) or not.
  461. */
  462. function getPreviewFieldCode($cmd,$fN,$withHTML) {
  463. # debug('getPreviewFieldCode():: fN='.$fN.', cmd='.$cmd,'function call');
  464. $fieldName = 'FE['.$this->table.']['.$fN.']';
  465. $type = $this->TCA["columns"][$fN]["config"]["type"];
  466. $feData = t3lib_div::_POST('FE');
  467. # debug(intval($feData[$this->table]['datetime']),'datetime');
  468. switch((string)$type) {
  469. case "input":
  470. $evalValuesArr = t3lib_div::trimExplode(',',$this->conf[$cmd.'.']['evalValues.'][$fN]);
  471. $displayTwice = false;
  472. $isPassword = false;
  473. foreach((array)$evalValuesArr as $eval) {
  474. switch((string)$eval) {
  475. case 'twice':
  476. $displayTwice = true;
  477. break;
  478. case 'password':
  479. $isPassword = true;
  480. break;
  481. }
  482. }
  483. $values = '###FIELD_'.$fN.'###';
  484. $feData = t3lib_div::_POST("FE");
  485. // Format the values. TODO: This only shows the date on a nice format if it is send to the page, not if it is from an overrideValue.
  486. if($isPassword) $values = '********';
  487. else if($this->TCA['columns'][$fN]["config"]["eval"]=='date' && !empty($feData[$this->table][$fN])) {
  488. $values = strftime("%e-%m-%Y",$feData[$this->table][$fN]);
  489. } else if($this->TCA['columns'][$fN]["config"]["eval"]=='datetime' && !empty($feData[$this->table][$fN])) {
  490. $values = strftime("%H:%M %e-%m-%Y",$feData[$this->table][$fN]);
  491. }
  492. if($displayTwice) {
  493. $fieldName_again = 'FE['.$this->table.']['.$fN.'_again]';
  494. return $withHTML?'<input type="hidden" name="'.$fieldName.'" /><input type="hidden" name="'.$fieldName_again.'" />'.$values:$values;
  495. } else {
  496. return $withHTML?'<input type="hidden" name="'.$fieldName.'" />'.$values:$values;
  497. }
  498. break;
  499. case "group":
  500. return $withHTML?'<input type="hidden" name="'.$fieldName.'" /><input type="hidden" name="FE['.$this->table.']['.$fN.'_file]" />###FIELD_'.$fN.'###,###FIELD_'.$fN.'_file###':'###FIELD_'.$fN.'###, ###FIELD_'.$fN.'_file###';
  501. break;
  502. case "select":
  503. $values = '###FIELD_'.$fN.'###';
  504. if($this->TCA['columns'][$fN]["config"]["foreign_table"]) { // reference to elements from another table
  505. $label = $GLOBALS["TCA"][$this->TCA['columns'][$fN]["config"]["foreign_table"]]["ctrl"]["label"];
  506. $feData = t3lib_div::_POST('FE');
  507. if($feData[$this->table][$fN]) {
  508. $uids = t3lib_div::trimExplode(',',$feData[$this->table][$fN]);
  509. $orClause = '';
  510. foreach($uids as $uid) $orClause .= $orClause ? 'OR uid LIKE \''.$uid.'\'' : 'uid = \''.$uid.'\'';
  511. $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*',$this->TCA['columns'][$fN]["config"]["foreign_table"],$orClause);
  512. if($GLOBALS['TYPO3_DB']->sql_error()) debug($GLOBALS['TYPO3_DB']->sql_error(),'sql error');
  513. $values = '';
  514. while($resRow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
  515. $values .= $values ? ', ' . $resRow[$label] : $resRow[$label];
  516. }
  517. }
  518. } elseif($this->TCA['columns'][$fN]["config"]["items"]) { // fixed items
  519. // get items array..
  520. $items = $this->TCA['columns'][$fN]["config"]["items"];
  521. if($this->TCA['columns'][$fN]["config"]["itemsProcFunc"]) { // if itemsProcFunc is set to fill the items array
  522. $options = '';
  523. $params = $this->TCA['columns'][$fN];
  524. $params['items'] = &$items;
  525. t3lib_div::callUserFunction($this->TCA['columns'][$fN]["config"]["itemsProcFunc"], $params, $this);
  526. }
  527. // find the right label according to the value, compared to the $items
  528. $feData = t3lib_div::_POST('FE');
  529. if($feData[$this->table][$fN]) {
  530. $vals = t3lib_div::trimExplode(',',$feData[$this->table][$fN]);
  531. $values = '';
  532. foreach($items as $item) {
  533. if(!empty($item)) {
  534. list($label,$val) = $item;
  535. if(in_array($val,$vals)) {
  536. $values .= $values ? ', ' . $label : $label;
  537. }
  538. }
  539. }
  540. }
  541. }
  542. return $withHTML?'<input type="hidden" name="'.$fieldName.'" />'.$values:$values;
  543. break;
  544. case "text":
  545. $values = '###FIELD_'.$fN.'###';
  546. $feData = t3lib_div::_POST('FE');
  547. if($feData[$this->table]['_TRANSFORM_'.$fN]) { // if rte output, we need to process it instead of parsing it through htmlspecialchar as the other values gets.
  548. $dataArr = $feData[$this->table];
  549. $dataArr = $this->rteProcessDataArr($dataArr, $this->table, $fN, 'db');
  550. $dataArr = $this->rteProcessDataArr($dataArr, $this->table, $fN, 'rte');
  551. $values = $withHTML ? $dataArr[$fN] : strip_tags($dataArr[$fN]);
  552. }
  553. return $withHTML?'<input type="hidden" name="'.$fieldName.'" />'.$values:$values;
  554. break;
  555. default:
  556. return $withHTML?'<input type="hidden" name="'.$fieldName.'" />###FIELD_'.$fN.'###':'###FIELD_'.$fN.'###';
  557. break;
  558. }
  559. }
  560. /**
  561. * Gets the fieldcode for field ($fN) of the form. This depends on the fields type.
  562. * @param string The cmd. Should be 'edit' or 'create'.
  563. * @param string The field to get the fieldcode for.
  564. */
  565. function getFormFieldCode($cmd,$fN) {
  566. # $this->TCA['columns']['title']["config"]["eval"] = 'date';
  567. $fieldName = 'FE['.$this->table.']['.$fN.']';
  568. $class = 'class="'.$this->caller->pi_getClassName('form-data-'.$fN).' '.$this->caller->pi_getClassName('form-data').'"';
  569. $defaultParams = ' name="'.$fieldName.'"'.$class;
  570. $type = $this->TCA["columns"][$fN]["config"]["type"];
  571. # debug($this->TCA['columns']);
  572. switch((string)$type) {
  573. case "input":
  574. $onChange = 'onChange="feedit_'.$this->table.'_formGet('."'".$fieldName."','".$this->TCA['columns'][$fN]["config"]["eval"]."','".$is_in."','".$checkbox."','".$checkboxVal."','".$checkbox_off."');".'"';
  575. $evalValuesArr = t3lib_div::trimExplode(',',$this->conf[$cmd.'.']['evalValues.'][$fN]);
  576. $displayTwice = false;
  577. $isPassword = false;
  578. foreach((array)$evalValuesArr as $eval) {
  579. switch((string)$eval) {
  580. case 'twice':
  581. $displayTwice = true;
  582. break;
  583. case 'password':
  584. $isPassword = true;
  585. break;
  586. }
  587. }
  588. $type = 'text';
  589. if($isPassword) $type = 'password';
  590. # debug($this->TCA['columns'][$fN]['config'],'config '.$fN);
  591. if($displayTwice) {
  592. $fieldName_again = 'FE['.$this->table.']['.$fN.'_again]';
  593. $onChange_again = 'onChange="feedit_'.$this->table.'_formGet('."'".$fieldName_again."','".$this->TCA['columns'][$fN]["config"]["eval"]."','".$is_in."','".$checkbox."','".$checkboxVal."','".$checkbox_off."');".'"';
  594. $this->additionalJS_end['feedit_'.$fN.'_set_data'] = 'feedit_'.$this->table.'_formSet('."'".$fieldName."','".$this->TCA['columns'][$fN]["config"]["eval"]."','".$is_in."','".$checkbox. "','".$checkboxVal."','".$checkbox_off."')".';';
  595. $this->additionalJS_end['feedit_'.$fN.'_again_set_data'] = 'feedit_'.$this->table.'_formSet('."'".$fieldName_again."','".$this->TCA['columns'][$fN]["config"]["eval"]."','".$is_in."','".$checkbox. "','".$checkboxVal."','".$checkbox_off."')".';';
  596. return '<input type="'.$type.'" name="'.$fieldName.'_feVal" '.$class.' maxlength="'.$this->TCA["columns"][$fN]["config"]["max"].'" '.$onChange.' />
  597. <input type="hidden" name="'.$fieldName.'" />
  598. <input type="'.$type.'" name="'.$fieldName_again.'_feVal" '.$class.' maxlength="'.$this->TCA["columns"][$fN]["config"]["max"].'" '.$onChange_again.' />
  599. <input type="hidden" name="'.$fieldName_again.'" />';
  600. } else {
  601. $this->additionalJS_end['feedit_'.$fN.'_set_data'] = 'feedit_'.$this->table.'_formSet('."'".$fieldName."','".$this->TCA['columns'][$fN]["config"]["eval"]."','".$is_in."','".$checkbox. "','".$checkboxVal."','".$checkbox_off."')".';';
  602. return
  603. '<input type="'.$type.'" name="'.$fieldName.'_feVal" id="'.$fieldName.'_feVal" '.$class.' maxlength="'.$this->TCA["columns"][$fN]["config"]["max"].'" '.$onChange.' />' .
  604. '<input type="hidden" name="'.$fieldName.'" />' .
  605. // inserts button for rlmp_dateselectlib
  606. (t3lib_extmgm::isLoaded('rlmp_dateselectlib') &&
  607. !empty($this->TCA['columns'][$fN]["config"]["eval"]) ?
  608. (is_int(array_search('date',t3lib_div::trimExplode(',',$this->TCA['columns'][$fN]["config"]["eval"])))
  609. ?
  610. tx_rlmpdateselectlib::getInputButton($fieldName.'_feVal',array('calConf.'=>array('inputFieldDateTimeFormat'=>'%e-%m-%Y')))
  611. :
  612. (is_int(array_search('datetime',t3lib_div::trimExplode(',',$this->TCA['columns'][$fN]["config"]["eval"])))
  613. ?
  614. tx_rlmpdateselectlib::getInputButton($fieldName.'_feVal',array('calConf.'=>array('inputFieldDateTimeFormat'=>'%H:%M %e-%m-%Y')))
  615. : ''))
  616. : '');
  617. }
  618. break;
  619. case "text":
  620. // Get the specialConf for the field. Placed in type array.
  621. $specialConf = $this->getFieldSpecialConf($this->table,$fN);
  622. /**** USE RTE OR NOT ****/
  623. if(!empty($specialConf) && is_object($this->RTEObj) && $this->RTEObj->isAvailable()) { // use RTE
  624. $this->RTEcounter++;
  625. $this->formName = $this->table.'_form';
  626. $this->strEntryField = $fN;
  627. $this->PA['itemFormElName'] = $fieldName;
  628. $feData = t3lib_div::_POST('FE');
  629. $this->PA['itemFormElValue'] = $feData[$this->table][$fN];
  630. $this->specConf = $specialConf;
  631. $pageTSConfig = $GLOBALS['TSFE']->getPagesTSconfig();
  632. # THIS WILL NOT WORK YET! mail sendt to author of rtehtmlarea STAN
  633. /* if(is_array($pageTSConfig['RTE.']['default.']['FE.']) && is_array($pageTSConfig['RTE.']['config.'][$this->table.'.'][$fN.'.']['FE.'])) {
  634. $this->thisConfig = t3lib_div::array_merge_recursive_overrule($pageTSConfig['RTE.']['default.']['FE.'],
  635. $pageTSConfig['RTE.']['config.'][$this->table.'.'][$fN.'.']['FE.']);
  636. } else {*/
  637. $this->thisConfig = $pageTSConfig['RTE.']['default.']['FE.'];
  638. // }
  639. $this->thePidValue = $GLOBALS['TSFE']->id;
  640. $RTEItem = $this->RTEObj->drawRTE($this,$this->table,$fN,$row=array(), $this->PA, $this->specConf, $this->thisConfig, $this->RTEtypeVal, '', $this->thePidValue);
  641. return $RTEItem . '<div'.$this->caller->pi_classParam('rte-clearer').'></div>';
  642. } else { // dont use RTE
  643. return '<textarea'.$defaultParams.' cols="'.$this->TCA["columns"][$fN]["config"]["cols"].'" rows="'.$this->TCA["columns"][$fN]["config"]["rows"].'" wrap="VIRTUAL"></textarea>';
  644. }
  645. break;
  646. case "check":
  647. if($this->TCA['columns'][$fN]['config']['cols']>1) debug("getFormFieldCode():: WARNING, checkbox have more cols, not implementet yet.");
  648. return '<input type="hidden" '.$defaultParams.' value="0"><input type="checkbox" '.$defaultParams.' value="1">';
  649. break;
  650. case "group":
  651. if($this->TCA['columns'][$fN]["config"]["internal_type"]=='file') {
  652. // fetch data from table
  653. $feData = t3lib_div::_POST('FE');
  654. $uid = $feData[$this->table]['uid'] ? $feData[$this->table]['uid'] : t3lib_div::_GET('rU');
  655. $rec = $GLOBALS['TSFE']->sys_page->getRawRecord($this->table,$uid);
  656. // make option tags from existing data.
  657. $options = "";
  658. foreach(explode(",",$rec[$fN]) as $opt)
  659. $options .= '<option value="'.$opt.'">'.$opt.'</option>';
  660. $result .= '<select size="'.$this->TCA['columns'][$fN]["config"]["size"].'" name="FE['.$this->table.']['.$fN.']_select" style="width:250px;">
  661. '.$options.'
  662. </select>
  663. <input type="hidden" name="'.$fieldName.'">
  664. <a onClick="feedit_manipulateGroup(\''.$fieldName.'\');return false;"><img border="0" src="typo3/gfx/group_clear.gif"></a>';
  665. # unset($result);
  666. if($this->TCA['columns'][$fN]["config"]["maxitems"]>sizeof(explode(",",$rec[$fN]))) {
  667. $result .= $this->TCA['columns'][$fN]["config"]["allowed"].'<input type="file" name="FE['.$this->table.']['.$fN.'_file][]" />';
  668. }
  669. return $result;
  670. } else {
  671. debug("getFormFieldCode()::GROUP TYPE 'DB' NOT SUPPORTET YET");
  672. }
  673. break;
  674. case "select":
  675. $feData = t3lib_div::_POST('FE');
  676. $uid = $feData[$this->table]['uid'] ? $feData[$this->table]['uid'] : t3lib_div::_GET('rU');
  677. $rec = $GLOBALS['TSFE']->sys_page->getRawRecord($this->table,$uid);
  678. if($this->TCA['columns'][$fN]["config"]["foreign_table"]) { // reference to elements from another table
  679. $label = $GLOBALS["TCA"][$this->TCA['columns'][$fN]["config"]["foreign_table"]]["ctrl"]["label"];
  680. $foreignTable = $this->TCA['columns'][$fN]["config"]["foreign_table"];
  681. $whereClause = $this->TCA['columns'][$fN]["config"]["foreign_table_where"];
  682. $storageAndSiteroot = $GLOBALS["TSFE"]->getStorageSiterootPids();
  683. $whereClause = str_replace('###CURRENT_PID###',intval($storageAndSiteroot["_STORAGE_PID"])/*intval($GLOBALS["TSFE"]->page['uid'])*/,$whereClause); // replaced with STORAGE_PID cause it makes more sense ;)
  684. # $whereClause = str_replace('###THIS_UID###',,$whereClause);
  685. # $whereClause = str_replace('###THIS_CID###',,$whereClause);
  686. $whereClause = str_replace('###STORAGE_PID###',intval($storageAndSiteroot["_STORAGE_PID"]),$whereClause);
  687. $whereClause = str_replace('###SITEROOT###',intval($storageAndSiteroot['_SITEROOT']),$whereClause);
  688. $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*',$foreignTable,'1=1 '.$this->cObj->enableFields($foreignTable).' '.$whereClause);
  689. if ($GLOBALS['TYPO3_DB']->sql_error()) debug(array($GLOBALS['TYPO3_DB']->sql_error()),'getFormFieldCode()::field='.$fN);
  690. // gets uids of selected records.
  691. $uids = $this->getUidsOfSelectedRecords($rec,$fN,$this->table);
  692. debug($uids,'uids');
  693. while($resRow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
  694. $selected = in_array($resRow["uid"],$uids)?"selected":"";
  695. $options .= '<option value="'.$resRow["uid"].'" '.$selected.'>'.$resRow[$label].'</option>';
  696. }
  697. } elseif($this->TCA['columns'][$fN]["config"]["items"]) { // fixed items
  698. // Get selected uids.
  699. $uids = array();
  700. if($feData[$this->table][$fN]) { // from post var
  701. $uids = explode(",",$feData[$this->table][$fN]);
  702. } elseif(!is_null($rec)) { // clean from DB
  703. $uids = explode(",",$rec[$fN]);
  704. } elseif($cmd=='create' && ($this->TCA['columns'][$fN]['config']['default'] || $this->conf[$cmd.'.']['defaultValues.'][$fN])) { // default value taken from mthfeedit typoscript or TCA
  705. $uids = explode(",",$this->conf[$cmd.'.']['defaultValues.'][$fN]?$this->conf[$cmd.'.']['defaultValues.'][$fN]:$this->TCA['columns'][$fN]['config']['default']);
  706. }
  707. $items = $this->TCA['columns'][$fN]["config"]["items"];
  708. $options = '<option value="0">-----</option>';
  709. if($this->TCA['columns'][$fN]["config"]["itemsProcFunc"]) { // if itemsProcFunc is set to fill the select box
  710. $options = '';
  711. $params = $this->TCA['columns'][$fN];
  712. $params['items'] = &$items;
  713. t3lib_div::callUserFunction($this->TCA['columns'][$fN]["config"]["itemsProcFunc"], $params, $this);
  714. }
  715. foreach((array)$items as $key => $item) {
  716. $selected = in_array($item[1],$uids)?"selected":"";
  717. if($key!=0)
  718. $options .= '<option value="'.$item[1].'"'.$selected.'>'.$this->getLLFromLabel($item[0]).'</option>';
  719. }
  720. } else { // unknown TCA config
  721. $options = '<option><em>Unknown TCA-configuration</em></option>';
  722. }
  723. if($this->TCA['columns'][$fN]["config"]["size"]) {
  724. $size = ' size="'.$this->TCA['columns'][$fN]["config"]["size"].'" ';
  725. if($this->TCA['columns'][$fN]["config"]["maxitems"]>1) {
  726. $size .= ' multiple ';
  727. $onChange = ' onChange="feedit_manipulateMultipleSelect(\''.$fieldName.'\')" ';
  728. $hr = '<input type="hidden" name="'.$fieldName.'" value="'.implode(",",$uids).'">';
  729. $name = substr($name,0,-1).'_select" ';
  730. }
  731. }
  732. $row .= '<select '.$size.' '.$onChange.' name="FE['.$this->table.']['.$fN.']_select">
  733. '.$options.'
  734. </select>'.$hr;
  735. return $row;
  736. break;
  737. case "user":
  738. debug("getFormFieldCode():: user fields not implementet yet.");
  739. case "radio":
  740. debug("getFormFieldCode():: radio buttons not implementet yet.");
  741. case "flex":
  742. debug("getFormFieldCode():: flex fields not implementet yet.");
  743. default:
  744. debug("getFormFieldCode():: Unknown type (".$type.") with field ".$fN);
  745. return '<input type="text"'.$defaultParams.' />';
  746. break;
  747. }
  748. }
  749. function getEditMenuTemplate() {
  750. return '
  751. <!-- ###TEMPLATE_EDITMENU### begin -->
  752. <br />'.($this->conf['no_header']?'':'<h1 class="'.$this->caller->pi_getClassName('header').' '.$this->caller->pi_getClassName('header-editmenu').'">'.$this->getLL("edit_menu_header").'</h1>').'
  753. <div class="'.$this->caller->pi_getClassName('message').' '.$this->caller->pi_getClassName('message-editmenu').'">'.$this->getLL("edit_menu_description").'</div>
  754. <div'.$this->caller->pi_classParam('editmenu-list').'>
  755. <!-- ###ALLITEMS### begin -->
  756. <!-- ###ITEM### begin -->
  757. <div><a href="###FORM_URL###&rU=###FIELD_uid###&cmd=edit&backURL=###FORM_URL_ENC###'.rawurlencode('&cmd=edit').'">###FIELD_'.strtolower($this->id_field).'###</a></div>
  758. <!-- ###ITEM### end -->
  759. <!-- ###ALLITEMS### end -->
  760. </div>
  761. <div class="'.$this->caller->pi_getClassName('link').' '.$this->caller->pi_getClassName('link-editmenu').'"><div><a href="###FORM_URL###&cmd=create">'.$this->getLL("edit_menu_createnew_label").'</a></div></div>
  762. <!-- ###TEMPLATE_EDITMENU### -->
  763. <!-- ###TEMPLATE_EDITMENU_NOITEMS### begin -->
  764. '.($this->conf['no_header']?'':'<h1 class="'.$this->caller->pi_getClassName('header').' '.$this->caller->pi_getClassName('header-editmenu-noitems').'">'.$this->getLL("edit_menu_noitems_header").'</h1>').'
  765. <div class="'.$this->caller->pi_getClassName('message').' '.$this->caller->pi_getClassName('message-editmenu-noitems').'">'.$this->getLL("edit_menu_noitems_description").'</div>
  766. <div class="'.$this->caller->pi_getClassName('link').' '.$this->caller->pi_getClassName('link-editmenu-noitems').'"><div><a href="###FORM_URL###&cmd=create">'.$this->getLL("edit_menu_createnew_label").'</a></div></div>
  767. <!-- ###TEMPLATE_EDITMENU_NOITEMS### -->
  768. ';
  769. }
  770. function getEditTemplate() {
  771. $HTMLFormEdit = $this->makeHTMLForm('edit');
  772. $HTMLPreviewEdit = $this->makeHTMLPreview('edit');
  773. if($this->conf['delete.']['preview']) {
  774. $deleteLink = '<div><a href="###FORM_URL###&cmd=delete&preview=1&backURL=###FORM_URL_ENC###&rU=###REC_UID###">'.$this->getLL("edit_delete_label").'</a></div>';
  775. } else {
  776. $deleteLink = '<div><a href="###FORM_URL###&cmd=delete&backURL=###FORM_URL_ENC###&rU=###REC_UID###" onClick="return confirm(\''.$this->getLL("edit_delete_confirm").'\');">'.$this->getLL("edit_delete_label").'</a></div>';
  777. }
  778. if(!$this->conf['delete']) $deleteLink = '';
  779. return '
  780. <!-- ###TEMPLATE_EDIT### -->
  781. '.($this->conf['no_header']?'':'<h1 class="'.$this->caller->pi_getClassName('header').' '.$this->caller->pi_getClassName('header-edit').'">'.$this->getLL("edit_header_prefix").' "###FIELD_'.strtolower($this->id_field).'###"</h1>').'
  782. '.($this->conf['text_in_top_of_form']?'<div'.$this->caller->pi_classParam('form-text').'>'.$this->cObj->stdWrap($this->conf['text_in_top_of_form'],$this->conf['text_in_top_of_form.']).'</div>':'').'
  783. <div'.$this->caller->pi_classParam('form-wrap').'>
  784. <form name="'.$this->table.'_form" method="post" action="###FORM_URL###" enctype="'.$GLOBALS["TYPO3_CONF_VARS"]["SYS"]["form_enctype"].'" onsubmit="'.implode(';', $this->additionalJS_submit).'">
  785. '.$HTMLFormEdit.'
  786. <div'.$this->caller->pi_classParam('form-row').'>
  787. ###HIDDENFIELDS###
  788. <input type="Submit" name="submit" value="'.($this->conf['edit.']['preview']?$this->getLL("edit_submit_label"):$this->getLL("edit_preview_submit_label")).'"'.$this->caller->pi_classParam('form-submit').'>
  789. </div>
  790. </form>
  791. </div>
  792. <div class="'.$this->caller->pi_getClassName('link').' '.$this->caller->pi_getClassName('link-edit').'">
  793. '.$deleteLink.'
  794. <div><a href="###FORM_URL###&cmd=edit">'.$this->getLL("back_label").'</a></div>
  795. </div>
  796. <!-- ###TEMPLATE_EDIT### end-->
  797. <!-- ###TEMPLATE_EDIT_PREVIEW### -->
  798. '.($this->conf['no_header']?'':'<h1 class="'.$this->caller->pi_getClassName('header').' '.$this->caller->pi_getClassName('header-edit-preview').'">'.$this->getLL("edit_header_prefix").' "###FIELD_'.strtolower($this->id_field).'###"</h1>').'
  799. '.($this->conf['text_in_top_of_preview']?'<div'.$this->caller->pi_classParam('preview-text').'>'.$this->cObj->stdWrap($this->conf['text_in_top_of_preview'],$this->conf['text_in_top_of_preview.']).'</div>':'').'
  800. <div'.$this->caller->pi_classParam('preview-wrap').'>
  801. <form name="'.$this->table.'_form" method="post" action="###FORM_URL###" enctype="'.$GLOBALS["TYPO3_CONF_VARS"]["SYS"]["form_enctype"].'">
  802. '.$HTMLPreviewEdit.'
  803. <div'.$this->caller->pi_classParam('preview-row').'>
  804. ###HIDDENFIELDS###
  805. <input type="Submit" name="doNotSave" value="'.$this->getLL("edit_preview_donotsave_label").'"'.$this->caller->pi_classParam('preview-donotsave').'>
  806. <input type="Submit" name="submit" value="'.$this->getLL("edit_preview_submit_label").'"'.$this->caller->pi_classParam('preview-submit').'>
  807. </div>
  808. </form>
  809. </div>
  810. <!-- ###TEMPLATE_EDIT_PREVIEW### end-->
  811. <!-- ###TEMPLATE_EDIT_SAVED### begin-->
  812. '.($this->conf['no_header']?'':'<h1 class="'.$this->caller->pi_getClassName('header').' '.$this->caller->pi_getClassName('header-edit-saved').'">'.$this->getLL("edit_saved_header").'</h1>').'
  813. <div class="'.$this->caller->pi_getClassName('message').' '.$this->caller->pi_getClassName('message-edit-saved').'">'.$this->getLL("edit_saved_message").'</div>
  814. <div class="'.$this->caller->pi_getClassName('link').' '.$this->caller->pi_getClassName('link-edit-saved').'"><div><a href="###FORM_URL###&cmd=edit">'.$this->getLL("back_label").'</a></div></div>
  815. <!-- ###TEMPLATE_EDIT_SAVED### end-->
  816. ';
  817. }
  818. function getCreateTemplate() {
  819. $HTMLFormCreate = $this->makeHTMLForm('create');
  820. $HTMLPreviewCreate = $this->makeHTMLPreview('create');
  821. return '
  822. <!-- ###TEMPLATE_CREATE_LOGIN### -->
  823. '.($this->conf['no_header']?'':'<h1 class="'.$this->caller->pi_getClassName('header').' '.$this->caller->pi_getClassName('header-create-login').'">'.$this->getLL("create_header_prefix").' '.$this->getLLFromLabel($this->TCA["ctrl"]["title"]).'</h1>').'
  824. '.($this->conf['text_in_top_of_form']?'<div'.$this->caller->pi_classParam('form-text').'>'.$this->cObj->stdWrap($this->conf['text_in_top_of_form'],$this->conf['text_in_top_of_form.']).'</div>':'').'
  825. <div'.$this->caller->pi_classParam('form-wrap').'>
  826. <form name="'.$this->table.'_form" method="post" action="###FORM_URL###" enctype="'.$GLOBALS["TYPO3_CONF_VARS"]["SYS"]["form_enctype"].'" onsubmit="'.implode(';', $this->additionalJS_submit).'">
  827. '.$HTMLFormCreate.'
  828. <div'.$this->caller->pi_classParam('form-row').'>
  829. ###HIDDENFIELDS###
  830. <input type="Submit" name="submit" value="'.($this->conf['create.']['preview']?$this->getLL("create_submit_label"):$this->getLL("create_preview_submit_label")).'"'.$this->caller->pi_classParam('form-submit').'>
  831. </div>
  832. </form>
  833. </div>
  834. <div class="'.$this->caller->pi_getClassName('link').' '.$this->caller->pi_getClassName('link-create-login').'"><div><a href="###FORM_URL###&cmd=edit">'.$this->getLL("create_edit_link").'</a></div></div>
  835. <!-- ###TEMPLATE_CREATE_LOGIN### end-->
  836. <!-- ###TEMPLATE_CREATE_LOGIN_PREVIEW### begin-->
  837. '.($this->conf['no_header']?'':'<h1 class="'.$this->caller->pi_getClassName('header').' '.$this->caller->pi_getClassName('header-create-login-preview').'">'.$this->getLL("create_header_prefix").' '.$this->getLLFromLabel($this->TCA["ctrl"]["title"]).'</h1>').'
  838. '.($this->conf['text_in_top_of_preview']?'<div'.$this->caller->pi_classParam('preview-text').'>'.$this->cObj->stdWrap($this->conf['text_in_top_of_preview'],$this->conf['text_in_top_of_preview.']).'</div>':'').'
  839. <div'.$this->caller->pi_classParam('preview-wrap').'>
  840. <form name="'.$this->table.'_form" method="post" action="###FORM_URL###" enctype="'.$GLOBALS["TYPO3_CONF_VARS"]["SYS"]["form_enctype"].'">
  841. '.$HTMLPreviewCreate.'
  842. <div'.$this->caller->pi_classParam('preview-row').'>
  843. ###HIDDENFIELDS###
  844. <input type="Submit" name="doNotSave" value="'.$this->getLL("create_preview_donotsave_label").'"'.$this->caller->pi_classParam('preview-donotsave').'>
  845. <input type="Submit" name="submit" value="'.$this->getLL("create_preview_submit_label").'"'.$this->caller->pi_classParam('preview-submit').'>
  846. </div>
  847. </form>
  848. </div>
  849. <!-- ###TEMPLATE_CREATE_LOGIN_PREVIEW### end-->
  850. <!-- ###TEMPLATE_CREATE### -->
  851. '.($this->conf['no_header']?'':'<h1 class="'.$this->caller->pi_getClassName('header').' '.$this->caller->pi_getClassName('header-create').'">'.$this->getLL("create_header_prefix").' '.$this->getLLFromLabel($this->TCA["ctrl"]["title"]).'</h1>').'
  852. '.($this->conf['text_in_top_of_form']?'<div'.$this->caller->pi_classParam('form-text').'>'.$this->cObj->stdWrap($this->conf['text_in_top_of_form'],$this->conf['text_in_top_of_form.']).'</div>':'').'
  853. <div'.$this->caller->pi_classParam('form-wrap').'>
  854. <form name="'.$this->table.'_form" method="post" action="###FORM_URL###" enctype="'.$GLOBALS["TYPO3_CONF_VARS"]["SYS"]["form_enctype"].'" onsubmit="'.implode(';', $this->additionalJS_submit).'">
  855. '.$HTMLFormCreate.'
  856. <div'.$this->caller->pi_classParam('form-row').'>
  857. ###HIDDENFIELDS###
  858. <input type="Submit" name="submit" value="'.($this->conf['create.']['preview']?$this->getLL("create_submit_label"):$this->getLL("create_preview_submit_label")).'"'.$this->caller->pi_classParam('form-submit').'>
  859. </div>
  860. </form>
  861. </div>
  862. <!-- ###TEMPLATE_CREATE### end-->
  863. <!-- ###TEMPLATE_CREATE_PREVIEW### begin-->
  864. '.($this->conf['no_header']?'':'<h1 class="'.$this->caller->pi_getClassName('header').' '.$this->caller->pi_getClassName('header-create-preview').'">'.$this->getLL("create_header_prefix").' '.$this->getLLFromLabel($this->TCA["ctrl"]["title"]).'</h1>').'
  865. '.($this->conf['text_in_top_of_preview']?'<div'.$this->caller->pi_classParam('preview-text').'>'.$this->cObj->stdWrap($this->conf['text_in_top_of_preview'],$this->conf['text_in_top_of_preview.']).'</div>':'').'
  866. <div'.$this->caller->pi_classParam('preview-wrap').'>
  867. <form name="'.$this->table.'_form" method="post" action="###FORM_URL###" enctype="'.$GLOBALS["TYPO3_CONF_VARS"]["SYS"]["form_enctype"].'">
  868. '.$HTMLPreviewCreate.'
  869. <div'.$this->caller->pi_classParam('preview-row').'>
  870. ###HIDDENFIELDS###
  871. <input type="Submit" name="doNotSave" value="'.$this->getLL("create_preview_donotsave_label").'"'.$this->caller->pi_classParam('preview-donotsave').'>
  872. <input type="Submit" name="submit" value="'.$this->getLL("create_preview_submit_label").'"'.$this->caller->pi_classParam('preview-submit').'>
  873. </div>
  874. </form>
  875. </div>
  876. <!-- ###TEMPLATE_CREATE_PREVIEW### end-->
  877. <!-- ###TEMPLATE_CREATE_SAVED### begin-->
  878. '.($this->conf['no_header']?'':'<h1 class="'.$this->caller->pi_getClassName('header').' '.$this->caller->pi_getClassName('header-create-saved').'">'.$this->getLL("create_saved_header").'</h1>').'
  879. <div class="'.$this->caller->pi_getClassName('message').' '.$this->caller->pi_getClassName('message-create-saved').'">'.$this->getLL("create_saved_message").'</div>
  880. <div class="'.$this->caller->pi_getClassName('link').' '.$this->caller->pi_getClassName('link-create-saved').'"><div><a href="###FORM_URL###&cmd=create">'.$this->getLL("back_label").'</a></div></div>
  881. <!-- ###TEMPLATE_CREATE_SAVED### end-->
  882. ';
  883. }
  884. function getDeleteTemplate() {
  885. return '
  886. <!-- ###TEMPLATE_DELETE_PREVIEW### begin-->
  887. '.($this->conf['no_header']?'':'<h1 class="'.$this->caller->pi_getClassName('header').' '.$this->caller->pi_getClassName('header-delete-preview').'">'.$this->getLL("delete_preview_header").'</h1>').'
  888. <div class="'.$this->caller->pi_getClassName('message').' '.$this->caller->pi_getClassName('message-delete-preview').'">'.$this->getLL("delete_preview_message").'</div>
  889. <div class="'.$this->caller->pi_getClassName('link').' '.$this->caller->pi_getClassName('link-delete-preview').'">
  890. <div><a href="###FORM_URL###&cmd=delete&backURL=###FORM_URL_ENC###&rU=###REC_UID###">'.$this->getLL("delete_preview_delete_label").'</a></div>
  891. <div><a href="###FORM_URL###&cmd=edit&rU=###REC_UID###&backURL=###BACK_URL###" >'.$this->getLL("delete_preview_dont_delete_label").'</a></div>
  892. </div>
  893. <!-- ###TEMPLATE_DELETE_PREVIEW### end-->
  894. <!-- ###TEMPLATE_DELETE_SAVED### begin-->
  895. '.($this->conf['no_header']?'':'<h1 class="'.$this->caller->pi_getClassName('header').' '.$this->caller->pi_getClassName('header-delete-saved').'">'.$this->getLL("delete_saved_header").'</h1>').'
  896. <div class="'.$this->caller->pi_getClassName('message').' '.$this->caller->pi_getClassName('message-delete-saved').'">'.$this->getLL("delete_saved_message").'</div>
  897. <div class="'.$this->caller->pi_getClassName('link').' '.$this->caller->pi_getClassName('link-delete-saved').'"><div><a href="###FORM_URL###&cmd=edit">'.$this->getLL("back_label").'</a></div></div>
  898. <!-- ###TEMPLATE_DELETE_SAVED### end-->
  899. ';
  900. }
  901. function getSetfixedTemplate() {
  902. //jsmodified: removed .nl2br($this->makeTEXTPreview('all')).
  903. return '
  904. <!-- ###TEMPLATE_SETFIXED_OK### -->
  905. '.($this->conf['no_header']?'':'<h1 class="'.$this->caller->pi_getClassName('header').' '.$this->caller->pi_getClassName('header-setfixed-ok').'">Entry Approved</h1>').'
  906. <div class="'.$this->caller->pi_getClassName('message').' '.$this->caller->pi_getClassName('message-setfixed-ok').'">Entry "###FIELD_'.$this->id_field.'###", has been approved.<br/><br/>' . '</div>
  907. <!-- ###TEMPLATE_SETFIXED_OK### end-->
  908. <!-- ###TEMPLATE_SETFIXED_OK_DELETE### -->
  909. '.($this->conf['no_header']?'':'<h1 class="'.$this->caller->pi_getClassName('header').' '.$this->caller->pi_getClassName('header-setfixed-ok-delete').'">Entry Deleted</h1>').'
  910. <div class="'.$this->caller->pi_getClassName('message').' '.$this->caller->pi_getClassName('message-setfixed-ok').'">Entry "###FIELD_'.$this->id_field.'###", has been deleted.<br/><br/>'.'</div>
  911. <!-- ###TEMPLATE_SETFIXED_OK_DELETE### end-->
  912. <!-- ###TEMPLATE_SETFIXED_FAILED### -->
  913. '.($this->conf['no_header']?'':'<h1 class="'.$this->caller->pi_getClassName('header').' '.$this->caller->pi_getClassName('header-setfixed-failed').'">Setfixed failed!</h1>').'
  914. <div class="'.$this->caller->pi_getClassName('message').' '.$this->caller->pi_getClassName('message-setfixed-failed').'">Failed: May happen if you click the setfixed link a second time (if the record has changed since the setfixed link was generated this error will happen!)</div>
  915. <!-- ###TEMPLATE_SETFIXED_FAILED### end-->
  916. ';
  917. }
  918. function getEmailTemplate() {
  919. //echo $this->makeTEXTPreview('edit'); //jstmp
  920. //jsmodified
  921. $plainText = preg_replace( '/([a-z0-1]###)/', "$1\n", $this->makeTEXTPreview('all') );
  922. // echo $plainText;
  923. return '
  924. <!-- ###EMAIL_TEMPLATE_CREATE_SAVED### begin -->
  925. Savvy Miss: New Blog Entry
  926. <!--###SUB_RECORD###-->
  927. You have submitted the following blog entry at '.t3lib_div::getIndpEnv('TYPO3_SITE_URL').':'.chr(10).'
  928. '.$this->makeTEXTPreview('all').'
  929. <!--###SUB_RECORD###-->
  930. <!-- ###EMAIL_TEMPLATE_CREATE_SAVED### end-->
  931. <!-- ###EMAIL_TEMPLATE_CREATE_SAVED-ADMIN### begin -->
  932. Savvy Miss: New Blog Entry
  933. <!--###SUB_RECORD###-->'
  934. //. /*jsmodified*/ $this->htmlToPlainText($this->makeTEXTPreview('all')).
  935. //. $this->htmlToPlainText($this->makeTEXTPreview('edit')).
  936. //. $this->htmlToPlainText('<p>I gotta say Im a</p>').
  937. //.$plainText.
  938. .$this->makeTEXTPreview('all').
  939. '
  940. Approve:
  941. ###THIS_URL######FORM_URL######SYS_SETFIXED_approve###
  942. Delete:
  943. ###THIS_URL######FORM_URL######SYS_SETFIXED_DELETE###
  944. <!--###SUB_RECORD###-->
  945. <!-- ###EMAIL_TEMPLATE_CREATE_SAVED-ADMIN### end-->
  946. <!-- ###EMAIL_TEMPLATE_EDIT_SAVED-ADMIN### begin -->
  947. Savvy Miss: Blog Entry Edited
  948. <!--###SUB_RECORD###-->
  949. '.$this->makeTEXTPreview('all').'
  950. Approve:
  951. ###THIS_URL######FORM_URL######SYS_SETFIXED_approve###
  952. Delete:
  953. ###THIS_URL######FORM_URL######SYS_SETFIXED_DELETE###
  954. <!--###SUB_RECORD###-->
  955. <!-- ###EMAIL_TEMPLATE_EDIT_SAVED-ADMIN### end-->
  956. <!-- ###EMAIL_TEMPLATE_SETFIXED_DELETE### begin -->
  957. Consultancy DELETED!
  958. <!--###SUB_RECORD###-->
  959. Record name: ###FIELD_'.$this->id_field.'###
  960. Your entry has been deleted by the admin for some reason.
  961. - kind regards.
  962. <!--###SUB_RECORD###-->
  963. <!-- ###EMAIL_TEMPLATE_SETFIXED_DELETE### begin -->
  964. <!-- ###EMAIL_TEMPLATE_SETFIXED_approve### begin -->
  965. Consultancy approved
  966. <!--###SUB_RECORD###-->
  967. Record name: ###FIELD_'.$this->id_field.'###
  968. Your consultancy entry has been approved!
  969. - kind regards.
  970. <!--###SUB_RECORD###-->
  971. <!-- ###EMAIL_TEMPLATE_SETFIXED_approve### begin -->
  972. ';
  973. }
  974. function getRequiredTemplate() {
  975. return '
  976. <!-- ###TEMPLATE_AUTH### -->
  977. '.($this->conf['no_header']?'':'<h1 class="'.$this->caller->pi_getClassName('header').' '.$this->caller->pi_getClassName('header-auth').'">Authentication failed</h1>').'
  978. <div class="'.$this->caller->pi_getClassName('message').' '.$this->caller->pi_getClassName('message-auth').'">Of some reason the authentication failed. </div>
  979. <!-- ###TEMPLATE_AUTH### end-->
  980. <!-- ###TEMPLATE_NO_PERMISSIONS### -->
  981. '.($this->conf['no_header']?'':'<h1 class="'.$this->caller->pi_getClassName('header').' '.$this->caller->pi_getClassName('header-no-permissions').'">No permissions to edit record</h3>').'
  982. <div class="'.$this->caller->pi_getClassName('message').' '.$this->caller->pi_getClassName('message-no-permissions').'">Sorry, you did not have permissions to edit the record.</div>
  983. <!-- ###TEMPLATE_NO_PERMISSIONS### end-->
  984. ';
  985. }
  986. /**********************************************************************************************
  987. * FUNCTIONS CALLED FROM fe_adminLib
  988. **********************************************************************************************/
  989. /*
  990. * This function has the data array passed to it in $content.
  991. * Must return the data array again.
  992. * The function runs through the fields from fe_adminLibs dataArr and does som required processing for the different fields types.
  993. */
  994. function processDataArray($content,$conf) {
  995. //echo "function processDataArray($content,$conf) {"; //tmpjs
  996. //debug($content,'processDataArray content');//TODODEBUG
  997. //debug($conf, 'processDataArray conf');//TODODEBUG
  998. $fe_adminLib = &$conf['parentObj'];
  999. $dataArr = $content;
  1000. $table = $fe_adminLib->theTable;
  1001. foreach((array)$dataArr as $fN=>$value) {
  1002. switch((string)$GLOBALS['TCA'][$table]['columns'][$fN]['config']['type']) {
  1003. case 'input':
  1004. // if evaltype is date or datetime and overrideValue is 'now' we transform it into the current timestamp + the int following 'now'.
  1005. // Example: if override value is now+30 we transform it into a timestamp representing the day 30 days from today
  1006. if(($GLOBALS['TCA'][$table]['columns'][$fN]['config']['eval']=='date' || $GLOBALS['TCA'][$table]['columns'][$fN]['config']['eval']=='datetime') &&
  1007. substr($fe_adminLib->conf[$fe_adminLib->cmdKey."."]["overrideValues."][$fN],0,3) == 'now') {
  1008. $dataArr[$fN] = time() + 24*60*60*intval(substr($fe_adminLib->conf[$fe_adminLib->cmdKey."."]["overrideValues."][$fN],3));
  1009. }
  1010. //jsmod
  1011. //if overridevalue is [currentUsername] , author is set to current user's username.
  1012. if(($GLOBALS['TCA'][$table]['columns'][$fN]['config']['eval']=='author' &&
  1013. $fe_adminLib->conf[$fe_adminLib->cmdKey."."]["overrideValues."][$fN] == '[currentUsername]')) {
  1014. //echo '[currentUsername] block ';//jstmp
  1015. if ($GLOBALS['TSFE']->loginUser) {
  1016. echo 'loginUser block ';
  1017. $dataArr[$fN] = $GLOBALS['TSFE']->fe_user->user['username'];
  1018. }
  1019. }
  1020. break;
  1021. case 'text':
  1022. $dataArr = $this->rteProcessDataArr($dataArr, $table, $fN, 'db');
  1023. break;
  1024. }
  1025. }
  1026. return $dataArr;
  1027. }
  1028. /*
  1029. * This function has the value-array passed to it before the value array is used to construct the update-JavaScript statements in fe_adminLib.
  1030. * Must return the value-array again.
  1031. * The function runs through the fields from fe_adminLibs dataArr and does som required stuff for the different fields types
  1032. */
  1033. function updateArray($content,$conf) {
  1034. //echo "function updateArray($content,$conf) {"; //jstmp
  1035. //print_r($content);
  1036. //print_r($conf);
  1037. # debug($content,'updateArray content');
  1038. # debug($conf,'updateArray conf');
  1039. $fe_adminLib = &$conf['parentObj'];
  1040. $dataArr = $content;
  1041. $table = $fe_adminLib->theTable;
  1042. foreach((array)$dataArr as $fN=>$value) {
  1043. switch((string)$GLOBALS['TCA'][$table]['columns'][$fN]['config']['type']) {
  1044. case 'group':
  1045. // we need to update the additional field $fN.'_file'.
  1046. $fe_adminLib->additionalUpdateFields .= ','.$fN.'_file';
  1047. break;
  1048. case 'input':
  1049. // if evaltype is date or datetime and defaultValue is 'now' we transform it into the current timestamp + the int following 'now'.
  1050. // Example: if default value is now+30 we transform it into a timestamp representing the day 30 days from today
  1051. if(($GLOBALS['TCA'][$table]['columns'][$fN]['config']['eval']=='date' || $GLOBALS['TCA'][$table]['columns'][$fN]['config']['eval']=='datetime') &&
  1052. substr($fe_adminLib->conf[$fe_adminLib->cmdKey."."]["defaultValues."][$fN],0,3) == 'now'/* && empty($dataArr[$fN])*/) {
  1053. $dataArr[$fN] = time() + 24*60*60*intval(substr($fe_adminLib->conf[$fe_adminLib->cmdKey."."]["defaultValues."][$fN],3));
  1054. }
  1055. //jsmod
  1056. //if overridevalue is [currentUsername] , author is set to current user's username.
  1057. //tmpjs
  1058. // echo " \$fN :" . $fN; //tmpjs
  1059. // echo " overrideValues :" . $fe_adminLib->conf[$fe_adminLib->cmdKey."."]["overrideValues."][$fN]; //tmpjs
  1060. // echo " loginUser :" . $GLOBALS['TSFE']->loginUser;//tmpjs
  1061. // echo " username :" . $GLOBALS['TSFE']->fe_user->user['username'];
  1062. // print_r( $fe_adminLib->conf[$fe_adminLib->cmdKey."."]["overrideValues."][$fN]); //jstmp
  1063. //
  1064. if ($fe_adminLib->conf[$fe_adminLib->cmdKey."."]["overrideValues."][$fN] == '[currentUsername]') {
  1065. //badif ($conf[$fe_adminLib->cmdKey."."]["overrideValues."][$fN] == '[currentUsername]') {
  1066. //echo 'currentUsername blocka ';//jstmp
  1067. }
  1068. //removed this condition($GLOBALS['TCA'][$table]['columns'][$fN]['config']['eval']=='author' &&
  1069. if((
  1070. $fe_adminLib->conf[$fe_adminLib->cmdKey."."]["overrideValues."][$fN] == '[currentUsername]')) {
  1071. // echo 'currentUsername blockb ';//jstmp
  1072. if ($GLOBALS['TSFE']->loginUser) {
  1073. //echo 'loginUser block ';
  1074. $dataArr[$fN] = $GLOBALS['TSFE']->fe_user->user['username'];
  1075. }
  1076. }
  1077. break;
  1078. case 'text':
  1079. $dataArr = $this->rteProcessDataArr($dataArr, $table, $fN, 'rte');
  1080. break;
  1081. case 'select':
  1082. $feData = t3lib_div::_POST('FE');
  1083. $uid = $feData[$table]['uid'] ? $feData[$table]['uid'] : t3lib_div::_GET('rU');
  1084. if($GLOBALS['TCA'][$table]['columns'][$fN]["config"]["foreign_table"] &&
  1085. $GLOBALS['TCA'][$table]['columns'][$fN]["config"]["MM"] &&
  1086. $uid) {
  1087. $dataArr[$fN] = implode(',',$this->getUidsOfSelectedRecords($dataArr,$fN,$fe_adminLib->theTable));
  1088. }
  1089. break;
  1090. default:
  1091. //echo "default case";
  1092. break;
  1093. }
  1094. }
  1095. # debug($dataArr);
  1096. return $dataArr;
  1097. }
  1098. /*
  1099. * This funtion is called after a record is saved in fe_adminLib.
  1100. * The function runs through the fields from fe_adminLibs dataArr and does som required stuff for the different fields types
  1101. */
  1102. function afterSave($content,$conf) {
  1103. // echo "function afterSave($content,$conf) {" ; //jstmp
  1104. # debug($content,'content');
  1105. # debug($conf,'conf');
  1106. # debug($_FILES,'$_FILES');
  1107. $fe_adminLib = &$conf['parentObj'];
  1108. $dataArr = $fe_adminLib->dataArr;
  1109. $table = $fe_adminLib->theTable;
  1110. foreach((array)$dataArr as $fN=>$value) {
  1111. switch((string)$GLOBALS['TCA'][$table]['columns'][$fN]['config']['type']) {
  1112. case 'group':
  1113. if($GLOBALS['TCA'][$table]['columns'][$fN]['config']['internal_type']=='file') { //internal_type=file
  1114. /**** DELETED FILES ****/
  1115. // if files are deleted in the field, we also want to make sure they are deleted on the server
  1116. if($content['origRec']) {
  1117. $diff = array_diff( explode(',',$content['origRec'][$fN]), explode(',',$content['rec'][$fN]) );
  1118. foreach((array)$diff as $file) {
  1119. $uploadPath = $GLOBALS['TCA'][$table]['columns'][$fN]['config']['uploadfolder'];
  1120. @unlink(PATH_site.$uploadPath.'/'.$file);
  1121. }
  1122. }
  1123. /**** UPLOADED FILES ****/
  1124. // if a new file is uploaded, we need to add to the database.
  1125. $file = $dataArr[$fN.'_file'];
  1126. if($file) {
  1127. $fV = $content['rec'][$fN] ? $content['rec'][$fN].','.$file : $file;
  1128. $cObj = t3lib_div::makeInstance('tslib_cObj');
  1129. $cObj->DBgetUpdate($table, $content['rec']['uid'], array($fN=>$fV), $fN, TRUE);
  1130. }
  1131. }
  1132. break;
  1133. case 'input':
  1134. if((
  1135. $fe_adminLib->conf[$fe_adminLib->cmdKey."."]["overrideValues."][$fN] == '[currentUsername]')) {
  1136. //echo 'currentUsername blockb ';//jstmp
  1137. if ($GLOBALS['TSFE']->loginUser) {
  1138. //echo 'loginUser block ';
  1139. //$dataArr[$fN] = $GLOBALS['TSFE']->fe_user->user['username'];
  1140. $insertID = $GLOBALS['TYPO3_DB']->sql_insert_id();
  1141. //echo "uid : " . $insertID; //$dataArr['uid'];
  1142. $query = "
  1143. UPDATE fe_users, tt_news
  1144. SET tt_news.author = fe_users.username
  1145. WHERE
  1146. fe_users.uid = tt_news.tx_newsfeedit_fe_cruser_id
  1147. AND tt_news.uid = $insertID
  1148. ";
  1149. //copy the user image from users upload dir to news upload dir - js
  1150. $documentRoot = $_SERVER['DOCUMENT_ROOT'];
  1151. //echo "documentRoot: $documentRoot"; //jsdbg
  1152. $uploadsDir = $documentRoot . '/fileadmin/uploads';
  1153. $userPicsDir = $uploadsDir . '/tx_srfeuserregister';
  1154. #$ttNewsUsersPicsDir = $uploadsDir . '/pics/feusers';
  1155. #$ttNewsUsersPicsDirPrefix = 'pics/feusers/';
  1156. $ttNewsUsersPicsDir = $uploadsDir . '/pics';
  1157. $ttNewsUsersPicsDirPrefix = '';
  1158. $userImage = $GLOBALS['TSFE']->fe_user->user['image'];
  1159. $slash = '/';
  1160. $source = $userPicsDir . $slash . $userImage;
  1161. $destination = $ttNewsUsersPicsDir . $slash . $userImage;
  1162. //echo "<br>\nCopying $source to $destination."; //jsdbg
  1163. if (!empty($userImage)) {
  1164. copy( $source, $destination );
  1165. //resize the image, just in case
  1166. $maxImageSizeW = '117';
  1167. $maxImageSizeH = '156';
  1168. $esapedParam = escapeshellcmd($destination);
  1169. //resize to max of specified height and width
  1170. $commandLine = "mogrify -resize {$maxImageSizeW}x{$maxImageSizeH} $esapedParam";
  1171. //echo $commandLine; //jstmp;
  1172. system($commandLine);
  1173. }
  1174. #$userImageRelativePath = $ttNewsUsersPicsDirPrefix . $userImage;
  1175. $userImageRelativePath = $userImage;
  1176. // MySQL 3. blows
  1177. $query = "
  1178. UPDATE tt_news
  1179. SET tt_news.author = '{$GLOBALS['TSFE']->fe_user->user['username']}'
  1180. , tt_news.image = '$userImageRelativePath'
  1181. WHERE tt_news.uid = $insertID
  1182. ";
  1183. $GLOBALS['TYPO3_DB']->sql_query($query);
  1184. }
  1185. }
  1186. break;
  1187. case 'select':
  1188. if($GLOBALS['TCA'][$table]['columns'][$fN]['config']['MM']) { //its a MM relation
  1189. $uids = explode(',',$dataArr[$fN]);
  1190. $uid = $content['rec']['uid'];
  1191. $mmTable = $GLOBALS['TCA'][$table]['columns'][$fN]['config']['MM'];
  1192. // update the $fN in $table
  1193. $cObj = t3lib_div::makeInstance('tslib_cObj');
  1194. $cObj->DBgetUpdate($table, $uid, array($fN=>count($uids)), $fN, TRUE);
  1195. // update the MM table
  1196. $GLOBALS['TYPO3_DB']->exec_DELETEquery($mmTable,'uid_local='.intval($uid));
  1197. foreach((array)$uids as $foreign_uid) {
  1198. $GLOBALS['TYPO3_DB']->exec_INSERTquery($mmTable,array('uid_local'=>intval($uid),'uid_foreign'=>intval($foreign_uid)));
  1199. }
  1200. }
  1201. break;
  1202. }
  1203. }
  1204. }
  1205. /**********************************************************************************************
  1206. * JAVASCRIPT FUNCTIONS
  1207. **********************************************************************************************/
  1208. function getJSBefore() {
  1209. $formName = $this->table.'_form';
  1210. $result .= '<script type="text/javascript" src="t3lib/jsfunc.evalfield.js"></script>
  1211. <script type="text/javascript">
  1212. function typoSetup() {
  1213. this.passwordDummy = "********";
  1214. this.decimalSign = ".";
  1215. }
  1216. var TS = new typoSetup();
  1217. var evalFunc = new evalFunc();
  1218. function feedit_'.$formName.'Set(theField, evallist, is_in, checkbox, checkboxValue,checkbox_off){
  1219. /*alert("SET:" + theField+": "+document.'.$formName.'[theField].value);*/
  1220. var theFObj = new evalFunc_dummy (evallist,is_in, checkbox, checkboxValue);
  1221. var feValField = theField+"_feVal";
  1222. if(!(document.'.$formName.' && document.'.$formName.'[theField] && document.'.$formName.'[feValField])) return;
  1223. theValue = document.'.$formName.'[theField].value;
  1224. /* valField = theField.substring(0,theField.length-1)+"_hrv]";
  1225. document.'.$formName.'[theField].value = theValue;
  1226. alert(theValue); */
  1227. document.'.$formName.'[feValField].value = evalFunc.outputObjValue(theFObj, theValue);
  1228. /*alert(theField+": "+document.'.$formName.'[theField].value);
  1229. alert(feValField+": "+document.'.$formName.'[feValField].value);*/
  1230. }
  1231. function feedit_'.$formName.'Get(theField, evallist, is_in, checkbox, checkboxValue,checkbox_off){
  1232. /*alert("GET: " + theField);*/
  1233. var theFObj = new evalFunc_dummy (evallist,is_in, checkbox, checkboxValue);
  1234. if (checkbox_off){
  1235. document.'.$formName.'[theField].value=checkboxValue;
  1236. }else{
  1237. document.'.$formName.'[theField].value = evalFunc.evalObjValue(theFObj, document.'.$formName.'[theField+"_feVal"].value);
  1238. /*if(document.'.$formName.'[theField].value.length==0)
  1239. for(idx=1; eval = feedit_split(evallist,",",idx);idx++);
  1240. if(eval == "required") {
  1241. alert("Feltet skal udfyldes");
  1242. }*/
  1243. }
  1244. feedit_'.$formName.'Set(theField, evallist, is_in, checkbox, checkboxValue,checkbox_off);
  1245. }
  1246. function feedit_manipulateMultipleSelect(theField) {
  1247. selObj = document.'.$formName.'[theField+"_select"];
  1248. val = selObj.value;
  1249. list = document.'.$formName.'[theField].value;
  1250. newList = "";
  1251. for(i=0;i<selObj.length;i++) {
  1252. if(selObj.options[i].selected == true) {
  1253. newList += selObj.options[i].value+",";
  1254. }
  1255. }
  1256. if(newList.length!=0)
  1257. newList = newList.substring(0,newList.length-1);
  1258. document.'.$formName.'[theField].value = newList;
  1259. }
  1260. function feedit_manipulateGroup(theField) {
  1261. selObj = document.'.$formName.'[theField+"_select"];
  1262. val = selObj.value;
  1263. list = document.'.$formName.'[theField].value;
  1264. newList = "";
  1265. for(i=0;i<selObj.length;i++) {
  1266. if(selObj.options[i].selected == false) {
  1267. newList += selObj.options[i].value+",";
  1268. } else {
  1269. rem_i = i;
  1270. }
  1271. }
  1272. if(newList.length!=0)
  1273. newList = newList.substring(0,newList.length-1);
  1274. alert(newList);
  1275. document.'.$formName.'[theField].value = newList;
  1276. selObj.options[rem_i] = null;
  1277. }
  1278. function feedit_split(theStr1, delim, index) {
  1279. var theStr = ""+theStr1;
  1280. var lengthOfDelim = delim.length;
  1281. sPos = -lengthOfDelim;
  1282. if (index<1) {index=1;}
  1283. for (var a=1; a<index; a++){
  1284. sPos = theStr.indexOf(delim, sPos+lengthOfDelim);
  1285. if (sPos==-1){return null;}
  1286. }
  1287. ePos = theStr.indexOf(delim, sPos+lengthOfDelim);
  1288. if(ePos == -1) {ePos = theStr.length;}
  1289. return (theStr.substring(sPos+lengthOfDelim,ePos));
  1290. }
  1291. </script>
  1292. ';
  1293. $result .= $this->additionalJS_initial.'<script type="text/javascript">'. implode(chr(10), $this->additionalJS_pre).'</script>';
  1294. if($this->conf['divide2tabs'])
  1295. $result .= $this->templateObj->getDynTabMenuJScode();
  1296. return $result;
  1297. }
  1298. function getJSAfter() {
  1299. return
  1300. '<script type="text/javascript">'.implode(chr(10), $this->additionalJS_post).'</script>'.chr(10).
  1301. '<script type="text/javascript">'.implode(chr(10), $this->additionalJS_end).'</script>';
  1302. }
  1303. /**********************************************************************************************
  1304. * HELPER FUNCTIONS
  1305. **********************************************************************************************/
  1306. /**
  1307. * Gets the special configurations for a field. The configurations placed in the type array.
  1308. *
  1309. * @param $table string the current table
  1310. * @param $fN string the fieldname to get the configurations for
  1311. * @return array the specialconf array
  1312. */
  1313. function getFieldSpecialConf($table,$fN) {
  1314. $specialConf = array();
  1315. $TCA = $GLOBALS["TCA"][$table];
  1316. // Get the type value
  1317. $type = 0; // default value
  1318. $typeField = $TCA['ctrl']['type'];
  1319. $uid = t3lib_div::_GET('rU');
  1320. if($typeField && $uid) { // get the type from the database else use default value
  1321. $rec = $GLOBALS['TSFE']->sys_page->getRawRecord($table,$uid);
  1322. $type = intval($rec[$typeField]);
  1323. }
  1324. // get the special configurations and check for an existing richtext configuration
  1325. $showitem = $TCA['types'][$type]['showitem'] ? explode(',',$TCA['types'][$type]['showitem']) : explode(',',$TCA['types'][1]['showitem']); // if ['types'][$type] we should try with ['types'][1] according to TCA doc
  1326. foreach((array)$showitem as $fieldConfig) {
  1327. $fC = explode(';',$fieldConfig);
  1328. if(trim($fC[0])==$fN) { // if field is $fN
  1329. foreach(explode(':',$fC[3]) as $sC) {
  1330. if(substr($sC,0,8)=='richtext') { // if there is a richtext configuration we found what we were looking for
  1331. $buttons = substr(trim($sC),9,strlen(trim($sC))-10);
  1332. $specialConf['richtext']['parameters'] = t3lib_div::trimExplode('|',$buttons);
  1333. } else if(substr($sC,0,13)=='rte_transform') {
  1334. $transConf = substr(trim($sC),14,strlen(trim($sC))-15);
  1335. $specialConf['rte_transform']['parameters'] = t3lib_div::trimExplode('|',$transConf);
  1336. }
  1337. }
  1338. }
  1339. }
  1340. return $specialConf;
  1341. }
  1342. /**
  1343. * Processes the field $fN in $dataArr be the rte mode $mode,
  1344. * according to the Page TS RTE.default.FE
  1345. *
  1346. * @param $dataArr array the dataArray
  1347. * @param $table string the table currently working on
  1348. * @param $fN string the fieldname of the table
  1349. * @param $mode string the transformation direction: either 'rte' or 'db'
  1350. * @return array the modified dataArr
  1351. */
  1352. function rteProcessDataArr($dataArr, $table, $fN, $mode) {
  1353. if(t3lib_extmgm::isLoaded('rtehtmlarea') && !$this->RTEObj)
  1354. $this->RTEObj = t3lib_div::makeInstance('tx_rtehtmlarea_pi2');
  1355. if(!empty($dataArr['_TRANSFORM_'.$fN]) && is_object($this->RTEObj) && $this->RTEObj->isAvailable()) {
  1356. $pageTSConfig = $GLOBALS['TSFE']->getPagesTSconfig();
  1357. # THIS WILL NOT WORK YET! mail sendt to author of rtehtmlarea STAN
  1358. /* if(is_array($pageTSConfig['RTE.']['default.']['FE.']) && is_array($pageTSConfig['RTE.']['config.'][$this->table.'.'][$fN.'.']['FE.'])) {
  1359. $this->thisConfig = t3lib_div::array_merge_recursive_overrule($pageTSConfig['RTE.']['default.']['FE.'],
  1360. $pageTSConfig['RTE.']['config.'][$this->table.'.'][$fN.'.']['FE.']);
  1361. } else {*/
  1362. $this->thisConfig = $pageTSConfig['RTE.']['default.']['FE.'];
  1363. // }
  1364. $this->thePidValue = $GLOBALS['TSFE']->id;
  1365. # $this->specConf = array('richtext' => 1, 'rte_transform' => array('parameters' => array('mode=ts_css','flag=rte_enabled')));
  1366. $this->specConf = $this->getFieldSpecialConf($table,$fN);
  1367. $dataArr[$fN] = $this->RTEObj->transformContent($mode,$dataArr[$fN],$table,$fN,$dataArr,$this->specConf,$this->thisConfig,'',$this->thePidValue);
  1368. }
  1369. return $dataArr;
  1370. }
  1371. /* Gets the uids if the selected record in a field of type SELECT.
  1372. * This function takes care of MM-relations too.
  1373. * (table is sendt along, as the function is called from updateArray too)
  1374. * @param string The record
  1375. * @param string The field of type SELECT in the record
  1376. * @returns array Array of uids
  1377. */
  1378. function getUidsOfSelectedRecords($rec,$fN,$table) {
  1379. global $TCA;
  1380. $feData = t3lib_div::_POST('FE');
  1381. $uid = $feData[$table]['uid'] ? $feData[$table]['uid'] : t3lib_div::_GET('rU');
  1382. $uids = array();
  1383. if($feData[$table][$fN]) { // from post var
  1384. $uids = explode(",",$feData[$table][$fN]);
  1385. } elseif($TCA[$table]['columns'][$fN]["config"]["MM"] && $uid) { // from mm-relation
  1386. $MMres = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*',$TCA[$table]['columns'][$fN]["config"]["MM"],'uid_local='.$uid,'','sorting');
  1387. if ($GLOBALS['TYPO3_DB']->sql_error()) debug(array($GLOBALS['TYPO3_DB']->sql_error(),$query),'getFormFieldCode()::field='.$fN);
  1388. if($GLOBALS['TYPO3_DB']->sql_num_rows($MMres)!=$rec[$fN])
  1389. debug("Wrong number of selections reached");
  1390. while($MMrow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($MMres))
  1391. $uids[] = $MMrow["uid_foreign"];
  1392. } else { // clean from DB
  1393. $uids = explode(",",$rec[$fN]);
  1394. }
  1395. return $uids;
  1396. }
  1397. function getLLFromLabel($label) {
  1398. return $GLOBALS['TSFE']->sL($label);
  1399. }
  1400. function getLL($key,$alt='') {
  1401. $label = $GLOBALS['TSFE']->getLLL($key,$this->LOCAL_LANG);
  1402. return $label ? $label : $alt;
  1403. }
  1404. /**
  1405. * array_merge_recursive2()
  1406. *
  1407. * Similar to array_merge_recursive but keyed-valued are always overwritten.
  1408. * Empty values is also overwritten.
  1409. * Priority goes to the 2nd array.
  1410. *
  1411. * @param $paArray1 array
  1412. * @param $paArray2 array
  1413. * @return array
  1414. */
  1415. function array_merge_recursive2($paArray1, $paArray2) {
  1416. if (!is_array($paArray1) or !is_array($paArray2)) {
  1417. return is_null($paArray2)?$paArray1:$paArray2;
  1418. }
  1419. foreach ($paArray2 AS $sKey2 => $sValue2) {
  1420. $paArray1[$sKey2] = $this->array_merge_recursive2(@$paArray1[$sKey2],
  1421. $sValue2);
  1422. }
  1423. return $paArray1;
  1424. }
  1425. }
  1426. if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/mth_feedit/class.tx_mthfeedit.php']) {
  1427. include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/mth_feedit/class.tx_mthfeedit.php']);
  1428. }
  1429. ?>