[+] BO : Back-office search use now AdminController.php

This commit is contained in:
vAugagneur
2011-11-03 17:14:13 +00:00
parent 0436dc10ad
commit 2ca8f6ec7d
6 changed files with 427 additions and 306 deletions
-304
View File
@@ -1,304 +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: 6844 $
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class AdminSearch extends AdminTab
{
public function searchIP($query)
{
if (!ip2long(trim($query)))
return;
$this->_list['customers'] = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
SELECT DISTINCT c.*
FROM `'._DB_PREFIX_.'customer` c
LEFT JOIN `'._DB_PREFIX_.'guest` g ON g.id_customer = c.id_customer
LEFT JOIN `'._DB_PREFIX_.'connections` co ON g.id_guest = co.id_guest
WHERE co.`ip_address` = \''.ip2long(trim($query)).'\'');
}
/**
* Search a specific string in the products and categories
*
* @params string $query String to find in the catalog
*/
public function searchCatalog($query)
{
$this->context = Context::getContext();
$this->_list['products'] = Product::searchByName($this->context->language->id, $query);
if (!empty($this->_list['products']))
for ($i = 0; $i < count($this->_list['products']); $i++)
$this->_list['products'][$i]['nameh'] = str_ireplace($query, '<span class="highlight">'.Tools::htmlentitiesUTF8($query).'</span>', $this->_list['products'][$i]['name']);
$this->_list['categories'] = Category::searchByName($this->context->language->id, $query);
}
/**
* Search a specific name in the customers
*
* @params string $query String to find in the catalog
*/
public function searchCustomer($query)
{
$this->_list['customers'] = Customer::searchByName($query);
}
function postProcess()
{
$this->context = Context::getContext();
$query = trim(Tools::getValue('bo_query'));
$searchType = (int)Tools::getValue('bo_search_type');
/* Handle empty search field */
if (empty($query))
$this->_errors[] = Tools::displayError('Please fill in search form first.');
else
{
echo '<h2>'.$this->l('Search results').'</h2>';
if (!$searchType and strlen($query) > 1)
{
global $_LANGADM;
$tabs = array();
$result = Db::getInstance()->executeS('SELECT class_name, name FROM '._DB_PREFIX_.'tab t INNER JOIN '._DB_PREFIX_.'tab_lang tl ON t.id_tab = tl.id_tab AND tl.id_lang = '.(int)$this->context->language->id);
foreach ($result as $row)
$tabs[$row['class_name']] = $row['name'];
foreach (AdminTab::$tabParenting as $key => $value)
$tabs[$key] = $tabs[$value];
$matchingResults = array();
foreach ($_LANGADM as $key => $value)
if (stripos($value, $query) !== false)
{
$key = substr($key, 0, -32);
if (in_array($key, array('AdminTab', 'index')))
continue;
// if class name doesn't exists, just ignore it
if (!isset($tabs[$key]))
continue;
if (!isset($matchingResults[$tabs[$key]]))
$matchingResults[$tabs[$key]] = array();
$matchingResults[$tabs[$key]][] = array('tab' => $key, 'value' => $value);
}
if (count($matchingResults))
{
arsort($matchingResults);
echo '<h3>'.$this->l('Features matching your query:').' '.count($matchingResults).'</h3>
<table class="table" cellpadding="0" cellspacing="0">';
foreach ($matchingResults as $key => $tab)
{
for ($i = 0; isset($tab[$i]); ++$i)
echo '<tr>
<th>'.($i == 0 ? htmlentities($key, ENT_COMPAT, 'utf-8') : '&nbsp;').'</th>
<td>
<a href="?tab='.$tab[$i]['tab'].'&token='.Tools::getAdminTokenLite($tab[$i]['tab']).'">
'.htmlentities(stripslashes($tab[$i]['value']), ENT_COMPAT, 'utf-8').'
</a>
</td>
</tr>';
}
echo '</table><div class="clear">&nbsp;</div>';
}
}
/* Product research */
if (!$searchType OR $searchType == 1)
{
$this->fieldsDisplay['catalog'] = (array(
'ID' => array('title' => $this->l('ID')),
'manufacturer' => array('title' => $this->l('Manufacturer')),
'reference' => array('title' => $this->l('Reference')),
'name' => array('title' => $this->l('Name')),
'price' => array('title' => $this->l('Price')),
'stock' => array('title' => $this->l('Stock')),
'status' => array('title' => $this->l('Status')),
'action' => array('title' => $this->l('Actions'))
));
/* Handle product ID */
if ($searchType == 1 AND (int)$query AND Validate::isUnsignedInt((int)$query))
if ($product = new Product((int)$query) AND Validate::isLoadedObject($product))
Tools::redirectAdmin('index.php?tab=AdminCatalog&id_product='.(int)($product->id).'&addproduct'.'&token='.Tools::getAdminToken('AdminCatalog'.(int)(Tab::getIdFromClassName('AdminCatalog')).(int)$this->context->employee->id));
/* Normal catalog search */
$this->searchCatalog($query);
}
/* Customer */
if (!$searchType OR $searchType == 2 OR $searchType == 6)
{
$this->fieldsDisplay['customers'] = (array(
'ID' => array('title' => $this->l('ID')),
'sex' => array('title' => $this->l('Sex')),
'name' => array('title' => $this->l('Name')),
'e-mail' => array('title' => $this->l('e-mail')),
'birthdate' => array('title' => $this->l('Birth date')),
'register_date' => array('title' => $this->l('Register date')),
'orders' => array('title' => $this->l('Orders')),
'status' => array('title' => $this->l('Status')),
'actions' => array('title' => $this->l('Actions'))
));
if (!$searchType OR $searchType == 2)
{
/* Handle customer ID */
if ($searchType AND (int)$query AND Validate::isUnsignedInt((int)$query))
if ($customer = new Customer((int)$query) AND Validate::isLoadedObject($customer))
Tools::redirectAdmin('index.php?tab=AdminCustomers&id_customer='.(int)($customer->id).'&viewcustomer'.'&token='.Tools::getAdminToken('AdminCustomers'.(int)(Tab::getIdFromClassName('AdminCustomers')).(int)$this->context->employee->id));
/* Normal customer search */
$this->searchCustomer($query);
}
if ($searchType == 6)
$this->searchIP($query);
}
/* Order */
if ($searchType == 3)
{
if ((int)$query AND Validate::isUnsignedInt((int)$query) AND $order = new Order((int)$query) AND Validate::isLoadedObject($order))
Tools::redirectAdmin('index.php?tab=AdminOrders&id_order='.(int)($order->id).'&vieworder'.'&token='.Tools::getAdminToken('AdminOrders'.(int)(Tab::getIdFromClassName('AdminOrders')).(int)$this->context->employee->id));
$this->_errors[] = Tools::displayError('No order found with this ID:').' '.Tools::htmlentitiesUTF8($query);
}
/* Invoices */
if ($searchType == 4)
{
if ((int)$query AND Validate::isUnsignedInt((int)$query) AND $invoice = Order::getInvoice((int)$query))
Tools::redirectAdmin('pdf.php?id_order='.(int)($invoice['id_order']).'&pdf');
$this->_errors[] = Tools::displayError('No invoice found with this ID:').' '.Tools::htmlentitiesUTF8($query);
}
/* Cart */
if ($searchType == 5)
{
if ((int)$query AND Validate::isUnsignedInt((int)$query) AND $cart = new Cart((int)$query) AND Validate::isLoadedObject($cart))
Tools::redirectAdmin('index.php?tab=AdminCarts&id_cart='.(int)($cart->id).'&viewcart'.'&token='.Tools::getAdminToken('AdminCarts'.(int)(Tab::getIdFromClassName('AdminCarts')).(int)$this->context->employee->id));
$this->_errors[] = Tools::displayError('No cart found with this ID:').' '.Tools::htmlentitiesUTF8($query);
}
/* IP */
// 6 - but it is included in the customer block
}
}
public function display()
{
self::$currentIndex = 'index.php';
$query = trim(Tools::getValue('bo_query'));
$nbCategories = $nbProducts = $nbCustomers = 0;
/* Display categories if any has been matching */
if (isset($this->_list['categories']) AND $nbCategories = sizeof($this->_list['categories']))
{
echo '<h3>'.$nbCategories.' '.($nbCategories > 1 ? $this->l('categories found with') : $this->l('category found with')).' <b>"'.Tools::htmlentitiesUTF8($query).'"</b></h3>';
echo '<table cellspacing="0" cellpadding="0" class="table">';
$irow = 0;
foreach ($this->_list['categories'] AS $k => $category)
echo '<tr class="'.($irow++ % 2 ? 'alt_row' : '').'"><td>'.rtrim(getPath(self::$currentIndex.'?tab=AdminCatalog', $category['id_category'], '', $query), ' >').'</td></tr>';
echo '</table>
<div class="clear">&nbsp;</div>';
}
/* Display products if any has been matching */
if (isset($this->_list['products']) AND !empty($this->_list['products']) AND $nbProducts = sizeof($this->_list['products']))
{
echo '<h3>'.$nbProducts.' '.($nbProducts > 1 ? $this->l('products found with') : $this->l('product found with')).' <b>"'.Tools::htmlentitiesUTF8($query).'"</b></h3>
<table class="table" cellpadding="0" cellspacing="0">
<tr>';
foreach ($this->fieldsDisplay['catalog'] AS $field)
echo '<th'.(isset($field['width']) ? 'style="width: '.$field['width'].'"' : '').'>'.$field['title'].'</th>';
echo '</tr>';
foreach ($this->_list['products'] AS $k => $product)
{
echo '
<tr>
<td>'.$product['id_product'].'</td>
<td align="center">'.($product['manufacturer_name'] != NULL ? stripslashes($product['manufacturer_name']) : '--').'</td>
<td>'.$product['reference'].'</td>
<td><a href="'.self::$currentIndex.'?tab=AdminCatalog&id_product='.$product['id_product'].'&addproduct&token='.Tools::getAdminToken('AdminCatalog'.(int)(Tab::getIdFromClassName('AdminCatalog')).(int)$this->context->employee->id).'">'.stripslashes($product['nameh']).'</a></td>
<td>'.Tools::displayPrice($product['price'], $this->context->currency).'</td>
<td align="center">'.$product['quantity'].'</td>
<td align="center"><a href="'.self::$currentIndex.'?tab=AdminCatalog&id_product='.$product['id_product'].'&status&token='.Tools::getAdminToken('AdminCatalog'.(int)(Tab::getIdFromClassName('AdminCatalog')).(int)$this->context->employee->id).'">
<img src="../img/admin/'.($product['active'] ? 'enabled.gif' : 'forbbiden.gif').'" alt="" /></a></td>
<td>
<a href="'.self::$currentIndex.'?tab=AdminCatalog&id_product='.$product['id_product'].'&addproduct&token='.Tools::getAdminToken('AdminCatalog'.(int)(Tab::getIdFromClassName('AdminCatalog')).(int)$this->context->employee->id).'">
<img src="../img/admin/edit.gif" alt="'.$this->l('Modify this product').'" /></a>&nbsp;
<a href="'.self::$currentIndex.'?tab=AdminCatalog&id_product='.$product['id_product'].'&deleteproduct&token='.Tools::getAdminToken('AdminCatalog'.(int)(Tab::getIdFromClassName('AdminCatalog')).(int)$this->context->employee->id).'"
onclick="return confirm(\''.$this->l('Do you want to delete this product?', __CLASS__, true, false).' ('.addslashes($product['name']).')\');">
<img src="../img/admin/delete.gif" alt="'.$this->l('Delete this product').'" /></a>
</td>
</tr>';
}
echo '</table>
<div class="clear">&nbsp;</div>';
}
/* Display customers if any has been matching */
if (isset($this->_list['customers']) AND !empty($this->_list['customers']) AND $nbCustomers = sizeof($this->_list['customers']))
{
echo '<h3>'.$nbCustomers.' '.($nbCustomers > 1 ? $this->l('customers') : $this->l('customer')).' '.$this->l('found with').' <b>"'.Tools::htmlentitiesUTF8($query).'"</b></h3>
<table cellspacing="0" cellpadding="0" class="table widthfull">
<tr>';
foreach ($this->fieldsDisplay['customers'] AS $field)
echo '<th'.(isset($field['width']) ? 'style="width: '.$field['width'].'"' : '').'>'.$field['title'].'</th>';
echo '</tr>';
$irow = 0;
foreach ($this->_list['customers'] AS $k => $customer)
{
echo '
<tr class="'.($irow++ % 2 ? 'alt_row' : '').'">
<td>'.$customer['id_customer'].'</td>
<td class="center"><img src="'.Gender::getStaticImage($customer['id_gender']).'" /></td>
<td>'.stripslashes($customer['lastname']).' '.stripslashes($customer['firstname']).'</td>
<td>'.stripslashes($customer['email']).'<a href="mailto:'.stripslashes($customer['email']).'"> <img src="../img/admin/email_edit.gif" alt="'.$this->l('Write to this customer').'" /></a></td>
<td>'.Tools::displayDate($customer['birthday'], $this->context->language->id).'</td>
<td>'.Tools::displayDate($customer['date_add'], $this->context->language->id).'</td>
<td>'.Order::getCustomerNbOrders($customer['id_customer']).'</td>
<td class="center"><img src="../img/admin/'.($customer['active'] ? 'enabled.gif' : 'forbbiden.gif').'" alt="" /></td>
<td class="center" width="60px">
<a href="'.self::$currentIndex.'?tab=AdminCustomers&id_customer='.$customer['id_customer'].'&viewcustomer&token='.Tools::getAdminToken('AdminCustomers'.(int)(Tab::getIdFromClassName('AdminCustomers')).(int)$this->context->employee->id).'">
<img src="../img/admin/details.gif" alt="'.$this->l('View orders').'" /></a>
<a href="'.self::$currentIndex.'?tab=AdminCustomers&id_customer='.$customer['id_customer'].'&addcustomer&token='.Tools::getAdminToken('AdminCustomers'.(int)(Tab::getIdFromClassName('AdminCustomers')).(int)$this->context->employee->id).'">
<img src="../img/admin/edit.gif" alt="'.$this->l('Modify this customer').'" /></a>
<a href="'.self::$currentIndex.'?tab=AdminCustomers&id_customer='.$customer['id_customer'].'&deletecustomer&token='.Tools::getAdminToken('AdminCustomers'.(int)(Tab::getIdFromClassName('AdminCustomers')).(int)$this->context->employee->id).'" onclick="return confirm(\''.$this->l('Are you sure?', __CLASS__, true, false).'\');">
<img src="../img/admin/delete.gif" alt="'.$this->l('Delete this customer').'" /></a>
</td>
</tr>';
}
echo '</table>
<div class="clear">&nbsp;</div>';
}
/* Display error if nothing has been matching */
if (!$nbCategories AND !$nbProducts AND !$nbCustomers)
echo '<h3>'.$this->l('Nothing found for').' "'.Tools::htmlentitiesUTF8($query).'"</h3>';
}
}
+4 -2
View File
@@ -210,8 +210,10 @@ $(document).ready(function()
<select name="bo_search_type" id="bo_search_type">
<option value="0">{l s='everywhere'}</option>
<option value="1" {if {$search_type} == 1} selected="selected" {/if}>{l s='catalog'}</option>
<option value="2" {if {$search_type} == 2} selected="selected" {/if}>{l s='customers'}</option>
<option value="6" {if {$search_type} == 6} selected="selected" {/if}>{l s='ip address'}</option>
<optgroup label="{l s='customers'}:">
<option value="2" {if {$search_type} == 2} selected="selected" {/if}>{l s='by name'}</option>
<option value="6" {if {$search_type} == 6} selected="selected" {/if}>{l s='by ip address'}</option>
</optgroup>
<option value="3" {if {$search_type} == 3} selected="selected" {/if}>{l s='orders'}</option>
<option value="4" {if {$search_type} == 4} selected="selected" {/if}>{l s='invoices'}</option>
<option value="5" {if {$search_type} == 5} selected="selected" {/if}>{l s='carts'}</option>
+86
View File
@@ -0,0 +1,86 @@
{*
* 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: 9596 $
* @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() {
$('body').highlight('{$query}');
});
</script>
{if isset($features) || isset($categories) || isset($products) || isset($customers)}
<h2>{l s='Search results'} :</h2>
{/if}
{if isset($features)}
{if !$features}
<h3>{l s='No features matching your query'} : {$query}</h3>
{else}
<h3>{l s='Features matching your query'} : {$query}</h3>
<table class="table" cellpadding="0" cellspacing="0">
{foreach $features key=key item=feature }
{foreach $feature key=k item=val name=feature_list}
<tr>
<th>{if $smarty.foreach.feature_list.first}{$key}{/if}</th>
<td>
<a href="{$val.link}">{$val.value}</a>
</td>
</tr>
{/foreach}
{/foreach}
</table>
<div class="clear">&nbsp;</div>
{/if}
{/if}
{if isset($categories)}
{if !$categories}
<h3>{l s='No categories matching your query'} : {$query}</h3>
{else}
<h3>{l s='Categories matching your query'} : {$query}</h3>
<table cellspacing="0" cellpadding="0" class="table">
{foreach $categories key=key item=category }
<tr class="alt_row">
<td>{$category}</td>
</tr>
{/foreach}
</table>
<div class="clear">&nbsp;</div>
{/if}
{/if}
{if isset($products)}
{if !$products}
<h3>{l s='No products matching your query'} : {$query}</h3>
{else}
<h3>{l s='Products matching your query'} : {$query}</h3>
{$products}
{/if}
{/if}
{if isset($customers)}
{if !$customers}
<h3>{l s='No customer matching your query'} : {$query}</h3>
{else}
<h3>{l s='Customer matching your query'} : {$query}</h3>
{$customers}
{/if}
{/if}
+15
View File
@@ -416,6 +416,21 @@ class CustomerCore extends ObjectModel
)'.$shop->addSqlRestriction(Shop::SHARE_CUSTOMER);
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
}
/**
* Search for customers by ip address
*
* @param string $ip Searched string
*/
public static function searchByIp($ip)
{
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
SELECT DISTINCT c.*
FROM `'._DB_PREFIX_.'customer` c
LEFT JOIN `'._DB_PREFIX_.'guest` g ON g.id_customer = c.id_customer
LEFT JOIN `'._DB_PREFIX_.'connections` co ON g.id_guest = co.id_guest
WHERE co.`ip_address` = \''.ip2long(trim($ip)).'\'');
}
/**
* Return several useful statistics about customer
+269
View File
@@ -0,0 +1,269 @@
<?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: 6844 $
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class AdminSearchControllerCore extends AdminController
{
public function __construct()
{
$this->display = 'view';
parent::__construct();
}
public function postProcess()
{
$this->context = Context::getContext();
$this->query = trim(Tools::getValue('bo_query'));
$searchType = (int)Tools::getValue('bo_search_type');
/* Handle empty search field */
if (empty($this->query))
{
$this->_errors[] = Tools::displayError('Please fill in search form first.');
return;
}
else
{
if (!$searchType and strlen($this->query) > 1)
$this->searchFeatures();
/* Product research */
if (!$searchType OR $searchType == 1)
{
/* Handle product ID */
if ($searchType == 1 AND (int)$this->query AND Validate::isUnsignedInt((int)$this->query))
if ($product = new Product((int)$this->query) AND Validate::isLoadedObject($product))
Tools::redirectAdmin('index.php?tab=AdminCatalog&id_product='.(int)($product->id).'&addproduct'.'&token='.Tools::getAdminToken('AdminCatalog'.(int)(Tab::getIdFromClassName('AdminCatalog')).(int)$this->context->employee->id));
/* Normal catalog search */
$this->searchCatalog();
}
/* Customer */
if (!$searchType OR $searchType == 2 OR $searchType == 6)
{
if (!$searchType OR $searchType == 2)
{
/* Handle customer ID */
if ($searchType AND (int)$this->query AND Validate::isUnsignedInt((int)$this->query))
if ($customer = new Customer((int)$this->query) AND Validate::isLoadedObject($customer))
Tools::redirectAdmin('index.php?tab=AdminCustomers&id_customer='.(int)($customer->id).'&viewcustomer'.'&token='.Tools::getAdminToken('AdminCustomers'.(int)(Tab::getIdFromClassName('AdminCustomers')).(int)$this->context->employee->id));
/* Normal customer search */
$this->searchCustomer();
}
if ($searchType == 6)
$this->searchIP();
}
/* Order */
if ($searchType == 3)
{
if ((int)$this->query AND Validate::isUnsignedInt((int)$this->query) AND $order = new Order((int)$this->query) AND Validate::isLoadedObject($order))
Tools::redirectAdmin('index.php?tab=AdminOrders&id_order='.(int)($order->id).'&vieworder'.'&token='.Tools::getAdminToken('AdminOrders'.(int)(Tab::getIdFromClassName('AdminOrders')).(int)$this->context->employee->id));
$this->_errors[] = Tools::displayError('No order found with this ID:').' '.Tools::htmlentitiesUTF8($this->query);
}
/* Invoices */
if ($searchType == 4)
{
if ((int)$this->query AND Validate::isUnsignedInt((int)$this->query) AND $invoice = Order::getInvoice((int)$this->query))
Tools::redirectAdmin('pdf.php?id_order='.(int)($invoice['id_order']).'&pdf');
$this->_errors[] = Tools::displayError('No invoice found with this ID:').' '.Tools::htmlentitiesUTF8($this->query);
}
/* Cart */
if ($searchType == 5)
{
if ((int)$this->query AND Validate::isUnsignedInt((int)$this->query) AND $cart = new Cart((int)$this->query) AND Validate::isLoadedObject($cart))
Tools::redirectAdmin('index.php?tab=AdminCarts&id_cart='.(int)($cart->id).'&viewcart'.'&token='.Tools::getAdminToken('AdminCarts'.(int)(Tab::getIdFromClassName('AdminCarts')).(int)$this->context->employee->id));
$this->_errors[] = Tools::displayError('No cart found with this ID:').' '.Tools::htmlentitiesUTF8($this->query);
}
/* IP */
// 6 - but it is included in the customer block
}
}
public function searchIP()
{
if (!ip2long(trim($this->query)))
{
$this->_errors[] = Tools::displayError('It seems that this is not an IP address :').' '.Tools::htmlentitiesUTF8($this->query);
return;
}
$this->_list['customers'] = Customer::searchByIp($this->query);
}
/**
* Search a specific string in the products and categories
*
* @params string $query String to find in the catalog
*/
public function searchCatalog()
{
$this->context = Context::getContext();
$this->_list['products'] = Product::searchByName($this->context->language->id, $this->query);
$this->_list['categories'] = Category::searchByName($this->context->language->id, $this->query);
}
/**
* Search a specific name in the customers
*
* @params string $query String to find in the catalog
*/
public function searchCustomer()
{
$this->_list['customers'] = Customer::searchByName($this->query);
}
/**
* Search a feature in all store
*
* @params string $query String to find in the catalog
*/
public function searchFeatures()
{
global $_LANGADM;
$tabs = array();
$result = Db::getInstance()->executeS('SELECT class_name, name FROM '._DB_PREFIX_.'tab t INNER JOIN '._DB_PREFIX_.'tab_lang tl ON t.id_tab = tl.id_tab AND tl.id_lang = '.(int)$this->context->language->id);
foreach ($result as $row)
$tabs[$row['class_name']] = $row['name'];
foreach (AdminTab::$tabParenting as $key => $value)
$tabs[$key] = $tabs[$value];
$this->_list['features'] = array();
foreach ($_LANGADM as $key => $value)
{
if (stripos($value, $this->query) !== false)
{
$key = substr($key, 0, -32);
if (in_array($key, array('AdminTab', 'index')))
continue;
// if class name doesn't exists, just ignore it
if (!isset($tabs[$key]))
continue;
if (!isset($this->_list['features'][$tabs[$key]]))
$this->_list['features'][$tabs[$key]] = array();
$this->_list['features'][$tabs[$key]][] = array('link' => '?tab='.Tools::safeOutput($key).'&token='.Tools::getAdminTokenLite($key) , 'value' => Tools::safeOutput($value));
}
}
if (!count($this->_list['features']))
$this->_list['features'] = false;
else
$this->_list['features'];
}
protected function initCustomerList()
{
$genders_icon = array('default' => 'unknown.gif');
$genders = array(0 => $this->l('?'));
foreach (Gender::getGenders() as $gender)
{
$genders_icon[$gender->id] = '../genders/'.(int)$gender->id.'.jpg';
$genders[$gender->id] = $gender->name;
}
$this->fieldsDisplay['customers'] = (array(
'id_customer' => array('title' => $this->l('ID'), 'align' => 'center'),
'id_gender' => array('title' => $this->l('Gender'), 'align' => 'center', 'icon' => $genders_icon, 'list' => $genders),
'firstname' => array('title' => $this->l('Name'), 'align' => 'center'),
'lastname' => array('title' => $this->l('Name'), 'align' => 'center'),
'email' => array('title' => $this->l('E-mail address'), 'align' => 'center'),
'birthday' => array('title' => $this->l('Birth date'), 'align' => 'center', 'type' => 'date'),
'date_add' => array('title' => $this->l('Register date'), 'align' => 'center', 'type' => 'date'),
'orders' => array('title' => $this->l('Orders'), 'align' => 'center'),
'active' => array('title' => $this->l('Enabled'),'align' => 'center','active' => 'status','type' => 'bool'),
));
}
protected function initProductList()
{
$this->fieldsDisplay['products'] = (array(
'id_product' => array('title' => $this->l('ID')),
'manufacturer_name' => array('title' => $this->l('Manufacturer'), 'align' => 'center'),
'reference' => array('title' => $this->l('Reference'), 'align' => 'center'),
'name' => array('title' => $this->l('Name')),
'price' => array('title' => $this->l('Price'), 'align' => 'right', 'price' => true),
'status' => array('title' => $this->l('Status'), 'align' => 'center'),
));
}
public function setMedia()
{
parent::setMedia();
$this->addJqueryPlugin('highlight');
}
public function initView()
{
$this->context->smarty->assign('query', $this->query);
if (sizeof($this->_errors))
parent::initView();
else
{
$helper = new HelperList();
$helper->currentIndex = self::$currentIndex;
$helper->token = $this->token;
$helper->shopLinkType = '';
$helper->simple_header = true;
if (isset($this->_list['features']))
$this->context->smarty->assign('features', $this->_list['features']);
if (isset($this->_list['categories']))
{
$categorie = array();
foreach($this->_list['categories'] as $category)
$categorie[] = getPath(self::$currentIndex.'?tab=AdminCatalog', (int)$category['id_category']);
$this->context->smarty->assign('categories', $categorie);
}
if (isset($this->_list['products']))
{
$view = '';
$this->initProductList();
$helper->identifier = 'id_product';
$helper->actions = array('edit', 'view');
if ($this->_list['products'])
$view = $helper->generateList($this->_list['products'], $this->fieldsDisplay['products']);
$this->context->smarty->assign('products', $view);
}
if (isset($this->_list['customers']))
{
$view = '';
$this->initCustomerList();
$helper->identifier = 'id_customer';
$helper->actions = array('edit', 'view');
if ($this->_list['customers'])
{
foreach($this->_list['customers'] as $key => $val)
$this->_list['customers'][$key]['orders'] = Order::getCustomerNbOrders((int)$val['id_customer']);
$view = $helper->generateList($this->_list['customers'], $this->fieldsDisplay['customers']);
}
$this->context->smarty->assign('customers', $view);
}
parent::initView();
}
}
}
+53
View File
@@ -0,0 +1,53 @@
/*
highlight v3
Highlights arbitrary terms.
<http://johannburkard.de/blog/programming/javascript/highlight-javascript-text-higlighting-jquery-plugin.html>
MIT license.
Johann Burkard
<http://johannburkard.de>
<mailto:jb@eaio.com>
*/
jQuery.fn.highlight = function(pat) {
function innerHighlight(node, pat) {
var skip = 0;
if (node.nodeType == 3) {
var pos = node.data.toUpperCase().indexOf(pat);
if (pos >= 0) {
var spannode = document.createElement('span');
spannode.className = 'highlight';
var middlebit = node.splitText(pos);
var endbit = middlebit.splitText(pat.length);
var middleclone = middlebit.cloneNode(true);
spannode.appendChild(middleclone);
middlebit.parentNode.replaceChild(spannode, middlebit);
skip = 1;
}
}
else if (node.nodeType == 1 && node.childNodes && !/(script|style)/i.test(node.tagName)) {
for (var i = 0; i < node.childNodes.length; ++i) {
i += innerHighlight(node.childNodes[i], pat);
}
}
return skip;
}
return this.each(function() {
innerHighlight(this, pat.toUpperCase());
});
};
jQuery.fn.removeHighlight = function() {
return this.find("span.highlight").each(function() {
this.parentNode.firstChild.nodeName;
with (this.parentNode) {
replaceChild(this.firstChild, this);
normalize();
}
}).end();
};