diff --git a/admin-dev/functions.php b/admin-dev/functions.php
index 764b3d8c8..e2f8f8d71 100644
--- a/admin-dev/functions.php
+++ b/admin-dev/functions.php
@@ -446,6 +446,8 @@ function runAdminTab($ajaxMode = false)
// init is different for new tabs (AdminController) and old tabs (AdminTab)
if ($adminObj instanceof AdminController)
{
+ if($ajaxMode)
+ $adminObj->ajax = true;
$adminObj->path = dirname($_SERVER["PHP_SELF"]);
$adminObj->run();
}
diff --git a/admin-dev/themes/template/adminHome.tpl b/admin-dev/themes/template/adminHome.tpl
new file mode 100644
index 000000000..d0ff2b430
--- /dev/null
+++ b/admin-dev/themes/template/adminHome.tpl
@@ -0,0 +1,114 @@
+
+
{l s='Dashboard'}
+
+
+ {if $upgrade}
+
+ {else}
+
{l s ='Update notification unavailable'}
+
+
{l s ='To receive PrestaShop update warnings, you need to activate the allow_url_fopen command in your php.ini config file.'} [{l s ='more info'}]
+
{l s ='If you don\'t know how to do that, please contact your host administrator !'}
+
+ {/if}
+
+{if $show_screencast}
+
+
+ {foreach from=$quick_links key=k item=link}
+ -
+
+
{$link.description}
+
+ {/foreach}
+
+ {$monthly_statistics}
+ {$customers_service}
+
+ {$stats_sales}
+ {$last_orders}
+
+
+ {$tips_optimization}
+
+
+
{l s='Loading...'}
+
+
+
+ {$discover_prestashop}
+
+
+{$HOOK_BACKOFFICEHOME}
+
+
diff --git a/admin-dev/themes/template/header.tpl b/admin-dev/themes/template/header.tpl
index 228ecf4f6..e2ba586a8 100644
--- a/admin-dev/themes/template/header.tpl
+++ b/admin-dev/themes/template/header.tpl
@@ -32,14 +32,13 @@
';
- $this->content .= '
';
+ }
+ return $content;
}
- }
+
public function setMedia()
{
parent::setMedia();
@@ -161,148 +165,42 @@ class AdminHomeControllerCore extends AdminController
'.
$this->l('Click here if you want to modify the main shop domain name').'');
}
- public function display()
- {
- $this->warnDomainName();
- $tab = get_class();
- $protocol = Tools::usingSecureMode()?'https':'http';
- $isoUser = $this->context->language->iso_code;
- $currency = Tools::setCurrency($this->context->cookie);
- $this->content .= '
-
'.$this->l('Dashboard').'
-
-
';
- if (@ini_get('allow_url_fopen'))
- {
- $upgrade = new Upgrader();
- if($update = $upgrade->checkPSVersion())
- $this->content .= '
';
- }
- else
- {
- $this->content .= '
'.$this->l('Update notification unavailable').'
';
- $this->content .= '
';
- $this->content .= '
'.$this->l('To receive PrestaShop update warnings, you need to activate the allow_url_fopen command in your php.ini config file.').' ['.$this->l('more info').']
';
- $this->content .= '
'.$this->l('If you don\'t know how to do that, please contact your host administrator !').'
';
- }
- $this->content .= '
';
+ private function getQuickLinks()
+ {
+ $quick_links['first'] = array(
+ 'href' => 'index.php?controller=AdminCatalog&addcategory&token='.Tools::getAdminTokenLite('AdminCatalog'),
+ 'title' => $this->l('New category'),
+ 'description' => $this->l('Create a new category and organize your products.'),
+ );
+
+ $quick_links['second'] = array(
+ 'href' => 'index.php?controller=AdminCatalog&addproduct&token='.Tools::getAdminTokenLite('AdminCatalog'),
+ 'title' => $this->l('New product'),
+ 'description' => $this->l('Fill up your catalog with new articles and attributes.'),
+ );
- if ($this->context->employee->show_screencast)
- $this->content .= '
-
-
-
-
-
-
';
-
-
- $this->content .= '
-
-
- -
-
-
'.$this->l('Create a new category and organize your products.').'
-
- -
-
-
'.$this->l('Fill up your catalog with new articles and attributes.').'
-
- -
-
-
'.$this->l('Manage your activity with a thorough analysis of your e-shop.').'
-
- -
-
-
'.$this->l('Add a new employee account and discharge a part of your duties of shop owner.').'
-
-
- ';
- $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
- SELECT SUM(o.`total_paid_real` / o.conversion_rate) as total_sales, COUNT(*) as total_orders
- FROM `'._DB_PREFIX_.'orders` o
- WHERE o.valid = 1
- AND o.`invoice_date` BETWEEN \''.date('Y-m').'-01 00:00:00\' AND \''.date('Y-m').'-31 23:59:59\' ');
- $result2 = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
- SELECT COUNT(`id_customer`) AS total_registrations
- FROM `'._DB_PREFIX_.'customer` c
- WHERE c.`date_add` BETWEEN \''.date('Y-m').'-01 00:00:00\' AND \''.date('Y-m').'-31 23:59:59\'');
- $result3 = Db::getInstance(_PS_USE_SQL_SLAVE_)->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 \''.date('Y-m').'-01 00:00:00\' AND \''.date('Y-m').'-31 23:59:59\'
- AND dr.`time_end` BETWEEN \''.date('Y-m').'-01 00:00:00\' AND \''.date('Y-m').'-31 23:59:59\'');
- $results = array_merge($result, array_merge($result2, $result3));
- $this->content .= '
-
-
-
-
- |
- '.$this->l('Sales').'
- |
-
- '
- .Tools::displayPrice($results['total_sales'], $currency)
- .'
- |
-
-
- |
- '.$this->l('Total registrations').'
- |
-
- '.(int)($results['total_registrations']).'
- |
-
-
- |
- '.$this->l('Total orders').'
- |
-
- '.(int)($results['total_orders']).'
- |
-
-
- |
- '.$this->l('Product pages viewed').'
- |
-
- '.(int)($results['total_viewed']).'
- |
-
-
-
- ';
+ $quick_links['third'] = array(
+ 'href' => 'index.php?controller=AdminStats&addproduct&token='.Tools::getAdminTokenLite('AdminStats'),
+ 'title' => $this->l('Statistics'),
+ 'description' => $this->l('Manage your activity with a thorough analysis of your e-shop.'),
+ );
+
+ $quick_links['fourth'] = array(
+ 'href' => 'index.php?controller=AdminEmployee&addproduct&token='.Tools::getAdminTokenLite('AdminEmployee'),
+ 'title' => $this->l('New employee'),
+ 'description' => $this->l('Add a new employee account and discharge a part of your duties of shop owner.'),
+ );
+ return $quick_links;
+ }
+
+ public function getCustomersService()
+ {
$all = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('SELECT COUNT(*) FROM '._DB_PREFIX_.'customer_thread');
$unread = (int)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('SELECT COUNT(*) FROM `'._DB_PREFIX_.'customer_thread` WHERE `status` = "open"');
$pending = (int)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('SELECT COUNT(*) FROM `'._DB_PREFIX_.'customer_thread` WHERE `status` LIKE "%pending%"');
$close = $all - ($unread + $pending);
- $this->content .= '
+ $content = '
@@ -339,13 +237,81 @@ class AdminHomeControllerCore extends AdminController
-
-
-
+
';
+ return $content;
+ }
+
+ public function getMonthlyStatistics()
+ {
+ $currency = Tools::setCurrency($this->context->cookie);
+ $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
+ SELECT SUM(o.`total_paid_real` / o.conversion_rate) as total_sales, COUNT(*) as total_orders
+ FROM `'._DB_PREFIX_.'orders` o
+ WHERE o.valid = 1
+ AND o.`invoice_date` BETWEEN \''.date('Y-m').'-01 00:00:00\' AND \''.date('Y-m').'-31 23:59:59\' ');
+ $result2 = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
+ SELECT COUNT(`id_customer`) AS total_registrations
+ FROM `'._DB_PREFIX_.'customer` c
+ WHERE c.`date_add` BETWEEN \''.date('Y-m').'-01 00:00:00\' AND \''.date('Y-m').'-31 23:59:59\'');
+ $result3 = Db::getInstance(_PS_USE_SQL_SLAVE_)->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 \''.date('Y-m').'-01 00:00:00\' AND \''.date('Y-m').'-31 23:59:59\'
+ AND dr.`time_end` BETWEEN \''.date('Y-m').'-01 00:00:00\' AND \''.date('Y-m').'-31 23:59:59\'');
+ $results = array_merge($result, array_merge($result2, $result3));
+
+ $content = '
+
+
+
+ |
+ '.$this->l('Sales').'
+ |
+
+ '
+ .Tools::displayPrice($results['total_sales'], $currency)
+ .'
+ |
+
+
+ |
+ '.$this->l('Total registrations').'
+ |
+
+ '.(int)($results['total_registrations']).'
+ |
+
+
+ |
+ '.$this->l('Total orders').'
+ |
+
+ '.(int)($results['total_orders']).'
+ |
+
+
+ |
+ '.$this->l('Product pages viewed').'
+ |
+
+ '.(int)($results['total_viewed']).'
+ |
+
+
+
';
+ return $content;
+ }
+
+ public function getStatsSales()
+ {
+ $content = '
'.$this->l('View more').' '.$this->l('Statistics').' / '.$this->l('Sales of the week').'
';
- define('PS_BASE_URI', __PS_BASE_URI__);
$chart = new Chart();
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
SELECT total_paid / conversion_rate as total_converted, invoice_date
@@ -356,11 +322,18 @@ class AdminHomeControllerCore extends AdminController
$chart->getCurve(1)->setPoint(strtotime($row['invoice_date']), $row['total_converted']);
$chart->setSize(580, 170);
$chart->setTimeMode(strtotime('-7 DAYS', time()), time(), 'd');
+ $currency = Tools::setCurrency($this->context->cookie);
$chart->getCurve(1)->setLabel($this->l('Sales +Tx').' ('.strtoupper($currency->iso_code).')');
- $this->content .= $chart->fetch();
- $this->content .= '
-
+ $content .= $chart->fetch();
+ $content .= '
+
';
+ return $content;
+ }
+
+ public function getLastOrders()
+ {
+ $content = '
-
-
-
'.$this->l('Loading...').'
-
- ';
+ }
+ }
+ else
+ $return = ''; // NOK
+ }
+ return $return;
+ }
+
+ public function getBlockDiscover()
+ {
+ $content = '';
+
+ $stream_context = @stream_context_create(array('http' => array('method'=> 'GET', 'timeout' => AdminHomeController::TIPS_TIMEOUT)));
+ $protocol = Tools::usingSecureMode() ? 'https' : 'http';
+ $isoUser = Context::getContext()->language->iso_code;
+ $isoCountry = Context::getContext()->country->iso_code;
+
+ $content = @file_get_contents($protocol.'://www.prestashop.com/partner/prestashop/prestashop-link.php?iso_country='.$isoCountry.'&iso_lang='.Tools::strtolower($isoUser).'&id_lang='.(int)Context::getContext()->language->id, false, $stream_context);
+ if (!$content)
+ return ''; // NOK
+ else
+ {
+ if(strpos($content, '|') !== false);
+ $content = explode('|', $content);
+ if ($content[0] == 'OK' && Validate::isCleanHtml($content[1]))
+ return $content[1];
+ else
+ return ''; // NOK
+ }
+ }
+ public function display()
+ {
+ $smarty = $this->context->smarty;
+ $smarty->assign('token',$this->token);
+
+ $this->warnDomainName();
+
+ $tab = get_class();
+ $protocol = Tools::usingSecureMode()?'https':'http';
+ $smarty->assign('protocol',$protocol);
+ $isoUser = $this->context->language->iso_code;
+ $smarty->assign('isoUser',$isoUser);
+ $currency = $this->context->currency;
+ $upgrade = null;
+ if (@ini_get('allow_url_fopen'))
+ {
+ $upgrade = new Upgrader();
+ $upgrade->checkPSVersion();
+ }
+ $smarty->assign('upgrade', $upgrade);
+
+ $smarty->assign('show_screencast', $this->context->employee->show_screencast);
+
+ // quick link to add a products, category, attributes etc.
+ $quick_links = $this->getQuickLinks();
+ $smarty->assign('quick_links',$quick_links);
+ $monthly_statistics = $this->getMonthlyStatistics();
+ $smarty->assign('monthly_statistics', $monthly_statistics);
+
+ $customers_service = $this->getCustomersService();
+ $smarty->assign('customers_service', $customers_service);
+
+ $stats_sales = $this->getStatsSales();
+ $smarty->assign('stats_sales', $stats_sales);
+
+ $last_orders = $this->getLastOrders();
+ $smarty->assign('last_orders', $last_orders);
+
if (Tools::isSubmit('hideOptimizationTips'))
Configuration::updateValue('PS_HIDE_OPTIMIZATION_TIPS', 1);
- $this->_displayOptimizationTips();
+ $tips_optimization = $this->_displayOptimizationTips();
+ $smarty->assign('tips_optimization', $tips_optimization);
- $this->content .= '
-
+ $discover_prestashop = '
'.$this->l('Loading...').'
-
-
';
+
';
+ $smarty->assign('discover_prestashop', $discover_prestashop);
- $this->content .= Module::hookExec('backOfficeHome');
- $this->context->smarty->assign('content', $this->content);
+ $HOOK_BACKOFFICEHOME = Module::hookExec('backOfficeHome');
+ $smarty->assign('HOOK_BACKOFFICEHOME', $HOOK_BACKOFFICEHOME);
+
parent::display();
}
}