Cleanup: Updated copyright notices
[Packages/TYPO3.CMS.git] / typo3 / wizard_forms.php
index 9073ad3..97ad8d7 100755 (executable)
@@ -2,7 +2,7 @@
 /***************************************************************
 *  Copyright notice
 *
-*  (c) 1999-2004 Kasper Skaarhoj (kasper@typo3.com)
+*  (c) 1999-2009 Kasper Skaarhoj (kasperYYYY@typo3.com)
 *  All rights reserved
 *
 *  This script is part of the TYPO3 project. The TYPO3 project is
@@ -31,7 +31,7 @@
  * 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]
  *
  *
  *  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 Skaarhoj <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($this->P['returnUrl']) . '\')); return false;') . '">' .
+                               '<img' . t3lib_iconWorks::skinImg($this->doc->backPath, 'gfx/closedok.gif') . ' class="c-inputButton" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:rm.closeDoc', 1) . '" alt="" />' .
+                               '</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,7 +315,7 @@ class SC_wizard_forms {
        function formsWizard()  {
 
                        // 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;
@@ -308,7 +356,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 +366,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 +379,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,7 +400,7 @@ 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'])       {
+                               if ($_POST['saveandclosedok_x'])        {
                                        header('Location: '.t3lib_div::locationHeaderUrl($this->P['returnUrl']));
                                        exit;
                                }
@@ -424,7 +471,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');
+                                       $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 +488,7 @@ class SC_wizard_forms {
                                        }
 
                                                // Required checkbox:
-                                       if (!t3lib_div::inList(',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 +503,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'])       {
@@ -480,6 +529,17 @@ class SC_wizard_forms {
                                                break;
                                        }
 
+                                               // Field configuration depending on the fields type:
+                                       switch((string)$confData['type'])       {
+                                               case 'textarea':
+                                               case 'input':
+                                               case 'password':
+                                                       if (strlen(trim($confData['specialEval'])))     {
+                                                               $hiddenFields[] = '<input type="hidden" name="FORMCFG[c]['.(($k+1)*2).'][specialEval]" value="'.htmlspecialchars($confData['specialEval']).'" />';
+                                                       }
+                                               break;
+                                       }
+
                                                // Default data
                                        if ($confData['type']=='select' || $confData['type']=='radio')  {
                                                $temp_cells[$LANG->getLL('forms_options')]='<textarea '.$this->doc->formWidthText(15).' rows="4" name="FORMCFG[c]['.(($k+1)*2).'][options]" title="'.$LANG->getLL('forms_options',1).'">'.t3lib_div::formatForTextarea($confData['default']).'</textarea>';
@@ -495,7 +555,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;
@@ -503,6 +563,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 {
@@ -542,7 +603,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":
@@ -596,8 +659,10 @@ class SC_wizard_forms {
                                </tr>';
                }
 
+               $content = '';
+
                        // Implode all table rows into a string, wrapped in table tags.
-               $content = '
+               $content.= '
 
                        <!--
                                Form wizard
@@ -606,22 +671,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);
 
@@ -722,11 +771,19 @@ class SC_wizard_forms {
                                                        if (intval($vv['cols']))        $tArr[0]=intval($vv['cols']);
                                                        if (intval($vv['rows']))        $tArr[1]=intval($vv['rows']);
                                                        if (trim($vv['extra']))         $tArr[2]=trim($vv['extra']);
+                                                       if (strlen($vv['specialEval'])) {
+                                                               $thisLine[2] = '';      // Preset blank default value so position 3 can get a value...
+                                                               $thisLine[3] = $vv['specialEval'];
+                                                       }
                                                break;
                                                case 'input':
                                                case 'password':
                                                        if (intval($vv['size']))        $tArr[0]=intval($vv['size']);
                                                        if (intval($vv['max']))         $tArr[1]=intval($vv['max']);
+                                                       if (strlen($vv['specialEval'])) {
+                                                               $thisLine[2] = '';      // Preset blank default value so position 3 can get a value...
+                                                               $thisLine[3] = $vv['specialEval'];
+                                                       }
                                                break;
                                                case 'file':
                                                        if (intval($vv['size']))        $tArr[0]=intval($vv['size']);
@@ -757,7 +814,6 @@ class SC_wizard_forms {
                                $inLines[]=ereg_replace("[\n\r]*",'',implode(' | ',$thisLine));
                        }
                }
-
                        // Finally, implode the lines into a string, and return it:
                return implode(chr(10),$inLines);
        }
@@ -828,11 +884,13 @@ class SC_wizard_forms {
                                                        $confData['cols'] = $fParts[1];
                                                        $confData['rows'] = $fParts[2];
                                                        $confData['extra'] = strtoupper($fParts[3])=='OFF' ? 'OFF' : '';
+                                                       $confData['specialEval'] = trim($parts[3]);
                                                break;
                                                case 'input':
                                                case 'password':
                                                        $confData['size'] = $fParts[1];
                                                        $confData['max'] = $fParts[2];
+                                                       $confData['specialEval'] = trim($parts[3]);
                                                break;
                                                case 'file':
                                                        $confData['size'] = $fParts[1];
@@ -911,22 +969,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();
@@ -936,4 +985,5 @@ foreach($SOBE->include_once as $INC_FILE)   include_once($INC_FILE);
 
 $SOBE->main();
 $SOBE->printContent();
-?>
+
+?>
\ No newline at end of file