* @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().'/..'); 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')))); 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 '