<?php
define('IN_ADMINCP', true);
require '../../source/class/class_core.php';
require '../3.0/config.php';
$chaeset="'".ODZ_CHARSET."'";
if($chaeset == "'utf-8'"){
    $chaeset = 'utf8';
}
header('Content-Type:text/html; charset=utf-8');
error_reporting(0);



//初始化环境
C::app()->init();
$url = parse_url($_G['siteurl']);
$_G['siteurl'] = $url['scheme'].'://'.$url['host'].'/';


include './config.php';


//扩展检测
echo '开始检测扩展<br/>';
$is_ok = true;
foreach($extensions as $extension){
	if(!extension_loaded($extension)){
		echo '<span style="color:red">'.$extension.'扩展不存在</span><br/>';
		$is_ok = false;
	}
}

if(!$is_ok){
	exit;
}

echo '<span style="color:#cc0000">扩展检测正确，检测完毕</span><br/>';

echo '<br/>';
//建表
echo '开始建立相关表<br/>';
$tables = array(
  'mocuz_common_member_wechat_bind' => "CREATE TABLE IF NOT EXISTS `mocuz_common_member_wechat_bind` (
                                    `uid` varchar(50) NOT NULL,
                                      `openid` char(32) NOT NULL DEFAULT '',
                                      `wechatname` char(50) NOT NULL DEFAULT '',
                                      `status` tinyint(1) NOT NULL DEFAULT '0' COMMENT '0已绑定，1删除绑定',
                                      PRIMARY KEY (`uid`),
                                      UNIQUE KEY `openid` (`openid`)
                                  ) ENGINE=MyISAM DEFAULT CHARSET=utf8",
'mocuz_member_password_status'=>"CREATE TABLE `mocuz_member_password_status` (
                                    `uid` varchar(50) NOT NULL,
                                    `login_type` tinyint(1) unsigned NOT NULL COMMENT '2免密登录，3微信登录',
                                    `password_status` tinyint(1) NOT NULL DEFAULT 1 COMMENT '1未设置，2已设置',
                                    PRIMARY KEY (`uid`)
                                  ) ENGINE=MyISAM DEFAULT CHARSET=utf8"
  );

foreach($tables as $table => $sql){
    $query_sql = "SHOW TABLES LIKE '{$table}'";
    if(DB::fetch_first($query_sql)){
       echo '<span style="color:blue">'.$table.'表已经存在</span><br/>';
       continue;
    }
    if(DB::query($sql)){
      echo $table.'建立成功<br/>';
    }else{
      echo $table.'建立失败<br/>';
      echo mysql_error().'<br/>';
      exit;
    }
}

$insert_sql = array("INSERT INTO `mocuz_card_setting` (`key`, `value`) values('not_password','0')");
foreach($insert_sql as $v){
    if(!DB::query($v)){
        echo "数据插入失败，请确认是否已存在"."</br>";
    }else{
        echo "数据插入成功</br>";
    }
}
?>
