<form method="post" name="smime" action="<?php echo $selfURL ?>">
<input type="hidden" name="actionID" value="" />

<table border="0" align="center" cellpadding="0" cellspacing="0" width="100%">
  <tr>
    <td align="left" class="header" nowrap="nowrap"><b><?php echo _("S/MIME Options") ?></b></td>
    <?php $app = 'imp'; Prefs_UI::generateNavigationCell('smime') ?>
  </tr>

  <tr>
    <td class="item" align="left" colspan="2">
      <table border="0" cellpadding="0" width="100%">
        <tr>
          <td class="item" align="left" valign="top">&nbsp;
            <input id="use_smime" type="checkbox" name="use_smime" <?php echo ($prefs->getValue('use_smime')) ? "checked=\"checked\"" : "" ?> />&nbsp;
          </td>
          <td class="item" align="left">
            <table border="0" cellpadding="0" width="75%">
              <tr>
                <td class="item" align="left"><label for="use_smime"><?php echo _("Enable S/MIME functionality?") ?></label>
                </td>
              </tr>
              <tr>
                <td class="item" align="left"><font color="red"><b><?php echo _("NOTE") ?>:</b></font> <?php echo _("S/MIME support requires popup windows to be used.  If your browser is currently set to disable popup windows, you must change this setting or else the S/MIME features will not work correctly") ?>.
                </td>
              </tr>
            </table>
          </td>
          <td class="item" align="right"><?php echo Help::link('imp', 'smime-overview') ?></td>
        </tr>
      </table>
    </td>
  </tr>

  <tr>
    <td nowrap="nowrap" align="left" class="header" valign="middle">
      <input type="submit" name="save" class="button" onclick="document.smime.actionID.value='save_options';return true;" value="<?php echo _("Save Options") ?>" />
    </td>
     <td class="header"></td>
  </tr>

  <tr rowspan="2"><td>&nbsp;</td></tr>

  <tr>
    <td class="header" align="left" nowrap="nowrap"><b><?php echo _("S/MIME Public Keyring") ?></b></td>
    <td class="header" align="right"><?php echo Help::link('imp', 'smime-manage-pubkey') ?></td>
  </tr>

  <tr>
    <td class="item" align="left" colspan="2">
      <table border="0" cellspacing="0" cellpadding="0">
<?php if (empty($pubkey_list)): ?>
        <tr>
          <td class="item" align="left">&nbsp;<b><?php echo _("No Public Keys Found") ?></b></td>
        </tr>
<?php elseif (is_a($pubkey_list, 'PEAR_Error')): ?>
        <tr>
          <td class="item" align="left">&nbsp;<b><?php echo _("Error") ?>:</b> <?php echo $pubkey_list->getMessage() ?></td>
        </tr>
<?php else: ?>
<?php foreach ($pubkey_list as $val): ?>
<?php $linkurl = Util::addParameter($selfURL, 'email', $val['email']); ?>
        <tr>
          <td class="item" align="left">&nbsp;<b><?php echo $val['name'] ?> (<?php echo $val['email'] ?>)</b></td>
          <td class="item" align="left">&nbsp;&nbsp;[<?php echo Horde::link(Util::addParameter($linkurl, 'actionID', 'view_public_key'), sprintf(_("View %s Public Key"), $val['name']), null, 'view_key'); ?><?php echo _("View") ?></a>]&nbsp;[<?php echo Horde::link(Util::addParameter($linkurl, 'actionID', 'info_public_key'), sprintf(_("Information on %s Public Key"), $val['name']), null, 'info_key'); ?><?php echo _("Details") ?></a>]&nbsp;[<?php echo Horde::link(Util::addParameter($linkurl, 'actionID', 'delete_public_key'), sprintf(_("Delete %s Public Key"), $val['name']), null, null, "if (confirm('" . addslashes(_("Are you sure you want to delete this public key?")) . "')) { return true; } else { return false; }"); ?><?php echo _("Delete") ?></a>]</td>
        </tr>
<?php endforeach; ?>
<?php endif; ?>
      </table>
    </td>
  </tr>
<?php if ($imp['file_upload']): ?>
  <tr>
    <td class="header" colspan="2">
      <table border="0" cellpadding="0" cellspacing="0" width="100%">
        <tr>
          <td nowrap="nowrap" align="left" valign="middle">
<?php $public_import_url = Util::addParameter(Util::addParameter($selfURL, 'actionID', 'import_public_key'), 'reload', $selfURL); ?>
            <input type="submit" name="save" class="button" onclick="open_smime_import('<?php echo $public_import_url ?>');return false;" value="<?php echo _("Import Public Key") ?>" />
          </td>
          <td align="right"><?php echo Help::link('imp', 'smime-import-pubkey') ?></td>
        </tr>
      </table>
    </td>
  </tr>
<?php endif; ?>

  <tr rowspan="2"><td>&nbsp;</td></tr>

  <tr>
    <td align="left" class="header" nowrap="nowrap"><b><?php echo _("Your S/MIME Public/Private Certificates") ?></b></td>
    <td class="header" align="right"><?php echo Help::link('imp', 'smime-overview-personalkey') ?></td>
  </tr>

  <tr>
    <td class="item" align="left" colspan="2">
      <table border="0" cellspacing="0" cellpadding="0">
<?php if (is_a($secure_check, 'PEAR_Error')): ?>
        <tr>
          <td class="item" align="left">&nbsp;<b><?php echo _("S/MIME Personal Keypair support requires a secure web connection.") ?></b></td>
        </tr>
      </table>
    </td>
<?php elseif ($prefs->getValue('smime_public_key') && $prefs->getValue('smime_private_key')): ?>
<?php
  $viewpublic_url = Util::addParameter($selfURL, 'actionID', 'view_personal_public_key');
  $infopublic_url = Util::addParameter($selfURL, 'actionID', 'info_personal_public_key');
  $unload_url = Util::addParameter($selfURL, 'actionID', 'unset_passphrase');
  $viewprivate_url = Util::addParameter($selfURL, 'actionID', 'view_personal_private_key');
?>
        <tr nowrap="nowrap">
          <td class="item" align="left"><b>&nbsp;<?php echo _("Your Public Key") ?>:</b></td>
          <td class="item" align="left">&nbsp;&nbsp;[<?php echo Horde::link($viewpublic_url, _("View Personal Public Key"), null, 'view_key') . _("View") ?></a>]&nbsp;[<?php echo Horde::link($infopublic_url, _("Information on Personal Public Key"), null, 'info_key') . _("Details") ?></a>]</td>
         </tr>
         <tr nowrap="nowrap">
          <td class="item" align="left"><b>&nbsp;<?php echo _("Your Private Key") ?>:</b></td>
          <td class="item" align="left">&nbsp;&nbsp;<?php if ($passphrase !== null): ?>[<?php echo (empty($passphrase)) ? Horde::link('', _("Enter Passphrase"), null, null, $opensmimewin . ' return false;') . _("Enter Passphrase") : Horde::link($unload_url, _("Unload Passphrase")) . _("Unload Passphrase") ?></a>]&nbsp;<?php endif; ?>[<?php echo Horde::link($viewprivate_url, _("View Personal Private Key"), null, 'view_key') . _("View") ?></a>]</td>
        </tr>
      </table>
    </td>
  </tr>

  <tr>
    <td class="header" align="left" colspan="2">
      <table border="0" cellspacing="0" cellpadding="0" width="100%">
        <tr nowrap="nowrap">
          <td align="left" valign="middle">
            <input type="submit" name="delete" class="button" onclick="if (confirm('<?php echo addslashes(_("Are you sure you want to delete your keypair? (This is NOT recommended!)")) ?>')) { document.smime.actionID.value='delete_key'; return true; } else { return false; }" value="<?php echo _("Delete Current Keys") ?>" />
          </td>
          <td align="right"><?php echo Help::link('imp', 'smime-delete-personal-certs') ?></td>
        </tr>
      </table>
    </td>
<?php else: ?>
  </tr>

<?php $personal_import_url = Util::addParameter($selfURL, 'actionID', 'import_personal_certs'); ?>
<?php if ($imp['file_upload']): ?>
      <tr nowrap="nowrap">
       <td class="item" align="left"><b>&nbsp;<?php echo _("No Personal Certificate Present") ?></b></td>
      </tr>
    </table>
   </td>
  </tr>

  <tr>
   <td nowrap="nowrap" align="left" class="header" valign="middle">
    <input type="submit" name="save" class="button" onclick="open_smime_import('<?php echo $personal_import_url ?>');return false;" value="<?php echo _("Import Personal Certificates") ?>" />
   </td>
   <td class="header"></td>
  </tr>
<?php endif; ?>
<?php endif; ?>
  <tr rowspan="2"><td>&nbsp;</td></tr>

  <tr>
    <td class="header" align="left" nowrap="nowrap">
      <input type="button" name="back" class="button" onclick="document.location.href='<?php echo IMP::prefsURL(true) ?>'" value="<?php echo _("Return to Main Preferences Screen") ?>" />
    </td>
    <td class="header">&nbsp;</td>
  </tr>
</table>

</form>
