22 private $roleRootNode;
26 private $groupRootNode;
30 private $userRootNode;
45 private $families = array();
56 private $addedIds = array();
57 private $schemaWritted = array();
76 $this->workAccount = new \Account();
81 $accounts = $this->
search->search();
83 $count = $accounts->length;
88 switch ($account->accounttype) {
89 case \Account::USER_TYPE:
93 case \Account::GROUP_TYPE:
97 case \Account::ROLE_TYPE:
102 throw new Exception(
"ACCT0100", $account->login, $account->id);
107 $this->reorderGroups();
111 $this->aborted =
true;
112 $this->rootNode->setAttribute(
"aborted",
"true");
120 return $this->xml->saveXML();
136 if (!is_dir($this->exportSchemaDirectory)) {
137 mkdir($this->exportSchemaDirectory);
152 if ($this->sessionKey) {
154 $action->session->register($this->sessionKey .
"::ABORT", self::ABORTORDER);
166 if ($this->sessionKey) {
168 $action->session->register($this->sessionKey, $text);
169 $msg = $action->session->read($this->sessionKey .
"::ABORT");
170 if ($msg === self::ABORTORDER) {
171 $action->session->register($this->sessionKey .
"::ABORT",
"CATCHED");
179 if ($this->sessionKey) {
181 return $action->session->read($this->sessionKey);
189 protected function reorderGroups()
191 $xpath = new \DOMXpath($this->xml);
192 $groups = $xpath->query(
'//accounts/groups/group/reference');
194 $groupLogins = array();
198 foreach ($groups as $loginNode) {
199 $groupLogins[] = pg_escape_string($loginNode->nodeValue);
201 if (count($groupLogins) > 0) {
203 $sql = sprintf(
"select memberof,id from users where login in (%s)", implode(array_map(
function (
$s)
205 return pg_escape_literal(
$s);
207 , $groupLogins) ,
", "));
209 $searchGroups = array();
210 foreach ($members as $parents) {
211 $memberOf = explode(
',', substr($parents[
"memberof"], 1, -1));
213 $searchGroups = array_merge($searchGroups,
$memberOf);
215 $searchGroups = array_unique($searchGroups);
216 $searchGroups = array_filter($searchGroups,
function ($x)
222 $sql = sprintf(
"select groups.iduser as groupid, groups.idgroup as parentid, users.login as grouplogin from groups, users where groups.iduser in (%s) and groups.iduser=users.id and users.accounttype='G'", implode(array_map(
function (
$s)
224 return pg_escape_literal(
$s);
226 , $searchGroups) ,
", "));
230 foreach ($groupTree as & $groupItem) {
231 $groupItem[
"groupid"] = intval($groupItem[
"groupid"]);
232 $groupItem[
"parentid"] = intval($groupItem[
"parentid"]);
235 $groupOrdered = array();
236 foreach ($groupLogins as $groupRef) {
237 $groupOrdered[] = array(
238 "reference" => $groupRef,
243 usort($groupOrdered,
function (
$a, $b)
245 if (
$a[
"order"] > $b[
"order"])
return +1;
246 elseif (
$a[
"order"] < $b[
"order"]) return -1;
250 foreach ($groupOrdered as $group) {
251 $reference = $group[
"reference"];
255 $groups = $xpath->query(sprintf(
'//accounts/groups/group/reference[text()=%s]/..', self::xpathLiteral($reference)))->item(0);
257 $groups->parentNode->appendChild($groups);
267 foreach ($tree as $row) {
268 if ($row[
"grouplogin"] === $groupIdentifier || $row[
"groupid"] === $groupIdentifier) {
269 $parentLevel = max($parentLevel, $this->
getDepthLevel($row[
"parentid"], $tree));
272 return $parentLevel + 1;
279 $xpath = new \DOMXpath($this->xml);
280 foreach ($xpath->query(
'//*[not(node())][not(@*)]') as $node) {
281 $node->parentNode->removeChild($node);
283 foreach ($xpath->query(
'//*[not(node())][not(@*)]') as $node) {
284 $node->parentNode->removeChild($node);
321 $this->xml = new \DOMDocument(
"1.0",
"utf-8");
322 $this->rootNode = $this->xml->createElement(
"accounts");
323 $this->rootNode->setAttribute(
"date", date(
"Y-m-d\\TH:i:s"));
324 $this->xml->appendChild($this->rootNode);
325 $this->roleRootNode = $this->xml->createElement(
"roles");
326 $this->rootNode->appendChild($this->roleRootNode);
327 $this->groupRootNode = $this->xml->createElement(
"groups");
328 $this->rootNode->appendChild($this->groupRootNode);
329 $this->userRootNode = $this->xml->createElement(
"users");
330 $this->userRootNode = $this->xml->createElement(
"users");
331 $this->rootNode->appendChild($this->userRootNode);
333 $this->xml->preserveWhiteSpace =
false;
334 $this->xml->formatOutput =
true;
344 $this->documentInfo[$user->id] = $user->fid;
352 $s = new \DocumentList();
353 $s->addDocumentIdentifiers($this->documentInfo);
354 if (!$this->exportDocument) {
362 $export = new \Dcp\ExportXmlDocument();
363 $export->setStructureAttributes(
true);
364 $export->setIncludeSchemaReference(
false);
366 $docXml = new \DOMDocument(
"1.0",
"utf-8");
367 $docXml->preserveWhiteSpace =
false;
368 $xpath = new \DOMXpath($this->xml);
369 $count =
$s->count();
373 $this->
setSessionMessage(sprintf(
___(
"Export relative document (%d/%d)",
"fuserexport") , $k, $count));
375 $documentNode = $this->xml->createElement(
"document");
376 $documentNode->setAttribute(
"family", $doc->fromname);
377 $uid = array_search($doc->id, $this->documentInfo);
378 $nodes = $xpath->query(sprintf(
'//*[@id="%d"]', $uid));
380 $accountNode = $nodes->item(0);
381 $accountNode->appendChild($documentNode);
382 if ($this->exportDocument) {
385 $export->setAttributeToExport(array(
386 $doc->fromid => $this->filterAttribute($doc)
389 $docXml->loadXML(
$xml);
392 $docNode = $this->xml->importNode($docXml->documentElement,
true);
394 $documentNode->appendChild($docNode);
395 if ($this->exportSchemaDirectory) {
396 $this->writeFamilySchema($doc->fromname);
400 if ($this->exportSchemaDirectory) {
407 copy(sprintf(
"%s/FDL/Layout/fdl.xsd",
DEFAULT_PUBDIR) , sprintf(
"%s/fdl.xsd", $this->exportSchemaDirectory));
408 copy(sprintf(
"%s/FDL/Layout/fdloptions.xsd",
DEFAULT_PUBDIR) , sprintf(
"%s/fdloptions.xsd", $this->exportSchemaDirectory));
409 $this->xml->documentElement->setAttribute(
"xmlns:xsi",
"http://www.w3.org/2001/XMLSchema-instance");
410 $this->xml->documentElement->setAttribute(
"xsi:noNamespaceSchemaLocation", self::XSDDIR .
"/accounts.xsd");
412 $xsd = new \DOMDocument();
413 $xsd->load(
"USERCARD/Layout/accounts.xsd");
414 $xpath = new \DOMXPath($xsd);
415 $documentTypeNode = $xpath->query(
'//xs:complexType[@name="documentType"]/xs:sequence')->item(0);
417 $this->writeFamilySchema(
"IUSER");
418 $this->writeFamilySchema(
"IGROUP");
419 $this->writeFamilySchema(
"ROLE");
421 $family = new_doc(
"",
"IUSER");
422 $subFams = $family->getChildFam();
423 foreach ($subFams as $subFam) {
424 $this->writeFamilySchema($subFam[
"name"]);
426 $family = new_doc(
"",
"IGROUP");
427 $subFams = $family->getChildFam();
428 foreach ($subFams as $subFam) {
429 $this->writeFamilySchema($subFam[
"name"]);
431 $family = new_doc(
"",
"ROLE");
432 $subFams = $family->getChildFam();
433 foreach ($subFams as $subFam) {
434 $this->writeFamilySchema($subFam[
"name"]);
437 foreach ($this->schemaWritted as $familyName => $true) {
438 $familyName = strtolower($familyName);
439 $node = $xsd->createElement(
"xs:element");
440 $node->setAttribute(
"type", sprintf(
"family-%s-type", $familyName));
441 $node->setAttribute(
"name", $familyName);
442 $node->setAttribute(
"minOccurs",
"0");
443 $documentTypeNode->appendChild($node);
445 $node = $xsd->createElement(
"xs:include");
446 $node->setAttribute(
"schemaLocation", sprintf(
"%s.xsd", $familyName));
448 $firstElement = $xpath->query(
'//xs:element')->item(0);
449 $firstElement->parentNode->insertBefore($node, $firstElement);
451 file_put_contents(sprintf(
"%s/accounts.xsd", $this->exportSchemaDirectory) , $xsd->saveXML());
454 protected function writeFamilySchema($familyName)
456 if (empty($this->schemaWritted[$familyName])) {
460 $fam = new_doc(
"", $familyName);
461 $output = sprintf(
"%s/%s.xsd", $this->exportSchemaDirectory, strtolower($fam->name));
463 file_put_contents($output, $fam->getXmlSchema(
true));
464 $this->schemaWritted[$familyName] =
true;
473 private function filterAttribute(\
Doc $doc)
476 $excludeFilters = array();
477 if (is_a($doc,
"\\Dcp\\Family\\Iuser")) {
478 if (!isset($this->families[
"IUSER"])) {
479 $this->families[
"IUSER"] = new_doc(
"",
"IUSER");
481 $excludeFilters = array(
510 if (is_a($doc,
"\\Dcp\\Family\\Igroup")) {
511 if (!isset($this->families[
"IGROUP"])) {
512 $this->families[
"IGROUP"] = new_doc(
"",
"IGROUP");
514 $excludeFilters = array(
541 if (is_a($doc,
"\\Dcp\\Family\\Role")) {
542 if (!isset($this->families[
"ROLE"])) {
543 $this->families[
"ROLE"] = new_doc(
"",
"ROLE");
545 $excludeFilters = array(
553 foreach ($attributes as $oattr) {
554 if ($oattr->usefor !==
"Q" && !in_array($oattr->id, $excludeFilters) && (!$oattr->isNormal || $oattr->type ===
"array" || $doc->
getRawValue($oattr->id) !==
"")) {
565 private function addParentInfo(\
Account $user, \DOMElement $node)
571 if (count($roles) > 0) {
572 $roleNode = $this->xml->createElement(
"associatedRoles");
573 $roleNode->setAttribute(
"reset",
"false");
574 $node->appendChild($roleNode);
575 foreach ($roles as $role) {
576 $this->workAccount->select($role);
577 $roleRef = $this->workAccount->login;
578 if ($this->exportRoleParent) {
581 $nodeInfo = $this->xml->createElement(
"associatedRole");
582 $nodeInfo->setAttribute(
"reference", $roleRef);
583 $roleNode->appendChild($nodeInfo);
587 if (count($groups) > 0) {
588 $roleNode = $this->xml->createElement(
"parentGroups");
589 $roleNode->setAttribute(
"reset",
"false");
590 $node->appendChild($roleNode);
591 foreach ($groups as $group) {
592 $this->workAccount->select($group);
593 $groupRef = $this->workAccount->login;
594 if ($this->exportGroupParent) {
597 $nodeInfo = $this->xml->createElement(
"parentGroup");
598 $nodeInfo->setAttribute(
"reference", $groupRef);
599 $roleNode->appendChild($nodeInfo);
610 $node = $this->xml->createElement(
"user");
618 foreach ($infos as
$info) {
619 $infoValue = $user->$info;
621 $nodeInfo = $this->xml->createElement($info, htmlspecialchars($infoValue));
622 $node->appendChild($nodeInfo);
625 $nodeInfo = $this->xml->createElement(
"status");
626 $nodeInfo->setAttribute(
"activated", $user->status ===
"D" ?
"false" :
"true");
627 $node->appendChild($nodeInfo);
629 if ($user->substitute) {
630 simpleQuery(
"", sprintf(
"select login from users where id = %d", $user->substitute) , $substituteLogin,
true,
true);
631 if ($substituteLogin) {
632 $nodeInfo = $this->xml->createElement(
"substitute");
633 $nodeInfo->setAttribute(
"reference", $substituteLogin);
634 $node->appendChild($nodeInfo);
637 if ($this->exportCryptedPassword) {
638 $nodeInfo = $this->xml->createElement(
"password", htmlspecialchars($user->password));
639 $nodeInfo->setAttribute(
"crypted",
"true");
640 $node->appendChild($nodeInfo);
643 $node->setAttribute(
"id", $user->id);
644 $this->addParentInfo($user, $node);
648 $this->userRootNode->appendChild($node);
656 if (empty($this->addedIds[$group->id])) {
657 $node = $this->xml->createElement(
"group");
658 $nodeInfo = $this->xml->createElement(
"reference", htmlspecialchars($group->login));
659 $node->appendChild($nodeInfo);
660 $nodeInfo = $this->xml->createElement(
"displayName", htmlspecialchars($group->
getAccountName()));
661 $node->appendChild($nodeInfo);
663 $node->setAttribute(
"id", $group->id);
666 $this->groupRootNode->appendChild($node);
667 $this->addedIds[$group->id] =
true;
668 $this->addParentInfo($group, $node);
677 if (empty($this->addedIds[$role->id])) {
678 $node = $this->xml->createElement(
"role");
679 $nodeInfo = $this->xml->createElement(
"reference", htmlspecialchars($role->login));
680 $node->appendChild($nodeInfo);
681 $nodeInfo = $this->xml->createElement(
"displayName", htmlspecialchars($role->
getAccountName()));
682 $node->appendChild($nodeInfo);
683 $node->setAttribute(
"id", $role->id);
686 $this->roleRootNode->appendChild($node);
687 $this->addedIds[$role->id] =
true;
703 if (strpos($str,
"'") ===
false) {
704 return "'" . $str .
"'";
706 return "concat(" . str_replace(array(
709 ) ,
"",
"'" . implode(
"',\"'\",'", explode(
"'", $str)) .
"'") .
")";
print< H1 > Check Database< i > $dbaccess</i ></H1 > $a
setExportGroupParent($exportGroupParent)
getDepthLevel($groupIdentifier, $tree)
setSearchAccount(\SearchAccount $s)
setExportRoleParent($exportRoleParent)
if(!function_exists('pgettext')) ___($message, $context="")
addRoleAccount(\Account $role)
static xpathLiteral($str)
getRoles($useSystemId=true)
setExportCryptedPassword($exportCryptedPassword)
setSessionKey($sessionKey)
setExportSchemaDirectory($exportSchemaDirectory)
& getAttributes($useMask=true)
setExportDocument($exportDocument)
memoDocumentInfo(\Account $user)
addUserAccount(\Account $user)
addGroupAccount(\Account $group)
simpleQuery($dbaccess, $query, &$result=array(), $singlecolumn=false, $singleresult=false, $useStrict=null)
getRawValue($idAttr, $def="")