00001 <?php
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 class Mage_Adminhtml_NotificationController extends Mage_Adminhtml_Controller_Action
00030 {
00031     public function indexAction()
00032     {
00033         $this->loadLayout()
00034             ->_setActiveMenu('system/notification')
00035             ->_addBreadcrumb(Mage::helper('adminnotification')->__('Messages Inbox'), Mage::helper('adminhtml')->__('Messages Inbox'))
00036             ->_addContent($this->getLayout()->createBlock('adminhtml/notification_inbox'))
00037             ->renderLayout();
00038     }
00039 
00040     public function markAsReadAction()
00041     {
00042         if ($id = $this->getRequest()->getParam('id')) {
00043             $session = Mage::getSingleton('adminhtml/session');
00044             $model = Mage::getModel('adminnotification/inbox')
00045                 ->load($id);
00046 
00047             if (!$model->getId()) {
00048                 $session->addError(Mage::helper('adminnotification')->__('Unable to proceed. Please, try again'));
00049                 $this->_redirect('*/*/');
00050                 return ;
00051             }
00052 
00053             try {
00054                 $model->setIsRead(1)
00055                     ->save();
00056                 $session->addSuccess(Mage::helper('adminnotification')->__('Message was successfully marked as read'));
00057             }
00058             catch (Mage_Core_Exception $e) {
00059                 $session->addError($e->getMessage());
00060             }
00061             catch (Exception $e) {
00062                 $session->addException($e, Mage::helper('adminnotification')->__('Error while marking as read. Please try again later.'));
00063             }
00064 
00065             $this->_redirectReferer();
00066             return;
00067         }
00068         $this->_redirect('*/*/');
00069     }
00070 
00071     public function massMarkAsReadAction()
00072     {
00073         $session = Mage::getSingleton('adminhtml/session');
00074         $ids = $this->getRequest()->getParam('notification');
00075         if (!is_array($ids)) {
00076             $session->addError(Mage::helper('adminnotification')->__('Please select messages'));
00077         }
00078         else {
00079             try {
00080                 foreach ($ids as $id) {
00081                     $model = Mage::getModel('adminnotification/inbox')
00082                         ->load($id);
00083                     if ($model->getId()) {
00084                         $model->setIsRead(1)
00085                             ->save();
00086                     }
00087                 }
00088                 $this->_getSession()->addSuccess(
00089                     Mage::helper('adminnotification')->__('Total of %d record(s) were successfully marked as read', count($ids))
00090                 );
00091             } catch (Mage_Core_Exception $e) {
00092                 $session->addError($e->getMessage());
00093             }
00094             catch (Exception $e) {
00095                 $session->addException($e, Mage::helper('adminnotification')->__('Error while marking as read. Please try again later.'));
00096             }
00097         }
00098         $this->_redirect('*/*/');
00099     }
00100 
00101     public function removeAction()
00102     {
00103         if ($id = $this->getRequest()->getParam('id')) {
00104             $session = Mage::getSingleton('adminhtml/session');
00105             $model = Mage::getModel('adminnotification/inbox')
00106                 ->load($id);
00107 
00108             if (!$model->getId()) {
00109                 $session->addError(Mage::helper('adminnotification')->__('Unable to proceed. Please, try again'));
00110                 $this->_redirect('*/*/');
00111                 return ;
00112             }
00113 
00114             try {
00115                 $model->setIsRemove(1)
00116                     ->save();
00117                 $session->addSuccess(Mage::helper('adminnotification')->__('Message was successfully removed'));
00118             }
00119             catch (Mage_Core_Exception $e) {
00120                 $session->addError($e->getMessage());
00121             }
00122             catch (Exception $e) {
00123                 $session->addException($e, Mage::helper('adminnotification')->__('Error while removing. Please try again later.'));
00124             }
00125 
00126             $this->_redirectReferer();
00127             return;
00128         }
00129         $this->_redirect('*/*/');
00130     }
00131 
00132     public function massRemoveAction()
00133     {
00134         $session = Mage::getSingleton('adminhtml/session');
00135         $ids = $this->getRequest()->getParam('notification');
00136         if (!is_array($ids)) {
00137             $session->addError(Mage::helper('adminnotification')->__('Please select messages'));
00138         }
00139         else {
00140             try {
00141                 foreach ($ids as $id) {
00142                     $model = Mage::getModel('adminnotification/inbox')
00143                         ->load($id);
00144                     if ($model->getId()) {
00145                         $model->setIsRemove(1)
00146                             ->save();
00147                     }
00148                 }
00149                 $this->_getSession()->addSuccess(
00150                     Mage::helper('adminnotification')->__('Total of %d record(s) were successfully removed', count($ids))
00151                 );
00152             } catch (Mage_Core_Exception $e) {
00153                 $session->addError($e->getMessage());
00154             }
00155             catch (Exception $e) {
00156                 $session->addException($e, Mage::helper('adminnotification')->__('Error while marking. Please try again later.'));
00157             }
00158         }
00159         $this->_redirectReferer();
00160     }
00161 
00162     protected function _isAllowed()
00163     {
00164         switch ($this->getRequest()->getActionName()) {
00165             case 'markAsRead':
00166                 $acl = 'system/adminnotification/mark_as_read';
00167                 break;
00168 
00169             case 'massMarkAsRead':
00170                 $acl = 'system/adminnotification/mark_as_read';
00171                 break;
00172 
00173             case 'remove':
00174                 $acl = 'system/adminnotification/remove';
00175                 break;
00176 
00177             case 'massRemove':
00178                 $acl = 'system/adminnotification/remove';
00179                 break;
00180 
00181             default:
00182                 $acl = 'system/adminnotification/show_list';
00183         }
00184         return Mage::getSingleton('admin/session')->isAllowed($acl);
00185     }
00186 }