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_Adminhtml
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: * Dashboard admin controller
29: *
30: * @category Mage
31: * @package Mage_Adminhtml
32: * @author Magento Core Team <core@magentocommerce.com>
33: */
34: class Mage_Adminhtml_DashboardController extends Mage_Adminhtml_Controller_Action
35: {
36: public function indexAction()
37: {
38: $this->_title($this->__('Dashboard'));
39:
40: $this->loadLayout();
41: $this->_setActiveMenu('dashboard');
42: $this->_addBreadcrumb(Mage::helper('adminhtml')->__('Dashboard'), Mage::helper('adminhtml')->__('Dashboard'));
43: $this->renderLayout();
44: }
45:
46: /**
47: * Gets most viewed products list
48: *
49: */
50: public function productsViewedAction()
51: {
52: $this->loadLayout();
53: $this->renderLayout();
54: }
55:
56: /**
57: * Gets latest customers list
58: *
59: */
60: public function customersNewestAction()
61: {
62: $this->loadLayout();
63: $this->renderLayout();
64: }
65:
66: /**
67: * Gets the list of most active customers
68: *
69: */
70: public function customersMostAction()
71: {
72: $this->loadLayout();
73: $this->renderLayout();
74: }
75:
76: public function ajaxBlockAction()
77: {
78: $output = '';
79: $blockTab = $this->getRequest()->getParam('block');
80: if (in_array($blockTab, array('tab_orders', 'tab_amounts', 'totals'))) {
81: $output = $this->getLayout()->createBlock('adminhtml/dashboard_' . $blockTab)->toHtml();
82: }
83: $this->getResponse()->setBody($output);
84: return;
85: }
86:
87: public function tunnelAction()
88: {
89: $httpClient = new Varien_Http_Client();
90: $gaData = $this->getRequest()->getParam('ga');
91: $gaHash = $this->getRequest()->getParam('h');
92: if ($gaData && $gaHash) {
93: $newHash = Mage::helper('adminhtml/dashboard_data')->getChartDataHash($gaData);
94: if ($newHash == $gaHash) {
95: if ($params = unserialize(base64_decode(urldecode($gaData)))) {
96: $response = $httpClient->setUri(Mage_Adminhtml_Block_Dashboard_Graph::API_URL)
97: ->setParameterGet($params)
98: ->setConfig(array('timeout' => 5))
99: ->request('GET');
100:
101: $headers = $response->getHeaders();
102:
103: $this->getResponse()
104: ->setHeader('Content-type', $headers['Content-type'])
105: ->setBody($response->getBody());
106: }
107: }
108: }
109: }
110:
111: protected function _isAllowed()
112: {
113: return Mage::getSingleton('admin/session')->isAllowed('dashboard');
114: }
115: }
116: