<%@ LANGUAGE = "VBScript.Encode" CODEPAGE="65001"%>
<!--#include file=function2.asp-->
<!--#include file=../inc/config.asp-->
<%
response.charset="UTF-8"
rem delcare 
dim c_serveraddr
dim a_filelist,v_filelist,v_istart,updatelist,v_localupdate,v_updatecount
dim v_updatelist
dim total,createnum,action

rem get value
c_serveraddr=request("serveraddr")
action=request("action")
createnum=request("createnum")
v_tmprootdir=update_Get_RootDir(web_c_setupfolder)
if action="" then
	call chkdomain()
else
	call chkupdate()
end if 

Function chkdomain()
	tmpkey=getfilecontent("../inc/isused")
	call savetofile(tmpkey,"../inc/isused.txt")
	truedomain=Request.ServerVariables("server_name")
	v_setfolder=setupfolder
	lastupdate=getfilecontent("../update.ini")
	response.redirect "http://www.web08.net/onlineupdate/signle_user/getdomain.asp?version=dyh&setfolder="&v_tmprootdir&"&truedomain="&truedomain&"&lastupdate="&lastupdate
	response.end
End Function

Function Chkupdate()
 rem update begin 
 if createnum="" then 
	response.write c_serveraddr&"update.asp"
	a_flielist=getxmltext(c_serveraddr&"update.asp")
	v_filelist=split(a_flielist,chr(13))
	v_localupdate=getfilecontent("../update.ini")
	call Web_L_FindStartI()
	v_updatecount=ubound(v_filelist)-v_istart-1
	call Web_L_Getupdatelist()
	total=v_updatecount
	v_tmpupdatelist=replacechar(v_updatelist)
	v_tmpupdatelist=replace(v_tmpupdatelist,",","",1,1)
	createnum=0
 else
	createnum=createnum+1
	total=request("total")
	a_filelist=request("a_filelist")
	//v_localupdate=getfilecontent("update.ini")
	v_tmpupdatelist=request("v_tmpupdatelist")
	v_updatecount=request("v_updatecount")
	v_dbcount=request("v_dbcount")
 end if 
 if action<>"iserror" then 
	msg="共发现"&v_updatecount&"个文件更新"
 end if 
 if clng(createnum)=clng(total) and action="beginupdate" then
	v_dbcount=ShowFileList("../update/")
	if v_dbcount<>"" then
		createnum=1
		v_dblist=split(v_dbcount,",")
		total=ubound(v_dblist)+1
		action="updatedb"
		msg="正在执行数据库更新"
	end if
 end if
 %>
<script src="getupdateinfo.js"></script>
<form name="create" method="post" action="update.asp">
	<input name="createnum" type="hidden" value="<%=createnum%>" >
	<input name="msg" type="hidden" value="<%=msg%>" >
	<input name="total" type="hidden" value="<%=total%>" >
	<input name="v_filelist" type="hidden" value="<%=a_filelist%>" >
	<input name="v_tmpupdatelist" type="hidden" value="<%=v_tmpupdatelist%>" >
	<input name="v_updatecount" type="hidden" value="<%=v_updatecount%>" >
	<input name="action" type="hidden" value="<%=action%>" >
	<input name="serveraddr" type="hidden" value="<%=c_serveraddr%>">
	<input name="v_dbcount" type="hidden" value="<%=v_dbcount%>">
</form>
<%
 if clng(createnum)>clng(total) and action="updatedb" then
	v_tmpfile=split(v_dbcount,",")
	for i=0 to ubound(v_tmpfile)
		call DelTmpFile("../update/"&v_tmpfile(i))
	next
	response.write "<br><br><p align=center >在线升级完成,感谢您的使用!</p>"
	response.write "<p align=center ><a onclick='javascript:window.close()' style='cursor:hand'>关闭窗口</a></p>"
	response.end
 end if  
%>
      <table width="450" border="1"  align=center bordercolor="#FFFFFF">
        <tr>
          <td align=center><%=msg%></td>
	</tr>
        <tr>
          <td align=left>进度：</td>
	</tr>
	<% IF clng(createnum)<clng(total)-1 then %>
	<tr>
          <td width="450" align=left bordercolor="#030303"><img src="images/button/bar.gif" width="<%=((createnum)/total)*450%>" height="15"></td>
	</tr>
	<tr>
	  <td align=left>正在执行第<%=createnum+1%>个更新 &nbsp;&nbsp;</td>
        </tr>
	<% elseif action="iserror" and createnum=1 then %>
	<tr>
	  <td align=left height=30><%=replacechartohtml(getfilecontent("../updateinfo.txt"))%></td>
        </tr>
	<% else %>
	<tr>
          <td width="450" align=left bordercolor="#030303"><img src="images/button/bar.gif" width="450" height="15"></td>
	</tr>
	 <tr>
	  <td align=center height=30>更新完成&nbsp;&nbsp;<a onclick="javascript:window.close()" style="cursor:hand">关闭窗口</a></td>
         </tr>
	<% end if %>

<% IF clng(createnum)<=(clng(total)-1) and action<>"updatedb" then %>
<%
	nowfolder=split(v_tmpupdatelist,",")(createnum)
	v_foldername=ReplaceChar(trim(replace(nowfolder,"-","")))
	tmpurl=c_serveraddr&v_foldername&"/filelist.txt"
	v_tmpcontent=getxmltext(tmpurl)
	call web_l_splitcontent(v_tmpcontent,v_foldername)
%>
  <tr> 
    <td align="left" >
	<div id="updateinfo" name="updateinfo"></div>
	<script>LoadValueInfo('<%=v_foldername%>');</script>
    </td>
  </tr>
 <script language="javascript">
	create.submit();
 </script>
<% else%>
   <% call DelTmpFile("../include/isused.txt")%>
<%end if%>
</table>

<%
 IF clng(createnum)<=clng(total) and action="updatedb" then 
	response.redirect "../update/"&split(v_dbcount,",")(createnum-1)&"?createnum="&createnum&"&v_dbcount="&v_dbcount&"&total="&total
 end if
%>
<% End Function%>