TYPO3 CMS  TYPO3_6-2
FormsController.php
Go to the documentation of this file.
1 <?php
3 
20 
111 
112  // Internal, dynamic:
119  public $doc;
120 
121  // Content accumulation for the module.
125  public $content;
126 
127  // Used to numerate attachments automatically.
131  public $attachmentCounter = 0;
132 
133  // Internal, static:
134  // If set, the string version of the content is interpreted/written as XML instead of
135  // the original linebased kind. This variable still needs binding to the wizard parameters
136  // - but support is ready!
140  public $xmlStorage = 0;
141 
142  // Internal, static: GPvars
143  // Wizard parameters, coming from TCEforms linking to the wizard.
147  public $P;
148 
149  // The array which is constantly submitted by the multidimensional form of this wizard.
153  public $FORMCFG;
154 
155  // Indicates if the form is of a dedicated type, like "formtype_mail" (for tt_content element "Form")
159  public $special;
160 
164  public function __construct() {
165  $GLOBALS['LANG']->includeLLFile('EXT:lang/locallang_wizards.xlf');
166  $GLOBALS['SOBE'] = $this;
167 
168  $this->init();
169  }
170 
176  protected function init() {
177  // GPvars:
178  $this->P = GeneralUtility::_GP('P');
179  $this->special = GeneralUtility::_GP('special');
180  $this->FORMCFG = GeneralUtility::_GP('FORMCFG');
181  // Setting options:
182  $this->xmlStorage = $this->P['params']['xmlOutput'];
183  // Document template object:
184  $this->doc = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Template\\DocumentTemplate');
185  $this->doc->backPath = $GLOBALS['BACK_PATH'];
186  $this->doc->setModuleTemplate('EXT:backend/Resources/Private/Templates/wizard_forms.html');
187  // Setting form tag:
188  list($rUri) = explode('#', GeneralUtility::getIndpEnv('REQUEST_URI'));
189  $this->doc->form = '<form action="' . htmlspecialchars($rUri) . '" method="post" name="wizardForm">';
190  }
191 
197  public function main() {
198  if ($this->P['table'] && $this->P['field'] && $this->P['uid']) {
199  $this->content .= $this->doc->section($GLOBALS['LANG']->getLL('forms_title'), $this->formsWizard(), 0, 1);
200  } else {
201  $this->content .= $this->doc->section($GLOBALS['LANG']->getLL('forms_title'), '<span class="typo3-red">' . $GLOBALS['LANG']->getLL('table_noData', 1) . '</span>', 0, 1);
202  }
203  // Setting up the buttons and markers for docheader
204  $docHeaderButtons = $this->getButtons();
205  $markers['CSH'] = $docHeaderButtons['csh'];
206  $markers['CONTENT'] = $this->content;
207  // Build the <body> for the module
208  $this->content = $this->doc->startPage('Form Wizard');
209  $this->content .= $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $markers);
210  $this->content .= $this->doc->endPage();
211  $this->content = $this->doc->insertStylesAndJS($this->content);
212  }
213 
220  public function printContent() {
221  echo $this->content;
222  }
223 
229  protected function getButtons() {
230  $buttons = array(
231  'csh' => '',
232  'csh_buttons' => '',
233  'close' => '',
234  'save' => '',
235  'save_close' => '',
236  'reload' => ''
237  );
238  if ($this->P['table'] && $this->P['field'] && $this->P['uid']) {
239  // CSH
240  $buttons['csh'] = BackendUtility::cshItem('xMOD_csh_corebe', 'wizard_forms_wiz', $GLOBALS['BACK_PATH'], '');
241  // CSH Buttons
242  $buttons['csh_buttons'] = BackendUtility::cshItem('xMOD_csh_corebe', 'wizard_forms_wiz_buttons', $GLOBALS['BACK_PATH'], '');
243  // Close
244  $buttons['close'] = '<a href="#" onclick="' . htmlspecialchars(('jumpToUrl(unescape(\'' . rawurlencode(GeneralUtility::sanitizeLocalUrl($this->P['returnUrl'])) . '\')); return false;')) . '">' . IconUtility::getSpriteIcon('actions-document-close', array('title' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:rm.closeDoc', TRUE))) . '</a>';
245  // Save
246  $buttons['save'] = '<input type="image" class="c-inputButton" name="savedok"' . IconUtility::skinImg($this->doc->backPath, 'gfx/savedok.gif') . ' title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:rm.saveDoc', TRUE) . '" />';
247  // Save & Close
248  $buttons['save_close'] = '<input type="image" class="c-inputButton" name="saveandclosedok"' . IconUtility::skinImg($this->doc->backPath, 'gfx/saveandclosedok.gif') . ' title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:rm.saveCloseDoc', TRUE) . '" />';
249  // Reload
250  $buttons['reload'] = '<input type="image" class="c-inputButton" name="_refresh"' . IconUtility::skinImg('', 'gfx/refresh_n.gif') . ' title="' . $GLOBALS['LANG']->getLL('forms_refresh', TRUE) . '" />';
251  }
252  return $buttons;
253  }
254 
261  public function formsWizard() {
262  if (!$this->checkEditAccess($this->P['table'], $this->P['uid'])) {
263  throw new \RuntimeException('Wizard Error: No access', 1385807526);
264  }
265  // First, check the references by selecting the record:
266  $row = BackendUtility::getRecord($this->P['table'], $this->P['uid']);
267  if (!is_array($row)) {
268  throw new \RuntimeException('Wizard Error: No reference to record', 1294587124);
269  }
270  // This will get the content of the form configuration code field to us - possibly
271  // cleaned up, saved to database etc. if the form has been submitted in the meantime.
272  $formCfgArray = $this->getConfigCode($row);
273  // Generation of the Form Wizards HTML code:
274  $content = $this->getFormHTML($formCfgArray, $row);
275  // Return content:
276  return $content;
277  }
278 
279  /****************************
280  *
281  * Helper functions
282  *
283  ***************************/
293  public function getConfigCode(&$row) {
294  // If some data has been submitted, then construct
295  if (isset($this->FORMCFG['c'])) {
296  // Process incoming:
297  $this->changeFunc();
298  // Convert to string (either line based or XML):
299  if ($this->xmlStorage) {
300  // Convert the input array to XML:
301  $bodyText = GeneralUtility::array2xml_cs($this->FORMCFG['c'], 'T3FormWizard');
302  // Setting cfgArr directly from the input:
303  $cfgArr = $this->FORMCFG['c'];
304  } else {
305  // Convert the input array to a string of configuration code:
306  $bodyText = $this->cfgArray2CfgString($this->FORMCFG['c']);
307  // Create cfgArr from the string based configuration - that way it is cleaned
308  // up and any incompatibilities will be removed!
309  $cfgArr = $this->cfgString2CfgArray($bodyText);
310  }
311  // If a save button has been pressed, then save the new field content:
312  if ($_POST['savedok_x'] || $_POST['saveandclosedok_x']) {
313  // Make TCEmain object:
314  $tce = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\DataHandling\\DataHandler');
315  $tce->stripslashes_values = 0;
316  // Put content into the data array:
317  $data = array();
318  $data[$this->P['table']][$this->P['uid']][$this->P['field']] = $bodyText;
319  if ($this->special == 'formtype_mail') {
320  $data[$this->P['table']][$this->P['uid']]['subheader'] = $this->FORMCFG['recipient'];
321  }
322  // Perform the update:
323  $tce->start($data, array());
324  $tce->process_datamap();
325  // Re-load the record content:
326  $row = BackendUtility::getRecord($this->P['table'], $this->P['uid']);
327  // If the save/close button was pressed, then redirect the screen:
328  if ($_POST['saveandclosedok_x']) {
329  \TYPO3\CMS\Core\Utility\HttpUtility::redirect(GeneralUtility::sanitizeLocalUrl($this->P['returnUrl']));
330  }
331  }
332  } else {
333  // If nothing has been submitted, load the $bodyText variable from the selected database row:
334  if ($this->xmlStorage) {
335  $cfgArr = GeneralUtility::xml2array($row[$this->P['field']]);
336  } else {
337  // Regular linebased form configuration:
338  $cfgArr = $this->cfgString2CfgArray($row[$this->P['field']]);
339  }
340  $cfgArr = is_array($cfgArr) ? $cfgArr : array();
341  }
342  // Return configuration code:
343  return $cfgArr;
344  }
345 
355  public function getFormHTML($formCfgArray, $row) {
356  // Initialize variables:
357  $specParts = array();
358  $hiddenFields = array();
359  $tRows = array();
360  // Set header row:
361  $cells = array(
362  $GLOBALS['LANG']->getLL('forms_preview', TRUE) . ':',
363  $GLOBALS['LANG']->getLL('forms_element', TRUE) . ':',
364  $GLOBALS['LANG']->getLL('forms_config', TRUE) . ':'
365  );
366  $tRows[] = '
367  <tr class="bgColor2" id="typo3-formWizardHeader">
368  <td>&nbsp;</td>
369  <td>' . implode('</td>
370  <td>', $cells) . '</td>
371  </tr>';
372  // Traverse the number of form elements:
373  $k = 0;
374  foreach ($formCfgArray as $confData) {
375  // Initialize:
376  $cells = array();
377  // If there is a configuration line which is active, then render it:
378  if (!isset($confData['comment'])) {
379  // Special parts:
380  if ($this->special == 'formtype_mail' && GeneralUtility::inList('formtype_mail,subject,html_enabled', $confData['fieldname'])) {
381  $specParts[$confData['fieldname']] = $confData['default'];
382  } else {
383  // Render title/field preview COLUMN
384  $cells[] = $confData['type'] != 'hidden' ? '<strong>' . htmlspecialchars($confData['label']) . '</strong>' : '';
385  // Render general type/title COLUMN:
386  $temp_cells = array();
387  // Field type selector:
388  $opt = array();
389  $opt[] = '<option value=""></option>';
390  $types = explode(',', 'input,textarea,select,check,radio,password,file,hidden,submit,property,label');
391  foreach ($types as $t) {
392  $opt[] = '
393  <option value="' . $t . '"' . ($confData['type'] == $t ? ' selected="selected"' : '') . '>' . $GLOBALS['LANG']->getLL(('forms_type_' . $t), TRUE) . '</option>';
394  }
395  $temp_cells[$GLOBALS['LANG']->getLL('forms_type')] = '
396  <select name="FORMCFG[c][' . ($k + 1) * 2 . '][type]">
397  ' . implode('
398  ', $opt) . '
399  </select>';
400  // Title field:
401  if (!GeneralUtility::inList('hidden,submit', $confData['type'])) {
402  $temp_cells[$GLOBALS['LANG']->getLL('forms_label')] = '<input type="text"' . $this->doc->formWidth(15) . ' name="FORMCFG[c][' . ($k + 1) * 2 . '][label]" value="' . htmlspecialchars($confData['label']) . '" />';
403  }
404  // Required checkbox:
405  if (!GeneralUtility::inList('check,hidden,submit,label', $confData['type'])) {
406  $temp_cells[$GLOBALS['LANG']->getLL('forms_required')] = '<input type="checkbox" name="FORMCFG[c][' . ($k + 1) * 2 . '][required]" value="1"' . ($confData['required'] ? ' checked="checked"' : '') . ' title="' . $GLOBALS['LANG']->getLL('forms_required', TRUE) . '" />';
407  }
408  // Put sub-items together into table cell:
409  $cells[] = $this->formatCells($temp_cells);
410  // Render specific field configuration COLUMN:
411  $temp_cells = array();
412  // Fieldname
413  if ($this->special == 'formtype_mail' && $confData['type'] == 'file') {
414  $confData['fieldname'] = 'attachment' . ++$this->attachmentCounter;
415  }
416  if (!GeneralUtility::inList('label', $confData['type'])) {
417  $temp_cells[$GLOBALS['LANG']->getLL('forms_fieldName')] = '<input type="text"' . $this->doc->formWidth(10) . ' name="FORMCFG[c][' . ($k + 1) * 2 . '][fieldname]" value="' . htmlspecialchars($confData['fieldname']) . '" title="' . $GLOBALS['LANG']->getLL('forms_fieldName', TRUE) . '" />';
418  }
419  // Field configuration depending on the fields type:
420  switch ((string) $confData['type']) {
421  case 'textarea':
422  $temp_cells[$GLOBALS['LANG']->getLL('forms_cols')] = '<input type="text"' . $this->doc->formWidth(5) . ' name="FORMCFG[c][' . ($k + 1) * 2 . '][cols]" value="' . htmlspecialchars($confData['cols']) . '" title="' . $GLOBALS['LANG']->getLL('forms_cols', TRUE) . '" />';
423  $temp_cells[$GLOBALS['LANG']->getLL('forms_rows')] = '<input type="text"' . $this->doc->formWidth(5) . ' name="FORMCFG[c][' . ($k + 1) * 2 . '][rows]" value="' . htmlspecialchars($confData['rows']) . '" title="' . $GLOBALS['LANG']->getLL('forms_rows', TRUE) . '" />';
424  $temp_cells[$GLOBALS['LANG']->getLL('forms_extra')] = '<input type="checkbox" name="FORMCFG[c][' . ($k + 1) * 2 . '][extra]" value="OFF"' . ($confData['extra'] == 'OFF' ? ' checked="checked"' : '') . ' title="' . $GLOBALS['LANG']->getLL('forms_extra', TRUE) . '" />';
425  break;
426  case 'input':
427 
428  case 'password':
429  $temp_cells[$GLOBALS['LANG']->getLL('forms_size')] = '<input type="text"' . $this->doc->formWidth(5) . ' name="FORMCFG[c][' . ($k + 1) * 2 . '][size]" value="' . htmlspecialchars($confData['size']) . '" title="' . $GLOBALS['LANG']->getLL('forms_size', TRUE) . '" />';
430  $temp_cells[$GLOBALS['LANG']->getLL('forms_max')] = '<input type="text"' . $this->doc->formWidth(5) . ' name="FORMCFG[c][' . ($k + 1) * 2 . '][max]" value="' . htmlspecialchars($confData['max']) . '" title="' . $GLOBALS['LANG']->getLL('forms_max', TRUE) . '" />';
431  break;
432  case 'file':
433  $temp_cells[$GLOBALS['LANG']->getLL('forms_size')] = '<input type="text"' . $this->doc->formWidth(5) . ' name="FORMCFG[c][' . ($k + 1) * 2 . '][size]" value="' . htmlspecialchars($confData['size']) . '" title="' . $GLOBALS['LANG']->getLL('forms_size', TRUE) . '" />';
434  break;
435  case 'select':
436  $temp_cells[$GLOBALS['LANG']->getLL('forms_size')] = '<input type="text"' . $this->doc->formWidth(5) . ' name="FORMCFG[c][' . ($k + 1) * 2 . '][size]" value="' . htmlspecialchars($confData['size']) . '" title="' . $GLOBALS['LANG']->getLL('forms_size', TRUE) . '" />';
437  $temp_cells[$GLOBALS['LANG']->getLL('forms_autosize')] = '<input type="checkbox" name="FORMCFG[c][' . ($k + 1) * 2 . '][autosize]" value="1"' . ($confData['autosize'] ? ' checked="checked"' : '') . ' title="' . $GLOBALS['LANG']->getLL('forms_autosize', TRUE) . '" />';
438  $temp_cells[$GLOBALS['LANG']->getLL('forms_multiple')] = '<input type="checkbox" name="FORMCFG[c][' . ($k + 1) * 2 . '][multiple]" value="1"' . ($confData['multiple'] ? ' checked="checked"' : '') . ' title="' . $GLOBALS['LANG']->getLL('forms_multiple', TRUE) . '" />';
439  break;
440  }
441  // Field configuration depending on the fields type:
442  switch ((string) $confData['type']) {
443  case 'textarea':
444 
445  case 'input':
446 
447  case 'password':
448  if (strlen(trim($confData['specialEval']))) {
449  $hiddenFields[] = '<input type="hidden" name="FORMCFG[c][' . ($k + 1) * 2 . '][specialEval]" value="' . htmlspecialchars($confData['specialEval']) . '" />';
450  }
451  break;
452  }
453  // Default data
454  if ($confData['type'] == 'select' || $confData['type'] == 'radio') {
455  $temp_cells[$GLOBALS['LANG']->getLL('forms_options')] = '<textarea ' . $this->doc->formWidth(15) . ' rows="4" name="FORMCFG[c][' . ($k + 1) * 2 . '][options]" title="' . $GLOBALS['LANG']->getLL('forms_options', TRUE) . '">' . GeneralUtility::formatForTextarea($confData['default']) . '</textarea>';
456  } elseif ($confData['type'] == 'check') {
457  $temp_cells[$GLOBALS['LANG']->getLL('forms_checked')] = '<input type="checkbox" name="FORMCFG[c][' . ($k + 1) * 2 . '][default]" value="1"' . (trim($confData['default']) ? ' checked="checked"' : '') . ' title="' . $GLOBALS['LANG']->getLL('forms_checked', TRUE) . '" />';
458  } elseif ($confData['type'] && $confData['type'] != 'file') {
459  $temp_cells[$GLOBALS['LANG']->getLL('forms_default')] = '<input type="text"' . $this->doc->formWidth(15) . ' name="FORMCFG[c][' . ($k + 1) * 2 . '][default]" value="' . htmlspecialchars($confData['default']) . '" title="' . $GLOBALS['LANG']->getLL('forms_default', TRUE) . '" />';
460  }
461  $cells[] = $confData['type'] ? $this->formatCells($temp_cells) : '';
462  // CTRL panel for an item (move up/down/around):
463  $ctrl = '';
464  $onClick = 'document.wizardForm.action+=\'#ANC_' . (($k + 1) * 2 - 2) . '\';';
465  $onClick = ' onclick="' . htmlspecialchars($onClick) . '"';
466  // FIXME $inputStyle undefined
467  $brTag = $inputStyle ? '' : '<br />';
468  if ($k != 0) {
469  $ctrl .= '<input type="image" name="FORMCFG[row_up][' . ($k + 1) * 2 . ']"' . IconUtility::skinImg($this->doc->backPath, 'gfx/pil2up.gif', '') . $onClick . ' title="' . $GLOBALS['LANG']->getLL('table_up', TRUE) . '" />' . $brTag;
470  } else {
471  $ctrl .= '<input type="image" name="FORMCFG[row_bottom][' . ($k + 1) * 2 . ']"' . IconUtility::skinImg($this->doc->backPath, 'gfx/turn_up.gif', '') . $onClick . ' title="' . $GLOBALS['LANG']->getLL('table_bottom', TRUE) . '" />' . $brTag;
472  }
473  $ctrl .= '<input type="image" name="FORMCFG[row_remove][' . ($k + 1) * 2 . ']"' . IconUtility::skinImg($this->doc->backPath, 'gfx/garbage.gif', '') . $onClick . ' title="' . $GLOBALS['LANG']->getLL('table_removeRow', TRUE) . '" />' . $brTag;
474  // FIXME $tLines undefined
475  if ($k + 1 != count($tLines)) {
476  $ctrl .= '<input type="image" name="FORMCFG[row_down][' . ($k + 1) * 2 . ']"' . IconUtility::skinImg($this->doc->backPath, 'gfx/pil2down.gif', '') . $onClick . ' title="' . $GLOBALS['LANG']->getLL('table_down', TRUE) . '" />' . $brTag;
477  } else {
478  $ctrl .= '<input type="image" name="FORMCFG[row_top][' . ($k + 1) * 2 . ']"' . IconUtility::skinImg($this->doc->backPath, 'gfx/turn_down.gif', '') . $onClick . ' title="' . $GLOBALS['LANG']->getLL('table_top', TRUE) . '" />' . $brTag;
479  }
480  $ctrl .= '<input type="image" name="FORMCFG[row_add][' . ($k + 1) * 2 . ']"' . IconUtility::skinImg($this->doc->backPath, 'gfx/add.gif', '') . $onClick . ' title="' . $GLOBALS['LANG']->getLL('table_addRow', TRUE) . '" />' . $brTag;
481  $ctrl = '<span class="c-wizButtonsV">' . $ctrl . '</span>';
482  // Finally, put together the full row from the generated content above:
483  $bgC = $confData['type'] ? ' class="bgColor5"' : '';
484  $tRows[] = '
485  <tr' . $bgC . '>
486  <td><a name="ANC_' . ($k + 1) * 2 . '"></a>' . $ctrl . '</td>
487  <td class="bgColor4">' . implode('</td>
488  <td valign="top">', $cells) . '</td>
489  </tr>';
490  }
491  } else {
492  $hiddenFields[] = '<input type="hidden" name="FORMCFG[c][' . ($k + 1) * 2 . '][comment]" value="' . htmlspecialchars($confData['comment']) . '" />';
493  }
494  // Increment counter:
495  $k++;
496  }
497  // If the form is of the special type "formtype_mail" (used for tt_content elements):
498  if ($this->special == 'formtype_mail') {
499  // Blank spacer:
500  $tRows[] = '
501  <tr>
502  <td colspan="4">&nbsp;</td>
503  </tr>';
504  // Header:
505  $tRows[] = '
506  <tr>
507  <td colspan="2" class="bgColor2">&nbsp;</td>
508  <td colspan="2" class="bgColor2"><strong>' . $GLOBALS['LANG']->getLL('forms_special_eform', TRUE) . ':</strong>' . BackendUtility::cshItem('xMOD_csh_corebe', 'wizard_forms_wiz_formmail_info', $GLOBALS['BACK_PATH'], '') . '</td>
509  </tr>';
510  // "FORM type":
511  $tRows[] = '
512  <tr class="bgColor5">
513  <td>&nbsp;</td>
514  <td class="bgColor4">&nbsp;</td>
515  <td>' . $GLOBALS['LANG']->getLL('forms_eform_formtype_mail', TRUE) . ':</td>
516  <td>
517  <input type="hidden" name="FORMCFG[c][' . 1000 * 2 . '][fieldname]" value="formtype_mail" />
518  <input type="hidden" name="FORMCFG[c][' . 1000 * 2 . '][type]" value="submit" />
519  <input type="text"' . $this->doc->formWidth(15) . ' name="FORMCFG[c][' . 1000 * 2 . '][default]" value="' . htmlspecialchars($specParts['formtype_mail']) . '" />
520  </td>
521  </tr>';
522  // "Send HTML mail":
523  $tRows[] = '
524  <tr class="bgColor5">
525  <td>&nbsp;</td>
526  <td class="bgColor4">&nbsp;</td>
527  <td>' . $GLOBALS['LANG']->getLL('forms_eform_html_enabled', TRUE) . ':</td>
528  <td>
529  <input type="hidden" name="FORMCFG[c][' . 1001 * 2 . '][fieldname]" value="html_enabled" />
530  <input type="hidden" name="FORMCFG[c][' . 1001 * 2 . '][type]" value="hidden" />
531  <input type="checkbox" name="FORMCFG[c][' . 1001 * 2 . '][default]" value="1"' . ($specParts['html_enabled'] ? ' checked="checked"' : '') . ' />
532  </td>
533  </tr>';
534  // "Subject":
535  $tRows[] = '
536  <tr class="bgColor5">
537  <td>&nbsp;</td>
538  <td class="bgColor4">&nbsp;</td>
539  <td>' . $GLOBALS['LANG']->getLL('forms_eform_subject', TRUE) . ':</td>
540  <td>
541  <input type="hidden" name="FORMCFG[c][' . 1002 * 2 . '][fieldname]" value="subject" />
542  <input type="hidden" name="FORMCFG[c][' . 1002 * 2 . '][type]" value="hidden" />
543  <input type="text"' . $this->doc->formWidth(15) . ' name="FORMCFG[c][' . 1002 * 2 . '][default]" value="' . htmlspecialchars($specParts['subject']) . '" />
544  </td>
545  </tr>';
546  // Recipient:
547  $tRows[] = '
548  <tr class="bgColor5">
549  <td>&nbsp;</td>
550  <td class="bgColor4">&nbsp;</td>
551  <td>' . $GLOBALS['LANG']->getLL('forms_eform_recipient', TRUE) . ':</td>
552  <td>
553  <input type="text"' . $this->doc->formWidth(15) . ' name="FORMCFG[recipient]" value="' . htmlspecialchars($row['subheader']) . '" />
554  </td>
555  </tr>';
556  }
557  $content = '';
558  // Implode all table rows into a string, wrapped in table tags.
559  $content .= '
560 
561  <!--
562  Form wizard
563  -->
564  <table border="0" cellpadding="1" cellspacing="1" id="typo3-formwizard">
565  ' . implode('', $tRows) . '
566  </table>';
567  // Add hidden fields:
568  $content .= implode('', $hiddenFields);
569  // Return content:
570  return $content;
571  }
572 
580  public function changeFunc() {
581  if ($this->FORMCFG['row_remove']) {
582  $kk = key($this->FORMCFG['row_remove']);
583  $cmd = 'row_remove';
584  } elseif ($this->FORMCFG['row_add']) {
585  $kk = key($this->FORMCFG['row_add']);
586  $cmd = 'row_add';
587  } elseif ($this->FORMCFG['row_top']) {
588  $kk = key($this->FORMCFG['row_top']);
589  $cmd = 'row_top';
590  } elseif ($this->FORMCFG['row_bottom']) {
591  $kk = key($this->FORMCFG['row_bottom']);
592  $cmd = 'row_bottom';
593  } elseif ($this->FORMCFG['row_up']) {
594  $kk = key($this->FORMCFG['row_up']);
595  $cmd = 'row_up';
596  } elseif ($this->FORMCFG['row_down']) {
597  $kk = key($this->FORMCFG['row_down']);
598  $cmd = 'row_down';
599  }
600  if ($cmd && \TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($kk)) {
601  if (substr($cmd, 0, 4) == 'row_') {
602  switch ($cmd) {
603  case 'row_remove':
604  unset($this->FORMCFG['c'][$kk]);
605  break;
606  case 'row_add':
607  $this->FORMCFG['c'][$kk + 1] = array();
608  break;
609  case 'row_top':
610  $this->FORMCFG['c'][1] = $this->FORMCFG['c'][$kk];
611  unset($this->FORMCFG['c'][$kk]);
612  break;
613  case 'row_bottom':
614  $this->FORMCFG['c'][1000000] = $this->FORMCFG['c'][$kk];
615  unset($this->FORMCFG['c'][$kk]);
616  break;
617  case 'row_up':
618  $this->FORMCFG['c'][$kk - 3] = $this->FORMCFG['c'][$kk];
619  unset($this->FORMCFG['c'][$kk]);
620  break;
621  case 'row_down':
622  $this->FORMCFG['c'][$kk + 3] = $this->FORMCFG['c'][$kk];
623  unset($this->FORMCFG['c'][$kk]);
624  break;
625  }
626  ksort($this->FORMCFG['c']);
627  }
628  }
629  }
630 
639  public function cfgArray2CfgString($cfgArr) {
640  // Initialize:
641  $inLines = array();
642  // Traverse the elements of the form wizard and transform the settings into configuration code.
643  foreach ($cfgArr as $vv) {
644  // If "content" is found, then just pass it over.
645  if ($vv['comment']) {
646  $inLines[] = trim($vv['comment']);
647  } else {
648  // Begin to put together the single-line configuration code of this field:
649  // Reset:
650  $thisLine = array();
651  // Set Label:
652  $thisLine[0] = str_replace('|', '', $vv['label']);
653  // Set Type:
654  if ($vv['type']) {
655  $thisLine[1] = ($vv['required'] ? '*' : '') . str_replace(',', '', (($vv['fieldname'] ? $vv['fieldname'] . '=' : '') . $vv['type']));
656  // Default:
657  $tArr = array('', '', '', '', '', '');
658  switch ((string) $vv['type']) {
659  case 'textarea':
660  if ((int)$vv['cols']) {
661  $tArr[0] = (int)$vv['cols'];
662  }
663  if ((int)$vv['rows']) {
664  $tArr[1] = (int)$vv['rows'];
665  }
666  if (trim($vv['extra'])) {
667  $tArr[2] = trim($vv['extra']);
668  }
669  if (strlen($vv['specialEval'])) {
670  // Preset blank default value so position 3 can get a value...
671  $thisLine[2] = '';
672  $thisLine[3] = $vv['specialEval'];
673  }
674  break;
675  case 'input':
676  case 'password':
677  if ((int)$vv['size']) {
678  $tArr[0] = (int)$vv['size'];
679  }
680  if ((int)$vv['max']) {
681  $tArr[1] = (int)$vv['max'];
682  }
683  if (strlen($vv['specialEval'])) {
684  // Preset blank default value so position 3 can get a value...
685  $thisLine[2] = '';
686  $thisLine[3] = $vv['specialEval'];
687  }
688  break;
689  case 'file':
690  if ((int)$vv['size']) {
691  $tArr[0] = (int)$vv['size'];
692  }
693  break;
694  case 'select':
695  if ((int)$vv['size']) {
696  $tArr[0] = (int)$vv['size'];
697  }
698  if ($vv['autosize']) {
699  $tArr[0] = 'auto';
700  }
701  if ($vv['multiple']) {
702  $tArr[1] = 'm';
703  }
704  break;
705  }
706  $tArr = $this->cleanT($tArr);
707  if (count($tArr)) {
708  $thisLine[1] .= ',' . implode(',', $tArr);
709  }
710  $thisLine[1] = str_replace('|', '', $thisLine[1]);
711  // Default:
712  if ($vv['type'] == 'select' || $vv['type'] == 'radio') {
713  $options = str_replace(',', '', $vv['options']);
714  $options = str_replace(
715  array(CR . LF, CR, LF),
716  ', ',
717  $options);
718  $thisLine[2] = $options;
719  } elseif ($vv['type'] == 'check') {
720  if ($vv['default']) {
721  $thisLine[2] = 1;
722  }
723  } elseif (trim($vv['default']) !== '') {
724  $thisLine[2] = $vv['default'];
725  }
726  if (isset($thisLine[2])) {
727  $thisLine[2] = str_replace('|', '', $thisLine[2]);
728  }
729  }
730  // Compile the final line:
731  $inLines[] = preg_replace('/[
732 
733 ]*/', '', implode(' | ', $thisLine));
734  }
735  }
736  // Finally, implode the lines into a string, and return it:
737  return implode(LF, $inLines);
738  }
739 
748  public function cfgString2CfgArray($cfgStr) {
749  // Traverse the number of form elements:
750  $tLines = explode(LF, $cfgStr);
751  $attachmentCounter = 0;
752  foreach ($tLines as $k => $v) {
753  // Initialize:
754  $confData = array();
755  $val = trim($v);
756  // Accept a line as configuration if a) it is blank(! - because blank lines indicates new,
757  // unconfigured fields) or b) it is NOT a comment.
758  if (!$val || strcspn($val, '#/')) {
759  // Split:
760  $parts = GeneralUtility::trimExplode('|', $val);
761  // Label:
762  $confData['label'] = trim($parts[0]);
763  // Field:
764  $fParts = GeneralUtility::trimExplode(',', $parts[1]);
765  $fParts[0] = trim($fParts[0]);
766  if ($fParts[0][0] === '*') {
767  $confData['required'] = 1;
768  $fParts[0] = substr($fParts[0], 1);
769  }
770  $typeParts = GeneralUtility::trimExplode('=', $fParts[0]);
771  $confData['type'] = trim(strtolower(end($typeParts)));
772  if ($confData['type']) {
773  if (count($typeParts) == 1) {
774  $confData['fieldname'] = substr(preg_replace('/[^a-zA-Z0-9_]/', '', str_replace(' ', '_', trim($parts[0]))), 0, 30);
775  // Attachment names...
776  if ($confData['type'] == 'file') {
777  $confData['fieldname'] = 'attachment' . $attachmentCounter;
778  $attachmentCounter = (int)$attachmentCounter + 1;
779  }
780  } else {
781  $confData['fieldname'] = str_replace(' ', '_', trim($typeParts[0]));
782  }
783  switch ((string) $confData['type']) {
784  case 'select':
785  case 'radio':
786  $confData['default'] = implode(LF, GeneralUtility::trimExplode(',', $parts[2]));
787  break;
788  default:
789  $confData['default'] = trim($parts[2]);
790  }
791  // Field configuration depending on the fields type:
792  switch ((string) $confData['type']) {
793  case 'textarea':
794  $confData['cols'] = $fParts[1];
795  $confData['rows'] = $fParts[2];
796  $confData['extra'] = strtoupper($fParts[3]) == 'OFF' ? 'OFF' : '';
797  $confData['specialEval'] = trim($parts[3]);
798  break;
799  case 'input':
800  case 'password':
801  $confData['size'] = $fParts[1];
802  $confData['max'] = $fParts[2];
803  $confData['specialEval'] = trim($parts[3]);
804  break;
805  case 'file':
806  $confData['size'] = $fParts[1];
807  break;
808  case 'select':
809  $confData['size'] = (int)$fParts[1] ? $fParts[1] : '';
810  $confData['autosize'] = strtolower(trim($fParts[1])) === 'auto' ? 1 : 0;
811  $confData['multiple'] = strtolower(trim($fParts[2])) === 'm' ? 1 : 0;
812  break;
813  }
814  }
815  } else {
816  // No configuration, only a comment:
817  $confData = array(
818  'comment' => $val
819  );
820  }
821  // Adding config array:
822  $cfgArr[] = $confData;
823  }
824  // Return cfgArr
825  return $cfgArr;
826  }
827 
836  public function cleanT($tArr) {
837  for ($a = count($tArr); $a > 0; $a--) {
838  if ((string)$tArr[$a - 1] !== '') {
839  break;
840  } else {
841  unset($tArr[$a - 1]);
842  }
843  }
844  return $tArr;
845  }
846 
855  public function formatCells($fArr) {
856  // Traverse the elements in $fArr and wrap them in table cells:
857  $lines = array();
858  foreach ($fArr as $l => $c) {
859  $lines[] = '
860  <tr>
861  <td nowrap="nowrap">' . htmlspecialchars(($l . ':')) . '&nbsp;</td>
862  <td>' . $c . '</td>
863  </tr>';
864  }
865  // Add a cell which will set a minimum width:
866  $lines[] = '
867  <tr>
868  <td nowrap="nowrap"><img src="clear.gif" width="70" height="1" alt="" /></td>
869  <td></td>
870  </tr>';
871  // Wrap in table and return:
872  return '
873  <table border="0" cellpadding="0" cellspacing="0">
874  ' . implode('', $lines) . '
875  </table>';
876  }
877 
886  protected function checkEditAccess($table, $uid) {
887  $calcPRec = BackendUtility::getRecord($table, $uid);
888  BackendUtility::fixVersioningPid($table, $calcPRec);
889  if (is_array($calcPRec)) {
890  // If pages:
891  if ($table == 'pages') {
892  $CALC_PERMS = $GLOBALS['BE_USER']->calcPerms($calcPRec);
893  $hasAccess = $CALC_PERMS & 2 ? TRUE : FALSE;
894  } else {
895  // Fetching pid-record first.
896  $CALC_PERMS = $GLOBALS['BE_USER']->calcPerms(BackendUtility::getRecord('pages', $calcPRec['pid']));
897  $hasAccess = $CALC_PERMS & 16 ? TRUE : FALSE;
898  }
899  // Check internals regarding access:
900  if ($hasAccess) {
901  $hasAccess = $GLOBALS['BE_USER']->recordEditAccessInternals($table, $calcPRec);
902  }
903  } else {
904  $hasAccess = FALSE;
905  }
906  return $hasAccess;
907  }
908 }
static cshItem($table, $field, $BACK_PATH, $wrap='', $onlyIconMode=FALSE, $styleAttrib='')
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]