[*] BO #PSFV-94 : Added AdminCustomerController
git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@9608 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
@@ -1,884 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* 2007-2011 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Open Software License (OSL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://opensource.org/licenses/osl-3.0.php
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to http://www.prestashop.com for more information.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2011 PrestaShop SA
|
||||
* @version Release: $Revision: 7320 $
|
||||
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
class AdminCustomers extends AdminTab
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->table = 'customer';
|
||||
$this->className = 'Customer';
|
||||
$this->lang = false;
|
||||
$this->edit = true;
|
||||
$this->view = true;
|
||||
$this->delete = true;
|
||||
$this->deleted = true;
|
||||
$this->requiredDatabase = true;
|
||||
|
||||
$this->_select = '(YEAR(CURRENT_DATE)-YEAR(`birthday`)) - (RIGHT(CURRENT_DATE, 5)<RIGHT(`birthday`, 5)) as age, (
|
||||
SELECT c.date_add FROM '._DB_PREFIX_.'guest g
|
||||
LEFT JOIN '._DB_PREFIX_.'connections c ON c.id_guest = g.id_guest
|
||||
WHERE g.id_customer = a.id_customer
|
||||
ORDER BY c.date_add DESC
|
||||
LIMIT 1
|
||||
) as connect';
|
||||
|
||||
$genders_icon = array('default' => 'unknown.gif');
|
||||
$genders = array(0 => $this->l('?'));
|
||||
foreach (Gender::getGenders() as $gender)
|
||||
{
|
||||
$genders_icon[$gender->id] = '../genders/'.$gender->id.'.jpg';
|
||||
$genders[$gender->id] = $gender->name;
|
||||
}
|
||||
|
||||
$this->fieldsDisplay = array(
|
||||
'id_customer' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25),
|
||||
'id_gender' => array(
|
||||
'title' => $this->l('Gender'),
|
||||
'width' => 30,
|
||||
'align' => 'center',
|
||||
'icon' => $genders_icon,
|
||||
'orderby' => false,
|
||||
'type' => 'select',
|
||||
'select' => $genders,
|
||||
'filter_key' => 'a!id_gender',
|
||||
),
|
||||
'lastname' => array('title' => $this->l('Last Name'), 'width' => 80),
|
||||
'firstname' => array('title' => $this->l('First name'), 'width' => 60),
|
||||
'email' => array('title' => $this->l('E-mail address'), 'width' => 120, 'maxlength' => 19),
|
||||
'age' => array('title' => $this->l('Age'), 'width' => 30, 'search' => false),
|
||||
'active' => array('title' => $this->l('Enabled'), 'width' => 25, 'align' => 'center', 'active' => 'status', 'type' => 'bool', 'orderby' => false),
|
||||
'newsletter' => array('title' => $this->l('News.'), 'width' => 25, 'align' => 'center', 'type' => 'bool', 'callback' => 'printNewsIcon', 'orderby' => false),
|
||||
'optin' => array('title' => $this->l('Opt.'), 'width' => 25, 'align' => 'center', 'type' => 'bool', 'callback' => 'printOptinIcon', 'orderby' => false),
|
||||
'date_add' => array('title' => $this->l('Registration'), 'width' => 30, 'type' => 'date', 'align' => 'right'),
|
||||
'connect' => array('title' => $this->l('Connection'), 'width' => 60, 'type' => 'datetime', 'search' => false),
|
||||
);
|
||||
|
||||
$this->shopLinkType = 'shop';
|
||||
$this->shopShareDatas = Shop::SHARE_CUSTOMER;
|
||||
|
||||
$this->optionsList = array(
|
||||
'general' => array(
|
||||
'title' => $this->l('Customers options'),
|
||||
'fields' => array(
|
||||
'PS_PASSWD_TIME_FRONT' => array('title' => $this->l('Regenerate password:'), 'desc' => $this->l('Security minimum time to wait to regenerate the password'),'validation' => 'isUnsignedInt', 'cast' => 'intval', 'size' => 5, 'type' => 'text', 'suffix' => ' '.$this->l('minutes'))
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function postProcess()
|
||||
{
|
||||
if (Tools::isSubmit('submitDel'.$this->table) OR Tools::isSubmit('delete'.$this->table))
|
||||
{
|
||||
$deleteForm = '
|
||||
<form action="'.htmlentities($_SERVER['REQUEST_URI']).'" method="post">
|
||||
<fieldset><legend>'.$this->l('How do you want to delete your customer(s)?').'</legend>
|
||||
'.$this->l('You have two ways to delete a customer, please choose what you want to do.').'
|
||||
<p>
|
||||
<input type="radio" name="deleteMode" value="real" id="deleteMode_real" />
|
||||
<label for="deleteMode_real" style="float:none">'.$this->l('I want to delete my customer(s) for real, all data will be removed from the database. A customer with the same e-mail address will be able to register again.').'</label>
|
||||
</p>
|
||||
<p>
|
||||
<input type="radio" name="deleteMode" value="deleted" id="deleteMode_deleted" />
|
||||
<label for="deleteMode_deleted" style="float:none">'.$this->l('I don\'t want my customer(s) to register again. The customer(s) will be removed from this list but all data will be kept in the database.').'</label>
|
||||
</p>';
|
||||
foreach ($_POST as $key => $value)
|
||||
if (is_array($value))
|
||||
foreach ($value as $val)
|
||||
$deleteForm .= '<input type="hidden" name="'.htmlentities($key).'[]" value="'.htmlentities($val).'" />';
|
||||
else
|
||||
$deleteForm .= '<input type="hidden" name="'.htmlentities($key).'" value="'.htmlentities($value).'" />';
|
||||
$deleteForm .= ' <br /><input type="submit" class="button" value="'.$this->l(' Delete ').'" />
|
||||
</fieldset>
|
||||
</form>
|
||||
<div class="clear"> </div>';
|
||||
}
|
||||
|
||||
if (Tools::getValue('submitAdd'.$this->table))
|
||||
{
|
||||
$groupList = Tools::getValue('groupBox');
|
||||
|
||||
/* Checking fields validity */
|
||||
$this->validateRules();
|
||||
if (!sizeof($this->_errors))
|
||||
{
|
||||
$id = (int)(Tools::getValue('id_'.$this->table));
|
||||
if (isset($id) AND !empty($id))
|
||||
{
|
||||
if ($this->tabAccess['edit'] !== '1')
|
||||
$this->_errors[] = Tools::displayError('You do not have permission to edit here.');
|
||||
else
|
||||
{
|
||||
$object = new $this->className($id);
|
||||
if (Validate::isLoadedObject($object))
|
||||
{
|
||||
$customer_email = strval(Tools::getValue('email'));
|
||||
|
||||
// check if e-mail already used
|
||||
if ($customer_email != $object->email)
|
||||
{
|
||||
$customer = new Customer();
|
||||
$customer->getByEmail($customer_email);
|
||||
if ($customer->id)
|
||||
$this->_errors[] = Tools::displayError('An account already exists for this e-mail address:').' '.$customer_email;
|
||||
}
|
||||
|
||||
if (!is_array($groupList) OR sizeof($groupList) == 0)
|
||||
$this->_errors[] = Tools::displayError('Customer must be in at least one group.');
|
||||
else
|
||||
if (!in_array(Tools::getValue('id_default_group'), $groupList))
|
||||
$this->_errors[] = Tools::displayError('Default customer group must be selected in group box.');
|
||||
|
||||
// Updating customer's group
|
||||
if (!sizeof($this->_errors))
|
||||
{
|
||||
$object->cleanGroups();
|
||||
if (is_array($groupList) AND sizeof($groupList) > 0)
|
||||
$object->addGroups($groupList);
|
||||
}
|
||||
}
|
||||
else
|
||||
$this->_errors[] = Tools::displayError('An error occurred while loading object.').' <b>'.$this->table.'</b> '.Tools::displayError('(cannot load object)');
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($this->tabAccess['add'] === '1')
|
||||
{
|
||||
$object = new $this->className();
|
||||
$this->copyFromPost($object, $this->table);
|
||||
$shop = new Shop((int)$object->id_shop);
|
||||
$object->id_group_shop = (int)$shop->id_group_shop;
|
||||
if (!$object->add())
|
||||
$this->_errors[] = Tools::displayError('An error occurred while creating object.').' <b>'.$this->table.' ('.Db::getInstance()->getMsgError().')</b>';
|
||||
elseif (($_POST[$this->identifier] = $object->id /* voluntary */) AND $this->postImage($object->id) AND !sizeof($this->_errors) AND $this->_redirect)
|
||||
{
|
||||
// Add Associated groups
|
||||
$group_list = Tools::getValue('groupBox');
|
||||
if (is_array($group_list) && sizeof($group_list) > 0)
|
||||
$object->addGroups($group_list, true);
|
||||
$parent_id = (int)(Tools::getValue('id_parent', 1));
|
||||
// Save and stay on same form
|
||||
if (Tools::isSubmit('submitAdd'.$this->table.'AndStay'))
|
||||
Tools::redirectAdmin(self::$currentIndex.'&'.$this->identifier.'='.$object->id.'&conf=3&update'.$this->table.'&token='.$this->token);
|
||||
// Save and back to parent
|
||||
if (Tools::isSubmit('submitAdd'.$this->table.'AndBackToParent'))
|
||||
Tools::redirectAdmin(self::$currentIndex.'&'.$this->identifier.'='.$parent_id.'&conf=3&token='.$this->token);
|
||||
// Default behavior (save and back)
|
||||
Tools::redirectAdmin(self::$currentIndex.($parent_id ? '&'.$this->identifier.'='.$object->id : '').'&conf=3&token='.$this->token);
|
||||
}
|
||||
}
|
||||
else
|
||||
$this->_errors[] = Tools::displayError('You do not have permission to add here.');
|
||||
}
|
||||
}
|
||||
}
|
||||
elseif (Tools::isSubmit('delete'.$this->table) AND $this->tabAccess['delete'] === '1')
|
||||
{
|
||||
switch (Tools::getValue('deleteMode'))
|
||||
{
|
||||
case 'real':
|
||||
$this->deleted = false;
|
||||
Discount::deleteByIdCustomer((int)(Tools::getValue('id_customer')));
|
||||
break;
|
||||
case 'deleted':
|
||||
$this->deleted = true;
|
||||
break;
|
||||
default:
|
||||
echo $deleteForm;
|
||||
if (isset($_POST['delete'.$this->table]))
|
||||
unset($_POST['delete'.$this->table]);
|
||||
if (isset($_GET['delete'.$this->table]))
|
||||
unset($_GET['delete'.$this->table]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
elseif (Tools::isSubmit('submitDel'.$this->table) AND $this->tabAccess['delete'] === '1')
|
||||
{
|
||||
switch (Tools::getValue('deleteMode'))
|
||||
{
|
||||
case 'real':
|
||||
$this->deleted = false;
|
||||
foreach (Tools::getValue('customerBox') as $id_customer)
|
||||
Discount::deleteByIdCustomer((int)($id_customer));
|
||||
break;
|
||||
case 'deleted':
|
||||
$this->deleted = true;
|
||||
break;
|
||||
default:
|
||||
echo $deleteForm;
|
||||
if (isset($_POST['submitDel'.$this->table]))
|
||||
unset($_POST['submitDel'.$this->table]);
|
||||
if (isset($_GET['submitDel'.$this->table]))
|
||||
unset($_GET['submitDel'.$this->table]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
elseif (Tools::isSubmit('submitGuestToCustomer') AND Tools::getValue('id_customer'))
|
||||
{
|
||||
if ($this->tabAccess['edit'] === '1')
|
||||
{
|
||||
$customer = new Customer((int)Tools::getValue('id_customer'));
|
||||
if (!Validate::isLoadedObject($customer))
|
||||
$this->_errors[] = Tools::displayError('This customer does not exist.');
|
||||
if(Customer::customerExists($customer->email))
|
||||
$this->_errors[] = Tools::displayError('This customer already exist as non-guest.');
|
||||
elseif ($customer->transformToCustomer(Tools::getValue('id_lang', Configuration::get('PS_LANG_DEFAULT'))))
|
||||
Tools::redirectAdmin(self::$currentIndex.'&'.$this->identifier.'='.$customer->id.'&conf=3&token='.$this->token);
|
||||
else
|
||||
$this->_errors[] = Tools::displayError('An error occurred while updating customer.');
|
||||
}
|
||||
else
|
||||
$this->_errors[] = Tools::displayError('You do not have permission to edit here.');
|
||||
}elseif (Tools::isSubmit('changeNewsletterVal') AND Tools::getValue('id_customer'))
|
||||
{
|
||||
$id_customer = (int)Tools::getValue('id_customer');
|
||||
$customer = new Customer($id_customer);
|
||||
if (!Validate::isLoadedObject($customer))
|
||||
$this->_errors[] = Tools::displayError('An error occurred while updating customer.');
|
||||
$update = Db::getInstance()->execute('UPDATE `'._DB_PREFIX_.'customer` SET newsletter = '.($customer->newsletter ? 0 : 1).' WHERE `id_customer` = '.(int)($customer->id));
|
||||
if (!$update)
|
||||
$this->_errors[] = Tools::displayError('An error occurred while updating customer.');
|
||||
Tools::redirectAdmin(self::$currentIndex.'&token='.$this->token);
|
||||
|
||||
}elseif (Tools::isSubmit('changeOptinVal') AND Tools::getValue('id_customer'))
|
||||
{
|
||||
$id_customer = (int)Tools::getValue('id_customer');
|
||||
$customer = new Customer($id_customer);
|
||||
if (!Validate::isLoadedObject($customer))
|
||||
$this->_errors[] = Tools::displayError('An error occurred while updating customer.');
|
||||
$update = Db::getInstance()->execute('UPDATE `'._DB_PREFIX_.'customer` SET optin = '.($customer->optin ? 0 : 1).' WHERE `id_customer` = '.(int)($customer->id));
|
||||
if (!$update)
|
||||
$this->_errors[] = Tools::displayError('An error occurred while updating customer.');
|
||||
Tools::redirectAdmin(self::$currentIndex.'&token='.$this->token);
|
||||
}
|
||||
|
||||
return parent::postProcess();
|
||||
}
|
||||
|
||||
public function viewcustomer()
|
||||
{
|
||||
$irow = 0;
|
||||
$defaultLanguage = $this->context->language->id;
|
||||
if (!($customer = $this->loadObject()))
|
||||
return;
|
||||
$customerStats = $customer->getStats();
|
||||
$addresses = $customer->getAddresses($defaultLanguage);
|
||||
$products = $customer->getBoughtProducts();
|
||||
$discounts = Discount::getCustomerDiscounts($defaultLanguage, $customer->id, false, false);
|
||||
$orders = Order::getCustomerOrders($customer->id, true);
|
||||
$carts = Cart::getCustomerCarts($customer->id);
|
||||
$groups = $customer->getGroups();
|
||||
$messages = CustomerThread::getCustomerMessages((int)$customer->id);
|
||||
$referrers = Referrer::getReferrers($customer->id);
|
||||
if ($totalCustomer = Db::getInstance()->getValue('SELECT SUM(total_paid_real) FROM '._DB_PREFIX_.'orders WHERE id_customer = '.(int)$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) > '.(int)$totalCustomer);
|
||||
$countBetterCustomers = (int)Db::getInstance()->getValue('SELECT FOUND_ROWS()') + 1;
|
||||
}
|
||||
else
|
||||
$countBetterCustomers = '-';
|
||||
|
||||
$gender = new Gender($customer->id_gender);
|
||||
|
||||
echo '
|
||||
<fieldset style="width:400px;float: left"><div style="float: right"><a href="'.self::$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="'.$gender->getImage().'" 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, $this->context->language->id, true).'<br />
|
||||
'.$this->l('Last visit:').' '.($customerStats['last_visit'] ? Tools::displayDate($customerStats['last_visit'], $this->context->language->id, true) : $this->l('never')).'<br />
|
||||
'.($countBetterCustomers != '-' ? $this->l('Rank: #').' '.(int)$countBetterCustomers.'<br />' : '')
|
||||
.(Shop::isFeatureActive() ? '<br />'.$this->l('Shop:').' '.Shop::getInstance($customer->id_shop)->name : '').'
|
||||
</fieldset>
|
||||
<fieldset style="width:300px;float:left;margin-left:50px">
|
||||
<div style="float: right">
|
||||
<a href="'.self::$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, $this->context->language->id).')' : $this->l('unknown')).'<br /><br />
|
||||
'.$this->l('Last update:').' '.Tools::displayDate($customer->date_upd, $this->context->language->id, 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'], $this->context->language->id, 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)$this->context->employee->id);
|
||||
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)$this->context->employee->id);
|
||||
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, $this->context->currency->id).'</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'], $this->context->language->id).'</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'], $this->context->language->id).'</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)$this->context->employee->id);
|
||||
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'], $this->context->language->id, 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)$this->context->employee->id);
|
||||
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)$this->context->employee->id);
|
||||
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)$this->context->employee->id);
|
||||
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'], $this->context->language->id, 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>';
|
||||
|
||||
$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);
|
||||
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($p['id_product'], false, $this->context->language->id, $p['id_shop']);
|
||||
$url = $this->context->link->getProductLink($product->id, $product->link_rewrite, Category::getLinkRewrite($product->id_category_default, $this->context->language->id), null, null, $p['cp_id_shop']);
|
||||
echo '
|
||||
<tr '.($irow++ % 2 ? 'class="alt_row"' : '').' style="cursor: pointer" onclick="document.location = \''.$url.'\'">
|
||||
<td>'.(int)$product->id.'</td>
|
||||
<td>'.Tools::htmlentitiesUTF8($product->name).'</td>
|
||||
<td align="center"><a href="'.$url.'"><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'], $this->context->language->id, 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>
|
||||
'.((Shop::isFeatureActive())? '<th style="width: 200px">'.$this->l('Shop').'</th>' : '').'
|
||||
</tr>';
|
||||
foreach ($referrers as $referrer)
|
||||
echo '<tr>
|
||||
<td>'.Tools::displayDate($referrer['date_add'], $this->context->language->id, true).'</td>
|
||||
<td>'.$referrer['name'].'</td>
|
||||
'.((Shop::isFeatureActive())? '<td>'.$referrer['shop_name'].'</td>' : '').'
|
||||
</tr>';
|
||||
echo '</table><div class="clear"> </div>';
|
||||
}
|
||||
echo '<a href="'.self::$currentIndex.'&token='.$this->token.'"><img src="../img/admin/arrow2.gif" /> '.$this->l('Back to customer list').'</a><br />';
|
||||
}
|
||||
|
||||
public function displayForm($isMainTab = true)
|
||||
{
|
||||
parent::displayForm();
|
||||
|
||||
if (!($obj = $this->loadObject(true)))
|
||||
return;
|
||||
|
||||
$birthday = explode('-', $this->getFieldValue($obj, 'birthday'));
|
||||
$customer_groups = Tools::getValue('groupBox', $obj->getGroups());
|
||||
$groups = Group::getGroups($this->_defaultFormLanguage, true);
|
||||
|
||||
echo '
|
||||
<form action="'.self::$currentIndex.'&submitAdd'.$this->table.'=1&token='.$this->token.'" method="post" autocomplete="off">
|
||||
'.($obj->id ? '<input type="hidden" name="id_'.$this->table.'" value="'.$obj->id.'" />' : '').'
|
||||
<fieldset><legend><img src="../img/admin/tab-customers.gif" />'.$this->l('Customer').'</legend>
|
||||
<label>'.$this->l('Gender:').' </label>
|
||||
<div class="margin-form">';
|
||||
foreach (Gender::getGenders() as $gender)
|
||||
{
|
||||
echo '<input type="radio" size="33" name="id_gender" id="gender_'.$gender->id.'" value="'.$gender->id.'" '.($this->getFieldValue($obj, 'id_gender') == $gender->id ? 'checked="checked" ' : '').'/>';
|
||||
echo '<label class="t" for="gender_'.$gender->id.'"> '.$gender->name.'</label> ';
|
||||
}
|
||||
echo ' <input type="radio" size="33" name="id_gender" id="gender_unknown" value="0" '.(($this->getFieldValue($obj, 'id_gender') == 9 || !$this->getFieldValue($obj, 'id_gender')) ? 'checked="checked" ' : '').'/>
|
||||
<label class="t" for="gender_unknown"> '.$this->l('Unknown').'</label>
|
||||
</div>
|
||||
<label>'.$this->l('Last name:').' </label>
|
||||
<div class="margin-form">
|
||||
<input type="text" size="33" name="lastname" value="'.htmlentities($this->getFieldValue($obj, 'lastname'), ENT_COMPAT, 'UTF-8').'" /> <sup>*</sup>
|
||||
<span class="hint" name="help_box">'.$this->l('Invalid characters:').' 0-9!<>,;?=+()@#"�{}_$%:<span class="hint-pointer"> </span></span>
|
||||
</div>
|
||||
<label>'.$this->l('First name:').' </label>
|
||||
<div class="margin-form">
|
||||
<input type="text" size="33" name="firstname" value="'.htmlentities($this->getFieldValue($obj, 'firstname'), ENT_COMPAT, 'UTF-8').'" /> <sup>*</sup>
|
||||
<span class="hint" name="help_box">'.$this->l('Forbidden characters:').' 0-9!<>,;?=+()@#"�{}_$%:<span class="hint-pointer"> </span></span>
|
||||
</div>
|
||||
<label>'.$this->l('Password:').' </label>
|
||||
<div class="margin-form">
|
||||
<input type="password" size="33" name="passwd" value="" /> '.(!$obj->id ? '<sup>*</sup>' : '').'
|
||||
<p>'.($obj->id ? $this->l('Leave blank if no change') : $this->l('5 characters min., only letters, numbers, or').' -_').'</p>
|
||||
</div>
|
||||
<label>'.$this->l('E-mail address:').' </label>
|
||||
<div class="margin-form">
|
||||
<input type="text" size="33" name="email" value="'.htmlentities($this->getFieldValue($obj, 'email'), ENT_COMPAT, 'UTF-8').'" /> <sup>*</sup>
|
||||
</div>
|
||||
<label>'.$this->l('Birthday:').' </label>';
|
||||
$sl_year = ($this->getFieldValue($obj, 'birthday')) ? $birthday[0] : 0;
|
||||
$years = Tools::dateYears();
|
||||
$sl_month = ($this->getFieldValue($obj, 'birthday')) ? $birthday[1] : 0;
|
||||
$months = Tools::dateMonths();
|
||||
$sl_day = ($this->getFieldValue($obj, 'birthday')) ? $birthday[2] : 0;
|
||||
$days = Tools::dateDays();
|
||||
$tab_months = array(
|
||||
$this->l('January'),
|
||||
$this->l('February'),
|
||||
$this->l('March'),
|
||||
$this->l('April'),
|
||||
$this->l('May'),
|
||||
$this->l('June'),
|
||||
$this->l('July'),
|
||||
$this->l('August'),
|
||||
$this->l('September'),
|
||||
$this->l('October'),
|
||||
$this->l('November'),
|
||||
$this->l('December'));
|
||||
echo '
|
||||
<div class="margin-form">
|
||||
<select name="days">
|
||||
<option value="">-</option>';
|
||||
foreach ($days as $v)
|
||||
echo '<option value="'.$v.'" '.($sl_day == $v ? 'selected="selected"' : '').'>'.$v.'</option>';
|
||||
echo '
|
||||
</select>
|
||||
<select name="months">
|
||||
<option value="">-</option>';
|
||||
foreach ($months as $k => $v)
|
||||
echo '<option value="'.$k.'" '.($sl_month == $k ? 'selected="selected"' : '').'>'.$this->l($v).'</option>';
|
||||
echo '</select>
|
||||
<select name="years">
|
||||
<option value="">-</option>';
|
||||
foreach ($years as $v)
|
||||
echo '<option value="'.$v.'" '.($sl_year == $v ? 'selected="selected"' : '').'>'.$v.'</option>';
|
||||
echo '</select>
|
||||
</div>';
|
||||
echo '<label>'.$this->l('Status:').' </label>
|
||||
<div class="margin-form">
|
||||
<input type="radio" name="active" id="active_on" value="1" '.($this->getFieldValue($obj, 'active') ? 'checked="checked" ' : '').'/>
|
||||
<label class="t" for="active_on"><img src="../img/admin/enabled.gif" alt="'.$this->l('Enabled').'" title="'.$this->l('Enabled').'" /></label>
|
||||
<input type="radio" name="active" id="active_off" value="0" '.(!$this->getFieldValue($obj, 'active') ? 'checked="checked" ' : '').'/>
|
||||
<label class="t" for="active_off"><img src="../img/admin/disabled.gif" alt="'.$this->l('Disabled').'" title="'.$this->l('Disabled').'" /></label>
|
||||
<p>'.$this->l('Allow or disallow this customer to log in').'</p>
|
||||
</div>
|
||||
<label>'.$this->l('Newsletter:').' </label>
|
||||
<div class="margin-form">
|
||||
<input type="radio" name="newsletter" id="newsletter_on" value="1" '.($this->getFieldValue($obj, 'newsletter') ? 'checked="checked" ' : '').'/>
|
||||
<label class="t" for="newsletter_on"><img src="../img/admin/enabled.gif" alt="'.$this->l('Enabled').'" title="'.$this->l('Enabled').'" /></label>
|
||||
<input type="radio" name="newsletter" id="newsletter_off" value="0" '.(!$this->getFieldValue($obj, 'newsletter') ? 'checked="checked" ' : '').'/>
|
||||
<label class="t" for="newsletter_off"><img src="../img/admin/disabled.gif" alt="'.$this->l('Disabled').'" title="'.$this->l('Disabled').'" /></label>
|
||||
<p>'.$this->l('Customer will receive your newsletter via e-mail').'</p>
|
||||
</div>
|
||||
<label>'.$this->l('Opt-in:').' </label>
|
||||
<div class="margin-form">
|
||||
<input type="radio" name="optin" id="optin_on" value="1" '.($this->getFieldValue($obj, 'optin') ? 'checked="checked" ' : '').'/>
|
||||
<label class="t" for="optin_on"><img src="../img/admin/enabled.gif" alt="'.$this->l('Enabled').'" title="'.$this->l('Enabled').'" /></label>
|
||||
<input type="radio" name="optin" id="optin_off" value="0" '.(!$this->getFieldValue($obj, 'optin') ? 'checked="checked" ' : '').'/>
|
||||
<label class="t" for="optin_off"><img src="../img/admin/disabled.gif" alt="'.$this->l('Disabled').'" title="'.$this->l('Disabled').'" /></label>
|
||||
<p>'.$this->l('Customer will receive your ads via e-mail').'</p>
|
||||
</div>
|
||||
<label>'.$this->l('Default group:').' </label>
|
||||
<div class="margin-form">
|
||||
<select name="id_default_group" onchange="checkDefaultGroup(this.value);">';
|
||||
foreach ($groups as $group)
|
||||
echo '<option value="'.(int)($group['id_group']).'"'.($group['id_group'] == $obj->id_default_group ? ' selected="selected"' : '').'>'.htmlentities($group['name'], ENT_NOQUOTES, 'utf-8').'</option>';
|
||||
echo '
|
||||
</select>
|
||||
<div class="hintGroup">'.$this->l('The group will be as applied by default.').'</div>
|
||||
</div>
|
||||
<label>'.$this->l('Groups:').' </label>
|
||||
<div class="margin-form">';
|
||||
if (sizeof($groups))
|
||||
{
|
||||
echo '
|
||||
<table cellspacing="0" cellpadding="0" class="table" style="width: 29.5em;">
|
||||
<tr>
|
||||
<th><input type="checkbox" name="checkme" class="noborder" onclick="checkDelBoxes(this.form, \'groupBox[]\', this.checked)" /></th>
|
||||
<th>'.$this->l('ID').'</th>
|
||||
<th>'.$this->l('Group name').'</th>
|
||||
</tr>';
|
||||
$irow = 0;
|
||||
foreach ($groups as $group)
|
||||
{
|
||||
echo '
|
||||
<tr class="'.($irow++ % 2 ? 'alt_row' : '').'">
|
||||
<td>'.'<input type="checkbox" name="groupBox[]" class="groupBox" id="groupBox_'.$group['id_group'].'" value="'.$group['id_group'].'" '.(in_array($group['id_group'], $customer_groups) ? 'checked="checked" ' : '').'/></td>
|
||||
<td>'.$group['id_group'].'</td>
|
||||
<td><label for="groupBox_'.$group['id_group'].'" class="t">'.$group['name'].'</label></td>
|
||||
</tr>';
|
||||
}
|
||||
echo '
|
||||
</table>
|
||||
<p style="padding:0px; margin:10px 0px 10px 0px;">'.$this->l('Check all the box(es) of groups of which the customer is to be a member').'<sup> *</sup></p>
|
||||
';
|
||||
} else
|
||||
echo '<p>'.$this->l('No group created').'</p>';
|
||||
echo '
|
||||
</div>';
|
||||
if (Shop::isFeatureActive())
|
||||
{
|
||||
$shops = Shop::getShops();
|
||||
echo '
|
||||
<label>'.$this->l('Shop:').' </label>
|
||||
<div class="margin-form">
|
||||
<select name="id_shop">';
|
||||
foreach ($shops as $shop)
|
||||
echo '<option value="'.(int)($shop['id_shop']).'"'.($shop['id_shop'] == (int)Configuration::get('PS_SHOP_DEFAULT') ? ' selected="selected"' : '').'>'.$shop['name'].'</option>';
|
||||
echo '
|
||||
</select>';
|
||||
}
|
||||
echo '
|
||||
<div class="margin-form">
|
||||
<input type="submit" value="'.$this->l(' Save ').'" name="submitAdd'.$this->table.'" class="button" />
|
||||
</div>
|
||||
<div class="small"><sup>*</sup> '.$this->l('Required field').'</div>
|
||||
</fieldset>
|
||||
</form>';
|
||||
}
|
||||
|
||||
public function getList($id_lang, $orderBy = NULL, $orderWay = NULL, $start = 0, $limit = NULL, $id_lang_shop = NULL)
|
||||
{
|
||||
return parent::getList(Context::getContext()->language->id, !Tools::getValue($this->table.'Orderby') ? 'date_add' : NULL, !Tools::getValue($this->table.'Orderway') ? 'DESC' : NULL);
|
||||
}
|
||||
|
||||
public function beforeDelete($object)
|
||||
{
|
||||
return $object->isUsed();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,300 @@
|
||||
{*
|
||||
* 2007-2011 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License (AFL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://opensource.org/licenses/afl-3.0.php
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to http://www.prestashop.com for more information.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2011 PrestaShop SA
|
||||
* @version Release: $Revision: 8971 $
|
||||
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*}
|
||||
|
||||
{if $firstCall}
|
||||
<script type="text/javascript">
|
||||
var vat_number = {$vat_number};
|
||||
var module_dir = '{$module_dir}';
|
||||
var id_language = {$defaultFormLanguage};
|
||||
var languages = new Array();
|
||||
|
||||
$(document).ready(function() {ldelim}
|
||||
{foreach $languages as $k => $language}
|
||||
languages[{$k}] = {ldelim}
|
||||
id_lang: {$language.id_lang},
|
||||
iso_code: '{$language.iso_code}',
|
||||
name: '{$language.name}'
|
||||
{rdelim};
|
||||
{/foreach}
|
||||
displayFlags(languages, id_language, {$allowEmployeeFormLang});
|
||||
|
||||
{if isset($fields_value.id_state)}
|
||||
if ($('#id_country') && $('#id_state'))
|
||||
{ldelim}
|
||||
ajaxStates({$fields_value.id_state});
|
||||
$('#id_country').change(function() {ldelim}
|
||||
ajaxStates();
|
||||
{rdelim});
|
||||
{rdelim}
|
||||
{/if}
|
||||
{rdelim});
|
||||
</script>
|
||||
<script type="text/javascript" src="../js/form.js"></script>
|
||||
{/if}
|
||||
{if isset($fields.title)}<h2>{$fields.title}</h2>{/if}
|
||||
<form action="{$current}&{$submit_action}=1&token={$token}" method="post" enctype="multipart/form-data">
|
||||
{if $form_id}
|
||||
<input type="hidden" name="id_{$table}" value="{$form_id}" />
|
||||
{/if}
|
||||
<fieldset>
|
||||
{foreach $fields as $key => $field}
|
||||
{if $key == 'legend'}
|
||||
<legend>
|
||||
{if isset($field.image)}<img src="{$field.image}" alt="{$field.title}" />{/if}
|
||||
{$field.title}
|
||||
</legend>
|
||||
{elseif $key == 'input'}
|
||||
{foreach $field as $input}
|
||||
{if $input.name == 'id_state'}
|
||||
<div id="contains_states" {if $contains_states}style="display:none;"{/if}>
|
||||
{/if}
|
||||
{if isset($input.label)}
|
||||
<label>{$input.label} </label>
|
||||
{/if}
|
||||
{if $input.type == 'hidden'}
|
||||
<input type="hidden" name="{$input.name}" value="{$fields_value[$input.name]}" />
|
||||
{else}
|
||||
<div class="margin-form">
|
||||
{if $input.type == 'text'}
|
||||
{if isset($input.lang) && isset($input.attributeLang)}
|
||||
{foreach $languages as $language}
|
||||
<div id="{$input.name}_{$language.id_lang}" style="display:{if $language.id_lang == $defaultFormLanguage}block{else}none{/if}; float: left;">
|
||||
<input type="text"
|
||||
name="{$input.name}_{$language.id_lang}"
|
||||
value="{$fields_value[$input.name][$language.id_lang]}"
|
||||
{if isset($input.size)}size="{$input.size}"{/if}
|
||||
{if isset($input.maxlength)}maxlength="{$input.maxlength}"{/if}
|
||||
{if isset($input.class)}class="{$input.class}"{/if}
|
||||
{if isset($input.readonly) && $input.readonly}readonly="readonly"{/if}
|
||||
{if isset($input.disabled) && $input.disabled}disabled="disabled"{/if} />
|
||||
{if isset($input.hint)}<span class="hint" name="help_box">{$input.hint}<span class="hint-pointer"> </span></span>{/if}
|
||||
</div>
|
||||
{/foreach}
|
||||
{if count($languages) > 1}
|
||||
<div class="displayed_flag">
|
||||
<img src="../img/l/{$defaultFormLanguage}.jpg"
|
||||
class="pointer"
|
||||
id="language_current_{$input.name}"
|
||||
onclick="toggleLanguageFlags(this);" />
|
||||
</div>
|
||||
<div id="languages_{$input.name}" class="language_flags">
|
||||
{l s='Choose language:'}<br /><br />
|
||||
{foreach $languages as $language}
|
||||
<img src="../img/l/{$language.id_lang}.jpg"
|
||||
class="pointer"
|
||||
alt="{$language.name}"
|
||||
title="{$language.name}"
|
||||
onclick="changeLanguage('{$input.name}', '{$input.attributeLang}', {$language.id_lang}, '{$language.iso_code}');" />
|
||||
{/foreach}
|
||||
</div>
|
||||
{/if}
|
||||
{else}
|
||||
<input type="text"
|
||||
name="{$input.name}"
|
||||
id="{$input.name}"
|
||||
value="{$fields_value[$input.name]}"
|
||||
{if isset($input.size)}size="{$input.size}"{/if}
|
||||
{if isset($input.maxlength)}maxlength="{$input.maxlength}"{/if}
|
||||
{if isset($input.class)}class="{$input.class}"{/if}
|
||||
{if isset($input.readonly) && $input.readonly}readonly="readonly"{/if}
|
||||
{if isset($input.disabled) && $input.disabled}disabled="disabled"{/if} />
|
||||
{if isset($input.hint)}<span class="hint" name="help_box">{$input.hint}<span class="hint-pointer"> </span></span>{/if}
|
||||
{/if}
|
||||
{elseif $input.type == 'select'}
|
||||
{if isset($input.options.query) && !$input.options.query && isset($input.empty_message)}
|
||||
{$input.empty_message}
|
||||
{$input.required = false}
|
||||
{$input.p = null}
|
||||
{else}
|
||||
<select name="{$input.name}" id="{$input.name}" {if isset($input.multiple)}multiple="multiple" {/if}{if isset($input.onchange)}onchange="{$input.onchange}"{/if}>
|
||||
{if isset($input.options.default)}
|
||||
<option value="{$input.options.default.value}">{$input.options.default.label}</option>
|
||||
{/if}
|
||||
{if isset($input.options.optiongroup)}
|
||||
{foreach $input.options.optiongroup.query AS $optiongroup}
|
||||
<optgroup label="{$optiongroup[$input.options.optiongroup.label]}">
|
||||
{foreach $optiongroup[$input.options.options.query] as $option}
|
||||
<option value="{$option[$input.options.options.id]}"
|
||||
{if isset($input.multiple)}
|
||||
{foreach $fields_value[$input.name] as $field_value}
|
||||
{if $field_value == $option[$input.options.options.id]}selected="selected"{/if}
|
||||
{/foreach}
|
||||
{else}
|
||||
{if $fields_value[$input.name] == $option[$input.options.options.id]}selected="selected"{/if}
|
||||
{/if}
|
||||
>{$option[$input.options.options.name]|escape:'htmlall':'UTF-8'}</option>
|
||||
{/foreach}
|
||||
</optgroup>
|
||||
{/foreach}
|
||||
{else}
|
||||
{foreach $input.options.query AS $option}
|
||||
<option value="{$option[$input.options.id]}"
|
||||
{if isset($input.multiple)}
|
||||
{foreach $fields_value[$input.name] as $field_value}
|
||||
{$field_value}
|
||||
{if $field_value == $option[$input.options.id]}selected="selected"{/if}
|
||||
{/foreach}
|
||||
{else}
|
||||
{if $fields_value[$input.name] == $option[$input.options.id]}selected="selected"{/if}
|
||||
{/if}
|
||||
>{$option[$input.options.name]|escape:'htmlall':'UTF-8'}</option>
|
||||
{/foreach}
|
||||
{/if}
|
||||
</select>
|
||||
{if isset($input.hint)}<span class="hint" name="help_box">{$input.hint}<span class="hint-pointer"> </span></span>{/if}
|
||||
{/if}
|
||||
{elseif $input.type == 'radio'}
|
||||
{foreach $input.values as $value}
|
||||
<input type="radio"
|
||||
name="{$input.name}"
|
||||
id="{$value.id}"
|
||||
value="{$value.value|escape:'htmlall':'UTF-8'}"
|
||||
{if $fields_value[$input.name] == $value.value}checked="checked"{/if} />
|
||||
<label {if isset($input.class)}class="{$input.class}"{/if} for="{$value.id}">
|
||||
{if isset($input.is_bool) && $input.is_bool == true}
|
||||
{if $value.value == 1}
|
||||
<img src="../img/admin/enabled.gif" alt="{$value.label}" title="{$value.label}" />
|
||||
{else}
|
||||
<img src="../img/admin/disabled.gif" alt="{$value.label}" title="{$value.label}" />
|
||||
{/if}
|
||||
{else}
|
||||
{$value.label}
|
||||
{/if}
|
||||
</label>
|
||||
{if isset($input.br) && $input.br}<br />{/if}
|
||||
{/foreach}
|
||||
{elseif $input.type == 'textarea'}
|
||||
{if isset($input.lang) && isset($input.attributeLang)}
|
||||
{foreach $languages as $language}
|
||||
<div id="{$input.name}_{$language.id_lang}" style="display:{if $language.id_lang == $defaultFormLanguage}block{else}none{/if}; float: left;">
|
||||
<textarea cols="{$input.cols}" rows="{$input.rows}" name="{$input.name}_{$language.id_lang}">{$fields_value[$input.name][$language.id_lang]}</textarea>
|
||||
</div>
|
||||
{/foreach}
|
||||
{if count($languages) > 1}
|
||||
<div class="displayed_flag">
|
||||
<img src="../img/l/{$defaultFormLanguage}.jpg"
|
||||
class="pointer"
|
||||
id="language_current_{$input.name}"
|
||||
onclick="toggleLanguageFlags(this);" />
|
||||
</div>
|
||||
<div id="languages_{$input.name}" class="language_flags">
|
||||
{l s='Choose language:'}<br /><br />
|
||||
{foreach $languages as $language}
|
||||
<img src="../img/l/{$language.id_lang}.jpg"
|
||||
class="pointer"
|
||||
alt="{$language.name}"
|
||||
title="{$language.name}"
|
||||
onclick="changeLanguage('{$input.name}', '{$input.attributeLang}', {$language.id_lang}, '{$language.iso_code}');" />
|
||||
{/foreach}
|
||||
</div>
|
||||
{/if}
|
||||
{else}
|
||||
<textarea name="{$input.name}" id="{$input.name}" cols="{$input.cols}" rows="{$input.rows}">{$fields_value[$input.name]}</textarea>
|
||||
{/if}
|
||||
{elseif $input.type == 'checkbox'}
|
||||
{foreach $input.values.query as $value}
|
||||
{assign var=id_checkbox value=$input.name|cat:'_'|cat:$value[$input.values.id]}
|
||||
<input type="checkbox" name="{$id_checkbox}" id="{$id_checkbox}" {if $fields_value[$id_checkbox]}checked="checked"{/if} />
|
||||
<label for="{$id_checkbox}" class="t"><strong>{$value[$input.values.name]}</strong></label><br />
|
||||
{/foreach}
|
||||
{elseif $input.type == 'file'}
|
||||
<input type="file" name="{$input.name}" />
|
||||
<img src="{$fields_value[$input.name]}" />
|
||||
{elseif $input.type == 'password'}
|
||||
<input type="password"
|
||||
name="{$input.name}"
|
||||
size="{$input.size}"
|
||||
value="" />
|
||||
{elseif $input.type == 'birthday'}
|
||||
{foreach $input.options as $key => $select}
|
||||
<select name="{$key}">
|
||||
<option value="">-</option>
|
||||
{if $key == 'months'}
|
||||
{foreach $select as $k => $v}
|
||||
<option value="{$k}" {if $k == $fields_value[$key]}selected="selected"{/if}>{$v}</option>
|
||||
{/foreach}
|
||||
{else}
|
||||
{foreach $select as $v}
|
||||
<option value="{$v}" {if $v == $fields_value[$key]}selected="selected"{/if}>{$v}</option>
|
||||
{/foreach}
|
||||
{/if}
|
||||
</select>
|
||||
{/foreach}
|
||||
{elseif $input.type == 'group'}
|
||||
{assign var=groups value=$input.values}
|
||||
{include file='form_group.tpl'}
|
||||
{elseif $input.type == 'shop' OR $input.type == 'group_shop'}
|
||||
{include file='form_shop.tpl'}
|
||||
{elseif $input.type == 'asso_shop' && isset($asso_shop) && $asso_shop}
|
||||
<label>{l s='Shop association:'}</label>
|
||||
<div class="margin-form">
|
||||
{$asso_shop}
|
||||
</div>
|
||||
{/if}
|
||||
{if isset($input.required) && $input.required} <sup>*</sup>{/if}
|
||||
{if isset($input.p)}
|
||||
<p class="clear">
|
||||
{if is_array($input.p)}
|
||||
{foreach $input.p as $p}
|
||||
{if is_array($p)}
|
||||
<span id="{$p.id}">{$p.text}</span><br />
|
||||
{else}
|
||||
{$p}<br />
|
||||
{/if}
|
||||
{/foreach}
|
||||
{else}
|
||||
{$input.p}
|
||||
{/if}
|
||||
</p>
|
||||
{/if}
|
||||
{if isset($languages)}<div class="clear"></div>{/if}
|
||||
</div>
|
||||
{/if}
|
||||
{if $input.name == 'id_state'}
|
||||
</div>
|
||||
{/if}
|
||||
{/foreach}
|
||||
{elseif $key == 'submit'}
|
||||
<div class="margin-form">
|
||||
<input type="submit" value="{$field.title}" name="{$submit_action}" {if isset($field.class)}class="{$field.class}"{/if} />
|
||||
</div>
|
||||
{/if}
|
||||
{/foreach}
|
||||
{if $required_fields}
|
||||
<div class="small"><sup>*</sup> {l s ='Required field'}</div>
|
||||
{/if}
|
||||
</fieldset>
|
||||
</form>
|
||||
|
||||
<br /><br />
|
||||
{if $firstCall && !$no_back}
|
||||
{if $back}
|
||||
<a href="{$back}"><img src="../img/admin/arrow2.gif" />{l s='Back'}</a>
|
||||
{else}
|
||||
<a href="{$current}&token={$token}"><img src="../img/admin/arrow2.gif" />{l s='Back to list'}</a>
|
||||
{/if}
|
||||
<br />
|
||||
{/if}
|
||||
@@ -0,0 +1,411 @@
|
||||
{*
|
||||
* 2007-2011 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License (AFL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://opensource.org/licenses/afl-3.0.php
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to http://www.prestashop.com for more information.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2011 PrestaShop SA
|
||||
* @version Release: $Revision: 8971 $
|
||||
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*}
|
||||
<script type="text/javascript">
|
||||
function saveCustomerNote()
|
||||
{
|
||||
$('#note_feedback').html('<img src="../img/loader.gif" />').show();
|
||||
var noteContent = $('#noteContent').val();
|
||||
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "ajax.php",
|
||||
data: "submitCustomerNote=1&id_customer={$customer->id}¬e="+noteContent,
|
||||
async : true,
|
||||
success: function(r) {
|
||||
$('#note_feedback').html('').hide();
|
||||
if (r == 'ok')
|
||||
{
|
||||
$('#note_feedback').html("<b style='color:green'>{l s='Your note has been saved'}</b>").fadeIn(400);
|
||||
$('#submitCustomerNote').attr('disabled', 'disabled');
|
||||
}
|
||||
else if (r == 'error:validation')
|
||||
$('#note_feedback').html("<b style='color:red'>({l s='Error: your note is not valid'}</b>").fadeIn(400);
|
||||
else if (r == 'error:update')
|
||||
$('#note_feedback').html("<b style='color:red'>{l s='Error: cannot save your note'}</b>").fadeIn(400);
|
||||
$('#note_feedback').fadeOut(3000);
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
<fieldset style="width:400px;float: left">
|
||||
<div style="float: right">
|
||||
<a href="{$current}&addcustomer&id_customer={$customer->id}&token={$token}">
|
||||
<img src="../img/admin/edit.gif" />
|
||||
</a>
|
||||
</div>
|
||||
<span style="font-weight: bold; font-size: 14px;">
|
||||
{$customer->firstname} {$customer->lastname}
|
||||
</span>
|
||||
<img src="{$gender_image}" style="margin-bottom: 5px" /><br />
|
||||
<a href="mailto:{$customer->email}" style="text-decoration: underline; color: blue">{$customer->email}</a>
|
||||
<br /><br />
|
||||
{l s='ID:'} {$customer->id|string_format:"%06d"}<br />
|
||||
{l s='Registration date:'} {$registration_date}<br />
|
||||
{l s='Last visit:'} {if $customer_stats['last_visit']}{$last_visit}{else}{l s='never'}{/if}<br />
|
||||
{if $count_better_customers != '-'}{l s='Rank: #'} {$count_better_customers}<br />{/if}
|
||||
{if $shop_is_feature_active}{l s='Shop:'} {$name_shop}<br />{/if}
|
||||
</fieldset>
|
||||
|
||||
<fieldset style="width:300px;float:left;margin-left:50px">
|
||||
<div style="float: right">
|
||||
<a href="{$current}&addcustomer&id_customer={$customer->id}&token={$token}">
|
||||
<img src="../img/admin/edit.gif" />
|
||||
</a>
|
||||
</div>
|
||||
{l s='Newsletter:'} {if $customer->newsletter}<img src="../img/admin/enabled.gif" />{else}<img src="../img/admin/disabled.gif" />{/if}<br />
|
||||
{l s='Opt-in:'} {if $customer->optin}<img src="../img/admin/enabled.gif" />{else}<img src="../img/admin/disabled.gif" />{/if}<br />
|
||||
{l s='Age:'} {$customer_stats['age']} {if isset($customer->birthday['age'])}({$customer_birthday}){else}{l s='unknown'}{/if}<br /><br />
|
||||
{l s='Last update:'} {$last_update}<br />
|
||||
{l s='Status:'} {if $customer->active}<img src="../img/admin/enabled.gif" />{else}<img src="../img/admin/disabled.gif" />{/if}
|
||||
|
||||
{if $customer->isGuest()}
|
||||
<div>
|
||||
{l s='This customer is registered as'} <b>{l s='guest'}</b>
|
||||
{if !$customer_exists}
|
||||
<form method="POST" action="index.php?tab=AdminCustomers&id_customer={$customer->id}&token={getAdminToken tab='AdminCustomers'}">
|
||||
<input type="hidden" name="id_lang" value="{$id_lang}" />
|
||||
<p class="center"><input class="button" type="submit" name="submitGuestToCustomer" value="{l s='Transform to customer'}" /></p>
|
||||
{l s='This feature generates a random password and sends an e-mail to the customer'}
|
||||
</form>
|
||||
{else}
|
||||
</div><div><b style="color:red;">{l s='A registered customer account exists with the same email address'}</b>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
</fieldset>
|
||||
|
||||
<div class="clear"> </div>
|
||||
|
||||
<fieldset style="height:190px">
|
||||
<legend>
|
||||
<img src="../img/admin/cms.gif" /> {l s='Add a private note'}
|
||||
</legend>
|
||||
<p>{l s='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');">{$customer_note}</textarea><br />
|
||||
<input type="submit" id="submitCustomerNote" class="button" value="{l s=' 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>
|
||||
|
||||
|
||||
<h2>{l s='Messages'} ({count($messages)})</h2>
|
||||
{if count($messages)}
|
||||
<table cellspacing="0" cellpadding="0" class="table">
|
||||
<tr>
|
||||
<th class="center">{l s='Status'}</th>
|
||||
<th class="center">{l s='Message'}</th>
|
||||
<th class="center">{l s='Sent on'}</th>
|
||||
</tr>
|
||||
{foreach $messages AS $message}
|
||||
<tr>
|
||||
<td>{$message['status']}</td>
|
||||
<td>
|
||||
<a href="index.php?tab=AdminCustomerThreads&id_customer_thread='$message['id_customer_thread']}&viewcustomer_thread&token={getAdminToken tab='AdminCustomerThreads'}">
|
||||
{$message['message']}...
|
||||
</a>
|
||||
</td>
|
||||
<td>{$message['date_add']}</td>
|
||||
</tr>
|
||||
{/foreach}
|
||||
</table>
|
||||
<div class="clear"> </div>
|
||||
{else}
|
||||
{$customer->firstname} {$customer->lastname} {l s='has never contacted you'}
|
||||
{/if}
|
||||
|
||||
{* display hook specified to this page : AdminCustomers *}
|
||||
{if $hook !== false}
|
||||
<div>{$hook}</div>
|
||||
{/if}
|
||||
|
||||
<div class="clear"> </div>
|
||||
|
||||
<h2>{l s='Groups'} ({count($groups)})</h2>
|
||||
{if $groups AND count($groups)}
|
||||
<table cellspacing="0" cellpadding="0" class="table">
|
||||
<tr>
|
||||
<th class="center">{l s='ID'}</th>
|
||||
<th class="center">{l s='Name'}</th>
|
||||
<th class="center">{l s='Actions'}</th>
|
||||
</tr>
|
||||
{foreach $groups AS $key => $group}
|
||||
<tr {if $key %2}class="alt_row"{/if} style="cursor: pointer" onclick="document.location = '?tab=AdminGroups&id_group={$group['id_group']}&viewgroup&token={getAdminToken tab='AdminGroups'}'">
|
||||
<td class="center">{$group['id_group']}</td>
|
||||
<td>{$group['name']}</td>
|
||||
<td align="center"><a href="?tab=AdminGroups&id_group={$group['id_group']}&viewgroup&token={getAdminToken tab='AdminGroups'}"><img src="../img/admin/details.gif" /></a></td>
|
||||
</tr>
|
||||
{/foreach}
|
||||
</table>
|
||||
{/if}
|
||||
<div class="clear"> </div>
|
||||
|
||||
|
||||
<h2>{l s='Orders'} ({count($orders)})</h2>
|
||||
{if $orders AND count($orders)}
|
||||
{assign var=count_ok value=count($orders_ok)}
|
||||
{if $count_ok}
|
||||
<div style="float:left;margin-right:20px">
|
||||
<h3 style="color:green;font-weight:700">
|
||||
{l s='Valid orders:'} {$count_ok} {l s='for'} {$total_ok}
|
||||
</h3>
|
||||
<table cellspacing="0" cellpadding="0" class="table float">
|
||||
<tr>
|
||||
<th class="center">{l s='ID'}</th>
|
||||
<th class="center">{l s='Date'}</th>
|
||||
<th class="center">{l s='Products'}</th>
|
||||
<th class="center">{l s='Total paid'}</th>
|
||||
<th class="center">{l s='Payment'}</th>
|
||||
<th class="center">{l s='State'}</th>
|
||||
<th class="center">{l s='Actions'}</th>
|
||||
</tr>
|
||||
{foreach $orders_ok AS $key => $order}
|
||||
<tr {if $key %2}class="alt_row"{/if} style="cursor: pointer" onclick="document.location = '?tab=AdminOrders&id_order={$order['id_order']}&vieworder&token={getAdminToken tab='AdminOrders'}'">
|
||||
<td class="center">{$order['id_order']}</td>
|
||||
<td>{$order['date_add']}</td>
|
||||
<td align="right">{$order['nb_products']}</td>
|
||||
<td align="right">{$order['total_paid_real']}</td>
|
||||
<td>{$order['payment']}</td>
|
||||
<td>{$order['order_state']}</td>
|
||||
<td align="center"><a href="?tab=AdminOrders&id_order={$order['id_order']}&vieworder&token={getAdminToken tab='AdminOrders'}"><img src="../img/admin/details.gif" /></a></td>
|
||||
</tr>
|
||||
{/foreach}
|
||||
</table>
|
||||
</div>
|
||||
{/if}
|
||||
{assign var=count_ko value=count($orders_ko)}
|
||||
{if $count_ko}
|
||||
<div style="float:left;margin-right:20px">
|
||||
<h3 style="color:red;font-weight:700">{l s='Invalid orders:'} {$count_ko}</h3>
|
||||
<table cellspacing="0" cellpadding="0" class="table float">
|
||||
<tr>
|
||||
<th class="center">{l s='ID'}</th>
|
||||
<th class="center">{l s='Date'}</th>
|
||||
<th class="center">{l s='Products'}</th>
|
||||
<th class="center">{l s='Total paid'}</th>
|
||||
<th class="center">{l s='Payment'}</th>
|
||||
<th class="center">{l s='State'}</th>
|
||||
<th class="center">{l s='Actions'}</th>
|
||||
</tr>
|
||||
{foreach $orders_ko AS $key => $order}
|
||||
<tr {if $key %2}class="alt_row"{/if} style="cursor: pointer" onclick="document.location = '?tab=AdminOrders&id_order={$order['id_order']}&vieworder&token={getAdminToken tab='AdminOrders'}'">
|
||||
<td class="center">{$order['id_order']}</td>
|
||||
<td>{$order['date_add']}</td>
|
||||
<td align="right">{$order['nb_products']}</td>
|
||||
<td align="right">{$order['total_paid_real']}</td>
|
||||
<td>{$order['payment']}</td>
|
||||
<td>{$order['order_state']}</td>
|
||||
<td align="center"><a href="?tab=AdminOrders&id_order={$order['id_order']}&vieworder&token={getAdminToken tab='AdminOrders'}"><img src="../img/admin/details.gif" /></a></td>
|
||||
</tr>
|
||||
{/foreach}
|
||||
</table>
|
||||
</div>
|
||||
<div class="clear"> </div>
|
||||
{/if}
|
||||
{else}
|
||||
{$customer->firstname} {$customer->lastname} {l s='has not placed any orders yet'}
|
||||
{/if}
|
||||
|
||||
{if $products AND count($products)}
|
||||
<div class="clear"> </div>
|
||||
<h2>{l s='Products'} ({count($products)})</h2>
|
||||
<table cellspacing="0" cellpadding="0" class="table">
|
||||
<tr>
|
||||
<th class="center">{l s='Date'}</th>
|
||||
<th class="center">{l s='Name'}</th>
|
||||
<th class="center">{l s='Quantity'}</th>
|
||||
<th class="center">{l s='Actions'}</th>
|
||||
</tr>
|
||||
{foreach $products AS $key => $product}
|
||||
<tr {if $key %2}class="alt_row"{/if} style="cursor: pointer" onclick="document.location = '?tab=AdminOrders&id_order={$product['id_order']}&vieworder&token={getAdminToken tab='AdminOrders'}'">
|
||||
<td>{$product['date_add']}</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={getAdminToken tab='AdminOrders'}"><img src="../img/admin/details.gif" /></a></td>
|
||||
</tr>
|
||||
{/foreach}
|
||||
</table>
|
||||
{/if}
|
||||
<div class="clear"> </div>
|
||||
|
||||
<h2>{l s='Addresses'} ({count($addresses)})</h2>
|
||||
{if count($addresses)}
|
||||
<table cellspacing="0" cellpadding="0" class="table">
|
||||
<tr>
|
||||
<th>{l s='Company'}</th>
|
||||
<th>{l s='Name'}</th>
|
||||
<th>{l s='Address'}</th>
|
||||
<th>{l s='Country'}</th>
|
||||
<th>{l s='Phone number(s)'}</th>
|
||||
<th>{l s='Actions'}</th>
|
||||
</tr>
|
||||
{foreach $addresses AS $key => $address}
|
||||
<tr {if $key %2}class="alt_row"{/if}>
|
||||
<td>{if $address['company']}{$address['company']}{else}--{/if}</td>
|
||||
<td>{$address['firstname']} {$address['lastname']}</td>
|
||||
<td>{$address['address1']} {if $address['address2']}{$address['address2']}{/if} {$address['postcode']} {$address['city']}</td>
|
||||
<td>{$address['country']}</td>
|
||||
<td>
|
||||
{if $address['phone']}
|
||||
{$address['phone']}
|
||||
{if $address['phone_mobile']}<br />{$address['phone_mobile']}{/if}
|
||||
{else}
|
||||
{if $address['phone_mobile']}<br />{$address['phone_mobile']}{else}--{/if}
|
||||
{/if}
|
||||
</td>
|
||||
<td align="center">
|
||||
<a href="?tab=AdminAddresses&id_address={$address['id_address']}&addaddress&token={getAdminToken tab='AdminAddresses'}"><img src="../img/admin/edit.gif" /></a>
|
||||
<a href="?tab=AdminAddresses&id_address={$address['id_address']}&deleteaddress&token={getAdminToken tab='AdminAddresses'}"><img src="../img/admin/delete.gif" /></a>
|
||||
</td>
|
||||
</tr>
|
||||
{/foreach}
|
||||
</table>
|
||||
{else}
|
||||
{$customer->firstname} {$customer->lastname} {l s='has not registered any addresses yet'}
|
||||
{/if}
|
||||
|
||||
<div class="clear"> </div>
|
||||
<h2>{l s='Discounts'} ({count($discounts)})</h2>
|
||||
{if count($discounts)}
|
||||
<table cellspacing="0" cellpadding="0" class="table">
|
||||
<tr>
|
||||
<th>{l s='ID'}</th>
|
||||
<th>{l s='Code'}</th>
|
||||
<th>{l s='Type'}</th>
|
||||
<th>{l s='Value'}</th>
|
||||
<th>{l s='Qty available'}</th>
|
||||
<th>{l s='Status'}</th>
|
||||
<th>{l s='Actions'}</th>
|
||||
</tr>
|
||||
{foreach $discounts AS $key => $discount}
|
||||
<tr {if $key %2}class="alt_row"{/if}>
|
||||
<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/{if $discount['active']}enabled.gif{else}disabled.gif{/if}" alt="{l s='Status'}" title="{l s='Status'}" /></td>
|
||||
<td align="center">
|
||||
<a href="?tab=AdminDiscounts&id_discount={$discount['id_discount']}&adddiscount&token={getAdminToken tab='AdminDiscounts'}"><img src="../img/admin/edit.gif" /></a>
|
||||
<a href="?tab=AdminDiscounts&id_discount={$discount['id_discount']}&deletediscount&token={getAdminToken tab='AdminDiscounts'}"><img src="../img/admin/delete.gif" /></a>
|
||||
</td>
|
||||
</tr>
|
||||
{/foreach}
|
||||
</table>
|
||||
{else}
|
||||
{$customer->firstname} {$customer->lastname} {l s='has no discount vouchers'}.
|
||||
{/if}
|
||||
<div class="clear"> </div>
|
||||
|
||||
<div style="float:left">
|
||||
<h2>{l s='Carts'} ({count($carts)})</h2>
|
||||
{if $carts AND count($carts)}
|
||||
<table cellspacing="0" cellpadding="0" class="table">
|
||||
<tr>
|
||||
<th class="center">{l s='ID'}</th>
|
||||
<th class="center">{l s='Date'}</th>
|
||||
<th class="center">{l s='Total'}</th>
|
||||
<th class="center">{l s='Carrier'}</th>
|
||||
<th class="center">{l s='Actions'}</th>
|
||||
</tr>
|
||||
{foreach $carts AS $key => $cart}
|
||||
<tr {if $key %2}class="alt_row"{/if} style="cursor: pointer" onclick="document.location = '?tab=AdminCarts&id_cart={$cart['id_cart']}&viewcart&token={getAdminToken tab='AdminCarts'}'">
|
||||
<td class="center">{$cart['id_cart']}</td>
|
||||
<td>{$cart['date_add']}</td>
|
||||
<td align="right">{$cart['total_price']}</td>
|
||||
<td>{$cart['name']}</td>
|
||||
<td align="center"><a href="index.php?tab=AdminCarts&id_cart={$cart['id_cart']}&viewcart&token={getAdminToken tab='AdminCarts'}"><img src="../img/admin/details.gif" /></a></td>
|
||||
</tr>
|
||||
{/foreach}
|
||||
</table>
|
||||
{else}
|
||||
{l s='No cart available'}.
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
{if count($interested)}
|
||||
<div style="float:left;margin-left:20px">
|
||||
<h2>{l s='Products'} ({count($interested)})</h2>
|
||||
<table cellspacing="0" cellpadding="0" class="table">
|
||||
{foreach $interested as $key => $p}
|
||||
<tr {if $key %2}class="alt_row"{/if} style="cursor: pointer" onclick="document.location = '{$p['url']}'">
|
||||
<td>{$p['id']}</td>
|
||||
<td>{$p['name']}</td>
|
||||
<td align="center"><a href="{$p['url']}"><img src="../img/admin/details.gif" /></a></td>
|
||||
</tr>
|
||||
{/foreach}
|
||||
</table>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<div class="clear"> </div>
|
||||
|
||||
{* Last connections *}
|
||||
{if count($connections)}
|
||||
<h2>{l s='Last connections'}</h2>
|
||||
<table cellspacing="0" cellpadding="0" class="table">
|
||||
<tr>
|
||||
<th style="width: 200px">{l s='Date'}</th>
|
||||
<th style="width: 100px">{l s='Pages viewed'}</th>
|
||||
<th style="width: 100px">{l s='Total time'}</th>
|
||||
<th style="width: 100px">{l s='Origin'}</th>
|
||||
<th style="width: 100px">{l s='IP Address'}</th>
|
||||
</tr>
|
||||
{foreach $connections as $connection}
|
||||
<tr>
|
||||
<td>{$connection['date_add']}</td>
|
||||
<td>{$connection['pages']}</td>
|
||||
<td>{$connection['time']}</td>
|
||||
<td>{$connection['http_referer']}</td>
|
||||
<td>{$connection['ipaddress']}</td>
|
||||
</tr>
|
||||
{/foreach}
|
||||
</table>
|
||||
<div class="clear"> </div>
|
||||
{/if}
|
||||
|
||||
{if count($referrers)}
|
||||
<h2>{l s='Referrers'}</h2>
|
||||
<table cellspacing="0" cellpadding="0" class="table">
|
||||
<tr>
|
||||
<th style="width: 200px">{l s='Date'}</th>
|
||||
<th style="width: 200px">{l s='Name'}</th>
|
||||
{if $shop_is_feature_active}<th style="width: 200px">{l s='Shop'}</th>{/if}
|
||||
</tr>
|
||||
{foreach $referrers as $referrer}
|
||||
<tr>
|
||||
<td>{$referrer['date_add']}</td>
|
||||
<td>{$referrer['name']}</td>
|
||||
{if $shop_is_feature_active}<td>{$referrer['shop_name']}</td>{/if}
|
||||
</tr>
|
||||
{/foreach}
|
||||
</table>
|
||||
<div class="clear"> </div>
|
||||
{/if}
|
||||
<a href="{$current}&token={$token}"><img src="../img/admin/arrow2.gif" /> {l s='Back to customer list'}</a><br />
|
||||
@@ -98,7 +98,7 @@
|
||||
{/foreach}
|
||||
|
||||
{if $shop_link_type}
|
||||
<td class="center" {if $name != $tr.shop_name}title="$tr.shop_name"{/if}>{$tr.shop_short_name}</td>
|
||||
<td class="center" {if $name != $tr.shop_name}title="{$tr.shop_name}"{/if}>{if isset($tr.shop_short_name)}{$tr.shop_short_name}{else}{$tr.shop_name}{/if}</td>
|
||||
{/if}
|
||||
{if $has_actions}
|
||||
<td class="center" style="white-space: nowrap;">
|
||||
|
||||
@@ -1495,7 +1495,7 @@ class AdminControllerCore extends Controller
|
||||
$select_shop = ', shop.name as shop_name ';
|
||||
$join_shop = ' LEFT JOIN '._DB_PREFIX_.$this->shopLinkType.' shop
|
||||
ON a.id_'.$this->shopLinkType.' = shop.id_'.$this->shopLinkType;
|
||||
$where_shop = $this->context->shop->sqlRestriction($this->shopShareDatas, 'a', $this->shopLinkType);
|
||||
$where_shop = $this->context->shop->addSqlRestriction($this->shopShareDatas, 'a', $this->shopLinkType);
|
||||
}
|
||||
|
||||
$assos = Shop::getAssoTables();
|
||||
|
||||
+142
-120
@@ -27,94 +27,108 @@
|
||||
|
||||
class CustomerCore extends ObjectModel
|
||||
{
|
||||
public $id;
|
||||
public $id;
|
||||
|
||||
public $id_shop;
|
||||
public $id_shop;
|
||||
|
||||
public $id_group_shop;
|
||||
public $id_group_shop;
|
||||
|
||||
/** @var string Secure key */
|
||||
public $secure_key;
|
||||
public $secure_key;
|
||||
|
||||
/** @var string protected note */
|
||||
public $note;
|
||||
public $note;
|
||||
|
||||
/** @var integer Gender ID */
|
||||
public $id_gender = 0;
|
||||
public $id_gender = 0;
|
||||
|
||||
/** @var integer Default group ID */
|
||||
public $id_default_group = _PS_DEFAULT_CUSTOMER_GROUP_;
|
||||
public $id_default_group = _PS_DEFAULT_CUSTOMER_GROUP_;
|
||||
|
||||
/** @var string Lastname */
|
||||
public $lastname;
|
||||
public $lastname;
|
||||
|
||||
/** @var string Firstname */
|
||||
public $firstname;
|
||||
public $firstname;
|
||||
|
||||
/** @var string Birthday (yyyy-mm-dd) */
|
||||
public $birthday = NULL;
|
||||
public $birthday = null;
|
||||
|
||||
/** @var string e-mail */
|
||||
public $email;
|
||||
public $email;
|
||||
|
||||
/** @var boolean Newsletter subscription */
|
||||
public $newsletter;
|
||||
public $newsletter;
|
||||
|
||||
/** @var string Newsletter ip registration */
|
||||
public $ip_registration_newsletter;
|
||||
public $ip_registration_newsletter;
|
||||
|
||||
/** @var string Newsletter ip registration */
|
||||
public $newsletter_date_add;
|
||||
public $newsletter_date_add;
|
||||
|
||||
/** @var boolean Opt-in subscription */
|
||||
public $optin;
|
||||
public $optin;
|
||||
|
||||
/** @var integer Password */
|
||||
public $passwd;
|
||||
public $passwd;
|
||||
|
||||
/** @var datetime Password */
|
||||
public $last_passwd_gen;
|
||||
public $last_passwd_gen;
|
||||
|
||||
/** @var boolean Status */
|
||||
public $active = true;
|
||||
public $active = true;
|
||||
|
||||
/** @var boolean Status */
|
||||
public $is_guest = 0;
|
||||
public $is_guest = 0;
|
||||
|
||||
/** @var boolean True if carrier has been deleted (staying in database as deleted) */
|
||||
public $deleted = 0;
|
||||
public $deleted = 0;
|
||||
|
||||
/** @var string Object creation date */
|
||||
public $date_add;
|
||||
public $date_add;
|
||||
|
||||
/** @var string Object last modification date */
|
||||
public $date_upd;
|
||||
public $date_upd;
|
||||
|
||||
public $years;
|
||||
public $days;
|
||||
public $months;
|
||||
public $years;
|
||||
public $days;
|
||||
public $months;
|
||||
|
||||
/** @var int customer id_country as determined by geolocation */
|
||||
public $geoloc_id_country;
|
||||
public $geoloc_id_country;
|
||||
/** @var int customer id_state as determined by geolocation */
|
||||
public $geoloc_id_state;
|
||||
public $geoloc_id_state;
|
||||
/** @var string customer postcode as determined by geolocation */
|
||||
public $geoloc_postcode;
|
||||
public $geoloc_postcode;
|
||||
|
||||
/** @var boolean is the customer logged in */
|
||||
public $logged = 0;
|
||||
public $logged = 0;
|
||||
|
||||
/** @var int id_guest meaning the guest table, not the guest customer */
|
||||
public $id_guest;
|
||||
public $id_guest;
|
||||
|
||||
protected $tables = array ('customer');
|
||||
|
||||
protected $fieldsRequired = array('lastname', 'passwd', 'firstname', 'email');
|
||||
protected $fieldsSize = array('lastname' => 32, 'passwd' => 32, 'firstname' => 32, 'email' => 128, 'note' => 65000);
|
||||
protected $fieldsValidate = array('secure_key' => 'isMd5', 'lastname' => 'isName', 'firstname' => 'isName', 'email' => 'isEmail', 'passwd' => 'isPasswd',
|
||||
'id_gender' => 'isUnsignedId', 'birthday' => 'isBirthDate', 'newsletter' => 'isBool', 'optin' => 'isBool', 'active' => 'isBool', 'note' => 'isCleanHtml', 'is_guest' => 'isBool', 'id_shop' => 'isUnsignedId','id_group_shop' => 'isUnsignedId',);
|
||||
protected $fieldsRequired = array('lastname', 'passwd', 'firstname', 'email');
|
||||
protected $fieldsSize = array('lastname' => 32, 'passwd' => 32, 'firstname' => 32, 'email' => 128, 'note' => 65000);
|
||||
protected $fieldsValidate = array(
|
||||
'secure_key' => 'isMd5',
|
||||
'lastname' => 'isName',
|
||||
'firstname' => 'isName',
|
||||
'email' => 'isEmail',
|
||||
'passwd' => 'isPasswd',
|
||||
'id_gender' => 'isUnsignedId',
|
||||
'birthday' => 'isBirthDate',
|
||||
'newsletter' => 'isBool',
|
||||
'optin' => 'isBool',
|
||||
'active' => 'isBool',
|
||||
'note' => 'isCleanHtml',
|
||||
'is_guest' => 'isBool',
|
||||
'id_shop' => 'isUnsignedId',
|
||||
'id_group_shop' => 'isUnsignedId'
|
||||
);
|
||||
|
||||
protected $webserviceParameters = array(
|
||||
protected $webserviceParameters = array(
|
||||
'fields' => array(
|
||||
'id_default_group' => array('xlink_resource' => 'groups'),
|
||||
'newsletter_date_add' => array(),
|
||||
@@ -126,8 +140,8 @@ class CustomerCore extends ObjectModel
|
||||
),
|
||||
);
|
||||
|
||||
protected $table = 'customer';
|
||||
protected $identifier = 'id_customer';
|
||||
protected $table = 'customer';
|
||||
protected $identifier = 'id_customer';
|
||||
|
||||
protected static $_defaultGroupId = array();
|
||||
protected static $_customerHasAddress = array();
|
||||
@@ -137,69 +151,69 @@ class CustomerCore extends ObjectModel
|
||||
{
|
||||
$this->validateFields();
|
||||
if (isset($this->id))
|
||||
$fields['id_customer'] = (int)($this->id);
|
||||
$fields['id_customer'] = (int)$this->id;
|
||||
|
||||
$fields['id_shop'] = (int)$this->id_shop;
|
||||
$fields['id_group_shop'] = (int)$this->id_group_shop;
|
||||
$fields['secure_key'] = pSQL($this->secure_key);
|
||||
$fields['note'] = pSQL($this->note, true);
|
||||
$fields['id_gender'] = (int)($this->id_gender);
|
||||
$fields['id_default_group'] = (int)($this->id_default_group);
|
||||
$fields['id_gender'] = (int)$this->id_gender;
|
||||
$fields['id_default_group'] = (int)$this->id_default_group;
|
||||
$fields['lastname'] = pSQL($this->lastname);
|
||||
$fields['firstname'] = pSQL($this->firstname);
|
||||
$fields['birthday'] = pSQL($this->birthday);
|
||||
$fields['email'] = pSQL($this->email);
|
||||
$fields['newsletter'] = (int)($this->newsletter);
|
||||
$fields['newsletter'] = (int)$this->newsletter;
|
||||
$fields['newsletter_date_add'] = pSQL($this->newsletter_date_add);
|
||||
$fields['ip_registration_newsletter'] = pSQL($this->ip_registration_newsletter);
|
||||
$fields['optin'] = (int)($this->optin);
|
||||
$fields['optin'] = (int)$this->optin;
|
||||
$fields['passwd'] = pSQL($this->passwd);
|
||||
$fields['last_passwd_gen'] = pSQL($this->last_passwd_gen);
|
||||
$fields['active'] = (int)($this->active);
|
||||
$fields['active'] = (int)$this->active;
|
||||
$fields['date_add'] = pSQL($this->date_add);
|
||||
$fields['date_upd'] = pSQL($this->date_upd);
|
||||
$fields['is_guest'] = (int)($this->is_guest);
|
||||
$fields['deleted'] = (int)($this->deleted);
|
||||
$fields['is_guest'] = (int)$this->is_guest;
|
||||
$fields['deleted'] = (int)$this->deleted;
|
||||
return $fields;
|
||||
}
|
||||
|
||||
public function add($autodate = true, $nullValues = true)
|
||||
public function add($autodate = true, $null_values = true)
|
||||
{
|
||||
$this->id_shop = ($this->id_shop) ? $this->id_shop : Context::getContext()->shop->getID();
|
||||
$this->id_group_shop = ($this->id_group_shop) ? $this->id_group_shop : Context::getContext()->shop->getGroupID();
|
||||
$this->birthday = (empty($this->years) ? $this->birthday : (int)($this->years).'-'.(int)($this->months).'-'.(int)($this->days));
|
||||
$this->birthday = (empty($this->years) ? $this->birthday : (int)$this->years.'-'.(int)$this->months.'-'.(int)$this->days);
|
||||
$this->secure_key = md5(uniqid(rand(), true));
|
||||
$this->last_passwd_gen = date('Y-m-d H:i:s', strtotime('-'.Configuration::get('PS_PASSWD_TIME_FRONT').'minutes'));
|
||||
if (empty($this->id_default_group))
|
||||
$this->id_default_group = 1;
|
||||
/* Can't create a guest customer, if this feature is disabled */
|
||||
if ($this->is_guest AND !Configuration::get('PS_GUEST_CHECKOUT_ENABLED'))
|
||||
if ($this->is_guest && !Configuration::get('PS_GUEST_CHECKOUT_ENABLED'))
|
||||
return false;
|
||||
if (!parent::add($autodate, $nullValues))
|
||||
if (!parent::add($autodate, $null_values))
|
||||
return false;
|
||||
|
||||
$row = array('id_customer' => (int)($this->id), 'id_group' => (int)$this->id_default_group);
|
||||
$row = array('id_customer' => (int)$this->id, 'id_group' => (int)$this->id_default_group);
|
||||
return Db::getInstance()->AutoExecute(_DB_PREFIX_.'customer_group', $row, 'INSERT');
|
||||
}
|
||||
|
||||
public function update($nullValues = false)
|
||||
public function update()
|
||||
{
|
||||
$this->birthday = (empty($this->years) ? $this->birthday : (int)$this->years.'-'.(int)$this->months.'-'.(int)$this->days);
|
||||
if ($this->newsletter AND !$this->newsletter_date_add)
|
||||
if ($this->newsletter && !$this->newsletter_date_add)
|
||||
$this->newsletter_date_add = date('Y-m-d H:i:s');
|
||||
return parent::update(true);
|
||||
}
|
||||
|
||||
public function delete()
|
||||
{
|
||||
$addresses = $this->getAddresses((int)(Configuration::get('PS_LANG_DEFAULT')));
|
||||
foreach ($addresses AS $address)
|
||||
$addresses = $this->getAddresses((int)Configuration::get('PS_LANG_DEFAULT'));
|
||||
foreach ($addresses as $address)
|
||||
{
|
||||
$obj = new Address((int)($address['id_address']));
|
||||
$obj = new Address((int)$address['id_address']);
|
||||
$obj->delete();
|
||||
}
|
||||
Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'customer_group` WHERE `id_customer` = '.(int)($this->id));
|
||||
Discount::deleteByIdCustomer((int)($this->id));
|
||||
Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'customer_group` WHERE `id_customer` = '.(int)$this->id);
|
||||
Discount::deleteByIdCustomer((int)$this->id);
|
||||
return parent::delete();
|
||||
}
|
||||
|
||||
@@ -208,7 +222,7 @@ class CustomerCore extends ObjectModel
|
||||
*
|
||||
* @return array Customers
|
||||
*/
|
||||
static public function getCustomers(Shop $shop = null)
|
||||
public static function getCustomers(Shop $shop = null)
|
||||
{
|
||||
if (!$shop)
|
||||
$shop = Context::getContext()->shop;
|
||||
@@ -227,16 +241,16 @@ class CustomerCore extends ObjectModel
|
||||
* @param string $passwd Password is also checked if specified
|
||||
* @return Customer instance
|
||||
*/
|
||||
public function getByEmail($email, $passwd = NULL, Shop $shop = null)
|
||||
public function getByEmail($email, $passwd = null, Shop $shop = null)
|
||||
{
|
||||
if (!Validate::isEmail($email) OR ($passwd AND !Validate::isPasswd($passwd)))
|
||||
if (!Validate::isEmail($email) || ($passwd && !Validate::isPasswd($passwd)))
|
||||
die (Tools::displayError());
|
||||
|
||||
if (!$shop)
|
||||
$shop = Context::getContext()->shop;
|
||||
|
||||
$sql = 'SELECT *
|
||||
FROM `'._DB_PREFIX_ .'customer`
|
||||
FROM `'._DB_PREFIX_.'customer`
|
||||
WHERE `active` = 1
|
||||
AND `email` = \''.pSQL($email).'\'
|
||||
'.$shop->addSqlRestriction(Shop::SHARE_CUSTOMER).'
|
||||
@@ -248,7 +262,7 @@ class CustomerCore extends ObjectModel
|
||||
if (!$result)
|
||||
return false;
|
||||
$this->id = $result['id_customer'];
|
||||
foreach ($result AS $key => $value)
|
||||
foreach ($result as $key => $value)
|
||||
if (key_exists($key, $this))
|
||||
$this->{$key} = $value;
|
||||
|
||||
@@ -267,7 +281,7 @@ class CustomerCore extends ObjectModel
|
||||
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
|
||||
SELECT `id_customer`
|
||||
FROM `'._DB_PREFIX_.'customer`
|
||||
WHERE `id_customer` = \''.(int)($id_customer).'\'
|
||||
WHERE `id_customer` = \''.(int)$id_customer.'\'
|
||||
AND active = 1
|
||||
AND `deleted` = 0');
|
||||
if (isset($result['id_customer']))
|
||||
@@ -280,10 +294,10 @@ class CustomerCore extends ObjectModel
|
||||
*
|
||||
* @param string $email e-mail
|
||||
* @param $return_id boolean
|
||||
* @param $ignoreGuest boolean, to exclude guest customer
|
||||
* @param $ignore_guest boolean, to exclude guest customer
|
||||
* @return Customer ID if found, false otherwise
|
||||
*/
|
||||
static public function customerExists($email, $return_id = false, $ignoreGuest = true, Shop $shop = null)
|
||||
public static function customerExists($email, $return_id = false, $ignore_guest = true, Shop $shop = null)
|
||||
{
|
||||
if (!Validate::isEmail($email))
|
||||
die (Tools::displayError());
|
||||
@@ -295,7 +309,7 @@ class CustomerCore extends ObjectModel
|
||||
FROM `'._DB_PREFIX_.'customer`
|
||||
WHERE `email` = \''.pSQL($email).'\'
|
||||
'.$shop->addSqlRestriction(Shop::SHARE_CUSTOMER).
|
||||
($ignoreGuest ? 'AND `is_guest` = 0' : '');
|
||||
($ignore_guest ? 'AND `is_guest` = 0' : '');
|
||||
$result = Db::getInstance()->getRow($sql);
|
||||
|
||||
if ($return_id)
|
||||
@@ -317,8 +331,8 @@ class CustomerCore extends ObjectModel
|
||||
self::$_customerHasAddress[$id_customer] = (bool)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
|
||||
SELECT `id_address`
|
||||
FROM `'._DB_PREFIX_.'address`
|
||||
WHERE `id_customer` = '.(int)($id_customer).'
|
||||
AND `id_address` = '.(int)($id_address).'
|
||||
WHERE `id_customer` = '.(int)$id_customer.'
|
||||
AND `id_address` = '.(int)$id_address.'
|
||||
AND `deleted` = 0');
|
||||
}
|
||||
return self::$_customerHasAddress[$id_customer];
|
||||
@@ -343,7 +357,7 @@ class CustomerCore extends ObjectModel
|
||||
LEFT JOIN `'._DB_PREFIX_.'country` c ON (a.`id_country` = c.`id_country`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'country_lang` cl ON (c.`id_country` = cl.`id_country`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'state` s ON (s.`id_state` = a.`id_state`)
|
||||
WHERE `id_lang` = '.(int)($id_lang).' AND `id_customer` = '.(int)($this->id).' AND a.`deleted` = 0';
|
||||
WHERE `id_lang` = '.(int)$id_lang.' AND `id_customer` = '.(int)$this->id.' AND a.`deleted` = 0';
|
||||
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
|
||||
}
|
||||
|
||||
@@ -356,10 +370,11 @@ class CustomerCore extends ObjectModel
|
||||
public static function getAddressesTotalById($id_customer)
|
||||
{
|
||||
return Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
|
||||
SELECT COUNT(`id_address`)
|
||||
FROM `'._DB_PREFIX_.'address`
|
||||
WHERE `id_customer` = '.(int)($id_customer).'
|
||||
AND `deleted` = 0');
|
||||
SELECT COUNT(`id_address`)
|
||||
FROM `'._DB_PREFIX_.'address`
|
||||
WHERE `id_customer` = '.(int)$id_customer.'
|
||||
AND `deleted` = 0'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -370,7 +385,7 @@ class CustomerCore extends ObjectModel
|
||||
*/
|
||||
public static function checkPassword($id_customer, $passwd)
|
||||
{
|
||||
if (!Validate::isUnsignedId($id_customer) OR !Validate::isMd5($passwd))
|
||||
if (!Validate::isUnsignedId($id_customer) || !Validate::isMd5($passwd))
|
||||
die (Tools::displayError());
|
||||
|
||||
$sql = 'SELECT `id_customer`
|
||||
@@ -412,19 +427,19 @@ class CustomerCore extends ObjectModel
|
||||
$result = Db::getInstance()->getRow('
|
||||
SELECT COUNT(`id_order`) AS nb_orders, SUM(`total_paid` / o.`conversion_rate`) AS total_orders
|
||||
FROM `'._DB_PREFIX_.'orders` o
|
||||
WHERE o.`id_customer` = '.(int)($this->id).'
|
||||
WHERE o.`id_customer` = '.(int)$this->id.'
|
||||
AND o.valid = 1');
|
||||
|
||||
$result2 = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
|
||||
SELECT MAX(c.`date_add`) AS last_visit
|
||||
FROM `'._DB_PREFIX_.'guest` g
|
||||
LEFT JOIN `'._DB_PREFIX_.'connections` c ON c.id_guest = g.id_guest
|
||||
WHERE g.`id_customer` = '.(int)($this->id));
|
||||
WHERE g.`id_customer` = '.(int)$this->id);
|
||||
|
||||
$result3 = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
|
||||
SELECT (YEAR(CURRENT_DATE)-YEAR(c.`birthday`)) - (RIGHT(CURRENT_DATE, 5)<RIGHT(c.`birthday`, 5)) AS age
|
||||
FROM `'._DB_PREFIX_.'customer` c
|
||||
WHERE c.`id_customer` = '.(int)($this->id));
|
||||
WHERE c.`id_customer` = '.(int)$this->id);
|
||||
|
||||
$result['last_visit'] = $result2['last_visit'];
|
||||
$result['age'] = ($result3['age'] != date('Y') ? $result3['age'] : '--');
|
||||
@@ -432,17 +447,17 @@ class CustomerCore extends ObjectModel
|
||||
}
|
||||
|
||||
public function getLastConnections()
|
||||
{
|
||||
{
|
||||
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
|
||||
SELECT c.date_add, COUNT(cp.id_page) AS pages, TIMEDIFF(MAX(cp.time_end), c.date_add) as time, http_referer,INET_NTOA(ip_address) as ipaddress
|
||||
FROM `'._DB_PREFIX_.'guest` g
|
||||
LEFT JOIN `'._DB_PREFIX_.'connections` c ON c.id_guest = g.id_guest
|
||||
LEFT JOIN `'._DB_PREFIX_.'connections_page` cp ON c.id_connections = cp.id_connections
|
||||
WHERE g.`id_customer` = '.(int)($this->id).'
|
||||
WHERE g.`id_customer` = '.(int)$this->id.'
|
||||
GROUP BY c.`id_connections`
|
||||
ORDER BY c.date_add DESC
|
||||
LIMIT 10');
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Specify if a customer already in base
|
||||
@@ -453,7 +468,7 @@ class CustomerCore extends ObjectModel
|
||||
// DEPRECATED
|
||||
public function customerIdExists($id_customer)
|
||||
{
|
||||
return self::customerIdExistsStatic((int)($id_customer));
|
||||
return self::customerIdExistsStatic((int)$id_customer);
|
||||
}
|
||||
|
||||
public static function customerIdExistsStatic($id_customer)
|
||||
@@ -461,22 +476,33 @@ class CustomerCore extends ObjectModel
|
||||
$row = Db::getInstance()->getRow('
|
||||
SELECT `id_customer`
|
||||
FROM '._DB_PREFIX_.'customer c
|
||||
WHERE c.`id_customer` = '.(int)($id_customer));
|
||||
WHERE c.`id_customer` = '.(int)$id_customer);
|
||||
|
||||
return isset($row['id_customer']);
|
||||
}
|
||||
|
||||
public function cleanGroups()
|
||||
{
|
||||
Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'customer_group` WHERE `id_customer` = '.(int)($this->id));
|
||||
Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'customer_group` WHERE `id_customer` = '.(int)$this->id);
|
||||
}
|
||||
|
||||
public function addGroups($groups)
|
||||
{
|
||||
foreach ($groups as $group)
|
||||
{
|
||||
$row = array('id_customer' => (int)($this->id), 'id_group' => (int)($group));
|
||||
Db::getInstance()->AutoExecute(_DB_PREFIX_.'customer_group', $row, 'INSERT');
|
||||
$groups_customers = $this->getGroups();
|
||||
if (count($groups_customers) == 0)
|
||||
{
|
||||
$row = array('id_customer' => (int)$this->id, 'id_group' => (int)$group);
|
||||
Db::getInstance()->AutoExecute(_DB_PREFIX_.'customer_group', $row, 'INSERT');
|
||||
}
|
||||
else
|
||||
foreach ($groups_customers as $group_customers)
|
||||
if ($group_customers != $group)
|
||||
{
|
||||
$row = array('id_customer' => (int)$this->id, 'id_group' => (int)$group);
|
||||
Db::getInstance()->AutoExecute(_DB_PREFIX_.'customer_group', $row, 'INSERT');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -513,7 +539,7 @@ class CustomerCore extends ObjectModel
|
||||
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
|
||||
SELECT * FROM `'._DB_PREFIX_.'orders` o
|
||||
LEFT JOIN `'._DB_PREFIX_.'order_detail` od ON o.id_order = od.id_order
|
||||
WHERE o.valid = 1 AND o.`id_customer` = '.(int)($this->id));
|
||||
WHERE o.valid = 1 AND o.`id_customer` = '.(int)$this->id);
|
||||
}
|
||||
|
||||
public static function getDefaultGroupId($id_customer)
|
||||
@@ -521,21 +547,30 @@ class CustomerCore extends ObjectModel
|
||||
if (!Group::isFeatureActive())
|
||||
return 1;
|
||||
|
||||
if (!isset(self::$_defaultGroupId[(int)($id_customer)]))
|
||||
self::$_defaultGroupId[(int)($id_customer)] = Db::getInstance()->getValue('SELECT `id_default_group` FROM `'._DB_PREFIX_.'customer` WHERE `id_customer` = '.(int)$id_customer);
|
||||
return self::$_defaultGroupId[(int)($id_customer)];
|
||||
if (!isset(self::$_defaultGroupId[(int)$id_customer]))
|
||||
self::$_defaultGroupId[(int)$id_customer] = Db::getInstance()->getValue('
|
||||
SELECT `id_default_group`
|
||||
FROM `'._DB_PREFIX_.'customer`
|
||||
WHERE `id_customer` = '.(int)$id_customer
|
||||
);
|
||||
return self::$_defaultGroupId[(int)$id_customer];
|
||||
}
|
||||
|
||||
static public function getCurrentCountry($id_customer, Cart $cart = null)
|
||||
public static function getCurrentCountry($id_customer, Cart $cart = null)
|
||||
{
|
||||
if (!$cart)
|
||||
$cart = Context::getContext()->cart;
|
||||
if (!$cart OR !$cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')})
|
||||
$id_address = (int)(Db::getInstance()->getValue('SELECT `id_address` FROM `'._DB_PREFIX_.'address` WHERE `id_customer` = '.(int)($id_customer).' AND `deleted` = 0 ORDER BY `id_address`'));
|
||||
if (!$cart || !$cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')})
|
||||
$id_address = (int)Db::getInstance()->getValue('
|
||||
SELECT `id_address`
|
||||
FROM `'._DB_PREFIX_.'address`
|
||||
WHERE `id_customer` = '.(int)$id_customer.'
|
||||
AND `deleted` = 0 ORDER BY `id_address`'
|
||||
);
|
||||
else
|
||||
$id_address = $cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')};
|
||||
$ids = Address::getCountryAndState($id_address);
|
||||
return (int)($ids['id_country'] ? $ids['id_country'] : Configuration::get('PS_COUNTRY_DEFAULT'));
|
||||
return (int)$ids['id_country'] ? $ids['id_country'] : Configuration::get('PS_COUNTRY_DEFAULT');
|
||||
}
|
||||
|
||||
public function toggleStatus()
|
||||
@@ -546,7 +581,7 @@ class CustomerCore extends ObjectModel
|
||||
return Db::getInstance()->execute('
|
||||
UPDATE `'.pSQL(_DB_PREFIX_.$this->table).'`
|
||||
SET `date_upd` = NOW()
|
||||
WHERE `'.pSQL($this->identifier).'` = '.(int)($this->id));
|
||||
WHERE `'.pSQL($this->identifier).'` = '.(int)$this->id);
|
||||
}
|
||||
|
||||
|
||||
@@ -555,7 +590,7 @@ class CustomerCore extends ObjectModel
|
||||
return (bool)$this->is_guest;
|
||||
}
|
||||
|
||||
public function transformToCustomer($id_lang, $password = NULL)
|
||||
public function transformToCustomer($id_lang, $password = null)
|
||||
{
|
||||
if (!$this->isGuest())
|
||||
return false;
|
||||
@@ -575,32 +610,19 @@ class CustomerCore extends ObjectModel
|
||||
'{passwd}' => $password
|
||||
);
|
||||
|
||||
Mail::Send((int)$id_lang, 'guest_to_customer', Mail::l('Your guest account has been transformed to customer account'), $vars, $this->email, $this->firstname.' '.$this->lastname);
|
||||
Mail::Send(
|
||||
(int)$id_lang,
|
||||
'guest_to_customer',
|
||||
Mail::l('Your guest account has been transformed to customer account'),
|
||||
$vars,
|
||||
$this->email,
|
||||
$this->firstname.' '.$this->lastname
|
||||
);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function printNewsIcon($id_customer, $tr)
|
||||
{
|
||||
$customer = new Customer($tr['id_customer']);
|
||||
if (!Validate::isLoadedObject($customer))
|
||||
die(Tools::displayError('Invalid objects'));
|
||||
echo '<a href="index.php?tab=AdminCustomers&id_customer='.(int)($customer->id).'&changeNewsletterVal&token='.Tools::getAdminTokenLite('AdminCustomers').'">'.
|
||||
($customer->newsletter ? '<img src="../img/admin/enabled.gif" />' : '<img src="../img/admin/disabled.gif" />').
|
||||
'</a>';
|
||||
}
|
||||
|
||||
public static function printOptinIcon($id_customer, $tr)
|
||||
{
|
||||
$customer = new Customer($tr['id_customer']);
|
||||
if (!Validate::isLoadedObject($customer))
|
||||
die(Tools::displayError('Invalid objects'));
|
||||
echo '<a href="index.php?tab=AdminCustomers&id_customer='.(int)($customer->id).'&changeOptinVal&token='.Tools::getAdminTokenLite('AdminCustomers').'">'.
|
||||
($customer->optin ? '<img src="../img/admin/enabled.gif" />' : '<img src="../img/admin/disabled.gif" />').
|
||||
'</a>';
|
||||
}
|
||||
|
||||
public function setWsPasswd($passwd)
|
||||
{
|
||||
if ($this->id != 0)
|
||||
@@ -617,16 +639,16 @@ class CustomerCore extends ObjectModel
|
||||
* Check customer informations and return customer validity
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @param boolean $withGuest
|
||||
* @param boolean $with_guest
|
||||
* @return boolean customer validity
|
||||
*/
|
||||
public function isLogged($withGuest = false)
|
||||
public function isLogged($with_guest = false)
|
||||
{
|
||||
if (!$withGuest AND $this->is_guest == 1)
|
||||
if (!$with_guest && $this->is_guest == 1)
|
||||
return false;
|
||||
|
||||
/* Customer is valid only if it can be load and if object password is the same as database one */
|
||||
if ($this->logged == 1 AND $this->id AND Validate::isUnsignedId($this->id) AND self::checkPassword($this->id, $this->passwd))
|
||||
if ($this->logged == 1 && $this->id && Validate::isUnsignedId($this->id) && self::checkPassword($this->id, $this->passwd))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,798 @@
|
||||
<?php
|
||||
/*
|
||||
* 2007-2011 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Open Software License (OSL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://opensource.org/licenses/osl-3.0.php
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to http://www.prestashop.com for more information.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2011 PrestaShop SA
|
||||
* @version Release: $Revision: 8971 $
|
||||
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
class AdminCustomersControllerCore extends AdminController
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->table = 'customer';
|
||||
$this->className = 'Customer';
|
||||
$this->lang = false;
|
||||
$this->deleted = true;
|
||||
|
||||
$this->addRowAction('edit');
|
||||
$this->addRowAction('view');
|
||||
$this->addRowAction('delete');
|
||||
|
||||
$this->requiredDatabase = true;
|
||||
|
||||
$this->context = Context::getContext();
|
||||
|
||||
$this->bulk_actions = array('delete' => array('text' => $this->l('Delete selected'), 'confirm' => $this->l('Delete selected items?')));
|
||||
|
||||
$this->default_form_language = $this->context->language->id;
|
||||
|
||||
$genders_icon = array('default' => 'unknown.gif');
|
||||
$genders = array(0 => $this->l('?'));
|
||||
foreach (Gender::getGenders() as $gender)
|
||||
{
|
||||
$genders_icon[$gender->id] = '../genders/'.$gender->id.'.jpg';
|
||||
$genders[$gender->id] = $gender->name;
|
||||
}
|
||||
|
||||
$this->fieldsDisplay = array(
|
||||
'id_customer' => array(
|
||||
'title' => $this->l('ID'),
|
||||
'align' => 'center',
|
||||
'width' => 25
|
||||
),
|
||||
'id_gender' => array(
|
||||
'title' => $this->l('Gender'),
|
||||
'width' => 30,
|
||||
'align' => 'center',
|
||||
'icon' => $genders_icon,
|
||||
'orderby' => false,
|
||||
'type' => 'select',
|
||||
'select' => $genders,
|
||||
'filter_key' => 'a!id_gender',
|
||||
),
|
||||
'lastname' => array(
|
||||
'title' => $this->l('Last Name'),
|
||||
'width' => 80
|
||||
),
|
||||
'firstname' => array(
|
||||
'title' => $this->l('First name'),
|
||||
'width' => 60
|
||||
),
|
||||
'email' => array(
|
||||
'title' => $this->l('E-mail address'),
|
||||
'width' => 120,
|
||||
'maxlength' => 19
|
||||
),
|
||||
'age' => array(
|
||||
'title' => $this->l('Age'),
|
||||
'width' => 30,
|
||||
'search' => false
|
||||
),
|
||||
'active' => array(
|
||||
'title' => $this->l('Enabled'),
|
||||
'width' => 25,
|
||||
'align' => 'center',
|
||||
'active' => 'status',
|
||||
'type' => 'bool',
|
||||
'orderby' => false),
|
||||
'newsletter' => array(
|
||||
'title' => $this->l('News.'),
|
||||
'width' => 25,
|
||||
'align' => 'center',
|
||||
'type' => 'bool',
|
||||
'callback' => 'printNewsIcon',
|
||||
'orderby' => false
|
||||
),
|
||||
'optin' => array(
|
||||
'title' => $this->l('Opt.'),
|
||||
'width' => 25,
|
||||
'align' => 'center',
|
||||
'type' => 'bool',
|
||||
'callback' => 'printOptinIcon',
|
||||
'orderby' => false
|
||||
),
|
||||
'date_add' => array(
|
||||
'title' => $this->l('Registration'),
|
||||
'width' => 30,
|
||||
'type' => 'date',
|
||||
'align' => 'right'
|
||||
),
|
||||
'connect' => array(
|
||||
'title' => $this->l('Connection'),
|
||||
'width' => 60,
|
||||
'type' => 'datetime',
|
||||
'search' => false
|
||||
)
|
||||
);
|
||||
|
||||
$this->shopLinkType = 'shop';
|
||||
$this->shopShareDatas = Shop::SHARE_CUSTOMER;
|
||||
|
||||
$this->options = array(
|
||||
'general' => array(
|
||||
'title' => $this->l('Customers options'),
|
||||
'fields' => array(
|
||||
'PS_PASSWD_TIME_FRONT' => array(
|
||||
'title' => $this->l('Regenerate password:'),
|
||||
'desc' => $this->l('Security minimum time to wait to regenerate the password'),
|
||||
'validation' => 'isUnsignedInt',
|
||||
'cast' => 'intval',
|
||||
'size' => 5,
|
||||
'type' => 'text',
|
||||
'suffix' => ' '.$this->l('minutes')
|
||||
)
|
||||
),
|
||||
'submit' => array()
|
||||
)
|
||||
);
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function initList()
|
||||
{
|
||||
$this->_select = '(YEAR(CURRENT_DATE)-YEAR(`birthday`)) - (RIGHT(CURRENT_DATE, 5)<RIGHT(`birthday`, 5)) as age, (
|
||||
SELECT c.date_add FROM '._DB_PREFIX_.'guest g
|
||||
LEFT JOIN '._DB_PREFIX_.'connections c ON c.id_guest = g.id_guest
|
||||
WHERE g.id_customer = a.id_customer
|
||||
ORDER BY c.date_add DESC
|
||||
LIMIT 1
|
||||
) as connect';
|
||||
|
||||
return parent::initList();
|
||||
}
|
||||
|
||||
public function initForm()
|
||||
{
|
||||
if (!($obj = $this->loadObject(true)))
|
||||
return;
|
||||
|
||||
$genders = Gender::getGenders();
|
||||
$total_genders = count($genders);
|
||||
$list_genders = array();
|
||||
for ($i = 0; $i < $total_genders; $i++)
|
||||
{
|
||||
$list_genders[$i]['id'] = 'gender_'.$genders[$i]->id;
|
||||
$list_genders[$i]['value'] = $genders[$i]->id;
|
||||
$list_genders[$i]['label'] = $genders[$i]->name;
|
||||
}
|
||||
$list_genders[$i]['id'] = 'gender_unknown';
|
||||
$list_genders[$i]['value'] = 0;
|
||||
$list_genders[$i]['label'] = $this->l('Unknown');
|
||||
|
||||
$years = Tools::dateYears();
|
||||
$months = Tools::dateMonths();
|
||||
$days = Tools::dateDays();
|
||||
|
||||
$groups = Group::getGroups($this->default_form_language, true);
|
||||
|
||||
$this->fields_form = array(
|
||||
'legend' => array(
|
||||
'title' => $this->l('Customer'),
|
||||
'image' => '../img/admin/tab-customers.gif'
|
||||
),
|
||||
'input' => array(
|
||||
array(
|
||||
'type' => 'radio',
|
||||
'label' => $this->l('Gender:'),
|
||||
'name' => 'id_gender',
|
||||
'required' => false,
|
||||
'class' => 't',
|
||||
'values' => $list_genders
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Last name:'),
|
||||
'name' => 'lastname',
|
||||
'size' => 33,
|
||||
'required' => true,
|
||||
'hint' => $this->l('Invalid characters:').' 0-9!<>,;?=+()@#"�{}_$%:'
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'label' => $this->l('First name:'),
|
||||
'name' => 'firstname',
|
||||
'size' => 33,
|
||||
'required' => true,
|
||||
'hint' => $this->l('Forbidden characters:').' 0-9!<>,;?=+()@#"�{}_$%:'
|
||||
),
|
||||
array(
|
||||
'type' => 'password',
|
||||
'label' => $this->l('Password:'),
|
||||
'name' => 'passwd',
|
||||
'size' => 33,
|
||||
'p' => ($obj->id ? $this->l('Leave blank if no change') : $this->l('5 characters min., only letters, numbers, or').' -_')
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'label' => $this->l('E-mail address:'),
|
||||
'name' => 'email',
|
||||
'size' => 33,
|
||||
'required' => true
|
||||
),
|
||||
array(
|
||||
'type' => 'birthday',
|
||||
'label' => $this->l('Birthday:'),
|
||||
'name' => 'birthday',
|
||||
'options' => array(
|
||||
'days' => $days,
|
||||
'months' => $months,
|
||||
'years' => $years
|
||||
)
|
||||
),
|
||||
array(
|
||||
'type' => 'radio',
|
||||
'label' => $this->l('Status:'),
|
||||
'name' => 'active',
|
||||
'required' => false,
|
||||
'class' => 't',
|
||||
'is_bool' => true,
|
||||
'values' => array(
|
||||
array(
|
||||
'id' => 'active_on',
|
||||
'value' => 1,
|
||||
'label' => $this->l('Enabled')
|
||||
),
|
||||
array(
|
||||
'id' => 'active_off',
|
||||
'value' => 0,
|
||||
'label' => $this->l('Disabled')
|
||||
)
|
||||
),
|
||||
'p' => $this->l('Allow or disallow this customer to log in')
|
||||
),
|
||||
array(
|
||||
'type' => 'radio',
|
||||
'label' => $this->l('Newsletter:'),
|
||||
'name' => 'newsletter',
|
||||
'required' => false,
|
||||
'class' => 't',
|
||||
'is_bool' => true,
|
||||
'values' => array(
|
||||
array(
|
||||
'id' => 'newsletter_on',
|
||||
'value' => 1,
|
||||
'label' => $this->l('Enabled')
|
||||
),
|
||||
array(
|
||||
'id' => 'newsletter_off',
|
||||
'value' => 0,
|
||||
'label' => $this->l('Disabled')
|
||||
)
|
||||
),
|
||||
'p' => $this->l('Customer will receive your newsletter via e-mail')
|
||||
),
|
||||
array(
|
||||
'type' => 'radio',
|
||||
'label' => $this->l('Opt-in:'),
|
||||
'name' => 'optin',
|
||||
'required' => false,
|
||||
'class' => 't',
|
||||
'is_bool' => true,
|
||||
'values' => array(
|
||||
array(
|
||||
'id' => 'optin_on',
|
||||
'value' => 1,
|
||||
'label' => $this->l('Enabled')
|
||||
),
|
||||
array(
|
||||
'id' => 'optin_off',
|
||||
'value' => 0,
|
||||
'label' => $this->l('Disabled')
|
||||
)
|
||||
),
|
||||
'p' => $this->l('Customer will receive your ads via e-mail')
|
||||
),
|
||||
array(
|
||||
'type' => 'select',
|
||||
'label' => $this->l('Default group:'),
|
||||
'name' => 'id_default_group',
|
||||
'options' => array(
|
||||
'query' => $groups,
|
||||
'id' => 'id_group',
|
||||
'name' => 'name'
|
||||
),
|
||||
'hint' => $this->l('The group will be as applied by default.')
|
||||
),
|
||||
array(
|
||||
'type' => 'group',
|
||||
'label' => $this->l('Group access:'),
|
||||
'name' => 'groupBox',
|
||||
'values' => $groups,
|
||||
'required' => true,
|
||||
'p' => $this->l('Check all the box(es) of groups of which the customer is to be a member')
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
if (Shop::isFeatureActive())
|
||||
{
|
||||
$this->fields_form['input'][] = array(
|
||||
'type' => 'select',
|
||||
'label' => $this->l('Shop:'),
|
||||
'name' => 'id_shop',
|
||||
'options' => array(
|
||||
'query' => Shop::getShops(),
|
||||
'id' => 'id_shop',
|
||||
'name' => 'name'
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
$this->fields_form['submit'] = array(
|
||||
'title' => $this->l(' Save '),
|
||||
'class' => 'button'
|
||||
);
|
||||
|
||||
$birthday = explode('-', $this->getFieldValue($obj, 'birthday'));
|
||||
|
||||
$this->fields_value = array(
|
||||
'years' => $this->getFieldValue($obj, 'birthday') ? $birthday[0] : 0,
|
||||
'months' => $this->getFieldValue($obj, 'birthday') ? $birthday[1] : 0,
|
||||
'days' => $this->getFieldValue($obj, 'birthday') ? $birthday[2] : 0,
|
||||
'id_shop' => (int)Configuration::get('PS_SHOP_DEFAULT')
|
||||
);
|
||||
|
||||
// Added values of object Group
|
||||
$customer_groups = $obj->getGroups();
|
||||
$customer_groups_ids = array();
|
||||
if (is_array($customer_groups))
|
||||
foreach ($customer_groups as $customer_group)
|
||||
$customer_groups_ids[] = $customer_group;
|
||||
foreach ($groups as $group)
|
||||
$this->fields_value['groupBox_'.$group['id_group']] = Tools::getValue('groupBox_'.$group['id_group'], in_array($group['id_group'], $customer_groups_ids));
|
||||
|
||||
return parent::initForm();
|
||||
}
|
||||
|
||||
public function initContent()
|
||||
{
|
||||
if ($this->display == 'view')
|
||||
return $this->initView();
|
||||
parent::initContent();
|
||||
}
|
||||
|
||||
public function initView()
|
||||
{
|
||||
if (!($customer = $this->loadObject()))
|
||||
return;
|
||||
|
||||
$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'] = 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 = Group::getGroups($this->default_form_language, true);
|
||||
$total_groups = count($groups);
|
||||
for ($i = 0; $i < $total_groups; $i++)
|
||||
{
|
||||
$group = new Group($groups[$i]);
|
||||
$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 ($order['valid'])
|
||||
{
|
||||
$orders_ok[] = $order;
|
||||
$total_ok += $order['total_paid_real'];
|
||||
}
|
||||
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']);
|
||||
$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);
|
||||
|
||||
$this->context->smarty->assign(array(
|
||||
'table' => $this->table,
|
||||
'current' => self::$currentIndex,
|
||||
'token' => $this->token,
|
||||
'content' => $this->content,
|
||||
'customer' => $customer,
|
||||
'gender_image' => $gender_image,
|
||||
|
||||
// General information of the customer
|
||||
'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::getInstance($customer->id_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')),
|
||||
|
||||
// Add a Private note
|
||||
'customer_note' => Tools::htmlentitiesUTF8($customer->note),
|
||||
|
||||
// Messages
|
||||
'messages' => $messages,
|
||||
|
||||
// Display hook specified to this page : AdminCustomers
|
||||
'hook' => Module::hookExec('adminCustomers', array('id_customer' => $customer->id)),
|
||||
|
||||
// Groups
|
||||
'groups' => $groups,
|
||||
|
||||
// Orders
|
||||
'orders' => $orders,
|
||||
'orders_ok' => $orders_ok,
|
||||
'orders_ko' => $orders_ko,
|
||||
'total_ok' => Tools::displayPrice($total_ok, $this->context->currency->id),
|
||||
|
||||
// Products
|
||||
'products' => $products,
|
||||
|
||||
// Addresses
|
||||
'addresses' => $customer->getAddresses($this->default_form_language),
|
||||
|
||||
// Discounts
|
||||
'discounts' => Discount::getCustomerDiscounts($this->default_form_language, $customer->id, false, false),
|
||||
|
||||
// Carts
|
||||
'carts' => $carts,
|
||||
|
||||
// Interested
|
||||
'interested' => $interested,
|
||||
|
||||
// Connections
|
||||
'connections' => $connections,
|
||||
|
||||
// Referrers
|
||||
'referrers' => $referrers,
|
||||
));
|
||||
}
|
||||
|
||||
public function postProcess()
|
||||
{
|
||||
/**
|
||||
* Todo : Where it's used?
|
||||
*/
|
||||
if (Tools::isSubmit('submitDel'.$this->table) || Tools::isSubmit('delete'.$this->table))
|
||||
{
|
||||
$delete_form = '
|
||||
<form action="'.htmlentities($_SERVER['REQUEST_URI']).'" method="post">
|
||||
<fieldset><legend>'.$this->l('How do you want to delete your customer(s)?').'</legend>
|
||||
'.$this->l('You have two ways to delete a customer, please choose what you want to do.').'
|
||||
<p>
|
||||
<input type="radio" name="deleteMode" value="real" id="deleteMode_real" />
|
||||
<label for="deleteMode_real" style="float:none">'.
|
||||
$this->l('I want to delete my customer(s) for real, all data will be removed from the database.
|
||||
A customer with the same e-mail address will be able to register again.').'
|
||||
</label>
|
||||
</p>
|
||||
<p>
|
||||
<input type="radio" name="deleteMode" value="deleted" id="deleteMode_deleted" />
|
||||
<label for="deleteMode_deleted" style="float:none">'.
|
||||
$this->l('I don\'t want my customer(s) to register again.
|
||||
The customer(s) will be removed from this list but all data will be kept in the database.').'
|
||||
</label>
|
||||
</p>';
|
||||
foreach ($_POST as $key => $value)
|
||||
if (is_array($value))
|
||||
foreach ($value as $val)
|
||||
$delete_form .= '<input type="hidden" name="'.htmlentities($key).'[]" value="'.htmlentities($val).'" />';
|
||||
else
|
||||
$delete_form .= '<input type="hidden" name="'.htmlentities($key).'" value="'.htmlentities($value).'" />';
|
||||
$delete_form .= ' <br /><input type="submit" class="button" value="'.$this->l(' Delete ').'" />
|
||||
</fieldset>
|
||||
</form>
|
||||
<div class="clear"> </div>';
|
||||
}
|
||||
|
||||
if (Tools::getValue('submitAdd'.$this->table))
|
||||
{
|
||||
/* Checking fields validity */
|
||||
$this->validateRules();
|
||||
if (!count($this->_errors))
|
||||
{
|
||||
$id = (int)Tools::getValue('id_'.$this->table);
|
||||
$group_list = Tools::getValue('groupBox');
|
||||
|
||||
//Update Object
|
||||
if (isset($id) && !empty($id))
|
||||
{
|
||||
if ($this->tabAccess['edit'] !== '1')
|
||||
$this->_errors[] = Tools::displayError('You do not have permission to edit here.');
|
||||
else
|
||||
{
|
||||
$object = new $this->className($id);
|
||||
if (Validate::isLoadedObject($object))
|
||||
{
|
||||
$customer_email = strval(Tools::getValue('email'));
|
||||
|
||||
// check if e-mail already used
|
||||
if ($customer_email != $object->email)
|
||||
{
|
||||
$customer = new Customer();
|
||||
$customer->getByEmail($customer_email);
|
||||
if ($customer->id)
|
||||
$this->_errors[] = Tools::displayError('An account already exists for this e-mail address:').' '.$customer_email;
|
||||
}
|
||||
|
||||
if (!is_array($group_list) || count($group_list) == 0)
|
||||
$this->_errors[] = Tools::displayError('Customer must be in at least one group.');
|
||||
else
|
||||
if (!in_array(Tools::getValue('id_default_group'), $group_list))
|
||||
$this->_errors[] = Tools::displayError('Default customer group must be selected in group box.');
|
||||
|
||||
// Updating customer's group
|
||||
if (!count($this->_errors))
|
||||
{
|
||||
$object->cleanGroups();
|
||||
if (is_array($group_list) && count($group_list) > 0)
|
||||
$object->addGroups($group_list);
|
||||
}
|
||||
}
|
||||
else
|
||||
$this->_errors[] = Tools::displayError('An error occurred while loading object.').'
|
||||
<b>'.$this->table.'</b> '.Tools::displayError('(cannot load object)');
|
||||
}
|
||||
}
|
||||
|
||||
//Create Object
|
||||
else
|
||||
{
|
||||
if ($this->tabAccess['add'] === '1')
|
||||
{
|
||||
$object = new $this->className();
|
||||
$this->copyFromPost($object, $this->table);
|
||||
$shop = new Shop((int)$object->id_shop);
|
||||
$object->id_group_shop = (int)$shop->id_group_shop;
|
||||
if (!$object->add())
|
||||
$this->_errors[] = Tools::displayError('An error occurred while creating object.').'
|
||||
<b>'.$this->table.' ('.Db::getInstance()->getMsgError().')</b>';
|
||||
else if (($_POST[$this->identifier] = $object->id /* voluntary */) &&
|
||||
$this->postImage($object->id) && !count($this->_errors) &&
|
||||
$this->_redirect)
|
||||
{
|
||||
// Add Associated groups
|
||||
$group_list = Tools::getValue('groupBox');
|
||||
if (is_array($group_list) && count($group_list) > 0)
|
||||
$object->addGroups($group_list);
|
||||
$parent_id = (int)Tools::getValue('id_parent', 1);
|
||||
// Save and stay on same form
|
||||
if (Tools::isSubmit('submitAdd'.$this->table.'AndStay'))
|
||||
Tools::redirectAdmin(self::$currentIndex.'&'.$this->identifier.'='.$object->id.'&conf=3&update'.$this->table.'&token='.$this->token);
|
||||
// Save and back to parent
|
||||
if (Tools::isSubmit('submitAdd'.$this->table.'AndBackToParent'))
|
||||
Tools::redirectAdmin(self::$currentIndex.'&'.$this->identifier.'='.$parent_id.'&conf=3&token='.$this->token);
|
||||
// Default behavior (save and back)
|
||||
Tools::redirectAdmin(self::$currentIndex.($parent_id ? '&'.$this->identifier.'='.$object->id : '').'&conf=3&token='.$this->token);
|
||||
}
|
||||
}
|
||||
else
|
||||
$this->_errors[] = Tools::displayError('You do not have permission to add here.');
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (Tools::isSubmit('delete'.$this->table) && $this->tabAccess['delete'] === '1')
|
||||
{
|
||||
switch (Tools::getValue('deleteMode'))
|
||||
{
|
||||
case 'real':
|
||||
$this->deleted = false;
|
||||
Discount::deleteByIdCustomer((int)Tools::getValue('id_customer'));
|
||||
break;
|
||||
case 'deleted':
|
||||
$this->deleted = true;
|
||||
break;
|
||||
default:
|
||||
echo $delete_form;
|
||||
if (isset($_POST['delete'.$this->table]))
|
||||
unset($_POST['delete'.$this->table]);
|
||||
if (isset($_GET['delete'.$this->table]))
|
||||
unset($_GET['delete'.$this->table]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (Tools::isSubmit('submitDel'.$this->table) && $this->tabAccess['delete'] === '1')
|
||||
{
|
||||
switch (Tools::getValue('deleteMode'))
|
||||
{
|
||||
case 'real':
|
||||
$this->deleted = false;
|
||||
foreach (Tools::getValue('customerBox') as $id_customer)
|
||||
Discount::deleteByIdCustomer((int)$id_customer);
|
||||
break;
|
||||
case 'deleted':
|
||||
$this->deleted = true;
|
||||
break;
|
||||
default:
|
||||
echo $delete_form;
|
||||
if (isset($_POST['submitDel'.$this->table]))
|
||||
unset($_POST['submitDel'.$this->table]);
|
||||
if (isset($_GET['submitDel'.$this->table]))
|
||||
unset($_GET['submitDel'.$this->table]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (Tools::isSubmit('submitGuestToCustomer') && Tools::getValue('id_customer'))
|
||||
{
|
||||
if ($this->tabAccess['edit'] === '1')
|
||||
{
|
||||
$customer = new Customer((int)Tools::getValue('id_customer'));
|
||||
if (!Validate::isLoadedObject($customer))
|
||||
$this->_errors[] = Tools::displayError('This customer does not exist.');
|
||||
if (Customer::customerExists($customer->email))
|
||||
$this->_errors[] = Tools::displayError('This customer already exist as non-guest.');
|
||||
else if ($customer->transformToCustomer(Tools::getValue('id_lang', Configuration::get('PS_LANG_DEFAULT'))))
|
||||
Tools::redirectAdmin(self::$currentIndex.'&'.$this->identifier.'='.$customer->id.'&conf=3&token='.$this->token);
|
||||
else
|
||||
$this->_errors[] = Tools::displayError('An error occurred while updating customer.');
|
||||
}
|
||||
else
|
||||
$this->_errors[] = Tools::displayError('You do not have permission to edit here.');
|
||||
}
|
||||
else if (Tools::isSubmit('changeNewsletterVal') && Tools::getValue('id_customer'))
|
||||
{
|
||||
$id_customer = (int)Tools::getValue('id_customer');
|
||||
$customer = new Customer($id_customer);
|
||||
if (!Validate::isLoadedObject($customer))
|
||||
$this->_errors[] = Tools::displayError('An error occurred while updating customer.');
|
||||
$update = Db::getInstance()->execute('UPDATE `'._DB_PREFIX_.'customer` SET newsletter = '.($customer->newsletter ? 0 : 1).' WHERE `id_customer` = '.(int)$customer->id);
|
||||
if (!$update)
|
||||
$this->_errors[] = Tools::displayError('An error occurred while updating customer.');
|
||||
Tools::redirectAdmin(self::$currentIndex.'&token='.$this->token);
|
||||
}
|
||||
else if (Tools::isSubmit('changeOptinVal') && Tools::getValue('id_customer'))
|
||||
{
|
||||
$id_customer = (int)Tools::getValue('id_customer');
|
||||
$customer = new Customer($id_customer);
|
||||
if (!Validate::isLoadedObject($customer))
|
||||
$this->_errors[] = Tools::displayError('An error occurred while updating customer.');
|
||||
$update = Db::getInstance()->execute('UPDATE `'._DB_PREFIX_.'customer` SET optin = '.($customer->optin ? 0 : 1).' WHERE `id_customer` = '.(int)$customer->id);
|
||||
if (!$update)
|
||||
$this->_errors[] = Tools::displayError('An error occurred while updating customer.');
|
||||
Tools::redirectAdmin(self::$currentIndex.'&token='.$this->token);
|
||||
}
|
||||
|
||||
return parent::postProcess();
|
||||
}
|
||||
|
||||
public function getList($id_lang, $order_by = null, $order_way = null, $start = 0, $limit = null, $id_lang_shop = null)
|
||||
{
|
||||
return parent::getList(
|
||||
Context::getContext()->language->id,
|
||||
!Tools::getValue($this->table.'Orderby') ? 'date_add' : null,
|
||||
!Tools::getValue($this->table.'Orderway') ? 'DESC' : null
|
||||
);
|
||||
}
|
||||
|
||||
public function beforeDelete($object)
|
||||
{
|
||||
return $object->isUsed();
|
||||
}
|
||||
|
||||
public static function printNewsIcon($id_customer, $tr)
|
||||
{
|
||||
$customer = new Customer($tr['id_customer']);
|
||||
if (!Validate::isLoadedObject($customer))
|
||||
return;
|
||||
return '<a href="index.php?tab=AdminCustomers&id_customer='.(int)$customer->id.'&changeNewsletterVal&token='.Tools::getAdminTokenLite('AdminCustomers').'">
|
||||
'.($customer->newsletter ? '<img src="../img/admin/enabled.gif" />' : '<img src="../img/admin/disabled.gif" />').
|
||||
'</a>';
|
||||
}
|
||||
|
||||
public static function printOptinIcon($id_customer, $tr)
|
||||
{
|
||||
$customer = new Customer($tr['id_customer']);
|
||||
if (!Validate::isLoadedObject($customer))
|
||||
return;
|
||||
return '<a href="index.php?tab=AdminCustomers&id_customer='.(int)$customer->id.'&changeOptinVal&token='.Tools::getAdminTokenLite('AdminCustomers').'">
|
||||
'.($customer->optin ? '<img src="../img/admin/enabled.gif" />' : '<img src="../img/admin/disabled.gif" />').
|
||||
'</a>';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user