* @copyright 2007-2011 PrestaShop SA * @version Release: $Revision: 7540 $ * @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().'/..'); include_once(PS_ADMIN_DIR.'/../config/config.inc.php'); include_once(PS_ADMIN_DIR.'/init.php'); 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')))); elseif (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; $this->_select = 'IF(cache_orders > 0, ROUND(cache_sales/cache_orders, 2), 0) as cart, (cache_visits*click_fee) as fee0, (cache_orders*base_fee) as fee1, (cache_sales*percent_fee/100) as fee2'; $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(); } private function enableCalendar() { return (!Tools::isSubmit('add'.$this->table) AND !Tools::isSubmit('submitAdd'.$this->table) AND !Tools::isSubmit('update'.$this->table)); } public function displayJavascript() { global $cookie, $currentIndex; $products = Product::getSimpleProducts((int)($cookie->id_lang)); $productsArray = array(); foreach ($products as $product) $productsArray[] = $product['id_product']; return ' '; } public function display() { global $currentIndex; 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() { global $currentIndex; 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($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) { global $currentIndex; 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.').'


'.$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() { global $cookie, $currentIndex; $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) { global $currentIndex; $irow = 0; $currency = new Currency(Configuration::get('PS_CURRENCY_DEFAULT')); 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], $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').' '; } } }