## OpenCA - CA Command
## (c) 2001 by Michael Bell and OpenCA Group
##
##   File Name: show_operations
##       Brief: show the available operations
## Description: show the available operations which will be
##              extracted from the scripts
##  Parameters: RBAC_DIR, SCRIPT_CONFIG_DIR

sub cmdShow_operations {

## load the needed config-parameters
my $rbac_dir = getRequired ('RBAC_DIR');
my $scripts  = getRequired ('OPERATIONS_DIR');
my $doc      = getRequired ('ShowOperationsSheet');

## load the prepared sheet
my $page = $tools->getFile ( $doc );
if (not $page) {
  configError ( i18nGettext ("The prepared sheet __SHEET__ cannot be loaded!", "__SHEET__", $doc) );
}

## load all scripts
opendir( DIR, $rbac_dir."/".$scripts ) or
  configError ( i18nGettext ("Cannot open __DIR__!", "__DIR__" , "$rbac_dir/$scripts") );
my @values = grep( /.*/, readdir DIR );
closedir( DIR );

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

## create table
my $table .= $query->startTable(COLS=>[ gettext ("Operations"), gettext ("Delete Op") ],
				WIDTH=>"100%",
				TITLE_BGCOLOR=>"#DDCCFF" );
my $op = "";
my $h_op = "";
for $op (@values) {
  if ( $op !~ /^${h_op}$/ ) {
    $table .= $query->addTableLine( DATA => [
      $op,
      "<a href=\"$self?cmd=show_prepared_operation&operation=".
        $op."&next_cmd=delete\">".gettext ("Delete")."</a>" ] );
    $h_op = $op;
  }
}
$table .= $query->endTable();

## build page
## Substitute the Variables in the $page
$page = $query->subVar( $page, '$uptime', $tools->getDate () );
$page = $query->subVar( $page, '$table', $table );

print "$page";

}

1;
