%@ 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 %>
<%= 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 %><%= strSubText %>