<%args>
  $msg             => undef
</%args>

    <& '/authentication/open_form.mhtml', 'session_id' => $session_id &>
    <h1><% i18nGettext ('I18N_OPENXPKI_CLIENT_HTML_MASON_GET_AUTHENTICATION_STACK_TITLE') %></h1>
    <p>
      <% i18nGettext ('I18N_OPENXPKI_CLIENT_HTML_MASON_GET_AUTHENTICATION_STACK_DESCRIPTION') %>
    </p>
    <select name="auth_stack">
%   ## let's print the available options
%   foreach my $stack (keys %{$auth_stacks})
%   {
      <option value="<% $stack %>"><% $auth_stacks->{$stack}->{NAME} %></option>
%   }
    </select>
    <& '/authentication/close_form.mhtml' &>
    <dl>
%   ## let's print the available options
%   foreach my $stack (keys %{$auth_stacks})
%   {
      <dt><% $auth_stacks->{$stack}->{NAME} %></dt>
      <dd><% i18nGettext($auth_stacks->{$stack}->{DESCRIPTION}) %></dd>
%   }
    </dl>

<%init>
    my $session_id = $context->{session_id};
    my $client     = $context->{client};

    ## check that we must handle this message
    return $msg if ($msg->{SERVICE_MSG} ne "GET_AUTHENTICATION_STACK");

    ## was the authentication stack specified by the user?
    my %data = $m->request_args();
    if (exists $data{'auth_stack'})
    {
        #print  STDERR "DATA: ".$data{'auth_stack'}."\n";
        $msg = $client->send_receive_service_msg ('GET_AUTHENTICATION_STACK',
                                                  {'AUTHENTICATION_STACK' => $data{'auth_stack'}});
        if ($msg->{'SERVICE_MSG'} ne 'GET_AUTHENTICATION_STACK')
        {
            return $msg;
        }
        #print  STDERR "second: ".$data{'auth_stack'}."\n";
    }

    ## ok let's ask the user for the auth stacks
    ## cache the last message in the context
    my $auth_stacks = $msg->{PARAMS}->{AUTHENTICATION_STACKS};
    $context->{msg} = $msg;
    $m->comp ('/lib/debug.mhtml',
              'level' => 99,
              'msg'   => "CONTEXT->MSG: ".Dumper($context->{msg}));
</%init>
<%once>
    use Data::Dumper;
</%once>
