<!--#include file="../inc/Conn.asp"-->
<!--#include file="inc/function.asp"-->
<!--#include file="../inc/MelyySoft.Update.asp"-->
<!-- #include file="Inc/Head.asp" -->
<script language="JavaScript" src="Update/AjaxRequest.Js"></script>
<%
If CheckFolderExist("Update.Asp") then Response.Redirect "Update.Asp"
Action=Trim(request("Action")) 
Select Case Action
Case "UpAdd"
	call UpAdd()
Case "ReUpdate"
	call ReUpdate()	
Case else
	call Detection()
End Select
Sub Detection()
    Dim UpVersion,IsLastVersion
	Dim i,I_UpVersion,W_UpVersion
	UpVersion=GetContent(UpDateUrl&"Version.asp")
	UpVersion = Split(UpVersion, vbCrLf)
	IsLastVersion = True
	
	For i = 0 to UBound(UpVersion)
	   I_UpVersion=UpVersion(i)
	   If toNum(I_UpVersion,0) > toNum(LocalVersion,0) Then
		   W_UpVersion=UpVersion(i)
		   IsLastVersion = False
		   Exit For
	   End If
	Next
	If Update="No" then
	    Call ShowInfo("系统关闭升级程序")			
	ElseIf IsLastVersion<>True then
	    Dim UpdateInfo,UpdateVerSion
		UpdateInfo="发现了更新文件版本号是"&W_UpVersion&"\n\n官方友情提示：官方升级可能会覆盖部分文件，自行修改文件，请做好备份!"
		UpdateVersion="Admin_UpDate.asp?Action=UpAdd&UpVersion="&W_UpVersion
		Response.Write("<script language=javascript>if(confirm('"&UpdateInfo&"')){this.parent.location.href='"&UpdateVersion&"';}</script>")
		response.end
	Else
	    Call ShowInfo("当前已经是最新版本")	
	end if
End Sub
Function ShowInfo(Title)
%>
<br>
<table width='100%' border='0' align='center' cellpadding='2' cellspacing='1' class='border'>
		<TBODY>
		<TR>
		  <TD class=Title align="center">在线升级</TD>
		</TR>
		<TR align="center">
		  <TD height=32 class="hback"><%=Title%>  <a href="?Action=ReUpdate"><font color="#FF0000">重新升级</font></a></TD>
		</TR>
	   </TBODY>
</TABLE> 
<%
End Function
Sub ReUpdate()
%>
<script language='JavaScript'>
    function addclass(){
		var select=document.myform.VerSionList;
		for(i=0;i<select.length;i++){
			if(document.myform.VerSionList[i].selected==true){
				document.myform.UpVersion.value=document.myform.VerSionList[i].value;
			}
		}
	}
   
</script>
<table width='100%' border='0' align='center' cellpadding='2' cellspacing='1' class='border'>
  <tr> 
    <td class="title" height="25"> <div align="center"><strong>重新升级 
        <br>
        </strong></div></td>
  </tr>
  <tr> 
    <form name="myform" method="post" action="Admin_Update.asp">
      <td><div align="center"> 
          <table width="100%" border="0" cellpadding="0" cellspacing="1">
            <tr bgcolor="#E7E7E7"> 
              <td width="9%" height="25" align="right" class=tdbgl><div align="center">需要升级的版本：</div></td>
              <td width="59%" class=tdbg><input type="text" name="UpVersion" id="UpVerSion" class="input" maxlength="60" size="15" readonly>
			  <%
			  Dim i,I_UpVersion,W_UpVersion
	UpVersion=GetContent(UpDateUrl&"Version.asp")
	UpVersion = Split(UpVersion, vbCrLf)
	%>
				  <select name="VerSionList" id="VerSionList" onChange="addclass()">
<%			  
	For i = 0 to UBound(UpVersion)
	   I_UpVersion=UpVersion(i)
	   %>
	   <option value="<%=I_UpVersion%>" <%If toNum(I_UpVersion,0) = toNum(LocalVersion,0) Then response.Write "Selected" end if%>><%=UpVersion(i)%></option>
	<%   
	Next
%>	
			  </select></td>
            </tr>
            
            
            <tr bgcolor="#E7E7E7">            </tr>
            <tr class=tdbg> 
              <td height="25" class="tdbgl"><input type="hidden" name="action" value="UpAdd"/></td>
              <td height="25"><input name="submit" type="submit" value="确定">
&nbsp;
<input name="reset" type="reset" value="取消"></td>
            </tr>
          </table>
        </div></td>
    </form>
  </tr>
</table>
<%
End Sub
Sub UpAdd()
Session("UpUrl")=""
Dim UpVersion,UpUrl,i,UpName
UpVersion=request("UpVersion")%>
<br>
<table width='100%' border='0' align='center' cellpadding='2' cellspacing='1' class='border'>
  <TBODY>
    <TR>
      <TD class=Title align="center">升级进度</TD>
    </TR>
    <TR class='tdbg' onMouseOut="this.className='tdbg'" onMouseOver="this.className='tdbgmouseover'">
      <TD height=32 align="center"><div class="RefreshLen"><span class="xingmu" id="RefreshLenx"></span></div></TD>
    </TR>
    <TR class='tdbg' onMouseOut="this.className='tdbg'" onMouseOver="this.className='tdbgmouseover'">
      <TD height=32  align="center"><span id="UpText"></span></TD>
    </TR>
  </TBODY>
</TABLE>
<br />
<table width='100%' border='0' align='center' cellpadding='2' cellspacing='1' class='border'>
  <tbody>
    <tr class="title" style="padding: 0px 2px;" align="center">
      <td>文件名称</td>
      <td width="15%">文件大小</td>
	  <td width="30%">说明</td>
      <td width="15%">状态</td>
    </tr>
	<%UpUrl=GetContent(UpDateUrl&UpVersion&"/Update_text.asp")
	Session("UpUrl")=UpUrl
	UpUrl = Split(UpUrl, vbCrLf)
	For i = 0 to UBound(UpUrl)-1
	UpName = Split(UpUrl(i),"|")%>
    <tr class='tdbg' onMouseOut="this.className='tdbg'" onMouseOver="this.className='tdbgmouseover'">
	  <%If UpName(4)=0 then%>
      <td height=32><%=UpName(1)%></td>
	  <%Else%>
	  <td height=32>系统文件</td>
	  <%End If%>
      <td height=32 ><%=UpName(2)%>KB</td>
	  <td height=32 ><%=UpName(3)%></td>
      <td><span id="UpZT<%=i%>">列队等待</span></td>
    </tr>
	<%Next%>
  </tbody>
</table>
<script language=javascript></script>
<Script language="JavaScript">
function upmycall(obj) {
	document.getElementById("UpText").innerHTML = "<a href=index.asp target=_top><font color=red>升级完成,请重新打开后台页!</font></a>";
	document.getElementById("RefreshLenx").style.width = "100%";
	document.getElementById("RefreshLenx").innerHTML = "100%";
	alert('升级成功');this.top.location.href='index.asp';
}

function mycallback(obj) {
var Upmunx=obj.responseText;
	Upmunx=Upmunx.split("|");
	document.getElementById("RefreshLenx").style.width = Upmunx[1]+"%";
	document.getElementById("RefreshLenx").innerHTML = Upmunx[1]+"%";
if (Upmunx[0]><%=UBound(UpUrl)-1%>){
if (Upmunx[2]==1)
	{
	document.getElementById("UpText").innerHTML = "安装升级文件";
	document.getElementById("UpZT"+(Upmunx[0]-1)).innerHTML = "<img src='Update/Ok.gif'>";
	var ajax=new AJAXRequest({
		url: "Update/Install.asp",
		method: "GET",
		oncomplete: upmycall,
		charset: "GB2312"
	});
ajax.get();
	}
else{
	document.getElementById("UpText").innerHTML = "<a href=index.asp target=_top><font color=red>升级完成,请重新打开后台页!</font></a>";
	document.getElementById("UpZT"+(Upmunx[0]-1)).innerHTML = "<img src='Update/Ok.gif'>";
	alert('升级成功');this.top.location.href='index.asp';
	}
}
else{
	document.getElementById("UpZT"+Upmunx[0]).innerHTML = "<img src='Update/Loading.gif'>";
	document.getElementById("UpZT"+(Upmunx[0]-1)).innerHTML = "<img src='Update/Ok.gif'>";
	var ajax=new AJAXRequest({
		url: "Admin_Update_Ajax.Asp?UpVersion=<%=UpVersion%>&Upmun="+Upmunx[0],
		method: "GET",
		oncomplete: mycallback,
		charset: "GB2312"
	});
ajax.get();
}
}
var ajax=new AJAXRequest({
		url: "Admin_Update_Ajax.Asp?Upmun=0&UpVersion=<%=UpVersion%>",
		method: "GET",
		oncomplete: mycallback,
		charset: "GB2312"
	});
ajax.get();
        </script>
<%End Sub
%>
</body>
</html>
