#!/usr/bin/perl -w
#
#    General Index document of the PDAL web interface
#
#    Copyright (C) 2004,2005 Alexandre Dulaunoy <adulau (AT) uucp.foo.be>
#
#    This  program is  free software;  you can  redistribute  it and/or
#    modify it  under the  terms of the  GNU General Public  License as
#    published by the Free Software Foundation; either version 2 of the
#    License, or (at your option) any later version.
#
#    This program  is distributed in the  hope that it  will be useful,
#    but  WITHOUT ANY WARRANTY;  without even  the implied  warranty of
#    MERCHANTABILITY or FITNESS FOR  A PARTICULAR PURPOSE.  See the GNU
#    General Public License for more details.
#
#    You should have received a  copy of the GNU General Public License
#    along  with this  program;  if  not, write  to  the Free  Software
#    Foundation,  Inc.,  51  Franklin   St,  Fifth  Floor,  Boston,  MA
#    02110-1301 USA

use HTML::Template;
use strict;
use CGI qw/:standard/;

# open the default PDAL template

my $template = HTML::Template->new(filename => 'index.tmpl',
					path => [ '../tmpl/'] );

my $actstate = 0;

# feed with parameters
#
# a -> action
# af -> action follow-up (start from 1 to n)
#

my $action          = param('a');
my $actionfollow    = param('af');
my $uploadedfile    = upload('uploaded_file');

if ($uploadedfile) {
    uploadFile($uploadedfile);
}

if (($action eq "add") and ($actionfollow < 2) ) {
    $actstate=1;
}



$template->param(PTITLE => 'Main page of the PDAL - '.$action, UPACT => $actstate);

# send the required ;-) Content-Type with the corresponding template

print "Content-Type: text/html\n\n", $template->output;


### Inner function of the Web interface (other must be in FAT library)


sub uploadFile {

    my $buffer;
    my $bytesread;

    my $filen = shift;

    $| = 1;

    open (OUTFILE,">>/tmp/$$");
        while ($bytesread=read($filen,$buffer,1024)) {
           print OUTFILE $buffer;
        }

}
 


