File: /www/wwwroot/bb.cwoyt.com/Application/Install/Controller/InstallController.class.php
<?php
// +----------------------------------------------------------------------
// | OneThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: 赛脑 <2233759493@qq.com> <http://www.sn.com>
// +----------------------------------------------------------------------
namespace Install\Controller;
use Think\Controller;
use Think\Db;
class InstallController extends Controller
{
protected function _initialize()
{
if(session('step') === null)
{
$this->redirect('step1');
}
if(is_file(MODULE_PATH . 'Data/install.lock'))
{
$this->error('已经成功安装了赛脑订单系统,请不要重复安装!', U('Index/index'));
}
}
public function step1()
{
session('error', false);
$env = check_env();
$dirfile = check_dirfile();
$func = check_func();
session('step', 1);
$this->assign('env', $env);
$this->assign('dirfile', $dirfile);
$this->assign('func', $func);
$this->display();
}
public function step2($db = null, $admin = null)
{
if(IS_POST)
{
include 'function.php';
$u = domain($_SERVER['HTTP_HOST']);
if($u == 3)
{
$this->error('当前域名未授权');
}
else if($u == 2)
{
$this->error('当前域名正常使用中');
}
$info = array( 'username' => 'admin', 'password' => 'admin', 'repassword' => 'admin', 'email' => 'admin@qq.com', );
session('admin_info', $info);
if(!is_array($db) || empty($db[0]) || empty($db[1]) || empty($db[2]) || empty($db[3]))
{
$this->error('请填写完整的数据库配置');
}
else
{
$conn = mysql_connect($db[1], $db[3], $db[4]);
if($conn)
{
$DB = array();
list($DB['DB_TYPE'], $DB['DB_HOST'], $DB['DB_NAME'], $DB['DB_USER'], $DB['DB_PWD'], $DB['DB_PORT'], $DB['DB_PREFIX']) = $db;
session('db_config', $DB);
$dbname = $DB['DB_NAME'];
unset($DB['DB_NAME']);
$db = Db::getInstance($DB);
$sql = "CREATE DATABASE IF NOT EXISTS `{$dbname}
` DEFAULT CHARACTER SET utf8";
$db->execute($sql) || $this->error($db->getError());
}
//else
//{
// $this->error('数据库链接失败!');
//}
}
$this->success('跳转到数据库安装页面!',U('step3'));
}
else
{
//session('error') && $this->error('环境检测没有通过,请调整环境后重试!');
$step = session('step');
if($step != 1 && $step != 2)
{
$this->redirect('step1');
}
session('step', 2);
$this->display();
}
}
public function step3()
{
if(session('step') != 2)
{
$this->redirect('step2');
}
$this->display();
$dbconfig = session('db_config');
$db = Db::getInstance($dbconfig);
create_tables($db, $dbconfig['DB_PREFIX']);
$auth = build_auth_key();
$admin = session('admin_info');
register_administrator($db, $dbconfig['DB_PREFIX'], $admin, $auth);
write_config($dbconfig, $auth);
if(session('error'))
{
delDirAndFile('Runtime');
session('step', 3);
$this->redirect('Install/Index/complete');
}
else
{
delDirAndFile('Runtime');
session('step', 3);
$this->redirect('Install/Index/complete');
}
}
}
?>