<!--
<%
'-------------------------------------------------------------------------
'Variables and data
'-------------------------------------------------------------------------
data = Request.Form("data") 'The new positions
group = cInt(Request.Form("toGroup")) 'To what group should we send the card?
fromGroup = cInt(Request.Form("fromGroup")) 'This is used to chech whether the group is 1 or not, if so: check amount of cards
groupType = Request.Form("type")
'-------------------------------------------------------------------------
'Check if the change is occurring in a theme or a group
'-------------------------------------------------------------------------
If groupType = "theme" then
sqlField = "_theme"
Else
sqlField = "_group"
End If
'-------------------------------------------------------------------------
'Remove the 'cards[]=' from the sReq, that leaves us with numers seperated
'with '&' only.
'-------------------------------------------------------------------------
With New RegExp
.Pattern = "cards\[\]\="
.IgnoreCase = True
.Global = True
newData = .Replace(data,"")
End With
'-------------------------------------------------------------------------
'Create an array of the string, split with '&'
'This array will now contain the ID:s of the cards, in new order
'Example, the string looks like this: 1&2&3 and will become: Array(1,2,3)
'-------------------------------------------------------------------------
dataArray = Split(newData,"&")
'-------------------------------------------------------------------------
'If aReq is an array, save the data
'-------------------------------------------------------------------------
If IsArray(dataArray) Then
'-------------------------------------------------------------------------
'Open DB connection
'-------------------------------------------------------------------------
Set cCon = New Connections
'-------------------------------------------------------------------------
'Check if the dropped to group is
'-------------------------------------------------------------------------
If fromGroup = 1 AND NOT groupType = "theme" Then
'-------------------------------------------------------------------------
' Check if this card is the last one in group 1
'-------------------------------------------------------------------------
amountCards = cCon("SELECT COUNT(*) FROM cards WHERE _group = 1 AND ISNULL(_theme)")(0,0)
If cint(amountCards) <= 1 Then
continue = false
Else
continue = true
End If
Else
continue = true
End If
'-------------------------------------------------------------------------
'Get the theme ID
'-------------------------------------------------------------------------
If groupType = "theme" Then
group = cCon("SELECT _id FROM theme WHERE _active = 1 ORDER BY _created DESC LIMIT 1")(0,0)
resetTheme = ""
Else
resetTheme = ", _theme = NULL"
End If
'-------------------------------------------------------------------------
'Update current position.
'-------------------------------------------------------------------------
If(continue) Then
For i = 0 To Ubound(dataArray) Step 1
'-------------------------------------------------------------------------
'If this a theme card, check if it's allowed to be transfered
'If yes, then check if this card has already been transfered
'-------------------------------------------------------------------------
If groupType = "theme" Then
aThemeCard = cCon("SELECT _id FROM theme_cards WHERE _theme = "&group&" AND _set = 1 AND _card = "&dataArray(i))
If Not IsArray(aThemeCard) Then
cCon("UPDATE cards SET _order = "&i+1&", "&sqlField&" = "&group&resetTheme&" WHERE _id = " & dataArray(i))
Response.Write("1")
End If
Else
cCon("UPDATE cards SET _order = "&i+1&", "&sqlField&" = "&group&resetTheme&" WHERE _id = " & dataArray(i))
Response.Write("2")
End If
Next
Else
Response.Write("No")
End If
'-------------------------------------------------------------------------
'Close DB connection
'-------------------------------------------------------------------------
Set cCon = Nothing
Else
Response.Write("No")
End If
%>