<?
		set_time_limit(0);
		
		$f = new Hon6FetchURL;
		$iserror = 0;
		
		$fetchurl = "http://hon6.sinaapp.com/listphp.php?ver=".$version;
		$filejson = $f->get($fetchurl);
		$filearray = json_decode($filejson);
		
		$fetchurl = "http://hon6.sinaapp.com/getver.php?ver=".$version;
		$verjson = $f->get($fetchurl);
		$verarray = json_decode($verjson);
		
		$pagecontent = "";
		
		if(!$filearray->success){
				$url = array();
				$tourl = URL_admin_index($url);
				$pagecontent .= $filearray->filelist;
				$iserror = 1;
		}
		
		if(!$verarray->success){
				$url = array();
				$tourl = URL_admin_index($url);
				$pagecontent .= $verarray->getver;
				$iserror = 1;
		}
		
		if($act == "upgrade" && $iserror == 0){
				
				$totalfile = count($filearray->filelist)*2;
				
				$fileno = 0;
					                      
				$pix = 100 / $totalfile;
				$progress = 0; 

				?>
		<!DOCTYPE html>
		<html xmlns="http://www.w3.org/1999/html">
		<head>
    <meta charset="utf-8">
    <meta name="viewport" content="target-densitydpi=device-dpi, width=device-width, initial-scale=1.0, maximum-scale=1">
    
    <link href="templates/admin/css/modern.css" rel="stylesheet">
    <link href="templates/admin/css/modern-responsive.css" rel="stylesheet">
    <link href="templates/admin/css/site.css" rel="stylesheet" type="text/css">
    <link href="templates/admin/js/google-code-prettify/prettify.css" rel="stylesheet" type="text/css">

    <script type="text/javascript" src="templates/admin/js/assets/jquery-1.9.0.min.js"></script>
    <script type="text/javascript" src="templates/admin/js/assets/jquery.mousewheel.min.js"></script>
    <script type="text/javascript" src="templates/admin/js/assets/moment.js"></script>
    <script type="text/javascript" src="templates/admin/js/assets/moment_langs.js"></script>

    <script type="text/javascript" src="templates/admin/js/modern/dropdown.js"></script>
    <script type="text/javascript" src="templates/admin/js/modern/accordion.js"></script>
    <script type="text/javascript" src="templates/admin/js/modern/buttonset.js"></script>
    <script type="text/javascript" src="templates/admin/js/modern/carousel.js"></script>
    <script type="text/javascript" src="templates/admin/js/modern/input-control.js"></script>
    <script type="text/javascript" src="templates/admin/js/modern/pagecontrol.js"></script>
    <script type="text/javascript" src="templates/admin/js/modern/rating.js"></script>
    <script type="text/javascript" src="templates/admin/js/modern/slider.js"></script>
    <script type="text/javascript" src="templates/admin/js/modern/tile-slider.js"></script>
    <script type="text/javascript" src="templates/admin/js/modern/tile-drag.js"></script>
    <script type="text/javascript" src="templates/admin/js/modern/calendar.js"></script>
		<style> 
    body, div input { font-family: Tahoma; font-size: 9pt } 
    </style> 
    <script language="JavaScript"> 
    <!-- 
    function updateProgress(sMsg, iWidth) 
    {  
        document.getElementById("status").innerHTML = sMsg; 
        document.getElementById("progress").style.width = iWidth + "%"; 
        document.getElementById("percent").innerHTML = parseInt(iWidth) + "%";  
        document.getElementById("imgs").innerHTML = "<p align=\"center\" style=\"font-size:25px\"><i id=\"icon-resize-sample\" class=\"icon-checkmark\" style=\"font-size:100px;color:green;\"></i>V<?php echo $verarray->getver->gradeid; ?>升级完毕</h2></p>";
     } 
    //--> 
    </script> 
    <title>杰奇HON6插件在线升级</title>
		</head>
		
		<body class="metrouicss" onload="prettyPrint()">
		<div class="page secondary">
				<div class="page-header">
            <div class="page-header-content">
                <div class="user-login">
           			     <a href="<?php echo URL_admin_login(array("act"=>"logout")); ?>">
           			         <div class="name" style="line-height:22px">
           			             <span class="first-name"><?php echo $_SESSION["admin"]->name; ?></span>
           			             <span class="last-name">注销</span>
           			         </div>
           			         <div class="avatar">
           			             <?php 
           			             		if($_SESSION["admin"]->avatar == 2){
           			             ?><img src="/files/system/avatar/0/<?php echo $_SESSION["admin"]->uid; ?>_s.jpg" alt="头像载入中..."/>
           			             <?php
           			             		}elseif($SESSION["admin"]->avatar == 0){
           			             ?><img src="images/userhead.gif" alt="头像载入中..."/>
           			             <?php
           			             		}
           			             ?><br/>
           			         </div>
           			     </a>
           			 </div>
           			 <h1>在线升级<small>请认证阅读升级提示</small></h1>
                <a class="back-button big page-back" href="<?php echo URL_admin_index(array()); ?>"></a>
            </div>
        </div>
        <div class="page-region">
						<div class="page-region-content">
							<br/><br/> <br/><br/>
							<div id="imgs"><p align="center"><img src="templates/admin/images/preloader-w8-cycle-black.gif"/></p></div>
							<br/><br/>
		<div><font color="gray">从版本 V<?php echo $verarray->getver->lastgrade; ?> 升级版本至 V<?php echo $verarray->getver->gradeid; ?></font></div>
		<div class="progress-bar">
        <div class="bar" style="width: <?php echo $width; ?>"></div>
    </div>
    <div class="progress-bar"><div class="bar" id="progress"></div> </div>            
    <div id="status">&nbsp;</div> 
    <div id="percent" style="position: relative; top: -15px; text-align: right; font-weight: bold; font-size: 8pt">0%</div>
    <br/><br/>
<?php 
		flush();
		while ($fileno <= $totalfile/2) {  
		   							if($filearray->filelist[$fileno]){
		   									echo"<div class=\"bg-color-blueDark padding10 fg-color-white\">";
		   									for($a=0;$a<=1;$a++){
		   											echo "<script language=\"JavaScript\">";
		   											if($a == 0){
		   													check_dir(dirname("bak/".$verarray->getver->lastgrade."/".$filearray->filelist[$fileno]));
  															$ok = copy($filearray->filelist[$fileno],"bak/".$verarray->getver->lastgrade."/".$filearray->filelist[$fileno]); //拷贝到新目录
								   							echo "updateProgress(\"备份".$filearray->filelist[$fileno]."中...\", ".intval($progress).")"; 
								   					}else{
								   							$phpcontent = $f->get("http://hon6.sinaapp.com/readphp.php?path=".$filearray->filelist[$fileno]."&ver=".$verarray->getver->gradeid);
																check_dir(dirname($filearray->filelist[$fileno]));
																$file = fopen($filearray->filelist[$fileno],"w");
																$oks = fwrite($file, $phpcontent);//百度首页8K
																fclose($file);
								   							echo "updateProgress(\"升级".$filearray->filelist[$fileno]."中...\", ".intval($progress).")"; 
								   					}
								   					echo "</script>";
								   					if($a == 0){
								   							echo "备份".$filearray->filelist[$fileno]."至 插件目录bak/".$verarray->getver->lastgrade."/".$filearray->filelist[$fileno];
								   							if($ok){
								   									echo " <font color=\"yellow\">成功</font> ";
								   							}else{
								   									echo " <font color=\"red\">失败</font> (需要对文件夹的读写权限！)";
								   							}
								   							echo "<br/>";
								   					}else{
								   							echo "升级".$filearray->filelist[$fileno];
								   							if($oks){
								   									echo " <font color=\"yellow\">成功</font> ";
								   							}else{
								   									echo " <font color=\"red\">失败</font> (需要对文件夹的读写权限！)";
								   							}
								   							echo "<br/>";
								   					}
								   					$progress += $pix;
								   			}
								   			echo "</div>";
								   	}							
								   	flush();
								   	$fileno++;  
		}//end while
?> 
		<script language="JavaScript"> 
		    updateProgress("升级完成", <?php echo $progress; ?>); 
		</script>
<?php 
		flush(); 
?> 
								</div>
								<p align="right"><a href="<?php echo URL_admin_index(array()); ?>" class="button bg-color-red fg-color-white">返回</a></p>
						</div>
		</div>
		
				<div class="nav-bar">
		        <div class="page">
		        <div class="nav-bar">
		            <div class="nav-bar-inner padding30">
		                    <span class="element">
		                    2012-2013, 杰奇wap插件 V<?php echo $version; ?> &copy; by <a class="fg-color-white" href="http://hon6.cn">Hon6 Phper</a> QQ群:90427804 技术QQ:858111797
		                   	</span>
		            </div>
		        </div>
		        </div>
		    </div>
		
		
		    <script type="text/javascript" src="templates/admin/js/assets/google-analytics.js"></script>
		    <script type="text/javascript" src="templates/admin/js/google-code-prettify/prettify.js"></script>
		    <script src="templates/admin/js/sharrre/jquery.sharrre-1.3.4.min.js"></script>
		
		    </body>
		</html>> 
				<?
				$f->get("http://hon6.sinaapp.com/upgrade.php?ver=".$version);
				exit();
				
		}elseif($iserror == 0){
				$smartydate = array("pagetitle" => "杰奇HON6插件在线升级",
														"filearray" => $filearray,
														"verarray" => $verarray,
													);

				$tplpath = "upgrade.tpl";
		}elseif($iserror == 1){
				$smartydate = array("pagetitle" => "杰奇HON6插件在线升级",
														"pagecontent" => $pagecontent."<br/>",
														"tourl" => $tourl,
														"redirecturl" => $tourl,
													);

				$tplpath = "public.tpl";
		}
?>