File: tree_alarms.php

package info (click to toggle)
nag2 2.3.4%2Bdebian0-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 6,256 kB
  • ctags: 1,719
  • sloc: php: 6,797; xml: 589; sql: 335; makefile: 75; sh: 26
file content (88 lines) | stat: -rw-r--r-- 3,135 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
<?php

$block_name = _("Menu Alarms");
$block_type = 'tree';

/**
 * $Horde: nag/lib/Block/tree_alarms.php,v 1.5.2.2 2008-01-02 16:50:50 chuck Exp $
 *
 * @package Horde_Block
 */
class Horde_Block_nag_tree_alarms extends Horde_Block {

    var $_app = 'nag';

    function _buildTree(&$tree, $indent = 0, $parent = null)
    {
        require_once dirname(__FILE__) . '/../base.php';

        $horde_alarm = null;
        if (!empty($GLOBALS['conf']['alarms']['driver'])) {
            require_once 'Horde/Alarm.php';
            $horde_alarm = Horde_Alarm::factory();
        }

        // Get any alarms in the next hour.
        $now = time();
        $alarms = Nag::listAlarms($now);
        if (is_a($alarms, 'PEAR_Error')) {
            return;
        }

        $alarmCount = 0;
        foreach ($alarms as $taskId => $task) {
            if ($horde_alarm &&
                $horde_alarm->isSnoozed($task->uid, Auth::getAuth())) {
                continue;
            }
            $alarmCount++;
            $differential = $task->due - $now;
            if ($differential >= 60) {
                $title = sprintf(_("%s is due in %s"), $task->name, Nag::secondsToString($differential));
            } else {
                $title = sprintf(_("%s is due now."), $task->name);
            }

            $url = Util::addParameter(Horde::applicationUrl('view.php'),
                                      array('task' => $task->id,
                                            'tasklist' => $task->tasklist));
            $tree->addNode($parent . $taskId,
                           $parent,
                           $task->name,
                           $indent + 1,
                           false,
                           array('icon' => 'alarm.png',
                                 'icondir' => $GLOBALS['registry']->getImageDir(),
                                 'title' => $title,
                                 'url' => $url));
        }

        if ($GLOBALS['registry']->get('url', $parent)) {
            $purl = $GLOBALS['registry']->get('url', $parent);
        } elseif ($GLOBALS['registry']->get('status', $parent) == 'heading' ||
                  !$GLOBALS['registry']->get('webroot')) {
            $purl = null;
        } else {
            $purl = Horde::url($GLOBALS['registry']->getInitialPage($parent));
        }
        $pnode_params = array('url' => $purl,
                              'icon' => $GLOBALS['registry']->get('icon', $parent),
                              'icondir' => '');

        $pnode_params = array('url' => $purl,
                              'icon' => $GLOBALS['registry']->get('icon', $parent),
                              'icondir' => '');
        $pnode_name = $GLOBALS['registry']->get('name', $parent);
        if ($alarmCount) {
            $pnode_name = '<strong>' . $pnode_name . '</strong>';
        }

        $tree->addNode($parent,
                       $GLOBALS['registry']->get('menu_parent', $parent),
                       $pnode_name,
                       $indent,
                       false,
                       $pnode_params);
    }

}