#!/usr/bin/perl -w

use CGI qw(:standard);
use CGI::Carp qw(fatalsToBrowser);
use strict;

my $pfad	= "../../httpdocs/data/";
my $FN_blog 	= $pfad."liste.csv";

my $ts = time();

########## Alte Einträge einlesen
my @alte_zeilen 	= read_file($FN_blog);	#enthält Zeilen der Blogdatei

print "Content-type: text/html\n\n";

########### Ausgabe an Browser und in Datei

print <<HTMLANFANG;
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Brennsuppe - Liste ekliger W&ouml;rter</title>
<meta name="author" content="Martin Gürtel, econosite">
<meta name="generator" content="Quanta+">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-15">
<meta name="robots" content="noindex">
</head>

<body>
<table width="90%" border="0" align="center"><tr>
      <td valign="top">
<h2>Liste ekliger W&ouml;rter</h2>
<h3>Letzter Eintrag:</h3>
HTMLANFANG

print "<p>$alte_zeilen[0]</p>";

if(param()) {
	unshift @alte_zeilen,$ts."\t".param('Eintrag')."\n";
}

my  $neu_eintrag = '';

foreach(@alte_zeilen) {
	$neu_eintrag .= $_;
}

print <<HTMLENDE;
<h3>Neuer Eintrag:</h3>
<form name="NeuerEintrag" action="/cgi-bin/protect/liste.pl" method="post">
<p><input type="text" class="feld" name="Eintrag" size="20" maxlength="30"></p>
<p><input type="Submit" name="" value="Eintragen"></p>
</form>
<p><a href="/hoam/index.php">[Zurück zur Homepage]</a></p>
</body>
</html>
HTMLENDE

write_file($FN_blog,$neu_eintrag);

sub read_file{
	open(F, $_[0]) || error("Can't open file $_[0]: $!");
	my @data = <F>;
	close F;
	return @data;
}
sub write_file{
	open(F, ">".$_[0]) || error("Can't open file $_[0]: $!");
	print F $_[1];
	close F;
}
sub error{
	print "Content-type: text/html\n\n";
	print $_[0];
}