## OpenCA - Command
## (c) 1998-2001 by Massimiliano Pala and OpenCA Group
##
##   File Name: bpListUser
##       Brief: Build Direcotry Listing
## Description: Build Directory Listing given ID
##  Parameters: ID

sub cmdBpListUser {

my $ID = $query->param( 'ID' );

my ( $dateColTitle, $rows, @cols, @list );

my $doc = 'BP_ListUserSheet';

## Get required parameters ( return only the value string )
my $sheet    = getRequired( $doc );
my $batchdir = getRequired( 'BP_DIR' );

if (defined $ID) {
    $ID = join ("/", split (/ */, $ID));
}
$batchdir .= "/".$ID;

opendir DIR, $batchdir;
my @list = readdir DIR;
closedir DIR;

## Get the base Page ( got in $page variable )
my $page   = $query->getFile( "$sheet" );
my $uptime = $tools->getDate();
 
configError ( i18nGettext ("Error loading file __FILE__!", "__FILE__", $sheet) ) if ( not $page);

$table = $query->startTable (COLS          => [ "ID-prefix" ],
                             WIDTH         => "100%",
                             TITLE_BGCOLOR => "#DDCCFF" );

## Process all Directories
my $user = i18nGettext ("There is no user with the ID __ID__.", "__ID__", $query->param( 'ID' ));
foreach $dirs ( @list ) {

    next if ($dirs =~ /^(\.|\.\.)$/);

    if ( (! -d $dirs) and
         ($dirs =~ /^ID$/)
       ) {
        $user = "<a href=\"$self?cmd=bpViewUser&ID=".
                      $query->param( 'ID' ).
                "\">".$query->param( 'ID' )."</a>";
    } elsif ($dirs =~ /^..+$/) {
        next;
    }


    next if (! -d $batchdir."/".$dirs);

    $col = "<a href=\"$self?cmd=bpListUser&ID=".$query->param( 'ID' ).$dirs.
         "\">".$query->param( 'ID' ).$dirs."</a>";
    $table .= $query->addTableLine( DATA =>[ $col ]);
}

## Close the Table
$table .= $query->endTable();
$table .= getCopyRight();

## Substitute the Variables in the $page
$page = $query->subVar( $page, '__uptime__', $uptime );
$page = $query->subVar( $page, '__table__',  $table );
$page = $query->subVar( $page, '__user__',   $user );

print "$page";

}

1;

