1: <?php
2: /**
3: * Magento
4: *
5: * NOTICE OF LICENSE
6: *
7: * This source file is subject to the Open Software License (OSL 3.0)
8: * that is bundled with this package in the file LICENSE.txt.
9: * It is also available through the world-wide-web at this URL:
10: * http://opensource.org/licenses/osl-3.0.php
11: * If you did not receive a copy of the license and are unable to
12: * obtain it through the world-wide-web, please send an email
13: * to license@magentocommerce.com so we can send you a copy immediately.
14: *
15: * DISCLAIMER
16: *
17: * Do not edit or add to this file if you wish to upgrade Magento to newer
18: * versions in the future. If you wish to customize Magento for your
19: * needs please refer to http://www.magentocommerce.com for more information.
20: *
21: * @category Mage
22: * @package Mage_Adminhtml
23: * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24: * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25: */
26:
27: class Mage_Adminhtml_Block_Notification_Window extends Mage_Adminhtml_Block_Notification_Toolbar
28: {
29: /**
30: * XML path of Severity icons url
31: */
32: const XML_SEVERITY_ICONS_URL_PATH = 'system/adminnotification/severity_icons_url';
33:
34: /**
35: * Severity icons url
36: *
37: * @var string
38: */
39: protected $_severityIconsUrl;
40:
41: /**
42: * Is available flag
43: *
44: * @var bool
45: */
46: protected $_available = null;
47:
48: /**
49: * Initialize block window
50: *
51: */
52: protected function _construct()
53: {
54: parent::_construct();
55:
56: $this->setHeaderText($this->escapeHtml($this->__('Incoming Message')));
57: $this->setCloseText($this->escapeHtml($this->__('close')));
58: $this->setReadDetailsText($this->escapeHtml($this->__('Read details')));
59: $this->setNoticeText($this->escapeHtml($this->__('NOTICE')));
60: $this->setMinorText($this->escapeHtml($this->__('MINOR')));
61: $this->setMajorText($this->escapeHtml($this->__('MAJOR')));
62: $this->setCriticalText($this->escapeHtml($this->__('CRITICAL')));
63:
64:
65: $this->setNoticeMessageText($this->escapeHtml($this->getLastNotice()->getTitle()));
66: $this->setNoticeMessageUrl($this->escapeUrl($this->getLastNotice()->getUrl()));
67:
68: switch ($this->getLastNotice()->getSeverity()) {
69: default:
70: case Mage_AdminNotification_Model_Inbox::SEVERITY_NOTICE:
71: $severity = 'SEVERITY_NOTICE';
72: break;
73: case Mage_AdminNotification_Model_Inbox::SEVERITY_MINOR:
74: $severity = 'SEVERITY_MINOR';
75: break;
76: case Mage_AdminNotification_Model_Inbox::SEVERITY_MAJOR:
77: $severity = 'SEVERITY_MAJOR';
78: break;
79: case Mage_AdminNotification_Model_Inbox::SEVERITY_CRITICAL:
80: $severity = 'SEVERITY_CRITICAL';
81: break;
82: }
83:
84: $this->setNoticeSeverity($severity);
85: }
86:
87: /**
88: * Can we show notification window
89: *
90: * @return bool
91: */
92: public function canShow()
93: {
94: if (!is_null($this->_available)) {
95: return $this->_available;
96: }
97:
98: if (!Mage::getSingleton('admin/session')->isFirstPageAfterLogin()) {
99: $this->_available = false;
100: return false;
101: }
102:
103: if (!$this->isOutputEnabled('Mage_AdminNotification')) {
104: $this->_available = false;
105: return false;
106: }
107:
108: if (!$this->_isAllowed()) {
109: $this->_available = false;
110: return false;
111: }
112:
113: if (is_null($this->_available)) {
114: $this->_available = $this->isShow();
115: }
116: return $this->_available;
117: }
118:
119:
120: /**
121: * Return swf object url
122: *
123: * @return string
124: */
125: public function getObjectUrl()
126: {
127: return $this->_getHelper()->getPopupObjectUrl();
128: }
129:
130: /**
131: * Retrieve Last Notice object
132: *
133: * @return Mage_AdminNotification_Model_Inbox
134: */
135: public function getLastNotice()
136: {
137: return $this->_getHelper()->getLatestNotice();
138: }
139:
140: /**
141: * Retrieve severity icons url
142: *
143: * @return string
144: */
145: public function getSeverityIconsUrl()
146: {
147: if (is_null($this->_severityIconsUrl)) {
148: $this->_severityIconsUrl =
149: (Mage::app()->getFrontController()->getRequest()->isSecure() ? 'https://' : 'http://')
150: . sprintf(Mage::getStoreConfig(self::XML_SEVERITY_ICONS_URL_PATH), Mage::getVersion(),
151: $this->getNoticeSeverity())
152: ;
153: }
154: return $this->_severityIconsUrl;
155: }
156:
157: /**
158: * Retrieve severity text
159: *
160: * @return string
161: */
162: public function getSeverityText()
163: {
164: return strtolower(str_replace('SEVERITY_', '', $this->getNoticeSeverity()));
165: }
166:
167: /**
168: * Check if current block allowed in ACL
169: *
170: * @param string $resourcePath
171: * @return bool
172: */
173: protected function _isAllowed()
174: {
175: if (!is_null($this->_aclResourcePath)) {
176: return Mage::getSingleton('admin/session')
177: ->isAllowed('admin/system/adminnotification/show_toolbar');
178: }
179: else {
180: return true;
181: }
182: }
183: }
184: