<?php
##
#	Project: PHPDISK File Storage Solution
#	This is NOT a freeware, use is subject to license terms.
#
#	Site: http://www.phpdisk.com
#
#	$Id: update68to70_utf8.php 310 2010-08-09 12:25:00Z along $
#
#	Copyright (C) 2008-2013 PHPDisk Team. All Rights Reserved.
#
##

$timestamp = time();
define('PHPDISK_ROOT', dirname(__FILE__));
define('IN_PHPDISK',TRUE);
define('SERVER_NAME',$_SERVER['SERVER_NAME']);

require_once PHPDISK_ROOT.'/system/configs.inc.php';
require_once PHPDISK_ROOT.'/includes/class/mysql.class.php';
require_once PHPDISK_ROOT.'/includes/function/global.func.php';

$db = new cls_mysql;
$db->connect($configs['dbhost'],$configs['dbuser'],$configs['dbpasswd'],$configs['dbname'],$configs['pconnect']);
unset($configs['dbhost'],$configs['dbuser'],$configs['dbpasswd'],$configs['pconnect'],$configs['charset']);

$tpf = $configs['tpf'];

pd_setcookie('phpdisk_info','');
$script_name = 'update68to70_utf8.php';
set_time_limit(900);
$step = (int)gpc('step','G',0);
$per_item = 50;
$total_step = 3;
$charset = 'utf-8';
$db_charset = array('utf-8'=>'utf8','gbk'=>'gbk');

$step_arr = array('准备数据转换','升级旧版本数据库结构','更新PHPDisk 7.0数据库结构','转换PHPDisk 6.8版数据');
?>
<!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=<?=$charset?>" />
<title>PHPDisk 6.8版 -> 7.0 数据转换程序 </title>
<style type="text/css">
body{ font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px}
.main{width:900px; margin:auto; padding:0 20px; border:8px #f2f2f2 solid}
.txtred{color:#FF0000}
.txtblue{color:#0000FF}
.txtgreen{color:#008800}
.txtgray{color:#666666}
</style>
</head>

<body>
<div class="main">
<h2>PHPDisk 6.8版 -> 7.0 数据转换程序<span class="txtgreen">[<?=strtoupper($charset)?>]</span>：第 <b><span class="txtred"><?=$step?></span> / <?=$total_step?> </b> 步</h2>
<h3 class="txtgray"><?=str_repeat('=',10).'&nbsp;&nbsp;'.$step_arr[$step].'&nbsp;&nbsp;'.str_repeat('=',10)?></h3>
<?
$next_txt = "<br><br><br><li><input type=\"button\" value=\"第 ".$step." 步转换成功，点击按钮进入第 ".($step+1)." 步 >>\" onclick=\"document.location='{$script_name}?step=".($step+1)."';\" /></li>";

switch($step){
	case 1:
		$sql_p ="ALTER TABLE  `pd_files` ADD  `yun_fid` BIGINT( 20 ) UNSIGNED NOT NULL DEFAULT  '0' AFTER  `file_id` ;";
    $sql_p .="DROP TABLE IF EXISTS `pd_uploadx_files`;";
	$sql_p .= "CREATE TABLE IF NOT EXISTS `pd_uploadx_files` (
  `id` char(8) NOT NULL,
  `userid` int(10) unsigned NOT NULL DEFAULT '0',
  `file_name` varchar(255) NOT NULL,
  `file_extension` varchar(30) NOT NULL,
  `file_size` int(10) unsigned NOT NULL DEFAULT '0',
  `file_parts` int(10) unsigned NOT NULL DEFAULT '0',
  `file_local_path` varchar(255) NOT NULL,
  `file_store_path` varchar(100) NOT NULL,
  `file_real_name` varchar(255) NOT NULL,
  `file_state` tinyint(1) unsigned NOT NULL DEFAULT '0',
  `file_time` int(10) unsigned NOT NULL DEFAULT '0',
  `folder_id` int(10) NOT NULL DEFAULT '0',
  `ip` varchar(15) NOT NULL,
  PRIMARY KEY (`id`),
  KEY `file_state` (`file_state`),
  KEY `userid` (`userid`)
) ENGINE=MyISAM DEFAULT CHARSET={$charset};";

		$arr_p = explode(';',$sql_p);
		for($i=0;$i<count($arr_p)-1;$i++){
			$db->query($arr_p[$i]);
			echo "<li>SQL Query: {$arr_p[$i]} ...... <span class=\"txtblue\">OK</span>.</li>";
		}
		echo $next_txt;
		break;

	case 2:

		echo $next_txt;

		break;

	case 3:

		echo "<h3 class='txtblue'>PHPDISK 6.8版 -> 7.0 数据转换成功。请按照转换文档继续操作。</h3>";
		echo "<h3 class='txtred'>注意：为了系统完全，转换成功后请删除此转换文件！！！</h3>";
		break;

	default:
		echo "<input type=\"button\" value=\"PHPDISK 6.8版 -> 7.0 数据转换，点击现在开始。\" onclick=\"document.location='{$script_name}?step=1';\" />";

}

function gonext($url,$timeout=1000){
	echo "<script>\r\n";
	echo "<!--\r\n";
	echo "function redirect() {\r\n";
	echo "	window.location.replace('$url');\r\n";
	echo "}\r\n";
	echo "setTimeout('redirect();', $timeout);\r\n";
	echo "-->\r\n";
	echo "</script>\r\n";
}

?>
<br /><br /><br />
<div align="center">PHPDisk Team 2008-2014&nbsp;&nbsp;<a href="http://bbs.phpdisk.com/" target="_blank">交流论坛</a>&nbsp;&nbsp;<a href="http://faq.phpdisk.com/" target="_blank">教程帮助</a></div>
</div>
</body>
</html>
