Kiitti hei $name hirveesti!
"; // The message to display, if there is an error $errormessage="

Oops! You seem to have forgotten either your name or the message!
"; // Defines, if special characters should be converted to their html equivalents like > to > // 1 enables and 0 disables this feature $specialchars=1; // Defines, if Ascii linebreaks (people pressing enter while filling the form should become // html linebreaks
// 1 enables and 0 disables this feature $linebreaks=1; // Entrytext, displayed every time the guestbooks gets loaded $entrytext = "Vieraskirja on poistettu käytöstä"; // Maximal length of the words, to prevent someone killing your layout $maxwordlength = 30; // Rules, displayed when you enter some text... $rules = "Kirjoita nyt sitten:"; if (!$pw || $pw != $pass){ /*----------------------------------------------------------------------------------------------- Adding a new entry to the data file ------------------------------------------------------------------------------------------------*/ if ($edit == "yes"){ // test if someone forgot to enter spaces. $spaces = explode(" ",$message); for ($i=0;$i $maxwordlength) $bozo="yes"; } $spaces = explode(" ",$name); for ($i=0;$i $maxwordlength) $bozo="yes"; } // When there is missing data, display the errormessage and reprint the form if ($name == "" || $message =="" || $bozo == "yes"|| $koodi != $kirjoitus){ echo $errormessage."\n"; if ($bozo = "yes") echo "V’h’n v’li’ jooko?!"; echo "
Handle:
eMail:
url:
Message:



Kirjoita lisäksi yläpuolella oleva varmistuskoodi alhaalla olevaan kenttään ja tuuppaa teksti eteenpäin.

"; } // 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,"r"); $content = fread($newfile, filesize($filelocation)); fclose($newfile); $lines = explode("%",$content); $counter = sizeof($lines); $newfile = fopen($filelocation,"a+"); $add = "%".$counter."#".$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 !="uus"){ if ($edit=="yes"){ echo "

Katsele

"; } else { echo $entrytext; echo "

Katsele
Kirjoita

"; } } // If the guestbook is displayed, show the sign Guestbook Link if ($action == "view"){echo "

Kirjoita

";} // If someone enters data, allow him to go back to the Guestbook if ($action == "uus"){echo "

Katsele

";} /*----------------------------------------------------------------------------------------------- Display the guestbook ------------------------------------------------------------------------------------------------*/ if ($action=="view"){ echo $entrytext; // 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(); $f=0; for ($i=sizeof($lines)-1;$i>=1;$i--){ $rev[$f]=$lines[$i]; $f++; } $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[2] != ""){$mailadd="email";} // if there is a url, display a link if ($user[3] != ""){ // if people were dumb enough not to add http:// do so if (substr($user[3],0,7)!= "http://"){ $user[3]="http://".$user[3]; } $urladd="url"; } // Display the entries, here you can tweak HTML echo "
$user[1]  $mailadd $urladd  ($user[4])
$user[5]
\n
"; } } /*----------------------------------------------------------------------------------------------- Add a new entry to the guestbook, display the rules and show the form. ------------------------------------------------------------------------------------------------*/ if ($action == "uus"){ echo "$rules
\n
Nimi:
eMail:
url:
Viesti:



Kirjoita lisäksi yläpuolella oleva varmistuskoodi alhaalla olevaan kenttään ja tuuppaa teksti eteenpäin.

"; } // If the guestbook is displayed, show the sign Guestbook Link if ($action == "view"){echo "

Kirjoita

";} // If someone enters data, allow him to go back to the Guestbook if ($action == "uus"){echo "

Katsele

";} echo "\n\n\n\n"; } /*----------------------------------------------------------------------------------------------- Admin Section! ------------------------------------------------------------------------------------------------*/ if ($pw == $pass){ // Display entries with delete / edit buttons if (!$del && !$edit & !$add){ echo $entrytext; // 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(); $f=0; for ($i=sizeof($lines)-1;$i>=1;$i--){ $rev[$f]=$lines[$i]; $f++; } $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[2] != ""){$mailadd="email";} // if there is a url, display a link if ($user[3] != ""){ // if people were dumb enough not to add http:// do so if (substr($user[3],0,7)!= "http://"){ $user[3]="http://".$user[3]; } $urladd="url"; } // Display the entries, here you can tweak HTML echo "
$user[1]  $mailadd $urladd  ($user[4])
$user[5]
\n
"; echo '
'; } } // edit entry if ($edit){ // is there already a file? (sheer paranoia) if (!file_exists($filelocation)) { $newfile = fopen($filelocation,"w+"); fclose($newfile); echo "There are no entries yet"; } // Read data into content $newfile = fopen($filelocation,"r"); $content = fread($newfile, filesize($filelocation)); fclose($newfile); // remove slashes $content=stripslashes($content); // divide into entries $lines = explode("%",$content); // loop over entries while(list($key)= each ($lines)){ // when the entry is the one to be edited, split in and display the form with the data if ($key == $edit){$user = explode("#",$lines[$key]);} } echo "
Handle:
eMail:
url:
date:
Message:
"; } // Add the changed data to the datafile if ($add){ if (!file_exists($filelocation)) { $newfile = fopen($filelocation,"w+"); fclose($newfile); } // exchange invalid characters $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);} // When ASCII Linebreaks should become
s if ($linebreaks==1){$message = nl2br($message);} // clear the filedata $newdatas=""; // read in old file... $newfile = fopen($filelocation,"r"); $content = fread($newfile, filesize($filelocation)); fclose($newfile); // strip the slashes PHP adds $content=stripslashes($content); // divide into entries $lines = explode("%",$content); // loop over entries while(list($key)= each ($lines)){ // when the entry is not the one to be changed... if ($key != $add){ // when it's not the first entry, don't add a % (prevents blank entry) if ($key != 0){$newdatas .= "%";} // else simply put in the old data $newdatas .= $lines[$key]; } // if the entry is the one that was changed, insert the new data else {$newdatas .= "%".$add."#".$name."#".$email."#".$url."#".$date."#".$message;} } // overwrite the old data file... $newfile = fopen($filelocation,"w+"); fwrite($newfile, $newdatas); fclose($newfile); // display linkbutton back echo "
The data of entry ".$name." has been changed!
"; } // Delete entry if ($del){ // check for datafile if (!file_exists($filelocation)) { $newfile = fopen($filelocation,"w+"); fclose($newfile); } // reset datavariable $newdatas=""; // read in old data $newfile = fopen($filelocation,"r"); $content = fread($newfile, filesize($filelocation)); fclose($newfile); // remove slashes $content=stripslashes($content); // divide into entries $lines = explode("%",$content); // reset new entry counter $count=0; // loop over entries while(list($key)= each ($lines)){ // when the entry is not the one to be deleted... if ($key != $del){ // when it's not the first entry, don't add a % (prevents blank entry) if ($key != 0){$newdatas .= "%";} // divide into data chunks $user = explode("#",$lines[$key]); // add new counter and add the data if ($key != 0){$newdatas .= $count."#".$user[1]."#".$user[2]."#".$user[3]."#".$user[4]."#".$user[5];} // increase counter $count++; } } // replace old data file $newfile = fopen($filelocation,"w+"); fwrite($newfile, $newdatas); fclose($newfile); echo "
The entry has been deleted
"; } } ?>