<!--#include file="conn.asp"-->
<!--#include file="inc/cookies_check.asp"-->
<!--#include file="../include/config.inc"-->
<%
'*****************************************
'* 软件名称 乐彼网上开店软件(56770 EShop)
'* 软件开发 http://www.56770.com
'* 版权所有 http://www.56770.com
'* 文件名称 Admin_upgrade.asp
'* 最后更新 2013-6-14 by 56770.kingdge
'*****************************************
admin_flag=",10.10,"
On Error Resume Next 
Server.ScriptTimeout=3000
include "lang/"& LangFilePath &"/lang_sys.inc"
include "lang/"& LangFilePath &"/lang_menu.inc"
include "lang/"& LangFilePath &"/lang_upgrade.inc"
CurrentId = 0
CurrentUrl = "Admin_Upgrade.asp"
LB_Head()
LB_Menu()
ServerUrl = "http://www.56770.com/autoupgrade/"
%>
<div class="tabmenu mainwidth">
      <ul>
		<li><a href="admin_space.asp"><span><%=Lang_Menu(155)%></span></a></li>
		<li><a href="admin_license.asp"><span><%=Lang_Menu(61)%></span></a></li>
        <li><a href="Admin_Config.asp"><span><%=Lang_Menu(187)%></span></a></li>
        <li class="current"><a href="Admin_upgrade.asp"><span><%=Lang_Menu(190)%></span></a></li>
      </ul>
</div>
<%
Response.Write("<div class=""tab-mainbody"">")
Response.Write("<div class=""tab-mainbody2"">")
If Eshop_Lebi_name="" Or instr(","&Eshop_Lebi_flag&",",admin_flag)=0 Then
		adminflag()
Else 
		Select Case request("action")
		Case "update" update()
		Case Else
		main()
		End Select
End If 
Response.Write("</div>")
Response.Write("</div>")
LB_Footer()

Sub update()
        If OnlyRead = 1 Then OnlyReadMessage()
		sys_upgrade = checknum(request("IsUpgrade"),0) &"|"& checknum(request("AutoCheck"),0) &"|"& safereplace(request("Upgrade_User")) &"|"& safereplace(request("Upgrade_Pwd")) &"||||||||||"
		set rs=server.CreateObject("adodb.recordset")
		sql="select * from [Lebi_system]"
		rs.open sql, conn, 1, 3
		rs("sys_upgrade")=sys_upgrade
		rs.update
		rs.close
		ManageLog Lang_Upgrade(1)
		NewEvent "0"
		Call Up_mes(Lang_sys(69),"·"& Lang_sys(68),0,m_u,0,0,2,1)
End Sub

Sub upgrade()
		If IsUpgrade = "0" Then 
				response.write("<script>document.getElementById('upmes').innerHTML+=""<span style='color:#0000FF'>"& Lang_Upgrade(15) &"</span><br />"";</script>")
				Exit Sub
		ElseIf CheckUpgrade = "0" Then
				response.write("<script>document.getElementById('upmes').innerHTML+=""<span style='color:#ff0000'>"& Lang_Upgrade(2) &"</span><br />"";</script>")
				session("CheckNewVersion") = ""
				Exit Sub
		ElseIf InStr(CheckUpgrade,"00") > 0 Then
				response.write("<script>document.getElementById('upmes').innerHTML+=""<span style='color:#0000FF'>"& GetErr(CheckUpgrade) &"</span><br />"";</script>")
				Exit Sub
		Else
				NewVersion = CheckUpgrade()
				response.write("<script>document.getElementById('upmes').innerHTML+=""["& NewVersion &"] "& Lang_Upgrade(3) &"<br />""</script>")
				response.flush
				SaveAs GetHttp(ServerUrl & NewVersion &".rar"),server.mappath("../"& NewVersion &".mdb")
				response.write("<script>loadingScroll.init('UpgradeBox',50);loadingScroll.doScroll();document.getElementById('upmes').innerHTML+=""["& NewVersion &"] "& Lang_Upgrade(4) &"<br />""</script>")
				response.flush
				If UnPack(NewVersion &".mdb") > 0 Then
						response.write("<script>document.getElementById('UpgradeBox').style.display = 'none';document.getElementById('upmes').innerHTML+=""["& NewVersion &"] "& Lang_Upgrade(5) &"<br />""</script>")
						response.flush
						UpdateDatabase = getpage("http://"& Request.ServerVariables("SERVER_NAME") &":"& request.ServerVariables("SERVER_PORT") & Eshop_url &"update/default.asp?step=step_3&Update_IsSqlDataBase=9")
						If InStr(UpdateDatabase,"系统升级完成!")>0 Then response.write("<script>document.getElementById('UpgradeBox').style.display = 'none';document.getElementById('upmes').innerHTML+=""["& NewVersion &"] "& Lang_Upgrade(6) &"<br />""</script>")
						DelFolder("../update/")
				End If
				If Checkfile(NewVersion&".txt") = 1 Then	
						response.write("<script>document.getElementById('UpgradeBox').style.display = 'none';document.getElementById('upmes').innerHTML+=""["& NewVersion &"] <a href='../"& NewVersion &".txt' target='_blank'><span style='color:#0000ff'>"& Lang_Upgrade(38) &"</span></a><br />""</script>")
				End If 
				If CStr(LCase(AdminPath)) <> "admin" Then 
						Call copyfile(Server.MapPath("../admin/"),Server.MapPath("../"& AdminPath &"/"))
						DelFolder("../admin/")
				End If 
				Savehtml "../include/Upgrade.inc",NewVersion
				DelFile(NewVersion &".mdb")
				response.write("<script>document.getElementById('UpgradeBox').style.display = 'none';document.getElementById('upmes').innerHTML+=""["& NewVersion &"] "& Lang_Upgrade(7) &"<br />""</script>")
				response.flush
				upgrade()
		End If
End Sub

Function CheckUpgrade()
		Dim RanNum
		Randomize
		RanNum = Int(9000000*rnd)+1000000
		LocalVersion = Replace(LoadFile("../include/Upgrade.inc"),".","")
		url = ServerUrl & "Upgrade.asp?domain="& Request.ServerVariables("SERVER_NAME") &"&user="& Upgrade_User &"&pwd="& Upgrade_Pwd &"&RanNum="& RanNum
		ServerUpgradeData = getpage(url)
		If InStr(ServerUpgradeData,"00") > 0 Then 
				CheckUpgrade = ServerUpgradeData
				Exit Function 
		End If 
		ServerVersion = Split(getpage(url),"|")
		For i = 0 To UBound(ServerVersion)
				If CLng(LocalVersion) >= CLng(Replace(ServerVersion(0),".","")) Then
						CheckUpgrade = 0
						Exit Function
				ElseIf CLng(LocalVersion) < CLng(Replace(ServerVersion(i),".","")) Then
						CheckUpgrade = ServerVersion(i)
				End If
		Next
End Function

Function Checkfile(filename)
		set fso=Server.CreateObject ("Scripting.FileSystemObject")
		If fso.FileExists(server.mappath("../"& filename)) = True Then
				Checkfile = 1
		Else
				Checkfile = 0
		End If
		set fso = nothing
End Function

Function DelFolder(FolderName)
		On Error Resume Next
		If IsObjInstalled("Scripting.FileSystemObject") Then
				allowfso = 1
		Else
				allowfso = 0
		End If
		If allowfso = 1 Then
                set fso=Server.CreateObject ("Scripting.FileSystemObject")
				fso.DeleteFolder(server.mappath(FolderName))
				Set fso = Nothing
		Else
                DelFolder = "<span style='color:#ff0000'>"& Lang_Upgrade(37) &"</span>"
		End If
End Function 

Function DelFile(FileName)
		Dim fso,path
		Set fso = Server.CreateObject("scripting.filesystemobject")
		If InStr(FileName, ":") <> 0 Then path = FileName Else path = Server.MapPath("../"& FileName)
		if fso.fileexists(path) then fso.DeleteFile (path)
		Set fso = Nothing
End Function 

Function GetErr(str)
		Select Case str 
		Case "001" GetErr = Lang_Upgrade(16)
		Case "002" GetErr = Lang_Upgrade(17)
		Case "003" GetErr = Lang_Upgrade(18)
		Case "004" GetErr = Lang_Upgrade(19)
		Case "005" GetErr = Lang_Upgrade(39)
		Case Else 
			GetErr = Lang_Upgrade(40)
		End Select 
End Function

Sub main()
%> 
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="classtable-top" id="upgrade">
<form name="system" method="post" action="?action=upgrade">
<tr>
	<td height="30" align="left" class="classhead"><input name="submit" type="image" src="lang/<%=LangFilePath%>/images/bt_app.gif" title=" <%=Lang_sys(1)%> " align="absmiddle"></td>
	<td align="right" class="classhead">
	<%=QuickMenu("admin_config.asp|"& Lang_Menu(187) &"","")%>
	</td>
 </tr>
<tr>
<td height="30" colspan="2" class="classtop" height="30"><%=Lang_Menu(190)%></td>
</tr>
<tr class="classrow">
<td width="15%" height="30" class="classrow"><%=Lang_Upgrade(20)%></td>
<td width="85%" class="classrow"><%=LoadFile("../include/Upgrade.inc")%></td>
</tr>
<tr class="classrow">
<td height="30" class="classrow"><%=Lang_Upgrade(21)%></td>
<td class="classrow"><%
url = ServerUrl & "Upgrade.asp?utype=check"
ServerUpgradeData = getpage(url)
response.write ServerUpgradeData
%></td>
</tr>
<tr class="classrow">
<td colspan="2" width="85%" class="classrow" height="30">
<div id="upmes"></div>
<div id="UpgradeBox" style="width:350px;padding:1px;height:10px;border:#CDCDCD 1px solid;display:none;overflow:hidden;float:left; position:relative;text-align:center"><div style="height:8px;background:#e0f3fa;border:#CCE4F0 1px solid; position:absolute;top:1px;left:1px;right:1px;z-index:1;width:350px">&nbsp;</div></div>
</td>
</tr>
</form>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="classtable" id="update">
<form name="system" method="post" action="?action=update">
<tr>
<td height="30" colspan="2" class="classtop" height="30"><%=Lang_Upgrade(8)%></td>
</tr>
<tr class="classrow">
<td width="15%" class="classrow" height="30"><%=Lang_Upgrade(9)%></td>
<td width="85%" class="classrow" height="30">
<input type="radio" value="1" <%=judge(IsUpgrade,"1")%> name="IsUpgrade"> <%=Lang_Upgrade(10)%>
<input type="radio" value="0" <%=judge(IsUpgrade,"0")%> name="IsUpgrade"> <%=Lang_Upgrade(11)%>
</td>
</tr>
<tr class="classrow">
<td width="15%" class="classrow" height="30"><%=Lang_Upgrade(12)%></td>
<td width="85%" class="classrow" height="30">
<input type="radio" value="1" <%=judge(AutoCheck,"1")%> name="AutoCheck"> <%=Lang_Upgrade(10)%>
<input type="radio" value="0" <%=judge(AutoCheck,"0")%> name="AutoCheck"> <%=Lang_Upgrade(11)%>
</td>
</tr>
<tr class="classrow">
<td width="15%" class="classrow" height="30"><%=Lang_Upgrade(13)%></td>
<td width="85%" class="classrow" height="30">
<input type="text" id="Upgrade_User" name="Upgrade_User" size="35" value="<%=Upgrade_User%>" class="form" style="width:200px">
</td>
</tr>
<tr class="classrow">
<td width="15%" class="classrow" height="30"><%=Lang_Upgrade(14)%></td>
<td width="85%" class="classrow" height="30">
<input type="password" id="Upgrade_Pwd" name="Upgrade_Pwd" size="35" value="<%=Upgrade_Pwd%>" class="form" style="width:200px">
</td>
</tr>
<tr>
  <td height="30" colspan="2" align="left" class="classfooter"><input name="submit" type="image" src="lang/<%=LangFilePath%>/images/bt_app.gif" title=" <%=Lang_sys(1)%> " align="absmiddle">&nbsp;<input type="image" src="lang/<%=LangFilePath%>/images/bt_res.gif" title=" <%=Lang_sys(2)%> " onclick="reset();return false;" align="absmiddle"></td>
 </tr>
</form>
</table>
<script type="text/javascript">    
var loadingScroll = {    
    init : function(boxDiv,Speed){       
        this.boxId=boxDiv;      
        this.scrollSpeed=Speed || 10;  
		document.getElementById(boxDiv).style.display = 'block';
    },    
    doScroll : function() {       
    var scrollWi = 0;  
    var HimalayaN=document.getElementById(this.boxId).getElementsByTagName("div")[0] ;      
    var HimalayaW=document.getElementById(this.boxId);       
    var pointW=(HimalayaN.scrollWidth/HimalayaW.scrollWidth)*100;
    var doScr=window.setInterval(function() {       
         scrollWi += 1;       
         if (scrollWi >= pointW) {       
             window.clearInterval(doScr);       
         } else {       
             HimalayaN.style.width = scrollWi + "%";       
         }       
     }, this.scrollSpeed);       
    }      
}     
tdshow("update");
</script>
<%
If request("action") = "upgrade" Then
	upgrade()
End If
End Sub
%>