File: summary.php

package info (click to toggle)
imp4 4.2-4lenny3
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 18,252 kB
  • ctags: 5,316
  • sloc: php: 21,340; xml: 19,302; makefile: 68; sql: 14
file content (145 lines) | stat: -rw-r--r-- 5,960 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<?php

$block_name = _("Folder Summary");

/**
 * $Horde: imp/lib/Block/summary.php,v 1.54.2.11 2007/12/20 13:59:25 jan Exp $
 *
 * @package Horde_Block
 */
class Horde_Block_imp_summary extends Horde_Block {

    /**
     * Whether this block has changing content.
     */
    var $updateable = true;

    var $_app = 'imp';

    function _title()
    {
        return Horde::link(Horde::url($GLOBALS['registry']->getInitialPage(), true)) . $GLOBALS['registry']->get('name') . '</a>';
    }

    function _params()
    {
        return array('show_unread' => array('type' => 'boolean',
                                            'name' => _("Only display folders with unread messages in them?"),
                                            'default' => 0),
                     'show_total' => array('type' => 'boolean',
                                           'name' => _("Show total number of mails in folder?"),
                                           'default' => 0)
                     );
    }

    function _content()
    {
        global $notification, $prefs, $registry;

        $GLOBALS['authentication'] = 'none';
        require dirname(__FILE__) . '/../base.php';

        $html = '<table cellspacing="0" width="100%">';

        if (!IMP::checkAuthentication(true)) {
            return $html . '<tr><td class="text">' . Horde::link(Horde::applicationUrl('index.php', true), sprintf(_("Log in to %s"), $registry->applications['imp']['name'])) . sprintf(_("Log in to %s"), $registry->applications['imp']['name']) . '</a></td></tr></table>';
        }

        /* Filter on INBOX display, if requested. */
        if ($prefs->getValue('filter_on_display')) {
            require_once IMP_BASE . '/lib/Filter.php';
            IMP_Filter::filter('INBOX');
        }

        /* Get list of mailboxes to poll. */
        require_once IMP_BASE . '/lib/IMAP/Tree.php';
        $imptree = &IMP_Tree::singleton();
        $folders = $imptree->getPollList(true, true);

        /* Quota info, if available. */
        $quota_msg = Util::bufferOutput(array('IMP', 'quota'));
        if (!empty($quota_msg)) {
            $html .= '<tr><td colspan="3">' . $quota_msg . '</td></tr>';
        }

        $newmsgs = array();
        $anyUnseen = false;

        foreach ($folders as $folder) {
            if (($folder == 'INBOX') ||
                ($_SESSION['imp']['base_protocol'] != 'pop3')) {
                $info = $imptree->getElementInfo($folder);
                if (!empty($info)) {
                    if (empty($this->_params['show_unread']) ||
                        !empty($info['unseen'])) {
                        if (!empty($info['newmsg'])) {
                            $newmsgs[$folder] = $info['newmsg'];
                        }
                        $url = Util::addParameter(Horde::applicationUrl('mailbox.php', true), array('no_newmail_popup' => 1, 'mailbox' => $folder));
                        $html .= '<tr style="cursor:pointer" class="text" onclick="self.location=\'' . $url . '\'"><td>';
                        if (!empty($info['unseen'])) {
                            $html .= '<strong>';
                            $anyUnseen = true;
                        }
                        $html .= Horde::link($url) . IMP::displayFolder($folder) . '</a>';
                        if (!empty($info['unseen'])) {
                            $html .= '</strong>';
                        }
                        $html .= '</td><td>' .
                            (!empty($info['unseen']) ? '<strong>' . $info['unseen'] . '</strong>' : '0') .
                            (!empty($this->_params['show_total']) ? '</td><td>(' . $info['messages'] . ')' : '') .
                            '</td></tr>';
                    }
                }
            }
        }

        $html .= '</table>';

        /* Check to see if user wants new mail notification, but only
         * if the user is logged into IMP. */
        if ($prefs->getValue('nav_popup')) {
            // Always include these scripts so they'll be there if
            // there's new mail in later dynamic updates.
            Horde::addScriptFile('prototype.js', 'imp', true);
            Horde::addScriptFile('effects.js', 'imp', true);
            Horde::addScriptFile('redbox.js', 'imp', true);
        }

        if (!empty($newmsgs)) {
            /* Reopen the mailbox R/W so we ensure the 'recent' flags are
             * cleared from the current mailbox. */
            $imp_imap = &IMP_IMAP::singleton();
            foreach ($newmsgs as $mbox => $nm) {
                $imp_imap->changeMbox($mbox);
            }

            if ($prefs->getValue('nav_popup')) {
                $alert = IMP::getNewMessagePopup($newmsgs);
                if (!Util::getFormData('httpclient')) {
                    $alert = 'document.observe("dom:loaded", function() { ' . $alert . ' });';
                }
                $notification->push($alert, 'javascript');
                $html .= Util::bufferOutput(array($notification, 'notify'), array('listeners' => 'javascript'));
            }

            if (class_exists('Notification_Listener_audio')
                && ($sound = $prefs->getValue('nav_audio'))) {
                $notification->push($registry->getImageDir() .
                                    '/audio/' . $sound, 'audio');
                $html .= Util::bufferOutput(array($notification, 'notify'), array('listeners' => 'audio'));
            }
        } elseif (!empty($this->_params['show_unread'])) {
            if (count($folders) == 0) {
                $html .= _("No folders are being checked for new mail.");
            } elseif (!$anyUnseen) {
                $html .= '<em>' . _("No folders with unseen messages") . '</em>';
            } elseif ($prefs->getValue('nav_popup')) {
                $html .= '<em>' . _("No folders with new messages") . '</em>';
            }
        }

        return $html;
    }

}