<?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.
*/
  if (IsUserAdmin()) {
    $UserIsAdmin = '1'; }
  else {
    $UserIsAdmin = '0'; }
  $EntriesPerPage = getSetup('SetupGuestbookEntriesPerPage');
  $NumberOfEntries = AnzahlEintraege();
  $NumberOfPages = ceil($NumberOfEntries/$EntriesPerPage);
  echo '<div class="GigKalender"><div class="Guestbook">';
  if ($NumberOfEntries!=0) // Einträge vorhanden
  {
    if (isset($_REQUEST['gb_page'])
      AND is_numeric($_REQUEST['gb_page'])
      AND $_REQUEST['gb_page']<=$NumberOfPages AND $_REQUEST['gb_page']>=1) // Bugfix v1.2.76_014
      { $CurrentPage = $_REQUEST['gb_page']; }
    else { $CurrentPage=$NumberOfPages; } // $NumberOfPages for DESC sorting in pagination, 1 for ASC

    $TopEntry  = ($NumberOfPages-$CurrentPage)*$EntriesPerPage;

    // Datensatz-Ausgabe festlegen
      $SQLQuery = "SELECT * FROM ".$prefix."guestbook order by Datum DESC LIMIT ".$TopEntry.", ".$EntriesPerPage;
    // Sämtliche Datensatz-Ausgabe durchfuehren
      $Result = mysqli_query($db, $SQLQuery);

    $GuestbookFrontendPagination = getGuestbookFrontendPagination();
    echo $GuestbookFrontendPagination;

    $CurrentEntry = $NumberOfEntries-$TopEntry;

    while ( $row = mysqli_fetch_array($Result)) {
      extract($row);
      echo '<div class="GuestbookEntry">
              <h2 class="GuestbookEntryHeadline">
                <span class="GuestbookEntryDate">'; 
      if ($UserIsAdmin=='1' && $CODE!='') {
        echo '<span class="ErrorMessage">IP: '.$IP.'</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
        echo '<a href="'.$GigKalenderPath.'guestbook/guestbook_edit.php?code='.$CODE.'"><img src="'.PATH.'frontend/images/guestbook_edit.png" alt="'.$L_010.'" title="'.$L_010.'" /></a> ';
        echo '<a href="'.$GigKalenderPath.'guestbook/guestbook_delete.php?code='.$CODE.'"><img src="'.PATH.'frontend/images/guestbook_delete.png" alt="'.$L_009.'" title="'.$L_009.'" /></a> ';
      }
      echo '['.date($SetupFrontendGuestbookDateFormat, $Datum).']</span> '.$CurrentEntry.'. '.$Name.' ';
      if ($Ort!="")
        echo $L_152.' '.$Ort.' ';
      echo '&nbsp;';
      if ($URL!="") echo ' <a href="'.$URL.'"><img src="'.PATH.'frontend/images/guestbook_url.png" alt="" /></a> ';
      if ($Email!="") {
        $FormActionURL = getFrontendURL ( 'SetupGuestbookEmailURL' );
        $FormActionURL .= 'gb_page=mail&id='.$GuestbookID;
        echo '<form style="display:inline" id="form'.$GuestbookID.'" method="post" action="'.$FormActionURL.'" accept-charset="UTF-8">
                              <p style="display:inline">
                                <input type="hidden" name="gb_page" value="mail" />
                                <input type="hidden" name="id" value="'.$GuestbookID.'" />
                                <a href="'.$FormActionURL.'" onclick="javascript:document.forms[\'form'.$GuestbookID.'\'].submit()"><img src="'.PATH.'frontend/images/guestbook_email.png" alt="" /></a>
                              </p>
                            </form>'; }

      //if ($ICQ!="0" AND $ICQ!="") echo ' <a href="http://people.icq.com/people/about_me.php?uin='.$ICQ.'"><img src="'.PATH.'frontend/images/guestbook_icq.png" alt="" /></a> ';
      echo '</h2>
          <div class="GuestbookEntryText">';
        $Nachricht = nl2br($Nachricht);
        echo $Nachricht;
        echo '
      </div>';
      if ($Kommentar!="") {
        echo '<div class="GuestbookEntryComment">'.$L_138.': ';
        echo nl2br($Kommentar);
        echo '</div>'; }
      echo '</div>';
      $CurrentEntry--;
    }
    echo $GuestbookFrontendPagination;
  }
  else // Keine Einträge vorhanden
  {
    // URL bestimmen
      if ($SetupGuestbookFormURL=='') {
        if (isset($_SERVER['REDIRECT_URL']))
          $REDIRECT_URL = $_SERVER['REDIRECT_URL'];
        else
          $REDIRECT_URL = '';
        $URL = $REDIRECT_URL.'?gb_page=form'; }
      else
        $URL = $SetupGuestbookFormURL;
      $URL = str_replace("&","&amp;",$URL);
    echo $L_144.'<br /><br />';
    echo '[ <a href="'.$URL.'"><img src="'.PATH.'frontend/images/guestbook_form.png" alt="" /></a> <a href="'.$URL.'">'.$L_112.'</a> ]';
  }
  echo '</div></div>';
?>