Skip to content

Instantly share code, notes, and snippets.

@csanz
Created December 15, 2010 06:57
Show Gist options
  • Select an option

  • Save csanz/741712 to your computer and use it in GitHub Desktop.

Select an option

Save csanz/741712 to your computer and use it in GitHub Desktop.
I wrote this very simple API for one of the flash programmers. I ported this over to java a few weeks later.
<%
'//##Misc Methods
'//-------------
'//#######################################
sub view(string) '//process string and add delimeter
response.write(string) & ";"
end sub
sub write(str)'//DONE
response.write(str)
end sub
sub getCount(sql)'//DONE
set r=Server.CreateObject("ADODB.Recordset")
' count records
r.Open sql,oConn
dim TotalRecords
TotalRecords=r("r_c")'//DONE
response.write ("TotalRecords=") & (TotalRecords)
end sub
function delExtra(var)'//DONE
num = len(var)
num = num - 1
var = right(var,num)
response.write(var)&("&")
end function
'//#######################################
'//list of in-line SQL statements
SQLSTORE="SELECT store.*, collection.*, categories.* FROM "&_
" categories RIGHT JOIN (collection RIGHT JOIN store ON "&_
" collection.collection_id = store.collection_id) ON "&_
" categories.category_id = store.category_id "&_
" where store.available_date <= GETDATE() and store.finish_date >=GETDATE()"
SQLInventory = "SELECT inventory.*, store.*, collection.*, categories.* FROM"&_
" collection INNER JOIN (categories INNER JOIN (store LEFT JOIN inventory ON store.item_id = inventory.item_id) ON " &_
" categories.category_id = store.category_id) ON collection.collection_id = store.collection_id "
'//####################################
function checkToSeeIfYouExist(member_name,cashPassed)'//DONE
cash = cashPassed
DBResult = "True"
statusUser = "Old_User"
if member_name <> "" and cash <> "" then
member_name = member_name
member_name_session = Session("BLASTeXchange_member_name")
if member_name_session = "" or member_name_session <> member_name then
DBResult = "False"'//false until is done quering database
sql1= "Select user_ex.* from user_ex where member_name LIKE '%" & member_name & "%'"
set r1=Server.CreateObject("ADODB.Recordset")
r1.open sql1, oConn, 1, 3
if r1.eof then
DBResult = "False" '//false until is done creating new record
sql = "select user_ex.* from user_ex"
set r=Server.CreateObject("ADODB.Recordset")
r.open sql, oConn, 1, 3
r.addnew
r.Fields("member_name") = member_name
r.Fields("cash_amount")= cash
r.Fields("date_created") = now
r.Fields("total_tickets") = cash
r.Update()
r.Close
set r=nothing
Session("BLASTeXchange_member_name") = member_name
DBResult = "True" '//successfully added new record
statusUser = "New_User"
else
Session("BLASTeXchange_member_name")= member_name
DBResult = "True" '//no need for database use so everything is cool
statusUser = "Old_User"
end if
end if
else
DBResult="False"
member_name="Null"
statusUser="Null"
end if
write ("User=")
write (member_name)
write ("&Status=")
write (statusUser)
write ("&DBResult=")
write (DBResult)
end function
'//### Individual User
function GetUserProfile(member_name)'//DONE
DBResult="True"
SQL = "select user_ex.profile from user_ex where member_name='"&member_name&"'"
set r=oConn.Execute(SQL)
if not r.eof then
profile = r("profile")
DBResult="True"
else
DBResult="False 5"
end if
r.Close
set r = nothing
if profile <> "" then
response.write (profile) & ("&")
end if
response.write ("DBResult=")
response.write(DBResult)
end function
'//##########################
function GetUserCollections(member_name)
DBResult="False"
if member_name <> "" then
SQL ="SELECT DISTINCT collection.collection_id, collection.collection_name, collection.collection_total, collection.collection_description, collection.collection_name, inventory.member_name "&_
" FROM collection INNER JOIN (store INNER JOIN inventory ON store.item_id = inventory.item_id) ON collection.collection_id = store.collection_id "&_
" WHERE (((inventory.member_name)='"&member_name&"'))"
set r=oConn.Execute(SQL)
if not r.eof then
while not r.eof
collection_id = collection_id & ";" & r("collection_id")
collection_name = collection_name & ";" & Server.URLEncode(r("collection_name"))
collection_description = collection_description & ";" & Server.URLEncode(r("collection_description"))
collection_total = collection_total & ";" & r("collection_total")
r.movenext
wend
DBResult="True"
response.write ("collection_id=")
delExtra(collection_id)
response.write ("collection_name=")
delExtra(collection_name)
response.write ("collection_description=")
delExtra(collection_description)
response.write ("collection_total=")
delExtra(collection_total)
else
DBResult="False"
end if
r.Close
set r = nothing
end if '//ending first if
response.write ("DBResult=")
response.write(DBResult)
end function
'//##########################
function GetUserInventoryByCollection(member_name, collection_idPassed)
DBResult="False"
if member_name <> "" and collection_idPassed <> "" then
SQL =" SELECT inventory.member_name, collection.collection_id, inventory.inventory_id, store.item_id, store.item_name, store.item_description, categories.category_id, categories.category_name, store.cost, store.amount, store.original_amount, store.url, store.thumbnail, store.issues, store.available_date, store.finish_date, store.rarity "&_
" FROM categories INNER JOIN (collection INNER JOIN (store INNER JOIN inventory ON store.item_id = inventory.item_id) ON collection.collection_id = store.collection_id) ON categories.category_id = store.category_id "&_
" WHERE (((inventory.member_name)='"&member_name&"') AND ((collection.collection_id)="&collection_idPassed&"))"
set r=oConn.Execute(SQL)
if not r.eof then
while not r.eof
inventory_id = inventory_id & ";" & r("inventory_id")
item_id = item_id & ";" & r("item_id")
item_name = item_name & ";" & Server.URLEncode(r("item_name"))
item_description = item_description & ";" & r("item_description")
category_id = category_id & ";" & r("category_id")
category_name = category_name & ";" & Server.URLEncode(r("category_name"))
cost = cost & ";" & r("cost")
amount = amount & ";" & r("amount")
original_amount = original_amount & ";" & r("original_amount")
url = url & ";" & r("url")
thumbnail = thumbnail & ";" & r("thumbnail")
issue = issue & ";" & r("issues")
available_date = available_date & ";" & r("available_date")
finish_date = finish_date & ";" & r("finish_date")
rarity = rarity & ";" & r("rarity")
r.movenext
wend
DBResult="True"
response.write("inventory_id=")
delExtra(inventory_id)
response.write("item_id=")
delExtra(item_id)
response.write("item_name=")
delExtra(item_name)
response.write("item_description=")
delExtra(item_description)
response.write("category_id=")
delExtra(category_id)
response.write("category_name=")
delExtra(category_name)
response.write("cost=")
delExtra(cost)
response.write("amount=")
delExtra(amount)
response.write("original_amount=")
delExtra(original_amount)
response.write("url=")
delExtra(url)
response.write("thumbnail=")
delExtra(thumbnail)
response.write("issue=")
delExtra(issue)
response.write("available_date=")
delExtra(available_date)
response.write("finish_date=")
delExtra(finish_date)
response.write("rarity=")
delExtra(rarity)
else
DBResult="False"
end if
r.Close
set r = nothing
end if '//ending first if
response.write ("DBResult=")
response.write(DBResult)
end function
'//##########################
function GetUserPoints(member_name)
'//cash_amount=2300&total_tickets=81120&total_tokens=10&total_keys=1&DBResult=True
DBResult="False"
if member_name <> "" then
SQL = "SELECT user_ex.* from user_ex where member_name='"&member_name&"'"
set r=oConn.Execute(SQL)
if not r.eof then
response.write ("cash_amount=") & r("cash_amount") & ("&")
response.write ("total_tickets=") & r("total_tickets") & ("&")
response.write ("total_tokens=") & r("total_tokens") & ("&")
response.write ("total_keys=") & r("total_keys")
DBResult="True"
else
DBResult="False"
end if
r.Close
set r = nothing
end if '//ending first if
if DBResult <> "False" then
response.write ("&")
end if
response.write ("DBResult=")
response.write(DBResult)
end function
'//##########################
function GetGlobalTable(name)
DBResult="False"
if name <> "" then
SQL = "SELECT global.* from global where name_gl='"&name&"'"
set r=oConn.Execute(SQL)
if not r.eof then
response.write r("string")
DBResult="True"
else
DBResult="False"
end if
r.Close
set r = nothing
end if '//ending first if
if DBResult <> "False" then
response.write ("&")
end if
response.write ("DBResult=")
response.write(DBResult)
end function
'//##########################
function SetGlobalTable(name,value)
valuePassed = Replace(value, ";", "&")
if name <> "" and value <> "" then
sql = "select global.* from global where name_gl ='" & name & "'"
set r=Server.CreateObject("ADODB.Recordset")
r.open sql, oConn, 1, 3
if not r.eof then
r.Fields("string") = valuePassed
r.Update()
DBResult= "True"
else
DBResult= "False"
end if
r.Close
set r=nothing
else
DBResult= "False"
end if
response.write("DBResult=") & (DBResult)
end function
'//##########################
function SetUserProfile(profilePassed,member_name)
profilePassed = Replace(profilePassed, ";", "&")
if member_name <> "" and profilePassed <> "" then
sql = "select user_ex.* from user_ex where member_name ='" & member_name & "'"
set r=Server.CreateObject("ADODB.Recordset")
r.open sql, oConn, 1, 3
if not r.eof then
r.Fields("profile") = profilePassed
r.Update()
DBResult= "True"
else
DBResult= "False"
end if
r.Close
set r=nothing
else
DBResult= "False"
end if
response.write("DBResult=") & (DBResult)
end function
'//##########################
function SetUserPoints(member_name,cash_amount,total_tickets,total_tokens,total_keys)
if member_name <> "" and cash_amount <> "" and total_tickets <> "" and total_tokens <> "" and total_keys <> "" then
sql = "select user_ex.* from user_ex where member_name ='" & member_name & "'"
set r=Server.CreateObject("ADODB.Recordset")
r.open sql, oConn, 1, 3
if not r.eof then
r.Fields("cash_amount") = cash_amount
r.Fields("total_tickets") = total_tickets
r.Fields("total_tokens") = total_tokens
r.Fields("total_keys") = total_keys
r.Update()
DBResult= "True"
else
DBResult= "False"
end if
r.Close
set r=nothing
else
DBResult= "False"
end if
response.write("DBResult=") & (DBResult)
end function
'//##########################
function AdjustUserPoints(member_name,pointsPassed)
pointsPassed = cint(pointsPassed)
if member_name <> "" and pointsPassed <> "" then
sql = "select user_ex.* from user_ex where member_name ='" & member_name & "'"
set r=Server.CreateObject("ADODB.Recordset")
r.open sql, oConn, 1, 3
if not r.eof then
if pointsPassed > 0 then
r.Fields("cash_amount") = r.Fields("cash_amount") + pointsPassed
r.Fields("total_tickets") = r.Fields("total_tickets") + pointsPassed
else
r.Fields("cash_amount") = r.Fields("cash_amount") + pointsPassed
end if
response.write ("cash_amount=") & r("cash_amount") & ("&")
response.write ("total_tickets=") & r("total_tickets") & ("&")
response.write ("total_tokens=") & r("total_tokens") & ("&")
response.write ("total_keys=") & r("total_keys") & ("&")
r.Update()
DBResult= "True"
else
DBResult= "False"
end if
r.Close
set r=nothing
else
DBResult= "False"
end if
response.write("DBResult=") & (DBResult)
end function
'//##########################
function GetUserRanks(page,maxperpage,min_total_tickets,max_total_tickets)
DBResult="False"
if min_total_tickets <> "" and max_total_tickets <> "" and page <> "" and maxperpage <> "" then
if max_total_tickets = 0 then
sql ="select user_ex.* from user_ex ORDER BY total_tickets DESC"
else
sql = "select user_ex.* from user_ex " &_
" where total_tickets BETWEEN " & min_total_tickets &" and " &max_total_tickets&" ORDER BY total_tickets DESC"
end if
'**********PAGING CODE**************
iPageSize = cInt(maxperpage)
If page = "" Then
iPageCurrent = 1
Else
iPageCurrent = CInt(page)
End If
'----------------------------------------------------
Set r = Server.CreateObject("ADODB.Recordset")
r.PageSize = iPageSize
r.CacheSize = iPageSize
r.Open sql, oConn, adOpenStatic, adLockReadOnly, adCmdText
iPageCount = r.PageCount
If iPageCurrent > iPageCount Then iPageCurrent = iPageCount
If iPageCurrent < 1 Then iPageCurrent = 1
If iPageCount = 0 Then
DBResult="False"'//No records found!
Else
r.AbsolutePage = iPageCurrent
DBResult="True"
'***********************
if not r.eof then
iRecordsShown = 0
Do While iRecordsShown < iPageSize And Not r.EOF
name = name & ";" & r("member_name")
total_tickets = total_tickets & ";" & r("total_tickets")
total_tokens = total_tokens & ";" & r("total_tokens")
total_keys = total_keys & ";" & r("total_keys")
iRecordsShown = iRecordsShown + 1
r.movenext
Loop
response.write "page_current=" & (iPageCurrent) & "&"
response.write "total_page=" & (iPageCount) & "&"
DBResult="True"
response.write ("member_name=")
delExtra(name)
response.write ("total_tickets=")
delExtra(total_tickets)
response.write ("total_tokens=")
delExtra(total_tokens)
response.write ("total_keys=")
delExtra(total_keys)
else
DBResult="False"
end if
end if
r.Close
set r = nothing
end if '//ending first if
response.write ("DBResult=")
response.write(DBResult)
end function
'//##########################
'//--- International Functions --
'//##########################
function SetUserTokens(member_name,tokens,total_tokens)
if member_name <> "" and tokens <> "" and total_tokens <> "" then
sql = "select user_ex.* from user_ex where member_name ='" & member_name & "'"
set r=Server.CreateObject("ADODB.Recordset")
r.open sql, oConn, 1, 3
if not r.eof then
r.Fields("tokens") = tokens
r.Fields("total_tokens") = total_tokens
response.write ("tokens=") & r("tokens") & ("&")
response.write ("total_tokens=") & r("total_tokens") & ("&")
r.Update()
DBResult= "True"
else
DBResult= "False"
end if
r.Close
set r=nothing
else
DBResult= "False"
end if
response.write("DBResult=") & (DBResult)
end function
'//##########################
function AdjustUserTokens(member_name,tokens)
tokens = cint(tokens)
if member_name <> "" and tokens <> "" then
sql = "select user_ex.* from user_ex where member_name ='" & member_name & "'"
set r=Server.CreateObject("ADODB.Recordset")
r.open sql, oConn, 1, 3
if not r.eof then
if tokens > 0 then
r.Fields("tokens") = r.Fields("tokens") + tokens
r.Fields("total_tokens") = r.Fields("total_tokens") + tokens
else
r.Fields("tokens") = r.Fields("tokens") + tokens
end if
response.write ("tokens=") & r("tokens") & ("&")
response.write ("total_tokens=") & r("total_tokens") & ("&")
r.Update()
DBResult= "True"
else
DBResult= "False"
end if
r.Close
set r=nothing
else
DBResult= "False"
end if
response.write("DBResult=") & (DBResult)
end function
'//##########################
function SetUserKeys(member_name,keys,total_keys)
if member_name <> "" and keys <> "" and total_keys <> "" then
sql = "select user_ex.* from user_ex where member_name ='" & member_name & "'"
set r=Server.CreateObject("ADODB.Recordset")
r.open sql, oConn, 1, 3
if not r.eof then
r.Fields("keys") = keys
r.Fields("total_keys") = total_keys
response.write ("keys=") & r("keys") & ("&")
response.write ("total_keys=") & r("total_keys") & ("&")
r.Update()
DBResult= "True"
else
DBResult= "False"
end if
r.Close
set r=nothing
else
DBResult= "False"
end if
response.write("DBResult=") & (DBResult)
end function
'//##########################
function AdjustUserKeys(member_name,keys)
keys = cint(keys)
if member_name <> "" and keys <> "" then
sql = "select user_ex.* from user_ex where member_name ='" & member_name & "'"
set r=Server.CreateObject("ADODB.Recordset")
r.open sql, oConn, 1, 3
if not r.eof then
if keys > 0then
r.Fields("keys") = r.Fields("keys") + keys
r.Fields("total_keys") = r.Fields("total_keys") + keys
else
r.Fields("keys") = r.Fields("keys") + keys
end if
response.write ("keys=") & r("keys") & ("&")
response.write ("total_keys=") & r("total_keys") & ("&")
r.Update()
DBResult= "True"
else
DBResult= "False"
end if
r.Close
set r=nothing
else
DBResult= "False"
end if
response.write("DBResult=") & (DBResult)
end function
'//##########################
function GetUserBuddy()
end function
'//##########################
function SetUserBuddy()
end function
'//##########################
function GetUserNavBar()
end function
'//##########################
function GetUserItemsOnStage()
end function
'//##########################
function SetUserItemOnStage()
end function
'//##########################
'*************************************************
'//### Shopping
'*************************************************
'GetShopCollections
'GetShopItemsByCollection
'GetShopItemInfo
'SetShopItemInfo -- admin. function --
'SetShopItemCost -- admin. function --
'SetShopItemOriginalAmount -- admin. function --
'SetShopItemAmount -- admin. function --
'SetShopItemSalesStatus -- admin. function --
'AutoUpdateShopItemSalesStatus -- admin. function --
'BuyShopItem
'BuyShopPack
'RemoveShopItem -- admin. function --
'//########################
function GetShopCollections()
DBResult="False"
Set rC = Server.CreateObject("ADODB.command")
Set rC.ActiveConnection = oConn
rC.commandText = "{CALL getCollections}"
Set r = Server.CreateObject("ADODB.recordset")
Set r = rC.execute
if not r.eof then
while not r.eof
collection_id = collection_id & ";" & r("collection_id")
collection_name = collection_name & ";" & Server.URLEncode(r("collection_name"))
collection_description = collection_description & ";" & Server.URLEncode(r("collection_description"))
collection_total = collection_total & ";" & r("collection_total")
r.movenext
wend
DBResult="True"
response.write ("collection_id=")
delExtra(collection_id)
response.write ("collection_name=")
delExtra(collection_name)
response.write ("collection_description=")
delExtra(collection_description)
response.write ("collection_total=")
delExtra(collection_total)
else
DBResult="False"
end if
r.Close
set r = nothing
response.write ("DBResult=")
response.write(DBResult)
end function
'//########################
'//collection_id =the collectionsís identifier
'//sales_status_id = 0 (for sale), 1 (new: for sale), 2 (special: on sale), 3 (sale suspended), 4 (recall)
'//max_cost = The max. cost (0 means no upper limit)
'//sort = The sorting order (none, byAvailableDate or byFinishDate ñ most recent first)
'//page = The page #
'//maxperpage
function GetShopItemsByCollection(collection_idPassed,sales_status_idPassed,max_costPassed,sortPassed,page,maxperpage)
DBResult="False 1"
if collection_idPassed <> "" and sales_status_idPassed <> "" and max_costPassed <> "" and sortPassed <> "" and page <> "" and maxperpage <> "" then
'//***************sort
Select Case sort
case "none", ""
sort = "item_name"
case "byAvailableDate"
sort = "available_date"
case "byFinishDate"
sort = "finish_date"
end select
'//**************status
if sales_status_idPassed <> 0 or sales_status_idPassed <> 1 or sales_status_idPassed <> 2 or sales_status_idPassed <> 3 or sales_status_idPassed <> 4 then
salesStat = 0
else
salesStat = sales_status_idPassed
end if
if max_costPassed = 0 then
sql ="select store.* from store where sales_status_id ="&salesStat&" and collection_id="&collection_idPassed &_
" ORDER BY "& sort &" DESC"
else
sql = "select store.* from store " &_
" where cost <= "&max_costPassed&" and collection_id="&collection_idPassed&_
" and sales_status_id ="&salesStat&" ORDER BY "& sort &" DESC"
end if
'response.write (sql) & "<br>"
'**********PAGING CODE**************
iPageSize = cInt(maxperpage)
If page = "" Then
iPageCurrent = 1
Else
iPageCurrent = CInt(page)
End If
'----------------------------------------------------
Set r = Server.CreateObject("ADODB.Recordset")
r.PageSize = iPageSize
r.CacheSize = iPageSize
r.Open sql, oConn, adOpenStatic, adLockReadOnly, adCmdText
iPageCount = r.PageCount
If iPageCurrent > iPageCount Then iPageCurrent = iPageCount
If iPageCurrent < 1 Then iPageCurrent = 1
If iPageCount = 0 Then
DBResult="False"'//No records found!
Else
r.AbsolutePage = iPageCurrent
DBResult="True"
'***********************
if not r.eof then
iRecordsShown = 0
Do While iRecordsShown < iPageSize And Not r.EOF
item_id = item_id & ";" & r("item_id")
item_name = item_name & ";" & Server.URLEncode(r("item_name"))
item_description = item_description & ";" & Server.URLEncode(r("item_description"))
collection_id = collection_id & ";" & r("collection_id")
cost = cost & ";" & r("cost")
amount = amount & ";" & r("amount")
original_amount = original_amount & ";" & r("original_amount")
url = url & ";" & r("url")
thumbnail = thumbnail & ";" & r("thumbnail")
issue = issue & ";" & r("issues")
iRecordsShown = iRecordsShown + 1
r.movenext
Loop
response.write "page_current=" & (iPageCurrent) & "&"
response.write "total_pages=" & (iPageCount) & "&"
DBResult="True"
response.write ("item_id=")
delExtra(item_id)
response.write ("item_name=")
delExtra(item_name)
response.write ("item_description=")
delExtra(item_description)
response.write ("collection_id=")
delExtra(collection_id)
response.write ("cost=")
delExtra(cost)
response.write ("amount=")
delExtra(amount)
response.write ("original_amount=")
delExtra(original_amount)
response.write ("url=")
delExtra(url)
response.write ("thumbnail=")
delExtra(thumbnail)
response.write ("issue=")
delExtra(issue)
else
DBResult="False"
end if
end if
r.Close
set r = nothing
end if '//ending first if
response.write ("DBResult=")
response.write(DBResult)
end function
'//########################
function GetShopCategories()
DBResult="False"
Set rC = Server.CreateObject("ADODB.command")
Set rC.ActiveConnection = oConn
rC.commandText = "{CALL getCategories}"
Set r = Server.CreateObject("ADODB.recordset")
Set r = rC.execute
if not r.eof then
while not r.eof
category_id = category_id & ";" & r("category_id")
if IsNull(r("category_name")) then
category_name = category_name & ";" & r("category_name")
else
category_name = category_name & ";" & Server.URLEncode(r("category_name"))
end if
if IsNull(r("category_description")) then
category_description = category_description & ";" & r("category_description")
else
category_description = category_description & ";" & Server.URLEncode(r("category_description"))
end if
r.movenext
wend
DBResult="True"
response.write ("category_id=")
delExtra(category_id)
response.write ("category_name=")
delExtra(category_name)
response.write ("category_description=")
delExtra(category_description)
else
DBResult="False"
end if
r.Close
set r = nothing
response.write ("DBResult=")
response.write(DBResult)
end function
'//##########################
function GetShopItemInfo(item_idPassed)
DBResult="False"
if item_idPassed <> "" then
SQL = "SELECT store.*, collection.*, categories.* FROM " &_
" categories INNER JOIN (collection INNER JOIN store ON collection.collection_id = store.collection_id) " &_
" ON categories.category_id = store.category_id WHERE item_id='"&item_idPassed&"'"
set r=oConn.Execute(SQL)
if not r.eof then
response.write ("category_id=") & r("category_id") & ("&")
'//**null if
if IsNull(r("category_name")) Then
response.write ("category_name=") & r("category_name") & ("&")
else
response.write ("category_name=") & Server.URLEncode(r("category_name")) & ("&")
end if
'//**null if
if IsNull(r("item_name")) then
response.write ("item_name=") & r("item_name") & ("&")
else
response.write ("item_name=") & Server.URLEncode(r("item_name")) & ("&")
end if
'//**null if
if IsNull(r("item_description")) then
response.write ("item_description=") & r("item_description") & ("&")
else
response.write ("item_description=") & Server.URLEncode(r("item_description")) & ("&")
end if
response.write ("collection_id=") & r("collection_id") & ("&")
'//**null if
if IsNull(r("collection_name")) then
response.write ("collection_name=") & r("collection_name") & ("&")
else
response.write ("collection_name=") & Server.URLEncode(r("collection_name")) & ("&")
end if
'//**null if
if IsNull(r("collection_description")) then
response.write ("collection_description=") & r("collection_description") & ("&")
else
response.write ("collection_description=") & Server.URLEncode(r("collection_description")) & ("&")
end if
response.write ("collection_total=") & r("collection_total") & ("&")
response.write ("cost=") & r("cost") & ("&")
response.write ("amount=") & r("amount") & ("&")
response.write ("original_amount=") & r("original_amount") & ("&")
response.write ("thumbnail=") & r("thumbnail") & ("&")
response.write ("issue=") & r("issues") & ("&")
response.write ("available_date=") & r("available_date") & ("&")
response.write ("finish_date=") & r("finish_date") & ("&")
response.write ("type_item=") & r("type_item") & ("&")
response.write ("sales_status_id=") & r("sales_status_id") & ("&")
response.write ("rarity=") & r("rarity") & ("&")
response.write ("issues=") & r("issues") & ("&")
response.write ("returns=") & r("returns") & ("&")
DBResult="True"
else
DBResult="False"
end if
r.Close
set r = nothing
end if '//ending first if
if DBResult <> "False" then
response.write ("&")
end if
response.write ("DBResult=")
response.write(DBResult)
end function
'//##########################
function BuyShopItem(item_idPassed, member_name)
DBResult= False
if member_name <> "" and item_idPassed <> "" then
'// 0 (for sale), 1 (new: for sale), 2 (special: on sale), 3 (sale suspended), 4 (recall)
'//GET USER INFO
getUserInfo = "SELECT user_ex.cash_amount FROM user_ex WHERE member_name='" & member_name & "'"
Set rUser=oConn.Execute(getUserInfo)
if not rUser.eof then
cashAvailable = rUser("cash_amount")
else
purchaseItem = False
DBReason = DBReason & ",Wrong+Member+Name"
end if
'//GET ITEM COST, STATUS, AND AVAILABILITY
getShopSQL = "SELECT store.*, collection.*, categories.* FROM " &_
" categories INNER JOIN (collection INNER JOIN store ON collection.collection_id = store.collection_id) " &_
" ON categories.category_id = store.category_id WHERE item_id='"&item_idPassed&"'"
Set rStore=oConn.Execute(getShopSQL)
'//SKIP IF DATABASE CAN NOT FIND RECORD
if not rStore.EOF then
purchaseItem = True
itemCost = rStore("cost")
saleStatus = cInt(rStore("sales_status_id"))
availableNo = rStore("amount")
original_amount = rStore("original_amount")
'//DETERMINE AVAILABILITY
if availableNo = 0 then
availableResult = False
DBReason = DBReason & ",Sold+Out"
else
availableResult = True
end if
'//FILTER STATUS
if saleStatus = 0 or saleStatus = 1 or saleStatus = 2 then
statusResult = True
else if saleStatus = 3 then
statusResult = False
DBReason = DBReason & ",Sale+Suspended"
else if saleStatus = 4 then
statusResult = False
DBReason = DBReason & ",Sale+Recalled"
end if
end if
end if
'//CHECK TO SEE IF USER HAVE ENOUGH CASH
if cashAvailable < itemCost then
cashAvailableResult = False
DBReason = DBReason & ",Insufficient+Cash"
else
cashAvailableResult = True
end if
else
'//NO ITEMS WITH THAT ITEM ID IN DATABASE
purchaseItem = False
DBReason = DBReason & ",Wrong+Item+Id"
end if
'//FINAL CHECK BEFORE PROCEDING *********** <<< >>> *********
if purchaseItem = False or availableResult = False or statusResult= False or cashAvailableResult = False then
DBResult= False
else
'//PURCHASE THE ITEM
SqlInventory= "select inventory.* from inventory"
set rInventory=Server.CreateObject("ADODB.Recordset")
rInventory.open SqlInventory, oConn, 1, 3
rInventory.AddNew
rInventory.Fields("item_id") = item_idPassed
rInventory.Fields("member_name") = member_name
rInventory.Fields("original_cost") = itemCost
rInventory.Fields("asking_cost") = "0"
rInventory.Fields("trade") = False
rInventory.Fields("issue") = original_amount - availableNo + 1
rInventory.Fields("location") = "Null"
rInventory.Fields("x") = "Null"
rInventory.Fields("y") = "Null"
rInventory.Fields("z") = "Null"
rInventory.Fields("post_date") = date
rInventory.Fields("reserved") = 0
'//DISPLAY INVENTORY DATA
rInventory.Update()
inventory_id = rInventory("inventory_id")
response.write ("inventory_id=") & (inventory_id) & ("&")
'//UPDATE USER DATA
set rUserUpdate=Server.CreateObject("ADODB.Recordset")
rUserUpdate.open getUserInfo, oConn, 1, 3
rUserUpdate.Fields("cash_amount") = rUserUpdate.Fields("cash_amount") - itemCost
rUserUpdate.Update()
response.write ("cash_amount=") & rUserUpdate("cash_amount") & ("&")
'//UPDATE SHOP
set rShopUpdate=Server.CreateObject("ADODB.Recordset")
rShopUpdate.open getShopSQL, oConn, 1, 3
rShopUpdate.Fields("amount") = rShopUpdate("amount") - 1
'//DISPLAY SHOP DATA
response.write ("category_id=") & rShopUpdate("category_id") & ("&")
'//**null if
if IsNull(rShopUpdate("category_name")) Then
response.write ("category_name=") & rShopUpdate("category_name") & ("&")
else
response.write ("category_name=") & Server.URLEncode(rShopUpdate("category_name")) & ("&")
end if
'//**null if
if IsNull(rShopUpdate("item_name")) then
response.write ("item_name=") & rShopUpdate("item_name") & ("&")
else
response.write ("item_name=") & Server.URLEncode(rShopUpdate("item_name")) & ("&")
end if
'//**null if
if IsNull(rShopUpdate("item_description")) then
response.write ("item_description=") & rShopUpdate("item_description") & ("&")
else
response.write ("item_description=") & Server.URLEncode(rShopUpdate("item_description")) & ("&")
end if
response.write ("collection_id=") & rShopUpdate("collection_id") & ("&")
'//**null if
if IsNull(rShopUpdate("collection_name")) then
response.write ("collection_name=") & rShopUpdate("collection_name") & ("&")
else
response.write ("collection_name=") & Server.URLEncode(rShopUpdate("collection_name")) & ("&")
end if
'//**null if
if IsNull(rShopUpdate("collection_description")) then
response.write ("collection_description=") & rShopUpdate("collection_description") & ("&")
else
response.write ("collection_description=") & Server.URLEncode(rShopUpdate("collection_description")) & ("&")
end if
response.write ("collection_total=") & rShopUpdate("collection_total") & ("&")
response.write ("cost=") & rShopUpdate("cost") & ("&")
response.write ("amount=") & rShopUpdate("amount") & ("&")
response.write ("original_amount=") & rShopUpdate("original_amount") & ("&")
response.write ("thumbnail=") & rShopUpdate("thumbnail") & ("&")
response.write ("issue=") & rShopUpdate("issues") & ("&")
response.write ("available_date=") & rShopUpdate("available_date") & ("&")
response.write ("finish_date=") & rShopUpdate("finish_date") & ("&")
response.write ("type_item=") & rShopUpdate("type_item") & ("&")
response.write ("sales_status_id=") & rShopUpdate("sales_status_id") & ("&")
response.write ("rarity=") & rShopUpdate("rarity") & ("&")
response.write ("returns=") & rShopUpdate("returns") & ("&")
rShopUpdate.update()
'//CLOSE ALL RECORDSETS
rUserUpdate.close
rInventory.close
rShopUpdate.close
rStore.close
rUser.close
set rInventory = nothing
set rUserUpdate = nothing
set rShopUpdate = nothing
set rStore= nothing
set rUser = nothing
DBResult= True
DBReason= ",None"
end if
else
DBResult= False
DBReason= ",Missing+Parameters"
end if
if DBReason <> "" then
response.write ("DBReason=")
delExtra(DBReason)
else
response.write ("DBReason=None&")
end if
response.write("DBResult=") & (DBResult)
end function
function BuyShopPack(cost,item_id_list, member_name,debug)
DBResult= False
if member_name <> "" and cost <> "" and item_id_list <> "" then
'//SPLIT ITEMS
item_id_list = Split(item_id_list,",")
'//GET USER INFO
getUserInfo = "SELECT user_ex.cash_amount FROM user_ex WHERE member_name='" & member_name & "'"
Set rUser=oConn.Execute(getUserInfo)
if not rUser.eof then
cashAvailable = rUser("cash_amount")
else
purchaseItem = False
DBReason = DBReason & ",Wrong+Member+Name"
end if
'//FOR LOOP ALL THE ITEMS YOU PASS AND PROCEED WITH CHECKS
var = 0
For each item_id in item_id_list
'//GET ITEM COST, STATUS, AND AVAILABILITY
getShopSQL = "set transaction isolation level serializable SELECT store.* FROM store WHERE item_id='"&item_id&"'"
Set rStore=oConn.Execute(getShopSQL)
'//SKIP IF DATABASE CAN NOT FIND RECORD
if not rStore.EOF then
itemFound = True
if debug = "true" then
'//**test**
wehaveitems = True
end if
saleStatus = cInt(rStore("sales_status_id"))
availableNo = Cint(rStore("amount"))
original_amount = Cint(rStore("original_amount"))
if debug = "true" then
'//**test**
response.write("Item Id = ") & (item_id) & "<br>"
response.write("item name =") & rStore("item_name") & "<br>"
response.write("Sale Status=") & (saleStatus) & "<br>"
response.write("Available Amount=") & (availableNo) & "<br>"
response.write("Original Amount=") & (original_amount) & "<hr>"
end if
'//DETERMINE AVAILABILITY
if availableNo = 0 then
availableResult = False
DBReason = DBReason & ",Sold+Out"
else
availableResult = True
end if
'//FILTER STATUS
if saleStatus = 0 or saleStatus = 1 or saleStatus = 2 then
statusResult = True
else if saleStatus = 3 then
statusResult = False
DBReason = DBReason & ",Sale+Suspended"
else if saleStatus = 4 then
statusResult = False
DBReason = DBReason & ",Sale+Recalled"
end if
end if
end if
else
'//NO ITEMS WITH THAT ITEM ID IN DATABASE
itemFound = False
if debug = "true" then
'//**test**
wehaveitems = False
end if
DBReason = DBReason & ",Wrong+Item+Id"
end if
'// END FOR LOOP CHECKS
if debug = "true" then
'//**test**
var = var + 1
end if
Next
if debug = "true" then
response.write("itemFound(after loop)=") & (itemFound) & "<br>"
response.write("we have some or all items=") & (wehaveitems) & "<br>"
'//**test**
response.write("testing loop sequence=")
response.write(var)
response.write("<p>")
end if
'//**test**
'//CHECK TO SEE IF USER HAVE ENOUGH CASH
if debug = "true" then
'//**test**
response.write("view cash available=") & (cashAvailable) &"<br>"
response.write("view cost=") &(cost)
response.write("<p>")
end if
cashAvailable = Cint(cashAvailable)
cost = Cint(cost)
if cashAvailable < cost then
cashAvailableResult = False
DBReason = DBReason & ",Insufficient+Cash"
else
cashAvailableResult = True
end if
'//FINAL CHECK BEFORE PROCEDING *********** <<< BUY >>> *********
if debug = "true" then
response.write("statusResult=") & (statusResult) & "<br>"
response.write("availableResult=") & (availableResult) & "<br>"
response.write("cashAvailableResult=") & (cashAvailableResult) & "<br>"
response.write("itemFound=") & (itemFound) & "<br>"
end if
if itemFound = False or availableResult = False or statusResult= False or cashAvailableResult = False then
DBResult= False
else
'response.end
'//PURCHASE THE ITEM
'//FOR LOOP ALL THE ITEMS AND ADD TO INVENTORY
For each item_id in item_id_list
'//GET STORE INFO
sqlStore="select * from store where item_id="&item_id
Set getItem=oConn.execute(sqlStore)
itemCost = getItem("cost")
availableNo = getItem("amount")
original_amount = getItem("original_amount")
SqlInventory= "select inventory.* from inventory"
set rInventory=Server.CreateObject("ADODB.Recordset")
rInventory.open SqlInventory, oConn, 1, 3
rInventory.AddNew
rInventory.Fields("item_id") = item_id
rInventory.Fields("member_name") = member_name
rInventory.Fields("original_cost") = itemCost
rInventory.Fields("asking_cost") = "0"
rInventory.Fields("trade") = False
rInventory.Fields("issue") = original_amount - availableNo + 1
rInventory.Fields("location") = "Null"
rInventory.Fields("x") = "Null"
rInventory.Fields("y") = "Null"
rInventory.Fields("z") = "Null"
rInventory.Fields("post_date") = date
rInventory.Fields("reserved") = 0
'//DISPLAY INVENTORY DATA
rInventory.Update()
inventory_id = inventory_id & "," & rInventory("inventory_id")
Next
response.write ("inventory_id=")
delExtra(inventory_id)
'//UPDATE USER DATA
set rUserUpdate=Server.CreateObject("ADODB.Recordset")
rUserUpdate.open getUserInfo, oConn, 1, 3
rUserUpdate.Fields("cash_amount") = rUserUpdate.Fields("cash_amount") - cost
rUserUpdate.Update()
response.write ("cash_amount=") & rUserUpdate("cash_amount") & ("&")
'//UPDATE SHOP
'//FOR LOOP ALL THE ITEMS AND ADD TO INVENTORY
For each item_id in item_id_list
ShopSQL ="SELECT store.*, collection.*, categories.* FROM " &_
" categories INNER JOIN (collection INNER JOIN store ON collection.collection_id = store.collection_id) " &_
" ON categories.category_id = store.category_id WHERE item_id='"&item_id&"'"
set rShopUpdate=Server.CreateObject("ADODB.Recordset")
rShopUpdate.open ShopSQL, oConn, 1, 3
rShopUpdate.Fields("amount") = rShopUpdate("amount") - 1
'***************************************************************************************
'//DISPLAY SHOP DATA
category_id=category_id & ";" & rShopUpdate("category_id")
'//**null if
if IsNull(rShopUpdate("category_name")) Then
category_name=category_name & ";" & rShopUpdate("category_name")
else
category_name=category_name & ";" & Server.URLEncode(rShopUpdate("category_name"))
end if
'//**null if
if IsNull(rShopUpdate("item_name")) then
item_name=item_name & ";" & rShopUpdate("item_name")
else
item_name=item_name & ";" & Server.URLEncode(rShopUpdate("item_name"))
end if
'//**null if
if IsNull(rShopUpdate("item_description")) then
item_description=item_description & ";" & rShopUpdate("item_description")
else
item_description=item_description & ";" & Server.URLEncode(rShopUpdate("item_description"))
end if
collection_id=collection_id & ";" & rShopUpdate("collection_id")
'//**null if
if IsNull(rShopUpdate("collection_name")) then
collection_name=collection_name & ";" & rShopUpdate("collection_name")
else
collection_name=collection_name & ";" & Server.URLEncode(rShopUpdate("collection_name"))
end if
'//**null if
if IsNull(rShopUpdate("collection_description")) then
collection_description=collection_description & ";" & rShopUpdate("collection_description")
else
collection_description=collection_description & ";" & Server.URLEncode(rShopUpdate("collection_description"))
end if
collection_total=collection_total & ";" & rShopUpdate("collection_total")
cost=cost & ";" & rShopUpdate("cost")
amount=amount & ";" & rShopUpdate("amount")
original_amount=original_amount & ";" & rShopUpdate("original_amount")
thumbnail=thumbnail & ";" & rShopUpdate("thumbnail")
issues=issues & ";" & rShopUpdate("issues")
available_date=available_date & ";" & rShopUpdate("available_date")
finish_date=finish_date & ";" & rShopUpdate("finish_date")
type_item=type_item & ";" & rShopUpdate("type_item")
sales_status_id=sales_status_id & ";" & rShopUpdate("sales_status_id")
rarity=rarity & ";" & rShopUpdate("rarity")
returns=returns & ";" & rShopUpdate("returns")
'***************************************************************************************
rShopUpdate.update()
next
response.write ("category_id=")
delExtra(category_id)
response.write ("item_name=")
delExtra(item_name)
response.write ("item_description=")
delExtra(item_description)
response.write ("collection_id=")
delExtra(collection_id)
response.write ("collection_name=")
delExtra(collection_name)
response.write ("collection_description=")
delExtra(collection_description)
response.write ("collection_total=")
delExtra(collection_total)
response.write ("cost=")
delExtra(cost)
response.write ("amount=")
delExtra(amount)
response.write ("original_amount=")
delExtra(original_amount)
response.write ("thumbnail=")
delExtra(thumbnail)
response.write ("issues=")
delExtra(issues)
response.write ("available_date=")
delExtra(available_date)
response.write ("finish_date=")
delExtra(finish_date)
response.write ("type_item=")
delExtra(type_item)
response.write ("sales_status_id=")
delExtra(sales_status_id)
response.write ("rarity=")
delExtra(rarity)
response.write ("returns=")
delExtra(returns)
'//CLOSE ALL RECORDSETS
rUserUpdate.close
rInventory.close
rShopUpdate.close
rStore.close
rUser.close
set rInventory = nothing
set rUserUpdate = nothing
set rShopUpdate = nothing
set rStore= nothing
set rUser = nothing
DBResult= True
DBReason= ",None"
end if
else
DBResult= False
DBReason= ",Missing+Parameters"
end if
if DBReason <> "" then
response.write ("DBReason=")
delExtra(DBReason)
else
response.write ("DBReason=None")
end if
response.write("DBResult=") & (DBResult)
end function
'//##########################
function GetShopItemsByCategory(category_id, sales_status_id,sort,page,maxperpage)
DBResult="False"
if category_id <> "" and sales_status_id <> "" and sort <> "" and page <> "" and maxperpage <> "" then
Select case sort
case "byAvailableDate"
sort = CStr("available_date")
case "byFinishDate"
sort = CStr("finish_date")
case "none", "NONE", "None"
sort = CStr("item_name")
end select
sql = "select store.* from store " &_
" where category_id=" & category_id &" and sales_status_id=" & sales_status_id &" ORDER BY " & sort &" DESC"
set r=oConn.Execute(SQL)
if not r.eof then
while not r.eof
item_id = item_id & ";" & r("item_id")
item_name = item_name & ";" & r("item_name")
collection_id = collection_id & ";" & r("collection_id")
cost = cost & ";" & r("cost")
original_amount = original_amount & ";" & r("original_amount")
url = url & ";" & r("url")
thumbnail = thumbnail & ";" & r("thumbnail")
issue = issue & ";" & r("issue")
available_date = available_date & ";" & r("available_date")
finish_date = finish_date & ";" & r("finish_date")
rarity = rarity & ";" & r("rarity")
collection_id = collection_id & ";" & r("collection_id")
collection_name = collection_name & ";" & r("collection_name")
available_date = available_date & ";" & r("available_date")
finish_date = finish_date & ";" & r("finish_date")
r.movenext
wend
DBResult="True"
response.write ("item_id=")
delExtra(item_id)
response.write ("item_name=")
delExtra(item_name)
response.write ("collection_id=")
delExtra(collection_id)
response.write ("cost=")
delExtra(cost)
response.write ("original_amount=")
delExtra(original_amount)
response.write ("url=")
delExtra(url)
response.write ("thumbnail=")
delExtra(thumbnail)
response.write ("issue=")
delExtra(issue)
response.write ("available_date=")
delExtra(available_date)
response.write ("finish_date=")
delExtra(finish_date)
response.write ("rarity=")
delExtra(rarity)
response.write ("collection_id=")
delExtra(collection_id)
response.write ("collection_name=")
delExtra(collection_name)
response.write ("available_date=")
delExtra(available_date)
response.write ("finish_date=")
delExtra(finish_date)
else
DBResult="False"
end if
r.Close
set r = nothing
end if '//ending first if
response.write ("DBResult=")
response.write(DBResult)
end function
'//--- International Functions --
function ReturnShopItem()
end function
'//##########################
function BuyPack()
end function
'//##########################
function GetBuddiesByCategory()
end function
'//##########################
'//### Trading
function GetTradingItemsByCategory()
end function
'//##########################
function GetReservedTradingItemsByCategory()
end function
'//##########################
function GetTradingItemsByCateogryAndCost()
end function
'//##########################
function SellTradeItem()
end function
'//##########################
function BuyTradeItem()
end function
'//##########################
function CancelTradeItem()
end function
'//##########################
function GetMyUnsoldTradingItemsByCategory()
end function
'//##########################
function SwapTradeItem()
end function
'//##########################
%>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment