<%args>
  $type   => undef
  $secret => undef
  $passwd => undef
  $part   => undef
</%args>
<h1>
  <% i18nGettext('I18N_OPENXPKI_CLIENT_HTML_MASON_API_SET_SECRET_TITLE') %>
</h1>
<p>
  <% i18nGettext('I18N_OPENXPKI_CLIENT_HTML_MASON_API_SET_SECRET_DESCRIPTION') %>
</p>

<& /service/open_form.mhtml &>

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

<table>
  <tr>
    <th><% i18nGettext('I18N_OPENXPKI_CLIENT_HTML_MASON_TABLE_HEAD_NAME') %></th>
    <th><% i18nGettext('I18N_OPENXPKI_CLIENT_HTML_MASON_TABLE_HEAD_VALUE') %></th>
  </tr>
% if ($type eq "plain") {
  <tr>
    <td><% i18nGettext('I18N_OPENXPKI_SET_SECRET_PART_NUMBER') %></td>
    <td><& /lib/html/input.mhtml, name => 'part' &>
  </tr>
% }
  <tr>
    <td><% i18nGettext('I18N_OPENXPKI_SET_SECRET_PASSWD') %></td>
    <td><& /lib/html/input.mhtml, name => 'passwd', type => 'password'  &>
  </tr>
</table>

<& /service/send_form.mhtml &>
<& /service/close_form.mhtml &>

<%init>
  if (defined $passwd and length $passwd)
  {
    ## somebody entered data into the form

    my %params = ("SECRET" => $secret,
                  "VALUE"  => $passwd);
    $params{PART} = $part if (defined $part and length $part);
    my $msg  = $context->{client}->send_receive_command_msg (
                   "set_secret_part", \%params);
    if ($msg->{SERVICE_MSG} eq "ERROR")
    {
        print "<h1>".$msg->{LIST}->[0]->{LABEL}."</h1>\n";
        print "<p>".$msg->{LIST}->[0]->{PARAMS}->{ERROR}."</p>\n";
        return 1;
    }
    return $m->comp ('key_list.html');
  }
</%init>
