<%@ LANGUAGE="VBSCRIPT" %> <% PageStrings = "18, 55, 104, 105, 107, 152, 153, 154, 161, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 265, 300, 648, 833, 1236, 1237, 1405, 1406, 1407, 1442, 1443, 1458, 1490, 1639, 1659, 1673, 1706, 1806, 1807, 1808, 1791, 1792" %> <% '----------------------------------------------- 'SET PAGETITLE TAG '----------------------------------------------- strPageTitleHTML = GetString("PageTitle_ProductSearch") & GetString("PageTitle_Separator") & GetString("Config_Webshopname") %> <% '=============================================== ' CactuShop ASP Shopping Cart ' ©1999-2007 Cactusoft International FZ-LLC ' www.cactusoft.com '=============================================== ' All rights reserved. ' Use of this code is covered by the terms and ' conditions in the license agreement. No ' unauthorized duplication or distribution is ' permitted. Cactusoft's copyright notices must ' remain in the ASP sections of the code. '=============================================== '=============================================== 'UPGRADE NOTE: numRecordPosition has become 'numSearchStartRecord. This values must not be passed 'to perform a new search (previously, a value 'or 1 was required to be passed) '=============================================== '************************************************************************************* ' SEARCH-SPECIFIC FUNCTIONS '************************************************************************************* 'Recursive function to write out the categories and sub-categories in a trail Function DoCats(objCategoriesDictionary, objSubCategoriesDictionary, numMotherID, strTrail, numLevel, numMaxLevel, numSelected) 'Write out the trail If numLevel <= numMaxLevel Or numMaxLevel = 0 Then If Clng(numMotherID) = Clng(numSelected) Then response.write("" & vbcrlf) Else response.write("" & vbcrlf) End If End If 'If there are any sub categories for this category If objSubCategoriesDictionary.Exists(NumSafe(numMotherID)) then 'Get all sub categories and loop through them arySubCategories = split(objSubCategoriesDictionary.Item(NumSafe(numMotherID)), ",") For each intSubCategory in arySubCategories If isnumeric(intSubCategory) then 'Add the sub category to the end of the trail and call the function with the new sub-cat strTrailToPass = "    " & strTrail DoCats objCategoriesDictionary, objSubCategoriesDictionary, intSubCategory, strTrailToPass, numLevel +1, numMaxLevel, numSelected end if Next end if end Function 'Recursive function to get all category IDs based on a parent category Function GetAllCatIDs(objCategoriesDictionary, objSubCategoriesDictionary, numMotherID) 'Start by setting it to this category GetAllCatIds = Cstr(numMotherID) 'If there are any sub categories for this category If objSubCategoriesDictionary.Exists(NumSafe(numMotherID)) then 'Get all sub categories and loop through them arySubCategories = split(objSubCategoriesDictionary.Item(NumSafe(numMotherID)), ",") For each intSubCategory in arySubCategories If isnumeric(intSubCategory) then 'Add on subcategories GetAllCatIDs = GetAllCatIDs & "," & GetAllCatIDs(objCategoriesDictionary, objSubCategoriesDictionary, intSubCategory) end if Next end if End Function 'Gets the next class for alternating rows numClassRowCount = 1 Function GetNextRowClass() GetNextRowClass = IIf(numClassRowCount mod 2 = 0, "form_line_2", "form_line_1") numClassRowCount = numClassRowCount + 1 End Function '************************************************************************************* ' COLLECT SEARCH VALUES FROM FORM OR CACTUSESSION '************************************************************************************* '----------------------------------------------- 'COLLECT VALUES '----------------------------------------------- numSearchStartRecord = NumSafe(request.querystring("numSearchStartRecord")) blnNewSearch = (numSearchStartRecord = 0) If numSearchStartRecord = 0 then numSearchStartRecord = 1 'Get useful application variables numAppSearchMaxRecs = NumSafe(GetAppVar("searchmaxrecs")) numAppCategoryLevelMenuSearch = NumSafe(GetAppVar("categorylevelsmenusearch")) strAppRecursiveCategorySearch = GetAppVar("recursivecategorysearch") numAppTryTheseCategories = NumSafe(GetAppVar("searchtrythesecategories")) strAppSearchDisplayType = GetAppVar("searchdisplaytype") '----------------------------------------------- 'SEARCH APPLICATION SETTINGS '----------------------------------------------- strCategorySearch = GetAppVar("categorysearch") strSearchByPrice = GetAppVar("searchbyprice") strAppUploadsFolder = GetAppVar("uploadsfolder") strAppAllowedImages = GetAppVar("allowedimages") '----------------------------------------------- 'SET VALUES FOR PRODUCTS, ROWS, COLS PER PAGE '----------------------------------------------- numProdsPerPage = NumSafe(GetAppVar("searchpagesize")) '--------------------------------------------- ' IS IT A NEW SEARCH? ' For a new search, we need to get all the ' form values, do a bit of cleaning, and ' store in cactusession. If it's not a new search ' (i.e. we're on page 2 onwards) then just ' get the values from cactusession. '--------------------------------------------- if blnNewSearch then '----------------------------------------------- 'GET THE USER-ENTERED SEARCH FIELDS 'CAT_ID - Category to search in (0 for all) 'strKeywords - keywords to search for 'strSearchCriteria - type of keyword search 'strAttributes - list of attributes to search on 'numPriceMin - minimum price to search on 'numPriceMax - maximum price to search on ' - (cleaned up with custom function) '----------------------------------------------- CAT_ID = NumSafe(request.querystring("CAT_ID")) strKeywords = trim(Request.querystring("strKeywords")) If strKeywords = "" then strKeywords = trim(request.QueryString("keywords")) strSearchCriteria = ListSafe(request.querystring("strSearchCriteria"), "any,all,exact", GetAppVar("defaultsearchcriteria")) numPriceMin = NumSafe(request.QueryString("numPriceMin")) numPriceMax = NumSafe(request.QueryString("numPriceMax")) 'Loop through all attributes to get their individual search values 'Convert this in to an array If SOFTWARE_IS_PRO Then strAttributes = Replace(request.QueryString("strAttributes"), ", ", "|") aryAttributes = Split(strAttributes, "|") strAttributeValues = GetAttributeValues(aryAttributes) aryAttributeValues = Split(strAttributeValues, "|") End If 'Store all raw values in cactusession. This are pretty much raw (minus safing them) objCactuSession.Edit "search_catid", CAT_ID objCactuSession.Edit "search_searchcriteria", strSearchCriteria objCactuSession.Edit "search_keywords", strKeywords objCactuSession.Edit "search_attributes", strAttributes objCactuSession.Edit "search_attributevalues", strAttributeValues objCactuSession.Edit "search_pricemin", numPriceMin objCactuSession.Edit "search_pricemax", numPriceMax Else 'Get the values from cactusession. Still have to be tidied up. CAT_ID = NumSafe(objCactuSession.Value("search_catid")) strSearchCriteria = ListSafe(objCactuSession.Value("search_searchcriteria"), "any,all,exact", GetAppVar("defaultsearchcriteria")) strKeywords = trim(objCactuSession.Value("search_keywords")) strAttributes = objCactuSession.Value("search_attributes") strAttributeValues = objCactuSession.Value("search_attributevalues") numPriceMin = NumSafe(objCactuSession.Value("search_pricemin")) numPriceMax = NumSafe(objCactuSession.Value("search_pricemax")) 'Split attribute and values in to arrays aryAttributes = Split(strAttributes, "|") aryAttributeValues = Split(strAttributeValues, "|") end if '************************************************************************************* 'CLEAN UP SEARCH VALUES '************************************************************************************* 'Check price range is valid If numPriceMax > 0 and numPriceMin > 0 and numPriceMin > numPriceMax then numPriceMax = 0 numPriceMin = 0 end if 'Clean the keywords - make a note if anything has changed strCleanKeywords = CleanSearchKeywords(strKeywords, strSearchCriteria) blnKeywordsCleaned = (strCleanKeywords <> strKeywords) strKeywords = strCleanKeywords 'DECIDE WHETHER TO DO THE SEARCH 'At least the keywords or one attribute has to 'be filled in to do a search blnDoSearch = not (strKeywords = "") or not (numPriceMin = 0) or not (numPriceMax = 0) If not blnDoSearch then If SOFTWARE_IS_PRO Then blnDoSearch = GotAtLeastOneAttribute(aryAttributeValues) End If End If 'Check both attribute and value have same bounds If SOFTWARE_IS_PRO Then If UBound(aryAttributes) <> UBound(aryAttributeValues) then aryAttributes = Split("") aryAttributeValues = Split("") End If End If '----------------------------------------------- 'READ PAGE TEMPLATE FROM FILE '----------------------------------------------- Call ReadFromTemplate(strTemplateLocation, aryPageTemplate) response.write(aryPageTemplate(0)) if blnDoSearch then '************************************************************************************* 'BUILD UP SEARCH TERMS '************************************************************************************* '----------------------------------------------- 'KEYWORD SEARCH CODE 'Cleans up the keywords, then builds up a query 'on various fields on product or description. '----------------------------------------------- 'Clean up aryKeywords = CreateKeywordArray(strKeywords, strSearchCriteria) 'Create WHERE clause on various fields - there's a string 'for product, version and category. If strKeywords <> "" then numCount = 0 For Each strKeyword in aryKeywords 'If we're not on the first keyword, add in a boolean 'phrase to break the spaces if numCount > 0 then strProductsClause = strProductsClause & iif(strSearchCriteria = "all", " AND ", " OR ") strVersionsClause = strVersionsClause & iif(strSearchCriteria = "all", " AND ", " OR ") End If 'Add on the query bit for product and version search strProductsClause = strProductsClause & "((P_Name" & CStr(numLanguageID) & " LIKE " & strUnicode & "'%" & SQLSafe(strKeyword) & "%') OR (" & castSQL("P_Desc" & CStr(numLanguageID)) & " LIKE " & strUnicode & "'%" & SQLSafe(strKeyword) & "%'))" strVersionsClause = (strVersionsClause & "((V_Name" & CStr(numLanguageID) & " LIKE " & strUnicode & "'%" & SQLSafe(strKeyword) & "%') OR (" & castSQL("V_Desc" & CStr(numLanguageID)) & " LIKE " & strUnicode & "'%" & SQLSafe(strKeyword) & "%') OR (V_CodeNumber LIKE " & strUnicode & "'%" & SQLSafe(strKeywords) & "%'))") numCount = numCount + 1 Next strProductsClause = "(" & strProductsClause & ")" strVersionsClause = "(" & strVersionsClause & ")" else strProductsClause = "1=1" strVersionsClause = "1=1" end if 'Modify clause for use with category strProdTypeClause = Replace(strProductsClause, "P", "CAT") '----------------------------------------------- 'SECTIONS CLAUSE 'If one specific section was selected '----------------------------------------------- if CAT_ID = 0 then strSectionClause = "1 = 1" else 'If it's recursive, get all subcategories for IN Clause. Otherwise 'just do a basic WHERE clause If strAppRecursiveCategorySearch = "y" then strSectionClause = "pt.CAT_ID IN (" & GetAllCatIDs(objCategoryDictionary, objParentDictionary, CAT_ID) & ")" else strSectionClause = "pt.CAT_ID = " & CAT_ID end if end if '----------------------------------------------- 'PERFORM THE QUERY ON PRODTYPES 'This does a 'try these categories' search. '----------------------------------------------- 'Only do this if we're not searching in a specific category, 'we've got keywords to search for and the feature hasn't been disabled if CAT_ID = 0 and strKeywords <> "" and numAppTryTheseCategories > 0 then 'If using access, append products table name for casting if strDatabaseType = "access" then strTblCat = "tblCactuShop" & TABLE_PREFIX & "Categories." else strTblCat = "" 'Run the search, getting TOP X fields (config setting) strQuery = LimitSQL("CAT_ID, CAT_Name" & CStr(numLanguageID) & ", " & strTblCat & castSQL("CAT_Desc" & CStr(numLanguageID)) & " as CAT_Desc" & CStr(numLanguageID) & " FROM tblCactuShop" & TABLE_PREFIX & "Categories WHERE CAT_Live = 'y' AND CAT_CustomerGroupID IN (0," & NumSafe(DB_CG_ID) & ") AND " & strProdTypeClause & " ORDER BY CAT_Name" & CStr(numLanguageID), numAppTryTheseCategories, false) Call ExecuteRS(strQuery, objRecordSet) blnGotCategories = not (objRecordSet.BOF and objRecordSet.EOF) If blnGotCategories then %>

<% WriteString("PageTitle_SearchResults") %>

<% WriteString("ContentText_NewSearch") %><% numCategoryCount = 0 response.Write "
" & GetString("ContentText_TryTheseCategories") & ":
" & vbcrlf end if objRecordSet.close end if '----------------------------------------------- ' PRICE CLAUSE '----------------------------------------------- If numPriceMin > 0 then If DB_CG_ID > 0 then strPriceClause = " AND (V_Price >= " & CStr(numPriceMin / objCurrency.ExchangeRate) & " OR CGP_Price >= " & CStr(numPriceMin / objCurrency.ExchangeRate) & ")" Else strPriceClause = " AND (V_Price >= " & CStr(numPriceMin/ objCurrency.ExchangeRate) & ")" End If End If If numPriceMax > 0 then If DB_CG_ID > 0 then strPriceClause = strPriceClause & " AND (V_Price <= " & CStr(numPriceMax / objCurrency.ExchangeRate) & " OR CGP_Price <= " & CStr(numPriceMax / objCurrency.ExchangeRate) & ")" Else strPriceClause = strPriceClause & " AND (V_Price <= " & CStr(numPriceMax / objCurrency.ExchangeRate) & ")" End If End If '----------------------------------------------- 'SET BASE QUERY PARTS '----------------------------------------------- strJoinSQL = "((((tblCactuShop" & TABLE_PREFIX & "Products p INNER JOIN tblCactuShop" & TABLE_PREFIX & "Versions v ON p.P_ID = v.V_ProductID) INNER JOIN tblCactuShop" & TABLE_PREFIX & "ProductCategoryLink ppt ON p.P_ID = ppt.PCAT_ProductID) INNER JOIN tblCactuShop" & TABLE_PREFIX & "Categories pt ON pt.CAT_ID = ppt.PCAT_CategoryID) INNER JOIN tblCactuShop" & TABLE_PREFIX & "TaxRates t on v.V_Tax = t.T_ID) LEFT OUTER JOIN tblCactuShop" & TABLE_PREFIX & "Suppliers s ON p.P_SupplierID = s.SUP_ID" If strPriceClause <> "" and DB_CG_ID > 0 then strJoinSQL = "(" & strJoinSQL & ") LEFT OUTER JOIN (SELECT CGP_VersionID, CGP_Price FROM tblCactuShop" & TABLE_PREFIX & "CustomerGroupPrices WHERE CGP_CustomerGroupID = " & NumSafe(DB_CG_ID) & ") cgp ON v.V_ID = cgp.CGP_VersionID" end if If SOFTWARE_IS_PRO Then 'Get hidden attributes SQL aryHiddenAttributes = GetHiddenAttributesArray() strAttributeSQL = BuildSearchAttributeSQL(aryAttributes, aryAttributeValues, strKeywords, strJoinSQL) strAttributeKeywordSQL = BuildHiddenSearchAttributeSQL(aryHiddenAttributes, strKeywords, strJoinSQL) End If 'Now build up the where clause. Start with the product & version strWhereSQL = "((" & strProductsClause & ") OR (" & strVersionsClause & ")" 'If we have attribute keywords, add that on If strAttributeKeywordSQL <> "" then strWhereSQL = strWhereSQL & " OR (vh.ATTRIBV_AttributeID IN (" & strAttributeKeywordSQL & ") AND vh.ATTRIBV_Value" & CStr(numLanguageID) & " LIKE ('%" & SQLSafe(strKeywords) & "%'))" 'Close the bracket round the keywords and add in the rest of the clauses strWhereSQL = strWhereSQL & ")" & strPriceClause & " AND CAT_Live = 'y' AND CAT_CustomerGroupID IN (0," & NumSafe(DB_CG_ID) & ") AND P_Live = 'y' AND V_Live = 'y' AND V_CustomerGroupID IN (0," & NumSafe(DB_CG_ID) & ") AND P_CustomerGroupID IN (0," & NumSafe(DB_CG_ID) & ") AND P_Name" & CStr(numLanguageID) & " <> '' AND (SUP_Live <> 'n' OR SUP_Live IS NULL) AND (" & strSectionClause & ")" & strAttributeSQL '----------------------------------------------- ' PERFORM THE QUERY ON PRODUCTS ' Pull out the minimium version price if reqd. ' See prodtype.asp for more info. '----------------------------------------------- strAppShowPriceOnProductDisplay = GetAppVar("showpriceonproductdisplay") 'If using access, append products table name for casting if strDatabaseType = "access" then strTblProd = "p." else strTblProd = "" strSelectValues = "P_ID, P_Type, P_Name" & CStr(numLanguageID) & ", " & strTblProd & castSQL("P_Desc" & CStr(numLanguageID)) & " as P_Desc" & CStr(numLanguageID) &", P_StrapLine" & CStr(numLanguageID) & ", P_OrderVersionsBy, P_VersionDisplayType, P_Featured" strSelectValues2 = Replace(strSelectValues, "as P_Desc" & CInt(numLanguageID),"") If strAppShowPriceOnProductDisplay = "y" then strQuery = LimitSQL(strSelectValues & ", MIN(V_Price) As MinPrice, MIN(T_TaxRate) As MinTaxRate FROM " & strJoinSQL & " WHERE " & strWhereSQL & " GROUP BY " & strSelectValues2 & " ORDER BY P_ID Desc", numAppSearchMaxRecs, true) Else strQuery = LimitSQL(strSelectValues & " FROM " & strJoinSQL & " WHERE " & strWhereSQL & " ORDER BY P_Name" & CStr(numLanguageID), numAppSearchMaxRecs, true) End If Call ExecuteRS(strQuery, objRecordSet) numRecordCount = objRecordSet.RecordCount '----------------------------------------------- 'MOVE TO CORRECT RECORD '----------------------------------------------- If numRecordCount > 0 then 'Jump to the first record objRecordSet.AbsolutePosition = numSearchStartRecord 'Create trail Set objTrail = New BreadCrumbTrail objTrail.PageHistory = "search" objTrail.SearchStartRecord = numSearchStartRecord Call objTrail.Build(objRecordSet2, "", "", "") 'Get the last record to show on this page - either the end of 'the page, or the end of the recordset numSearchLastRecord = numSearchStartRecord + numProdsPerPage - 1 If numSearchLastRecord > numRecordCount then numSearchLastRecord = numRecordCount 'Generate prev/next links (stores in strPageLinks) %> <% 'Only write out the heading if it wasn't done above on categories If not blnGotCategories then %>

<% WriteString("PageTitle_SearchResults") %>

<% WriteString("ContentText_NewSearch") %><% end if %>
<% =strPageLinks %>
<% 'Show number of results returned, search keywords %>
<% =GetString("ContentText_ViewingResults") & " " & numSearchStartRecord & " - " & numSearchLastRecord & " " & GetString("ContentText_Of") & " " & numRecordCount %><% If strKeywords <> "" then response.Write " " & GetString("ContentText_For") & " '" & WriteSafe(strKeywords) & "'" %>
<% 'Need to add support for special 'search' display type Call ShowProducts(objRecordSet, objRecordSet2, numProdsPerPage, strAppSearchDisplayType, "search", aryKeywords, numSearchStartRecord, objTrail) objRecordSet.Close %> <% else '----------------------------------------------- 'IF IT RETURNS NO RECORDS, SET ERROR TEXT AND 'SHOW SEARCH FORM AGAIN '----------------------------------------------- objRecordSet.close strSubText = GetString("ContentText_NoResults") If blnGotCategories then blnDoSearchForm = false %>

<%= strSubText %>

<% Else blnDoSearchForm = True End If end if else '----------------------------------------------- 'IF A SEARCH HASN'T YET BEEN PERFORMED, SET 'TITLE LINKS AND WRITE OUT SEARCH FORM AGAIN '----------------------------------------------- If blnKeywordsCleaned then 'Keywords were cleaned, so say nothing was found (lie) strSubText = GetString("ContentText_NoResults") else 'No keywords entered strSubText = GetString("ContentText_EnterKeywords") End if blnDoSearchForm = True end if If blnDoSearchForm then %>

<% WriteString("PageTitle_ProductSearch") %>

<% end if 'Finish things off response.write(aryPageTemplate(1)) Call EndPage() %>