/**
  * This function fills the default markers:
  *
  * ###PRINT_LINK###
  * ###PDF_LINK###
  * ###CSV_LINK###
  *
  * @return string Template with replaced markers
  */
 protected function fillDefaultMarkers()
 {
     parent::fillDefaultMarkers();
     if (Tx_Formhandler_Globals::$formValuesPrefix) {
         $params[Tx_Formhandler_Globals::$formValuesPrefix] = $this->gp;
     } else {
         $params = $this->gp;
     }
     $params['type'] = 98;
     $label = Tx_Formhandler_StaticFuncs::getTranslatedMessage($this->langFiles, 'print');
     if (strlen($label) == 0) {
         $label = 'print';
     }
     $markers['###PRINT_LINK###'] = $this->cObj->getTypolink($label, $GLOBALS['TSFE']->id, $params);
     unset($params['type']);
     if ($this->componentSettings['actions.']) {
         foreach ($this->componentSettings['actions.'] as $action => $options) {
             $sanitizedAction = str_replace('.', '', $action);
             $class = $options['class'];
             if ($class) {
                 $class = Tx_Formhandler_StaticFuncs::prepareClassName($class);
                 $generator = $this->componentManager->getComponent($class);
                 $generator->init($this->gp, $options['config.']);
                 $markers['###' . strtoupper($sanitizedAction) . '_LINK###'] = $generator->getLink($params);
             }
         }
     }
     $this->fillFEUserMarkers($markers);
     $this->fillFileMarkers($markers);
     $this->template = $this->cObj->substituteMarkerArray($this->template, $markers);
 }
 /**
  * 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;
     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');
         Tx_Formhandler_Globals::$predef = $predef;
         Tx_Formhandler_Globals::$cObj = $this->cObj;
         Tx_Formhandler_Globals::$overrideSettings = $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 = Tx_Formhandler_StaticFuncs::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) {
         $result = '<div style="color:red; font-weight: bold">Caught exception: ' . $e->getMessage() . '</div>';
         $result .= '<div style="color:red; font-weight: bold">File: ' . $e->getFile() . '(' . $e->getLine() . ')</div>';
     }
     if (Tx_Formhandler_Globals::$session && Tx_Formhandler_Globals::$session->get('debug')) {
         foreach (Tx_Formhandler_Globals::$debuggers as $idx => $debugger) {
             $debugger->outputDebugLog();
         }
     }
     return $result;
 }
 protected function log($markAsSpam = FALSE)
 {
     $classesArray = $this->settings['loggers.'];
     if (isset($classesArray) && is_array($classesArray)) {
         foreach ($classesArray as $idx => $tsConfig) {
             if (is_array($tsConfig) && isset($tsConfig['class']) && !empty($tsConfig['class']) && intval($tsConfig['disable']) !== 1) {
                 $className = Tx_Formhandler_StaticFuncs::prepareClassName($tsConfig['class']);
                 Tx_Formhandler_StaticFuncs::Message('calling_class', array($className));
                 $obj = $this->componentManager->getComponent($className);
                 if ($markAsSpam) {
                     $tsConfig['config.']['markAsSpam'] = 1;
                 }
                 $obj->init($this->gp, $tsConfig['config.']);
                 $obj->process();
             } else {
                 Tx_Formhandler_StaticFuncs::throwException('classesarray_error');
             }
         }
     }
 }
 protected function init()
 {
     $this->fieldName = $_GET['field'];
     $this->uploadedFileName = $_GET['uploadedFileName'];
     if (isset($_GET['pid'])) {
         $this->id = intval($_GET['pid']);
     } else {
         $this->id = intval($_GET['id']);
     }
     $this->componentManager = Tx_Formhandler_Component_Manager::getInstance();
     tslib_eidtools::connectDB();
     $this->initializeTSFE($this->id);
     Tx_Formhandler_Globals::$cObj = $GLOBALS['TSFE']->cObj;
     $randomID = t3lib_div::_GP('randomID');
     Tx_Formhandler_Globals::$randomID = $randomID;
     if (!Tx_Formhandler_Globals::$session) {
         $ts = $GLOBALS['TSFE']->tmpl->setup['plugin.']['Tx_Formhandler.']['settings.'];
         $sessionClass = 'Tx_Formhandler_Session_PHP';
         if ($ts['session.']) {
             $sessionClass = Tx_Formhandler_StaticFuncs::prepareClassName($ts['session.']['class']);
         }
         Tx_Formhandler_Globals::$session = $this->componentManager->getComponent($sessionClass);
     }
     $this->settings = Tx_Formhandler_Globals::$session->get('settings');
     //init ajax
     if ($this->settings['ajax.']) {
         $class = $this->settings['ajax.']['class'];
         if (!$class) {
             $class = 'Tx_Formhandler_AjaxHandler_JQuery';
         }
         $class = Tx_Formhandler_StaticFuncs::prepareClassName($class);
         $ajaxHandler = $this->componentManager->getComponent($class);
         Tx_Formhandler_Globals::$ajaxHandler = $ajaxHandler;
         $ajaxHandler->init($this->settings['ajax.']['config.']);
         $ajaxHandler->initAjax();
     }
 }
 /**
  * Parses the email settings in flexform of a specific type (admin|user]
  *
  * @param array $currentSettings The current settings array containing the settings made via TypoScript
  * @param string $type (admin|user)
  * @param array $optionsToParse Array containing all option names to parse.
  * @return array The parsed email settings
  */
 private function parseEmailSettingsByType($currentSettings, $type, $optionsToParse = array())
 {
     $typeLower = strtolower($type);
     $typeUpper = strtoupper($type);
     $section = 'sEMAIL' . $typeUpper;
     $emailSettings = $currentSettings;
     foreach ($optionsToParse as $idx => $option) {
         $value = Tx_Formhandler_StaticFuncs::pi_getFFvalue($this->cObj->data['pi_flexform'], $option, $section);
         if (strlen($value) > 0) {
             $emailSettings[$option] = $value;
             if (isset($this->gp[$value])) {
                 $emailSettings[$option] = $this->gp[$value];
             }
         } else {
             switch ($option) {
                 case 'to_email':
                 case 'to_name':
                 case 'sender_email':
                 case 'replyto_email':
                 case 'cc_email':
                 case 'bcc_email':
                 case 'return_path':
                     $emailSettings[$option] = $this->parseList($currentSettings, $type, $option);
                     break;
                 case 'subject':
                 case 'sender_name':
                 case 'replyto_name':
                 case 'cc_name':
                 case 'bcc_name':
                     $emailSettings[$option] = $this->parseValue($currentSettings, $type, $option);
                     break;
                 case 'attachment':
                     $emailSettings[$option] = $this->parseFilesList($currentSettings, $type, $option);
                     break;
                 case 'attachPDF':
                     if (isset($currentSettings['attachPDF.']) && is_array($currentSettings['attachPDF.'])) {
                         $generatorClass = $currentSettings['attachPDF.']['class'];
                         if ($generatorClass) {
                             $generatorClass = Tx_Formhandler_StaticFuncs::prepareClassName($generatorClass);
                             $generator = $this->componentManager->getComponent($generatorClass);
                             $generator->init($this->gp, $currentSettings['attachPDF.']['config.']);
                             $file = $generator->process();
                             unset($currentSettings['attachPDF.']);
                             $emailSettings['attachPDF'] = $file;
                         }
                     } elseif ($currentSettings['attachPDF']) {
                         $emailSettings['attachPDF'] = $currentSettings['attachPDF'];
                     }
                     break;
                 case 'htmlEmailAsAttachment':
                     if (isset($currentSettings['htmlEmailAsAttachment']) && !strcmp($currentSettings['htmlEmailAsAttachment'], '1')) {
                         $emailSettings['htmlEmailAsAttachment'] = 1;
                     }
                     break;
                 case 'filePrefix':
                     if (isset($currentSettings['filePrefix'])) {
                         $emailSettings['filePrefix'] = $currentSettings['filePrefix'];
                     }
                     break;
                 case 'plain.':
                     if (isset($currentSettings['plain.'])) {
                         $emailSettings['plain.'] = $currentSettings['plain.'];
                     }
                     break;
                 case 'html.':
                     if (isset($currentSettings['html.'])) {
                         $emailSettings['html.'] = $currentSettings['html.'];
                     }
                     break;
             }
         }
     }
     $this->fillLangMarkersInSettings($emailSettings);
     return $emailSettings;
 }
 protected function initializeDebuggers()
 {
     $this->addFormhandlerClass($this->settings['debuggers.'], 'Tx_Formhandler_Debugger_Print');
     foreach ($this->settings['debuggers.'] as $idx => $options) {
         if (intval($options['disable']) !== 1) {
             $debuggerClass = $options['class'];
             $debuggerClass = Tx_Formhandler_StaticFuncs::prepareClassName($debuggerClass);
             $debugger = $this->componentManager->getComponent($debuggerClass);
             $debugger->init($this->gp, $options['config.']);
             $debugger->validateConfig();
             Tx_Formhandler_Globals::$debuggers[] = $debugger;
         }
     }
 }
 public function loadConfig()
 {
     if (!Tx_Formhandler_Globals::$session) {
         $ts = $GLOBALS['TSFE']->tmpl->setup['plugin.']['Tx_Formhandler.']['settings.'];
         $sessionClass = 'Tx_Formhandler_Session_PHP';
         if ($ts['session.']) {
             $sessionClass = Tx_Formhandler_StaticFuncs::prepareClassName($ts['session.']['class']);
         }
         Tx_Formhandler_Globals::$session = $this->componentManager->getComponent($sessionClass);
     }
     $tsConfig = Tx_Formhandler_Globals::$session->get('settings');
     $this->settings = array();
     if ($tsConfig['validators.']) {
         foreach ($tsConfig['validators.'] as $idx => $settings) {
             if (is_array($settings['config.'])) {
                 $this->settings = array_merge($this->settings, $settings['config.']);
             }
         }
     }
 }