<?php
include('gbook/config.php');

$select = "SELECT * FROM ".$prefix."config WHERE id='1'";
$query = mysql_query($select);
$result = mysql_fetch_array($query);

$result['header'] = stripslashes($result['header']);
$lenght = stripslashes($result['lenght']);
$url = stripslashes($result['url']);
$result['bgfarbe'] = stripslashes($result['bgfarbe']);

$result['header'] = str_replace(":css:",stripslashes($result['css']),$result['header']);
@eval("?>".$result['header']."<?");        // Header Ausgabe
echo "<body bgcolor=\"".$result['bgfarbe']."\">";

function smilies($text) {
        $smilies = array(
        ":)=>smile.gif",
        ":D=>biggrins.gif",
        ";)=>zwinker.gif",
        ":sleep:=>sleep.gif",
        ":frage:=>frage.gif",
        "8)=>sun.gif",
        ":king:=>king.gif",
        ":deal:=>deal.gif",
        ":(=>mad.gif",
        ":{=>brb.gif",
        ":camper:=>camper.gif",
        ":sex:=>sex.gif",
        ":chainsaw:=>chainsaw.gif",
        ":heavymetal:=>heavymetal.gif",
        ":teddy:=>teddy.gif",
        ":computer:=>computer.gif",
        ":mecker:=>mecker.gif");

        for($i=0; $i<count($smilies); $i++) {
                $smily = explode("=>", $smilies[$i]);
                $text = str_replace($smily[0], "<img src=\"gbook/gfx/".$smily[1]."\">", $text);
        }
        return $text;
}

function lenght($text) {
        global $lenght;
        $text = str_replace("<", " <", $text);
        $textarray = explode(" ", $text);
        $j = count($textarray);
        $i = 0;
        $text = "";
        while ($i < $j) {
                $laenge = 0;
                $laenge = strlen($textarray[$i]);
                if($laenge > $lenght) $teil = chunk_split($textarray[$i], $lenght, " ");
                else $teil = $textarray[$i]." ";
                $text .= $teil;
                $i++;
        }
        return $text;
}

/* Eintrag hinzufügen */
if($addlog == "submit") {
        $c_time = time();
        $last_ip_q = mysql_query("SELECT * FROM ".$prefix."config WHERE id='1'");
        $last_ip = mysql_fetch_array($last_ip_q);
        $time = $c_time - $last_ip['time'];
        if(!$cur_ip = $HTTP_X_FORWARDED_FOR) $cur_ip = getenv(REMOTE_ADDR);

        if(empty($inhalt) OR empty($name) OR empty($code)) {
                echo "<div align=\"center\"><p><b>F&uuml;llen sie bitte die Pflichtfelder <i>Name</i>, <i>Inhalt</i> und <i>Controllcode</i> aus.</b></p></div>";

        }

        elseif(!empty($icq) AND !is_numeric($icq)) {
                echo "<div align=\"center\"><p><b>Falsche ICQ!</b></p></div>";


        } elseif($code != "7856") {
                echo "<div align=\"center\"><p><b>Controllcode falsch!</b></p></div>";

        } else {
                if($last_ip['lastip'] == $cur_ip AND $time < 120) {                // 2 Minuten Reload-Sperre
                        echo "<div align=\"center\"><p><b>Reload-Sperre</b></p></div>";
                } else {
                        mysql_query("UPDATE ".$prefix."config SET lastip='$cur_ip', time='$c_time' WHERE id='1'");
                        $inhalt = addslashes(chop($inhalt));
                        $name = addslashes(chop($name));
                        $email = addslashes(chop($email));
                        $homepage = addslashes(chop($homepage));
                        $icq = addslashes(chop($icq));
                        $datum = addslashes(date("d.m.y H:i"));
                        $sqlbefehl = "INSERT INTO ".$prefix."book (inhalt,name,email,homepage,icq,datum) VALUES ('$inhalt','$name','$email','$homepage','$icq','$datum')";
                        $query = mysql_query($sqlbefehl);
                        echo "<div align=\"center\"><p><b>hinzugef&uuml;gt</b></p></div>";
                }
        }
}

$select = "SELECT * FROM ".$prefix."config WHERE id='1'";
$query = mysql_query($select);
$result = mysql_fetch_array($query);

$result['welcome'] = stripslashes(nl2br($result['welcome']));
$result['smileys'] = stripslashes($result['smileys']);
?>
<div align="center">
<?
echo $result['welcome'];

/* Einträge vorhanden - Ausgabe */
$gesamt = mysql_result(mysql_query("SELECT COUNT(*) FROM ".$prefix."book"),0);
if($gesamt != 1) echo "<p>Es sind ".$gesamt." G&auml;stebucheintr&auml;ge vorhanden.</p>";
else echo "<p>Es ist ".$gesamt." G&auml;stebucheintrag vorhanden.</p>";
?>
<script language="JavaScript" type="text/javascript">
function cursor() {
        if (( navigator.userAgent.indexOf("Opera" ) != -1) || ( navigator.userAgent.indexOf("Netscape" ) != -1)) {
                text_before = document.entryadd.inhalt.value;
                text_after = "";
        } else {
                document.entryadd.inhalt.focus();
                var sel = document.selection.createRange();
                sel.collapse();
                var sel_before = sel.duplicate();
                var sel_after = sel.duplicate();
                sel.moveToElementText(document.entryadd.inhalt);
                sel_before.setEndPoint("StartToStart",sel);
                sel_after.setEndPoint("EndToEnd",sel);
                text_before = sel_before.text;
                text_after = sel_after.text;
        }
}
function insert(AddCode) {
        cursor();
        document.entryadd.inhalt.value = text_before + AddCode + text_after;
        document.entryadd.inhalt.focus();
}

function init(thisCode) {
        with ( document.entryadd.inhalt.value ) {
                insert(" "+thisCode+" ");
                document.entryadd.inhalt.focus();
        }
}
</script>
<br>
  <form name="entryadd" method="post" action="">
  <table width="381" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td width="108"><b><span style="font-size: 8pt">Name</span></b></td>
      <td width="276">
        <span style="font-size: 8pt">
        <input type="text" name="name" size="20">
      </span>
      </td>
    </tr>
    <tr>
      <td width="108"><b><span style="font-size: 8pt">Email:</span></b></td>
      <td width="276">
        <span style="font-size: 8pt">
        <input type="text" name="email" size="20">
      </span>
      </td>
    </tr>
    <tr>
      <td width="108"><b><span style="font-size: 8pt">Homepage:</span></b></td>
      <td width="276">
        <span style="font-size: 8pt">
        <input type="text" name="homepage" size="20" value="http://">
      </span>
      </td>
    </tr>
    <tr>
      <td width="108"><b><span style="font-size: 8pt">Icq:</span></b></td>
      <td width="276">
        <span style="font-size: 8pt">
        <input type="text" name="icq" size="20">
      </span>
      </td>
    </tr>
    <tr>
      <td width="108" valign="top"><b><span style="font-size: 8pt">Inhalt:</span></b></td>
      <td width="276">
        <span style="font-size: 8pt">
        <textarea name="inhalt" cols="32" rows="7" wrap="virtual"></textarea>
              </span>
      </td>
    </tr>

    <tr>
      <td width="108" valign="top"><b><span style="font-size: 10pt">Controllcode:</span></b></td>
      <td width="276"><b><span style="font-size: 10pt"><strong>Controllcode "7856" eintragen:</strong></span></b>
        <br>
        <span style="font-size: 8pt">
        <input type="text" name="code" size="20">
              </span>
      </td>
    </tr>


    <tr>
      <td width="108" valign="top">
        <b>
        <span style="font-size: 8pt">
        </i></span></b></td>
      <td width="276" valign="bottom">
        <span style="font-size: 8pt">
        <input type="submit" name="submit" value="submit">
        <input type="reset" name="reset" value="reset">
        <input type="hidden" name="addlog" value="submit">
              </span>
      </td>
    </tr>
    <tr>
      <td width="108" height="19" valign="top"> &nbsp;</td>
      <td height="19" valign="bottom">
              &nbsp;</td>



    </tr>
    <tr>
      <td width="108" height="43" valign="top"> <b><span style="font-size: 8pt">Smileys:</span></b></td>
      <td height="43" valign="bottom">
              <a href="javascript:init(':)')">                <span style="font-size: 8pt">                <img src="gbook/gfx/smile.gif" alt=" :) " border="0"></span></a><span style="font-size: 8pt">
        <a href="javascript:init(':(')">                <img src="gbook/gfx/mad.gif" alt=" :( " border="0"></a>
        <a href="javascript:init(':D')">                <img src="gbook/gfx/biggrins.gif" alt=" :D " border="0"></a>
        <a href="javascript:init(';)')">                <img src="gbook/gfx/zwinker.gif" alt=" ;) " border="0"></a>
        <a href="javascript:init('8)')">                <img src="gbook/gfx/sun.gif" alt=" 8) " border="0"></a>
        <a href="javascript:init(':frage:')">        <img src="gbook/gfx/frage.gif" alt=" :frage: " border="0"></a>
        <a href="javascript:init(':{')">                <img src="gbook/gfx/brb.gif" alt=" :{ " border="0"></a>
        <a href="javascript:init(':teddy:')">                <img src="gbook/gfx/teddy.gif" alt=" :teddy: " border="0"><br></a>
        <a href="javascript:init(':sleep:')">                <img src="gbook/gfx/sleep.gif" alt=" :sleep: " border="0"></a>
        <a href="javascript:init(':sex:')">                <img src="gbook/gfx/sex.gif" alt=" :sex: " border="0"></a>
        <a href="javascript:init(':mecker:')">                <img src="gbook/gfx/mecker.gif" alt=" :mecker: " border="0"></a>
        <a href="javascript:init(':king:')">                <img src="gbook/gfx/king.gif" alt=" :king: " border="0"></a>
        <a href="javascript:init(':heavymetal:')">                <img src="gbook/gfx/heavymetal.gif" alt=" :heavymetal: " border="0"><br></a>
        <a href="javascript:init(':email:')">                <img src="gbook/gfx/email.gif" alt=" :email: " border="0"></a>
        <a href="javascript:init(':edit:')">                <img src="gbook/gfx/edit.gif" alt=" :edit: " border="0"></a>
        <a href="javascript:init(':deal:')">                <img src="gbook/gfx/deal.gif" alt=" :deal: " border="0"></a>
        <a href="javascript:init(':computer:')">              <img src="gbook/gfx/computer.gif" alt=" :computer: " border="0"></a>
        <a href="javascript:init(':chainsaw:')">                <img src="gbook/gfx/chainsaw.gif" alt=" :chainsaw: " border="0"></a>
        <a href="javascript:init(':camper:')">                <img src="gbook/gfx/camper.gif" alt=" :camper: " border="0"></a>

        </span>

        </td>



    </tr>
  </table>
  </form>
<br>
<?
if(!isset($_GET['start'])) {
        $start = 0;
} else {
        $start = $_GET['start'];
}

$select = "SELECT * FROM ".$prefix."config WHERE id='1'";
$query = mysql_query($select);
if($result = mysql_fetch_array($query)) {
        $entrysperpage = stripslashes($result['entrysperpage']);
        $smileys = stripslashes($result['smileys']);
}

if(!isset($start)) {
        $id = $gesamt;
} else {
        $id = $gesamt - $start;
}

$select = "SELECT * FROM ".$prefix."book ORDER BY id DESC LIMIT $start, $entrysperpage";
$query = mysql_query($select);
while ($result = mysql_fetch_array($query)) {
        $select2 = "SELECT * FROM ".$prefix."badwords";
        $query2 = mysql_query($select2);
        while ($word = mysql_fetch_array($query2)) {
                $word['word'] = stripslashes($word['word']);
                $word['newword'] = stripslashes($word['newword']);
                $result['inhalt'] = str_replace($word['word'],$word['newword'],$result['inhalt']);
        }
        $select3 = "SELECT * FROM ".$prefix."config WHERE id='1'";
        $query3 = mysql_query($select3);
        $table = mysql_fetch_array($query3);
        $table['entrytable'] = stripslashes($table['entrytable']);
        if($smileys == "on") {
                $result['inhalt'] = str_replace("[b]","<b>",$result['inhalt']);
                $result['inhalt'] = str_replace("[/b]","</b>",$result['inhalt']);
                $result['inhalt'] = str_replace("[i]","<i>",$result['inhalt']);
                $result['inhalt'] = str_replace("[/i]","</i>",$result['inhalt']);
                $table['entrytable'] = str_replace(":inhalt:",smilies(lenght(stripslashes(nl2br($result['inhalt'])))),$table['entrytable']);
        } else {
                $result['inhalt'] = str_replace("[b]","",$result['inhalt']);
                $result['inhalt'] = str_replace("[/b]","",$result['inhalt']);
                $result['inhalt'] = str_replace("[i]","",$result['inhalt']);
                $result['inhalt'] = str_replace("[/i]","",$result['inhalt']);
                $table['entrytable'] = str_replace(":inhalt:",lenght(stripslashes(nl2br($result['inhalt']))),$table['entrytable']);
        }

        $table['entrytable'] = stripslashes($table['entrytable']);
        $table['entrytable'] = str_replace(":mail:",stripslashes($result['email']),$table['entrytable']);
        $table['entrytable'] = str_replace(":id:",stripslashes($id),$table['entrytable']);
        $table['entrytable'] = str_replace(":name:",stripslashes($result['name']),$table['entrytable']);
        $table['entrytable'] = str_replace(":datum:",stripslashes($result['datum']),$table['entrytable']);
        if($result['homepage'] != "") {
                $table['entrytable'] = str_replace(":homepage:",stripslashes($result['homepage']),$table['entrytable']);
        }
        if($result['icq'] != "") {
                $result['icq'] = stripslashes($result['icq']);
                $icq = "<a href=\"http://wwp.icq.com/scripts/search.dll?to=".$result['icq']."\">".$result['icq']." <img src=\"http://wwp.icq.com/scripts/online.dll?icq=".$result['icq']."&img=5\" border=\"0\"></a>";
                $table['entrytable'] = str_replace(":icq:",$icq,$table['entrytable']);
        } else {
                $table['entrytable'] = str_replace(":icq:","N/A",$table['entrytable']);
        }
?>
<br>
<br>
<?
        eval("?>".$table['entrytable']."<?");
?>
<br>
<?
        $id--;
}
echo "<br>";
if($gesamt % $entrysperpage == 0) {
        $la = $gesamt / $entrysperpage;
} else {
        $la = ceil($gesamt / $entrysperpage);
}
echo "| ";
for($x = 1; $x <= $la; $x++) {

        $n_sv = $x*$entrysperpage-$entrysperpage;

?>
<a href="index2.php?section=gbook&start=<?= $n_sv ?>"><?= $x ?></a> |
<?php
}
?>