<?php
if( !defined('ISDVBBS') ){
	header('HTTP/1.0 404 Not Found');
	exit;
}
?>
<br>
<table width="95%" border="0" cellspacing="1" cellpadding="0"  align="center" class="tableborder">
<tr> 
<td height="23" align="left" colspan="6" class="tit1"><?=$lang['upgrade.info131'].$lang['upgrade.info133']?></td>
</tr>
<tr align="left">
<td height="23" class="forumrow" style="text-align:center;width:15%">
<input type="submit" name="Submit" value="<? echo $lang['upgrade.info132']?>" style="color: #FF0000;width:80px;height:50px;border:1px outset;">
</td>
<td height="23" class="forumrow" style="LINE-HEIGHT: 140%">
<?=$lang['upgrade.info134']?>
</td>
</tr>
</table>
<!--导航-->
<table border="0" cellspacing="0" cellpadding="0"  align="center" class="tableborder">
<tr align="center">
<td height="25" align="center" <?if($reaction=='forum' or $reaction==''){echo 'bgcolor="#C9DEFA"';}else{echo 'bgcolor="#F1F3F5"';}?>  width="10%"><a href="?reaction=forum"><font color="<?if($reaction=='forum' or $reaction==''){echo 'red';}else{echo '#000000';}?>"><?=$lang['upgrade.info15']?></font></a></td>
<td height="25" align="center" <?if($reaction=='setting'){echo 'bgcolor="#C9DEFA"';}else{echo 'bgcolor="#F1F3F5"';}?> width="10%"><a href="?reaction=setting"><font color="<?if($reaction=='setting'){echo 'red';}else{echo '#000000';}?>"><?=$lang['upgrade.info51']?></font></a></td>
<td width="10%" align="center" <?if($reaction=='upgrade'){echo 'bgcolor="#C9DEFA"';}else{echo 'bgcolor="#F1F3F5"';}?>></font><a href="?reaction=upgrade"><font color="<?if($reaction=='upgrade'){echo 'red';}else{echo '#000000';}?>"><?=$lang['upgrade.info21']?></font></a></td>
<td width="10%" align="center" <?if($reaction=='log'){echo 'bgcolor="#C9DEFA"';}else{echo 'bgcolor="#F1F3F5"';}?>></font><a href="?reaction=log"><font color="<?if($reaction=='log'){echo 'red';}else{echo '#000000';}?>"><?=$lang['upgrade.info2']?></font></a></td>
</tr>
</table>
<!--导航结束-->
<?if($reaction=='forum' or $reaction==''){?>
<table width="100%"  border="0" cellspacing="0" cellpadding="0" class="tableborder">
  <tr>
    <td colspan="2" class="tdtit"><?=$lang['upgrade.info131']?> <?=$lang['upgrade.info15']?></td>
  </tr>
  <tr class="forumrow">
    <td width="30%" height="25"><?=$lang['forum.version']?></td>
    <td width="70%" height="25"><?echo " Dvbbs.php Version ".strval($foruminfo["version"]/100).".".strval($foruminfo["version"]/10%10).".".strval($foruminfo["version"]%10)?></td>
  </tr>
  <tr class="forumrow1">
    <td width="30%" height="25"><?=$lang['forum.database']?></td>
    <td width="70%" height="25"><?echo($foruminfo["database"]); ?></td>
  </tr>
  <tr class="forumrow">
    <td width="30%" height="25"><?echo $lang['forum.language']?></td>
    <td width="70%" height="25"><?echo($foruminfo["charset"]); ?></td>
  </tr>
  <tr class="forumrow1">
    <td width="30%" height="25"><?echo $lang['forum.encode']?></td>
    <td width="70%" height="25"><?echo($foruminfo["encode"]); ?></td>
  </tr>
  <tr class="forumrow">
    <td width="30%" height="25"><?echo $lang['forum.lastupdate']?></td>
    <td width="70%" height="25"><?echo $foruminfo["lastmodified"]==0?$lang['forum.noupdate']:(date("Y-m-d H:i:s",$foruminfo["lastmodified"])); ?>      <a href="?reaction=upgrade"><?echo $lang["forum.upgradenow"]; ?></a></td>
  </tr>
  
</table>
<?}elseif($reaction=='setting'){?>
<table width="100%"  border="0" cellspacing="0" cellpadding="0" class="tableborder">
  <form name="from1" id="frmsetting" method="GET" action="">
  <tr>
    <td colspan="2" class="tdtit"><?=$lang['upgrade.info131']?> <?=$lang['upgrade.info51']?></td>
  </tr>
  <tr class="forumrow">
   <td width="35%" class="forumrow"> <?=$lang['upgrade.method']?></td>
   <td width="65%" class="forumrow">
     <input type="hidden" name="reaction" id="reaction" value="setting">
     <input type="hidden" name="doaction" value="save">
    <input type="radio" name="autoupgrade" value="1" <?if($foruminfo["autoupgrade"] == "1"){echo "checked";}?>><?=$lang['upgrade.auto']?>&nbsp;&nbsp;&nbsp;&nbsp;
<input type="radio" name="autoupgrade" value="0" <?if($foruminfo["autoupgrade"] == "0"){echo "checked";}?>><?=$lang['upgrade.manual']?>&nbsp;
  </tr>
  <tr class="forumrow1">
    <td width="40%" height="25"><?php echo $lang['upgrade.interval']?></td>
    <td width="60%" height="25"><?php echo $lang['upgrade.each']?>  <input type="text" name="interval" size="2" value="<?php echo intval($foruminfo["query_interval"]/3600) ?>">  <?php echo $lang['upgrade.hour'].$lang['upgrade.onetime']?></td>
  </tr>
  <tr class="forumrow">
    <td width="40%" height="25"><?php echo $lang['upgrade.server']."<BR>".$lang['upgrade.serverAlert']?></td>
    <td width="60%" height="25"><input type="text" name="upgradeserver" size="35" value="<?echo $foruminfo["upgradeserver"] ?>"></td>
     <tr class="forumrow1">
    <td width="40%" height="25"><?echo $lang['upgrade.auth']."<BR>".$lang['upgrade.authAlert']?></td>
    <td width="60%" height="25"><input type="radio" name="auth" value="1" <?if($foruminfo["auth"] == 1){echo "checked";}?>><?php echo $lang['upgrade.yes']?>&nbsp;&nbsp;&nbsp;&nbsp;
<input type="radio" name="auth" value="0" <?if($foruminfo["auth"] == 0){echo "checked";}?>><?=$lang['upgrade.no']?>&nbsp;</td>
  </tr>
    <input type="hidden" name="autorun" value="1">

<tr class="forumrow">
    <td width="40%" height="25"><?=$lang['upgrade.ftpserver']?></td>
    <td width="60%" height="25"><input type="text" name="ftpserver" size="35" value="<?echo $foruminfo["ftpserver"] ?>"></td>
  </tr>
 <tr class="forumrow1">
    <td width="40%" height="25"><?=$lang['upgrade.ftpport']?></td>
    <td width="60%" height="25"><input type="text" name="ftpport" size="35" value="<?echo $foruminfo["ftpport"] ?>"></td>
  </tr>
  
 <tr class="forumrow">
    <td width="40%" height="25"><?=$lang['upgrade.ftpuser']?></td>
    <td width="60%" height="25"><input type="text" name="ftpuser" size="35" value="<?echo $foruminfo["ftpuser"] ?>"></td>
</tr>
  
<tr class="forumrow1">
    <td width="40%" height="25"><?=$lang['upgrade.ftppass']?></td>
    <td width="60%" height="25"><input type="text" name="ftppass" size="35" value="<?echo $foruminfo["ftppass"] ?>"></td>
</tr>
<tr class="forumrow">
    <td width="40%" height="25"><?=$lang['upgrade.ftproot']?></td>
    <td width="60%" height="25"><input type="text" name="ftproot" size="35" value="<?echo $foruminfo["ftproot"] ?>">&nbsp;&nbsp;&nbsp;&nbsp;<a href="#" onclick="document.getElementById('reaction').value='ftptest';document.getElementById('frmsetting').submit()"><font color=red><?echo $lang['upgrade.ftptest']?></font></a></td>
</tr>
<tr><td colspan="2" class="forumrow1" style="text-align:center">
<input type="submit" name="Submit" value="<?php echo $lang['upgrade.save']?>" class="button">
</td>
</tr>
</form>
</table>
<?}elseif($reaction=='upgrade') {?>
<style>
/***全局定义***/
*{ margin:0; padding:0;}
div { margin-left:auto; margin-right:auto;}
form { margin:0px; padding:0px;}
input,img { margin:0px; padding:0px;  vertical-align: middle; font-size:12px;}
img{ border:none;}
input { border:1px solid #acd6ed; height:18px; line-height:18px; color:#666666;}
a { color:#CC3300; text-decoration:none; }
a:hover { color:#CC3300; text-decoration:underline; }
.red { color:#ff3300; font-family:Arial,sans-serif; font-size:11px;}

#main{POSITION: absolute;width:500px; height:342px; top:50%;left:50%;margin:-171px 0 0 -250px;font-size:12px; color:#012737;visibility:hidden;z-index:3}
#tit{ width:100%; height:34px; line-height:34px; font-size:14px; color:#ffffff; background:url("images/upgrade/tit_bg.gif");}
#tit_name { text-indent:20px; float:left;}
#close { float:right; margin-top:6px; margin-right:10px;}
#mainbox { clear:both;width:498px; height:342px; border:1px #D7EAF0 solid; border-top:none;}
#box_left { width:145px; height:340px; background:url("images/upgrade/left_bg.gif"); border:1px solid #ffffff; border-right:none; float:left; }
#box_right { width:351px; height:340px; background:url("images/upgrade/bg.gif"); border:1px solid #ffffff; border-left:none; float:left; text-align:center;}
#text_01{ width:80%; height:150px; line-height:180%;  margin-top:50px; text-align:left; overflow-y:auto;POSITION:relative;vertical-align:bottom;}
#text_02 { width:80%; height:30px;  line-height:180%;  margin-top:10px; margin-bottom:10px; background:#e5f0f6; border:1px solid #ffffff; padding:10px 10px; text-align:left;}
#ProgressBar {font:12px Verdana, Arial, Helvetica, sans-serif;border:1px solid #5B94DF;text-align: left;}
#Pointer {border:1px solid  #FFFFFF;filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=#DDE9F9, endColorstr=#81ACE7;margin-left: 0px;}
#Lable {position:absolute;width:100%;text-align: center;}
</style>
<table width="100%"  border="0" cellspacing="0" cellpadding="0" class="tableborder">
  <tr>
    <td colspan="6" class="tdtit"><?=$lang['upgrade.info131']?> <?=$lang['upgrade.info21']?></td>
  </tr>
</table>

<table border="0" cellspacing="1" cellpadding="1"  align="center" class="tableborder">
  <?php if(count($updatefiles)>0){?>
  <tr class="forumrow1">
    <td style="text-align:center;" colspan="7"><?echo $lang['upgrade.upgradecount1'].strval(count($updatefiles)).$lang['upgrade.upgradecount2']?></td>
  </tr>
   <tr class="forumrow2">
    <td style="text-align:center;"></td>
    <td style="text-align:center;"><?echo $lang['upgrade.filename']?></td>
    <td style="text-align:center;"><?echo $lang['upgrade.fullname']?></td>
    <td style="text-align:center;"><?echo $lang['upgrade.filesize']?></td>
    <td style="text-align:center;"><?echo $lang['upgrade.alert']?></td>
    <td style="text-align:center;"><?echo $lang['upgrade.more']?></td>
    <td style="text-align:center;"><?echo $lang['upgrade.publish']?></td>
  </tr>
  <?php
  $singlerow=true;
  while($uf=each($updatefiles)){
  		if(is_array($uf)&&count($uf[1])==10){?>
 <tr class="forumrow<?php if($singlerow)echo "1"?>" style="padding:1px;">
    <td style="text-align:center;"><input type="checkbox" name="fileid" value="<?echo $uf[1][0]?>" checked></td>
    <td height="25" style="text-align:center;"><?echo $uf[1][1]?></td>
    <td height="25" style="text-align:center;"><?echo $uf[1][2]?></div></td>
    <td height="25" style="text-align:center;"><?echo formatSize($uf[1][6])?><input type="hidden" name="filesize" value="<?echo $uf[1][6]?>"></td>
    <td height="25" style="text-align:center;"><?php echo $lang['upgrade.level'.$uf[1][8]]?> </td>
    <td height="25" style="text-align:center;"><?echo $uf[1][9]?></td>
    <td height="25" style="text-align:center;"><?echo date("Y-m-d H:i:s",$uf[1][7])?></td>
</tr>
  <?php
  $singlerow=$singlerow?false:true;
  		}
  }
 ?>
  <tr class="forumrow">
		<td colspan="2"><input type="submit" class="button" class="myButton" value="<?echo $lang['upgrade.downandupdate']?>"  onclick="upgradestart()" name="button"></td>
		<td colspan="5"></td>
	</tr>
<?php
  }else{?>
	 <tr class="forumrow">
		<td colspan="7" align="center"><font color=red><?php echo $lang["upgrade.info16"]?></font></td>
	</tr>
<?php
  }?>
</table>
<div id="back" style="position:absolute;left:0;top:0;width:100%;height:0px;visibility:hidden;z-index:2"> </div>
<div id="main">
<!------------------系统标题开始-------------------->
  <div id="tit"><span id="tit_name"><?php echo $lang["upgrade.title"]?></span><span id="close"><input type="image" src="images/upgrade/close.gif" alt="" border="0" style="height: auto; border: none;" onclick="doOnCancel()" /></span></div>
  <div id="mainbox">
     <div id="box_left"></div>
	 <div id="box_right">
	    <div id="text_01"></div>
	    <div id="text_02">
		<div id="ProgressBar">
			<div id="Lable">0%</div>
			<div id="Pointer" style="width:0%"></div>
		</div>
		</div>
	   <h1><input type="button" id="btnfinish" class="myButton" alt="" border="0" onclick="doOnFinished()" value="<?php echo $lang["upgrade.btnfinish"]?>" style="height:25px;width:60px;"  disabled=true />&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" alt="" border="0" value="<?php echo $lang["upgrade.btncancel"]?>"  onclick="doOnCancel()"  style="height:25px;width:60px;" /></h1>
	 </div>
  </div>
<!------------------中间部分结束-------------------->
</div>
</div>
<?}elseif($reaction=='log') {?>
   <table width="100%"  border="0" cellspacing="0" cellpadding="0" class="tableborder">
  <tr>
    <td colspan="6" class="tdtit"><?=$lang['upgrade.info131']?> <?=$lang['upgrade.info2']?></td>
  </tr>
</table>
<table border="0" cellspacing="1" cellpadding="1"  align="center" class="tableborder">
  <form name="frmfilelist"  id="frmfilelist" method="get" action="?" onsubmit="return checkform(document.getElementById('frmfilelist'))">
  <?php if($db->affected_rows()>0) {?>
  
   <tr class="forumrow2">
    <td style="text-align:center;"></td>
    <td style="text-align:center;"><?echo $lang['upgrade.fullname']?></td>
    <td style="text-align:center;"><?echo $lang['upgrade.filesize']?></td>
    <td style="text-align:center;"><?echo $lang['upgrade.alert']?></td>
    <td style="text-align:center;"><?echo $lang['upgrade.more']?></td>
     <td style="text-align:center;"><?echo $lang['upgrade.status']?></td>
    <td style="text-align:center;"><?echo $lang['upgrade.publish']?></td>
    <td style="text-align:center;"><?echo $lang['upgrade.modified']?></td>
  </tr>
  <?php
  $singlerow=true;
  while($rs=$db->fetch_array($query)){
  	$fileextname=strtolower((false===($dpos=strrpos($rs["filepath"],'.')))?'':substr($rs["filepath"],$dpos+1));	
  ?>
 <tr class="forumrow<?php if($singlerow)echo "1"?>" style="padding:1px;">
    <td style="text-align:center;"><input type="checkbox" name="fileid[]" value="<?echo $rs["id"]?>"></td>
    <td height="25" style="text-align:center;"><?echo $rs["filepath"]?></td>
    <td height="25" style="text-align:center;"><?echo formatSize($rs["filesize"])?></td>
    <td height="25" style="text-align:center;"><?php echo $lang['upgrade.level'.$rs["securitylevel"]]?> </td>
    <td height="25" style="text-align:center;"><?echo $rs["securityalert"]?></td>
    <td height="25" style="text-align:center;"><?echo $lang['upgrade.status'.$rs["isdone"]]?></td>
    <td height="25" style="text-align:center;"><?echo date("Y-m-d H:i:s",$rs["lastupdate"])?></td>
    <td height="25" style="text-align:center;"><?
    if($rs["lastmodified"]==0){
    	echo $lang['upgrade.nooperator'];
    }else{
    	echo date("Y-m-d H:i:s",$rs["lastmodified"]);
    }
     ?></td>
</tr>
  <?php
  $singlerow=$singlerow?false:true;
  }
 ?>
  <tr class="forumrow">
        <td><input type="checkbox" id="optSelectAll" value="" onclick="selectall(document.getElementById('optSelectAll').checked)" >全选<input type="hidden" name="reaction" value="log"><input type="hidden" id="doaction" name="doaction" value=""></td>
		<td colspan="7"><input type="submit" class="button" class="myButton" value="<?echo $lang['upgrade.restore']?>"  onclick="document.getElementById('doaction').value='restore';" name="button">&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" class="button" class="myButton" value="<?echo $lang['upgrade.update']?>" onclick="document.getElementById('doaction').value='update'" name="button">&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" class="button" class="myButton" value="<?echo $lang['upgrade.delete']?>" onclick="if(confirm('<?echo $lang['upgrade.delete_enter']?>')){document.getElementById('doaction').value='delete'}else{return false};" name="button"></td>
		
	</tr>
<?php
  }else{?>
	 <tr class="forumrow">
		<td colspan="7" align="center"><font color=red><?php echo $lang["upgrade.info22"]?></font></td>
	</tr>
<?php
  }?>
	</form>
</table>		
<table width="100%"  border="1" cellspacing="1" cellpadding="1" class="tableborder">
  <tr>
    <td style="height:25px;">
	<?
	if($total!=0){
		$p = new page;
		$p->setall($page,$total,$page_size,$lang['upgrade.item'],$lang['upgrade.message'],'100%','center','biz');
		print $p->printpage(null,1);
	}
	?>
	</td>
  </tr>
</table>
  
<?}?>
<script language="javascript">
var total=0;
var ajax=getajax();
var curfile=false;
var finishcount=0;
var enabled=true;
var finished=false;
var downsize=0;
function getajax(){
	try{
		ajax = new ActiveXObject("Microsoft.XMLHTTP");
	}catch(e){
		try{
			ajax = new ActiveXObject("Msxml2.XMLHTTP");
		}catch(e){
			try{
				ajax = new XMLHttpRequest();
			}catch(e){
				ajax = null;
			}
		}
	}
	return ajax;
}


function upgradestart(){
	showupdate('visible');
	var files=document.getElementsByName("fileid");
	var filesizes=document.getElementsByName("filesize");
	for(i=0;i<files.length;i++){
		if(parseInt(files[i].value)!=0&&files[i].checked)total+=parseInt(filesizes[i].value);
	}
	if(finished){
		document.getElementById("text_01").innerHTML="<?php echo $lang["upgrade.info16"]?><BR>";
		return true;
	}
	document.getElementById("text_01").innerHTML="<?php echo $lang["upgrade.info17"]?><BR>";
	exec_upgrade();
}
function exec_upgrade(){
	if(!ajax){
		alert("<?echo $lang["upgrade.noajax"]?>");
		showupdate("hidden");
		return false;
	}

	var files=document.getElementsByName("fileid");
	var filesizes=document.getElementsByName("filesize");
	for(i=0;i<files.length;i++){
		if(parseInt(files[i].value)!=0&&files[i].checked){
			curfile=files[i];
			downsize+=parseInt(filesizes[i].value);
			break;
		}
	}
	if(i==files.length){
		//已经全部下载完成
		if(finished)return true;
		finished=true;
		document.getElementById("text_01").innerHTML+="<?php echo $lang["upgrade.info18"]?><BR>";
		alert('<?php echo $lang["upgrade.info18"]?>');
		window.location.href="?reaction=upgrade";
	}else{
		finishcount+=1;
		document.getElementById("text_01").innerHTML+="<?php echo $lang["upgrade.info19"]?><font color=red size=4>"+finishcount+"</font><?php echo $lang["upgrade.info20"].$lang["upgrade.info9"]?><BR>";
		ajax.open("GET", "upgrade.php?reaction=down&i="+curfile.value, true);
		ajax.setRequestHeader("Content-Type", "text/html;charset=<?echo $lang["upgrade.charset"]?>");
		ajax.setRequestHeader("If-Modified-Since","0");
		ajax.send(null);
	}
	try{
		ajax.onreadystatechange = ajaxOnResponsed;
	}catch(e){
		ajax.onload = ajaxOnResponsed;
		ajax.onerror = ajaxOnResponsed;
	}


}
function ajaxOnResponsed(){
	if(ajax.readyState == 4&&ajax.status==200){
		strhtml = ajax.responseText;
		result=strhtml.split("@@@");
		if(parseInt(result.length)==5){
			document.getElementById("text_01").innerHTML+=result[2]+"<BR>";
			if(parseInt(result[1])!=0){
				doOnerror(result[1]);
			}else{
				updateProgressBar();
				sc();
				if(downsize == total) {
					document.getElementById("btnfinish").disabled = false;
				}
				curfile.value=0;
				if(enabled){
					if(!finished){
						exec_upgrade();
					}else{
						window.setTimeout('window.document.location="?reaction=upgrade"',1000);
					}
				}else{
					enabled=true;
				}
			}
		}else{
			//返回数据格式错误
			alert('数据格式错误');
			location="?reaction=upgrade";
		}
	}else{

	}
}

function doOnerror(errno){
	errno=parseInt(errno);
	switch(errno){
		case 1:
		break;
		case 2:
		break;
		case 4:
		break;
		case 8:
		alert('<?php echo $lang['upgrade.info7']?>');
		window.location.href="upgrade.php?reaction=upgrade";
		break;
		case 2147483647:
		break;
		default :
		break;
	}
}
function doOnCancel(){
	showupdate("hidden");
	enabled=false;
}

function doOnFinished(){
	showupdate("hidden");
	window.document.location="?reaction=log";
}

function showupdate(s){
	var thiswin=window.parent.document.getElementById("frmright");
	window.scroll(0,0);
	var objback=document.getElementById("back");
	var objupcontent=document.getElementById("main");
	objback.style.background="#333333";
	objback.style.filter="alpha(opacity=40)";
	objback.style.height=thiswin.document.body.clientHeight;
	objback.style.visibility=s;
	objupcontent.style.visibility=s;
}

function selectall(bl){
	var files=document.getElementsByName("fileid[]");
	for(i=0;i<files.length;i++){
		files[i].checked=bl;
	}
}
function selectneg(){
	var files=document.getElementsByName("fileid[]");
	for(i=0;i<files.length;i++){
		files[i].checked=(!files[i].checked);
	}
}
function checkform(){
	var files=document.getElementsByName("fileid[]");
	for(i=0;i<files.length;i++){
		if(files[i].checked)return true;
	}
	alert("<?php echo $lang["upgrade.nochoose"]?>");
	return false;
}

function updateProgressBar() {
	p = parseInt(downsize/total*100)+ "%";
	document.getElementById("Pointer").style.width = p;
	document.getElementById("Lable").innerHTML = p;
}

function sc()
{
	var e=document.getElementById("text_01")
	e.scrollTop=e.scrollHeight;
}

</script>