<?php

set_time_limit(0);
include("../global.php");

if($_GET[step]!="4"){
	echo '<!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=utf-8" />
<title>正在升级中.... - - Powered by PHPYun.</title>

<link href="'.$config[sy_weburl].'/template/member/style/msg.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div class="content" style="background:f5f5f5;">
  <div class="content-title" style="width:100%"><span style="width:100%">正在升级中,已进行'.$_GET[step].'/4</span></div>
  <div style="border:1px solid #ccc; float:left;width:100%;">
    <dl style="width:100%">
       <p style="text-align:center;"><img src="loading.gif"></p><br>
	   <p style="text-align:center;"><font color="red">本次更新时间较长,请不要中途中断,以免升级失败,请耐心等待！</font></p>
    </dl>
</div>
</div>
</body>
</html>';
};
if($_GET[step]==""){

	echo "<script>location.href='$config[sy_weburl]/update/index.php?step=1';</script>";

}

/****************************第一步：新增数据字段************************************/
if($_GET[step]=="1"){

	$db->query("ALTER TABLE `$db_config[def]answer_review` ADD COLUMN `status`  int(11) NULL DEFAULT 0");

	$db->query("ALTER TABLE `$db_config[def]answer_review` ADD COLUMN `statusbody`  text");

	$db->query("ALTER TABLE `$db_config[def]answer` ADD COLUMN `status`  int(11) NULL DEFAULT 0");

	$db->query("ALTER TABLE `$db_config[def]answer` ADD COLUMN `statusbody`  text");

	$db->query("ALTER TABLE `$db_config[def]yqmb` ADD COLUMN `status`  int(11) NULL DEFAULT 0");

	$db->query("ALTER TABLE `$db_config[def]yqmb` ADD COLUMN `statusbody`  text");

	$db->query("ALTER TABLE `$db_config[def]msg` ADD COLUMN `status`  int(11) NULL DEFAULT 0");

	$db->query("ALTER TABLE `$db_config[def]msg` ADD COLUMN `statusbody`  text");

	$db->query("ALTER TABLE `$db_config[def]msg` ADD COLUMN `issys`  int(11) NULL DEFAULT 0");

	$db->query("ALTER TABLE `$db_config[def]company` ADD COLUMN `expoure`  int(11) NULL DEFAULT 0");

	$db->query("ALTER TABLE `$db_config[def]company_job` ADD COLUMN `jobexpoure`  int(11) NULL DEFAULT 0");

	$db->query("ALTER TABLE `$db_config[def]company_cert` ADD COLUMN `social_credit`  varchar(255) NULL DEFAULT ''");

	
	if(!$config['com_yqmb_status']){
	
		$db->query("INSERT INTO `$db_config[def]admin_config` SET `name`='com_yqmb_status',`config`='0'");
		
		$config['com_yqmb_status'] = '0';
	
	}
	if(!$config['user_msg_status']){
	
		$db->query("INSERT INTO `$db_config[def]admin_config` SET `name`='user_msg_status',`config`='0'");
		
		$config['user_msg_status'] = '0';
	
	}
	if(!$config['answer_check']){
	
		$db->query("INSERT INTO `$db_config[def]admin_config` SET `name`='answer_check',`config`='0'");
		
		$config['answer_check'] = '0';
	
	}
	if(!$config['answer_review_check']){
	
		$db->query("INSERT INTO `$db_config[def]admin_config` SET `name`='answer_review_check',`config`='0'");
		
		$config['answer_review_check'] = '0';
	
	}

	if(!$config['answer_review_check']){
	
		$db->query("INSERT INTO `$db_config[def]admin_config` SET `name`='answer_review_check',`config`='0'");
		
		$config['answer_review_check'] = '0';
	
	}

	if(!$config['warning_sendresume']){
	
		$db->query("INSERT INTO `$db_config[def]admin_config` SET `name`='warning_sendresume',`config`='20'");
		
		$config['warning_sendresume'] = '20';
	
	}
	
	
	made_web(PLUS_PATH.'config.php',ArrayToString($config),'config');
	


	echo "<script>location.href='$config[sy_weburl]/update/index.php?step=2';</script>";

}
/****************************第二步：调整默认数据************************************/


if($_GET[step]=="2"){


	$db->query("UPDATE `" . $db_config[def] . "answer_review` SET `status` ='1'");
	$db->query("UPDATE `" . $db_config[def] . "answer` SET `status` ='1'");
	$db->query("UPDATE `" . $db_config[def] . "yqmb` SET `status` ='1'");
	$db->query("UPDATE `" . $db_config[def] . "msg` SET `status` ='1',`issys`='1'");

	$db->query("UPDATE `" . $db_config[def] . "company` SET `expoure` =`hits` + 0");

	$db->query("UPDATE `" . $db_config[def] . "company_job` SET `jobexpoure` =`jobhits` + 0");

	echo "<script>location.href='$config[sy_weburl]/update/index.php?step=3';</script>";
}


/****************************第三步：清空缓存************************************/
if($_GET[step]=="3"){
	$delfiles="data/templates_c";
	$dh=@opendir($delfiles);
	while($file=@readdir($dh)){
		if($file!="."&&$file!=".."){
			$fullpath=$delfiles."/".$file;
			@unlink($fullpath);
		}
	}
	@closedir($dh);
	echo "<script>location.href='$config[sy_weburl]/update/index.php?step=4';</script>";
}
/****************************第六步：升级完成************************************/
if($_GET[step]=="4"){
	echo "数据库升级成功！请删除/update/ 目录 根据以下提示继续操作！";
	echo "<pre>";
	echo "1：进入后台 系统-设置-网站LOGO 设置修改相关新增默认图选项";
	echo "<pre>";
	echo "2：进入后台 工具-生成-<font color='red'>生成缓存(数据库缓存)</font>";
	echo "<pre>";
	echo "3：进入后台 清除缓存";
	echo "<pre>";
	echo "4：其他各项配置按需修改";
	echo "<pre>";
}

?>