Advertisement
Guest User

Untitled

a guest
Dec 15th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.43 KB | None | 0 0
  1. <?php
  2.  
  3. header('Content-Type: text/html; charset=utf-8');
  4. session_start();
  5.  
  6. $onstore = 0; // 1 - искать только товары которые есть на складе, 0 - искать все товары
  7.  
  8. if($_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') {
  9. if($_GET['q']){
  10. define('DIR_ROOT', str_replace("\\","/",realpath(dirname(__FILE__))));
  11. include_once(DIR_ROOT.'/includes/init.php');
  12. include_once(DIR_CFG.'/connect.inc.wa.php');
  13. require_once(DIR_CLASSES.'/class.languagesmanager.php');
  14. require_once(DIR_FUNC.'/currency_functions.php' );
  15.  
  16. $DB_tree = new DataBase();
  17. $DB_tree->connect(SystemSettings::get('DB_HOST'), SystemSettings::get('DB_USER'), SystemSettings::get('DB_PASS'));
  18. $DB_tree->selectDB(SystemSettings::get('DB_NAME'));
  19. define('VAR_DBHANDLER','DBHandler');
  20. $Register = &Register::getInstance();
  21. $Register->set(VAR_DBHANDLER, $DB_tree);
  22.  
  23. $currency = currGetCurrencyByID( $_SESSION['current_currency'] );
  24. $currency_str = str_replace('{value}','',$currency['display_template_ru']);
  25.  
  26. $langManager = &LanguagesManager::getInstance();
  27. $ln = LanguagesManager::getLanguageInstance($_SESSION['current_language']);
  28. $store_str = ($onstore)?' AND prd.in_stock > 0 ':'';
  29.  
  30. $sql = mysql_query("SELECT prd.name_".$ln->iso2." name, prd.Price, prd.productID , prd.slug FROM SC_products prd
  31. 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
  32. GROUP BY prd.name_".$ln->iso2."
  33. ORDER BY prd.name_".$ln->iso2."
  34. LIMIT 0,10");
  35.  
  36. while( $row_base = mysql_fetch_assoc($sql) ){
  37. $res = mb_strpos(mb_strtolower($row_base["name"],"UTF-8"), mb_strtolower($_GET['q'],"UTF-8"));
  38. if($res!==false&&$res==0) {
  39. $row_base["Price"] = trim($row_base["Price"]);
  40. echo getHref($row_base).", ".$row_base["Price"].$currency_str."\n";
  41. } else $other[] = $row_base;
  42. }
  43.  
  44. if( count($other) ){
  45. foreach( $other as $_product ){
  46. $_product["Price"] = trim($_product["Price"]);
  47. echo getHref($_product).", ".$_product["Price"].$currency_str."\n";
  48. }
  49. }
  50. }
  51. }
  52.  
  53. function getHref($product){
  54. $phrase = addslashes($_GET['q']);
  55. $phrase = str_replace(array('\'','"'), " ", $_GET['q']/*$phrase*/);
  56. $product["name"] = addslashes($product["name"]);
  57. $name = preg_replace('/'.$phrase.'/sui','|',$product["name"]);
  58. $word = explode('|',$name);
  59.  
  60. $style_start = '<span class="match_phrase">';
  61. $style_end = '</span>';
  62.  
  63. if(empty($word[0]) && empty($word[1])){
  64. $product["name"] = $style_start.$product["name"].$style_end;
  65. } else if(empty($word[0])) {
  66. $product["name"] = $style_start.str_replace(array($word[1]),array($style_end.$word[1]),$product["name"]);
  67. } else if(empty($word[1])) {
  68. $product["name"] = str_replace(array($word[0]),array($word[0].$style_start),$product["name"]).$style_end;
  69. } else {
  70. $product["name"] = str_replace(array($word[0],$word[1]),array($word[0].$style_start,$style_end.$word[1]),$product["name"]);
  71. }
  72. $product["name"] = stripslashes($product["name"]);
  73.  
  74. $url = str_replace('/published/SC/html/scripts','',xHtmlSetQuery('?ukey=product&productID='.$product["productID"].'&product_slug='.$product["slug"]));
  75. $url = str_replace('autocomplete.php','',$url);
  76. return '<span class="href_url" id="'.$url.'">'.$product["name"].'</span>';
  77. }
  78.  
  79. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement