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

    <& '/authentication/open_form.mhtml', 'session_id' => $session_id &>
    <div class="title">
    <% i18nGettext ('I18N_OPENXPKI_CLIENT_HTML_MASON_GET_PKI_REALM_TITLE') %>
    </div>
    <div class="description">
        <% i18nGettext ('I18N_OPENXPKI_CLIENT_HTML_MASON_GET_PKI_REALM_DESCRIPTION') %>
    </div>
    <select name="pki_realm">
<%perl>
    ## let's print the available options
    foreach my $realm (keys %{$pki_realms})
    {
        print "<option value='$realm'>".
              $pki_realms->{$realm}->{NAME}." - ".
              $pki_realms->{$realm}->{DESCRIPTION}.
              "</option>\n";
    }
</%perl>
    </select>
    <& '/authentication/close_form.mhtml' &>

<%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_PKI_REALM");

    ## was the pki realm specified by the user?
    my %data = $m->request_args();
    if (exists $data{'pki_realm'})
    {
        $msg = $client->send_receive_service_msg ('GET_PKI_REALM',
                                                  {'PKI_REALM' => $data{'pki_realm'}});
        if ($msg->{'SERVICE_MSG'} ne 'GET_PKI_REALM')
        {
            return $msg;
        }
    }

    ## ok let's ask the user for the PKI realm
    ## cache the last message in the context
    my $pki_realms  = $msg->{PARAMS}->{PKI_REALMS};
    $context->{msg} = $msg;
</%init>
