<%Option Explicit%> <% ShopCheckAdmin "shopa_editdisplay.asp" '************************************************************* ' Version 6.50 ' add a category to the database or edit/delete cataegory ' July 5, 2005 ' May 30, 2005 add translate ' Jan 2, 2006 Fix category display when xaddproductsubcategorybycategory=Yes '*************************************************************** 'Modified - Added the catlanguage field for the category display pages. ' add category template Dim CategoryCount Dim Categories Dim CategoryNums Dim dbtable Dim strcatdescription, strcatimage, strimpressions Dim lnghighercategoryid,strcathassubcategory,strcatextra 'VP-ASP 6.50 - add new category fields dim strcatextra2,strcatextra3 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 'CATEGORY DROPDOWN dim categoryarray ' xxx by 4 array dim rsfieldsvalue, displayfieldvalue, highercategoryid, i, display,recordcount,catid,catdescription,loopcount dim arraysize,strcategorylist,rsfieldvalue Const dccategoryid = 0 ' categoryid Const dccatdescription = 1 ' name Const dccatlinks = 2 ' links Const dchighercategoryid = 3 ' highercategoryid const dcnote=4 const dchassubcategory = 5 ' Dim Actiontype Dim Which, infomsg Dim Addaction, updateaction, deleteaction dbtable="categories" Dim myconn sError="" ShopOpenDatabaseP 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" 'VP-ASP 6.50 - new category fields CatGetFieldRequest objrs,strcatextra2,"catextra2" CatGetFieldRequest objrs,strcatextra3,"catextra3" 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" CatGetFieldRequest objrs,strimpressions,"impressions" 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 'VP-ASP 6.50 - broadened defintion of IF statement to cover cases where xmysql hasn't been set if ucase(xdatabasetype) = "MYSQL" OR ucase(xdatabasetype) = "MYSQL351" OR 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" 'VP-ASP 6.50 - new category fields CatUpdateField objrs,strcatextra2,"catextra2" CatUpdateField objrs,strcatextra3,"catextra3" 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 %>
<%shopwriteheader ucase(left(dbtable, 1)) & right(dbtable, len(dbtable) - 1) & " Setup"%> <% if which<>"" then response.write "" end if response.write "" if which <> "" then response.write "" end if response.write "" %>
Advanced Edit CategoriesGo Back to Category List
" & getlang("langadminadvanced") & " " & getlang("LangCommonEdit") & "Back To " & ucase(left(dbtable, 1)) & right(dbtable, len(dbtable) - 1) & "
<%shopwriteerror sError%>
<% GenerateDisplayHeader "Basic Information" GenerateDisplayBodyHeader Response.Write("
") 'VPASP 600 - ADD HTML EDITOR AddEditor "addproduct" 'VP-ASP 6.50 - Added buttons to top of page as well as bottom response.write "
" If which<>"" then 'VPASP 600 - HTMLEDITOR If getconfig("xhtmleditor")="Yes" then Response.Write("    ") Response.Write("") else Response.Write("    ") Response.Write("") end if Response.Write("  ") response.write "

" else 'VPASP 600 - HTMLEDITOR If getconfig("xhtmleditor")="Yes" then Response.Write("") else Response.Write("") end if end if response.write "
" Response.Write "

" if which > "" then Response.write tablerow & tablecolumn & getlang("LangProductCatNum") & tablecolumnend & tablecolumn & lngcategoryid & Tablecolumnend end if 'PCreateRowText getlang("LangProductDescription"),"catdescription",strcatdescription,2,"catdescription" catformateditrow getlang("LangProductDescription"),"catdescription",strcatdescription CatCreateRowImage getlang("LangProductImage"), "catimage", strcatimage,"catimage" Response.write tablerow & tablecolumn & "Higher Category" & tablecolumnend & "") ' FormatEditHelp "highercategoryid", helpfile response.write ("") If strcathassubcategory="" then strcathassubcategory=novalue Response.write tablerow & tablecolumn & getlang("LangSubcategories") & tablecolumnend & "") ' FormatEditHelp "hassubcategory", helpfile response.write ("") ' formateditrow getlang("LangSubcategories") & " " & getlang("langcommonYes"),"hassubcategory" ,strcathassubcategory if strcathide="" then strcathide=novalue Response.write tablerow & tablecolumn & getlang("LangHideProduct") & tablecolumnend & "") ' FormatEditHelp "cathide", helpfile response.write ("") catformateditrow getlang("Langproductmatch"),"productmatch",strcatproductmatch catformateditrow getlang("LangCustomermatch"),"customermatch" ,strcatcustomermatch PCreateRowText "catmemo","catmemo",strcatmemo,3,"catmemo" ' 31/01/2006 catextra changed to text input ' PcreateRowTExt "catextra","catextra",strcatextra,1,"catextra" if lcase(strcatextra) = "
" then strcatextra = "" catformateditrow "Cat Extra","catextra" ,strcatextra 'VP-ASP 6.50 - extra category fields if lcase(strcatextra2) = "
" then strcatextra2 = "" catformateditrow "Cat Extra 2","catextra2" ,strcatextra2 if lcase(strcatextra3) = "
" then strcatextra3 = "" catformateditrow "Cat Extra 3","catextra3" ,strcatextra3 catformateditrow getlang("LangLanguage"),"catlanguage",strcatlanguage catformateditrow getlang("LangProductTemplate"),"catproducttemplate" ,strcattemplate if which > "" then CatFormatEditRowSTatic "Impressions","impressions" ,strimpressions end if Response.Write(tableDefEnd) response.write "

" response.write "
" If which<>"" then 'VPASP 600 - HTMLEDITOR If getconfig("xhtmleditor")="Yes" then Response.Write("    ") Response.Write("") else Response.Write("    ") Response.Write("") end if 'VP-ASP 6.50 - Moved Delete button to be on same line as Add and Update Response.Write("  ") response.write "

" else 'VPASP 600 - HTMLEDITOR If getconfig("xhtmleditor")="Yes" then Response.Write("") else Response.Write("") end if end if response.write "
" AddHiddenfields Response.Write("") GenerateDisplayBodyFooter AddtranslateLinkMenu myconn, which, dbtable gethelp "categories" 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("" 'FormatEditHelp fieldname, helpfile response.write "" end sub Sub PCreateRowText (caption, fieldname, fieldvalue, rows, realname) dim url, htmlurl, linkurl url="shopa_addcategory.asp?which=" & which htmlurl="shopa_htmledit.asp?which=" & which & "&idfield=categoryid&table=categories&fieldname=" & realname htmlurl=htmlurl & "&url=" & server.urlencode(url) Linkurl="" & "HTML edit" & "" Response.write tablerow & tablecolumn & caption 'If getconfig("xhtmleditor")="Yes" then ' If realname<>"" and which<>"" Then ' Response.write "
" & linkurl ' end if 'end if response.write tablecolumnend response.write "" 'FormatEditHelp fieldname, helpfile response.write "" end sub Sub AddHiddenFields Formathiddenfield "idfield","categoryid" Formathiddenfield "which",which Formathiddenfield "table",dbtable end sub Sub FormatHiddenField (fieldname, fieldvalue) response.write "" & vbcrlf end sub '****************************************************************** ' used in the admin section to create a text form box '******************************************************************* Sub CatFormatEditRow (caption,fieldname,fieldvalue) dim capdisplay capdisplay=caption if capdisplay="" then capdisplay=fieldname end if Response.Write TableRow Response.write TableColumn & capdisplay & TableColumnEnd Response.write TableColumn & "" & vbcrlf Response.write tableColumnEnd 'FormatEditHelp fieldname, helpfile Response.write TableRowEnd end sub 'VPASP600 - Create a row for just text entries that aren't for editing (ie. impressions) Sub CatFormatEditRowSTatic (caption,fieldname,fieldvalue) dim capdisplay capdisplay=caption if capdisplay="" then capdisplay=fieldname end if Response.Write TableRow Response.write TableColumn & capdisplay & TableColumnEnd Response.write TableColumn & fieldvalue & tableColumnEnd 'FormatEditHelp fieldname, helpfile Response.write TableRowEnd end sub '************************************************************************************ ' Link to shopa_translatelist.asp if the product has been added '************************************************************************************ Sub AddtranslateLink If which="" then exit sub if getconfig("xtranslate")<>"Yes" then exit sub response.write "
" response.write "" & getlang("langadminlanguages") & "" end sub '**************************************************************************************** ' list all categories/subcategories except if 'xaddproductsubcategorybycategory=Yes tghen only list subcategories ' belonging to this category ' does not subport sub sub categories '**************************************************************************************** sub GenerateAllcategoryselection dim limitfield limitfield="" if getconfig("xaddproductsubcategorybycategory")="Yes" then if lngccategory="" then ' exit sub else limitfield=lngccategory end if end if 'GeneratemaincategoryFormField "strcategorylist", strcategorylist,getlang("langcommonselect"),"" GeneratemaincategoryFormField "highercategoryid", lnghighercategoryid,getlang("langcommonselect"),limitfield end sub '************************************************************************************************ ' used to generate single selections for main and subcategories ' limit field allows to limit to only main categories when set to 0 '********************************************************************************************* sub GeneratemaincategoryFormField (selectname, currentvalue, firstfield, limitfield) dim rsfieldsvalue, displayfieldvalue, highercategoryid, i, display response.write " " end sub sub Getallcategories '********************************************************************************************** ' get all categories ' use xmaxcategories or whichever is higher '********************************************************************************************* dim rs, sql, arraysize, i, highercategoryid, hidden arraysize=getconfig("Xmaxcategories") arraysize=clng(arraysize) sql="select * from categories order by highercategoryid,catdescription" set rs=myconn.execute(sql) i=0 recordcount=rs.recordcount if isnumeric(recordcount) and recordcount>0 then arraysize=recordcount end if redim categoryarray(arraysize,5) do while not rs.eof categoryarray(i,dccatdescription)=rs("catdescription") categoryarray(i,dccatlinks)=rs("catdescription") categoryarray(i,dccategoryid)=clng(rs("categoryid")) highercategoryid=rs("highercategoryid") if isnull(highercategoryid) then highercategoryid=0 categoryarray(i,dchighercategoryid)=highercategoryid hidden=rs("cathide") if not isnull(hidden) then categoryarray(i,dcnote)="hidden" end if If categoryarray(i,dccategoryid)=lngccategory then categoryarray(i,dcnote)=getlang("maincategory") end if categoryarray(i,dchassubcategory)=rs("hassubcategory") rs.movenext i=i+1 loop categorycount=i closerecordset rs if categorycount>0 then GenerateCategoryLinks ' generate links to categories end if end sub '************************************************************************************************ ' generate links in form cat--- subcat---subcat '*********************************************************************************************** Sub GenerateCategorylinks dim i, catlink, categoryid,j, sep 'VP-ASP 6.09 - check if higercategoryid has been set to categoryID for categories dim caterror caterror= 0 sep="---" for i = 0 to categorycount-1 catlink=categoryarray(i,dccatdescription) highercategoryid=categoryarray(i,dchighercategoryid) categoryid=categoryarray(i,dccategoryid) 'VP-ASP 6.09 - check if higercategoryid has been set to categoryID for categories if clng(categoryid)=clng(highercategoryid) then if caterror = 0 then response.write "CategoryID/HigherCategoryID Conflicts
" caterror = 1 end if highercategoryid=0 response.write "Higher Category ID is the same as the Category ID for Record #" & categoryid & ". Please update this record manually.
" end if do while highercategoryid<>0 j=Findincatarray(highercategoryid) ' find entry for higher category if j =-1 then exit for ' not found catdescription=categoryarray(j,dccatdescription) catlink=catdescription & sep & catlink ' generate higher--- cat highercategoryid=categoryarray(j,dchighercategoryid) ' see if it has a higher categgoryid loopcount=loopcount+1 'if loopcount>10 then ' exit for 'end if 'VP-ASP 6.09 - check if higercategoryid has been set to categoryID for categories if clng(categoryarray(j,dccategoryid))=clng(highercategoryid) then if caterror = 0 then response.write "CategoryID/HigherCategoryID Conflicts
" caterror = 1 end if highercategoryid=0 response.write "Higher Category ID is the same as the Category ID for Record #" & categoryid & ". Please update this record manually.
" end if loop catlink=catlink & " (" & categoryid & ")" 'if categoryarray(i,dchassubcategory) = "Yes" then ' categoryarray(i,dccatlinks)="" 'else categoryarray(i,dccatlinks)=catlink 'end if ' debugwrite "catlink=" & catlink next end sub Function Findincatarray(categoryid) dim z for z=0 to categorycount-i catid=categoryarray(z,dccategoryid) if catid=categoryid then findincatarray=z exit function end if next findincatarray=-1 end function sub AddCategories getallcategories ' create an array of all categories 'GeneratemaincategorySelection ' drop down of all main categories Generateallcategoryselection ' drop down of all actegories end sub %>
" ' GenerateselectV categories, categorynums,lnghighercategoryid,"highercategoryid",categorycount, getlang("LangCommonSelect") AddCategories response.write ("
" GenerateselectNV YesNos,strcathassubcategory,"hassubcategory",yesnocount, "" response.write ("
" GenerateselectNV YesNos,strcathide,"cathide",yesnocount, "" response.write ("
" & header &"") end sub ' Sub GetProductCategory ' Need to get category number from array for update Dim CategoryName Dim k 'locate category in category table 'debugwrite "category count=" & categorycount for k = 0 to categorycount-1 ' debugwrite "searching for " & strcategory & "matching " & categories(i) if strcategory=categories(k) then lngCategoryID=categorynums(k) exit sub end if next lngcCategory=0 Debugwrite "GetProductCategory Failed to find =" & strcategory end sub Sub GetExistingProduct dim getsql lngcategoryid=getsess("categoryid") getsql="select * from categories where categoryid=" & lngcategoryid 'debugwrite getsql Set objRS = myconn.Execute(getsql) If objRS.EOF Then catresetfield objrs,lngcategoryid,"categoryid" catresetfield objrs,strcatdescription,"catdescription" catresetfield objrs,strcatimage,"catimage" catresetfield objrs,lnghighercategoryid,"highercategoryid" catresetfield objrs,strcathassubcategory,"hassubcategory" strcathassubcategory=Novalue catresetfield objrs,strcatextra,"catextra" 'VP-ASP 6.50 - extra category fields catresetfield objrs,strcatextra2,"catextra2" catresetfield objrs,strcatextra3,"catextra3" catresetfield objrs,strcatlanguage,"catlanguage" catresetfield objrs,strcathide,"cathide" catresetfield objrs,strcatproductmatch,"productmatch" catresetfield objrs,strcatcustomermatch,"customermatch" catresetfield objrs,strcattemplate,"cattemplate" CatResetField objRS, strCatMemo, "catmemo" strcathide=novalue Else CatGetField objrs,strcatmemo,"catmemo" CatGetField objrs,lngcategoryid,"categoryid" CatGetField objrs,strcatdescription,"catdescription" CatGetField objrs,strcatimage,"catimage" CatGetField objrs,lnghighercategoryid,"highercategoryid" CatGetField objrs,strcathassubcategory,"hassubcategory" If strcathassubcategory="" then strcathassubcategory=Novalue else strcathassubcategory=Yesvalue end if CatGetField objrs,strcatextra,"catextra" 'VP-ASP 6.50 - extra category fields CatGetField objrs,strcatextra2,"catextra2" CatGetField objrs,strcatextra3,"catextra3" CatGetField objrs,strcatlanguage,"catlanguage" CatGetField objrs,strcathide,"cathide" If strcathide="" then strcathide=Novalue else strcathide=Yesvalue end if CatGetField objrs,strcatproductmatch,"productmatch" CatGetField objrs,strcatcustomermatch,"customermatch" CatGetField objrs,strcattemplate,"catproducttemplate" CatGetField objrs,strimpressions,"impressions" End If Closerecordset objRS End Sub Sub CatGetField (objrs,fieldvalue,fieldname) 'debugwrite fieldname fieldvalue=objrs(fieldname) If isnull(fieldvalue) then fieldvalue="" end if end sub Sub CatGetFieldRequest (unused, fieldvalue,fieldname) fieldvalue=request(fieldname) end sub Sub CatResetField (unused, fieldvalue,fieldname) fieldvalue="" end sub Sub Deletecategory which=request("which") 'VP-ASP 6.09 - Precautionary Security Fix if which > "" then If not isnumeric(which) then shoperror "Category ID must be numeric" End if end if dim sql, url sql="delete from categories where categoryid=" & which myconn.execute(sql) shopclosedatabase myconn url="shopa_editdisplay.asp?table=categories" responseredirect url end sub Sub CatCreateRowImage (caption, fieldname, fieldvalue,dbfield) dim uploadurl dim imageurl imageurl="" uploadurl="" If fieldvalue<>"" then imageurl="" & getlang("langcommonview") & "" end if If Getconfig("xupload")="Yes" then ' if lngcategoryid<>"" then uploadurl="shopa_uploadpop.asp?form=addproduct&formfield=" & fieldname & "&id=" & lngcategoryid & "&field=" & dbfield & "&table=categories&idfield=categoryid&url=" & server.urlencode("shopa_addcategory.asp") ' end if end if Response.Write tablerow & tableColumn & caption & tablecolumnend response.write "" If uploadurl<>"" then ' Response.write " " & getlang("langupload") & "

" Response.write " " & getlang("langupload") & "" end if If imageurl<>"" then response.write " " & imageurl end if response.write "
" 'VPASP 600 - ADD HTML EDITOR If getconfig("xhtmleditor")="Yes" then addHTMLEditor fieldname, fieldvalue, "addproduct" else response.write "" end if response.write "