* @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 '