<?php
/*
'**************************************************************************************************
' 软件名称: 盘锦DJ舞曲网CMS Content Management PjRen.Net
' 版本编号: Version 2.5
' 盘锦舞曲: http://www.pj57.com
' 官方网站: http://www.pjren.net
' 小说网站: http://www.hx39.com
' 0427DJ网: http://www.0427dj.net
' 官方论坛: http://www.tianjiazhen.com
' 版权所有: 盘锦舞曲开发团队    盘锦人(QQ:814006710)
' 郑重声明:
'    1、任何个人或组织不得在未经授权的情况下删除、修改、拷贝本软件及其他副本上一切关于版权的信息；
'    2、盘锦网络事业部保留此软件的法律追究权利
'**************************************************************************************************
*/
include "../include/conn.php";
include "../include/function.php";
include "admin_version.php";
include "admin_loginstate.php";
@set_time_limit(0);
?>
<!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>后台程序升级</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" />
<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>
<body>
<?php
SystemPer(1);
if(!remote_file_exists("http://www.pjren.net/pjren_net_vip/update.xml")){
	die("对不起,载入远程升级文件出错1!");
	}
for($ii=0;$ii<4;$ii++){
	$UpdateContent=@file_get_contents("http://www.pjren.net/pjren_net_vip/update.xml");
	if($UpdateContent) break;
}

if(!IsNul($UpdateContent)){
	$UpdateContent=geturl("http://www.pjren.net/pjren_net_vip/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="100%" border="0" cellpadding="0" cellspacing="0"  class="tb_style">
        	<tr>
            	<td class="td_title" colspan="4">&nbsp;程序升级中......&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://vip.l.gp/zhuangbi/".$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");
		$FileArr22=$FileArr2[0];
		$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.$FileArr22."|".$FileArr2[2];
			}
		else{
			$Local=$Local."\r\n".$FileArr22."|".$FileArr2[2];
			}
		
?>
           	<tr>
            	<td class="td_border" height="30">&nbsp;<?php echo ($k+1)?></td>
                <td class="td_border">&nbsp;<?php echo $FileArr2[0]?>(<?php echo $FileArr2[2]?>)</td>
                <td class="td_border">&nbsp;<?php echo $FileArr2[1]?></td>
              	<td align="center" class="td_border">&nbsp;<font color="green">更新成功</font></td>
            </tr>
<?php	
		}
	fwrite(fopen("backup/log.txt","wb"),$Local);
?>		
        	<tr>
            	<td class="td_border" colspan="4">&nbsp;<input type="button" onclick="window.location='admin_update.php'" value="返回升级页面" class="rb1"></td>
         </tr>
      </table>	
<?php	
	die();
	}
?>
<body>
<div class="r_main">
	<div class="r_content">
		<div class="r_content_1">
        <form action="?action=update" method="post" name="from1" id="form1">
        <table width="100%" border="0" cellpadding="0" cellspacing="0"  class="tb_style">
        	<tr>
            	<td class="td_title" colspan="4">&nbsp;程序升级系统&nbsp;</td>
            </tr>
             <tr>
            	<td width="6%" height="30" class="td_border">&nbsp;选择</td>
                <td width="44%" class="td_border">&nbsp;文件名</td>
                <td width="38%" 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);
	$UpdatedFile=$FileArr[0];
	$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" height="30">&nbsp;<input type="checkbox" class="checkbox" name="S_ID[]" id="S_ID" value="<?php echo $i?>"><?php echo ($i+1)?></td>
                <td class="td_border">&nbsp;<?php echo $FileArr[0]?>(<?php echo $FileArr[2]?>)</td>
                <td 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" 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" class="td_border" height="30">&nbsp;<font color='red'>＊ 注意：为了防止出现意外错误，自动更新前请先做好文件备份！</font></td>
            </tr>           
		
        </table>
        </form>
		</div>
	</div>
</div>
<?php include "admin_bottom.php" ?>
</body>
