$value) { $_GET[$key]=htmlentities($_GET[$key]); } foreach($_POST as $key => $value) { $_POST[$key]=htmlentities($_POST[$key]); } foreach($_REQUEST as $key => $value) { $_REQUEST[$key]=htmlentities($_REQUEST[$key]); } //=============================================== /********************************************************************************************** - If ANY of the passed keywords are an active SKU, user will be sent to that page. - If a Designer or Price has been selected or an entry made for Price, that filter will NOT appear on the left hand side. - Categories will always be visible, and expand if there are subtypes for it Future expansions: - "like ##AA#" where more items come up with similar metals and stones - AJAX toggles for different views (more detail, less detail, order by date added asc/desc, order by price asc/desc) - tweak the use of categories so that specific names are used, and rings are put into only one. add extra filters for things like diamond, gemstone, etc. **********************************************************************************************/ if(!empty($_REQUEST['itemsPerPage'])){ $itemsPerPage = $_REQUEST['itemsPerPage']; }elseif(!empty($_GET['itemsPerPage'])){ $itemsPerPage = $_GET['itemsPerPage']; }else{ $itemsPerPage = 36; } define("CONFIG_RESULTSPERPAGE", $itemsPerPage); # number of items (results) to display per page define("CONFIG_SHOWPRICEINRESULTS", true); # um.... show or don't show the price. pretty obvious. :) define("CONFIG_DESCLENGTH", 53); # length of the short description, in characters # check a string to see if it has the credentials to be a SKU function is_SKU($string) { # matches string that begins with 2-3 numbers, and followed by # 1-2 characters that are a letter, and followed by 1 number return (preg_match("/^([0-9]+)$/", $string)); } function format_for_screen_output($string, $length=-1) { $strReturn = stripslashes($string); $strReturn = htmlspecialchars($strReturn); return ($length > -1) ? substr($strReturn,0,$length).((strlen($strReturn)>$length)?"...":"") : $strReturn; } function print_search_form($help = true, $istop = true) { global $filter; global $price_orig; global $keywords_original; global $input; ?>
0, it is a child category if( $parent != 0 ) { #subcategory, if the parent is not 0 $filter['category']['query'] = "INNER JOIN Item_to_Types itt ON i.ItemID=itt.ItemID INNER JOIN ItemTypes ty ON itt.ItemTypeID=ty.ItemTypeID AND itt.ItemTypeID='".$filter['category']['value']."' "; } else { $filter['category']['query'] = " AND i.Deleted='N' AND i.ItemTypeID='".$filter['category']['value']."' "; } } else { $filter['category']['value'] = false; $filter['category']['query'] = ""; $cat_auto = false; /* $keywords_tmp = (isset($_REQUEST['keywords'])) ? stripslashes( $_REQUEST['keywords'] ) : ""; $matches = ''; $i = 0; foreach( explode( " ", $keywords_tmp ) as $word ) { if( strlen( $word ) > 2 ) { if( $i > 0 ) { $matches .= ' OR '; } $matches .= "ItemType REGEXP '^".$word."s?'"; $i++; } } $sql = "SELECT ItemTypeID, ItemType, ParentID FROM ItemTypes WHERE $matches"; #echo $sql; $cat_auto = @db_read( $sql ); if( $cat_auto !== false && mysql_num_rows( $cat_auto ) == 1 ) { $row = mysql_fetch_array( $cat_auto ); #automatically filter by the type, if one keyword matches exactly if( $row[2] == 0 ) { $filter['category']['query'] = " AND i.Deleted='N' AND i.ItemTypeID='".$row[0]."' "; } else { $filter['category']['query'] = "INNER JOIN Item_to_Types itt ON i.ItemID=itt.ItemID INNER JOIN ItemTypes ty ON itt.ItemTypeID=ty.ItemTypeID AND itt.ItemTypeID='".$row[0]."' "; } #remove that keyword from the rest of the searches $_REQUEST['keywords'] = preg_replace( '/'.$row[1].'?/i', "", $_REQUEST['keywords'] ); $cat_auto = true; } else { $cat_auto = false; } */ } /*************************** Categories can either be: a) a main type (rings, earrings, necklaces, etc.), or b) a sub type (engagement, halo, pave, etc.) c) not defined If it's a main type, we want to show any available subtypes under it. with counts If it's a subtype, we want to see siblings and the parent. with counts for subtypes only If no category was selected, then only show main types. with counts. *************************** if( !empty( $_REQUEST['Category'] ) ): // category selected $_REQUEST['Category']=htmlentities($_REQUEST['Category']); $filter['category']['value'] = intval($_REQUEST['Category']); $parent = @db_read_onefield( "SELECT ParentID FROM ItemTypes WHERE Deleted='N' AND ItemTypeID='".$filter['category']['value']."'" ); #echo "$parent"; if($parent > 0): // subtype selected $filter['category']['query'] = "INNER JOIN Item_to_Types itt ON i.ItemID=itt.ItemID INNER JOIN ItemTypes ty ON itt.ItemTypeID=ty.ItemTypeID AND itt.ItemTypeID='".$filter['category']['value']."' "; else: // main type is selected $filter['category']['query'] = " AND i.Deleted='N' AND i.ItemTypeID='".$filter['category']['value']."' "; # find subtypes beneath this one & counts endif; else: // no category selected endif;*/ #see if a designer is being filtered if( !empty( $_REQUEST['DesignerID'] ) ) { $filter['designer']['value'] = intval($_REQUEST['DesignerID']); $filter['designer']['query'] = " AND (i.DesignerID='".$filter['designer']['value']."' OR c.CollectionID='".$filter['designer']['value']."') "; $des_auto = false; } else { $filter['designer']['value'] = false; $filter['designer']['query'] = ""; $_REQUEST['keywords']=htmlentities($_REQUEST['keywords']); if (isset($_REQUEST['keywords'])) $keywords_tmp = stripslashes( $_REQUEST['keywords'] ); else $keywords_tmp = ""; $matches = ''; $i = 0; foreach( explode( " ", $keywords_tmp ) as $word ) { if( strlen( $word ) > 3 ) { if( $i > 0 ) { $matches .= ' OR '; } $matches .= "DesignerName LIKE '%".$word."%'"; $i++; } } $sql = "SELECT DesignerID, DesignerName FROM Designers WHERE Deleted='N' AND (Regular=1 OR Closeout=1) AND DesignerName NOT LIKE '%diamond%' AND $matches"; #echo $sql; $des_auto = @db_read( $sql ); if( $des_auto !== false && mysql_num_rows( $des_auto ) == 1 ) { $row = mysql_fetch_array( $des_auto ); $row[1] = strtolower($row[1]); #automatically filter by the type, if one keyword matches exactly $filter['designer']['query'] = " AND (i.DesignerID='".$row[0]."' OR c.CollectionID='".$row[0]."') "; #remove that keyword from the rest of the searches foreach( explode( " ", trim(strtolower($keywords_tmp)) ) as $word ) { $word = trim( $word ); if( strlen( $word ) > 3 && strpos( $row[1], $word ) !== false ) { $_REQUEST['keywords'] = str_replace( $word, "", strtolower($_REQUEST['keywords']) ); } } $des_auto = true; } else { $des_auto = false; } } #see if a date is being filtered if( !empty( $_REQUEST['Date'] ) ) { $filter['date']['value'] = $_REQUEST['Date']; $day = floor((time() - strtotime( $filter['date']['value'] ))/86400); $filter['date']['query'] = " AND i.DateAdded >= DATE_SUB(CURDATE(),INTERVAL ".$day." DAY)"; } else { $filter['date']['value'] = false; $filter['date']['query'] = ""; } #see if a price is being filtered if( !empty( $_REQUEST['Price'] ) ) { $price_orig = $_REQUEST['Price']; $price_orig_text = str_replace( "-1000000", " and up", $price_orig ); $price_range = explode( "-", $_REQUEST['Price'] ); if( $price_range[0] == 0 ) $price_range[0]++; $filter['price']['value'] = intval($_REQUEST['Price']); $filter['price']['query'] = " AND i.ShowPrice=1 AND i.Price BETWEEN ".intval($price_range[0])." AND ".intval($price_range[1])." AND i.Price > 0 "; } else { $price_orig = ''; $price_range = array( 0=>'1', 1=>'1000000' ); $filter['price']['value'] = false; $filter['price']['query'] = ""; } #do not search if all keywords and filters are empty $input = true; #if they submitted keywords, continue if( !empty( $_REQUEST['keywords'] ) ) { $keywords = htmlentities($_REQUEST['keywords']); $keywords = stripslashes( trim($keywords) ); $link = "?keywords=".htmlentities($keywords_original, ENT_QUOTES); if( !empty( $keywords ) ) { $match = "WHERE (MATCH(i.SKU, i.StoreSKU, i.Description, i.ShortDesc, i.Comments, i.Specs) AGAINST ('".$keywords."' IN BOOLEAN MODE) OR MATCH( d.DesignerName ) AGAINST ('".$keywords."' IN BOOLEAN MODE)) AND i.Deleted='N' AND d.Deleted='N' ".$filter['price']['query'].$filter['date']['query']; $match_order = "( 0.6*(MATCH(i.SKU, i.StoreSKU, i.Description, i.ShortDesc, i.Comments, i.Specs) AGAINST ('".$keywords."' IN BOOLEAN MODE)) + 0.3*(MATCH( d.DesignerName ) AGAINST ('".$keywords."' IN BOOLEAN MODE)/3) + 0.1*(SQRT(i.Views)/5) ) DESC"; } else { $match = "WHERE i.Deleted='N' ".$filter['price']['query'].$filter['date']['query']; $match_order = "i.Views DESC"; } if( $filter['category']['value'] === false ) { $i = 0; $matches = ''; foreach( explode( " ", $keywords ) as $word ) { if( strlen( $word ) > 2 ) { if( $i > 0 ) { $matches .= ' OR '; } $matches .= "ItemType LIKE '%".$word."%'"; $i++; } } $sql = "SELECT ItemType, ItemTypeID FROM ItemTypes WHERE ".$matches." ORDER BY RAND() LIMIT 4"; # echo $sql; $cat_match = @db_read( $sql ); } else { $cat_match = false; } if( $filter['designer']['value'] === false ) { $i = 0; $matches = ''; foreach( explode( " ", $keywords ) as $word ) { if( strlen( $word ) > 2 ) { if( $i > 0 ) { $matches .= ' OR '; } $matches .= "DesignerName LIKE '%".$word."%'"; $i++; } } $des_match = @db_read( "SELECT DesignerName, DesignerID FROM Designers WHERE Deleted='N' AND (Regular=1 OR Closeout=1) AND ".$matches." ORDER BY RAND() LIMIT 4" ); } else { $des_match = false; } if( rand(0,1) == 1 ) { $article = @db_read( "SELECT PageName, PageTitle FROM Pages WHERE MATCH( PageTitle, PageText, Keywords, Description, PageName ) AGAINST ('".$keywords."') AND SiteID=\"pearlmans\" AND visible=1 ORDER BY RAND() LIMIT 1" ); if( !empty( $article ) && mysql_num_rows( $article ) > 0 ) { $article = mysql_fetch_array( $article ); } else { $article = false; } } else { $article = false; } } else { // no keywords were entered $keywords = ""; $cat_match = false; // category match $des_match = false; // designer match // add price query string if a price filter has been entered if( !empty( $filter['price']['query'] ) ) { $match = " WHERE i.Deleted='N' ".$filter['price']['query']; } // add date query string if a date query has been entered if( !empty( $filter['date']['query'] ) ) { if( empty( $match ) ) { $match = " WHERE i.Deleted='N' ".$filter['date']['query']; } else { $match .= $filter['date']['query']; } } if( empty( $match ) ) { $match = " WHERE i.Deleted='N' "; } if( !empty( $filter['price']['query'] ) ){ $match_order = " i.Price DESC "; }else{ $match_order = " i.Views DESC "; } if( !empty( $keywords_original ) ) { $link = "?keywords=".htmlentities($keywords_original, ENT_QUOTES); } else { $link = "?"; } $article = false; } if( !empty( $_REQUEST['page'] ) ) { $_REQUEST['page']=htmlentities($_REQUEST['page']); $link = $link.'&page='.intval($_REQUEST['page']); } if( !empty( $_REQUEST['itemsPerPage'] ) ) { $link = $link.'&itemsPerPage='.$_REQUEST['itemsPerPage']; } #save the search /* if( !isInternalIp() ) { @db_write( "INSERT INTO searches (keywords,designer,category,price_low,price_high,offset,IP,searchtime,daterange) VALUES ('".$keywords_original."', '".$filter['designer']['value']."', '".$filter['category']['value']."', '".$price_range[0]."', '".$price_range[1]."', '".$offset."', '".$_SERVER['REMOTE_ADDR']."', NOW(), '".$filter['date']['value']."')" ); } */ #the bulk of the main query so it is consistent with the other queries $mainQuery = "FROM Items i LEFT JOIN ItemCollections c ON i.ItemID=c.ItemID" # LEFT JOIN products pr ON i.SKU=pr.model ." INNER JOIN Designers d ON i.DesignerID=d.DesignerID ".$filter['designer']['query']." AND d.DesignerID NOT IN (57,79) AND d.Deleted='N' INNER JOIN ItemTypes t ON i.ItemTypeID=t.ItemTypeID ".$filter['category']['query']." $match "; #if there is a price filter in place, add that to the query $filter['price']['variable'] = "Price"; if( $filter['price']['value'] !== false ) { $filter['price']['sql'] = false; $link = $link.'&Price='.intval($price_range[0]).'-'.intval($price_range[1]); } else { #otherwise get the price and counts of results /* rounds price to the thousand, gets the log, multiplies it by two, and rounds that number off before getting the min, number, and max doing this creates grouped ranges of prices rather than just within the thousands or exactly similar prices pretty decent mathmagic. keep it. */ $filter['price']['sql'] = @db_read( "SELECT MIN(i.Price), COUNT(i.Price), MAX(i.Price) $mainQuery GROUP BY round(log( 10, round(i.Price,-3))*2) ORDER BY i.Price DESC" ); } #if there is a date filter in place, add that to the query $filter['date']['variable'] = "Date"; if( $filter['date']['value'] !== false ) { $filter['date']['sql'] = false; $link = $link.'&Date='.$filter['date']['value']; } else { //^/^/^/ NOT EVEN USED!!! /^/^/^/^/^/^/^/^/^/^/^/^/^/^/^/^/^/^/^/^/^/^/^/^/ #otherwise get the date and counts of results. Only go back 120 days $filter['date']['sql'] = @db_read( "SELECT (TRUNCATE( DateAdded , -7 )) AS Date1, COUNT( TRUNCATE( DateAdded , -7 ) ) AS Results, (TRUNCATE( DateAdded , -7 )) AS Date2 $mainQuery GROUP BY TRUNCATE(DateAdded,-7) ORDER BY TRUNCATE(DateAdded,-7) DESC WHERE DateAdded >= DATE_SUB(CURDATE(),INTERVAL 120 DAY) LIMIT 5" ); } #if there is a category filter in place, add that to the query $filter['category']['variable'] = "Category"; if( $filter['category']['value'] !== false ) { $check = @db_read( "SELECT ItemType, ItemTypeID FROM ItemTypes WHERE Deleted='N' AND ParentID='".intval($filter['category']['value'])."'" ); if( mysql_num_rows( $check ) > 0 ) { $tmpmain = str_replace( "INNER JOIN ItemTypes t ON i.ItemTypeID=t.ItemTypeID ".$filter['category']['query']." $match ", "", $mainQuery); $filter['category']['sql'] = @db_read( "SELECT t.ItemType, COUNT(i.ItemTypeID), t.ItemTypeID $tmpmain LEFT JOIN Item_to_Types itt ON i.ItemID=itt.ItemID INNER JOIN ItemTypes t ON itt.ItemTypeID=t.ItemTypeID $match AND t.ParentID='".intval($filter['category']['value'])."' GROUP BY i.ItemTypeID, t.ItemType ORDER BY t.ItemType" ); } else { $filter['category']['sql'] = false; } $link = $link.'&Category='.$filter['category']['value']; } else { #otherwise get the category and counts of results $filter['category']['sql'] = @db_read( "SELECT t.ItemType, COUNT(i.ItemTypeID), t.ItemTypeID $mainQuery GROUP BY i.ItemTypeID, t.ItemType ORDER BY t.ItemTypeID" ); } #if there is a designer filter in place, add that to the query $filter['designer']['variable'] = "DesignerID"; if( $filter['designer']['value'] !== false ) { $filter['designer']['sql'] = false; $link = $link.'&DesignerID='.$filter['designer']['value']; } else { #otherwise get the designers and counts of results $filter['designer']['sql'] = @db_read( "SELECT d.DesignerName, COUNT(i.ItemID), d.DesignerID $mainQuery GROUP BY i.designerid, d.designerName ORDER BY d.DesignerName" ); } if( empty( $keywords_original ) && empty( $filter['designer']['value'] ) && empty( $filter['category']['value'] ) && empty( $filter['date']['value'] ) && empty( $price_orig ) ) { $input = false; $search = false; $count = false; } else { $search = @db_read( "SELECT DISTINCT i.ItemID, i.ShortDesc, d.DesignerName, t.ItemType, i.SKU, i.Title, i.DateAdded, i.CloseOutShowReduced, i.CloseOutPrice, i.ItemTypeID, i.DesignerID, i.Price, i.ShowPrice, i.Views, d.PageTitle" /*, pr.enabled, pr.product_id*/." $mainQuery ORDER BY $match_order LIMIT $offset, ".CONFIG_RESULTSPERPAGE ); $count = @db_read_onefield( "SELECT COUNT(i.ItemID) $mainQuery" ); if( $count == 1 ) { $result = mysql_fetch_array( $search ); $go_here = item_link($result["DesignerID"],$result['PageTitle'],$result['ItemType'],$result['SKU']); header( "Location: ".$go_here ); exit; } } $searchTitle = @db_read_onefield( "SELECT `DesignerName` FROM `Designers` WHERE `DesignerID` =".$filter['designer']['value']."" ); $typeTitle = @db_read_onefield( "SELECT `ItemType` FROM `ItemTypes` WHERE `ItemTypeID` =".$filter['category']['value']."" ); $page_title = ""; if( !empty( $keywords_original ) ): $page_title .= html_entity_decode($keywords_original); $page_title .= " "; endif; if($searchTitle != ''): $page_title .= $searchTitle." "; endif; if($typeTitle != ''): $page_title .= $typeTitle." "; endif; $page_title .= "luxury jewelry at Pearlman's Jewelers"; echo ""; ?>Please search by at least one option above
or
Use filters on the left to show a particular category, designer, date or price.
Try filtering your results to see only '; $trythis = true; while( $row = mysql_fetch_array( $cat_match ) ): if( $tryor > 0 ) echo ' or '; echo ''; echo ''.$row[0].''; echo ''; $tryor++; endwhile; endif; if( $des_auto === false && $des_match !== false && mysql_num_rows( $des_match ) > 0 ): if( !$trythis ) echo '
Try filtering your results to see only ';
while( $row = mysql_fetch_array( $des_match ) ):
if( $tryor > 0 )
echo ' or ';
echo '';
echo ''.stripslashes($row[0]).'';
echo '';
$tryor++;
endwhile;
endif;
if( !empty( $expand ) )
echo "
Filters: ".$expand;
//if( $limit ) echo " Maximum of ";
//echo " $total results found.
";
#show related pages
if( empty( $_SESSION['search_article'] ) )
$_SESSION['search_article'] = array();
if( $article !== false )
{
$article_title = $article[0];
if( !empty( $article_title ) && empty( $_SESSION['article_title'][$article_title] ) )
{
$_SESSION['search_article'][$article_title] = true;
echo '
Related Article: '.stripslashes($article[1]).'
'; } } $_REQUEST['page']=htmlentities($_REQUEST['page']); if( $total <= CONFIG_RESULTSPERPAGE ) echo 'Try removing filters or keywords to see more results
'; if( !empty( $_REQUEST['page'] ) ) $link = str_replace( '&page='.intval($_REQUEST['page']), '', $link ); $link = $link.'&page='; $link_nav = 'You may search by keywords like sapphire, ritani, earrings, etc.
Keep in mind that having many keywords may dilute your results.
(i.e. rose gold may return results matching either rose or gold, so it may be more effective to simply search for rose)
To narrow your search results, we organized our inventory using the filters on the left side of this page. Be sure to scroll the entire page for a complete list. You can now target your search by:
Searches are not case sensitive and you may use any combination of keywords OR filters to find the best results.
You may remove any filter or keyword from the search results by clicking (remove) next to the keyword or filter found below the search box.
Common words like "where" and "how" as well as single digit numbers are ignored.
Use a plus sign (+) before the word or enclose the item in quotes [ "1 ct." ]
Search by exact phrase using double quotes (“ ”) around the search terms.