"TYPO3 4.0.1: typo3_src-4.0.1/typo3/wizard_forms.php Source File", "datetime" => "Sat Dec 2 19:22:35 2006", "date" => "2 Dec 2006", "doxygenversion" => "1.4.6", "projectname" => "TYPO3 4.0.1", "projectnumber" => "4.0.1" ); get_header($doxygen_vars); ?>

wizard_forms.php

00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 1999-2005 Kasper Skaarhoj (kasperYYYY@typo3.com)
00006 *  All rights reserved
00007 *
00008 *  This script is part of the TYPO3 project. The TYPO3 project is
00009 *  free software; you can redistribute it and/or modify
00010 *  it under the terms of the GNU General Public License as published by
00011 *  the Free Software Foundation; either version 2 of the License, or
00012 *  (at your option) any later version.
00013 *
00014 *  The GNU General Public License can be found at
00015 *  http://www.gnu.org/copyleft/gpl.html.
00016 *  A copy is found in the textfile GPL.txt and important notices to the license
00017 *  from the author is found in LICENSE.txt distributed with these scripts.
00018 *
00019 *
00020 *  This script is distributed in the hope that it will be useful,
00021 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00022 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023 *  GNU General Public License for more details.
00024 *
00025 *  This copyright notice MUST APPEAR in all copies of the script!
00026 ***************************************************************/
00063 $BACK_PATH='';
00064 require ('init.php');
00065 require ('template.php');
00066 $LANG->includeLLFile('EXT:lang/locallang_wizards.xml');
00067 
00068 
00069 
00070 
00071 
00072 
00073 
00074 
00075 
00076 
00077 
00078 
00175 class SC_wizard_forms {
00176 
00177                 // Internal, dynamic:
00178         var $doc;                                       // Document template object
00179         var $content;                           // Content accumulation for the module.
00180         var $include_once=array();      // List of files to include.
00181         var $attachmentCounter = 0;     // Used to numerate attachments automatically.
00182 
00183 
00184                 // Internal, static:
00185         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!
00186 
00187 
00188                 // Internal, static: GPvars
00189         var $P;                                         // Wizard parameters, coming from TCEforms linking to the wizard.
00190         var $FORMCFG;                           // The array which is constantly submitted by the multidimensional form of this wizard.
00191         var $special;                           // Indicates if the form is of a dedicated type, like "formtype_mail" (for tt_content element "Form")
00192 
00193 
00194 
00195 
00196 
00197 
00203         function init() {
00204                 global $BACK_PATH;
00205 
00206                         // GPvars:
00207                 $this->P = t3lib_div::_GP('P');
00208                 $this->special = t3lib_div::_GP('special');
00209                 $this->FORMCFG = t3lib_div::_GP('FORMCFG');
00210 
00211                         // Setting options:
00212                 $this->xmlStorage = $this->P['params']['xmlOutput'];
00213 
00214                         // Document template object:
00215                 $this->doc = t3lib_div::makeInstance('mediumDoc');
00216                 $this->doc->docType = 'xhtml_trans';
00217                 $this->doc->backPath = $BACK_PATH;
00218                 $this->doc->JScode=$this->doc->wrapScriptTags('
00219                         function jumpToUrl(URL,formEl)  {       //
00220                                 window.location.href = URL;
00221                         }
00222                 ');
00223 
00224                         // Setting form tag:
00225                 list($rUri) = explode('#',t3lib_div::getIndpEnv('REQUEST_URI'));
00226                 $this->doc->form ='<form action="'.htmlspecialchars($rUri).'" method="post" name="wizardForm">';
00227 
00228                         // Start page:
00229                 $this->content=$this->doc->startPage('Form Wizard');
00230 
00231                         // If save command found, include tcemain:
00232                 if ($_POST['savedok_x'] || $_POST['saveandclosedok_x']) {
00233                         $this->include_once[]=PATH_t3lib.'class.t3lib_tcemain.php';
00234                 }
00235         }
00236 
00242         function main() {
00243                 global $LANG;
00244 
00245                 if ($this->P['table'] && $this->P['field'] && $this->P['uid'])  {
00246                         $this->content.=$this->doc->section($LANG->getLL('forms_title'),$this->formsWizard(),0,1);
00247                 } else {
00248                         $this->content.=$this->doc->section($LANG->getLL('forms_title'),'<span class="typo3-red">'.$LANG->getLL('table_noData',1).'</span>',0,1);
00249                 }
00250         }
00251 
00257         function printContent() {
00258                 $this->content.= $this->doc->endPage();
00259                 $this->content = $this->doc->insertStylesAndJS($this->content);
00260                 echo $this->content;
00261         }
00262 
00268         function formsWizard()  {
00269 
00270                         // First, check the references by selecting the record:
00271                 $row = t3lib_BEfunc::getRecord($this->P['table'],$this->P['uid']);
00272                 if (!is_array($row))    {
00273                         t3lib_BEfunc::typo3PrintError ('Wizard Error','No reference to record',0);
00274                         exit;
00275                 }
00276 
00277                         // 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.
00278                 $formCfgArray = $this->getConfigCode($row);
00279 
00280                         // Generation of the Form Wizards HTML code:
00281                 $content = $this->getFormHTML($formCfgArray,$row);
00282 
00283                         // Return content:
00284                 return $content;
00285         }
00286 
00287 
00288 
00289 
00290 
00291 
00292 
00293 
00294 
00295 
00296 
00297         /****************************
00298          *
00299          * Helper functions
00300          *
00301          ***************************/
00302 
00311         function getConfigCode(&$row)   {
00312 
00313                         // If some data has been submitted, then construct
00314                 if (isset($this->FORMCFG['c'])) {
00315 
00316                                 // Process incoming:
00317                         $this->changeFunc();
00318 
00319                                 // Convert to string (either line based or XML):
00320                         if ($this->xmlStorage)  {
00321                                         // Convert the input array to XML:
00322                                 $bodyText = t3lib_div::array2xml_cs($this->FORMCFG['c'],'T3FormWizard');
00323 
00324                                         // Setting cfgArr directly from the input:
00325                                 $cfgArr = $this->FORMCFG['c'];
00326                         } else {
00327                                         // Convert the input array to a string of configuration code:
00328                                 $bodyText = $this->cfgArray2CfgString($this->FORMCFG['c']);
00329 
00330                                         // Create cfgArr from the string based configuration - that way it is cleaned up and any incompatibilities will be removed!
00331                                 $cfgArr = $this->cfgString2CfgArray($bodyText);
00332                         }
00333 
00334                                 // If a save button has been pressed, then save the new field content:
00335                         if ($_POST['savedok_x'] || $_POST['saveandclosedok_x']) {
00336 
00337                                         // Make TCEmain object:
00338                                 $tce = t3lib_div::makeInstance('t3lib_TCEmain');
00339                                 $tce->stripslashes_values=0;
00340 
00341                                         // Put content into the data array:
00342                                 $data=array();
00343                                 $data[$this->P['table']][$this->P['uid']][$this->P['field']]=$bodyText;
00344                                 if ($this->special=='formtype_mail')    {
00345                                         $data[$this->P['table']][$this->P['uid']]['subheader']=$this->FORMCFG['recipient'];
00346                                 }
00347 
00348                                         // Perform the update:
00349                                 $tce->start($data,array());
00350                                 $tce->process_datamap();
00351 
00352                                         // Re-load the record content:
00353                                 $row = t3lib_BEfunc::getRecord($this->P['table'],$this->P['uid']);
00354 
00355                                         // If the save/close button was pressed, then redirect the screen:
00356                                 if ($_POST['saveandclosedok_x'])        {
00357                                         header('Location: '.t3lib_div::locationHeaderUrl($this->P['returnUrl']));
00358                                         exit;
00359                                 }
00360                         }
00361                 } else {        // If nothing has been submitted, load the $bodyText variable from the selected database row:
00362                         if ($this->xmlStorage)  {
00363                                 $cfgArr = t3lib_div::xml2array($row[$this->P['field']]);
00364                         } else {        // Regular linebased form configuration:
00365                                 $cfgArr = $this->cfgString2CfgArray($row[$this->P['field']]);
00366                         }
00367                         $cfgArr = is_array($cfgArr) ? $cfgArr : array();
00368                 }
00369 
00370                         // Return configuration code:
00371                 return $cfgArr;
00372         }
00373 
00382         function getFormHTML($formCfgArray,$row)        {
00383                 global $LANG;
00384 
00385                         // Initialize variables:
00386                 $specParts=array();
00387                 $hiddenFields=array();
00388                 $tRows=array();
00389 
00390                         // Set header row:
00391                 $cells=array($LANG->getLL('forms_preview',1).':',
00392                                                 $LANG->getLL('forms_element',1).':',
00393                                                 $LANG->getLL('forms_config',1).':',
00394                 );
00395                 $tRows[]='
00396                         <tr class="bgColor2" id="typo3-formWizardHeader">
00397                                 <td>&nbsp;</td>
00398                                 <td>'.implode('</td>
00399                                 <td>',$cells).'</td>
00400                         </tr>';
00401 
00402                         // Traverse the number of form elements:
00403                 $k=0;
00404                 foreach($formCfgArray as $confData)     {
00405 
00406                                 // Initialize:
00407                         $cells=array();
00408 
00409                                 // If there is a configuration line which is active, then render it:
00410                         if (!isset($confData['comment'])) {
00411 
00412                                         // Special parts:
00413                                 if ($this->special=='formtype_mail' && t3lib_div::inList('formtype_mail,subject,html_enabled',$confData['fieldname']))  {
00414                                         $specParts[$confData['fieldname']] = $confData['default'];
00415                                 } else {
00416 
00417                                                 // Render title/field preview COLUMN
00418                                         $cells[]=$confData['type']!='hidden' ? '<strong>'.htmlspecialchars($confData['label']).'</strong>' : '';
00419 
00420 
00421                                                 // Render general type/title COLUMN:
00422                                         $temp_cells=array();
00423 
00424                                                 // Field type selector:
00425                                         $opt=array();
00426                                         $opt[]='<option value=""></option>';
00427                                         $types = explode(',','input,textarea,select,check,radio,password,file,hidden,submit,property,label');
00428                                         foreach($types as $t)   {
00429                                                 $opt[]='
00430                                                                 <option value="'.$t.'"'.($confData['type']==$t?' selected="selected"':'').'>'.$LANG->getLL('forms_type_'.$t,1).'</option>';
00431                                         }
00432                                         $temp_cells[$LANG->getLL('forms_type')]='
00433                                                         <select name="FORMCFG[c]['.(($k+1)*2).'][type]">
00434                                                                 '.implode('
00435                                                                 ',$opt).'
00436                                                         </select>';
00437 
00438                                                 // Title field:
00439                                         if (!t3lib_div::inList('hidden,submit',$confData['type']))      {
00440                                                 $temp_cells[$LANG->getLL('forms_label')]='<input type="text"'.$this->doc->formWidth(15).' name="FORMCFG[c]['.(($k+1)*2).'][label]" value="'.htmlspecialchars($confData['label']).'" />';
00441                                         }
00442 
00443                                                 // Required checkbox:
00444                                         if (!t3lib_div::inList('check,hidden,submit,label',$confData['type']))          {
00445                                                 $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).'" />';
00446                                         }
00447 
00448                                                 // Put sub-items together into table cell:
00449                                         $cells[]=$this->formatCells($temp_cells);
00450 
00451 
00452                                                 // Render specific field configuration COLUMN:
00453                                         $temp_cells=array();
00454 
00455                                                 // Fieldname
00456                                         if ($this->special=='formtype_mail' && $confData['type']=='file')       {
00457                                                 $confData['fieldname'] = 'attachment'.(++$this->attachmentCounter);
00458                                         }
00459                                         if (!t3lib_div::inList('label',$confData['type']))      {
00460                                                 $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).'" />';
00461                                         }
00462 
00463                                                 // Field configuration depending on the fields type:
00464                                         switch((string)$confData['type'])       {
00465                                                 case 'textarea':
00466                                                         $temp_cells[$LANG->getLL('forms_cols')]='<input type="text"'.$this->doc->formWidth(5).' name="FORMCFG[c]['.(($k+1)*2).'][cols]" value="'.htmlspecialchars($confData['cols']).'" title="'.$LANG->getLL('forms_cols',1).'" />';
00467                                                         $temp_cells[$LANG->getLL('forms_rows')]='<input type="text"'.$this->doc->formWidth(5).' name="FORMCFG[c]['.(($k+1)*2).'][rows]" value="'.htmlspecialchars($confData['rows']).'" title="'.$LANG->getLL('forms_rows',1).'" />';
00468                                                         $temp_cells[$LANG->getLL('forms_extra')]='<input type="checkbox" name="FORMCFG[c]['.(($k+1)*2).'][extra]" value="OFF"'.($confData['extra']=='OFF'?' checked="checked"':'').' title="'.$LANG->getLL('forms_extra',1).'" />';
00469                                                 break;
00470                                                 case 'input':
00471                                                 case 'password':
00472                                                         $temp_cells[$LANG->getLL('forms_size')]='<input type="text"'.$this->doc->formWidth(5).' name="FORMCFG[c]['.(($k+1)*2).'][size]" value="'.htmlspecialchars($confData['size']).'" title="'.$LANG->getLL('forms_size',1).'" />';
00473                                                         $temp_cells[$LANG->getLL('forms_max')]='<input type="text"'.$this->doc->formWidth(5).' name="FORMCFG[c]['.(($k+1)*2).'][max]" value="'.htmlspecialchars($confData['max']).'" title="'.$LANG->getLL('forms_max',1).'" />';
00474                                                 break;
00475                                                 case 'file':
00476                                                         $temp_cells[$LANG->getLL('forms_size')]='<input type="text"'.$this->doc->formWidth(5).' name="FORMCFG[c]['.(($k+1)*2).'][size]" value="'.htmlspecialchars($confData['size']).'" title="'.$LANG->getLL('forms_size',1).'" />';
00477                                                 break;
00478                                                 case 'select':
00479                                                         $temp_cells[$LANG->getLL('forms_size')]='<input type="text"'.$this->doc->formWidth(5).' name="FORMCFG[c]['.(($k+1)*2).'][size]" value="'.htmlspecialchars($confData['size']).'" title="'.$LANG->getLL('forms_size',1).'" />';
00480                                                         $temp_cells[$LANG->getLL('forms_autosize')]='<input type="checkbox" name="FORMCFG[c]['.(($k+1)*2).'][autosize]" value="1"'.($confData['autosize']?' checked="checked"':'').' title="'.$LANG->getLL('forms_autosize',1).'" />';
00481                                                         $temp_cells[$LANG->getLL('forms_multiple')]='<input type="checkbox" name="FORMCFG[c]['.(($k+1)*2).'][multiple]" value="1"'.($confData['multiple']?' checked="checked"':'').' title="'.$LANG->getLL('forms_multiple',1).'" />';
00482                                                 break;
00483                                         }
00484 
00485                                                 // Field configuration depending on the fields type:
00486                                         switch((string)$confData['type'])       {
00487                                                 case 'textarea':
00488                                                 case 'input':
00489                                                 case 'password':
00490                                                         if (strlen(trim($confData['specialEval'])))     {
00491                                                                 $hiddenFields[] = '<input type="hidden" name="FORMCFG[c]['.(($k+1)*2).'][specialEval]" value="'.htmlspecialchars($confData['specialEval']).'" />';
00492                                                         }
00493                                                 break;
00494                                         }
00495 
00496                                                 // Default data
00497                                         if ($confData['type']=='select' || $confData['type']=='radio')  {
00498                                                 $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>';
00499                                         } elseif ($confData['type']=='check')   {
00500                                                 $temp_cells[$LANG->getLL('forms_checked')]='<input type="checkbox" name="FORMCFG[c]['.(($k+1)*2).'][default]" value="1"'.(trim($confData['default'])?' checked="checked"':'').' title="'.$LANG->getLL('forms_checked',1).'" />';
00501                                         } elseif ($confData['type'] && $confData['type']!='file') {
00502                                                 $temp_cells[$LANG->getLL('forms_default')]='<input type="text"'.$this->doc->formWidth(15).' name="FORMCFG[c]['.(($k+1)*2).'][default]" value="'.htmlspecialchars($confData['default']).'" title="'.$LANG->getLL('forms_default',1).'" />';
00503                                         }
00504 
00505                                         $cells[]=$confData['type']?$this->formatCells($temp_cells):'';
00506 
00507                                                 // CTRL panel for an item (move up/down/around):
00508                                         $ctrl='';
00509                                         $onClick="document.wizardForm.action+='#ANC_".(($k+1)*2-2)."';";
00510                                         $onClick=' onclick="'.htmlspecialchars($onClick).'"';
00511 // FIXME $inputStyle undefined
00512                                         $brTag=$inputStyle?'':'<br />';
00513                                         if ($k!=0)      {
00514                                                 $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;
00515                                         } else {
00516                                                 $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;
00517                                         }
00518                                         $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;
00519 // FIXME $tLines undefined
00520                                         if (($k+1)!=count($tLines))     {
00521                                                 $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;
00522                                         } else {
00523                                                 $ctrl.='<input type="image" name="FORMCFG[row_top]['.(($k+1)*2).']"'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/turn_down.gif','').$onClick.' title="'.$LANG->getLL('table_top',1).'" />'.$brTag;
00524                                         }
00525                                         $ctrl.='<input type="image" name="FORMCFG[row_add]['.(($k+1)*2).']"'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/add.gif','').$onClick.' title="'.$LANG->getLL('table_addRow',1).'" />'.$brTag;
00526 
00527                                         $ctrl='<span class="c-wizButtonsV">'.$ctrl.'</span>';
00528 
00529                                                 // Finally, put together the full row from the generated content above:
00530                                         $bgC = $confData['type']?' class="bgColor5"':'';
00531                                         $tRows[]='
00532                                                 <tr'.$bgC.'>
00533                                                         <td><a name="ANC_'.(($k+1)*2).'"></a>'.$ctrl.'</td>
00534                                                         <td class="bgColor4">'.implode('</td>
00535                                                         <td valign="top">',$cells).'</td>
00536                                                 </tr>';
00537                                 }
00538                         } else {
00539                                 $hiddenFields[]='<input type="hidden" name="FORMCFG[c]['.(($k+1)*2).'][comment]" value="'.htmlspecialchars($confData['comment']).'" />';
00540                         }
00541 
00542                                 // Increment counter:
00543                         $k++;
00544                 }
00545 
00546                         // If the form is of the special type "formtype_mail" (used for tt_content elements):
00547                 if ($this->special=='formtype_mail')    {
00548 
00549                                 // Blank spacer:
00550                         $tRows[]='
00551                                 <tr>
00552                                         <td colspan="4">&nbsp;</td>
00553                                 </tr>';
00554 
00555                                 // Header:
00556                         $tRows[]='
00557                                 <tr>
00558                                         <td colspan="2" class="bgColor2">&nbsp;</td>
00559                                         <td colspan="2" class="bgColor2"><strong>'.$LANG->getLL('forms_special_eform',1).':</strong>'.
00560                                                 t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'wizard_forms_wiz_formmail_info', $GLOBALS['BACK_PATH'],'').
00561                                                 '</td>
00562                                 </tr>';
00563 
00564                                 // "FORM type":
00565                         $tRows[]='
00566                                 <tr class="bgColor5">
00567                                         <td>&nbsp;</td>
00568                                         <td class="bgColor4">&nbsp;</td>
00569                                         <td>'.$LANG->getLL('forms_eform_formtype_mail',1).':</td>
00570                                         <td>
00571                                                 <input type="hidden" name="FORMCFG[c]['.(1000*2).'][fieldname]" value="formtype_mail" />
00572                                                 <input type="hidden" name="FORMCFG[c]['.(1000*2).'][type]" value="submit" />
00573                                                 <input type="text"'.$this->doc->formWidth(15).' name="FORMCFG[c]['.(1000*2).'][default]" value="'.htmlspecialchars($specParts['formtype_mail']).'" />
00574                                         </td>
00575                                 </tr>';
00576 
00577                                 // "Send HTML mail":
00578                         $tRows[]='
00579                                 <tr class="bgColor5">
00580                                         <td>&nbsp;</td>
00581                                         <td class="bgColor4">&nbsp;</td>
00582                                         <td>'.$LANG->getLL('forms_eform_html_enabled',1).':</td>
00583                                         <td>
00584                                                 <input type="hidden" name="FORMCFG[c]['.(1001*2).'][fieldname]" value="html_enabled" />
00585                                                 <input type="hidden" name="FORMCFG[c]['.(1001*2).'][type]" value="hidden" />
00586                                                 <input type="checkbox" name="FORMCFG[c]['.(1001*2).'][default]" value="1"'.($specParts['html_enabled']?' checked="checked"':'').' />
00587                                         </td>
00588                                 </tr>';
00589 
00590                                 // "Subject":
00591                         $tRows[]='
00592                                 <tr class="bgColor5">
00593                                         <td>&nbsp;</td>
00594                                         <td class="bgColor4">&nbsp;</td>
00595                                         <td>'.$LANG->getLL('forms_eform_subject',1).':</td>
00596                                         <td>
00597                                                 <input type="hidden" name="FORMCFG[c]['.(1002*2).'][fieldname]" value="subject" />
00598                                                 <input type="hidden" name="FORMCFG[c]['.(1002*2).'][type]" value="hidden" />
00599                                                 <input type="text"'.$this->doc->formWidth(15).' name="FORMCFG[c]['.(1002*2).'][default]" value="'.htmlspecialchars($specParts['subject']).'" />
00600                                         </td>
00601                                 </tr>';
00602 
00603                                 // Recipient:
00604                         $tRows[]='
00605                                 <tr class="bgColor5">
00606                                         <td>&nbsp;</td>
00607                                         <td class="bgColor4">&nbsp;</td>
00608                                         <td>'.$LANG->getLL('forms_eform_recipient',1).':</td>
00609                                         <td>
00610                                                 <input type="text"'.$this->doc->formWidth(15).' name="FORMCFG[recipient]" value="'.htmlspecialchars($row['subheader']).'" />
00611                                         </td>
00612                                 </tr>';
00613                 }
00614 
00615                 $content = '';
00616 
00617                         // Add CSH:
00618                 $content.= t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'wizard_forms_wiz', $GLOBALS['BACK_PATH'],'');
00619 
00620                         // Implode all table rows into a string, wrapped in table tags.
00621                 $content.= '
00622 
00623                         <!--
00624                                 Form wizard
00625                         -->
00626                         <table border="0" cellpadding="1" cellspacing="1" id="typo3-formwizard">
00627                                 '.implode('',$tRows).'
00628                         </table>';
00629 
00630                         // Add saving buttons in the bottom:
00631                 $content.= '
00632 
00633                         <!--
00634                                 Save buttons:
00635                         -->
00636                         <div id="c-saveButtonPanel">';
00637                 $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).'" />';
00638                 $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).'" />';
00639                 $content.= '<a href="#" onclick="'.htmlspecialchars('jumpToUrl(unescape(\''.rawurlencode($this->P['returnUrl']).'\')); return false;').'">'.
00640                                         '<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="" />'.
00641                                         '</a>';
00642                 $content.= '<input type="image" class="c-inputButton" name="_refresh"'.t3lib_iconWorks::skinImg('','gfx/refresh_n.gif','').' title="'.$LANG->getLL('forms_refresh',1).'" />';
00643                         // Add CSH:
00644                 $content.= t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'wizard_forms_wiz_buttons', $GLOBALS['BACK_PATH'],'');
00645                 $content.= '
00646                         </div>
00647                 ';
00648 
00649                         // Add hidden fields:
00650                 $content.= implode('',$hiddenFields);
00651 
00652                         // Return content:
00653                 return $content;
00654         }
00655 
00662         function changeFunc()   {
00663                 if ($this->FORMCFG['row_remove'])       {
00664                         $kk = key($this->FORMCFG['row_remove']);
00665                         $cmd='row_remove';
00666                 } elseif ($this->FORMCFG['row_add'])    {
00667                         $kk = key($this->FORMCFG['row_add']);
00668                         $cmd='row_add';
00669                 } elseif ($this->FORMCFG['row_top'])    {
00670                         $kk = key($this->FORMCFG['row_top']);
00671                         $cmd='row_top';
00672                 } elseif ($this->FORMCFG['row_bottom']) {
00673                         $kk = key($this->FORMCFG['row_bottom']);
00674                         $cmd='row_bottom';
00675                 } elseif ($this->FORMCFG['row_up'])     {
00676                         $kk = key($this->FORMCFG['row_up']);
00677                         $cmd='row_up';
00678                 } elseif ($this->FORMCFG['row_down'])   {
00679                         $kk = key($this->FORMCFG['row_down']);
00680                         $cmd='row_down';
00681                 }
00682 
00683                 if ($cmd && t3lib_div::testInt($kk)) {
00684                         if (substr($cmd,0,4)=='row_')   {
00685                                 switch($cmd)    {
00686                                         case 'row_remove':
00687                                                 unset($this->FORMCFG['c'][$kk]);
00688                                         break;
00689                                         case 'row_add':
00690                                                 $this->FORMCFG['c'][$kk+1]=array();
00691                                         break;
00692                                         case 'row_top':
00693                                                 $this->FORMCFG['c'][1]=$this->FORMCFG['c'][$kk];
00694                                                 unset($this->FORMCFG['c'][$kk]);
00695                                         break;
00696                                         case 'row_bottom':
00697                                                 $this->FORMCFG['c'][1000000]=$this->FORMCFG['c'][$kk];
00698                                                 unset($this->FORMCFG['c'][$kk]);
00699                                         break;
00700                                         case 'row_up':
00701                                                 $this->FORMCFG['c'][$kk-3]=$this->FORMCFG['c'][$kk];
00702                                                 unset($this->FORMCFG['c'][$kk]);
00703                                         break;
00704                                         case 'row_down':
00705                                                 $this->FORMCFG['c'][$kk+3]=$this->FORMCFG['c'][$kk];
00706                                                 unset($this->FORMCFG['c'][$kk]);
00707                                         break;
00708                                 }
00709                                 ksort($this->FORMCFG['c']);
00710                         }
00711                 }
00712         }
00713 
00721         function cfgArray2CfgString($cfgArr)    {
00722 
00723                         // Initialize:
00724                 $inLines=array();
00725 
00726                         // Traverse the elements of the form wizard and transform the settings into configuration code.
00727                 foreach($cfgArr as $vv) {
00728                         if ($vv['comment'])     {       // If "content" is found, then just pass it over.
00729                                 $inLines[]=trim($vv['comment']);
00730                         } else {        // Begin to put together the single-line configuration code of this field:
00731 
00732                                         // Reset:
00733                                 $thisLine=array();
00734 
00735                                         // Set Label:
00736                                 $thisLine[0]=str_replace('|','',$vv['label']);
00737 
00738                                         // Set Type:
00739                                 if ($vv['type'])        {
00740                                         $thisLine[1]=($vv['required']?'*':'').str_replace(',','',($vv['fieldname']?$vv['fieldname'].'=':'').$vv['type']);
00741 
00742                                                 // Default:
00743                                         $tArr=array('','','','','','');
00744                                         switch((string)$vv['type'])     {
00745                                                 case 'textarea':
00746                                                         if (intval($vv['cols']))        $tArr[0]=intval($vv['cols']);
00747                                                         if (intval($vv['rows']))        $tArr[1]=intval($vv['rows']);
00748                                                         if (trim($vv['extra']))         $tArr[2]=trim($vv['extra']);
00749                                                         if (strlen($vv['specialEval'])) {
00750                                                                 $thisLine[2] = '';      // Preset blank default value so position 3 can get a value...
00751                                                                 $thisLine[3] = $vv['specialEval'];
00752                                                         }
00753                                                 break;
00754                                                 case 'input':
00755                                                 case 'password':
00756                                                         if (intval($vv['size']))        $tArr[0]=intval($vv['size']);
00757                                                         if (intval($vv['max']))         $tArr[1]=intval($vv['max']);
00758                                                         if (strlen($vv['specialEval'])) {
00759                                                                 $thisLine[2] = '';      // Preset blank default value so position 3 can get a value...
00760                                                                 $thisLine[3] = $vv['specialEval'];
00761                                                         }
00762                                                 break;
00763                                                 case 'file':
00764                                                         if (intval($vv['size']))        $tArr[0]=intval($vv['size']);
00765                                                 break;
00766                                                 case 'select':
00767                                                         if (intval($vv['size']))        $tArr[0]=intval($vv['size']);
00768                                                         if ($vv['autosize'])    $tArr[0]='auto';
00769                                                         if ($vv['multiple'])    $tArr[1]='m';
00770                                                 break;
00771                                         }
00772                                         $tArr = $this->cleanT($tArr);
00773                                         if (count($tArr))       $thisLine[1].=','.implode(',',$tArr);
00774 
00775                                         $thisLine[1]=str_replace('|','',$thisLine[1]);
00776 
00777                                                 // Default:
00778                                         if ($vv['type']=='select' || $vv['type']=='radio')      {
00779                                                 $thisLine[2]=str_replace(chr(10),', ',str_replace(',','',$vv['options']));
00780                                         } elseif ($vv['type']=='check') {
00781                                                 if ($vv['default'])     $thisLine[2]=1;
00782                                         } elseif (strcmp(trim($vv['default']),'')) {
00783                                                 $thisLine[2]=$vv['default'];
00784                                         }
00785                                         if (isset($thisLine[2]))                $thisLine[2]=str_replace('|','',$thisLine[2]);
00786                                 }
00787 
00788                                         // Compile the final line:
00789                                 $inLines[]=ereg_replace("[\n\r]*",'',implode(' | ',$thisLine));
00790                         }
00791                 }
00792                         // Finally, implode the lines into a string, and return it:
00793                 return implode(chr(10),$inLines);
00794         }
00795 
00803         function cfgString2CfgArray($cfgStr)    {
00804 
00805                         // Traverse the number of form elements:
00806                 $tLines=explode(chr(10),$cfgStr);
00807                 foreach($tLines as $k => $v)    {
00808 
00809                                 // Initialize:
00810                         $confData=array();
00811                         $val=trim($v);
00812 
00813                                 // Accept a line as configuration if a) it is blank(! - because blank lines indicates new, unconfigured fields) or b) it is NOT a comment.
00814                         if (!$val || strcspn($val,'#/')) {
00815 
00816                                         // Split:
00817                                 $parts = t3lib_div::trimExplode('|',$val);
00818 
00819                                         // Label:
00820                                 $confData['label'] = trim($parts[0]);
00821 
00822                                         // Field:
00823                                 $fParts = t3lib_div::trimExplode(',',$parts[1]);
00824                                 $fParts[0]=trim($fParts[0]);
00825                                 if (substr($fParts[0],0,1)=='*')        {
00826                                         $confData['required'] = 1;
00827                                         $fParts[0] = substr($fParts[0],1);
00828                                 }
00829 
00830                                 $typeParts = t3lib_div::trimExplode('=',$fParts[0]);
00831                                 $confData['type'] = trim(strtolower(end($typeParts)));
00832 
00833                                 if ($confData['type'])  {
00834                                         if (count($typeParts)==1)       {
00835                                                 $confData['fieldname'] = substr(ereg_replace('[^a-zA-Z0-9_]','',str_replace(' ','_',trim($parts[0]))),0,30);
00836 
00837                                                         // Attachment names...
00838                                                 if ($confData['type']=='file')  {
00839                                                         $confData['fieldname']='attachment'.$attachmentCounter;
00840                                                         $attachmentCounter=intval($attachmentCounter)+1;
00841                                                 }
00842                                         } else {
00843                                                 $confData['fieldname'] = str_replace(' ','_',trim($typeParts[0]));
00844                                         }
00845 
00846                                         switch((string)$confData['type'])       {
00847                                                 case 'select':
00848                                                 case 'radio':
00849                                                         $confData['default'] = implode(chr(10),t3lib_div::trimExplode(',',$parts[2]));
00850                                                 break;
00851                                                 default:
00852                                                         $confData['default'] = trim($parts[2]);
00853                                                 break;
00854                                         }
00855 
00856                                                 // Field configuration depending on the fields type:
00857                                         switch((string)$confData['type'])       {
00858                                                 case 'textarea':
00859                                                         $confData['cols'] = $fParts[1];
00860                                                         $confData['rows'] = $fParts[2];
00861                                                         $confData['extra'] = strtoupper($fParts[3])=='OFF' ? 'OFF' : '';
00862                                                         $confData['specialEval'] = trim($parts[3]);
00863                                                 break;
00864                                                 case 'input':
00865                                                 case 'password':
00866                                                         $confData['size'] = $fParts[1];
00867                                                         $confData['max'] = $fParts[2];
00868                                                         $confData['specialEval'] = trim($parts[3]);
00869                                                 break;
00870                                                 case 'file':
00871                                                         $confData['size'] = $fParts[1];
00872                                                 break;
00873                                                 case 'select':
00874                                                         $confData['size'] = intval($fParts[1])?$fParts[1]:'';
00875                                                         $confData['autosize'] = strtolower(trim($fParts[1]))=='auto' ? 1 : 0;
00876                                                         $confData['multiple'] = strtolower(trim($fParts[2]))=='m' ? 1 : 0;
00877                                                 break;
00878                                         }
00879                                 }
00880                         } else {
00881                                         // No configuration, only a comment:
00882                                 $confData=array(
00883                                         'comment' => $val
00884                                 );
00885                         }
00886 
00887                                 // Adding config array:
00888                         $cfgArr[]=$confData;
00889                 }
00890 
00891                         // Return cfgArr
00892                 return $cfgArr;
00893         }
00894 
00902         function cleanT($tArr)  {
00903                 for($a=count($tArr);$a>0;$a--)  {
00904                         if (strcmp($tArr[$a-1],''))     {
00905                                 break;
00906                         } else {
00907                                 unset($tArr[$a-1]);
00908                         }
00909                 }
00910                 return $tArr;
00911         }
00912 
00920         function formatCells($fArr)     {
00921 
00922                         // Traverse the elements in $fArr and wrap them in table cells:
00923                 $lines=array();
00924                 foreach($fArr as $l => $c)      {
00925                         $lines[]='
00926                                 <tr>
00927                                         <td nowrap="nowrap">'.htmlspecialchars($l.':').'&nbsp;</td>
00928                                         <td>'.$c.'</td>
00929                                 </tr>';
00930                 }
00931 
00932                         // Add a cell which will set a minimum width:
00933                 $lines[]='
00934                         <tr>
00935                                 <td nowrap="nowrap"><img src="clear.gif" width="70" height="1" alt="" /></td>
00936                                 <td></td>
00937                         </tr>';
00938 
00939                         // Wrap in table and return:
00940                 return '
00941                         <table border="0" cellpadding="0" cellspacing="0">
00942                                 '.implode('',$lines).'
00943                         </table>';
00944         }
00945 }
00946 
00947 // Include extension?
00948 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/wizard_forms.php'])  {
00949         include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/wizard_forms.php']);
00950 }
00951 
00952 
00953 
00954 
00955 
00956 
00957 
00958 
00959 
00960 
00961 
00962 
00963 // Make instance:
00964 $SOBE = t3lib_div::makeInstance('SC_wizard_forms');
00965 $SOBE->init();
00966 
00967 // Include files?
00968 foreach($SOBE->include_once as $INC_FILE)       include_once($INC_FILE);
00969 
00970 $SOBE->main();
00971 $SOBE->printContent();
00972 ?>