protected function init()
 {
     $this->settings = $this->getSettings();
     $this->formValuesPrefix = Tx_Formhandler_StaticFuncs::getSingle($this->settings, 'formValuesPrefix');
     Tx_Formhandler_Globals::$formID = Tx_Formhandler_StaticFuncs::getSingle($this->settings, 'formID');
     Tx_Formhandler_Globals::$formValuesPrefix = $this->formValuesPrefix;
     //set debug mode
     $isDebugMode = Tx_Formhandler_StaticFuncs::getSingle($this->settings, 'debug');
     $this->debugMode = intval($isDebugMode) === 1;
     $sessionClass = 'Tx_Formhandler_Session_PHP';
     if ($this->settings['session.']) {
         $sessionClass = Tx_Formhandler_StaticFuncs::prepareClassName($this->settings['session.']['class']);
     }
     Tx_Formhandler_Globals::$session = $this->componentManager->getComponent($sessionClass);
     $this->gp = Tx_Formhandler_Staticfuncs::getMergedGP();
     $randomID = $this->gp['randomID'];
     if (!$randomID) {
         $randomID = Tx_Formhandler_StaticFuncs::generateRandomID();
     }
     Tx_Formhandler_Globals::$randomID = $randomID;
     $action = t3lib_div::_GP('action');
     if (Tx_Formhandler_Globals::$formValuesPrefix) {
         $temp = t3lib_div::_GP(Tx_Formhandler_Globals::$formValuesPrefix);
         $action = $temp['action'];
     }
     if (Tx_Formhandler_Globals::$session->get('finished') && !$action) {
         Tx_Formhandler_Globals::$session->reset();
         unset($_GET[Tx_Formhandler_Globals::$formValuesPrefix]);
         unset($_GET['id']);
         Tx_Formhandler_StaticFuncs::doRedirect($GLOBALS['TSFE']->id, FALSE, $_GET);
         exit;
     }
     $this->parseConditions();
     $this->initializeDebuggers();
     $this->getStepInformation();
     $currentStepFromSession = Tx_Formhandler_Globals::$session->get('currentStep');
     $prevStep = $currentStepFromSession;
     if (intval($prevStep) !== intval($currentStepFromSession)) {
         $this->currentStep = 1;
         $this->lastStep = 1;
         Tx_Formhandler_StaticFuncs::throwException('You messed with the steps!');
     }
     $this->mergeGPWithSession(FALSE, $this->currentStep);
     $this->parseConditions();
     //read template file
     $this->templateFile = Tx_Formhandler_StaticFuncs::readTemplateFile($this->templateFile, $this->settings);
     Tx_Formhandler_Globals::$templateCode = $this->templateFile;
     $this->langFiles = Tx_Formhandler_StaticFuncs::readLanguageFiles($this->langFiles, $this->settings);
     Tx_Formhandler_Globals::$langFiles = $this->langFiles;
     $this->validateConfig();
     Tx_Formhandler_Globals::$settings = $this->settings;
     //set debug mode again cause it may have changed in specific step settings
     $this->debugMode = intval($this->settings['debug']) === 1;
     Tx_Formhandler_Globals::$session->set('debug', $this->debugMode);
     Tx_Formhandler_StaticFuncs::debugMessage('using_prefix', array($this->formValuesPrefix));
     //init view
     $viewClass = $this->settings['view'];
     if (!$viewClass) {
         $viewClass = 'Tx_Formhandler_View_Form';
     }
     Tx_Formhandler_StaticFuncs::debugMessage('using_view', array($viewClass));
     Tx_Formhandler_StaticFuncs::debugMessage('current_gp', array(), 1, $this->gp);
     $this->storeSettingsInSession();
     $this->mergeGPWithSession(FALSE, $this->currentStep);
     //set submitted
     $this->submitted = $this->isFormSubmitted();
     if (!$this->submitted) {
         $this->reset();
     }
     // set stylesheet file(s)
     $this->addCSS();
     // add JavaScript file(s)
     $this->addJS();
     Tx_Formhandler_StaticFuncs::debugMessage('current_session_params', array(), 1, (array) Tx_Formhandler_Globals::$session->get('values'));
     $viewClass = Tx_Formhandler_StaticFuncs::prepareClassName($viewClass);
     $this->view = $this->componentManager->getComponent($viewClass);
     $this->view->setLangFiles($this->langFiles);
     $this->view->setSettings($this->settings);
     Tx_Formhandler_Globals::$gp = $this->gp;
     //init ajax
     if ($this->settings['ajax.']) {
         $class = $this->settings['ajax.']['class'];
         if (!$class) {
             $class = 'Tx_Formhandler_AjaxHandler_JQuery';
         }
         Tx_Formhandler_StaticFuncs::debugMessage('using_ajax', array($class));
         $class = Tx_Formhandler_StaticFuncs::prepareClassName($class);
         $ajaxHandler = $this->componentManager->getComponent($class);
         Tx_Formhandler_Globals::$ajaxHandler = $ajaxHandler;
         $ajaxHandler->init($this->settings['ajax.']['config.']);
         $ajaxHandler->initAjax();
     }
     if (!$this->gp['randomID']) {
         $this->gp['randomID'] = Tx_Formhandler_Globals::$randomID;
     }
 }
 /**
  * Checks if the form got submitted too often and throws Exception if TRUE.
  *
  * @param int Timebase value
  * @param string Timebase unit (seconds|minutes|hours|days)
  * @param int maximum amount of submissions in given time base.
  * @param boolean add IP address to where clause
  * @return void
  */
 private function check($value, $unit, $maxValue, $addIPToWhere = TRUE)
 {
     $timestamp = Tx_Formhandler_StaticFuncs::getTimestamp($value, $unit);
     $where = 'crdate >= ' . $timestamp;
     if ($addIPToWhere) {
         $where = 'ip=\'' . t3lib_div::getIndpEnv('REMOTE_ADDR') . '\' AND ' . $where;
     }
     $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid,ip,crdate,params', $this->logTable, $where);
     if ($res && $GLOBALS['TYPO3_DB']->sql_num_rows($res) >= $maxValue) {
         $this->log(TRUE);
         $message = 'You are not allowed to send more mails because form got submitted too many times ';
         if ($addIPToWhere) {
             $message .= 'by your IP address ';
         }
         $message .= 'in the last ' . $value . ' ' . $unit . '!';
         if ($this->settings['report.']['email']) {
             while (FALSE !== ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))) {
                 $rows[] = $row;
             }
             $intervalValue = $this->settings['report.']['interval.']['value'];
             $intervalUnit = $this->settings['report.']['interval.']['unit'];
             $send = TRUE;
             if ($intervalUnit && $intervalValue) {
                 $intervalTstamp = Tx_Formhandler_StaticFuncs::getTimestamp($intervalValue, $intervalUnit);
                 $where = 'pid=' . $GLOBALS['TSFE']->id . ' AND crdate>' . $intervalTstamp;
                 if ($addIPToWhere) {
                     $where .= ' AND ip=\'' . t3lib_div::getIndpEnv('REMOTE_ADDR') . '\'';
                 }
                 $res_log = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid', $this->reportTable, $where);
                 if ($res_log && $GLOBALS['TYPO3_DB']->sql_num_rows($res_log) > 0) {
                     $send = FALSE;
                     $GLOBALS['TYPO3_DB']->sql_free_result($res_log);
                 }
             }
             if ($send) {
                 if ($addIPToWhere) {
                     $this->sendReport('ip', $rows);
                 } else {
                     $this->sendReport('global', $rows);
                 }
             } else {
                 Tx_Formhandler_StaticFuncs::debugMessage('alert_mail_not_sent', array(), 2);
             }
         }
         $GLOBALS['TYPO3_DB']->sql_free_result($res);
         if ($this->settings['redirectPage']) {
             Tx_Formhandler_StaticFuncs::doRedirect($this->settings['redirectPage'], $this->settings['correctRedirectUrl'], $this->settings['additionalParams.']);
             Tx_Formhandler_StaticFuncs::debugMessage('redirect_failed', array(), 2);
             exit(0);
         } else {
             throw new Exception($message);
         }
     }
 }