function get_array_branch($temp_tree, $id)
{
    global $current_level;
    $current_level--;
    if (is_array($temp_tree)) {
        foreach ($temp_tree as $key => $value) {
            if ($temp_tree[$key]['id'] == $id) {
                // all right, the id is a match leaf
                $new_tree[] = array('id' => $temp_tree[$key]['id'], 'name' => $temp_tree[$key]['name'], 'parent' => $temp_tree[$key]['parent'], 'level' => $current_level);
                if ($branch = get_array_branch($temp_tree, $temp_tree[$key]['parent'])) {
                    // merge the new array with the old array
                    $new_tree = array_merge($new_tree, $branch);
                }
                $current_level++;
            }
        }
    }
    return isset($new_tree) ? $new_tree : false;
}
/**
* grouptree (public)
* 
* returns array of parent groups starting from lowest group (Everybody) and moving to higher,
* last element is a direct parent group
* if parameter group ID is 0 then return only everybody group
* 
* @package CMS
* 
* @param int $group_id 
*
* $grouptree = get_grouptree(array("group_id" => $this->group_id));
*/
function get_grouptree()
{
    $args = func_get_arg(0);
    $sql = "SELECT group_id AS id, parent_group_id AS parent, name FROM groups ORDER BY name";
    $sth = new SQL($sql);
    while ($data = $sth->fetch()) {
        $temp_tree[] = $data;
    }
    $grouptree = get_array_branch($temp_tree, $args['group_id']);
    # if no tree genreated then get evrybody group
    if (!is_array($grouptree)) {
        $sql = "SELECT group_id AS id, parent_group_id AS parent, name FROM groups WHERE is_predefined='1'";
        $sth = new SQL($sql);
        $grouptree[] = $sth->fetch('ASSOC');
    }
    $grouptree = array_reverse($grouptree);
    return $grouptree;
}