* code for task#952.

This commit is contained in:
zhujinyong
2012-12-02 09:14:31 +00:00
parent 732a020e3a
commit e3e41ca8ba
6 changed files with 133 additions and 1 deletions

View File

@@ -1,5 +1,6 @@
<?php
$config->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;

View File

@@ -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.
*

View File

@@ -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 %saccount must be three letters at least";
$lang->user->error->accountDupl = "ID %sthis account has been exist";
$lang->user->error->realname = "ID %splease input realname";
$lang->user->error->password = "ID %spassword must be six letters at least";
$lang->user->error->mail = "ID %splease input correct email address";

View File

@@ -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请填写正确的邮箱地址";

View File

@@ -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.
*

View File

@@ -0,0 +1,43 @@
<?php
/**
* The batch create view of user module of ZenTaoPMS.
*
* @copyright Copyright 2009-2012 青岛易软天创网络科技有限公司 (QingDao Nature Easy Soft Network Technology Co,LTD www.cnezsoft.com)
* @license LGPL (http://www.gnu.org/licenses/lgpl.html)
* @author Yangyang Shi <shiyangyang@cnezsoft.com>
* @package story
* @version $Id$
* @link http://www.zentao.net
*/
?>
<?php include '../../common/view/header.html.php';?>
<?php include '../../common/view/chosen.html.php';?>
<script> var batchCreateNum = '<?php echo $config->user->batchCreate;?>'; </script>
<form method='post' target='hiddenwin' id='dataform'>
<table class='table-1 fixed'>
<caption><?php echo $lang->user->batchCreate;?></caption>
<tr>
<th class='w-20px'><?php echo $lang->idAB;?></th>
<th class='w-150px'><?php echo $lang->user->dept;?></th>
<th class='w-150px'><?php echo $lang->user->account;?></th>
<th class='w-150px'><?php echo $lang->user->realname;?></th>
<th><?php echo $lang->user->email;?></th>
<th class='w-80px'><?php echo $lang->user->gender;?></th>
<th><?php echo $lang->user->password;?></th>
</tr>
<?php for($i = 0; $i < $config->user->batchCreate; $i++):?>
<?php $pri = 3;?>
<tr class='a-center'>
<td><?php echo $i+1;?></td>
<td><?php echo html::select("dept[$i]", $depts, $deptID, "class='select-2'");?>
<td><?php echo html::input("account[$i]", '', "class='text-2' autocomplete='off'");?></td>
<td><?php echo html::input("realname[$i]", '', "class='text-2'");?></td>
<td><?php echo html::input("email[$i]", '', "class='text-3'");?></td>
<td><?php echo html::radio("gender[$i]", (array)$lang->user->genderList, 'm');?></td>
<td><?php echo html::input("password[$i]", '', "class='text-3' autocomplete='off'");?></td>
</tr>
<?php endfor;?>
<tr><td colspan='7' class='a-center'><?php echo html::submitButton() . html::resetButton();?></td></tr>
</table>
</form>
<?php include '../../common/view/footer.html.php';?>