* add for batch edit user.

This commit is contained in:
wangyidong
2012-12-19 07:50:54 +00:00
parent 73a332d847
commit c0bddae881
7 changed files with 152 additions and 17 deletions

View File

@@ -52,9 +52,10 @@ include '../../common/view/tablesorter.html.php';
</tr>
</thead>
<tbody>
<form action='<?php echo $this->createLink('user', 'batchEdit', "deptID=$deptID")?>' method='post'>
<?php foreach($users as $user):?>
<tr class='a-center'>
<td><?php echo html::checkbox('userIDList[]', $user->id) . $user->id;?></td>
<td><?php echo "<input type='checkbox' name='userIDList[]' value='$user->id'> "; printf('%03d', $user->id);?></td>
<td><?php if(!common::printLink('user', 'view', "account=$user->account", $user->realname)) echo $user->realname;?></td>
<td><?php echo $user->account;?></td>
<td><?php echo $lang->user->roleList[$user->role];?></td>
@@ -75,16 +76,16 @@ include '../../common/view/tablesorter.html.php';
<?php endforeach;?>
</tbody>
<tfoot>
<tr>
<td colspan='11'>
<?php
echo html::selectAll();
echo html::selectReverse();
$pager->show();
?>
</td>
</tr>
</tfoot>
<tr>
<td colspan='11'>
<?php
echo html::selectAll() . html::selectReverse();
echo html::submitButton($lang->user->batchEdit);
$pager->show();
?>
</td>
</tr>
</tfoot>
</table>
</td>
</tr>

View File

@@ -333,6 +333,36 @@ class user extends control
$this->display();
}
/**
* Batch edit user.
*
* @param int $deptID
* @access public
* @return void
*/
public function batchEdit($deptID = 0)
{
if(isset($_POST['userIDList']))
{
$this->view->users = $this->dao->select('*')->from(TABLE_USER)->where('id')->in($this->post->userIDList)->orderBy('id')->fetchAll('id');
}
elseif($_POST)
{
$this->user->batchEdit();
die(js::locate($this->createLink('company', 'browse', "deptID=$deptID"), 'parent'));
}
$this->lang->set('menugroup.user', 'company');
$this->lang->user->menu = $this->lang->company->menu;
$this->lang->user->menuOrder = $this->lang->company->menuOrder;
$header['title'] = $this->lang->company->common . $this->lang->colon . $this->lang->user->batchEdit;
$position[] = $this->lang->user->edit;
$this->view->header = $header;
$this->view->position = $position;
$this->view->depts = $this->dept->getOptionMenu();
$this->display();
}
/**
* Delete a user.
*

View File

@@ -38,6 +38,7 @@ $lang->user->visits = 'Visits';
$lang->user->ip = 'Last IP';
$lang->user->last = 'Last login';
$lang->user->status = 'Status';
$lang->user->ditto = 'Ditto';
$lang->user->index = "Index";
$lang->user->view = "Info";

View File

@@ -38,6 +38,7 @@ $lang->user->visits = '访问次数';
$lang->user->ip = '最后IP';
$lang->user->last = '最后登录';
$lang->user->status = '状态';
$lang->user->ditto = '同上';
$lang->user->index = "用户视图首页";
$lang->user->view = "用户详情";
@@ -45,6 +46,7 @@ $lang->user->create = "添加用户";
$lang->user->batchCreate = "批量添加用户";
$lang->user->read = "查看用户";
$lang->user->edit = "编辑用户";
$lang->user->batchEdit = "批量编辑";
$lang->user->unlock = "解锁用户";
$lang->user->update = "编辑用户";
$lang->user->delete = "删除用户";

View File

@@ -232,15 +232,21 @@ class userModel extends model
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($users->email[$i] and !validater::checkEmail($users->email[$i])) die(js::error(sprintf($this->lang->user->error->mail, $i+1)));
$users->password[$i] = (isset($prev['password']) and $users->ditto[$i] == 'on') ? $prev['password'] : $users->password[$i];
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]->dept = (isset($prev['dept']) and $users->dept[$i] == 'ditto') ? $prev['dept'] : $users->dept[$i];
$data[$i]->account = $users->account[$i];
$data[$i]->realname = $users->realname[$i];
$data[$i]->role = (isset($prev['role']) and $users->role[$i] == 'ditto') ? $prev['role'] : $users->role[$i];
$data[$i]->email = $users->email[$i];
$data[$i]->gender = $users->gender[$i];
$data[$i]->password = md5($users->password[$i]);
$prev['dept'] = $data[$i]->dept;
$prev['role'] = $data[$i]->role;
$prev['password'] = $users->password[$i];
}
}
foreach($data as $user)
@@ -300,6 +306,49 @@ class userModel extends model
}
}
/**
* Batch edit user.
*
* @access public
* @return void
*/
public function batchEdit()
{
$oldUsers = $this->dao->select('id, account')->from(TABLE_USER)->where('id')->in(array_keys($this->post->account))->fetchPairs('id', 'account');
$accountGroup = $this->dao->select('id, account')->from(TABLE_USER)->where('account')->in($this->post->account)->fetchGroup('account', 'id');
foreach($this->post->account as $id => $account)
{
$users[$id]['account'] = $account;
$users[$id]['dept'] = $this->post->dept[$id];
$users[$id]['realname'] = $this->post->realname[$id];
$users[$id]['role'] = $this->post->role[$id];
$users[$id]['commiter'] = $this->post->commiter[$id];
$users[$id]['email'] = $this->post->email[$id];
$users[$id]['join'] = $this->post->join[$id];
if(isset($accountGroup[$account]) and count($accountGroup[$account]) >1) die(js::error(sprintf($this->lang->user->error->accountDupl, $id)));
if(!validater::checkReg($users[$id]['account'], '|(.){3,}|')) die(js::error(sprintf($this->lang->user->error->account, $id)));
if($users[$id]['realname'] == '') die(js::error(sprintf($this->lang->user->error->realname, $id)));
if($users[$id]['email'] and !validater::checkEmail($users[$id]['email'])) die(js::error(sprintf($this->lang->user->error->mail, $id)));
}
foreach($users as $id => $user)
{
$this->dao->update(TABLE_USER)->data($user)->where('id')->eq((int)$id)->exec();
if($user['account'] != $oldUsers[$id])
{
$oldAccount = $oldUsers[$id];
$this->dao->update(TABLE_USERGROUP)->set('account')->eq($user['account'])->where('account')->eq($oldAccount)->exec();
if(strpos($this->app->company->admins, ',' . $oldAccount . ',') !== false)
{
$admins = str_replace(',' . $oldAccount . ',', ',' . $user['account'] . ',', $this->app->company->admins);
$this->dao->update(TABLE_COMPANY)->set('admins')->eq($admins)->where('id')->eq($this->app->company->id)->exec(false);
}
if(!dao::isError() and $this->app->user->account == $oldAccount) $this->app->user->account = $users['account'];
}
}
}
/**
* Update password
*

View File

@@ -21,23 +21,31 @@
<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 class='w-150px'><?php echo $lang->user->role;?></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 $depts = $depts + array('ditto' => $lang->user->ditto)?>
<?php $lang->user->roleList = $lang->user->roleList + array('ditto' => $lang->user->ditto)?>
<?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::select("dept[$i]", $depts, $i > 0 ? 'ditto' : $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::select("role[$i]", $lang->user->roleList, $i > 0 ? 'ditto' : '', "class='select-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>
<td>
<?php
echo html::input("password[$i]", '', "class='text-3' autocomplete='off'");
echo "<input type='checkbox' name='ditto[$i]' " . ($i> 0 ? "checked" : '') . " />"
?>
</td>
</tr>
<?php endfor;?>
<tr><td colspan='7' class='a-center'><?php echo html::submitButton() . html::resetButton();?></td></tr>
<tr><td colspan='8' class='a-center'><?php echo html::submitButton() . html::resetButton();?></td></tr>
</table>
</form>
<?php include '../../common/view/footer.html.php';?>

View File

@@ -0,0 +1,44 @@
<?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';?>
<?php include '../../common/view/datepicker.html.php';?>
<form method='post' target='hiddenwin' id='dataform'>
<table class='table-1 fixed'>
<caption><?php echo $lang->user->batchEdit;?></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 class='w-150px'><?php echo $lang->user->role;?></th>
<th><?php echo $lang->user->commiter;?></th>
<th><?php echo $lang->user->email;?></th>
<th class='w-150px'><?php echo $lang->user->join;?></th>
</tr>
<?php foreach($users as $user):?>
<tr class='a-center'>
<td><?php echo $user->id;?></td>
<td><?php echo html::select("dept[$user->id]", $depts, $user->dept, "class='select-2'");?>
<td><?php echo html::input("account[$user->id]", $user->account, "class='text-2' autocomplete='off'");?></td>
<td><?php echo html::input("realname[$user->id]", $user->realname, "class='text-2'");?></td>
<td><?php echo html::select("role[$user->id]", $lang->user->roleList, $user->role, "class='select-2'");?>
<td><?php echo html::input("commiter[$user->id]", $user->commiter, "class='text-3'");?></td>
<td><?php echo html::input("email[$user->id]", $user->email, "class='text-3'");?></td>
<td><?php echo html::input("join[$user->id]", $user->join, "class='text-2 date'");?></td>
</tr>
<?php endforeach;?>
<tr><td colspan='7' class='a-center'><?php echo html::submitButton() . html::resetButton();?></td></tr>
</table>
</form>
<?php include '../../common/view/footer.html.php';?>