<?php
    $g=&$GLOBALS;
    $g[HEADER]->addscriptfile(AM_PLUGIN_URL.'/tree/dtree/vertdtree.js','htreeplugin');
    function buildHTree($rows,$uptolevel=3)
    {
        $g=&$GLOBALS;
    ?>
    <link rel="StyleSheet" href="<?=AM_PLUGIN_URL?>/tree/dtree/dtree.css" type="text/css" />
    <a href="javascript:t.closeAll();">Close All</a>
    <script language='javascript'>
        t = new dTree('t','<?=AM_PLUGIN_URL.'/tree/'?>');
        <?
        foreach($rows as $row)
        {
                if($row[parent_id]==0) $pid=-1;
                else $pid=$row[parent_id];
                if($g[id]==$row[id]) $pid=-1;
                $level=(int)(strlen($row[upline])/12);                
                if($level<=$uptolevel) $nodeOpen='true';
                else $nodeOpen='false';
                                             
        ?>
            t.add(<?=$row[id]?>, <?=$pid?>, '<?=str_replace("'",'\'',$row[id].$row[first_name].' '.$row[last_name])?>', '<?=$row[url]?>', '<?=$row[urltip]?>', '', '','',<?=$nodeOpen?>);
        <?}?>
        document.write(t); 
    </script> 
    <?   
    }
?>