Infinite category Add new category code

Source: Internet
Author: User
Tags parent directory servervariables

' Infinite category Add new category code
' OrderID The order of all columns
' Rootorderid the order of the same top column
' Classorderid the order of the same parent column


If Request ("action") = "Addsave" Then

Channelid=cint (Trim (Request.Form ("Channelid"))
Parentclassid=trim (Request.Form ("ParentID"))
Classname=trim (Request.Form ("ClassName"))
Classfoldername=trim (Request.Form ("Classfoldername"))
Classmemo=trim (Request.Form ("Classmemo"))
Classkeywords=trim (Request.Form ("Classkeywords"))
Classdescription=trim (Request.Form ("Classdescription"))
Iscreatefolder=trim (Request.Form ("Iscreatefolder"))

If Classname= "" Then
Response.Write (' <script>alert (' system error. Please return to fill in the column Category name '); History.go ( -1);</script> ")
Response. End ()
End If

If Classfoldername= "" Then
Response.Write (' <script>alert (' system error. Please return to fill in the Column Category Directory folder '); History.go ( -1);</script> ")
Response. End ()
End If

If classmemo= "" Then
Response.Write (' <script>alert (' system error. Please return to fill in the Column category description '); History.go ( -1);</script> ")
Response. End ()
End If

If classkeywords= "" Then
Response.Write (' <script>alert (' system error. Please return to fill in column category search keywords '); History.go ( -1);</script> ")
Response. End ()
End If

If classdescription= "" Then
Response.Write (' <script>alert (' system error. Please return to fill in column category search descriptive word '); History.go ( -1);</script> ")
Response. End ()
End If


If isvalidwindowsfoldername (classfoldername) =false Then
Response. Write ("<script language=javascript>alert (' directory name is incorrectly formatted, return as determined"); History.back ();</script> ")
Response. End ()
End If

Classfoldername=replace (Pcase (Classfoldername), "", "-")

' Website Channel Project
Set Rs=server. CreateObject ("Adodb.recordset")
Sql= "SELECT * from Systemchannellist Where channelid=" &channelid
Rs.Open sql,conn,1,3
If rs.eof and Rs.bof then
Rs.close
Set rs=nothing
Conn.close
Set conn=nothing
Response.Write (' <script>alert (' No this channel data, the system is coming back. '); location.href= ' classlist.asp ';</script> ')
Response. End ()
Else
ChannelName =rs ("ChannelName")
Channelfolderurl=rs ("Channelfolderurl")
Channelfolderpath=rs ("Channelfolderpath")
End If
Rs.close
Set rs=nothing

Session ("Channelid") =channelid
Session ("ClassName") =classname
Session ("Classfoldername") =classfoldername
Session ("Classmemo") =classmemo
Session ("Classkeywords") =classkeywords
Session ("Classdescription") =classdescription
Session ("Iscreatefolder") =iscreatefolder



If Parentclassid=0 Then
' Add top class column
' Querying parent-class related data
Parentclassname= "" ' Parent class name
Parentclassfoldername= "" ' Parent directory Name
Parentclassdepth=0 ' Parent class depth
Newclassrootid=0 ' top class ID
Parentclassidpath=0 ' ID path

' Get the largest column that already exists ClassID
Maxclassid = Conn.execute ("Select Max (ClassID) as List1 from Softclass") ("List1")
If IsNull (MAXCLASSID) Then
Newrootorderid=1
Newclassorderid=1
Neworderid=1
Previd=0
Else
Previd=maxclassid

' Get order in the same parent column
Newclassorderid=1

' Get the order in the same top class column
Newrootorderid=1

' Get the order of all columns
Set Rs1=conn.execute ("Select Count (*) from Softclass")
If IsNull (rs1 (0)) Then
Neworderid=1
Else
Neworderid=rs1 (0) # +1
End If
Set rs1=nothing

End If

Classfolderpath=classfoldername
classlocalpath=channelfolderpath& "/" &classfolderpath
classfolderurl=channelfolderurl& "/" &replace (Classfolderpath, "/", "/")
Else
' Add Sub Class column

' Add to the first level column and add to the N-level column under two situations

' Query target parent class related data
Set Rsparent=server. CreateObject ("Adodb.recordset")
Sqlparent= "SELECT * from Softclass where classid=" &parentclassid
Rsparent.open sqlparent,conn,1,3
If rsparent.eof and Rsparent.bof then
Response.Write (' <script>alert (') failed to query the corresponding data for the parent class category. System is about to return to the previous page '); History.go ( -1);</script> ")
Response. End ()
Else
Parentclassid=rsparent ("ClassID")
Parentclassname=rsparent ("ClassName") ' Parent class name
Parentclassfoldername=rsparent ("Classfoldername") ' Parent class directory name
Parentclassfolderpath=rsparent ("Classfolderpath") ' Parent class directory name
Parentclassfolderurl=rsparent ("Classfolderurl") ' Parent class access path
Parentclassdepth=rsparent ("classdepth") ' Parent class depth
Parentclassidpath=rsparent ("Parentidpath")
Child=rsparent ("Child")

If Parentclassdepth=0 then ' if the target parent column is a level column

Oldclassrootid=rsparent ("Rootid") ' Original Rootid
Newclassrootid=rsparent ("ClassID") ' latest Rootid

If Child>0 then ' if Add column to have sub column of the first level column

' Get the upcoming columns ClassID
Maxclassid = Conn.execute ("Select Max (ClassID) as List1 from Softclass where parentid=" &parentclassid) ("List1")
Previd=maxclassid

' Get the order in the child columns of the same parent class
Set Rs1=conn.execute ("Select Max (Classorderid) from Softclass where parentid=" &parentclassid)
If IsNull (rs1 (0)) Then
Newclassorderid=1
Else
Newclassorderid=rs1 (0) # +1
End If
Set rs1=nothing

' Get the order of the columns in the same top class
Set Rs1=conn.execute ("Select Max (Rootorderid) from Softclass where Parentidpath like '" &ParentClassIDPath& "," & amp;newclassrootid& ",% '")
If IsNull (rs1 (0)) Then
Newrootorderid=conn.execute ("Select Rootorderid,classid from Softclass where classid=" &maxclassid) ("RootOrderID ") +1
Else
Newrootorderid=rs1 (0) # +1
End If
Set rs1=nothing

' Get the order in all columns

Set Rs1=conn.execute ("Select Max (OrderID) from Softclass where Parentidpath like '" &ParentIDPath& "," & maxclassid& ",% ' and rootid>0")
If IsNull (rs1 (0)) Then
Neworderid=conn.execute ("Select Orderid,classid from Softclass where classid=" &MaxClassID& "and Rootid>0") ("OrderID") +1
Else
Neworderid=rs1 (0) # +1
End If
Set rs1=nothing

' Update the other back column rootid,classid corresponding Rootorderid,classorderid,orderid
' Rootorderid,classorderid don't need to move either.
Conn.execute ("Update softclass set rootorderid=rootorderid+1 where rootorderid>=" &newrootorderid)

Conn.execute ("Update softclass set orderid=orderid+1 where orderid>=" &neworderid)

Else ' If the target column has no sub columns

Previd=0
newrootorderid=2
Newclassorderid=1
' Get the order in all columns
Set Rs1=conn.execute ("Select Max (OrderID) from Softclass where Parentidpath like '" &ParentIDPath& "," & maxclassid& ",% ' and rootid>0")
If IsNull (rs1 (0)) Then
neworderid=2
Else
Neworderid=rs1 (0) # +1
End If
Set rs1=nothing


' Update the other back column rootid,classid corresponding Rootorderid,classorderid,orderid
' Rootorderid,classorderid don't need to move either.
Conn.execute ("Update softclass set orderid=orderid+1 where orderid>=" &neworderid)

End If

Else

' If the target parent class is N-Class column classdepth>1 level
Newclassrootid=rsparent ("Rootid")
Oldclassrootid=rsparent ("Rootid") ' latest Rootid
Response. Write ("<br>" &oldclassrootid)
Topclassrootid=conn.execute ("Select Rootid,classid from Softclass where classid=" &oldclassrootid) ("RootID")
Response. Write ("<br>" &topclassrootid)

If Child>0 then ' if the target N-level parent column already exists in the child column

' Get the upcoming columns ClassID
Maxclassid = Conn.execute ("Select Max (ClassID) as List1 from Softclass where parentid=" &parentclassid) ("List1")
Previd=maxclassid
' Get order in the same parent column
Set Rs1=conn.execute ("Select Max (Classorderid) from Softclass where parentid=" &parentclassid)
Newclassorderid=rs1 (0) # +1
Set rs1=nothing

' Get the order of the columns in the same top class

Set Rs1=conn.execute ("Select Max (Rootorderid) from Softclass where Parentidpath like '" &ParentIDPath& "," & maxclassid& ",% '")

If IsNull (rs1 (0)) Then
Newrootorderid=conn.execute ("Select Rootorderid,classid from Softclass where classid=" &maxclassid) (0) # +1
Else
Newrootorderid=rs1 (0) # +1
End If
Set rs1=nothing

' Get order in all columns
Set Rs1=conn.execute ("Select Max (OrderID) from Softclass where Parentidpath like '" &ParentIDPath& "," & maxclassid& ",% '")

If IsNull (rs1 (0)) Then
Neworderid=conn.execute ("Select Orderid,classid from Softclass where classid=" &maxclassid) (0) # +1
Else
Neworderid=rs1 (0) # +2
End If
Set rs1=nothing

' Update the other back column rootid,classid corresponding Rootorderid,classorderid,orderid
' Rootorderid,classorderid don't need to move either.
Conn.execute ("Update softclass set rootorderid=rootorderid+1 where rootorderid>=" &newRootOrderID& "and Rootid= "&oldclassrootid)
Conn.execute ("Update softclass set orderid=orderid+1 where orderid>=" &neworderid)

Else ' If the target N-level parent column does not exist a sub column

Previd=0
' Get order in the same parent column
Newclassorderid=1

' Get the order in the same top class column
' If there is a sub column in front, and the child column has other sub columns
Set Rs1=conn.execute ("Select Max (Rootorderid) from Softclass where Parentidpath like '" &ParentClassIDPath& ",% ' ")
If IsNull (rs1 (0)) Then
Newrootorderid=conn.execute ("Select Max (Rootorderid) from Softclass where classdepth=" &ParentClassDepth& ") (0) # +1
Else
Newrootorderid=rs1 (0) # +1
End If

Set rs1=nothing
Response. Write ("<br>" &newrootorderid)
Response. Write ("<br>" &topclassrootid)
Conn.execute ("Update softclass set rootorderid=rootorderid+1 where rootorderid>=" &newRootOrderID& "and Rootid= "&oldclassrootid)

' Get order in all columns
Neworderid=conn.execute ("Select Orderid,classid from Softclass where classid=" &parentclassid) ("OrderID") +1


' Update the other back column rootid,classid corresponding Rootorderid,classorderid,orderid
' Rootorderid,classorderid don't need to move either.
Conn.execute ("Update softclass set orderid=orderid+1 where orderid>=" &neworderid)
' Conn.execute ("Update softclass set orderid=orderid+1 where rootid>" &topClassRootID& "and Parentid=0")
' Conn.execute ("Update softclass set orderid=orderid+1 where rootid>" &oldClassRootID& "and Parentid>0")
End If

End If

End If

Rsparent.close
Set rsparent=nothing

' Get current path-related parameters from parent class data
classfolderpath=parentclassfolderpath& "/" &classfoldername
classlocalpath=channelfolderpath& "/" &classfolderpath
classfolderurl=channelfolderurl& "/" &replace (Classfolderpath, "/", "/")

End If

' Create the corresponding category directory
If Iscreatefolder=1 Then
CreateFolder Classlocalpath,iscreatefolder
End If

' Response. Write ("<br>" &neworderid)
' Response. Write ("<br>" &newrootorderid)
' Response. Write ("<br>" &newclassorderid)

' Add new data and modify related field values

Userip = Request.ServerVariables ("Http_x_forwarded_for")
If Userip = "" Then Userip = Request.ServerVariables ("REMOTE_ADDR")
Userfrom=cstr (Request.ServerVariables ("Http_referer"))

Correctsqlclassfoldername=replace (Classfoldername, "'", "" ")
Correctsqlclassname=replace (ClassName, "'", "" ")
Set Rs=server. CreateObject ("Adodb.recordset")
Sql= "SELECT * from Softclass where classfoldername= '" &CorrectSqlClassFolderName& "' and Classname= '" & correctsqlclassname& "' and parentid= ' &parentclassid
Rs.Open sql,conn,3,3
If not rs.eof and not Rs.bof then
Rs.close
Set rs=nothing
Conn.close
Set conn=nothing
Response.Write (' <script>alert (' This column category data already exists. System coming back '); History.go ( -1);</script> ")
Response.End
Else
Rs.addnew

RS ("Channelid") =channelid
RS ("ChannelName") =channelname
RS ("Channelfolderpath") =channelfolderpath
RS ("Channelfolderurl") =channelfolderurl

If Parentclassid=0 Then
' Level of directory depth is 0
RS ("parentname") = ""
RS ("ParentID") =0
RS ("classdepth") =0
RS ("Parentidpath") = "0"
Else
RS ("ParentName") =parentclassname
RS ("ParentID") =parentclassid



RS ("Classdepth") =cint (parentclassdepth) +1
RS ("Parentidpath") =parentclassidpath& "," &parentclassid
End If
RS ("OrderID") =neworderid
RS ("Rootorderid") =newrootorderid
RS ("Classorderid") =newclassorderid
RS ("Rootid") =newclassrootid
RS ("Previd") =previd

RS ("ClassName") =classname
RS ("Classfoldername") =classfoldername
RS ("Classfolderpath") =classfolderpath
RS ("Classlocalpath") =classlocalpath

RS ("Classmemo") =classmemo
RS ("Classkeywords") =classkeywords
RS ("Classdescription") =classdescription
RS ("Iscreatefolder") =iscreatefolder



RS ("AddUser") =session ("Managerusername")
RS ("Addtime") =now ()
RS ("Addip") =userip
RS ("Addfrom") =userfrom
Rs.update
End If
Rs.close
Set rs=nothing
Newclassid=conn.execute ("Select Classid,orderid from Softclass where orderid=" &neworderid) ("ClassID")
' Update the ' NextID ' field value of the previous column in the same parent column
If Previd>0 Then
Conn.execute ("Update softclass set nextid=" & Newclassid & "where classid=" & Previd)
End If

If Parentclassid>0 Then
' Update the number of sub columns in the parent column
Child=conn.execute ("Select Count (*) as List1 from Softclass where parentid=" &parentclassid) ("List1")
Conn.execute ("Update softclass Set child=" &Child& "where classid=" &parentclassid)
End If

Conn.close
Set conn=nothing
Response.Write ("<script>alert" column category "&ClassName&" added complete. System is about to return to the list '); location.href= ' classlist.asp ';</script> ')
Response. End ()
End If

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.