1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12:
13:
14: 15: 16: 17: 18: 19: 20: 21: 22:
23: class IMP_Prefs_Special_PgpPublicKey implements Horde_Core_Prefs_Ui_Special
24: {
25: 26:
27: public function init(Horde_Core_Prefs_Ui $ui)
28: {
29: }
30:
31: 32:
33: public function display(Horde_Core_Prefs_Ui $ui)
34: {
35: global $injector, $page_output, $prefs, $session;
36:
37: $page_output->addScriptPackage('IMP_Script_Package_Imp');
38:
39: $imp_pgp = $injector->getInstance('IMP_Crypt_Pgp');
40:
41:
42: try {
43: $pubkey_list = $imp_pgp->listPublicKeys();
44: } catch (Horde_Exception $e) {
45: $pubkey_list = array();
46: }
47:
48: $pgp_url = IMP_Basic_Pgp::url();
49:
50: $view = new Horde_View(array(
51: 'templatePath' => IMP_TEMPLATES . '/prefs'
52: ));
53: $view->addHelper('Horde_Core_View_Helper_Help');
54: $view->addHelper('Text');
55:
56: if (!empty($pubkey_list)) {
57: $plist = array();
58: $self_url = $ui->selfUrl(array(
59: 'special' => true,
60: 'token' => true
61: ));
62:
63: foreach ($pubkey_list as $val) {
64: $plist[] = array(
65: 'name' => $val['name'],
66: 'email' => $val['email'],
67: 'view' => Horde::link($pgp_url->copy()->add(array('actionID' => 'view_public_key', 'email' => $val['email'])), sprintf(_("View %s Public Key"), $val['name']), null, 'view_key'),
68: 'info' => Horde::link($pgp_url->copy()->add(array('actionID' => 'info_public_key', 'email' => $val['email'])), sprintf(_("Information on %s Public Key"), $val['name']), null, 'info_key'),
69: 'delete' => Horde::link($self_url->copy()->add(array('delete_pgp_pubkey' => 1, 'email' => $val['email'])), sprintf(_("Delete %s Public Key"), $val['name']), null, null, "window.confirm('" . addslashes(_("Are you sure you want to delete this public key?")) . "')")
70: );
71: }
72: $view->pubkey_list = $plist;
73: }
74:
75: if ($session->get('imp', 'file_upload')) {
76: $view->can_import = true;
77: $view->no_source = !$prefs->getValue('add_source');
78: if (!$view->no_source) {
79: $page_output->addInlineScript(array(
80: '$("import_pgp_public").observe("click", function(e) { ' . Horde::popupJs($pgp_url, array('params' => array('actionID' => 'import_public_key', 'reload' => base64_encode($ui->selfUrl()->setRaw(true))), 'height' => 275, 'width' => 750, 'urlencode' => true)) . '; e.stop(); })'
81: ), true);
82: }
83: }
84:
85: return $view->render('pgppublickey');
86: }
87:
88: 89:
90: public function update(Horde_Core_Prefs_Ui $ui)
91: {
92: global $injector, $notification;
93:
94: if (isset($ui->vars->delete_pgp_pubkey)) {
95: try {
96: $injector->getInstance('IMP_Crypt_Pgp')->deletePublicKey($ui->vars->email);
97: $notification->push(sprintf(_("PGP Public Key for \"%s\" was successfully deleted."), $ui->vars->email), 'horde.success');
98: } catch (Horde_Exception $e) {
99: $notification->push($e);
100: }
101: }
102:
103: return false;
104: }
105:
106: }
107: