## OpenCA - CA Command
## (c) 2001 by Michael Bell and OpenCA Group
##
##   File Name: show_prepared_script
##       Brief: show a special script
## Description: show a special script and a button to add/delete the script
##  Parameters: script, owner_method, operation, owner_argument, next_cmd

sub cmdShow_prepared_script {

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

my @cols;
my $page;

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

my $operation      = $query->param ('operation');
my $script         = $query->param ('script');
my $owner_method   = $query->param ('owner_method');
my $owner_argument = $query->param ('owner_argument');

## check for the existence of the script
my $conffile = getRequired ('RBAC_DIR')."/".
               getRequired ('SCRIPT_CONFIG_DIR')."/".
               encodeName ($script).".conf";

my $data = "<input type=hidden name=script value=\"".$script."\">\n";
my $table .= $query->startTable(COLS=>[ gettext("Variable"), gettext("Data") ],
                                WIDTH=>"100%",
                                TITLE_BGCOLOR=>"#DDCCFF" );
$table .= $query->addTableLine( DATA => [ gettext("Scriptname"), $script ] );

if ( $query->param ('next_cmd') =~ /^delete$/i ) {
  $data .= "<input type=hidden name=cmd value=delete_script>\n";
  $data .= "<input type=submit value=\"".gettext("DELETE this Script")."\">\n";
} else {
  libLoadCommand ("new_script");
  checkNew_script();

  $data .= "<input type=hidden name=operation value=\"".$operation."\">\n";
  $data .= "<input type=hidden name=owner_method value=\"".$owner_method."\">\n";
  $data .= "<input type=hidden name=owner_argument value=\"".$owner_argument."\">\n";
  $data .= "<input type=hidden name=cmd value=new_script>";
  $data .= "<input type=submit value=\"".gettext("Create this Script")."\">\n";
  $table .= $query->addTableLine( DATA => [ gettext("Operation"), $operation ] );
  $table .= $query->addTableLine( DATA => [ gettext("Owner_Method"), $owner_method ] );
  $table .= $query->addTableLine( DATA => [ gettext("Owner_Argument"), $owner_argument ] );
}

$table .= $query->endTable();

## Substitute the Variables in the $page
$page = $query->subVar( $page, '$script', $script );
$page = $query->subVar( $page, '$table', $table );
$page = $query->subVar( $page, '$data', $data );

print "$page";

}

1;
