<% Class O_catalogue Private oConn Private oBase Private intID Sub Class_Initialize() Set oBase = Base End Sub Function Connect(sConn,ID) Set oConn = sConn intID = ID End Function Function Sidebar sFile = oBase.LoadView("catalogue","sidebar",0) sFile = oBase.InsertValue(sFile,"HREF_CATEGORIES",URL("catalogue","all_categories",0)) sFile = oBase.InsertValue(sFile,"HREF_PRODUCTS",URL("catalogue","all_products",0)) sFile = oBase.InsertValue(sFile,"HREF_ORDERS",URL("catalogue","all_orders",0)) Response.Write(sFile) End Function Function All_Products(nID) sFile = oBase.LoadView("catalogue","all",1) aParts = DoSplit(sFile) sHeader = aParts(0) sFooter = aParts(2) sQ = oDB.ExecuteQuery(oConn,"SELECT DISTINCT catalogue_categories.id, catalogue_categories.title, catalogue_categories.sort_order FROM catalogue_categories, catalogue_products WHERE catalogue_products.categoryID = catalogue_categories.id ORDER BY catalogue_categories.sort_order ASC") If IsArray(sQ) Then For i = 0 to uBound(sQ,2) sRepeat = sRepeat & aParts(1) sRepeat = oBase.InsertValue(sRepeat,"ID",sQ(0,i)) sRepeat = oBase.InsertValue(sRepeat,"TITLE",sQ(1,i)) sQa = oDB.ExecuteQuery(oConn,"SELECT COUNT(id) AS ProductCount FROM catalogue_products WHERE categoryId = " & sQ(0,i)) If IsArray(sQa) Then iProductCount = sQa(0,0) Else iProductCount = 0 End If sRepeat = oBase.InsertValue(sRepeat,"COUNT",iProductCount) sRepeat = oBase.InsertValue(sRepeat,"PRODUCTS",GetProducts(sQ(0,i))) Next 'sFooter = oBase.InsertValue(sFooter,"PAGINATION",oBase.GetPageControls(strQ,intPageSize,intCount)) Else sFooter = oBase.InsertValue(sFooter,"NOTHING",True) 'sFooter = oBase.InsertValue(sFooter,"PAGINATION","") End If sFooter = oBase.InsertValue(sFooter,"HREF_ADD",URL("catalogue","add_product",0)) sFooter = oBase.InsertValue(sFooter,"NOTHING",False) sFooter = oBase.InsertValue(sFooter,"PAGINATION","") Response.Write(sHeader & sRepeat & sFooter) End Function Function GetProducts(nID) Dim sQ Dim i Dim sFile Dim aParts Dim sHeader Dim sFooter Dim sRepeat Dim intCount Dim strQ intPageSize = 1000 sFile = oBase.LoadView("catalogue","all-products-categories",1) aParts = DoSplit(sFile) sHeader = aParts(0) sFooter = aParts(2) strQ = "SELECT id, productName, productActive, files_id FROM catalogue_products WHERE categoryId = "&nID&" ORDER BY sort_order ASC" sQ = oDB.ExecutePgQuery(oConn,strQ,intPageSize) intCount = oDB.GetCount(oConn,strQ) sHeader = oBase.InsertValue(sHeader,"CATEGORY",nID) sHeader = oBase.InsertValue(sHeader,"HREF_STATUS",URL2("catalogue","change_product_status",0,"window=1")) sHeader = oBase.InsertValue(sHeader,"HREF_SORT",URL2("catalogue","sort_products",0,"window=1")) If IsArray(sQ) Then 'sFooter = oBase.InsertValue(sFooter,"NOTHING",False) For i = 0 to uBound(sQ,2) sRepeat = sRepeat & aParts(1) sRepeat = oBase.InsertValue(sRepeat,"ID",sQ(0,i)) sRepeat = oBase.InsertValue(sRepeat,"NAME",sQ(1,i)) If sQ(2,i) Then sRepeat = oBase.InsertValue(sRepeat,"ACTIVE",True) sRepeat = oBase.InsertValue(sRepeat,"INACTIVE",False) Else sRepeat = oBase.InsertValue(sRepeat,"INACTIVE",True) sRepeat = oBase.InsertValue(sRepeat,"ACTIVE",False) End If sRepeat = oBase.InsertValue(sRepeat,"HREF_EDIT",URL2("catalogue","edit_product",sQ(0,i),"temp=" & sQ(3,i))) sRepeat = oBase.InsertValue(sRepeat,"HREF_DELETE",URL("catalogue","delete_product",sQ(0,i))) Next End If GetProducts = sHeader & sRepeat & sFooter End Function Function Change_Product_Status(nID) Dim sReturn sReturn = "" blnStatus = oDB.GetValue(oConn,"productActive","catalogue_products","WHERE id = " & Request.QueryString("product")) If blnStatus Then oDB.ExecuteNonQuery oConn,"UPDATE catalogue_products SET productActive = False WHERE id = " & Request.QueryString("product") sReturn = C_SKIN & "/images/icons/cross.png" Else oDB.ExecuteNonQuery oConn,"UPDATE catalogue_products SET productActive = True WHERE id = " & Request.QueryString("product") sReturn = C_SKIN & "/images/icons/tick.png" End If Response.Write(sReturn) End Function Function Add_Product(nID) sFile = oBase.LoadView("catalogue","add-product",0) sFile = oBase.InsertValue(sFile,"FILES",Files.UploadForm(0)) 'sFile = oBase.InsertValue(sFile,"VARIATIONS",VariationsTable(0,0)) sFile = oBase.InsertValue(sFile,"HREF_VARIANTS",URL2("catalogue","get_variations",0,"window=1")) sFile = oBase.InsertValue(sFile,"FILES_ID",C_TEMP_FOLDER) sFile = oBase.InsertValue(sFile,"HREF_ACTION",URL("catalogue","save_product",0)) sFile = oBase.InsertValue(sFile,"HREF_CATEGORIES_LOOKUP",URL2("catalogue","category_lookup",0,"window=1")) Response.Write(sFile) End Function Function Get_Variations(nID) If Request.QueryString("product") <> "" Then Response.Write(VariationsTable(Request.QueryString("product"),Request.QueryString("category"))) Else Response.Write(VariationsTable(0,Request.QueryString("category"))) End If End Function Function Edit_Product(nID) sFile = oBase.LoadView("catalogue","edit-product",0) sQ = oDB.ExecuteQuery(oConn,"SELECT catalogue_products.id, catalogue_products.productName, catalogue_products.productManufacturer, catalogue_products.productModel, catalogue_products.productDescription, catalogue_products.productSpecifications, catalogue_products.categoryId, catalogue_categories.title, catalogue_products.files_id FROM catalogue_products INNER JOIN catalogue_categories ON catalogue_categories.id = catalogue_products.categoryId WHERE catalogue_products.id = " & nID) If IsArray(sQ) Then sFile = oBase.InsertValue(sFile,"HREF_VARIANTS",URL2("catalogue","get_variations",0,"window=1")) sFile = oBase.InsertValue(sFile,"ID",sQ(0,0)) sFile = oBase.InsertValue(sFile,"PRODUCT_NAME",sQ(1,0)) sFile = oBase.InsertValue(sFile,"PRODUCT_MANUFACTURER",sQ(2,0)) sFile = oBase.InsertValue(sFile,"PRODUCT_MODEL",sQ(3,0)) sFile = oBase.InsertValue(sFile,"PRODUCT_DESCRIPTION",sQ(4,0)) sFile = oBase.InsertValue(sFile,"PRODUCT_SPECIFICATIONS",sQ(5,0)) sFile = oBase.InsertValue(sFile,"PRODUCT_CATEGORY",sQ(6,0)) sFile = oBase.InsertValue(sFile,"CATEGORY_NAME",sQ(7,0)) End If sFile = oBase.InsertValue(sFile,"FILES",Files.UploadForm(0)) sFile = oBase.InsertValue(sFile,"VARIATIONS",VariationsTable(sQ(0,0),sQ(6,0))) sFile = oBase.InsertValue(sFile,"FILES_ID",sQ(8,i)) sFile = oBase.InsertValue(sFile,"HREF_ACTION",URL("catalogue","update_product",0)) sFile = oBase.InsertValue(sFile,"HREF_CATEGORIES_LOOKUP",URL2("catalogue","category_lookup",0,"window=1")) Response.Write(sFile) End Function Function Save_Product(nID) Dim intID Dim oItem intID = 0 Set oForm = Server.CreateObject("Scripting.Dictionary") For Each Item in Request.Form Select Case Item Case "variants" oForm.Add "productVariants", Request.Form("variants") Case "options" oForm.Add "variationOptions", Request.Form("options") Case "productActive" Case Else If InStr(Item,"var_") > 0 Then ElseIf InStr(Item,"option_") > 0 Then Else Response.Write(Item & "
") oForm.Add Item, Request.Form(Item) End If End Select Next If Request.Form("productActive") = "on" Then oForm.Add "productActive", 1 Else oForm.Add "productActive", 0 End If intID = oDB.ExecuteInsert(oConn,"catalogue_products",oForm) Set oForm = Nothing 'Set oVariant = JSON.parse(Request.Form("variants")) ' For Each Key in oVariant.variants.keys() ' For Each Item in oVariant.variants.get(Key).keys() ' Set oItem = oVariant.variants.get(Key).get(Item) ' oDB.ExecuteNonQuery oConn,"INSERT INTO catalogue_product_variations (productId, variationCode, variationSize, variationColour, variationPrice) VALUES ("&intID&",'"&oItem.code&"','"&oItem.size&"','"&oItem.colour&"',"&oItem.price&")" ' Set oItem = Nothing ' Next ' Next ' Set oVariant = Nothing If intID <> 0 Then Response.Redirect(URL2("catalogue","all_products",intID,"success-msg=Product successfully added")) Else Response.Redirect(URL2("catalogue","all_products",intID,"error-msg=An error occurred while adding the product")) End If End Function Function OldUpdate_Product(nID) For Each Item in Request.Form Response.Write("

" & Item & " - " & Request.Form(Item) & "

") Next End Function Function Update_Product(nID) Dim intID Dim oItem intID = Request.Form("id") Set oForm = Server.CreateObject("Scripting.Dictionary") For Each Item in Request.Form Select Case Item Case "variants" oForm.Add "productVariants", Request.Form("variants") Case "options" oForm.Add "variationOptions", Request.Form("options") Case Else If InStr(Item,"var_") > 0 Then ElseIf InStr(Item,"option_") > 0 Then Else Response.Write(Item & "
") oForm.Add Item, Request.Form(Item) End If End Select Next oDB.ExecuteUpdate oConn,"catalogue_products",oForm Set oForm = Nothing 'oDB.ExecuteNonQuery oConn,"DELETE FROM catalogue_product_variations WHERE productId = " & intID ' Set oVariant = JSON.parse(Request.Form("variants")) ' For Each Key in oVariant.variants.keys() ' For Each Item in oVariant.variants.get(Key).keys() ' Set oItem = oVariant.variants.get(Key).get(Item) ' oDB.ExecuteNonQuery oConn,"INSERT INTO catalogue_product_variations (productId, variationCode, variationSize, variationColour, variationPrice) VALUES ("&intID&",'"&oItem.code&"','"&oItem.size&"','"&oItem.colour&"',"&oItem.price&")" ' Set oItem = Nothing ' Next ' Next ' Set oVariant = Nothing If intID <> 0 Then Response.Redirect(URL2("catalogue","all_products",intID,"success-msg=Product successfully updated")) Else Response.Redirect(URL2("catalogue","all_products",intID,"error-msg=An error occurred while updating the product")) End If End Function Function Delete_Product(nID) Dim sFiles sFiles = oDB.GetValue(oConn,"files_id","catalogue_products","WHERE id = " & nID) 'Delete Product oDB.ExecuteNonQuery oConn,"DELETE FROM catalogue_products WHERE id = " & nID 'Delete Product Variations oDB.ExecuteNonQuery oConn,"DELETE FROM catalogue_product_variations WHERE productId = " & nID Set oFS = Server.CreateObject("Scripting.FileSystemObject") If oFS.FolderExists(C_ROOT_UPLOADS & "\" & sFiles) Then oFS.DeleteFolder(C_ROOT_UPLOADS & "\" & sFiles) End If Set oFS = Nothing Response.Redirect(URL2("catalogue","all_products",intID,"success-msg=Product successfully deleted")) End Function Function Delete_Variations(nID) oDB.ExecuteNonQuery oConn, "UPDATE catalogue_products SET productVariants = null WHERE id = " & nID End Function Function VariationsTable(intID, intCategory) Dim sQ Dim i sFile = oBase.LoadView("catalogue","variations",1) aParts = DoSplit(sFile) sHeader = aParts(0) sFooter = aParts(2) strColumnHeadings = GetVariantColumnHeadings(intCategory) If strColumnHeadings <> "0" Then sHeader = oBase.InsertValue(sHeader,"VARIANT_COLUMN_NAMES",strColumnHeadings) Else sHeader = oBase.InsertValue(sHeader,"VARIANT_COLUMN_NAMES","") End IF intVariantCount = GetVariantCount(intID) 'intVariantColumnCount = GetVariantColumnCount(intID) If intVariantCount > 0 Then For i = 0 to intVariantCount - 1 sRepeat = sRepeat & aParts(1) sRepeat = oBase.InsertValue(sRepeat,"ID",i) sRepeat = oBase.InsertValue(sRepeat,"VARIANT_COLS",GetVariantColumns(i,intID,intCategory)) sRepeat = oBase.InsertValue(sRepeat,"VARIANT_OPTION_COLS",GetVariantOptions(i,intID,intCategory)) Next sHeader = oBase.InsertValue(sHeader,"VARIANT_COUNT",intVariantCount - 1) sFooter = oBase.InsertValue(sFooter,"NOTHING",False) sFooter = oBase.InsertValue(sFooter,"BTN_NOTHING",True) sHeader = oBase.InsertValue(sHeader,"NOTHING",False) Else If strColumnHeadings <> "0" Then sRepeat = sRepeat & aParts(1) sRepeat = oBase.InsertValue(sRepeat,"ID",0) sHeader = oBase.InsertValue(sHeader,"VARIANT_COUNT",0) sRepeat = oBase.InsertValue(sRepeat,"VARIANT_COLS",GetVariantColumns(0,intID,intCategory)) sRepeat = oBase.InsertValue(sRepeat,"VARIANT_OPTION_COLS",GetVariantOptions(0,intID,intCategory)) sFooter = oBase.InsertValue(sFooter,"NOTHING",False) sFooter = oBase.InsertValue(sFooter,"BTN_NOTHING",True) sHeader = oBase.InsertValue(sHeader,"NOTHING",False) Else sHeader = oBase.InsertValue(sHeader,"VARIANT_COUNT",0) sFooter = oBase.InsertValue(sFooter,"NOTHING",True) sFooter = oBase.InsertValue(sFooter,"BTN_NOTHING",False) sHeader = oBase.InsertValue(sHeader,"NOTHING",True) End If End If VariationsTable = sHeader & sRepeat & sFooter End Function Function GetVariantCount(intID) strVariants = oDB.GetValue(oConn,"productVariants","catalogue_products","WHERE id = " & intID) Dim intCount intCount = 0 If strVariants <> "" Then Set oVariant = JSON.parse(strVariants) For Each Key in oVariant.variants.keys() For Each Item in oVariant.variants.get(Key).keys() Set oItem = oVariant.variants.get(Key).get(Item) intCount = intCount + 1 Set oItem = Nothing Next Next Set oVariant = Nothing Else intCount = 0 End If GetVariantCount = intCount End Function Function GetVariantColumns(intCounter,intProduct,intCategory) Dim sQ Dim i strLabel = "" strLabel = "Item_Code" sFile = oBase.LoadView("catalogue","variant-cols",1) aParts = DoSplit(sFile) sHeader = aParts(0) sFooter = aParts(2) sVariants = oDB.GetValue(oConn,"productVariants","catalogue_products","WHERE id = " & intProduct) intColCounter = 0 intCol = 0 If sVariants <> "" Then Set oVariant = JSON.parse(sVariants) Set oItem = oVariant.variants.get(0).get(intCounter) For Each Col in oItem.Keys() intCol = intCol + 1 sRepeat = sRepeat & aParts(1) strName = "var_" & Replace(LCase(Col)," ","_") & "_" & intCounter sRepeat = oBase.InsertValue(sRepeat,"ID",intCounter) sRepeat = oBase.InsertValue(sRepeat,"FIELD_NAME",strName) sRepeat = oBase.InsertValue(sRepeat,"FIELD_VALUE",Eval("oItem."&Col&"")) 'Response.Write(sColName & "
") 'sRepeat = oBase.InsertValue(sRepeat,"FIELD_VALUE",oVariant.variants.get(0)) Next Set oItem = Nothing intColCounter = intColCounter + 1 Set oVariant = Nothing Else sQ = oDB.ExecuteQuery(oConn,"SELECT id, col_heading FROM catalogue_category_variations WHERE category_id = " & intCategory) If IsArray(sQ) Then For i = 0 to uBound(sQ,2) strName = "var_" & Replace(LCase(sQ(1,i))," ","_") & "_0" sRepeat = sRepeat & aParts(1) sRepeat = oBase.InsertValue(sRepeat,"ID",i) sRepeat = oBase.InsertValue(sRepeat,"FIELD_NAME",strName) sRepeat = oBase.InsertValue(sRepeat,"FIELD_VALUE","") Next End If End If sFooter = oBase.InsertValue(sFooter,"ID",intCounter) GetVariantColumns = sHeader & sRepeat & sFooter End Function Function GetVariantOptions(intCounter,intProduct,intCategory) Dim sQ Dim i sFile = oBase.LoadView("catalogue","variant-options-cols",0) sFile = oBase.InsertValue(sFile,"COLSPAN",GetVariantHeadingCount(0,intID,intCategory) + 1) sFile = oBase.InsertValue(sFile,"ID",intCounter) sVariants = oDB.GetValue(oConn,"variationOptions","catalogue_products","WHERE id = " & intProduct) intColCounter = 0 intCol = 0 If sVariants <> "" Then Set oVariant = JSON.parse(sVariants) 'For Each Key in oVariant.options.keys() For Each Item in oVariant.options.get(0).keys() If Trim(Item) = Trim("var_options_"&intCounter) Then Set oItem = oVariant.options.get(0).get(Item) intCount = intCount + 1 sPrice = "oItem.price_" & intCounter sSpecialPrice = "oItem.special_price_" & intCounter bFeatured = Eval("oItem.var_options_"&intCounter&"_featured") bNew = Eval("oItem.var_options_"&intCounter&"_new") bOut = Eval("oItem.var_options_"&intCounter&"_outofstock") sFile = oBase.InsertValue(sFile,"PRICE",Eval(sPrice)) sFile = oBase.InsertValue(sFile,"SPECIAL_PRICE",Eval(sSpecialPrice)) sFile = oBase.InsertValue(sFile,"FEATURED",bFeatured) sFile = oBase.InsertValue(sFile,"NEW_ARRIVAL",bNew) sFile = oBase.InsertValue(sFile,"OUTOFSTOCK",bOut) Set oItem = Nothing End If Next 'Next Set oVariant = Nothing 'Response.Write(intCount & "
") 'aOptions = Split(sVariants,"|") ' If IsArray(aOptions) Then ' sFile = oBase.InsertValue(sFile,"PRICE",aOptions(0)) ' sFile = oBase.InsertValue(sFile,"SPECIAL_PRICE",aOptions(1)) ' sFile = oBase.InsertValue(sFile,"FEATURED",aOptions(2)) ' sFile = oBase.InsertValue(sFile,"NEW_ARRIVAL",aOptions(3)) ' sFile = oBase.InsertValue(sFile,"OUTOFSTOCK",aOptions(4)) ' End If Else sFile = oBase.InsertValue(sFile,"PRICE","") sFile = oBase.InsertValue(sFile,"SPECIAL_PRICE","") sFile = oBase.InsertValue(sFile,"FEATURED",False) sFile = oBase.InsertValue(sFile,"NEW_ARRIVAL",False) sFile = oBase.InsertValue(sFile,"OUTOFSTOCK",False) End If GetVariantOptions = sFile End Function Function GetVariantHeadingCount(intCounter,intProduct,intCategory) Dim sQ Dim i strLabel = "" strLabel = "Item_Code" sVariants = oDB.GetValue(oConn,"productVariants","catalogue_products","WHERE id = " & intProduct) intColCounter = 0 intCol = 0 If sVariants <> "" Then Set oVariant = JSON.parse(sVariants) Set oItem = oVariant.variants.get(0).get(intCounter) For Each Col in oItem.Keys() intColCounter = intColCounter + 1 intCol = intCol + 1 strName = "var_" & Replace(LCase(Col)," ","_") & "_" & intCounter Next Set oItem = Nothing intColCounter = intColCounter + 1 Set oVariant = Nothing Else sQ = oDB.ExecuteQuery(oConn,"SELECT id, col_heading FROM catalogue_category_variations WHERE category_id = " & intCategory) If IsArray(sQ) Then For i = 0 to uBound(sQ,2) intColCounter = intColCounter + 1 strName = "var_" & Replace(LCase(sQ(1,i))," ","_") & "_0" Next End If End If GetVariantHeadingCount = intColCounter End Function Function GetVariantColumnHeading(intID,intNum) Dim sQ Dim i sQ = oDB.ExecuteQuery(oConn,"SELECT id, col_heading FROM catalogue_category_variations WHERE category_id = " & intID) If IsArray(sQ) Then For i = 0 to intNum - 1 strReturn = sQ(1,i) Next Else strReturn = False End If GetVariantColumnHeading = strReturn End Function Function GetVariantColumnHeadings(intID) Dim sQ Dim i sFile = oBase.LoadView("catalogue","variant-col-names",1) aParts = DoSplit(sFile) sHeader = aParts(0) sFooter = aParts(2) sQ = oDB.ExecuteQuery(oConn,"SELECT id, col_heading FROM catalogue_category_variations WHERE category_id = " & intID) If IsArray(sQ) Then For i = 0 to uBound(sQ,2) sRepeat = sRepeat & aParts(1) sRepeat = oBase.InsertValue(sRepeat,"COL_HEADING",sQ(1,i)) Next If uBound(sQ,2) > -1 Then GetVariantColumnHeadings = sHeader & sRepeat & sFooter Else GetVariantColumnHeadings = "0" End If Else GetVariantColumnHeadings = "0" End If End Function Function Sort_Products(nID) aSort = Split(Request.QueryString("sort"),",") For i = 0 to uBound(aSort) intID = CInt(Replace(aSort(i),"row_","")) oDB.ExecuteNonQuery oConn,"UPDATE catalogue_products SET sort_order = " & i & " WHERE id = " & intID Next End Function 'START CATEGORIES Function All_Categories(nID) sFile = oBase.LoadView("catalogue","all-categories",1) aParts = DoSplit(sFile) sHeader = aParts(0) sFooter = aParts(2) sQ = oDB.ExecuteQuery(oConn,"SELECT id, title, sort_order, parent_id, files_id FROM catalogue_categories WHERE parent_id = 0 ORDER BY sort_order ASC") sHeader = oBase.InsertValue(sHeader,"HREF_SORT",URL("catalogue","sort_categories",0)) If IsArray(sQ) Then For i = 0 to uBound(sQ,2) sRepeat = sRepeat & aParts(1) sRepeat = oBase.InsertValue(sRepeat,"ID",sQ(0,i)) sRepeat = oBase.InsertValue(sRepeat,"CATEGORY_NAME",sQ(1,i)) sParentName = oDB.GetValue(oConn,"title","catalogue_categories","WHERE id = " & sQ(3,i)) If sParentName = "" Then sParentName = "None" End If sQa = oDB.ExecuteQuery(oConn,"SELECT COUNT(id) AS ProductCount FROM catalogue_products WHERE categoryID = " & sQ(0,i)) If IsArray(sQa) Then iProductCount = sQa(0,0) Else iProductCount = 0 End If sRepeat = oBase.InsertValue(sRepeat,"PARENT",sParentName) sRepeat = oBase.InsertValue(sRepeat,"PRODUCT_COUNT",iProductCount) sRepeat = oBase.InsertValue(sRepeat,"HREF_EDIT",URL2("catalogue","edit_category",sQ(0,i),"cnt=" & iProductCount)) 'Check for sub categories as well as products before enabling the delete button sQb = oDB.ExecuteQuery(oConn,"SELECT (SELECT COUNT(id) FROM catalogue_products WHERE categoryId = MainCategoryTable.id) AS MainProductCount, (SELECT COUNT(SubCategoryTable.id) AS ProductCount FROM catalogue_categories AS SubCategoryTable INNER JOIN catalogue_products ON catalogue_products.categoryId = SubCategoryTable.id WHERE SubCategoryTable.parent_id = MainCategoryTable.id) AS SubCategoryProductCount, (SELECT COUNT(id) FROM catalogue_categories WHERE parent_id = MainCategoryTable.id) AS SubCategoryCount FROM catalogue_categories AS MainCategoryTable WHERE MainCategoryTable.id = " & sQ(0,i)) If IsArray(sQb) Then If sQb(0,0) > 0 OR sQb(1,0) > 0 OR sQb(2,0) > 0 Then sRepeat = oBase.InsertValue(sRepeat,"HREF_DELETE","#") strMessage = "" If sQb(2,0) > 0 Then strMessage = "Category cannot be deleted. First delete all sub categories." Else If sQb(0,0) > 0 AND sQb(1,0) = 0 Then strMessage = "Category cannot be deleted. Please delete all products from this category." ElseIf sQb(1,0) > 0 Then strMessage = "Category cannot be deleted. Please delete all products from all sub categories." End If End If sRepeat = oBase.InsertValue(sRepeat,"ONCLICK","alert('"&strMessage&"')") sRepeat = oBase.InsertValue(sRepeat,"TITLE",strMessage) sRepeat = oBase.InsertValue(sRepeat,"STYLE","color: #CCC") Else sRepeat = oBase.InsertValue(sRepeat,"STYLE","") sRepeat = oBase.InsertValue(sRepeat,"TITLE","Click to delete this category") sRepeat = oBase.InsertValue(sRepeat,"HREF_DELETE",URL("catalogue","delete_category",sQ(0,i))) sRepeat = oBase.InsertValue(sRepeat,"ONCLICK","return confirm('Are you sure you want to delete this category?')") End If End If sRepeat = oBase.InsertValue(sRepeat,"SUB_CATEGORIES",GetAllSubCategories(sQ(0,i))) Next sFooter = oBase.InsertValue(sFooter,"NOTHING",False) Else sFooter = oBase.InsertValue(sFooter,"NOTHING",True) End If sFooter = oBase.InsertValue(sFooter,"HREF_ADD",URL("catalogue","add_category",0)) Response.Write(sHeader & sRepeat & sFooter) End Function Function GetAllSubCategories(intID) Dim i Dim sQ Dim sQa sFile = oBase.LoadView("catalogue","sub-categories",1) aParts = DoSplit(sFile) sQ = oDB.ExecuteQuery(oConn,"SELECT id, title, sort_order, parent_id, files_id FROM catalogue_categories WHERE parent_id = "&intID&" ORDER BY sort_order ASC") If IsArray(sQ) Then For i = 0 to uBound(sQ,2) sRepeat = sRepeat & aParts(1) sRepeat = oBase.InsertValue(sRepeat,"ID",sQ(0,i)) sRepeat = oBase.InsertValue(sRepeat,"CATEGORY_NAME",sQ(1,i)) sParentName = oDB.GetValue(oConn,"title","catalogue_categories","WHERE id = " & sQ(3,i)) If sParentName = "" Then sParentName = "None" End If sQa = oDB.ExecuteQuery(oConn,"SELECT COUNT(id) AS ProductCount FROM catalogue_products WHERE categoryID = " & sQ(0,i)) If IsArray(sQa) Then iProductCount = sQa(0,0) Else iProductCount = 0 End If sRepeat = oBase.InsertValue(sRepeat,"PARENT",sParentName) sRepeat = oBase.InsertValue(sRepeat,"PRODUCT_COUNT",iProductCount) sRepeat = oBase.InsertValue(sRepeat,"HREF_EDIT",URL2("catalogue","edit_category",sQ(0,i),"cnt=" & iProductCount)) 'Check for sub categories as well as products before enabling the delete button sQb = oDB.ExecuteQuery(oConn,"SELECT (SELECT COUNT(id) FROM catalogue_products WHERE categoryId = MainCategoryTable.id) AS MainProductCount, (SELECT COUNT(SubCategoryTable.id) AS ProductCount FROM catalogue_categories AS SubCategoryTable INNER JOIN catalogue_products ON catalogue_products.categoryId = SubCategoryTable.id WHERE SubCategoryTable.parent_id = MainCategoryTable.id) AS SubCategoryProductCount, (SELECT COUNT(id) FROM catalogue_categories WHERE parent_id = MainCategoryTable.id) AS SubCategoryCount FROM catalogue_categories AS MainCategoryTable WHERE MainCategoryTable.id = " & sQ(0,i)) If IsArray(sQb) Then If sQb(0,0) > 0 OR sQb(1,0) > 0 OR sQb(2,0) > 0 Then sRepeat = oBase.InsertValue(sRepeat,"HREF_DELETE","#") strMessage = "" If sQb(2,0) > 0 Then strMessage = "Category cannot be deleted. First delete all sub categories." Else If sQb(0,0) > 0 AND sQb(1,0) = 0 Then strMessage = "Category cannot be deleted. Please delete all products from this category." ElseIf sQb(1,0) > 0 Then strMessage = "Category cannot be deleted. Please delete all products from all sub categories." End If End If sRepeat = oBase.InsertValue(sRepeat,"ONCLICK","alert('"&strMessage&"')") sRepeat = oBase.InsertValue(sRepeat,"TITLE",strMessage) sRepeat = oBase.InsertValue(sRepeat,"STYLE","color: #CCC") Else sRepeat = oBase.InsertValue(sRepeat,"STYLE","") sRepeat = oBase.InsertValue(sRepeat,"TITLE","Click to delete this category") sRepeat = oBase.InsertValue(sRepeat,"HREF_DELETE",URL("catalogue","delete_category",sQ(0,i))) sRepeat = oBase.InsertValue(sRepeat,"ONCLICK","return confirm('Are you sure you want to delete this category?')") End If End If sRepeat = oBase.InsertValue(sRepeat,"SUB_CATEGORIES",GetAllSubCategories(sQ(0,i))) Next End If GetAllSubCategories = sHeader & sRepeat & sFooter End Function Function Sort_Categories(nID) aSort = Split(Request.QueryString("sort"),",") For i = 0 to uBound(aSort) intID = CInt(Replace(aSort(i),"row_","")) oDB.ExecuteNonQuery oConn,"UPDATE catalogue_categories SET sort_order = " & i & " WHERE id = " & intID Next End Function Function CategoriesList(intID,intCat) sFile = oBase.LoadView("catalogue","categories-list",1) aParts = DoSplit(sFile) sHeader = aParts(0) sFooter = aParts(2) 'sQ = oDB.ExecuteQuery(oConn,"SELECT id, End Function Function Category_Lookup(nID) Dim arrReturn() Dim sReturn sReturn = "{""catalogue"":[" sQ = oDB.ExecuteQuery(oConn,"SELECT id, title FROM catalogue_setup ORDER BY id ASC") If IsArray(sQ) Then Redim arrReturn(uBound(sQ,2)) For i = 0 to uBound(sQ,2) sReturn = sReturn & "{""id"": "&sQ(0,i)&",""name"":""" & sQ(1,i) & """,""categories"":[" sQa = oDB.ExecuteQuery(oConn,"SELECT id, title FROM catalogue_categories WHERE catalogue_id = " & sQ(0,i) & " AND parent_id = 0 ORDER BY sort_order ASC") If IsArray(sQa) Then For j = 0 to uBound(sQa,2) If HasChildCategory(sQa(0,j)) = False Then sReturn = sReturn & "{" sReturn = sReturn & """id"": " & sQa(0,j) & ",""name"":"""&sQa(1,j)&""", ""children"":["&SubCategory_Lookup(sQa(0,j))&"]" sReturn = sReturn & "}," Else sReturn = sReturn & "{" sReturn = sReturn & """id"": " & sQa(0,j) & ",""name"":"""&sQa(1,j)&""",""disabled"":true,""children"":["&SubCategory_Lookup(sQa(0,j))&"]" sReturn = sReturn & "}," End If Next sReturn = Left(sReturn,Len(sReturn) - 1) End If sReturn = sReturn & "]}," sReturn = Left(sReturn,Len(sReturn) - 1) Next End If sReturn = sReturn & "]}" Response.Write(sReturn) End Function Function SubCategory_Lookup(intID) Dim sReturn Dim sQ sReturn = "" sQ = oDB.ExecuteQuery(oConn,"SELECT id, title FROM catalogue_categories WHERE parent_id = " & intID & " ORDER BY sort_order ASC") If IsArray(sQ) Then For i = 0 to uBound(sQ,2) If HasChildCategory(sQ(0,i)) = False Then sReturn = sReturn & "{" sReturn = sReturn & """id"":"&sQ(0,i)&", ""name"": """&sQ(1,i)&""",""children"": ["&SubCategory_Lookup(sQ(0,i))&"]" sReturn = sReturn & "}," Else sReturn = sReturn & "{" sReturn = sReturn & """id"":"&sQ(0,i)&", ""name"": """&sQ(1,i)&""",""disabled"" : true, children"": ["&SubCategory_Lookup(sQ(0,i))&"]" sReturn = sReturn & "}," End If Next sReturn = Left(sReturn,Len(sReturn) - 1) End If SubCategory_Lookup = sReturn End Function Function Add_Category(nID) sFile = oBase.LoadView("catalogue","add_category",1) aParts = DoSplit(sFile) sHeader = aParts(0) sFooter = aParts(2) sContent = aParts(1) 'sContent = oBase.InsertValue(sContent,"PARENT_LIST",ParentList(0)) sContent = oBase.InsertValue(sContent,"MEDIA",Files.UploadForm(null)) sContent = oBase.InsertValue(sContent,"CATALOGUE_SETUP",CatalogueVersion(0)) sQ = oDB.ExecuteQuery(oConn,"SELECT id FROM catalogue_setup") If IsArray(sQ) Then If uBound(sQ,2) = 0 Then sContent = oBase.InsertValue(sContent,"SINGLE_CATALOGUE",True) sHeader = oBase.InsertValue(sHeader,"SINGLE_CATALOGUE_JS",True) sContent = oBase.InsertValue(sContent,"MULTIPLE_CATALOGUE",False) sHeader = oBase.InsertValue(sHeader,"CATALOGUE_ID",sQ(0,0)) sContent = oBase.InsertValue(sContent,"CATALOGUE_ID",sQ(0,0)) Else sHeader = oBase.InsertValue(sHeader,"SINGLE_CATALOGUE_JS",False) sContent = oBase.InsertValue(sContent,"SINGLE_CATALOGUE",False) sContent = oBase.InsertValue(sContent,"MULTIPLE_CATALOGUE",True) End If End If sHeader = oBase.InsertValue(sHeader,"HREF_PARENT_LIST",URL2("catalogue","AddCategory_ParentList",0,"window=1")) Response.Write(sHeader & sContent & sFooter) End Function Function AddCategory_ParentList(intSelected) sFile = oBase.LoadView("catalogue","category-list",1) aParts = DoSplit(sFile) sHeader = aParts(0) sFooter = aParts(2) sQ = oDB.ExecuteQuery(oConn,"SELECT id, title, sort_order FROM catalogue_categories WHERE catalogue_id = " & Request.QueryString("catalogue") & " AND parent_id = 0") sRepeat = sRepeat & aParts(1) sRepeat = oBase.InsertValue(sRepeat,"ID","0") sRepeat = oBase.InsertValue(sRepeat,"TITLE","None") sRepeat = oBase.InsertValue(sRepeat,"CHILDREN","") sRepeat = oBase.InsertValue(sRepeat,"SELECTED",False) If IsArray(sQ) Then For i = 0 to uBound(sQ,2) iIndentLevel = 0 sRepeat = sRepeat & aParts(1) sRepeat = oBase.InsertValue(sRepeat,"ID",sQ(0,i)) sRepeat = oBase.InsertValue(sRepeat,"TITLE",sQ(1,i)) sRepeat = oBase.InsertValue(sRepeat,"CHILDREN",ParentListChildren(sQ(0,i),intSelected,0)) If Trim(intSelected) = Trim(sQ(0,i)) Then sRepeat = oBase.InsertValue(sRepeat,"SELECTED",True) Else sRepeat = oBase.InsertValue(sRepeat,"SELECTED",False) End If sRepeat = sRepeat & aParts(1) sRepeat = oBase.InsertValue(sRepeat,"ID","") sRepeat = oBase.InsertValue(sRepeat,"TITLE","----------------------------") sRepeat = oBase.InsertValue(sRepeat,"CHILDREN","") sRepeat = oBase.InsertValue(sRepeat,"SELECTED",False) Next End If Response.Write(sHeader & sRepeat & sFooter) End Function Function ParentListChildren(intCatID, intSelected, intIndent) Dim i Dim sQ Dim j sFile = oBase.LoadView("catalogue","category-list-children",1) aParts = DoSplit(sFile) sHeader = aParts(0) sFooter = aParts(2) sQ = oDB.ExecuteQuery(oConn,"SELECT id, title, sort_order FROM catalogue_categories WHERE parent_id = " & intCatID) If IsArray(sQ) Then 'intIndent = intIndent + 1 For i = 0 to uBound(sQ,2) sRepeat = sRepeat & aParts(1) If Trim(sQ(0,i)) = Trim(intSelected) Then sRepeat = oBase.InsertValue(sRepeat,"SELECTED",True) Else sRepeat = oBase.InsertValue(sRepeat,"SELECTED",False) End If sRepeat = oBase.InsertValue(sRepeat,"ID",sQ(0,i)) sRepeat = oBase.InsertValue(sRepeat,"TITLE",sQ(1,i)) If Trim(intSelected) = Trim(sQ(0,i)) Then sRepeat = oBase.InsertValue(sRepeat,"SELECTED",True) Else sRepeat = oBase.InsertValue(sRepeat,"SELECTED",False) End If sRepeat = oBase.InsertValue(sRepeat,"CHILDREN",ParentListChildren(sQ(0,i),intSelected,intIndent+1)) sLevelIndent = "" For j = 0 to intIndent sLevelIndent = sLevelIndent & " - " Next sRepeat = oBase.InsertValue(sRepeat,"LEVEL",sLevelIndent) Next ParentListChildren = sHeader & sRepeat & sFooter Else ParentListChildren = "" End If End Function Function CatalogueVersion(iID) Dim sQ Dim i sReturn = "" sQ = oDB.ExecuteQuery(oConn,"SELECT id,title,cat_level FROM catalogue_setup") If IsArray(sQ) Then For i = 0 to uBound(sQ,2) If iID = sQ(0,i) Then sReturn = sReturn & "" Else sReturn = sReturn & "" End If Next End If CatalogueVersion = sReturn End Function Function ParentList(nID) iID = Request.QueryString("id") iCat = Request.QueryString("catalogue") If iCat <> "" Then iLevel = oDB.GetValue(oConn,"cat_level","catalogue_setup","WHERE id = " & iCat) If iLevel > 0 Then sReturn = "" sFile = oBase.LoadView("catalogue","category-list",1) aParts = DoSplit(sFile) sHeader = aParts(0) sFooter = aParts(2) sQ = oDB.ExecuteQuery(oConn,"SELECT id, title FROM catalogue_categories WHERE parent_id = 0 AND catalogue_id = "&iCat&" ORDER by sort_order ASC") If Trim(iID) = "0" Then sHeader = oBase.InsertValue(sHeader,"SELECTED",True) Else sHeader = oBase.InsertValue(sHeader,"SELECTED",False) End If If IsArray(sQ) Then For i = 0 to uBound(sQ,2) sRepeat = sRepeat & aParts(1) sRepeat = oBase.InsertValue(sRepeat,"ID",sQ(0,i)) sRepeat = oBase.InsertValue(sRepeat,"TITLE",sQ(1,i)) sRepeat = oBase.InsertValue(sRepeat,"CHILDREN",SubParentList(sQ(0,i))) If Trim(iID) = Trim(sQ(0,i)) Then sRepeat = oBase.InsertValue(sRepeat,"SELECTED",True) Else sRepeat = oBase.InsertValue(sRepeat,"SELECTED",False) End If Next End If Response.Write(sHeader & sRepeat & sFooter) End If End If End Function Function SubParentList(iID) sReturn = "" sQ = oDB.ExecuteQuery(oConn,"SELECT id, title FROM catalogue_categories WHERE parent_id = "&iID&" ORDER by sort_order ASC") If IsArray(sq) Then For i = 0 to uBound(sQ,2) If iID = sQ(0,i) Then sReturn = sReturn & "" Else sReturn = sReturn & "" End If Next End If SubParentList = sReturn End Function Function Category_Save(nID) dim aFields Set aFields = Server.CreateObject("Scripting.Dictionary") For Each Item in Request.Form If Item = "sort_order" Then If Request.Form("sort_order") <> "" Then aFields(Item) = Request.Form(Item) Else aFields(Item) = 0 End If Else aFields(Item) = Request.Form(Item) End If Next If HasProducts(Request.Form("parent_id")) Then Response.Redirect("?controller=catalogue&view=add_category&error-msg=There are products associated with the selected parent category. Remove these products before adding sub categories.") Else iDBID = oDB.ExecuteInsert(oConn,"catalogue_categories",aFields) Set aFields = Nothing If iDBID > 0 Then Response.Redirect("?controller=catalogue&view=all_categories&success-msg=Category successfully added") Else Response.Write("

An error has occurred while saving the category.

") End If End If End Function Function HasProducts(intCategory) Dim sReturn Dim sQ isReturn = False sQ = oDB.ExecuteQuery(oConn,"SELECT id FROM catalogue_products WHERE categoryId = " & intCategory) If IsArray(sQ) Then isReturn = True End If HasProducts = isReturn End Function Function Category_Update(nID) Set oHeadings = Server.CreateObject("Scripting.Dictionary") dim aFields Dim intVarCounter intVarCounter = 0 Set aFields = Server.CreateObject("Scripting.Dictionary") For Each Item in Request.Form Select Case Item Case "sort_order" If Request.Form("sort_order") <> "" Then aFields(Item) = Request.Form(Item) Else aFields(Item) = 0 End If Case "variants" Case Else If InStr(Item,"var_") > 0 Then Else 'Response.Write(Item & "
") aFields.Add Item, Request.Form(Item) End If End Select Next iDBID = oDB.ExecuteUpdate(oConn,"catalogue_categories",aFields) Set aFields = Nothing oDB.ExecuteNonQuery oConn,"DELETE FROM catalogue_category_variations WHERE category_id = " & Request.Form("id") Set oVariant = JSON.parse(Request.Form("variants")) For Each Key in oVariant.variants.keys() For Each Item in oVariant.variants.get(Key).keys() 'Response.Write(Item & "
") Set oItem = oVariant.variants.get(Key).get(Item) oHeadings.add LCase(Replace(oItem.heading," ","_")), 1 oDB.ExecuteNonQuery oConn,"INSERT INTO catalogue_category_variations (category_id, col_heading) VALUES ("&Request.Form("id")&",'"&oItem.heading&"')" Set oItem = Nothing intVarCounter = intVarCounter + 1 Next Next Set oVariant = Nothing sQ = oDB.ExecuteQuery(oConn,"SELECT id, productVariants FROM catalogue_products WHERE categoryId = " & Request.Form("id")) If IsArray(sQ) Then For i = 0 to uBound(sQ,2) sParse = "" sVariations = sQ(1,i) If sVariations <> "" Then Set oVars = JSON.parse(sVariations) sParse = sParse & "{""variants"":[{" For Each Item in oVars.variants.keys() For Each oVar in oVars.variants.get(Item).keys() sParse = sParse & """" & oVar & """ : {" Set oCurrent = Server.CreateObject("Scripting.Dictionary") Set oItem = oVars.variants.get(Item).get(oVar) For Each oVal in oItem.keys() oVal = LCase(Replace(oVal," ","_")) If Not oCurrent.Exists(oVal) Then thisValue = Eval("oItem." & oVal) oCurrent.Add oVal, thisValue End If Next For Each oDic in oHeadings If oCurrent.Exists(oDic) Then sParse = sParse & """" & oDic & """ : """ & oCurrent(oDic) & """," Else sParse = sParse & """" & oDic & """ : """"," End If Next sParse = Left(sParse,Len(sParse)-1) Set oItem = Nothing Set oCurrent = Nothing sParse = sParse & "}," Next sParse = Left(sParse,Len(sParse)-1) Next sParse = sParse & "}]}" Set oVars = Nothing End If oDB.ExecuteNonQuery oConn,"UPDATE catalogue_products SET productVariants = '"&sParse&"' WHERE id = " & sQ(0,i) Next End If If iDBID = true Then Response.Redirect("?controller=catalogue&view=all_categories&success-msg=Category successfully updated") Else Response.Write("

An error has occurred while saving the category.

") End If Set oHeadings = Nothing End Function Function Edit_Category(nID) sFile = oBase.LoadView("catalogue","edit_category",1) aParts = DoSplit(sFile) sHeader = aParts(0) sFooter = aParts(2) sQ = oDB.ExecuteQuery(oConn,"SELECT id,title,parent_id,description,sort_order,catalogue_id FROM catalogue_categories WHERE id = " & nID) If IsArray(sQ) Then For i = 0 to uBound(sQ,2) sRepeat = sRepeat & aParts(1) sRepeat = oBase.InsertValue(sRepeat,"TITLE",sQ(1,i)) sRepeat = oBase.InsertValue(sRepeat,"DESCRIPTION",sQ(3,i)) sRepeat = oBase.InsertValue(sRepeat,"MEDIA",Files.UploadForm(null)) sRepeat = oBase.InsertValue(sRepeat,"SORT_ORDER",sQ(4,i)) sRepeat = oBase.InsertValue(sRepeat,"PARENT_LIST",ParentList(sQ(2,i))) sRepeat = oBase.InsertValue(sRepeat,"ID",sQ(0,i)) sRepeat = oBase.InsertValue(sRepeat,"CATALOGUE_SETUP",CatalogueVersion(sQ(5,i))) sRepeat = oBase.InsertValue(sRepeat,"HREF_PARENT_LIST",URL2("catalogue","AddCategory_ParentList",sQ(2,i),"window=1")) sRepeat = oBase.InsertValue(sRepeat,"VARIATIONS",GetCategoryVariations(sQ(0,i))) If Request.QueryString("cnt") > 0 Then sRepeat = oBase.InsertValue(sRepeat,"COUNT",True) 'False hides the section between the IFNULL:COUNT statement tags. 'sRepeat = oBase.InsertValue(sRepeat,"ERROR_MESSAGE","Oops! No headings because this category contains products so you cannot make any changes to the headings - to change the headings you will have to first delete the products!") 'Display error message in ERROR_MESSAGE tag sRepeat = oBase.InsertValue(sRepeat,"ERROR_MESSAGE","") 'Displays the ERROR_MESSAGE tag Else sRepeat = oBase.InsertValue(sRepeat,"COUNT",True) 'Show variations sRepeat = oBase.InsertValue(sRepeat,"ERROR_MESSAGE","") 'Clears the ERROR_MESSAGE tag End If sQ = oDB.ExecuteQuery(oConn,"SELECT id FROM catalogue_setup") If IsArray(sQ) Then If uBound(sQ,2) = 0 Then sRepeat = oBase.InsertValue(sRepeat,"SINGLE_CATALOGUE",True) sRepeat = oBase.InsertValue(sRepeat,"MULTIPLE_CATALOGUE",False) sRepeat = oBase.InsertValue(sRepeat,"CATALOGUE_ID",sQ(0,0)) Else sRepeat = oBase.InsertValue(sRepeat,"SINGLE_CATALOGUE",False) sRepeat = oBase.InsertValue(sRepeat,"MULTIPLE_CATALOGUE",True) End If End If Next Else sRepeat = "

The item you are looking for does not exist.

" End If Response.Write(sHeader & sRepeat & sFooter) End Function Function GetCategoryVariations(intID) Dim sQ Dim i sFile = oBase.LoadView("catalogue","category-variations",1) aParts = DoSplit(sFile) sHeader = aParts(0) sFooter = aParts(2) sQ = oDB.ExecuteQuery(oConn,"SELECT id, category_id, col_heading, sort_order FROM catalogue_category_variations WHERE category_id = " & intID) If IsArray(sQ) Then sHeader = oBase.InsertValue(sHeader,"VARIANT_COUNT",uBound(sQ,2)) For i = 0 to uBound(sQ,2) sRepeat = sRepeat & aParts(1) sRepeat = oBase.InsertValue(sRepeat,"ID",i) sRepeat = oBase.InsertValue(sRepeat,"HEADING",sQ(2,i)) Next Else sHeader = oBase.InsertValue(sHeader,"VARIANT_COUNT",0) sRepeat = sRepeat & aParts(1) sRepeat = oBase.InsertValue(sRepeat,"ID",0) sRepeat = oBase.InsertValue(sRepeat,"HEADING","Code") End If GetCategoryVariations = sHeader & sRepeat & sFooter End Function Function Delete_Category(nID) sQ = oDB.ExecuteQuery(oConn,"SELECT (SELECT COUNT(id) FROM catalogue_products WHERE categoryId = MainCategoryTable.id) AS MainProductCount, (SELECT COUNT(SubCategoryTable.id) AS ProductCount FROM catalogue_categories AS SubCategoryTable INNER JOIN catalogue_products ON catalogue_products.categoryId = SubCategoryTable.id WHERE SubCategoryTable.parent_id = MainCategoryTable.id) AS SubCategoryProductCount, (SELECT COUNT(id) FROM catalogue_categories WHERE parent_id = MainCategoryTable.id) AS SubCategoryCount FROM catalogue_categories AS MainCategoryTable WHERE MainCategoryTable.id = " & nID) If IsArray(sQ) Then If sQ(2,0) > 0 Then Response.Redirect("?controller=catalogue&view=all_categories&error-msg=Category cannot be deleted. First delete all sub categories.") Else If sQ(0,0) > 0 AND sQ(1,0) = 0 Then Response.Redirect("?controller=catalogue&view=all_categories&error-msg=Category cannot be deleted. Please delete all products from this category.") ElseIf sQ(1,0) > 0 Then Response.Redirect("?controller=catalogue&view=all_categories&error-msg=Category cannot be deleted. Please delete all products from all sub categories.") Else oDB.DeleteRecord oConn,"SELECT id FROM catalogue_categories WHERE id = " & nID oDB.DeleteRecord oConn,"SELECT id FROM catalogue_categories WHERE parent_id = " & nID Response.Redirect("?controller=catalogue&view=all_categories&success-msg=Category has been deleted.") End If End If End If End Function Function CategoryList(iID) sReturn = "" sReturn = "" sQa = oDB.ExecuteQuery(oConn,"SELECT id, title FROM catalogue_setup ORDER BY title ASC") If IsArray(sQa) Then For j = 0 to uBound(sQa,2) sReturn = sReturn & "" sQ = oDB.ExecuteQuery(oConn,"SELECT id, title FROM catalogue_categories WHERE parent_id = 0 AND catalogue_id = "&sQa(0,j)&" ORDER BY title ASC") If IsArray(sQ) Then For i = 0 to uBound(sQ,2) If HasChildCategory(sQ(0,i)) Then sReturn = sReturn & "" sReturn = sReturn & GetChildrenCategories(sQ(0,i),iID) sReturn = sReturn & "" Else If sQ(0,i) = iID Then sReturn = sReturn & "" Else sReturn = sReturn & "" End If End If Next End If sReturn = sReturn & "" Next End If CategoryList = sReturn End Function Function HasChildCategory(iID) sQ = oDB.ExecuteQuery(oConn,"SELECT id FROM catalogue_categories WHERE parent_id = " & iID) If IsArray(sQ) Then HasChildCategory = True Else HasChildCategory = False End If End Function Function GetChildrenCategories(iID,iSelected) sReturn = "" sQ = oDB.ExecuteQuery(oConn,"SELECT id, title FROM catalogue_categories WHERE parent_id = " & iID) If IsArray(sQ) Then For i = 0 to uBound(sQ,2) If HasChildCategory(sQ(0,i)) Then sReturn = sReturn & "" sReturn = sReturn & GetChildrenCategories(sQ(0,i),iID) sReturn = sReturn & "" Else If iSelected = sQ(0,i) Then sReturn = sReturn & "" Else sReturn = sReturn & "" End If End If Next End If GetChildrenCategories = sReturn End Function 'END CATEGORIES End Class %>