18 require_once SQ_INCLUDE_PATH.
'/asset.inc';
19 require_once SQ_CORE_PACKAGE_PATH.
'/interfaces/bridge/bridge.inc';
20 require_once SQ_FUDGE_PATH.
'/general/file_system.inc';
37 public $groups = NULL;
38 public $group_members = NULL;
39 public $user_memberships = NULL;
52 $res = parent::__construct($assetid);
69 protected function _getName($short_name=FALSE, $contextid=NULL)
72 if ($contextid === NULL) {
73 $contextid = $GLOBALS[
'SQ_SYSTEM']->getContextId();
77 $values = $GLOBALS[
'SQ_SYSTEM']->am->getAttributeValuesByName(
'name', $this->
type(), Array($this->
id), $contextid);
78 if (empty($values) === TRUE) {
79 return parent::_getName($short_name, $contextid);
81 return $values[$this->id];
95 #require_once 'XML/Tree.php';
96 require_once SQ_INCLUDE_PATH.
'/general_occasional.inc';
98 $filename = $this->data_path.
'/contents.xml';
100 if (!file_exists($filename) || (filemtime($filename) < strtotime(
'-'.$this->
attr(
'refresh_time').
' seconds'))) {
102 if ($this->
attr(
'data_url')) {
103 $xml = @file_get_contents($this->
attr(
'data_url'));
105 if (!is_dir($this->data_path)) {
106 create_directory($this->data_path);
108 string_to_file($xml, $filename);
112 if (!file_exists($filename))
return;
114 $root = @simplexml_load_file($filename);
119 $this->groups = Array();
120 $this->group_members = Array();
121 $this->user_memberships = Array();
122 foreach ($root->children() as $group_node) {
123 if ($group_node->getName() !=
'group')
continue;
124 $groupid = (int)$group_node->attributes()->id;
125 $this->groups[$groupid] = (string)$group_node->attributes()->name;
126 foreach ($group_node->children() as $member_node) {
127 $_attributes = Array();
128 foreach ($member_node->attributes() as $k => $v) {
129 $_attributes[$k] = (string)$v;
131 $this->group_members[$groupid][((int)$member_node->attributes()->id)] = $_attributes;
132 $this->user_memberships[(int)$member_node->attributes()->id][] = $groupid;
154 function getAsset($assetid, $type_code=
'', $mute_errors=FALSE)
156 $bits = explode(
':', $assetid);
157 switch (count($bits)) {
159 return $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid, $type_code, $mute_errors);
161 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset(
'user_group');
162 $shadowid = $bits[1];
165 $ug->name = $this->groups[$shadowid];
166 $ug->short_name = $this->groups[$shadowid];
167 $ug->status = $this->status;
168 $ug->setAttrValue(
'name', $this->groups[$shadowid]);
172 $personid = $bits[2];
173 $user_type = $this->
attr(
'user_type');
174 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset($user_type);
175 $user =
new $user_type();
176 $user->id = $assetid;
177 $user->status = $this->status;
178 if (isset($this->group_members[$groupid][$personid])) {
179 foreach ($this->group_members[$groupid][$personid] as $field => $val) {
180 if (isset($user->vars[$field])) {
181 $user->setAttrValue($field, $val);
185 $user->name = $user->_getName();
186 $user->short_name = $user->_getName(TRUE);
218 function getLinks($assetid, $link_types, $type_code=
'', $strict_type_code=TRUE, $side_of_link=
'major', $sort_by=NULL, $dependant=NULL, $exclusive=NULL)
221 if ($dependant || $exclusive) {
226 if (! $link_types && SQ_LINK_TYPE_1) {
231 $user_type_codes = array_diff($GLOBALS[
'SQ_SYSTEM']->am->getTypeDescendants(Array(
'user',
'user_group'), TRUE), Array(
'root_user'));
232 if (!empty($type_code) && !in_array($type_code, $user_type_codes)) {
236 $bits = explode(
':', $assetid);
237 switch (count($bits)) {
239 if (($assetid == $this->
id) && ($side_of_link ==
'major')) {
242 'majorid' => $this->
id,
243 'link_type' => SQ_LINK_TYPE_1,
244 'major_type_code' =>
'xml_user_bridge',
245 'minor_type_code' =>
'user_group',
252 foreach ($this->groups as $id => $name) {
253 $sample[
'minorid'] = $this->
id.
':'.$id;
258 return $GLOBALS[
'SQ_SYSTEM']->am->getLinks($assetid, $link_types, $type_code, $strict_type_code, $side_of_link, $sort_by, $dependant, $exclusive);
262 if ($side_of_link ==
'major') {
265 'majorid' => $assetid,
266 'link_type' => SQ_LINK_TYPE_1,
267 'major_type_code' =>
'user_group',
268 'minor_type_code' => $this->
attr(
'user_type'),
275 foreach ($this->group_members[$bits[1]] as $userid => $details) {
276 $sample[
'minorid'] = $assetid.
':'.$userid;
284 'minorid' => $assetid,
285 'majorid' => $this->
id,
286 'link_type' => SQ_LINK_TYPE_1,
287 'major_type_code' =>
'xml_user_bridge',
288 'minor_type_code' =>
'user_group',
298 if ($side_of_link ==
'major') {
303 'minorid' => $assetid,
304 'link_type' => SQ_LINK_TYPE_1,
305 'major_type_code' =>
'user_group',
306 'minor_type_code' => $this->
attr(
'user_type'),
313 foreach ($this->user_memberships[$bits[2]] as $groupid) {
314 $sample[
'majorid'] = $this->
id.
':'.$groupid;
339 function getParents($assetid, $type_code=
'', $strict_type_code=TRUE)
341 $bits = explode(
':', $assetid);
343 switch (count($bits)) {
345 $res = $GLOBALS[
'SQ_SYSTEM']->am->getParents($assetid, $type_code, $strict_type_code);
348 if (empty($type_code) || ($type_code ==
'xml_user_bridge') || (!$strict_type_code && ($type_code ==
'bridge'))) {
349 $res = Array($this->
id =>
'xml_user_bridge');
353 if (empty($type_code) || ($type_code ==
'user_group') || (!$strict_type_code && ($type_code ==
'folder'))) {
354 foreach ($this->user_memberships[$bits[2]] as $groupid) {
355 $res[$groupid] =
'user_group';
385 function getChildren($assetid, $type_code=
'', $strict_type_code=TRUE, $dependant=NULL, $sort_by=NULL)
387 $bits = explode(
':', $assetid);
389 switch (count($bits)) {
391 if ($assetid == $this->
id) {
392 foreach ($this->group_members as $groupid => $members) {
393 $res[$this->
id.
':'.$groupid] = Array(Array(
'type_code' =>
'user_group'));
397 return $GLOBALS[
'SQ_SYSTEM']->am->getChildren($assetid, $type_code=
'', $strict_type_code=TRUE, $dependant=NULL, $sort_by=NULL);
402 foreach (array_get_index($this->group_members, $bits[1], Array()) as $memberid => $details) {
403 $res[$assetid.
':'.$memberid] = Array(Array(
'type_code' =>
'bulkmail_user'));
436 function getLink($assetid, $link_type=NULL, $type_code=
'', $strict_type_code=TRUE, $value=NULL, $side_of_link=
'major', $exclusive=NULL)
497 function getAssetInfo($assetids, $type_code=Array(), $strict_type_code=TRUE, $field=
'')
499 assert_type($assetids,
'array');
500 if (empty($assetids))
return Array();
501 if (!is_array($type_code)) {
502 $type_code = Array($type_code);
504 $template = reset($GLOBALS[
'SQ_SYSTEM']->am->getAssetInfo($this->id));
507 $available_types = $GLOBALS[
'SQ_SYSTEM']->am->getTypeAncestors($this->
attr(
'user_type'));
508 $available_types[] = $this->
attr(
'user_type');
509 if (empty($type_code) || array_intersect($available_types, $type_code)) {
511 foreach ($assetids as $assetid) {
512 $asset =& $this->
getAsset($assetid, $this->
attr(
'user_type'));
515 foreach ($template as $i => $v) {
516 if ($i ==
'type_code')
continue;
517 $entry[$i] = $asset->$i;
520 $entry = $asset->$field;
522 $res[$assetid] = $entry;
526 if (empty($type_code) || in_array(
'user_group', $type_code)) {
528 foreach ($assetids as $id) {
529 $bits = explode(
':', $id);
530 if (count($bits) == 2) {
531 $name = array_get_index($this->groups, $bits[1]);
534 $entry[
'name'] = $name;
535 $entry[
'short_name'] = $name;
536 $entry[
'type_code'] =
'user_group';
540 $res[$id] = array_get_index($entry, $field);
563 if (!is_array($assetids)) {
564 $my_assetids = Array($assetids);
566 $my_assetids = $assetids;
568 foreach ($my_assetids as $assetid) {
569 $bits = explode(
':', $assetid);
570 switch (count($bits)) {
572 $res[$assetid] = ($assetid == $this->id);
575 $res[$assetid] = isset($this->groups[$bits[1]]);
578 $res[$assetid] = isset($this->groups[$bits[1]]) && isset($this->group_members[$bits[1]][$bits[2]]);
582 return (is_array($assetids)) ? $res : $res[$assetids];
607 function getPermission($assetid, $permission, $granted=null, $and_greater=
true, $expand_groups=
false, $all_info=
false)
609 return $GLOBALS[
'SQ_SYSTEM']->am->getPermission($this->
id, $permission, $granted, $and_greater, $expand_groups, $all_info);
651 public function countLinks($assetid, $side_of_link=
'major', $link_types=0, $type_code=
'', $strict_type_code=TRUE, $ignore_linkid=0)