   <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

	<head>
		<meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
		<meta name="generator" content="Adobe GoLive">
		<title>Guestbook Processing</title>
<?php
       function Search($mark, $replace, $filename)
       {
                $fr=fopen($filename,"r");
                if($fr)
                {
                    $string=fread($fr, filesize($filename));
                    fclose($fr);
                    clearstatcache();
                }
                else   echo"Can not find file".$filename;
                $new_string=str_replace($mark, $replace, $string);
                $fw=fopen($filename,"w");
                if ($fw)
                {
                fputs($fw, $new_string);
                fclose($fw);
                }

       }



 ?>
    </head>
    <body>
<?php

                $settings=$HTTP_POST_VARS;
 //Comment and uncomment source-code for using some features
                if($settings["checkboxname"]=="true")
                {
                Search("<!--mark_name-->",
                "<p>Name:</p><input type='text' name='name' value=''size='24' border='0'> ","input.htm");
                Search("<!--mark_name-->", "Name", "output.php");
                }
                else
                {
                Search("<p>Name:</p><input type='text' name='name' value=''size='24' border='0'>", "<!--mark_name-->","input.htm");
                Search("Name", "<!--mark_name-->",  "output.php");
                }

                if($settings["checkboxtown"]=="true")
                {
                Search("<!--mark_town-->",
                "<p>City/Town:</p><input type='text' name='town' value=''size='24' border='0'> ","input.htm");
                }
                else
                {
                Search("<p>City/Town:</p><input type='text' name='town' value=''size='24' border='0'>",
                "<!--mark_town-->","input.htm");
                }

                if($settings["checkboxmail"]=="true")
                {
                Search("<!--mark_mail-->",
                "<p>e-mail Address:</p><input type='text' name='mail' value=''size='24' border='0'> ","input.htm");
                }
                else
                {
                Search("<p>e-mail Address:</p><input type='text' name='mail' value=''size='24' border='0'>",
                "<!--mark_mail-->","input.htm");
                }

                if($settings["name_prove"]=="true")
                {
                Search("/*mark_prove_name..", "/*mark_prove_name*/", "output.php");
                Search("..mark_prove_name_b*/", "/*mark_prove_name_b*/", "output.php");
                }
                else
                {
                Search("/*mark_prove_name*/", "/*mark_prove_name..", "output.php");
                Search("/*mark_prove_name_b*/", "..mark_prove_name_b*/", "output.php");
                }

                if($settings["town_prove"]=="true")
                {
                Search("/*mark_prove_town..", "/*mark_prove_town*/", "output.php");
                Search("..mark_prove_town_b*/", "/*mark_prove_town_b*/", "output.php");
                }
                else
                {
                Search("/*mark_prove_town*/", "/*mark_prove_town..", "output.php");
                Search("/*mark_prove_town_b*/", "..mark_prove_town_b*/", "output.php");
                }

                if($settings["mail_prove"]=="true")
                {
                Search("/*mark_prove_mail..", "/*mark_prove_mail*/", "output.php");
                Search("..mark_prove_mail_b*/", "/*mark_prove_mail_b*/", "output.php");
                }
                else
                {
                Search("/*mark_prove_mail*/", "/*mark_prove_mail..", "output.php");
                Search("/*mark_prove_mail_b*/", "..mark_prove_mail_b*/", "output.php");
                }
                if($settings["date"]=="true")
                {
                Search("//mark_time", "/*mark_time*/", "output.php");
                Search("<!--mark_time-->", "Date", "output.php");
                }
                else
                {
                Search("/*mark_time*/", "//mark_time", "output.php");
                Search("Date", "<!--mark_time-->",  "output.php");
                }
                if($settings["i"]=="true")
                {
                Search("//mark_i..", "/*mark_i*/", "output.php");
                }
                else
                {
                Search("/*mark_i*/", "//mark_i..", "output.php");
                }

 //Set user_data
                if($settings["webmaster_address"]!="")
                {
                $user_data[0]=$settings["webmaster_address"];
                }
                if($settings["webmaster_address"]=="")
                {
                $user_data[0]="";
                }
                if($settings["count_chars"]!="")
                {
                $user_data[1]=$settings["count_chars"];
                }
                if($settings["count_chars"]=="" ||$settings["count_chars"]=="0" ||
                $settings["count_chars"]=="00" ||$settings["count_chars"]=="000" ||
                $settings["count_chars"]=="0000")
                {
                $user_data[1]=100000;
                }
                if($settings["filter1"]!="")
                {
                $user_data[2]=$settings["filter1"];
                }
                if($settings["filter1"]=="")
                {
                $user_data[2]=$settings["filter1"];
                }

 //Save as textfile
                $fw=fopen("data.txt","w");
                for ($i=0;$i<count($user_data); $i++)
                {
                $trimmed[$i]=trim($user_data[$i]);
                fputs($fw,"$trimmed[$i]\n");
                }
                fclose($fw);
                
                $fw=fopen("settings.txt","w");
                if($settings["checkboxname"]=="true")
                {fputs($fw, "checked\n");}
                else
                {fputs($fw, "\n");}
                
                if($settings["checkboxtown"]=="true")
                {fputs($fw, "checked\n");}
                else
                {fputs($fw, "\n");}
                
                 if($settings["checkboxmail"]=="true")
                {fputs($fw, "checked\n");}
                else
                {fputs($fw, "\n");}
                
                if($settings["name_prove"]=="true")
                {fputs($fw, "checked\n");}
                else
                {fputs($fw, "\n");}

                if($settings["town_prove"]=="true")
                {fputs($fw, "checked\n");}
                else
                {fputs($fw, "\n");}
                
                if($settings["mail_prove"]=="true")
                {fputs($fw, "checked\n");}
                else
                {fputs($fw, "\n");}
                
                 if($settings["i"]=="true")
                {fputs($fw, "checked\n");}
                else
                {fputs($fw, "\n");}
                
                if($settings["date"]=="true")
                {fputs($fw, "checked\n");}
                else
                {fputs($fw, "\n");}

                
                fclose($fw);


 //Get old comments
                $filename="comments.txt";
                $fr=@fopen($filename,"r");

                if($fr)
                {
                    $strings=fread($fr, filesize($filename));
                    fclose($fr);
                    clearstatcache();
                }
                else   echo"Can not find $filename";
                
 //Delete all
                if($settings["delete_all"]=="true")
                {
                $strings="";
                }
                
 //Delete comment number i
                if($strings!="")
                {{
                $strings=explode("//**//", $strings);
                }
                if($settings["delete_i"]!="")
                {
                $k=--$settings["delete_i"];
                $deleted=array_splice($strings,$k ,1);
                }
                $strings=implode("//**//", $strings);}
 //Save
                $fw=fopen($filename,"w");
                if ($fw)
                {
                fputs($fw, $strings);
                fclose($fw);
                }
                




 ?>
           Configuration changes have been successfully applied.<br><br>
           <a href="input.htm">Return to Guestbook Entry Form</a><br>
           <a href="output.php">Return to Guestbook log</a>
   </body>
</html>


