* finish the install module.

This commit is contained in:
wangchunsheng
2010-01-01 14:36:09 +00:00
parent 79e09bbd1f
commit c8104f9198
9 changed files with 307 additions and 18 deletions

View File

@@ -23,9 +23,17 @@
*/
class install extends control
{
/* 构造函数,检查是否是通过安装入口调用。*/
public function __construct()
{
if(!defined('IN_INSTALL')) die();
parent::__construct();
}
/* 安装程序首页。*/
public function index()
{
if(!isset($this->config->installed) or !$this->config->installed) $this->session->set('installing', true);
$this->view->header->title = $this->lang->install->welcome;
$this->display();
}
@@ -50,7 +58,6 @@ class install extends control
public function step2()
{
$this->view->header->title = $this->lang->install->setConfig;
$this->view->webRoot = $this->install->getWebRoot();
$this->display();
}
@@ -59,10 +66,49 @@ class install extends control
{
if(!empty($_POST))
{
$this->view = (object)$_POST;
$this->view->lang = $this->lang;
$this->view->config = $this->config;
$this->view->header->title = $this->lang->install->saveConfig;
$return = $this->install->checkConfig();
if($return->result == 'ok')
{
$this->view = (object)$_POST;
$this->view->lang = $this->lang;
$this->view->config = $this->config;
$this->view->header->title = $this->lang->install->saveConfig;
$this->display();
}
else
{
$this->view->header->title = $this->lang->install->saveConfig;
$this->view->error = $return->error;
$this->display();
}
}
else
{
$this->locate($this->createLink('install'));
}
}
/* 第四步,创建公司,生成管理员帐号。*/
public function step4()
{
if(!empty($_POST))
{
$this->install->grantPriv();
if(dao::isError()) die(js::error(dao::getError()));
echo (js::alert($this->lang->install->success));
unset($_SESSION['installing']);
die(js::locate('index.php', 'parent'));
}
$this->view->header->title = $this->lang->install->getPriv;
if(!isset($this->config->installed) or !$this->config->installed)
{
$this->view->error = $this->lang->install->errorNotSaveConfig;
$this->display();
}
else
{
$this->view->pmsDomain = $this->server->HTTP_HOST;
$this->display();
}
}

View File

@@ -22,20 +22,20 @@
* @link http://www.zentao.cn
*/
$lang->install->common = '安装';
$lang->install->next = '下一步';
$lang->install->pre = '返回';
$lang->install->reload = '刷新';
$lang->install->error = '错误 ';
$lang->install->start = '开始安装';
$lang->install->welcome = '欢迎使用禅道项目管理软件!';
$lang->install->desc = <<<EOT
禅道项目管理软件(ZenTaoPMS)是一款国产的基于LGPL协议开源免费的项目管理软件它集产品管理、项目管理、测试管理于一体同时还包含了事务管理、组织管理等诸多功能是中小型企业项目管理的首选。
禅道项目管理软件使用PHP + MySQL开发基于自主的PHP开发框架──ZenTaoPHP而成。第三方开发者或者企业可以非常方便的开发插件或者进行定制。
EOT;
$lang->install->start = '开始安装';
$lang->install->next = '下一步';
$lang->install->reload = '刷新';
$lang->install->checking = '系统检查';
$lang->install->setConfig = '生成配置文件';
$lang->install->saveConfig = '保存配置文件';
$lang->install->settingDB = '设置数据库';
$lang->install->save2File = '拷贝上面文本框中的内容,将其保存到"%s"中。';
$lang->install->ok = '检查通过(√)';
$lang->install->fail = '检查失败(×)';
$lang->install->loaded = '已加载';
@@ -44,12 +44,11 @@ $lang->install->exists = '目录存在 ';
$lang->install->notExists = '目录不存在 ';
$lang->install->writable = '目录可写 ';
$lang->install->notWritable= '目录不可写 ';
$lang->install->phpINI = 'PHP配置文件';
$lang->install->checkItem = '检查项';
$lang->install->current = '当前配置';
$lang->install->result = '检查结果';
$lang->install->action = '如何修改';
$lang->install->key = '配置项';
$lang->install->value = '值';
$lang->install->phpVersion = 'PHP版本';
$lang->install->phpFail = 'PHP版本必须大于5.2.0';
@@ -63,6 +62,7 @@ $lang->install->dataRoot = '上传文件目录';
$lang->install->mkdir = '<p>需要创建目录%s。<br /> linux下面命令为<br /> mkdir -p %s</p>';
$lang->install->chmod = '需要修改目录 "%s" 的权限。<br />linux下面命令为<br />chmod o=rwx -R %s';
$lang->install->settingDB = '设置数据库';
$lang->install->webRoot = 'PMS所在网站目录';
$lang->install->requestType = 'URL方式';
$lang->install->requestTypes['GET'] = '普通方式';
@@ -73,3 +73,27 @@ $lang->install->dbUser = '数据库用户名';
$lang->install->dbPassword = '数据库密码';
$lang->install->dbName = 'PMS使用的库';
$lang->install->dbPrefix = '建表使用的前缀';
$lang->install->createDB = '自动创建数据库';
$lang->install->clearDB = '清空现有数据';
$lang->install->errorConnectDB = '数据库连接失败 ';
$lang->install->errorCreateDB = '数据库创建失败';
$lang->install->errorCreateTable = '创建表失败';
$lang->install->setConfig = '生成配置文件';
$lang->install->key = '配置项';
$lang->install->value = '值';
$lang->install->saveConfig = '保存配置文件';
$lang->install->save2File = '拷贝上面文本框中的内容,将其保存到 " %s "中。';
$lang->install->errorNotSaveConfig = '还没有保存配置文件';
$lang->install->getPriv = '设置帐号';
$lang->install->company = '公司名称';
$lang->install->pms = 'PMS地址';
$lang->install->pmsNote = '即通过什么地址可以访问到禅道项目管理设置域名或者IP地址即可不需要http';
$lang->install->account = '管理员帐号';
$lang->install->password = '管理员密码';
$lang->install->errorEmptyPassword = '密码不能为空';
$lang->install->success = "安装成功请删除install.php登录禅道管理系统设置用户及分组";

View File

@@ -98,4 +98,142 @@ class installModel extends model
{
return rtrim(pathinfo($_SERVER['SCRIPT_NAME'], PATHINFO_DIRNAME), '/') . '/';
}
/* 检查配置。*/
public function checkConfig()
{
$return->result = 'ok';
/* 连接到数据库。*/
$this->setDBParam();
$this->dbh = $this->connectDB();
if(!is_object($this->dbh))
{
$return->result = 'fail';
$return->error = $this->lang->install->errorConnectDB . $this->dbh;
return $return;
}
/* 获得数据库版本。*/
$version = $this->getMysqlVersion();
/* 数据库不存在,尝试建之。*/
if(!$this->dbExists())
{
if(!$this->createDB($version))
{
$return->result = 'fail';
$return->error = $this->lang->install->errorCreateDB;
return $return;
}
}
/* 创建表。*/
if(!$this->createTable($version))
{
$return->result = 'fail';
$return->error = $this->lang->install->errorCreateTable;
return $return;
}
return $return;
}
/* 设置数据库参数。*/
public function setDBParam()
{
$this->config->db->host = $this->post->dbHost;
$this->config->db->name = $this->post->dbName;
$this->config->db->user = $this->post->dbUser;
$this->config->db->password = $this->post->dbPassword;
$this->config->db->port = $this->post->dbPort;
$this->config->db->prefix = $this->post->dbPrefix;
}
/* 连接到数据库。*/
public function connectDB()
{
$dsn = "mysql:host={$this->config->db->host}; port={$this->config->db->port}";
try
{
$dbh = new PDO($dsn, $this->config->db->user, $this->config->db->password);
$dbh->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ);
$dbh->setAttribute(PDO::ATTR_ERRMODE, $this->config->db->errorMode);
$dbh->exec("SET NAMES {$this->config->db->encoding}");
return $dbh;
}
catch (PDOException $exception)
{
return $exception->getMessage();
}
}
/* 判断数据库是否存在。*/
public function dbExists()
{
$sql = "SHOW DATABASES like '{$this->config->db->name}'";
return $this->dbh->query($sql)->fetch();
}
/* 获得mysql的版本号。*/
public function getMysqlVersion()
{
$sql = "SELECT VERSION() AS version";
$result = $this->dbh->query($sql)->fetch();
return substr($result->version, 0, 3);
}
/* 创建数据库。*/
public function createDB($version)
{
$sql = "CREATE DATABASE `{$this->config->db->name}`";
if($version > 4.1) $sql .= " DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci";
return $this->dbh->query($sql);
}
/* 创建表。*/
public function createTable($version)
{
$dbFile = $this->app->getAppRoot() . 'db' . $this->app->getPathFix() . 'zentao.sql';
$tables = explode(';', file_get_contents($dbFile));
foreach($tables as $table)
{
$table = trim($table);
if(empty($table)) continue;
if(strpos($table, 'CREATE') !== false and $version <= 4.1)
{
$table = str_replace('DEFAULT CHARSET=utf8', '', $table);
}
elseif(strpos($table, 'DROP') !== false and $this->post->clearDB != false)
{
$table = str_replace('--', '', $table);
}
$table = str_replace('`zt_', $this->config->db->name . '.`zt_', $table);
$table = str_replace('zt_', $this->config->db->prefix, $table);
if(!$this->dbh->query($table)) return false;
}
return true;
}
/* 生成公司,设立管理员帐号。*/
public function grantPriv()
{
if($this->post->password == '') die(js::error($this->lang->install->errorEmptyPassword));
$admin->account = $this->post->account;
$admin->realname = $this->post->account;
$admin->password = md5($this->post->password);
$this->dao->replace(TABLE_USER)->data($admin)->autoCheck()->check('account', 'notempty')->exec();
if(!dao::isError())
{
$company->name = $this->post->company;
$company->pms = $this->post->pms;
$company->admins = ",$admin->account,";
$this->dao->replace(TABLE_COMPANY)->data($company)->autoCheck()->batchCheck('name, pms', 'notempty')->exec();
if(!dao::isError())
{
$companyID = $this->dbh->lastInsertID();
$this->dao->update(TABLE_USER)->set('company')->eq($companyID)->where('account')->eq($admin->account)->limit(1)->exec();
}
}
}
}

View File

@@ -1,6 +1,6 @@
<script language='Javascript'>var needPing = false;</script>
<div class='yui-d0'>
<iframe frameborder='0' name='hiddenwin' id='hiddenwin' class='<?php $config->debug ? print("debugwin") : print('hiddenwin')?>'></iframe>
<iframe frameborder='0' name='hiddenwin' id='hiddenwin' class='hiddenwin'></iframe>
</div>
<div id='footer' class='yui-d0 yui-t7'>
<div class='yui-g'>

View File

@@ -1,6 +1,7 @@
<?php
$config->webRoot = $this->install->getWebRoot();
$clientTheme = $this->app->getClientTheme();
$webRoot = $this->app->getWebRoot();
$webRoot = $this->config->webRoot;
$jsRoot = $webRoot . "js/";
$themeRoot = $webRoot . "theme/";
?>

View File

@@ -91,6 +91,10 @@
else
{
echo html::a($this->createLink('install', 'step1'), $lang->install->reload);
if($pdoResult == 'fail' or $pdoMySQLResult == 'fail')
{
echo '<p class="f-12px a-left">' . '<strong>' . $lang->install->phpINI . '</strong><br />' . nl2br($this->install->getIniInfo()) . '</p>';
}
}
?>
</td>

View File

@@ -60,7 +60,7 @@
</tr>
<tr>
<th><?php echo $lang->install->dbPrefix;?></th>
<td><?php echo html::input('dbPrefix', 'zt_');?></td>
<td><?php echo html::input('dbPrefix', 'zt_') . html::checkBox('clearDB', $lang->install->clearDB);?></td>
</tr>
<tr>
<td colspan='2' class='a-center'><?php echo html::submitButton();?></td>

View File

@@ -23,7 +23,9 @@
?>
<?php include './header.html.php';?>
<?php
$configContent = <<<EOT
if(!isset($error))
{
$configContent = <<<EOT
<?php
\$config->installed = true; //标志是否已经安装。
\$config->debug = true; //是否打开debug功能。
@@ -36,8 +38,16 @@ $configContent = <<<EOT
\$config->db->password = '$dbPassword'; //密码。
\$config->db->prefix = '$dbPrefix'; //表前缀。
EOT;
}
?>
<div class='yui-d0'>
<?php if(isset($error)):?>
<table class='table-6' align='center'>
<caption><?php echo $lang->install->error;?></caption>
<tr><td><?php echo $error;?></td></tr>
<tr><td><?php echo html::commonButton($lang->install->pre, "onclick='javascript:history.back(-1)'");?></td></tr>
</table>
<?php else:?>
<table class='table-6' align='center'>
<caption><?php echo $lang->install->saveConfig;?></caption>
<tr>
@@ -52,5 +62,6 @@ EOT;
</td>
</tr>
</table>
<?php endif;?>
</div>
<?php include './footer.html.php';?>

View File

@@ -0,0 +1,65 @@
<?php
/**
* The html template file of step4 method of install module of ZenTaoMS.
*
* ZenTaoMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ZenTaoMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with ZenTaoMS. If not, see <http://www.gnu.org/licenses/>.
*
* @copyright Copyright: 2009 Chunsheng Wang
* @author Chunsheng Wang <wwccss@263.net>
* @package ZenTaoMS
* @version $Id$
*/
?>
<?php include './header.html.php';?>
<div class='yui-d0'>
<?php if(isset($error)):?>
<table class='table-6' align='center'>
<caption><?php echo $lang->install->error;?></caption>
<tr><td><?php echo $error;?></td></tr>
<tr><td><?php echo html::commonButton($lang->install->pre, "onclick='javascript:history.back(-1)'");?></td></tr>
</table>
<?php elseif(isset($success)):?>
<table class='table-6' align='center'>
<caption><?php echo $lang->install->success;?></caption>
<tr><td><?php echo $lang->install->afterSuccess;?></td></tr>
<tr><td><?php echo html::commonButton($lang->install->pre, "onclick='javascript:history.back(-1)'");?></td></tr>
</table>
<?php else:?>
<form method='post' target='hiddenwin'>
<table class='table-6' align='center'>
<caption><?php echo $lang->install->getPriv;?></caption>
<tr>
<th class='rowhead'><?php echo $lang->install->company;?></th>
<td><?php echo html::input('company');?></td>
</tr>
<tr>
<th class='rowhead'><?php echo $lang->install->pms;?></th>
<td><?php echo html::input('pms', $pmsDomain) . "<span class='f-12px'>{$lang->install->pmsNote}</span>";?></td>
</tr>
<tr>
<th class='rowhead'><?php echo $lang->install->account;?></th>
<td><?php echo html::input('account');?></td>
</tr>
<tr>
<th class='rowhead'><?php echo $lang->install->password;?></th>
<td><?php echo html::input('password');?></td>
</tr>
<tr class='a-center'>
<td colspan='2'><?php echo html::submitButton();?></td>
</tr>
</table>
</form>
<?php endif;?>
</div>
<?php include './footer.html.php';?>