<%args>
    $workflow_type => undef
    $cert_serial   => undef
    $cert_issuer   => undef
</%args>

<& /service/open_form.mhtml &>

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

<h1><% i18nGettext ('I18N_OPENXPKI_CLIENT_HTML_MASON_CREATE_CRR_GET_CERTIFICATE_TITLE') %></h1>
<p>
  <% i18nGettext('I18N_OPENXPKI_CLIENT_HTML_MASON_CREATE_CRR_GET_CERTIFICATE_DESCRIPTION') %>
</p>

<table>
  <tr>
    <td><% i18nGettext ('I18N_OPENXPKI_CLIENT_HTML_MASON_CERTIFICATE_SERIAL') %></td>
    <td>
      <& '/lib/html/input.mhtml',
         'name'  => 'cert_serial',
         'value' => '',
         'max'   => 32,
         'min'   => 1 &>
    </td>
  </tr>
  <tr>
    <td><% i18nGettext ('I18N_OPENXPKI_CLIENT_HTML_MASON_CERTIFICATE_ISSUER') %></td>
    <td>
      <& '/lib/html/input.mhtml',
         'name'  => 'cert_issuer',
         'value' => '',
         'max'   => 64,
         'min'   => 16 &>
    </td>
  </tr>
</table>

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

<& /service/create_csr/print_errors.mhtml, 'errors' => \@errors &>
<& /service/create_csr/print_descriptions.mhtml, 'descriptions' => \%descriptions &>

<%init>
    my @errors = ();

    my $new_form = 1;
       $new_form = 0
           if (defined $cert_serial and defined $cert_issuer);

    if (defined $cert_serial and
        $cert_serial !~ /^[1-9][0-9]*$/)
    {
        push @errors,
             i18nGettext ('I18N_OPENXPKI_CLIENT_HTML_MASON_WRONG_CERTIFICATE_SERIAL');
    }
    if (defined $cert_issuer and
        $cert_issuer !~ /^[0-9a-zA-Z\s]*$/)
    {
        push @errors,
             i18nGettext ('I18N_OPENXPKI_CLIENT_HTML_MASON_WRONG_CERTIFICATE_ISSUER');
    }

    return ($cert_serial, $cert_issuer)
        if (not $new_form and not scalar @errors);

</%init>
