* @copyright PrestaShop * @license http://www.opensource.org/licenses/osl-3.0.php Open-source licence 3.0 * @version 1.3 * */ include_once(PS_ADMIN_DIR.'/../classes/AdminTab.php'); class AdminSearch extends AdminTab { /** * Search a specific string in the products and categories * * @params string $query String to find in the catalog */ public function searchCatalog($query) { global $cookie; $this->_list['products'] = Product::searchByName(intval($cookie->id_lang), $query); if (!empty($this->_list['products'])) for ($i = 0; $i < count($this->_list['products']); $i++) $this->_list['products'][$i]['nameh'] = str_ireplace($query, ''.$query.'', $this->_list['products'][$i]['name']); $this->_list['categories'] = Category::searchByName(intval($cookie->id_lang), $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() { global $cookie; /* Handle empty search field */ if (!isset($_POST['bo_query']) OR empty($_POST['bo_query']) OR !isset($_POST['bo_search_type'])) { echo '

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

'; $this->_errors[] = Tools::displayError('please fill in search form first'); } else { $_POST['bo_query'] = trim($_POST['bo_query']); /* Product research */ if (!intval($_POST['bo_search_type']) OR intval($_POST['bo_search_type']) == 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')), 'tax' => array('title' => $this->l('Tax')), 'stock' => array('title' => $this->l('Stock')), 'weight' => array('title' => $this->l('Weight')), 'status' => array('title' => $this->l('Status')), 'action' => array('title' => $this->l('Actions')) )); /* Handle product ID */ if (intval($_POST['bo_search_type']) AND intval($_POST['bo_query']) AND Validate::isUnsignedInt(intval($_POST['bo_query']))) { $product = new Product(intval($_POST['bo_query'])); if (Validate::isLoadedObject($product)) Tools::redirectAdmin('index.php?tab=AdminCatalog&id_product='.intval($_POST['bo_query']).'&addproduct'.'&token='.Tools::getAdminToken('AdminCatalog'.intval(Tab::getIdFromClassName('AdminCatalog')).intval($cookie->id_employee))); } $this->searchCatalog(trim(strval($_POST['bo_query']))); } /* Customer */ if (!intval($_POST['bo_search_type']) OR intval($_POST['bo_search_type']) == 2) { $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')) )); /* Handle customer ID */ if (intval($_POST['bo_search_type']) AND intval($_POST['bo_query']) AND Validate::isUnsignedInt(intval($_POST['bo_query']))) { $customer = new Customer(intval($_POST['bo_query'])); if ($customer->id) Tools::redirectAdmin('index.php?tab=AdminCustomers&id_customer='.intval($_POST['bo_query']).'&viewcustomer'.'&token='.Tools::getAdminToken('AdminCustomers'.intval(Tab::getIdFromClassName('AdminCustomers')).intval($cookie->id_employee))); else $this->_errors[] = Tools::displayError('customer #').intval($_POST['bo_query']).' '.Tools::displayError('not found'); } /* Search customers by name */ else self::searchCustomer($_POST['bo_query']); } /* Order */ if (intval($_POST['bo_search_type']) == 3) { if (intval($_POST['bo_query']) AND Validate::isUnsignedInt(intval($_POST['bo_query']))) { $order = new Order(intval($_POST['bo_query'])); if ($order->id) Tools::redirectAdmin('index.php?tab=AdminOrders&id_order='.intval($_POST['bo_query']).'&vieworder'.'&token='.Tools::getAdminToken('AdminOrders'.intval(Tab::getIdFromClassName('AdminOrders')).intval($cookie->id_employee))); else $this->_errors[] = Tools::displayError('order #').intval($_POST['bo_query']).' '.Tools::displayError('not found'); } else $this->_errors[] = Tools::displayError('please type an order ID'); } /* Invoices */ if (intval($_POST['bo_search_type']) == 4) { if (intval($_POST['bo_query']) AND Validate::isUnsignedInt(intval($_POST['bo_query']))) { if ($invoice = Order::getInvoice(intval($_POST['bo_query']))) { Tools::redirectAdmin('pdf.php?id_order='.intval($invoice['id_order']).'&pdf'); } else $this->_errors[] = Tools::displayError('invoice #').intval($_POST['bo_query']).' '.Tools::displayError('not found'); } else $this->_errors[] = Tools::displayError('please type an invoice ID'); } else Tools::displayError('please fill in search form first.'); /* Cart */ if (intval($_POST['bo_search_type']) == 5) { if (intval($_POST['bo_query']) AND Validate::isUnsignedInt(intval($_POST['bo_query']))) { if ($cart = new Cart(intval($_POST['bo_query'])) AND $cart->id) { Tools::redirectAdmin('index.php?tab=AdminCarts&id_cart='.intval($cart->id).'&viewcart'.'&token='.Tools::getAdminToken('AdminCarts'.intval(Tab::getIdFromClassName('AdminCarts')).intval($cookie->id_employee))); } else $this->_errors[] = Tools::displayError('cart #').intval($_POST['bo_query']).' '.Tools::displayError('not found'); } else $this->_errors[] = Tools::displayError('please type a cart ID'); } } } public function display() { global $cookie; $currentIndex = 'index.php'; $currency = new Currency(Configuration::get('PS_CURRENCY_DEFAULT')); $query = isset($_POST['bo_query']) ? trim(strval($_POST['bo_query'])) : ''; /* 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::safeOutput($query).'"

'; echo ' '; $irow = 0; foreach ($this->_list['categories'] AS $k => $category) echo ''; echo '
'.rtrim(getPath($currentIndex.'?tab=AdminCatalog', $category['id_category'], '', $query), ' >').'


'; } else $nbCategories = 0; /* 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::safeOutput($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'], $currency).' '.stripslashes($product['tax_name']).' '.$product['quantity'].' '.$product['weight'].' '.Configuration::get('PS_WEIGHT_UNIT').' '.$this->l('Modify this product').'  '.$this->l('Delete this product').'
 
'; } else $nbProducts = 0; /* 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::safeOutput($query).'"

'; foreach ($this->fieldsDisplay['customers'] AS $field) echo ''.$field['title'].''; echo ' '; $irow = 0; foreach ($this->_list['customers'] AS $k => $customer) { $imgGender = $customer['id_gender'] == 1 ? ''.$this->l('Male').'' : ($customer['id_gender'] == 2 ? ''.$this->l('Female').'' : ''); echo ' '; } echo '
'.$customer['id_customer'].' '.$imgGender.' '.stripslashes($customer['lastname']).' '.stripslashes($customer['firstname']).' '.stripslashes($customer['email']).' '.$this->l('Write to this customer').' '.Tools::displayDate($customer['birthday'], intval($cookie->id_lang)).' '.Tools::displayDate($customer['date_add'], intval($cookie->id_lang)).' '.Order::getCustomerNbOrders($customer['id_customer']).' '.$this->l('View orders').' '.$this->l('Modify this customer').' '.$this->l('Delete this customer').'
 
'; } else $nbCustomers = 0; if (isset($this->_list['cart'])) { $cart = $this->_list['cart']; $products = $cart->getProducts(); $discounts = $cart->getDiscounts(); $total_discounts = $cart->getOrderTotal(false, 2); $total_shipping = $cart->getOrderShippingCost($cart->id_carrier); $total_wrapping = $cart->getOrderTotal(true, 6); $total_products = $cart->getOrderTotal(true, 1); $total_price = $cart->getOrderTotal(); echo '

'.$this->l('Cart found:').' (#'.sprintf('%08d', $cart->id).')

'; if ($products) foreach ($products as $product) echo ' '; if ($discounts) foreach ($discounts as $discount) echo ' '; echo '
'.$this->l('Reference').' Product '.$this->l('Quantity').' '.$this->l('Unit price').' '.$this->l('Total price').'
'.$product['reference'].' '.$product['name'].' '.$product['quantity'].' '.Tools::displayPrice($product['price'], $currency).' '.Tools::displayPrice($product['total_wt'], $currency).'
'.$discount['name'].' '.$discount['description'].' 1 -'.Tools::displayPrice($discount['value'], $currency).' -'.Tools::displayPrice($discount['value'], $currency).'
'.$this->l('Products:').' '.Tools::displayPrice($total_products, $currency).'
'.$this->l('Vouchers').' '.Tools::displayPrice($total_discounts, $currency).'
'.$this->l('Gift-wrapping:').' '.Tools::displayPrice($total_wrapping, $currency).'
'.$this->l('Shipping:').' '.Tools::displayPrice($total_shipping, $currency).'
'.$this->l('Total:').' '.Tools::displayPrice($total_price, $currency).'
 
'; } /* Display error if nothing has been matching */ if (!$nbCategories AND !$nbProducts AND !$nbCustomers AND !isset($this->_list['cart'])) echo '

'.$this->l('Nothing found').'.

'; } } ?>