) $where_clause .= " AND "; $from = ConvertPriceToUniversalUnit( $price["from"] ); $where_clause .= " Price>=".(double)$from." "; } if ( trim($price["to"]) != "" && $price["to"] != null ) { if ( $where_clause != "" ) $where_clause .= " AND "; $to = ConvertPriceToUniversalUnit( $price["to"] ); $where_clause .= " Price<=".(double)$to." "; } } // categoryID if ( isset($callBackParam["categoryID"]) ) { $searchInSubcategories = false; if ( isset($callBackParam["searchInSubcategories"]) ) { if ( $callBackParam["searchInSubcategories"] ) $searchInSubcategories = true; else $searchInSubcategories = false; } if ( $searchInSubcategories ) { $where_clause = _getConditionWithCategoryConjWithSubCategories( $where_clause, $callBackParam["categoryID"] ); } else { $where_clause = _getConditionWithCategoryConj( $where_clause, $callBackParam["categoryID"] ); } } if ( $where_clause != "" ) $where_clause = "where ".$where_clause; } $order_by_clause = "order by ".CONF_DEFAULT_SORT_ORDER; if ( isset($callBackParam["sort"]) ) { if ( $callBackParam["sort"] == "categoryID" || $callBackParam["sort"] == "name" || $callBackParam["sort"] == "brief_description" || $callBackParam["sort"] == "in_stock" || $callBackParam["sort"] == "Price" || $callBackParam["sort"] == "customer_votes" || $callBackParam["sort"] == "customers_rating" || $callBackParam["sort"] == "list_price" || $callBackParam["sort"] == "sort_order" || $callBackParam["sort"] == "items_sold" || $callBackParam["sort"] == "product_code" || $callBackParam["sort"] == "shipping_freight" || $callBackParam["sort"] == "viewed_times" ) { $order_by_clause = " order by ".xEscSQL($callBackParam["sort"])." ASC "; if ( isset($callBackParam["direction"]) ) if ( $callBackParam["direction"] == "DESC" ) $order_by_clause = " order by ".xEscSQL($callBackParam["sort"])." DESC "; } } $sqlQueryCount = "select count(*) from ".PRODUCTS_TABLE." ".$where_clause; $q = db_query( $sqlQueryCount ); $products_count = db_fetch_row($q); $products_count = $products_count[0]; $limit_clause= (isset($callBackParam["extraParametrsTemplate"]) || !$CountRowOnPage)?"":" LIMIT ".$offset.",".$CountRowOnPage; $sqlQuery = "select categoryID, name, brief_description, ". " customers_rating, Price, in_stock, tpl_city,". " customer_votes, list_price, ". " productID, default_picture, sort_order, items_sold, enabled, ". " product_code, description, shipping_freight, viewed_times, min_order_amount from ".PRODUCTS_TABLE." ". $where_clause." ".$order_by_clause.$limit_clause; $q = db_query( $sqlQuery ); $result = array(); $i = 0; if ($offset >= 0 && $offset <= $products_count ) { while( $row = db_fetch_row($q) ) { if ( isset($callBackParam["extraParametrsTemplate"]) ){ // take into "extra" parametrs $testResult = _testExtraParametrsTemplate( $row["productID"], $replicantExtraParametersTpl ); if ( !$testResult ) continue; } if ( (($i >= $offset || !isset($callBackParam["extraParametrsTemplate"])) && $i < $offset + $CountRowOnPage) || $navigatorParams == null ) { $row["PriceWithUnit"] = show_price($row["Price"]); $row["list_priceWithUnit"]= show_price($row["list_price"]); // you save (value) $row["SavePrice"] = show_price($row["list_price"]-$row["Price"]); // you save (%) if ($row["list_price"]) $row["SavePricePercent"] = ceil(((($row["list_price"]-$row["Price"])/$row["list_price"])*100)); _setPictures( $row ); $row["product_extra"] = GetExtraParametrs( $row["productID"] ); $row["product_extra_count"] = count($row["product_extra"]); $row["PriceWithOutUnit"] = show_priceWithOutUnit( $row["Price"] ); if ( ((double)$row["shipping_freight"]) > 0 ) $row["shipping_freightUC"] = show_price( $row["shipping_freight"] ); $row["name"] = ($row["name"]) ? $row["name"] : $row['tpl_city']; $row["description"] = $row["description"]; $row["brief_description"] = $row["brief_description"]; $row["product_code"] = $row["product_code"]; $row["viewed_times"] = $row["viewed_times"]; $row["items_sold"] = $row["items_sold"]; $result[] = $row; } $i++; } } $count_row = isset($callBackParam["extraParametrsTemplate"])?$i:$products_count; return $result; } // ***************************************************************************** // Purpose gets all products by categoryID // Inputs $callBackParam item // "search_simple" - string search simple // "direction" - sort direction DESC - by descending, by ascending otherwise // "searchInSubcategories" - if true function searches product in subcategories, otherwise it does not // "searchInEnabledSubcategories" - this parametr is actual when "searchInSubcategories" parametr is specified // if true this function take in mind enabled categories only // "categoryID" - is not set or category ID to be searched // "name" - array of name template // "product_code" - array of product code template // "price" - array of item // "from" - down price range // "to" - up price range // "enabled" - value of column "enabled" in database // "extraParametrsTemplate" // Remarks // Returns function prdSearchProductByTemplate($callBackParam, &$count_row, $navigatorParams = null ) { // navigator params if ( $navigatorParams != null ) { $offset = xEscSQL($navigatorParams["offset"]); $CountRowOnPage = xEscSQL($navigatorParams["CountRowOnPage"]); } else { $offset = 0; $CountRowOnPage = 0; } if ( isset($callBackParam["extraParametrsTemplate"]) ){ $replicantExtraParametersTpl = $callBackParam["extraParametrsTemplate"]; } // special symbol prepare if ( isset($callBackParam["search_simple"]) ) { /* for( $i=0; $i $value ) { if ( is_int($key) ) { $callBackParam["extraParametrsTemplate"][$key] = xEscSQL(trim($callBackParam["extraParametrsTemplate"][$key]) ); _deletePercentSymbol( $callBackParam["extraParametrsTemplate"][$key] ); } } } $where_clause = ""; if ( isset($callBackParam["search_simple"]) ) { if (!count($callBackParam["search_simple"])) //empty array { $where_clause = " where 0"; } else //search array is not empty { $sscount = count($callBackParam["search_simple"]); for ($n=0; $n<$sscount; $n++) { if ( $where_clause != "" ) $where_clause .= " AND "; $where_clause .= " ( LOWER(name) LIKE '%".xToText(trim(strtolower($callBackParam["search_simple"][$n])))."%' OR ". " LOWER(description) LIKE '%".xEscSQL(trim(strtolower($callBackParam["search_simple"][$n])))."%' OR ". " LOWER(product_code) LIKE '%".xEscSQL(trim(strtolower($callBackParam["search_simple"][$n])))."%' OR ". " LOWER(brief_description) LIKE '%".xEscSQL(trim(strtolower($callBackParam["search_simple"][$n])))."%' ) "; } if ( $where_clause != "" ) { $where_clause = " where categoryID>1 and enabled=1 and ".$where_clause; } else { $where_clause = " where categoryID>1 and enabled=1"; } if(CONF_CHECKSTOCK && CONF_SHOW_NULL_STOCK){ if ( $where_clause != "" ) $where_clause .= " AND in_stock>0 "; else $where_clause = "where in_stock>0 "; } } } else { // "enabled" parameter if ( isset($callBackParam["enabled"]) ) { if ( $where_clause != "" ) $where_clause .= " AND "; $where_clause.=" enabled=".(int)$callBackParam["enabled"]; } // take into "name" parameter if ( isset($callBackParam["name"]) ) { foreach( $callBackParam["name"] as $name ) if (strlen($name)>0) { if ( $where_clause != "" ) $where_clause .= " AND "; $where_clause .= " LOWER(name) LIKE '%".xToText(trim(strtolower($name)))."%' "; } } // take into "product_code" parameter if ( isset($callBackParam["product_code"]) ) { foreach( $callBackParam["product_code"] as $product_code ) { if ( $where_clause != "" ) $where_clause .= " AND "; $where_clause .= " LOWER(product_code) LIKE '%".xToText(trim(strtolower($product_code)))."%' "; } } // take into "price" parameter if ( isset($callBackParam["price"]) ) { $price = $callBackParam["price"]; if ( trim($price["from"]) != "" && $price["from"] != null ) { if ( $where_clause != "" ) $where_clause .= " AND "; $from = ConvertPriceToUniversalUnit( $price["from"] ); $where_clause .= " Price>=".(double)$from." "; } if ( trim($price["to"]) != "" && $price["to"] != null ) { if ( $where_clause != "" ) $where_clause .= " AND "; $to = ConvertPriceToUniversalUnit( $price["to"] ); $where_clause .= " Price<=".(double)$to." "; } } if(CONF_CHECKSTOCK && CONF_SHOW_NULL_STOCK){ if ( $where_clause != "" ) $where_clause .= " AND in_stock>0 "; else $where_clause = "where in_stock>0 "; } // categoryID if ( isset($callBackParam["categoryID"]) ) { $searchInSubcategories = false; if ( isset($callBackParam["searchInSubcategories"]) ) { if ( $callBackParam["searchInSubcategories"] ) $searchInSubcategories = true; else $searchInSubcategories = false; } if ( $searchInSubcategories ) { $where_clause = _getConditionWithCategoryConjWithSubCategories( $where_clause, $callBackParam["categoryID"] ); } else { $where_clause = _getConditionWithCategoryConj( $where_clause, $callBackParam["categoryID"] ); } } if ( $where_clause != "" ) $where_clause = "where ".$where_clause; } $order_by_clause = "order by ".CONF_DEFAULT_SORT_ORDER.""; if ( isset($callBackParam["sort"]) ) { if ( $callBackParam["sort"] == "categoryID" || $callBackParam["sort"] == "name" || $callBackParam["sort"] == "brief_description" || $callBackParam["sort"] == "in_stock" || $callBackParam["sort"] == "Price" || $callBackParam["sort"] == "customer_votes" || $callBackParam["sort"] == "customers_rating" || $callBackParam["sort"] == "list_price" || $callBackParam["sort"] == "sort_order" || $callBackParam["sort"] == "items_sold" || $callBackParam["sort"] == "product_code" || $callBackParam["sort"] == "shipping_freight" || $callBackParam["sort"] == "viewed_times" ) { $order_by_clause = " order by ".xEscSQL($callBackParam["sort"])." ASC "; if ( isset($callBackParam["direction"]) ) if ( $callBackParam["direction"] == "DESC" ) $order_by_clause = " order by ".xEscSQL($callBackParam["sort"])." DESC "; } } $sqlQueryCount = "select count(*) from ".PRODUCTS_TABLE." ".$where_clause; $q = db_query( $sqlQueryCount ); $products_count = db_fetch_row($q); $products_count = $products_count[0]; $limit_clause= (isset($callBackParam["extraParametrsTemplate"]) || !$CountRowOnPage)?"":" LIMIT ".$offset.",".$CountRowOnPage; $sqlQuery = "select productID, categoryID, p.UID, customers_rating, customer_votes, default_picture, items_sold, enabled, viewed_times, pictures, tpl_city, IF(p.tplID>0,tp.Price,p.Price) Price, IF(p.tplID>0,tp.in_stock,p.in_stock) in_stock, IF(p.tplID>0,tp.list_price,p.list_price) list_price, IF(p.tplID>0,tp.sort_order,p.sort_order) sort_order, IF(p.tplID>0,tp.product_code,p.product_code) product_code, IF(p.tplID>0,tp.folder_pictures,p.folder_pictures) folder_pictures, IF(p.tplID>0,REPLACE( tp.name,'{city}',p.tpl_city ),p.name) name, IF(p.tplID>0,REPLACE( tp.brief_description,'{city}',p.tpl_city ),p.brief_description) brief_description, IF(p.tplID>0,REPLACE( tp.description,'{city}',p.tpl_city ),p.description) description, IF(p.tplID>0,tp.shipping_freight,p.shipping_freight) shipping_freight, IF(p.tplID>0,tp.min_order_amount,p.min_order_amount) min_order_amount from ".PRODUCTS_TABLE." p LEFT JOIN ". PRODUCTS_TPL_TABLE." tp USING(tplID) ".$where_clause." ".$order_by_clause.$limit_clause; $q = db_query( $sqlQuery ); $result = array(); $i = 0; if ($offset >= 0 && $offset <= $products_count ) { while( $row = db_fetch_row($q) ) { if ( isset($callBackParam["extraParametrsTemplate"]) ){ // take into "extra" parametrs $testResult = _testExtraParametrsTemplate( $row["productID"], $replicantExtraParametersTpl ); if ( !$testResult ) continue; } if ( (($i >= $offset || !isset($callBackParam["extraParametrsTemplate"])) && $i < $offset + $CountRowOnPage) || $navigatorParams == null ) { $row["PriceWithUnit"] = show_price($row["Price"]); $row["list_priceWithUnit"]= show_price($row["list_price"]); // you save (value) $row["SavePrice"] = show_price($row["list_price"]-$row["Price"]); // you save (%) if ($row["list_price"]) $row["SavePricePercent"] = ceil(((($row["list_price"]-$row["Price"])/$row["list_price"])*100)); $row["product_extra"] = GetExtraParametrs( $row["productID"] ); $row["product_extra_count"] = count($row["product_extra"]); $row["PriceWithOutUnit"] = show_priceWithOutUnit( $row["Price"] ); if ( ((double)$row["shipping_freight"]) > 0 ) $row["shipping_freightUC"] = show_price( $row["shipping_freight"] ); _setPictures( $row ); $result[] = $row; } $i++; } } $count_row = isset($callBackParam["extraParametrsTemplate"])?$i:$products_count; return $result; } function prdGetMetaKeywordTag( $productID ) { $q = db_query("select meta_description from ".PRODUCTS_TABLE." where productID=".(int)$productID); if ( $row=db_fetch_row($q) ) return $row["meta_description"]; else return ""; } function prdGetMetaTags( $productID ) //gets META keywords and description - an HTML code to insert into section { $q = db_query( "select meta_description, meta_keywords from ". PRODUCTS_TABLE." where productID=".(int)$productID ); $row = db_fetch_row($q); $meta_description = $row["meta_description"]; $meta_keywords = $row["meta_keywords"]; $res = ""; if ( $meta_description != "" ) $res .= "\n"; if ( $meta_keywords != "" ) $res .= "\n"; return $res; } function prdSearchProductByTemplate_new( $callBackParam, &$count_row, $navigatorParams = null ) { // navigator params $where_clause='where enabled=1 and( ('.make_serch_string( "LOWER(p.`title`)", $callBackParam["search_simple"] ). ') or ('.make_serch_string( "LOWER(p.`name`)", $callBackParam["search_simple"] ).') or ('.make_serch_string( "LOWER(p.`tpl_city`)", $callBackParam["search_simple"] ). ') )'; //$q=db_query("select categoryID, `name`,`title`,`cat_h1` from ".CATEGORIES_TABLE." where (".make_serch_string( "LOWER(`name`)", $tmp ).") OR (".make_serch_string( "LOWER(`title`)", $tmp ).") or (".make_serch_string( "LOWER(`cat_h1`)", $tmp ).") order by name") // special symbol prepare $order_by_clause = "order by ".CONF_DEFAULT_SORT_ORDER.""; $sqlQuery = "select p.productID, p.categoryID, p.default_picture, p.enabled, p.pictures, p.UID, p.maps_sort, p.tpl_city as n2, IF(tplID>0, REPLACE(tp.name,'{city}',p.tpl_city),p.name) name, IF(tplID>0,tp.Price, p.Price) Price, IF(tplID>0,tp.folder_pictures,tp.folder_pictures) folder_pictures, IF(tplID>0,tp.product_code,p.product_code) product_code, IF(tplID>0,REPLACE(tp.title,'{city}',p.tpl_city),p.title) title from ".PRODUCTS_TABLE. " as p left join ".PRODUCTS_TPL_TABLE." as tp USING(tplID) $where_clause order by p.tpl_city "; //echo '$sqlQuery='.$sqlQuery; exit; $q = db_query( $sqlQuery ); $result = array(); $i = 0; while( $row = db_fetch_row($q) ) { if($row["folder_pictures"]){ $row["brif_picture"] = explode(",", $row["pictures"]); $row["brif_picture"] = $row["brif_picture"][0]; $row["pic_path"] = "/data/pictures_tpl/".$row["folder_pictures"]."/80/"; }else{ $row["pic_path"] = "/data/pictures/lmenu/"; } $row["PriceWithUnit"] = show_price($row["Price"]); $row["list_priceWithUnit"] = isset($row["list_price"]) ? show_price($row["list_price"]):"";//papush // you save (value) if(isset($row["list_price"])) $row["SavePrice"] = show_price($row["list_price"]-$row["Price"]); else $row["SavePrice"] = 0; // you save (%) //_setPictures( $row ); $row["maps_sort"] = (int)$row["maps_sort"]; //if ($row["n2"]!="")$row["name"] = $row["name"].' ��� '.$row["n2"]; $row["strlen"]=strlen($row["name"]); if($row["folder_pictures"]){ $row["brief_pictures"] = explode(",", $row["pictures"]); $row["brief_picture"] = "pictures_tpl/".$row["folder_pictures"]."/380/".$row["brief_pictures"][0]; }else{ $row["brief_picture"] = "pictures/main_pic/".$row["big_picture"]; } $result[] = $row; $i++; } $products_count = COUNT($row); $count_row = $i; $arr_columns_prod=array('name','title'); $result=sortresults($result,$arr_columns_prod); return $result; } ?>