/***************************************************************
* Copyright notice
*
-* (c) 1999-2004 Kasper Skaarhoj (kasper@typo3.com)
+* (c) 1999-2010 Kasper Skaarhoj (kasperYYYY@typo3.com)
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* Revised for TYPO3 3.6 November/2003 by Kasper Skaarhoj
* XHTML compliant
*
- * @author Kasper Skaarhoj <kasper@typo3.com>
+ * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
*/
/**
* [CLASS/FUNCTION INDEX of SCRIPT]
*
*
* 84: class SC_wizard_table
- * 112: function init()
- * 150: function main()
- * 166: function printContent()
- * 175: function tableWizard()
+ * 116: function init()
+ * 158: function main()
+ * 173: function printContent()
+ * 184: function tableWizard()
*
* SECTION: Helper functions
- * 214: function getConfigCode($row)
- * 280: function getTableHTML($cfgArr,$row)
- * 429: function changeFunc()
- * 545: function cfgArray2CfgString($cfgArr)
- * 576: function cfgString2CfgArray($cfgStr,$cols)
+ * 223: function getConfigCode($row)
+ * 293: function getTableHTML($cfgArr,$row)
+ * 450: function changeFunc()
+ * 572: function cfgArray2CfgString($cfgArr)
+ * 603: function cfgString2CfgArray($cfgStr,$cols)
*
* TOTAL FUNCTIONS: 9
* (This index is automatically created/updated by the extension "extdeveval")
/**
* Script Class for rendering the Table Wizard
*
- * @author Kasper Skaarhoj <kasper@typo3.com>
+ * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
* @package TYPO3
* @subpackage core
*/
class SC_wizard_table {
// Internal, dynamic:
- var $doc; // Document template object
+ /**
+ * document template object
+ *
+ * @var mediumDoc
+ */
+ var $doc;
var $content; // Content accumulation for the module.
var $include_once=array(); // List of files to include.
var $inputStyle=0; // True, then <input> fields are shown, not textareas.
// Internal, static:
var $xmlStorage=0; // If set, the string version of the content is interpreted/written as XML instead of the original linebased kind. This variable still needs binding to the wizard parameters - but support is ready!
+ var $numNewRows=1; // Number of new rows to add in bottom of wizard
var $colsFieldName='cols'; // Name of field in parent record which MAY contain the number of columns for the table - here hardcoded to the value of tt_content. Should be set by TCEform parameters (from P)
var $P; // Wizard parameters, coming from TCEforms linking to the wizard.
var $TABLECFG; // The array which is constantly submitted by the multidimensional form of this wizard.
+ // table parsing
+ var $tableParsing_quote; // quoting of table cells
+ var $tableParsing_delimiter; // delimiter between table cells
* @return void
*/
function init() {
- global $BACK_PATH,$HTTP_POST_VARS;
-
// GPvars:
$this->P = t3lib_div::_GP('P');
$this->TABLECFG = t3lib_div::_GP('TABLE');
// Setting options:
$this->xmlStorage = $this->P['params']['xmlOutput'];
+ $this->numNewRows = t3lib_div::intInRange($this->P['params']['numNewRows'],1,50,5);
// Textareas or input fields:
$this->inputStyle=isset($this->TABLECFG['textFields']) ? $this->TABLECFG['textFields'] : 1;
// Document template object:
- $this->doc = t3lib_div::makeInstance('mediumDoc');
- $this->doc->docType = 'xhtml_trans';
- $this->doc->backPath = $BACK_PATH;
+ $this->doc = t3lib_div::makeInstance('template');
+ $this->doc->backPath = $GLOBALS['BACK_PATH'];
+ $this->doc->setModuleTemplate('templates/wizard_table.html');
$this->doc->JScode=$this->doc->wrapScriptTags('
function jumpToUrl(URL,formEl) { //
- document.location = URL;
+ window.location.href = URL;
}
');
list($rUri) = explode('#',t3lib_div::getIndpEnv('REQUEST_URI'));
$this->doc->form ='<form action="'.htmlspecialchars($rUri).'" method="post" name="wizardForm">';
- // Start page:
- $this->content.=$this->doc->startPage('Table');
-
// If save command found, include tcemain:
- if ($HTTP_POST_VARS['savedok_x'] || $HTTP_POST_VARS['saveandclosedok_x']) {
+ if ($_POST['savedok_x'] || $_POST['saveandclosedok_x']) {
$this->include_once[]=PATH_t3lib.'class.t3lib_tcemain.php';
}
+
+ $this->tableParsing_delimiter = '|';
+ $this->tableParsing_quote = '';
}
/**
* @return void
*/
function main() {
- global $LANG;
-
- if ($this->P['table'] && $this->P['field'] && $this->P['uid']) {
- $this->content.=$this->doc->section($LANG->getLL('table_title'),$this->tableWizard(),0,1);
+ if ($this->P['table'] && $this->P['field'] && $this->P['uid']) {
+ $this->content.= $this->doc->section($GLOBALS['LANG']->getLL('table_title'), $this->tableWizard(), 0, 1);
} else {
- $this->content.=$this->doc->section($LANG->getLL('table_title'),'<span class="typo3-red">'.$LANG->getLL('table_noData',1).'</span>',0,1);
+ $this->content.= $this->doc->section($GLOBALS['LANG']->getLL('table_title'), '<span class="typo3-red">' . $GLOBALS['LANG']->getLL('table_noData',1) . '</span>', 0, 1);
}
- $this->content.=$this->doc->endPage();
+
+ // Setting up the buttons and markers for docheader
+ $docHeaderButtons = $this->getButtons();
+ $markers['CSH'] = $docHeaderButtons['csh'];
+ $markers['CONTENT'] = $this->content;
+
+ // Build the <body> for the module
+ $this->content = $this->doc->startPage('Table');
+ $this->content.= $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $markers);
+ $this->content.= $this->doc->endPage();
+ $this->content = $this->doc->insertStylesAndJS($this->content);
}
/**
}
/**
+ * Create the panel of buttons for submitting the form or otherwise perform operations.
+ *
+ * @return array all available buttons as an assoc. array
+ */
+ protected function getButtons() {
+ $buttons = array(
+ 'csh' => '',
+ 'csh_buttons' => '',
+ 'close' => '',
+ 'save' => '',
+ 'save_close' => '',
+ 'reload' => '',
+ );
+
+ if ($this->P['table'] && $this->P['field'] && $this->P['uid']) {
+ // CSH
+ $buttons['csh'] = t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'wizard_table_wiz', $GLOBALS['BACK_PATH'], '');
+
+ // CSH Buttons
+ $buttons['csh_buttons'] = t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'wizard_table_wiz_buttons', $GLOBALS['BACK_PATH'], '');
+
+ // Close
+ $buttons['close'] = '<a href="#" onclick="' . htmlspecialchars('jumpToUrl(unescape(\'' . rawurlencode(t3lib_div::sanitizeLocalUrl($this->P['returnUrl'])) . '\')); return false;') . '">' .
+ t3lib_iconWorks::getSpriteIcon('actions-document-close', array('title' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:rm.closeDoc', TRUE))) .
+ '</a>';
+
+ // Save
+ $buttons['save'] = '<input type="image" class="c-inputButton" name="savedok"' . t3lib_iconWorks::skinImg($this->doc->backPath, 'gfx/savedok.gif') . ' title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:rm.saveDoc', 1) . '" />';
+
+ // Save & Close
+ $buttons['save_close'] = '<input type="image" class="c-inputButton" name="saveandclosedok"' . t3lib_iconWorks::skinImg($this->doc->backPath, 'gfx/saveandclosedok.gif') . ' title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:rm.saveCloseDoc', 1) . '" />';
+
+ // Reload
+ $buttons['reload'] = '<input type="image" class="c-inputButton" name="_refresh"' . t3lib_iconWorks::skinImg($this->doc->backPath, 'gfx/refresh_n.gif') . ' title="' . $GLOBALS['LANG']->getLL('forms_refresh', 1) . '" />';
+ }
+
+ return $buttons;
+ }
+
+ /**
* Draws the table wizard content
*
* @return string HTML content for the form.
function tableWizard() {
// First, check the references by selecting the record:
- $row=t3lib_BEfunc::getRecord($this->P['table'],$this->P['uid']);
+ $row = t3lib_BEfunc::getRecord($this->P['table'],$this->P['uid']);
if (!is_array($row)) {
t3lib_BEfunc::typo3PrintError ('Wizard Error','No reference to record',0);
exit;
* @access private
*/
function getConfigCode($row) {
- global $HTTP_POST_VARS;
+
+ // get delimiter settings
+ $flexForm = t3lib_div::xml2array($row['pi_flexform']);
+
+ if (is_array($flexForm)) {
+ $this->tableParsing_quote = $flexForm['data']['s_parsing']['lDEF']['tableparsing_quote']['vDEF']?chr(intval($flexForm['data']['s_parsing']['lDEF']['tableparsing_quote']['vDEF'])):'';
+ $this->tableParsing_delimiter = $flexForm['data']['s_parsing']['lDEF']['tableparsing_delimiter']['vDEF']?chr(intval($flexForm['data']['s_parsing']['lDEF']['tableparsing_delimiter']['vDEF'])):'|';
+ }
// If some data has been submitted, then construct
if (isset($this->TABLECFG['c'])) {
// Convert to string (either line based or XML):
if ($this->xmlStorage) {
// Convert the input array to XML:
- $bodyText = t3lib_div::array2xml($this->TABLECFG['c'],'',0,'T3TableWizard');
+ $bodyText = t3lib_div::array2xml_cs($this->TABLECFG['c'],'T3TableWizard');
// Setting cfgArr directly from the input:
$cfgArr = $this->TABLECFG['c'];
}
// If a save button has been pressed, then save the new field content:
- if ($HTTP_POST_VARS['savedok_x'] || $HTTP_POST_VARS['saveandclosedok_x']) {
+ if ($_POST['savedok_x'] || $_POST['saveandclosedok_x']) {
// Make TCEmain object:
$tce = t3lib_div::makeInstance('t3lib_TCEmain');
$tce->process_datamap();
// If the save/close button was pressed, then redirect the screen:
- if ($HTTP_POST_VARS['saveandclosedok_x']) {
- header('Location: '.t3lib_div::locationHeaderUrl($this->P['returnUrl']));
- exit;
+ if ($_POST['saveandclosedok_x']) {
+ t3lib_utility_Http::redirect(t3lib_div::sanitizeLocalUrl($this->P['returnUrl']));
}
}
} else { // If nothing has been submitted, load the $bodyText variable from the selected database row:
if ($this->inputStyle) {
$cells[]='<input type="text"'.$this->doc->formWidth(20).' name="TABLE[c]['.(($k+1)*2).']['.(($a+1)*2).']" value="'.htmlspecialchars($cellContent).'" />';
} else {
- $cellContent=eregi_replace('<br[ ]?[\/]?>',chr(10),$cellContent);
+ $cellContent=preg_replace('/<br[ ]?[\/]?>/i',LF,$cellContent);
$cells[]='<textarea '.$this->doc->formWidth(20).' rows="5" name="TABLE[c]['.(($k+1)*2).']['.(($a+1)*2).']">'.t3lib_div::formatForTextarea($cellContent).'</textarea>';
}
}
$ctrl.='<input type="image" name="TABLE[row_remove]['.(($k+1)*2).']"'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/garbage.gif','').$onClick.' title="'.$LANG->getLL('table_removeRow',1).'" />'.$brTag;
+// FIXME what is $tLines? See wizard_forms.php for the same.
if (($k+1)!=count($tLines)) {
$ctrl.='<input type="image" name="TABLE[row_down]['.(($k+1)*2).']"'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/pil2down.gif','').$onClick.' title="'.$LANG->getLL('table_down',1).'" />'.$brTag;
} else {
foreach($firstRow as $temp) {
$ctrl='';
if ($a!=0) {
- $ctrl.='<input type="image" name="TABLE[col_left]['.(($a+1)*2).']"'.t3lib_iconWorks::skinImg('','gfx/pil2left.gif','').' title="'.$LANG->getLL('table_left',1).'" />';
+ $ctrl.='<input type="image" name="TABLE[col_left]['.(($a+1)*2).']"'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/pil2left.gif','').' title="'.$LANG->getLL('table_left',1).'" />';
} else {
$ctrl.='<input type="image" name="TABLE[col_end]['.(($a+1)*2).']"'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/turn_left.gif','').' title="'.$LANG->getLL('table_end',1).'" />';
}
$content = '';
- // Add CSH:
- $content.= t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'wizard_table_wiz', $GLOBALS['BACK_PATH'],'');
-
// Implode all table rows into a string, wrapped in table tags.
$content.= '
'.implode('',$tRows).'
</table>';
- // Add saving buttons in the bottom:
- $content.= '
-
- <!--
- Save buttons:
- -->
- <div id="c-saveButtonPanel">';
- $content.= '<input type="image" class="c-inputButton" name="savedok"'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/savedok.gif','').' title="'.$LANG->sL('LLL:EXT:lang/locallang_core.php:rm.saveDoc',1).'" />';
- $content.= '<input type="image" class="c-inputButton" name="saveandclosedok"'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/saveandclosedok.gif','').' title="'.$LANG->sL('LLL:EXT:lang/locallang_core.php:rm.saveCloseDoc',1).'" />';
- $content.= '<a href="#" onclick="'.htmlspecialchars('jumpToUrl(unescape(\''.rawurlencode($this->P['returnUrl']).'\')); return false;').'">'.
- '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/closedok.gif','width="21" height="16"').' class="c-inputButton" title="'.$LANG->sL('LLL:EXT:lang/locallang_core.php:rm.closeDoc',1).'" alt="" />'.
- '</a>';
- $content.= '<input type="image" class="c-inputButton" name="_refresh"'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/refresh_n.gif','').' title="'.$LANG->getLL('forms_refresh',1).'" />';
- $content.= t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'wizard_table_wiz_buttons', $GLOBALS['BACK_PATH'],'');
- $content.= '
- </div>
- ';
-
// Input type checkbox:
$content.= '
<div id="c-inputMode">
'.
'<input type="hidden" name="TABLE[textFields]" value="0" />'.
- '<input type="checkbox" name="TABLE[textFields]" value="1"'.($this->inputStyle?' checked="checked"':'').' /> '.
- $LANG->getLL('table_smallFields').'
+ '<input type="checkbox" name="TABLE[textFields]" id="textFields" value="1"'.($this->inputStyle?' checked="checked"':'').' /> <label for="textFields">'.
+ $LANG->getLL('table_smallFields').'</label>
</div>
<br /><br />
unset($this->TABLECFG['c'][$kk]);
break;
case 'row_add':
- $this->TABLECFG['c'][$kk+1]=array();
+ for($a=1;$a<=$this->numNewRows;$a++) {
+ if (!isset($this->TABLECFG['c'][$kk+$a])) { // Checking if set: The point is that any new row inbetween existing rows will be true after one row is added while if rows are added in the bottom of the table there will be no existing rows to stop the addition of new rows which means it will add up to $this->numNewRows rows then.
+ $this->TABLECFG['c'][$kk+$a] = array();
+ } else {
+ break;
+ }
+ }
break;
case 'row_top':
$this->TABLECFG['c'][1]=$this->TABLECFG['c'][$kk];
ksort($this->TABLECFG['c']);
}
if (substr($cmd,0,4)=='col_') {
- reset($this->TABLECFG['c']);
- while(list($cAK)=each($this->TABLECFG['c'])) {
+ foreach ($this->TABLECFG['c'] as $cAK => $value) {
switch($cmd) {
case 'col_remove':
unset($this->TABLECFG['c'][$cAK][$kk]);
}
// Convert line breaks to <br /> tags:
- reset($this->TABLECFG['c']);
- while(list($a)=each($this->TABLECFG['c'])) {
- reset($this->TABLECFG['c'][$a]);
- while(list($b)=each($this->TABLECFG['c'][$a])) {
- $this->TABLECFG['c'][$a][$b] = str_replace(chr(10),'<br />',str_replace(chr(13),'',$this->TABLECFG['c'][$a][$b]));
+ foreach ($this->TABLECFG['c'] as $a => $value) {
+ foreach ($this->TABLECFG['c'][$a] as $b => $value2) {
+ $this->TABLECFG['c'][$a][$b] = str_replace(LF,'<br />',str_replace(CR,'',$this->TABLECFG['c'][$a][$b]));
}
}
}
$inLines=array();
// Traverse the elements of the table wizard and transform the settings into configuration code.
- reset($this->TABLECFG['c']);
- while(list($a)=each($this->TABLECFG['c'])) {
+ foreach ($this->TABLECFG['c'] as $a => $value) {
$thisLine=array();
- reset($this->TABLECFG['c'][$a]);
- while(list($b)=each($this->TABLECFG['c'][$a])) {
- $thisLine[]=str_replace('|','',$this->TABLECFG['c'][$a][$b]);
+ foreach ($this->TABLECFG['c'][$a] as $b => $value) {
+ $thisLine[]=$this->tableParsing_quote.str_replace($this->tableParsing_delimiter,'',$this->TABLECFG['c'][$a][$b]).$this->tableParsing_quote;
}
- $inLines[]=implode('|',$thisLine);
+ $inLines[]=implode($this->tableParsing_delimiter,$thisLine);
}
// Finally, implode the lines into a string:
- $bodyText = implode(chr(10),$inLines);
+ $bodyText = implode(LF,$inLines);
// Return the configuration code:
return $bodyText;
function cfgString2CfgArray($cfgStr,$cols) {
// Explode lines in the configuration code - each line is a table row.
- $tLines=explode(chr(10),$cfgStr);
+ $tLines=explode(LF,$cfgStr);
// Setting number of columns
if (!$cols && trim($tLines[0])) { // auto...
- $cols = count(explode('|',$tLines[0]));
+ $cols = count(explode($this->tableParsing_delimiter,$tLines[0]));
}
$cols=$cols?$cols:4;
foreach($tLines as $k => $v) {
// Initialize:
- $vParts = explode('|',$v);
+ $vParts = explode($this->tableParsing_delimiter,$v);
// Traverse columns:
for ($a=0;$a<$cols;$a++) {
+ if ($this->tableParsing_quote && substr($vParts[$a],0,1) == $this->tableParsing_quote && substr($vParts[$a],-1,1) == $this->tableParsing_quote) {
+ $vParts[$a] = substr(trim($vParts[$a]),1,-1);
+ }
$cfgArr[$k][$a]=$vParts[$a];
}
}
}
}
-// Include extension?
+
if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/wizard_table.php']) {
include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/wizard_table.php']);
}
-
-
-
-
-
-
-
-
-
// Make instance:
$SOBE = t3lib_div::makeInstance('SC_wizard_table');
$SOBE->init();
$SOBE->main();
$SOBE->printContent();
-?>
+
+?>
\ No newline at end of file