-
- // See if user exist
- $ret = $this->lookup($alias);
- if(empty($ret))
- return $this->set_error(sprintf(_("User '%s' does not exist"),
- $alias));
-
- // Create query
- $query = sprintf("UPDATE %s SET nickname='%s', firstname='%s', ".
- "lastname='%s', email='%s', label='%s' ".
- "WHERE owner='%s' AND nickname='%s'",
- $this->table,
- $this->dbh->quoteString($userdata['nickname']),
- $this->dbh->quoteString($userdata['firstname']),
- $this->dbh->quoteString($userdata['lastname']),
- $this->dbh->quoteString($userdata['email']),
- $this->dbh->quoteString($userdata['label']),
- $this->owner,
- $this->dbh->quoteString($alias) );
-
- // Do the insert
- $r = $this->dbh->simpleQuery($query);
- if($r == DB_OK) return true;
-
- // Fail
- return $this->set_error(sprintf(_("Database error: %s"),
- DB::errorMessage($r)));
- }
- } // End of class abook_database
+ }
+
+ /* See if user exist */
+ $ret = $this->lookup($alias);
+ if (empty($ret)) {
+ return $this->set_error(sprintf(_("User \"%s\" does not exist"),$alias));
+ }
+
+ /* make sure that new nickname is not used */
+ if (strtolower($alias) != strtolower($userdata['nickname'])) {
+ /* same check as in add() */
+ $ret = $this->lookup($userdata['nickname']);
+ if (!empty($ret)) {
+ $error = sprintf(_("User '%s' already exist."), $ret['nickname']);
+ return $this->set_error($error);
+ }
+ }
+
+ /* Create query */
+ $query = sprintf("UPDATE %s SET nickname='%s', firstname='%s', ".
+ "lastname='%s', email='%s', label='%s' ".
+ "WHERE owner='%s' AND nickname='%s'",
+ $this->table,
+ $this->dbh->quoteString($userdata['nickname']),
+ $this->dbh->quoteString($userdata['firstname']),
+ $this->dbh->quoteString((!empty($userdata['lastname'])?$userdata['lastname']:'')),
+ $this->dbh->quoteString($userdata['email']),
+ $this->dbh->quoteString((!empty($userdata['label'])?$userdata['label']:'')),
+ $this->owner,
+ $this->dbh->quoteString($alias) );
+
+ /* Do the insert */
+ $r = $this->dbh->simpleQuery($query);
+
+ /* Check for errors */
+ if (DB::isError($r)) {
+ return $this->set_error(sprintf(_("Database error: %s"),
+ DB::errorMessage($r)));
+ }
+ return true;
+ }
+} /* End of class abook_database */