<?php
     //   error_reporting(E_ERROR|E_WARNING);  

    $g=&$GLOBALS;
    $g[HEADER]->addscriptfile(AM_PLUGIN_URL.'/tree/dtree/dtree.js','vtreeplugin');
    
    
    function buildTree($rows,$uptolevel=3)
    {
        $g=&$GLOBALS;
    ?>
    <link rel="StyleSheet" href="<?=AM_PLUGIN_URL?>/tree/dtree/dtree.css" type="text/css" />    
    
    <script language='javascript'>
        t = new dTree('t','<?=AM_PLUGIN_URL.'/tree/'?>');
        <?
            foreach($rows as $row)
            {
                
                if($row[parent_id]==-1 && empty($pid)) $pid=-1;
                else $pid=$row[parent_id];      
               
                                
                
                if($g[id]==$row[id]) $pid=-1;
                $level=$level+1;
                
                
                if($level<=$uptolevel) $nodeOpen=true;
                else $nodeOpen=false;
                
                
                
               
                //$row['name']=str_replace ("'","\\'", $row['name']);
                $row['name']=str_replace ("'","", $row['name']);
                          
           // dbug($row[name]);    
            ?>
            
            
            t.add(<?=$row[id]?>, <?=$pid?>, '<?=str_replace("'",'\'',$row[name])?>', '<?=$row[url]?>', '<?=$row[urltip]?>', '<?=$row[target_path]?>', '<?=$row[icon]?>','<?=$row[icon_open]?>','<?=$nodeOpen?>');
            <?}?>
        document.write(t); 
    </script> 
    
    <?   
    }
?>