%option explicit%>
<%
Const ExtraDisplay="No"
ShopCheckAdmin "shopa_editdisplay.asp"
'**************************************************************************
' Shop administration Only
' Format list of Records in any table so that they can be viewed or deleted
' add sort facility, fields to display
' 5.00 Apr 3, 2003
' Free Version
'**************************************************************************
dim mysql
Dim Fieldcount
Dim Headnames(6)
Dim ProcType
Dim SortType
Dim Sortfield
Dim SortUpDown
Dim Sortupdownnames(2)
Dim Sortupdownvalues(2)
Dim Sortupdowncount
Dim Procnames(3)
dim Procvalues(3)
Dim Fieldnames
Dim Fieldnamecount
Dim DisplayFields
Dim displayFieldCount
Dim DisplayField
Dim Idfield
Dim SelectField
Dim SelectValue
Dim maxfields
Dim i
Dim item
dim dbtable
Dim scriptresponder
dim fieldname
Dim rstemp
Dim dbc
dim SpecialFunction
Dim Continue
Dim SelectAll
Dim productcategoryid
dim language
dim partsql
'
'
SelectAll=""
GetTableName
SetSess "CurrentURL","shopa_editdisplay.asp"
AdminPageHeader
GetDatabase
If dbtable<>"" then ' no valid table
GetSpecialFunction
EditOpenDatabase dbc,database,dbtable
GetInput ' get all form fields
maxfields=6
ProcessSpecialRequests ' delete or mail requests
SetupResponders
GenerateDisplayHeader ' Generate sort button etc
' Different Responders for different tables
ShopopenRecordSet mysql, rstemp, mypagesize, mypage
GenerateTable ' write the tabe
Call PageNavBar (Mysql) ' put bottom navigation bar
rsTemp.close ' close database
set rstemp=nothing
ShopCloseDatabase dbc
end if
AdminPageTrailer ' Write admin trailer
'
Sub GetDatabase
Database=request("database")
if database="" then
database=GetSess("db")
else
SetSess "db",database
end if
if database="" then
Debugwrite "No database specified"
end if
end sub
Sub GetTableName
dbtable=Request("Table")
if dbtable="" then
dbtable=GetSess("table")
else
ValidateTable
end if
if dbtable="" then
shopwriteerror getlang("langEditSelectFail")
exit sub
end if
SetSess "table",dbtable
'Response.write getlang("langEdittablename") & " = " & dbtable & "
"
end sub
Sub GetSpecialFunction
specialfunction=Request("Specialfunction")
if specialfunction="" then
specialfunction=GetSess("specialfunction")
If Specialfunction="" then
specialfunction=getlang("langCommonDelete")
setsess("specialfunction"),specialfunction
end if
else
If ucase(Specialfunction)="NULL" then
SpecialFunction=""
end if
end if
SetSess "specialfunction",specialfunction
end sub
'**************************************************************************
Sub GetInput
mypage = Request("page")
'first time we need everything, othertimes sql is set up
sortfield=request("Sortfield")
' See how we are sorting
If Sortfield="" or Sortfield=getlang("langCommonSelect") then
sortfield=IdField
end if
SelectValue=request("Selectvalue")
SelectField=request("selectField")
Productcategoryid=request("productcategoryid")
If productcategoryid=getlang("langCommonselect") then
productcategoryid=""
end if
If SelectField=getlang("langCommonselect") then
selectvalue=""
end if
'response.write "sortfield="& sortfield & "
"
' see which types processed or unprocessed
SortUpdown=request("SortUpdown")
If SortUpdown="" then
sortupdown="ASC"
end if
if mypage="" then
SetFieldNames ' field names for table
GetDisplayfields
mypage=1
GenerateSQL
else
Mysql=Getsess("sqlquery")
Fieldcount=GetSess("Fieldcount")
Fieldnames=GetsessA("Fieldnames")
sortfield=GetSess("sortfield")
sortupdown=GetSess("sortupdown")
IDfield=GetSess("IDfield")
productcategoryid=GetSess("productcategoryid")
language=Getsess("editlanguage")
dbtable=GetSess("table")
DisplayFields=GetSess("DisplayFields")
DisplayFieldCount=GetSess("DisplayFieldCount")
partsql=getsess("partsql")
end if
maxrecs=getconfig("xeditdisplaymaxrecords")
mypagesize=maxrecs
SetUpDown
' see if mail of export
If Request("SelectAll")<>"" then
SelectAll=" checked "
end if
database=Getsess("db")
end sub
'
' SQL is generate by using fields on form
Sub GenerateSQL
dim sqlproc
dim key
dim sqladd
sqladd=" Where"
MySql = "SELECT * from " & lcase(dbtable)
if Selectvalue<> "" then
key = SelectValue & "%"
If isnumeric(selectvalue) then
mySQL = MySQL & " where " & SelectField & "=" & Selectvalue
else
mySQL = MySQL & " where " & SelectField & " like '" & key & "'"
end if
sqladd=" AND "
end if
If ucase(dbtable)="PRODUCTS" then
DoRestrictProducts MySQL, sqladd
end if
If Productcategoryid<>"" then
mysql=Mysql & sqladd
mysql=Mysql & " ccategory=" & productcategoryid
sqladd=" And "
end if
AddLanguagesql mysql, sqladd
If sortfield="" then sortfield=idfield
If sortfield<>"" then
mysql=mysql & " order by " & sortfield & " " & sortupdown
end if
SetSess "sqlquery",MySQL
Setsess "sortfield",sortfield
Setsess "sortupdown",sortupdown
If getconfig("xdebug")="Yes" then
debugwrite "generated sql=" & mysql & "
"
end if
End sub
'
Sub DorestrictProducts (isql, sqladd)
if getconfig("XAdminRestrictProducts")<>"Yes" then exit sub
If GetSess("Admintype")="" then exit sub
If GetSess("Admintype")="SUPER" then exit sub
iSql = isql & sqladd & " userid='" & GetSess("shopadmin") & "'"
end sub
Sub GenerateTable()
dim howmanyfields
dim my_link
Dim howmanyrecs
Dim ArrayFields
Dim fieldvalue
dim idvalue
SetSess "Table",dbtable
SetSess "Dbname",dbname
SetSess "Idfield",idfield
SetSess "Fieldcount",fieldcount
If DisplayFieldcount> 0 then
howmanyfields=DisplayFieldCount-1
ArrayFields=DisplayFields
else
howmanyfields=fieldcount-1
ArrayFields=Fieldnames
end if
'DebugWrite "fieldcount = " & fieldcount & "howmany=" & howmanyfields
if howmanyfields > maxfields then
howmanyfields = maxfields
end if
response.write "
| <% GenerateSelectV categories,categoryids,productcategoryid,"productcategoryid", catcount,getlang("langCommonSelect") Response.write " | " %><%=getlang("langcommoncategories")%> |
" %>
| <% GenerateSelectNV languages,language,"language", langcount,getlang("langcommonselect") Response.write " | " %><%=getlang("LangLanguage")%> |