<!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</title>
	</head>

	<body bgcolor="#ffffff">
        <?php
 //Get vars
 //The setting 'track_vars' must be "ON" (standard).
               $new_comment_array=$HTTP_POST_VARS;
               $user_data=file("data.txt", "r");

               //New Comment?
               if($new_comment_array["new_entry"]=="true")
               {
               //Prove "Is 'text' filled"
               if($new_comment_array["comment"]=="")
               {
                  die("You have to fill the textfield!");
               }
 //Prove "Is 'name' filled?"
 /*mark_prove_name..
               if($new_comment_array["name"]=="")
               {
                  die("You have to fill the namefield!");
               }
 ..mark_prove_name_b*/
 
 //Prove "Is 'town' filled?"
 /*mark_prove_town..
               if($new_comment_array["town"]=="")
               {
                  die("You have to enter a town!");
               }
 ..mark_prove_town_b*/
            
 //Prove"Is 'mail' filled?"
 /*mark_prove_mail..
               if($new_comment_array["mail"]=="")
               {
                  die("Please fill the mailadressfield!");
               }

               if (eregi("^[_a-z0-9]+(\.[_a-z0-9-]+)*@([a-z0-9-]+\.)+([a-z0-9]{2,4})$",
                $new_comment_array["mail"]))

                  {$go_on="true";}

               if(!$go_on)
               {
                   die("The mailaddress is not correct!");
               }
 ..mark_prove_mail_b*/

            
 //Saving new comment
          if($new_comment_array!="")
               {
 //Date
 /*mark_time*/   $date=$new_comment_array["localDate"];
 
 //Send mail with the new comment
                $address=trim($user_data[0]);
                if($address!="")
                {
                $message= $date."\n".$new_comment_array["name"]."\n".$new_comment_array["mail"]."\n".
                $new_comment_array["town"]."\n".$new_comment_array["comment"];
                $send=mail($address,"New comment",$message);
                }

 //Comment to string
                $new_string=$date."/*/".$new_comment_array["name"]."//".$new_comment_array["town"]."//"
               .$new_comment_array["mail"]."/*/".$new_comment_array["comment"];
               
 //Get old comments
                $filename="comments.txt";
                $fr=@fopen($filename,"r");

                if($fr)
                {
                    $old_strings=fread($fr, filesize($filename));
                    fclose($fr);
                }
                else die("Can not find file $filename!");

 //Merge and save.
                $strings=$new_string."//**//".$old_strings;
                
                $fw=@fopen($filename,"w");

                if ($fw)
                {
                    fputs($fw, $strings);
                    fclose($fw);
                }
                else die("Can not find file $filename!");
               }
                unset($new_comment_array["new_entry"]);
                echo "Your post has been added to the guestbook! Thank you for using the guestbook.<br>";
                echo '<a href="output.php">Return to Guestbook log.</a>';
                die;
 //End 'Getting new comment'. Script can  be included.
               }
      ?>
      <?php
      
 //Show the commments
              if($new_comment_array["new_entry"]!="true")
                {
                $filename="comments.txt";
                $fr=fopen($filename,"r");
                if($fr)
                {
                    $strings=fread($fr, filesize($filename));
                    fclose($fr);
                }
                else   die("Can not find file $filename");}

 //Create filters
			$trim=trim($user_data[2]);
			$trimmed1=str_replace(" ", "", $trim);
			if($trimmed1 !="")
			{
				$filter1=explode(",", $trimmed1);
			}

 //Start search for  filter-functions
        function filter($data,$filter,$exchange)
        {
          for ($n=0;$n<count($filter);$n++) {
           if (strstr($exchange,"###")) $change=str_replace("###", $filter[$n], $exchange);
           else $change=$exchange;
           $data=preg_replace("/(?i)$filter[$n](?=(,|\s|\?|\!|\")|$)/", $change, $data);
        }
    return $data;
    }
?>
<table width="80%">
    <tr>
        <td colspan="3">
        <h1>Guestbook</h1>
        </td>
    </tr>
    <tr>
        <td colspan="2">Number of entries:         <?
              $table=explode("//**//", $strings);
              if($table[0]=="")
              {
              echo"None";
              }
              else
              {
              $count=count($table);
              $coun=--$count;
              echo $coun;
              }
        ?>
        
        <br><br></td>
        <td align="right">

        </td>
    </tr>
    <tr>
        <td bgcolor="999999"><b>Date</b></td>
        <td bgcolor="999999"><b>Name</b></td>
        <td bgcolor="999999"><b>Comment</b></td>
    </tr>
         <?
 //start comment-table
               for ($i=0;$i<$coun; $i++) {
               $cell=explode("/*/", $table[$i]);
               $user=explode("//", $cell[1]);
         ?>
    <tr valign="top">
        <td bgcolor="cccccc">
        <?
 //mark_i..    $j=1+$i;
 //mark_i..    echo $j.".<br>";
               echo $cell[0];
        ?>
    </td>
        <td bgcolor="cccccc">
        <?
               echo "<b>".strtoupper($user[0])."</b><br>".$user[1]."<br>
               <a href=\"mailto:".$user[2]."\">".strtolower($user[2])."</a>";
        ?>
    </td>
        <td bgcolor="cccccc">
        <?
               $text=nl2br(strip_tags(stripslashes($cell[2])));
               $text=filter($text,$filter1,"<b>*CENSORED*</b>");

               $text=strip_tags(stripslashes($text));
 //Cut long entries
          if(strlen($text)>$user_data[1])
            {
               $cut_text=wordwrap($text,$user_data[1],"%@%");
            if ($cut_text!="")
            {
               $pos=strpos($cut_text,"%@%");
               $new_cut_text=substr($cut_text,0,$pos);
               echo $new_cut_text."(...)<br><form  method=\"post\" action=\"ShowAll.php\">
            <input type=\"hidden\" name=\"Date\"  value=\"".$cell[0]."\">
            <input type=\"hidden\" name=\"User\"  value=\"".$user[0]."\">
            <input type=\"hidden\" name=\"Text\"  value=\"".$text."\">
            ";
            }
            if ($cut_text=="")
            {
            $new_cut_text=substr($text,0 ,$user_data[1]);
            echo $new_cut_text."(...)<br><form  method=\"post\" action=\"ShowAll.php\">
            <input type=\"hidden\" name=\"Date\"  value=\"".$cell[0]."\">
            <input type=\"hidden\" name=\"User\"  value=\"".$user[0]."\">
            <input type=\"hidden\" name=\"Text\"  value=\"".$text."\">
            ";
            }
        ?>
           <b onclick="submit(document.forms[0].elements);">
           <u><font color="#00008b">see the whole comment</font></u></b>
           </form>
           <?
            }
 //show short comments
         elseif (strlen($text)<$user_data[1])
            {
            echo $text;
            }
        ?>
        </td>
    </tr>

        <?
 //Stop comment-table
          }
        ?>
    <tr>
        <td bgcolor="999999" colspan="3" align="right"><a href="input.htm" target="_self">To post your own comment click here</a></td>
    </tr>
    <tr>
        <td colspan="3"></td>
    </tr>
</table>
</body>
</html>
                
