<?php
if(!@include('./includes/common.inc.php')) {
	exit('请将本文件移到程序根目录再运行!');
}
require_once "./includes/cache.func.php";
function splitsql($sql){
	$sql = str_replace("\r", "\n", $sql);
	$ret = array();
	$num = 0;
	$queriesarray = explode(";", trim($sql));
	unset($sql);
	foreach($queriesarray as $query) {
		$queries = explode("\n", trim($query));
		foreach($queries as $query) {
			$ret[$num] .= $query[0] == "#" ? NULL : $query;
		}
		$num++;
	}
	return($ret);
}
if($system_version['homesite'] <> 'pic.71116.com'){
	exit('非官方下载的原版程序和修改过的程序不允许进行升级!');
}
if($system_version['version'] < '1.24'){
?>
<!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>美女图片 Cms 升级程序 v1.23 to v1.24</title>
<style type="text/css">
<!--
body,td {font-family: Geneva, Arial, Helvetica, sans-serif, Tahoma;font-size: 12px;color:#1876b7;}
.login {font-family: Geneva, Arial, Helvetica, sans-serif, Tahoma;font-size: 12px;height: 16px;border-top-width: 1px;border-right-width: 1px;border-bottom-width: 1px;border-left-width: 1px;border-top-color: #FFFFFF;border-right-color: #EEEEEE;border-bottom-color: #EEEEEE;border-left-color: #FFFFFF;background-color: #f2f2f2;}
input,textarea {font-family: Geneva, Arial, Helvetica, sans-serif, Tahoma;font-size: 12px;border-top-width: 1px;border-right-width: 1px;border-bottom-width: 1px;border-left-width: 1px;border-top-color: #FFFFFF;border-right-color: #EEEEEE;border-bottom-color: #EEEEEE;border-left-color: #FFFFFF;background-color: #f2f2f2;}
a {color: #1876b7;text-decoration: none;}
a:hover {color: #000000;text-decoration: underline;}
.smalltxt{ font: 11px Arial, Tahoma; }
Input,select,textarea{ font: 11px Tahoma, Verdana; color: #000000; font-weight: normal; background-color: #F8F8F8; }
form{ margin: 0; padding: 0;}
select{ font: 11px Arial, Tahoma; color: #000000; font-weight: normal; background-color: #F8F8F8; }
.nav{ font: 12px Tahoma, Verdana; color: #000000; font-weight: bold; }
.nav a{ color: #000000;}
.header{ font: 12px Tahoma, Verdana; color: #1876B7; font-weight: bold;background-color: #DAEEFA;background-image:url(images/header.gif);}
.header a{ color: #1876b7; }
.category{ font: 11px Arial, Tahoma; color: #000000; background-color: #EEF6F9; }
.tableborder{ background: #DCEEF6; border: 1px solid #98D5EC }
 .smalltxt{ font: 11px Arial, Tahoma; }
.bold{ font-weight: bold; }
.altbg1{ background: #F8F8F8; }
.altbg2{ background: #FFFFFF; }
.maintable{ width: 98%; background-color: #FFFFFF; }
.menu {color:#FFFFFF;}
.menu a{color:#FFFFFF;font-weight:bold;}
.menu a:hover{color:#CCFFFF;}
-->
</style>
</head>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<table border="0" cellspacing="1" cellpadding="3" width="680" align="center" class="tableborder">
<tr><td class="header">
<center>
美女图片 Cms 升级程序 v1.23 to v1.24
</center>
</td>
</tr>
<? 
	if(empty($step)) {
?>
<tr><td bgcolor="#ffffff">
<center>
<br>
<br>
你是否现在开始进行系统升级?
<input type=button value="是" class="button" onclick="location.href='updatev124.php?step=update';">
<input type=button value="否" class="button" onclick="location.href='updatev124.php?step=update_exit';">&emsp;&emsp;<BR>
<br><br>&nbsp;&nbsp;<font color=red><b>注意事项:</b></font>安装后请务必删除“updatev124.php”!
</center>
</td>
</tr>
</table>
<?
	} elseif($step=='update') {
?>
<tr><td bgcolor="#ffffff" align="left">
<form name="form1" method="post" action="updatev124.php">
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;升级注意事项:<br><br>
<li>升级程序会新建数据表：<?=$tablepre?>ping 以防万一请先备份所有数据</li><br><br>
<li>如果数据表名存在时，还要进行安装，则点击强制升级。<font color=red>注：如果升级的数据表名存在的话，请谨慎操作！！！</font></li><br><br>
<li>请选择安装方式：<input class="radio" type="radio" name="step" value="doupdate" checked> 默认升级
<input class="radio" type="radio" name="step" value="coerce"> 强制升级(会删除同名数据表，请谨慎使用该选项)</li><br><br>
<li><font color=red>升级完成后,必定要删除“updatev124.php”</font></li><br><br>
<li><font color=red>升级完成后,进人后台设置首页FLASH图片压缩尺寸为 宽 420 px 高 240 px </font></li><br><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;点击按钮开始升级&nbsp;&nbsp;&nbsp;&nbsp;
<input type="submit" value="开始升级" class="button">
</form>
</td></tr></table>
<?
	} elseif($step=='update_exit') {
		header("Location:/");
		mexit();
	} elseif($step=='doupdate' or $step == 'coerce') {
	$tablearr = array($tablepre.'ping');
	$query = $db->query("show tables");
	while($row = $db->fetch_row($query)) {
		if(in_array($row[0], $tablearr)) {
			if($step == "coerce"){
				$db->query("DROP TABLE IF EXISTS `".$row[0]."`", 1);
			} else {
				echo "数据表名存在，不能进行升级，如果还要升级请选择强制升级<br><a href='javascript:history.back()'>[ 点击返回 ]</a>";
				mexit();
			}
		}
	}
	$pluscharset = "gbk";
	$pluscharstr = $pluscharset ? " CHARACTER SET ".$pluscharset : "";
	$query = "
CREATE TABLE {$tablepre}ping (
  id mediumint(8) NOT NULL auto_increment,
  pid smallint(3) NOT NULL default '0',
  uid smallint(3) NOT NULL default '0',
  uname varchar(20) NOT NULL default '',
  uip varchar(20) NOT NULL default '',
  uding smallint(3) NOT NULL default '0',
  face varchar(100) NOT NULL default '',
  pingl mediumtext NOT NULL,
  `time` date NOT NULL default '0000-00-00',
  PRIMARY KEY  (id)
) TYPE=MyISAM{$pluscharstr};
";
$sqlquery = splitsql($query);
foreach($sqlquery as $sql) {
	if(trim($sql) != '') {
		$db->query(stripslashes($sql));
		if($sqlerror = $db->error()) {
			break;
		}
	}
}
?>
<tr><td bgcolor="#ffffff">
<center>
数据库升级完成!<br>
请上传 update 目录内的文件覆盖完成升级！<br>
进人后台设置首页FLASH图片压缩尺寸为 宽 420 px 高 240 px 
<br>
<br>
<a href=/admin>点击这里进入后台</a>
<br><br>
</center>
</td></tr>
</table>
<?
	}
} else {
echo "您当前的版本是：V ".$system_version['version']."与升级版本不符合。";
}
	
?>