Overview

Packages

  • currencysymbol
  • MAbout
  • Mage
    • Admin
    • Adminhtml
    • AdminNotification
    • Api
    • Api2
    • Authorizenet
    • Backup
    • Bundle
    • Captcha
    • Catalog
    • CatalogIndex
    • CatalogInventory
    • CatalogRule
    • CatalogSearch
    • Centinel
    • Checkout
    • Cms
    • Compiler
    • Connect
    • Contacts
    • Core
    • Cron
    • CurrencySymbol
    • Customer
    • Dataflow
    • Directory
    • DirtectPost
    • Downloadable
    • Eav
    • GiftMessage
    • GoogleAnalytics
    • GoogleBase
    • GoogleCheckout
    • ImportExport
    • Index
    • Install
    • Log
    • Media
    • Newsletter
    • Oauth
    • Page
    • PageCache
    • Paygate
    • Payment
    • Paypal
    • PaypalUk
    • Persistent
    • Poll
    • ProductAlert
    • Rating
    • Reports
    • Review
    • Rss
    • Rule
    • Sales
    • SalesRule
    • Sedfriend
    • Sendfriend
    • Shipping
    • Sitemap
    • Tag
    • Tax
    • Usa
    • Weee
    • Widget
    • Wishlist
    • XmlConnect
  • None
  • Phoenix
    • Moneybookers
  • PHP
  • Zend
    • Date
    • Mime
    • XmlRpc

Classes

  • Mage_XmlConnect_Adminhtml_MobileController
  • Mage_XmlConnect_Block_Adminhtml_History
  • Mage_XmlConnect_Block_Adminhtml_History_Grid
  • Mage_XmlConnect_Block_Adminhtml_Mobile
  • Mage_XmlConnect_Block_Adminhtml_Mobile_Edit
  • Mage_XmlConnect_Block_Adminhtml_Mobile_Edit_Form
  • Mage_XmlConnect_Block_Adminhtml_Mobile_Edit_Submission
  • Mage_XmlConnect_Block_Adminhtml_Mobile_Edit_Tab_Cache
  • Mage_XmlConnect_Block_Adminhtml_Mobile_Edit_Tab_Content
  • Mage_XmlConnect_Block_Adminhtml_Mobile_Edit_Tab_Design
  • Mage_XmlConnect_Block_Adminhtml_Mobile_Edit_Tab_Design_Accordion
  • Mage_XmlConnect_Block_Adminhtml_Mobile_Edit_Tab_Design_Accordion_Images
  • Mage_XmlConnect_Block_Adminhtml_Mobile_Edit_Tab_Design_Accordion_Tabs
  • Mage_XmlConnect_Block_Adminhtml_Mobile_Edit_Tab_Design_Accordion_Themes
  • Mage_XmlConnect_Block_Adminhtml_Mobile_Edit_Tab_Design_Preview
  • Mage_XmlConnect_Block_Adminhtml_Mobile_Edit_Tab_Design_Themes
  • Mage_XmlConnect_Block_Adminhtml_Mobile_Edit_Tab_Flurryanalytics
  • Mage_XmlConnect_Block_Adminhtml_Mobile_Edit_Tab_General
  • Mage_XmlConnect_Block_Adminhtml_Mobile_Edit_Tab_Notification
  • Mage_XmlConnect_Block_Adminhtml_Mobile_Edit_Tab_Payment
  • Mage_XmlConnect_Block_Adminhtml_Mobile_Edit_Tab_Settings
  • Mage_XmlConnect_Block_Adminhtml_Mobile_Edit_Tab_Social
  • Mage_XmlConnect_Block_Adminhtml_Mobile_Edit_Tab_Submission_History
  • Mage_XmlConnect_Block_Adminhtml_Mobile_Edit_Tabs
  • Mage_XmlConnect_Block_Adminhtml_Mobile_Form_Element_Addrow
  • Mage_XmlConnect_Block_Adminhtml_Mobile_Form_Element_Color
  • Mage_XmlConnect_Block_Adminhtml_Mobile_Form_Element_Country
  • Mage_XmlConnect_Block_Adminhtml_Mobile_Form_Element_Datetime
  • Mage_XmlConnect_Block_Adminhtml_Mobile_Form_Element_Font
  • Mage_XmlConnect_Block_Adminhtml_Mobile_Form_Element_Image
  • Mage_XmlConnect_Block_Adminhtml_Mobile_Form_Element_Page
  • Mage_XmlConnect_Block_Adminhtml_Mobile_Form_Element_Tabs
  • Mage_XmlConnect_Block_Adminhtml_Mobile_Form_Element_Theme
  • Mage_Xmlconnect_Block_Adminhtml_Mobile_Grid
  • Mage_XmlConnect_Block_Adminhtml_Mobile_Grid_Renderer_Bool
  • Mage_XmlConnect_Block_Adminhtml_Mobile_Grid_Renderer_Type
  • Mage_XmlConnect_Block_Adminhtml_Mobile_Preview_Content
  • Mage_XmlConnect_Block_Adminhtml_Mobile_Preview_Tabitems
  • Mage_XmlConnect_Block_Adminhtml_Mobile_Submission
  • Mage_XmlConnect_Block_Adminhtml_Mobile_Submission_Form
  • Mage_XmlConnect_Block_Adminhtml_Mobile_Submission_Renderer_Country_Androidmarket
  • Mage_XmlConnect_Block_Adminhtml_Mobile_Submission_Renderer_Country_Istore
  • Mage_XmlConnect_Block_Adminhtml_Mobile_Submission_Tab_Container
  • Mage_XmlConnect_Block_Adminhtml_Mobile_Submission_Tab_Container_Submission
  • Mage_XmlConnect_Block_Adminhtml_Mobile_Submission_Tabs
  • Mage_XmlConnect_Block_Adminhtml_Mobile_Widget_Form
  • Mage_XmlConnect_Block_Adminhtml_Queue
  • Mage_XmlConnect_Block_Adminhtml_Queue_Edit
  • Mage_XmlConnect_Block_Adminhtml_Queue_Edit_Form
  • Mage_XmlConnect_Block_Adminhtml_Queue_Grid
  • Mage_XmlConnect_Block_Adminhtml_Queue_Grid_Renderer_Action
  • Mage_XmlConnect_Block_Adminhtml_Queue_Grid_Renderer_Application
  • Mage_XmlConnect_Block_Adminhtml_Queue_Grid_Renderer_Id
  • Mage_XmlConnect_Block_Adminhtml_Queue_Grid_Renderer_Msgtitle
  • Mage_XmlConnect_Block_Adminhtml_Queue_Grid_Renderer_Pushtitle
  • Mage_XmlConnect_Block_Adminhtml_Queue_Grid_Renderer_Status
  • Mage_XmlConnect_Block_Adminhtml_Queue_Grid_Renderer_Template
  • Mage_XmlConnect_Block_Adminhtml_Template
  • Mage_XmlConnect_Block_Adminhtml_Template_Edit
  • Mage_XmlConnect_Block_Adminhtml_Template_Edit_Form
  • Mage_XmlConnect_Block_Adminhtml_Template_Grid
  • Mage_XmlConnect_Block_Adminhtml_Template_Grid_Renderer_Application
  • Mage_XmlConnect_Block_Adminhtml_Template_Grid_Renderer_Name
  • Mage_XmlConnect_Block_Adminhtml_Template_Preview
  • Mage_XmlConnect_Block_Adminhtml_Template_Preview_Form
  • Mage_XmlConnect_Block_Cart
  • Mage_XmlConnect_Block_Cart_Crosssell
  • Mage_XmlConnect_Block_Cart_Info
  • Mage_XmlConnect_Block_Cart_Item_Renderer
  • Mage_XmlConnect_Block_Cart_Item_Renderer_Configurable
  • Mage_XmlConnect_Block_Cart_Item_Renderer_Grouped
  • Mage_XmlConnect_Block_Cart_Paypal_Mecl_Details
  • Mage_XmlConnect_Block_Cart_Paypal_Mecl_Review
  • Mage_XmlConnect_Block_Cart_Paypal_Mecl_Shippingmethods
  • Mage_XmlConnect_Block_Cart_Paypal_Mep_Totals
  • Mage_XmlConnect_Block_Cart_Totals
  • Mage_XmlConnect_Block_Catalog
  • Mage_XmlConnect_Block_Catalog_Category
  • Mage_XmlConnect_Block_Catalog_Category_Info
  • Mage_XmlConnect_Block_Catalog_Filters
  • Mage_XmlConnect_Block_Catalog_Product
  • Mage_XmlConnect_Block_Catalog_Product_Attributes
  • Mage_XmlConnect_Block_Catalog_Product_Gallery
  • Mage_XmlConnect_Block_Catalog_Product_List
  • Mage_XmlConnect_Block_Catalog_Product_Options
  • Mage_XmlConnect_Block_Catalog_Product_Options_Bundle
  • Mage_XmlConnect_Block_Catalog_Product_Options_Configurable
  • Mage_XmlConnect_Block_Catalog_Product_Options_Giftcard
  • Mage_XmlConnect_Block_Catalog_Product_Options_Grouped
  • Mage_XmlConnect_Block_Catalog_Product_Options_Simple
  • Mage_XmlConnect_Block_Catalog_Product_Options_Virtual
  • Mage_XmlConnect_Block_Catalog_Product_Price
  • Mage_XmlConnect_Block_Catalog_Product_Price_Bundle
  • Mage_XmlConnect_Block_Catalog_Product_Price_Default
  • Mage_XmlConnect_Block_Catalog_Product_Price_Giftcard
  • Mage_XmlConnect_Block_Catalog_Product_Related
  • Mage_XmlConnect_Block_Catalog_Product_Review
  • Mage_XmlConnect_Block_Catalog_Product_Review_List
  • Mage_XmlConnect_Block_Catalog_Search
  • Mage_XmlConnect_Block_Catalog_Search_Suggest
  • Mage_XmlConnect_Block_Checkout_Address_Billing
  • Mage_XmlConnect_Block_Checkout_Address_Form
  • Mage_XmlConnect_Block_Checkout_Address_Shipping
  • Mage_XmlConnect_Block_Checkout_Agreements
  • Mage_XmlConnect_Block_Checkout_Order_Review
  • Mage_XmlConnect_Block_Checkout_Order_Review_Info
  • Mage_XmlConnect_Block_Checkout_Payment_Method_Authorizenet
  • Mage_XmlConnect_Block_Checkout_Payment_Method_Ccsave
  • Mage_XmlConnect_Block_Checkout_Payment_Method_Checkmo
  • Mage_XmlConnect_Block_Checkout_Payment_Method_Info_Authorizenet
  • Mage_XmlConnect_Block_Checkout_Payment_Method_Info_Ccsave
  • Mage_XmlConnect_Block_Checkout_Payment_Method_Info_Checkmo
  • Mage_XmlConnect_Block_Checkout_Payment_Method_Info_Free
  • Mage_XmlConnect_Block_Checkout_Payment_Method_Info_Paypal_Abstract
  • Mage_XmlConnect_Block_Checkout_Payment_Method_Info_Paypal_Express
  • Mage_XmlConnect_Block_Checkout_Payment_Method_Info_Paypal_Mecl
  • Mage_XmlConnect_Block_Checkout_Payment_Method_Info_Pbridge_Authorizenet
  • Mage_XmlConnect_Block_Checkout_Payment_Method_Info_Pbridge_Paypal_Direct
  • Mage_XmlConnect_Block_Checkout_Payment_Method_Info_Pbridge_Paypaluk_Direct
  • Mage_XmlConnect_Block_Checkout_Payment_Method_Info_Pbridge_Verisign
  • Mage_XmlConnect_Block_Checkout_Payment_Method_Info_Purchaseorder
  • Mage_XmlConnect_Block_Checkout_Payment_Method_List
  • Mage_XmlConnect_Block_Checkout_Payment_Method_Paypal_Direct
  • Mage_XmlConnect_Block_Checkout_Payment_Method_Paypal_Payflow
  • Mage_XmlConnect_Block_Checkout_Payment_Method_Pbridge_Abstract
  • Mage_XmlConnect_Block_Checkout_Payment_Method_Pbridge_Authorizenet
  • Mage_XmlConnect_Block_Checkout_Payment_Method_Pbridge_Paypal
  • Mage_XmlConnect_Block_Checkout_Payment_Method_Pbridge_Paypaluk
  • Mage_XmlConnect_Block_Checkout_Payment_Method_Pbridge_Verisign
  • Mage_XmlConnect_Block_Checkout_Payment_Method_Purchaseorder
  • Mage_XmlConnect_Block_Checkout_Pbridge_Result
  • Mage_XmlConnect_Block_Checkout_Shipping_Method_Available
  • Mage_XmlConnect_Block_Cms_Page
  • Mage_XmlConnect_Block_Configuration
  • Mage_XmlConnect_Block_Customer_Address_Form
  • Mage_XmlConnect_Block_Customer_Address_List
  • Mage_XmlConnect_Block_Customer_Form
  • Mage_XmlConnect_Block_Customer_Form_Renderer_Boolean
  • Mage_XmlConnect_Block_Customer_Form_Renderer_Date
  • Mage_XmlConnect_Block_Customer_Form_Renderer_File
  • Mage_XmlConnect_Block_Customer_Form_Renderer_Image
  • Mage_XmlConnect_Block_Customer_Form_Renderer_Multiline
  • Mage_XmlConnect_Block_Customer_Form_Renderer_Multiselect
  • Mage_XmlConnect_Block_Customer_Form_Renderer_Select
  • Mage_XmlConnect_Block_Customer_Form_Renderer_Text
  • Mage_XmlConnect_Block_Customer_Form_Renderer_Textarea
  • Mage_XmlConnect_Block_Customer_GiftcardCheck
  • Mage_XmlConnect_Block_Customer_Order_Details
  • Mage_XmlConnect_Block_Customer_Order_Item_Renderer_Bundle
  • Mage_XmlConnect_Block_Customer_Order_Item_Renderer_Default
  • Mage_XmlConnect_Block_Customer_Order_Item_Renderer_Downloadable
  • Mage_XmlConnect_Block_Customer_Order_Item_Renderer_Giftcard
  • Mage_XmlConnect_Block_Customer_Order_Item_Renderer_Grouped
  • Mage_XmlConnect_Block_Customer_Order_Items
  • Mage_XmlConnect_Block_Customer_Order_List
  • Mage_XmlConnect_Block_Customer_Order_Totals
  • Mage_XmlConnect_Block_Customer_Order_Totals_Customerbalance
  • Mage_XmlConnect_Block_Customer_Order_Totals_Customerbalance_Refunded
  • Mage_XmlConnect_Block_Customer_Order_Totals_Giftcards
  • Mage_XmlConnect_Block_Customer_Order_Totals_Tax
  • Mage_XmlConnect_Block_Customer_Storecredit
  • Mage_XmlConnect_Block_Home
  • Mage_XmlConnect_Block_Review_Form
  • Mage_XmlConnect_Block_Wishlist
  • Mage_XmlConnect_CartController
  • Mage_XmlConnect_CatalogController
  • Mage_XmlConnect_CheckoutController
  • Mage_XmlConnect_CmsController
  • Mage_XmlConnect_ConfigurationController
  • Mage_XmlConnect_Controller_Action
  • Mage_XmlConnect_CustomerController
  • Mage_XmlConnect_Helper_Android
  • Mage_XmlConnect_Helper_Catalog_Category_Image
  • Mage_XmlConnect_Helper_Customer_Form_Renderer
  • Mage_XmlConnect_Helper_Customer_Order
  • Mage_XmlConnect_Helper_Data
  • Mage_XmlConnect_Helper_Image
  • Mage_XmlConnect_Helper_Ipad
  • Mage_XmlConnect_Helper_Iphone
  • Mage_XmlConnect_Helper_Theme
  • Mage_XmlConnect_IndexController
  • Mage_XmlConnect_Model_Adminhtml_System_Config_Backend_Baseurl
  • Mage_XmlConnect_Model_Adminhtml_System_Config_Backend_Currency_Default
  • Mage_XmlConnect_Model_Application
  • Mage_XmlConnect_Model_Catalog_Category_Image
  • Mage_XmlConnect_Model_ConfigData
  • Mage_XmlConnect_Model_History
  • Mage_XmlConnect_Model_Mysql4_Application
  • Mage_XmlConnect_Model_Mysql4_Application_Collection
  • Mage_XmlConnect_Model_Mysql4_Cms_Page_Collection
  • Mage_XmlConnect_Model_Mysql4_ConfigData
  • Mage_XmlConnect_Model_Mysql4_ConfigData_Collection
  • Mage_XmlConnect_Model_Mysql4_Filter_Collection
  • Mage_XmlConnect_Model_Mysql4_History
  • Mage_XmlConnect_Model_Mysql4_History_Collection
  • Mage_XmlConnect_Model_Mysql4_Queue
  • Mage_XmlConnect_Model_Mysql4_Queue_Collection
  • Mage_XmlConnect_Model_Mysql4_Setup
  • Mage_XmlConnect_Model_Mysql4_Template
  • Mage_XmlConnect_Model_Mysql4_Template_Collection
  • Mage_XmlConnect_Model_Observer
  • Mage_XmlConnect_Model_Payment_Method_Paypal_Config
  • Mage_XmlConnect_Model_Payment_Method_Paypal_Mecl
  • Mage_XmlConnect_Model_Payment_Method_Paypal_Mep
  • Mage_XmlConnect_Model_Paypal_Mecl_Checkout
  • Mage_XmlConnect_Model_Paypal_Mep_Checkout
  • Mage_XmlConnect_Model_Preview_Abstract
  • Mage_XmlConnect_Model_Preview_Android
  • Mage_XmlConnect_Model_Preview_Ipad
  • Mage_XmlConnect_Model_Preview_Iphone
  • Mage_XmlConnect_Model_Queue
  • Mage_XmlConnect_Model_Resource_Application
  • Mage_XmlConnect_Model_Resource_Application_Collection
  • Mage_XmlConnect_Model_Resource_Cms_Page_Collection
  • Mage_XmlConnect_Model_Resource_ConfigData
  • Mage_XmlConnect_Model_Resource_ConfigData_Collection
  • Mage_XmlConnect_Model_Resource_Filter_Collection
  • Mage_XmlConnect_Model_Resource_History
  • Mage_XmlConnect_Model_Resource_History_Collection
  • Mage_XmlConnect_Model_Resource_Queue
  • Mage_XmlConnect_Model_Resource_Queue_Collection
  • Mage_XmlConnect_Model_Resource_Setup
  • Mage_XmlConnect_Model_Resource_Template
  • Mage_XmlConnect_Model_Resource_Template_Collection
  • Mage_XmlConnect_Model_Simplexml_Element
  • Mage_XmlConnect_Model_Simplexml_Form
  • Mage_XmlConnect_Model_Simplexml_Form_Abstract
  • Mage_XmlConnect_Model_Simplexml_Form_Element_Abstract
  • Mage_XmlConnect_Model_Simplexml_Form_Element_Checkbox
  • Mage_XmlConnect_Model_Simplexml_Form_Element_Collection
  • Mage_XmlConnect_Model_Simplexml_Form_Element_CountryListSelect
  • Mage_XmlConnect_Model_Simplexml_Form_Element_Date
  • Mage_XmlConnect_Model_Simplexml_Form_Element_Email
  • Mage_XmlConnect_Model_Simplexml_Form_Element_Fieldset
  • Mage_XmlConnect_Model_Simplexml_Form_Element_File
  • Mage_XmlConnect_Model_Simplexml_Form_Element_Image
  • Mage_XmlConnect_Model_Simplexml_Form_Element_Multiline
  • Mage_XmlConnect_Model_Simplexml_Form_Element_Multiselect
  • Mage_XmlConnect_Model_Simplexml_Form_Element_Select
  • Mage_XmlConnect_Model_Simplexml_Form_Element_Text
  • Mage_XmlConnect_Model_Simplexml_Form_Element_Textarea
  • Mage_XmlConnect_Model_Simplexml_Form_Element_Validator
  • Mage_XmlConnect_Model_Simplexml_Form_Element_Validator_Abstract
  • Mage_XmlConnect_Model_Simplexml_Form_Element_Validator_Rule
  • Mage_XmlConnect_Model_Tabs
  • Mage_XmlConnect_Model_Template
  • Mage_XmlConnect_Model_Theme
  • Mage_XmlConnect_Paypal_MeclController
  • Mage_XmlConnect_Paypal_MepController
  • Mage_XmlConnect_PbridgeController
  • Mage_XmlConnect_ReviewController
  • Mage_XmlConnect_WishlistController

Interfaces

  • Mage_XmlConnect_Model_Simplexml_Form_Element_Renderer_Interface
  • Overview
  • Package
  • Class
  • Tree
   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_XmlConnect
  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: /**
  28:  * XmlConnect Adminhtml mobile controller
  29:  *
  30:  * @category    Mage
  31:  * @package     Mage_XmlConnect
  32:  * @author      Magento Core Team <core@magentocommerce.com>
  33:  */
  34: class Mage_XmlConnect_Adminhtml_MobileController extends Mage_Adminhtml_Controller_Action
  35: {
  36:     /**
  37:      * Initialize application
  38:      *
  39:      * @param string $paramName
  40:      * @param bool|string $type
  41:      * @return Mage_XmlConnect_Model_Application
  42:      */
  43:     protected function _initApp($paramName = 'application_id', $type = false)
  44:     {
  45:         $id = (int) $this->getRequest()->getParam($paramName);
  46:         $app = Mage::getModel('xmlconnect/application');
  47:         if ($id) {
  48:             $app->load($id);
  49:             if ($app->getId()) {
  50:                 $app->loadConfiguration();
  51:             }
  52:         } else {
  53:             $app->setType($type);
  54:             Mage::register('current_app', $app);
  55:             $app->loadDefaultConfiguration();
  56:             Mage::unregister('current_app');
  57:         }
  58:         Mage::register('current_app', $app);
  59:         return $app;
  60:     }
  61: 
  62:     /**
  63:      * Restore data from session $_POST and $_FILES (processed)
  64:      *
  65:      * @param array $data
  66:      * @return array|null
  67:      */
  68:     protected function _restoreSessionFilesFormData($data)
  69:     {
  70:         $filesData = Mage::getSingleton('adminhtml/session')->getUploadedFilesFormData(true);
  71:         if (!empty($filesData) && is_array($filesData)) {
  72:             if (!is_array($data)) {
  73:                 $data = array();
  74:             }
  75:             foreach ($filesData as $filePath => $fileName) {
  76:                 $target =& $data;
  77:                 Mage::helper('xmlconnect')->_injectFieldToArray($target, $filePath, $fileName);
  78:             }
  79:         }
  80:         return $data;
  81:     }
  82: 
  83:     /**
  84:      * Mobile applications management
  85:      *
  86:      * @return null
  87:      */
  88:     public function indexAction()
  89:     {
  90:         $this->loadLayout();
  91:         $this->_setActiveMenu('xmlconnect/mobile');
  92:         $this->renderLayout();
  93:     }
  94: 
  95:     /**
  96:      * Create new app
  97:      *
  98:      * @return null
  99:      */
 100:     public function newAction()
 101:     {
 102:         Mage::getSingleton('adminhtml/session')->setData('new_application', true);
 103:         $this->loadLayout();
 104:         $this->_setActiveMenu('xmlconnect/mobile');
 105:         $this->renderLayout();
 106:     }
 107: 
 108:     /**
 109:      * Submission Action, loads application data
 110:      *
 111:      * @return null
 112:      */
 113:     public function submissionAction()
 114:     {
 115:         try {
 116:             $app = $this->_initApp();
 117:             if (!$app->getId()) {
 118:                 $this->_getSession()->addError($this->__('App does not exist.'));
 119:                 $this->_redirect('*/*/');
 120:                 return;
 121:             }
 122:             $app->loadSubmit();
 123:             if ((bool) Mage::getSingleton('adminhtml/session')->getLoadSessionFlag(true)) {
 124:                 $data = $this->_restoreSessionFilesFormData(
 125:                     Mage::getSingleton('adminhtml/session')->getFormSubmissionData(true)
 126:                 );
 127:                 if (!empty($data)) {
 128:                     $app->setData(Mage::helper('xmlconnect')->arrayMergeRecursive($app->getData(), $data));
 129:                 }
 130:             }
 131: 
 132:             $this->loadLayout();
 133:             $this->_setActiveMenu('xmlconnect/mobile');
 134:             $this->renderLayout();
 135:         } catch (Mage_Core_Exception $e) {
 136:             $this->_getSession()->addError($e->getMessage());
 137:             if (isset($app)) {
 138:                 $this->_redirect('*/*/edit', array('application_id' => $app->getId()));
 139:             } else {
 140:                 $this->_redirect('*/*/');
 141:             }
 142:         } catch (Exception $e) {
 143:             $this->_getSession()->addException($e, $this->__('Can\'t open submission form.'));
 144:             if (isset($app)) {
 145:                 $this->_redirect('*/*/edit', array('application_id' => $app->getId()));
 146:             } else {
 147:                 $this->_redirect('*/*/');
 148:             }
 149:         }
 150:     }
 151: 
 152:     /**
 153:      * Edit app form
 154:      *
 155:      * @return null
 156:      */
 157:     public function editAction()
 158:     {
 159:         $redirectBack = false;
 160:         try {
 161:             $id = (int) $this->getRequest()->getParam('application_id');
 162:             $type = $this->getRequest()->getParam('type');
 163:             $app = $this->_initApp('application_id', $type);
 164: 
 165:             if (!$app->getId() && $id) {
 166:                 $this->_getSession()->addError($this->__('App does not exist.'));
 167:                 $this->_redirect('*/*/');
 168:                 return;
 169:             }
 170: 
 171:             $newAppData = $this->_restoreSessionFilesFormData(
 172:                 Mage::getSingleton('adminhtml/session')->getFormData(true)
 173:             );
 174: 
 175:             if (!empty($newAppData)) {
 176:                 $app->setData(Mage::helper('xmlconnect')->arrayMergeRecursive($app->getData(), $newAppData));
 177:             }
 178: 
 179:             if ($app->getId() || $app->getType()) {
 180:                 Mage::getSingleton('adminhtml/session')->setData('new_application', false);
 181:             } else {
 182:                 $this->_redirect('*/*/new');
 183:             }
 184: 
 185:             $devArray = Mage::helper('xmlconnect')->getSupportedDevices();
 186:             if (array_key_exists($app->getType(), $devArray)) {
 187:                 $deviceTitle = $devArray[$app->getType()];
 188:             }
 189:             $deviceTitle = isset($deviceTitle) ? $deviceTitle : $app->getType();
 190:             $app->setDevtype($deviceTitle);
 191:             $app->loadSubmit();
 192:             $this->loadLayout();
 193:             $this->_setActiveMenu('xmlconnect/mobile');
 194:             $this->renderLayout();
 195:         } catch (Mage_Core_Exception $e) {
 196:             $this->_getSession()->addError($e->getMessage());
 197:             $redirectBack = true;
 198:         } catch (Exception $e) {
 199:             $this->_getSession()->addError($this->__('Unable to load application form.'));
 200:             $redirectBack = true;
 201:             Mage::logException($e);
 202:         }
 203:         if ($redirectBack) {
 204:             $this->_redirect('*/*/');
 205:             return;
 206:         }
 207:     }
 208: 
 209:     /**
 210:      * Submit POST application action
 211:      *
 212:      * @return null
 213:      */
 214:     public function submissionPostAction()
 215:     {
 216:         $data = $this->getRequest()->getPost();
 217:         try {
 218:             $isError = false;
 219:             if (!empty($data)) {
 220:                 Mage::getSingleton('adminhtml/session')->setFormSubmissionData($this->_filterFormDataForSession($data));
 221:             }
 222:             /** @var $app Mage_XmlConnect_Model_Application */
 223:             $app = $this->_initApp('key');
 224:             $app->loadSubmit();
 225:             $newAppData = $this->_processUploadedFiles($app->getData(), true);
 226:             if (!empty($newAppData)) {
 227:                 $app->setData(Mage::helper('xmlconnect')->arrayMergeRecursive($app->getData(), $newAppData));
 228:             }
 229:             $params = $app->prepareSubmitParams($data);
 230:             $errors = $app->validateSubmit($params);
 231:             if ($errors !== true) {
 232:                 foreach ($errors as $err) {
 233:                     $this->_getSession()->addError($err);
 234:                 }
 235:                 $isError = true;
 236:             }
 237:             if (!$isError) {
 238:                 $this->_processPostRequest();
 239:                 $history = Mage::getModel('xmlconnect/history');
 240:                 $history->setData(array(
 241:                     'params' => $params, 'application_id' => $app->getId(),
 242:                     'created_at' => Mage::getModel('core/date')->date(), 'store_id' => $app->getStoreId(),
 243:                     'title' => isset($params['title']) ? $params['title'] : '', 'name' => $app->getName(),
 244:                     'code' => $app->getCode(), 'activation_key' => isset($params['resubmission_activation_key'])
 245:                         ? $params['resubmission_activation_key'] : $params['key'],
 246:                 ));
 247:                 $history->save();
 248:                 $app->getResource()->updateApplicationStatus(
 249:                     $app->getId(), Mage_XmlConnect_Model_Application::APP_STATUS_SUCCESS
 250:                 );
 251:                 $this->_getSession()->addSuccess($this->__('App has been submitted.'));
 252:                 $this->_clearSessionData();
 253:                 $this->_redirect('*/*/edit', array('application_id' => $app->getId()));
 254:             } else {
 255:                 Mage::getSingleton('adminhtml/session')->setLoadSessionFlag(true);
 256:                 $this->_redirect('*/*/submission', array('application_id' => $app->getId()));
 257:             }
 258:         } catch (Mage_Core_Exception $e) {
 259:             $this->_getSession()->addError($e->getMessage());
 260:             if (isset($app)) {
 261:                 Mage::getSingleton('adminhtml/session')->setLoadSessionFlag(true);
 262:                 $this->_redirect('*/*/submission', array('application_id' => $app->getId()));
 263:             } else {
 264:                 $this->_redirect('*/*/');
 265:             }
 266:         } catch (Exception $e) {
 267:             $this->_getSession()->addException($e, $this->__('Can\'t submit application.'));
 268:             Mage::logException($e);
 269:             if (isset($app)) {
 270:                 Mage::getSingleton('adminhtml/session')->setLoadSessionFlag(true);
 271:                 $this->_redirect('*/*/submission', array('application_id' => $app->getId()));
 272:             } else {
 273:                 $this->_redirect('*/*/');
 274:             }
 275:         }
 276:     }
 277: 
 278:     /**
 279:      * Format post/get data for session storage
 280:      *
 281:      * @param array $data - $_REQUEST[]
 282:      * @return array
 283:      */
 284:     protected function _filterFormDataForSession($data)
 285:     {
 286:         $params = null;
 287:         if (isset($data['conf']) && is_array($data['conf'])) {
 288:             if (isset($data['conf']['submit_text']) && is_array($data['conf']['submit_text'])) {
 289:                 $params = &$data['conf']['submit_text'];
 290:             }
 291:         }
 292:         if (isset($params['country']) && is_array($params['country'])) {
 293:             $data['conf']['submit_text']['country'] = implode(',', $params['country']);
 294:         }
 295:         return $data;
 296:     }
 297: 
 298:     /**
 299:      * Clear session data
 300:      * Used after successful save/submit action
 301:      *
 302:      * @return this
 303:      */
 304:     protected function _clearSessionData()
 305:     {
 306:         Mage::getSingleton('adminhtml/session')->unsFormData();
 307:         Mage::getSingleton('adminhtml/session')->unsFormSubmissionData();
 308:         Mage::getSingleton('adminhtml/session')->unsUploadedFilesFormData();
 309:         return $this;
 310:     }
 311: 
 312:     /**
 313:      * Send HTTP POST request to magentocommerce.com
 314:      *
 315:      * @return null
 316:      */
 317:     protected function _processPostRequest()
 318:     {
 319:         try {
 320:             /** @var $app Mage_XmlConnect_Model_Application */
 321:             $app = Mage::helper('xmlconnect')->getApplication();
 322:             $params = $app->getSubmitParams();
 323: 
 324:             $appConnectorUrl = Mage::getStoreConfig('xmlconnect/mobile_application/magentocommerce_url');
 325: 
 326:             $curl = new Varien_Http_Adapter_Curl();
 327:             $verifyPeerValue = Mage::getStoreConfig('xmlconnect/mobile_application/curl_ssl_verifypeer');
 328:             $curl->setConfig(array(
 329:                 'timeout' => Mage_XmlConnect_Helper_Data::CURLOPT_DEFAULT_TIMEOUT,
 330:                 'verifypeer' => $verifyPeerValue, 'verifyhost' => 2, 'header' => false
 331:             ));
 332: 
 333:             $mCommerceUrl = $appConnectorUrl . $params['key'];
 334:             $curl->write(Zend_Http_Client::POST, $mCommerceUrl, CURL_HTTP_VERSION_1_1, array(), $params);
 335: 
 336:             $result = $curl->read();
 337:             if(false === $result) {
 338:                 Mage::log('Curl error: ' . $curl->getError());
 339:                 $curl->close();
 340:                 Mage::throwException($this->__('Request internal error.'));
 341:             }
 342:             $curl->close();
 343: 
 344:             // Assert that we received an expected message in reponse.
 345:             $resultArray = json_decode($result, true);
 346: 
 347:             $app->setResult($result);
 348:             $success = isset($resultArray['success']) && $resultArray['success'] === true;
 349: 
 350:             $app->setSuccess($success);
 351:             if (!$app->getSuccess()) {
 352:                 $message = isset($resultArray['message']) ? $resultArray['message']: '';
 353:                 if (is_array($message)) {
 354:                     $message = implode(' ,', $message);
 355:                 }
 356:                 Mage::throwException($this->__('Submit App failure. %s', $message));
 357:             }
 358:         } catch (Exception $e) {
 359:             throw $e;
 360:         }
 361:     }
 362: 
 363:     /**
 364:      * Save action
 365:      *
 366:      * @return null
 367:      */
 368:     public function saveAction()
 369:     {
 370:         $data = $this->getRequest()->getPost();
 371:         $redirectSubmit = $this->getRequest()->getParam('submitapp', false);
 372:         $app = false;
 373:         $isError = false;
 374:         if ($data) {
 375:             Mage::getSingleton('adminhtml/session')->setFormData($data);
 376:             try {
 377:                 $id = (int) $this->getRequest()->getParam('application_id');
 378: 
 379:                 if (!$id && isset($data['devtype'])) {
 380:                     $devArray = Mage::helper('xmlconnect')->getSupportedDevices();
 381:                     if (!array_key_exists($data['devtype'], $devArray)) {
 382:                         $this->_getSession()->addError($this->__('Wrong device type.'));
 383:                         $isError = true;
 384:                     }
 385:                 }
 386: 
 387:                 $app = $this->_initApp('application_id', $data['devtype']);
 388:                 if (!$app->getId() && $id) {
 389:                     $this->_getSession()->addError($this->__('App does not exist.'));
 390:                     $this->_redirect('*/*/');
 391:                     return;
 392:                 }
 393:                 $app->addData($this->_preparePostData($data));
 394:                 $app->addData($this->_processUploadedFiles($app->getData()));
 395:                 $errors = $app->validate();
 396: 
 397:                 if ($errors !== true) {
 398:                     foreach ($errors as $err) {
 399:                         $this->_getSession()->addError($err);
 400:                     }
 401:                     $isError = true;
 402:                 }
 403: 
 404:                 if (!$isError) {
 405:                     $this->_saveThemeAction($data, 'current_theme');
 406:                     $app->save();
 407:                     $this->_getSession()->addSuccess($this->__('App has been saved.'));
 408:                     $this->_clearSessionData();
 409:                 }
 410:             } catch (Mage_Core_Exception $e) {
 411:                 $this->_getSession()->addException($e, $e->getMessage());
 412:                 $isError = true;
 413:             } catch (Exception $e) {
 414:                 $this->_getSession()->addException($e, $this->__('Unable to save app.'));
 415:                 $isError = true;
 416:                 Mage::logException($e);
 417:             }
 418:         }
 419:         $isApplication = $app instanceof Mage_XmlConnect_Model_Application;
 420:         if (!$isError && $isApplication && $app->getId() && $redirectSubmit) {
 421:             $this->_redirect('*/*/submission', array('application_id' => $app->getId()));
 422:         } else if ($isError && $isApplication && $app->getId()) {
 423:             Mage::getSingleton('adminhtml/session')->setLoadSessionFlag(true);
 424:             $this->_redirect('*/*/edit', array('application_id' => $app->getId()));
 425:         } else if ($isError && $isApplication && !$app->getId() && $app->getType()) {
 426:             $this->_redirect('*/*/edit', array('type' => $app->getType()));
 427:         } else if ($this->getRequest()->getParam('back') && $isApplication) {
 428:             $this->_redirect('*/*/edit', array('application_id' => $app->getId()));
 429:         } else {
 430:             $this->_redirect('*/*/');
 431:         }
 432:     }
 433: 
 434:     /**
 435:      * Save changes to theme
 436:      *
 437:      * @param array     $data
 438:      * @param string    $paramId
 439:      */
 440:     protected function _saveThemeAction($data, $paramId = 'saveTheme')
 441:     {
 442:         $themeName = trim($this->getRequest()->getParam($paramId, false));
 443:         if ($themeName) {
 444:             /** @var $themesHelper Mage_XmlConnect_Helper_Theme */
 445:             $themesHelper = Mage::helper('xmlconnect/theme');
 446:             try {
 447:                 if (array_key_exists($themeName, $themesHelper->getAllThemes())) {
 448:                     /** @var $theme Mage_XmlConnect_Model_Theme */
 449:                     $theme = $themesHelper->getThemeByName($themeName);
 450:                     if ($theme instanceof Mage_XmlConnect_Model_Theme) {
 451:                         if ($paramId == 'saveTheme') {
 452:                             $convertedConf = $this->_convertPost($data);
 453:                         } else {
 454:                             if (isset($data['conf'])) {
 455:                                 $convertedConf = $data['conf'];
 456:                             } else {
 457:                                 $response = array(
 458:                                     'error' => true,
 459:                                     'message' => $this->__('Cannot save theme "%s". Incorrect data received', $themeName)
 460:                                 );
 461:                             }
 462:                         }
 463:                         if (!isset($response)) {
 464:                             $theme->importAndSaveData($convertedConf);
 465:                             $response = array(
 466:                                 'message'   => $this->__('Changes have been saved to theme.'),
 467:                                 'themes'    => $themesHelper->getAllThemesArray(true),
 468:                                 'themeSelector' => $themesHelper->getThemesSelector($themeName),
 469:                                 'selectedTheme' => $themeName
 470:                             );
 471:                         }
 472:                     } else {
 473:                         $response = array('error' => true, 'message' => $this->__('Cannot load theme "%s".', $themeName));
 474:                     }
 475:                 } else {
 476:                     $convertedConf = $this->_convertPost($data);
 477:                     $newTheme = $themesHelper->createNewTheme($themeName, $convertedConf);
 478:                     $response = array(
 479:                         'message'       => $this->__('Theme has been created.'),
 480:                         'themes'        => $themesHelper->getAllThemesArray(true),
 481:                         'themeSelector' => $themesHelper->getThemesSelector($newTheme->getName()),
 482:                         'selectedTheme' => $newTheme->getName()
 483:                     );
 484:                 }
 485:             } catch (Mage_Core_Exception $e) {
 486:                 $response = array('error' => true, 'message' => $e->getMessage());
 487:             } catch (Exception $e) {
 488:                 $response = array('error' => true, 'message' => $this->__('Can\'t save theme.'));
 489:             }
 490:         } else {
 491:             $response = array('error' => true, 'message' => $this->__('Theme name is not set.'));
 492:         }
 493:         if (is_array($response)) {
 494:             $response = Mage::helper('core')->jsonEncode($response);
 495:             $this->getResponse()->setBody($response);
 496:         }
 497:     }
 498: 
 499:     /**
 500:      * Converts native Ajax data from flat to real array
 501:      * Convert array key->value pairs inside array like:
 502:      * "conf_native_bar_tintcolor" => $val   to   $conf['native']['bar']['tintcolor'] => $val
 503:      *
 504:      * @param array $data $_POST
 505:      * @return array
 506:      */
 507:     protected function _convertPost($data)
 508:     {
 509:         $conf = array();
 510:         foreach ($data as $key => $val) {
 511:             $parts = explode('_', $key);
 512:             // "4" - is number of expected params conf_native_bar_tintcolor in correct data
 513:             if (is_array($parts) && count($parts) == 4) {
 514:                 list(, $key1, $key2, $key3) = $parts;
 515:                 if (!isset($conf[$key1])) {
 516:                     $conf[$key1] = array();
 517:                 }
 518:                 if (!isset($conf[$key1][$key2])) {
 519:                     $conf[$key1][$key2] = array();
 520:                 }
 521:                 $conf[$key1][$key2][$key3] = $val;
 522:             }
 523:         }
 524:         return $conf;
 525:     }
 526: 
 527:     /**
 528:      * Delete theme action
 529:      *
 530:      * @return null
 531:      */
 532:     public function deleteThemeAction()
 533:     {
 534:         $themeId = $this->getRequest()->getParam('theme_id', false);
 535:         if ($themeId) {
 536:             try {
 537:                 /** @var $themesHelper Mage_XmlConnect_Helper_Theme */
 538:                 $themesHelper = Mage::helper('xmlconnect/theme');
 539:                 $result = $themesHelper->deleteTheme($themeId);
 540:                 if ($result) {
 541:                     $response = array(
 542:                         'message'   => $this->__('Theme has been delete.'),
 543:                         'themes'    => $themesHelper->getAllThemesArray(true),
 544:                         'themeSelector' => $themesHelper->getThemesSelector(),
 545:                         'selectedTheme' => $themesHelper->getDefaultThemeName()
 546:                     );
 547:                 } else {
 548:                     $response = array(
 549:                         'error'     => true,
 550:                         'message'   => $this->__('Can\'t delete "%s" theme.', $themeId)
 551:                     );
 552:                 }
 553:             } catch (Mage_Core_Exception $e) {
 554:                 $response = array('error' => true, 'message'   => $e->getMessage());
 555:             } catch (Exception $e) {
 556:                 $response = array(
 557:                     'error'     => true,
 558:                     'message'   => $this->__('Can\'t delete "%s" theme.', $themeId)
 559:                 );
 560:             }
 561:         } else {
 562:             $response = array('error' => true, 'message' => $this->__('Theme name is not set.'));
 563:         }
 564:         if (is_array($response)) {
 565:             $response = Mage::helper('core')->jsonEncode($response);
 566:             $this->getResponse()->setBody($response);
 567:         }
 568:     }
 569: 
 570:     /**
 571:      * Save Theme action
 572:      *
 573:      * @return null
 574:      */
 575:     public function saveThemeAction()
 576:     {
 577:         $data = $this->getRequest()->getPost();
 578:         $this->_saveThemeAction($data);
 579:     }
 580: 
 581:     /**
 582:      * Save Theme action
 583:      *
 584:      * @return null
 585:      */
 586:     public function resetThemeAction()
 587:     {
 588:         try {
 589:             $theme = $this->getRequest()->getPost('theme', null);
 590:             Mage::helper('xmlconnect/theme')->resetTheme($theme);
 591:             $response = Mage::helper('xmlconnect/theme')->getAllThemesArray(true);
 592:         } catch (Mage_Core_Exception $e) {
 593:             $response = array('error' => true, 'message' => $e->getMessage());
 594:         } catch (Exception $e) {
 595:             $response = array('error' => true, 'message' => $this->__('Can\'t reset theme.'));
 596:         }
 597:         if (is_array($response)) {
 598:             $response = Mage::helper('core')->jsonEncode($response);
 599:             $this->getResponse()->setBody($response);
 600:         }
 601:     }
 602: 
 603:     /**
 604:      * Preview Home action handler
 605:      *
 606:      * @return null
 607:      */
 608:     public function previewHomeAction()
 609:     {
 610:         $this->_previewAction('preview_home_content');
 611:     }
 612: 
 613:     /**
 614:      * Preview Home landscape mode action handler
 615:      */
 616:     public function previewHomeHorAction()
 617:     {
 618:         $this->_previewAction('preview_home_hor_content');
 619:     }
 620: 
 621:     /**
 622:      * Preview Catalog action handler
 623:      *
 624:      * @return null
 625:      */
 626:     public function previewCatalogAction()
 627:     {
 628:         $this->_previewAction('preview_catalog_content');
 629:     }
 630: 
 631:     /**
 632:      * Preview Catalog landscape mode action handler
 633:      */
 634:     public function previewCatalogHorAction()
 635:     {
 636:         $this->_previewAction('preview_catalog_hor_content');
 637:     }
 638: 
 639:     /**
 640:      * Preview Product Info action handler
 641:      */
 642:     public function previewProductinfoAction()
 643:     {
 644:         $this->_previewAction('preview_productinfo_content');
 645:     }
 646: 
 647:     /**
 648:      * Preview AirMail Queue Template action handler
 649:      */
 650:     public function previewQueueAction()
 651:     {
 652:         $message = $this->_initMessage();
 653:         if ($message->getId()) {
 654:             $this->getRequest()->setParam('queue_preview', $message->getId());
 655:         }
 656:         $this->_forward('previewTemplate');
 657:     }
 658: 
 659:     /**
 660:      * Preview AirMail Template action handler
 661:      */
 662:     public function previewTemplateAction()
 663:     {
 664:         $this->loadLayout('adminhtml_mobile_template_preview');
 665:         $this->renderLayout();
 666:     }
 667: 
 668:     /**
 669:      * Preview action implementation
 670:      *
 671:      * @param string $block
 672:      */
 673:     protected function _previewAction($block)
 674:     {
 675:         $redirectBack = false;
 676:         try {
 677:             $deviceType = $this->getRequest()->getParam('devtype');
 678:             $app = $this->_initApp('application_id', $deviceType);
 679:             if (!$this->getRequest()->getParam('submission_action')) {
 680:                 $app->addData($this->_preparePostData($this->getRequest()->getPost()));
 681:             }
 682:             /** render base configuration of application */
 683:             $appConf = $app->getRenderConf();
 684:             try {
 685:                 /** try to upload files */
 686:                 $dataUploaded = $this->_processUploadedFiles($app->getData());
 687:                 $app->addData($dataUploaded);
 688:                 /** render configuration with just uploaded images */
 689:                 $appConf = $app->getRenderConf();
 690:             } catch (Exception $e) {
 691:                 /** when cannot upload - just tell user what is happen */
 692:                 $jsErrorMessage = addslashes($e->getMessage());
 693:             }
 694: 
 695:             $this->loadLayout(false);
 696:             $preview = $this->getLayout()->getBlock($block);
 697: 
 698:             if (isset($jsErrorMessage)) {
 699:                 $preview->setJsErrorMessage($jsErrorMessage);
 700:             }
 701:             $preview->setConf($appConf);
 702:             Mage::helper('xmlconnect')->getPreviewModel()->setConf($appConf);
 703:             $this->renderLayout();
 704:             return;
 705:         } catch (Mage_Core_Exception $e) {
 706:             $this->_getSession()->addException($e, $e->getMessage());
 707:             $redirectBack = true;
 708:         } catch (Exception $e) {
 709:             $this->_getSession()->addException($e, $this->__('Unable to process preview.'));
 710:             $redirectBack = true;
 711:         }
 712:         if (isset($app) && $app instanceof Mage_XmlConnect_Model_Application && $redirectBack) {
 713:             $this->_redirect('*/*/edit', array('application_id' => $app->getId()));
 714:         } else {
 715:             $this->_redirect('*/*/');
 716:         }
 717:     }
 718: 
 719:     /**
 720:      * Delete app action
 721:      *
 722:      * @return null
 723:      */
 724:     public function deleteAction()
 725:     {
 726:         try {
 727:             $app = $this->_initApp();
 728:             if (!$app->getIsSubmitted()) {
 729:                 $app->delete();
 730:                 $this->_getSession()->addSuccess($this->__('App has been deleted.'));
 731:             } else {
 732:                 Mage::throwException($this->__('It\'s not allowed to delete submitted application.'));
 733:             }
 734:         } catch (Mage_Core_Exception $e) {
 735:             $this->_getSession()->addException($e, $e->getMessage());
 736:         } catch (Exception $e) {
 737:             $this->_getSession()->addException($e, $this->__('Unable to find an app to delete.'));
 738:         }
 739:         $this->_redirect('*/*/');
 740:     }
 741: 
 742:     /**
 743:      * Delete template action
 744:      */
 745:     public function deleteTemplateAction()
 746:     {
 747:         // check if we know what should be deleted
 748:         if ($id = $this->getRequest()->getParam('id')) {
 749:             try {
 750:                 // init template and delete
 751:                 Mage::getModel('xmlconnect/template')->load($id)->delete();
 752: 
 753:                 // display success message
 754:                 Mage::getSingleton('adminhtml/session')->addSuccess($this->__('Template has been deleted.'));
 755: 
 756:                 // go to grid
 757:                 $this->_redirect('*/*/template');
 758:                 return;
 759: 
 760:             } catch (Exception $e) {
 761:                 // display error message
 762:                 Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
 763:                 // go back to edit form
 764:                 $this->_redirect('*/*/template', array('id' => $id));
 765:                 return;
 766:             }
 767:         }
 768: 
 769:         // display error message
 770:         Mage::getSingleton('adminhtml/session')->addError($this->__('Unable to find template to delete.'));
 771:     }
 772: 
 773:     /**
 774:      * Check the permission to run it
 775:      *
 776:      * @return boolean
 777:      */
 778:     protected function _isAllowed()
 779:     {
 780:         return Mage::getSingleton('admin/session')->isAllowed('xmlconnect');
 781:     }
 782: 
 783:     /**
 784:      * List application submit history
 785:      */
 786:     public function historyAction()
 787:     {
 788:         $this->loadLayout();
 789:         $this->_setActiveMenu('xmlconnect/history');
 790:         $this->renderLayout();
 791:     }
 792: 
 793:     /**
 794:      * Render apps grid
 795:      *
 796:      * @return null
 797:      */
 798:     public function gridAction()
 799:     {
 800:         $this->loadLayout(false);
 801:         $this->_setActiveMenu('xmlconnect/mobile');
 802:         $this->renderLayout();
 803:     }
 804: 
 805:     /**
 806:      * Process all uploaded files
 807:      * setup file names to the configuration return array
 808:      *
 809:      * @param array $data
 810:      * @param bool $restore
 811:      * @return array
 812:      */
 813:     protected function _processUploadedFiles($data, $restore = false)
 814:     {
 815:         if ($restore === true) {
 816:             $this->_uploadedFiles = Mage::getSingleton('adminhtml/session')->getUploadedFilesFormDataSubmit();
 817:         }
 818:         if (!isset($this->_uploadedFiles) || !is_array($this->_uploadedFiles)) {
 819:             $this->_uploadedFiles = array();
 820:         }
 821: 
 822:         if (!empty($_FILES)) {
 823:             foreach ($_FILES as $field => $file) {
 824:                 if (!empty($file['name']) && is_scalar($file['name'])) {
 825:                     $uploadedFileName = Mage::helper('xmlconnect/image')->handleUpload($field);
 826:                     if (!empty($uploadedFileName)) {
 827:                         $this->_uploadedFiles[$field] = $uploadedFileName;
 828:                     }
 829:                 }
 830:             }
 831:         }
 832: 
 833:         foreach ($this->_uploadedFiles as $fieldPath => $fileName) {
 834:             Mage::helper('xmlconnect')->_injectFieldToArray($data, $fieldPath, $fileName);
 835:         }
 836:         Mage::getSingleton('adminhtml/session')->setUploadedFilesFormData($this->_uploadedFiles);
 837:         if ($restore === true) {
 838:             Mage::getSingleton('adminhtml/session')->setUploadedFilesFormDataSubmit($this->_uploadedFiles);
 839:         }
 840:         return $data;
 841:     }
 842: 
 843:     /**
 844:      * Prepare post data
 845:      * Retains previous data in the object.
 846:      *
 847:      * @param array $arr
 848:      * @return array
 849:      */
 850:     public function _preparePostData(array $arr)
 851:     {
 852:         unset($arr['code']);
 853:         if (!empty($arr['conf']['native']['pages'])) {
 854:             /**
 855:              * Remove emptied pages
 856:              */
 857:             $pages = array();
 858:             foreach ($arr['conf']['native']['pages'] as $_page) {
 859:                 if (!empty($_page['id']) && !empty($_page['label'])) {
 860:                     $pages[] = $_page;
 861:                 }
 862:             }
 863:             $arr['conf']['native']['pages'] = $pages;
 864:         }
 865:         if (isset($arr['conf']['new_pages']['ids']) && isset($arr['conf']['new_pages']['labels'])) {
 866:             $newPages = array();
 867:             $cmsPages = &$arr['conf']['new_pages'];
 868:             $idx = 0;
 869:             foreach ($cmsPages['ids'] as $key => $value) {
 870:                 if (!empty($value) && !empty($cmsPages['labels'][$key])) {
 871:                     $newPages[$idx]['id'] = trim($value);
 872:                     $newPages[$idx++]['label'] = trim($cmsPages['labels'][$key]);
 873:                 }
 874:             }
 875:             if (!isset($arr['conf']['native']['pages'])) {
 876:                 $arr['conf']['native']['pages'] = array();
 877:             }
 878:             if (!empty($newPages)) {
 879:                 $arr['conf']['native']['pages'] = array_merge($arr['conf']['native']['pages'], $newPages);
 880:             }
 881:             unset($arr['conf']['new_pages']);
 882:         }
 883: 
 884:         /**
 885:          * Check cache settings
 886:          */
 887:         $lifetime = &$arr['conf']['native']['cacheLifetime'];
 888:         $lifetime = $lifetime <= 0 ? '' : (int)$lifetime;
 889: 
 890:         /**
 891:          * Restoring current_theme over selected but not applied theme
 892:          */
 893:         if (isset($arr['current_theme'])) {
 894:             $arr['conf']['extra']['theme'] = $arr['current_theme'];
 895:         }
 896:         if (!isset($arr['conf']['defaultCheckout'])) {
 897:             $arr['conf']['defaultCheckout'] = array();
 898:         }
 899:         if (!isset($arr['conf']['defaultCheckout']['isActive'])) {
 900:             $arr['conf']['defaultCheckout']['isActive'] = 0;
 901:         }
 902: 
 903:         if (!isset($arr['conf']['paypal'])) {
 904:             $arr['conf']['paypal'] = array();
 905:         }
 906:         if (!isset($arr['conf']['paypal']['isActive'])) {
 907:             $arr['conf']['paypal']['isActive'] = 0;
 908:         }
 909:         return $arr;
 910:     }
 911: 
 912:     /**
 913:      * Submission history grid action on submission history tab
 914:      */
 915:     public function submissionHistoryGridAction()
 916:     {
 917:         $this->_initApp();
 918:         $this->loadLayout();
 919:         $this->renderLayout();
 920:     }
 921: 
 922:     /**
 923:      * Initialize message queue
 924:      *
 925:      * @param string $paramName
 926:      * @return Mage_XmlConnect_Model_Queue
 927:      */
 928:     protected function _initMessage($paramName = 'id')
 929:     {
 930:         $id = (int) $this->getRequest()->getParam($paramName);
 931:         $message = Mage::getModel('xmlconnect/queue')->load($id);
 932:         Mage::unregister('current_message');
 933:         Mage::register('current_message', $message);
 934:         return $message;
 935:     }
 936: 
 937:     /**
 938:      * Initialize Template object
 939:      *
 940:      * @param string $paramName
 941:      * @return Mage_XmlConnect_Model_Template
 942:      */
 943:     protected function _initTemplate($paramName = 'id')
 944:     {
 945:         $id = (int) $this->getRequest()->getParam($paramName);
 946:         $template = Mage::getModel('xmlconnect/template')->load($id);
 947:         Mage::unregister('current_template');
 948:         Mage::register('current_template', $template);
 949:         return $template;
 950:     }
 951: 
 952:     /**
 953:      * List AirMail message queue grid
 954:      *
 955:      * @return null
 956:      */
 957:     public function queueAction()
 958:     {
 959:         $this->loadLayout();
 960:         $this->_setActiveMenu('xmlconnect/queue');
 961:         $this->renderLayout();
 962:     }
 963: 
 964:     /**
 965:      * Edit message action
 966:      *
 967:      * @return null
 968:      */
 969:     public function editQueueAction()
 970:     {
 971:         $message = $this->_initMessage();
 972:         if ($message->getId()) {
 973:             $this->getRequest()->setParam('template_id', $message->getTemplateId());
 974:             $this->_initTemplate('template_id');
 975:         }
 976:         $this->_forward('queueMessage');
 977:     }
 978: 
 979:     /**
 980:      * Filtering posted data. Converting localized data if needed
 981:      *
 982:      * @param array $data
 983:      * @return array
 984:      */
 985:     protected function _filterPostData($data)
 986:     {
 987:         $data = $this->_filterDateTime($data, array('exec_time'));
 988:         return $data;
 989:     }
 990: 
 991:     /**
 992:      * Cancel queue action
 993:      *
 994:      * @return null
 995:      */
 996:     public function cancelQueueAction()
 997:     {
 998:         try {
 999:             $id = $this->getRequest()->getParam('id');
1000:             $message = $this->_initMessage();
1001:             if (!$message->getId() && $id) {
1002:                 $this->_getSession()->addError($this->__('Queue does not exist.'));
1003:                 $this->_redirect('*/*/');
1004:                 return;
1005:             }
1006:             $message->setStatus(Mage_XmlConnect_Model_Queue::STATUS_CANCELED);
1007:             $message->save();
1008:         } catch (Mage_Core_Exception $e) {
1009:             $this->_getSession()->addException($e, $e->getMessage());
1010:         } catch (Exception $e) {
1011:             $this->_getSession()->addException($e, $this->__('Unable to cancel queue.'));
1012:             Mage::logException($e);
1013:         }
1014: 
1015:         $this->_redirect('*/*/queue');
1016:     }
1017: 
1018:     /**
1019:      * Delete queue action
1020:      *
1021:      * @return null
1022:      */
1023:     public function deleteQueueAction()
1024:     {
1025:         try {
1026:             $id = $this->getRequest()->getParam('id');
1027:             $message = $this->_initMessage();
1028:             if (!$message->getId() && $id) {
1029:                 $this->_getSession()->addError($this->__('Queue does not exist.'));
1030:                 $this->_redirect('*/*/');
1031:                 return;
1032:             }
1033:             $message->setStatus(Mage_XmlConnect_Model_Queue::STATUS_DELETED);
1034:             $message->save();
1035:         } catch (Mage_Core_Exception $e) {
1036:             $this->_getSession()->addException($e, $e->getMessage());
1037:         } catch (Exception $e) {
1038:             $this->_getSession()->addException($e, $this->__('Unable to delete queue.'));
1039:             Mage::logException($e);
1040:         }
1041: 
1042:         $this->_redirect('*/*/queue');
1043:     }
1044: 
1045:     /**
1046:      * Cancel selected queue action
1047:      *
1048:      * @return null
1049:      */
1050:     public function massCancelQueueAction()
1051:     {
1052:         $queueIds = $this->getRequest()->getParam('queue');
1053:         if(!is_array($queueIds)) {
1054:              Mage::getSingleton('adminhtml/session')->addError(Mage::helper('adminhtml')->__('Please select message(s).'));
1055:         } else {
1056:             try {
1057:                 $queue = Mage::getModel('xmlconnect/queue');
1058:                 foreach ($queueIds as $queueId) {
1059:                     $queue->reset()->load((int)$queueId)->setStatus(Mage_XmlConnect_Model_Queue::STATUS_CANCELED)
1060:                         ->save();
1061:                 }
1062:                 Mage::getSingleton('adminhtml/session')->addSuccess(
1063:                     Mage::helper('adminhtml')->__('Total of %d record(s) were canceled.', count($queueIds))
1064:                 );
1065:             } catch (Exception $e) {
1066:                 Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
1067:             }
1068:         }
1069: 
1070:         $this->_redirect('*/*/queue');
1071:     }
1072: 
1073:     /**
1074:      * Delete selected queue action
1075:      *
1076:      * @return null
1077:      */
1078:     public function massDeleteQueueAction()
1079:     {
1080:         $queueIds = $this->getRequest()->getParam('queue');
1081:         if(!is_array($queueIds)) {
1082:              Mage::getSingleton('adminhtml/session')->addError(Mage::helper('adminhtml')->__('Please select message(s).'));
1083:         } else {
1084:             try {
1085:                 $queue = Mage::getModel('xmlconnect/queue');
1086:                 foreach ($queueIds as $queueId) {
1087:                     $queue->reset()->load($queueId)->setStatus(Mage_XmlConnect_Model_Queue::STATUS_DELETED)->save();
1088:                 }
1089:                 Mage::getSingleton('adminhtml/session')->addSuccess(
1090:                     Mage::helper('adminhtml')->__('Total of %d record(s) were deleted.', count($queueIds))
1091:                 );
1092:             } catch (Exception $e) {
1093:                 Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
1094:             }
1095:         }
1096: 
1097:         $this->_redirect('*/*/queue');
1098:     }
1099: 
1100:     /**
1101:      * Save AirMail message action
1102:      *
1103:      * @return null
1104:      */
1105:     public function saveMessageAction()
1106:     {
1107:         $data         = $this->_filterPostData($this->getRequest()->getPost());
1108:         $isError      = false;
1109:         $message      = false;
1110: 
1111:         if ($data) {
1112:             try {
1113:                 $data = Mage::getModel('core/input_filter_maliciousCode')->filter($data);
1114:                 $template = $this->_initTemplate('template_id');
1115:                 $message = $this->_initMessage();
1116: 
1117:                 if (!$template->getId() && !$message->getTemplateId()) {
1118:                     $this->_getSession()->addError($this->__('Template for new AirMail Message does not exist.'));
1119:                     $this->_redirect('*/*/queue');
1120:                     return;
1121:                 }
1122: 
1123:                 /** @var $app Mage_XmlConnect_Model_Application */
1124:                 $app = Mage::getModel('xmlconnect/application')->loadByCode($template->getAppCode());
1125:                 $deviceType = Mage::helper('xmlconnect')->getDeviceType($app);
1126: 
1127:                 if ($deviceType == Mage_XmlConnect_Helper_Data::DEVICE_TYPE_ANDROID
1128:                     && $data['type'] == Mage_XmlConnect_Model_Queue::MESSAGE_TYPE_AIRMAIL
1129:                 ) {
1130:                     $this->_getSession()->addError($this->__('Android doesn\'t support AirMail message type.'));
1131:                     $redirectParams = $this->_getQueueMessageParams($message);
1132:                     $action = $message->getId() ? 'editQueue' : 'queueMessage';
1133:                     $this->_redirect('*/*/' . $action, $redirectParams);
1134:                     return;
1135:                 }
1136: 
1137:                 $temporaryObject = new Varien_Object();
1138:                 $temporaryObject->setData($data);
1139: 
1140:                 if ($temporaryObject->getTemplateId()) {
1141:                     $message->setTemplateId($temporaryObject->getTemplateId());
1142:                 } else {
1143:                     $message->setTemplateId($template->getId());
1144:                 }
1145: 
1146:                 if (!$message->getId()) {
1147:                     // set status for new messages only
1148:                     $message->setStatus(Mage_XmlConnect_Model_Queue::STATUS_IN_QUEUE);
1149:                 } elseif ($message->getStatus() != Mage_XmlConnect_Model_Queue::STATUS_IN_QUEUE) {
1150:                     $this->_getSession()->addError(
1151:                         $this->__('Message can be edited when status of the message is "In Queue" only.')
1152:                     );
1153:                     $this->_redirect('*/*/queue');
1154:                     return;
1155:                 }
1156: 
1157:                 switch ($temporaryObject->getType()) {
1158:                     case Mage_XmlConnect_Model_Queue::MESSAGE_TYPE_AIRMAIL:
1159:                         $message->setData('type', Mage_XmlConnect_Model_Queue::MESSAGE_TYPE_AIRMAIL);
1160:                         break;
1161: 
1162:                     case Mage_XmlConnect_Model_Queue::MESSAGE_TYPE_PUSH:
1163:                     default:
1164:                         $message->setData('type', Mage_XmlConnect_Model_Queue::MESSAGE_TYPE_PUSH);
1165:                         break;
1166:                 }
1167:                 if ($temporaryObject->getExecTime()) {
1168:                     $execTime = Mage::getSingleton('core/date')->gmtDate(null, $temporaryObject->getExecTime());
1169:                     $message->setExecTime($execTime ? $execTime : Mage::getSingleton('core/date')->gmtDate());
1170:                 } else {
1171:                     $message->setExecTime(new Zend_Db_Expr('NULL'));
1172:                 }
1173:                 if ($template->getId()) {
1174:                     $message->setAppCode($template->getAppCode());
1175:                 }
1176:                 $message->setPushTitle($temporaryObject->getPushTitle());
1177:                 $message->setMessageTitle($temporaryObject->getMessageTitle());
1178:                 $message->setContent($temporaryObject->getContent());
1179:                 $message->save();
1180:             } catch (Mage_Core_Exception $e) {
1181:                 $this->_getSession()->addException($e, $e->getMessage());
1182:                 $isError = true;
1183:             } catch (Exception $e) {
1184:                 $this->_getSession()->addException($e, $this->__('Unable to save message.'));
1185:                 $isError = true;
1186:                 Mage::logException($e);
1187:             }
1188:         }
1189: 
1190:         if ($isError) {
1191:             if ($isError) {
1192:                 Mage::getSingleton('adminhtml/session')->setLoadSessionFlag(true);
1193:             }
1194:             $redirectParams = $this->_getQueueMessageParams($message);
1195:             $this->_redirect('*/*/queueMessage', $redirectParams);
1196:         } else {
1197:             $this->_redirect('*/*/queue');
1198:         }
1199:     }
1200: 
1201:     /**
1202:      * Get queue message action params
1203:      *
1204:      * @param Mage_XmlConnect_Model_Queue $message
1205:      * @return array
1206:      */
1207:     protected function _getQueueMessageParams(Mage_XmlConnect_Model_Queue $message)
1208:     {
1209:         $redirectParams = array();
1210:         if ($message && $message->getId()) {
1211:             $redirectParams['id'] = $message->getId();
1212:         } else {
1213:             $redirectParams['template_id'] = (int) $this->getRequest()->getParam('template_id');
1214:         }
1215:         return $redirectParams;
1216:     }
1217: 
1218:     /**
1219:      * Temlate grid
1220:      *
1221:      * @return null
1222:      */
1223:     public function templateAction()
1224:     {
1225:         $this->loadLayout();
1226:         $this->_setActiveMenu('xmlconnect/template');
1227:         $this->renderLayout();
1228:     }
1229: 
1230:     /**
1231:      * Create new template action
1232:      *
1233:      * @return null
1234:      */
1235:     public function newTemplateAction()
1236:     {
1237:         $this->_forward('editTemplate');
1238:     }
1239: 
1240:     /**
1241:      * Edit template action
1242:      *
1243:      * @return null
1244:      */
1245:     public function editTemplateAction()
1246:     {
1247:         $template = $this->_initTemplate();
1248: 
1249:         $applicationsFound = Mage::helper('xmlconnect')->getApplicationOptions();
1250:         if (!$template->getId() && empty($applicationsFound)) {
1251:             $this->_getSession()->addError($this->__('At last one application has to be created.'));
1252:             $this->_redirect('*/*/template');
1253:             return;
1254:         }
1255: 
1256:         $this->loadLayout();
1257:         $this->_setActiveMenu('xmlconnect/templates');
1258:         $this->renderLayout();
1259:     }
1260: 
1261:     /**
1262:      * Save template action
1263:      *
1264:      * @return null
1265:      */
1266:     public function saveTemplateAction()
1267:     {
1268:         $data = $this->getRequest()->getPost();
1269:         $template = false;
1270:         $isError = false;
1271:         if ($data) {
1272:             $data = Mage::getModel('core/input_filter_maliciousCode')->filter($data);
1273:             Mage::getSingleton('adminhtml/session')->setTemplateFormData($data);
1274:             try {
1275:                 $id = $this->getRequest()->getParam('id');
1276:                 $template = $this->_initTemplate();
1277:                 if (!$template->getId() && $id) {
1278:                     $this->_getSession()->addError($this->__('Template does not exist.'));
1279:                     $this->_redirect('*/*/');
1280:                     return;
1281:                 }
1282:                 $template->addData($data);
1283:                 $template->save();
1284:             } catch (Mage_Core_Exception $e) {
1285:                 $this->_getSession()->addException($e, $e->getMessage());
1286:                 $isError = true;
1287:             } catch (Exception $e) {
1288:                 $this->_getSession()->addException($e, $this->__('Unable to save template.'));
1289:                 $isError = true;
1290:                 Mage::logException($e);
1291:             }
1292:         }
1293: 
1294:         if ($isError && ($template && $template->getId())) {
1295:             Mage::getSingleton('adminhtml/session')->setLoadSessionFlag(true);
1296:             $this->_redirect('*/*/editTemplate', array('id' => $template->getId()));
1297:         } else {
1298:             $this->_redirect('*/*/template');
1299:         }
1300:     }
1301: 
1302:     /**
1303:      * Add message to queue action
1304:      *
1305:      * @return null
1306:      */
1307:     public function queueMessageAction()
1308:     {
1309:         $message = $this->_initMessage();
1310:         if (!$message->getId()) {
1311:             $template = $this->_initTemplate('template_id');
1312:             if (!$template->getId()) {
1313:                 $this->_getSession()->addError($this->__('Template for new AirMail Message does not exist.'));
1314:                 $this->_redirect('*/*/template');
1315:             }
1316:         }
1317: 
1318:         if (isset($template)) {
1319:             $applicationId = $template->getApplicationId();
1320:         } else {
1321:             $applicationId = Mage::getModel('xmlconnect/template')->load($message->getTemplateId())->getApplicationId();
1322:         }
1323: 
1324:         /** @var $app Mage_XmlConnect_Model_Application */
1325:         $app = Mage::getModel('xmlconnect/application')->load($applicationId);
1326: 
1327:         if(!$app->isNotificationsActive()) {
1328:             $this->_getSession()->addError(
1329:                 $this->__('Queue is allowed only for applications with enabled Push Notification.')
1330:             );
1331:             $action = $message->getId() ? 'queue' : 'template';
1332:             $this->_redirect('*/*/' . $action);
1333:             return;
1334:         }
1335: 
1336:         $this->loadLayout();
1337:         if ($message->getId()) {
1338:             $title = $this->__('Edit AirMail Message');
1339:         } else {
1340:             $title = $this->__('New AirMail Message');
1341:         }
1342:         $this->_addBreadcrumb($this->__('AirMail Message Queue'), $this->__('AirMail Message Queue'),
1343:             $this->getUrl('*/*/queue')
1344:         );
1345:         $this->_addBreadcrumb($title, $title);
1346: 
1347:         $this->_setActiveMenu('xmlconnect/queue');
1348:         $this->renderLayout();
1349:     }
1350: 
1351:     /**
1352:      * Edit queue message action
1353:      *
1354:      * @return null
1355:      */
1356:     public function editMessageAction()
1357:     {
1358:         $this->_forward('queueMessage');
1359:     }
1360: }
1361: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0