% if ($message) {
% }
<% inputFromFile($logfile) %>
%#
%# ========================================================================
%#
<%args>
$action => ''
$text => ''
%args>
%#
<%init>
require CGI::Cookie;
my $message = '';
my $logtime = '+5m';
my $cookie;
my $forum_Post;
my $user_Password;
my $logfile = "logfile.txt";
my $user_Name;
my %user_Cookie = fetch CGI::Cookie;
my $cookie_Name;
if (%user_Cookie){
$cookie_Name = Person->retrieve(cookie => $user_Cookie{'ID'}->value);
}
if ($cookie_Name){
$cookie = new CGI::Cookie (-name=>'ID', -value=>$user_Cookie{'ID'}->value, -expires=>$logtime);
$user_Name = Person->retrieve(id => $cookie_Name)->name;
$r->header_out('Set-cookie' => $cookie);
$message = "Welcome back, $user_Name";
}
if ($action =~ /Post/){
if ($cookie_Name){
if ($text){
outputToFile($user_Name, $text, $logfile);
$message = "Your message has been added.";
}
else {$message = "You need to enter some text!";}
}
else {$message = "You must log in to post on the Forum!";}
}
sub outputToFile{
my ($user_Name, $text, $logFile) = @_;
# chdir $m->current_comp->source_dir;
open FILE, ">> $logFile";
print FILE qq{ $user_Name said "$text"
\n};
close FILE;
}
sub inputFromFile{
my ($logFile) = @_;
my @logArray;
my $logString;
# chdir $m->current_comp->source_dir;
open FILE, "< $logFile";
@logArray = ;
close FILE;
while (@logArray){$logString .= shift@logArray}
return ($logString);
}
%init>