<%guidedisplay=1%>
<%Response.Buffer  =  true  %>
<!--#include file="admin_start.asp"-->
<style>
<!--
body           { font-size: 9pt; line-height:150% }
-->
</style>
<%
function dropupdate()

if objFSO.FolderExists(Server.MapPath("update_file")) then objFSO.deletefolder Server.MapPath("update_file"),true  '删除升级文件夹

end function

function filename(n)
	dim i
	dim nn
	if n="" then
	   filename = "|err|"
	   Exit Function
	end if
	
	nn=split(n,"/")
	for i=2 to ubound(nn)
	filename=filename&"/"&nn(i)
	next
	
end function

function table_exists(table_name)
table_exists=false
set rsSchema=Conn.openSchema(20)
rsSchema.movefirst
do while not rsSchema.eof 
 if rsSchema("TABLE_TYPE")="TABLE" then
    if  rsSchema("TABLE_NAME")=table_name then
        table_exists=true
        exit do
    end if
   end if
rsSchema.movenext
loop
set rsSchema=nothing
end function

'//////////////////////////////定义
dim file_create(200)
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
'//////////////////////////////检查文件完整性
If not objFSO.FileExists(Server.MapPath("update_file/config.up"))  Then 
response.write "<script>alert('升级失败！文件[ config.up ]缺失，请重新下载升级程序！');window.close();</script>"
dropupdate()
response.end
end if

If not objFSO.FileExists(Server.MapPath("update_file/file.up"))  Then 
response.write "<script>alert('升级失败！文件[ file.up ]缺失，请重新下载升级程序！');window.close();</script>"
dropupdate()
response.end
end if

If not objFSO.FileExists(Server.MapPath("update_file/sql.up"))  Then 
response.write "<script>alert('升级失败！文件[ sql.up ]缺失，请重新下载升级程序！');window.close();</script>"
dropupdate()
response.end
end if


'//////////////////////////////取得文件夹和文件列表
mysys.functions.include("update_file/config.up")
mysys.functions.include("update_file/file.up")

'//////////////////////////////取得当前系统的版本信息
'if table_exists("update_info") then
set rs=conn.execute("select * from sys_update_info order by update_date desc")
if rs.eof then
update_ver_m=2
update_ver_s=1
update_date="目前还没有升级！"
else
update_ver_m=rs("update_ver_m")
update_ver_s=rs("update_ver_s")
'update_id=rs("update_id")
update_date=rs("update_date")
end if
rs.close

if ver_m="" or ver_s="" then 
	response.write "<script>alert('升级失败！升级程序不完整！');window.close();</script>"
    dropupdate()
	response.end
else
	if ver_m<>update_ver_m then
	response.write "<script>alert('升级失败！不同系列系统不能升级！');window.close();</script>"
    dropupdate()
	response.end
	end if 
	if ver_s<update_ver_s then
	response.write "<script>alert('升级失败！升级程序版本低于原版本！');window.close();</script>"
    dropupdate()
	response.end
	end if 
end if

response.write "·升级详细信息：<br>"
response.write "----------------------------------------------------------------------<br>"
response.write " <script>window.top.document.update.doing_step.value='升级进程：';"&vbcrlf
response.write " window.top.document.update.doing.style.width=0;"&vbcrlf
response.write " window.top.document.update.doing_num.value='0%';"&vbcrlf
response.write " window.top.document.update.update_ver.value='"&update_ver_m&"."&update_ver_s&"';"&vbcrlf
response.write " window.top.document.update.ver.value='"&ver_m&"."&ver_s&"';"&vbcrlf
response.write " window.top.document.update.update_date_lasttime.value='"&update_date&"';"&vbcrlf
response.write " window.top.document.update.update_date.value='"&ver_date&"';"&vbcrlf
response.write " </script>"&vbcrlf
response.write "&nbsp;·<font color='red'><b>升级必须文件检查完毕</b></font><br>"
response.write "&nbsp;·<font color='red'><b>升级版信息：</b></font><br>"
response.write info
response.write "----------------------------------------------------------------------<br>"
response.flush
'//////////////////////////////start
sub form_show
response.write " <script>window.top.document.update.doing.style.width="&int(width)&";"&vbcrlf
response.write " window.top.document.update.doing_num.value='"&int(doing_num)&"%';"&vbcrlf
'response.write " window.top.document.frames('I1').document.scrollIntoView();"&vbcrlf
'response.write " alert(window.top.document.frames('I1'));"&vbcrlf
response.write " </script>"&vbcrlf
response.write "&nbsp;&nbsp;"&show
response.write "<br>"
response.flush
end sub


file_all=file_num+1
'/////////////////////复制文件
for ii=1 to file_num
file_c=filename(file_create(ii))
if file_c<>"|err|" then MySys.check.makenewsdir(server.MapPath(".."&file_c))
If objFSO.FileExists(Server.MapPath("update_file"&file_c)) Then

set sourcefile=objFSO.getfile(Server.MapPath("update_file"&file_c))
sourcefile.copy Server.MapPath(".."&file_c),true

show="<nobr>&nbsp;·文件[ "&file_c&" ]复制完成</nobr>"
width=((i+ii-1)/file_all)*350
doing_num=((i+ii-1)/file_all)*100
form_show

set sourcefile=nothing
else
response.write "<script>alert('升级失败！文件[ "&file_c&" ]缺失，请重新下载升级程序！');window.close();</script>"
dropupdate()
response.end
end if
next

show="&nbsp;&nbsp;·<font color='red'><b>文件系统升级完成！</b></font>"
response.write show
response.write "<br>"
response.flush

'/////////////////////更新数据库
mysys.functions.include("update_file/sql.up")

show="·<font color='red'><b>数据库系统升级完成！</b></font>"
width=((i+ii)/file_all)*350
doing_num=((i+ii)/file_all)*100
form_show

'/////////////////////更新版本信息
set rs=server.CreateObject("adodb.recordset")
rs.open "select * from sys_update_info",conn,1,3
rs.addnew
rs("update_ver_m")=ver_m
rs("update_ver_s")=ver_s
rs("update_date")=now()
rs("update_id")=update_id
rs("update_info")=info
rs.update
rs.close
set rs=nothing
show="&nbsp;&nbsp;·<font color='red'><b>版本信息更新完成！</b></font>"
response.write show
response.write "<br>"
response.flush

'/////////////////////完成升级
dropupdate()
response.write "<script>alert('系统升级完成！');</script>"
response.Write"<script>window.location='http://www.freshbox.cn/update/emart/access/update_done.asp?id="&update_id&"'</script>"
%>
<!--#include file="admin_end.asp"-->
