Report abuse

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<!-- #include file="conn.asp" -->
<%
'-------------------------------------------------------------------------
'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 #1
  '-------------------------------------------------------------------------
  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
%>