diff --git a/phpgwapi/inc/class.menutree.inc.php b/phpgwapi/inc/class.menutree.inc.php index 5ce7dc5fbc..7406fb791e 100644 --- a/phpgwapi/inc/class.menutree.inc.php +++ b/phpgwapi/inc/class.menutree.inc.php @@ -25,294 +25,360 @@ /*********************************************/ class menutree { - 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 - function menutree() - { - $this->read_from_file = True; - } +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 - function showtree($treefile, $expandlevels="", $num_menus = 50, $invisible_menus = Null){ - global $phpgw_info, $phpgw; - - $script = $SCRIPT_NAME; - - $img_expand = "templates/default/images/tree_expand.gif"; - $img_collapse = "templates/default/images/tree_collapse.gif"; - $img_line = "templates/default/images/tree_vertline.gif"; - $img_split = "templates/default/images/tree_split.gif"; - $img_end = "templates/default/images/tree_end.gif"; - $img_leaf = "templates/default/images/tree_leaf.gif"; - $img_spc = "templates/default/images/tree_space.gif"; - - /*********************************************/ - /* Read text file with tree structure */ - /*********************************************/ - - /*********************************************/ - /* read file to $tree array */ - /* tree[x][0] -> tree level */ - /* tree[x][1] -> item text */ - /* tree[x][2] -> item link */ - /* tree[x][3] -> link target */ - /* tree[x][4] -> last item in subtree */ - /*********************************************/ - - $maxlevel=0; - $cnt=0; + function menutree() + { + $this->read_from_file = True; + } - if ($this->read_from_file) { - $fd = fopen($treefile, "r"); - if ($fd==0) die("menutree.inc : Unable to open file ".$treefile); - while ($buffer = fgets($fd, 4096)) { - $tree[$cnt][0]=strspn($buffer,"."); - $tmp=rtrim(substr($buffer,$tree[$cnt][0])); - $node=explode("|",$tmp); - $tree[$cnt][1]=$node[0]; - $tree[$cnt][2]=$node[1]; - $tree[$cnt][3]=$node[2]; - $tree[$cnt][4]=0; - if ($tree[$cnt][0] > $maxlevel) $maxlevel=$tree[$cnt][0]; - $cnt++; - } - fclose($fd); - } else { - $ta = explode("\n",$treefile); - while (list($null,$buffer) = each($ta)) { - $tree[$cnt][0]=strspn($buffer,"."); - $tmp=rtrim(substr($buffer,$tree[$cnt][0])); - $node=explode("|",$tmp); - $tree[$cnt][1]=$node[0]; - $tree[$cnt][2]=$node[1]; - $tree[$cnt][3]=$node[2]; - $tree[$cnt][4]=0; - if ($tree[$cnt][0] > $maxlevel) $maxlevel=$tree[$cnt][0]; - $cnt++; - } - } - for ($i=0; $i tree level */ + /* tree[x][1] -> item text */ + /* tree[x][2] -> item link */ + /* tree[x][3] -> link target */ + /* tree[x][4] -> last item in subtree */ + /*********************************************/ - /*********************************************/ - /* Get Node numbers to expand */ - /*********************************************/ + $maxlevel=0; + $cnt=-1; + + if($this->read_from_file) + { + $fd = fopen($treefile, 'r'); + if($fd==0) + { + 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])); + $node=explode('|',$tmp); + $tree[$cnt][1]=$node[0]; + $tree[$cnt][2]=$node[1]; + $tree[$cnt][3]=$node[2]; + $tree[$cnt][4]=0; + if($tree[$cnt][0] > $maxlevel) + { + $maxlevel=$tree[$cnt][0]; + } + } + fclose($fd); + } + else + { + $ta = explode("\n",$treefile); + while (list($null,$buffer) = each($ta)) + { + $cnt++; + $tree[$cnt][0]=strspn($buffer,"."); + $tmp=rtrim(substr($buffer,$tree[$cnt][0])); + $node=explode('|',$tmp); + $tree[$cnt][1]=$node[0]; + $tree[$cnt][2]=$node[1]; + $tree[$cnt][3]=$node[2]; + $tree[$cnt][4]=0; + if($tree[$cnt][0] > $maxlevel) + { + $maxlevel=$tree[$cnt][0]; + } + } + } + $c_tree = count($tree); + for($i=0; $i<$c_tree; $i++) + { + if($i!=0) + { + $expand[$i]=0; + } + else + { + $expand[$i]=1; + } + if($tree[$i][0] <= 2) + { + $visible[$i]=1; + } + else + { + $visible[$i]=0; + } + $levels[$i]=0; + } + + /*********************************************/ + /* Get Node numbers to expand */ + /*********************************************/ - if ($expandlevels!="") $explevels = explode("|",$expandlevels); + if($expandlevels!='') + { + $explevels = explode('|',$expandlevels); + $c_exp = count($explevels); + for($i=0;$i<$c_exp;$i++) + { + $expand[$explevels[$i]]=1; + } + } + else + { + $c_exp = 0; + } - $i=0; - while($i=0; $i--) { - if ( $tree[$i][0] < $lastlevel ) { - for ($j=$tree[$i][0]+1; $j <= $maxlevel; $j++) { - $levels[$j]=0; - } - } - if ( $levels[$tree[$i][0]]==0 ) { - $levels[$tree[$i][0]]=1; - $tree[$i][4]=1; - } else - $tree[$i][4]=0; - $lastlevel=$tree[$i][0]; - } + $lastlevel=$maxlevel; + for ($i=count($tree)-1; $i>=0; $i -= 1) + { + if($tree[$i][0] < $tree[$i+1][0]) + { + for($j=$tree[$i][0]+1; $j <= $maxlevel; $j++) + { + $levels[$j]=0; + } + } + if($levels[$tree[$i][0]]==0) + { + $levels[$tree[$i][0]]=1; + $tree[$i][4]=1; + } + else + { + $tree[$i][4]=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++) + { + $n=$explevels[$i]; + if(($visible[$n]==1) && ($expand[$n]==1)) + { + for($j=$n+1;$tree[$j][0]>$tree[$n][0];$j++) + { + if($tree[$j][0]==$tree[$n][0]+1) + { + $visible[$j]=1; + } + } + } + } + /*********************************************/ + /* Output nicely formatted tree */ + /*********************************************/ - $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<$maxlevel; $i++) +// { +// $levels[$i]=1; +// } - - for ($i=0; $i $tree[$n][0] ) { - if ($tree[$j][0]==$tree[$n][0]+1) $visible[$j]=1; - $j++; - } - } - } - - - for ($i=0; $i'."\n"; - $str .= '' . $this->root_level_value . ''; - $str .= "\n".''; - for ($i=0; $i<$maxlevel; $i++) $str .= ''; - $str .= ''."\n"; - } + if($cnt==0) + { + $str = ''."\n"; + $str .= '' . $this->root_level_value . ''; + $str .= "\n".''; + for ($k=0; $k<$maxlevel; $k++) + { + $str .= ''; + } + $str .= ''."\n"; + } - /****************************************/ - /* start new row */ - /****************************************/ - $str .= ''; + /****************************************/ + /* start new row */ + /****************************************/ + $str .= ''; - /****************************************/ - /* vertical lines from higher levels */ - /****************************************/ - $i=0; - while ($i<$tree[$cnt][0]-1) { - if ($levels[$i]==1) - $str .= ''; - else - $str .= ''; - $i++; - } + /****************************************/ + /* vertical lines from higher levels */ + /****************************************/ + $i=0; + while ($i<$tree[$cnt][0]-1) + { + if ($levels[$i]==1) + { + $str .= ''; + } + else + { + $str .= ''; + } + $i++; + } - /****************************************/ - /* corner at end of subtree or t-split */ - /****************************************/ - if ($tree[$cnt][4]==1) { - $str .= ''; - $levels[$tree[$cnt][0]-1]=0; - } else { - $str .= ''; - $levels[$tree[$cnt][0]-1]=1; - } + /****************************************/ + /* corner at end of subtree or t-split */ + /****************************************/ + if ($tree[$cnt][4]==1) + { + $str .= ''; + $levels[$tree[$cnt][0]-1]=0; + } + else + { + $str .= ''; + $levels[$tree[$cnt][0]-1]=1; + } - /********************************************/ - /* Node (with subtree) or Leaf (no subtree) */ - /********************************************/ - if ($tree[$cnt+1][0]>$tree[$cnt][0]) { - - if ($expand[$cnt]==0) - $str .= ''; - else - $str .= ''; - } else { - /*************************/ - /* Tree Leaf */ - /*************************/ - - $str .= ''; - } + /********************************************/ + /* Node (with subtree) or Leaf (no subtree) */ + /********************************************/ + if($tree[$cnt+1][0]>$tree[$cnt][0]) + { + if($expand[$cnt]==0) + { + $str .= ''; + } + else + { + $str .= ''; + } + } + elseif(isset($tree[$cnt+1][0])) + { + /*************************/ + /* Tree Leaf */ + /*************************/ + $str .= ''; + } - /****************************************/ - /* output item text */ - /****************************************/ - if ($tree[$cnt][2]=="") - $str .= ''; - else - $str .= ''; + /****************************************/ + /* output item text */ + /****************************************/ + if ($tree[$cnt][2]=='') + { + $str .= ''; + } + else + { + $str .= ''; + } - /****************************************/ - /* end row */ - /****************************************/ + /****************************************/ + /* end row */ + /****************************************/ - $str .= ''."\n"; - } - $cnt++; - } - $str .= '
| | \|-\|-+-o+-o'.$tree[$cnt][1].''.$tree[$cnt][1].''.$tree[$cnt][1].''.$tree[$cnt][1].'
'."\n"; + $str .= ''."\n"; + } + $str .= ''."\n"; - return $str; + return $str; - /***************************************************/ - /* Tree file format */ - /* */ - /* */ - /* The first line is always of format : */ - /* .[rootname] */ - /* */ - /* each line contains one item, the line starts */ - /* with a series of dots(.). Each dot is one level */ - /* deeper. Only one level at a time once is allowed*/ - /* Next comes the come the item name, link and */ - /* link target, seperated by a |. */ - /* */ - /* example: */ - /* */ - /* .top */ - /* ..category 1 */ - /* ...item 1.1|item11.htm|main */ - /* ...item 2.2|item12.htm|main */ - /* ..category 2|cat2overview.htm|main */ - /* ...item 2.1|item21.htm|main */ - /* ...item 2.2|item22.htm|main */ - /* ...item 2.3|item23.htm|main */ - /* */ - /***************************************************/ - } + /***************************************************/ + /* Tree file format */ + /* */ + /* */ + /* The first line is always of format : */ + /* .[rootname] */ + /* */ + /* each line contains one item, the line starts */ + /* with a series of dots(.). Each dot is one level */ + /* deeper. Only one level at a time once is allowed*/ + /* Next comes the come the item name, link and */ + /* link target, seperated by a |. */ + /* */ + /* example: */ + /* */ + /* .top */ + /* ..category 1 */ + /* ...item 1.1|item11.htm|main */ + /* ...item 2.2|item12.htm|main */ + /* ..category 2|cat2overview.htm|main */ + /* ...item 2.1|item21.htm|main */ + /* ...item 2.2|item22.htm|main */ + /* ...item 2.3|item23.htm|main */ + /* */ + /***************************************************/ + } }