public static function singleRealmTree($realmID, $ID, $group)
 {
     global $cfg;
     $db = Database::getInstance($cfg['Auth']['dsn']);
     //get all children of the node specified
     $sql = "SELECT * from realms\n\t\t\tWHERE realms.parent = {$realmID}";
     $subRealms = $db->getAll($sql);
     $list = '';
     foreach ($subRealms as $realm) {
         $sql = "SELECT count(*) FROM realms\n\t\t\t\tWHERE parent = " . $realm['realmid'];
         if ($db->getOne($sql) > 0) {
             $child = 1;
         } else {
             $child = 0;
         }
         if (!$group) {
             //group realmtree
             $uAccess = AuthUtil::getUserAccess($realm['realmid'], $ID);
             $gAccess = AuthUtil::getGroupAccessForUser($realm['realmid'], $ID);
         } else {
             //user realmtree
             $gAccess = AuthUtil::getGroupAccess($realm['realmid'], $ID);
             if ($gAccess = 'y') {
                 $list = $list . '<item text="' . htmlspecialchars($realm['name']) . ' (a,d,i)" id="rlm' . $realm['realmid'] . '" im0="green.gif" child="' . $child . '" >';
             } elseif ($gAccess = 'n') {
                 $list = $list . '<item text="' . htmlspecialchars($realm['name']) . ' (a,d,i)" id="rlm' . $realm['realmid'] . '" im0="red.gif" child="' . $child . '" >';
             } else {
                 $list = $list . '<item text="' . htmlspecialchars($realm['name']) . ' (a,d,i)" id="rlm' . $realm['realmid'] . '" im0="white.gif" child="' . $child . '" >';
             }
         }
     }
     return $list;
 }
    public static function singleRealmTree($realmID, $ID, $group)
    {
        global $cfg;
        $db = Database::getInstance($cfg['Auth']['dsn']);
        //get all children of the node specified
        $sql = "SELECT * from realms\n\t\t\tWHERE realms.parentid = {$realmID}";
        $subRealms = $db->getAll($sql);
        $list = '';
        if ($realmID != 0) {
            if ($group === false) {
                //user realmtree
                $uAccess = AuthUtil::getUserAccess($realmID, $ID);
                $gAccess = AuthUtil::getGroupAccessForUser($realmID, $ID);
                if ($gAccess == 'n' && $uAccess != 'n') {
                    $gAc = 'g ';
                } else {
                    $gAc = '';
                }
                if ($gAccess == 'n' || $uAccess == 'n') {
                    $list = $list . '<item text="allow" id="opa' . $realmID . '" im0="radio_off.gif" child="0" />';
                    $list = $list . '<item text="' . $gAc . 'deny" id="opd' . $realmID . '" im0="radio_on.gif" child="0" />';
                    $list = $list . '<item text="ignore" id="opi' . $realmID . '" im0="radio_off.gif" child="0" />';
                } elseif ($gAccess == 'y' || $uAccess == 'y') {
                    $list = $list . '<item text="' . $gAc . 'allow" id="opa' . $realmID . '" im0="radio_on.gif" child="0" />';
                    $list = $list . '<item text="deny" id="opd' . $realmID . '" im0="radio_off.gif" child="0" />';
                    $list = $list . '<item text="ignore" id="opi' . $realmID . '" im0="radio_off.gif" child="0" />';
                } else {
                    $list = $list . '<item text="' . $gAc . 'allow" id="opa' . $realmID . '" im0="radio_off.gif" child="0" />';
                    $list = $list . '<item text="' . $gAc . 'deny" id="opd' . $realmID . '" im0="radio_off.gif" child="0" />';
                    $list = $list . '<item text="ignore" id="opi' . $realmID . '" im0="radio_on.gif" child="0" />';
                }
            } else {
                //group realmtree
                $gAccess = AuthUtil::getGroupAccess($realmID, $ID);
                if ($gAccess == 'y') {
                    $list = $list . '<item text="allow" id="opa' . $realmID . '" im0="radio_on.gif" child="0" />';
                    $list = $list . '<item text="deny" id="opd' . $realmID . '" im0="radio_off.gif" child="0" />';
                    $list = $list . '<item text="ignore" id="opi' . $realmID . '" im0="radio_off.gif" child="0" />';
                } elseif ($gAccess == 'n') {
                    $list = $list . '<item text="allow" id="opa' . $realmID . '" im0="radio_off.gif" child="0" />';
                    $list = $list . '<item text="deny" id="opd' . $realmID . '" im0="radio_on.gif" child="0" />';
                    $list = $list . '<item text="ignore" id="opi' . $realmID . '" im0="radio_off.gif" child="0" />';
                } else {
                    $list = $list . '<item text="allow" id="opa' . $realmID . '" im0="radio_off.gif" child="0" />';
                    $list = $list . '<item text="deny" id="opd' . $realmID . '" im0="radio_off.gif" child="0" />';
                    $list = $list . '<item text="ignore" id="opi' . $realmID . '" im0="radio_on.gif" child="0" />';
                }
            }
        }
        foreach ($subRealms as $realm) {
            if ($group === false) {
                //user realmtree
                $uAccess = AuthUtil::getUserAccess($realm['realmid'], $ID);
                $gAccess = AuthUtil::getGroupAccessForUser($realm['realmid'], $ID);
                if ($gAccess == 'n' || $uAccess == 'n') {
                    $list = $list . '<item text="' . htmlspecialchars($realm['name']) . '" id="rlm' . $realm['realmid'] . '" im0="red.gif" 
						im1="red.gif" im2="red.gif" child="1" />';
                } elseif ($gAccess == 'y' || $uAccess == 'y') {
                    $list = $list . '<item text="' . htmlspecialchars($realm['name']) . '" id="rlm' . $realm['realmid'] . '" im0="green.gif" 
						im1="green.gif" im2="green.gif" child="1" />';
                } else {
                    $list = $list . '<item text="' . htmlspecialchars($realm['name']) . '" id="rlm' . $realm['realmid'] . '" im0="white.gif"
						im1="white.gif" im2="white.gif" child="1" />';
                }
            } else {
                //group realmtree
                $gAccess = AuthUtil::getGroupAccess($realm['realmid'], $ID);
                if ($gAccess == 'y') {
                    $list = $list . '<item text="' . htmlspecialchars($realm['name']) . '" id="rlm' . $realm['realmid'] . '" im0="green.gif" 
						im1="green.gif" im2="green.gif" child="1" />';
                } elseif ($gAccess == 'n') {
                    $list = $list . '<item text="' . htmlspecialchars($realm['name']) . '" id="rlm' . $realm['realmid'] . '" im0="red.gif" 
						im1="red.gif" im2="red.gif" child="1" />';
                } else {
                    $list = $list . '<item text="' . htmlspecialchars($realm['name']) . '" id="rlm' . $realm['realmid'] . '" im0="white.gif"
						im1="white.gif" im2="white.gif" child="1" />';
                }
            }
        }
        return $list;
    }
 public static function recBuildRealmTree($data, $node, $details, $guid, $group)
 {
     if ($group === true) {
         $details['groupallow'] = AuthUtil::getGroupAccess($node[0], $guid);
     } elseif ($group === false) {
         $details['userallow'] = AuthUtil::getUserAccess($node[0], $guid);
         $details['groupallow'] = AuthUtil::getGroupAccessForUser($node[0], $guid);
     }
     $tree = array('_DETAILS_' => $details);
     foreach ($data as $row) {
         if ($row['parentid'] == $node[0]) {
             $tree[$row['name']] = $row['name'];
             $tmp = $node;
             array_unshift($tmp, $row['realmid']);
             $tree[$row['name']] = AuthUtil::recBuildrealmTree($data, $tmp, $row, $guid, $group);
         }
     }
     return $tree;
 }