/db/admin/cat_edit.asp

https://github.com/semious/dynacomcorp · ASP · 328 lines · 308 code · 20 blank · 0 comment · 65 complexity · 38328df0f01b9f3b99f08ca98ea40249 MD5 · raw file

  1. <!--#include file="conn.asp"-->
  2. <%
  3. Response.Buffer = True
  4. Response.ExpiresAbsolute = Now() - 1
  5. Response.Expires = 0
  6. Response.CacheControl = no-cache
  7. dim action,id,sql
  8. dim rs
  9. dim flag
  10. dim i
  11. dim sub_array
  12. dim msg
  13. dim rs1
  14. dim item_a
  15. item_a = ""
  16. msg=""
  17. set rs =server.createobject("adodb.recordset")
  18. set rs1 =server.createobject("adodb.recordset")
  19. action=trim(cstr(request("action")))
  20. id=trim(cstr(request("id")))
  21. if action="" or id = "" then
  22. response.write("0")
  23. response.End()
  24. end if
  25. if action = "get" then
  26. rs.open "select * from cat where id=" & id,conn
  27. if rs.eof then
  28. response.End()
  29. else
  30. response.Write(cstr(rs("name"))+"|"+trim(cstr(rs("des")))+"|"+trim(cstr(rs("pic"))))
  31. response.End()
  32. end if
  33. rs.close
  34. response.End()
  35. end if
  36. if action = "update" then
  37. dim name,des,pic
  38. name=trim(cstr(request("name")))
  39. des=trim(cstr(request("des")))
  40. pic=trim(cstr(request("pic")))
  41. name=replace(name,"'","''")
  42. des=replace(des,"'","''")
  43. pic=replace(pic,"'","''")
  44. sql = "update cat set "
  45. sql = sql + "name='" + name +"',"
  46. sql = sql + "des='" + des + "',"
  47. sql = sql + "pic='" + pic + "' "
  48. sql = sql + " where id = " & id
  49. conn.execute sql
  50. response.Write("1")
  51. response.End()
  52. end if
  53. if action = "getsub" then
  54. rs.open "select * from cat where id="& id,conn
  55. if rs.eof then
  56. response.End()
  57. else
  58. if rs("dncat")<>"0" and rs("dncat")<>"" then
  59. sub_array = split(rs("dncat"),"|")
  60. rs.close
  61. for i= 1 to ubound(sub_array)-1
  62. rs.open "select * from cat where id = " & sub_array(i),conn
  63. if not rs.eof then
  64. msg = msg + cstr(rs("name")) + "|" + cstr(rs("id")) + "|"
  65. end if
  66. rs.close
  67. next
  68. response.Write("1"+"@"+msg)
  69. response.End()
  70. end if
  71. if (rs("dncat")="0" or rs("dncat")="") and (rs("p_id")<>"0" and rs("p_id")<>"") then
  72. sub_array = split(rs("p_id"),"|")
  73. rs.close
  74. for i= 1 to ubound(sub_array)-1
  75. rs.open "select * from product where id = " & sub_array(i),conn
  76. if not rs.eof then
  77. msg = msg + cstr(rs("name")) + "|" + cstr(rs("id")) + "|"
  78. end if
  79. rs.close
  80. next
  81. response.Write("2"+"@"+msg)
  82. response.End()
  83. end if
  84. if (rs("dncat")="0" or rs("dncat")="") and (rs("p_id")="0" or rs("p_id")="") then
  85. response.Write("0@0")
  86. response.End()
  87. end if
  88. end if
  89. rs.close
  90. response.End()
  91. end if
  92. if action = "getrank" then
  93. dim rank
  94. rs.open "select * from cat where id="& id &" order by name",conn
  95. if rs.eof then
  96. response.End()
  97. else
  98. if rs("rank")<3 then
  99. rank = cint(cstr(rs("rank")))+1
  100. rs.close
  101. rs.open "select * from cat where rank = '"+cstr(rank)+"' order by name"
  102. if not rs.eof then
  103. while not rs.eof
  104. if msg="" then
  105. msg = trim(cstr(rs("name"))) + "|" + trim(cstr(rs("id")))
  106. else
  107. msg = msg + "|" + trim(cstr(rs("name"))) + "|" + trim(cstr(rs("id")))
  108. end if
  109. rs.movenext
  110. wend
  111. end if
  112. rs.close
  113. response.Write(msg)
  114. response.End()
  115. else
  116. rs.close
  117. rs.open "select * from product order by name"
  118. if not rs.eof then
  119. while not rs.eof
  120. if msg="" then
  121. msg = trim(cstr(rs("name"))) + "|" + trim(cstr(rs("id")))
  122. else
  123. msg = msg + "|" + trim(cstr(rs("name"))) + "|" + trim(cstr(rs("id")))
  124. end if
  125. rs.movenext
  126. wend
  127. end if
  128. rs.close
  129. response.Write(msg)
  130. response.End()
  131. end if
  132. end if
  133. rs.close
  134. response.End()
  135. end if
  136. if action = "updateadditem" then
  137. dim subi
  138. dim items
  139. flag=0
  140. subi=trim(cstr(request("subi")))
  141. rs.open "select * from cat where id = " & id,conn,1,3
  142. if not rs.eof then
  143. if rs("rank")<3 then
  144. items = split(cstr(rs("dncat")),"|")
  145. for i = lbound(items) to ubound(items)
  146. if trim(cstr(items(i))) = trim(cstr(subi)) then
  147. flag=1
  148. exit for
  149. end if
  150. next
  151. if flag=0 then
  152. if rs("dncat")="" or rs("dncat") = "0" then
  153. rs("dncat") = "|"+subi+"|"
  154. else
  155. rs("dncat") = rs("dncat") + subi +"|"
  156. end if
  157. rs.update
  158. rs.close
  159. response.Write("1")
  160. response.End()
  161. else
  162. response.Write("1")
  163. response.End()
  164. end if
  165. else
  166. items = split(cstr(rs("p_id")),"|")
  167. for i = lbound(items) to ubound(items)
  168. if trim(cstr(items(i))) = trim(cstr(subi)) then
  169. flag=1
  170. exit for
  171. end if
  172. next
  173. if flag = 0 then
  174. if rs("p_id")="" or rs("p_id")= "0"then
  175. rs("p_id") = "|"+subi+"|"
  176. else
  177. rs("p_id") = rs("p_id") + subi +"|"
  178. end if
  179. rs.update
  180. rs.close
  181. response.Write("1")
  182. response.End()
  183. else
  184. response.Write("1")
  185. response.End()
  186. end if
  187. end if
  188. end if
  189. rs.close
  190. response.End()
  191. end if
  192. if action = "updateitem" then
  193. flag=0
  194. subi=trim(cstr(request("subi")))
  195. rs.open "select * from cat where id=" & id,conn,1,3
  196. if not rs.eof then
  197. if rs("rank")<3 then
  198. items = split(cstr(rs("dncat")),"|")
  199. for i = lbound(items) to ubound(items)
  200. if trim(cstr(items(i))) = trim(cstr(subi)) then
  201. items(i)=""
  202. exit for
  203. end if
  204. next
  205. for i = lbound(items) to ubound(items)
  206. if trim(cstr(items(i))) <> "" then
  207. item_a = item_a + "|" + items(i)
  208. end if
  209. next
  210. if item_a = "" then
  211. item_a = "0"
  212. else
  213. item_a = item_a + "|"
  214. end if
  215. rs("dncat") = cstr(item_a)
  216. rs.update
  217. rs.close
  218. response.Write("1")
  219. response.End()
  220. else
  221. items = split(cstr(rs("p_id")),"|")
  222. for i = lbound(items) to ubound(items)
  223. if trim(cstr(items(i))) = trim(cstr(subi)) then
  224. items(i)=""
  225. exit for
  226. end if
  227. next
  228. for i = lbound(items) to ubound(items)
  229. if trim(cstr(items(i))) <> "" then
  230. item_a = item_a + "|" + items(i)
  231. end if
  232. next
  233. if item_a = "" then
  234. item_a = "0"
  235. else
  236. item_a = item_a + "|"
  237. end if
  238. rs("p_id") = cstr(item_a)
  239. rs.update
  240. rs.close
  241. response.Write("1")
  242. response.End()
  243. end if
  244. end if
  245. rs.close
  246. response.End()
  247. end if
  248. if action = "getitem" then
  249. rs.open "select * from cat where id = " & id,conn
  250. if rs.eof then
  251. response.End()
  252. else
  253. if rs("rank")<3 then
  254. rs.close
  255. rs.open "select * from cat where id = " & cstr(id)
  256. if not rs.eof then
  257. if rs("dncat")<>"" and rs("dncat")<>"0" then
  258. sub_array = split(rs("dncat"),"|")
  259. for i = 1 to ubound(sub_array)-1
  260. rs1.open "select * from cat where id=" & cstr(sub_array(i)),conn
  261. if not rs1.eof then
  262. if msg = "" then
  263. msg = trim(cstr(rs1("name"))) + "|" + trim(cstr(rs1("id")))
  264. else
  265. msg = msg + "|" + trim(cstr(rs1("name"))) + "|" + trim(cstr(rs1("id")))
  266. end if
  267. end if
  268. rs1.close
  269. next
  270. else
  271. response.Write("0")
  272. response.End()
  273. end if
  274. end if
  275. rs.close
  276. response.Write(msg)
  277. response.End()
  278. else
  279. rs.close
  280. rs.open "select * from cat where id = " & cstr(id)
  281. if not rs.eof then
  282. if rs("p_id")<>"" and rs("p_id")<>"0" then
  283. sub_array = split(rs("p_id"),"|")
  284. for i = 1 to ubound(sub_array)-1
  285. rs1.open "select * from product where id = " & cstr(sub_array(i)),conn
  286. if not rs1.eof then
  287. if msg = "" then
  288. msg = trim(cstr(rs1("name"))) + "|" + trim(cstr(rs1("id")))
  289. else
  290. msg = msg + "|" + trim(cstr(rs1("name"))) + "|" + trim(cstr(rs1("id")))
  291. end if
  292. end if
  293. rs1.close
  294. next
  295. else
  296. response.Write("0")
  297. response.End()
  298. end if
  299. end if
  300. rs.close
  301. response.Write(msg)
  302. response.End()
  303. end if
  304. end if
  305. rs.close
  306. response.End()
  307. end if
  308. %>