/**
  * Searches for upload folders set in TypoScript setup.
  * Returns all upload folders as array.
  *
  * @return array
  */
 public function getAllTempUploadFolders()
 {
     $uploadFolders = array();
     //set default upload folder
     $defaultUploadFolder = '/uploads/formhandler/tmp/';
     //if temp upload folder set in TypoScript, take that setting
     $settings = $this->globals->getSession()->get('settings');
     if (is_array($settings['files.']['uploadFolder.'])) {
         foreach ($settings['files.']['uploadFolder.'] as $fieldName => $folderSettings) {
             $uploadFolders[] = $this->sanitizePath($this->getSingle($settings['files.']['uploadFolder.'], $fieldName));
         }
     } elseif ($settings['files.']['uploadFolder']) {
         $defaultUploadFolder = $this->sanitizePath($this->getSingle($settings['files.'], 'uploadFolder'));
     }
     //If no special upload folder for a field was set, add the default upload folder
     if (count($uploadFolders) === 0) {
         $uploadFolders[] = $defaultUploadFolder;
     }
     return $uploadFolders;
 }
 /**
  * Main method of the dispatcher. This method is called as a user function.
  *
  * @return string rendered view
  * @param string $content
  * @param array $setup The TypoScript config
  */
 public function main($content, $setup)
 {
     $this->pi_USER_INT_obj = 1;
     $this->globals = Tx_Formhandler_Globals::getInstance();
     $this->utilityFuncs = Tx_Formhandler_UtilityFuncs::getInstance();
     try {
         //init flexform
         $this->pi_initPIflexForm();
         /*
          * Parse values from flexform:
          * - Template file
          * - Translation file
          * - Predefined form
          * - E-mail settings
          * - Required fields
          * - Redirect page
          */
         $templateFile = $this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'template_file', 'sDEF');
         $langFile = $this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'lang_file', 'sDEF');
         $predef = $this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'predefined', 'sDEF');
         $this->globals->setCObj($this->cObj);
         if ($setup['usePredef']) {
             $predef = $this->utilityFuncs->getSingle($setup, 'usePredef');
         }
         $this->globals->getCObj()->setCurrentVal($predef);
         $this->globals->setPredef($predef);
         $this->globals->setOverrideSettings($setup);
         $this->componentManager = Tx_Formhandler_Component_Manager::getInstance();
         /*
          * set controller:
          * 1. Default controller
          * 2. TypoScript
          */
         $controller = 'Tx_Formhandler_Controller_Form';
         if ($setup['controller']) {
             $controller = $setup['controller'];
         }
         $controller = $this->utilityFuncs->prepareClassName($controller);
         $controller = $this->componentManager->getComponent($controller);
         if (isset($content)) {
             $controller->setContent($this->componentManager->getComponent('Tx_Formhandler_Content', $content));
         }
         if (strlen($templateFile) > 0) {
             $controller->setTemplateFile($templateFile);
         }
         if (strlen($langFile) > 0) {
             $controller->setLangFiles(array($langFile));
         }
         if (strlen($predef) > 0) {
             $controller->setPredefined($predef);
         }
         $result = $controller->process();
     } catch (Exception $e) {
         \TYPO3\CMS\Core\Utility\GeneralUtility::sysLog($e->getFile() . '(' . $e->getLine() . ')' . ' ' . $e->getMessage(), 'formhandler', \TYPO3\CMS\Core\Utility\GeneralUtility::SYSLOG_SEVERITY_ERROR);
         $result = $this->utilityFuncs->getTranslatedMessage($this->globals->getLangFiles(), 'fe-exception');
         if (!$result) {
             $result = '<div style="color:red; font-weight: bold">' . $this->utilityFuncs->getExceptionMessage('fe-exception') . '</div>';
         }
         if ($this->globals->getSession() && $this->globals->getSession()->get('debug')) {
             $result = '<div style="color:red; font-weight: bold">' . $e->getMessage() . '</div>';
             $result .= '<div style="color:red; font-weight: bold">File: ' . $e->getFile() . '(' . $e->getLine() . ')</div>';
             $result .= '<div style="color:red; font-weight: bold">' . $e->getTraceAsString() . '</div>';
         }
     }
     if ($this->globals->getSession() && $this->globals->getSession()->get('debug')) {
         $debuggers = $this->globals->getDebuggers();
         foreach ($debuggers as $idx => $debugger) {
             $debugger->outputDebugLog();
         }
     }
     return $result;
 }