From e3e41ca8ba0a6b1829536d69b6ea47749851b9bd Mon Sep 17 00:00:00 2001 From: zhujinyong Date: Sun, 2 Dec 2012 09:14:31 +0000 Subject: [PATCH] * code for task#952. --- module/user/config.php | 3 +- module/user/control.php | 30 ++++++++++++++++++ module/user/lang/en.php | 7 +++++ module/user/lang/zh-cn.php | 7 +++++ module/user/model.php | 44 +++++++++++++++++++++++++++ module/user/view/batchcreate.html.php | 43 ++++++++++++++++++++++++++ 6 files changed, 133 insertions(+), 1 deletion(-) create mode 100644 module/user/view/batchcreate.html.php diff --git a/module/user/config.php b/module/user/config.php index cd74896f1d..e688b2707b 100644 --- a/module/user/config.php +++ b/module/user/config.php @@ -1,5 +1,6 @@ user->create->requiredFields = 'account,realname,password,password1,password2'; $config->user->edit->requiredFields = 'account,realname'; -$config->user->failTimes = 6; +$config->user->failTimes = 6; $config->user->lockMinutes = 10; +$config->user->batchCreate = 10; diff --git a/module/user/control.php b/module/user/control.php index a02cdaaf55..7b5f59ed1a 100644 --- a/module/user/control.php +++ b/module/user/control.php @@ -274,6 +274,36 @@ class user extends control $this->display(); } + + /** + * Batch create users. + * + * @param int $deptID + * @access public + * @return void + */ + public function batchCreate($deptID = 0) + { + $this->lang->set('menugroup.user', 'company'); + $this->lang->user->menu = $this->lang->company->menu; + $this->lang->user->menuOrder = $this->lang->company->menuOrder; + + if(!empty($_POST)) + { + $this->user->batchCreate(); + die(js::locate($this->createLink('company', 'browse'), 'parent')); + } + + $header['title'] = $this->lang->company->common . $this->lang->colon . $this->lang->user->batchCreate; + $position[] = $this->lang->user->batchCreate; + $this->view->header = $header; + $this->view->position = $position; + $this->view->depts = $this->dept->getOptionMenu(); + $this->view->deptID = $deptID; + + $this->display(); + } + /** * Edit a user. * diff --git a/module/user/lang/en.php b/module/user/lang/en.php index eb6d65872a..16b85fc75c 100644 --- a/module/user/lang/en.php +++ b/module/user/lang/en.php @@ -13,6 +13,7 @@ $lang->user->common = 'User'; $lang->user->index = "Index"; $lang->user->view = "Info"; $lang->user->create = "Add"; +$lang->user->batchCreate = "Batch add user"; $lang->user->read = "Info"; $lang->user->edit = "Edit"; $lang->user->unlock = "Unlock"; @@ -89,3 +90,9 @@ $lang->user->status = 'Status'; $lang->user->placeholder->account = 'Letters/underline/numbers, three above'; $lang->user->placeholder->password1 = 'Six above'; $lang->user->placeholder->join = 'The date the employee join the company'; + +$lang->user->error->account = "ID %s,account must be three letters at least"; +$lang->user->error->accountDupl = "ID %s,this account has been exist"; +$lang->user->error->realname = "ID %s,please input realname"; +$lang->user->error->password = "ID %s,password must be six letters at least"; +$lang->user->error->mail = "ID %s,please input correct email address"; diff --git a/module/user/lang/zh-cn.php b/module/user/lang/zh-cn.php index a4e3f42263..e539a3a74f 100644 --- a/module/user/lang/zh-cn.php +++ b/module/user/lang/zh-cn.php @@ -13,6 +13,7 @@ $lang->user->common = '用户'; $lang->user->index = "用户视图首页"; $lang->user->view = "用户详情"; $lang->user->create = "添加用户"; +$lang->user->batchCreate = "批量添加用户"; $lang->user->read = "查看用户"; $lang->user->edit = "编辑用户"; $lang->user->unlock = "解锁用户"; @@ -89,3 +90,9 @@ $lang->user->status = '状态'; $lang->user->placeholder->account = '英文、数字和下划线的组合,三位以上'; $lang->user->placeholder->password1 = '六位以上'; $lang->user->placeholder->join = '入职日期'; + +$lang->user->error->account = "ID %s,用户名必须三位以上"; +$lang->user->error->accountDupl = "ID %s,该用户名已经存在"; +$lang->user->error->realname = "ID %s,必须填写真实姓名"; +$lang->user->error->password = "ID %s,密码必须六位以上"; +$lang->user->error->mail = "ID %s,请填写正确的邮箱地址"; diff --git a/module/user/model.php b/module/user/model.php index b4aee65959..febf55397d 100644 --- a/module/user/model.php +++ b/module/user/model.php @@ -176,6 +176,50 @@ class userModel extends model ->exec(); } + /** + * Batch create users. + * + * @param int $users + * @access public + * @return void + */ + public function batchCreate() + { + $users = fixer::input('post')->get(); + $data = array(); + for($i = 0; $i < $this->config->user->batchCreate; $i++) + { + if($users->account[$i] != '') + { + $account = $this->dao->select('account')->from(TABLE_USER)->where('account')->eq($users->account[$i])->fetch(); + if($account) die(js::error(sprintf($this->lang->user->error->accountDupl, $i+1))); + if(!validater::checkReg($users->account[$i], '|(.){3,}|')) die(js::error(sprintf($this->lang->user->error->account, $i+1))); + if($users->realname[$i] == '') die(js::error(sprintf($this->lang->user->error->realname, $i+1))); + if(!validater::checkEmail($users->email[$i])) die(js::error(sprintf($this->lang->user->error->mail, $i+1))); + if(!validater::checkReg($users->password[$i], '|(.){6,}|')) die(js::error(sprintf($this->lang->user->error->password, $i+1))); + + $data[$i]->dept = $users->dept[$i]; + $data[$i]->account = $users->account[$i]; + $data[$i]->realname = $users->realname[$i]; + $data[$i]->email = $users->email[$i]; + $data[$i]->gender = $users->gender[$i]; + $data[$i]->password = md5($users->password[$i]); + } + } + foreach($data as $user) + { + $this->dao->insert(TABLE_USER)->data($user) + ->autoCheck() + ->batchCheck($this->config->user->create->requiredFields, 'notempty') + ->exec(); + if(dao::isError()) + { + echo js::error(dao::getError()); + die(js::reload('parent')); + } + } + } + /** * Update a user. * diff --git a/module/user/view/batchcreate.html.php b/module/user/view/batchcreate.html.php new file mode 100644 index 0000000000..9a17b56d36 --- /dev/null +++ b/module/user/view/batchcreate.html.php @@ -0,0 +1,43 @@ + + * @package story + * @version $Id$ + * @link http://www.zentao.net + */ +?> + + + +
+ + + + + + + + + + + + user->batchCreate; $i++):?> + + + + + + + + + + + +
user->batchCreate;?>
idAB;?>user->dept;?>user->account;?>user->realname;?>user->email;?>user->gender;?>user->password;?>
+ user->genderList, 'm');?>
+
+