<%args>
    $workflow_type => undef
    $role          => undef
</%args>

<& /service/open_form.mhtml &>

<& /lib/html/hidden.mhtml, 'name' => 'workflow_type', 'value' => $workflow_type &>

<h1><% i18nGettext ('I18N_OPENXPKI_CLIENT_HTML_MASON_CREATE_CSR_GET_ROLE_TITLE') %></h1>
<p>
  <% i18nGettext('I18N_OPENXPKI_CLIENT_HTML_MASON_CREATE_CSR_GET_ROLE_DESCRIPTION') %>
</p>
<p>
<& /lib/html/select.mhtml,
   'name'    => "role",
   'default' => [ $role ],
   'values'  => [ @roles ] &>
</p>
<& /service/send_form.mhtml &>
<& /service/close_form.mhtml &>
<dl>

<%init>
    ## read all roles from the server
    my $msg = $context->{client}->send_receive_command_msg("get_roles");
    # FIXME: the following fails in both Konqueror and Opera with
    # "not an array reference". Weird.
    my @roles = @{$msg->{PARAMS}};

    ## return the role if it exists
    if (defined $role and
        grep /^$role$/, @roles)
    {
        return $role;
    }

    ## if we have only one configuration
    ## then we have not to ask the user
    if (scalar @roles == 1)
    {
        return $roles[0];
    }

    ## ok, we have to ask the user
</%init>
