Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
Lib.Usercard.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @package FDL
5 */
6 /**
7  * Function utilities to manipulate users
8  *
9  * @author Anakeen
10  * @version $Id: Lib.Usercard.php,v 1.5 2007/02/16 07:35:54 eric Exp $
11  * @package FDL
12  * @subpackage USERCARD
13  */
14 /**
15  */
16 include_once ("Class.Group.php");
17 include_once ("FDL/Class.Dir.php");
18 /**
19  * refresh a set of group
20  * @param array $tg the groups which has been modify by insertion/deletion of user
21  * @return
22  */
23 
24 function refreshGroups($groupIdList, $refresh = false, &$currentPath = array() , &$groupDepth = array())
25 {
26  /*
27  * @var Group $wg
28  */
29  static $wg = null;
30 
31  if (!$wg) $wg = new group("", 2); // working group;
32  // Iterate over given groups list
33  foreach ($groupIdList as $groupId) {
34  // Detect loops in groups
35  if (array_search($groupId, $currentPath)) {
36  error_log(__CLASS__ . "::" . __FUNCTION__ . " " . sprintf("Loop detected in group with id '%s' (path=[%s])", $groupId, join('-', $currentPath)));
37  continue;
38  }
39  // Get direct parent groups list
40  $parentGroupIdList = $wg->getParentsGroupId($groupId);
41  // Compute depth of current group and recursively compute depth on parent groups
42  array_push($currentPath, $groupId);
43  if (isset($groupDepth[$groupId])) $groupDepth[$groupId] = max($groupDepth[$groupId], count($currentPath));
44  else $groupDepth[$groupId] = count($currentPath);
45  refreshGroups($parentGroupIdList, $refresh, $currentPath, $groupDepth);
46  array_pop($currentPath);
47  }
48  // End of groups traversal
49  if (count($currentPath) <= 0) {
50  // We can now refresh the groups based on their ascending depth
51  uasort($groupDepth, function ($a, $b)
52  {
53  return ($a - $b);
54  });
55  foreach ($groupDepth as $group => $depth) {
56  refreshOneGroup($group, $refresh);
57  }
58  }
59 
60  return $groupIdList;
61 }
62 
63 function array_unset(&$t, $vp)
64 {
65  foreach ($t as $k => $v) {
66  if ($v == $vp) unset($t[$k]);
67  }
68 }
69 
70 function refreshOneGroup($gid, $refresh)
71 {
72  global $_SERVER;
73  $g = new Account("", $gid);
74  if ($g->fid > 0 && $g->accounttype == 'G') {
75  $dbaccess = $g->dbaccess;
76  /**
77  * @var \Dcp\Family\Igroup $doc
78  */
79  $doc = new_Doc($dbaccess, $g->fid);
80  if ($doc->isAlive()) {
81  //if ($_SERVER['HTTP_HOST'] == "") error_log(sprintf("\trefreshing %s\n", $doc->title));
82  wbartext(sprintf(_("refreshing %s") , $doc->title));
83  if ($refresh) $doc->refreshMembers();
84  $doc->SetGroupMail();
85  $doc->modify();
86  $doc->specPostInsert();
87  $doc->setValue("grp_isrefreshed", "1");
88  $doc->modify(true, array(
89  "grp_isrefreshed"
90  ) , true);
91  }
92  }
93 }
wbartext($text)
Definition: Lib.Common.php:637
print< H1 > Check Database< i > $dbaccess</i ></H1 > $a
Definition: checklist.php:45
refreshGroups($groupIdList, $refresh=false, &$currentPath=array(), &$groupDepth=array())
global $_SERVER
new_Doc($dbaccess, $id= '', $latest=false)
$dbaccess
Definition: checkVault.php:17
array_unset(&$t, $vp)
← centre documentaire © anakeen