<?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.
*/
  $Path = str_replace('\\','/', __FILE__);
  $Path = str_replace('guestbook/guestbook_mail.php', '', $Path);

  include_once ($Path."gigkalender.ini.php");
  include_once ("functions.php");
  include_once ($Path."functions/standard.php");
  include_once ($Path."includes/frontend_language_selector.php");
  
  if (isset($_POST['BackURL'])) $BackURL = $_POST['BackURL'];
        else $BackURL = '';

  $GuestbookID = $_REQUEST['id'];
  echo '<div class="GigKalender"><div class="Guestbook">';
  if (isset($_POST['message']))
  {
    $messageIsSpam = messageIsSpam ( $_POST['name'], $_POST['message'], $_SERVER['REMOTE_ADDR'], '', '');
    if ($messageIsSpam!='noSpam') writeSpamLog ( $_POST['name'], '', $_POST['email'], '', '', '', $_POST['message'], $_SERVER['REMOTE_ADDR'], $messageIsSpam, 'guestbook_mail' );
  }
  $SQLQuery = "SELECT * FROM ".$prefix."guestbook WHERE GuestbookID = '".$GuestbookID."' LIMIT 1";
  $Result = mysqli_query($db, $SQLQuery);
  while ($row = mysqli_fetch_array($Result))
  {
    extract($row);
    $Datum = DatumUndUhrzeitAusTimestamp ($Datum);
    $Name = $Name;
    $empfänger = $Email;
  }
  $Path = $_SERVER['HTTP_HOST'];
  $subject = $L_139.' '.$Path;

  if (isset($_POST['senden']) && isset($_POST['name']) && isset($_POST['email']) && ($_POST['message']!="") && checkEmail ($_POST['email']) && (messageIsSpam($_POST['name'], $_POST['message'], '', '', '')))
  {
    $MailName = $_POST['name'];
    $MailEmail = $_POST['email'];
    $MailMessage = $_POST['message'];
    $MailMessage = $L_020." ".$Name.",\n\n".$L_140." ".$Path.".\n\n".$L_141."\n\n---\n\n".$L_022." ".$MailName."\n\n".$L_026." ".$MailMessage;


    // Mail mit Header definieren
      $optheader[] = "From: ".$MailName." <".$MailEmail.">";
      $optheader[] = "Content-Type: text/plain; Charset=utf-8";
      $header = implode("\n", $optheader);

    // Mail versenden
      if ( !@mail($empfänger, $subject, $MailMessage, $header) )
        echo '<span class="ErrorMessage">'.$L_ERROR_Email_could_not_be_sent.'</span><br /><br />';
        else
          echo $L_142;
      // URL bestimmen
        if ( $SetupGuestbookURL=='' ) $URL = $BackURL;
            else $URL = $SetupGuestbookURL;
        $URL = str_replace("&","&amp;",$URL);
      echo '<br /><br /><br /><a href="'.$BackURL.'">'.$L_155.'</a>';
  }
  else
  {
    echo $L_Here_you_can_sent_a_message_to." ".$Name.":<br /><br />";
    $REQUEST_URI = str_replace("&","&amp;",$_SERVER['REQUEST_URI']);
    echo '<div id="GuestbookEntryForm">
    
    <form action="'.$REQUEST_URI.'" method="post" accept-charset="UTF-8">
      <table summary="Forumular">
    ';
    // Name
    if (isset($_POST['senden']) && ($_POST['name']==""))
    {
      echo '<tr><td></td><td class="ErrorMessage">'.$L_121.'</td><td></td></tr>';
    }
    if ( isset($_POST['name'] )) { $Name = $_POST['name']; }
    else { $Name = ''; }
    $Name = htmlspecialchars(stripslashes($Name));
    echo '
      <tr>
        <td align="right" valign="top">'.$L_114.':</td>
        <td>
          <input type="text" name="name" maxlength="40" value="'.$Name.'" />
        </td>
        <td valign="top">*</td>
      </tr>
    ';
    // Email
    if (isset($_POST['senden']) && ($_POST['email']==""))
    {
      echo '<tr><td></td><td class="ErrorMessage">'.$L_216.'</td><td></td></tr>';
    }
    if (isset($_POST['senden']) && $_POST['email']!="" && !checkEmail ($_POST['email']))
    {
      echo '<tr><td></td><td class="ErrorMessage">'.$L_122.'</td><td></td></tr>';
    }
    if ( isset($_POST['email'] )) { $Email = $_POST['email']; }
    else { $Email = ''; }    
    echo '
     <tr>
       <td align="right" valign="top">'.$L_115.':</td>
       <td>
         <input type="text" name="email" maxlength="80" value="'.$Email.'" />
       </td>
       <td valign="top">*</td>
     </tr>
    ';
    // Message
    if (isset($_POST['senden']) && preg_match ( '|word:|', $messageIsSpam ))
    { echo '<tr><td></td><td class="ErrorMessage">'.$L_124.'<br /></td><td></td></tr>'; }

    if (isset($_POST['senden']) && ($_POST['message']==""))
    {
      echo '<tr><td></td><td class="ErrorMessage">'.$L_125.'</td><td></td></tr>';
    }
    if (isset($_POST['senden']) && $messageIsSpam=='code')
      { echo '<tr><td></td><td class="ErrorMessage">'.$L_ERROR_Message_contains_invalide_characters.'</td><td></td></tr>'; }
    if ( isset($_POST['message'] )) { $Message = $_POST['message']; }
    else { $Message = ''; }
    $Message = htmlspecialchars(stripslashes($Message));
    if ($BackURL=='') $BackURL = str_replace("&","&amp;",$_SERVER['HTTP_REFERER']);
    echo '
      <tr>
        <td align="right" valign="top">'.$L_119.':</td>
        <td><textarea name="message" rows="6" cols="">'.$Message.'</textarea></td>
        <td valign="top">*</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td style="white-space : nowrap; display: inline;">
          <input type="submit" name="senden" value="'.$L_Button42.'" class="button submitButton" />
          <input type="button" value="'.$L_Button03.'" onclick="self.location.href=\''.$BackURL.'\'" class="button"/>
          <input type="hidden" name="BackURL" value="'.$BackURL.'" />
          <input type="hidden" name="gb_page" value="mail" />
          <input type="hidden" name="id" value="'.$GuestbookID.'" />
        </td>
        <td valign="top"></td>
      </tr>
      </table>
      </form></div>
    ';
  }
  echo '</div></div>';
?>