<form method="post" name="pgp" 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 _("PGP Options") ?></b></td>
    <?php PrefsUI::generateNavigationCell('pgp') ?>
  </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 type="checkbox" name="use_pgp" <?php echo ($prefs->getValue('use_pgp')) ? "checked=\"checked\"" : "" ?> />&nbsp;
          </td>
          <td class="item" align="left">
            <table border="0" cellpadding="0" width="75%">
              <tr>
                <td class="item" align="left"><?php echo _("Enable PGP functionality?") ?>
                </td>
              </tr>
              <tr>
                <td class="item" align="left"><font color="red"><b><?php echo _("NOTE") ?>:</b></font> <?php echo _("PGP 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 PGP features will not work correctly") ?>.
                </td>
              </tr>
            </table>
          </td>
          <td class="item" align="right"><?php echo Help::link('imp', 'pgp-overview') ?></td>
        </tr>

        <tr><td>&nbsp;</td></tr>

<?php if (!$prefs->isLocked('pgp_attach_pubkey')): ?>
        <tr>
          <td class="item" align="left">&nbsp;
            <input type="checkbox" name="pgp_attach_pubkey" <?php echo ($prefs->getValue('pgp_attach_pubkey')) ? "checked=\"checked\"" : "" ?> />&nbsp;
          </td>
          <td class="item" align="left">
            <?php echo _("Should your PGP public key to be attached to your messages by default?") ?>
          </td>
          <td class="item" align="right"><?php echo Help::link('imp', 'pgp-option-attach-pubkey') ?></td>
        </tr>
<?php endif; ?>

<?php if (!$prefs->isLocked('pgp_scan_body')): ?>
        <tr>
          <td class="item" align="left">&nbsp;
            <input type="checkbox" name="pgp_scan_body" <?php echo ($prefs->getValue('pgp_scan_body')) ? "checked=\"checked\"" : "" ?> />&nbsp;
          </td>
          <td class="item" align="left">
            <?php echo _("Should the body of text/plain messages be scanned for PGP data?") ?>
          </td>
          <td class="item" align="right"><?php echo Help::link('imp', 'pgp-option-scan-body') ?></td>
        </tr>
<?php endif; ?>

      </table>
    </td>
  </tr>

  <tr>
    <td nowrap="nowrap" align="left" class="header" valign="middle">
      <input type="submit" name="save" class="button" onclick="document.pgp.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 _("PGP Public Keyring") ?></b></td>
    <td class="header" align="right"><?php echo Help::link('imp', 'pgp-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 Keys in Keyring") ?></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 $key => $val) {
    $linkurl = Horde::addParameter($selfURL, 'email', $key);
?>
        <tr>
          <td class="item" align="left">&nbsp;<b><?php echo $val['name'] ?> (<?php echo $key ?>)</b></td>
          <td class="item" align="left">&nbsp;&nbsp;[<?php echo Horde::link(Horde::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(Horde::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(Horde::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 } ?>
<?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 = Horde::addParameter(Horde::addParameter($selfURL, 'actionID', 'import_public_key'), 'reload', $selfURL); ?>
            <input type="submit" name="save" class="button" onclick="open_pgp_import('<?php echo $public_import_url ?>');return false;" value="<?php echo _("Import Public Key") ?>" />
          </td>
          <td align="right"><?php echo Help::link('imp', 'pgp-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 PGP Public/Private Keys") ?></b></td>
    <td class="header" align="right"><?php echo Help::link('imp', 'pgp-overview-personalkey') ?></td>
  </tr>

  <tr>
    <td class="item" align="left" colspan="2">
      <table border="0" cellpadding="0" width="100%">
<?php if (is_a($secure_check, 'PEAR_Error')): ?>
        <tr>
          <td class="item" align="left">&nbsp;<b><?php echo _("PGP Personal Keypair support requires a secure web connection.") ?></b></td>
        </tr>
      </table>
    </td>
  </tr>
<?php elseif ($prefs->getValue('pgp_public_key') && $prefs->getValue('pgp_private_key')): ?>
<?php
  $viewpublic_url = Horde::addParameter($selfURL, 'actionID', 'view_personal_public_key');
  $infopublic_url = Horde::addParameter($selfURL, 'actionID', 'info_personal_public_key');
  $sendpublic_url = Horde::addParameter($selfURL, 'actionID', 'send_public_key');
  $unload_url = Horde::addParameter($selfURL, 'actionID', 'unset_passphrase');
  $viewprivate_url = Horde::addParameter($selfURL, 'actionID', 'view_personal_private_key');
  $infoprivate_url = Horde::addParameter($selfURL, 'actionID', 'info_personal_private_key');
?>
        <tr>
          <td class="item" align="left" rowspan="2">
            <table border="0" cellspacing="0" cellpadding="0">
              <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>]&nbsp;[<?php echo Horde::link($sendpublic_url, _("Send Key to Public Keyserver")) . _("Send Key to Public Keyserver") ?></a>]</td>
              </tr>
              <tr>
                <td class="item" align="left"><b>&nbsp;<?php echo _("Your Private Key") ?>:</b></td>
                <td class="item" align="left">&nbsp;&nbsp;[<?php echo (empty($passphrase)) ? Horde::link('', _("Enter Passphrase"), null, null, $openpgpwin . ' return false;') . _("Enter Passphrase") : Horde::link($unload_url, _("Unload Passphrase")) . _("Unload Passphrase") ?></a>]&nbsp;[<?php echo Horde::link($viewprivate_url, _("View Personal Private Key"), null, 'view_key') . _("View") ?></a>]&nbsp;[<?php echo Horde::link($infoprivate_url, _("Information on Personal Private Key"), null, 'info_key') . _("Details") ?></a>]</td>
              </tr>
            </table>
          </td>
          <td class="item" align="right"><?php echo Help::link('imp', 'pgp-personalkey-public') ?></td>
        </tr>

        <tr>
          <td class="item" align="right"><?php echo Help::link('imp', 'pgp-personalkey-private') ?></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.pgp.actionID.value='delete_key'; return true; } else { return false; }" value="<?php echo _("Delete Current Keys") ?>" />
          </td>
          <td align="right"><?php echo Help::link('imp', 'pgp-personalkey-delete') ?></td>
        </tr>
      </table>
    </td>
  </tr>
<?php else: ?>
<?php
require_once HORDE_BASE . '/lib/Identity.php';
$imp_identity = &Identity::singleton(array('imp', 'imp'));
$personal_import_url = Horde::addParameter($selfURL, 'actionID', 'import_personal_public_key');
?>
        <tr>
          <td class="item" align="left" rowspan="6">
            <table border="0" cellpadding="0">
              <tr>
                <td class="item" align="left"><b>&nbsp;<?php echo _("Your Name") ?>:</b></td>
                <td class="item" align="left">&nbsp;&nbsp;<input type="text" name="generate_realname" size="30" maxlength="60" class="fixed" value="<?php echo $imp_identity->getFullname(); ?>"/></td>
              </tr>

              <tr>
                <td class="item" align="left"><b>&nbsp;<?php echo _("Comment") ?>:</b></td>
                <td class="item" align="left">&nbsp;&nbsp;<input type="text" name="generate_comment" size="30" maxlength="60" class="fixed" /></td>
              </tr>

              <tr>
                <td class="item" align="left"><b>&nbsp;<?php echo _("E-mail Address") ?>:</b></td>
                <td class="item" align="left">&nbsp;&nbsp;<input type="text" name="generate_email" size="30" maxlength="60" class="fixed" value="<?php echo $imp_identity->getFromAddress(); ?>"/></td>
              </tr>

              <tr>
                <td class="item" align="left"><b>&nbsp;<?php echo _("Key Length") ?>:</b></td>
                <td class="item" align="left">&nbsp;
                  <select name="generate_keylength">
                    <option value="1024">1024</option>
                    <option value="2048">2048</option>
                  </select>
                </td>
              </tr>

              <tr>
                <td class="item" align="left"><b>&nbsp;<?php echo _("Passphrase") ?>:</b></td>
                <td class="item" align="left">&nbsp;&nbsp;<input type="password" name="generate_passphrase1" size="30" maxlength="60" class="fixed" /></td>
              </tr>

              <tr>
                <td class="item" align="left"><b>&nbsp;<?php echo _("Passphrase (Again)") ?>:</b></td>
                <td class="item" align="left">&nbsp;&nbsp;<input type="password" name="generate_passphrase2" size="30" maxlength="60" class="fixed" /></td>
              </tr>
            </table>
          </td>
          <td class="item" align="right"><?php echo Help::link('imp', 'pgp-personalkey-create-name') ?></td>
        </tr>

        <tr>
          <td class="item" align="right"><?php echo Help::link('imp', 'pgp-personalkey-create-comment') ?></td>
        </tr>

        <tr>
          <td class="item" align="right"><?php echo Help::link('imp', 'pgp-personalkey-create-email') ?></td>
        </tr>

        <tr>
          <td class="item" align="right"><?php echo Help::link('imp', 'pgp-personalkey-create-keylength') ?></td>
        </tr>

        <tr>
          <td class="item" align="right"><?php echo Help::link('imp', 'pgp-personalkey-create-passphrase') ?></td>
        </tr>

        <tr>
          <td class="item">&nbsp;</td>
        </tr>
      </table>
    </td>
  </tr>

  <tr>
    <td colspan="2" class="header">
      <table border="0" cellpadding="0" width="100%">
        <tr nowrap="nowrap">
          <td align="left" valign="middle">
            <input type="submit" name="save" class="button" onclick="document.pgp.actionID.value='generate_key';return true;" value="<?php echo _("Create Keys") ?>" />
<?php if ($imp['file_upload']): ?>
            <input type="submit" name="save" class="button" onclick="open_pgp_import('<?php echo $personal_import_url ?>');return false;" value="<?php echo _("Import Keypair") ?>" />
<?php endif; ?>
          </td>
          <td align="right"><?php echo Help::link('imp', 'pgp-personalkey-create-actions') ?></td>
        </tr>
      </table>
    </td>
  </tr>
<?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 Horde::applicationUrl('prefs.php', true) ?>'" value="<?php echo _("Return to Main Preferences Screen") ?>" />
    </td>
    <td class="header">&nbsp;</td>
  </tr>
</table>

</form>
