<?php
/* Connecting */
#####################
// Daten
######################
@mysql_connect($host, $user, $pass) OR die(mysql_error());
@mysql_select_db($db) OR die("ERROR\n".mysql_error());
/* ENDE Connecting */
echo '<h1>Gästebuch</h1>
      <span style="float:right; margin-bottom:5px;">
       <a style="margin-bottom:5px;" href="index.php?site=gb_add">Eintrag erstellen</a>
      </span>';
    
// Auslesen der Einträge
$sql = "SELECT
            Name,
            Datum,
            Email,
            Homepage,
            Inhalt,
            Kommentar,
            ID
        FROM
            gaestebuch
        ORDER BY
            Datum DESC";
$result = mysql_query($sql) OR die(mysql_error());
// Ausgeben der Anzahl von Einträgen
echo'Einträge im Gästebuch: '.mysql_num_rows($result)."\n".
     '<div style="border:0px; border-bottom:1px solid black; width:100%; height:1%; margin-top:5px;"></div>'."\n";
while($row = mysql_fetch_assoc($result))
{
 echo '<div>'."\n".
      '<div style="font-weight:bold; vertical-align:middle; margin-top:5px;">'."\n".
      '<img src="http://www.html.de/images/icons/post.gif" style="vertical-align:middle; width:14px; height:13px; border:0px;" alt="Post von '.$row['Name'].'" /> '.$row['Name'].' schrieb um '.$row['Datum']."\n".
      '</div>'."\n".
      '<div style="clear:both; display:block;">'."\n";
       // Smiley umwandlung 
       $smiley = nl2br($row['Inhalt']);
       $smiley = str_replace(":)", "<img src=\"http://www.html.de/images/gbook/smile.gif\">", $smiley);
       $smiley = str_replace(";)", "<img src=\"http://www.html.de/images/gbook/wink.gif\">", $smiley);
       $smiley = str_replace(":D", "<img src=\"http://www.html.de/images/gbook/laughing.gif\">", $smiley);
       $smiley = str_replace(":P", "<img src=\"http://www.html.de/images/gbook/tongue.gif\">", $smiley);
       $smiley = str_replace(":O", "<img src=\"http://www.html.de/images/gbook/wassat.gif\">", $smiley);
       $smiley = str_replace(":S", "<img src=\"http://www.html.de/images/gbook/sad.gif\">", $smiley);
       $smiley = str_replace(":(", "<img src=\"http://www.html.de/images/gbook/angry.gif\">", $smiley);
       $smiley = str_replace(":Q", "<img src=\"http://www.html.de/images/gbook/crying.gif\">", $smiley);
       $smiley = str_replace(":smile:", "<img src=\"http://www.html.de/images/gbook/smile.gif\">", $smiley);
       $smiley = str_replace(":wink:", "<img src=\"http://www.html.de/images/gbook/wink.gif\">", $smiley);
       $smiley = str_replace(":laughing:", "<img src=\"http://www.html.de/images/gbook/laughing.gif\">", $smiley);
       $smiley = str_replace(":tongue:", "<img src=\"http://www.html.de/images/gbook/tongue.gif\">", $smiley);
       $smiley = str_replace(":wassat:", "<img src=\"http://www.html.de/images/gbook/wassat.gif\">", $smiley);
       $smiley = str_replace(":sad:", "<img src=\"http://www.html.de/images/gbook/sad.gif\">", $smiley);
       $smiley = str_replace(":angry:", "<img src=\"http://www.html.de/images/gbook/angry.gif\">", $smiley);
       $smiley = str_replace(":crying:", "<img src=\"http://www.html.de/images/gbook/crying.gif\">", $smiley);
       function bild($url = false)
       {
        if(!$url)
        {
         return false;
        }
        list($width,$height,$type) = getimagesize($url);
        if(max($width,$height) > 300)
        {
         return('Ihr Bild "'.$url.'" ist zu groß! Maximale Größe: 300x300px');
        }
        return('<img src="'.$url.'" alt="" style="width: '.$width.';height:'.$height.';border:0;" />');
       }
       $smiley = preg_replace("%\[img\](.*)\[\/img]%isUe","bild('$1')",$smiley);
       $smiley = preg_replace("%\[url\](.*)\[\/url]%isU", "<a href=\"http://$1\">$1</a>",$smiley);
 echo '<br />'.$smiley."\n";
       // Kommentar vom Admin checken
       if(trim($row['Kommentar'] != ""))
       {
        echo '  <div style="font-size:9px; margin-top:15px; margin-bottom:15px;"><i><b>Admin Kommentar:</b></i><br />'.nl2br($row['Kommentar']).'</div>';
       }
       // Email abchecken
       if(trim($row['Email']) == '')
       {
        echo '';
       }
       else
       {
        echo '<a href="mailto:'.$row['Email'].'" alt="Email von '.$row['Name'].'"><img src="http://www.html.de/images/icons/kontakt.gif" style="width:16px; height:16px; border:0px;" alt="Homepage von '.$row['Name'].'" /></a>'."\n";
       }
       // Homepage abchecken
       if(trim($row['Homepage']) != '')
       {
        if(strtolower(substr($row['Homepage'], 0, 7)) == 'http://')
        {
         echo ' <a href="'.$row['Homepage'].'"><img src="http://www.html.de/images/icons/home.gif" style="width:16px; height:16px; border:0px;" alt="Homepage von '.$row['Name'].'" /></a> ';
        }
        else
        {
         echo ' <a href="http://'.$row['Homepage'].'"><img src="http://www.html.de/images/icons/home.gif" style="width:16px; height:16px; border:0px;" alt="Homepage von '.$row['Name'].'" /></a> ';
        }
       }
 echo'<div style="float:right; margin-bottom:5px;"><a style="text-decoration:none;" href="index.php?site=#top"><img src="http://www.html.de/images/icons/top.gif" style="width:7px; height:8px; border:0px;" alt="" /> Nach oben</a></div>';
 echo'<div style="width:100%; height:1px; border:0px; border-bottom:1px solid #000000; margin-bottom:7px; margin-top:20px;"></div>'."\n".
     '</div>'."\n".
    '</div>';
}
?>