diff --git a/db/demo.sql b/db/demo.sql index 0857f2029d..c2fd11e3fd 100644 --- a/db/demo.sql +++ b/db/demo.sql @@ -305,7 +305,7 @@ INSERT INTO `zt_user` (`id`, `company`, `dept`, `account`, `password`, `realname INSERT INTO `zt_user` (`id`, `company`, `dept`, `account`, `password`, `realname`, `nickname`, `commiter`, `avatar`, `birthday`, `gender`, `email`, `msn`, `qq`, `yahoo`, `gtalk`, `wangwang`, `mobile`, `phone`, `address`, `zipcode`, `join`, `visits`, `ip`, `last`, `deleted`) VALUES(5, 1, 2, 'dev2', 'e10adc3949ba59abbe56e057f20f883e', '开发乙', '', '', '', '0000-00-00', 'm', '', '', '', '', '', '', '', '', '', '', '0000-00-00', 1, '192.168.0.8', 1338864116, '0'); INSERT INTO `zt_user` (`id`, `company`, `dept`, `account`, `password`, `realname`, `nickname`, `commiter`, `avatar`, `birthday`, `gender`, `email`, `msn`, `qq`, `yahoo`, `gtalk`, `wangwang`, `mobile`, `phone`, `address`, `zipcode`, `join`, `visits`, `ip`, `last`, `deleted`) VALUES(6, 1, 2, 'dev3', 'e10adc3949ba59abbe56e057f20f883e', '开发丙', '', '', '', '0000-00-00', 'm', '', '', '', '', '', '', '', '', '', '', '0000-00-00', 1, '192.168.0.8', 1338864187, '0'); INSERT INTO `zt_user` (`id`, `company`, `dept`, `account`, `password`, `realname`, `nickname`, `commiter`, `avatar`, `birthday`, `gender`, `email`, `msn`, `qq`, `yahoo`, `gtalk`, `wangwang`, `mobile`, `phone`, `address`, `zipcode`, `join`, `visits`, `ip`, `last`, `deleted`) VALUES(7, 1, 3, 'tester1', 'e10adc3949ba59abbe56e057f20f883e', '测试甲', '', '', '', '0000-00-00', 'm', '', '', '', '', '', '', '', '', '', '', '0000-00-00', 3, '192.168.0.8', 1338865739, '0'); -INSERT INTO `zt_user` (`id`, `company`, `dept`, `account`, `password`, `realname`, `nickname`, `commiter`, `avatar`, `birthday`, `gender`, `email`, `msn`, `qq`, `yahoo`, `gtalk`, `wangwang`, `mobile`, `phone`, `address`, `zipcode`, `join`, `visits`, `ip`, `last`, `deleted`) VALUES(8, 1, 0, 'tester2', 'e10adc3949ba59abbe56e057f20f883e', '测试乙', '', '', '', '0000-00-00', 'm', '', '', '', '', '', '', '', '', '', '', '0000-00-00', 2, '192.168.0.8', 1338865450, '0'); +INSERT INTO `zt_user` (`id`, `company`, `dept`, `account`, `password`, `realname`, `nickname`, `commiter`, `avatar`, `birthday`, `gender`, `email`, `msn`, `qq`, `yahoo`, `gtalk`, `wangwang`, `mobile`, `phone`, `address`, `zipcode`, `join`, `visits`, `ip`, `last`, `deleted`) VALUES(8, 1, 3, 'tester2', 'e10adc3949ba59abbe56e057f20f883e', '测试乙', '', '', '', '0000-00-00', 'm', '', '', '', '', '', '', '', '', '', '', '0000-00-00', 2, '192.168.0.8', 1338865450, '0'); INSERT INTO `zt_user` (`id`, `company`, `dept`, `account`, `password`, `realname`, `nickname`, `commiter`, `avatar`, `birthday`, `gender`, `email`, `msn`, `qq`, `yahoo`, `gtalk`, `wangwang`, `mobile`, `phone`, `address`, `zipcode`, `join`, `visits`, `ip`, `last`, `deleted`) VALUES(9, 1, 3, 'tester3', 'e10adc3949ba59abbe56e057f20f883e', '测试丙', '', '', '', '0000-00-00', 'm', '', '', '', '', '', '', '', '', '', '', '0000-00-00', 1, '192.168.0.8', 1338865125, '0'); INSERT INTO `zt_user` (`id`, `company`, `dept`, `account`, `password`, `realname`, `nickname`, `commiter`, `avatar`, `birthday`, `gender`, `email`, `msn`, `qq`, `yahoo`, `gtalk`, `wangwang`, `mobile`, `phone`, `address`, `zipcode`, `join`, `visits`, `ip`, `last`, `deleted`) VALUES(10, 1, 1, 'testManager', 'e10adc3949ba59abbe56e057f20f883e', '测试经理', '', '', '', '0000-00-00', 'm', '', '', '', '', '', '', '', '', '', '', '0000-00-00', 6, '192.168.0.8', 1338865842, '0'); diff --git a/module/admin/control.php b/module/admin/control.php index 23769a1b07..6d1cebe5b3 100644 --- a/module/admin/control.php +++ b/module/admin/control.php @@ -116,4 +116,44 @@ class admin extends control echo "Repairing TABLE: " . $result->Table . "\t" . $result->Msg_type . ":" . $result->Msg_text . "\n"; } } + + /** + * clear data. + * + * @access public + * @return void + */ + public function clearData() + { + if(!empty($_POST)) + { + $this->confirmClearData(); + } + + $this->display(); + } + + /** + * Confirm clear data. + * + * @param string $confirm no|yes + * @access public + * @return void + */ + public function confirmClearData($confirm = 'no') + { + if($confirm == 'no') + { + die(js::confirm($this->lang->admin->confirmClearData, inlink('confirmClearData', "confirm=yes"))); + } + else + { + $result = $this->admin->clearData(); + if($result) + { + die(js::alert($this->lang->admin->clearDataSucceed)); + } + die(js::alert($this->lang->admin->clearDataFailed)); + } + } } diff --git a/module/admin/lang/en.php b/module/admin/lang/en.php index 9bcc3f571a..3de5b1d49b 100644 --- a/module/admin/lang/en.php +++ b/module/admin/lang/en.php @@ -18,6 +18,18 @@ $lang->admin->welcome = 'Welcome to ZenTaoPMS.'; $lang->admin->browseCompany = 'Browse Company'; +$lang->admin->clearData = 'Clear Data'; +$lang->admin->confirmClearData = 'Are you sure to clear data?'; +$lang->admin->clearDataFailed = 'Failed to clear data!'; +$lang->admin->clearDataSucceed = 'Succeed to clear data!'; +$lang->admin->clearDataDesc = <<Clear data is dangerous. Be sure to backup your database and other data files and sure nobody is using pms when importing.\n +The impact of clearing data: +1、Clearing data will have no effect on table company,table group,and table groupPriv. +2、If you have choosed import demo data when installing,then clearing data will delete the item where key equals showDemoUsers on config table, and delete all demo users on user table. +3、For others tables:clear all data. +EOT; + $lang->admin->info->caption = 'ZentaoPMS information'; $lang->admin->info->version = 'The current version of the system is %s,'; $lang->admin->info->links = 'You can visit the following link:'; diff --git a/module/admin/lang/zh-cn.php b/module/admin/lang/zh-cn.php index 7255d7bd04..407254fba2 100644 --- a/module/admin/lang/zh-cn.php +++ b/module/admin/lang/zh-cn.php @@ -18,6 +18,18 @@ $lang->admin->welcome = '欢迎使用禅道管理软件后台管理系统'; $lang->admin->browseCompany = '浏览公司'; +$lang->admin->clearData = '清除数据'; +$lang->admin->confirmClearData = '您确认要清楚数据吗?'; +$lang->admin->clearDataFailed = '清除数据失败!'; +$lang->admin->clearDataSucceed = '清除数据成功!'; +$lang->admin->clearDataDesc = <<清除数据存在一定的风险,清楚数据之前,我们强烈建议您备份数据库及相应的数据文件,并保证清楚数据的时候,没有其他人进行操作。\n +清除数据对数据库的影响如下: +1、清楚数据不会对company, group, groupPriv表进行操作。 +2、如果安装的时候有导入demo数据,则会删除config表key=showDemoUsers的记录,并删除user表中的所有demo用户。 +3、对于其他表则进行全部清除操作。 +EOT; + $lang->admin->info->caption = '禅道系统信息'; $lang->admin->info->version = '当前系统的版本是%s,'; $lang->admin->info->links = '您可以访问以下链接:'; diff --git a/module/admin/model.php b/module/admin/model.php index 9ee7b02833..8b4e2c1e55 100644 --- a/module/admin/model.php +++ b/module/admin/model.php @@ -138,4 +138,46 @@ class adminModel extends model $register->email = $this->app->user->email; return $register; } + + /** + * Clear data. + * + * @access public + * @return void + */ + public function clearData() + { + $result = $this->dbh->query('SHOW TABLES')->fetchAll(); + $showDemoUsers = $this->dao->select('value')->from(TABLE_CONFIG)->where('`key`')->eq('showDemoUsers')->fetch(); + foreach($result as $item) + { + $table = current((array)$item); + if(strpos($table, 'company') !== false) continue; + if(strpos($table, 'group') !== false) continue; + if(strpos($table, 'user') !== false) + { + if($showDemoUsers) + { + $this->dao->delete()->from($table) + ->where('account')->in(array('productManager', 'projectManager', 'testManager', 'dev1', 'dev2', 'dev3', 'tester1', 'tester2', 'tester3')) + ->exec(); + if(dao::isError()) return false; + } + continue; + } + if(strpos($table, 'config') !== false) + { + if($showDemoUsers) + { + $this->dao->delete()->from($table) + ->where('`key`')->eq('showDemoUsers') + ->exec(); + if(dao::isError()) return false; + } + continue; + } + if(!$this->dbh->query("TRUNCATE TABLE `$table`")) return false; + } + return true; + } } diff --git a/module/admin/view/cleardata.html.php b/module/admin/view/cleardata.html.php new file mode 100755 index 0000000000..f8e409cc1f --- /dev/null +++ b/module/admin/view/cleardata.html.php @@ -0,0 +1,21 @@ + + * @package admin + * @version $Id: view.html.php 2568 2012-02-09 06:56:35Z shiyangyangwork@yahoo.cn $ + * @link http://www.zentao.net + */ +?> + +
+ + + + +
admin->clearData;?>
admin->clearDataDesc);?>
admin->clearData) . html::hidden('confirm', 'no');?>
+
+ diff --git a/module/common/lang/en.php b/module/common/lang/en.php index fb4e9f9699..ac77e50af1 100644 --- a/module/common/lang/en.php +++ b/module/common/lang/en.php @@ -228,6 +228,7 @@ $lang->admin->menu->index = array('link' => 'Index|admin|index'); $lang->admin->menu->extension = array('link' => 'Extension|extension|browse', 'subModule' => 'extension'); $lang->admin->menu->editor = array('link' => 'Extension editor|editor|index', 'subModule' => 'editor'); $lang->admin->menu->mail = array('link' => 'ConfigEmail|mail|set', 'subModule' => 'mail'); +$lang->admin->menu->clearData = array('link' => 'ClearData|admin|cleardata'); $lang->admin->menu->convert = array('link' => 'Import|convert|index', 'subModule' => 'convert'); $lang->admin->menu->trashes = array('link' => 'Trash|action|trash', 'subModule' => 'action'); $lang->convert->menu = $lang->admin->menu; diff --git a/module/common/lang/zh-cn.php b/module/common/lang/zh-cn.php index 4b8cbb502c..5b51c06a07 100644 --- a/module/common/lang/zh-cn.php +++ b/module/common/lang/zh-cn.php @@ -228,6 +228,7 @@ $lang->admin->menu->index = array('link' => '首页|admin|index'); $lang->admin->menu->extension = array('link' => '插件管理|extension|browse', 'subModule' => 'extension'); $lang->admin->menu->editor = array('link' => '扩展编辑器|editor|index', 'subModule' => 'editor'); $lang->admin->menu->mail = array('link' => 'Email配置|mail|set', 'subModule' => 'mail'); +$lang->admin->menu->clearData = array('link' => '清除数据|admin|cleardata'); $lang->admin->menu->convert = array('link' => '从其他系统导入|convert|index', 'subModule' => 'convert'); $lang->admin->menu->trashes = array('link' => '回收站|action|trash', 'subModule' => 'action'); $lang->convert->menu = $lang->admin->menu; diff --git a/module/install/model.php b/module/install/model.php index 86db0fefd9..8e1bbebe72 100644 --- a/module/install/model.php +++ b/module/install/model.php @@ -369,6 +369,7 @@ class installModel extends model $table = str_replace('zt_', $this->config->db->prefix, $table); if(!$this->dbh->query($table)) return false; } + $config->company = '1'; $config->owner = 'system'; $config->section = 'global';