<?php
$gb="gastenboek_db.txt";
$status=$_GET['status'];
if($status=='')
{
$aantal=count($file)-1;
$splitteken=$_GET['split'];
$file=file($gb);
echo "<center>";
$van=count($file)-1;
$x=$van;
$tot=$van-4;
$y=$tot;
$b=0;
if($_GET['p']){
list($van,$tot)=split("-",$_GET['p']);
}
for($i=0; $i < count($file); $i++){
if($x > 0){
$b++;
if($x==$van){
$line.=" | <B>".$b."</b> | ";
} else {
$line.=" | <a href='gastenboek.php?p=".$x."-".$y."'>".$b."</a> | ";
}
$x=$x-5;
$y=$y-5;
}
}
for($i=$van; $i >= $tot; $i--)
{
list($naam,$email,$bericht,$datum)=split("\|","$file[$i]");
$bericht=stripslashes($bericht);
$bericht=eregi_replace(":D","<img src='smilies/bigsmile.gif' alt=':D'>",$bericht);
$bericht=eregi_replace(":s","<img src='smilies/wacko.gif' alt=':S'>",$bericht);
$bericht=eregi_replace(":@","<img src='smilies/mad.gif' alt=':@'>",$bericht);
$bericht=eregi_replace(":p","<img src='smilies/toung.gif' alt=':p'>",$bericht);
$bericht=eregi_replace(":o","<img src='smilies/amazed.gif' alt=':o'>",$bericht);
$bericht=eregi_replace("\(h\)","<img src='smilies/cool.gif' alt=''>",$bericht);
$bericht=eregi_replace(":'\(","<img src='smilies/cry.gif' alt=''>",$bericht);
$bericht=eregi_replace(":)","<img src='smilies/smile.gif' alt=''>",$bericht);
$bericht=eregi_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]","<a href='\\0' target=_blank>\\0</a>",$bericht);
echo "<table width=350 style='height:130'>";
$email=str_replace(" ","",$email);
if($email){
echo "<tr><td><a href='mailto:$naam <$email> ?subject=reaktie Gastenboek scriptkiddies.nl'>$naam</a></td><td align=right>$datum</td></tr>";
}
else
{
echo "<tr><td><font color=blue>$naam</a></td><td align=right>$datum</td></tr>";
}
echo "<tr><td colspan=2>$bericht</td></tr>";
echo "<tr><td colspan=2><hr NOSHADE=NOSHADE SIZE=1></td></tr>";
echo "</table>\n \n";
}
echo $line." <BR>";
echo "<BR><a href='gastenboek.php?status=schrijven'>Teken gastenboek</a>\n </center>";
}
if($status=='save')
{
$controle="ok";
if($email){
if(eregi("@",$email) && eregi("\.",$email)){
$controle="ok";
} else {
$controle="error";
}
}
if((strlen($naam) > 1) && (strlen($bericht) > 5) && $controle=="ok"){
$naam=htmlentities($_POST['naam']);
$email=htmlentities($_POST['email']);
$bericht=htmlentities($_POST['bericht']);
$bericht=nl2br($bericht);
$bericht=str_replace("\n","",$bericht);
$bericht=str_replace("\r","",$bericht);
$email=str_replace("@","@",$email);
$bericht=str_replace("|",":",$bericht);
$email=str_replace("|",":",$email);
$naam=str_replace("|",":",$naam);
$datum=date("H:i:s d-m-Y");
$fp=fopen("gastenboek.txt","a");
fwrite($fp,"".$naam." | ".$email." | ".$bericht." | ".$datum." | ". $REMOTE_ADDR ."\n");
fclose($fp);
echo "<script>window.location='gastenboek.php'</script><a href='gastenboek.php'>Klik hier als je niet word doorgestuurt</a>";
}
else
{
echo "Er is een fout opgetreden, dit ligt aan het volgende:<BR>";
echo "- Naam was te kort.<BR>";
echo "- Bericht was te kort.<BR>";
echo "- E-mail adres klopt niet, email is niet verplicht.<BR>";
}
}
if($status=='schrijven')
{
?>
<center>
<form action='gastenboek.php?status=save' method=post>
<table>
<tr>
<td>Naam:</td>
<td><input type=text name=naam></td>
</tr>
<tr>
<td>Email:</td>
<td><input type=text name=email></td>
</tr>
<tr><td colspan=2>Bericht:</td></tr>
<tr><td colspan=2><textarea name=bericht rows=5 cols=50></textarea></td></tr>
<tr><td colspan=2><input type=submit value='schrijf'></td></tr>
</table>
</form>
</center>
<?php
}
?>