<?
$datadir="Gastbuch/";
$buchfile=$datadir . "gastbuch.txt";
$trenner="+++___+++";

function add_entry($name,$eintrag){
  global $trenner;
  global $buchfile;

  $zeit=getdate(time());
  $ts=sprintf("%02d.%02d.%d - %02d:%02d",$zeit[mday],$zeit[mon],$zeit[year],$zeit[hours],$zeit[minutes]);
/*
   $ts=$zeit[mday] . "." . $zeit[mon] . "." . $zeit[year] . " - " . $zeit[hours] . ":" . $zeit[minutes];
*/
  $fp=fopen($buchfile,'a');
  if ($fp){
    fputs($fp,$trenner . "\n");
    fputs($fp,$ts . "\n");
    fputs($fp,$name ."\n");
    fputs($fp,$eintrag . "\n");
    fclose($fp);
    return 1;
  } else return 0;
}

function get_entry($nr){
  global $trenner;
  global $buchfile;
  
  $i=0;
  $fp=fopen($buchfile,'r');
  if($fp){
    while ($line = fgets($fp, 4096)){
      if (strstr($line,$trenner))$i++;
      if ($i == $nr){
        $a[]=$line;    
      } 
    }   
    fclose($fp);
    return $a;
  } else return 0;
}

function count_entry(){
  global $trenner;
  global $buchfile;
  
  $i=0;
  $fp=fopen($buchfile,'r');
  if($fp){
    while ($line = fgets($fp, 4096)){
      if (strstr($line,$trenner))$i++;
    }   
    fclose($fp);
    return $i;
  } else return 0;
}


?>
