<%guidedisplay=1%>
<%copyrightend=1%>
<%Response.Buffer  =  true  %>
<!--#include file="admin_start.asp"-->
<style>
<!--
body         { font-size: 9pt; color: #FF0000 }
td         { font-size: 9pt; color: #FF0000 }
input        { font-size: 9pt }
-->
</style>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312"></head>
<body topmargin="10" leftmargin="0" rightmargin="0" bottommargin="0" marginwidth="0" marginheight="0">
<%
If request("action") = "ok" Then
Server.ScriptTimeOut = 9000
response.write "<!--/////////////////////////////////////////////////////////////////////////////////////////////////////////-->"
response.write "<!--/////////////////////////////////////////////////////////////////////////////////////////////////////////-->"
response.write "<!--/////////////////////////////////////////////////////////////////////////////////////////////////////////-->"
response.write "<!--/////////////////////////////////////////////////////////////////////////////////////////////////////////-->"
response.write "<left>&nbsp;&nbsp;·服务器端正在验证您的升级权限，请稍等！<br><br>"
response.flush
'/////////////////////////////////////////////////////////////////////////////////////  download(url)下载函数
Function get_url(url)
    On Error Resume Next
    Dim ii, xmlhttp
    Set xmlhttp = Server.CreateObject("Microsoft.XMLHTTP")
    ii = 1
   Do While ii < 5 And ii > 0
        xmlhttp.Open "get", url, false
        xmlhttp.send
        If Err.Number <> 0 Then
            ii = ii + 1
        Else
            ii = 0
        End If
    Loop
    If ii >= 5 Then
        get_url = ""
        Exit Function
    End If
    get_url = xmlhttp.ResponseBody
    Set xmlhttp = Nothing
End Function
'///////////////////////////////////////////////////////////////////////
Function BytesToBstr(body, Cset)
    Dim objstream
    If Len(body) = 0 Then
        BytesToBstr="|err|文件下载失败！"&Err.Description&",<center>请检查网络连接然后重新升级[刷新本页即可]"
        Exit Function
    End If
    Set objstream = Server.CreateObject("adodb.stream")
    objstream.Type = 1
    objstream.Mode = 3
    objstream.Open
    objstream.write body
    objstream.Position = 0
    objstream.Type = 2
    objstream.Charset = Cset
    BytesToBstr = objstream.ReadText
    objstream.Close
    Set objstream = Nothing
End Function
'///////////////////////////////////////////////////////////////////////
Function download(url,des)
    'Dim des
	dim file_check
	
   

   ' response.write url
   ' response.end
    If url <> "" Then
        des = Server.mappath(des)
        url = url_update + "&file=" + Replace(url, "http", "")
    Else
        download = flase
        Exit Function
    End If
    
    'response.write des
    'response.end
    
    file = get_url(url)
    file_check = BytesToBstr(file, "GB2312")
    If Len(file_check) = 0 Or InStr(file_check, "|err|") <> 0 Then

        If Len(file_check) > 0 And InStr(file_check, ",") <> 0 Then
            info_back = Split(file_check, ",")
            err_back_server = Replace(info_back(0), "|err|", "")
            answer = info_back(1)
        Else
            err_back_server = Replace(file_check, "|err|", "")
        End If

        download = flase
        Exit Function
    End If
    If fso.FileExists(des) Then fso.deletefile des, True
    Set objAdostream = Server.CreateObject("ADODB.Stream")
    objAdostream.Type = 1
    objAdostream.Open()
    objAdostream.write (file)
    objAdostream.SaveToFile (des)
    objAdostream.SetEOS
    Set objAdostream = Nothing
    download = True
End Function
'/////////////////////////////////////////////////////////////////////////////////////  download_files()???t?D?°???t????oˉêy
Function download_files()
    response.write " <script>window.top.document.update.doing_step.value='下载升级文件：';</script>" & vbCrLf
    
	mysys.check.makenewsdir(server.mappath("update_file"))
	
	If Not download("config_"&update_id&".up","update_file/config.up") Then
        err_back_client = "[升级版本信息列表]下载失败！<br>"
        Exit Function
    Else
        response.write "&nbsp;&nbsp;·文件[升级版本信息列表]下载完成<br>"
        response.flush
    End If
    If Not download("file_"&update_id&".up","update_file/file.up") Then
        err_back_client = "[文件列表]下载失败！"
        Exit Function
    Else
        response.write "&nbsp;&nbsp;·文件[文件列表]下载完成<br>"
        response.flush
    End If
    If Not download("sql_"&update_id&".up","update_file/sql.up") Then
        err_back_client = "[数据库更新列表]下载失败！"
        Exit Function
    Else
        response.write "&nbsp;&nbsp;·文件[数据库更新列表]下载完成<br>"
        response.flush
    End If
    '///////???????t
    Mysys.functions.include ("update_file/file.up")
    file_all = file_num
    For i = 1 To file_num
	
        file_custom=filename(file_create(i))
		if file_custom<>"|err|" then
			MySys.check.makenewsdir(server.MapPath("update_file"&file_custom))
			
			If Not download(Replace(file_create(i), "../", ""),"update_file"&file_custom) Then '???????t
	            download_files = False
	            Exit Function
	        Else
	            response.write " <script>window.top.document.update.doing.style.width=" & Int(((i) / file_all) * 350) & ";" & vbCrLf
	            response.write " window.top.document.update.doing_num.value='" & Int(((i) / file_all) * 100) & "%';" & vbCrLf
	            response.write " </script>" & vbCrLf
	            response.write "<nobr>&nbsp;&nbsp;文件[ " & file_custom & " ]下载成功！</nobr>"
	            response.write "<br>"
	            response.flush
	        End If
        end if
    Next
    download_files = 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 update_check()
    
	dim url
	dim file
	dim file_check
		
	update_id = request.Form("update_id")
    update_password = request.Form("update_password")
    url = Replace(url_update, "send.asp", "update_check.asp") + "&update_id=" + update_id + "&update_password=" + update_password
    file = get_url(url)
    '////////?ì2é·′à?D??￠
    file_check = BytesToBstr(file, "GB2312")
   ' response.write file_check
   ' response.end
    If Len(file_check) = 0 Or InStr(file_check, "|err|") <> 0 Then

        If Len(file_check) > 0 And InStr(file_check, ",") <> 0 Then
            info_back = Split(file_check, ",")
            err_back_server = Replace(info_back(0), "|err|", "")
            answer = info_back(1)
        Else
            err_back_server = Replace(file_check, "|err|", "")
        End If

        update_check = flase
        Exit Function
    Else
        update_check = True
    End If
End Function
'/////////////////////////////////////////////////////////////////////////////////////  主程序！！
Dim err_back_server, err_back_client, fso
Dim file_create(300)    '文件列表数组
Dim answer, answer_default, url_update, update_id, update_password

answer = "&nbsp;&nbsp;&nbsp;&nbsp;请重新升级，您可以：<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[1] 刷新本页<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[2] 在管理页面的升级选项内点击“我要升级”<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[3] 联系我们的客服人员"
update_id = request("update_id")
update_password = request("update_password")
'url_update = "http://www.kawebs.com/update/send.asp?f=1" '升级服务器地址
url_update = "http://www.freshbox.cn/update/emart/access/send.asp?key_r="&year(now())&month(now())&day(now())&hour(now())&minute(now())&second(now()) '升级服务器地址
Set fso = Server.CreateObject("Scripting.FileSystemObject")

If update_check() Then
    response.write "<left>&nbsp;&nbsp;·权限检查完成！<br><br>"
    response.flush

    If download_files() Then
        response.write "<script>window.location='admin_update_install_handle.asp';</script>" '执行升级程序！！
    Else
        response.write "<left>&nbsp;&nbsp;·文件下载出错！<br><br>"
        if len(err_back_server)>0 then response.write "<left>&nbsp;&nbsp;&nbsp;&nbsp;·反馈错误信息[升级服务器]：<font color='green'>"&err_back_server&"</font><br><br>"
        response.write "<left>&nbsp;&nbsp;&nbsp;&nbsp;·反馈错误信息[系统服务器]：<font color='green'>"&err_back_client&"</font>"
        response.write "<left>&nbsp;&nbsp;&nbsp;&nbsp;·解决方法：<br><font color='green'>"&answer&"</font>"
    End If
Else
    response.write "<left>&nbsp;&nbsp;·用户权限检查错误！<br><br>"
    response.write "<left>&nbsp;&nbsp;&nbsp;&nbsp;·反馈错误信息[升级服务器]：<font color='green'>"&err_back_server&"</font><br><br>"
    response.write "<left>&nbsp;&nbsp;&nbsp;&nbsp;·解决方法：<br><br><font color='green'>"&answer&"</font>"
End If
'/////////////////////////////////////////////////////////////////////////////////////  释放资源！！
Set fso = Nothing
Set folder = Nothing
Set file = Nothing

else
%>
<div align="center">
<table cellpadding="0" cellspacing="0" width="300" height="116" style="border: 1px solid #0275B9">
<form method="POST" action="admin_update_download.asp?action=ok">
			<!-- MSTableType="nolayout" -->
			<tr>
				<td height="25" width="427" align="right">　</td>
				<td height="25" width="578" align="left">
				　</td>
			</tr>
			<tr>
				<td height="25" width="427" align="right">升级ID：</td>
				<td height="25" width="578" align="left">
				<input type="text" name="update_id" size="20"> *</td>
			</tr>
			<tr>
				<td height="25" width="427" align="right">升级密码：</td>
				<td height="25" width="578" align="left">
				<input type="password" name="update_password" size="22" style="font-size: 9pt"> *</td>
			</tr>
			<tr>
				<td height="41" colspan="2">
				<p align="center"><input type="reset" value="重置" name="B2">&nbsp;
				<input type="submit" value="提交升级" name="B1"></td>
			</tr>
		</table>
</div>
</form>
</table>
<div align="center">
<table cellpadding="0" cellspacing="0" width="218" height="140" style="line-height: 150%">
<tr><td>
<font color="#0000FF">升级注意事项：<br>
&nbsp; 1 保证您的服务器连接到了互联网<br>
&nbsp; 2 已经备份好您的文件<br>
&nbsp; 3 没有修改过源文件及数据库的结构 <br>
&nbsp; 4 对升级导致的系统无法使用的问题<br>
&nbsp;&nbsp;&nbsp; 请您用备份的文件还原系统。<br>
&nbsp; 5 您使用的是注册正式版<br>
&nbsp; 6 更多问题请联系我们的客服人员</font><br>
</td></tr>
</table>
</div>
<%
end if
%>
</body>
<!--#include file="admin_end.asp"-->
