%
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 "productActive"
Case Else
If InStr(Item,"var_") > 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 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 Else
If InStr(Item,"var_") > 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)
sHeader = oBase.InsertValue(sHeader,"VARIANT_COLUMN_NAMES",GetVariantColumnHeadings(intCategory))
intVariantCount = GetVariantCount(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))
Next
Else
sRepeat = sRepeat & aParts(1)
sRepeat = oBase.InsertValue(sRepeat,"ID",0)
sRepeat = oBase.InsertValue(sRepeat,"VARIANT_COLS",GetVariantColumns(0,intID,intCategory))
End If
sHeader = oBase.InsertValue(sHeader,"VARIANT_COUNT",intVariantCount - 1)
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 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
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
End If
GetVariantColumnHeadings = sHeader & sRepeat & sFooter
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),"temp=" & sQ(4,i)))
sRepeat = oBase.InsertValue(sRepeat,"HREF_EDIT",URL2("catalogue","edit_category",sQ(0,i),"cnt=" & iProductCount))
sRepeat = oBase.InsertValue(sRepeat,"HREF_DELETE",URL("catalogue","delete_category",sQ(0,i)))
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))
sRepeat = oBase.InsertValue(sRepeat,"HREF_DELETE",URL("catalogue","delete_category",sQ(0,i)))
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)
sReturn = sReturn & "{"
sReturn = sReturn & """id"": " & sQa(0,j) & ",""name"":"""&sQa(1,j)&""", ""children"":["&SubCategory_Lookup(sQa(0,j))&"]"
sReturn = sReturn & "},"
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)
sReturn = sReturn & "{"
sReturn = sReturn & """id"":"&sQ(0,i)&", ""name"": """&sQ(1,i)&""",""children"": ["&SubCategory_Lookup(sQ(0,i))&"]"
sReturn = sReturn & "},"
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
'Response.Write("
" & Item & " - " & Request.Form(Item) & "
") 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 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 Function Function Category_Update(nID) dim aFields 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 & "An error has occurred while saving the category.
") End If 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",False) '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 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","") End If GetCategoryVariations = sHeader & sRepeat & sFooter End Function Function Delete_Category(nID) sQ = oDB.DeleteRecord(oConn,"SELECT id FROM catalogue_categories WHERE id = " & nID) sQ = 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 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 & "" 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 & "