Fixed bug #13294: IRRE deleted combo records are still validated by TBE_EDITOR (Thank...
[Packages/TYPO3.CMS.git] / typo3 / wizard_forms.php
old mode 100755 (executable)
new mode 100644 (file)
index 5f1ae17..6e35581
@@ -2,7 +2,7 @@
 /***************************************************************
 *  Copyright notice
 *
-*  (c) 1999-2008 Kasper Skaarhoj (kasperYYYY@typo3.com)
+*  (c) 1999-2010 Kasper Skårhøj (kasperYYYY@typo3.com)
 *  All rights reserved
 *
 *  This script is part of the TYPO3 project. The TYPO3 project is
  * Wizard to help make forms (fx. for tt_content elements) of type 'form'.
  *
  * $Id$
- * Revised for TYPO3 3.6 November/2003 by Kasper Skaarhoj
+ * Revised for TYPO3 3.6 November/2003 by Kasper Skårhøj
  * XHTML compliant
  *
- * @author     Kasper Skaarhoj <kasperYYYY@typo3.com>
+ * @author     Kasper Skårhøj <kasperYYYY@typo3.com>
  */
 /**
  * [CLASS/FUNCTION INDEX of SCRIPT]
@@ -168,7 +168,7 @@ $LANG->includeLLFile('EXT:lang/locallang_wizards.xml');
 /**
  * Script Class for rendering the Form Wizard
  *
- * @author     Kasper Skaarhoj <kasperYYYY@typo3.com>
+ * @author     Kasper Skårhøj <kasperYYYY@typo3.com>
  * @package TYPO3
  * @subpackage core
  */
@@ -206,8 +206,6 @@ class SC_wizard_forms {
         * @return      void
         */
        function init() {
-               global $BACK_PATH;
-
                        // GPvars:
                $this->P = t3lib_div::_GP('P');
                $this->special = t3lib_div::_GP('special');
@@ -217,9 +215,9 @@ class SC_wizard_forms {
                $this->xmlStorage = $this->P['params']['xmlOutput'];
 
                        // 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_forms.html');
                $this->doc->JScode=$this->doc->wrapScriptTags('
                        function jumpToUrl(URL,formEl)  {       //
                                window.location.href = URL;
@@ -230,9 +228,6 @@ class SC_wizard_forms {
                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('Form Wizard');
-
                        // If save command found, include tcemain:
                if ($_POST['savedok_x'] || $_POST['saveandclosedok_x']) {
                        $this->include_once[]=PATH_t3lib.'class.t3lib_tcemain.php';
@@ -245,13 +240,22 @@ class SC_wizard_forms {
         * @return      void
         */
        function main() {
-               global $LANG;
-
                if ($this->P['table'] && $this->P['field'] && $this->P['uid'])  {
-                       $this->content.=$this->doc->section($LANG->getLL('forms_title'),$this->formsWizard(),0,1);
+                       $this->content .= $this->doc->section($GLOBALS['LANG']->getLL('forms_title'), $this->formsWizard(), 0, 1);
                } else {
-                       $this->content.=$this->doc->section($LANG->getLL('forms_title'),'<span class="typo3-red">'.$LANG->getLL('table_noData',1).'</span>',0,1);
+                       $this->content .= $this->doc->section($GLOBALS['LANG']->getLL('forms_title'), '<span class="typo3-red">' . $GLOBALS['LANG']->getLL('table_noData',1) . '</span>', 0, 1);
                }
+
+               // 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('Form Wizard');
+               $this->content.= $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $markers);
+               $this->content.= $this->doc->endPage();
+               $this->content = $this->doc->insertStylesAndJS($this->content);
        }
 
        /**
@@ -260,12 +264,50 @@ class SC_wizard_forms {
         * @return      void
         */
        function printContent() {
-               $this->content.= $this->doc->endPage();
-               $this->content = $this->doc->insertStylesAndJS($this->content);
                echo $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_forms_wiz', $GLOBALS['BACK_PATH'], '');
+
+                       // CSH Buttons
+                       $buttons['csh_buttons'] = t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'wizard_forms_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('', 'gfx/refresh_n.gif') . ' title="' . $GLOBALS['LANG']->getLL('forms_refresh', 1) . '" />';
+               }
+
+               return $buttons;
+       }
+
+       /**
         * Draws the form wizard content
         *
         * @return      string          HTML content for the form.
@@ -273,10 +315,9 @@ class SC_wizard_forms {
        function formsWizard()  {
 
                        // First, check the references by selecting the record:
-               $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;
+               $row = t3lib_BEfunc::getRecord($this->P['table'],$this->P['uid']);
+               if (!is_array($row)) {
+                       throw new RuntimeException('Wizard Error: No reference to record');
                }
 
                        // This will get the content of the form configuration code field to us - possibly cleaned up, saved to database etc. if the form has been submitted in the meantime.
@@ -358,9 +399,8 @@ class SC_wizard_forms {
                                $row = t3lib_BEfunc::getRecord($this->P['table'],$this->P['uid']);
 
                                        // If the save/close button was pressed, then redirect the screen:
-                               if ($_POST['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:
@@ -619,9 +659,6 @@ class SC_wizard_forms {
 
                $content = '';
 
-                       // Add CSH:
-               $content.= t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'wizard_forms_wiz', $GLOBALS['BACK_PATH'],'');
-
                        // Implode all table rows into a string, wrapped in table tags.
                $content.= '
 
@@ -632,25 +669,6 @@ class SC_wizard_forms {
                                '.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('','gfx/refresh_n.gif','').' title="'.$LANG->getLL('forms_refresh',1).'" />';
-                       // Add CSH:
-               $content.= t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'wizard_forms_wiz_buttons', $GLOBALS['BACK_PATH'],'');
-               $content.= '
-                       </div>
-               ';
-
                        // Add hidden fields:
                $content.= implode('',$hiddenFields);
 
@@ -781,7 +799,7 @@ class SC_wizard_forms {
 
                                                // Default:
                                        if ($vv['type']=='select' || $vv['type']=='radio')      {
-                                               $thisLine[2]=str_replace(chr(10),', ',str_replace(',','',$vv['options']));
+                                               $thisLine[2]=str_replace(LF,', ',str_replace(',','',$vv['options']));
                                        } elseif ($vv['type']=='check') {
                                                if ($vv['default'])     $thisLine[2]=1;
                                        } elseif (strcmp(trim($vv['default']),'')) {
@@ -791,11 +809,11 @@ class SC_wizard_forms {
                                }
 
                                        // Compile the final line:
-                               $inLines[]=ereg_replace("[\n\r]*",'',implode(' | ',$thisLine));
+                               $inLines[]=preg_replace("/[\n\r]*/",'',implode(' | ',$thisLine));
                        }
                }
                        // Finally, implode the lines into a string, and return it:
-               return implode(chr(10),$inLines);
+               return implode(LF,$inLines);
        }
 
        /**
@@ -808,7 +826,7 @@ class SC_wizard_forms {
        function cfgString2CfgArray($cfgStr)    {
 
                        // Traverse the number of form elements:
-               $tLines=explode(chr(10),$cfgStr);
+               $tLines=explode(LF,$cfgStr);
                foreach($tLines as $k => $v)    {
 
                                // Initialize:
@@ -837,7 +855,7 @@ class SC_wizard_forms {
 
                                if ($confData['type'])  {
                                        if (count($typeParts)==1)       {
-                                               $confData['fieldname'] = substr(ereg_replace('[^a-zA-Z0-9_]','',str_replace(' ','_',trim($parts[0]))),0,30);
+                                               $confData['fieldname'] = substr(preg_replace('/[^a-zA-Z0-9_]/','',str_replace(' ','_',trim($parts[0]))),0,30);
 
                                                        // Attachment names...
                                                if ($confData['type']=='file')  {
@@ -851,7 +869,7 @@ class SC_wizard_forms {
                                        switch((string)$confData['type'])       {
                                                case 'select':
                                                case 'radio':
-                                                       $confData['default'] = implode(chr(10),t3lib_div::trimExplode(',',$parts[2]));
+                                                       $confData['default'] = implode(LF,t3lib_div::trimExplode(',',$parts[2]));
                                                break;
                                                default:
                                                        $confData['default'] = trim($parts[2]);
@@ -949,22 +967,13 @@ class SC_wizard_forms {
        }
 }
 
-// Include extension?
+
 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/wizard_forms.php']) {
        include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/wizard_forms.php']);
 }
 
 
 
-
-
-
-
-
-
-
-
-
 // Make instance:
 $SOBE = t3lib_div::makeInstance('SC_wizard_forms');
 $SOBE->init();
@@ -974,4 +983,5 @@ foreach($SOBE->include_once as $INC_FILE)   include_once($INC_FILE);
 
 $SOBE->main();
 $SOBE->printContent();
-?>
+
+?>
\ No newline at end of file