Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- header('Content-Type: text/html; charset=utf-8');
- session_start();
- $onstore = 0; // 1 - искать только товары которые есть на складе, 0 - искать все товары
- if($_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') {
- if($_GET['q']){
- define('DIR_ROOT', str_replace("\\","/",realpath(dirname(__FILE__))));
- include_once(DIR_ROOT.'/includes/init.php');
- include_once(DIR_CFG.'/connect.inc.wa.php');
- require_once(DIR_CLASSES.'/class.languagesmanager.php');
- require_once(DIR_FUNC.'/currency_functions.php' );
- $DB_tree = new DataBase();
- $DB_tree->connect(SystemSettings::get('DB_HOST'), SystemSettings::get('DB_USER'), SystemSettings::get('DB_PASS'));
- $DB_tree->selectDB(SystemSettings::get('DB_NAME'));
- define('VAR_DBHANDLER','DBHandler');
- $Register = &Register::getInstance();
- $Register->set(VAR_DBHANDLER, $DB_tree);
- $currency = currGetCurrencyByID( $_SESSION['current_currency'] );
- $currency_str = str_replace('{value}','',$currency['display_template_ru']);
- $langManager = &LanguagesManager::getInstance();
- $ln = LanguagesManager::getLanguageInstance($_SESSION['current_language']);
- $store_str = ($onstore)?' AND prd.in_stock > 0 ':'';
- $sql = mysql_query("SELECT prd.name_".$ln->iso2." name, prd.Price, prd.productID , prd.slug FROM SC_products prd
- WHERE LOWER(prd.name_".$ln->iso2.") LIKE '%".mb_strtolower(addslashes(/*$_GET['q']*/str_replace(array('\'','"'), " ", $_GET['q'])),"UTF-8")."%' ".$store_str." AND prd.Price > 0 AND prd.categoryID > 1 AND prd.ordering_available > 0 AND prd.enabled > 0
- GROUP BY prd.name_".$ln->iso2."
- ORDER BY prd.name_".$ln->iso2."
- LIMIT 0,10");
- while( $row_base = mysql_fetch_assoc($sql) ){
- $res = mb_strpos(mb_strtolower($row_base["name"],"UTF-8"), mb_strtolower($_GET['q'],"UTF-8"));
- if($res!==false&&$res==0) {
- $row_base["Price"] = trim($row_base["Price"]);
- echo getHref($row_base).", ".$row_base["Price"].$currency_str."\n";
- } else $other[] = $row_base;
- }
- if( count($other) ){
- foreach( $other as $_product ){
- $_product["Price"] = trim($_product["Price"]);
- echo getHref($_product).", ".$_product["Price"].$currency_str."\n";
- }
- }
- }
- }
- function getHref($product){
- $phrase = addslashes($_GET['q']);
- $phrase = str_replace(array('\'','"'), " ", $_GET['q']/*$phrase*/);
- $product["name"] = addslashes($product["name"]);
- $name = preg_replace('/'.$phrase.'/sui','|',$product["name"]);
- $word = explode('|',$name);
- $style_start = '<span class="match_phrase">';
- $style_end = '</span>';
- if(empty($word[0]) && empty($word[1])){
- $product["name"] = $style_start.$product["name"].$style_end;
- } else if(empty($word[0])) {
- $product["name"] = $style_start.str_replace(array($word[1]),array($style_end.$word[1]),$product["name"]);
- } else if(empty($word[1])) {
- $product["name"] = str_replace(array($word[0]),array($word[0].$style_start),$product["name"]).$style_end;
- } else {
- $product["name"] = str_replace(array($word[0],$word[1]),array($word[0].$style_start,$style_end.$word[1]),$product["name"]);
- }
- $product["name"] = stripslashes($product["name"]);
- $url = str_replace('/published/SC/html/scripts','',xHtmlSetQuery('?ukey=product&productID='.$product["productID"].'&product_slug='.$product["slug"]));
- $url = str_replace('autocomplete.php','',$url);
- return '<span class="href_url" id="'.$url.'">'.$product["name"].'</span>';
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement