function get_array_leafs($temp_tree, $id)
{
    global $current_level;
    $current_level++;
    foreach ($temp_tree as $key => $value) {
        if ($temp_tree[$key]['parent'] == $id) {
            // all right, the parent id is a match
            $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_leafs($temp_tree, $temp_tree[$key]['id'])) {
                // merge the new array with the old array
                $new_tree = array_merge($new_tree, $branch);
            }
            $current_level--;
        }
    }
    return isset($new_tree) ? $new_tree : false;
}
		<TR style="display: <?php 
        if ($extension_level > 0) {
            ?>
none<?php 
        }
        ?>
" id="overview<?php 
        echo $value['parent'] . '_' . $idx;
        ?>
EXT">
			<td id="section"><?php 
        echo str_repeat('&nbsp;&nbsp;', $extension_level);
        ?>
			<?php 
        #### if subtree exists
        if (is_array(get_array_leafs($temp_tree, $value['id']))) {
            ?>
			<IMG SRC="<?php 
            echo $site->CONF['wwwroot'] . $site->CONF['styles_path'];
            ?>
/gfx/general/arrow_closed.gif" WIDTH="16" HEIGHT="16" BORDER="0" alt="expand" id="image<?php 
            echo $value['id'];
            ?>
" style="cursor:hand" onclick="ExpandDetail(<?php 
            echo $value['id'];
            ?>
)" onkeypress="ExpandDetail(<?php 
            echo $value['id'];
            ?>
)" align=absmiddle><a href="#" onclick="ExpandDetail(<?php 
            echo $value['id'];
/**
* get_groupleafs (public)
* 
* returns array of child groups recursively starting from given group, 
* array includes also given group (by parameter) itself
* 
* @package CMS
* 
* @param int $group_id 
*
* $groupleafs = get_groupleafs(array("group_id" => $this->group_id));
*/
function get_groupleafs()
{
    global $current_level;
    $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('ASSOC')) {
        $temp_tree[] = $data;
        # remember current group
        if ($data['id'] == $args['group_id']) {
            $current_group = $data;
        }
    }
    $current_level = 1;
    # set NULL global variable
    $groupleafs = get_array_leafs($temp_tree, $args['group_id']);
    # include also curretn group (by parameter) to array:
    $groupleafs[] = $current_group;
    #echo printr($groupleafs);
    return $groupleafs;
}