From 68fc8b4e12e4368130adcc8ab4da3f3e3e107a55 Mon Sep 17 00:00:00 2001 From: lLefevre Date: Thu, 10 Nov 2011 15:53:47 +0000 Subject: [PATCH] [*] BO : #PSFV-94 - added AdminReferrersController git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@10046 b9a71923-0436-4b27-9f14-aed3839534dd --- admin-dev/ajax.php | 2 +- admin-dev/tabs/AdminReferrers.php | 471 ---------------- .../themes/template/helper/form/form.tpl | 508 +++++++++--------- .../template/helper/list/list_header.tpl | 2 + admin-dev/themes/template/referrers/form.tpl | 122 +++++ .../template/referrers/form_settings.tpl | 65 +++ .../themes/template/referrers/list_header.tpl | 95 ++++ admin-dev/themes/template/referrers/view.tpl | 134 +++++ admin-dev/themes/template/stats/calendar.tpl | 4 +- admin-dev/themes/template/stats/engines.tpl | 4 +- admin-dev/themes/template/stats/view.tpl | 64 +++ classes/AdminController.php | 26 +- classes/HelperForm.php | 24 +- classes/Referrer.php | 165 +++--- .../admin/AdminReferrersController.php | 467 ++++++++++++++++ controllers/admin/AdminStatsTabController.php | 30 +- 16 files changed, 1361 insertions(+), 822 deletions(-) delete mode 100644 admin-dev/tabs/AdminReferrers.php create mode 100644 admin-dev/themes/template/referrers/form.tpl create mode 100644 admin-dev/themes/template/referrers/form_settings.tpl create mode 100644 admin-dev/themes/template/referrers/list_header.tpl create mode 100644 admin-dev/themes/template/referrers/view.tpl create mode 100644 admin-dev/themes/template/stats/view.tpl create mode 100644 controllers/admin/AdminReferrersController.php diff --git a/admin-dev/ajax.php b/admin-dev/ajax.php index f171ff0f1..52b90a571 100644 --- a/admin-dev/ajax.php +++ b/admin-dev/ajax.php @@ -87,7 +87,7 @@ if (Tools::isSubmit('ajaxProductManufacturers')) if (Tools::isSubmit('ajaxReferrers')) { - require('tabs/AdminReferrers.php'); + require(_PS_CONTROLLER_DIR_.'admin/AdminReferrersController.php'); } if (Tools::isSubmit('ajaxProductSuppliers')) diff --git a/admin-dev/tabs/AdminReferrers.php b/admin-dev/tabs/AdminReferrers.php deleted file mode 100644 index ac52b5b72..000000000 --- a/admin-dev/tabs/AdminReferrers.php +++ /dev/null @@ -1,471 +0,0 @@ - -* @copyright 2007-2011 PrestaShop SA -* @version Release: $Revision: 6844 $ -* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) -* International Registered Trademark & Property of PrestaShop SA -*/ - -if (!defined('_PS_ADMIN_DIR_')) define('_PS_ADMIN_DIR_', getcwd().'/..'); - -if (Tools::getValue('token') == Tools::getAdminToken('AdminReferrers'.(int)(Tab::getIdFromClassName('AdminReferrers')).(int)(Tools::getValue('id_employee')))) -{ - if (Tools::isSubmit('ajaxProductFilter')) - Referrer::getAjaxProduct((int)(Tools::getValue('id_referrer')), (int)(Tools::getValue('id_product')), new Employee((int)(Tools::getValue('id_employee')))); - else if (Tools::isSubmit('ajaxFillProducts')) - { - $jsonArray = array(); - $result = Db::getInstance()->executeS(' - SELECT p.id_product, pl.name - FROM '._DB_PREFIX_.'product p - LEFT JOIN '._DB_PREFIX_.'product_lang pl ON (p.id_product = pl.id_product AND pl.id_lang = '.(int)(Tools::getValue('id_lang')).') - '.(Tools::getValue('filter') != 'undefined' ? 'WHERE name LIKE "%'.pSQL(Tools::getValue('filter')).'%"' : '')); - foreach ($result as $row) - $jsonArray[] = '{id_product:'.(int)($row['id_product']).',name:\''.addslashes($row['name']).'\'}'; - die ('['.implode(',', $jsonArray).']'); - } -} - -include_once(dirname(__FILE__).'/AdminStats.php'); - -class AdminReferrers extends AdminTab -{ - public function __construct() - { - $this->table = 'referrer'; - $this->className = 'Referrer'; - $this->view = true; - $this->edit = true; - $this->delete = true; - - parent::__construct(); - - $this->_select = 'SUM(sa.cache_visitors) AS cache_visitors, SUM(sa.cache_visits) AS cache_visits, SUM(sa.cache_pages) AS cache_pages, - SUM(sa.cache_registrations) AS cache_registrations, SUM(sa.cache_orders) AS cache_orders, SUM(sa.cache_sales) AS cache_sales, - IF(sa.cache_orders > 0, ROUND(sa.cache_sales/sa.cache_orders, 2), 0) as cart, (sa.cache_visits*click_fee) as fee0, - (sa.cache_orders*base_fee) as fee1, (sa.cache_sales*percent_fee/100) as fee2'; - $this->_join = 'LEFT JOIN `'._DB_PREFIX_.'referrer_shop` sa ON (sa.'.$this->identifier.' = a.'.$this->identifier.' AND sa.id_shop IN ('.implode(', ', $this->context->shop->getListOfID()).'))'; - $this->_group = 'GROUP BY sa.id_referrer'; - $this->fieldsDisplay = array( - 'id_referrer' => array('title' => $this->l('ID'), 'width' => 25, 'align' => 'center'), - 'name' => array('title' => $this->l('Name'), 'width' => 80), - 'cache_visitors' => array('title' => $this->l('Visitors'), 'width' => 30, 'align' => 'center'), - 'cache_visits' => array('title' => $this->l('Visits'), 'width' => 30, 'align' => 'center'), - 'cache_pages' => array('title' => $this->l('Pages'), 'width' => 30, 'align' => 'center'), - 'cache_registrations' => array('title' => $this->l('Reg.'), 'width' => 30, 'align' => 'center'), - 'cache_orders' => array('title' => $this->l('Ord.'), 'width' => 30, 'align' => 'center'), - 'cache_sales' => array('title' => $this->l('Sales'), 'width' => 80, 'align' => 'right', 'prefix' => '', 'suffix' => '', 'price' => true), - 'cart' => array('title' => $this->l('Avg. cart'), 'width' => 50, 'align' => 'right', 'price' => true), - 'cache_reg_rate' => array('title' => $this->l('Reg. rate'), 'width' => 30, 'align' => 'center'), - 'cache_order_rate' => array('title' => $this->l('Order rate'), 'width' => 30, 'align' => 'center'), - 'fee0' => array('title' => $this->l('Click'), 'width' => 30, 'align' => 'right', 'price' => true), - 'fee1' => array('title' => $this->l('Base'), 'width' => 30, 'align' => 'right', 'price' => true), - 'fee2' => array('title' => $this->l('Percent'), 'width' => 30, 'align' => 'right', 'price' => true)); - } - - private function enableCalendar() - { - return (!Tools::isSubmit('add'.$this->table) AND !Tools::isSubmit('submitAdd'.$this->table) AND !Tools::isSubmit('update'.$this->table)); - } - - public function displayJavascript() - { - $products = Product::getSimpleProducts($this->context->language->id); - $productsArray = array(); - foreach ($products as $product) - $productsArray[] = $product['id_product']; - - return ' - '; - } - - public function display() - { - if (!Tools::isSubmit('viewreferrer')) - echo $this->displayJavascript(); - - if ($this->enableCalendar()) - { - echo ' -
- '.AdminStatsTab::displayCalendarStatic(array('Calendar' => $this->l('Calendar'), 'Day' => $this->l('Today'), 'Month' => $this->l('Month'), 'Year' => $this->l('Year'))).' -
'; - if (!Tools::isSubmit('viewreferrer')) - echo ' -
-
'.$this->l('Settings').' -
- -
- - - - - - -
-
-

'.$this->l('Direct traffic can be quite consuming. You should consider enabling it only if you have a strong database server and a strong need for it.').'

- -
-
-
-

'.$this->l('Indexation').'

-

'.$this->l('There is a huge quantity of data, so each connection corresponding to a referrer is indexed. You can refresh this index by clicking on the button below. Be aware that it may take a long time and it is only needed if you modified or added a referrer and if you want your changes to be retroactive.').'

- -
-
-
-

'.$this->l('Cache').'

-

'.$this->l('For you to sort and filter your data, it is cached. You can refresh the cache by clicking on the button below.').'

- -
-
-
'; - } - echo '
 
'; - parent::display(); - echo '
 
'; - } - - public function postProcess() - { - if ($this->enableCalendar()) - { - $calendarTab = new AdminStats(); - $calendarTab->postProcess(); - } - - if (Tools::isSubmit('submitSettings')) - if ($this->tabAccess['edit'] === '1') - if (Configuration::updateValue('TRACKING_DIRECT_TRAFFIC', (int)(Tools::getValue('tracking_dt')))) - Tools::redirectAdmin(self::$currentIndex.'&conf=4&token='.Tools::getValue('token')); - - if (ModuleGraph::getDateBetween() != Configuration::get('PS_REFERRERS_CACHE_LIKE') OR Tools::isSubmit('submitRefreshCache')) - Referrer::refreshCache(); - if (Tools::isSubmit('submitRefreshIndex')) - Referrer::refreshIndex(); - - return parent::postProcess(); - } - - public function displayForm($isMainTab = true) - { - parent::displayForm(); - - if (!($obj = $this->loadObject(true))) - return; - foreach (array('http_referer_like', 'http_referer_regexp', 'request_uri_like', 'request_uri_regexp') as $field) - $obj->{$field} = str_replace('\\', '\\\\', $obj->{$field}); - $uri = Tools::getHttpHost(true, true).__PS_BASE_URI__; - - echo ' -
- '.($obj->id ? '' : '').' -
'.$this->l('Affiliate').' - -
- * -
- -
- -

'.$this->l('Leave blank if no change').'

-
-

- '.$this->l('Affiliates can access their own data with this name and password.').'
- '.$this->l('Front access:').' '.$uri.'modules/trackingfront/stats.php -

-
-
-
'.$this->l('Commission plan').' - -
- -

'.$this->l('Fee given for each visit.').'

-
- -
- -

'.$this->l('Fee given for each order placed.').'

-
- -
- -

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

-
'; - if (Shop::isFeatureActive()) - { - echo '
'; - $this->displayAssoShop(); - echo '
'; - } - echo '
-
-
'.$this->l('Help').' - -
-
-
'.$this->l('Technical information - Simple mode').' - '.$this->l('Get help!').'
-
-

'.$this->l('HTTP referrer').'

- -
- -
- -
- -
-

'.$this->l('Request Uri').'

- -
- -
- -
- -
-
-
- -
-
- '.$this->l('If you know how to use MySQL regular expressions, you can use the').' '.$this->l('expert mode').'. -
-
-
'.$this->l('Technical information - Expert mode').' - -
-
-
'; - } - - public function viewreferrer() - { - $referrer = new Referrer((int)(Tools::getValue('id_referrer'))); - - $displayTab = array( - 'uniqs' => $this->l('Unique visitors'), - 'visitors' => $this->l('Visitors'), - 'visits' => $this->l('Visits'), - 'pages' => $this->l('Pages viewed'), - 'registrations' => $this->l('Registrations'), - 'orders' => $this->l('Orders'), - 'sales' => $this->l('Sales'), - 'reg_rate' => $this->l('Registration rate'), - 'order_rate' => $this->l('Order rate'), - 'click_fee' => $this->l('Click fee'), - 'base_fee' => $this->l('Base fee'), - 'percent_fee' => $this->l('Percent fee')); - echo ' - -
Statistics -

'.$referrer->name.'

- '; - foreach ($displayTab as $data => $label) - echo ''; - echo '
'.$label.'
-
-
- '.$this->l('Filter by product:').' - -
-
- '; - } - - public function displayListContent($token = NULL) - { - $irow = 0; - if ($this->_list) - foreach ($this->_list AS $tr) - { - $id = $tr[$this->identifier]; - echo ' - '; - foreach ($this->fieldsDisplay AS $key => $params) - { - echo ''.(isset($params['prefix']) ? $params['prefix'] : ''); - if (isset($tr[$key]) AND isset($params['price'])) - echo Tools::displayPrice($tr[$key], $this->context->currency); - elseif (isset($tr[$key])) - echo $tr[$key]; - else - echo '--'; - echo (isset($params['suffix']) ? $params['suffix'] : '').''; - } - echo ' - - - '.$this->l('View').' - - '.$this->l('Edit').' - - '.$this->l('Delete').' - '; - } - } -} - - diff --git a/admin-dev/themes/template/helper/form/form.tpl b/admin-dev/themes/template/helper/form/form.tpl index f3e77b01d..e6b53d81b 100644 --- a/admin-dev/themes/template/helper/form/form.tpl +++ b/admin-dev/themes/template/helper/form/form.tpl @@ -90,258 +90,276 @@ {if $form_id} {/if} -
- {foreach $fields as $key => $field} - {if $key == 'legend'} - - {if isset($field.image)}{$field.title}{/if} - {$field.title} - - {elseif $key == 'input'} - {foreach $field as $input} - {if $input.name == 'id_state'} -
- {/if} - {block name="label"} - {if isset($input.label)} - + {foreach $fields as $f => $fieldset} +
+ {foreach $fieldset.form as $key => $field} + {if $key == 'legend'} + + {if isset($field.image)}{$field.title}{/if} + {$field.title} + + {elseif $key == 'input'} + {foreach $field as $input} + {if $input.name == 'id_state'} +
{/if} - {/block} - {if $input.type == 'hidden'} - - {else} - {block name="start_field_block"} -
- {/block} - {if $input.type == 'text'} - {if isset($input.lang)} -
- {foreach $languages as $language} -
- - {if isset($input.hint)}{$input.hint} {/if} -
- {/foreach} -
- {else} - - {if isset($input.suffix)}{$input.suffix}{/if} - {if isset($input.hint)}{$input.hint} {/if} + {block name="label"} + {if isset($input.label)} + {/if} - {elseif $input.type == 'select'} - {if isset($input.options.query) && !$input.options.query && isset($input.empty_message)} - {$input.empty_message} - {$input.required = false} - {$input.p = null} - {else} - + {else} + {block name="start_field_block"} +
+ {/block} + {if $input.type == 'text'} + {if isset($input.lang)} +
+ {foreach $languages as $language} +
+ + {if isset($input.hint)}{$input.hint} {/if} +
{/foreach} - {else} - {foreach $input.options.query AS $option} - - {/foreach} - {/if} - - {if isset($input.hint)}{$input.hint} {/if} - {/if} - {elseif $input.type == 'radio'} - {foreach $input.values as $value} - - - {if isset($input.br) && $input.br}
{/if} - {/foreach} - {elseif $input.type == 'textarea'} - {if isset($input.lang)} -
- {foreach $languages as $language} -
- -
- {/foreach} -
- {else} - - {/if} - {elseif $input.type == 'checkbox'} - {foreach $input.values.query as $value} - {assign var=id_checkbox value=$input.name|cat:'_'|cat:$value[$input.values.id]} - -
- {/foreach} - {elseif $input.type == 'file'} - {if isset($input.display_image) && $input.display_image} - {if isset($fields_value.image) && $fields_value.image} -
- {$fields_value.image} -

{l s='File size'} {$fields_value.size}kb

- - {l s='Delete'} {l s='Delete'} - -

- {/if} - {/if} - - {elseif $input.type == 'password'} - - {elseif $input.type == 'birthday'} - {foreach $input.options as $key => $select} - - {/foreach} - {elseif $input.type == 'group'} - {assign var=groups value=$input.values} - {include file='helper/form/form_group.tpl'} - {elseif $input.type == 'shop' OR $input.type == 'group_shop'} - {include file='helper/form/form_shop.tpl'} - {elseif $input.type == 'categories'} - {include file='helper/form/form_category.tpl' categories=$input.values} - {elseif $input.type == 'asso_shop' && isset($asso_shop) && $asso_shop} - {$asso_shop} - {elseif $input.type == 'color'} - - - {elseif $input.type == 'date'} - - - {elseif $input.type == 'free'} - {$fields_value[$input.name]} - {/if} - {if isset($input.required) && $input.required} *{/if} - {if isset($input.p)} -

- {if is_array($input.p)} - {foreach $input.p as $p} - {if is_array($p)} - {$p.text}
- {else} - {$p}
- {/if} - {/foreach} +

{else} - {$input.p} + + {if isset($input.suffix)}{$input.suffix}{/if} + {if isset($input.hint)}{$input.hint} {/if} {/if} -

+ {elseif $input.type == 'select'} + {if isset($input.options.query) && !$input.options.query && isset($input.empty_message)} + {$input.empty_message} + {$input.required = false} + {$input.p = null} + {else} + + {if isset($input.hint)}{$input.hint} {/if} + {/if} + {elseif $input.type == 'radio'} + {foreach $input.values as $value} + + + {if isset($input.br) && $input.br}
{/if} + {/foreach} + {elseif $input.type == 'textarea'} + {if isset($input.lang)} +
+ {foreach $languages as $language} +
+ +
+ {/foreach} +
+ {else} + + {/if} + {elseif $input.type == 'checkbox'} + {foreach $input.values.query as $value} + {assign var=id_checkbox value=$input.name|cat:'_'|cat:$value[$input.values.id]} + +
+ {/foreach} + {elseif $input.type == 'file'} + {if isset($input.display_image) && $input.display_image} + {if isset($fields_value.image) && $fields_value.image} +
+ {$fields_value.image} +

{l s='File size'} {$fields_value.size}kb

+ + {l s='Delete'} {l s='Delete'} + +

+ {/if} + {/if} + + {elseif $input.type == 'password'} + + {elseif $input.type == 'birthday'} + {foreach $input.options as $key => $select} + + {/foreach} + {elseif $input.type == 'group'} + {assign var=groups value=$input.values} + {include file='helper/form/form_group.tpl'} + {elseif $input.type == 'shop' OR $input.type == 'group_shop'} + {include file='helper/form/form_shop.tpl'} + {elseif $input.type == 'categories'} + {include file='helper/form/form_category.tpl' categories=$input.values} + {elseif $input.type == 'asso_shop' && isset($asso_shop) && $asso_shop} + {$asso_shop} + {elseif $input.type == 'color'} + + + {elseif $input.type == 'date'} + + + {elseif $input.type == 'free'} + {$fields_value[$input.name]} + {/if} + {if isset($input.required) && $input.required} *{/if} + {if isset($input.p)} +

+ {if is_array($input.p)} + {foreach $input.p as $p} + {if is_array($p)} + {$p.text}
+ {else} + {$p}
+ {/if} + {/foreach} + {else} + {$input.p} + {/if} +

+ {/if} + {if isset($languages)}
{/if} + {block name="end_field_block"}
{/block} {/if} - {if isset($languages)}
{/if} - {block name="end_field_block"}
{/block} - {/if} - {if $input.name == 'id_state'} -
- {/if} - {/foreach} - {elseif $key == 'submit'} -
- -
+ {if $input.name == 'id_state'} +
+ {/if} + {/foreach} + {elseif $key == 'submit'} +
+ +
+ {elseif $key == 'p'} +

+ {if is_array($field)} + {foreach $field as $k => $p} + {if is_array($p)} + {$p.text}
+ {else} + {$p} + {if isset($field[$k+1])}
{/if} + {/if} + {/foreach} + {else} + {$field} + {/if} +

+ {/if} + {block name="other_input"}{/block} + {/foreach} + {if $required_fields} +
* {l s ='Required field'}
{/if} - {block name="other_input"}{/block} - {/foreach} - {if $required_fields} -
* {l s ='Required field'}
- {/if} - {if isset($fields.tinymce) && $fields.tinymce} - - - - {/if} -
- {block name="other_fieldsets"}{/block} + {if isset($fields.tinymce) && $fields.tinymce} + + + + {/if} + + {block name="other_fieldsets"}{/block} + {if isset($fields[$f+1])}
{/if} + {/foreach} {/block} diff --git a/admin-dev/themes/template/helper/list/list_header.tpl b/admin-dev/themes/template/helper/list/list_header.tpl index 42e46a93f..a84a89fe9 100644 --- a/admin-dev/themes/template/helper/list/list_header.tpl +++ b/admin-dev/themes/template/helper/list/list_header.tpl @@ -79,6 +79,8 @@
{block name="leadin"}{/block}
{/if} +{block name="override_header"}{/block} +
diff --git a/admin-dev/themes/template/referrers/form.tpl b/admin-dev/themes/template/referrers/form.tpl new file mode 100644 index 000000000..e90fef401 --- /dev/null +++ b/admin-dev/themes/template/referrers/form.tpl @@ -0,0 +1,122 @@ +{* +* 2007-2011 PrestaShop +* +* NOTICE OF LICENSE +* +* This source file is subject to the Academic Free License (AFL 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/afl-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 +* @copyright 2007-2011 PrestaShop SA +* @version Release: $Revision: 9795 $ +* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*} +{extends file="../helper/form/form.tpl"} + +{block name="other_fieldsets"} + {if $f == 1} +
+
+ + {l s='Help'} + + +
+ {/if} +{/block} + +{block name="other_input"} + + {if $key == 'help'} + + {l s='Get help!'} + + {/if} + +{/block} + +{block name="label"} + + {if $input.name == 'http_referer_regexp'} + + + {if $input.name == 'request_uri_regexp_not'} + + {/if} + +{/block} + +{block name="script"} + + $(document).ready(function() { + $('fieldset#fieldset_3 legend').css('cursor', 'pointer'); + $('fieldset#fieldset_3 legend').click(function(){ + $('#tracking_expert').slideToggle(); + }); + }); + +{/block} diff --git a/admin-dev/themes/template/referrers/form_settings.tpl b/admin-dev/themes/template/referrers/form_settings.tpl new file mode 100644 index 000000000..c56e5864e --- /dev/null +++ b/admin-dev/themes/template/referrers/form_settings.tpl @@ -0,0 +1,65 @@ +{* +* 2007-2011 PrestaShop +* +* NOTICE OF LICENSE +* +* This source file is subject to the Academic Free License (AFL 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/afl-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 +* @copyright 2007-2011 PrestaShop SA +* @version Release: $Revision: 8971 $ +* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*} + + + +
+
+ + {l s='Settings'} + + + +
+ + + + + + +
+
+

{l s='Direct traffic can be quite consuming. You should consider enabling it only if you have a strong database server and a strong need for it.'}

+ + +
+
+

{l s='Indexation'}

+

{l s='There is a huge quantity of data, so each connection corresponding to a referrer is indexed. You can refresh this index by clicking on the button above. Be aware that it may take a long time and it is only needed if you modified or added a referrer and if you want your changes to be retroactive.'}

+ + +
+
+

{l s='Cache'}

+

{l s='For you to sort and filter your data, it is cached. You can refresh the cache by clicking on the button above.'}

+ + +
+
+ +
 
+ + \ No newline at end of file diff --git a/admin-dev/themes/template/referrers/list_header.tpl b/admin-dev/themes/template/referrers/list_header.tpl new file mode 100644 index 000000000..2ebe8a5a9 --- /dev/null +++ b/admin-dev/themes/template/referrers/list_header.tpl @@ -0,0 +1,95 @@ +{* +* 2007-2011 PrestaShop +* +* NOTICE OF LICENSE +* +* This source file is subject to the Academic Free License (AFL 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/afl-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 +* @copyright 2007-2011 PrestaShop SA +* @version Release: $Revision: 9639 $ +* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*} + +{extends file="helper/list/list_header.tpl"} + +{block name="override_header"} + + + {if $enable_calendar} + {$calendar_form} + {$settings_form} + {/if} +{/block} \ No newline at end of file diff --git a/admin-dev/themes/template/referrers/view.tpl b/admin-dev/themes/template/referrers/view.tpl new file mode 100644 index 000000000..dc945f645 --- /dev/null +++ b/admin-dev/themes/template/referrers/view.tpl @@ -0,0 +1,134 @@ +{* +* 2007-2011 PrestaShop +* +* NOTICE OF LICENSE +* +* This source file is subject to the Academic Free License (AFL 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/afl-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 +* @copyright 2007-2011 PrestaShop SA +* @version Release: $Revision: 8897 $ +* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*} + +{extends file="helper/view/view.tpl"} + +{block name="override_tpl"} + + + + {if $enable_calendar} + {$calendar_form} + {/if} + + + + +
+ + {l s='Statistics'} + +

{$referrer->name}

+
+ {foreach $display_tab as $data => $label} + + + + + {/foreach} +
{$label}
+
+
+ +
+ +
+
+ +
+ +
+
+ + + +{/block} + diff --git a/admin-dev/themes/template/stats/calendar.tpl b/admin-dev/themes/template/stats/calendar.tpl index f3060b9ef..aadce2307 100644 --- a/admin-dev/themes/template/stats/calendar.tpl +++ b/admin-dev/themes/template/stats/calendar.tpl @@ -32,7 +32,7 @@ {$translations.Calendar}
-
+
@@ -45,7 +45,7 @@

{if isset($translations.To)}{$translations.To}{else}{l s='From:'}{/if}

- +
diff --git a/admin-dev/themes/template/stats/engines.tpl b/admin-dev/themes/template/stats/engines.tpl index 2b4e6b195..039c6f560 100644 --- a/admin-dev/themes/template/stats/engines.tpl +++ b/admin-dev/themes/template/stats/engines.tpl @@ -24,7 +24,7 @@ * International Registered Trademark & Property of PrestaShop SA *} -
+
{l s='Settings'} @@ -54,7 +54,7 @@ {l s='No grid engine module installed'} {/if}

-

+

 
\ No newline at end of file diff --git a/admin-dev/themes/template/stats/view.tpl b/admin-dev/themes/template/stats/view.tpl new file mode 100644 index 000000000..5c1b51bcb --- /dev/null +++ b/admin-dev/themes/template/stats/view.tpl @@ -0,0 +1,64 @@ +{* +* 2007-2011 PrestaShop +* +* NOTICE OF LICENSE +* +* This source file is subject to the Academic Free License (AFL 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/afl-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 +* @copyright 2007-2011 PrestaShop SA +* @version Release: $Revision: 8897 $ +* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*} + +{extends file="helper/view/view.tpl"} + +{block name="override_tpl"} + + +{/block} + diff --git a/classes/AdminController.php b/classes/AdminController.php index 1dc387abc..19cc880f6 100644 --- a/classes/AdminController.php +++ b/classes/AdminController.php @@ -76,6 +76,9 @@ class AdminControllerCore extends Controller public $tpl_option_vars = array(); public $tpl_view_vars = array(); + /** @var bool if you want more fieldsets in the form */ + public $multiple_fieldsets = false; + public $fields_value = false; /** @var array Errors displayed after post processing */ @@ -1358,8 +1361,12 @@ class AdminControllerCore extends Controller $this->content .= $this->context->smarty->fetch($this->context->smarty->template_dir[0].'form_submit_ajax.tpl'); if ($this->fields_form && is_array($this->fields_form)) { + if (!$this->multiple_fieldsets) + $this->fields_form = array(array('form' => $this->fields_form)); + if (empty($this->toolbar_title)) $this->initToolbarTitle(); + $this->getlanguages(); $helper = new HelperForm($this); $helper->override_folder = $this->tpl_folder; @@ -1368,6 +1375,7 @@ class AdminControllerCore extends Controller $helper->allow_employee_form_lang = $this->allow_employee_form_lang; $helper->fields_value = $this->getFieldsValue($this->object); $helper->tpl_vars = $this->tpl_form_vars; + $helper->multiple_fieldsets = $this->multiple_fieldsets; if ($this->tabAccess['view']) { if (Tools::getValue('back')) @@ -1852,14 +1860,16 @@ class AdminControllerCore extends Controller public function getFieldsValue($obj) { - if (isset($this->fields_form['input'])) - foreach ($this->fields_form['input'] as $input) - if (empty($this->fields_value[$input['name']])) - if (isset($input['lang']) && $input['lang']) - foreach ($this->_languages as $language) - $this->fields_value[$input['name']][$language['id_lang']] = $this->getFieldValue($obj, $input['name'], $language['id_lang']); - else - $this->fields_value[$input['name']] = $this->getFieldValue($obj, $input['name']); + info($this->fields_form); + foreach ($this->fields_form as $fieldset) + if (isset($fieldset['form']['input'])) + foreach ($fieldset['form']['input'] as $input) + if (empty($this->fields_value[$input['name']])) + if (isset($input['lang']) && $input['lang']) + foreach ($this->_languages as $language) + $this->fields_value[$input['name']][$language['id_lang']] = $this->getFieldValue($obj, $input['name'], $language['id_lang']); + else + $this->fields_value[$input['name']] = $this->getFieldValue($obj, $input['name']); return $this->fields_value; } diff --git a/classes/HelperForm.php b/classes/HelperForm.php index dcc19394b..6299e35f9 100644 --- a/classes/HelperForm.php +++ b/classes/HelperForm.php @@ -31,22 +31,18 @@ class HelperFormCore extends Helper public $first_call = true; public $toolbar = true; - /** - * @var array of forms fields - * Usage : - * - */ + /** @var array of forms fields */ protected $fields_form = array(); + + /** @var array values ​​of form fields */ public $fields_value = array(); + public $table; - /** @var if not null, a title will be added on that list */ + /** @var string if not null, a title will be added on that list */ public $title = null; - /** - * Used to override default 'submitAdd' parameter in form action attribute - * @var string - */ + /** @var string Used to override default 'submitAdd' parameter in form action attribute */ public $submit_action = ''; public $token; @@ -76,7 +72,7 @@ class HelperFormCore extends Helper if (isset($this->fields_form['asso_shop']) && Shop::isFeatureActive()) if ($this->fields_form['asso_shop'] == 'group') $asso_shop = $this->displayAssoShop('group_shop'); - elseif ($this->fields_form['asso_shop'] == 'shop') + else if ($this->fields_form['asso_shop'] == 'shop') $asso_shop = $this->displayAssoShop(); $iso = $this->context->language->iso_code; @@ -103,12 +99,14 @@ class HelperFormCore extends Helper 'asso_shop' => isset($asso_shop) ? $asso_shop : null, 'iso' => file_exists(_PS_ROOT_DIR_.'/js/tiny_mce/langs/'.$iso.'.js') ? $iso : 'en', 'path_css' => _THEME_CSS_DIR_, - 'ad' => dirname($_SERVER["PHP_SELF"]), - + 'ad' => dirname($_SERVER['PHP_SELF']) )); return parent::generate(); } + /** + * Return true if there are required fields + */ public function getFieldsRequired() { if (isset($this->fields_form['input'])) diff --git a/classes/Referrer.php b/classes/Referrer.php index a90f1d9a2..749ef0f23 100644 --- a/classes/Referrer.php +++ b/classes/Referrer.php @@ -30,7 +30,7 @@ class ReferrerCore extends ObjectModel public $id_shop; public $name; public $passwd; - + public $http_referer_regexp; public $http_referer_like; public $request_uri_regexp; @@ -39,25 +39,43 @@ class ReferrerCore extends ObjectModel public $http_referer_like_not; public $request_uri_regexp_not; public $request_uri_like_not; - + public $base_fee; public $percent_fee; public $click_fee; - - public $date_add; - - protected $fieldsRequired = array('name'); - protected $fieldsSize = array('name' => 64, 'http_referer_regexp' => 64, 'request_uri_regexp' => 64, 'http_referer_like' => 64, 'request_uri_like' => 64, 'passwd' => 32); - protected $fieldsValidate = array( - 'id_shop' => 'isUnsignedInt', - 'name' => 'isGenericName', 'passwd' => 'isPasswd', - 'http_referer_regexp' => 'isCleanHtml', 'request_uri_regexp' => 'isCleanHtml', 'http_referer_like' => 'isCleanHtml', 'request_uri_like' => 'isCleanHtml', - 'http_referer_regexp_not' => 'isCleanHtml', 'request_uri_regexp_not' => 'isCleanHtml', 'http_referer_like_not' => 'isCleanHtml', 'request_uri_like_not' => 'isCleanHtml', - 'base_fee' => 'isFloat', 'percent_fee' => 'isFloat', 'click_fee' => 'isFloat'); - protected $table = 'referrer'; - protected $identifier = 'id_referrer'; - + public $date_add; + + protected $fieldsRequired = array('name'); + protected $fieldsSize = array( + 'name' => 64, + 'http_referer_regexp' => 64, + 'request_uri_regexp' => 64, + 'http_referer_like' => 64, + 'request_uri_like' => 64, + 'passwd' => 32 + ); + + protected $fieldsValidate = array( + 'id_shop' => 'isUnsignedInt', + 'name' => 'isGenericName', + 'passwd' => 'isPasswd', + 'http_referer_regexp' => 'isCleanHtml', + 'request_uri_regexp' => 'isCleanHtml', + 'http_referer_like' => 'isCleanHtml', + 'request_uri_like' => 'isCleanHtml', + 'http_referer_regexp_not' => 'isCleanHtml', + 'request_uri_regexp_not' => 'isCleanHtml', + 'http_referer_like_not' => 'isCleanHtml', + 'request_uri_like_not' => 'isCleanHtml', + 'base_fee' => 'isFloat', + 'percent_fee' => 'isFloat', + 'click_fee' => 'isFloat' + ); + + protected $table = 'referrer'; + protected $identifier = 'id_referrer'; + protected static $_join = '(r.http_referer_like IS NULL OR r.http_referer_like = \'\' OR cs.http_referer LIKE r.http_referer_like) AND (r.request_uri_like IS NULL OR r.request_uri_like = \'\' OR cs.request_uri LIKE r.request_uri_like) AND (r.http_referer_like_not IS NULL OR r.http_referer_like_not = \'\' OR cs.http_referer NOT LIKE r.http_referer_like_not) @@ -66,7 +84,7 @@ class ReferrerCore extends ObjectModel AND (r.request_uri_regexp IS NULL OR r.request_uri_regexp = \'\' OR cs.request_uri REGEXP r.request_uri_regexp) AND (r.http_referer_regexp_not IS NULL OR r.http_referer_regexp_not = \'\' OR cs.http_referer NOT REGEXP r.http_referer_regexp_not) AND (r.request_uri_regexp_not IS NULL OR r.request_uri_regexp_not = \'\' OR cs.request_uri NOT REGEXP r.request_uri_regexp_not)'; - + public function getFields() { $this->validateFields(); @@ -87,7 +105,7 @@ class ReferrerCore extends ObjectModel $fields['date_add'] = pSQL($this->date_add); return $fields; } - + public function add($autodate = true, $nullValues = false) { if (!($result = parent::add($autodate, $nullValues))) @@ -106,11 +124,11 @@ class ReferrerCore extends ObjectModel SELECT id_referrer, id_connections_source FROM '._DB_PREFIX_.'referrer r LEFT JOIN '._DB_PREFIX_.'connections_source cs ON ('.self::$_join.') - WHERE id_connections_source = '.(int)($id_connections_source).' + WHERE id_connections_source = '.(int)$id_connections_source.' )'; Db::getInstance()->execute($sql); } - + /** * Get list of referrers connections of a customer * @@ -124,7 +142,7 @@ class ReferrerCore extends ObjectModel LEFT JOIN '._DB_PREFIX_.'connections_source cs ON c.id_connections = cs.id_connections LEFT JOIN '._DB_PREFIX_.'referrer r ON ('.self::$_join.') LEFT JOIN '._DB_PREFIX_.'shop s ON s.id_shop = c.id_shop - WHERE g.id_customer = '.(int)($id_customer).' + WHERE g.id_customer = '.(int)$id_customer.' AND r.name IS NOT NULL ORDER BY c.date_add DESC'; return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql); @@ -145,7 +163,7 @@ class ReferrerCore extends ObjectModel $join = 'LEFT JOIN `'._DB_PREFIX_.'page` p ON cp.`id_page` = p.`id_page` LEFT JOIN `'._DB_PREFIX_.'page_type` pt ON pt.`id_page_type` = p.`id_page_type`'; $where = ' AND pt.`name` = \'product\' - AND p.`id_object` = '.(int)($id_product); + AND p.`id_object` = '.(int)$id_product; } $sql = 'SELECT COUNT(DISTINCT cs.id_connections_source) AS visits, @@ -183,9 +201,9 @@ class ReferrerCore extends ObjectModel LEFT JOIN `'._DB_PREFIX_.'page` p ON cp.`id_page` = p.`id_page` LEFT JOIN `'._DB_PREFIX_.'page_type` pt ON pt.`id_page_type` = p.`id_page_type`'; $where = ' AND pt.`name` = \'product\' - AND p.`id_object` = '.(int)($id_product); + AND p.`id_object` = '.(int)$id_product; } - + $sql = 'SELECT COUNT(DISTINCT cu.id_customer) AS registrations FROM '._DB_PREFIX_.'referrer_cache rc LEFT JOIN '._DB_PREFIX_.'referrer_shop rs ON rc.id_referrer = rs.id_referrer @@ -199,7 +217,7 @@ class ReferrerCore extends ObjectModel '.$shop->addSqlRestriction(false, 'c').' '.$shop->addSqlRestriction(Shop::SHARE_CUSTOMER, 'cu').' AND cu.date_add > cs.date_add - AND rc.id_referrer = '.(int)($this->id) + AND rc.id_referrer = '.(int)$this->id .$where; $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql); return (int)$result['registrations']; @@ -218,9 +236,9 @@ class ReferrerCore extends ObjectModel if ($id_product) { $join = 'LEFT JOIN '._DB_PREFIX_.'order_detail od ON oo.id_order = od.id_order'; - $where = ' AND od.product_id = '.(int)($id_product); + $where = ' AND od.product_id = '.(int)$id_product; } - + $sql = 'SELECT oo.id_order FROM '._DB_PREFIX_.'referrer_cache rc LEFT JOIN '._DB_PREFIX_.'referrer_shop rs ON rc.id_referrer = rs.id_referrer @@ -234,16 +252,16 @@ class ReferrerCore extends ObjectModel '.$shop->addSqlRestriction(false, 'c').' '.$shop->addSqlRestriction(Shop::SHARE_ORDER, 'oo').' AND oo.date_add > cs.date_add - AND rc.id_referrer = '.(int)($this->id).' + AND rc.id_referrer = '.(int)$this->id.' AND oo.valid = 1' .$where; $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql); - + $implode = array(); foreach ($result as $row) if ((int)$row['id_order']) $implode[] = (int)$row['id_order']; - + if ($implode) { $sql = 'SELECT COUNT(id_order) AS orders, SUM(total_paid_real / conversion_rate) AS sales @@ -256,7 +274,7 @@ class ReferrerCore extends ObjectModel else return array('orders' => 0, 'sales' => 0); } - + /** * Refresh cache data of referrer statistics in referrer_shop table * @@ -265,31 +283,31 @@ class ReferrerCore extends ObjectModel */ public static function refreshCache($referrers = null, $employee = null) { - if (!$referrers OR !is_array($referrers)) + if (!$referrers || !is_array($referrers)) $referrers = Db::getInstance()->executeS('SELECT id_referrer FROM '._DB_PREFIX_.'referrer'); foreach ($referrers as $row) { $referrer = new Referrer($row['id_referrer']); - foreach (Shop::getShops(true, null, true) as $shopID) + foreach (Shop::getShops(true, null, true) as $shop_id) { - if (!$referrer->isAssociatedToShop($shopID)) + if (!$referrer->isAssociatedToShop($shop_id)) continue; - $shop = new Shop($shopID); - $statsVisits = $referrer->getStatsVisits(null, $employee, $shop); + $shop = new Shop($shop_id); + $stats_visits = $referrer->getStatsVisits(null, $employee, $shop); $registrations = $referrer->getRegistrations(null, $employee, $shop); - $statsSales = $referrer->getStatsSales(null, $employee, $shop); + $stats_sales = $referrer->getStatsSales(null, $employee, $shop); Db::getInstance()->autoExecute(_DB_PREFIX_.'referrer_shop', array( - 'cache_visitors' => $statsVisits['uniqs'], - 'cache_visits' => $statsVisits['visits'], - 'cache_pages' => $statsVisits['pages'], - 'cache_registrations' =>$registrations, - 'cache_orders' => $statsSales['orders'], - 'cache_sales' => number_format($statsSales['sales'], 2, '.', ''), - 'cache_reg_rate' => $statsVisits['uniqs'] ? $registrations / $statsVisits['uniqs'] : 0, - 'cache_order_rate' => $statsVisits['uniqs'] ? $statsSales['orders'] / $statsVisits['uniqs'] : 0, - ), 'UPDATE', 'id_referrer = '.$referrer->id.' AND id_shop = '.$shopID); + 'cache_visitors' => $stats_visits['uniqs'], + 'cache_visits' => $stats_visits['visits'], + 'cache_pages' => $stats_visits['pages'], + 'cache_registrations' => $registrations, + 'cache_orders' => $stats_sales['orders'], + 'cache_sales' => number_format($stats_sales['sales'], 2, '.', ''), + 'cache_reg_rate' => $stats_visits['uniqs'] ? $registrations / $stats_visits['uniqs'] : 0, + 'cache_order_rate' => $stats_visits['uniqs'] ? $stats_sales['orders'] / $stats_visits['uniqs'] : 0, + ), 'UPDATE', 'id_referrer = '.$referrer->id.' AND id_shop = '.$shop_id); } } @@ -297,7 +315,7 @@ class ReferrerCore extends ObjectModel Configuration::updateValue('PS_REFERRERS_CACHE_DATE', date('Y-m-d H:i:s')); return true; } - + /** * Cache liaison between connections_source data and referrers data * @@ -305,7 +323,7 @@ class ReferrerCore extends ObjectModel */ public static function refreshIndex($referrers = null) { - if (!$referrers OR !is_array($referrers)) + if (!$referrers || !is_array($referrers)) { Db::getInstance()->execute('TRUNCATE '._DB_PREFIX_.'referrer_cache'); Db::getInstance()->execute(' @@ -318,46 +336,47 @@ class ReferrerCore extends ObjectModel else foreach ($referrers as $row) { - Db::getInstance()->execute('DELETE FROM '._DB_PREFIX_.'referrer_cache WHERE id_referrer = '.(int)($row['id_referrer'])); + Db::getInstance()->execute('DELETE FROM '._DB_PREFIX_.'referrer_cache WHERE id_referrer = '.(int)$row['id_referrer']); Db::getInstance()->execute(' INSERT INTO '._DB_PREFIX_.'referrer_cache (id_referrer, id_connections_source) ( SELECT id_referrer, id_connections_source FROM '._DB_PREFIX_.'referrer r LEFT JOIN '._DB_PREFIX_.'connections_source cs ON ('.self::$_join.') - WHERE id_referrer = '.(int)($row['id_referrer']).' + WHERE id_referrer = '.(int)$row['id_referrer'].' )'); } } - + public static function getAjaxProduct($id_referrer, $id_product, $employee = null) { + $context = Context::getContext(); $product = new Product($id_product, false, Configuration::get('PS_LANG_DEFAULT')); $currency = Currency::getCurrencyInstance(Configuration::get('PS_CURRENCY_DEFAULT')); $referrer = new Referrer($id_referrer); - $statsVisits = $referrer->getStatsVisits($id_product, $employee); - $registrations = $referrer->getRegistrations($id_product, $employee); - $statsSales = $referrer->getStatsSales($id_product, $employee); + $stats_visits = $referrer->getStatsVisits($id_product, $employee, $context->shop); + $registrations = $referrer->getRegistrations($id_product, $employee, $context->shop); + $stats_sales = $referrer->getStatsSales($id_product, $employee, $context->shop); // If it's a product and it has no visits nor orders - if ((int)($id_product) AND !$statsVisits['visits'] AND !$statsSales['orders']) + if ((int)$id_product && !$stats_visits['visits'] && !$stats_sales['orders']) exit; - - $jsonArray = array(); - $jsonArray[] = '"id_product":"'.(int)($product->id).'"'; - $jsonArray[] = '"product_name":"'.addslashes($product->name).'"'; - $jsonArray[] = '"uniqs":"'.(int)($statsVisits['uniqs']).'"'; - $jsonArray[] = '"visitors":"'.(int)($statsVisits['visitors']).'"'; - $jsonArray[] = '"visits":"'.(int)($statsVisits['visits']).'"'; - $jsonArray[] = '"pages":"'.(int)($statsVisits['pages']).'"'; - $jsonArray[] = '"registrations":"'.(int)($registrations).'"'; - $jsonArray[] = '"orders":"'.(int)($statsSales['orders']).'"'; - $jsonArray[] = '"sales":"'.Tools::displayPrice($statsSales['sales'], $currency).'"'; - $jsonArray[] = '"cart":"'.Tools::displayPrice(((int)($statsSales['orders']) ? $statsSales['sales'] / (int)($statsSales['orders']) : 0), $currency).'"'; - $jsonArray[] = '"reg_rate":"'.number_format((int)($statsVisits['uniqs']) ? (int)($registrations) / (int)($statsVisits['uniqs']) : 0, 4, '.', '').'"'; - $jsonArray[] = '"order_rate":"'.number_format((int)($statsVisits['uniqs']) ? (int)($statsSales['orders']) / (int)($statsVisits['uniqs']) : 0, 4, '.', '').'"'; - $jsonArray[] = '"click_fee":"'.Tools::displayPrice((int)($statsVisits['visits']) * $referrer->click_fee, $currency).'"'; - $jsonArray[] = '"base_fee":"'.Tools::displayPrice($statsSales['orders'] * $referrer->base_fee, $currency).'"'; - $jsonArray[] = '"percent_fee":"'.Tools::displayPrice($statsSales['sales'] * $referrer->percent_fee / 100, $currency).'"'; - die ('[{'.implode(',', $jsonArray).'}]'); + + $json_array = array(); + $json_array[] = '"id_product":"'.(int)$product->id.'"'; + $json_array[] = '"product_name":"'.addslashes($product->name).'"'; + $json_array[] = '"uniqs":"'.(int)$stats_visits['uniqs'].'"'; + $json_array[] = '"visitors":"'.(int)$stats_visits['visitors'].'"'; + $json_array[] = '"visits":"'.(int)$stats_visits['visits'].'"'; + $json_array[] = '"pages":"'.(int)$stats_visits['pages'].'"'; + $json_array[] = '"registrations":"'.(int)$registrations.'"'; + $json_array[] = '"orders":"'.(int)$stats_sales['orders'].'"'; + $json_array[] = '"sales":"'.Tools::displayPrice($stats_sales['sales'], $currency).'"'; + $json_array[] = '"cart":"'.Tools::displayPrice(((int)$stats_sales['orders'] ? $stats_sales['sales'] / (int)$stats_sales['orders'] : 0), $currency).'"'; + $json_array[] = '"reg_rate":"'.number_format((int)$stats_visits['uniqs'] ? (int)$registrations / (int)$stats_visits['uniqs'] : 0, 4, '.', '').'"'; + $json_array[] = '"order_rate":"'.number_format((int)$stats_visits['uniqs'] ? (int)$stats_sales['orders'] / (int)$stats_visits['uniqs'] : 0, 4, '.', '').'"'; + $json_array[] = '"click_fee":"'.Tools::displayPrice((int)$stats_visits['visits'] * $referrer->click_fee, $currency).'"'; + $json_array[] = '"base_fee":"'.Tools::displayPrice($stats_sales['orders'] * $referrer->base_fee, $currency).'"'; + $json_array[] = '"percent_fee":"'.Tools::displayPrice($stats_sales['sales'] * $referrer->percent_fee / 100, $currency).'"'; + die ('[{'.implode(',', $json_array).'}]'); } } \ No newline at end of file diff --git a/controllers/admin/AdminReferrersController.php b/controllers/admin/AdminReferrersController.php new file mode 100644 index 000000000..22556e66a --- /dev/null +++ b/controllers/admin/AdminReferrersController.php @@ -0,0 +1,467 @@ + +* @copyright 2007-2011 PrestaShop SA +* @version Release: $Revision: 6844 $ +* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*/ + +if (!defined('_PS_ADMIN_DIR_')) define('_PS_ADMIN_DIR_', getcwd().'/..'); + +if (Tools::getValue('token') == Tools::getAdminToken('AdminReferrers'.(int)Tab::getIdFromClassName('AdminReferrers').(int)Tools::getValue('id_employee'))) +{ + if (Tools::isSubmit('ajaxProductFilter')) + Referrer::getAjaxProduct( + (int)Tools::getValue('id_referrer'), + (int)Tools::getValue('id_product'), + new Employee((int)Tools::getValue('id_employee')) + ); + else if (Tools::isSubmit('ajaxFillProducts')) + { + $json_array = array(); + $result = Db::getInstance()->executeS(' + SELECT p.id_product, pl.name + FROM '._DB_PREFIX_.'product p + LEFT JOIN '._DB_PREFIX_.'product_lang pl + ON (p.id_product = pl.id_product AND pl.id_lang = '.(int)Tools::getValue('id_lang').') + '.(Tools::getValue('filter') != 'undefined' ? 'WHERE name LIKE "%'.pSQL(Tools::getValue('filter')).'%"' : '') + ); + + foreach ($result as $row) + $json_array[] = '{id_product:'.(int)$row['id_product'].',name:\''.addslashes($row['name']).'\'}'; + + die ('['.implode(',', $json_array).']'); + } +} + +class AdminReferrersControllerCore extends AdminController +{ + public function __construct() + { + $this->table = 'referrer'; + $this->className = 'Referrer'; + $this->fieldsDisplay = array( + 'id_referrer' => array( + 'title' => $this->l('ID'), + 'width' => 25, + 'align' => 'center' + ), + 'name' => array( + 'title' => $this->l('Name'), + 'width' => 80 + ), + 'cache_visitors' => array( + 'title' => $this->l('Visitors'), + 'width' => 30, + 'align' => 'center' + ), + 'cache_visits' => array( + 'title' => $this->l('Visits'), + 'width' => 30, + 'align' => 'center' + ), + 'cache_pages' => array( + 'title' => $this->l('Pages'), + 'width' => 30, + 'align' => 'center' + ), + 'cache_registrations' => array( + 'title' => $this->l('Reg.'), + 'width' => 30, + 'align' => 'center' + ), + 'cache_orders' => array( + 'title' => $this->l('Ord.'), + 'width' => 30, + 'align' => 'center' + ), + 'cache_sales' => array( + 'title' => $this->l('Sales'), + 'width' => 80, + 'align' => 'right', + 'prefix' => '', + 'suffix' => '', + 'price' => true + ), + 'cart' => array( + 'title' => $this->l('Avg. cart'), + 'width' => 50, + 'align' => 'right', + 'price' => true + ), + 'cache_reg_rate' => array( + 'title' => $this->l('Reg. rate'), + 'width' => 30, + 'align' => 'center' + ), + 'cache_order_rate' => array( + 'title' => $this->l('Order rate'), + 'width' => 30, + 'align' => 'center' + ), + 'fee0' => array( + 'title' => $this->l('Click'), + 'width' => 30, + 'align' => 'right', + 'price' => true + ), + 'fee1' => array( + 'title' => $this->l('Base'), + 'width' => 30, + 'align' => 'right', + 'price' => true + ), + 'fee2' => array( + 'title' => $this->l('Percent'), + 'width' => 30, + 'align' => 'right', + 'price' => true + ) + ); + + parent::__construct(); + } + + public function initList() + { + // Display list Referrers: + $this->addRowAction('view'); + $this->addRowAction('edit'); + $this->addRowAction('delete'); + + $this->bulk_actions = array('delete' => array('text' => $this->l('Delete selected'), 'confirm' => $this->l('Delete selected items?'))); + + $this->_select = 'SUM(sa.cache_visitors) AS cache_visitors, SUM(sa.cache_visits) AS cache_visits, SUM(sa.cache_pages) AS cache_pages, + SUM(sa.cache_registrations) AS cache_registrations, SUM(sa.cache_orders) AS cache_orders, SUM(sa.cache_sales) AS cache_sales, + IF(sa.cache_orders > 0, ROUND(sa.cache_sales/sa.cache_orders, 2), 0) as cart, (sa.cache_visits*click_fee) as fee0, + (sa.cache_orders*base_fee) as fee1, (sa.cache_sales*percent_fee/100) as fee2'; + $this->_join = ' + LEFT JOIN `'._DB_PREFIX_.'referrer_shop` sa + ON (sa.'.$this->identifier.' = a.'.$this->identifier.' AND sa.id_shop IN ('.implode(', ', $this->context->shop->getListOfID()).'))'; + + $this->_group = 'GROUP BY sa.id_referrer'; + + $this->toolbar_btn['save-calendar'] = array( + 'href' => '#', + 'desc' => $this->l('Save Calendar') + ); + + $this->toolbar_btn['save-settings'] = array( + 'href' => '#', + 'desc' => $this->l('Save Settings') + ); + + $this->toolbar_btn['refresh-index'] = array( + 'href' => '#', + 'desc' => $this->l('Refresh Index') + ); + + $this->toolbar_btn['refresh-cache'] = array( + 'href' => '#', + 'desc' => $this->l('Refresh Cache') + ); + + $this->tpl_list_vars = array( + 'enable_calendar' => $this->enableCalendar(), + 'calendar_form' => $this->displayCalendar(), + 'settings_form' => $this->displaySettings() + ); + + return parent::initList(); + } + + public function initForm() + { + $uri = Tools::getHttpHost(true, true).__PS_BASE_URI__; + + $this->fields_form[0] = array('form' => array( + 'legend' => array( + 'title' => $this->l('Affiliate'), + 'image' => '../img/admin/affiliation.png' + ), + 'input' => array( + array( + 'type' => 'text', + 'label' => $this->l('Name:'), + 'name' => 'name', + 'size' => 20, + 'required' => true + ), + array( + 'type' => 'password', + 'label' => $this->l('Password:'), + 'name' => 'passwd', + 'size' => 20, + 'p' => $this->l('Leave blank if no change') + ) + ), + 'p' => array( + $this->l('Affiliates can access their own data with this name and password.'), + $this->l('Front access:').' '.$uri.'modules/trackingfront/stats.php' + ) + )); + + $this->fields_form[1] = array('form' => array( + 'legend' => array( + 'title' => $this->l('Commission plan'), + 'image' => '../img/admin/money.png' + ), + 'input' => array( + array( + 'type' => 'text', + 'label' => $this->l('Click fee:'), + 'name' => 'click_fee', + 'size' => 8, + 'p' => $this->l('Fee given for each visit.') + ), + array( + 'type' => 'text', + 'label' => $this->l('Base fee:'), + 'name' => 'base_fee', + 'size' => 8, + 'p' => $this->l('Fee given for each order placed.') + ), + array( + 'type' => 'text', + 'label' => $this->l('Percent fee:'), + 'name' => 'percent_fee', + 'size' => 8, + 'p' => $this->l('Percent of the sales.') + ) + ) + )); + + if (Shop::isFeatureActive()) + { + $this->fields_form[1]['form']['input'][] = array( + 'type' => 'shop', + 'label' => $this->l('Shop association:'), + 'name' => 'checkBoxShopAsso', + 'values' => Shop::getTree() + ); + } + + $this->fields_form[2] = array('form' => array( + 'legend' => array( + 'title' => $this->l('Technical information - Simple mode'), + 'image' => '../img/admin/affiliation.png' + ), + 'help' => true, + 'input' => array( + array( + 'type' => 'textarea', + 'label' => $this->l('Include:'), + 'name' => 'http_referer_like', + 'cols' => 40, + 'rows' => 1, + 'h3' => $this->l('HTTP referrer') + ), + array( + 'type' => 'textarea', + 'label' => $this->l('Exclude:'), + 'name' => 'http_referer_like_not', + 'cols' => 40, + 'rows' => 1 + ), + array( + 'type' => 'textarea', + 'label' => $this->l('Include:'), + 'name' => 'request_uri_like', + 'cols' => 40, + 'rows' => 1, + 'h3' => $this->l('Request Uri') + ), + array( + 'type' => 'textarea', + 'label' => $this->l('Exclude:'), + 'name' => 'request_uri_like_not', + 'cols' => 40, + 'rows' => 1 + ) + ), + 'p' => $this->l('If you know how to use MySQL regular expressions, you can use the').' + '.$this->l('expert mode').'.', + 'submit' => array( + 'title' => $this->l(' Save '), + 'class' => 'button' + ) + )); + + $this->fields_form[3] = array('form' => array( + 'legend' => array( + 'title' => $this->l('Technical information - Expert mode'), + 'image' => '../img/admin/affiliation.png' + ), + 'input' => array( + array( + 'type' => 'textarea', + 'label' => $this->l('Include:'), + 'name' => 'http_referer_regexp', + 'cols' => 40, + 'rows' => 1, + 'h3' => $this->l('HTTP referrer') + ), + array( + 'type' => 'textarea', + 'label' => $this->l('Exclude:'), + 'name' => 'http_referer_regexp_not', + 'cols' => 40, + 'rows' => 1 + ), + array( + 'type' => 'textarea', + 'label' => $this->l('Include:'), + 'name' => 'request_uri_regexp', + 'cols' => 40, + 'rows' => 1, + 'h3' => $this->l('Request Uri') + ), + array( + 'type' => 'textarea', + 'label' => $this->l('Exclude:'), + 'name' => 'request_uri_regexp_not', + 'cols' => 40, + 'rows' => 1 + ) + ) + )); + + $this->multiple_fieldsets = true; + + if (!($obj = $this->loadObject(true))) + return; + + $this->fields_value = array( + 'click_fee' => number_format((float)($this->getFieldValue($obj, 'click_fee')), 2), + 'base_fee' => number_format((float)($this->getFieldValue($obj, 'base_fee')), 2), + 'percent_fee' => number_format((float)($this->getFieldValue($obj, 'percent_fee')), 2), + 'http_referer_like' => str_replace('\\', '\\\\', htmlentities($this->getFieldValue($obj, 'http_referer_like'), ENT_COMPAT, 'UTF-8')), + 'http_referer_like_not' => str_replace('\\', '\\\\', htmlentities($this->getFieldValue($obj, 'http_referer_like_not'), ENT_COMPAT, 'UTF-8')), + 'request_uri_like' => str_replace('\\', '\\\\', htmlentities($this->getFieldValue($obj, 'request_uri_like'), ENT_COMPAT, 'UTF-8')), + 'request_uri_like_not' => str_replace('\\', '\\\\', htmlentities($this->getFieldValue($obj, 'request_uri_like_not'), ENT_COMPAT, 'UTF-8')) + ); + + //Added values of object Shop + if ($obj->id) + { + $assos = array(); + $sql = 'SELECT `id_shop`, `'.pSQL($this->identifier).'` + FROM `'._DB_PREFIX_.pSQL($this->table).'_shop` + WHERE `'.pSQL($this->identifier).'` = '.(int)$obj->id; + foreach (Db::getInstance()->executeS($sql) as $row) + $this->fields_value['shop'][$row['id_shop']][] = $row[$this->identifier]; + } + + $this->tpl_form_vars = array('uri' => $uri); + + return parent::initForm(); + } + + public function displayCalendar($action = null, $table = null, $identifier = null, $id = null) + { + return AdminStatsTabController::displayCalendarForm(array( + 'Calendar' => $this->l('Calendar'), + 'Day' => $this->l('Today'), + 'Month' => $this->l('Month'), + 'Year' => $this->l('Year') + ), $this->token, $action, $table, $identifier, $id); + } + + public function displaySettings() + { + if (!Tools::isSubmit('viewreferrer')) + { + $tpl = $this->context->smarty->createTemplate($this->tpl_folder.'form_settings.tpl'); + + $tpl->assign(array( + 'current' => self::$currentIndex, + 'token' => $this->token, + 'tracking_dt' => (int)Tools::getValue('tracking_dt', Configuration::get('TRACKING_DIRECT_TRAFFIC')) + )); + + return $tpl->fetch(); + } + } + + private function enableCalendar() + { + return (!Tools::isSubmit('add'.$this->table) && !Tools::isSubmit('submitAdd'.$this->table) && !Tools::isSubmit('update'.$this->table)); + } + + public function postProcess() + { + if ($this->enableCalendar()) + { + $calendar_tab = new AdminStatsController(); + $calendar_tab->postProcess(); + } + + if (Tools::isSubmit('submitSettings')) + if ($this->tabAccess['edit'] === '1') + if (Configuration::updateValue('TRACKING_DIRECT_TRAFFIC', (int)Tools::getValue('tracking_dt'))) + Tools::redirectAdmin(self::$currentIndex.'&conf=4&token='.Tools::getValue('token')); + + if (ModuleGraph::getDateBetween() != Configuration::get('PS_REFERRERS_CACHE_LIKE') || Tools::isSubmit('submitRefreshCache')) + Referrer::refreshCache(); + if (Tools::isSubmit('submitRefreshIndex')) + Referrer::refreshIndex(); + + return parent::postProcess(); + } + + public function initView() + { + $this->toolbar_btn['save-calendar'] = array( + 'href' => '#', + 'desc' => $this->l('Save Calendar') + ); + + $referrer = new Referrer((int)Tools::getValue('id_referrer')); + + $display_tab = array( + 'uniqs' => $this->l('Unique visitors'), + 'visitors' => $this->l('Visitors'), + 'visits' => $this->l('Visits'), + 'pages' => $this->l('Pages viewed'), + 'registrations' => $this->l('Registrations'), + 'orders' => $this->l('Orders'), + 'sales' => $this->l('Sales'), + 'reg_rate' => $this->l('Registration rate'), + 'order_rate' => $this->l('Order rate'), + 'click_fee' => $this->l('Click fee'), + 'base_fee' => $this->l('Base fee'), + 'percent_fee' => $this->l('Percent fee')); + + $this->tpl_view_vars = array( + 'enable_calendar' => $this->enableCalendar(), + 'calendar_form' => $this->displayCalendar($this->action, $this->table, $this->identifier, (int)Tools::getValue($this->identifier)), + 'referrer' => new Referrer((int)Tools::getValue('id_referrer')), + 'display_tab' => $display_tab, + 'id_employee' => (int)$this->context->employee->id, + 'id_lang' => (int)$this->context->language->id + ); + + return parent::initView(); + } +} + + diff --git a/controllers/admin/AdminStatsTabController.php b/controllers/admin/AdminStatsTabController.php index 3b0d73a6c..c305bea01 100644 --- a/controllers/admin/AdminStatsTabController.php +++ b/controllers/admin/AdminStatsTabController.php @@ -37,6 +37,17 @@ abstract class AdminStatsTabControllerCore extends AdminPreferencesControllerCor public function initContent() { $this->toolbar_title = $this->l('Stats'); + + $this->toolbar_btn['save-calendar'] = array( + 'href' => '#', + 'desc' => $this->l('Save Calendar') + ); + + $this->toolbar_btn['save-settings'] = array( + 'href' => '#', + 'desc' => $this->l('Save Settings') + ); + if ($this->display == 'view') { // Some controllers use the view action without an object @@ -59,7 +70,7 @@ abstract class AdminStatsTabControllerCore extends AdminPreferencesControllerCor public function displayCalendar() { - return $this->displayCalendarForm(array( + return self::displayCalendarForm(array( 'Calendar' => $this->l('Calendar', 'AdminStatsTab'), 'Day' => $this->l('Day', 'AdminStatsTab'), 'Month' => $this->l('Month', 'AdminStatsTab'), @@ -67,19 +78,24 @@ abstract class AdminStatsTabControllerCore extends AdminPreferencesControllerCor 'From' => $this->l('From:', 'AdminStatsTab'), 'To' => $this->l('To:', 'AdminStatsTab'), 'Save' => $this->l('Save', 'AdminStatsTab') - )); + ), $this->token); } - public function displayCalendarForm($translations) + public static function displayCalendarForm($translations, $token, $action = null, $table = null, $identifier = null, $id = null) { - $tpl = $this->context->smarty->createTemplate('stats/calendar.tpl'); + $context = Context::getContext(); + $tpl = $context->smarty->createTemplate('stats/calendar.tpl'); $tpl->assign(array( 'current' => self::$currentIndex, - 'token' => $this->token, + 'token' => $token, + 'action' => $action, + 'table' => $table, + 'identifier' => $identifier, + 'id' => $id, 'translations' => $translations, - 'datepickerFrom' => Tools::getValue('datepickerFrom', $this->context->employee->stats_date_from), - 'datepickerTo' => Tools::getValue('datepickerTo', $this->context->employee->stats_date_to) + 'datepickerFrom' => Tools::getValue('datepickerFrom', $context->employee->stats_date_from), + 'datepickerTo' => Tools::getValue('datepickerTo', $context->employee->stats_date_to) )); return $tpl->fetch();