/**
  * Generating the form for new guestbook entries
  *
  * @return	string		$content : the form (HTML)
  */
 function displayForm()
 {
     if (is_array($this->LOCAL_LANG) && count($this->LOCAL_LANG) > 0) {
         $markerArray = $this->initFormMarkerArray();
         $markerArray['###PID###'] = $GLOBALS["TSFE"]->id;
         $url = $this->getUrl($GLOBALS["TSFE"]->id);
         $markerArray['###ACTION_URL###'] = htmlspecialchars($url);
         $markerArray['###FORM_ERROR###'] = '';
         $markerArray['###FORM_ERROR_FIELDS###'] = '';
         // <Frank Nägler added onErrorHook>
         if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ve_guestbook']['onErrorHook'])) {
             foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ve_guestbook']['onErrorHook'] as $_classRef) {
                 $_procObj =& t3lib_div::getUserObj($_classRef);
                 $_procObj->onErrorProcessor($error, $this);
             }
         }
         // </Frank Nägler added onErrorHook>
         $this->postvars = t3lib_div::_GP('tx_veguestbook_pi1') ? t3lib_div::_GP('tx_veguestbook_pi1') : array();
         if (isset($this->postvars['submitted']) && $this->postvars['submitted'] == 1) {
             foreach ($this->postvars as $key => $value) {
                 $value = $this->local_cObj->removeBadHTML($value, array());
                 $this->postvars[$key] = $value;
             }
             if (isset($this->postvars['homepage'])) {
                 if (!strstr($this->postvars['homepage'], 'http://') && !empty($this->postvars['homepage'])) {
                     $this->postvars['homepage'] = 'http://' . $this->postvars['homepage'];
                 }
             }
             foreach ($this->postvars as $k => $v) {
                 $markerArray['###VALUE_' . strtoupper($k) . '###'] = stripslashes($v);
             }
             $error = $this->checkForm();
             if (!empty($error)) {
                 $markerArray['###FORM_ERROR###'] = $this->pi_getLL('form_error');
                 $markerArray['###FORM_ERROR_FIELDS###'] = $error;
             } else {
                 $db_fields = array('firstname', 'surname', 'email', 'homepage', 'place', 'entry', 'entrycomment');
                 $saveData['uid'] = '';
                 $saveData['pid'] = $this->config['pid_list'];
                 $saveData['tstamp'] = time();
                 $saveData['crdate'] = time();
                 $saveData['deleted'] = '0';
                 $saveData['sys_language_uid'] = $this->sys_language_uid;
                 $saveData['remote_addr'] = $_SERVER['REMOTE_ADDR'];
                 if ($this->for_tt_news) {
                     $saveData['uid_tt_news'] = $this->tt_news['tx_news_pi1[news]'];
                 }
                 if ($this->config['manual_backend_release'] == 1) {
                     $saveData['hidden'] = '1';
                 } else {
                     $saveData['hidden'] = '0';
                 }
                 foreach ($this->postvars as $k => $v) {
                     if (in_array($k, $db_fields)) {
                         if ($this->config['allowedTags']) {
                             $v = strip_tags($v, $this->config['allowedTags']);
                         }
                         $saveData[$k] = $this->local_cObj->removeBadHTML($v, array());
                     }
                 }
                 if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ve_guestbook']['preEntryInsertHook'])) {
                     foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ve_guestbook']['preEntryInsertHook'] as $_classRef) {
                         $_procObj =& t3lib_div::getUserObj($_classRef);
                         $saveData = $_procObj->preEntryInsertProcessor($saveData, $this);
                     }
                 }
                 $insert = $GLOBALS['TYPO3_DB']->exec_INSERTquery($this->strEntryTable, $saveData);
                 if ($insert) {
                     if (!empty($this->config['notify_mail'])) {
                         $this->sendNotificationMail($this->config['notify_mail']);
                     }
                     if (!empty($this->postvars['email']) && $this->config['feedback_mail']) {
                         $this->sendFeedbackMail($this->postvars['email']);
                     }
                     if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ve_guestbook']['postEntryInsertedHook'])) {
                         foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ve_guestbook']['postEntryInsertedHook'] as $_classRef) {
                             $_procObj =& t3lib_div::getUserObj($_classRef);
                             $_procObj->postEntryInsertedProcessor($this);
                         }
                     }
                     // clear cache
                     $TCE = t3lib_div::makeInstance('t3lib_TCEmain');
                     $TCE->admin = 1;
                     // Clear cache for pages entered in TSconfig:
                     if ($this->config['clearCacheCmdOnInsert']) {
                         $commands = t3lib_div::trimExplode(',', strtolower($this->config['clearCacheCmdOnInsert']), 1);
                         $commands = array_unique($commands);
                         foreach ($commands as $commandPart) {
                             $GLOBALS['TSFE']->clearPageCacheContent_pidList($commandPart);
                         }
                     }
                     $GLOBALS['TSFE']->clearPageCacheContent_pidList($GLOBALS['TSFE']->id);
                     $GLOBALS['TSFE']->clearPageCacheContent_pidList($this->config['redirect_page']);
                     // clear index
                     if (t3lib_extMgm::isLoaded('indexed_search')) {
                         $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('phash', 'index_phash', ' data_page_id = ' . $this->config['redirect_page']);
                         if ($res) {
                             while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
                                 $phash = (int) $row['phash'];
                                 if ($phash > 0) {
                                     tx_indexedsearch_indexer::removeOldIndexedPages($phash);
                                 }
                             }
                         }
                     }
                     header('Location: ' . $this->getUrl($this->config['redirect_page']));
                 }
             }
         }
         // Pre-fill form data if FE user in logged in
         if (!$this->postvars && $GLOBALS['TSFE']->loginUser) {
             $surname_pos = strpos($GLOBALS['TSFE']->fe_user->user['name'], ' ');
             $markerArray['###VALUE_FIRSTNAME###'] = substr($GLOBALS['TSFE']->fe_user->user['name'], 0, $surname_pos);
             $markerArray['###VALUE_SURNAME###'] = substr($GLOBALS['TSFE']->fe_user->user['name'], $surname_pos + 1);
             $markerArray['###VALUE_EMAIL###'] = $GLOBALS['TSFE']->fe_user->user['email'];
             $markerArray['###VALUE_HOMEPAGE###'] = $GLOBALS['TSFE']->fe_user->user['www'];
             $markerArray['###VALUE_PLACE###'] = $GLOBALS['TSFE']->fe_user->user['city'];
         }
         $markerArray = $this->markObligationFields($markerArray);
         $this->status = 'displayForm';
         // Adds hook for processing of extra item markers
         if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ve_guestbook']['extraItemMarkerHook'])) {
             foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ve_guestbook']['extraItemMarkerHook'] as $_classRef) {
                 $_procObj =& t3lib_div::getUserObj($_classRef);
                 $markerArray = $_procObj->extraItemMarkerProcessor($markerArray, $row, $this->config, $this);
             }
         }
         $template = $this->cObj->getSubpart($this->templateCode, '###TEMPLATE_FORM###');
         if (!$GLOBALS['TSFE']->loginUser) {
             if (is_object($this->freeCap) and $this->config['captcha'] == 'sr_freecap') {
                 $markerArray = array_merge($markerArray, $this->freeCap->makeCaptcha());
                 $template = $this->cObj->substituteSubpart($template, '###CAPTCHA_INSERT###', '');
             } elseif (t3lib_extMgm::isLoaded('captcha') and $this->config['captcha'] == 'captcha') {
                 $markerArray['###CAPTCHA_IMAGE###'] = '<img src="' . t3lib_extMgm::siteRelPath('captcha') . 'captcha/captcha.php" alt="" />';
                 $template = $this->cObj->substituteSubpart($template, '###SR_FREECAP_INSERT###', '');
             } else {
                 $template = $this->cObj->substituteSubpart($template, '###SR_FREECAP_INSERT###', '');
                 $template = $this->cObj->substituteSubpart($template, '###CAPTCHA_INSERT###', '');
             }
         } else {
             $template = $this->cObj->substituteSubpart($template, '###SR_FREECAP_INSERT###', '');
             $template = $this->cObj->substituteSubpart($template, '###CAPTCHA_INSERT###', '');
         }
         $form = $this->cObj->substituteMarkerArrayCached($template, $markerArray, array(), array());
         $form = preg_replace('/###[A-Za-z_1234567890]+###/', '', $form);
         return $form;
     }
 }