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
00030
00031
00032
00033
00034 class Mage_Adminhtml_Newsletter_SubscriberController extends Mage_Adminhtml_Controller_Action
00035 {
00036
00037 public function indexAction()
00038 {
00039 if ($this->getRequest()->getParam('ajax')) {
00040 $this->_forward('grid');
00041 return;
00042 }
00043
00044 $this->loadLayout();
00045
00046 $this->_setActiveMenu('newsletter/subscriber');
00047
00048 $this->_addBreadcrumb(Mage::helper('newsletter')->__('Newsletter'), Mage::helper('newsletter')->__('Newsletter'));
00049 $this->_addBreadcrumb(Mage::helper('newsletter')->__('Subscribers'), Mage::helper('newsletter')->__('Subscribers'));
00050
00051 $this->_addContent(
00052 $this->getLayout()->createBlock('adminhtml/newsletter_subscriber','subscriber')
00053 );
00054
00055 $this->renderLayout();
00056 }
00057
00058 public function gridAction()
00059 {
00060 $this->loadLayout();
00061 $this->getResponse()->setBody(
00062 $this->getLayout()->createBlock('adminhtml/newsletter_subscriber_grid')->toHtml()
00063 );
00064 }
00065
00066
00067
00068
00069 public function exportCsvAction()
00070 {
00071 $fileName = 'subscribers.csv';
00072 $content = $this->getLayout()->createBlock('adminhtml/newsletter_subscriber_grid')
00073 ->getCsv();
00074
00075 $this->_prepareDownloadResponse($fileName, $content);
00076 }
00077
00078
00079
00080
00081 public function exportXmlAction()
00082 {
00083 $fileName = 'subscribers.xml';
00084 $content = $this->getLayout()->createBlock('adminhtml/newsletter_subscriber_grid')
00085 ->getXml();
00086
00087 $this->_prepareDownloadResponse($fileName, $content);
00088 }
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100 protected function _sendUploadResponse($fileName, $content, $contentType='application/octet-stream')
00101 {
00102 $this->_prepareDownloadResponse($fileName, $content, $contentType);
00103 }
00104
00105 public function massUnsubscribeAction()
00106 {
00107 $subscribersIds = $this->getRequest()->getParam('subscriber');
00108 if (!is_array($subscribersIds)) {
00109 Mage::getSingleton('adminhtml/session')->addError(Mage::helper('newsletter')->__('Please select subscriber(s)'));
00110 }
00111 else {
00112 try {
00113 foreach ($subscribersIds as $subscriberId) {
00114 $subscriber = Mage::getModel('newsletter/subscriber')->load($subscriberId);
00115 $subscriber->unsubscribe();
00116 }
00117 Mage::getSingleton('adminhtml/session')->addSuccess(
00118 Mage::helper('adminhtml')->__(
00119 'Total of %d record(s) were successfully updated', count($subscribersIds)
00120 )
00121 );
00122 } catch (Exception $e) {
00123 Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
00124 }
00125 }
00126
00127 $this->_redirect('*/*/index');
00128 }
00129
00130 protected function _isAllowed()
00131 {
00132 return Mage::getSingleton('admin/session')->isAllowed('newsletter/subscriber');
00133 }
00134 }