1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13:
14: class Horde_Core_Notification_Event_Status extends Horde_Notification_Event_Status
15: {
16: 17: 18: 19: 20: 21: 22: 23:
24: public function __construct($data, $type = null, array $flags = array())
25: {
26: if (empty($type)) {
27: $type = ($data instanceof PEAR_Error || $data instanceof Exception)
28: ? 'horde.error'
29: : (is_string($data) ? 'horde.message' : 'horde.error');
30: }
31:
32: $this->charset = 'UTF-8';
33:
34: parent::__construct($data, $type, $flags);
35: }
36:
37: 38: 39: 40: 41:
42: public function __toString()
43: {
44: $text = null;
45:
46: switch ($this->type) {
47: case 'horde.alarm':
48: $alarm = $this->flags['alarm'];
49: $text = $alarm['title'];
50:
51: if (!empty($alarm['params']['notify']['show'])) {
52: try {
53: $text = Horde::link(Horde::url($GLOBALS['registry']->linkByPackage($alarm['params']['notify']['show']['__app'], 'show', $alarm['params']['notify']['show'])), $alarm['text']) . $text . '</a>';
54: } catch (Horde_Exception $e) {
55: return $e->getMessage();
56: }
57: }
58:
59: if (!empty($alarm['user']) &&
60: $GLOBALS['browser']->hasFeature('xmlhttpreq')) {
61: try {
62: $url = Horde::url($GLOBALS['registry']->get('webroot', 'horde') . '/services/snooze.php', true);
63: } catch (Horde_Exception $e) {
64: return $e->getMessage();
65: }
66: $opts = array(
67: '-1' => Horde_Core_Translation::t("Dismiss"),
68: '5' => Horde_Core_Translation::t("5 minutes"),
69: '15' => Horde_Core_Translation::t("15 minutes"),
70: '60' => Horde_Core_Translation::t("1 hour"),
71: '360' => Horde_Core_Translation::t("6 hours"),
72: '1440' => Horde_Core_Translation::t("1 day")
73: );
74: $id = 'snooze_' . md5($alarm['id']);
75: $text .= ' <small onmouseover="if(typeof ' . $id . '_t!=\'undefined\')clearTimeout(' . $id . '_t);Element.show(\'' . $id . '\')" onmouseout="' . $id . '_t=setTimeout(function(){Element.hide(\'' . $id . '\')},500)">[' . Horde_Core_Translation::t("Snooze...") . '<span id="' . $id . '" style="display:none"> ';
76: $first = true;
77: foreach ($opts as $minutes => $desc) {
78: if (!$first) {
79: $text .= ', ';
80: }
81: $text .= Horde::link('#', '', '', '', 'new Ajax.Request(\'' . $url . '\',{parameters:{alarm:\'' . $alarm['id'] . '\',snooze:' . $minutes . '},onSuccess:function(){Element.remove(this);}.bind(this.parentNode.parentNode.parentNode)});return false;') . $desc . '</a>';
82: $first = false;
83: }
84: $text .= '</span>]</small>';
85: }
86:
87: $img = 'alerts/alarm.png';
88: $label = Horde_Core_Translation::t("Alarm");
89: break;
90:
91: case 'horde.error':
92: $img = 'alerts/error.png';
93: $label = Horde_Core_Translation::t("Error");
94: break;
95:
96: case 'horde.message':
97: $img = 'alerts/message.png';
98: $label = Horde_Core_Translation::t("Message");
99: break;
100:
101: case 'horde.success':
102: $img = 'alerts/success.png';
103: $label = Horde_Core_Translation::t("Success");
104: break;
105:
106: case 'horde.warning':
107: $img = 'alerts/warning.png';
108: $label = Horde_Core_Translation::t("Warning");
109: break;
110:
111: default:
112: return parent::__toString();
113: }
114:
115: return Horde::img($img, $label) .
116: (is_null($text) ? parent::__toString() : $text);
117: }
118:
119: }
120: