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

sub cmdSearch_rights {

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


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

## load modules
opendir ( DIR, $rbac."/".$modules) or
  configError ( i18nGettext ("Cannot open the directory with the modules! (__DIR__)", "__DIR__", "$rbac/$modules"));
my @values = readdir  DIR ;
closedir ( DIR );
$module = "<select name=module>\n";
$module .= "<option value=\"\">\n";
for my $h (@values) {
  if ( $h !~ /^(\.\.|\.)/ ) {
    $h = decodeName ($h);
    $module .= "<option value=\"".$h."\">".$h."\n";
  }
}
$module .= "</select>\n";

## load operations
opendir ( DIR, $rbac."/".$operations) or
  configError ( i18nGettext ("Cannot open the directory with the operations! (__DIR__)", "__DIR__", "$rbac/$operations"));
my @values = readdir  DIR ;
@values = sort @values;
closedir ( DIR );
$operation = "<select name=operation>\n";
$operation .= "<option value=\"\">\n";
for my $h (@values) {
  $h = decodeName ($h);
  if ( $h !~ /^(\.\.|\.)/ ) {
    $operation .= "<option value=\"".$h."\">".$h."\n";
  }
}
$operation .= "</select>\n";

## load operator and owner from roles
opendir ( DIR, $rbac."/".$roles) or
  configError ( i18nGettext ("Cannot open the directory with the roles! (__DIR__)", "__DIR__", "$rbac/$roles"));
my @values = readdir  DIR ;
closedir ( DIR );
$operator = "<select name=operator>\n";
$owner    = "<select name=owner>\n";
$operator .= "<option value=\"\">".gettext ("&lt;new user&gt;")."\n";
$owner    .= "<option value=\"\">".gettext ("&lt;CA itself or any role&gt;")."\n";
for my $h (@values) {
  if ( $h !~ /^(\.\.|\.)/ ) {
    $h = decodeName ($h);
    $operator .= "<option value=\"".$h."\">".$h."\n";
    $owner    .= "<option value=\"".$h."\">".$h."\n";
  }
}
$operator .= "</select>\n";
$owner    .= "</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, '$module', $module );
$page = $query->subVar( $page, '$operation', $operation );
$page = $query->subVar( $page, '$operator', $operator );
$page = $query->subVar( $page, '$owner', $owner );

print "$page";

}

1;

