1: <?php
2: /*
3:
4: *
5: * NOTICE OF LICENSE
6: *
7: * This source file is subject to the Open Software License (OSL 3.0)
8: * or OpenGPL v3 license (GNU Public License V3.0)
9: * that is bundled with this package in the file LICENSE.txt.
10: * It is also available through the world-wide-web at this URL:
11: * http://opensource.org/licenses/osl-3.0.php
12: * or
13: * http://www.gnu.org/licenses/gpl-3.0.txt
14: * If you did not receive a copy of the license and are unable to
15: * obtain it through the world-wide-web, please send an email
16: * to info@e-abi.ee so we can send you a copy immediately.
17: *
18: * DISCLAIMER
19: *
20: * Do not edit or add to this file if you wish to upgrade this module to newer
21: * versions in the future.
22: *
23: * @category Eabi
24: * @package Eabi_Dpd
25: * @copyright Copyright (c) 2014 Aktsiamaailm LLC (http://en.e-abi.ee/)
26: * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
27: * @license http://www.gnu.org/licenses/gpl-3.0.txt GNU Public License V3.0
28: * @author Matis Halmann
29: *
30:
31: */
32:
33: /**
34: * <p>Handles the AJAX request defined for the backend (from database table eabi_livehandler)</p>
35: * <p>Security model: If Page itself can be displayed, then it is allowed to run actions, which are bound to current Livehandler model. If user switches page, then current model actions cannot be run any more.</p>
36: * <p>If user does not show any activity for Eabi_Livehandler_IndexController::ALLOWED time seconds, then actions cannot be run after timeout.</p>
37: *
38: * @author matishalmann
39: */
40: class Eabi_Livehandler_Adminhtml_LivehandlerController extends Mage_Adminhtml_Controller_Action {
41: const ALLOWED_TIME = 1800;
42: protected function _initAction() {
43: return $this;
44: }
45:
46: /**
47: *
48: * @throws Exception
49: */
50: public function processAction() {
51: $result = array();
52: if (!$this->_getEabi()->getConfigData('eabi_livehandler/main/enabled')) {
53: throw new Exception('Module Eabi Livehandler is not enabled');
54: }
55: /*
56: * Check if the process is in Session allowed list.
57: *
58: */
59: $session = Mage::getSingleton('core/session');
60: $time = time();
61:
62: $processName = base64_decode($this->getRequest()->getParam('__path'));
63: $processEntries = $session->getData('eabi_livehandler_entries');
64: $website = Mage::app()->getStore()->getWebsiteId();
65: $store = Mage::app()->getStore()->getStoreId();
66:
67:
68: if (is_array($processEntries) && isset($processEntries[$processName]) && $time - $processEntries[$processName] < self::ALLOWED_TIME) {
69:
70:
71: //execute the action.
72: $isAdmin = true;
73: $model = $processName;
74:
75: //get action by action name, website, store, is_admin = false
76: $actionsCollection = Mage::getModel('eabi_livehandler/entry')->getCollection()->setModelFilter($model, $isAdmin, $website, $store);
77:
78: $classesRan = array();
79:
80: $result = array();
81: foreach ($actionsCollection as $action) {
82: $action->load($action->getId());
83: if (isset($classesRan[$action->getModelClass()])) {
84: continue;
85: }
86:
87:
88: if (!isset($result['_is_error']) || !$result['_is_error']) {
89: $processEntries[$processName] = $time;
90: $result = $action->runAdmin($this->getRequest()->getPost());
91: }
92: $classesRan[$action->getModelClass()] = true;
93:
94: }
95:
96:
97:
98: Mage::getSingleton('core/session')->setData('eabi_livehandler_entries', $processEntries);
99: } else {
100: $result['_is_error'] = true;
101: }
102:
103:
104: echo Zend_Json::encode($result);
105: die();
106: }
107: /**
108: *
109: * @return Eabi_Livehandler_Helper_Data
110: */
111: protected function _getEabi() {
112: return Mage::helper('eabi');
113: }
114:
115:
116: }
117:
118:
119: