Beispiel #1
0
	static function log($referrerUrl, $page) {
		$isExternal = (
			strpos($referrerUrl,Director::baseURL()) === FALSE
		);
		
		$referrer = new Referrer();
		$referrer->URL = $referrerUrl;
		$referrer->PageID = $page->ID;
		$referrer->IsExternal = $isExternal;
		$referrer->write();
	}
 public function add($autodate = true, $nullValues = false)
 {
     if ($result = parent::add($autodate, $nullValues)) {
         Referrer::cacheNewSource($this->id);
     }
     return $result;
 }
    public function displayAccount()
    {
        global $smarty, $cookie;
        if (!isset($cookie->stats_date_from)) {
            $cookie->stats_date_from = date('Y-m-d');
        }
        if (!isset($cookie->stats_date_to)) {
            $cookie->stats_date_to = date('Y-m-t');
        }
        $fakeEmployee = new Employee();
        $fakeEmployee->stats_date_from = $cookie->stats_date_from;
        $fakeEmployee->stats_date_to = $cookie->stats_date_to;
        Referrer::refreshCache(array(array('id_referrer' => intval($cookie->tracking_id))), $fakeEmployee);
        $referrer = new Referrer(intval($cookie->tracking_id));
        $smarty->assign('referrer', $referrer);
        $smarty->assign('datepickerFrom', $fakeEmployee->stats_date_from);
        $smarty->assign('datepickerTo', $fakeEmployee->stats_date_to);
        $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'), 'base_fee' => $this->l('Base fee'), 'percent_fee' => $this->l('Percent fee'), 'click_fee' => $this->l('Click fee'), 'sales' => $this->l('Sales'), 'cart' => $this->l('Average cart'), 'reg_rate' => $this->l('Registration rate'), 'order_rate' => $this->l('Order rate'));
        $smarty->assign('displayTab', $displayTab);
        $products = Product::getSimpleProducts(intval($cookie->id_lang));
        $productsArray = array();
        foreach ($products as $product) {
            $productsArray[] = $product['id_product'];
        }
        $echo = '
		<script type="text/javascript" src="../../js/jquery/datepicker/ui/i18n/ui.datepicker-' . Db::getInstance()->getValue('SELECT iso_code FROM ' . _DB_PREFIX_ . 'lang WHERE `id_lang` = ' . intval($cookie->id_lang)) . '.js"></script>
		<script type="text/javascript">
			$("#datepickerFrom").datepicker({
				prevText:"",
				nextText:"",
				dateFormat:"yy-mm-dd"});
			$("#datepickerTo").datepicker({
				prevText:"",
				nextText:"",
				dateFormat:"yy-mm-dd"});
			
			function updateValues()
			{
				$.getJSON("stats.php",{ajaxProductFilter:1,id_referrer:' . $referrer->id . ',token:"' . $cookie->tracking_passwd . '",id_product:0},
					function(j) {';
        foreach ($displayTab as $key => $value) {
            $echo .= '$("#' . $key . '").html(j[0].' . $key . ');';
        }
        $echo .= '		}
				)
			}		

			var productIds = new Array(\'' . implode('\',\'', $productsArray) . '\');
			var referrerStatus = new Array();
			
			function newProductLine(id_referrer, result, color)
			{
				return \'\'+
				\'<tr id="trprid_\'+id_referrer+\'_\'+result.id_product+\'" style="background-color: rgb(\'+color+\', \'+color+\', \'+color+\');">\'+
				\'	<td align="center">\'+result.id_product+\'</td>\'+
				\'	<td>\'+result.product_name+\'</td>\'+
				\'	<td align="center">\'+result.uniqs+\'</td>\'+
				\'	<td align="center">\'+result.visits+\'</td>\'+
				\'	<td align="center">\'+result.pages+\'</td>\'+
				\'	<td align="center">\'+result.registrations+\'</td>\'+
				\'	<td align="center">\'+result.orders+\'</td>\'+
				\'	<td align="right">\'+result.sales+\'</td>\'+
				\'	<td align="right">\'+result.cart+\'</td>\'+
				\'	<td align="center">\'+result.reg_rate+\'</td>\'+
				\'	<td align="center">\'+result.order_rate+\'</td>\'+
				\'	<td align="center">\'+result.click_fee+\'</td>\'+
				\'	<td align="center">\'+result.base_fee+\'</td>\'+
				\'	<td align="center">\'+result.percent_fee+\'</td>\'+
				\'</tr>\';
			}
			
			function showProductLines()
			{
				var irow = 0;
				for (var i = 0; i < productIds.length; ++i)
					$.getJSON("stats.php",{ajaxProductFilter:1,token:"' . $cookie->tracking_passwd . '",id_referrer:' . $referrer->id . ',id_product:productIds[i]},
						function(result) {
							var newLine = newProductLine(' . $referrer->id . ', result[0], (irow++%2 ? 204 : 238));
							$(newLine).hide().insertBefore($(\'#trid_dummy\')).fadeIn();
						}
					);
			}
		</script>';
        $echo2 = '
		<script type="text/javascript">
			updateValues();
			//showProductLines();
		</script>';
        return $this->display(__FILE__, 'header.tpl') . $echo . $this->display(__FILE__, 'account.tpl') . $echo2;
    }
    public function viewcustomer()
    {
        global $currentIndex, $cookie, $link;
        $irow = 0;
        $configurations = Configuration::getMultiple(array('PS_LANG_DEFAULT', 'PS_CURRENCY_DEFAULT'));
        $defaultLanguage = (int) $configurations['PS_LANG_DEFAULT'];
        $defaultCurrency = (int) $configurations['PS_CURRENCY_DEFAULT'];
        if (!($customer = $this->loadObject())) {
            return;
        }
        $customerStats = $customer->getStats();
        $addresses = $customer->getAddresses($defaultLanguage);
        $products = $customer->getBoughtProducts();
        $discounts = Discount::getCustomerDiscounts($defaultLanguage, (int) $customer->id, false, false);
        $orders = Order::getCustomerOrders((int) $customer->id, true);
        $carts = Cart::getCustomerCarts((int) $customer->id);
        $groups = $customer->getGroups();
        $messages = CustomerThread::getCustomerMessages((int) $customer->id);
        $referrers = Referrer::getReferrers((int) $customer->id);
        if ($totalCustomer = Db::getInstance()->getValue('SELECT SUM(total_paid_real) FROM ' . _DB_PREFIX_ . 'orders WHERE id_customer = ' . $customer->id . ' AND valid = 1')) {
            Db::getInstance()->getValue('SELECT SQL_CALC_FOUND_ROWS COUNT(*) FROM ' . _DB_PREFIX_ . 'orders WHERE valid = 1 GROUP BY id_customer HAVING SUM(total_paid_real) > ' . $totalCustomer);
            $countBetterCustomers = (int) Db::getInstance()->getValue('SELECT FOUND_ROWS()') + 1;
        } else {
            $countBetterCustomers = '-';
        }
        echo '
		<fieldset style="width:400px;float: left"><div style="float: right"><a href="' . $currentIndex . '&addcustomer&id_customer=' . $customer->id . '&token=' . $this->token . '"><img src="../img/admin/edit.gif" /></a></div>
			<span style="font-weight: bold; font-size: 14px;">' . $customer->firstname . ' ' . $customer->lastname . '</span>
			<img src="../img/admin/' . ($customer->id_gender == 2 ? 'female' : ($customer->id_gender == 1 ? 'male' : 'unknown')) . '.gif" style="margin-bottom: 5px" /><br />
			<a href="mailto:' . $customer->email . '" style="text-decoration: underline; color: blue">' . $customer->email . '</a><br /><br />
			' . $this->l('ID:') . ' ' . sprintf('%06d', $customer->id) . '<br />
			' . $this->l('Registration date:') . ' ' . Tools::displayDate($customer->date_add, (int) $cookie->id_lang, true) . '<br />
			' . $this->l('Last visit:') . ' ' . ($customerStats['last_visit'] ? Tools::displayDate($customerStats['last_visit'], (int) $cookie->id_lang, true) : $this->l('never')) . '<br />
			' . ($countBetterCustomers != '-' ? $this->l('Rank: #') . ' ' . (int) $countBetterCustomers . '<br />' : '') . '
		</fieldset>
		<fieldset style="width:300px;float:left;margin-left:50px">
			<div style="float: right">
				<a href="' . $currentIndex . '&addcustomer&id_customer=' . $customer->id . '&token=' . $this->token . '"><img src="../img/admin/edit.gif" /></a>
			</div>
			' . $this->l('Newsletter:') . ' ' . ($customer->newsletter ? '<img src="../img/admin/enabled.gif" />' : '<img src="../img/admin/disabled.gif" />') . '<br />
			' . $this->l('Opt-in:') . ' ' . ($customer->optin ? '<img src="../img/admin/enabled.gif" />' : '<img src="../img/admin/disabled.gif" />') . '<br />
			' . $this->l('Age:') . ' ' . $customerStats['age'] . ' ' . (!empty($customer->birthday['age']) ? '(' . Tools::displayDate($customer->birthday, (int) $cookie->id_lang) . ')' : $this->l('unknown')) . '<br /><br />
			' . $this->l('Last update:') . ' ' . Tools::displayDate($customer->date_upd, (int) $cookie->id_lang, true) . '<br />
			' . $this->l('Status:') . ' ' . ($customer->active ? '<img src="../img/admin/enabled.gif" />' : '<img src="../img/admin/disabled.gif" />');
        if ($customer->isGuest()) {
            echo '
			<div>
			' . $this->l('This customer is registered as') . ' <b>' . $this->l('guest') . '</b>';
            if (!Customer::customerExists($customer->email)) {
                echo '
					<form method="POST" action="index.php?tab=AdminCustomers&id_customer=' . (int) $customer->id . '&token=' . Tools::getAdminTokenLite('AdminCustomers') . '">
						<input type="hidden" name="id_lang" value="' . (int) (sizeof($orders) ? $orders[0]['id_lang'] : Configuration::get('PS_LANG_DEFAULT')) . '" />
						<p class="center"><input class="button" type="submit" name="submitGuestToCustomer" value="' . $this->l('Transform to customer') . '" /></p>
						' . $this->l('This feature generates a random password and sends an e-mail to the customer') . '</form>';
            } else {
                echo '</div><div><b style="color:red;">' . $this->l('A registered customer account exists with the same email address') . '</b>';
            }
            echo '
			</div>
			';
        }
        echo '
		</fieldset>
		<div class="clear">&nbsp;</div>';
        echo '<fieldset style="height:190px"><legend><img src="../img/admin/cms.gif" /> ' . $this->l('Add a private note') . '</legend>
			<p>' . $this->l('This note will be displayed to all the employees but not to the customer.') . '</p>
			<form action="ajax.php" method="post" onsubmit="saveCustomerNote();return false;" id="customer_note">
				<textarea name="note" id="noteContent" style="width:600px;height:100px" onkeydown="$(\'#submitCustomerNote\').removeAttr(\'disabled\');">' . Tools::htmlentitiesUTF8($customer->note) . '</textarea><br />
				<input type="submit" id="submitCustomerNote" class="button" value="' . $this->l('   Save   ') . '" style="float:left;margin-top:5px" disabled="disabled" />
				<span id="note_feedback" style="float:left;margin:10px 0 0 10px"></span>
			</form>
		</fieldset>
		<div class="clear">&nbsp;</div>
		<script type="text/javascript">
			function saveCustomerNote()
			{
				$("#note_feedback").html("<img src=\\"../img/loader.gif\\" />").show();
				var noteContent = $("#noteContent").val();
				$.post("ajax.php", {submitCustomerNote:1,id_customer:' . (int) $customer->id . ',note:noteContent}, function (r) {
					$("#note_feedback").html("").hide();
					if (r == "ok")
					{
						$("#note_feedback").html("<b style=\\"color:green\\">' . addslashes($this->l('Your note has been saved')) . '</b>").fadeIn(400);
						$("#submitCustomerNote").attr("disabled", "disabled");
					}
					else if (r == "error:validation")
						$("#note_feedback").html("<b style=\\"color:red\\">' . addslashes($this->l('Error: your note is not valid')) . '</b>").fadeIn(400);
					else if (r == "error:update")
						$("#note_feedback").html("<b style=\\"color:red\\">' . addslashes($this->l('Error: cannot save your note')) . '</b>").fadeIn(400);
					$("#note_feedback").fadeOut(3000);
				});
			}
		</script>';
        echo '<h2>' . $this->l('Messages') . ' (' . sizeof($messages) . ')</h2>';
        if (sizeof($messages)) {
            echo '
			<table cellspacing="0" cellpadding="0" class="table">
				<tr>
					<th class="center">' . $this->l('Status') . '</th>
					<th class="center">' . $this->l('Message') . '</th>
					<th class="center">' . $this->l('Sent on') . '</th>
				</tr>';
            foreach ($messages as $message) {
                echo '<tr>
					<td>' . $message['status'] . '</td>
					<td><a href="index.php?tab=AdminCustomerThreads&id_customer_thread=' . (int) $message['id_customer_thread'] . '&viewcustomer_thread&token=' . Tools::getAdminTokenLite('AdminCustomerThreads') . '">' . substr(strip_tags(html_entity_decode($message['message'], ENT_NOQUOTES, 'UTF-8')), 0, 75) . '...</a></td>
					<td>' . Tools::displayDate($message['date_add'], (int) $cookie->id_lang, true) . '</td>
				</tr>';
            }
            echo '</table>
			<div class="clear">&nbsp;</div>';
        } else {
            echo $customer->firstname . ' ' . $customer->lastname . ' ' . $this->l('has never contacted you.');
        }
        // display hook specified to this page : AdminCustomers
        if (($hook = Module::hookExec('adminCustomers', array('id_customer' => $customer->id))) !== false) {
            echo '<div>' . $hook . '</div>';
        }
        echo '<div class="clear">&nbsp;</div>';
        echo '<h2>' . $this->l('Groups') . ' (' . sizeof($groups) . ')</h2>';
        if ($groups and sizeof($groups)) {
            echo '
			<table cellspacing="0" cellpadding="0" class="table">
				<tr>
					<th class="center">' . $this->l('ID') . '</th>
					<th class="center">' . $this->l('Name') . '</th>
					<th class="center">' . $this->l('Actions') . '</th>
				</tr>';
            $tokenGroups = Tools::getAdminToken('AdminGroups' . (int) Tab::getIdFromClassName('AdminGroups') . (int) $cookie->id_employee);
            foreach ($groups as $group) {
                $objGroup = new Group($group);
                echo '
				<tr ' . ($irow++ % 2 ? 'class="alt_row"' : '') . ' style="cursor: pointer" onclick="document.location = \'?tab=AdminGroups&id_group=' . $objGroup->id . '&viewgroup&token=' . $tokenGroups . '\'">
					<td class="center">' . $objGroup->id . '</td>
					<td>' . $objGroup->name[$defaultLanguage] . '</td>
					<td align="center"><a href="?tab=AdminGroups&id_group=' . $objGroup->id . '&viewgroup&token=' . $tokenGroups . '"><img src="../img/admin/details.gif" /></a></td>
				</tr>';
            }
            echo '
			</table>';
        }
        echo '<div class="clear">&nbsp;</div>';
        echo '<h2>' . $this->l('Orders') . ' (' . sizeof($orders) . ')</h2>';
        if ($orders and sizeof($orders)) {
            $totalOK = 0;
            $ordersOK = array();
            $ordersKO = array();
            $tokenOrders = Tools::getAdminToken('AdminOrders' . (int) Tab::getIdFromClassName('AdminOrders') . (int) $cookie->id_employee);
            foreach ($orders as $order) {
                if ($order['valid']) {
                    $ordersOK[] = $order;
                    $totalOK += $order['total_paid_real'];
                } else {
                    $ordersKO[] = $order;
                }
            }
            $orderHead = '
			<table cellspacing="0" cellpadding="0" class="table float">
				<tr>
					<th class="center">' . $this->l('ID') . '</th>
					<th class="center">' . $this->l('Date') . '</th>
					<th class="center">' . $this->l('Products') . '</th>
					<th class="center">' . $this->l('Total paid') . '</th>
					<th class="center">' . $this->l('Payment') . '</th>
					<th class="center">' . $this->l('State') . '</th>
					<th class="center">' . $this->l('Actions') . '</th>
				</tr>';
            $orderFoot = '</table>';
            if ($countOK = sizeof($ordersOK)) {
                echo '<div style="float:left;margin-right:20px"><h3 style="color:green;font-weight:700">' . $this->l('Valid orders:') . ' ' . $countOK . ' ' . $this->l('for') . ' ' . Tools::displayPrice($totalOK, new Currency($defaultCurrency)) . '</h3>' . $orderHead;
                foreach ($ordersOK as $order) {
                    echo '<tr ' . ($irow++ % 2 ? 'class="alt_row"' : '') . ' style="cursor: pointer" onclick="document.location = \'?tab=AdminOrders&id_order=' . $order['id_order'] . '&vieworder&token=' . $tokenOrders . '\'">
						<td class="center">' . $order['id_order'] . '</td>
							<td>' . Tools::displayDate($order['date_add'], (int) $cookie->id_lang) . '</td>
							<td align="right">' . $order['nb_products'] . '</td>
							<td align="right">' . Tools::displayPrice($order['total_paid_real'], new Currency((int) $order['id_currency'])) . '</td>
							<td>' . $order['payment'] . '</td>
							<td>' . $order['order_state'] . '</td>
							<td align="center"><a href="?tab=AdminOrders&id_order=' . $order['id_order'] . '&vieworder&token=' . $tokenOrders . '"><img src="../img/admin/details.gif" /></a></td>
						</tr>';
                }
                echo $orderFoot . '</div>';
            }
            if ($countKO = sizeof($ordersKO)) {
                echo '<div style="float:left;margin-right:20px"><h3 style="color:red;font-weight:700">' . $this->l('Invalid orders:') . ' ' . $countKO . '</h3>' . $orderHead;
                foreach ($ordersKO as $order) {
                    echo '
						<tr ' . ($irow++ % 2 ? 'class="alt_row"' : '') . ' style="cursor: pointer" onclick="document.location = \'?tab=AdminOrders&id_order=' . $order['id_order'] . '&vieworder&token=' . $tokenOrders . '\'">
							<td class="center">' . $order['id_order'] . '</td>
							<td>' . Tools::displayDate($order['date_add'], (int) $cookie->id_lang) . '</td>
							<td align="right">' . $order['nb_products'] . '</td>
							<td align="right">' . Tools::displayPrice($order['total_paid_real'], new Currency((int) $order['id_currency'])) . '</td>
							<td>' . $order['payment'] . '</td>
							<td>' . $order['order_state'] . '</td>
							<td align="center"><a href="?tab=AdminOrders&id_order=' . $order['id_order'] . '&vieworder&token=' . $tokenOrders . '"><img src="../img/admin/details.gif" /></a></td>
						</tr>';
                }
                echo $orderFoot . '</div><div class="clear">&nbsp;</div>';
            }
        } else {
            echo $customer->firstname . ' ' . $customer->lastname . ' ' . $this->l('has not placed any orders yet');
        }
        if ($products and sizeof($products)) {
            echo '<div class="clear">&nbsp;</div>
			<h2>' . $this->l('Products') . ' (' . sizeof($products) . ')</h2>
			<table cellspacing="0" cellpadding="0" class="table">
				<tr>
					<th class="center">' . $this->l('Date') . '</th>
					<th class="center">' . $this->l('Name') . '</th>
					<th class="center">' . $this->l('Quantity') . '</th>
					<th class="center">' . $this->l('Actions') . '</th>
				</tr>';
            $tokenOrders = Tools::getAdminToken('AdminOrders' . (int) Tab::getIdFromClassName('AdminOrders') . (int) $cookie->id_employee);
            foreach ($products as $product) {
                echo '
				<tr ' . ($irow++ % 2 ? 'class="alt_row"' : '') . ' style="cursor: pointer" onclick="document.location = \'?tab=AdminOrders&id_order=' . $product['id_order'] . '&vieworder&token=' . $tokenOrders . '\'">
					<td>' . Tools::displayDate($product['date_add'], (int) $cookie->id_lang, true) . '</td>
					<td>' . $product['product_name'] . '</td>
					<td align="right">' . $product['product_quantity'] . '</td>
					<td align="center"><a href="?tab=AdminOrders&id_order=' . $product['id_order'] . '&vieworder&token=' . $tokenOrders . '"><img src="../img/admin/details.gif" /></a></td>
				</tr>';
            }
            echo '
			</table>';
        }
        echo '<div class="clear">&nbsp;</div>
		<h2>' . $this->l('Addresses') . ' (' . sizeof($addresses) . ')</h2>';
        if (sizeof($addresses)) {
            echo '
			<table cellspacing="0" cellpadding="0" class="table">
				<tr>
					<th>' . $this->l('Company') . '</th>
					<th>' . $this->l('Name') . '</th>
					<th>' . $this->l('Address') . '</th>
					<th>' . $this->l('Country') . '</th>
					<th>' . $this->l('Phone number(s)') . '</th>
					<th>' . $this->l('Actions') . '</th>
				</tr>';
            $tokenAddresses = Tools::getAdminToken('AdminAddresses' . (int) Tab::getIdFromClassName('AdminAddresses') . (int) $cookie->id_employee);
            foreach ($addresses as $address) {
                echo '
				<tr ' . ($irow++ % 2 ? 'class="alt_row"' : '') . '>
					<td>' . ($address['company'] ? $address['company'] : '--') . '</td>
					<td>' . $address['firstname'] . ' ' . $address['lastname'] . '</td>
					<td>' . $address['address1'] . ($address['address2'] ? ' ' . $address['address2'] : '') . ' ' . $address['postcode'] . ' ' . $address['city'] . '</td>
					<td>' . $address['country'] . '</td>
					<td>' . ($address['phone'] ? $address['phone'] . ($address['phone_mobile'] ? '<br />' . $address['phone_mobile'] : '') : ($address['phone_mobile'] ? '<br />' . $address['phone_mobile'] : '--')) . '</td>
					<td align="center">
						<a href="?tab=AdminAddresses&id_address=' . $address['id_address'] . '&addaddress&token=' . $tokenAddresses . '"><img src="../img/admin/edit.gif" /></a>
						<a href="?tab=AdminAddresses&id_address=' . $address['id_address'] . '&deleteaddress&token=' . $tokenAddresses . '"><img src="../img/admin/delete.gif" /></a>
					</td>
				</tr>';
            }
            echo '
			</table>';
        } else {
            echo $customer->firstname . ' ' . $customer->lastname . ' ' . $this->l('has not registered any addresses yet') . '.';
        }
        echo '<div class="clear">&nbsp;</div>
		<h2>' . $this->l('Discounts') . ' (' . sizeof($discounts) . ')</h2>';
        if (sizeof($discounts)) {
            echo '
			<table cellspacing="0" cellpadding="0" class="table">
				<tr>
					<th>' . $this->l('ID') . '</th>
					<th>' . $this->l('Code') . '</th>
					<th>' . $this->l('Type') . '</th>
					<th>' . $this->l('Value') . '</th>
					<th>' . $this->l('Qty available') . '</th>
					<th>' . $this->l('Status') . '</th>
					<th>' . $this->l('Actions') . '</th>
				</tr>';
            $tokenDiscounts = Tools::getAdminToken('AdminDiscounts' . (int) Tab::getIdFromClassName('AdminDiscounts') . (int) $cookie->id_employee);
            foreach ($discounts as $discount) {
                echo '
				<tr ' . ($irow++ % 2 ? 'class="alt_row"' : '') . '>
					<td align="center">' . $discount['id_discount'] . '</td>
					<td>' . $discount['name'] . '</td>
					<td>' . $discount['type'] . '</td>
					<td align="right">' . $discount['value'] . '</td>
					<td align="center">' . $discount['quantity_for_user'] . '</td>
					<td align="center"><img src="../img/admin/' . ($discount['active'] ? 'enabled.gif' : 'disabled.gif') . '" alt="' . $this->l('Status') . '" title="' . $this->l('Status') . '" /></td>
					<td align="center">
						<a href="?tab=AdminDiscounts&id_discount=' . $discount['id_discount'] . '&adddiscount&token=' . $tokenDiscounts . '"><img src="../img/admin/edit.gif" /></a>
						<a href="?tab=AdminDiscounts&id_discount=' . $discount['id_discount'] . '&deletediscount&token=' . $tokenDiscounts . '"><img src="../img/admin/delete.gif" /></a>
					</td>
				</tr>';
            }
            echo '
			</table>';
        } else {
            echo $customer->firstname . ' ' . $customer->lastname . ' ' . $this->l('has no discount vouchers') . '.';
        }
        echo '<div class="clear">&nbsp;</div>';
        echo '<div style="float:left">
		<h2>' . $this->l('Carts') . ' (' . sizeof($carts) . ')</h2>';
        if ($carts and sizeof($carts)) {
            echo '
			<table cellspacing="0" cellpadding="0" class="table">
				<tr>
					<th class="center">' . $this->l('ID') . '</th>
					<th class="center">' . $this->l('Date') . '</th>
					<th class="center">' . $this->l('Total') . '</th>
					<th class="center">' . $this->l('Carrier') . '</th>
					<th class="center">' . $this->l('Actions') . '</th>
				</tr>';
            $tokenCarts = Tools::getAdminToken('AdminCarts' . (int) Tab::getIdFromClassName('AdminCarts') . (int) $cookie->id_employee);
            foreach ($carts as $cart) {
                $cartI = new Cart((int) $cart['id_cart']);
                $summary = $cartI->getSummaryDetails();
                $currency = new Currency((int) $cart['id_currency']);
                $carrier = new Carrier((int) $cart['id_carrier']);
                echo '
				<tr ' . ($irow++ % 2 ? 'class="alt_row"' : '') . ' style="cursor: pointer" onclick="document.location = \'?tab=AdminCarts&id_cart=' . $cart['id_cart'] . '&viewcart&token=' . $tokenCarts . '\'">
					<td class="center">' . sprintf('%06d', $cart['id_cart']) . '</td>
					<td>' . Tools::displayDate($cart['date_add'], (int) $cookie->id_lang, true) . '</td>
					<td align="right">' . Tools::displayPrice($summary['total_price'], $currency) . '</td>
					<td>' . $carrier->name . '</td>
					<td align="center"><a href="index.php?tab=AdminCarts&id_cart=' . $cart['id_cart'] . '&viewcart&token=' . $tokenCarts . '"><img src="../img/admin/details.gif" /></a></td>
				</tr>';
            }
            echo '
			</table>';
        } else {
            echo $this->l('No cart available') . '.';
        }
        echo '</div>';
        $interested = Db::getInstance()->ExecuteS('SELECT DISTINCT id_product FROM ' . _DB_PREFIX_ . 'cart_product cp INNER JOIN ' . _DB_PREFIX_ . 'cart c on c.id_cart = cp.id_cart WHERE c.id_customer = ' . (int) $customer->id . ' AND cp.id_product NOT IN (
		SELECT product_id FROM ' . _DB_PREFIX_ . 'orders o inner join ' . _DB_PREFIX_ . 'order_detail od ON o.id_order = od.id_order WHERE o.valid = 1 AND o.id_customer = ' . (int) $customer->id . ')');
        if (count($interested)) {
            echo '<div style="float:left;margin-left:20px">
			<h2>' . $this->l('Products') . ' (' . count($interested) . ')</h2>
			<table cellspacing="0" cellpadding="0" class="table">';
            foreach ($interested as $p) {
                $product = new Product((int) $p['id_product'], false, $cookie->id_lang);
                echo '
				<tr ' . ($irow++ % 2 ? 'class="alt_row"' : '') . ' style="cursor: pointer" onclick="document.location = \'' . $link->getProductLink((int) $product->id, $product->link_rewrite, Category::getLinkRewrite($product->id_category_default, (int) $cookie->id_lang)) . '\'">
					<td>' . (int) $product->id . '</td>
					<td>' . Tools::htmlentitiesUTF8($product->name) . '</td>
					<td align="center"><a href="' . $link->getProductLink((int) $product->id, $product->link_rewrite, Category::getLinkRewrite($product->id_category_default, (int) $cookie->id_lang)) . '"><img src="../img/admin/details.gif" /></a></td>
				</tr>';
            }
            echo '</table></div>';
        }
        echo '<div class="clear">&nbsp;</div>';
        /* Last connections */
        $connections = $customer->getLastConnections();
        if (sizeof($connections)) {
            echo '<h2>' . $this->l('Last connections') . '</h2>
			<table cellspacing="0" cellpadding="0" class="table">
				<tr>
					<th style="width: 200px">' . $this->l('Date') . '</th>
					<th style="width: 100px">' . $this->l('Pages viewed') . '</th>
					<th style="width: 100px">' . $this->l('Total time') . '</th>
					<th style="width: 100px">' . $this->l('Origin') . '</th>
					<th style="width: 100px">' . $this->l('IP Address') . '</th>
				</tr>';
            foreach ($connections as $connection) {
                echo '<tr>
						<td>' . Tools::displayDate($connection['date_add'], (int) $cookie->id_lang, true) . '</td>
						<td>' . (int) $connection['pages'] . '</td>
						<td>' . $connection['time'] . '</td>
						<td>' . ($connection['http_referer'] ? preg_replace('/^www./', '', parse_url($connection['http_referer'], PHP_URL_HOST)) : $this->l('Direct link')) . '</td>
						<td>' . $connection['ipaddress'] . '</td>
					</tr>';
            }
            echo '</table><div class="clear">&nbsp;</div>';
        }
        if (sizeof($referrers)) {
            echo '<h2>' . $this->l('Referrers') . '</h2>
			<table cellspacing="0" cellpadding="0" class="table">
				<tr>
					<th style="width: 200px">' . $this->l('Date') . '</th>
					<th style="width: 200px">' . $this->l('Name') . '</th>
				</tr>';
            foreach ($referrers as $referrer) {
                echo '<tr>
						<td>' . Tools::displayDate($referrer['date_add'], (int) $cookie->id_lang, true) . '</td>
						<td>' . $referrer['name'] . '</td>
					</tr>';
            }
            echo '</table><div class="clear">&nbsp;</div>';
        }
        echo '<a href="' . $currentIndex . '&token=' . $this->token . '"><img src="../img/admin/arrow2.gif" /> ' . $this->l('Back to customer list') . '</a><br />';
    }
 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);
     $stats_visits = $referrer->getStatsVisits($id_product, $employee);
     $registrations = $referrer->getRegistrations($id_product, $employee);
     $stats_sales = $referrer->getStatsSales($id_product, $employee);
     // If it's a product and it has no visits nor orders
     if ((int) $id_product && !$stats_visits['visits'] && !$stats_sales['orders']) {
         exit;
     }
     $json_array = array('id_product' => (int) $product->id, 'product_name' => addslashes($product->name), 'uniqs' => (int) $stats_visits['uniqs'], 'visitors' => (int) $stats_visits['visitors'], 'visits' => (int) $stats_visits['visits'], 'pages' => (int) $stats_visits['pages'], 'registrations' => (int) $registrations, 'orders' => (int) $stats_sales['orders'], 'sales' => Tools::displayPrice($stats_sales['sales'], $currency), 'cart' => Tools::displayPrice((int) $stats_sales['orders'] ? $stats_sales['sales'] / (int) $stats_sales['orders'] : 0, $currency), 'reg_rate' => number_format((int) $stats_visits['uniqs'] ? (int) $registrations / (int) $stats_visits['uniqs'] : 0, 4, '.', ''), 'order_rate' => number_format((int) $stats_visits['uniqs'] ? (int) $stats_sales['orders'] / (int) $stats_visits['uniqs'] : 0, 4, '.', ''), 'click_fee' => Tools::displayPrice((int) $stats_visits['visits'] * $referrer->click_fee, $currency), 'base_fee' => Tools::displayPrice($stats_sales['orders'] * $referrer->base_fee, $currency), 'percent_fee' => Tools::displayPrice($stats_sales['sales'] * $referrer->percent_fee / 100, $currency));
     die('[' . Tools::jsonEncode($json_array) . ']');
 }
Beispiel #6
0
    public function viewcustomer()
    {
        global $currentIndex, $cookie;
        $irow = 0;
        $configurations = Configuration::getMultiple(array('PS_LANG_DEFAULT', 'PS_CURRENCY_DEFAULT'));
        $defaultLanguage = intval($configurations['PS_LANG_DEFAULT']);
        $defaultCurrency = intval($configurations['PS_CURRENCY_DEFAULT']);
        $customer = $this->loadObject();
        $customerStats = $customer->getStats();
        $addresses = $customer->getAddresses($defaultLanguage);
        $discounts = Discount::getCustomerDiscounts($defaultLanguage, $customer->id, false, false);
        $orders = Order::getCustomerOrders($customer->id);
        $carts = Cart::getCustomerCarts($customer->id);
        $groups = $customer->getGroups();
        $referrers = Referrer::getReferrers($customer->id);
        echo '
		<div style="float: left">
		<fieldset style="width: 400px"><div style="float: right"><a href="' . $currentIndex . '&addcustomer&id_customer=' . $customer->id . '&token=' . $this->token . '"><img src="../img/admin/edit.gif" /></a></div>
			<span style="font-weight: bold; font-size: 14px;">' . $customer->firstname . ' ' . $customer->lastname . '</span>
			<img src="../img/admin/' . ($customer->id_gender == 2 ? 'female' : ($customer->id_gender == 1 ? 'male' : 'unknown')) . '.gif" style="margin-bottom: 5px" /><br />
			<a href="mailto:' . $customer->email . '" style="text-decoration: underline; color: blue">' . $customer->email . '</a><br /><br />
			' . $this->l('ID:') . ' ' . sprintf('%06d', $customer->id) . '<br />
			' . $this->l('Registration date:') . ' ' . Tools::displayDate($customer->date_add, intval($cookie->id_lang), true) . '<br />
			' . $this->l('Last visit:') . ' ' . ($customerStats['last_visit'] ? Tools::displayDate($customerStats['last_visit'], intval($cookie->id_lang), true) : $this->l('never')) . '
		</fieldset>
		</div>
		<div style="float: left; margin-left: 50px">
		<fieldset style="width: 300px"><div style="float: right"><a href="' . $currentIndex . '&addcustomer&id_customer=' . $customer->id . '&token=' . $this->token . '"><img src="../img/admin/edit.gif" /></a></div>
			' . $this->l('Newsletter:') . ' ' . ($customer->newsletter ? '<img src="../img/admin/enabled.gif" />' : '<img src="../img/admin/disabled.gif" />') . '<br />
			' . $this->l('Opt-in:') . ' ' . ($customer->optin ? '<img src="../img/admin/enabled.gif" />' : '<img src="../img/admin/disabled.gif" />') . '<br />
			' . $this->l('Age:') . ' ' . $customerStats['age'] . ' ' . (!empty($customer->birthday['age']) ? '(' . Tools::displayDate($customer->birthday, intval($cookie->id_lang)) . ')' : $this->l('unknown')) . '<br /><br />
			' . $this->l('Last update:') . ' ' . Tools::displayDate($customer->date_upd, intval($cookie->id_lang), true) . '<br />
			' . $this->l('Status:') . ' ' . ($customer->active ? '<img src="../img/admin/enabled.gif" />' : '<img src="../img/admin/disabled.gif" />') . '
		</fieldset>
		</div>
		<div class="clear">&nbsp;</div>';
        // display hook specified to this page : AdminCustomers
        if (($hook = Module::hookExec('adminCustomers', array('id_customer' => $customer->id))) !== false) {
            echo '<div>' . $hook . '</div>';
        }
        echo '<h2>' . $this->l('Groups') . ' (' . sizeof($groups) . ')</h2>';
        if ($groups and sizeof($groups)) {
            echo '
			<table cellspacing="0" cellpadding="0" class="table">
				<tr>
					<th class="center">' . $this->l('ID') . '</th>
					<th class="center">' . $this->l('Name') . '</th>
					<th class="center">' . $this->l('Actions') . '</th>
				</tr>';
            $tokenGroups = Tools::getAdminToken('AdminGroups' . intval(Tab::getIdFromClassName('AdminGroups')) . intval($cookie->id_employee));
            foreach ($groups as $group) {
                $objGroup = new Group($group);
                echo '
				<tr ' . ($irow++ % 2 ? 'class="alt_row"' : '') . ' style="cursor: pointer" onclick="document.location = \'?tab=AdminGroups&id_group=' . $objGroup->id . '&viewgroup&token=' . $tokenGroups . '\'">
					<td class="center">' . $objGroup->id . '</td>
					<td>' . $objGroup->name[$defaultLanguage] . '</td>
					<td align="center"><a href="?tab=AdminGroups&id_group=' . $objGroup->id . '&viewgroup&token=' . $tokenGroups . '"><img src="../img/admin/details.gif" /></a></td>
				</tr>';
            }
            echo '
			</table>';
        }
        echo '<div class="clear">&nbsp;</div>';
        echo '<h2>' . $this->l('Orders') . ' (' . sizeof($orders) . ')</h2>';
        if ($orders and sizeof($orders)) {
            echo '
			<table cellspacing="0" cellpadding="0" class="table">
				<tr>
					<th class="center">' . $this->l('ID') . '</th>
					<th class="center">' . $this->l('Date') . '</th>
					<th class="center">' . $this->l('Quantity') . '</th>
					<th class="center">' . $this->l('Total') . '</th>
					<th class="center">' . $this->l('Payment') . '</th>
					<th class="center">' . $this->l('State') . '</th>
					<th class="center">' . $this->l('Actions') . '</th>
				</tr>';
            $tokenOrders = Tools::getAdminToken('AdminOrders' . intval(Tab::getIdFromClassName('AdminOrders')) . intval($cookie->id_employee));
            foreach ($orders as $order) {
                echo '
				<tr ' . ($irow++ % 2 ? 'class="alt_row"' : '') . ' style="cursor: pointer" onclick="document.location = \'?tab=AdminOrders&id_order=' . $order['id_order'] . '&vieworder&token=' . $tokenOrders . '\'">
					<td class="center">' . sprintf('%06d', $order['id_order']) . '</td>
					<td>' . Tools::displayDate($order['date_add'], intval($cookie->id_lang), true) . '</td>
					<td align="right">' . $order['nb_products'] . '</td>
					<td align="right">' . Tools::displayPrice($order['total_paid'], new Currency(intval($order['id_currency']))) . '</td>
					<td>' . $order['payment'] . '</td>
					<td>' . $order['order_state'] . '</td>
					<td align="center"><a href="?tab=AdminOrders&id_order=' . $order['id_order'] . '&vieworder&token=' . $tokenOrders . '"><img src="../img/admin/details.gif" /></a></td>
				</tr>';
            }
            echo '
			</table>';
        } else {
            echo $customer->firstname . ' ' . $customer->lastname . ' ' . $this->l('has placed no orders yet');
        }
        echo '<div class="clear">&nbsp;</div>
		<h2>' . $this->l('Addresses') . ' (' . sizeof($addresses) . ')</h2>';
        if (sizeof($addresses)) {
            echo '
			<table cellspacing="0" cellpadding="0" class="table">
				<tr>
					<th>' . $this->l('Company') . '</th>
					<th>' . $this->l('Name') . '</th>
					<th>' . $this->l('Address') . '</th>
					<th>' . $this->l('Country') . '</th>
					<th>' . $this->l('Phone number(s)') . '</th>
					<th>' . $this->l('Actions') . '</th>
				</tr>';
            $tokenAddresses = Tools::getAdminToken('AdminAddresses' . intval(Tab::getIdFromClassName('AdminAddresses')) . intval($cookie->id_employee));
            foreach ($addresses as $address) {
                echo '
				<tr ' . ($irow++ % 2 ? 'class="alt_row"' : '') . '>
					<td>' . ($address['company'] ? $address['company'] : '--') . '</td>
					<td>' . $address['firstname'] . ' ' . $address['lastname'] . '</td>
					<td>' . $address['address1'] . ($address['address2'] ? ' ' . $address['address2'] : '') . ' ' . $address['postcode'] . ' ' . $address['city'] . '</td>
					<td>' . $address['country'] . '</td>
					<td>' . ($address['phone'] ? $address['phone'] . ($address['phone_mobile'] ? '<br />' . $address['phone_mobile'] : '') : ($address['phone_mobile'] ? '<br />' . $address['phone_mobile'] : '--')) . '</td>
					<td align="center">
						<a href="?tab=AdminAddresses&id_address=' . $address['id_address'] . '&addaddress&token=' . $tokenAddresses . '"><img src="../img/admin/edit.gif" /></a>
						<a href="?tab=AdminAddresses&id_address=' . $address['id_address'] . '&deleteaddress&token=' . $tokenAddresses . '"><img src="../img/admin/delete.gif" /></a>
					</td>
				</tr>';
            }
            echo '
			</table>';
        } else {
            echo $customer->firstname . ' ' . $customer->lastname . ' ' . $this->l('has registered no addresses yet') . '.';
        }
        echo '<div class="clear">&nbsp;</div>
		<h2>' . $this->l('Discounts') . ' (' . sizeof($discounts) . ')</h2>';
        if (sizeof($discounts)) {
            echo '
			<table cellspacing="0" cellpadding="0" class="table">
				<tr>
					<th>' . $this->l('ID') . '</th>
					<th>' . $this->l('Code') . '</th>
					<th>' . $this->l('Type') . '</th>
					<th>' . $this->l('Value') . '</th>
					<th>' . $this->l('Qty available') . '</th>
					<th>' . $this->l('Status') . '</th>
					<th>' . $this->l('Actions') . '</th>
				</tr>';
            $tokenDiscounts = Tools::getAdminToken('AdminDiscounts' . intval(Tab::getIdFromClassName('AdminDiscounts')) . intval($cookie->id_employee));
            foreach ($discounts as $discount) {
                echo '
				<tr ' . ($irow++ % 2 ? 'class="alt_row"' : '') . '>
					<td align="center">' . $discount['id_discount'] . '</td>
					<td>' . $discount['name'] . '</td>
					<td>' . $discount['type'] . '</td>
					<td align="right">' . $discount['value'] . '</td>
					<td align="center">' . $discount['quantity_for_user'] . '</td>
					<td align="center"><img src="../img/admin/' . ($discount['active'] ? 'enabled.gif' : 'disabled.gif') . '" alt="' . $this->l('Status') . '" title="' . $this->l('Status') . '" /></td>
					<td align="center">
						<a href="?tab=AdminDiscounts&id_discount=' . $discount['id_discount'] . '&adddiscount&token=' . $tokenDiscounts . '"><img src="../img/admin/edit.gif" /></a>
						<a href="?tab=AdminDiscounts&id_discount=' . $discount['id_discount'] . '&deletediscount&token=' . $tokenDiscounts . '"><img src="../img/admin/delete.gif" /></a>
					</td>
				</tr>';
            }
            echo '
			</table>';
        } else {
            echo $customer->firstname . ' ' . $customer->lastname . ' ' . $this->l('has no discount vouchers') . '.';
        }
        echo '<div class="clear">&nbsp;</div>';
        echo '<h2>' . $this->l('Carts') . ' (' . sizeof($carts) . ')</h2>';
        if ($carts and sizeof($carts)) {
            echo '
			<table cellspacing="0" cellpadding="0" class="table">
				<tr>
					<th class="center">' . $this->l('ID') . '</th>
					<th class="center">' . $this->l('Date') . '</th>
					<th class="center">' . $this->l('Total') . '</th>
					<th class="center">' . $this->l('Carrier') . '</th>
					<th class="center">' . $this->l('Actions') . '</th>
				</tr>';
            $tokenCarts = Tools::getAdminToken('AdminCarts' . intval(Tab::getIdFromClassName('AdminCarts')) . intval($cookie->id_employee));
            foreach ($carts as $cart) {
                $cartI = new Cart(intval($cart['id_cart']));
                $summary = $cartI->getSummaryDetails();
                $currency = new Currency(intval($cart['id_currency']));
                $carrier = new Carrier(intval($cart['id_carrier']));
                echo '
				<tr ' . ($irow++ % 2 ? 'class="alt_row"' : '') . ' style="cursor: pointer" onclick="document.location = \'?tab=AdminCarts&id_cart=' . $cart['id_cart'] . '&viewcart&token=' . $tokenCarts . '\'">
					<td class="center">' . sprintf('%06d', $cart['id_cart']) . '</td>
					<td>' . Tools::displayDate($cart['date_add'], intval($cookie->id_lang), true) . '</td>
					<td align="right">' . Tools::displayPrice($summary['total_price'], $currency) . '</td>
					<td>' . $carrier->name . '</td>
					<td align="center"><a href="?tab=AdminCarts&id_cart=' . $cart['id_cart'] . '&viewcart&token=' . $tokenCarts . '"><img src="../img/admin/details.gif" /></a></td>
				</tr>';
            }
            echo '
			</table>';
        } else {
            echo $this->l('No cart available') . '.';
        }
        echo '<div class="clear">&nbsp;</div>';
        /* Last connections */
        $connections = $customer->getLastConnections();
        if (sizeof($connections)) {
            echo '<h2>' . $this->l('Last connections') . '</h2>
            <table cellspacing="0" cellpadding="0" class="table">
                <tr>
                    <th style="width: 200px">' . $this->l('Date') . '</th>
                    <th style="width: 100px">' . $this->l('Pages viewed') . '</th>
                    <th style="width: 100px">' . $this->l('Total time') . '</th>
                    <th style="width: 100px">' . $this->l('Origin') . '</th>
                    <th style="width: 100px">' . $this->l('IP Address') . '</th>
                </tr>';
            foreach ($connections as $connection) {
                echo '<tr>
                        <td>' . Tools::displayDate($connection['date_add'], intval($cookie->id_lang), true) . '</td>
                        <td>' . intval($connection['pages']) . '</td>
                        <td>' . $connection['time'] . '</td>
                        <td>' . ($connection['http_referer'] ? preg_replace('/^www./', '', parse_url($connection['http_referer'], PHP_URL_HOST)) : $this->l('Direct link')) . '</td>
                        <td>' . $connection['ipaddress'] . '</td>
                    </tr>';
            }
            echo '</table><div class="clear">&nbsp;</div>';
        }
        if (sizeof($referrers)) {
            echo '<h2>' . $this->l('Referrers') . '</h2>
            <table cellspacing="0" cellpadding="0" class="table">
                <tr>
                    <th style="width: 200px">' . $this->l('Date') . '</th>
                    <th style="width: 200px">' . $this->l('Name') . '</th>
                </tr>';
            foreach ($referrers as $referrer) {
                echo '<tr>
                        <td>' . Tools::displayDate($referrer['date_add'], intval($cookie->id_lang), true) . '</td>
                        <td>' . $referrer['name'] . '</td>
                    </tr>';
            }
            echo '</table><div class="clear">&nbsp;</div>';
        }
        echo '<a href="' . $currentIndex . '&token=' . $this->token . '"><img src="../img/admin/arrow2.gif" /> ' . $this->l('Back to customer list') . '</a><br />';
    }
    public function renderView()
    {
        /** @var Customer $customer */
        if (!($customer = $this->loadObject())) {
            return;
        }
        $this->context->customer = $customer;
        $gender = new Gender($customer->id_gender, $this->context->language->id);
        $gender_image = $gender->getImage();
        $customer_stats = $customer->getStats();
        $sql = 'SELECT SUM(total_paid_real) FROM ' . _DB_PREFIX_ . 'orders WHERE id_customer = %d AND valid = 1';
        if ($total_customer = Db::getInstance()->getValue(sprintf($sql, $customer->id))) {
            $sql = 'SELECT SQL_CALC_FOUND_ROWS COUNT(*) FROM ' . _DB_PREFIX_ . 'orders WHERE valid = 1 AND id_customer != ' . (int) $customer->id . ' GROUP BY id_customer HAVING SUM(total_paid_real) > %d';
            Db::getInstance()->getValue(sprintf($sql, (int) $total_customer));
            $count_better_customers = (int) Db::getInstance()->getValue('SELECT FOUND_ROWS()') + 1;
        } else {
            $count_better_customers = '-';
        }
        $orders = Order::getCustomerOrders($customer->id, true);
        $total_orders = count($orders);
        for ($i = 0; $i < $total_orders; $i++) {
            $orders[$i]['total_paid_real_not_formated'] = $orders[$i]['total_paid_real'];
            $orders[$i]['total_paid_real'] = Tools::displayPrice($orders[$i]['total_paid_real'], new Currency((int) $orders[$i]['id_currency']));
        }
        $messages = CustomerThread::getCustomerMessages((int) $customer->id);
        $total_messages = count($messages);
        for ($i = 0; $i < $total_messages; $i++) {
            $messages[$i]['message'] = substr(strip_tags(html_entity_decode($messages[$i]['message'], ENT_NOQUOTES, 'UTF-8')), 0, 75);
            $messages[$i]['date_add'] = Tools::displayDate($messages[$i]['date_add'], null, true);
            if (isset(self::$meaning_status[$messages[$i]['status']])) {
                $messages[$i]['status'] = self::$meaning_status[$messages[$i]['status']];
            }
        }
        $groups = $customer->getGroups();
        $total_groups = count($groups);
        for ($i = 0; $i < $total_groups; $i++) {
            $group = new Group($groups[$i]);
            $groups[$i] = array();
            $groups[$i]['id_group'] = $group->id;
            $groups[$i]['name'] = $group->name[$this->default_form_language];
        }
        $total_ok = 0;
        $orders_ok = array();
        $orders_ko = array();
        foreach ($orders as $order) {
            if (!isset($order['order_state'])) {
                $order['order_state'] = $this->l('There is no status defined for this order.');
            }
            if ($order['valid']) {
                $orders_ok[] = $order;
                $total_ok += $order['total_paid_real_not_formated'];
            } else {
                $orders_ko[] = $order;
            }
        }
        $products = $customer->getBoughtProducts();
        $carts = Cart::getCustomerCarts($customer->id);
        $total_carts = count($carts);
        for ($i = 0; $i < $total_carts; $i++) {
            $cart = new Cart((int) $carts[$i]['id_cart']);
            $this->context->cart = $cart;
            $summary = $cart->getSummaryDetails();
            $currency = new Currency((int) $carts[$i]['id_currency']);
            $carrier = new Carrier((int) $carts[$i]['id_carrier']);
            $carts[$i]['id_cart'] = sprintf('%06d', $carts[$i]['id_cart']);
            $carts[$i]['date_add'] = Tools::displayDate($carts[$i]['date_add'], null, true);
            $carts[$i]['total_price'] = Tools::displayPrice($summary['total_price'], $currency);
            $carts[$i]['name'] = $carrier->name;
        }
        $sql = 'SELECT DISTINCT cp.id_product, c.id_cart, c.id_shop, cp.id_shop AS cp_id_shop
				FROM ' . _DB_PREFIX_ . 'cart_product cp
				JOIN ' . _DB_PREFIX_ . 'cart c ON (c.id_cart = cp.id_cart)
				JOIN ' . _DB_PREFIX_ . 'product p ON (cp.id_product = p.id_product)
				WHERE c.id_customer = ' . (int) $customer->id . '
					AND NOT EXISTS (
							SELECT 1
							FROM ' . _DB_PREFIX_ . 'orders o
							JOIN ' . _DB_PREFIX_ . 'order_detail od ON (o.id_order = od.id_order)
							WHERE product_id = cp.id_product AND o.valid = 1 AND o.id_customer = ' . (int) $customer->id . '
						)';
        $interested = Db::getInstance()->executeS($sql);
        $total_interested = count($interested);
        for ($i = 0; $i < $total_interested; $i++) {
            $product = new Product($interested[$i]['id_product'], false, $this->default_form_language, $interested[$i]['id_shop']);
            if (!Validate::isLoadedObject($product)) {
                continue;
            }
            $interested[$i]['url'] = $this->context->link->getProductLink($product->id, $product->link_rewrite, Category::getLinkRewrite($product->id_category_default, $this->default_form_language), null, null, $interested[$i]['cp_id_shop']);
            $interested[$i]['id'] = (int) $product->id;
            $interested[$i]['name'] = Tools::htmlentitiesUTF8($product->name);
        }
        $emails = $customer->getLastEmails();
        $connections = $customer->getLastConnections();
        if (!is_array($connections)) {
            $connections = array();
        }
        $total_connections = count($connections);
        for ($i = 0; $i < $total_connections; $i++) {
            $connections[$i]['http_referer'] = $connections[$i]['http_referer'] ? preg_replace('/^www./', '', parse_url($connections[$i]['http_referer'], PHP_URL_HOST)) : $this->l('Direct link');
        }
        $referrers = Referrer::getReferrers($customer->id);
        $total_referrers = count($referrers);
        for ($i = 0; $i < $total_referrers; $i++) {
            $referrers[$i]['date_add'] = Tools::displayDate($referrers[$i]['date_add'], null, true);
        }
        $customerLanguage = new Language($customer->id_lang);
        $shop = new Shop($customer->id_shop);
        $this->tpl_view_vars = array('customer' => $customer, 'gender' => $gender, 'gender_image' => $gender_image, 'registration_date' => Tools::displayDate($customer->date_add, null, true), 'customer_stats' => $customer_stats, 'last_visit' => Tools::displayDate($customer_stats['last_visit'], null, true), 'count_better_customers' => $count_better_customers, 'shop_is_feature_active' => Shop::isFeatureActive(), 'name_shop' => $shop->name, 'customer_birthday' => Tools::displayDate($customer->birthday), 'last_update' => Tools::displayDate($customer->date_upd, null, true), 'customer_exists' => Customer::customerExists($customer->email), 'id_lang' => $customer->id_lang, 'customerLanguage' => $customerLanguage, 'customer_note' => Tools::htmlentitiesUTF8($customer->note), 'messages' => $messages, 'groups' => $groups, 'orders' => $orders, 'orders_ok' => $orders_ok, 'orders_ko' => $orders_ko, 'total_ok' => Tools::displayPrice($total_ok, $this->context->currency->id), 'products' => $products, 'addresses' => $customer->getAddresses($this->default_form_language), 'discounts' => CartRule::getCustomerCartRules($this->default_form_language, $customer->id, false, false), 'carts' => $carts, 'interested' => $interested, 'emails' => $emails, 'connections' => $connections, 'referrers' => $referrers, 'show_toolbar' => true);
        return parent::renderView();
    }
 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();
 }
Beispiel #9
0
 public function displayAccount()
 {
     if (!isset($this->context->cookie->stats_date_from)) {
         $this->context->cookie->stats_date_from = date('Y-m-01');
     }
     if (!isset($this->context->cookie->stats_date_to)) {
         $this->context->cookie->stats_date_to = date('Y-m-t');
     }
     Referrer::refreshCache(array(array('id_referrer' => (int) $this->context->cookie->tracking_id)));
     $referrer = new Referrer((int) $this->context->cookie->tracking_id);
     $this->smarty->assign('referrer', $referrer);
     $this->smarty->assign('datepickerFrom', $this->context->cookie->stats_date_from);
     $this->smarty->assign('datepickerTo', $this->context->cookie->stats_date_to);
     $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'), 'base_fee' => $this->l('Base fee'), 'percent_fee' => $this->l('Percent fee'), 'click_fee' => $this->l('Click fee'), 'sales' => $this->l('Sales'), 'cart' => $this->l('Average cart'), 'reg_rate' => $this->l('Registration rate'), 'order_rate' => $this->l('Order rate'));
     $this->smarty->assign('displayTab', $display_tab);
     $products = Product::getSimpleProducts($this->context->language->id);
     $products_array = array();
     foreach ($products as $product) {
         $products_array[] = $product['id_product'];
     }
     $js_files = array();
     $jquery_files = Media::getJqueryPath();
     if (is_array($jquery_files)) {
         $js_files = array_merge($js_files, $jquery_files);
     } else {
         $js_files[] = $jquery_files;
     }
     $jquery_ui_files = Media::getJqueryUIPath('ui.datepicker', 'base', true);
     $js_files = array_merge($js_files, $jquery_ui_files['js']);
     $css_files = $jquery_ui_files['css'];
     $js_files[] = $this->_path . 'js/trackingfront.js';
     $js_tpl_var = array('product_ids' => implode(', ', $products_array), 'referrer_id' => $referrer->id, 'token' => $this->context->cookie->tracking_passwd, 'display_tab' => implode('", "', array_keys($display_tab)));
     $this->smarty->assign(array('js' => $js_files, 'css' => $css_files, 'js_tpl_var' => $js_tpl_var));
     return $this->display(__FILE__, 'views/templates/front/account.tpl');
 }
 public function postProcess()
 {
     if ($this->enableCalendar()) {
         // Warning, instantiating a controller here changes the controller in the Context...
         $calendar_tab = new AdminStatsController();
         $calendar_tab->postProcess();
         // ...so we set it back to the correct one here
         $this->context->controller = $this;
     }
     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();
 }
Beispiel #11
0
include "../class.mysqldb.php";
include "../class.referrer.php";
include "../class.shoutbox.php";
include "../class.news.php";
include "../class.patient.php";
include "../class.anesthesiologist.php";
include "../class.site.php";
include "../class.kbase.php";
include "../class.nurse.php";
include "../initsession.php";

$db = new MySQLDB;
$conn = $db->connid();
$db->selectdb("openaims");
$referrer = new Referrer;
$anes = new Anes;
$nurse = new Nurse;
$patient = new Patient;
$site = new Site;
$kbase = new Kbase;
$shoutbox = new Shoutbox;

if (!$site->apply_iprestriction($_SERVER["REMOTE_ADDR"],"DSS")) {
    session_destroy();
    header("location: warning.html");
}

?>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
Beispiel #12
0
 public static function getAjaxProduct($id_referrer, $id_product, $employee = null)
 {
     $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);
     // If it's a product and it has no visits nor orders
     if ((int) $id_product and !$statsVisits['visits'] and !$statsSales['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) . '}]');
 }
Beispiel #13
0
 public static function getAjaxProduct($id_referrer, $id_product, $employee = null)
 {
     $product = new Product($id_product, false, Configuration::get('PS_LANG_DEFAULT'));
     $currency = new Currency(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);
     // If it's a product and it has no visits nor orders
     if (intval($id_product) and !$statsVisits['visits'] and !$statsSales['orders']) {
         exit;
     }
     $jsonArray = array();
     $jsonArray[] = 'id_product:\'' . intval($product->id) . '\'';
     $jsonArray[] = 'product_name:\'' . addslashes($product->name) . '\'';
     $jsonArray[] = 'uniqs:\'' . intval($statsVisits['uniqs']) . '\'';
     $jsonArray[] = 'visitors:\'' . intval($statsVisits['visitors']) . '\'';
     $jsonArray[] = 'visits:\'' . intval($statsVisits['visits']) . '\'';
     $jsonArray[] = 'pages:\'' . intval($statsVisits['pages']) . '\'';
     $jsonArray[] = 'registrations:\'' . intval($registrations) . '\'';
     $jsonArray[] = 'orders:\'' . intval($statsSales['orders']) . '\'';
     $jsonArray[] = 'sales:\'' . Tools::displayPrice($statsSales['sales'], $currency) . '\'';
     $jsonArray[] = 'cart:\'' . Tools::displayPrice(intval($statsSales['orders']) ? $statsSales['sales'] / intval($statsSales['orders']) : 0, $currency) . '\'';
     $jsonArray[] = 'reg_rate:\'' . number_format(intval($statsVisits['uniqs']) ? intval($registrations) / intval($statsVisits['uniqs']) : 0, 4, '.', '') . '\'';
     $jsonArray[] = 'order_rate:\'' . number_format(intval($statsVisits['uniqs']) ? intval($statsSales['orders']) / intval($statsVisits['uniqs']) : 0, 4, '.', '') . '\'';
     $jsonArray[] = 'click_fee:\'' . Tools::displayPrice(intval($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) . '}]');
 }
Beispiel #14
0
	function init() {
		parent::init();

		Requirements::themedCSS("layout");
		Requirements::themedCSS("typography");
		Requirements::themedCSS("form");

		$request = $this->getRequest();
		if($request) {
			$referrerUrl = $request->getHeader('Referer');
			if($referrerUrl) {
				Referrer::log($referrerUrl, $this);
			}
		}
	}