This commit is contained in:
skeeter 2001-04-22 02:39:39 +00:00
parent d5343aee16
commit a161abb81e

View File

@ -25,6 +25,7 @@
/*********************************************/ /*********************************************/
class menutree { class menutree {
var $read_from_file; // You can send the tree info from a string or file var $read_from_file; // You can send the tree info from a string or file
var $root_level_value; // This is what the top level name or image will be var $root_level_value; // This is what the top level name or image will be
@ -33,18 +34,17 @@ class menutree {
$this->read_from_file = True; $this->read_from_file = True;
} }
function showtree($treefile, $expandlevels="", $num_menus = 50, $invisible_menus = Null){ function showtree($treefile, $expandlevels='', $num_menus = 50, $invisible_menus = Null)
global $phpgw_info, $phpgw; {
global $phpgw_info, $phpgw, $SCRIPT_FILENAME;
$script = $SCRIPT_NAME; $img_expand = 'templates/default/images/tree_expand.gif';
$img_collapse = 'templates/default/images/tree_collapse.gif';
$img_expand = "templates/default/images/tree_expand.gif"; $img_line = 'templates/default/images/tree_vertline.gif';
$img_collapse = "templates/default/images/tree_collapse.gif"; $img_split = 'templates/default/images/tree_split.gif';
$img_line = "templates/default/images/tree_vertline.gif"; $img_end = 'templates/default/images/tree_end.gif';
$img_split = "templates/default/images/tree_split.gif"; $img_leaf = 'templates/default/images/tree_leaf.gif';
$img_end = "templates/default/images/tree_end.gif"; $img_spc = 'templates/default/images/tree_space.gif';
$img_leaf = "templates/default/images/tree_leaf.gif";
$img_spc = "templates/default/images/tree_space.gif";
/*********************************************/ /*********************************************/
/* Read text file with tree structure */ /* Read text file with tree structure */
@ -60,40 +60,70 @@ class menutree {
/*********************************************/ /*********************************************/
$maxlevel=0; $maxlevel=0;
$cnt=0; $cnt=-1;
if ($this->read_from_file) { if($this->read_from_file)
$fd = fopen($treefile, "r"); {
if ($fd==0) die("menutree.inc : Unable to open file ".$treefile); $fd = fopen($treefile, 'r');
while ($buffer = fgets($fd, 4096)) { if($fd==0)
$tree[$cnt][0]=strspn($buffer,"."); {
die("menutree.inc : Unable to open file ".$treefile);
}
while($buffer = fgets($fd, 4096))
{
$cnt++;
$tree[$cnt][0]=strspn($buffer,'.');
$tmp=rtrim(substr($buffer,$tree[$cnt][0])); $tmp=rtrim(substr($buffer,$tree[$cnt][0]));
$node=explode("|",$tmp); $node=explode('|',$tmp);
$tree[$cnt][1]=$node[0]; $tree[$cnt][1]=$node[0];
$tree[$cnt][2]=$node[1]; $tree[$cnt][2]=$node[1];
$tree[$cnt][3]=$node[2]; $tree[$cnt][3]=$node[2];
$tree[$cnt][4]=0; $tree[$cnt][4]=0;
if ($tree[$cnt][0] > $maxlevel) $maxlevel=$tree[$cnt][0]; if($tree[$cnt][0] > $maxlevel)
$cnt++; {
$maxlevel=$tree[$cnt][0];
}
} }
fclose($fd); fclose($fd);
} else { }
else
{
$ta = explode("\n",$treefile); $ta = explode("\n",$treefile);
while (list($null,$buffer) = each($ta)) { while (list($null,$buffer) = each($ta))
{
$cnt++;
$tree[$cnt][0]=strspn($buffer,"."); $tree[$cnt][0]=strspn($buffer,".");
$tmp=rtrim(substr($buffer,$tree[$cnt][0])); $tmp=rtrim(substr($buffer,$tree[$cnt][0]));
$node=explode("|",$tmp); $node=explode('|',$tmp);
$tree[$cnt][1]=$node[0]; $tree[$cnt][1]=$node[0];
$tree[$cnt][2]=$node[1]; $tree[$cnt][2]=$node[1];
$tree[$cnt][3]=$node[2]; $tree[$cnt][3]=$node[2];
$tree[$cnt][4]=0; $tree[$cnt][4]=0;
if ($tree[$cnt][0] > $maxlevel) $maxlevel=$tree[$cnt][0]; if($tree[$cnt][0] > $maxlevel)
$cnt++; {
$maxlevel=$tree[$cnt][0];
} }
} }
for ($i=0; $i<count($tree); $i++) { }
$c_tree = count($tree);
for($i=0; $i<$c_tree; $i++)
{
if($i!=0)
{
$expand[$i]=0; $expand[$i]=0;
}
else
{
$expand[$i]=1;
}
if($tree[$i][0] <= 2)
{
$visible[$i]=1;
}
else
{
$visible[$i]=0; $visible[$i]=0;
}
$levels[$i]=0; $levels[$i]=0;
} }
@ -101,12 +131,18 @@ class menutree {
/* Get Node numbers to expand */ /* Get Node numbers to expand */
/*********************************************/ /*********************************************/
if ($expandlevels!="") $explevels = explode("|",$expandlevels); if($expandlevels!='')
{
$i=0; $explevels = explode('|',$expandlevels);
while($i<count($explevels)) { $c_exp = count($explevels);
for($i=0;$i<$c_exp;$i++)
{
$expand[$explevels[$i]]=1; $expand[$explevels[$i]]=1;
$i++; }
}
else
{
$c_exp = 0;
} }
/*********************************************/ /*********************************************/
@ -114,77 +150,72 @@ class menutree {
/*********************************************/ /*********************************************/
$lastlevel=$maxlevel; $lastlevel=$maxlevel;
for ($i=count($tree)-1; $i>=0; $i--) { for ($i=count($tree)-1; $i>=0; $i -= 1)
if ( $tree[$i][0] < $lastlevel ) { {
for ($j=$tree[$i][0]+1; $j <= $maxlevel; $j++) { if($tree[$i][0] < $tree[$i+1][0])
{
for($j=$tree[$i][0]+1; $j <= $maxlevel; $j++)
{
$levels[$j]=0; $levels[$j]=0;
} }
} }
if ( $levels[$tree[$i][0]]==0 ) { if($levels[$tree[$i][0]]==0)
{
$levels[$tree[$i][0]]=1; $levels[$tree[$i][0]]=1;
$tree[$i][4]=1; $tree[$i][4]=1;
} else }
else
{
$tree[$i][4]=0; $tree[$i][4]=0;
$lastlevel=$tree[$i][0]; }
// $lastlevel=$tree[$i][0];
} }
/*********************************************/ /*********************************************/
/* Determine visible nodes */ /* Determine visible nodes */
/*********************************************/ /*********************************************/
// $visible[0]=1; // root is always visible
// $visible[1]=1; // root is always visible
// $visible[2]=1; // root is always visible
// $visible[3]=1; // root is always visible
// $visible[4]=1; // root is always visible
// $visible[5]=1; // root is always visible
// $visible[6]=1; // root is always visible
// $visible[7]=1; // root is always visible
// $visible[8]=1; // root is always visible
// $visible[9]=1; // root is always visible
// $visible[10]=1; // root is always visible
// $visible[11]=1; // root is always visible
// $visible[12]=1; // root is always visible
// $visible[13]=1; // root is always visible
// $visible[14]=1; // root is always visible
// $visible[15]=1; // root is always visible
// $visible[16]=1; // root is always visible
// $visible[17]=1; // root is always visible
// $visible[18]=1; // root is always visible
// $visible[19]=1; // root is always visible
// $visible[20]=1; // root is always visible
// $visible[21]=1; // root is always visible
// $visible[22]=1; // root is always visible
// $visible[23]=1; // root is always visible
// $visible[24]=1; // root is always visible
// $visible[25]=1; // root is always visible
// $visible[26]=1; // root is always visible
// $visible[27]=1; // root is always visible
// $visible[28]=1; // root is always visible
for ($i=0; $i<$c_exp; $i++)
{
$visible[0]=1; // root is always visible
$visible[1]=1; // root is always visible
$visible[2]=1; // root is always visible
$visible[3]=1; // root is always visible
$visible[4]=1; // root is always visible
$visible[5]=1; // root is always visible
$visible[6]=1; // root is always visible
$visible[7]=1; // root is always visible
$visible[8]=1; // root is always visible
$visible[9]=1; // root is always visible
$visible[10]=1; // root is always visible
$visible[11]=1; // root is always visible
$visible[12]=1; // root is always visible
$visible[13]=1; // root is always visible
$visible[14]=1; // root is always visible
$visible[15]=1; // root is always visible
$visible[16]=1; // root is always visible
$visible[17]=1; // root is always visible
$visible[18]=1; // root is always visible
$visible[19]=1; // root is always visible
$visible[20]=1; // root is always visible
$visible[21]=1; // root is always visible
$visible[22]=1; // root is always visible
$visible[23]=1; // root is always visible
$visible[24]=1; // root is always visible
$visible[25]=1; // root is always visible
$visible[26]=1; // root is always visible
$visible[27]=1; // root is always visible
$visible[28]=1; // root is always visible
for ($i=0; $i<count($explevels); $i++) {
$n=$explevels[$i]; $n=$explevels[$i];
if ( ($visible[$n]==1) && ($expand[$n]==1) ) { if(($visible[$n]==1) && ($expand[$n]==1))
$j=$n+1; {
while ( $tree[$j][0] > $tree[$n][0] ) { for($j=$n+1;$tree[$j][0]>$tree[$n][0];$j++)
if ($tree[$j][0]==$tree[$n][0]+1) $visible[$j]=1; {
$j++; if($tree[$j][0]==$tree[$n][0]+1)
} {
}
}
for ($i=0; $i<count($explevels); $i++) {
$n=$explevels[$i];
if ( ($visible[$n]==1) && ($expand[$n]==1) ) {
$j=$n+1;
while ( $tree[$j][0] == $tree[$n][0] + 1 ) {
$visible[$j]=1; $visible[$j]=1;
$j++; }
} }
} }
} }
@ -194,33 +225,53 @@ class menutree {
/* Output nicely formatted tree */ /* Output nicely formatted tree */
/*********************************************/ /*********************************************/
for ($i=0; $i<$maxlevel; $i++) $levels[$i]=1; // for($i=0; $i<$maxlevel; $i++)
// {
// $levels[$i]=1;
// }
$maxlevel++; $maxlevel++;
$cnt=0; $cnt=0;
while ($cnt<count($tree)) { for($cnt=0;$cnt<$c_tree - 1;$cnt++)
if ($visible[$cnt]) { {
if(!$visible[$cnt])
{
continue;
}
/****************************************/ /****************************************/
/* Create expand/collapse parameters */ /* Create expand/collapse parameters */
/****************************************/ /****************************************/
#$i=1; $params="p="; $params='p=';
#while($i<count($expand)) { for($i=1;$i<=$c_tree;$i++)
# if ( ($expand[$i]==1) && ($cnt!=$i) || ($expand[$i]==0 && $cnt==$i)) { {
# $params=$params.$i; if(($expand[$i]==1) && ($cnt!=$i) || ($expand[$i]==0 && $cnt==$i))
# $params=$params."|"; {
# } if($params != 'p=')
# $i++; {
#} $params .= '|';
}
$params .= $i;
}
}
if($params=='p=')
{
$params='';
}
/****************************************/ /****************************************/
/* Always display the extreme top level */ /* Always display the extreme top level */
/****************************************/ /****************************************/
if($cnt==0) { if($cnt==0)
{
$str = '<table cellspacing="0" cellpadding="0" border="0" cols="'.($maxlevel+3).'" width="'.($maxlevel*16+100).'">'."\n"; $str = '<table cellspacing="0" cellpadding="0" border="0" cols="'.($maxlevel+3).'" width="'.($maxlevel*16+100).'">'."\n";
$str .= '<a href="' . $phpgw->link('/'.$phpgw_info['flags']['currentapp'].'/index.php',$params) . '" target="_parent">' . $this->root_level_value . '</a>'; $str .= '<a href="' . $phpgw->link('/'.$phpgw_info['flags']['currentapp'].'/index.php',$params) . '" target="_parent">' . $this->root_level_value . '</a>';
$str .= "\n".'<tr>'; $str .= "\n".'<tr>';
for ($i=0; $i<$maxlevel; $i++) $str .= '<td width=16></td>'; for ($k=0; $k<$maxlevel; $k++)
{
$str .= '<td width=16></td>';
}
$str .= '<td width=100></td></tr>'."\n"; $str .= '<td width=100></td></tr>'."\n";
} }
@ -233,21 +284,29 @@ class menutree {
/* vertical lines from higher levels */ /* vertical lines from higher levels */
/****************************************/ /****************************************/
$i=0; $i=0;
while ($i<$tree[$cnt][0]-1) { while ($i<$tree[$cnt][0]-1)
{
if ($levels[$i]==1) if ($levels[$i]==1)
{
$str .= '<td><img src="' . $img_line . '" alt="|"></td>'; $str .= '<td><img src="' . $img_line . '" alt="|"></td>';
}
else else
{
$str .= '<td><img src="' . $img_spc . '" alt=" "></td>'; $str .= '<td><img src="' . $img_spc . '" alt=" "></td>';
}
$i++; $i++;
} }
/****************************************/ /****************************************/
/* corner at end of subtree or t-split */ /* corner at end of subtree or t-split */
/****************************************/ /****************************************/
if ($tree[$cnt][4]==1) { if ($tree[$cnt][4]==1)
{
$str .= '<td><img src="' . $img_end . '" alt="\"></td>'; $str .= '<td><img src="' . $img_end . '" alt="\"></td>';
$levels[$tree[$cnt][0]-1]=0; $levels[$tree[$cnt][0]-1]=0;
} else { }
else
{
$str .= '<td><img src="' . $img_split . '" alt="|-"></td>'; $str .= '<td><img src="' . $img_split . '" alt="|-"></td>';
$levels[$tree[$cnt][0]-1]=1; $levels[$tree[$cnt][0]-1]=1;
} }
@ -255,27 +314,36 @@ class menutree {
/********************************************/ /********************************************/
/* Node (with subtree) or Leaf (no subtree) */ /* Node (with subtree) or Leaf (no subtree) */
/********************************************/ /********************************************/
if ($tree[$cnt+1][0]>$tree[$cnt][0]) { if($tree[$cnt+1][0]>$tree[$cnt][0])
{
if($expand[$cnt]==0) if($expand[$cnt]==0)
$str .= '<td><a href="'.$phpgw->link('/'.$phpgw_info['flags']['currentapp'].'/'.$script,$params).'"><img src="'.$img_expand.'" border="no" alt="+"></a></td>'; {
$str .= '<td><a href="'.$phpgw->link('/'.$phpgw_info['flags']['currentapp'].'/'.basename($SCRIPT_FILENAME),$params).'"><img src="'.$img_expand.'" border="no" alt="+"></a></td>';
}
else else
$str .= '<td><a href="'.$phpgw->link('/'.$phpgw_info['flags']['currentapp'].'/'.$script,$params).'"><img src="'.$img_collapse.'" border="no" alt="-"></a></td>'; {
} else { $str .= '<td><a href="'.$phpgw->link('/'.$phpgw_info['flags']['currentapp'].'/'.basename($SCRIPT_FILENAME),$params).'"><img src="'.$img_collapse.'" border="no" alt="-"></a></td>';
}
}
elseif(isset($tree[$cnt+1][0]))
{
/*************************/ /*************************/
/* Tree Leaf */ /* Tree Leaf */
/*************************/ /*************************/
$str .= '<td><img src="' . $img_leaf . '" alt="o"></td>'; $str .= '<td><img src="' . $img_leaf . '" alt="o"></td>';
} }
/****************************************/ /****************************************/
/* output item text */ /* output item text */
/****************************************/ /****************************************/
if ($tree[$cnt][2]=="") if ($tree[$cnt][2]=='')
$str .= '<td colspan="'.($maxlevel-$tree[$cnt][0]).'">'.$tree[$cnt][1].'<font face="Arial, Helvetica, san-serif" size="2"></td>'; {
$str .= '<td colspan="'.($maxlevel-$tree[$cnt][0]).'">'.$tree[$cnt][1].'<font face="'.$phpgw_info['theme']['font'].'" size="2"></td>';
}
else else
$str .= '<td colspan="'.($maxlevel-$tree[$cnt][0]).'"><font face="Arial, Helvetica, san-serif" size="2"><a href="'.$phpgw->link('/'.$phpgw_info['flags']['currentapp'].'/'.$tree[$cnt][2],$params).'" target="'.$tree[$cnt][3].'">'.$tree[$cnt][1].'</a></td>'; {
$str .= '<td colspan="'.($maxlevel-$tree[$cnt][0]).'"><font face="'.$phpgw_info['theme']['font'].'" size="2"><a href="'.$phpgw->link('/'.$phpgw_info['flags']['currentapp'].'/'.$tree[$cnt][2],$params).'" target="'.$tree[$cnt][3].'">'.$tree[$cnt][1].'</a></td>';
}
/****************************************/ /****************************************/
/* end row */ /* end row */
@ -283,8 +351,6 @@ class menutree {
$str .= '</tr>'."\n"; $str .= '</tr>'."\n";
} }
$cnt++;
}
$str .= '</table>'."\n"; $str .= '</table>'."\n";
return $str; return $str;