From be83f9f729b3d8bc67d375b6561024f18de3c7d2 Mon Sep 17 00:00:00 2001 From: wangchunsheng Date: Fri, 6 Nov 2009 02:19:03 +0000 Subject: [PATCH] * fix the bug of when add user and list user. --- module/common/lang/zh-cn.php | 1 + module/dept/model.php | 5 +++-- module/user/control.php | 4 +++- module/user/model.php | 38 ++++++++++++++++++++++-------------- 4 files changed, 30 insertions(+), 18 deletions(-) diff --git a/module/common/lang/zh-cn.php b/module/common/lang/zh-cn.php index 3979ddc62b..aa2e472b9e 100644 --- a/module/common/lang/zh-cn.php +++ b/module/common/lang/zh-cn.php @@ -103,6 +103,7 @@ $lang->error->int = array("『%s』应当是数字。", "『%s』应 $lang->error->float = "『%s』应当是数字,可以是小数。"; $lang->error->email = "『%s』应当为合法的EMAIL。"; $lang->error->date = "『%s』应当为合法的日期。"; +$lang->error->account = "『%s』应当为合法的用户名。"; /* 分页信息。*/ $lang->pager->noRecord = "暂时没有记录"; diff --git a/module/dept/model.php b/module/dept/model.php index 4e94eafb5a..0cc969e9cd 100644 --- a/module/dept/model.php +++ b/module/dept/model.php @@ -233,8 +233,9 @@ class deptModel extends model /* 获得某一个部门的成员列表。*/ public function getUsers($deptID) { - $sql = "SELECT * FROM " . TABLE_USER . " WHERE dept " . helper::dbIN($deptID) . " ORDER BY id"; - return $this->dbh->query($sql)->fetchAll(); + $sql = $this->dao->select('*')->from(TABLE_USER); + if($deptID) $sql->where('dept')->in($deptID); + return $sql->orderBy('id')->fetchAll(); } /* 删除一个部门。Todo: 需要修改下级目录的权限,还有对应的需求列表。*/ diff --git a/module/user/control.php b/module/user/control.php index 39d4de8d4b..cd9435a32e 100644 --- a/module/user/control.php +++ b/module/user/control.php @@ -152,6 +152,7 @@ class user extends control if(!empty($_POST)) { $this->user->create($companyID); + if(dao::isError()) die(js::error(dao::getError())); if($from == 'admin') { die(js::locate($this->createLink('admin', 'browseuser', "companyid={$this->app->company->id}"), 'parent')); @@ -179,7 +180,8 @@ class user extends control if(!empty($_POST)) { $this->user->update($userID); - if($from == 'admin') + if(dao::isError()) die(js::error(dao::getError())); + if($from == 'admin') { die(js::locate($this->createLink('admin', 'browseuser', "companyid={$this->app->company->id}"), 'parent')); } diff --git a/module/user/model.php b/module/user/model.php index dc818eb6dc..dd9cf13f05 100644 --- a/module/user/model.php +++ b/module/user/model.php @@ -52,26 +52,34 @@ class userModel extends model /* ÐÂÔöһ¸öÓû§¡£*/ function create($companyID) { - extract($_POST); - $sql = "INSERT INTO " . TABLE_USER . "(account, realname, email, gendar, `join`, password, company, dept) - VALUES('$account', '$realname', '$email', '$gendar', '$join', MD5('$password'), '$companyID', '$dept')"; - return $this->dbh->query($sql); + $user = fixer::input('post') + ->add('company', (int)$companyID) + ->setDefault('join', '0000-00-00') + ->get(); + $this->dao->insert(TABLE_USER)->data($user) + ->autoCheck() + ->batchCheck('account, realname, password', 'notempty') + ->check('account', 'unique') + ->check('account', 'account') + ->exec(); } /* ¸üÐÂһ¸öÓû§¡£*/ function update($userID) { - extract($_POST); - if(empty($password)) - { - $password = 'password'; - } - else - { - $password = "MD5('$password')"; - } - $sql = "UPDATE " . TABLE_USER . " SET account = '$account', realname = '$realname', email = '$email', gendar = '$gendar', `join` = '$join', password = $password, dept = '$dept' WHERE id = '$userID' LIMIT 1"; - return $this->dbh->exec($sql); + $userID = (int)$userID; + $user = fixer::input('post') + ->setDefault('join', '0000-00-00') + ->setIF($this->post->password != '', 'password', md5($this->post->password)) + ->removeIF($this->post->password == '', 'password') + ->get(); + $this->dao->update(TABLE_USER)->data($user) + ->autoCheck() + ->batchCheck('account, realname, password', 'notempty') + ->check('account', 'unique', "id != '$userID'") + ->check('account', 'account') + ->where('id')->eq((int)$userID) + ->exec(); } /* ɾ³ýһ¸öÓû§¡£*/