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 2b98af9..6e35581
@@ -2,7 +2,7 @@
 /***************************************************************
 *  Copyright notice
 *
-*  (c) 1999-2004 Kasper Skaarhoj (kasper@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 <kasper@typo3.com>
+ * @author     Kasper Skårhøj <kasperYYYY@typo3.com>
  */
 /**
  * [CLASS/FUNCTION INDEX of SCRIPT]
  *
  *
  *  175: class SC_wizard_forms
- *  202:     function init()
- *  238:     function main()
- *  254:     function printContent()
- *  263:     function formsWizard()
+ *  203:     function init()
+ *  242:     function main()
+ *  257:     function printContent()
+ *  268:     function formsWizard()
  *
  *              SECTION: Helper functions
- *  306:     function getConfigCode(&$row)
- *  378:     function getFormHTML($formCfgArray,$row)
- *  631:     function changeFunc()
- *  690:     function cfgArray2CfgString($cfgArr)
- *  765:     function cfgString2CfgArray($cfgStr)
- *  854:     function cleanT($tArr)
- *  872:     function formatCells($fArr)
+ *  311:     function getConfigCode(&$row)
+ *  382:     function getFormHTML($formCfgArray,$row)
+ *  662:     function changeFunc()
+ *  721:     function cfgArray2CfgString($cfgArr)
+ *  803:     function cfgString2CfgArray($cfgStr)
+ *  902:     function cleanT($tArr)
+ *  920:     function formatCells($fArr)
  *
  * TOTAL FUNCTIONS: 11
  * (This index is automatically created/updated by the extension "extdeveval")
@@ -63,7 +63,7 @@
 $BACK_PATH='';
 require ('init.php');
 require ('template.php');
-include ('sysext/lang/locallang_wizards.php');
+$LANG->includeLLFile('EXT:lang/locallang_wizards.xml');
 
 
 
@@ -168,14 +168,19 @@ include ('sysext/lang/locallang_wizards.php');
 /**
  * Script Class for rendering the Form Wizard
  *
- * @author     Kasper Skaarhoj <kasper@typo3.com>
+ * @author     Kasper Skårhøj <kasperYYYY@typo3.com>
  * @package TYPO3
  * @subpackage core
  */
 class SC_wizard_forms {
 
                // 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 $attachmentCounter = 0;     // Used to numerate attachments automatically.
@@ -201,8 +206,6 @@ class SC_wizard_forms {
         * @return      void
         */
        function init() {
-               global $BACK_PATH,$HTTP_POST_VARS;
-
                        // GPvars:
                $this->P = t3lib_div::_GP('P');
                $this->special = t3lib_div::_GP('special');
@@ -212,12 +215,12 @@ 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)  {       //
-                               document.location = URL;
+                               window.location.href = URL;
                        }
                ');
 
@@ -225,11 +228,8 @@ 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 ($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';
                }
        }
@@ -240,14 +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);
                }
-               $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('Form Wizard');
+               $this->content.= $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $markers);
+               $this->content.= $this->doc->endPage();
+               $this->content = $this->doc->insertStylesAndJS($this->content);
        }
 
        /**
@@ -260,6 +268,46 @@ class SC_wizard_forms {
        }
 
        /**
+        * 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.
@@ -267,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.
@@ -308,7 +355,6 @@ class SC_wizard_forms {
         * @access private
         */
        function getConfigCode(&$row)   {
-               global $HTTP_POST_VARS;
 
                        // If some data has been submitted, then construct
                if (isset($this->FORMCFG['c'])) {
@@ -319,7 +365,7 @@ class SC_wizard_forms {
                                // Convert to string (either line based or XML):
                        if ($this->xmlStorage)  {
                                        // Convert the input array to XML:
-                               $bodyText = t3lib_div::array2xml($this->FORMCFG['c'],'',0,'T3FormWizard');
+                               $bodyText = t3lib_div::array2xml_cs($this->FORMCFG['c'],'T3FormWizard');
 
                                        // Setting cfgArr directly from the input:
                                $cfgArr = $this->FORMCFG['c'];
@@ -332,7 +378,7 @@ class SC_wizard_forms {
                        }
 
                                // 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');
@@ -353,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 ($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:
@@ -424,7 +469,7 @@ class SC_wizard_forms {
                                                // Field type selector:
                                        $opt=array();
                                        $opt[]='<option value=""></option>';
-                                       $types = explode(',','input,textarea,select,check,radio,password,file,hidden,submit,property');
+                                       $types = explode(',','input,textarea,select,check,radio,password,file,hidden,submit,property,label');
                                        foreach($types as $t)   {
                                                $opt[]='
                                                                <option value="'.$t.'"'.($confData['type']==$t?' selected="selected"':'').'>'.$LANG->getLL('forms_type_'.$t,1).'</option>';
@@ -441,7 +486,7 @@ class SC_wizard_forms {
                                        }
 
                                                // Required checkbox:
-                                       if (!t3lib_div::inList('check,hidden,submit',$confData['type']))                {
+                                       if (!t3lib_div::inList('check,hidden,submit,label',$confData['type']))          {
                                                $temp_cells[$LANG->getLL('forms_required')]='<input type="checkbox" name="FORMCFG[c]['.(($k+1)*2).'][required]" value="1"'.($confData['required']?' checked="checked"':'').' title="'.$LANG->getLL('forms_required',1).'" />';
                                        }
 
@@ -456,7 +501,9 @@ class SC_wizard_forms {
                                        if ($this->special=='formtype_mail' && $confData['type']=='file')       {
                                                $confData['fieldname'] = 'attachment'.(++$this->attachmentCounter);
                                        }
-                                       $temp_cells[$LANG->getLL('forms_fieldName')]='<input type="text"'.$this->doc->formWidth(10).' name="FORMCFG[c]['.(($k+1)*2).'][fieldname]" value="'.htmlspecialchars($confData['fieldname']).'" title="'.$LANG->getLL('forms_fieldName',1).'" />';
+                                       if (!t3lib_div::inList('label',$confData['type']))      {
+                                               $temp_cells[$LANG->getLL('forms_fieldName')]='<input type="text"'.$this->doc->formWidth(10).' name="FORMCFG[c]['.(($k+1)*2).'][fieldname]" value="'.htmlspecialchars($confData['fieldname']).'" title="'.$LANG->getLL('forms_fieldName',1).'" />';
+                                       }
 
                                                // Field configuration depending on the fields type:
                                        switch((string)$confData['type'])       {
@@ -506,7 +553,7 @@ class SC_wizard_forms {
                                        $ctrl='';
                                        $onClick="document.wizardForm.action+='#ANC_".(($k+1)*2-2)."';";
                                        $onClick=' onclick="'.htmlspecialchars($onClick).'"';
-
+// FIXME $inputStyle undefined
                                        $brTag=$inputStyle?'':'<br />';
                                        if ($k!=0)      {
                                                $ctrl.='<input type="image" name="FORMCFG[row_up]['.(($k+1)*2).']"'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/pil2up.gif','').$onClick.' title="'.$LANG->getLL('table_up',1).'" />'.$brTag;
@@ -514,6 +561,7 @@ class SC_wizard_forms {
                                                $ctrl.='<input type="image" name="FORMCFG[row_bottom]['.(($k+1)*2).']"'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/turn_up.gif','').$onClick.' title="'.$LANG->getLL('table_bottom',1).'" />'.$brTag;
                                        }
                                        $ctrl.='<input type="image" name="FORMCFG[row_remove]['.(($k+1)*2).']"'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/garbage.gif','').$onClick.' title="'.$LANG->getLL('table_removeRow',1).'" />'.$brTag;
+// FIXME $tLines undefined
                                        if (($k+1)!=count($tLines))     {
                                                $ctrl.='<input type="image" name="FORMCFG[row_down]['.(($k+1)*2).']"'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/pil2down.gif','').$onClick.' title="'.$LANG->getLL('table_down',1).'" />'.$brTag;
                                        } else {
@@ -553,7 +601,9 @@ class SC_wizard_forms {
                        $tRows[]='
                                <tr>
                                        <td colspan="2" class="bgColor2">&nbsp;</td>
-                                       <td colspan="2" class="bgColor2"><strong>'.$LANG->getLL('forms_special_eform',1).':</strong></td>
+                                       <td colspan="2" class="bgColor2"><strong>'.$LANG->getLL('forms_special_eform',1).':</strong>'.
+                                               t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'wizard_forms_wiz_formmail_info', $GLOBALS['BACK_PATH'],'').
+                                               '</td>
                                </tr>';
 
                                // "FORM type":
@@ -607,8 +657,10 @@ class SC_wizard_forms {
                                </tr>';
                }
 
+               $content = '';
+
                        // Implode all table rows into a string, wrapped in table tags.
-               $content = '
+               $content.= '
 
                        <!--
                                Form wizard
@@ -617,22 +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).'" />
-                       </div>
-               ';
-
                        // Add hidden fields:
                $content.= implode('',$hiddenFields);
 
@@ -763,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']),'')) {
@@ -773,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);
        }
 
        /**
@@ -790,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:
@@ -819,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')  {
@@ -833,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]);
@@ -931,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();
@@ -956,4 +983,5 @@ foreach($SOBE->include_once as $INC_FILE)   include_once($INC_FILE);
 
 $SOBE->main();
 $SOBE->printContent();
-?>
+
+?>
\ No newline at end of file