From 2ca8f6ec7dc93b67c5729898e1beddcbeac6d714 Mon Sep 17 00:00:00 2001 From: vAugagneur Date: Thu, 3 Nov 2011 17:14:13 +0000 Subject: [PATCH] [+] BO : Back-office search use now AdminController.php --- admin-dev/tabs/AdminSearch.php | 304 -------------------- admin-dev/themes/template/header.tpl | 6 +- admin-dev/themes/template/search/view.tpl | 86 ++++++ classes/Customer.php | 15 + controllers/admin/AdminSearchController.php | 269 +++++++++++++++++ js/jquery/plugins/jquery.highlight.js | 53 ++++ 6 files changed, 427 insertions(+), 306 deletions(-) delete mode 100644 admin-dev/tabs/AdminSearch.php create mode 100644 admin-dev/themes/template/search/view.tpl create mode 100644 controllers/admin/AdminSearchController.php create mode 100644 js/jquery/plugins/jquery.highlight.js diff --git a/admin-dev/tabs/AdminSearch.php b/admin-dev/tabs/AdminSearch.php deleted file mode 100644 index 9ab30d08e..000000000 --- a/admin-dev/tabs/AdminSearch.php +++ /dev/null @@ -1,304 +0,0 @@ - -* @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, ''.Tools::htmlentitiesUTF8($query).'', $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 '

'.$this->l('Search results').'

'; - - 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 '

'.$this->l('Features matching your query:').' '.count($matchingResults).'

- '; - foreach ($matchingResults as $key => $tab) - { - for ($i = 0; isset($tab[$i]); ++$i) - echo ' - - - '; - } - echo '
'.($i == 0 ? htmlentities($key, ENT_COMPAT, 'utf-8') : ' ').' - - '.htmlentities(stripslashes($tab[$i]['value']), ENT_COMPAT, 'utf-8').' - -
 
'; - } - } - - - /* 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 '

'.$nbCategories.' '.($nbCategories > 1 ? $this->l('categories found with') : $this->l('category found with')).' "'.Tools::htmlentitiesUTF8($query).'"

'; - echo ''; - $irow = 0; - foreach ($this->_list['categories'] AS $k => $category) - echo ''; - echo '
'.rtrim(getPath(self::$currentIndex.'?tab=AdminCatalog', $category['id_category'], '', $query), ' >').'
-
 
'; - } - - /* Display products if any has been matching */ - if (isset($this->_list['products']) AND !empty($this->_list['products']) AND $nbProducts = sizeof($this->_list['products'])) - { - echo '

'.$nbProducts.' '.($nbProducts > 1 ? $this->l('products found with') : $this->l('product found with')).' "'.Tools::htmlentitiesUTF8($query).'"

- - '; - foreach ($this->fieldsDisplay['catalog'] AS $field) - echo ''.$field['title'].''; - echo ''; - foreach ($this->_list['products'] AS $k => $product) - { - echo ' - - - - - - - - - - '; - } - echo '
'.$product['id_product'].''.($product['manufacturer_name'] != NULL ? stripslashes($product['manufacturer_name']) : '--').''.$product['reference'].''.stripslashes($product['nameh']).''.Tools::displayPrice($product['price'], $this->context->currency).''.$product['quantity'].' - - - '.$this->l('Modify this product').'  - - '.$this->l('Delete this product').' -
-
 
'; - } - - /* Display customers if any has been matching */ - if (isset($this->_list['customers']) AND !empty($this->_list['customers']) AND $nbCustomers = sizeof($this->_list['customers'])) - { - echo '

'.$nbCustomers.' '.($nbCustomers > 1 ? $this->l('customers') : $this->l('customer')).' '.$this->l('found with').' "'.Tools::htmlentitiesUTF8($query).'"

- - '; - foreach ($this->fieldsDisplay['customers'] AS $field) - echo ''.$field['title'].''; - echo ''; - $irow = 0; - foreach ($this->_list['customers'] AS $k => $customer) - { - echo ' - - - - - - - - - - - '; - } - echo '
'.$customer['id_customer'].''.stripslashes($customer['lastname']).' '.stripslashes($customer['firstname']).''.stripslashes($customer['email']).' '.$this->l('Write to this customer').''.Tools::displayDate($customer['birthday'], $this->context->language->id).''.Tools::displayDate($customer['date_add'], $this->context->language->id).''.Order::getCustomerNbOrders($customer['id_customer']).' - - '.$this->l('View orders').' - - '.$this->l('Modify this customer').' - - '.$this->l('Delete this customer').' -
-
 
'; - } - - /* Display error if nothing has been matching */ - if (!$nbCategories AND !$nbProducts AND !$nbCustomers) - echo '

'.$this->l('Nothing found for').' "'.Tools::htmlentitiesUTF8($query).'"

'; - } -} diff --git a/admin-dev/themes/template/header.tpl b/admin-dev/themes/template/header.tpl index c3ef53ad3..071f675d0 100644 --- a/admin-dev/themes/template/header.tpl +++ b/admin-dev/themes/template/header.tpl @@ -210,8 +210,10 @@ $(document).ready(function()