## OpenCA - CA Command
## (c) 2001 by Michael Bell and OpenCA Group
##
##   File Name: add_script
##       Brief: add a new script
## Description: shows a html-form where you can enter the data
##              of the new script
##  Parameters: none

sub cmdAdd_script {

## the data which is stored in the configurationfile of a script
my $operation;

## Get required parameters ( return only the value string )
my $sheet    = getRequired( 'AddScriptSheet' );
my $uptime   = $tools->getDate();
my $rbac     = getRequired ( 'RBAC_DIR' );
my $operations = getRequired ( 'OPERATIONS_DIR');

## load operations
opendir ( DIR, $rbac."/".$operations) or
  configError ( i18nGettext ("Cannot open the directory with the operations! (__DIR__)",
                             "__DIR__",
                             "$rbac/$operations"));
my @values = readdir  DIR ;
closedir ( DIR );

## sort them
my @hvalues;
foreach my $item (@values) {
        if ( $item !~ /^(\.\.|\.)$/ ) {
                push @hvalues, decodeName ($item);
        }
}
@values = sort @hvalues;

## build select statement
$operation = "<select name=operation>\n";
for my $h (@values) {
  $operation .= "<option value=\"".$h."\">".$h."\n";
}
$operation .= "</select>\n";

my $page;

## Get the base Page ( got in $page variable )
if( not $page = $query->getFile( "$sheet" ) ) {
	configError ( i18nGettext ("File not Found : __SHEET__", "__SHEET__", $sheet));
};

## Substitute the Variables in the $page
$page = $query->subVar( $page, '$uptime', $uptime );
$page = $query->subVar( $page, '$operation', $operation );

print "$page";

}

1;

