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.XMLUtil.php");
45 $this->_old_error_handler = set_error_handler(
"XMLUtilErrorHandler");
49 $this->_xml->SetOptions(array(
'TimeStampFlag' => 0,
'XmlOptions' => array(XML_OPTION_SKIP_WHITE => 1)));
52 $aDbPermissions = array(
55 $this->_xml->bSecureMode = TRUE;
56 foreach ($aDbPermissions as $MethodName => $Permission)
57 $this->_xml->aPermissions[$MethodName] = $Permission;
59 if (!$this->_xml->Open($this->_initParams[
'filename'], FALSE, $lock))
61 $this->_xml->XmlDb->setVerbose(0);
63 $this->_fileOpened =
true;
66 register_shutdown_function(array(&$this,
'closeConnection'));
74 if ($this->_old_error_handler != null)
75 set_error_handler($this->_old_error_handler);
77 $this->_fileOpened =
false;
85 if (($err = $this->_xml->XmlDb->getLastError()) !=
'')
88 $this->_xml->bModifyFlag =
false;
92 $this->_xml->bModifyFlag =
true;
100 if (!$this->_fileOpened)
109 if ($this->_fileOpened)
118 if ($this->_fileOpened)
120 $this->_xml->bModifyFlag = FALSE;
156 $userRepository = array();
157 $userRepository[
'users'] = array();
158 $userRepository[
'roles'] = array();
161 $this->_initParams = $params;
166 $userQuery =
"*/users/*";
167 $userPathArray = $this->_xml->XmlDb->evaluate($userQuery);
168 foreach ($userPathArray as $userPath)
170 $curUserID = $this->_xml->XmlDb->getAttributes($userPath,
'id');
172 $user->setDBID($this->_xml->XmlDb->getAttributes($userPath,
'id'));
173 $user->setLogin($this->_xml->XmlDb->getData($userPath.
"/login"));
174 $user->setPassword($this->_xml->XmlDb->getData($userPath.
"/password"));
175 $user->setName($this->_xml->XmlDb->getData($userPath.
"/name"));
176 $user->setFirstname($this->_xml->XmlDb->getData($userPath.
"/firstname"));
177 $user->setConfig($this->_xml->XmlDb->getData($userPath.
"/config"));
178 $userRolesPathArray = $this->_xml->XmlDb->evaluate($userPath.
'/userroles/roleid');
179 foreach ($userRolesPathArray as $userRolePath)
181 $roleId = $this->_xml->XmlDb->getData($userRolePath);
182 $rolePathArray = $this->_xml->XmlDb->evaluate(
'*/roles/role[@id="'.$roleId.
'"]/name');
184 $role->setDBID($roleId);
185 $role->setName($this->_xml->XmlDb->getData($rolePathArray[0]));
186 $user->addChild($role);
188 $userRepository[
'users'][
sizeof($userRepository[
'users'])] = &$user;
191 $roleQuery =
"*/roles/*";
192 $rolePathArray = $this->_xml->XmlDb->evaluate($roleQuery);
193 foreach ($rolePathArray as $rolePath)
195 $curRoleID = $this->_xml->XmlDb->getAttributes($rolePath,
'id');
197 $role->setDBID($curRoleID);
198 $role->setName($this->_xml->XmlDb->getData($rolePath.
"/name"));
199 $userRepository[
'roles'][
sizeof($userRepository[
'roles'])] = $role;
202 return $userRepository;
211 return new $className;
220 return new $className;
228 $newID = $this->_xml->GetNextInsertId();
231 $parentPathArray = $this->_xml->XmlDb->evaluate(
'*/users');
234 $userPath = $this->_xml->XmlDb->appendChild($parentPathArray[0],
'<user/>');
235 $this->_xml->XmlDb->setAttributes($userPath, array(
'id' => $newID));
237 $namePath = $this->_xml->XmlDb->appendChild($userPath,
'<name/>');
238 $this->_xml->XmlDb->insertData($namePath, $name);
240 $firstnamePath = $this->_xml->XmlDb->appendChild($userPath,
'<firstname/>');
241 $this->_xml->XmlDb->insertData($firstnamePath, $firstname);
243 $loginPath = $this->_xml->XmlDb->appendChild($userPath,
'<login/>');
244 $this->_xml->XmlDb->insertData($loginPath, $login);
246 $passwordPath = $this->_xml->XmlDb->appendChild($userPath,
'<password/>');
247 $this->_xml->XmlDb->insertData($passwordPath, $password);
249 $configPath = $this->_xml->XmlDb->appendChild($userPath,
'<config/>');
251 $rolesPath = $this->_xml->XmlDb->appendChild($userPath,
'<userroles/>');
257 $user =
new $className;
258 $user->setDBID($newID);
259 $user->setLogin($login);
260 $user->setPassword($password);
261 $user->setName($name);
262 $user->setFirstname($firstname);
272 $userQuery =
'*/users/user[@id="'.$user->getDBID().
'"]';
273 $userPathArray = $this->_xml->XmlDb->evaluate($userQuery);
276 $this->_xml->_RemoveRecord($userPathArray);
288 $propertyQuery =
'*/users/user[@id="'.$user->getDBID().
'"]/'.$property;
289 $propertyPathArray = $this->_xml->XmlDb->evaluate($propertyQuery);
291 $this->_xml->XmlDb->replaceData($propertyPathArray[0], $value);
302 $newID = $this->_xml->GetNextInsertId();
305 $parentPathArray = $this->_xml->XmlDb->evaluate(
'*/roles');
308 $rolePath = $this->_xml->XmlDb->appendChild($parentPathArray[0],
'<role/>');
309 $this->_xml->XmlDb->setAttributes($rolePath, array(
'id' => $newID));
310 $namePath = $this->_xml->XmlDb->appendChild($rolePath,
'<name/>');
311 $this->_xml->XmlDb->insertData($namePath, $name);
316 return new Role($newID, $name);
325 $rolesQuery =
'*/users/user/userroles/roleid[.="'.$role->getDBID().
'"]';
326 $rolesPathArray = $this->_xml->XmlDb->evaluate($rolesQuery);
329 $this->_xml->_RemoveRecord($rolesPathArray);
332 $roleQuery =
'*/roles/role[@id="'.$role->getDBID().
'"]';
333 $rolePathArray = $this->_xml->XmlDb->evaluate($roleQuery);
336 $this->_xml->_RemoveRecord($rolePathArray);
348 $propertyQuery =
'*/roles/role[@id="'.$role->getDBID().
'"]/'.$property;
349 $propertyPathArray = $this->_xml->XmlDb->evaluate($propertyQuery);
351 $this->_xml->XmlDb->replaceData($propertyPathArray[0], $value);
363 $rolesQuery =
'*/users/user[@id="'.$user->getDBID().
'"]/userroles';
364 $rolesPathArray = $this->_xml->XmlDb->evaluate($rolesQuery);
367 $rolePath = $this->_xml->XmlDb->appendChild($rolesPathArray[0],
'<roleid/>');
368 $this->_xml->XmlDb->insertData($rolePath, $role->getDBID());
380 $rolesQuery =
'*/users/user[@id="'.$user->getDBID().
'"]/userroles/roleid[.="'.$role->getDBID().
'"]';
381 $rolesPathArray = $this->_xml->XmlDb->evaluate($rolesQuery);
384 $this->_xml->_RemoveRecord($rolesPathArray);
Abstract base class for role classes that represent a user role.
throwEx($message, $file='', $line='')
XMLUtil helps in using XML files as storage. XMLUtil is a subclass of CXmlDb that is customized for u...
UserManagerXML is a UserManager that stores user and role information in an XML file.
addUserToRoleImpl(&$role, &$user)
removeUserFromRoleImpl(&$role, &$user)
UserManager is used to edit users and roles. UserManager supports the following operations: ...
& createUserImpl($name, $firstname, $login, $password)
openConnection($lock=true)
setUserPropertyImpl(&$user, $property, $value)
setRolePropertyImpl(&$role, $property, $value)