<?php
define('IN_ADMINCP', true);
require '../../../source/class/class_core.php';
require '../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(
  DB::table('mocuz_member_device') => "CREATE TABLE `".DB::table('mocuz_member_device')."` (
    `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
    `devicetoken` varchar(100) NOT NULL DEFAULT '',
    `platform` varchar(15) NOT NULL DEFAULT '',
    `uid` mediumint(8) unsigned NOT NULL,
    `status` tinyint(1) unsigned NOT NULL DEFAULT '1',
    PRIMARY KEY (`id`),
    KEY `status` (`status`),
    KEY `uid_devicetoken_platform` (`uid`,`devicetoken`,`platform`),
    KEY `devicetoken` (`devicetoken`)
  ) ENGINE=MyISAM AUTO_INCREMENT=7 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;
    }
}
?>
