<?php
/*
	[SupeSite] (C) 2007-2009 Comsenz Inc.
	$Id: update.php 11565 2009-03-10 07:21:08Z zhaofei $
*/

if(!@include('./common.php')) {
	exit('请将本文件移到程序根目录再运行!');
}

error_reporting(0);

//不让计划任务执行
$_SGLOBAL['cronnextrun'] = $_SGLOBAL['timestamp']+3600;

//新SQL
$sqlfile = S_ROOT.'./data/install.sql';
if(!file_exists($sqlfile)) {
	show_msg('最新的SQL不存在,请先将最新的数据库结构文件 install.sql 已经上传到 ./data 目录下面后，再运行本升级程序');
}

$lockfile = './data/update.lock';
if(file_exists($lockfile)) {
	show_msg('警告!您已经升级过SupeSite数据库结构<br>
		为了保证数据安全，请立即手动删除 update.php 文件<br>
		如果您想再次升级SupeSite，请删除 data/update.lock 文件，再次运行安装文件');
}

//提交处理
if(submitcheck('delsubmit')) {
	//删除表
	if(!empty($_POST['deltables'])) {
		foreach ($_POST['deltables'] as $tname => $value) {
			$_SGLOBAL['db']->query("DROP TABLE ".tname($tname));
		}
	}
	//删除字段
	if(!empty($_POST['delcols'])) {
		foreach ($_POST['delcols'] as $tname => $cols) {
			foreach ($cols as $col => $indexs) {
				if($col == 'PRIMARY') {
					$_SGLOBAL['db']->query("ALTER TABLE ".tname($tname)." DROP PRIMARY KEY", 'SILENT');//屏蔽错误
				} elseif($col == 'KEY') {
					foreach ($indexs as $index => $value) {
						$_SGLOBAL['db']->query("ALTER TABLE ".tname($tname)." DROP INDEX `$index`", 'SILENT');//屏蔽错误
					}
				} else {
					$_SGLOBAL['db']->query("ALTER TABLE ".tname($tname)." DROP `$col`");
				}
			}
		}
	}

	show_msg('删除表和字段操作完成了', '?step=3');
}

//处理开始
if(empty($_GET['step'])) {
	//开始
	$_GET['step'] = 0;

	show_msg('
	<div id="notice">
	<font style="color:#F00"><strong>升级警告：</strong><br><br>
	本版为独立的SupeSite功能，原来的X-Space功能将全部取消，数据库中将不在保留这些数据，请做好备份工作。<br><br>

	<strong>不保留的功能：</strong><br>
	用户空间数据、日志、图片主题、影音、文件、圈子、商品、书签、专题、好友、用户风格、脚印、留言、日志分类、评论<br>
	<br></font>	
	<strong>保留的功能：</strong><br>
	广告、公告、系统分类、频道、模型、模块、收藏、友情链接、投票、资讯、采集器、资讯评论等<br>
	<br>
	<strong>如果需要保留上述功能，请选择我们的UCenter Home产品，UCenter Home会对原X-Space数据进行转换。</strong><br>
	<a href="http://u.discuz.net/" target="_blank">UCenter Home官方站点</a>
	<br><br>
	<a href="javascript:;" onclick="ready();">我已经认真阅读以上规则，进入升级...</a><br>
	</div>
	
	<div id="ready" style="display:none;">
	本升级程序会参照最新的SQL文,对您的SupeSite数据库进行升级。<br><br>
	升级前请做好以下前期工作：<br><br>
	<b>第一步：</b><br>
	备份当前的数据库，避免升级失败，造成数据丢失而无法恢复；<br><br>
	<b>第二步：</b><br>
	将程序包 ./upload/ 目录中，除 config.new.php 文件、./install/ 目录以外的其他所有文件，全部上传并覆盖当前程序。<b>特别注意的是，最新数据库结构 ./data/install.sql 文件不要忘记上传，否则会导致升级失败</b>；<br><br>
	<b>第三步：</b><br>
	确认已经将程序包 ./update 目录中最新的 update.php 升级程序上传到服务器程序根目录中<br>
	<br><br>
	<a href="javascript:;" onclick="notice();">返回升级警告</a>&nbsp;&nbsp;
	<a href="update.php?step=1">已经做好了以上工作，升级开始</a><br><br>
	特别提醒：为了数据安全，升级完毕后，不要忘记删除本升级文件。
	</div>
	<script>
		function $(id) {
			return document.getElementById(id);
		}
		function notice() {
			$(\'notice\').style.display = \'\';
			$(\'ready\').style.display = \'none\';
		}
		function ready() {
			$(\'notice\').style.display = \'none\';
			$(\'ready\').style.display = \'\';
		}
	</script>
	');

} elseif ($_GET['step'] == 1) {

	//config.php检测
	$newconfigvalues = array(
		'var' => array('$_SC', '$_SC[\'dbhost\']', '$_SC[\'dbuser\']', '$_SC[\'dbpw\']', '$_SC[\'dbname\']', '$_SC[\'tablepre\']', '$_SC[\'pconnect\']', '$_SC[\'dbcharset\']', '$_SC[\'siteurl\']', 
						'$_SC[\'dbhost_bbs\']', '$_SC[\'dbuser_bbs\']', '$_SC[\'dbpw_bbs\']', '$_SC[\'dbname_bbs\']', '$_SC[\'tablepre_bbs\']', '$_SC[\'pconnect_bbs\']', '$_SC[\'dbcharset_bbs\']', '$_SC[\'bbsver\']', '$_SC[\'bbsurl\']', '$_SC[\'bbsattachurl\']', 
						'$_SC[\'dbhost_uch\']', '$_SC[\'dbuser_uch\']', '$_SC[\'dbpw_uch\']', '$_SC[\'dbname_uch\']', '$_SC[\'tablepre_uch\']', '$_SC[\'pconnect_uch\']', '$_SC[\'dbcharset_uch\']', '$_SC[\'uchurl\']', '$_SC[\'uchattachurl\']', '$_SC[\'uchftpurl\']', 
						'$_SC[\'founder\']', '$_SC[\'dbreport\']', '$_SC[\'cookiepre\']', '$_SC[\'cookiedomain\']', '$_SC[\'cookiepath\']', '$_SC[\'headercharset\']', '$_SC[\'charset\']', '$_SC[\'adminemail\']', '$_SC[\'sendmail_silent\']', '$_SC[\'mailsend\']', 
						'$mailcfg', '$mailcfg[\'maildelimiter\']', '$mailcfg[\'mailusername\']', '$mailcfg[\'server\']', '$mailcfg[\'port\']', '$mailcfg[\'auth\']', '$mailcfg[\'from\']', '$mailcfg[\'auth_username\']', '$mailcfg[\'auth_password\']', '$_SC[\'tplrefresh\']', '$_SC[\'cachegrade\']'),
		'define' => array('UC_CONNECT', 'UC_DBHOST', 'UC_DBUSER', 'UC_DBPW', 'UC_DBNAME', 'UC_DBCHARSET', 'UC_DBTABLEPRE', 'UC_DBCONNECT', 'UC_KEY', 'UC_API', 'UC_CHARSET', 'UC_IP', 'UC_APPID', 'UC_PPP')
	);
	$configcontent = sreadfile(S_ROOT.'/config.php');
	preg_match_all("/([$].*?)[\s\t\n]/i", $configcontent, $configvars);
	preg_match_all("/define\('(UC_.*?)'/i", $configcontent, $configdefines);
	$scarcity = array();
	foreach($newconfigvalues as $key => $val) {
		foreach($val as $value) {
			if(!in_array($value, ($key == 'var' ? $configvars[1] : $configdefines[1]))) $scarcity[] = $value;
		}
	}
	if(!empty($scarcity)) {
		show_msg('当前服务器上“config.php”文件不是最新，需要您对其进行更新。<br/><br/>
				文件中缺少的参数:<br/>'.implode('<br/>', $scarcity).'<br/><br/>
				请参考程序包 ./upload 目录中，config.new.php文件，将现行config.php文件更新后，再运行本升级程序');
	}
	
	//新的SQL
	$sql = sreadfile($sqlfile);
	preg_match_all("/CREATE\s+TABLE\s+supe\_(.+?)\s+\((.+?)\)\s+(TYPE|ENGINE)\=/is", $sql, $matches);
	$newtables = empty($matches[1])?array():$matches[1];
	$newsqls = empty($matches[0])?array():$matches[0];
	if(empty($newtables) || empty($newsqls)) {
		show_msg('最新的SQL不存在,请先将最新的数据库结构文件 install.sql 已经上传到 ./data 目录下面后，再运行本升级程序');
	}

	//升级表
	$i = empty($_GET['i'])?0:intval($_GET['i']);
	if($i>=count($newtables)) {
		//处理完毕
		show_msg('数据库结构升级完毕，进入下一步操作', '?step=2');
	}
	
	//当前处理表
	$newtable = $newtables[$i];
	$newcols = getcolumn($newsqls[$i]);

	//获取当前SQL
	if(!$query = $_SGLOBAL['db']->query("SHOW CREATE TABLE ".tname($newtable), 'SILENT')) {
		//添加表
		preg_match("/(CREATE TABLE .+?)\s+[TYPE|ENGINE]+\=/is", $newsqls[$i], $maths);
		if(strpos($newtable, 'session')) {
			$type = mysql_get_server_info() > '4.1' ? " ENGINE=MEMORY".(empty($_SC['dbcharset'])?'':" DEFAULT CHARSET=$_SC[dbcharset]" ): " TYPE=HEAP";
		} else {
			$type = mysql_get_server_info() > '4.1' ? " ENGINE=MYISAM".(empty($_SC['dbcharset'])?'':" DEFAULT CHARSET=$_SC[dbcharset]" ): " TYPE=MYISAM";
		}
		$usql = $maths[1].$type;
		$usql = str_replace("CREATE TABLE supe_", 'CREATE TABLE '.$_SC['tablepre'], $usql);
		if(!$_SGLOBAL['db']->query($usql, 'SILENT')) {
			show_msg('添加表 '.tname($newtable).' 出错,请手工执行以下SQL语句后,再重新运行本升级程序:<br><br>'.shtmlspecialchars($usql));
		} else {
			$msg = '添加表 '.tname($newtable).' 完成';
		}
	} else {
		$value = $_SGLOBAL['db']->fetch_array($query);
		$oldcols = getcolumn($value['Create Table']);

		//获取升级SQL文
		$updates = array();
		foreach ($newcols as $key => $value) {
			if($key == 'PRIMARY') {
				if($value != $oldcols[$key]) {
					if(!empty($oldcols[$key])) $updates[] = "DROP PRIMARY KEY";
					$updates[] = "ADD PRIMARY KEY $value";
				}
			} elseif ($key == 'KEY') {
				foreach ($value as $subkey => $subvalue) {
					if(!empty($oldcols['KEY'][$subkey])) {
						if($subvalue != $oldcols['KEY'][$subkey]) {
							$updates[] = "DROP INDEX `$subkey`";
							$updates[] = "ADD INDEX `$subkey` $subvalue";
						}
					} else {
						$updates[] = "ADD INDEX `$subkey` $subvalue";
					}
				}
			} else {
				if(!empty($oldcols[$key])) {
					if(str_replace('mediumtext', 'text', $value) != str_replace('mediumtext', 'text', $oldcols[$key])) {
						$updates[] = "CHANGE `$key` `$key` $value";
					}
				} else {
					$updates[] = "ADD `$key` $value";
				}
			}
		}

		//升级处理
		if(!empty($updates)) {
			$usql = "ALTER TABLE ".tname($newtable)." ".implode(', ', $updates);
			if(!$_SGLOBAL['db']->query($usql, 'SILENT')) {
				show_msg('升级表 '.tname($newtable).' 出错,请手工执行以下升级语句后,再重新运行本升级程序:<br><br><b>升级SQL语句</b>:<div style=\"position:absolute;font-size:11px;font-family:verdana,arial;background:#EBEBEB;padding:0.5em;\">'.shtmlspecialchars($usql)."</div><br><b>Error</b>: ".$_SGLOBAL['db']->error()."<br><b>Errno.</b>: ".$_SGLOBAL['db']->errno());
			} else {
				$msg = '升级表 '.tname($newtable).' 完成';
			}
		} else {
			$msg = '检查表 '.tname($newtable).' 完成，不需升级';
		}
	}

	//处理下一个
	$next = '?step=1&i='.($_GET['i']+1);
	show_msg($msg, $next);

} elseif ($_GET['step'] == 2) {
	
	//6.0.1 -> 7.0 数据处理
	
	//config
	$sitekey = mksitekey();
	$datas = array(
		"'template', 'default'",
		"'sitekey', '$sitekey'"
	);
	$_SGLOBAL['db']->query("REPLACE INTO ".tname('settings')." (`variable`, `value`) VALUES (".implode('),(', $datas).")");
	
	$needupdate = 1;
	$query = $_SGLOBAL['db']->query("SELECT grouptitle,managedelmembers FROM ".tname('usergroups')." LIMIT 1");
	if($value = @$_SGLOBAL['db']->fetch_array($query)) {
		$needupdate = 0;
	}
	if(empty($value['grouptitle'])) {
		$needupdate = 1;
	} elseif(empty($value['managedelmembers'])) {
		$needupdate = 2;
	}
	//6.0.1 -> 7.0 正式
	if($needupdate == 1) {
		//usergroups
		$datas = array(
			"'1', '管理员', '0', '1', '0', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '0', '1', '1'",
			"'2', '普通用户组', '0', '1', '1', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '1', '0', '0', '0', '1', '0', '0'"
		);
		$_SGLOBAL['db']->query("TRUNCATE TABLE ".tname('usergroups'));
		$_SGLOBAL['db']->query("INSERT INTO ".tname('usergroups').
								" (groupid, grouptitle, system, managespacenews, needcheck, managerobots, managerobotmessages, managecategories, managesettings, manageusergroups, manageannouncements, managead, manageblocks, managebbs, managebbsforums, managethreads, manageuchome, managemodels, managechannel, managemember, managedelmembers, managehtml, managecache, managewords, manageattachmenttypes, managedatabase, managetpl, managecrons, managecheck, managecss, managefriendlinks, manageprefields, managesitemap, manageitems, managecomments, manageattachments, managetags, managereports, managepolls, managecustomfields, managestyles, managestyletpl, managemodelmanages, managemodelfolders, managemodelcategories, allowundelete, modelneedcheck, allowmodelundelete, closeignore) ".
								" VALUES (".implode('),(', $datas).")");
		
		//修改用户组
		if(discuz_exists()) {
			dbconnect(1);
			$uids = array();
			$query = $_SGLOBAL['db_bbs']->query("SELECT uid FROM ".tname('members', 1)." WHERE adminid='1'");
			while($value = $_SGLOBAL['db']->fetch_array($query)) {
				$uids[] = $value['uid'];
			}
			$_SGLOBAL['db']->query('UPDATE '.tname('members').' SET groupid=\'2\' WHERE uid NOT IN ('.simplode($uids).')');
			$_SGLOBAL['db']->query('UPDATE '.tname('members').' SET groupid=\'1\' WHERE uid IN ('.simplode($uids).')');
		}
	} elseif($needupdate == 2) {
		$_SGLOBAL['db']->query('UPDATE '.tname('usergroups').' SET managedelmembers=\'1\' WHERE groupid = \'1\'');
	}
	
	//删除多余频道
	deletetable('channels', 'nameid IN (\'link\', \'blog\', \'video\', \'topic\', \'file\', \'image\', \'group\', \'goods\')');
	
	//删除多余计划任务
	deletetable('crons', 'filename IN (\'cleanvisitors.php\', \'cleantracks.php\', \'updatespaceviewnum.php\', \'makearchiver.php\')');
	
	//添加站点是否开放注册默认值
	$query = $_SGLOBAL['db']->query("SELECT value FROM ".tname('settings')." WHERE variable='allowregister'");
	$haveallowregister = $_SGLOBAL['db']->fetch_array($query);
	if(empty($haveallowregister)) {
		$_SGLOBAL['db']->query("REPLACE INTO ".tname('settings')." (`variable`, `value`) VALUES ('allowregister', '1')");
	}
	
	//处理下一个
	$next = 'update.php?step=3';
	show_msg("数据库数据升级完毕，进入下一步", $next);
							
} elseif ($_GET['step'] == 3) {

	//检查需要删除的字段

	//老表集合
	$oldtables = array();
	$query = $_SGLOBAL['db']->query("SHOW TABLES LIKE '$_SC[tablepre]%'");
	while ($value = $_SGLOBAL['db']->fetch_array($query)) {
		$values = array_values($value);
		if(!strexists($values[0], 'cache')) {
			$oldtables[] = $values[0];//分表、缓存
		}
	}

	//新表集合
	$sql = sreadfile($sqlfile);
	preg_match_all("/CREATE\s+TABLE\s+supe\_(.+?)\s+\((.+?)\)\s+(TYPE|ENGINE)\=/is", $sql, $matches);
	$newtables = empty($matches[1])?array():$matches[1];
	$newsqls = empty($matches[0])?array():$matches[0];

	//需要删除的表
	$deltables = array();
	$delcolumns = array();

	//老的有，新的没有
	foreach ($oldtables as $tname) {
		$tname = substr($tname, strlen($_SC['tablepre']));
		if(in_array($tname, $newtables)) {
			//比较字段是否多余
			$query = $_SGLOBAL['db']->query("SHOW CREATE TABLE ".tname($tname));
			$cvalue = $_SGLOBAL['db']->fetch_array($query);
			$oldcolumns = getcolumn($cvalue['Create Table']);

			//新的
			$i = array_search($tname, $newtables);
			$newcolumns = getcolumn($newsqls[$i]);

			//老的有，新的没有的字段
			foreach ($oldcolumns as $colname => $colstruct) {
				if(!strexists($colname, 'field_')) {
					if($colname == 'PRIMARY') {
						//关键字
						if(empty($newcolumns[$colname])) {
							$delcolumns[$tname][] = 'PRIMARY';
						}
					} elseif($colname == 'KEY') {
						//索引
						foreach ($colstruct as $key_index => $key_value) {
							if(empty($newcolumns[$colname][$key_index])) {
								$delcolumns[$tname]['KEY'][$key_index] = $key_value;
							}
						}
					} else {
						//普通字段
						if(empty($newcolumns[$colname])) {
							$delcolumns[$tname][] = $colname;
						}
					}
				}
			}
		} else {
			if(!preg_match("/(categories|comments|items|message|rates|folders)$/i", $tname)) $deltables[] = $tname;
		}
	}

	//显示
	show_header();
	echo '<form method="post" action="update.php?step=3">';
	echo '<input type="hidden" name="formhash" value="'.formhash().'">';

	//删除表
	$deltablehtml = '';
	if($deltables) {
		$deltablehtml .= '<table>';
		foreach ($deltables as $tablename) {
			$deltablehtml .= "<tr><td><input type=\"checkbox\" name=\"deltables[$tablename]\" value=\"1\"></td><td>{$_SC['tablepre']}$tablename</td></tr>";
		}
		$deltablehtml .= '</table>';
		echo "<p>以下 数据表 与标准数据库相比是多余的:<br>您可以根据需要自行决定是否删除</p>$deltablehtml";
	}

	//删除字段
	$delcolumnhtml = '';
	if($delcolumns) {
		$delcolumnhtml .= '<table>';
		foreach ($delcolumns as $tablename => $cols) {
			foreach ($cols as $col) {
				if (is_array($col)) {
					foreach ($col as $index => $indexvalue) {
						$delcolumnhtml .= "<tr><td><input type=\"checkbox\" name=\"delcols[$tablename][KEY][$index]\" value=\"1\"></td><td>{$_SC['tablepre']}$tablename</td><td>索引 $index $indexvalue</td></tr>";
					}
				} elseif($col == 'PRIMARY') {
					$delcolumnhtml .= "<tr><td><input type=\"checkbox\" name=\"delcols[$tablename][PRIMARY]\" value=\"1\"></td><td>{$_SC['tablepre']}$tablename</td><td>主键 PRIMARY</td></tr>";
				} else {
					$delcolumnhtml .= "<tr><td><input type=\"checkbox\" name=\"delcols[$tablename][$col]\" value=\"1\"></td><td>{$_SC['tablepre']}$tablename</td><td>字段 $col</td></tr>";
				}
			}
		}
		$delcolumnhtml .= '</table>';

		echo "<p>以下 字段 与标准数据库相比是多余的:<br>您可以根据需要自行决定是否删除</p>$delcolumnhtml";
	}

	if(empty($deltables) && empty($delcolumns)) {
		echo "<p>与标准数据库相比，没有需要删除的数据表和字段</p><a href=\"?step=4\">请点击进入下一步</a></p>";
	} else {
		echo "<p><font style=\"color:#F00;\">如果您需要将原X-Space转换到UCenter Home，请先转换后再删除这些数据。</font></p><p><input type=\"submit\" name=\"delsubmit\" value=\"提交删除\"></p><p>您也可以忽略多余的表和字段<br><a href=\"?step=4\">直接进入下一步</a></p>";
	}
	echo '<input type="hidden" name="formhash" value="'.formhash().'"></form>';

	show_footer();
	exit();

} elseif ($_GET['step'] == 4) {
		
	//更新缓存
	include_once(S_ROOT.'./function/cache.func.php');

	updatesettingcache();
	//用户组缓存
	updategroupcache();
	//广告缓存
	updateadcache();
	//crons列表
	updatecronscache();
	//计划任务
	updatecroncache();
	//分类
	updatecategorycache();
	//缓存语言屏蔽
	updatecensorcache();
	if(discuz_exists()) {
		//缓存论坛设置
		updatebbssetting();
		//缓存论坛风格设置
		updatebbsstyle();
		//缓存论坛bbcode/smiles
		updatebbsbbcode();
	}
	
	//写log
	if(@$fp = fopen($lockfile, 'w')) {
		fwrite($fp, 'SupeSite');
		fclose($fp);
	}

	show_msg('升级完成，为了您的数据安全，避免重复升级，请登录FTP删除本文件!');
}


//正则匹配,获取字段/索引/关键字信息
function getcolumn($creatsql) {

	preg_match("/\((.+)\)/is", $creatsql, $matchs);

	$cols = explode("\n", $matchs[1]);
	$newcols = array();
	foreach ($cols as $value) {
		$value = trim($value);
		if(empty($value)) continue;
		$value = remakesql($value);//特使字符替换
		if(substr($value, -1) == ',') $value = substr($value, 0, -1);//去掉末尾逗号

		$vs = explode(' ', $value);
		$cname = $vs[0];

		if(strtoupper($cname) == 'KEY') {
			$subvalue = trim(substr($value, 3));
			$subvs = explode(' ', $subvalue);
			$subcname = $subvs[0];
			$newcols['KEY'][$subcname] = trim(substr($value, (5+strlen($subcname))));
		} elseif(strtoupper($cname) == 'INDEX') {
			$subvalue = trim(substr($value, 5));
			$subvs = explode(' ', $subvalue);
			$subcname = $subvs[0];
			$newcols['KEY'][$subcname] = trim(substr($value, (7+strlen($subcname))));
		} elseif(strtoupper($cname) == 'PRIMARY') {
			$newcols['PRIMARY'] = trim(substr($value, 11));
		} else {
			$newcols[$cname] = trim(substr($value, strlen($cname)));
		}
	}
	return $newcols;
}

//整理sql文
function remakesql($value) {
	$value = trim(preg_replace("/\s+/", ' ', $value));//空格标准化
	$value = str_replace(array('`',', ', ' ,', '( ' ,' )'), array('', ',', ',','(',')'), $value);//去掉无用符号
	$value = preg_replace('/(text NOT NULL) default \'\'/i',"\\1", $value);//去掉无用符号
	return $value;
}

//显示
function show_msg($message, $url_forward='') {
	global $_SGLOBAL;

	obclean();

	if($url_forward) {
		$_SGLOBAL['extrahead'] = '<meta http-equiv="refresh" content="1; url='.$url_forward.'">';
		$message = "<a href=\"$url_forward\">$message(跳转中...)</a>";
	} else {
		$_SGLOBAL['extrahead'] = '';
	}

	show_header();
	print<<<END
	<table>
	<tr><td>$message</td></tr>
	</table>
END;
	show_footer();
	exit();
}


//页面头部
function show_header() {
	global $_SGLOBAL, $_SC;

	$nowarr = array($_GET['step'] => ' class="current"');

	if(empty($_SGLOBAL['extrahead'])) $_SGLOBAL['extrahead'] = '';

	print<<<END
	<!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=$_SC[charset]" />
	$_SGLOBAL[extrahead]
	<title> SupeSite 数据库升级程序 </title>
	<style type="text/css">
	* {font-size:12px; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 1.5em; word-break: break-all; }
	body { text-align:center; margin: 0; padding: 0; background: #F5FBFF; }
	.bodydiv { margin: 40px auto 0; width:720px; text-align:left; border: solid #86B9D6; border-width: 5px 1px 1px; background: #FFF; }
	h1 { font-size: 18px; margin: 1px 0 0; line-height: 50px; height: 50px; background: #E8F7FC; color: #5086A5; padding-left: 10px; }
	#menu {width: 100%; margin: 10px auto; text-align: center; }
	#menu td { height: 30px; line-height: 30px; color: #999; border-bottom: 3px solid #EEE; }
	.current { font-weight: bold; color: #090 !important; border-bottom-color: #F90 !important; }
	.showtable { width:100%; border: solid; border-color:#86B9D6 #B2C9D3 #B2C9D3; border-width: 3px 1px 1px; margin: 10px auto; background: #F5FCFF; }
	.showtable td { padding: 3px; }
	.showtable strong { color: #5086A5; }
	.datatable { width: 100%; margin: 10px auto 25px; }
	.datatable td { padding: 5px 0; border-bottom: 1px solid #EEE; }
	input { border: 1px solid #B2C9D3; padding: 5px; background: #F5FCFF; }
	.button { margin: 10px auto 20px; width: 100%; }
	.button td { text-align: center; }
	.button input, .button button { border: solid; border-color:#F90; border-width: 1px 1px 3px; padding: 5px 10px; color: #090; background: #FFFAF0; cursor: pointer; }
	#footer { font-size: 10px; line-height: 40px; background: #E8F7FC; text-align: center; height: 38px; overflow: hidden; color: #5086A5; margin-top: 20px; }
	</style>
	</head>
	<body>
	<div class="bodydiv">
	<h1>SupeSite数据库升级工具</h1>
	<div style="width:90%;margin:0 auto;">
	<table id="menu">
	<tr>
	<td{$nowarr[0]}>升级开始</td>
	<td{$nowarr[1]}>数据库结构添加/升级</td>
	<td{$nowarr[2]}>数据库数据升级</td>
	<td{$nowarr[3]}>数据库结构删除</td>
	<td{$nowarr[4]}>升级完成</td>
	</tr>
	</table>
	<br>
END;
}

//页面顶部
function show_footer() {
	print<<<END
	</div>
	<div id="footer">&copy; Comsenz Inc. 2001-2009 http://www.supesite.com</div>
	</div>
	<br>
	</body>
	</html>
END;
}

?>