public function process() { parent::process(); $discounts = Discount::getCustomerDiscounts((int) self::$cookie->id_lang, (int) self::$cookie->id_customer, true, false); $nbDiscounts = 0; foreach ($discounts as $discount) { if ($discount['quantity_for_user']) { $nbDiscounts++; } } self::$smarty->assign(array('nbDiscounts' => (int) $nbDiscounts, 'discount' => $discounts)); }
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"> </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"> </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"> </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"> </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"> </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"> </div>'; } } else { echo $customer->firstname . ' ' . $customer->lastname . ' ' . $this->l('has not placed any orders yet'); } if ($products and sizeof($products)) { echo '<div class="clear"> </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"> </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"> </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"> </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"> </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"> </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"> </div>'; } echo '<a href="' . $currentIndex . '&token=' . $this->token . '"><img src="../img/admin/arrow2.gif" /> ' . $this->l('Back to customer list') . '</a><br />'; }
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"> </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"> </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"> </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"> </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"> </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"> </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"> </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"> </div>'; } echo '<a href="' . $currentIndex . '&token=' . $this->token . '"><img src="../img/admin/arrow2.gif" /> ' . $this->l('Back to customer list') . '</a><br />'; }
<?php /* SSL Management */ $useSSL = true; include dirname(__FILE__) . '/config/config.inc.php'; include dirname(__FILE__) . '/init.php'; if (!$cookie->isLogged()) { Tools::redirect('authentication.php?back=discount.php'); } $discounts = Discount::getCustomerDiscounts(intval($cookie->id_lang), intval($cookie->id_customer), true, false); $nbDiscounts = 0; foreach ($discounts as $discount) { if ($discount['quantity_for_user']) { $nbDiscounts++; } } $smarty->assign(array('nbDiscounts' => intval($nbDiscounts), 'discount' => $discounts)); include dirname(__FILE__) . '/header.php'; $smarty->display(_PS_THEME_DIR_ . 'discount.tpl'); include dirname(__FILE__) . '/footer.php';
public function renderView() { if (!($customer = $this->loadObject())) { return; } $this->context->customer = $customer; $gender = new Gender($customer->id_gender); $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 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]['date_add'] = Tools::displayDate($orders[$i]['date_add'], $this->context->language->id); $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'], $this->context->language->id, true); } $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('The state isn\'t still 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(); $total_products = count($products); for ($i = 0; $i < $total_products; $i++) { $products[$i]['date_add'] = Tools::displayDate($products[$i]['date_add'], $this->default_form_language, true); } $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'], $this->default_form_language, true); $carts[$i]['total_price'] = Tools::displayPrice($summary['total_price'], $currency); $carts[$i]['name'] = $carrier->name; } $sql = 'SELECT DISTINCT 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) WHERE c.id_customer = ' . (int) $customer->id . ' AND cp.id_product NOT IN ( SELECT product_id FROM ' . _DB_PREFIX_ . 'orders o JOIN ' . _DB_PREFIX_ . 'order_detail od ON (o.id_order = od.id_order) WHERE 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']); $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); } $connections = $customer->getLastConnections(); $total_connections = count($connections); for ($i = 0; $i < $total_connections; $i++) { $connections[$i]['date_add'] = Tools::displayDate($connections[$i]['date_add'], $this->default_form_language, true); $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'], $this->default_form_language, true); } $shop = new Shop($customer->id_shop); $this->tpl_view_vars = array('customer' => $customer, 'gender_image' => $gender_image, 'registration_date' => Tools::displayDate($customer->date_add, $this->default_form_language, true), 'customer_stats' => $customer_stats, 'last_visit' => Tools::displayDate($customer_stats['last_visit'], $this->default_form_language, true), 'count_better_customers' => $count_better_customers, 'shop_is_feature_active' => Shop::isFeatureActive(), 'name_shop' => $shop->name, 'customer_birthday' => Tools::displayDate($customer->birthday, $this->default_form_language), 'last_update' => Tools::displayDate($customer->date_upd, $this->default_form_language, true), 'customer_exists' => Customer::customerExists($customer->email), 'id_lang' => (int) (count($orders) ? $orders[0]['id_lang'] : Configuration::get('PS_LANG_DEFAULT')), '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' => Discount::getCustomerDiscounts($this->default_form_language, $customer->id, false, false), 'carts' => $carts, 'interested' => $interested, 'connections' => $connections, 'referrers' => $referrers, 'show_toolbar' => true); return parent::renderView(); }