<?php
/*
    CREATIVE COMMONS - Attribution-No Derivative Works 3.0 Germany:
    - You may not alter, transform, or build upon this work.
    - Dieses Werk darf nicht bearbeitet oder in anderer Weise verändert werden.
*/
  // Pfad definieren
    $Path = str_replace('\\','/', __FILE__);
    $Path = str_replace('guestbook/guestbook_form_internal.php', '', $Path);
  // Inhalt-Anfang
    // Variablen definieren
      if (!isset($submit)) {
        if (!isset($gb_name)) $gb_name = '';
        if (!isset($gb_ort)) $gb_ort = '';
        if (!isset($gb_email)) $gb_email = '';
        if (!isset($gb_EchteURL)) $gb_EchteURL = '';
        if (!isset($gb_icq)) $gb_icq = '';
        if (!isset($gb_text)) $gb_text = '';
        if (!isset($url)) $url = ''; }
      if (!isset($gb_agreement)) $gb_agreement = '';
      $gb_ip = getRealIP(); // Bugfix: v1.2.80_112
      if (!isset($BackURL)) {
        if (!empty($_SERVER['HTTP_REFERER']))
          $BackURL = $_SERVER['HTTP_REFERER'];
        else
          $BackURL = ""; }
      $URLform = getFrontendURL('SetupGuestbookFormURL');
      $Token = md5(uniqid('Token'));
      $messageIsSpam = messageIsSpam ($gb_name, $gb_text, $gb_ip, $gb_EchteURL, $url);

  if ($messageIsSpam=="blocked-ip") {
    http_response_code(404);
    die(); }

  // Write spam log
    if ($messageIsSpam!='noSpam')
      writeSpamLog($gb_name, $gb_ort, $gb_email, $gb_EchteURL, $url, $gb_icq,
        $gb_text, $gb_ip, $messageIsSpam, 'guestbook_form' );

  echo '<div class="GigKalender"><div class="Guestbook">';
  // Formular auf Fehler überprüfen
      if
      (
           (isset($submit))
        && ($gb_name!="")
        && ($gb_text!="")
        &&
        (
          ( ($gb_email!="") && checkEmail ($gb_email) )
          OR
          ( ($gb_email=="") )
        )
        &&
        (
          ( ($gb_EchteURL!="") && checkURL ($gb_EchteURL) )
          OR
          ( ($gb_EchteURL=="http://") )
          OR
          ( ($gb_EchteURL=="") )
        )
        &&
        (
          ( ($gb_icq!="") && checkICQNumber ($gb_icq) )
          OR
          ( ($gb_icq=="") )
        )
        && (!$SetupFrontendGuestbookPrivacyPolicy || ($gb_agreement=='checked'))
        && $messageIsSpam=='noSpam'
      )
      {
        // test for time spent to fill the form
        $diff = microtime(TRUE)-$AntiSpamTimestamp;
        $diff = number_format($diff, 2, '.', '');
        if ($diff<2.5) {
          writeSpamLog($gb_name, $gb_ort, $gb_email, $gb_EchteURL, $url, $gb_icq,
            $gb_text, $gb_ip, 'form-completion-time: '.$diff.' s', 'guestbook_form');
          http_response_code(404);
          die(); }
        elseif (!isFormReload( $gb_name, $gb_text, $gb_ip )) {
          if (addGuestbookEntry($gb_name, $gb_email, $gb_EchteURL, $gb_icq, $gb_text, $gb_ip, $gb_ort))
            echo $L_126.'<br />';
          else
            echo $L_127.'<br />'; }
        else echo '<span class="ErrorMessage">'.$L_ERROR_Entry_already_exists.'</span>';
        // URL bestimmen
        $GuestbookURL = getFrontendURL('SetupGuestbookURL');
        // Back link
        echo '<br /><br /><br /><a href="'.$GuestbookURL.'">'.$L_155.'</a>';
      }
      else {
        echo '<div id="GuestbookEntryForm">
                <form method="post" action="'.$URLform.'" accept-charset="UTF-8">
                  <table>';
        // IP
          // Spamtest
            if (isset($submit) && $messageIsSpam=='ip')
              echo '<tr><td></td><td class="ErrorMessage">'.$L_120.'<br /><br /></td><td></td></tr>';
        // Name
          if (isset($submit)) {
            if (empty($gb_name))
              echo '<tr><td></td><td class="ErrorMessage">'.$L_121.'</td><td></td></tr>';
            // Spam test
            elseif (preg_match('|word-in-name:|', $messageIsSpam))
              echo '<tr><td></td><td class="ErrorMessage">'.$L_124.'</td><td></td></tr>'; }
          echo '<tr>
                  <td align="right" valign="top">'.$L_114.':</td>
                  <td><input type="text" name="gb_name" value="'.$gb_name.'" /></td>
                  <td valign="top">*</td>
                </tr>';
        // Location
          echo '<tr>
                  <td align="right" valign="top">'.$L_GuestbookLocation.':</td>
                  <td><input type="text" name="gb_ort" value="'.$gb_ort.'" /></td>
                  <td></td>
                </tr>';    
        // Email
          if (isset($submit) && !empty($gb_email) && !checkEmail($gb_email))
            echo '<tr><td></td><td class="ErrorMessage">'.$L_122.'</td><td></td></tr>';
          echo '<tr>
                  <td align="right" valign="top">'.$L_115.':</td>
                  <td><input type="text" name="gb_email" value="'.$gb_email.'" /></td>
                  <td></td>
                </tr>';
        // URL
          // Spam test
            if (isset($submit) && $messageIsSpam=='domain')
              echo '<tr><td></td><td class="ErrorMessage"><br />'.$L_128.'</td><td></td></tr>';
          //$gb_EchteURL = trim($gb_EchteURL, " "); // Bugfix v1.2.76_029
          if (isset($submit) && !empty($gb_EchteURL)) {
            if (!checkURL ($gb_EchteURL))
              if (!stristr($gb_EchteURL, "http://" ) OR !stristr($gb_EchteURL, "https://" )) { // Bugfix v1.2.78_047
                $gb_EchteURL = 'http://'.$gb_EchteURL;
                echo '<tr><td></td><td class="ErrorMessage">'.$L_ERROR_Added_missing_http_OK.'</td></tr>'; }
              else
                echo '<tr><td></td><td class="ErrorMessage">'.$L_123.'</td></tr>'; }
          echo '<tr>
                  <td align="right" valign="top">'.$L_116.':</td>
                  <td><input type="text" name="gb_EchteURL" value="'.$gb_EchteURL.'" /></td>
                  <td></td>
                </tr>';
        // Fake URL as spam trap
          echo '<tr style="display:none;">
                  <td align="right" valign="top">'.$L_117.':</td>
                  <td><input type="text" name="url" value="'.$url.'" /></td>
                  <td></td>
                </tr>';
        // ICQ
          // ICQ-Nummer überprüfen
            if (isset($submit) && !empty($gb_icq) && !checkICQNumber($gb_icq) )
              echo '<tr><td></td><td class="ErrorMessage">'.$L_164.'</td><td></td></tr>';
          echo '<tr>
                  <td align="right" valign="top">'.$L_118.':</td>
                  <td><input type="text" name="gb_icq" value="'.$gb_icq.'" /></td>
                  <td></td>
                </tr>';
        // Message
          if (isset($submit)) {
            // Spam test
            if (preg_match('|word-in-message:|', $messageIsSpam))
              echo '<tr><td></td><td class="ErrorMessage">'.$L_124.'</td><td></td></tr>';
            elseif (preg_match ('|blocked-character:|', $messageIsSpam))
              echo '<tr><td></td><td class="ErrorMessage">'.$L_ERROR_Message_contains_invalide_characters.'</td><td></td></tr>';
            // empty message
            elseif (empty($gb_text))
              echo '<tr><td></td><td class="ErrorMessage">'.$L_125.'</td><td></td></tr>'; }
          //$gb_text = htmlspecialchars(stripslashes($gb_text));
          echo '<tr>
                  <td align="right" valign="top">'.$L_119.':</td>
                  <td><textarea name="gb_text" rows="5" cols="">'.$gb_text.'</textarea></td>
                  <td valign="top">*</td>
                </tr>';
        // Privacy Policy

          if ($SetupFrontendGuestbookPrivacyPolicy) {
            if (isset($submit) && empty($gb_agreement))
              echo '<tr><td></td><td class="ErrorMessage">'.$L_ERROR_Missing_agreement.'</td></tr>';
            // Define string with link to privacy policy
              // Check if a Link can be set
                if ($SetupFrontendPrivacyPolicyURL) $Link = '<a href="'.$SetupFrontendPrivacyPolicyURL.'">'.$L_Privacy_Policy.'</a>';
                  else $Link = $L_Privacy_Policy;
              // replace variable %1 in language string with the link
                $L_Field_Agreement = str_ireplace("%1", $Link, $L_Field_Agreement);
            echo '<tr>
                    <td align="right" valign="top"></td>
                    <td>
                      <input style="width:auto" type="checkbox" name="gb_agreement" value="checked" '.$gb_agreement.'/>
                      '.$L_Field_Agreement.'
                    </td>
                   </tr>'; }
        // AntiSpamTimestamp
          if (!isset($submit)) {
            $AntiSpamTimestamp = microtime(TRUE); }
        // Button
             echo '<tr>
                  <td></td>
                  <td>
                    <input type="submit" value="'.$L_Button30.'" name="submit" class="button submitButton" />
                    <input type="button" value="'.$L_Button03.'" onclick="self.location.href=\''.$BackURL.'\'" class="button"/>
                    <input type="hidden" name="AntiSpamTimestamp" value="'.$AntiSpamTimestamp.'" />
                    <input type="hidden" name="BackURL" value="'.$BackURL.'" />
                    <input type="hidden" name="gb_page" value="form" />
                  </td>
                  <td></td>
                </tr>
              </table>
       	    </form>
          </div>';
      }
   echo '</div></div>';
?>