public function statusAction()
 {
     $id = $this->_getParam('id');
     $code = $this->_getParam('code');
     $status = $this->_getParam('new_status');
     //check input
     if (!isset($id)) {
         throw new Zend_Exception('Subscription not found');
     }
     if (!isset($code)) {
         throw new Zend_Exception('Subscription not found');
     }
     if (!isset($status) || !in_array($status, array('subscribed', 'unsubscribed'))) {
         throw new Zend_Exception('Subscription not found');
     }
     $subscription = new Contact_Model_Subscription();
     if (!Contact_Model_SubscriptionMapper::getInstance()->findByCode($id, $code, $subscription)) {
         throw new Zend_Exception('Subscription not found');
     }
     //update status
     if ($subscription->get_status() != $status) {
         $subscription->set_status($status);
         $dt = date("Y-m-d H:i:s");
         if ($status == 'subscribed') {
             $subscription->set_subscribed_dt($dt);
         } else {
             $subscription->set_unsubscribed_dt($dt);
         }
         Contact_Model_SubscriptionMapper::getInstance()->save($subscription);
     }
     $this->view->subscription = $subscription;
     $this->renderScript('subscribe-generic/' . CURR_LANG . '/status_' . $status . '.phtml');
 }
 /**
  * Export action
  */
 public function exportAction()
 {
     $langFilter = $this->_request->getParam('langFilter');
     $searchFilter = $this->_request->getParam('searchFilter');
     $fromFilter = $this->_request->getParam('fromFilter');
     $toFilter = $this->_request->getParam('toFilter');
     //contact types
     $header = array('status' => $this->translate('Status'), 'first_name' => $this->translate('First Name'), 'last_name' => $this->translate('Last Name'), 'gender' => $this->translate('Gender'), 'email' => $this->translate('Email'), 'lang' => $this->translate('Language'), 'subscribed_dt' => $this->translate('Subscribed'), 'unsubscribed_dt' => $this->translate('Unsubscribed'));
     $criteria = array('application_id' => $this->_applicationId, 'data_type' => 'array');
     $criteria = array('application_id' => $this->_applicationId);
     if (null != $this->_getParam('langFilter')) {
         $criteria['lang'] = $this->_getParam('langFilter');
     }
     if (null != $this->_getParam('statusFilter')) {
         $criteria['status'] = $this->_getParam('statusFilter');
     }
     if (null != $this->_getParam('genderFilter')) {
         $criteria['gender'] = $this->_getParam('genderFilter');
     }
     if (null != $this->_getParam('subscribed_from_dt')) {
         $criteria['subscribed_from'] = HCMS_Utils_Date::dateLocalToIso($this->_getParam('subscribed_from_dt'));
     }
     if (null != $this->_getParam('subscribed_to_dt')) {
         $criteria['subscribed_to'] = HCMS_Utils_Date::dateLocalToIso($this->_getParam('subscribed_to_dt'));
     }
     if (null != $this->_getParam('unsubscribed_from_dt')) {
         $criteria['unsubscribed_from'] = HCMS_Utils_Date::dateLocalToIso($this->_getParam('unsubscribed_from_dt'));
     }
     if (null != $this->_getParam('unsubscribed_to_dt')) {
         $criteria['unsubscribed_to'] = HCMS_Utils_Date::dateLocalToIso($this->_getParam('unsubscribed_to_dt'));
     }
     if (isset($orderFilter) && !empty($orderFilter)) {
         $orderBy = array($orderFilter);
     } else {
         $orderBy = array('s.subscribed_dt DESC', 's.unsubscribed_dt DESC', 's.id DESC');
     }
     //read data to export
     $records = Contact_Model_SubscriptionMapper::getInstance()->fetchAll($criteria, $orderBy);
     /* @var $record Contact_Model_Subscription */
     foreach ($records as $record) {
         $recordArr = $record->toArray();
         $recordArr['gender'] = isset($recordArr['gender']) ? $this->view->translate($recordArr['gender']) : '';
         $records_trans[] = $recordArr;
     }
     //get exported object
     $objPHPExcel = Contact_Model_SubscriptionMapper::getInstance()->exportToExcel($this->_applicationId, $header, $records_trans, $this);
     if ($objPHPExcel != null) {
         while (ob_get_level() > 0) {
             ob_end_clean();
         }
         //disable layout
         $this->_helper->layout->disableLayout();
         $this->_helper->viewRenderer->setNoRender(true);
         // rename sheet
         $objPHPExcel->getActiveSheet()->setTitle($this->translate($this->_application->get_name()));
         $fileName = $this->_application->get_name() . "-newsletter-subscriptions" . "-" . Zend_Date::now()->toString('d-MMM-Y') . ".xls";
         // redirect output to client browser
         header('Content-Type: application/vnd.ms-excel');
         header('Content-Disposition: attachment;filename="' . $fileName . '"');
         header('Cache-Control: max-age=0');
         //create excel writer
         $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
         // output to browser
         $objWriter->save('php://output');
         exit;
     } else {
         $this->getHelper('flashMessenger')->addMessage(array("err" => $this->translate("Error occurred while exporting!")));
         $this->_redirect($this->view->url(array('action' => 'index')));
     }
 }