<% 	Dim action,ModeID,Rs,danwei,MakeFolderDir,AutoPage,admintemplatevalue,usertemplatevalue,umr,def
	ModeID = skweboa.Return_to_numerical(Request("ModeID")):umr = skweboa.Return_to_numerical(Request("umr")):def = skweboa.Return_to_numerical(Request("def"))
	action = Request.QueryString("A")
	 if ModeID=0 or ModeID="" Then ModeID=1
	Select Case action
		   Case "AddSave","ESave"
		   		Call AddSave()
			Case "Add","E"
				Call AddEdit()
	End Select
	IF action = "Del" Then		
	Dim rs1
		IF ModeID  > 4 Then
			Set rs1=skweboa.SK_axe("select id,classid,modeid from class_skweb where modeid="& ModeID)
			Do While Not rs1.eof
						Dim rsp
						Set rs = skweboa.SK_axe("Select * From "&skweboa.SK_Mroot(rs1("modeid"),2)&" Where ClassID ='" & rs1("classid") & "'")
						Do While Not rs.eof
									Dim Tmps,TmpUs 
									If Right(skweboa.SK_Mroot(rs1("modeid"),10),1)<>"/" Then 
											Call skweboa.SKDelFile(MyDbPath&rs("FileName")&skweboa.SK_Mroot(rs1("modeid"),11))
									Else
											Call skweboa.SKDelFile(MyDbPath&rs("FileName")&"/Index"&skweboa.SK_Mroot(rs1("modeid"),11))
									End If 
									Conn.execute("Delete from Comment_skweb  Where skwebicleID=" & rs("id") & " and ModeID="&rs1("modeid")&"")
									Conn.execute("Delete from Digg_skweb  Where NewsID=" & rs("id") & " and modeid="&rs1("modeid")&"")
									Conn.execute("Delete from "&skweboa.SK_Mroot(rs1("modeid"),2)&"  Where ID=" & rs("id") & "")
						rs.movenext
						loop
									Conn.execute("Delete from class_skweb  Where ID=" & rs1("id") )  '删除栏目
			rs1.movenext
			loop
			skweboa.SK_axe("Delete From Mode_skweb Where ModeID=" & ModeID)	
			skweboa.SK_axe("Delete From Table_skweb Where ModeID=" & ModeID)	 '删除字段
			Conn.execute("Drop table "&skweboa.SK_Mroot(ModeID,2)&"") '删除数据表
			Call skweboa.SKDelFile(MyDbPath&"SKCMS/Mode/"&skweboa.SK_Mroot(ModeID,0))  '删除配置文件夹
			Call skweboa.SK_window("删除模型成功",""&MyDbPath&""&skweboa.SK_sys(23)&"/Mode/","","3")	
 		Else
		 	Call skweboa.SK_window("系统定义的模型不允许删除","","1","3")	
 		End IF
	End IF
	Sub AddSave()
	  	 Dim ModeName,ModeTable,sql,rs2,rs2Sql,ModeNote,IFmake
		 Dim UpfilesDir,RecyleIF,CommentCode,Commentsize,WriteComment,CommentTemp,gg,xsfs,xssl
		 Dim SK_userICOb,adminmb
		 ModeName = skweboa.S("ModeName")
		 ModeTable = skweboa.S("ModeTable")&"_U_skweb"
		 ModeNote = skweboa.S("ModeNote")
 		 SK_userICOb=skweboa.Return_to_numerical(skweboa.S("SK_userICOb"))
		 adminmb=skweboa.Return_to_numerical(skweboa.S("adminmb"))
		 IFmake = skweboa.S("IFmake")
		 UpfilesDir = skweboa.S("UpfilesDir")
		 RecyleIF = skweboa.S("RecyleIF")
		 danwei = skweboa.S("danwei")
		 MakeFolderDir = skweboa.S("MakeFolderDir")
 		 AutoPage = skweboa.Return_to_numerical(skweboa.S("AutoPage"))
		 CommentCode = skweboa.Return_to_numerical(skweboa.S("CommentCode"))
		 Commentsize = skweboa.Return_to_numerical(skweboa.S("Commentsize"))
		 WriteComment = skweboa.Return_to_numerical(skweboa.S("WriteComment"))
		 CommentTemp = skweboa.S("CommentTemp")
          xsfs=skweboa.S("xsfs")
	      xssl=skweboa.S("xssl")
		 If adminmb="1" Then 
 			admintemplatevalue=	skweboa.FSOSaveASP(request.form("admintemplatevalue"),MyDbPath&"SKCMS/Mode/"&ModeID&"/admin.inc")
		 End If 
		 If SK_userICOb="1" Then 
 			usertemplatevalue=	skweboa.FSOSaveASP(request.form("usertemplatevalue"),MyDbPath&"SKCMS/Mode/"&ModeID&"/user.inc")
		 End If 

		 IF skweboa.S("ModeName") = "" Then
		 Call skweboa.SK_window("模型名称不能为空!","","","2"):Exit Sub
		 End If
		 Set rs2 = Server.CreateObject("adodb.recordset")
  if action="AddSave" Then		
  Else '修改模型		 
		 	If Not skweboa.SK_axe("SELECT ModeName FROM Mode_skweb Where ModeID <>" & ModeID & " AND  ModeName='" & ModeName & "' order by ModeID desc").eof Then
			Call skweboa.SK_window("系统已存在该模型名称!","","","2"):Exit Sub
			 End if	
			  rs2Sql = "select * from Mode_skweb Where ModeID=" &ModeID
			  rs2.Open rs2Sql, Conn, 1, 3
			  if rs2.eof then 	Call skweboa.SK_window("错误!","","","2")	:Exit Sub
		 End if 
		 If skweboa.Return_to_numerical(skweboa.S("adminmb"))="1" Then 
 			Call skweboa.FSOSaveASP(request.form("admintemplatevalue"),MyDbPath&"SKCMS/Mode/"&ModeID&"/admin.inc")
		 End If 
		 If SK_userICOb="1" Then 
 			usertemplatevalue=	skweboa.FSOSaveASP(request.form("usertemplatevalue"),MyDbPath&"SKCMS/Mode/"&ModeID&"/user.inc")
		 End If 
		  rs2("ModeName") = ModeName
		  rs2("ModeNote") = ModeNote
		  rs2("IFmake") = IFmake
		  rs2("RecyleIF") = RecyleIF
		  rs2("UpfilesDir") = UpfilesDir
		  rs2("danwei") = danwei
		  rs2("MakeFolderDir") = MakeFolderDir
		  rs2("AutoPage") = AutoPage
 		  rs2("SK_userICOb")=SK_userICOb
		  rs2("adminmb")=adminmb
		  rs2("xsfs")=xsfs
		  rs2("xssl")=xssl 	
		  if Request.Form("gg")="" then
		  rs2("gg")=0		  
		  else
		  rs2("gg")=Request.Form("gg")	
		  end if
		  rs2.Update
		  rs2.Close:Set rs2 = Nothing	
		  Application.Contents.RemoveAll
	     Dim DIY_Article,i
	     For I=0 To 38
		 DIY_Article=DIY_Article& Replace(Replace(request.Form("skweboa_D" & I &""),"§","") & "§",",","")
	     Next
		 Call skweboa.FSOSaveASP(DIY_Article,""&MyDbPath&"SKCMS/Mode/"&ModeID&"/sk.cs")
  		 Call skweboa.SK_window("模型修改成功",""&MyDbPath&"SKCMS/dialog.asp?action=clos","","3")
	End Sub
	Sub AddEdit()
	Dim ModeTable,ModeName,IFmake,RecyleIF,UpfilesDir,ModeNote,A,WriteComment,CommentCode,Commentsize
	Dim CommentTemp,SK_userICOb,adminmb
	if action="Add" Then
	UpfilesDir="other/"
	AutoPage=0 : A="AddSave":WriteComment=3:CommentCode=0:Commentsize=0:xsfs=0:xssl=20:danwei="篇":ModeNote=1:MakeFolderDir=""
	Else
	Set Rs=server.CreateObject("adodb.recordset") 
	Rs.OPen "Select * from Mode_skweb Where ModeID = "&ModeID&" order by ModeID desc",Conn,1,1
	ModeTable = Rs("ModeTable")
	ModeName = Rs("ModeName")
	IFmake = Rs("IFmake")
	RecyleIF = Rs("RecyleIF")
	UpfilesDir=Rs("UpfilesDir")
	ModeNote=Rs("ModeNote")
	gg=Rs("gg")
	danwei=Rs("danwei")
	MakeFolderDir=Rs("MakeFolderDir")
	AutoPage=Rs("AutoPage")
    SK_userICOb=Rs("SK_userICOb")
	adminmb=Rs("adminmb")
	xsfs=Rs("xsfs")
	xssl=Rs("xssl")	
	If adminmb="1" Then 
 		admintemplatevalue=Server.HTMLEncode(skweboa.SK_Temporarily_style(MyDbPath&"SKCMS/Mode/"&ModeID&"/admin.inc","utf-8"))
	End If 
	If SK_userICOb="1" Then 
 		usertemplatevalue=Server.HTMLEncode(skweboa.SK_Temporarily_style(MyDbPath&"SKCMS/Mode/"&ModeID&"/user.inc","utf-8"))
	End If 
	If request("def")="1" Then 
			admintemplatevalue=M.skweb_NoRormMXList(ModeID)
			adminmb=1
 	End If 
	If adminmb=1 Then def=1
	If SK_userICOb=1 Then umr=1
	If request("umr")="1" Then 
			usertemplatevalue=M.skwebUser_MXList(ModeID)
			SK_userICOb=1
 	End If 
	A="ESave"
	end If
    skweboa_D=Split(skweboa.SK_Temporarily_style(MyDbPath&"SKCMS/Mode/"&ModeID&"/sk.cs","utf-8"),"§")
	%>