#!/usr/local/bin/perl
#Shows contents of the file that is accessible through test_file_write.html
#file: test_file_write
#This will append data to the end of a file

require "/home/bear-008/users/downeyt/scripts/parse-lib.pl";
%query=&get_query;

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

#open the file for reading and appending
open file,"+>>test_data";

#get the data from the query string
#each new entry starts a new line, and data can have multiple lines
$data=$query{'info'};
if ($data)
{
    print file "\n$data";
}

#reset file to start, otherwise wierd things happen
seek file,0,0;

#print the start of the HTML document
print <<END;
<html>
<head>
<title>
Show file and allow append
</title>
</head>
<body>
Enter the data that you would like to append to the file
<form method=get>
<textarea name="info" rows=4 cols=60>
</textarea>
<br><input type="submit" value="Add Text To File">
</form>
<hr>
<h2>Contents of file</h2>
<hr>
<pre>
END
    ;

#print the file with any new data already appended
if (!(eof file))
{
    while (<file>)
    {
	print "$_";
    }
    close file;
}
else
{
    print "File is empty\n";
}

print <<TAIL;
</pre>
</body>
</html>
TAIL
    ;






