%Option Explicit%>
<%
ShopCheckAdmin "shopa_editdisplay.asp"
'*************************************************************
' Version 5.0
' add a category to the database
' Apr 21, 2003
' Nov 19, 2003 Fix responseredirect
'***************************************************************
'Modified - Added the catlanguage field for the category display pages.
' add category template
Dim CategoryCount
Dim Categories
Dim CategoryNums
Dim dbtable
Dim strcatdescription, strcatimage
Dim lnghighercategoryid,strcathassubcategory,strcatextra
Dim strcathide,strcatproductmatch,strcatcustomermatch
dim strcattemplate
dim strcatmemo
dim helpfile
helpfile="shopa_categoryhelp.htm"
'Language Modification
dim strcatlanguage
Dim YesNos(3), YesNoCount
Yesnos(0)=replace(getlang("langcommonYes")," ","")
Yesnos(1)=replace(getlang("langCommonNo")," ","")
Dim Novalue, yesvalue
Yesvalue=yesnos(0)
novalue=yesnos(1)
Yesnocount=2
'
Dim Actiontype
Dim Which, infomsg
Dim Addaction, updateaction, deleteaction
dbtable="categories"
Dim myconn
sError=""
ShopOpenDatabase myconn
Addaction=Request.form("add")
Updateaction=Request.form("update")
Deleteaction=request("delete")
If DeleteAction<>"" then
DeleteCategory
end if
which=request("which")
GetCategories
AdminPageHeader
FormatEditHelpHeader
If addaction="" and updateaction="" Then
If which<>"" then
SetSess "categoryid", which
GetExistingProduct
end if
DisplayForm
else
ProcessUserAction
end if
ShopCloseDatabase myconn
AdminPageTrailer
SUB ProcessUserAction
GetFormData ' get fields from form
ValidateData ' make sure we have them all
if sError = "" Then
UpdateProduct
Serror=Infomsg
GetExistingProduct
which=getSess("categoryid")
end if
Displayform
end sub
Sub GetFormData
dim objrs
CatGetFieldRequest objrs,strcatmemo,"catmemo"
CatGetFieldRequest objrs,lngcategoryid,"categoryid"
CatGetFieldRequest objrs,strcatdescription,"catdescription"
CatGetFieldRequest objrs,strcatimage,"catimage"
CatGetFieldRequest objrs,lnghighercategoryid,"highercategoryid"
CatGetFieldRequest objrs,strcathassubcategory,"hassubcategory"
If strcathassubcategory=Novalue then
strcathassubcategory=""
end if
CatGetFieldRequest objrs,strcatextra,"catextra"
CatGetFieldRequest objrs,strcathide,"cathide"
If strcathide=Novalue then
strcathide=""
end if
CatGetFieldRequest objrs,strcatproductmatch,"productmatch"
CatGetFieldRequest objrs,strcatcustomermatch,"customermatch"
CatGetFieldRequest objrs,strcatlanguage,"catlanguage"
CatGetFieldRequest objrs,strcattemplate,"catproducttemplate"
end sub
'
Sub ValidateData
sError=""
If strcatdescription = "" Then
sError = sError & getlang("LangProductDescription") & " " & getlang("langcustrequired") & "
"
end if
If lnghighercategoryid=getlang("LangCommonSelect") Then
lnghighercategoryid=0
End If
end sub
' ************************
Sub UpdateProduct
If getconfig("xMysql")="Yes" then
Mysqlupdatecategory myconn
exit sub
end if
dim sqlo
dim rso
dim filtersql
Set objRS = Server.CreateObject("ADODB.Recordset")
If updateaction<>"" then
filtersql ="select * from categories Where categoryid=" & GetSess("CategoryID")
' debugwrite filtersql
objRS.open filtersql, myconn, adOpenKeyset, adLockOptimistic
objRS.Update
infomsg= strcatdescription & getlang("LangProductUpdated") & " - " & GetSess("CategoryID") & "
"
else
objRS.open "categories", myconn, adOpenKeyset, adLockOptimistic
objRS.AddNew
end if
'CatUpdateField objrs,lngcategoryid,"categoryid"
CatUpdateField objrs,strcatdescription,"catdescription"
CatUpdateField objrs,strcatimage,"catimage"
CatUpdateField objrs,lnghighercategoryid,"highercategoryid"
if strcathassubcategory=novalue then
strcathassubcategory=""
end if
if strcathide=novalue then
strcathide=""
end if
CatUpdateField objrs,strcathassubcategory,"hassubcategory"
CatUpdateField objrs,strcatextra,"catextra"
CatUpdateField objrs,strcathide,"cathide"
CatUpdateField objrs,strcatproductmatch,"productmatch"
CatUpdateField objrs,strcatcustomermatch,"customermatch"
CatUpdateField objrs,strcatmemo,"catmemo"
CatUpdateField objrs,strcatlanguage,"catlanguage"
CatUpdateField objrs,strcattemplate,"catproducttemplate"
objRS.Update
Closerecordset objrs
If addaction<>"" then
sqlo = "SELECT max(categoryid) FROM categories"
Set rso = myconn.Execute(sqlo)
lngcategoryID = Cint(rso(0))
Setsess "categoryID",rso(0)
which=rso(0)
rso.Close
set rso=nothing
Infomsg= strcatdescription & getlang("LangProductAdded") & " - " & GetSess("categoryID") & "
"
end if
End Sub
'
Sub CatUpdateField (objrs, fieldvalue, fieldname)
if getconfig("xdebug")="Yes" then
debugwrite fieldname & "=" & fieldvalue
else
on error resume next
end if
if fieldvalue="" then
objRS(Fieldname)=NULL
exit sub
end if
'Debugwrite fieldname & "value=" & fieldvalue
if ucase(fieldvalue)="NULL" then
objRS(Fieldname)=NULL
else
objRS(Fieldname)=fieldvalue
end if
end sub
Sub DisplayForm
shopwriteerror sError
if which<>"" then
Response.write "
" response.write "" & getlang("LangCommonEdit") & " " end if response.write "" & getlang("LangEditSelectSetup") & " " & dbtable & "" Response.write "
" Response.Write("") End Sub '*********************** Sub GetCategories ' get categories from database and store in array for quicker access dim sql dim rsCat SQL = "SELECT * from categories order by catdescription" categorycount=0 Set rsCat = myconn.Execute(SQL) redim Categories(getconfig("xMaxCategories")) redim CategoryNums(getconfig("xMaxCategories")) categorycount=0 Do While NOT rscat.EOF categories(categorycount)= rscat("catdescription") & " [" & rscat("categoryid") & "]" categorynums(categorycount)= rscat("categoryid") ' Debugwrite categories(categorycount) categorycount=categorycount+1 rscat.movenext loop rscat.close set rscat=nothing end sub Sub RowHeader (Header) Dim srowColor srowColor="FFFFFF" Response.Write("