[*] BO #PSFV-94 : Added AdminStatsController && AdminStatsTabController && norm of statistic modules

git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@10004 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
lLefevre
2011-11-09 15:48:15 +00:00
parent 42bfc372da
commit dc716baa05
28 changed files with 980 additions and 891 deletions
-238
View File
@@ -1,238 +0,0 @@
<?php
/*
* 2007-2011 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2011 PrestaShop SA
* @version Release: $Revision: 7307 $
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
include_once(_PS_ADMIN_DIR_.'/tabs/AdminPreferences.php');
abstract class AdminStatsTab extends AdminPreferences
{
public function postProcess()
{
$this->context = Context::getContext();
if (Tools::isSubmit('submitDatePicker'))
{
if (!Validate::isDate($from = Tools::getValue('datepickerFrom')) OR !Validate::isDate($to = Tools::getValue('datepickerTo')))
$this->_errors[] = Tools::displayError('Date specified is invalid');
}
if (Tools::isSubmit('submitDateDay'))
{
$from = date('Y-m-d');
$to = date('Y-m-d');
}
if (Tools::isSubmit('submitDateDayPrev'))
{
$yesterday = time() - 60*60*24;
$from = date('Y-m-d', $yesterday);
$to = date('Y-m-d', $yesterday);
}
if (Tools::isSubmit('submitDateMonth'))
{
$from = date('Y-m-01');
$to = date('Y-m-t');
}
if (Tools::isSubmit('submitDateMonthPrev'))
{
$m = (date('m') == 1 ? 12 : date('m') - 1);
$y = ($m == 12 ? date('Y') - 1 : date('Y'));
$from = $y.'-'.$m.'-01';
$to = $y.'-'.$m.date('-t', mktime(12, 0, 0, $m, 15, $y));
}
if (Tools::isSubmit('submitDateYear'))
{
$from = date('Y-01-01');
$to = date('Y-12-31');
}
if (Tools::isSubmit('submitDateYearPrev'))
{
$from = (date('Y') - 1).date('-01-01');
$to = (date('Y') - 1).date('-12-31');
}
if (isset($from) AND isset($to) AND !sizeof($this->_errors))
{
$this->context->employee->stats_date_from = $from;
$this->context->employee->stats_date_to = $to;
$this->context->employee->update();
Tools::redirectAdmin($_SERVER['REQUEST_URI']);
}
if (Tools::getValue('submitSettings'))
{
if ($this->tabAccess['edit'] === '1')
{
self::$currentIndex .= '&module='.Tools::getValue('module');
Configuration::updateValue('PS_STATS_RENDER', Tools::getValue('PS_STATS_RENDER', Configuration::get('PS_STATS_RENDER')));
Configuration::updateValue('PS_STATS_GRID_RENDER', Tools::getValue('PS_STATS_GRID_RENDER', Configuration::get('PS_STATS_GRID_RENDER')));
}
else
$this->_errors[] = Tools::displayError('You do not have permission to edit here.');
}
if (sizeof($this->_errors))
AdminTab::displayErrors();
}
protected function displayEngines()
{
$graphEngine = Configuration::get('PS_STATS_RENDER');
$gridEngine = Configuration::get('PS_STATS_GRID_RENDER');
$arrayGraphEngines = ModuleGraphEngine::getGraphEngines();
$arrayGridEngines = ModuleGridEngine::getGridEngines();
echo '
<form action="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'" method="post">
<fieldset style="width: 200px;"><legend><img src="../img/admin/tab-preferences.gif" />'.$this->l('Settings', 'AdminStatsTab').'</legend>';
echo '<p><strong>'.$this->l('Graph engine', 'AdminStatsTab').' </strong><br />';
if (sizeof($arrayGraphEngines))
{
echo '<select name="PS_STATS_RENDER">';
foreach ($arrayGraphEngines as $k => $value)
echo '<option value="'.$k.'"'.($k == $graphEngine ? ' selected="selected"' : '').'>'.$value[0].'</option>';
echo '</select><p>';
}
else
echo $this->l('No graph engine module installed', 'AdminStatsTab');
echo '<p><strong>'.$this->l('Grid engine', 'AdminStatsTab').' </strong><br />';
if (sizeof($arrayGridEngines))
{
echo '<select name="PS_STATS_GRID_RENDER">';
foreach ($arrayGridEngines as $k => $value)
echo '<option value="'.$k.'"'.($k == $gridEngine ? ' selected="selected"' : '').'>'.$value[0].'</option>';
echo '</select></p>';
}
else
echo $this->l('No grid engine module installed', 'AdminStatsTab');
echo '<p><input type="submit" value="'.$this->l(' Save ', 'AdminStatsTab').'" name="submitSettings" class="button" /></p>
</fieldset>
</form><div class="clear space">&nbsp;</div>';
}
protected function getDate()
{
$year = isset($this->context->cookie->stats_year) ? $this->context->cookie->stats_year : date('Y');
$month = isset($this->context->cookie->stats_month) ? sprintf('%02d', $this->context->cookie->stats_month) : '%';
$day = isset($this->context->cookie->stats_day) ? sprintf('%02d', $this->context->cookie->stats_day) : '%';
return $year.'-'.$month.'-'.$day;
}
public function displayCalendar()
{
echo '<div id="calendar">
'.self::displayCalendarStatic(array(
'Calendar' => $this->l('Calendar', 'AdminStatsTab'), 'Day' => $this->l('Day', 'AdminStatsTab'),
'Month' => $this->l('Month', 'AdminStatsTab'), 'Year' => $this->l('Year', 'AdminStatsTab'),
'From' => $this->l('From:', 'AdminStatsTab'), 'To' => $this->l('To:', 'AdminStatsTab'), 'Save' => $this->l('Save', 'AdminStatsTab')
)).'
<div class="clear space">&nbsp;</div></div>';
}
public static function displayCalendarStatic($translations)
{
$context = Context::getContext();
includeDatepicker(array('datepickerFrom', 'datepickerTo'));
return '
<fieldset style="width: 200px; font-size:13px;"><legend><img src="../img/admin/date.png" /> '.$translations['Calendar'].'</legend>
<div>
<form action="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'" method="post">
<input type="submit" name="submitDateDay" class="button" value="'.$translations['Day'].'">
<input type="submit" name="submitDateMonth" class="button" value="'.$translations['Month'].'">
<input type="submit" name="submitDateYear" class="button" value="'.$translations['Year'].'"><br />
<input type="submit" name="submitDateDayPrev" class="button" value="'.$translations['Day'].'-1" style="margin-top:2px">
<input type="submit" name="submitDateMonthPrev" class="button" value="'.$translations['Month'].'-1" style="margin-top:2px">
<input type="submit" name="submitDateYearPrev" class="button" value="'.$translations['Year'].'-1" style="margin-top:2px">
<p>'.(isset($translations['From']) ? $translations['From'] : 'From:').' <input type="text" name="datepickerFrom" id="datepickerFrom" value="'.Tools::getValue('datepickerFrom', $context->employee->stats_date_from).'"></p>
<p>'.(isset($translations['To']) ? $translations['To'] : 'To:').' <input type="text" name="datepickerTo" id="datepickerTo" value="'.Tools::getValue('datepickerTo', $context->employee->stats_date_to).'"></p>
<input type="submit" name="submitDatePicker" class="button" value="'.(isset($translations['Save']) ? $translations['Save'] : ' Save ').'" />
</form>
</div>
</fieldset>';
}
public function displaySearch()
{
return;
echo '
<fieldset style="margin-top:20px; width: 200px;"><legend><img src="../img/admin/binoculars.png" /> '.$this->l('Search', 'AdminStatsTab').'</legend>
<input type="text" /> <input type="button" class="button" value="'.$this->l('Go', 'AdminStatsTab').'" />
</fieldset>';
}
private function getModules()
{
$sql = 'SELECT h.`name` AS hook, m.`name`
FROM `'._DB_PREFIX_.'module` m
LEFT JOIN `'._DB_PREFIX_.'hook_module` hm ON hm.`id_module` = m.`id_module`
LEFT JOIN `'._DB_PREFIX_.'hook` h ON hm.`id_hook` = h.`id_hook`
WHERE h.`name` LIKE \'AdminStatsModules\'
AND m.`active` = 1
GROUP BY hm.id_module
ORDER BY hm.`position`';
return Db::getInstance()->executeS($sql);
}
public function displayMenu()
{
$modules = $this->getModules();
echo '<fieldset style="width: 200px"><legend><img src="../img/admin/navigation.png" /> '.$this->l('Navigation', 'AdminStatsTab').'</legend>';
if (sizeof($modules))
{
foreach ($modules AS $module)
if ($moduleInstance = Module::getInstanceByName($module['name']))
echo '<h4><img src="../modules/'.$module['name'].'/logo.gif" /><a href="'.self::$currentIndex.'&token='.Tools::getValue('token').'&module='.$module['name'].'">'.$moduleInstance->displayName.'</a></h4>';
}
else
echo $this->l('No module installed', 'AdminStatsTab');
echo '</fieldset><div class="clear space">&nbsp;</div>';
}
public function display()
{
echo '<div style="float:left">';
$this->displayCalendar();
$this->displayEngines();
$this->displayMenu();
$this->displaySearch();
echo '</div>
<div style="float:left; margin-left:20px;">';
if (!($moduleName = Tools::getValue('module')) AND $moduleInstance = Module::getInstanceByName('statsforecast') AND $moduleInstance->active)
$moduleName = 'statsforecast';
if ($moduleName)
{
// Needed for the graphics display when this is the default module
$_GET['module'] = $moduleName;
if (!isset($moduleInstance))
$moduleInstance = Module::getInstanceByName($moduleName);
if ($moduleInstance AND $moduleInstance->active)
echo Hook::exec('AdminStatsModules', NULL, $moduleInstance->id);
else
echo $this->l('Module not found', 'AdminStatsTab');
}
else
echo '<h3 class="space">'.$this->l('Please select a module in the left column.').'</h3>';
echo '</div><div class="clear"></div>';
}
}
+3 -3
View File
@@ -1143,7 +1143,7 @@ class AdminControllerCore extends Controller
$img = _MODULE_DIR_.$tab['module'].'/'.$tab['class_name'].'.png'; $img = _MODULE_DIR_.$tab['module'].'/'.$tab['class_name'].'.png';
// retrocompatibility // retrocompatibility
if(!file_exists($img)) if (!file_exists($img))
$img = str_replace('png', 'gif', $img); $img = str_replace('png', 'gif', $img);
// tab[class_name] does not contains the "Controller" suffix // tab[class_name] does not contains the "Controller" suffix
@@ -1561,7 +1561,7 @@ class AdminControllerCore extends Controller
unset($parse_query['setShopContext']); unset($parse_query['setShopContext']);
Tools::redirectAdmin($url['path'].'?'.http_build_query($parse_query)); Tools::redirectAdmin($url['path'].'?'.http_build_query($parse_query));
} }
elseif (!Shop::isFeatureActive()) else if (!Shop::isFeatureActive())
$this->context->cookie->shopContext = 's-1'; $this->context->cookie->shopContext = 's-1';
$shop_id = ''; $shop_id = '';
@@ -2423,7 +2423,7 @@ EOF;
<div id="languages_'.$id.'" class="language_flags"> <div id="languages_'.$id.'" class="language_flags">
'.$this->l('Choose language:').'<br /><br />'; '.$this->l('Choose language:').'<br /><br />';
foreach ($languages as $language) foreach ($languages as $language)
if($use_vars_instead_of_ids) if ($use_vars_instead_of_ids)
$output .= '<img src="../img/l/'.(int)($language['id_lang']).'.jpg" class="pointer" alt="'.$language['name'].'" title="'.$language['name'].'" onclick="changeLanguage(\''.$id.'\', '.$ids.', '.$language['id_lang'].', \''.$language['iso_code'].'\');" /> '; $output .= '<img src="../img/l/'.(int)($language['id_lang']).'.jpg" class="pointer" alt="'.$language['name'].'" title="'.$language['name'].'" onclick="changeLanguage(\''.$id.'\', '.$ids.', '.$language['id_lang'].', \''.$language['iso_code'].'\');" /> ';
else else
$output .= '<img src="../img/l/'.(int)($language['id_lang']).'.jpg" class="pointer" alt="'.$language['name'].'" title="'.$language['name'].'" onclick="changeLanguage(\''.$id.'\', \''.$ids.'\', '.$language['id_lang'].', \''.$language['iso_code'].'\');" /> '; $output .= '<img src="../img/l/'.(int)($language['id_lang']).'.jpg" class="pointer" alt="'.$language['name'].'" title="'.$language['name'].'" onclick="changeLanguage(\''.$id.'\', \''.$ids.'\', '.$language['id_lang'].', \''.$language['iso_code'].'\');" /> ';
+12 -11
View File
@@ -27,7 +27,7 @@
abstract class ModuleGraphEngineCore extends Module abstract class ModuleGraphEngineCore extends Module
{ {
protected $_type; protected $_type;
public function __construct($type) public function __construct($type)
{ {
@@ -44,22 +44,23 @@ abstract class ModuleGraphEngineCore extends Module
public static function getGraphEngines() public static function getGraphEngines()
{ {
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
SELECT m.`name` SELECT m.`name`
FROM `'._DB_PREFIX_.'module` m FROM `'._DB_PREFIX_.'module` m
LEFT JOIN `'._DB_PREFIX_.'hook_module` hm ON hm.`id_module` = m.`id_module` LEFT JOIN `'._DB_PREFIX_.'hook_module` hm ON hm.`id_module` = m.`id_module`
LEFT JOIN `'._DB_PREFIX_.'hook` h ON hm.`id_hook` = h.`id_hook` LEFT JOIN `'._DB_PREFIX_.'hook` h ON hm.`id_hook` = h.`id_hook`
WHERE h.`name` = \'GraphEngine\''); WHERE h.`name` = \'displayAdminStatsGraphEngine\'
');
$arrayEngines = array(); $array_engines = array();
foreach ($result AS $module) foreach ($result as $module)
{ {
$instance = Module::getInstanceByName($module['name']); $instance = Module::getInstanceByName($module['name']);
if (!$instance) if (!$instance)
continue; continue;
$arrayEngines[$module['name']] = array($instance->displayName, $instance->description); $array_engines[$module['name']] = array($instance->displayName, $instance->description);
} }
return $arrayEngines; return $array_engines;
} }
abstract public function createValues($values); abstract public function createValues($values);
+13 -11
View File
@@ -27,7 +27,7 @@
abstract class ModuleGridEngineCore extends Module abstract class ModuleGridEngineCore extends Module
{ {
protected $_type; protected $_type;
public function __construct($type) public function __construct($type)
{ {
@@ -44,21 +44,23 @@ abstract class ModuleGridEngineCore extends Module
public static function getGridEngines() public static function getGridEngines()
{ {
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
SELECT m.`name` SELECT m.`name`
FROM `'._DB_PREFIX_.'module` m FROM `'._DB_PREFIX_.'module` m
LEFT JOIN `'._DB_PREFIX_.'hook_module` hm ON hm.`id_module` = m.`id_module` LEFT JOIN `'._DB_PREFIX_.'hook_module` hm ON hm.`id_module` = m.`id_module`
LEFT JOIN `'._DB_PREFIX_.'hook` h ON hm.`id_hook` = h.`id_hook` LEFT JOIN `'._DB_PREFIX_.'hook` h ON hm.`id_hook` = h.`id_hook`
WHERE h.`name` = \'GridEngine\''); WHERE h.`name` = \'displayAdminStatsGridEngine\'
');
$arrayEngines = array(); $array_engines = array();
foreach ($result AS $module) foreach ($result as $module)
{ {
$instance = Module::getInstanceByName($module['name']); $instance = Module::getInstanceByName($module['name']);
if (!$instance) if (!$instance)
continue; continue;
$arrayEngines[$module['name']] = array($instance->displayName, $instance->description); $array_engines[$module['name']] = array($instance->displayName, $instance->description);
} }
return $arrayEngines;
return $array_engines;
} }
abstract public function setValues($values); abstract public function setValues($values);
@@ -25,11 +25,6 @@
* International Registered Trademark & Property of PrestaShop SA * International Registered Trademark & Property of PrestaShop SA
*/ */
class AdminStatsControllerCore extends AdminStatsTabControllerCore
include_once(dirname(__FILE__).'/AdminStatsTab.php');
class AdminStats extends AdminStatsTab
{ {
} }
@@ -0,0 +1,232 @@
<?php
/*
* 2007-2011 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2011 PrestaShop SA
* @version Release: $Revision: 7307 $
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
abstract class AdminStatsTabControllerCore extends AdminPreferencesControllerCore
{
public function init()
{
parent::init();
$this->action = 'view';
$this->display = 'view';
}
public function initContent()
{
if ($this->display == 'view')
{
// Some controllers use the view action without an object
if ($this->className)
$this->loadObject(true);
$this->content .= $this->initView();
}
$this->content .= $this->displayCalendar();
$this->content .= $this->displayEngines();
$this->content .= $this->displayMenu();
$this->content .= $this->displayStats();
$this->context->smarty->assign(array(
'content' => $this->content,
'url_post' => self::$currentIndex.'&token='.$this->token,
));
}
public function displayCalendar()
{
return $this->displayCalendarForm(array(
'Calendar' => $this->l('Calendar', 'AdminStatsTab'),
'Day' => $this->l('Day', 'AdminStatsTab'),
'Month' => $this->l('Month', 'AdminStatsTab'),
'Year' => $this->l('Year', 'AdminStatsTab'),
'From' => $this->l('From:', 'AdminStatsTab'),
'To' => $this->l('To:', 'AdminStatsTab'),
'Save' => $this->l('Save', 'AdminStatsTab')
));
}
public function displayCalendarForm($translations)
{
$tpl = $this->context->smarty->createTemplate('stats/calendar.tpl');
$tpl->assign(array(
'current' => self::$currentIndex,
'token' => $this->token,
'translations' => $translations,
'datepickerFrom' => Tools::getValue('datepickerFrom', $this->context->employee->stats_date_from),
'datepickerTo' => Tools::getValue('datepickerTo', $this->context->employee->stats_date_to)
));
return $tpl->fetch();
}
protected function displayEngines()
{
$tpl = $this->context->smarty->createTemplate('stats/engines.tpl');
$tpl->assign(array(
'current' => self::$currentIndex,
'token' => $this->token,
'graph_engine' => Configuration::get('PS_STATS_RENDER'),
'grid_engine' => Configuration::get('PS_STATS_GRID_RENDER'),
'array_graph_engines' => ModuleGraphEngine::getGraphEngines(),
'array_grid_engines' => ModuleGridEngine::getGridEngines()
));
return $tpl->fetch();
}
public function displayMenu()
{
$tpl = $this->context->smarty->createTemplate('stats/menu.tpl');
$modules = $this->getModules();
$module_instance = array();
foreach ($modules as $module)
$module_instance[$module['name']] = Module::getInstanceByName($module['name']);
$tpl->assign(array(
'current' => self::$currentIndex,
'token' => $this->token,
'modules' => $modules,
'module_instance' => $module_instance
));
return $tpl->fetch();
}
private function getModules()
{
$sql = 'SELECT h.`name` AS hook, m.`name`
FROM `'._DB_PREFIX_.'module` m
LEFT JOIN `'._DB_PREFIX_.'hook_module` hm ON hm.`id_module` = m.`id_module`
LEFT JOIN `'._DB_PREFIX_.'hook` h ON hm.`id_hook` = h.`id_hook`
WHERE h.`name` LIKE \'displayAdminStatsModules\'
AND m.`active` = 1
GROUP BY hm.id_module
ORDER BY hm.`position`';
return Db::getInstance()->executeS($sql);
}
public function displayStats()
{
$tpl = $this->context->smarty->createTemplate('stats/stats.tpl');
if (!($module_name = Tools::getValue('module')) && $module_instance = Module::getInstanceByName('statsforecast') AND $module_instance->active)
$module_name = 'statsforecast';
if ($module_name)
{
$_GET['module'] = $module_name;
if (!isset($module_instance))
$module_instance = Module::getInstanceByName($module_name);
if ($module_instance && $module_instance->active)
$hook = Hook::exec('AdminStatsModules', NULL, $module_instance->id);
}
$tpl->assign(array(
'module_name' => $module_name,
'module_instance' => $module_instance,
'hook' => $hook
));
return $tpl->fetch();
}
public function postProcess()
{
$this->context = Context::getContext();
if (Tools::isSubmit('submitDatePicker'))
{
if (!Validate::isDate($from = Tools::getValue('datepickerFrom')) || !Validate::isDate($to = Tools::getValue('datepickerTo')))
$this->_errors[] = Tools::displayError('Date specified is invalid');
}
if (Tools::isSubmit('submitDateDay'))
{
$from = date('Y-m-d');
$to = date('Y-m-d');
}
if (Tools::isSubmit('submitDateDayPrev'))
{
$yesterday = time() - 60 * 60 * 24;
$from = date('Y-m-d', $yesterday);
$to = date('Y-m-d', $yesterday);
}
if (Tools::isSubmit('submitDateMonth'))
{
$from = date('Y-m-01');
$to = date('Y-m-t');
}
if (Tools::isSubmit('submitDateMonthPrev'))
{
$m = (date('m') == 1 ? 12 : date('m') - 1);
$y = ($m == 12 ? date('Y') - 1 : date('Y'));
$from = $y.'-'.$m.'-01';
$to = $y.'-'.$m.date('-t', mktime(12, 0, 0, $m, 15, $y));
}
if (Tools::isSubmit('submitDateYear'))
{
$from = date('Y-01-01');
$to = date('Y-12-31');
}
if (Tools::isSubmit('submitDateYearPrev'))
{
$from = (date('Y') - 1).date('-01-01');
$to = (date('Y') - 1).date('-12-31');
}
if (isset($from) && isset($to) && !count($this->_errors))
{
$this->context->employee->stats_date_from = $from;
$this->context->employee->stats_date_to = $to;
$this->context->employee->update();
Tools::redirectAdmin($_SERVER['REQUEST_URI']);
}
if (Tools::getValue('submitSettings'))
{
if ($this->tabAccess['edit'] === '1')
{
self::$currentIndex .= '&module='.Tools::getValue('module');
Configuration::updateValue('PS_STATS_RENDER', Tools::getValue('PS_STATS_RENDER', Configuration::get('PS_STATS_RENDER')));
Configuration::updateValue('PS_STATS_GRID_RENDER', Tools::getValue('PS_STATS_GRID_RENDER', Configuration::get('PS_STATS_GRID_RENDER')));
}
else
$this->_errors[] = Tools::displayError('You do not have permission to edit here.');
}
if (count($this->_errors))
AdminTab::displayErrors();
}
protected function getDate()
{
$year = isset($this->context->cookie->stats_year) ? $this->context->cookie->stats_year : date('Y');
$month = isset($this->context->cookie->stats_month) ? sprintf('%02d', $this->context->cookie->stats_month) : '%';
$day = isset($this->context->cookie->stats_day) ? sprintf('%02d', $this->context->cookie->stats_day) : '%';
return $year.'-'.$month.'-'.$day;
}
}
+58 -48
View File
@@ -30,43 +30,43 @@ if (!defined('_PS_VERSION_'))
class Pagesnotfound extends Module class Pagesnotfound extends Module
{ {
private $_html = ''; private $_html = '';
function __construct() public function __construct()
{ {
$this->name = 'pagesnotfound'; $this->name = 'pagesnotfound';
$this->tab = 'analytics_stats'; $this->tab = 'analytics_stats';
$this->version = 1.0; $this->version = 1.0;
$this->author = 'PrestaShop'; $this->author = 'PrestaShop';
$this->need_instance = 0; $this->need_instance = 0;
parent::__construct(); parent::__construct();
$this->displayName = $this->l('Pages not found'); $this->displayName = $this->l('Pages not found');
$this->description = $this->l('Display the pages requested by your visitors but not found.'); $this->description = $this->l('Display the pages requested by your visitors but not found.');
} }
function install() public function install()
{ {
if (!parent::install() OR !$this->registerHook('top') OR !$this->registerHook('AdminStatsModules')) if (!parent::install() || !$this->registerHook('top') || !$this->registerHook('AdminStatsModules'))
return false; return false;
return Db::getInstance()->execute(' return Db::getInstance()->execute('
CREATE TABLE `'._DB_PREFIX_.'pagenotfound` ( CREATE TABLE `'._DB_PREFIX_.'pagenotfound` (
id_pagenotfound INTEGER UNSIGNED NOT NULL AUTO_INCREMENT, id_pagenotfound INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
id_shop INTEGER UNSIGNED NOT NULL DEFAULT \'1\', id_shop INTEGER UNSIGNED NOT NULL DEFAULT \'1\',
id_group_shop INTEGER UNSIGNED NOT NULL DEFAULT \'1\', id_group_shop INTEGER UNSIGNED NOT NULL DEFAULT \'1\',
request_uri VARCHAR(256) NOT NULL, request_uri VARCHAR(256) NOT NULL,
http_referer VARCHAR(256) NOT NULL, http_referer VARCHAR(256) NOT NULL,
date_add DATETIME NOT NULL, date_add DATETIME NOT NULL,
PRIMARY KEY(id_pagenotfound), PRIMARY KEY(id_pagenotfound),
INDEX (`date_add`) INDEX (`date_add`)
) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8;'); ) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8;');
} }
function uninstall() public function uninstall()
{ {
return (parent::uninstall() AND Db::getInstance()->execute('DROP TABLE `'._DB_PREFIX_.'pagenotfound`')); return (parent::uninstall() && Db::getInstance()->execute('DROP TABLE `'._DB_PREFIX_.'pagenotfound`'));
} }
private function getPages() private function getPages()
{ {
@@ -81,7 +81,7 @@ class Pagesnotfound extends Module
foreach ($result as $row) foreach ($result as $row)
{ {
$row['http_referer'] = parse_url($row['http_referer'], PHP_URL_HOST).parse_url($row['http_referer'], PHP_URL_PATH); $row['http_referer'] = parse_url($row['http_referer'], PHP_URL_HOST).parse_url($row['http_referer'], PHP_URL_PATH);
if (!isset($row['http_referer']) OR empty($row['http_referer'])) if (!isset($row['http_referer']) || empty($row['http_referer']))
$row['http_referer'] = '--'; $row['http_referer'] = '--';
if (!isset($pages[$row['request_uri']])) if (!isset($pages[$row['request_uri']]))
$pages[$row['request_uri']] = array('nb' => 0); $pages[$row['request_uri']] = array('nb' => 0);
@@ -92,14 +92,14 @@ class Pagesnotfound extends Module
return $pages; return $pages;
} }
function hookAdminStatsModules() public function hookAdminStatsModules()
{ {
if (Tools::isSubmit('submitTruncatePNF')) if (Tools::isSubmit('submitTruncatePNF'))
{ {
Db::getInstance()->execute('TRUNCATE `'._DB_PREFIX_.'pagenotfound`'); Db::getInstance()->execute('TRUNCATE `'._DB_PREFIX_.'pagenotfound`');
$this->_html .= '<div class="conf confirm"><img src="../img/admin/ok.gif" /> '.$this->l('Pages not found has been emptied.').'</div>'; $this->_html .= '<div class="conf confirm"><img src="../img/admin/ok.gif" /> '.$this->l('Pages not found has been emptied.').'</div>';
} }
elseif (Tools::isSubmit('submitDeletePNF')) else if (Tools::isSubmit('submitDeletePNF'))
{ {
Db::getInstance()->execute(' Db::getInstance()->execute('
DELETE FROM `'._DB_PREFIX_.'pagenotfound` DELETE FROM `'._DB_PREFIX_.'pagenotfound`
@@ -107,12 +107,12 @@ class Pagesnotfound extends Module
$this->_html .= '<div class="conf confirm"><img src="../img/admin/ok.gif" /> '.$this->l('Pages not found have been deleted.').'</div>'; $this->_html .= '<div class="conf confirm"><img src="../img/admin/ok.gif" /> '.$this->l('Pages not found have been deleted.').'</div>';
} }
$this->_html .= '<fieldset class="width3"><legend><img src="../modules/'.$this->name.'/logo.gif" /> '.$this->displayName.'</legend>'; $this->_html .= '<fieldset><legend><img src="../modules/'.$this->name.'/logo.gif" /> '.$this->displayName.'</legend>';
if (!file_exists(dirname(__FILE__).'/../../.htaccess')) if (!file_exists(dirname(__FILE__).'/../../.htaccess'))
$this->_html .= '<div class="warning warn">'.$this->l('You <b>must</b> use a .htaccess file to redirect 404 errors to the page "404.php"').'</div>'; $this->_html .= '<div class="warning warn">'.$this->l('You <b>must</b> use a .htaccess file to redirect 404 errors to the page "404.php"').'</div>';
$pages = $this->getPages(); $pages = $this->getPages();
if (sizeof($pages)) if (count($pages))
{ {
$this->_html .= ' $this->_html .= '
<table class="table" cellpadding="0" cellspacing="0"> <table class="table" cellpadding="0" cellspacing="0">
@@ -137,42 +137,52 @@ class Pagesnotfound extends Module
$this->_html .= '<div class="conf confirm"><img src="../img/admin/ok.gif" /> '.$this->l('No pages registered').'</div>'; $this->_html .= '<div class="conf confirm"><img src="../img/admin/ok.gif" /> '.$this->l('No pages registered').'</div>';
$this->_html .= '</fieldset>'; $this->_html .= '</fieldset>';
if (sizeof($pages)) if (count($pages))
$this->_html .= '<div class="clear">&nbsp;</div> $this->_html .= '<div class="clear">&nbsp;</div>
<fieldset class="width3"><legend><img src="../img/admin/delete.gif" /> '.$this->l('Empty database').'</legend> <fieldset><legend><img src="../img/admin/delete.gif" /> '.$this->l('Empty database').'</legend>
<form action="'.Tools::htmlEntitiesUtf8($_SERVER['REQUEST_URI']).'" method="post"> <form action="'.Tools::htmlEntitiesUtf8($_SERVER['REQUEST_URI']).'" method="post">
<input type="submit" class="button" name="submitDeletePNF" value="'.$this->l('Empty ALL pages not found in this period').'"> <input type="submit" class="button" name="submitDeletePNF" value="'.$this->l('Empty ALL pages not found in this period').'">
<input type="submit" class="button" name="submitTruncatePNF" value="'.$this->l('Empty ALL pages not found').'"> <input type="submit" class="button" name="submitTruncatePNF" value="'.$this->l('Empty ALL pages not found').'">
</form> </form>
</fieldset>'; </fieldset>';
$this->_html .= '<div class="clear">&nbsp;</div> $this->_html .= '<br />
<fieldset class="width3"><legend><img src="../img/admin/comment.gif" /> '.$this->l('Guide').'</legend> <fieldset><legend><img src="../img/admin/comment.gif" /> '.$this->l('Guide').'</legend>
<h2>'.$this->l('404 errors').'</h2> <h2>'.$this->l('404 errors').'</h2>
<p>'.$this->l('A 404 error is an HTTP error code which means that the file requested by the user cannot be found. In your case it means that one of your visitors entered a wrong URL in the address bar or that you or another website has a dead link. When it is available, the referrer is shown so you can find the page which contains the dead link. If not, it means generally that it is a direct access, so someone may have bookmarked a link which doesn\'t exist anymore.').'</p> <p>'.$this->l('A 404 error is an HTTP error code which means that the file requested by the user cannot be found.
In your case it means that one of your visitors entered a wrong URL in the address bar or that you or another website has a dead link.
When it is available, the referrer is shown so you can find the page which contains the dead link.
If not, it means generally that it is a direct access, so someone may have bookmarked a link which doesn\'t exist anymore.').'</p>
<h3>'.$this->l('How to catch these errors?').'</h3> <h3>'.$this->l('How to catch these errors?').'</h3>
<p>'.$this->l('If your webhost supports the <i>.htaccess</i> file, you can create it in the root directory of PrestaShop and insert the following line inside:').' <i>ErrorDocument 404 '.__PS_BASE_URI__.'404.php</i>. '.$this->l('A user requesting a page which doesn\'t exist will be redirected to the page.').' <i>'.__PS_BASE_URI__.'404.php</i>. '.$this->l('This module logs the accesses to this page: the page requested, the referrer and the number of times that it occurred.').'</p><br /> <p>'.$this->l('If your webhost supports the <i>.htaccess</i> file, you can create it in the root directory of PrestaShop and insert the following line inside:').'
<i>ErrorDocument 404 '.__PS_BASE_URI__.'404.php</i>. '.
$this->l('A user requesting a page which doesn\'t exist will be redirected to the page.').' <i>'.__PS_BASE_URI__.'404.php</i>. '.
$this->l('This module logs the accesses to this page: the page requested, the referrer and the number of times that it occurred.').'</p><br />
</fieldset>'; </fieldset>';
return $this->_html; return $this->_html;
} }
function hookTop($params) public function hookTop($params)
{ {
if (strstr($_SERVER['REQUEST_URI'], '404.php') AND isset($_SERVER['REDIRECT_URL'])) if (strstr($_SERVER['REQUEST_URI'], '404.php') && isset($_SERVER['REDIRECT_URL']))
$_SERVER['REQUEST_URI'] = $_SERVER['REDIRECT_URL']; $_SERVER['REQUEST_URI'] = $_SERVER['REDIRECT_URL'];
if (!Validate::isUrl($request_uri = $_SERVER['REQUEST_URI']) OR strstr($_SERVER['REQUEST_URI'], '-admin404')) if (!Validate::isUrl($request_uri = $_SERVER['REQUEST_URI']) || strstr($_SERVER['REQUEST_URI'], '-admin404'))
return; return;
if (strstr($_SERVER['PHP_SELF'], '404.php') AND !strstr($_SERVER['REQUEST_URI'], '404.php')) if (strstr($_SERVER['PHP_SELF'], '404.php') && !strstr($_SERVER['REQUEST_URI'], '404.php'))
{ {
$http_referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : ''; $http_referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '';
if (empty($http_referer) OR Validate::isAbsoluteUrl($http_referer)) if (empty($http_referer) || Validate::isAbsoluteUrl($http_referer))
Db::getInstance()->execute('INSERT INTO `'._DB_PREFIX_.'pagenotfound` (`request_uri`, `http_referer`, `date_add`, `id_shop`, `id_group_shop`) VALUES (\''.pSQL($request_uri).'\', \''.pSQL($http_referer).'\', NOW(), '.$this->context->shop->getID().', '.$this->context->shop->getGroupID().')'); Db::getInstance()->execute('
INSERT INTO `'._DB_PREFIX_.'pagenotfound` (`request_uri`, `http_referer`, `date_add`, `id_shop`, `id_group_shop`)
VALUES (\''.pSQL($request_uri).'\', \''.pSQL($http_referer).'\', NOW(), '.$this->context->shop->getID().', '.$this->context->shop->getGroupID().')
');
} }
} }
} }
function pnfSort($a, $b) { function pnfSort($a, $b)
if ($a['nb'] == $b['nb']) {
return 0; if ($a['nb'] == $b['nb'])
return ($a['nb'] > $b['nb']) ? -1 : 1; return 0;
return ($a['nb'] > $b['nb']) ? -1 : 1;
} }
+32 -28
View File
@@ -30,19 +30,19 @@ if (!defined('_PS_VERSION_'))
class SEKeywords extends ModuleGraph class SEKeywords extends ModuleGraph
{ {
private $_html = ''; private $html = '';
private $_query = ''; private $_query = '';
private $_query2 = ''; private $_query2 = '';
public function __construct() public function __construct()
{ {
$this->name = 'sekeywords'; $this->name = 'sekeywords';
$this->tab = 'analytics_stats'; $this->tab = 'analytics_stats';
$this->version = 1.0; $this->version = 1.0;
$this->author = 'PrestaShop'; $this->author = 'PrestaShop';
$this->need_instance = 0; $this->need_instance = 0;
parent::__construct(); parent::__construct();
$this->_query = 'SELECT `keyword`, COUNT(TRIM(`keyword`)) as occurences $this->_query = 'SELECT `keyword`, COUNT(TRIM(`keyword`)) as occurences
FROM `'._DB_PREFIX_.'sekeyword` FROM `'._DB_PREFIX_.'sekeyword`
@@ -54,13 +54,13 @@ class SEKeywords extends ModuleGraph
HAVING occurences > '.(int)Configuration::get('SEK_MIN_OCCURENCES').' HAVING occurences > '.(int)Configuration::get('SEK_MIN_OCCURENCES').'
ORDER BY occurences DESC'; ORDER BY occurences DESC';
$this->displayName = $this->l('Search engine keywords'); $this->displayName = $this->l('Search engine keywords');
$this->description = $this->l('Display which keywords have led visitors to your website.'); $this->description = $this->l('Display which keywords have led visitors to your website.');
} }
public function install() public function install()
{ {
if (!parent::install() OR !$this->registerHook('top') OR !$this->registerHook('AdminStatsModules')) if (!parent::install() || !$this->registerHook('top') || !$this->registerHook('AdminStatsModules'))
return false; return false;
Configuration::updateValue('SEK_MIN_OCCURENCES', 1); Configuration::updateValue('SEK_MIN_OCCURENCES', 1);
Configuration::updateValue('SEK_FILTER_KW', ''); Configuration::updateValue('SEK_FILTER_KW', '');
@@ -75,16 +75,16 @@ class SEKeywords extends ModuleGraph
) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8'); ) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8');
} }
public function uninstall() public function uninstall()
{ {
if (!parent::uninstall()) if (!parent::uninstall())
return false; return false;
return (Db::getInstance()->execute('DROP TABLE `'._DB_PREFIX_.'sekeyword`')); return (Db::getInstance()->execute('DROP TABLE `'._DB_PREFIX_.'sekeyword`'));
} }
public function hookTop($params) public function hookTop($params)
{ {
if (!isset($_SERVER['HTTP_REFERER']) OR strstr($_SERVER['HTTP_REFERER'], Tools::getHttpHost(false, false))) if (!isset($_SERVER['HTTP_REFERER']) || strstr($_SERVER['HTTP_REFERER'], Tools::getHttpHost(false, false)))
return; return;
if ($keywords = $this->getKeywords($_SERVER['HTTP_REFERER'])) if ($keywords = $this->getKeywords($_SERVER['HTTP_REFERER']))
@@ -105,9 +105,9 @@ class SEKeywords extends ModuleGraph
$this->csvExport(array('type' => 'pie')); $this->csvExport(array('type' => 'pie'));
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($this->_query.ModuleGraph::getDateBetween().$this->_query2); $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($this->_query.ModuleGraph::getDateBetween().$this->_query2);
$total = count($result); $total = count($result);
$this->_html = '<fieldset class="width3"><legend><img src="../modules/'.$this->name.'/logo.gif" /> '.$this->displayName.'</legend> $this->html = '<fieldset><legend><img src="../modules/'.$this->name.'/logo.gif" /> '.$this->displayName.'</legend>
'.$total.' '.($total == 1 ? $this->l('keyword matches your query.') : $this->l('keywords match your query.')).'<div class="clear">&nbsp;</div>'; '.$total.' '.($total == 1 ? $this->l('keyword matches your query.') : $this->l('keywords match your query.')).'<div class="clear">&nbsp;</div>';
if ($result AND $total) if ($result && $total)
{ {
$table = ' $table = '
<div style="overflow-y: scroll; height: 600px;"> <div style="overflow-y: scroll; height: 600px;">
@@ -123,27 +123,31 @@ class SEKeywords extends ModuleGraph
$table .= '<tr><td>'.$keyword.'</td><td style="text-align: right">'.$occurences.'</td></tr>'; $table .= '<tr><td>'.$keyword.'</td><td style="text-align: right">'.$occurences.'</td></tr>';
} }
$table .= '</tbody></table></div>'; $table .= '</tbody></table></div>';
$this->_html .= '<center>'.$this->engine(array('type' => 'pie')).'</center> $this->html .= '<div>'.$this->engine(array('type' => 'pie')).'</div>
<br class="clear" /> <br class="clear" />
<p><a href="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'&export=1&exportType=language"><img src="../img/admin/asterisk.gif" />'.$this->l('CSV Export').'</a></p><br class="clear" /> <p><a href="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'&export=1&exportType=language"><img src="../img/admin/asterisk.gif" />'.$this->l('CSV Export').'</a></p><br class="clear" />
<form action="'.Tools::htmlentitiesUTF8($_SERVER['REQUEST_URI']).'" method="post"> <form action="'.Tools::htmlentitiesUTF8($_SERVER['REQUEST_URI']).'" method="post">
'.$this->l('Filter by keyword').' <input type="text" name="SEK_FILTER_KW" value="'.Tools::htmlentitiesUTF8(Configuration::get('SEK_FILTER_KW')).'" /> '.$this->l('Filter by keyword').' <input type="text" name="SEK_FILTER_KW" value="'.Tools::htmlentitiesUTF8(Configuration::get('SEK_FILTER_KW')).'" />
'.$this->l('and min occurrences').' <input type="text" name="SEK_MIN_OCCURENCES" value="'.(int)(Configuration::get('SEK_MIN_OCCURENCES')).'" /> '.$this->l('and min occurrences').' <input type="text" name="SEK_MIN_OCCURENCES" value="'.(int)Configuration::get('SEK_MIN_OCCURENCES').'" />
<input type="submit" class="button" name="submitSEK" value="'.$this->l(' Apply ').'" /> <input type="submit" class="button" name="submitSEK" value="'.$this->l(' Apply ').'" />
</form> </form>
<br class="clear" />'.$table; <br class="clear" />'.$table;
} }
else else
$this->_html .= '<p><strong>'.$this->l('No keywords').'</strong></p>'; $this->html .= '<p><strong>'.$this->l('No keywords').'</strong></p>';
$this->_html .= '</fieldset><br class="clear" /> $this->html .= '</fieldset><br class="clear" />
<fieldset class="width3"><legend><img src="../img/admin/comment.gif" /> '.$this->l('Guide').'</legend> <fieldset><legend><img src="../img/admin/comment.gif" /> '.$this->l('Guide').'</legend>
<h2>'.$this->l('Identify external search engines\' keywords').'</h2> <h2>'.$this->l('Identify external search engines\' keywords').'</h2>
<p>'.$this->l('One of the most common ways of finding a website through a search engine. Identifying the most popular keywords entered by your new visitors allows you to see which products you should put in front if you want to attract more visitors and potential customers.').'</p><br /> <p>'.$this->l('One of the most common ways of finding a website through a search engine.
Identifying the most popular keywords entered by your new visitors allows you to see which products you should put in front if you want to attract more visitors and potential customers.').'
</p><br />
<h3>'.$this->l('How does it work?').'</h2> <h3>'.$this->l('How does it work?').'</h2>
<p>'.$this->l('When a visitor comes to your website, the server notes their previous location. This module parses the URL and finds the keywords in it. Currently, it manages the following search engines:').'<b> Google, AOL, Yandex, Ask, NHL, Yahoo, Baidu, Lycos, Exalead, Live, Voila</b> '.$this->l('and').' <b>Altavista</b>. '.$this->l('Soon it will be possible to dynamically add new search engines and contribute to this module.').'</p><br /> <p>'.$this->l('When a visitor comes to your website, the server notes their previous location. This module parses the URL and finds the keywords in it.
Currently, it manages the following search engines:').'<b> Google, AOL, Yandex, Ask, NHL, Yahoo, Baidu, Lycos, Exalead, Live, Voila</b> '.$this->l('and').' <b>Altavista</b>. '.
$this->l('Soon it will be possible to dynamically add new search engines and contribute to this module.').'</p><br />
</fieldset>'; </fieldset>';
return $this->_html; return $this->html;
} }
public function getKeywords($url) public function getKeywords($url)
@@ -166,9 +170,9 @@ class SEKeywords extends ModuleGraph
{ {
$kArray = array(); $kArray = array();
preg_match('/[^a-z]'.$varname.'=.+\&'.'/U', $parsedUrl['query'], $kArray); preg_match('/[^a-z]'.$varname.'=.+\&'.'/U', $parsedUrl['query'], $kArray);
if (!isset($kArray[0]) OR empty($kArray[0])) if (!isset($kArray[0]) || empty($kArray[0]))
preg_match('/[^a-z]'.$varname.'=.+$'.'/', $parsedUrl['query'], $kArray); preg_match('/[^a-z]'.$varname.'=.+$'.'/', $parsedUrl['query'], $kArray);
if (!isset($kArray[0]) OR empty($kArray[0])) if (!isset($kArray[0]) || empty($kArray[0]))
return false; return false;
$kString = urldecode(str_replace('+', ' ', ltrim(substr(rtrim($kArray[0], '&'), strlen($varname) + 1), '='))); $kString = urldecode(str_replace('+', ' ', ltrim(substr(rtrim($kArray[0], '&'), strlen($varname) + 1), '=')));
return $kString; return $kString;
@@ -38,7 +38,7 @@ class StatsBestCategories extends ModuleGrid
private $_emptyMessage; private $_emptyMessage;
private $_pagingMessage; private $_pagingMessage;
function __construct() public function __construct()
{ {
$this->name = 'statsbestcategories'; $this->name = 'statsbestcategories';
$this->tab = 'analytics_stats'; $this->tab = 'analytics_stats';
@@ -90,7 +90,7 @@ class StatsBestCategories extends ModuleGrid
public function install() public function install()
{ {
return (parent::install() AND $this->registerHook('AdminStatsModules')); return (parent::install() && $this->registerHook('AdminStatsModules'));
} }
public function hookAdminStatsModules($params) public function hookAdminStatsModules($params)
@@ -109,7 +109,7 @@ class StatsBestCategories extends ModuleGrid
$this->csvExport($engineParams); $this->csvExport($engineParams);
$this->_html = ' $this->_html = '
<fieldset class="width3"><legend><img src="../modules/'.$this->name.'/logo.gif" /> '.$this->displayName.'</legend> <fieldset><legend><img src="../modules/'.$this->name.'/logo.gif" /> '.$this->displayName.'</legend>
'.$this->engine($engineParams).' '.$this->engine($engineParams).'
<br /><a href="'.htmlentities($_SERVER['REQUEST_URI']).'&export=1"><img src="../img/admin/asterisk.gif" />'.$this->l('CSV Export').'</a> <br /><a href="'.htmlentities($_SERVER['REQUEST_URI']).'&export=1"><img src="../img/admin/asterisk.gif" />'.$this->l('CSV Export').'</a>
</fieldset>'; </fieldset>';
@@ -136,7 +136,7 @@ class StatsBestCategories extends ModuleGrid
{ {
$ntreeRestriction = array(); $ntreeRestriction = array();
foreach ($result as $row) foreach ($result as $row)
$ntreeRestriction[] = '(nleft >= ' . $row['nleft'] . ' AND nright <= ' . $row['nright'] . ')'; $ntreeRestriction[] = '(nleft >= '.$row['nleft'].' AND nright <= '.$row['nright'].')';
if ($ntreeRestriction) if ($ntreeRestriction)
{ {
@@ -194,10 +194,10 @@ class StatsBestCategories extends ModuleGrid
if (Validate::IsName($this->_sort)) if (Validate::IsName($this->_sort))
{ {
$this->_query .= ' ORDER BY `'.$this->_sort.'`'; $this->_query .= ' ORDER BY `'.$this->_sort.'`';
if (isset($this->_direction) AND Validate::IsSortDirection($this->_direction)) if (isset($this->_direction) && Validate::IsSortDirection($this->_direction))
$this->_query .= ' '.$this->_direction; $this->_query .= ' '.$this->_direction;
} }
if (($this->_start === 0 OR Validate::IsUnsignedInt($this->_start)) AND Validate::IsUnsignedInt($this->_limit)) if (($this->_start === 0 || Validate::IsUnsignedInt($this->_start)) && Validate::IsUnsignedInt($this->_limit))
$this->_query .= ' LIMIT '.$this->_start.', '.($this->_limit); $this->_query .= ' LIMIT '.$this->_start.', '.($this->_limit);
$this->_values = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($this->_query); $this->_values = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($this->_query);
$this->_totalCount = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('SELECT FOUND_ROWS()'); $this->_totalCount = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('SELECT FOUND_ROWS()');
@@ -38,7 +38,7 @@ class StatsBestCustomers extends ModuleGrid
private $_emptyMessage; private $_emptyMessage;
private $_pagingMessage; private $_pagingMessage;
function __construct() public function __construct()
{ {
$this->name = 'statsbestcustomers'; $this->name = 'statsbestcustomers';
$this->tab = 'analytics_stats'; $this->tab = 'analytics_stats';
@@ -92,7 +92,7 @@ class StatsBestCustomers extends ModuleGrid
public function install() public function install()
{ {
return (parent::install() AND $this->registerHook('AdminStatsModules')); return (parent::install() && $this->registerHook('AdminStatsModules'));
} }
public function hookAdminStatsModules($params) public function hookAdminStatsModules($params)
@@ -109,19 +109,21 @@ class StatsBestCustomers extends ModuleGrid
if (Tools::getValue('export')) if (Tools::getValue('export'))
$this->csvExport($engineParams); $this->csvExport($engineParams);
$this->_html = ' $this->_html = '
<fieldset class="width3"><legend><img src="../modules/'.$this->name.'/logo.gif" /> '.$this->displayName.'</legend> <fieldset><legend><img src="../modules/'.$this->name.'/logo.gif" /> '.$this->displayName.'</legend>
'.$this->engine($engineParams).' '.$this->engine($engineParams).'
<p><a href="'.htmlentities($_SERVER['REQUEST_URI']).'&export=1"><img src="../img/admin/asterisk.gif" />'.$this->l('CSV Export').'</a></p> <p><a href="'.htmlentities($_SERVER['REQUEST_URI']).'&export=1"><img src="../img/admin/asterisk.gif" />'.$this->l('CSV Export').'</a></p>
</fieldset><br /> </fieldset><br />
<fieldset class="width3"><legend><img src="../img/admin/comment.gif" /> '.$this->l('Guide').'</legend> <fieldset><legend><img src="../img/admin/comment.gif" /> '.$this->l('Guide').'</legend>
<h2 >'.$this->l('Develop clients\' loyalty').'</h2> <h2 >'.$this->l('Develop clients\' loyalty').'</h2>
<p class="space"> <p class="space">
'.$this->l('Keeping a client is more profitable than gaining a new one. Thus, it is necessary to develop their loyalty, in other words to make them want to come back to your webshop.').' <br /> '.$this->l('Keeping a client is more profitable than gaining a new one. Thus, it is necessary to develop their loyalty, in other words to make them want to come back to your webshop.').' <br />
'.$this->l('Word of mouth is also a means to of getting new, satisfied clients; a dissatisfied one won\'t attract new clients.').'<br /> '.$this->l('Word of mouth is also a means to of getting new, satisfied clients; a dissatisfied one won\'t attract new clients.').'<br />
'.$this->l('In order to achieve this goal you can organize: ').' '.$this->l('In order to achieve this goal you can organize: ').'
<ul> <ul>
<li>'.$this->l('Punctual operations: commercial rewards (personalized special offers, product or service offered), non commercial rewards (priority handling of an order or a product), pecuniary rewards (bonds, discount coupons, payback).').'</li> <li>'.$this->l('Punctual operations: commercial rewards (personalized special offers, product or service offered),
<li>'.$this->l('Sustainable operations: loyalty points or cards, which not only justify communication between merchant and client, but also offer advantages to clients (private offers, discounts).').'</li> non commercial rewards (priority handling of an order or a product), pecuniary rewards (bonds, discount coupons, payback).').'</li>
<li>'.$this->l('Sustainable operations: loyalty points or cards, which not only justify communication between merchant and client,
but also offer advantages to clients (private offers, discounts).').'</li>
</ul> </ul>
'.$this->l('These operations encourage clients to buy products and visit your webshop regularly.').' <br /> '.$this->l('These operations encourage clients to buy products and visit your webshop regularly.').' <br />
</p><br /> </p><br />
@@ -151,10 +153,10 @@ class StatsBestCustomers extends ModuleGrid
if (Validate::IsName($this->_sort)) if (Validate::IsName($this->_sort))
{ {
$this->_query .= ' ORDER BY `'.$this->_sort.'`'; $this->_query .= ' ORDER BY `'.$this->_sort.'`';
if (isset($this->_direction) AND Validate::IsSortDirection($this->_direction)) if (isset($this->_direction) && Validate::IsSortDirection($this->_direction))
$this->_query .= ' '.$this->_direction; $this->_query .= ' '.$this->_direction;
} }
if (($this->_start === 0 OR Validate::IsUnsignedInt($this->_start)) AND Validate::IsUnsignedInt($this->_limit)) if (($this->_start === 0 || Validate::IsUnsignedInt($this->_start)) && Validate::IsUnsignedInt($this->_limit))
$this->_query .= ' LIMIT '.$this->_start.', '.($this->_limit); $this->_query .= ' LIMIT '.$this->_start.', '.($this->_limit);
$this->_values = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($this->_query); $this->_values = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($this->_query);
$this->_totalCount = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('SELECT FOUND_ROWS()'); $this->_totalCount = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('SELECT FOUND_ROWS()');
@@ -31,14 +31,14 @@ if (!defined('_PS_VERSION_'))
class StatsBestManufacturers extends ModuleGrid class StatsBestManufacturers extends ModuleGrid
{ {
private $_html = null; private $_html = null;
private $_query = null; private $_query = null;
private $_columns = null; private $_columns = null;
private $_defaultSortColumn = null; private $_defaultSortColumn = null;
private $_defaultSortDirection = null; private $_defaultSortDirection = null;
private $_emptyMessage = null; private $_emptyMessage = null;
private $_pagingMessage = null; private $_pagingMessage = null;
function __construct() public function __construct()
{ {
$this->name = 'statsbestmanufacturers'; $this->name = 'statsbestmanufacturers';
$this->tab = 'analytics_stats'; $this->tab = 'analytics_stats';
@@ -83,7 +83,7 @@ class StatsBestManufacturers extends ModuleGrid
public function install() public function install()
{ {
return (parent::install() AND $this->registerHook('AdminStatsModules')); return (parent::install() && $this->registerHook('AdminStatsModules'));
} }
public function hookAdminStatsModules($params) public function hookAdminStatsModules($params)
@@ -102,7 +102,7 @@ class StatsBestManufacturers extends ModuleGrid
$this->csvExport($engineParams); $this->csvExport($engineParams);
$this->_html = ' $this->_html = '
<fieldset class="width3"><legend><img src="../modules/'.$this->name.'/logo.gif" /> '.$this->displayName.'</legend> <fieldset><legend><img src="../modules/'.$this->name.'/logo.gif" /> '.$this->displayName.'</legend>
'.$this->engine($engineParams).' '.$this->engine($engineParams).'
<br /><a href="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'&export=1"><img src="../img/admin/asterisk.gif" />'.$this->l('CSV Export').'</a> <br /><a href="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'&export=1"><img src="../img/admin/asterisk.gif" />'.$this->l('CSV Export').'</a>
</fieldset>'; </fieldset>';
@@ -141,10 +141,10 @@ class StatsBestManufacturers extends ModuleGrid
if (Validate::IsName($this->_sort)) if (Validate::IsName($this->_sort))
{ {
$this->_query .= ' ORDER BY `'.$this->_sort.'`'; $this->_query .= ' ORDER BY `'.$this->_sort.'`';
if (isset($this->_direction) AND Validate::IsSortDirection($this->_direction)) if (isset($this->_direction) && Validate::IsSortDirection($this->_direction))
$this->_query .= ' '.$this->_direction; $this->_query .= ' '.$this->_direction;
} }
if (($this->_start === 0 OR Validate::IsUnsignedInt($this->_start)) AND Validate::IsUnsignedInt($this->_limit)) if (($this->_start === 0 || Validate::IsUnsignedInt($this->_start)) && Validate::IsUnsignedInt($this->_limit))
$this->_query .= ' LIMIT '.$this->_start.', '.($this->_limit); $this->_query .= ' LIMIT '.$this->_start.', '.($this->_limit);
$this->_values = Db::getInstance()->executeS($this->_query); $this->_values = Db::getInstance()->executeS($this->_query);
} }
@@ -38,7 +38,7 @@ class StatsBestProducts extends ModuleGrid
private $_emptyMessage = null; private $_emptyMessage = null;
private $_pagingMessage = null; private $_pagingMessage = null;
function __construct() public function __construct()
{ {
$this->name = 'statsbestproducts'; $this->name = 'statsbestproducts';
$this->tab = 'analytics_stats'; $this->tab = 'analytics_stats';
@@ -118,7 +118,7 @@ class StatsBestProducts extends ModuleGrid
public function install() public function install()
{ {
return (parent::install() AND $this->registerHook('AdminStatsModules')); return (parent::install() && $this->registerHook('AdminStatsModules'));
} }
public function hookAdminStatsModules($params) public function hookAdminStatsModules($params)
@@ -137,7 +137,7 @@ class StatsBestProducts extends ModuleGrid
$this->csvExport($engineParams); $this->csvExport($engineParams);
$this->_html = ' $this->_html = '
<fieldset class="width3"><legend><img src="../modules/'.$this->name.'/logo.gif" /> '.$this->displayName.'</legend> <fieldset><legend><img src="../modules/'.$this->name.'/logo.gif" /> '.$this->displayName.'</legend>
'.$this->engine($engineParams).' '.$this->engine($engineParams).'
<p><a href="'.htmlentities($_SERVER['REQUEST_URI']).'&export=1"><img src="../img/admin/asterisk.gif" />'.$this->l('CSV Export').'</a></p> <p><a href="'.htmlentities($_SERVER['REQUEST_URI']).'&export=1"><img src="../img/admin/asterisk.gif" />'.$this->l('CSV Export').'</a></p>
</fieldset>'; </fieldset>';
@@ -176,11 +176,11 @@ class StatsBestProducts extends ModuleGrid
if (Validate::IsName($this->_sort)) if (Validate::IsName($this->_sort))
{ {
$this->_query .= ' ORDER BY `'.$this->_sort.'`'; $this->_query .= ' ORDER BY `'.$this->_sort.'`';
if (isset($this->_direction) AND Validate::IsSortDirection($this->_direction)) if (isset($this->_direction) && Validate::IsSortDirection($this->_direction))
$this->_query .= ' '.$this->_direction; $this->_query .= ' '.$this->_direction;
} }
if (($this->_start === 0 OR Validate::IsUnsignedInt($this->_start)) AND Validate::IsUnsignedInt($this->_limit)) if (($this->_start === 0 || Validate::IsUnsignedInt($this->_start)) && Validate::IsUnsignedInt($this->_limit))
$this->_query .= ' LIMIT '.$this->_start.', '.($this->_limit); $this->_query .= ' LIMIT '.$this->_start.', '.($this->_limit);
$this->_values = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($this->_query); $this->_values = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($this->_query);
$this->_totalCount = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('SELECT FOUND_ROWS()'); $this->_totalCount = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('SELECT FOUND_ROWS()');
@@ -31,14 +31,14 @@ if (!defined('_PS_VERSION_'))
class StatsBestSuppliers extends ModuleGrid class StatsBestSuppliers extends ModuleGrid
{ {
private $_html = null; private $_html = null;
private $_query = null; private $_query = null;
private $_columns = null; private $_columns = null;
private $_defaultSortColumn = null; private $_defaultSortColumn = null;
private $_defaultSortDirection = null; private $_defaultSortDirection = null;
private $_emptyMessage = null; private $_emptyMessage = null;
private $_pagingMessage = null; private $_pagingMessage = null;
function __construct() public function __construct()
{ {
$this->name = 'statsbestsuppliers'; $this->name = 'statsbestsuppliers';
$this->tab = 'analytics_stats'; $this->tab = 'analytics_stats';
@@ -83,7 +83,7 @@ class StatsBestSuppliers extends ModuleGrid
public function install() public function install()
{ {
return (parent::install() AND $this->registerHook('AdminStatsModules')); return (parent::install() && $this->registerHook('AdminStatsModules'));
} }
public function hookAdminStatsModules($params) public function hookAdminStatsModules($params)
@@ -101,7 +101,7 @@ class StatsBestSuppliers extends ModuleGrid
if (Tools::getValue('export') == 1) if (Tools::getValue('export') == 1)
$this->csvExport($engineParams); $this->csvExport($engineParams);
$this->_html = ' $this->_html = '
<fieldset class="width3"><legend><img src="../modules/'.$this->name.'/logo.gif" /> '.$this->displayName.'</legend> <fieldset><legend><img src="../modules/'.$this->name.'/logo.gif" /> '.$this->displayName.'</legend>
'.$this->engine($engineParams).' '.$this->engine($engineParams).'
<p><a href="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'&export=1"><img src="../img/admin/asterisk.gif" />'.$this->l('CSV Export').'</a></p> <p><a href="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'&export=1"><img src="../img/admin/asterisk.gif" />'.$this->l('CSV Export').'</a></p>
</fieldset>'; </fieldset>';
@@ -142,11 +142,11 @@ class StatsBestSuppliers extends ModuleGrid
if (Validate::IsName($this->_sort)) if (Validate::IsName($this->_sort))
{ {
$this->_query .= ' ORDER BY `'.$this->_sort.'`'; $this->_query .= ' ORDER BY `'.$this->_sort.'`';
if (isset($this->_direction) AND Validate::IsSortDirection($this->_direction)) if (isset($this->_direction) && Validate::IsSortDirection($this->_direction))
$this->_query .= ' '.$this->_direction; $this->_query .= ' '.$this->_direction;
} }
if (($this->_start === 0 OR Validate::IsUnsignedInt($this->_start)) AND Validate::IsUnsignedInt($this->_limit)) if (($this->_start === 0 || Validate::IsUnsignedInt($this->_start)) && Validate::IsUnsignedInt($this->_limit))
$this->_query .= ' LIMIT '.$this->_start.', '.($this->_limit); $this->_query .= ' LIMIT '.$this->_start.', '.($this->_limit);
$this->_values = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($this->_query); $this->_values = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($this->_query);
} }
@@ -38,7 +38,7 @@ class StatsBestVouchers extends ModuleGrid
private $_emptyMessage; private $_emptyMessage;
private $_pagingMessage; private $_pagingMessage;
function __construct() public function __construct()
{ {
$this->name = 'statsbestvouchers'; $this->name = 'statsbestvouchers';
$this->tab = 'analytics_stats'; $this->tab = 'analytics_stats';
@@ -83,7 +83,7 @@ class StatsBestVouchers extends ModuleGrid
public function install() public function install()
{ {
return (parent::install() AND $this->registerHook('AdminStatsModules')); return (parent::install() && $this->registerHook('AdminStatsModules'));
} }
public function hookAdminStatsModules($params) public function hookAdminStatsModules($params)
@@ -102,7 +102,7 @@ class StatsBestVouchers extends ModuleGrid
$this->csvExport($engineParams); $this->csvExport($engineParams);
$this->_html = ' $this->_html = '
<fieldset class="width3"><legend><img src="../modules/'.$this->name.'/logo.gif" /> '.$this->displayName.'</legend> <fieldset><legend><img src="../modules/'.$this->name.'/logo.gif" /> '.$this->displayName.'</legend>
'.$this->engine($engineParams).' '.$this->engine($engineParams).'
<br /><a href="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'&export=1"><img src="../img/admin/asterisk.gif" />'.$this->l('CSV Export').'</a> <br /><a href="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'&export=1"><img src="../img/admin/asterisk.gif" />'.$this->l('CSV Export').'</a>
</fieldset>'; </fieldset>';
@@ -124,7 +124,7 @@ class StatsBestVouchers extends ModuleGrid
if (isset($this->_direction)) if (isset($this->_direction))
$this->_query .= ' '.$this->_direction; $this->_query .= ' '.$this->_direction;
} }
if (($this->_start === 0 OR Validate::IsUnsignedInt($this->_start)) AND Validate::IsUnsignedInt($this->_limit)) if (($this->_start === 0 || Validate::IsUnsignedInt($this->_start)) && Validate::IsUnsignedInt($this->_limit))
$this->_query .= ' LIMIT '.$this->_start.', '.($this->_limit); $this->_query .= ' LIMIT '.$this->_start.', '.($this->_limit);
$this->_values = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($this->_query); $this->_values = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($this->_query);
$this->_totalCount = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('SELECT FOUND_ROWS()'); $this->_totalCount = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('SELECT FOUND_ROWS()');
+26 -22
View File
@@ -30,28 +30,28 @@ if (!defined('_PS_VERSION_'))
class StatsCarrier extends ModuleGraph class StatsCarrier extends ModuleGraph
{ {
private $_html = ''; private $_html = '';
private $_query = ''; private $_query = '';
private $_query2 = ''; private $_query2 = '';
private $_option = ''; private $_option = '';
function __construct() public function __construct()
{ {
$this->name = 'statscarrier'; $this->name = 'statscarrier';
$this->tab = 'analytics_stats'; $this->tab = 'analytics_stats';
$this->version = 1.0; $this->version = 1.0;
$this->author = 'PrestaShop'; $this->author = 'PrestaShop';
$this->need_instance = 0; $this->need_instance = 0;
parent::__construct(); parent::__construct();
$this->displayName = $this->l('Carrier distribution'); $this->displayName = $this->l('Carrier distribution');
$this->description = $this->l('Display the carriers distribution'); $this->description = $this->l('Display the carriers distribution');
} }
public function install() public function install()
{ {
return (parent::install() AND $this->registerHook('AdminStatsModules')); return (parent::install() && $this->registerHook('AdminStatsModules'));
} }
public function hookAdminStatsModules($params) public function hookAdminStatsModules($params)
@@ -60,38 +60,42 @@ class StatsCarrier extends ModuleGraph
FROM `'._DB_PREFIX_.'orders` o FROM `'._DB_PREFIX_.'orders` o
WHERE o.`date_add` BETWEEN '.ModuleGraph::getDateBetween().' WHERE o.`date_add` BETWEEN '.ModuleGraph::getDateBetween().'
'.$this->sqlShopRestriction(Shop::SHARE_ORDER, 'o').' '.$this->sqlShopRestriction(Shop::SHARE_ORDER, 'o').'
'.((int)(Tools::getValue('id_order_state')) ? 'AND (SELECT oh.id_order_state FROM `'._DB_PREFIX_.'order_history` oh WHERE o.id_order = oh.id_order ORDER BY oh.date_add DESC, oh.id_order_history DESC LIMIT 1) = '.(int)(Tools::getValue('id_order_state')) : ''); '.((int)Tools::getValue('id_order_state') ? 'AND (SELECT oh.id_order_state FROM `'._DB_PREFIX_.'order_history` oh WHERE o.id_order = oh.id_order ORDER BY oh.date_add DESC, oh.id_order_history DESC LIMIT 1) = '.(int)Tools::getValue('id_order_state') : '');
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql); $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql);
$states = OrderState::getOrderStates($this->context->language->id); $states = OrderState::getOrderStates($this->context->language->id);
if (Tools::getValue('export')) if (Tools::getValue('export'))
$this->csvExport(array('type' => 'pie', 'option' => Tools::getValue('id_order_state'))); $this->csvExport(array('type' => 'pie', 'option' => Tools::getValue('id_order_state')));
$this->_html = ' $this->_html = '
<fieldset class="width3"><legend><img src="../modules/'.$this->name.'/logo.gif" /> '.$this->displayName.'</legend> <fieldset><legend><img src="../modules/'.$this->name.'/logo.gif" /> '.$this->displayName.'</legend>
<form action="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'" method="post" style="float: right;"> <form action="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'" method="post" style="float: right;">
<select name="id_order_state"> <select name="id_order_state">
<option value="0"'.((!Tools::getValue('id_order_state')) ? ' selected="selected"' : '').'>'.$this->l('All').'</option>'; <option value="0"'.((!Tools::getValue('id_order_state')) ? ' selected="selected"' : '').'>'.$this->l('All').'</option>';
foreach ($states AS $state) foreach ($states as $state)
$this->_html .= '<option value="'.$state['id_order_state'].'"'.(($state['id_order_state'] == Tools::getValue('id_order_state')) ? ' selected="selected"' : '').'>'.$state['name'].'</option>'; $this->_html .= '<option value="'.$state['id_order_state'].'"'.(($state['id_order_state'] == Tools::getValue('id_order_state')) ? ' selected="selected"' : '').'>'.$state['name'].'</option>';
$this->_html .= '</select> $this->_html .= '</select>
<input type="submit" name="submitState" value="'.$this->l('Filter').'" class="button" /> <input type="submit" name="submitState" value="'.$this->l('Filter').'" class="button" />
</form> </form>
<p><img src="../img/admin/down.gif" />'.$this->l('This graph represents the carrier distribution for your orders. You can also limit it to orders in one state.').'</p> <p><img src="../img/admin/down.gif" />'.$this->l('This graph represents the carrier distribution for your orders. You can also limit it to orders in one state.').'</p>
'.($result['total'] ? $this->engine(array('type' => 'pie', 'option' => Tools::getValue('id_order_state'))).'<br /><br /> <a href="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'&export=1&exportType=language"><img src="../img/admin/asterisk.gif" />'.$this->l('CSV Export').'</a>' : $this->l('No valid orders for this period.')).' '.($result['total'] ? $this->engine(array('type' => 'pie', 'option' => Tools::getValue('id_order_state'))).'<br /><br /> <a href="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'&export=1&exportType=language"><img src="../img/admin/asterisk.gif" />'.$this->l('CSV Export').'</a>' : $this->l('No valid orders for this period.')).'
</fieldset>'; </fieldset>';
return $this->_html; return $this->_html;
} }
public function setOption($option, $layers = 1) public function setOption($option, $layers = 1)
{ {
$this->_option = (int)($option); $this->_option = (int)$option;
} }
protected function getData($layers) protected function getData($layers)
{ {
$stateQuery = ''; $stateQuery = '';
if ((int)($this->_option)) if ((int)$this->_option)
$stateQuery = 'AND (SELECT oh.id_order_state FROM `'._DB_PREFIX_.'order_history` oh WHERE o.id_order = oh.id_order ORDER BY oh.date_add DESC, oh.id_order_history DESC LIMIT 1) = '.(int)($this->_option); $stateQuery = 'AND (
SELECT oh.id_order_state FROM `'._DB_PREFIX_.'order_history` oh
WHERE o.id_order = oh.id_order
ORDER BY oh.date_add DESC, oh.id_order_history DESC
LIMIT 1) = '.(int)$this->_option;
$this->_titles['main'] = $this->l('Percentage of orders by carrier'); $this->_titles['main'] = $this->l('Percentage of orders by carrier');
$sql = 'SELECT c.name, COUNT(DISTINCT o.`id_order`) as total $sql = 'SELECT c.name, COUNT(DISTINCT o.`id_order`) as total
@@ -104,8 +108,8 @@ class StatsCarrier extends ModuleGraph
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql); $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
foreach ($result as $row) foreach ($result as $row)
{ {
$this->_values[] = $row['total']; $this->_values[] = $row['total'];
$this->_legend[] = $row['name']; $this->_legend[] = $row['name'];
} }
} }
} }
+30 -28
View File
@@ -33,23 +33,23 @@ class StatsCatalog extends Module
private $_join = ''; private $_join = '';
private $_where = ''; private $_where = '';
function __construct() public function __construct()
{ {
$this->name = 'statscatalog'; $this->name = 'statscatalog';
$this->tab = 'analytics_stats'; $this->tab = 'analytics_stats';
$this->version = 1.0; $this->version = 1.0;
$this->author = 'PrestaShop'; $this->author = 'PrestaShop';
$this->need_instance = 0; $this->need_instance = 0;
parent::__construct(); parent::__construct();
$this->displayName = $this->l('Catalog statistics'); $this->displayName = $this->l('Catalog statistics');
$this->description = $this->l('General statistics about your catalog.'); $this->description = $this->l('General statistics about your catalog.');
} }
public function install() public function install()
{ {
return (parent::install() AND $this->registerHook('AdminStatsModules')); return (parent::install() && $this->registerHook('AdminStatsModules'));
} }
public function getQuery1() public function getQuery1()
@@ -119,14 +119,15 @@ class StatsCatalog extends Module
$precalc2 = array(); $precalc2 = array();
foreach ($precalc as $array) foreach ($precalc as $array)
$precalc2[] = (int)($array['id_product']); $precalc2[] = (int)$array['id_product'];
$sql = 'SELECT p.id_product, pl.name, pl.link_rewrite $sql = 'SELECT p.id_product, pl.name, pl.link_rewrite
FROM `'._DB_PREFIX_.'product` p FROM `'._DB_PREFIX_.'product` p
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (pl.`id_product` = p.`id_product` AND pl.id_lang = '.(int)$id_lang.$this->context->shop->addSqlRestrictionOnLang('pl').') LEFT JOIN `'._DB_PREFIX_.'product_lang` pl
ON (pl.`id_product` = p.`id_product` AND pl.id_lang = '.(int)$id_lang.$this->context->shop->addSqlRestrictionOnLang('pl').')
'.$this->_join.' '.$this->_join.'
WHERE p.`active` = 1 WHERE p.`active` = 1
'.(sizeof($precalc2) ? 'AND p.`id_product` NOT IN ('.implode(',', $precalc2).')' : '').' '.(count($precalc2) ? 'AND p.`id_product` NOT IN ('.implode(',', $precalc2).')' : '').'
'.$this->_where; '.$this->_where;
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql); $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
return array('total' => Db::getInstance(_PS_USE_SQL_SLAVE_)->NumRows(), 'result' => $result); return array('total' => Db::getInstance(_PS_USE_SQL_SLAVE_)->NumRows(), 'result' => $result);
@@ -134,7 +135,6 @@ class StatsCatalog extends Module
public function hookAdminStatsModules($params) public function hookAdminStatsModules($params)
{ {
$categories = Category::getCategories($this->context->language->id, true, false); $categories = Category::getCategories($this->context->language->id, true, false);
$productToken = Tools::getAdminToken('AdminCatalog'.(int)(Tab::getIdFromClassName('AdminCatalog')).(int)$this->context->employee->id); $productToken = Tools::getAdminToken('AdminCatalog'.(int)(Tab::getIdFromClassName('AdminCatalog')).(int)$this->context->employee->id);
$irow = 0; $irow = 0;
@@ -169,7 +169,7 @@ class StatsCatalog extends Module
$html = ' $html = '
<script type="text/javascript" language="javascript">$(\'#calendar\').slideToggle();</script> <script type="text/javascript" language="javascript">$(\'#calendar\').slideToggle();</script>
<fieldset class="width3"><legend><img src="../modules/'.$this->name.'/logo.gif" /> '.$this->displayName.'</legend> <fieldset><legend><img src="../modules/'.$this->name.'/logo.gif" /> '.$this->displayName.'</legend>
<label> <label>
'.$this->l('Choose a category').' '.$this->l('Choose a category').'
</label> </label>
@@ -178,23 +178,25 @@ class StatsCatalog extends Module
<select name="id_category" onchange="$(\'#categoriesForm\').submit();"> <select name="id_category" onchange="$(\'#categoriesForm\').submit();">
<option value="0">'.$this->l('All').'</option>'; <option value="0">'.$this->l('All').'</option>';
foreach ($categories as $category) foreach ($categories as $category)
$html .= '<option value="'.$category['id_category'].'"'.($id_category == $category['id_category'] ? ' selected="selected"' : '').'>'.$category['name'].'</option>'; $html .= '<option value="'.$category['id_category'].'"'.($id_category == $category['id_category'] ? ' selected="selected"' : '').'>'.
$category['name'].'
</option>';
$html .= ' $html .= '
</select> </select>
</form> </form>
</div> </div>
<div class="clear space"></div> <div class="clear space"></div>
<table> <table>
'.$this->returnLine($this->l('Products available:'), (int)($total)).' '.$this->returnLine($this->l('Products available:'), (int)$total).'
'.$this->returnLine($this->l('Average price (base price):'), Tools::displayPrice($averagePrice, $this->context->currency)).' '.$this->returnLine($this->l('Average price (base price):'), Tools::displayPrice($averagePrice, $this->context->currency)).'
'.$this->returnLine($this->l('Product pages viewed:'), (int)($totalPageViewed)).' '.$this->returnLine($this->l('Product pages viewed:'), (int)$totalPageViewed).'
'.$this->returnLine($this->l('Products bought:'), (int)($totalBought)).' '.$this->returnLine($this->l('Products bought:'), (int)$totalBought).'
'.$this->returnLine($this->l('Average number of page visits:'), number_format((float)($averageViewed), 2, '.', '')).' '.$this->returnLine($this->l('Average number of page visits:'), number_format((float)$averageViewed, 2, '.', '')).'
'.$this->returnLine($this->l('Average number of purchases:'), number_format((float)($averagePurchase), 2, '.', '')).' '.$this->returnLine($this->l('Average number of purchases:'), number_format((float)$averagePurchase, 2, '.', '')).'
'.$this->returnLine($this->l('Images available:'), (int)($totalPictures)).' '.$this->returnLine($this->l('Images available:'), (int)$totalPictures).'
'.$this->returnLine($this->l('Average number of images:'), number_format((float)($averagePictures), 2, '.', '')).' '.$this->returnLine($this->l('Average number of images:'), number_format((float)$averagePictures, 2, '.', '')).'
'.$this->returnLine($this->l('Products never viewed:'), (int)($totalNV).' / '.(int)($total)).' '.$this->returnLine($this->l('Products never viewed:'), (int)$totalNV.' / '.(int)$total).'
'.$this->returnLine('<a style="cursor : pointer" onclick="$(\'#pnb\').slideToggle();">'.$this->l('Products never purchased:').'</a>', (int)($totalNB).' / '.(int)($total)).' '.$this->returnLine('<a style="cursor : pointer" onclick="$(\'#pnb\').slideToggle();">'.$this->l('Products never purchased:').'</a>', (int)$totalNB.' / '.(int)$total).'
'.$this->returnLine($this->l('Conversion rate*:'), $conversion).' '.$this->returnLine($this->l('Conversion rate*:'), $conversion).'
</table> </table>
<div style="margin-top: 20px;"> <div style="margin-top: 20px;">
@@ -203,10 +205,10 @@ class StatsCatalog extends Module
</div> </div>
</fieldset>'; </fieldset>';
if (sizeof($productsNB) AND sizeof($productsNB) < 50) if (count($productsNB) && count($productsNB) < 50)
{ {
$html .= ' $html .= '<br />
<fieldset class="width3 space"><legend><img src="../modules/'.$this->name.'/basket_delete.png" /> '.$this->l('Products never purchased').'</legend> <fieldset><legend><img src="../modules/'.$this->name.'/basket_delete.png" /> '.$this->l('Products never purchased').'</legend>
<table cellpadding="0" cellspacing="0" class="table"> <table cellpadding="0" cellspacing="0" class="table">
<tr><th>'.$this->l('ID').'</th><th>'.$this->l('Name').'</th><th>'.$this->l('Edit / View').'</th></tr>'; <tr><th>'.$this->l('ID').'</th><th>'.$this->l('Name').'</th><th>'.$this->l('Edit / View').'</th></tr>';
foreach ($productsNB as $product) foreach ($productsNB as $product)
+83 -49
View File
@@ -30,33 +30,55 @@ if (!defined('_PS_VERSION_'))
class StatsCheckUp extends Module class StatsCheckUp extends Module
{ {
function __construct() private $html = '';
{
$this->name = 'statscheckup'; public function __construct()
$this->tab = 'analytics_stats'; {
$this->version = 1.0; $this->name = 'statscheckup';
$this->tab = 'analytics_stats';
$this->version = 1.0;
$this->author = 'PrestaShop'; $this->author = 'PrestaShop';
$this->need_instance = 0; $this->need_instance = 0;
parent::__construct(); parent::__construct();
$this->displayName = $this->l('Catalog evaluation'); $this->displayName = $this->l('Catalog evaluation');
$this->description = $this->l('Quick evaluation of your catalog quality.'); $this->description = $this->l('Quick evaluation of your catalog quality.');
} }
public function install() public function install()
{ {
foreach (array('CHECKUP_DESCRIPTIONS_LT'=>100,'CHECKUP_DESCRIPTIONS_GT'=>400,'CHECKUP_IMAGES_LT'=>1,'CHECKUP_IMAGES_GT'=>2,'CHECKUP_SALES_LT'=>1,'CHECKUP_SALES_GT'=>2,'CHECKUP_STOCK_LT'=>1,'CHECKUP_STOCK_GT'=>3) as $confname => $confdefault) $confs = array(
'CHECKUP_DESCRIPTIONS_LT'=>100,
'CHECKUP_DESCRIPTIONS_GT'=>400,
'CHECKUP_IMAGES_LT'=>1,
'CHECKUP_IMAGES_GT'=>2,
'CHECKUP_SALES_LT'=>1,
'CHECKUP_SALES_GT'=>2,
'CHECKUP_STOCK_LT'=>1,
'CHECKUP_STOCK_GT'=>3
);
foreach ($confs as $confname => $confdefault)
if (!Configuration::get($confname)) if (!Configuration::get($confname))
Configuration::updateValue($confname, (int)$confdefault); Configuration::updateValue($confname, (int)$confdefault);
return (parent::install() && $this->registerHook('AdminStatsModules')); return (parent::install() && $this->registerHook('AdminStatsModules'));
} }
function hookAdminStatsModules() public function hookAdminStatsModules()
{ {
if (Tools::isSubmit('submitCheckup')) if (Tools::isSubmit('submitCheckup'))
{ {
foreach (array('CHECKUP_DESCRIPTIONS_LT','CHECKUP_DESCRIPTIONS_GT','CHECKUP_IMAGES_LT','CHECKUP_IMAGES_GT','CHECKUP_SALES_LT','CHECKUP_SALES_GT','CHECKUP_STOCK_LT','CHECKUP_STOCK_GT') as $confname) $confs = array(
'CHECKUP_DESCRIPTIONS_LT',
'CHECKUP_DESCRIPTIONS_GT',
'CHECKUP_IMAGES_LT',
'CHECKUP_IMAGES_GT',
'CHECKUP_SALES_LT',
'CHECKUP_SALES_GT',
'CHECKUP_STOCK_LT',
'CHECKUP_STOCK_GT'
);
foreach ($confs as $confname)
Configuration::updateValue($confname, (int)Tools::getValue($confname)); Configuration::updateValue($confname, (int)Tools::getValue($confname));
echo '<div class="conf confirm"><img src="../img/admin/ok.gif"> '.$this->l('Configuration updated').'</div>'; echo '<div class="conf confirm"><img src="../img/admin/ok.gif"> '.$this->l('Configuration updated').'</div>';
} }
@@ -100,7 +122,7 @@ class StatsCheckUp extends Module
$orderBy = 'p.id_product'; $orderBy = 'p.id_product';
if ($this->context->cookie->checkup_order == 2) if ($this->context->cookie->checkup_order == 2)
$orderBy = 'pl.name'; $orderBy = 'pl.name';
elseif ($this->context->cookie->checkup_order == 3) else if ($this->context->cookie->checkup_order == 3)
$orderBy = 'nbSales DESC'; $orderBy = 'nbSales DESC';
// Get products stats // Get products stats
@@ -122,7 +144,8 @@ class StatsCheckUp extends Module
WHERE pa.id_product = p.id_product WHERE pa.id_product = p.id_product
), p.quantity) as stock ), p.quantity) as stock
FROM '._DB_PREFIX_.'product p FROM '._DB_PREFIX_.'product p
LEFT JOIN '._DB_PREFIX_.'product_lang pl ON (p.id_product = pl.id_product AND pl.id_lang = '.(int)$this->context->language->id.$this->context->shop->addSqlRestrictionOnLang('pl').') LEFT JOIN '._DB_PREFIX_.'product_lang pl
ON (p.id_product = pl.id_product AND pl.id_lang = '.(int)$this->context->language->id.$this->context->shop->addSqlRestrictionOnLang('pl').')
'.$this->context->shop->addSqlAssociation('product', 'p').' '.$this->context->shop->addSqlAssociation('product', 'p').'
ORDER BY '.$orderBy; ORDER BY '.$orderBy;
$result = $db->executeS($sql); $result = $db->executeS($sql);
@@ -137,29 +160,38 @@ class StatsCheckUp extends Module
'STOCK' => array('name' => $this->l('Stock'), 'text' => $this->l('items')) 'STOCK' => array('name' => $this->l('Stock'), 'text' => $this->l('items'))
); );
$html = ' $this->html = '
<style type="text/css"> <style type="text/css">
form.checkup input[type=text] {width:30px} form.checkup input[type=text] {width:30px}
table.checkup {float:left} form.checkup div {margin-top:20px}
form.checkup div {float:left;margin-left:20px}
table.checkup th {text-align:center} table.checkup th {text-align:center}
table.checkup td {padding:5px 10px} table.checkup td {padding:5px 10px}
table.checkup2 td {text-align:right} table.checkup2 td {text-align:right}
</style> </style>
<form action="'.AdminTab::$currentIndex.'&token='.Tools::safeOutput(Tools::getValue('token')).'&module='.$this->name.'" method="post" class="checkup"> <form action="'.AdminController::$currentIndex.'&token='.Tools::safeOutput(Tools::getValue('token')).'&module='.$this->name.'" method="post" class="checkup">
<table class="table checkup" border="0" cellspacing="0" cellspacing="0"> <table class="table checkup" border="0" cellspacing="0" cellspacing="0">
<tr><th></th><th>'.$arrayColors[0].' '.$this->l('Not enough').'</th><th>'.$arrayColors[2].' '.$this->l('Alright').'</th></tr>'; <tr>
foreach ($arrayConf as $conf => $translations) <th></th>
$html .= '<tr> <th>'.$arrayColors[0].' '.$this->l('Not enough').'</th>
<th>'.$translations['name'].'</th> <th>'.$arrayColors[2].' '.$this->l('Alright').'</th>
<td>'.$this->l('lower than').' <input type="text" name="CHECKUP_'.$conf.'_LT" value="'.Tools::safeOutput(Tools::getValue('CHECKUP_'.$conf.'_LT', Configuration::get('CHECKUP_'.$conf.'_LT'))).'" /> '.$translations['text'].' </tr>';
<td>'.$this->l('greater than').' <input type="text" name="CHECKUP_'.$conf.'_GT" value="'.Tools::safeOutput(Tools::getValue('CHECKUP_'.$conf.'_GT', Configuration::get('CHECKUP_'.$conf.'_GT'))).'" /> '.$translations['text'].' foreach ($arrayConf as $conf => $translations)
</tr>'; $this->html .= '<tr>
$html .= '</table> <th>'.$translations['name'].'</th>
<td>'.$this->l('lower than').'
<input type="text" name="CHECKUP_'.$conf.'_LT"
value="'.Tools::safeOutput(Tools::getValue('CHECKUP_'.$conf.'_LT', Configuration::get('CHECKUP_'.$conf.'_LT'))).'" /> '.$translations['text'].'
</td>
<td>'.$this->l('greater than').'
<input type="text" name="CHECKUP_'.$conf.'_GT"
value="'.Tools::safeOutput(Tools::getValue('CHECKUP_'.$conf.'_GT', Configuration::get('CHECKUP_'.$conf.'_GT'))).'" /> '.$translations['text'].'
</td>
</tr>';
$this->html .= '</table>
<div><input type="submit" name="submitCheckup" class="button" value="'.$this->l(' Save ').'" /></div> <div><input type="submit" name="submitCheckup" class="button" value="'.$this->l(' Save ').'" /></div>
</form> </form>
<div class="clear">&nbsp;</div> <br />
<form action="'.AdminTab::$currentIndex.'&token='.Tools::safeOutput(Tools::getValue('token')).'&module='.$this->name.'" method="post"> <form action="'.AdminController::$currentIndex.'&token='.Tools::safeOutput(Tools::getValue('token')).'&module='.$this->name.'" method="post">
'.$this->l('Order by').' '.$this->l('Order by').'
<select name="submitCheckupOrder" onchange="this.form.submit();" style="width:100px"> <select name="submitCheckupOrder" onchange="this.form.submit();" style="width:100px">
<option value="1">'.$this->l('ID').'</option> <option value="1">'.$this->l('ID').'</option>
@@ -167,15 +199,15 @@ class StatsCheckUp extends Module
<option value="3" '.($this->context->cookie->checkup_order == 3 ? 'selected="selected"' : '').'>'.$this->l('Sales').'</option> <option value="3" '.($this->context->cookie->checkup_order == 3 ? 'selected="selected"' : '').'>'.$this->l('Sales').'</option>
</select> </select>
</form> </form>
<div class="clear">&nbsp;</div> <br />
<table class="table checkup2" border="0" cellspacing="0" cellspacing="0"> <table class="table checkup2" border="0" cellspacing="0" cellspacing="0">
<tr> <tr>
<th>'.$this->l('ID').'</th> <th>'.$this->l('ID').'</th>
<th>'.$this->l('Item').'</th> <th>'.$this->l('Item').'</th>
<th>'.$this->l('Active').'</th>'; <th>'.$this->l('Active').'</th>';
foreach ($languages as $language) foreach ($languages as $language)
$html .= '<th>'.$this->l('Desc.').' ('.strtoupper($language['iso_code']).')</th>'; $this->html .= '<th>'.$this->l('Desc.').' ('.strtoupper($language['iso_code']).')</th>';
$html .= ' $this->html .= '
<th>'.$this->l('Images').'</th> <th>'.$this->l('Images').'</th>
<th>'.$this->l('Sales').'</th> <th>'.$this->l('Sales').'</th>
<th>'.$this->l('Stock').'</th> <th>'.$this->l('Stock').'</th>
@@ -194,7 +226,12 @@ class StatsCheckUp extends Module
$totals['images'] += (int)$scores['images']; $totals['images'] += (int)$scores['images'];
$totals['sales'] += (int)$scores['sales']; $totals['sales'] += (int)$scores['sales'];
$totals['stock'] += (int)$scores['stock']; $totals['stock'] += (int)$scores['stock'];
$descriptions = $db->executeS('SELECT l.iso_code, pl.description FROM '._DB_PREFIX_.'product_lang pl LEFT JOIN '._DB_PREFIX_.'lang l ON pl.id_lang = l.id_lang WHERE id_product = '.(int)$row['id_product'].$this->context->shop->addSqlRestrictionOnLang('pl')); $descriptions = $db->executeS('
SELECT l.iso_code, pl.description
FROM '._DB_PREFIX_.'product_lang pl
LEFT JOIN '._DB_PREFIX_.'lang l
ON pl.id_lang = l.id_lang
WHERE id_product = '.(int)$row['id_product'].$this->context->shop->addSqlRestrictionOnLang('pl'));
foreach ($descriptions as $description) foreach ($descriptions as $description)
{ {
$row['desclength_'.$description['iso_code']] = Tools::strlen(strip_tags($description['description'])); $row['desclength_'.$description['iso_code']] = Tools::strlen(strip_tags($description['description']));
@@ -204,16 +241,16 @@ class StatsCheckUp extends Module
$scores['average'] = array_sum($scores) / $divisor; $scores['average'] = array_sum($scores) / $divisor;
$scores['average'] = ($scores['average'] < 1 ? 0 : ($scores['average'] > 1.5 ? 2 : 1)); $scores['average'] = ($scores['average'] < 1 ? 0 : ($scores['average'] > 1.5 ? 2 : 1));
$html .= '<tr> $this->html .= '<tr>
<td>'.$row['id_product'].'</td> <td>'.$row['id_product'].'</td>
<td style="text-align:left"><a href="index.php?tab=AdminCatalog&updateproduct&id_product='.$row['id_product'].'&token='.$tokenProducts.'">'.Tools::substr($row['name'], 0, 42).'</a></td> <td style="text-align:left"><a href="index.php?tab=AdminCatalog&updateproduct&id_product='.$row['id_product'].'&token='.$tokenProducts.'">'.Tools::substr($row['name'], 0, 42).'</a></td>
<td>'.$arrayColors[$scores['active']].'</td>'; <td>'.$arrayColors[$scores['active']].'</td>';
foreach ($languages as $language) foreach ($languages as $language)
if (isset($row['desclength_'.$language['iso_code']])) if (isset($row['desclength_'.$language['iso_code']]))
$html .= '<td>'.(int)$row['desclength_'.$language['iso_code']].' '.$arrayColors[$scores['description_'.$language['iso_code']]].'</td>'; $this->html .= '<td>'.(int)$row['desclength_'.$language['iso_code']].' '.$arrayColors[$scores['description_'.$language['iso_code']]].'</td>';
else else
$html .= '<td>0 '.$arrayColors[0].'</td>'; $this->html .= '<td>0 '.$arrayColors[0].'</td>';
$html .= ' $this->html .= '
<td>'.(int)$row['nbImages'].' '.$arrayColors[$scores['images']].'</td> <td>'.(int)$row['nbImages'].' '.$arrayColors[$scores['images']].'</td>
<td>'.(int)$row['nbSales'].' '.$arrayColors[$scores['sales']].'</td> <td>'.(int)$row['nbSales'].' '.$arrayColors[$scores['sales']].'</td>
<td>'.(int)$row['stock'].' '.$arrayColors[$scores['stock']].'</td> <td>'.(int)$row['stock'].' '.$arrayColors[$scores['stock']].'</td>
@@ -237,13 +274,13 @@ class StatsCheckUp extends Module
$totals['average'] = array_sum($totals) / $divisor; $totals['average'] = array_sum($totals) / $divisor;
$totals['average'] = ($totals['average'] < 1 ? 0 : ($totals['average'] > 1.5 ? 2 : 1)); $totals['average'] = ($totals['average'] < 1 ? 0 : ($totals['average'] > 1.5 ? 2 : 1));
$html .= ' $this->html .= '
<tr> <tr>
<th colspan="2"></th> <th colspan="2"></th>
<th>'.$this->l('Active').'</th>'; <th>'.$this->l('Active').'</th>';
foreach ($languages as $language) foreach ($languages as $language)
$html .= '<th>'.$this->l('Desc.').' ('.strtoupper($language['iso_code']).')</th>'; $this->html .= '<th>'.$this->l('Desc.').' ('.strtoupper($language['iso_code']).')</th>';
$html .= ' $this->html .= '
<th>'.$this->l('Images').'</th> <th>'.$this->l('Images').'</th>
<th>'.$this->l('Sales').'</th> <th>'.$this->l('Sales').'</th>
<th>'.$this->l('Stock').'</th> <th>'.$this->l('Stock').'</th>
@@ -253,19 +290,16 @@ class StatsCheckUp extends Module
<td colspan="2"></td> <td colspan="2"></td>
<td>'.$arrayColors[$totals['active']].'</td>'; <td>'.$arrayColors[$totals['active']].'</td>';
foreach ($languages as $language) foreach ($languages as $language)
$html .= '<td>'.$arrayColors[$totals['description_'.$language['iso_code']]].'</td>'; $this->html .= '<td>'.$arrayColors[$totals['description_'.$language['iso_code']]].'</td>';
$html .= ' $this->html .= '
<td>'.$arrayColors[$totals['images']].'</td> <td>'.$arrayColors[$totals['images']].'</td>
<td>'.$arrayColors[$totals['sales']].'</td> <td>'.$arrayColors[$totals['sales']].'</td>
<td>'.$arrayColors[$totals['stock']].'</td> <td>'.$arrayColors[$totals['stock']].'</td>
<td>'.$arrayColors[$totals['average']].'</td> <td>'.$arrayColors[$totals['average']].'</td>
</tr> </tr>
</table> </table>
<div class="clear">&nbsp;</div> <div class="clear">&nbsp;</div>';
<script type="text/javascript">
$(document).ready(function(){$("#container").css("width", "1200px");});
</script>';
return $html; return $this->html;
} }
} }
+56 -39
View File
@@ -30,27 +30,27 @@ if (!defined('_PS_VERSION_'))
class StatsEquipment extends ModuleGraph class StatsEquipment extends ModuleGraph
{ {
private $_html = ''; private $html = '';
private $_query = ''; private $_query = '';
private $_query2 = ''; private $_query2 = '';
function __construct() public function __construct()
{ {
$this->name = 'statsequipment'; $this->name = 'statsequipment';
$this->tab = 'analytics_stats'; $this->tab = 'analytics_stats';
$this->version = 1.0; $this->version = 1.0;
$this->author = 'PrestaShop'; $this->author = 'PrestaShop';
$this->need_instance = 0; $this->need_instance = 0;
parent::__construct(); parent::__construct();
$this->displayName = $this->l('Software'); $this->displayName = $this->l('Software');
$this->description = $this->l('Display the software used by your visitors.'); $this->description = $this->l('Display the software used by your visitors.');
} }
public function install() public function install()
{ {
return (parent::install() AND $this->registerHook('AdminStatsModules')); return (parent::install() && $this->registerHook('AdminStatsModules'));
} }
/** /**
@@ -65,7 +65,22 @@ class StatsEquipment extends ModuleGraph
'.$this->sqlShopRestriction(false, 'c'); '.$this->sqlShopRestriction(false, 'c');
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql, false); $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql, false);
$calcArray = array('jsOK' => 0, 'jsKO' => 0, 'javaOK' => 0, 'javaKO' => 0, 'wmpOK' => 0, 'wmpKO' => 0, 'qtOK' => 0, 'qtKO' => 0, 'realOK' => 0, 'realKO' => 0, 'flashOK' => 0, 'flashKO' => 0, 'directorOK' => 0, 'directorKO' => 0); $calcArray = array(
'jsOK' => 0,
'jsKO' => 0,
'javaOK' => 0,
'javaKO' => 0,
'wmpOK' => 0,
'wmpKO' => 0,
'qtOK' => 0,
'qtKO' => 0,
'realOK' => 0,
'realKO' => 0,
'flashOK' => 0,
'flashKO' => 0,
'directorOK' => 0,
'directorKO' => 0
);
while ($row = Db::getInstance(_PS_USE_SQL_SLAVE_)->nextRow($result)) while ($row = Db::getInstance(_PS_USE_SQL_SLAVE_)->nextRow($result))
{ {
if (!$row['javascript']) if (!$row['javascript'])
@@ -102,44 +117,46 @@ class StatsEquipment extends ModuleGraph
if (Tools::getValue('export')) if (Tools::getValue('export'))
if (Tools::getValue('exportType') == 'browser') if (Tools::getValue('exportType') == 'browser')
$this->csvExport(array('type' => 'pie', 'option' => 'wb')); $this->csvExport(array('type' => 'pie', 'option' => 'wb'));
elseif (Tools::getValue('exportType') == 'os') else if (Tools::getValue('exportType') == 'os')
$this->csvExport(array('type' => 'pie', 'option' => 'os')); $this->csvExport(array('type' => 'pie', 'option' => 'os'));
$equipment = $this->getEquipment(); $equipment = $this->getEquipment();
$this->_html = ' $this->html = '
<fieldset class="width3"><legend><img src="../modules/'.$this->name.'/logo.gif" /> '.$this->displayName.'</legend> <fieldset><legend><img src="../modules/'.$this->name.'/logo.gif" /> '.$this->displayName.'</legend>
<center> <p><img src="../img/admin/down.gif" />'.$this->l('Determine the percentage of web browsers used by your customers.').'</p>
<p><img src="../img/admin/down.gif" />'.$this->l('Determine the percentage of web browsers used by your customers.').'</p> '.$this->engine(array('type' => 'pie', 'option' => 'wb')).'<br /><br />
'.$this->engine(array('type' => 'pie', 'option' => 'wb')).'<br /><br /> <p><a href="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'&export=1&exportType=browser"><img src="../img/admin/asterisk.gif" />'.$this->l('CSV Export').'</a></p>
<p><a href="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'&export=1&exportType=browser"><img src="../img/admin/asterisk.gif" />'.$this->l('CSV Export').'</a></p> <p><img src="../img/admin/down.gif" />'.$this->l('Determine the percentage of operating systems used by your customers.').'</p>
<p><img src="../img/admin/down.gif" />'.$this->l('Determine the percentage of operating systems used by your customers.').'</p> '.$this->engine(array('type' => 'pie', 'option' => 'os')).'
'.$this->engine(array('type' => 'pie', 'option' => 'os')).' <p><a href="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'&export=1&exportType=os"><img src="../img/admin/asterisk.gif" />'.$this->l('CSV Export').'</a></p>';
<p><a href="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'&export=1&exportType=os"><img src="../img/admin/asterisk.gif" />'.$this->l('CSV Export').'</a></p>';
if ($equipment) if ($equipment)
{ {
$this->_html .= '<table class="table space" border="0" cellspacing="0" cellpadding="0"> $this->html .= '<table class="table space" border="0" cellspacing="0" cellpadding="0">
<tr><th style="width: 200px">'.$this->l('Plug-ins').'</th><th></th></tr>'; <tr><th style="width: 200px">'.$this->l('Plug-ins').'</th><th></th></tr>';
foreach ($equipment as $name => $value) foreach ($equipment as $name => $value)
$this->_html .= '<tr><td>'.$name.'</td><td>'.number_format(100 * $value, 2).'%</td></tr>'; $this->html .= '<tr><td>'.$name.'</td><td>'.number_format(100 * $value, 2).'%</td></tr>';
$this->_html .= '</table>'; $this->html .= '</table>';
} }
$this->_html .= ' $this->html .= '
</center> </fieldset>
</fieldset><br /> <br />
<fieldset class="width3"><legend><img src="../img/admin/comment.gif" /> '.$this->l('Guide').'</legend> <fieldset><legend><img src="../img/admin/comment.gif" /> '.$this->l('Guide').'</legend>
<h2>'.$this->l('Ensure that your website is accessible to all.').'</h2> <h2>'.$this->l('Ensure that your website is accessible to all.').'</h2>
<p> <p>
'.$this->l('When managing Websites, it is important to keep track of software used by visitors in order to be sure that the site displays the same way for everyone. PrestaShop was built in order to be compatible with most recent Web browsers and computer operating systems (OS). However, because you may end up adding advanced features to your Website or even modify the core PrestaShop code, these additions may not be accessible by everyone. That is why it is a good idea to keep tabs on the percentage of users for each type of software before adding or changing something that only a limited number of users will be able to access.').' '.$this->l('When managing Websites, it is important to keep track of software used by visitors in order to be sure that the site displays the same way for everyone.
PrestaShop was built in order to be compatible with most recent Web browsers and computer operating systems (OS).
However, because you may end up adding advanced features to your Website or even modify the core PrestaShop code, these additions may not be accessible by everyone.
That is why it is a good idea to keep tabs on the percentage of users for each type of software before adding or changing something that only a limited number of users will be able to access.').'
</p><br /> </p><br />
</fieldset>'; </fieldset>';
return $this->_html; return $this->html;
} }
public function setOption($option, $layers = 1) public function setOption($option, $layers = 1)
{ {
switch($option) switch ($option)
{ {
case 'wb': case 'wb':
$this->_titles['main'] = $this->l('Web browser use'); $this->_titles['main'] = $this->l('Web browser use');
@@ -174,8 +191,8 @@ class StatsEquipment extends ModuleGraph
$i = 0; $i = 0;
foreach ($result as $row) foreach ($result as $row)
{ {
$this->_values[$i] = $row['total']; $this->_values[$i] = $row['total'];
$this->_legend[$i++] = $row['name']; $this->_legend[$i++] = $row['name'];
} }
} }
} }
+22 -22
View File
@@ -40,19 +40,19 @@ class StatsForecast extends Module
private $t7 = 0; private $t7 = 0;
private $t8 = 0; private $t8 = 0;
public function __construct() public function __construct()
{ {
$this->name = 'statsforecast'; $this->name = 'statsforecast';
$this->tab = 'analytics_stats'; $this->tab = 'analytics_stats';
$this->version = 1.0; $this->version = 1.0;
$this->author = 'PrestaShop'; $this->author = 'PrestaShop';
$this->need_instance = 0; $this->need_instance = 0;
parent::__construct(); parent::__construct();
$this->displayName = $this->l('Stats Dashboard'); $this->displayName = $this->l('Stats Dashboard');
$this->description = ''; $this->description = '';
} }
public function install() public function install()
{ {
@@ -61,7 +61,7 @@ class StatsForecast extends Module
public function getContent() public function getContent()
{ {
Tools::redirectAdmin('index.php?tab=AdminStats&module=statsforecast&token='.Tools::getAdminTokenLite('AdminStats')); Tools::redirectAdmin('index.php?controller=AdminStats&module=statsforecast&token='.Tools::getAdminTokenLite('AdminStats'));
} }
public function hookAdminStatsModules() public function hookAdminStatsModules()
@@ -133,14 +133,14 @@ class StatsForecast extends Module
{ {
$dateEnd = strtotime($employee->stats_date_to.' 23:59:59'); $dateEnd = strtotime($employee->stats_date_to.' 23:59:59');
$dateToday = time(); $dateToday = time();
for ($i = strtotime($employee->stats_date_from.' 00:00:00'); $i <= $dateEnd AND $i <= $dateToday; $i += 86400) for ($i = strtotime($employee->stats_date_from.' 00:00:00'); $i <= $dateEnd && $i <= $dateToday; $i += 86400)
$dataTable[$i] = array('fix_date' => date('Y-m-d', $i), 'countOrders' => 0, 'countProducts' => 0, 'totalProducts' => 0); $dataTable[$i] = array('fix_date' => date('Y-m-d', $i), 'countOrders' => 0, 'countProducts' => 0, 'totalProducts' => 0);
} }
while ($row = $db->nextRow($result)) while ($row = $db->nextRow($result))
$dataTable[strtotime($row['fix_date'])] = $row; $dataTable[strtotime($row['fix_date'])] = $row;
$this->_html .= '<div style="float:left;width:660px"> $this->_html .= '<div>
<fieldset><legend><img src="../modules/'.$this->name.'/logo.gif" /> '.$this->displayName.'</legend> <fieldset><legend><img src="../modules/'.$this->name.'/logo.gif" /> '.$this->displayName.'</legend>
<p style="float:left">'.$this->l('All amounts are without taxes.').'</p> <p style="float:left">'.$this->l('All amounts are without taxes.').'</p>
<form id="granularity" action="'.$ru.'#granularity" method="post" style="float:right"> <form id="granularity" action="'.$ru.'#granularity" method="post" style="float:right">
@@ -176,7 +176,7 @@ class StatsForecast extends Module
while ($row = $db->nextRow($visits)) while ($row = $db->nextRow($visits))
$visitArray[$row['fix_date']] = $row['visits']; $visitArray[$row['fix_date']] = $row['visits'];
$discountArray = array(); /*$discountArray = array();
$sql = 'SELECT '.$dateFromGInvoice.' as fix_date, SUM(od.value) as total $sql = 'SELECT '.$dateFromGInvoice.' as fix_date, SUM(od.value) as total
FROM '._DB_PREFIX_.'orders o FROM '._DB_PREFIX_.'orders o
LEFT JOIN '._DB_PREFIX_.'order_discount od ON o.id_order = od.id_order LEFT JOIN '._DB_PREFIX_.'order_discount od ON o.id_order = od.id_order
@@ -187,12 +187,12 @@ class StatsForecast extends Module
GROUP BY '.$dateFromGInvoice; GROUP BY '.$dateFromGInvoice;
$discounts = Db::getInstance()->executeS($sql, false); $discounts = Db::getInstance()->executeS($sql, false);
while ($row = $db->nextRow($discounts)) while ($row = $db->nextRow($discounts))
$discountArray[$row['fix_date']] = $row['total']; $discountArray[$row['fix_date']] = $row['total'];*/
$today = date('Y-m-d'); $today = date('Y-m-d');
foreach ($dataTable as $row) foreach ($dataTable as $row)
{ {
$discountToday = (isset($discountArray[$row['fix_date']]) ? $discountArray[$row['fix_date']] : 0); $discountToday = 0;//(isset($discountArray[$row['fix_date']]) ? $discountArray[$row['fix_date']] : 0);
$visitsToday = (int)(isset($visitArray[$row['fix_date']]) ? $visitArray[$row['fix_date']] : 0); $visitsToday = (int)(isset($visitArray[$row['fix_date']]) ? $visitArray[$row['fix_date']] : 0);
$dateFromGReg = ($this->context->cookie->stats_granularity != 42 $dateFromGReg = ($this->context->cookie->stats_granularity != 42
@@ -316,7 +316,7 @@ class StatsForecast extends Module
.$this->sqlShopRestriction(Shop::SHARE_ORDER, 'o'); .$this->sqlShopRestriction(Shop::SHARE_ORDER, 'o');
$orders = Db::getInstance()->getValue($sql); $orders = Db::getInstance()->getValue($sql);
$this->_html .= '<div class="clear">&nbsp;</div> $this->_html .= '<br />
<fieldset><legend><img src="../modules/'.$this->name.'/funnel.png" /> '.$this->l('Conversion').'</legend> <fieldset><legend><img src="../modules/'.$this->name.'/funnel.png" /> '.$this->l('Conversion').'</legend>
<span style="float:left;text-align:center;margin-right:10px;padding-top:15px">'.$this->l('Visitors').'<br />'.$visitors.'</span> <span style="float:left;text-align:center;margin-right:10px;padding-top:15px">'.$this->l('Visitors').'<br />'.$visitors.'</span>
<span style="float:left;text-align:center;margin-right:10px"> <span style="float:left;text-align:center;margin-right:10px">
@@ -358,7 +358,7 @@ class StatsForecast extends Module
$prop5000 = 5000 / 30 * $interval; $prop5000 = 5000 / 30 * $interval;
$this->_html .= ' $this->_html .= '
<div class="clear">&nbsp;</div>'; <br />';
$this->_html .= '<fieldset><legend id="payment"><img src="../img/t/AdminPayment.gif" />'.$this->l('Payment distibution').'</legend> $this->_html .= '<fieldset><legend id="payment"><img src="../img/t/AdminPayment.gif" />'.$this->l('Payment distibution').'</legend>
<form id="cat" action="'.$ru.'#payment" method="post" style="float:right"> <form id="cat" action="'.$ru.'#payment" method="post" style="float:right">
<input type="hidden" name="submitIdZone" value="1" /> <input type="hidden" name="submitIdZone" value="1" />
@@ -381,7 +381,7 @@ class StatsForecast extends Module
$this->_html .= ' $this->_html .= '
</table> </table>
</fieldset> </fieldset>
<div class="clear">&nbsp;</div> <br />
<fieldset><legend><img src="../img/t/AdminCatalog.gif" /> '.$this->l('Category distribution').'</legend> <fieldset><legend><img src="../img/t/AdminCatalog.gif" /> '.$this->l('Category distribution').'</legend>
<form id="cat" action="'.$ru.'#cat" method="post" style="float:right"> <form id="cat" action="'.$ru.'#cat" method="post" style="float:right">
<input type="hidden" name="submitIdZone" value="1" /> <input type="hidden" name="submitIdZone" value="1" />
@@ -406,7 +406,7 @@ class StatsForecast extends Module
$this->_html .= ' $this->_html .= '
</table> </table>
</fieldset> </fieldset>
<div class="clear">&nbsp;</div> <br />
<fieldset><legend><img src="../img/t/AdminLanguages.gif" /> '.$this->l('Language distribution').'</legend> <fieldset><legend><img src="../img/t/AdminLanguages.gif" /> '.$this->l('Language distribution').'</legend>
<table class="table" border="0" cellspacing="0" cellspacing="0"> <table class="table" border="0" cellspacing="0" cellspacing="0">
<tr><th>'.$this->l('Customers').'</th><th>'.$this->l('Sales').'</th><th>'.$this->l('%').'</th><th colspan="2">'.$this->l('Growth').'</th></tr>'; <tr><th>'.$this->l('Customers').'</th><th>'.$this->l('Sales').'</th><th>'.$this->l('%').'</th><th colspan="2">'.$this->l('Growth').'</th></tr>';
@@ -425,7 +425,7 @@ class StatsForecast extends Module
$this->_html .= ' $this->_html .= '
</table> </table>
</fieldset> </fieldset>
<div class="clear">&nbsp;</div> <br />
<fieldset><legend><img src="../img/t/AdminLanguages.gif" />'.$this->l('Zone distribution').'</legend> <fieldset><legend><img src="../img/t/AdminLanguages.gif" />'.$this->l('Zone distribution').'</legend>
<table class="table" border="0" cellspacing="0" cellspacing="0"> <table class="table" border="0" cellspacing="0" cellspacing="0">
<tr><th>'.$this->l('Zone').'</th><th>'.$this->l('Count').'</th><th>'.$this->l('Total').'</th><th>'.$this->l('% Count').'</th><th>'.$this->l('% Sales').'</th></tr>'; <tr><th>'.$this->l('Zone').'</th><th>'.$this->l('Count').'</th><th>'.$this->l('Total').'</th><th>'.$this->l('% Count').'</th><th>'.$this->l('% Sales').'</th></tr>';
@@ -441,7 +441,7 @@ class StatsForecast extends Module
$this->_html .= ' $this->_html .= '
</table> </table>
</fieldset> </fieldset>
<div class="clear">&nbsp;</div> <br />
<fieldset><legend id="currencies"><img src="../img/t/AdminCurrencies.gif" />'.$this->l('Currency distribution').'</legend> <fieldset><legend id="currencies"><img src="../img/t/AdminCurrencies.gif" />'.$this->l('Currency distribution').'</legend>
<form id="cat" action="'.$ru.'#currencies" method="post" style="float:right"> <form id="cat" action="'.$ru.'#currencies" method="post" style="float:right">
<input type="hidden" name="submitIdZone" value="1" /> <input type="hidden" name="submitIdZone" value="1" />
@@ -465,7 +465,7 @@ class StatsForecast extends Module
$this->_html .= ' $this->_html .= '
</table> </table>
</fieldset> </fieldset>
<div class="clear">&nbsp;</div> <br />
<fieldset><legend><img src="../img/t/AdminCatalog.gif" />'.$this->l('Attribute distribution').'</legend> <fieldset><legend><img src="../img/t/AdminCatalog.gif" />'.$this->l('Attribute distribution').'</legend>
<table class="table" border="0" cellspacing="0" cellspacing="0"> <table class="table" border="0" cellspacing="0" cellspacing="0">
<tr><th>'.$this->l('Group').'</th><th>'.$this->l('Attribute').'</th><th>'.$this->l('Count').'</th></tr>'; <tr><th>'.$this->l('Group').'</th><th>'.$this->l('Attribute').'</th><th>'.$this->l('Count').'</th></tr>';
+34 -26
View File
@@ -30,23 +30,25 @@ if (!defined('_PS_VERSION_'))
class StatsLive extends Module class StatsLive extends Module
{ {
function __construct() private $html = '';
{
$this->name = 'statslive'; public function __construct()
$this->tab = 'analytics_stats'; {
$this->version = 1.0; $this->name = 'statslive';
$this->tab = 'analytics_stats';
$this->version = 1.0;
$this->author = 'PrestaShop'; $this->author = 'PrestaShop';
$this->need_instance = 0; $this->need_instance = 0;
parent::__construct(); parent::__construct();
$this->displayName = $this->l('Visitors online'); $this->displayName = $this->l('Visitors online');
$this->description = $this->l('Display the list of customers and visitors currently online.'); $this->description = $this->l('Display the list of customers and visitors currently online.');
} }
public function install() public function install()
{ {
return (parent::install() AND $this->registerHook('AdminStatsModules')); return parent::install() && $this->registerHook('AdminStatsModules');
} }
/** /**
@@ -115,56 +117,62 @@ class StatsLive extends Module
list($visitors, $totalVisitors) = $this->getVisitorsOnline(); list($visitors, $totalVisitors) = $this->getVisitorsOnline();
$irow = 0; $irow = 0;
echo '<script type="text/javascript" language="javascript"> $this->html .= '<script type="text/javascript" language="javascript">
$("#calendar").next().remove(); $("#calendar").next().remove();
$("#calendar").remove(); $("#calendar").remove();
</script>'; </script>';
if (!Configuration::get('PS_STATSDATA_CUSTOMER_PAGESVIEWS')) if (!Configuration::get('PS_STATSDATA_CUSTOMER_PAGESVIEWS'))
echo '<div class="warn width3">'.$this->l('You must activate the option "pages views for each customer" in the "Stats datamining" module in order to see the pages currently viewed by your customers.').'</div>'; $this->html .= '<div class="warn">'.
echo ' $this->l('You must activate the option "pages views for each customer" in the "Stats datamining" module in order to see the pages currently viewed by your customers.').'
<fieldset class="width3"><legend><img src="../modules/'.$this->name.'/logo.gif" /> '.$this->l('Customers online').'</legend>'; </div>';
$this->html .= '
<fieldset><legend><img src="../modules/'.$this->name.'/logo.gif" /> '.$this->l('Customers online').'</legend>';
if ($totalCustomers) if ($totalCustomers)
{ {
echo $this->l('Total:').' '.(int)($totalCustomers).' $this->html .= $this->l('Total:').' '.(int)$totalCustomers.'
<table cellpadding="0" cellspacing="0" class="table space"> <table cellpadding="0" cellspacing="0" class="table space">
<tr><th>'.$this->l('ID').'</th><th>'.$this->l('Name').'</th><th>'.$this->l('Current Page').'</th><th>'.$this->l('View').'</th></tr>'; <tr><th>'.$this->l('ID').'</th><th>'.$this->l('Name').'</th><th>'.$this->l('Current Page').'</th><th>'.$this->l('View').'</th></tr>';
foreach ($customers as $customer) foreach ($customers as $customer)
echo ' $this->html .= '
<tr'.($irow++ % 2 ? ' class="alt_row"' : '').'> <tr'.($irow++ % 2 ? ' class="alt_row"' : '').'>
<td>'.$customer['id_customer'].'</td> <td>'.$customer['id_customer'].'</td>
<td style="width: 200px;">'.$customer['firstname'].' '.$customer['lastname'].'</td> <td style="width: 200px;">'.$customer['firstname'].' '.$customer['lastname'].'</td>
<td style="width: 200px;">'.$customer['page'].'</td> <td style="width: 200px;">'.$customer['page'].'</td>
<td style="text-align: right; width: 25px;"> <td style="text-align: right; width: 25px;">
<a href="index.php?tab=AdminCustomers&id_customer='.$customer['id_customer'].'&viewcustomer&token='.Tools::getAdminToken('AdminCustomers'.(int)(Tab::getIdFromClassName('AdminCustomers')).(int)$this->context->employee->id).'" target="_blank"> <a href="index.php?tab=AdminCustomers&id_customer='.$customer['id_customer'].'&viewcustomer&token='.Tools::getAdminToken('AdminCustomers'.(int)Tab::getIdFromClassName('AdminCustomers').(int)$this->context->employee->id).'"
target="_blank">
<img src="../modules/'.$this->name.'/logo.gif" /> <img src="../modules/'.$this->name.'/logo.gif" />
</a> </a>
</td> </td>
</tr>'; </tr>';
echo '</table>'; $this->html .= '</table>';
} }
else else
echo $this->l('There are no customers online.'); $this->html .= $this->l('There are no customers online.');
echo '</fieldset> $this->html .= '</fieldset>
<fieldset class="width3 space"><legend><img src="../modules/'.$this->name.'/logo.gif" /> '.$this->l('Visitors online').'</legend>'; <br />
<fieldset><legend><img src="../modules/'.$this->name.'/logo.gif" /> '.$this->l('Visitors online').'</legend>';
if ($totalVisitors) if ($totalVisitors)
{ {
echo $this->l('Total:').' '.(int)($totalVisitors).' $this->html .= $this->l('Total:').' '.(int)($totalVisitors).'
<div style="overflow-y: scroll; height: 600px;"> <div style="overflow-y: scroll; height: 600px;">
<table cellpadding="0" cellspacing="0" class="table space"> <table cellpadding="0" cellspacing="0" class="table space">
<tr><th>'.$this->l('Guest').'</th><th>'.$this->l('IP').'</th><th>'.$this->l('Since').'</th><th>'.$this->l('Current page').'</th><th>'.$this->l('Referrer').'</th></tr>'; <tr><th>'.$this->l('Guest').'</th><th>'.$this->l('IP').'</th><th>'.$this->l('Since').'</th><th>'.$this->l('Current page').'</th><th>'.$this->l('Referrer').'</th></tr>';
foreach ($visitors as $visitor) foreach ($visitors as $visitor)
echo '<tr'.($irow++ % 2 ? ' class="alt_row"' : '').'> $this->html .= '<tr'.($irow++ % 2 ? ' class="alt_row"' : '').'>
<td>'.$visitor['id_guest'].'</td> <td>'.$visitor['id_guest'].'</td>
<td style="width: 80px;">'.long2ip($visitor['ip_address']).'</td> <td style="width: 80px;">'.long2ip($visitor['ip_address']).'</td>
<td style="width: 100px;">'.substr($visitor['date_add'], 11).'</td> <td style="width: 100px;">'.substr($visitor['date_add'], 11).'</td>
<td style="width: 200px;">'.(isset($visitor['page']) ? $visitor['page'] : $this->l('Undefined')).'</td> <td style="width: 200px;">'.(isset($visitor['page']) ? $visitor['page'] : $this->l('Undefined')).'</td>
<td style="width: 200px;">'.(empty($visitor['http_referer']) ? $this->l('none') : parse_url($visitor['http_referer'], PHP_URL_HOST)).'</td> <td style="width: 200px;">'.(empty($visitor['http_referer']) ? $this->l('none') : parse_url($visitor['http_referer'], PHP_URL_HOST)).'</td>
</tr>'; </tr>';
echo '</table></div>'; $this->html .= '</table></div>';
} }
else else
echo $this->l('There are no visitors online.'); $this->html .= $this->l('There are no visitors online.');
echo '</fieldset>'; $this->html .= '</fieldset>';
return $this->html;
} }
} }
+34 -34
View File
@@ -30,28 +30,28 @@ if (!defined('_PS_VERSION_'))
class StatsNewsletter extends ModuleGraph class StatsNewsletter extends ModuleGraph
{ {
private $_html = ''; private $_html = '';
private $_query = ''; private $_query = '';
private $_query2 = ''; private $_query2 = '';
private $_option = ''; private $_option = '';
function __construct() public function __construct()
{ {
$this->name = 'statsnewsletter'; $this->name = 'statsnewsletter';
$this->tab = 'analytics_stats'; $this->tab = 'analytics_stats';
$this->version = 1.0; $this->version = 1.0;
$this->author = 'PrestaShop'; $this->author = 'PrestaShop';
$this->need_instance = 0; $this->need_instance = 0;
parent::__construct(); parent::__construct();
$this->displayName = $this->l('Newsletter'); $this->displayName = $this->l('Newsletter');
$this->description = $this->l('Display the newsletter registrations'); $this->description = $this->l('Display the newsletter registrations');
} }
public function install() public function install()
{ {
return (parent::install() AND $this->registerHook('AdminStatsModules')); return (parent::install() && $this->registerHook('AdminStatsModules'));
} }
public function hookAdminStatsModules($params) public function hookAdminStatsModules($params)
@@ -62,11 +62,11 @@ class StatsNewsletter extends ModuleGraph
if (Tools::getValue('export')) if (Tools::getValue('export'))
$this->csvExport(array('type' => 'line', 'layers' => 3)); $this->csvExport(array('type' => 'line', 'layers' => 3));
$this->_html = ' $this->_html = '
<fieldset class="width3"><legend><img src="../modules/'.$this->name.'/logo.gif" /> '.$this->displayName.'</legend> <fieldset><legend><img src="../modules/'.$this->name.'/logo.gif" /> '.$this->displayName.'</legend>
<p>'.$this->l('Registrations from customers:').' '.(int)($totals['customers']).'</p> <p>'.$this->l('Registrations from customers:').' '.(int)$totals['customers'].'</p>
<p>'.$this->l('Registrations from visitors:').' '.(int)($totals['visitors']).'</p> <p>'.$this->l('Registrations from visitors:').' '.(int)$totals['visitors'].'</p>
<p>'.$this->l('Both:').' '.(int)($totals['both']).'</p> <p>'.$this->l('Both:').' '.(int)$totals['both'].'</p>
<center>'.$this->engine(array('type' => 'line', 'layers' => 3)).'</center> <div>'.$this->engine(array('type' => 'line', 'layers' => 3)).'</div>
<p><a href="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'&export=1"><img src="../img/admin/asterisk.gif" />'.$this->l('CSV Export').'</a></p> <p><a href="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'&export=1"><img src="../img/admin/asterisk.gif" />'.$this->l('CSV Export').'</a></p>
</fieldset>'; </fieldset>';
} }
@@ -119,11 +119,11 @@ class StatsNewsletter extends ModuleGraph
{ {
$result1 = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($this->_query.$this->getDate()); $result1 = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($this->_query.$this->getDate());
$result2 = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($this->_query2.$this->getDate()); $result2 = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($this->_query2.$this->getDate());
foreach ($result1 AS $row) foreach ($result1 as $row)
$this->_values[0][(int)(substr($row['newsletter_date_add'], 0, 4))] += 1; $this->_values[0][(int)substr($row['newsletter_date_add'], 0, 4)] += 1;
if ($result2) if ($result2)
foreach ($result2 AS $row) foreach ($result2 as $row)
$this->_values[1][(int)(substr($row['newsletter_date_add'], 0, 4))] += 1; $this->_values[1][(int)substr($row['newsletter_date_add'], 0, 4)] += 1;
foreach ($this->_values[2] as $key => $zerofill) foreach ($this->_values[2] as $key => $zerofill)
$this->_values[2][$key] = $this->_values[0][$key] + $this->_values[1][$key]; $this->_values[2][$key] = $this->_values[0][$key] + $this->_values[1][$key];
} }
@@ -132,11 +132,11 @@ class StatsNewsletter extends ModuleGraph
{ {
$result1 = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($this->_query.$this->getDate()); $result1 = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($this->_query.$this->getDate());
$result2 = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($this->_query2.$this->getDate()); $result2 = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($this->_query2.$this->getDate());
foreach ($result1 AS $row) foreach ($result1 as $row)
$this->_values[0][(int)(substr($row['newsletter_date_add'], 5, 2))] += 1; $this->_values[0][(int)substr($row['newsletter_date_add'], 5, 2)] += 1;
if ($result2) if ($result2)
foreach ($result2 AS $row) foreach ($result2 as $row)
$this->_values[1][(int)(substr($row['newsletter_date_add'], 5, 2))] += 1; $this->_values[1][(int)substr($row['newsletter_date_add'], 5, 2)] += 1;
foreach ($this->_values[2] as $key => $zerofill) foreach ($this->_values[2] as $key => $zerofill)
$this->_values[2][$key] = $this->_values[0][$key] + $this->_values[1][$key]; $this->_values[2][$key] = $this->_values[0][$key] + $this->_values[1][$key];
} }
@@ -145,11 +145,11 @@ class StatsNewsletter extends ModuleGraph
{ {
$result1 = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($this->_query.$this->getDate()); $result1 = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($this->_query.$this->getDate());
$result2 = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($this->_query2.$this->getDate()); $result2 = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($this->_query2.$this->getDate());
foreach ($result1 AS $row) foreach ($result1 as $row)
$this->_values[0][(int)(substr($row['newsletter_date_add'], 8, 2))] += 1; $this->_values[0][(int)substr($row['newsletter_date_add'], 8, 2)] += 1;
if ($result2) if ($result2)
foreach ($result2 AS $row) foreach ($result2 as $row)
$this->_values[1][(int)(substr($row['newsletter_date_add'], 8, 2))] += 1; $this->_values[1][(int)substr($row['newsletter_date_add'], 8, 2)] += 1;
foreach ($this->_values[2] as $key => $zerofill) foreach ($this->_values[2] as $key => $zerofill)
$this->_values[2][$key] = $this->_values[0][$key] + $this->_values[1][$key]; $this->_values[2][$key] = $this->_values[0][$key] + $this->_values[1][$key];
} }
@@ -158,11 +158,11 @@ class StatsNewsletter extends ModuleGraph
{ {
$result1 = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($this->_query.$this->getDate()); $result1 = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($this->_query.$this->getDate());
$result2 = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($this->_query2.$this->getDate()); $result2 = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($this->_query2.$this->getDate());
foreach ($result1 AS $row) foreach ($result1 as $row)
$this->_values[0][(int)(substr($row['newsletter_date_add'], 11, 2))] += 1; $this->_values[0][(int)substr($row['newsletter_date_add'], 11, 2)] += 1;
if ($result2) if ($result2)
foreach ($result2 AS $row) foreach ($result2 as $row)
$this->_values[1][(int)(substr($row['newsletter_date_add'], 11, 2))] += 1; $this->_values[1][(int)substr($row['newsletter_date_add'], 11, 2)] += 1;
foreach ($this->_values[2] as $key => $zerofill) foreach ($this->_values[2] as $key => $zerofill)
$this->_values[2][$key] = $this->_values[0][$key] + $this->_values[1][$key]; $this->_values[2][$key] = $this->_values[0][$key] + $this->_values[1][$key];
} }
+26 -24
View File
@@ -32,23 +32,23 @@ class StatsOrigin extends ModuleGraph
{ {
private $_html; private $_html;
function __construct() public function __construct()
{ {
$this->name = 'statsorigin'; $this->name = 'statsorigin';
$this->tab = 'analytics_stats'; $this->tab = 'analytics_stats';
$this->version = 1.0; $this->version = 1.0;
$this->author = 'PrestaShop'; $this->author = 'PrestaShop';
$this->need_instance = 0; $this->need_instance = 0;
parent::__construct(); parent::__construct();
$this->displayName = $this->l('Visitors origin'); $this->displayName = $this->l('Visitors origin');
$this->description = $this->l('Display the websites your visitors come from.'); $this->description = $this->l('Display the websites your visitors come from.');
} }
function install() public function install()
{ {
return (parent::install() AND $this->registerHook('AdminStatsModules')); return (parent::install() && $this->registerHook('AdminStatsModules'));
} }
private function getOrigins($dateBetween) private function getOrigins($dateBetween)
@@ -63,7 +63,7 @@ class StatsOrigin extends ModuleGraph
$websites = array($directLink => 0); $websites = array($directLink => 0);
while ($row = Db::getInstance(_PS_USE_SQL_SLAVE_)->nextRow($result)) while ($row = Db::getInstance(_PS_USE_SQL_SLAVE_)->nextRow($result))
{ {
if (!isset($row['http_referer']) OR empty($row['http_referer'])) if (!isset($row['http_referer']) || empty($row['http_referer']))
++$websites[$directLink]; ++$websites[$directLink];
else else
{ {
@@ -78,42 +78,44 @@ class StatsOrigin extends ModuleGraph
return $websites; return $websites;
} }
function hookAdminStatsModules() public function hookAdminStatsModules()
{ {
$websites = $this->getOrigins(ModuleGraph::getDateBetween()); $websites = $this->getOrigins(ModuleGraph::getDateBetween());
if (Tools::getValue('export')) if (Tools::getValue('export'))
if (Tools::getValue('exportType') == 'top') if (Tools::getValue('exportType') == 'top')
$this->csvExport(array('type' => 'pie')); $this->csvExport(array('type' => 'pie'));
$this->_html = '<fieldset class="width3"><legend><img src="../modules/'.$this->name.'/logo.gif" /> '.$this->l('Origin').'</legend>'; $this->_html = '<fieldset><legend><img src="../modules/'.$this->name.'/logo.gif" /> '.$this->l('Origin').'</legend>';
if (sizeof($websites)) if (count($websites))
{ {
$this->_html .= ' $this->_html .= '
<center><p><img src="../img/admin/down.gif" />'. $this->l('Here is the percentage of the 10 most popular referrer websites by which visitors went through to get to your shop.').'</p> <p><img src="../img/admin/down.gif" />'.$this->l('Here is the percentage of the 10 most popular referrer websites by which visitors went through to get to your shop.').'</p>
'.$this->engine(array('type' => 'pie')).'</center> <div>'.$this->engine(array('type' => 'pie')).'</div>
<p><a href="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'&export=1&exportType=top"><img src="../img/admin/asterisk.gif" />'.$this->l('CSV Export').'</a></p><br /><br /> <p><a href="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'&export=1&exportType=top"><img src="../img/admin/asterisk.gif" />'.$this->l('CSV Export').'</a></p><br /><br />
<div style="overflow-y: scroll; height: 600px;"> <div style="overflow-y: scroll; height: 600px;">
<center>
<table class="table " border="0" cellspacing="0" cellspacing="0"> <table class="table " border="0" cellspacing="0" cellspacing="0">
<tr> <tr>
<th style="width:400px;">'.$this->l('Origin').'</th> <th style="width:400px;">'.$this->l('Origin').'</th>
<th style="width:50px; text-align: right">'.$this->l('Total').'</th> <th style="width:50px; text-align: right">'.$this->l('Total').'</th>
</tr>'; </tr>';
foreach ($websites as $website => $total) foreach ($websites as $website => $total)
$this->_html .= '<tr><td>'.(!strstr($website, ' ') ? '<a href="'.Tools::getProtocol().$website.'">' : '').$website.(!strstr($website, ' ') ? '</a>' : '').'</td><td style="text-align: right">'.$total.'</td></tr>'; $this->_html .= '<tr>
$this->_html .= '</table></center></div>'; <td>'.(!strstr($website, ' ') ? '<a href="'.Tools::getProtocol().$website.'">' : '').$website.(!strstr($website, ' ') ? '</a>' : '').'</td><td style="text-align: right">'.$total.'</td>
</tr>';
$this->_html .= '</table></div>';
} }
else else
$this->_html .= '<p><strong>'.$this->l('Direct links only').'</strong></p>'; $this->_html .= '<p><strong>'.$this->l('Direct links only').'</strong></p>';
$this->_html .= '</fieldset><br /> $this->_html .= '</fieldset><br />
<fieldset class="width3"><legend><img src="../img/admin/comment.gif" /> '.$this->l('Guide').'</legend> <fieldset><legend><img src="../img/admin/comment.gif" /> '.$this->l('Guide').'</legend>
<h2>'.$this->l('What is a referrer website?').'</h2> <h2>'.$this->l('What is a referrer website?').'</h2>
<p> <p>
'.$this->l('When visiting a webpage, the referrer is the URL of the previous webpage from which a link was followed.').'<br /> '.$this->l('When visiting a webpage, the referrer is the URL of the previous webpage from which a link was followed.').'<br />
'.$this->l('A referrer enables you to know which keywords are entered by visitors in search engines when getting to your shop and allows you to optimize web promotion.').'<br /><br /> '.$this->l('A referrer enables you to know which keywords are entered by visitors in search engines when getting to your shop and allows you to optimize web promotion.').'<br /><br />
'. $this->l('A referrer can be:').' '.$this->l('A referrer can be:').'
<ul> <ul>
<li class="bullet">'. $this->l('Someone who put a link on their website for your shop').'</li> <li class="bullet">'.$this->l('Someone who put a link on their website for your shop').'</li>
<li class="bullet">'. $this->l('A partner with whom you made a link exchange in order to bring in sales or attract new customers').'</li> <li class="bullet">'.$this->l('A partner with whom you made a link exchange in order to bring in sales or attract new customers').'</li>
</ul> </ul>
</p> </p>
</fieldset>'; </fieldset>';
@@ -30,71 +30,70 @@ if (!defined('_PS_VERSION_'))
class StatsPersonalInfos extends ModuleGraph class StatsPersonalInfos extends ModuleGraph
{ {
private $_html = ''; private $html = '';
private $_query = ''; private $_query = '';
private $_option; private $_option;
function __construct() public function __construct()
{ {
$this->name = 'statspersonalinfos'; $this->name = 'statspersonalinfos';
$this->tab = 'analytics_stats'; $this->tab = 'analytics_stats';
$this->version = 1.0; $this->version = 1.0;
$this->author = 'PrestaShop'; $this->author = 'PrestaShop';
$this->need_instance = 0; $this->need_instance = 0;
parent::__construct(); parent::__construct();
$this->displayName = $this->l('Registered Customer Info'); $this->displayName = $this->l('Registered Customer Info');
$this->description = $this->l('Display characteristics such as gender and age.'); $this->description = $this->l('Display characteristics such as gender and age.');
} }
public function install() public function install()
{ {
return (parent::install() AND $this->registerHook('AdminStatsModules')); return (parent::install() && $this->registerHook('AdminStatsModules'));
} }
public function hookAdminStatsModules($params) public function hookAdminStatsModules($params)
{ {
$this->_html = '<fieldset class="width3"><legend><img src="../modules/'.$this->name.'/logo.gif" /> '.$this->displayName.'</legend>'; $this->html = '<fieldset><legend><img src="../modules/'.$this->name.'/logo.gif" /> '.$this->displayName.'</legend>';
if (sizeof(Customer::getCustomers())) if (count(Customer::getCustomers()))
{ {
if (Tools::getValue('export')) if (Tools::getValue('export'))
if (Tools::getValue('exportType') =='gender') if (Tools::getValue('exportType') == 'gender')
$this->csvExport(array('type' => 'pie', 'option' => 'gender')); $this->csvExport(array('type' => 'pie', 'option' => 'gender'));
elseif (Tools::getValue('exportType') =='age') else if (Tools::getValue('exportType') == 'age')
$this->csvExport(array('type' => 'pie', 'option' => 'age')); $this->csvExport(array('type' => 'pie', 'option' => 'age'));
elseif (Tools::getValue('exportType') =='country') else if (Tools::getValue('exportType') == 'country')
$this->csvExport(array('type' => 'pie', 'option' => 'country')); $this->csvExport(array('type' => 'pie', 'option' => 'country'));
elseif (Tools::getValue('exportType') =='currency') else if (Tools::getValue('exportType') == 'currency')
$this->csvExport(array('type' => 'pie', 'option' => 'currency')); $this->csvExport(array('type' => 'pie', 'option' => 'currency'));
elseif (Tools::getValue('exportType') =='language') else if (Tools::getValue('exportType') == 'language')
$this->csvExport(array('type' => 'pie', 'option' => 'language')); $this->csvExport(array('type' => 'pie', 'option' => 'language'));
$this->_html .= ' $this->html .= '
<p><img src="../img/admin/down.gif" />'.$this->l('Gender distribution allows you to determine the percentage of men and women among your customers.').'</p>
<center><p><img src="../img/admin/down.gif" />'.$this->l('Gender distribution allows you to determine the percentage of men and women among your customers.').'</p> <div>'.$this->engine(array('type' => 'pie', 'option' => 'gender')).'</div><br />
'.$this->engine(array('type' => 'pie', 'option' => 'gender')).'<br /></center>
<p><a href="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'&export=1&exportType=gender"><img src="../img/admin/asterisk.gif" />'.$this->l('CSV Export').'</a></p> <p><a href="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'&export=1&exportType=gender"><img src="../img/admin/asterisk.gif" />'.$this->l('CSV Export').'</a></p>
<br class="clear" /><br /> <br class="clear" /><br />
<center><p><img src="../img/admin/down.gif" />'.$this->l('Age ranges allows you to determine in which age range your customers are.').'</p> <p><img src="../img/admin/down.gif" />'.$this->l('Age ranges allows you to determine in which age range your customers are.').'</p>
'.$this->engine(array('type' => 'pie', 'option' => 'age')).'<br /></center> <div>'.$this->engine(array('type' => 'pie', 'option' => 'age')).'</div><br />
<p><a href="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'&export=1&exportType=age"><img src="../img/admin/asterisk.gif" />'.$this->l('CSV Export').'</a></p><br /><br /> <p><a href="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'&export=1&exportType=age"><img src="../img/admin/asterisk.gif" />'.$this->l('CSV Export').'</a></p><br /><br />
<center><p><img src="../img/admin/down.gif" />'.$this->l('Country distribution allows you to determine in which part of the world your customers are shopping from.').'</p> <p><img src="../img/admin/down.gif" />'.$this->l('Country distribution allows you to determine in which part of the world your customers are shopping from.').'</p>
'.$this->engine(array('type' => 'pie', 'option' => 'country')).'<br /></center> <div>'.$this->engine(array('type' => 'pie', 'option' => 'country')).'</div><br />
<p><a href="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'&export=1&exportType=country"><img src="../img/admin/asterisk.gif" />'.$this->l('CSV Export').'</a></p><br /><br /> <p><a href="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'&export=1&exportType=country"><img src="../img/admin/asterisk.gif" />'.$this->l('CSV Export').'</a></p><br /><br />
<center><p><img src="../img/admin/down.gif" />'.$this->l('Currency ranges allows you to determine which currencies your customers are using.').'</p> <p><img src="../img/admin/down.gif" />'.$this->l('Currency ranges allows you to determine which currencies your customers are using.').'</p>
'.$this->engine(array('type' => 'pie', 'option' => 'currency')).'<br /></center> <div>'.$this->engine(array('type' => 'pie', 'option' => 'currency')).'</div><br />
<p><a href="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'&export=1&exportType=currency"><img src="../img/admin/asterisk.gif" />'.$this->l('CSV Export').'</a></p><br /><br /> <p><a href="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'&export=1&exportType=currency"><img src="../img/admin/asterisk.gif" />'.$this->l('CSV Export').'</a></p><br /><br />
<center><p><img src="../img/admin/down.gif" />'.$this->l('Language distribution allows you to determine the general languages your customers are using on your shop.').'</p> <p><img src="../img/admin/down.gif" />'.$this->l('Language distribution allows you to determine the general languages your customers are using on your shop.').'</p>
'.$this->engine(array('type' => 'pie', 'option' => 'language')).'<br /></center> <div>'.$this->engine(array('type' => 'pie', 'option' => 'language')).'</div><br />
<p><a href="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'&export=1&exportType=language"><img src="../img/admin/asterisk.gif" />'.$this->l('CSV Export').'</a></p> <p><a href="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'&export=1&exportType=language"><img src="../img/admin/asterisk.gif" />'.$this->l('CSV Export').'</a></p>
</center>'; </center>';
} }
else else
$this->_html .= '<p>'.$this->l('No customers registered yet.').'</p>'; $this->html .= '<p>'.$this->l('No customers registered yet.').'</p>';
$this->_html .= ' $this->html .= '
</fieldset><br /> </fieldset><br />
<fieldset class="width3"><legend><img src="../img/admin/comment.gif" /> '.$this->l('Guide').'</legend> <fieldset><legend><img src="../img/admin/comment.gif" /> '.$this->l('Guide').'</legend>
<h2>'.$this->l('Target your audience').'</h2> <h2>'.$this->l('Target your audience').'</h2>
<p> <p>
'.$this->l('In order for each message to have an impact, you need to know to whom it should be addressed.').' '.$this->l('In order for each message to have an impact, you need to know to whom it should be addressed.').'
@@ -110,7 +109,7 @@ class StatsPersonalInfos extends ModuleGraph
</ul> </ul>
</p><br /> </p><br />
</fieldset>'; </fieldset>';
return $this->_html; return $this->html;
} }
public function setOption($option, $layers = 1) public function setOption($option, $layers = 1)
@@ -164,7 +163,7 @@ class StatsPersonalInfos extends ModuleGraph
'.$this->sqlShopRestriction(Shop::SHARE_CUSTOMER).' '.$this->sqlShopRestriction(Shop::SHARE_CUSTOMER).'
AND `birthday` IS NOT NULL'; AND `birthday` IS NOT NULL';
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql); $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql);
if (isset($result['total']) AND $result['total']) if (isset($result['total']) && $result['total'])
{ {
$this->_values[] = $result['total']; $this->_values[] = $result['total'];
$this->_legend[] = $this->l('0-18 years old'); $this->_legend[] = $this->l('0-18 years old');
@@ -178,7 +177,7 @@ class StatsPersonalInfos extends ModuleGraph
'.$this->sqlShopRestriction(Shop::SHARE_CUSTOMER).' '.$this->sqlShopRestriction(Shop::SHARE_CUSTOMER).'
AND `birthday` IS NOT NULL'; AND `birthday` IS NOT NULL';
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql); $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql);
if (isset($result['total']) AND $result['total']) if (isset($result['total']) && $result['total'])
{ {
$this->_values[] = $result['total']; $this->_values[] = $result['total'];
$this->_legend[] = $this->l('18-24 years old'); $this->_legend[] = $this->l('18-24 years old');
@@ -192,7 +191,7 @@ class StatsPersonalInfos extends ModuleGraph
'.$this->sqlShopRestriction(Shop::SHARE_CUSTOMER).' '.$this->sqlShopRestriction(Shop::SHARE_CUSTOMER).'
AND `birthday` IS NOT NULL'; AND `birthday` IS NOT NULL';
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql); $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql);
if (isset($result['total']) AND $result['total']) if (isset($result['total']) && $result['total'])
{ {
$this->_values[] = $result['total']; $this->_values[] = $result['total'];
$this->_legend[] = $this->l('25-34 years old'); $this->_legend[] = $this->l('25-34 years old');
@@ -206,7 +205,7 @@ class StatsPersonalInfos extends ModuleGraph
'.$this->sqlShopRestriction(Shop::SHARE_CUSTOMER).' '.$this->sqlShopRestriction(Shop::SHARE_CUSTOMER).'
AND `birthday` IS NOT NULL'; AND `birthday` IS NOT NULL';
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql); $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql);
if (isset($result['total']) AND $result['total']) if (isset($result['total']) && $result['total'])
{ {
$this->_values[] = $result['total']; $this->_values[] = $result['total'];
$this->_legend[] = $this->l('35-49 years old'); $this->_legend[] = $this->l('35-49 years old');
@@ -220,7 +219,7 @@ class StatsPersonalInfos extends ModuleGraph
'.$this->sqlShopRestriction(Shop::SHARE_CUSTOMER).' '.$this->sqlShopRestriction(Shop::SHARE_CUSTOMER).'
AND `birthday` IS NOT NULL'; AND `birthday` IS NOT NULL';
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql); $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql);
if (isset($result['total']) AND $result['total']) if (isset($result['total']) && $result['total'])
{ {
$this->_values[] = $result['total']; $this->_values[] = $result['total'];
$this->_legend[] = $this->l('50-59 years old'); $this->_legend[] = $this->l('50-59 years old');
@@ -233,7 +232,7 @@ class StatsPersonalInfos extends ModuleGraph
'.$this->sqlShopRestriction(Shop::SHARE_CUSTOMER).' '.$this->sqlShopRestriction(Shop::SHARE_CUSTOMER).'
AND `birthday` IS NOT NULL'; AND `birthday` IS NOT NULL';
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql); $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql);
if (isset($result['total']) AND $result['total']) if (isset($result['total']) && $result['total'])
{ {
$this->_values[] = $result['total']; $this->_values[] = $result['total'];
$this->_legend[] = $this->l('60 years old and more'); $this->_legend[] = $this->l('60 years old and more');
@@ -245,7 +244,7 @@ class StatsPersonalInfos extends ModuleGraph
WHERE `birthday` IS NULL WHERE `birthday` IS NULL
'.$this->sqlShopRestriction(Shop::SHARE_CUSTOMER); '.$this->sqlShopRestriction(Shop::SHARE_CUSTOMER);
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql); $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql);
if (isset($result['total']) AND $result['total']) if (isset($result['total']) && $result['total'])
{ {
$this->_values[] = $result['total']; $this->_values[] = $result['total'];
$this->_legend[] = $this->l('Unknown'); $this->_legend[] = $this->l('Unknown');
@@ -265,8 +264,8 @@ class StatsPersonalInfos extends ModuleGraph
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql); $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
foreach ($result as $row) foreach ($result as $row)
{ {
$this->_values[] = $row['total']; $this->_values[] = $row['total'];
$this->_legend[] = $row['name']; $this->_legend[] = $row['name'];
} }
break; break;
@@ -281,8 +280,8 @@ class StatsPersonalInfos extends ModuleGraph
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql); $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
foreach ($result as $row) foreach ($result as $row)
{ {
$this->_values[] = $row['total']; $this->_values[] = $row['total'];
$this->_legend[] = $row['name']; $this->_legend[] = $row['name'];
} }
break; break;
@@ -297,8 +296,8 @@ class StatsPersonalInfos extends ModuleGraph
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql); $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
foreach ($result as $row) foreach ($result as $row)
{ {
$this->_values[] = $row['total']; $this->_values[] = $row['total'];
$this->_legend[] = $row['name']; $this->_legend[] = $row['name'];
} }
break; break;
} }
+76 -68
View File
@@ -30,28 +30,28 @@ if (!defined('_PS_VERSION_'))
class StatsProduct extends ModuleGraph class StatsProduct extends ModuleGraph
{ {
private $_html = ''; private $html = '';
private $_query = ''; private $_query = '';
private $_option = 0; private $_option = 0;
private $_id_product = 0; private $_id_product = 0;
function __construct() public function __construct()
{ {
$this->name = 'statsproduct'; $this->name = 'statsproduct';
$this->tab = 'analytics_stats'; $this->tab = 'analytics_stats';
$this->version = 1.0; $this->version = 1.0;
$this->author = 'PrestaShop'; $this->author = 'PrestaShop';
$this->need_instance = 0; $this->need_instance = 0;
parent::__construct(); parent::__construct();
$this->displayName = $this->l('Product details'); $this->displayName = $this->l('Product details');
$this->description = $this->l('Get detailed statistics for each product.'); $this->description = $this->l('Get detailed statistics for each product.');
} }
public function install() public function install()
{ {
return (parent::install() AND $this->registerHook('AdminStatsModules')); return (parent::install() && $this->registerHook('AdminStatsModules'));
} }
public function getTotalBought($id_product) public function getTotalBought($id_product)
@@ -73,7 +73,7 @@ class StatsProduct extends ModuleGraph
$sql = 'SELECT SUM(od.`product_quantity` * od.`product_price`) AS total $sql = 'SELECT SUM(od.`product_quantity` * od.`product_price`) AS total
FROM `'._DB_PREFIX_.'order_detail` od FROM `'._DB_PREFIX_.'order_detail` od
LEFT JOIN `'._DB_PREFIX_.'orders` o ON o.`id_order` = od.`id_order` LEFT JOIN `'._DB_PREFIX_.'orders` o ON o.`id_order` = od.`id_order`
WHERE od.`product_id` = '.(int)($id_product).' WHERE od.`product_id` = '.(int)$id_product.'
'.$this->sqlShopRestriction(Shop::SHARE_ORDER, 'o').' '.$this->sqlShopRestriction(Shop::SHARE_ORDER, 'o').'
AND o.valid = 1 AND o.valid = 1
AND o.`date_add` BETWEEN '.$dateBetween; AND o.`date_add` BETWEEN '.$dateBetween;
@@ -90,7 +90,7 @@ class StatsProduct extends ModuleGraph
LEFT JOIN `'._DB_PREFIX_.'page_type` pt ON pt.`id_page_type` = p.`id_page_type` LEFT JOIN `'._DB_PREFIX_.'page_type` pt ON pt.`id_page_type` = p.`id_page_type`
WHERE pt.`name` = \'product\' WHERE pt.`name` = \'product\'
'.$this->sqlShopRestriction(false, 'pv').' '.$this->sqlShopRestriction(false, 'pv').'
AND p.`id_object` = '.(int)($id_product).' AND p.`id_object` = '.(int)$id_product.'
AND dr.`time_start` BETWEEN '.$dateBetween.' AND dr.`time_start` BETWEEN '.$dateBetween.'
AND dr.`time_end` BETWEEN '.$dateBetween; AND dr.`time_end` BETWEEN '.$dateBetween;
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql); $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql);
@@ -105,8 +105,8 @@ class StatsProduct extends ModuleGraph
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON p.`id_product` = pl.`id_product`'.$this->context->shop->addSqlRestrictionOnLang('pl').' LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON p.`id_product` = pl.`id_product`'.$this->context->shop->addSqlRestrictionOnLang('pl').'
'.$this->context->shop->addSqlAssociation('product', 'p').' '.$this->context->shop->addSqlAssociation('product', 'p').'
'.(Tools::getValue('id_category') ? 'LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON p.`id_product` = cp.`id_product`' : '').' '.(Tools::getValue('id_category') ? 'LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON p.`id_product` = cp.`id_product`' : '').'
WHERE pl.`id_lang` = '.(int)($id_lang).' WHERE pl.`id_lang` = '.(int)$id_lang.'
'.(Tools::getValue('id_category') ? 'AND cp.id_category = '.(int)(Tools::getValue('id_category')) : '').' '.(Tools::getValue('id_category') ? 'AND cp.id_category = '.(int)Tools::getValue('id_category') : '').'
ORDER BY pl.`name`'; ORDER BY pl.`name`';
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql); return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
} }
@@ -119,7 +119,7 @@ class StatsProduct extends ModuleGraph
WHERE o.date_add BETWEEN '.$this->getDate().' WHERE o.date_add BETWEEN '.$this->getDate().'
'.$this->sqlShopRestriction(Shop::SHARE_ORDER, 'o').' '.$this->sqlShopRestriction(Shop::SHARE_ORDER, 'o').'
AND o.valid = 1 AND o.valid = 1
AND od.product_id = '.(int)($id_product); AND od.product_id = '.(int)$id_product;
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql); return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
} }
@@ -148,26 +148,26 @@ class StatsProduct extends ModuleGraph
public function hookAdminStatsModules($params) public function hookAdminStatsModules($params)
{ {
$id_category = (int)(Tools::getValue('id_category')); $id_category = (int)Tools::getValue('id_category');
$currency = Context::getContext()->currency; $currency = Context::getContext()->currency;
if (Tools::getValue('export')) if (Tools::getValue('export'))
if (!Tools::getValue('exportType')) if (!Tools::getValue('exportType'))
$this->csvExport(array('layers' => 2, 'type' => 'line', 'option' => '42')); $this->csvExport(array('layers' => 2, 'type' => 'line', 'option' => '42'));
$this->_html = '<fieldset class="width3"><legend><img src="../modules/'.$this->name.'/logo.gif" /> '.$this->displayName.'</legend>'; $this->html = '<fieldset><legend><img src="../modules/'.$this->name.'/logo.gif" /> '.$this->displayName.'</legend>';
if ($id_product = (int)(Tools::getValue('id_product'))) if ($id_product = (int)Tools::getValue('id_product'))
{ {
if (Tools::getValue('export')) if (Tools::getValue('export'))
if (Tools::getValue('exportType') == 1) if (Tools::getValue('exportType') == 1)
$this->csvExport(array('layers' => 2, 'type' => 'line', 'option' => '1-'.$id_product)); $this->csvExport(array('layers' => 2, 'type' => 'line', 'option' => '1-'.$id_product));
elseif (Tools::getValue('exportType') == 2) else if (Tools::getValue('exportType') == 2)
$this->csvExport(array('type' => 'pie', 'option' => '3-'.$id_product)); $this->csvExport(array('type' => 'pie', 'option' => '3-'.$id_product));
$product = new Product($id_product, false, $this->context->language->id); $product = new Product($id_product, false, $this->context->language->id);
$totalBought = $this->getTotalBought($product->id); $totalBought = $this->getTotalBought($product->id);
$totalSales = $this->getTotalSales($product->id); $totalSales = $this->getTotalSales($product->id);
$totalViewed = $this->getTotalViewed($product->id); $totalViewed = $this->getTotalViewed($product->id);
$this->_html .= '<h3>'.$product->name.' - '.$this->l('Details').'</h3> $this->html .= '<h3>'.$product->name.' - '.$this->l('Details').'</h3>
<p>'.$this->l('Total bought:').' '.$totalBought.'</p> <p>'.$this->l('Total bought:').' '.$totalBought.'</p>
<p>'.$this->l('Sales (-Tx):').' '.Tools::displayprice($totalSales, $currency).'</p> <p>'.$this->l('Sales (-Tx):').' '.Tools::displayprice($totalSales, $currency).'</p>
<p>'.$this->l('Total viewed:').' '.$totalViewed.'</p> <p>'.$this->l('Total viewed:').' '.$totalViewed.'</p>
@@ -175,15 +175,15 @@ class StatsProduct extends ModuleGraph
<center>'.$this->engine(array('layers' => 2, 'type' => 'line', 'option' => '1-'.$id_product)).'</center> <center>'.$this->engine(array('layers' => 2, 'type' => 'line', 'option' => '1-'.$id_product)).'</center>
<br /> <br />
<p><a href="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'&export=1&exportType=1"><img src="../img/admin/asterisk.gif" />'.$this->l('CSV Export').'</a></p>'; <p><a href="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'&export=1&exportType=1"><img src="../img/admin/asterisk.gif" />'.$this->l('CSV Export').'</a></p>';
if ($hasAttribute = $product->hasAttributes() AND $totalBought) if ($hasAttribute = $product->hasAttributes() && $totalBought)
$this->_html .= '<h3 class="space">'.$this->l('Attribute sales distribution').'</h3><center>'.$this->engine(array('type' => 'pie', 'option' => '3-'.$id_product)).'</center><br /> $this->html .= '<h3 class="space">'.$this->l('Attribute sales distribution').'</h3><center>'.$this->engine(array('type' => 'pie', 'option' => '3-'.$id_product)).'</center><br />
<p><a href="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'&export=1&exportType=2"><img src="../img/admin/asterisk.gif" />'.$this->l('CSV Export').'</a></p><br />'; <p><a href="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'&export=1&exportType=2"><img src="../img/admin/asterisk.gif" />'.$this->l('CSV Export').'</a></p><br />';
if ($totalBought) if ($totalBought)
{ {
$sales = $this->getSales($id_product, $this->context->language->id); $sales = $this->getSales($id_product, $this->context->language->id);
$this->_html .= '<br class="clear" /> $this->html .= '<br class="clear" />
<h3>'.$this->l('Sales').'</h3> <h3>'.$this->l('Sales').'</h3>
<div style="overflow-y: scroll; height: '.min(400, (count($sales)+1)*32).'px;"> <div style="overflow-y: scroll; height: '.min(400, (count($sales) + 1) * 32).'px;">
<table class="table" border="0" cellspacing="0" cellspacing="0"> <table class="table" border="0" cellspacing="0" cellspacing="0">
<thead> <thead>
<tr> <tr>
@@ -195,24 +195,24 @@ class StatsProduct extends ModuleGraph
<th>'.$this->l('Price').'</th> <th>'.$this->l('Price').'</th>
</tr> </tr>
</thead><tbody>'; </thead><tbody>';
$tokenOrder = Tools::getAdminToken('AdminOrders'.(int)(Tab::getIdFromClassName('AdminOrders')).(int)($this->context->employee->id)); $tokenOrder = Tools::getAdminToken('AdminOrders'.(int)Tab::getIdFromClassName('AdminOrders').(int)$this->context->employee->id);
$tokenCustomer = Tools::getAdminToken('AdminCustomers'.(int)(Tab::getIdFromClassName('AdminCustomers')).(int)($this->context->employee->id)); $tokenCustomer = Tools::getAdminToken('AdminCustomers'.(int)Tab::getIdFromClassName('AdminCustomers').(int)$this->context->employee->id);
foreach ($sales as $sale) foreach ($sales as $sale)
$this->_html .= ' $this->html .= '
<tr> <tr>
<td>'.Tools::displayDate($sale['date_add'], (int)($this->context->language->id), false).'</td> <td>'.Tools::displayDate($sale['date_add'], (int)$this->context->language->id, false).'</td>
<td align="center"><a href="?tab=AdminOrders&id_order='.$sale['id_order'].'&vieworder&token='.$tokenOrder.'">'.(int)($sale['id_order']).'</a></td> <td align="center"><a href="?tab=AdminOrders&id_order='.$sale['id_order'].'&vieworder&token='.$tokenOrder.'">'.(int)($sale['id_order']).'</a></td>
<td align="center"><a href="?tab=AdminCustomers&id_customer='.$sale['id_customer'].'&viewcustomer&token='.$tokenCustomer.'">'.(int)($sale['id_customer']).'</a></td> <td align="center"><a href="?tab=AdminCustomers&id_customer='.$sale['id_customer'].'&viewcustomer&token='.$tokenCustomer.'">'.(int)($sale['id_customer']).'</a></td>
'.($hasAttribute ? '<td>'.$sale['product_name'].'</td>' : '').' '.($hasAttribute ? '<td>'.$sale['product_name'].'</td>' : '').'
<td>'.(int)($sale['product_quantity']).'</td> <td>'.(int)$sale['product_quantity'].'</td>
<td>'.Tools::displayprice($sale['total'], $currency).'</td> <td>'.Tools::displayprice($sale['total'], $currency).'</td>
</tr>'; </tr>';
$this->_html .= '</tbody></table></div>'; $this->html .= '</tbody></table></div>';
$crossSelling = $this->getCrossSales($id_product, $this->context->language->id); $crossSelling = $this->getCrossSales($id_product, $this->context->language->id);
if (count($crossSelling)) if (count($crossSelling))
{ {
$this->_html .= '<br class="clear" /> $this->html .= '<br class="clear" />
<h3>'.$this->l('Cross Selling').'</h3> <h3>'.$this->l('Cross Selling').'</h3>
<div style="overflow-y: scroll; height: 200px;"> <div style="overflow-y: scroll; height: 200px;">
<table class="table" border="0" cellspacing="0" cellspacing="0"> <table class="table" border="0" cellspacing="0" cellspacing="0">
@@ -223,30 +223,30 @@ class StatsProduct extends ModuleGraph
<th>'.$this->l('Average price').'</th> <th>'.$this->l('Average price').'</th>
</tr> </tr>
</thead><tbody>'; </thead><tbody>';
$tokenProducts = Tools::getAdminToken('AdminCatalog'.(int)(Tab::getIdFromClassName('AdminCatalog')).(int)($this->context->employee->id)); $tokenProducts = Tools::getAdminToken('AdminCatalog'.(int)Tab::getIdFromClassName('AdminCatalog').(int)$this->context->employee->id);
foreach ($crossSelling as $selling) foreach ($crossSelling as $selling)
$this->_html .= ' $this->html .= '
<tr> <tr>
<td ><a href="?tab=AdminCatalog&id_product='.(int)($selling['id_product']).'&addproduct&token='.$tokenProducts.'">'.$selling['pname'].'</a></td> <td ><a href="?tab=AdminCatalog&id_product='.(int)$selling['id_product'].'&addproduct&token='.$tokenProducts.'">'.$selling['pname'].'</a></td>
<td align="center">'.(int)($selling['pqty']).'</td> <td align="center">'.(int)$selling['pqty'].'</td>
<td align="right">'.Tools::displayprice($selling['pprice'], $currency).'</td> <td align="right">'.Tools::displayprice($selling['pprice'], $currency).'</td>
</tr>'; </tr>';
$this->_html .= '</tbody></table></div>'; $this->html .= '</tbody></table></div>';
} }
} }
} }
else else
{ {
$categories = Category::getCategories((int)$this->context->language->id, true, false); $categories = Category::getCategories((int)$this->context->language->id, true, false);
$this->_html .= ' $this->html .= '
<label>'.$this->l('Choose a category').'</label> <label>'.$this->l('Choose a category').'</label>
<div class="margin-form"> <div class="margin-form">
<form action="" method="post" id="categoriesForm"> <form action="" method="post" id="categoriesForm">
<select name="id_category" onchange="$(\'#categoriesForm\').submit();"> <select name="id_category" onchange="$(\'#categoriesForm\').submit();">
<option value="0">'.$this->l('All').'</option>'; <option value="0">'.$this->l('All').'</option>';
foreach ($categories as $category) foreach ($categories as $category)
$this->_html .= '<option value="'.$category['id_category'].'"'.($id_category == $category['id_category'] ? ' selected="selected"' : '').'>'.$category['name'].'</option>'; $this->html .= '<option value="'.$category['id_category'].'"'.($id_category == $category['id_category'] ? ' selected="selected"' : '').'>'.$category['name'].'</option>';
$this->_html .= ' $this->html .= '
</select> </select>
</form> </form>
</div> </div>
@@ -265,25 +265,33 @@ class StatsProduct extends ModuleGraph
</thead><tbody>'; </thead><tbody>';
foreach ($this->getProducts($this->context->language->id) as $product) foreach ($this->getProducts($this->context->language->id) as $product)
$this->_html .= '<tr><td>'.$product['reference'].'</td><td><a href="'.AdminTab::$currentIndex.'&token='.Tools::safeOutput(Tools::getValue('token')).'&module='.$this->name.'&id_product='.$product['id_product'].'">'.$product['name'].'</a></td><td>'.$product['quantity'].'</td></tr>'; $this->html .= '
<tr>
<td>'.$product['reference'].'</td>
<td>
<a href="'.AdminTab::$currentIndex.'&token='.Tools::safeOutput(Tools::getValue('token')).'&module='.$this->name.'&id_product='.$product['id_product'].'">'.$product['name'].'</a>
</td>
<td>'.$product['quantity'].'</td>
</tr>';
$this->_html .= '</tbody></table><br /></div><br /> $this->html .= '</tbody></table><br /></div><br />
<a href="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'&export=1"><img src="../img/admin/asterisk.gif" />'.$this->l('CSV Export').'</a><br />'; <a href="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'&export=1"><img src="../img/admin/asterisk.gif" />'.$this->l('CSV Export').'</a><br />';
} }
$this->_html .= '</fieldset><br /> $this->html .= '</fieldset><br />
<fieldset class="width3"><legend><img src="../img/admin/comment.gif" /> '.$this->l('Guide').'</legend> <fieldset><legend><img src="../img/admin/comment.gif" /> '.$this->l('Guide').'</legend>
<h2>'.$this->l('Number of purchases compared to number of viewings').'</h2> <h2>'.$this->l('Number of purchases compared to number of viewings').'</h2>
<p> <p>
'.$this->l('After choosing a category and selecting a product, informational graphs will appear. Then, you will be able to analyze them.').' '.$this->l('After choosing a category and selecting a product, informational graphs will appear. Then, you will be able to analyze them.').'
<ul> <ul>
<li class="bullet">'.$this->l('If you notice that a product is successful and often purchased, but viewed infrequently, you should put it more prominently on your webshop front-office.').'</li> <li class="bullet">'.$this->l('If you notice that a product is successful and often purchased, but viewed infrequently, you should put it more prominently on your webshop front-office.').'</li>
<li class="bullet">'.$this->l('On the other hand, if a product has many viewings but is not often purchased, we advise you to check or modify this product\'s information, description and photography again.').' <li class="bullet">'.$this->l('On the other hand, if a product has many viewings but is not often purchased,
we advise you to check or modify this product\'s information, description and photography again.').'
</li> </li>
</ul> </ul>
</p> </p>
</fieldset>'; </fieldset>';
return $this->_html; return $this->html;
} }
public function setOption($option, $layers = 1) public function setOption($option, $layers = 1)
@@ -303,7 +311,7 @@ class StatsProduct extends ModuleGraph
$this->_query[0] = 'SELECT o.`date_add`, SUM(od.`product_quantity`) AS total $this->_query[0] = 'SELECT o.`date_add`, SUM(od.`product_quantity`) AS total
FROM `'._DB_PREFIX_.'order_detail` od FROM `'._DB_PREFIX_.'order_detail` od
LEFT JOIN `'._DB_PREFIX_.'orders` o ON o.`id_order` = od.`id_order` LEFT JOIN `'._DB_PREFIX_.'orders` o ON o.`id_order` = od.`id_order`
WHERE od.`product_id` = '.(int)($this->_id_product).' WHERE od.`product_id` = '.(int)$this->_id_product.'
'.$this->sqlShopRestriction(Shop::SHARE_ORDER, 'o').' '.$this->sqlShopRestriction(Shop::SHARE_ORDER, 'o').'
AND o.valid = 1 AND o.valid = 1
AND o.`date_add` BETWEEN '.$dateBetween.' AND o.`date_add` BETWEEN '.$dateBetween.'
@@ -316,7 +324,7 @@ class StatsProduct extends ModuleGraph
LEFT JOIN `'._DB_PREFIX_.'page_type` pt ON pt.`id_page_type` = p.`id_page_type` LEFT JOIN `'._DB_PREFIX_.'page_type` pt ON pt.`id_page_type` = p.`id_page_type`
WHERE pt.`name` = \'product\' WHERE pt.`name` = \'product\'
'.$this->sqlShopRestriction(false, 'pv').' '.$this->sqlShopRestriction(false, 'pv').'
AND p.`id_object` = '.(int)($this->_id_product).' AND p.`id_object` = '.(int)$this->_id_product.'
AND dr.`time_start` BETWEEN '.$dateBetween.' AND dr.`time_start` BETWEEN '.$dateBetween.'
AND dr.`time_end` BETWEEN '.$dateBetween.' AND dr.`time_end` BETWEEN '.$dateBetween.'
GROUP BY dr.`time_start`'; GROUP BY dr.`time_start`';
@@ -347,29 +355,29 @@ class StatsProduct extends ModuleGraph
if ($this->_option == 42) if ($this->_option == 42)
{ {
$products = $this->getProducts($this->context->language->id); $products = $this->getProducts($this->context->language->id);
foreach ($products AS $product) foreach ($products as $product)
{ {
$this->_values[0][] = $product['reference']; $this->_values[0][] = $product['reference'];
$this->_values[1][] = $product['name']; $this->_values[1][] = $product['name'];
$this->_values[2][] = $product['quantity']; $this->_values[2][] = $product['quantity'];
$this->_legend[] = $product['id_product']; $this->_legend[] = $product['id_product'];
} }
} }
elseif ($this->_option != 3) else if ($this->_option != 3)
$this->setDateGraph($layers, true); $this->setDateGraph($layers, true);
else else
{ {
$product = new Product($this->_id_product, false, (int)($this->getLang())); $product = new Product($this->_id_product, false, (int)$this->getLang());
$combArray = array(); $combArray = array();
$assocNames = array(); $assocNames = array();
$combinaisons = $product->getAttributeCombinaisons((int)($this->getLang())); $combinaisons = $product->getAttributeCombinaisons((int)$this->getLang());
foreach ($combinaisons AS $k => $combinaison) foreach ($combinaisons as $k => $combinaison)
$combArray[$combinaison['id_product_attribute']][] = array('group' => $combinaison['group_name'], 'attr' => $combinaison['attribute_name']); $combArray[$combinaison['id_product_attribute']][] = array('group' => $combinaison['group_name'], 'attr' => $combinaison['attribute_name']);
foreach ($combArray AS $id_product_attribute => $product_attribute) foreach ($combArray as $id_product_attribute => $product_attribute)
{ {
$list = ''; $list = '';
foreach ($product_attribute AS $attribute) foreach ($product_attribute as $attribute)
$list .= trim($attribute['group']).' - '.trim($attribute['attr']).', '; $list .= trim($attribute['group']).' - '.trim($attribute['attr']).', ';
$list = rtrim($list, ', '); $list = rtrim($list, ', ');
$assocNames[$id_product_attribute] = $list; $assocNames[$id_product_attribute] = $list;
@@ -378,8 +386,8 @@ class StatsProduct extends ModuleGraph
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($this->_query); $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($this->_query);
foreach ($result as $row) foreach ($result as $row)
{ {
$this->_values[] = $row['total']; $this->_values[] = $row['total'];
$this->_legend[] = @$assocNames[$row['product_attribute_id']]; $this->_legend[] = @$assocNames[$row['product_attribute_id']];
} }
} }
} }
@@ -389,8 +397,8 @@ class StatsProduct extends ModuleGraph
for ($i = 0; $i < $layers; $i++) for ($i = 0; $i < $layers; $i++)
{ {
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($this->_query[$i]); $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($this->_query[$i]);
foreach ($result AS $row) foreach ($result as $row)
$this->_values[$i][(int)(substr($row['date_add'], 0, 4))] += $row['total']; $this->_values[$i][(int)(substr($row['date_add'], 0, 4))] += $row['total'];
} }
} }
@@ -399,8 +407,8 @@ class StatsProduct extends ModuleGraph
for ($i = 0; $i < $layers; $i++) for ($i = 0; $i < $layers; $i++)
{ {
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($this->_query[$i]); $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($this->_query[$i]);
foreach ($result AS $row) foreach ($result as $row)
$this->_values[$i][(int)(substr($row['date_add'], 5, 2))] += $row['total']; $this->_values[$i][(int)(substr($row['date_add'], 5, 2))] += $row['total'];
} }
} }
@@ -409,8 +417,8 @@ class StatsProduct extends ModuleGraph
for ($i = 0; $i < $layers; $i++) for ($i = 0; $i < $layers; $i++)
{ {
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($this->_query[$i]); $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($this->_query[$i]);
foreach ($result AS $row) foreach ($result as $row)
$this->_values[$i][(int)(substr($row['date_add'], 8, 2))] += $row['total']; $this->_values[$i][(int)(substr($row['date_add'], 8, 2))] += $row['total'];
} }
} }
@@ -419,8 +427,8 @@ class StatsProduct extends ModuleGraph
for ($i = 0; $i < $layers; $i++) for ($i = 0; $i < $layers; $i++)
{ {
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($this->_query[$i]); $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($this->_query[$i]);
foreach ($result AS $row) foreach ($result as $row)
$this->_values[$i][(int)(substr($row['date_add'], 11, 2))] += $row['total']; $this->_values[$i][(int)(substr($row['date_add'], 11, 2))] += $row['total'];
} }
} }
} }
@@ -30,26 +30,26 @@ if (!defined('_PS_VERSION_'))
class StatsRegistrations extends ModuleGraph class StatsRegistrations extends ModuleGraph
{ {
private $_html = ''; private $_html = '';
private $_query = ''; private $_query = '';
function __construct() function __construct()
{ {
$this->name = 'statsregistrations'; $this->name = 'statsregistrations';
$this->tab = 'analytics_stats'; $this->tab = 'analytics_stats';
$this->version = 1.0; $this->version = 1.0;
$this->author = 'PrestaShop'; $this->author = 'PrestaShop';
$this->need_instance = 0; $this->need_instance = 0;
parent::__construct(); parent::__construct();
$this->displayName = $this->l('Customer accounts'); $this->displayName = $this->l('Customer accounts');
$this->description = $this->l('Display the progress of customer registration.'); $this->description = $this->l('Display the progress of customer registration.');
} }
/** /**
* Called during module installation * Called during module installation
*/ */
public function install() public function install()
{ {
return (parent::install() AND $this->registerHook('AdminStatsModules')); return (parent::install() AND $this->registerHook('AdminStatsModules'));
@@ -109,16 +109,16 @@ class StatsRegistrations extends ModuleGraph
if (Tools::getValue('export')) if (Tools::getValue('export'))
$this->csvExport(array('layers' => 0, 'type' => 'line')); $this->csvExport(array('layers' => 0, 'type' => 'line'));
$this->_html = ' $this->_html = '
<fieldset class="width3"><legend><img src="../modules/'.$this->name.'/logo.gif" /> '.$this->displayName.'</legend> <fieldset><legend><img src="../modules/'.$this->name.'/logo.gif" /> '.$this->displayName.'</legend>
<p> <p>
'.$this->l('Visitors who have stopped at the registering step:').' '.(int)($totalBlocked).($totalRegistrations ? ' ('.number_format(100*$totalBlocked/($totalRegistrations+$totalBlocked), 2).'%)' : '').'<br /> '.$this->l('Visitors who have stopped at the registering step:').' '.(int)($totalBlocked).($totalRegistrations ? ' ('.number_format(100*$totalBlocked/($totalRegistrations+$totalBlocked), 2).'%)' : '').'<br />
'.$this->l('Visitors who have placed an order directly after registration:').' '.(int)($totalBuyers).($totalRegistrations ? ' ('.number_format(100*$totalBuyers/($totalRegistrations), 2).'%)' : '').' '.$this->l('Visitors who have placed an order directly after registration:').' '.(int)($totalBuyers).($totalRegistrations ? ' ('.number_format(100*$totalBuyers/($totalRegistrations), 2).'%)' : '').'
</p> </p>
<p>'.$this->l('Total customer accounts:').' '.$totalRegistrations.'</p> <p>'.$this->l('Total customer accounts:').' '.$totalRegistrations.'</p>
<center>'.$this->engine(array('type' => 'line')).'</center> <div>'.$this->engine(array('type' => 'line')).'</div>
<p><a href="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'&export=1"><img src="../img/admin/asterisk.gif" />'.$this->l('CSV Export').'</a></p> <p><a href="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'&export=1"><img src="../img/admin/asterisk.gif" />'.$this->l('CSV Export').'</a></p>
</fieldset><br /> </fieldset><br />
<fieldset class="width3"><legend><img src="../img/admin/comment.gif" /> '.$this->l('Guide').'</legend> <fieldset><legend><img src="../img/admin/comment.gif" /> '.$this->l('Guide').'</legend>
<h2>'.$this->l('Number of customer accounts created').'</h2> <h2>'.$this->l('Number of customer accounts created').'</h2>
<p>'.$this->l('The total number of accounts created is not in itself important information. However, it is beneficial to analyze the number created over time. This will indicate whether or not things are on the right track.').'</p> <p>'.$this->l('The total number of accounts created is not in itself important information. However, it is beneficial to analyze the number created over time. This will indicate whether or not things are on the right track.').'</p>
<br /><h3>'.$this->l('How to act on the registrations\' evolution?').'</h3> <br /><h3>'.$this->l('How to act on the registrations\' evolution?').'</h3>
@@ -152,7 +152,7 @@ class StatsRegistrations extends ModuleGraph
{ {
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($this->_query.$this->getDate()); $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($this->_query.$this->getDate());
foreach ($result AS $row) foreach ($result AS $row)
$this->_values[(int)(substr($row['date_add'], 0, 4))]++; $this->_values[(int)(substr($row['date_add'], 0, 4))]++;
} }
protected function setYearValues($layers) protected function setYearValues($layers)
@@ -178,7 +178,7 @@ class StatsRegistrations extends ModuleGraph
{ {
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($this->_query.$this->getDate()); $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($this->_query.$this->getDate());
foreach ($result AS $row) foreach ($result AS $row)
$this->_values[(int)(substr($row['date_add'], 11, 2))]++; $this->_values[(int)(substr($row['date_add'], 11, 2))]++;
} }
} }
+22 -22
View File
@@ -30,25 +30,25 @@ if (!defined('_PS_VERSION_'))
class StatsSales extends ModuleGraph class StatsSales extends ModuleGraph
{ {
private $_html = ''; private $_html = '';
private $_query = ''; private $_query = '';
private $_query2 = ''; private $_query2 = '';
private $_option = ''; private $_option = '';
private $id_country = ''; private $id_country = '';
function __construct() function __construct()
{ {
$this->name = 'statssales'; $this->name = 'statssales';
$this->tab = 'analytics_stats'; $this->tab = 'analytics_stats';
$this->version = 1.0; $this->version = 1.0;
$this->author = 'PrestaShop'; $this->author = 'PrestaShop';
$this->need_instance = 0; $this->need_instance = 0;
parent::__construct(); parent::__construct();
$this->displayName = $this->l('Sales and orders'); $this->displayName = $this->l('Sales and orders');
$this->description = $this->l('Display the sales evolution and orders by statuses'); $this->description = $this->l('Display the sales evolution and orders by statuses');
} }
public function install() public function install()
{ {
@@ -67,7 +67,7 @@ class StatsSales extends ModuleGraph
$this->csvExport(array('type' => 'pie', 'option' => '3-'.(int)Tools::getValue('id_country'))); $this->csvExport(array('type' => 'pie', 'option' => '3-'.(int)Tools::getValue('id_country')));
$this->_html = ' $this->_html = '
<fieldset class="width3"><legend><img src="../modules/'.$this->name.'/logo.gif" /> '.$this->displayName.'</legend> <fieldset><legend><img src="../modules/'.$this->name.'/logo.gif" /> '.$this->displayName.'</legend>
<form action="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'" method="post" style="float: right; margin-left: 10px;"> <form action="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'" method="post" style="float: right; margin-left: 10px;">
<select name="id_country"> <select name="id_country">
<option value="0"'.((!Tools::getValue('id_order_state')) ? ' selected="selected"' : '').'>'.$this->l('All').'</option>'; <option value="0"'.((!Tools::getValue('id_order_state')) ? ' selected="selected"' : '').'>'.$this->l('All').'</option>';
@@ -76,15 +76,15 @@ class StatsSales extends ModuleGraph
$this->_html .= '</select> $this->_html .= '</select>
<input type="submit" name="submitCountry" value="'.$this->l('Filter').'" class="button" /> <input type="submit" name="submitCountry" value="'.$this->l('Filter').'" class="button" />
</form> </form>
<p><center><img src="../img/admin/down.gif" /> <p><img src="../img/admin/down.gif" />
'.$this->l('These graphs represent the evolution of your orders and sales turnover for a given period. This tool allows for quick overview of the viability of your shop. You can also keep watch on the difference between time periods (like the holiday season). Only valid orders are included in these two graphs.').' '.$this->l('These graphs represent the evolution of your orders and sales turnover for a given period. This tool allows for quick overview of the viability of your shop. You can also keep watch on the difference between time periods (like the holiday season). Only valid orders are included in these two graphs.').'
</center></p> </p>
<p>'.$this->l('Orders placed:').' '.(int)($totals['orderCount']).'</p> <p>'.$this->l('Orders placed:').' '.(int)($totals['orderCount']).'</p>
<p>'.$this->l('Products bought:').' '.(int)($totals['products']).'</p> <p>'.$this->l('Products bought:').' '.(int)($totals['products']).'</p>
<center>'.$this->engine(array('type' => 'line', 'option' => '1-'.(int)Tools::getValue('id_country'), 'layers' => 2)).'</center> <div>'.$this->engine(array('type' => 'line', 'option' => '1-'.(int)Tools::getValue('id_country'), 'layers' => 2)).'</div>
<p><a href="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'&export=1"><img src="../img/admin/asterisk.gif" alt="" />'.$this->l('CSV Export').'</a></p> <p><a href="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'&export=1"><img src="../img/admin/asterisk.gif" alt="" />'.$this->l('CSV Export').'</a></p>
<p>'.$this->l('Sales:').' '.Tools::displayPrice($totals['orderSum'], $currency).'</p> <p>'.$this->l('Sales:').' '.Tools::displayPrice($totals['orderSum'], $currency).'</p>
<center>'.$this->engine(array('type' => 'line', 'option' => '2-'.(int)Tools::getValue('id_country'))).'</center></p> <div>'.$this->engine(array('type' => 'line', 'option' => '2-'.(int)Tools::getValue('id_country'))).'</div>
<p><a href="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'&export=2"><img src="../img/admin/asterisk.gif" alt="" />'.$this->l('CSV Export').'</a></p> <p><a href="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'&export=2"><img src="../img/admin/asterisk.gif" alt="" />'.$this->l('CSV Export').'</a></p>
<p class="space"><img src="../img/admin/down.gif" /> <p class="space"><img src="../img/admin/down.gif" />
'.$this->l('You can see the order state distribution below.').' '.$this->l('You can see the order state distribution below.').'
@@ -92,8 +92,8 @@ class StatsSales extends ModuleGraph
'.($totals['orderCount'] ? $this->engine(array('type' => 'pie', 'option' => '3-'.(int)Tools::getValue('id_country'))) : $this->l('No orders for this period.')).'</center> '.($totals['orderCount'] ? $this->engine(array('type' => 'pie', 'option' => '3-'.(int)Tools::getValue('id_country'))) : $this->l('No orders for this period.')).'</center>
<p><a href="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'&export=3"><img src="../img/admin/asterisk.gif" />'.$this->l('CSV Export').'</a></p> <p><a href="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'&export=3"><img src="../img/admin/asterisk.gif" />'.$this->l('CSV Export').'</a></p>
</fieldset> </fieldset>
<br class="clear" /> <br />
<fieldset class="width3"><legend><img src="../img/admin/comment.gif" /> '.$this->l('Guide').'</legend> <fieldset><legend><img src="../img/admin/comment.gif" /> '.$this->l('Guide').'</legend>
<h2>'.$this->l('Various order statuses').'</h2> <h2>'.$this->l('Various order statuses').'</h2>
<p> <p>
'.$this->l('In your back-office, you can find the following order statuses : Awaiting check payment, Payment accepted, Preparation in progress, Shipping, Delivered, Cancelled, Refund, Payment error, Out of stock, and Awaiting bank wire payment.').'<br /> '.$this->l('In your back-office, you can find the following order statuses : Awaiting check payment, Payment accepted, Preparation in progress, Shipping, Delivered, Cancelled, Refund, Payment error, Out of stock, and Awaiting bank wire payment.').'<br />
@@ -248,8 +248,8 @@ class StatsSales extends ModuleGraph
GROUP BY oh.`id_order_state`'); GROUP BY oh.`id_order_state`');
foreach ($result as $row) foreach ($result as $row)
{ {
$this->_values[] = $row['total']; $this->_values[] = $row['total'];
$this->_legend[] = $row['name']; $this->_legend[] = $row['name'];
} }
} }
} }
+23 -23
View File
@@ -30,15 +30,15 @@ if (!defined('_PS_VERSION_'))
class StatsSearch extends ModuleGraph class StatsSearch extends ModuleGraph
{ {
private $_html = ''; private $_html = '';
private $_query = ''; private $_query = '';
private $_query2 = ''; private $_query2 = '';
function __construct() public function __construct()
{ {
$this->name = 'statssearch'; $this->name = 'statssearch';
$this->tab = 'analytics_stats'; $this->tab = 'analytics_stats';
$this->version = 1.0; $this->version = 1.0;
$this->author = 'PrestaShop'; $this->author = 'PrestaShop';
$this->need_instance = 0; $this->need_instance = 0;
@@ -54,13 +54,13 @@ class StatsSearch extends ModuleGraph
HAVING occurences > 1 HAVING occurences > 1
ORDER BY occurences DESC'; ORDER BY occurences DESC';
$this->displayName = $this->l('Shop search'); $this->displayName = $this->l('Shop search');
$this->description = $this->l('Display which keywords have been searched by your visitors.'); $this->description = $this->l('Display which keywords have been searched by your visitors.');
} }
function install() public function install()
{ {
if (!parent::install() OR !$this->registerHook('search') OR !$this->registerHook('AdminStatsModules')) if (!parent::install() || !$this->registerHook('search') || !$this->registerHook('AdminStatsModules'))
return false; return false;
return Db::getInstance()->execute(' return Db::getInstance()->execute('
CREATE TABLE `'._DB_PREFIX_.'statssearch` ( CREATE TABLE `'._DB_PREFIX_.'statssearch` (
@@ -74,31 +74,31 @@ class StatsSearch extends ModuleGraph
) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8'); ) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8');
} }
function uninstall() public function uninstall()
{ {
if (!parent::uninstall()) if (!parent::uninstall())
return false; return false;
return (Db::getInstance()->execute('DROP TABLE `'._DB_PREFIX_.'statssearch`')); return (Db::getInstance()->execute('DROP TABLE `'._DB_PREFIX_.'statssearch`'));
} }
/** /**
* Insert keywords in statssearch table when a search is launched on FO * Insert keywords in statssearch table when a search is launched on FO
*/ */
function hookSearch($params) public function hookSearch($params)
{ {
$sql = 'INSERT INTO `'._DB_PREFIX_.'statssearch` (`id_shop`, `id_group_shop`, `keywords`, `results`, `date_add`) $sql = 'INSERT INTO `'._DB_PREFIX_.'statssearch` (`id_shop`, `id_group_shop`, `keywords`, `results`, `date_add`)
VALUES ('.$this->context->shop->getID(true).', '.$this->context->shop->getGroupID().', \''.pSQL($params['expr']).'\', '.(int)$params['total'].', NOW())'; VALUES ('.$this->context->shop->getID(true).', '.$this->context->shop->getGroupID().', \''.pSQL($params['expr']).'\', '.(int)$params['total'].', NOW())';
Db::getInstance()->execute($sql); Db::getInstance()->execute($sql);
} }
function hookAdminStatsModules() public function hookAdminStatsModules()
{ {
if (Tools::getValue('export')) if (Tools::getValue('export'))
$this->csvExport(array('type' => 'pie')); $this->csvExport(array('type' => 'pie'));
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($this->_query.ModuleGraph::getDateBetween().$this->_query2); $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($this->_query.ModuleGraph::getDateBetween().$this->_query2);
$this->_html = ' $this->_html = '
<fieldset class="width3"><legend><img src="../modules/'.$this->name.'/logo.gif" /> '.$this->displayName.'</legend>'; <fieldset><legend><img src="../modules/'.$this->name.'/logo.gif" /> '.$this->displayName.'</legend>';
$table = '<div style="overflow-y: scroll; height: 600px;"> $table = '<div style="overflow-y: scroll; height: 600px;">
<table class="table" border="0" cellspacing="0" cellspacing="0"> <table class="table" border="0" cellspacing="0" cellspacing="0">
<thead> <thead>
@@ -120,8 +120,8 @@ class StatsSearch extends ModuleGraph
} }
$table .= '</tbody></table></div>'; $table .= '</tbody></table></div>';
if (sizeof($result)) if (count($result))
$this->_html .= '<center>'.$this->engine(array('type' => 'pie')).'</center> $this->_html .= '<div>'.$this->engine(array('type' => 'pie')).'</div>
<p><a href="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'&export=1"><img src="../img/admin/asterisk.gif" />'.$this->l('CSV Export').'</a></p> <p><a href="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'&export=1"><img src="../img/admin/asterisk.gif" />'.$this->l('CSV Export').'</a></p>
<br class="clear" />'.$table; <br class="clear" />'.$table;
else else
+34 -27
View File
@@ -30,31 +30,33 @@ if (!defined('_PS_VERSION_'))
class StatsStock extends Module class StatsStock extends Module
{ {
function __construct() private $html = '';
{
$this->name = 'statsstock'; public function __construct()
$this->tab = 'analytics_stats'; {
$this->version = 1.0; $this->name = 'statsstock';
$this->tab = 'analytics_stats';
$this->version = 1.0;
$this->author = 'PrestaShop'; $this->author = 'PrestaShop';
$this->need_instance = 0; $this->need_instance = 0;
parent::__construct(); parent::__construct();
$this->displayName = $this->l('Stock stats'); $this->displayName = $this->l('Stock stats');
$this->description = ''; $this->description = '';
} }
public function install() public function install()
{ {
return (parent::install() && $this->registerHook('AdminStatsModules')); return parent::install() && $this->registerHook('AdminStatsModules');
} }
function hookAdminStatsModules() public function hookAdminStatsModules()
{ {
if (Tools::isSubmit('submitCategory')) if (Tools::isSubmit('submitCategory'))
$this->context->cookie->statsstock_id_category = Tools::getValue('statsstock_id_category'); $this->context->cookie->statsstock_id_category = Tools::getValue('statsstock_id_category');
$ru = AdminTab::$currentIndex.'&module='.$this->name.'&token='.Tools::getValue('token'); $ru = AdminController::$currentIndex.'&module='.$this->name.'&token='.Tools::getValue('token');
$currency = new Currency(Configuration::get('PS_CURRENCY_DEFAULT')); $currency = new Currency(Configuration::get('PS_CURRENCY_DEFAULT'));
$filter = ((int)$this->context->cookie->statsstock_id_category ? ' AND p.id_product IN (SELECT cp.id_product FROM '._DB_PREFIX_.'category_product cp WHERE cp.id_category = '.(int)$this->context->cookie->statsstock_id_category.')' : ''); $filter = ((int)$this->context->cookie->statsstock_id_category ? ' AND p.id_product IN (SELECT cp.id_product FROM '._DB_PREFIX_.'category_product cp WHERE cp.id_category = '.(int)$this->context->cookie->statsstock_id_category.')' : '');
@@ -74,30 +76,33 @@ class StatsStock extends Module
), p.wholesale_price * p.quantity) as stockvalue ), p.wholesale_price * p.quantity) as stockvalue
FROM '._DB_PREFIX_.'product p FROM '._DB_PREFIX_.'product p
'.$this->context->shop->addSqlAssociation('product', 'p').' '.$this->context->shop->addSqlAssociation('product', 'p').'
INNER JOIN '._DB_PREFIX_.'product_lang pl ON (p.id_product = pl.id_product AND pl.id_lang = '.(int)$this->context->language->id.$this->context->shop->addSqlRestrictionOnLang('pl').') INNER JOIN '._DB_PREFIX_.'product_lang pl
ON (p.id_product = pl.id_product AND pl.id_lang = '.(int)$this->context->language->id.$this->context->shop->addSqlRestrictionOnLang('pl').')
WHERE 1 = 1 WHERE 1 = 1
'.$filter; '.$filter;
$products = Db::getInstance()->executeS($sql); $products = Db::getInstance()->executeS($sql);
echo ' $this->html .= '
<script type="text/javascript">$(\'#calendar\').slideToggle();</script> <script type="text/javascript">$(\'#calendar\').slideToggle();</script>
<h2 style="float:left">'.$this->l('Stock value').'</h2> <fieldset><legend><img src="../modules/'.$this->name.'/logo.gif" /> '.$this->l('Stock value').'</legend>
<form action="'.$ru.'" method="post" style="float:right"> <form action="'.$ru.'" method="post">
<input type="hidden" name="submitCategory" value="1" /> <input type="hidden" name="submitCategory" value="1" />
'.$this->l('Category').' : <select name="statsstock_id_category" onchange="this.form.submit();"> '.$this->l('Category').' : <select name="statsstock_id_category" onchange="this.form.submit();">
<option value="0">-- '.$this->l('All').' --</option>'; <option value="0">-- '.$this->l('All').' --</option>';
foreach (Category::getSimpleCategories($this->context->language->id) as $category) foreach (Category::getSimpleCategories($this->context->language->id) as $category)
echo '<option value="'.(int)$category['id_category'].'" '.($this->context->cookie->statsstock_id_category == $category['id_category'] ? 'selected="selected"' : '').'>'.$category['name'].'</option>'; $this->html .= '<option value="'.(int)$category['id_category'].'" '.
echo ' </select> ($this->context->cookie->statsstock_id_category == $category['id_category'] ? 'selected="selected"' : '').'>'.
</form> $category['name'].'
<div style="clear:both">&nbsp;</div>'; </option>';
$this->html .= '</select>
</form><br />';
if (!count($products)) if (!count($products))
echo $this->l('Your catalog is empty.'); $this->html .= $this->l('Your catalog is empty.');
else else
{ {
$rollup = array('quantity' => 0, 'wholesale_price' => 0, 'stockvalue' => 0); $rollup = array('quantity' => 0, 'wholesale_price' => 0, 'stockvalue' => 0);
echo '<table class="table" cellspacing="0" cellpadding="0"> $this->html .= '<table class="table" cellspacing="0" cellpadding="0">
<tr> <tr>
<th>'.$this->l('ID').'</th> <th>'.$this->l('ID').'</th>
<th>'.$this->l('Ref.').'</th> <th>'.$this->l('Ref.').'</th>
@@ -111,7 +116,7 @@ class StatsStock extends Module
$rollup['quantity'] += $product['quantity']; $rollup['quantity'] += $product['quantity'];
$rollup['wholesale_price'] += $product['wholesale_price']; $rollup['wholesale_price'] += $product['wholesale_price'];
$rollup['stockvalue'] += $product['stockvalue']; $rollup['stockvalue'] += $product['stockvalue'];
echo '<tr> $this->html .= '<tr>
<td>'.$product['id_product'].'</td> <td>'.$product['id_product'].'</td>
<td>'.$product['reference'].'</td> <td>'.$product['reference'].'</td>
<td>'.$product['name'].'</td> <td>'.$product['name'].'</td>
@@ -120,7 +125,7 @@ class StatsStock extends Module
<td>'.Tools::displayPrice($product['stockvalue'], $currency).'</td> <td>'.Tools::displayPrice($product['stockvalue'], $currency).'</td>
</tr>'; </tr>';
} }
echo ' $this->html .= '
<tr> <tr>
<th colspan="3"></th> <th colspan="3"></th>
<th>'.$this->l('Total stock').'</th> <th>'.$this->l('Total stock').'</th>
@@ -134,7 +139,9 @@ class StatsStock extends Module
<td>'.Tools::displayPrice($rollup['stockvalue'], $currency).'</td> <td>'.Tools::displayPrice($rollup['stockvalue'], $currency).'</td>
</tr> </tr>
</table> </table>
<p>* '.$this->l('Average price when the product has attributes.').'</p>'; <p>* '.$this->l('Average price when the product has attributes.').'</p></fieldset>';
return $this->html;
} }
} }
} }