<?php
include "../include/function.php";
include '../comm/conn.php';
include '../comm/config.php';
include '../comm/checkpostandget.php';
include 'check.php';
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>后台程序升级-YES风淘宝客网赚系统</title>
<script type="text/javascript" language="javascript">var tentpath='<?php echo S_SitePath?>';</script>
<script src="js/jquery.js"></script>
<script src="js/alerts.js"></script>
<link href="images/alerts.css" rel="stylesheet" type="text/css" media="screen"/>
<link  href="images/style.css" rel="stylesheet" type="text/css" />
<link href="../images/style1.css" rel="stylesheet" type="text/css">
<link href="../images/sty.css" rel="stylesheet" type="text/css">
<script language="javascript">
 $(document).ready(function(){
	$("#ChkAll").click(function(){
		if($(this).attr("checked")==true){
			$("input[id='S_ID']").each(function(){
				$(this).attr("checked",true);									 
			})							
		}else{
			$("input[id='S_ID']").each(function(){
				$(this).attr("checked",false);									 
			})							
		}
		})
	
	$("#btn_update").click(function(){
		if($("input[@type=checkbox]:checked").size()==0){
       		alert('请选择要升级的文件!');
       		return false;
    	}
		$("#form1").submit();

		})
		
})	
</script>
</head>
<?php
include("../comm/head.php");
?>
<body>
<div align="center">
<div class="r_main">
	<div class="r_content">
		<div class="r_content_1">
<?php

if(!remote_file_exists("http://soft.yesfeng.com/php/mode2/update.xml")){
	die("对不起,载入远程升级文件出错!");
	}
for($ii=0;$ii<4;$ii++){
	$UpdateContent=@file_get_contents("http://soft.yesfeng.com/php/mode2/update.xml");
	if($UpdateContent) break;
}

if(!IsNul($UpdateContent)){
	$UpdateContent=geturl("http://soft.yesfeng.com/php/mode2/update.xml");
	}
if(!file_exists("backup/log.txt")){
	fwrite(fopen("backup/log.txt","wb"),"");
	}
$Local=file_get_contents("backup/log.txt");
$FileInfoArr=explode(chr(13),$UpdateContent);
$action=SafeRequest("action","get");
if($action=="update"){
	$ID=RequestBox("S_ID");
	$S_Path=$_SERVER['PHP_SELF'];
	
	$S_PathPos=strrpos($S_Path,'/');
	$S_Path=substr($S_Path,0,$S_PathPos+1);
	$S_Path=substr($S_Path,strlen(S_SitePath));
	$S_ID=explode(",",$ID);
?>
        <table width="950" border="0" cellpadding="0" cellspacing="0"  class="tb_style">
        	<tr>
            	<td class="td_title" align="left"  colspan="4">&nbsp;程序升级中-更换模板为【模板2】......&nbsp;</td>
         </tr>
           

<?php
	for($k=0;$k<count($S_ID);$k++){
		$FileArr2=explode('|',$FileInfoArr[$S_ID[$k]]);
		$FileArr2[0]=trim($FileArr2[0]);
		$S_FilePath="http://soft.yesfeng.com/php/mode2/".$FileArr2[0]."";
		if(!remote_file_exists($S_FilePath)){
			echo ReplaceStr($FileArr2[0],".xml",".php")."远程文件不存在";
			}
		else{
			for($kk=0;$kk<4;$kk++){
				$FileContent=@file_get_contents($S_FilePath);
				if($FileContent) break;
				}
				
			if(!IsNul($FileContent)){
				$FileContent=geturl($S_FilePath);
				}
			}
		$FileArr2[0]=ReplaceStr($FileArr2[0],".xml",".php");
		$FileArr2[0]=ReplaceStr($FileArr2[0],"admin/",$S_Path);
		if(S_Dvname!="video"){
			$FileArr2[0]=ReplaceStr($FileArr2[0],"video/",S_Dvname."/");
			}
		if(S_Dtname!="topic"){
			$FileArr2[0]=ReplaceStr($FileArr2[0],"topic/",S_Dtname."/");
			}
		if(S_Dnname!="article"){
			$FileArr2[0]=ReplaceStr($FileArr2[0],"article/",S_Dnname."/");
			}
		fwrite(fopen("../".$FileArr2[0],"wb"),$FileContent);
		if($Local==""){
			$Local=$Local.$FileArr2[0]."|".$FileArr2[2];
			}
		else{
			$Local=$Local."\r\n".$FileArr2[0]."|".$FileArr2[2];
			}
		
?>
           	<tr>
            	<td class="td_border" align="left"  height="30">&nbsp;<?php echo ($k+1)?></td>
                <td align="left"  class="td_border">&nbsp;<?php echo $FileArr2[0]?>(<?php echo $FileArr2[2]?>)</td>
                <td  align="left" class="td_border">&nbsp;<?php echo $FileArr2[1]?></td>
              	<td align="left" align="center" class="td_border">?<font color="green">更新成功</font></td>
            </tr>
<?php	
		}
	fwrite(fopen("backup/log.txt","wb"),$Local);
?>		
        	<tr>
            	<td align="left" class="td_border"  colspan="4">&nbsp;<input type="button" onclick="window.location='admin_update.php'" value="返回升级页面" class="rb1"></td>
         </tr>
      </table>	
<?php	
	die();
	}
?>

        <form action="?action=update" method="post" name="from1" id="form1">
        <table width="950" border="0" cellpadding="0" cellspacing="0"  class="tb_style">
        	<tr>
            	<td class="td_title" colspan="4">&nbsp;
           	    <div align="left">程序升级系统-更换模板为【模板2】&nbsp;</div></td>
            </tr>
             <tr>
            	<td width="6%" align="left" height="30" class="td_border">&nbsp;选择</td>
                <td width="44%" align="left" class="td_border">&nbsp;文件名</td>
                <td width="38%" align="left" class="td_border">&nbsp;升级说明</td>
                <td width="12%" align="center" class="td_border">更新状态</td>
            </tr>
<?php
$S_Path2=$_SERVER['PHP_SELF'];
$S_PathPos=strrpos($S_Path2,'/');
$S_Path2=substr($S_Path2,0,$S_PathPos+1);
$S_Path2=substr($S_Path2,strlen(S_SitePath));

for($i=0;$i<(count($FileInfoArr));$i++){
	$FileArr=explode('|',$FileInfoArr[$i]);		
	$FileArr[0]=trim($FileArr[0]);
	$FileArr[0]=ReplaceStr($FileArr[0],".xml",".php");
	$UpdatedFile=ReplaceStr($FileArr[0],"admin/",$S_Path2);
	$Local=ReplaceStr($Local,S_Dvname."/","video/");
	$Local=ReplaceStr($Local,S_Dnname."/","article/");
	$Local=ReplaceStr($Local,S_Dtname."/","topic/");
	if(stristr($Local,$UpdatedFile."|".$FileArr[2])){
		$IsUpdate="<font color=green>文件已更新</font>";
		}
	else{
		$IsUpdate="<font color=red>文件未更新</font>";
		}
	$FileArr[0]="../".$FileArr[0];
?>
           	<tr>
            	<td class="td_border" align="left" height="30">&nbsp;<input type="checkbox" class="checkbox" name="S_ID[]" id="S_ID" value="<?php echo $i?>"><?php echo ($i+1)?></td>
                <td align="left" class="td_border">&nbsp;<?php echo $FileArr[0]?>(<?php echo $FileArr[2]?>)</td>
                <td align="left" class="td_border">&nbsp;<?php echo $FileArr[1]?></td>
              <td align="center" class="td_border">&nbsp;<?php echo $IsUpdate?></td>
            </tr>
	
<?php		
	}
?>            
            <tr>
            	<td colspan="4" align="left" class="td_border" height="30">&nbsp;<input type="checkbox" class="checkbox" id="ChkAll"> 
            	全选&nbsp;
            	&nbsp;&nbsp; <input type="submit" value="开始更新文件" class="rb1" id="btn_update"></td>
            </tr>
            <tr>
            	<td colspan="4" align="left" class="td_border" height="30">&nbsp;<font color='red'>＊ 注意：为了防止出现意外错误，自动更新前请先做好文件备份！</font></td>
            </tr>           
		
        </table>
        </form>
		</div>
	</div>
</div>
</div>
</body>
