source: contrib/Dms/TreeMenuSafe.php @ 3526

Revision 3526, 4.6 KB checked in by afernandes, 13 years ago (diff)

Ticket #1416 - Disponibilizado modulos Timesheet e DMS para a comunidade.

  • Property svn:executable set to *
Line 
1<?php
2  // TreeMenuSafe.php
3  // Author: Chip Chapin <cchapin@chipchapin.com>
4  // This file is an extension to HTML_TreeMenu, by Richard Heyes.
5  // Much of the code is based on Heyes' client-side JavaScript code.
6 
7  include_once('TreeMenu.php');
8  include_once('ccBrowserInfo.php');
9 
10  // Browser detection determines whether we generate DHTML menus
11  static $tmsDoesMenus = 'maybe';
12 
13
14class HTML_TreeMenuSafe extends HTML_TreeMenu
15{
16  // Constructor
17  function HTML_TreeMenuSafe($layer=null, $images=null, $linkTarget = '_self', $usePersistence = true)
18  {
19    if ($GLOBALS['tmsDoesMenus'] == 'maybe') {
20      $tmb = new ccBrowserInfo();
21      $GLOBALS['tmsDoesMenus'] = ($tmb->is_ie5up() || $tmb->is_moz5up);
22    }
23    HTML_TreeMenu::HTML_TreeMenu($layer, $images, $linkTarget, $usePersistence);
24  } // HTML_TreeMenuSafe
25
26  function printMenu($images=null, $rigidmenu=false, $layer=null)
27  {
28    if (!$rigidmenu && $GLOBALS['tmsDoesMenus']) HTML_TreeMenu::printMenu($images, $layer);
29    elseif (!empty($this->items)) {
30      // Static menu
31      // $images could have been set in the constructor,
32      // so don't assign to it unless a value has been supplied here.
33      // $layer is not used for static menus.
34      if (!empty($images))     $this->images = $images;
35      for ($i=0; $i < count($this->items); $i++) {
36        $this->_printStaticMenu($this, $i);
37      }
38    } // static menu
39  } // printMenu
40
41
42  //
43  // Helper Functions
44  //
45 
46  // Print HTML for a single menu node
47  // This code is based on the JavaScript function drawMenu().
48  function _printNode($thisnode, $currentlevel, $prepend='', $modifier='')
49  {
50    if (empty($this->images)) {
51      // No images in output
52      $iconimg = '';
53      $imgTag  = '';
54    }
55    else {
56      $gifname   = 'branch';
57      $iconimg   = $thisnode->icon ? sprintf('<img src="%s/%s" width="20" height="20" align="top">',
58                                       $this->images, $thisnode->icon) : '';
59      $imgTag    = sprintf('<img src="%s/%s%s.gif" width="20" height="20" align="top" border="0" />',
60                           $this->images, $gifname, $modifier);
61    }
62    $linkStart   = $thisnode->link ? sprintf('<a href="%s" target="%s">',
63                                       $thisnode->link, $this->linkTarget) : '';
64    $linkEnd     = $thisnode->link ? '</a>' : '';
65    $titleString = $thisnode->text;
66    $styleStart  = '';
67    $styleEnd    = '';
68    if ($thisnode->style == 'auto') {
69      $styleInx = min($currentlevel, count($GLOBALS['_autostyles'])-1);
70      $styleStart = '<span class="' . $GLOBALS['_autostyles'][$styleInx] . '">';
71      $styleEnd   = '</span>';
72    }
73    echo '<nobr>'. $styleStart . $prepend .
74         (parentLayerID == null && nodes.length == 1 ? '' : $imgTag) .
75         $iconimg .
76         $linkStart . $titleString . $linkEnd .
77         $styleEnd . "</nobr><br>\n";
78  } // _printNode
79
80
81  // Static menu.
82  // Print current node and all subnodes
83  function _printStaticMenu($nodeParent, $nodeinx, $currentlevel=0, $prepend='')
84  {
85    $thisnode    = $nodeParent->items[$nodeinx];
86    $cntSubnodes = empty($thisnode->items) ? 0 : count($thisnode->items);
87    $cntSiblings = empty($nodeParent->items) ? 0 : count($nodeParent->items);
88
89    // Gif modifier
90    if ($nodeinx == 0 && $currentlevel == 0) $modifier = $cntSubnodes > 1 ? 'top' : 'single';
91    elseif ($nodeinx == ($cntSiblings - 1))  $modifier = 'bottom';
92    else                                     $modifier = ''; 
93    $this->_printNode($thisnode, $currentlevel, $prepend, $modifier);
94   
95    // Print any subnodes
96    for ($i=0; $i<$cntSubnodes; $i++) {
97      // Determine what to prepend to child subnode entries.
98      $newPrepend = $prepend;
99      if (empty($this->images)) {
100        // No images.  Use spaces instead
101        $newPrepend .= '&nbsp;&nbsp;';
102      }
103      else {
104        // Prepend images to each menu entry
105        //if ($currentlevel == 0 && $cntSiblings == 1) $nppimg = '';
106        //^^^  This special case does not apply to static menus.
107        //     Why?  Bwaaa Ha Ha Ha Haaaaaaa!!  Try it and see.  Happy Halloween...
108        if ($nodeinx < ($cntSiblings - 1))       $nppimg = 'line.gif';
109        else                                     $nppimg = 'linebottom.gif';
110        $newPrepend .= sprintf('<img ninx=%d csn=%d src="%s/%s" width="20" height="20" align="top">', $nodeinx, $cntSubnodes, $this->images, $nppimg);
111      }
112
113      // Now print the menu entry for this node
114      $this->_printStaticMenu($thisnode, $i, $currentlevel+1, $newPrepend);
115    }
116  } // _printStaticMenu
117
118
119} // class HTML_TreeMenuSafe
120
121       
122?>
Note: See TracBrowser for help on using the repository browser.