package interactive::http; # $Id$
use diagnostics;
use strict;
use vars qw(@ISA);
@ISA = qw(interactive);
use CGI;
use interactive;
use common;
use log;
my $script_name = $ENV{INTERACTIVE_HTTP};
my $no_header;
my $pipe_r = "/tmp/interactive_http_r";
my $pipe_w = "/tmp/interactive_http_w";
sub open_stdout() {
open STDOUT, ">$pipe_w" or die;
$| = 1;
print CGI::header();
$no_header = 1;
}
# cont_stdout must be called after open_stdout and before the first print
sub cont_stdout {
my ($title) = @_;
print CGI::start_html('-title' => $title) if $no_header;
$no_header = 0;
}
sub new_uid() {
my ($s, $ms) = gettimeofday();
$s * 256 + $ms % 256;
}
sub new {
open_stdout();
bless {}, $_[0];
}
sub end {
-e $pipe_r or return; # don't run this twice
my $q = CGI->new;
cont_stdout("Exit");
print "It's done, thanks for playing", $q->end_html;
close STDOUT;
unlink $pipe_r, $pipe_w;
}
sub exit { end(); exit($_[1]) }
END { end() }
sub ask_fromW {
my ($o, $common, $l, $_l2) = @_;
redisplay:
my $uid = new_uid();
my $q = CGI->new;
$q->param(state => 'next_step');
$q->param(uid => $uid);
cont_stdout($common->{title});
# print $q->img({ -src => "/icons/$o->{icon}" }) if $o->{icon};
print @{$common->{messages}};
print $q->start_form('-name' => 'form', '-action' => $script_name, '-method' => 'post');
print "