<?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.
*/
  include_once ("functions.php");
  $IP = $_SERVER['REMOTE_ADDR'];
  if ( isset($_POST['senden']) ) $senden = true;
  else  $senden = false;
  if
    (
          ($senden!="")
      && ($Name!="")
      && ($Nachricht!="")
      &&
      (
        ( ($Email!="") && checkEmail ($Email) )
        OR
        ( ($Email=="") )
      )
      &&
      (
        ( ($URL!="") && checkURL ($URL) )
        OR
        ( ($URL=="http://") )
        OR
        ( ($URL=="") )
      )
//       &&
//         (
//           ( ($ICQ!="") && checkICQNumber ($ICQ) )
//           OR
//           ( ($ICQ=="") )
//         )
      && (messageIsSpam ($Name, $Nachricht, $IP, $URL, '')=='noSpam')
    )
  {
    $FormularKorrektAusgefuellt = true;
  }
  else 
  {
    $Title = '';
    $Text = '';
    $Publish = ''; 
    $FormularKorrektAusgefuellt = false;
  }

  // Überschrift ausgeben
    if ($_REQUEST['job']=='edit') { echo '<p class="Headline">'.$L_Headline44.'</p>'; }
    
  $xUserRightAddGuestbookEntries = 1;
  $xUserRightEditGuestbookEntries = 1;
  if ( $xUserRightAddGuestbookEntries OR $xUserRightEditGuestbookEntries )
  {
    // Inhalt hier einfügen
      if ( !isset($_POST['senden']) )  // Gig editieren
      {
        if (isset($_REQUEST['GuestbookID'])) { $GuestbookID = $_REQUEST['GuestbookID']; }

        else { $GuestbookID = ''; }
        $SQLQuery = "SELECT * FROM ".$prefix."guestbook WHERE GuestbookID = '$GuestbookID'";
        $Result = mysqli_query($db, $SQLQuery);
        while ($row = mysqli_fetch_array($Result))
        {
          extract($row);
          //$Name = stripslashes($Name);
          //$Ort = stripslashes($Ort);
          //$Nachricht = stripslashes($Nachricht);
          //$Kommentar = stripslashes($Kommentar);
        }
      }
      else
      {
        // Post-Variablen in Variablen speichern
          foreach ($_POST as $key => $value) {
            $$key = stripslashes($value); }
      }
      if ($FormularKorrektAusgefuellt == true) {
        // Guestbook bearbeiten
        if ($_REQUEST['job']=='edit') {
          if ($URL=="http://")
            $URL="";
          $updated = editGuestbookEntry($GuestbookID, $Name, $Email, $URL, $ICQ, $Nachricht, $Ort, $Kommentar);
          if ($updated)
            echo $L_165.'<br /><br />';
          else
            echo $L_166.'<br /><br />'; }

      echo '
        <form method="post" action="index.php?submenue=guestbook&content=backend_showAllGuestbookEntries" accept-charset="UTF-8">
          <fieldset>
            <input type="submit" value="'.$L_Button26.'" class="button" />
          </fieldset>
        </form>';
      }
      else
      {
        // Post-Variablen in Variablen speichern
          foreach ($_POST as $key => $value) $$key = stripslashes($value);
        echo '
          <form method="post" action="index.php?submenue=guestbook&amp;content=backend_addGuestbookEntry&amp;job='.$_REQUEST['job'].'" accept-charset="UTF-8">
      	   <table summary="AddGuestbookEntry">
            ';
            // Name
              if ($senden!="" && $Name=="")
              { echo '<tr><td></td><td class="ErrorMessage">'.$L_121.'</td><td></td></tr>'; }
              $Name = htmlspecialchars($Name);
              echo '<tr>
                  <td align="right" valign="top">'.$L_114.':</td>
                  <td><input type="text" name="Name" value="'.$Name.'" /></td>
                  <td valign="top">*</td>
                </tr>';
            // Ort
              $Ort = htmlspecialchars($Ort);
              echo '<tr>
                  <td align="right" valign="top">'.$L_GuestbookLocation.':</td>
                  <td><input type="text" name="Ort" value="'.$Ort.'" /></td>
                  <td valign="top">&nbsp;</td>
                </tr>';
            // Email
              if ($senden!="" && $Email && !checkEmail ($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="Email" value="'.$Email.'" /></td>
                      <td valign="top">&nbsp;</td>
                    </tr>';
            // Echte URL
              $IP = $_SERVER['REMOTE_ADDR'];
              // Spamtest
                if ($senden!="" && messageIsSpam ($Name, $Nachricht, $IP, $URL, $URL)=='domain')
                { echo '<tr><td></td><td class="ErrorMessage"><br />'.$L_128.'</td><td></td></tr>'; }
              //if ( $URL == "") { $URL = "http://"; }
              //if ( !stristr($URL, "http://" ) ) { $URL = "http://".$URL; }
              if ($senden!="" && $URL && !checkURL ($URL))
              { 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="URL" value="'.$URL.'" /></td>
                  <td valign="top">&nbsp;</td>
                </tr>';
            // ICQ
              // ICQ-Nummer überprüfen
                
//                 if ($senden!="" && $ICQ && !checkICQNumber($ICQ) )
//                 { echo '<tr><td></td><td class="ErrorMessage">'.$L_164.'</td><td></td></tr>'; }
//                 if ( $ICQ=='0' ) $ICQ='';
//               echo '<tr>
//                       <td align="right" valign="top">'.$L_118.':</td>
//                       <td><input type="text" name="ICQ" value="'.$ICQ.'" /></td>
//                       <td valign="top">&nbsp;</td>
//                     </tr>';
            echo '<input type="hidden" name="ICQ" value="'.$ICQ.'" />';
            // Nachricht
              // Spamtest
                if ($senden!="" && messageIsSpam ($Name, $Nachricht, $IP, $URL, $URL)=='word')
                { echo '<tr><td></td><td class="ErrorMessage">'.$L_124.'</td><td></td></tr>'; }
              if ( $senden && !$Nachricht )
              { echo '<tr><td></td><td class="ErrorMessage">'.$L_125.'</td><td></td></tr>'; }
              $Nachricht = htmlspecialchars($Nachricht);
              echo '<tr>
                      <td align="right" valign="top">'.$L_119.':</td>
                      <td><textarea name="Nachricht" rows="5" cols="">'.$Nachricht.'</textarea></td>
                      <td valign="top">*</td>
                    </tr>';
            // Kommentar
              $Kommentar = htmlspecialchars($Kommentar ?? ''); // Bugfix v1.2.83_097
              echo '<tr>
        		          <td align="right" valign="top">'.$L_138.':</td>
        		          <td><textarea name="Kommentar" rows="6" cols="">'.$Kommentar.'</textarea></td>
        		          <td valign="top">&nbsp;</td>
      		          </tr>';



          // Button
          echo '
        	   <tr>
              <td></td>
              <td>
                <input type="submit" name="senden" value="'.$L_Button01.'" class="button" />
                <input type="button" value="'.$L_Button03.'" onclick="history.go(-1)" class="button" />
                <input type="hidden" name="GuestbookID" value="'.$GuestbookID.'" />
              </td>
        	   </tr>
      	   </table>
    	 </form>
        ';
      }
    // Inhalt zuende
  }
  else
  { echo $L_015; }
?>