$maxwordlength) $bozo="yes";
}
// When there is missing data, display the errormessage and reprint the form
if ($name == "" || $message =="" || $bozo == "yes"){
echo $errormessage."\n";
if ($bozo = "yes") echo "Bitte die leeren Felder ausfüllen und nochmals Speichern!";
echo "
";
}
// If all the entries are correct, display thanksmessage add to datafile
else {
echo $thanksmessage."\n";
// Change % and # to percent and no, to avoid wrong splitting of the data.
$message = eregi_replace("#","no.",$message);
$message = eregi_replace("%","percent",$message);
$name = eregi_replace("#","no.",$name);
$name = eregi_replace("%","percent",$name);
// When specialchars are to be replaced...
if ($specialchars==1){
$message=htmlentities($message);
$name=htmlentities($name);
}
// When ASCII Linebreaks should become
s
if ($linebreaks==1){$message = nl2br($message);}
// When there is no datafile yet, create a new one
if (!file_exists($filelocation)) {
$newfile = fopen($filelocation,"w+");
fclose($newfile);
}
// Add the data to the end of the datafile
$newfile = fopen($filelocation,"a+");
$add = "%".$name."#".$email."#".$url."#".date("F jS Y")."#".$message."\n";
fwrite($newfile, $add);
fclose($newfile);
}
}
/*-----------------------------------------------------------------------------------------------
Introduction Screen when there is no data from the form
------------------------------------------------------------------------------------------------*/
if ($action != "view" && $action !="new"){
if ($edit=="yes"){
echo "Gästebuch ansehen
";
}
else {
echo "$entrytext
" ;
echo "
Gästebuch ansehen
Neuer Eintrag ins Gästebuch
";
}
}
// If the guestbook is displayed, show the sign Guestbook Link
if ($action == "view"){echo "Neuer Eintrag ins Gästebuch
";}
// If someone enters data, allow him to go back to the Guestbook
if ($action == "new"){echo "Gästebuch ansehen
";}
/*-----------------------------------------------------------------------------------------------
Display the guestbook
------------------------------------------------------------------------------------------------*/
if ($action=="view"){
// When there is no data file, create a new one and say there are no entries.
if (!file_exists($filelocation)) {
$newfile = fopen($filelocation,"w+");
fclose($newfile);
echo "There are no entries yet";
}
// Open the datafile and read the content
$newfile = fopen($filelocation,"r");
$content = fread($newfile, filesize($filelocation));
fclose($newfile);
// Remove the slashes PHP automatically puts before special characters
$content=stripslashes($content);
// Put the entries into the array lines
$lines = explode("%",$content);
// Define and fill the reverse array (showing the last entry first)
$rev=array();
for ($i=sizeof($lines)-1;$i>0;$i--){array_push($rev,$lines[$i]);}
$lines=$rev;
// Display all the entries of the guestbook
while(list($key)= each ($lines)){
/*
/ split the data lines into a user array
/ user[0] is the name, [1] is the email, [2] is the url [3] is the date and [4] the message
*/
$urladd="";
$mailadd="";
$user = explode("#",$lines[$key]);
// if there is an email, display an email link
if ($user[1] != ""){$mailadd="email";}
// if there is a url, display a link
if ($user[2] != ""){
// if people were dumb enough not to add http:// do so
if (substr($user[2],0,7)!= "http://"){
$user[2]="http://".$user[2];
}
$urladd="Webseite";
}
// Display the entries, here you can tweak HTML
echo "
$user[0] |
$mailadd |
$urladd |
($user[3]) |
|
$user[4] |
|
";
}
}
/*-----------------------------------------------------------------------------------------------
Add a new entry to the guestbook, display the rules and show the form.
------------------------------------------------------------------------------------------------*/
if ($action == "new"){
echo "
";
}
// If the guestbook is displayed, show the sign Guestbook Link
if ($action == "view"){echo "Neuer Eintrag ins Gästebuch
";}
// If someone enters data, allow him to go back to the Guestbook
if ($action == "new"){echo "
";}
echo "\n\n\n\n";
?>