<%args>
    $wf_info    => undef
    $testresult => undef
    $steps      => undef
</%args>

<%init>
    my $current_cert = $wf_info->{CONTEXT}->{certs_installed};
    my $total_certs = $wf_info->{CONTEXT}->{nr_of_certs};
    my $current_step = $total_certs + $current_cert;
</%init>


% if ($current_cert == 1) {
  <h1> <% i18nGettext('I18N_OPENXPKI_HTML_SMARTCARD_CERTIFICATE_INSTALLATION',
                       '__CURRENTSTEP__' => $current_step,
                       '__STEPS__' => $steps) %> </h1>
  <p><% i18nGettext('I18N_OPENXPKI_HTML_SMARTCARD_CERTIFICATE_INSTALLATION_TEXT') %></p>
% }
% else { # this is at least the second certificate to be installed
  <h1> <% i18nGettext('I18N_OPENXPKI_HTML_SMARTCARD_CERTIFICATE_INSTALLATIONMORE_CERTIFICATES_TITLE',
                       '__CURRENTSTEP__' => $current_step,
                       '__STEPS__' => $steps) %> </h1>
  <p><% i18nGettext('I18N_OPENXPKI_HTML_SMARTCARD_CERTIFICATE_INSTALLATION_MORE_CERTIFICATES_TEXT', '__CURRENTCERT__' => $current_cert, '__TOTALCERTS__' => $total_certs) %></p>
% }
<p>
<& /service/open_form.mhtml &>
%    my $csp = $wf_info->{CONTEXT}->{client_csp};
%    my $certificate = $wf_info->{CONTEXT}->{certificate};
<& /lib/html/hidden.mhtml, 'name' => 'csp', 'value' => $csp &>
<& /lib/html/hidden.mhtml, 'name' => 'cert', 'value' => $certificate &>
%    my $params = '';
%    my %hash = $context->{menu}->get_menu_hash();
%    foreach my $key (keys %hash)
%    {
%          $params .= $key . '=' . $hash{$key} . ';';
%    }
<script type="text/javascript">
<!--
    function InstallCertIEAndTest (form) {
        test_result = InstallCertIE(form, 'silent');
        form.Submit.disabled = true;
// TODO -- do some real certificate testing here
//        signFormIE(OpenXPKI);
//        alert(OpenXPKI.signature.value);
//        var Settings = new ActiveXObject("CAPICOM.Settings");
//        Settings.EnablePromptForCertificateUI = true;
//        var SignedData = new ActiveXObject("CAPICOM.SignedData");
//        SignedData.Content = "test";
//        var signature = SignedData.Sign('');
//        alert(signature);
//        SignedData.Verify(signature);
//        SignedData.Verify(signature, false, CAPICOM_VERIFY_SIGNATURE_AND_CERTIFICATE);
//        signFormIE(OpenXPKI, this);
        search = window.location.search;
        if (search == '') {
            search = search + ";<% $params %>";
        }
        s_no_testresult = search.replace(/;testresult=.*$/, "");
        window.location.search = s_no_testresult + ";testresult=" + test_result;
    }
-->
</script>
<input type="button"
       name="Submit"
       value="<% i18nGettext('I18N_OPENXPKI_HTML_SMARTCARD_INSTALL_CERTIFICATE') %>"
       onClick="InstallCertIEAndTest(document.OpenXPKI)"/>
<& '/service/close_form.mhtml' &>
<!-- <pre>
<% $wf_info->{CONTEXT}->{certificate} %>
</pre>
-->
