19 require_once(BASE.
"wcmf/lib/security/class.UserManager.php");
20 require_once(BASE.
"wcmf/lib/security/class.User.php");
21 require_once(BASE.
"wcmf/lib/security/class.Role.php");
22 require_once(BASE.
"wcmf/lib/util/class.InifileParser.php");
23 require_once(BASE.
"wcmf/3rdparty/adodb/adodb.inc.php");
47 $this->_conn = &ADONewConnection($params[
'dbType']);
48 $connected = $this->_conn->PConnect($params[
'dbHostName'],$params[
'dbUserName'],$params[
'dbPassword'],$params[
'dbName']);
52 $this->_conn->replaceQuote =
"\'";
53 $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
54 define(ADODB_OUTP,
"gError");
57 $this->_dbPrefix = $params[
'dbPrefix'];
61 if (($logSQL = $parser->getValue(
'logSQL',
'cms')) ===
false)
63 $this->_conn->LogSQL($logSQL);
99 $userRepository = array();
100 $userRepository[
'users'] = array();
101 $userRepository[
'roles'] = array();
108 $sqlStr =
"SELECT ".$this->_dbPrefix.
"user.id, ".$this->_dbPrefix.
"user.name, ".$this->_dbPrefix.
"user.login, ".$this->_dbPrefix.
"user.password, ".$this->_dbPrefix.
"user.firstname, ".$this->_dbPrefix.
"user.config, ".$this->_dbPrefix.
"role.name AS rolename
109 FROM ".$this->_dbPrefix.
"user LEFT JOIN ".$this->_dbPrefix.
"nm_user_role ON ".$this->_dbPrefix.
"user.id=".$this->_dbPrefix.
"nm_user_role.fk_user_id LEFT JOIN ".$this->_dbPrefix.
"role
110 ON ".$this->_dbPrefix.
"nm_user_role.fk_role_id=".$this->_dbPrefix.
"role.id ORDER BY user.id;";
111 $rs = &$this->_conn->Execute($sqlStr);
113 while ($rs && $row = $rs->FetchRow())
115 if ($row[
'id'] != $curUserID)
117 $curUserID = $row[
'id'];
118 $user =
new User($curUserID, $row[
'login'], $row[
'password'], $row[
'name'], $row[
'firstname'], $row[
'config'], array());
119 $userRepository[
'users'][$curUserID] = $user;
121 if ($row[
'rolename'] !=
'')
122 $userRepository[
'users'][$curUserID]->addRole($row[
'rolename']);
125 $sqlStr =
"SELECT ".$this->_dbPrefix.
"role.id, ".$this->_dbPrefix.
"role.name FROM ".$this->_dbPrefix.
"role;";
126 $rs = &$this->_conn->Execute($sqlStr);
127 while ($rs && $row = $rs->FetchRow())
128 $userRepository[
'roles'][$row[
'id']] =
new Role($row[
'id'], $row[
'name']);
130 return $userRepository;
138 $newID = $this->_conn->GenID();
139 $sqlStr =
"INSERT INTO ".$this->_dbPrefix.
"user (id, name, firstname, login, password) VALUES (".$this->_conn->qstr($newID).
", ".
140 $this->_conn->qstr($name).
", ".$this->_conn->qstr($firstname).
", ".$this->_conn->qstr($login).
", ".$this->_conn->qstr($password).
");";
141 if ($this->_conn->Execute($sqlStr) ===
false)
143 Log::error($this->_conn->ErrorMsg().
". Your query was: ".$sqlStr, __CLASS__);
144 WCMFException::throwEx(
"Error creating user '".$login.
"'. See log file for details.", __FILE__, __LINE__);
156 $sqlStr =
"DELETE FROM ".$this->_dbPrefix.
"nm_user_role WHERE fk_user_id=".$this->_conn->qstr($user->getID()).
";";
157 if ($this->_conn->Execute($sqlStr) ===
false)
159 Log::error($this->_conn->ErrorMsg().
". Your query was: ".$sqlStr, __CLASS__);
160 WCMFException::throwEx(
"Error removing user '".$user->getLogin().
"' from his roles. See log file for details.", __FILE__, __LINE__);
163 $sqlStr =
"DELETE FROM ".$this->_dbPrefix.
"user WHERE id=".$this->_conn->qstr($user->getID()).
";";
164 if ($this->_conn->Execute($sqlStr) ===
false)
166 Log::error($this->_conn->ErrorMsg().
". Your query was: ".$sqlStr, __CLASS__);
167 WCMFException::throwEx(
"Error removing user '".$user->getLogin().
"'. See log file for details.", __FILE__, __LINE__);
176 $sqlStr =
"UPDATE ".$this->_dbPrefix.
"user SET ".$property.
"=".$this->_conn->qstr($value).
" WHERE id=".$this->_conn->qstr($user->getID()).
";";
177 if ($this->_conn->Execute($sqlStr) ===
false)
179 Log::error($this->_conn->ErrorMsg().
". Your query was: ".$sqlStr, __CLASS__);
180 WCMFException::throwEx(
"Error changing property '".$property.
"' for user '".$user->getLogin().
"'. See log file for details.", __FILE__, __LINE__);
189 $newID = $this->_conn->GenID();
190 $sqlStr =
"INSERT INTO ".$this->_dbPrefix.
"role (id, name) VALUES (".$this->_conn->qstr($newID).
", ".$this->_conn->qstr($name).
");";
191 if ($this->_conn->Execute($sqlStr) ===
false)
193 Log::error($this->_conn->ErrorMsg().
". Your query was: ".$sqlStr, __CLASS__);
206 $sqlStr =
"DELETE FROM ".$this->_dbPrefix.
"nm_user_role WHERE fk_role_id=".$this->_conn->qstr($role->getID()).
";";
207 if ($this->_conn->Execute($sqlStr) ===
false)
209 Log::error($this->_conn->ErrorMsg().
". Your query was: ".$sqlStr, __CLASS__);
210 WCMFException::throwEx(
"Error removing role '".$role->getName().
"' from her users. See log file for details.", __FILE__, __LINE__);
213 $sqlStr =
"DELETE FROM ".$this->_dbPrefix.
"role WHERE id=".$this->_conn->qstr($role->getID()).
";";
214 if ($this->_conn->Execute($sqlStr) ===
false)
216 Log::error($this->_conn->ErrorMsg().
". Your query was: ".$sqlStr, __CLASS__);
217 WCMFException::throwEx(
"Error removing role '".$role->getName().
"'. See log file for details.", __FILE__, __LINE__);
226 $sqlStr =
"UPDATE ".$this->_dbPrefix.
"role SET ".$property.
"=".$this->_conn->qstr($value).
" WHERE id=".$this->_conn->qstr($role->getID()).
";";
227 if ($this->_conn->Execute($sqlStr) ===
false)
229 Log::error($this->_conn->ErrorMsg().
". Your query was: ".$sqlStr, __CLASS__);
230 WCMFException::throwEx(
"Error changing property '".$property.
"' for role '".$role->getName().
"'. See log file for details.", __FILE__, __LINE__);
239 $sqlStr =
"INSERT INTO ".$this->_dbPrefix.
"nm_user_role (fk_user_id, fk_role_id) VALUES (".$this->_conn->qstr($user->getID()).
", ".$this->_conn->qstr($role->getID()).
");";
240 if ($this->_conn->Execute($sqlStr) ===
false)
242 Log::error($this->_conn->ErrorMsg().
". Your query was: ".$sqlStr, __CLASS__);
243 WCMFException::throwEx(
"Error adding user '".$user->getLogin().
"' to role '".$role->getName().
"'. See log file for details.", __FILE__, __LINE__);
252 $sqlStr =
"DELETE FROM ".$this->_dbPrefix.
"nm_user_role WHERE fk_user_id=".$this->_conn->qstr($user->getID()).
" AND fk_role_id=".$this->_conn->qstr($role->getID()).
";";
253 if ($this->_conn->Execute($sqlStr) ===
false)
255 Log::error($this->_conn->ErrorMsg().
". Your query was: ".$sqlStr, __CLASS__);
256 WCMFException::throwEx(
"Error removing user '".$user->getLogin().
"' from role '".$role->getName().
"'. See log file for details.", __FILE__, __LINE__);
error($message, $category)
Abstract base class for user classes that represent a system user.
Abstract base class for role classes that represent a user role.
setRolePropertyImpl($role, $property, $value)
throwEx($message, $file='', $line='')
setUserPropertyImpl($user, $property, $value)
UserManager is used to edit users and roles. UserManager supports the following operations: ...
createUserImpl($name, $firstname, $login, $password)
removeUserFromRoleImpl($role, $user)
addUserToRoleImpl($role, $user)
UserManagerRDB is a UserManager that stores user and role information in a database using RDBMappers...