name = 'statshome'; $this->tab = 'Stats'; $this->version = 1.0; $ru = dirname($_SERVER['REQUEST_URI'].'a'); $this->_adminPath = substr($ru, strrpos($ru, '/')); parent::__construct(); $this->displayName = $this->l('Condensed stats for the Back Office homepage'); $this->description = $this->l('Display a small block of statistics on the Back Office homepage'); } public function install() { return (parent::install() AND $this->registerHook('backOfficeHome')); } private function _postProcess() { include_once(dirname(__FILE__).'/../..'.$this->_adminPath.'/tabs/AdminStats.php'); $calendarTab = new AdminStats(); $calendarTab->postProcess(); } public function hookBackOfficeHome($params) { global $cookie; $this->_postProcess(); $currency = Currency::getCurrency(intval(Configuration::get('PS_CURRENCY_DEFAULT'))); $results = $this->getResults(); $employee = new Employee(intval($cookie->id_employee)); $id_tab_stats = Tab::getIdFromClassName('AdminStats'); $access = Profile::getProfileAccess($employee->id_profile, $id_tab_stats); if (!$access['view']) return ''; $this->_html = '
'.$this->l('Statistics').'



'.Tools::displayPrice($results['total_sales'], $currency).'

'.$this->l('of sales').'



'.intval($results['total_registrations']).'

'.(($results['total_registrations'] != 1) ? $this->l('registrations') : $this->l('registration')).'



'.intval($results['total_orders']).'

'.(($results['total_orders'] != 1) ? $this->l('orders placed') : $this->l('order placed')).'



'.intval($results['total_viewed']).'

'.(($results['total_viewed'] != 1) ? $this->l('product pages viewed') : $this->l('product page viewed')).'

'; include_once(dirname(__FILE__).'/../..'.$this->_adminPath.'/tabs/AdminStats.php'); $this->_html .= AdminStatsTab::displayCalendarStatic(array('Calendar' => $this->l('Calendar'), 'Day' => $this->l('Day'), 'Month' => $this->l('Month'), 'Year' => $this->l('Year'), 'From' => $this->l('From:'), 'To' => $this->l('To:'), 'Save' => $this->l('Save'))); $this->_html .= '

'.$this->l('Visitors online now:').' '.intval($this->getVisitorsNow()).'



'; return $this->_html; } private function getVisitorsNow() { return Db::getInstance()->getValue(' SELECT COUNT(DISTINCT cp.`id_connections`) FROM `'._DB_PREFIX_.'connections_page` cp WHERE TIME_TO_SEC(TIMEDIFF(NOW(), cp.`time_start`)) < 900'); } private function getResults() { $yearFrom = intval(Configuration::get('STATSHOME_YEAR_FROM')); $monthFrom = intval(Configuration::get('STATSHOME_MONTH_FROM')); $dayFrom = intval(Configuration::get('STATSHOME_DAY_FROM')); $yearTo = intval(Configuration::get('STATSHOME_YEAR_TO')); $monthTo = intval(Configuration::get('STATSHOME_MONTH_TO')); $dayTo = intval(Configuration::get('STATSHOME_DAY_TO')); if (!$yearFrom) Configuration::updateValue('STATSHOME_YEAR_FROM', $yearFrom = date('Y')); if (!$yearFrom) Configuration::updateValue('STATSHOME_YEAR_TO', $yearTo = date('Y')); $monthFrom = $monthFrom ? ((strlen($monthFrom) == 1 ? '0' : '').$monthFrom) : '01'; $dayFrom = $dayFrom ? ((strlen($dayFrom) == 1 ? '0' : '').$dayFrom) : '01'; $monthTo = $monthTo ? ((strlen($monthTo) == 1 ? '0' : '').$monthTo) : '12'; $dayTo = $dayTo ? ((strlen($dayTo) == 1 ? '0' : '').$dayTo) : '31'; $result = Db::getInstance()->getRow(' SELECT SUM(o.`total_paid_real` / c.conversion_rate) as total_sales, COUNT(*) as total_orders FROM `'._DB_PREFIX_.'orders` o LEFT JOIN `'._DB_PREFIX_.'currency` c ON o.id_currency = c.id_currency WHERE o.valid = 1 AND o.`invoice_date` BETWEEN '.ModuleGraph::getDateBetween()); $result2 = Db::getInstance()->getRow(' SELECT COUNT(`id_customer`) AS total_registrations FROM `'._DB_PREFIX_.'customer` c WHERE c.`date_add` BETWEEN '.ModuleGraph::getDateBetween()); $result3 = Db::getInstance()->getRow(' SELECT SUM(pv.`counter`) AS total_viewed FROM `'._DB_PREFIX_.'page_viewed` pv LEFT JOIN `'._DB_PREFIX_.'date_range` dr ON pv.`id_date_range` = dr.`id_date_range` LEFT JOIN `'._DB_PREFIX_.'page` p ON pv.`id_page` = p.`id_page` LEFT JOIN `'._DB_PREFIX_.'page_type` pt ON pt.`id_page_type` = p.`id_page_type` WHERE pt.`name` = \'product.php\' AND dr.`time_start` BETWEEN '.ModuleGraph::getDateBetween().' AND dr.`time_end` BETWEEN '.ModuleGraph::getDateBetween()); return array_merge($result, array_merge($result2, $result3)); } } ?>