<!--#include file="Inc/Config.asp" -->
<%
Server.ScriptTimeOut=99999999
'''''''''''''''''''''''''''''''''''''''''''''''''''''''
'SQL版CIXIBLOG2.0 TO CITYBLOG1.0升级程序=============='
'程序作者:陈若帆 Oicq:26092554===+++++++++++++++++++++'
'升级前请先做好备份==000000000000000000000000000000000'
'升级前请先查看升级帮助,做好升级准备'11111111111111111'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim UserRs,Article_ByMonth,StrIngs,UserID
Dim RegExpObj,BodyText,ARTID,LinkRs,TBUser_Name 
Dim TBBlog_Name,BlogTopTitle,PhotoToARs,SqlString
DIM User8,User1,User2,User9,User3,User7

Sub UpdateAB()
	Conn.Execute("update Article Set Isphoto=0 Where Isphoto Is Null")
	Conn.Execute("Update Tb_User Set User_Sex='男' Where User_Sex='' Or User_Sex='M'")
	Conn.Execute("Update Tb_User Set User_Sex='女' Where User_Sex='F'")
	Conn.Execute("Update Tb_User Set Blog_Title='我写,我读,我博客...' Where Blog_Title=''")
	Conn.Execute("Update Article Set Whather='晴' Where Whather='1'")
	Conn.Execute("Update Article Set Whather='雪' Where Whather='0'")
	Conn.Execute("Update Article Set Whather='雪' Where Whather='5'")
	Conn.Execute("Update Article Set Whather='多云' Where Whather='2'")
	Conn.Execute("Update Article Set Whather='雨' Where Whather='7'")
	Conn.Execute("Update Article Set Whather='雨' Where Whather='3'")
	Conn.Execute("Update Article Set Whather='多云转晴' Where Whather='6'")
	Conn.Execute("Update Article Set Whather='台风' Where Whather='4'")
End Sub
Sub UPPHOTOCLASS()'复制相册分类到文章分类表
	Set PhotoToARs=Conn.ExeCute("Select User_ID,PhotoClass From Tb_Photo_Class Order By ID")
	Do While Not PhotoToARs.Eof
		Conn.Execute("INSERT INTO [Tb_User_Class](User_id,Blog_Class,Photo) VALUES("& PhotoToARs(0) &",'"& PhotoToARs(1) &"',1)")
	PhotoToARs.MoveNext
	Loop
	PhotoToARs.Close:Set PhotoToARs=Nothing
End Sub
Sub PhotoToArticle()'复制相册到文章表
	Conn.ExeCute("Update Article Set Article_ByClass='0000000默认分类' Where Article_ByClass='Default' Or Article_ByClass='默认分类'")
	Set PhotoToARs=Conn.ExeCute("Select PhotoID,User_ID,Photo_Class,Photo,PhotoTitle,PhotoInfo,PhotoTop,PhotoDate,SeeCount,ReCount,(SELECT User_Name From Tb_User Where ID=Tb_Photo.User_id) From Tb_Photo Order By PhotoID")
	Do While Not PhotoToARs.Eof
			SqlString="INSERT INTO [Article] (User_ID,User_Name,Article_Title,Article_Zy,Blog_Info,Whather,Article_ByMonth,Article_Hid,Article_Time,Article_ByClass,Article_Code,Article_Form,Article_Tag,Photo,IsPhoto,See_Count,Re_Count)"
			SqlString=SqlString & " VALUES("& PhotoToARs(1) &",'"& PhotoToARs(10) &"','"& PhotoToARs(4) &"','"& PhotoToARs(4) &"','"& PhotoToARs(5) &"','未知天气','无',0,'"&  PhotoToARs(7)  &"','"& PhotoToARs(2) &"','108','未知','摄影|图片|相册|照片','"& PhotoToARs(3)  &"',1,"&PhotoToARs(8)&","&PhotoToARs(9)&")"
            On Error resume next
			Conn.ExeCute(SqlString)
			ARTID=CONN.EXECUTE("SELECT Top 1 Article_ID FROM [Article] Order By Article_ID Desc")(0)
			Conn.ExeCute("Update Tb_Reply Set Reply_Blog_ID="& ARTID &" Where Reply_Blog_ID="& PhotoToARs(0) &"")
	PhotoToARs.MoveNext
	Loop
	PhotoToARs.Close:Set PhotoToARs=Nothing
End Sub
Sub UpdateByMonth()'更改日期
	Set RS=Conn.ExEcUTE("Select Article_ID,Article_Time From Article Order By Article_ID")
	Do While Not Rs.Eof
		Article_ByMonth=Year(Rs(1))&month(Rs(1))&"||"&Year(Rs(1))&"年"&MonthName(Month(Rs(1)))&"份"
		Conn.ExeCute("Update Article Set Article_ByMonth='"& Article_ByMonth &"' Where Article_ID="& Rs(0) &"")
	Rs.MoveNext
	Loop
	Rs.Close:Set Rs=Nothing
End Sub
Sub UpdateClass()'升级分类
	Conn.ExeCute("Update Article Set Article_ByClass='1111111默认相册' Where Article_ByClass='Default' Or Article_ByClass='默认分类' Or Article_ByClass='默认相册'")
	Set RS=Conn.ExEcUTE("Select id,User_id,Blog_Class From Tb_User_Class")
	Do While Not Rs.Eof
		Article_ByMonth="0000000" & Rs(0)
		Article_ByMonth=Right(Article_ByMonth,7) & Rs(2)
		Conn.ExeCute("Update Article Set Article_ByClass='"& Article_ByMonth &"' Where Article_ByClass='"& Rs(2) &"'")
	Rs.MoveNext
	Loop
	Rs.Close:Set Rs=Nothing
End Sub

Sub DOUserID()
DIM UserID
	Set UserRs=Conn.Execute("Select ID,User_Name,User_Sex,User_Mail,Blog_Url,Blog_Name,Blog_Title,Blog_Info,User_Photo,User_Date From Tb_User Order By ID")
	Do While Not UserRs.Eof
		'复制相关文件
		UserID=UserRs(0)
		CBlogObj.CreateFolder(CityBlogDir & "UserUpLoad/User" & Cint(UserID/800) & "/")
		CBlogObj.Copyfile CityBlogDir & "inc/uploaddir/", CBlogObj.GetUpLoadDir(UserID)
		CBlogObj.Copyfile CBlogObj.GetDir(UserRs(0)) & "/UpLoadFile/", CBlogObj.GetUpLoadDir(UserID)
		CBlogObj.Copyfile CityBlogDir & "inc/default/", CBlogObj.GetDir(UserRs(0))
		'End复制相关文件
		'生成SETUP.ASP
		BlogTopTitle=UserRs(6)
		IF IsDom Then 
			BlogTopTitle=BlogTopTitle & " http://" & UserRs(4) & "." & WebHost
		End IF
		UserID=UserRs(0)
		User8=UserRs(8)
		User1=UserRs(1)
		User2=UserRs(2)
		User9=UserRs(9)
		User3=UserRs(3)
		User7=UserRs(7)
		TBBlog_Name=UserRs(5) & "(" & User1 & "'S Blog)"
		BodyText=CBlogObj.GetTxt(CityBlogDir & "inc/usersetup.inc")
		Set RegExpObj=new RegExp
		RegExpObj.IgnoreCase =true
		RegExpObj.Global=True
		RegExpObj.Pattern="(#UserID#)"
		BodyText=RegExpObj.Replace(BodyText,UserID)
		RegExpObj.Pattern="(#UserBlogTitle#)"
		BodyText=RegExpObj.Replace(BodyText,BlogTopTitle)
		RegExpObj.Pattern="(#BlogName#)"
		BodyText=RegExpObj.Replace(BodyText,TBBlog_Name)
		RegExpObj.Pattern="(#PageSize#)"
		BodyText=RegExpObj.Replace(BodyText,10)
		RegExpObj.Pattern="(#photo#)"
		BodyText=RegExpObj.Replace(BodyText,User8)
		RegExpObj.Pattern="(#UserName#)"
		BodyText=RegExpObj.Replace(BodyText,User1)
		RegExpObj.Pattern="(#Sex#)"
		BodyText=RegExpObj.Replace(BodyText,User2)
		RegExpObj.Pattern="(#Date#)"
		BodyText=RegExpObj.Replace(BodyText,User9)
		RegExpObj.Pattern="(#Email#)"
		BodyText=RegExpObj.Replace(BodyText,User3)
		RegExpObj.Pattern="(#City#)"
		BodyText=RegExpObj.Replace(BodyText,"没有填写")
		RegExpObj.Pattern="(#Announcement#)"
		BodyText=RegExpObj.Replace(BodyText,User7)
		Set RegExpObj=nothing
		CBlogObj.WriteStream CBlogObj.GetDir(UserID) & "/setup.asp",BodyText
		'END生成SETUP.ASP
		'生成友情联接
		StrIngs=""
		StrIngs="<ul id=""link"" class=""rightdiv"">"
		Dim ObjXML,AllNodesNum,Root,iii,XmlPath
		XmlPath=CBlogObj.GetDir(UserRs(0)) & "/link.xml"
		Set objXML = Server.CreateObject("Microsoft.FreeThreadedXMLDOM")
		objXML.Load (Server.MapPath(XmlPath))
		if objXML.parseError.ErrorCode=0 then
			Set Root = objXML.documentElement.selectSingleNode("index")
			AllNodesNum = Root.childNodes.length - 1
			For iii = 0 To AllNodesNum
				StrIngs=StrIngs & "<li>"& root.childNodes.Item(iii).childNodes.Item(0).Text &"</li>"
			Next
		End IF
		StrIngs=StrIngs&"</ul>"
		CblogObj.WriteStream CBlogObj.GetDir(UserRs(0)) & "/link.html",StrIngs
		CblogObj.SaveUserClassXml(UserRs(0))
		CblogObj.SaveUserMonthXml(UserRs(0))
		CblogObj.SaveReXml(UserRs(0))
		Response.Write UserID & "<br/>"
		Conn.Execute("INSERT INTO [Message](UserID,UserName,Message,Messdate) VALUES("& UserRs(0) &",'系统消息','由于系统升级，模板回到了初始界面，请你登入后台，然后重选一下模板','"&Now&"')")
	UserRs.MoveNext
	Loop
	UserRs.Close:Set UserRs=Nothing
	Response.Write "完成升级了,请删除此文件<br/>"
	Set CblogObj=NotHing
	Response.End
End Sub


Call UpdateAB()
Call UPPHOTOCLASS()
Call PhotoToArticle()
Call UpdateByMonth()
Call UpdateClass()
Call DOUserID()

%>
