Source for file rowmenu-defs.php

Documentation is available at rowmenu-defs.php

  1. <?php
  2. /* ******************************************************************** */
  3. /* CATALYST PHP Source Code */
  4. /* -------------------------------------------------------------------- */
  5. /* This program is free software; you can redistribute it and/or modify */
  6. /* it under the terms of the GNU General Public License as published by */
  7. /* the Free Software Foundation; either version 2 of the License, or */
  8. /* (at your option) any later version. */
  9. /* */
  10. /* This program is distributed in the hope that it will be useful, */
  11. /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
  12. /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
  13. /* GNU General Public License for more details. */
  14. /* */
  15. /* You should have received a copy of the GNU General Public License */
  16. /* along with this program; if not, write to: */
  17. /* The Free Software Foundation, Inc., 59 Temple Place, Suite 330, */
  18. /* Boston, MA 02111-1307 USA */
  19. /* -------------------------------------------------------------------- */
  20. /* */
  21. /* Filename: rowmenu-defs.php */
  22. /* Author: Paul Waite */
  23. /* Description: Definitions for a non-javascript multi-level menu */
  24. /* system, in horizontal rendering with each menu level */
  25. /* set one below the other in rows. */
  26. /* */
  27. /* ******************************************************************** */
  28. /** @package menu */
  29. include_once("treemenu-defs.php");
  30.  
  31. // ----------------------------------------------------------------------
  32. /**
  33. * A hierarchical menu renderer which does not use Javascript to
  34. * implement the menuoption display. NB: this renderer is basically
  35. * the same functionally as the treemenu but is rendered differently.
  36. * The menu is rendered in a table of 1 column x N rows. The top row
  37. * contains all menu items of LEVEL 0, the second row contains items
  38. * of LEVEL 1 and so on. Rows will only be rendered if the previous
  39. * level has an EXPANDED heading menu option. So, at the start the
  40. * menu is rendered with only the top level (LEVEL 0) items row
  41. * displayed. If there are sub-menus, then one or more of these top
  42. * items will be a "heading item" and clicking on it will reveal the
  43. * next level of sub-menu items for which it is the parent. Items
  44. * which are expanded or current location will be given the style
  45. * defined by the ".hlmenuitem" class in sitestyle.css. All other
  46. * menu styles are as defined in the '.menu" class. The menu status
  47. * is saved/recovered from ax_wwwsession.menu_status and is therefore
  48. * persistent.
  49. * @package menu
  50. */
  51. class rowmenu extends treemenu {
  52. /** Separator string between menu options */
  53.  
  54. var $separator = SEP_BAR;
  55. /** Array of background colours for each level */
  56.  
  57. var $background_colours = array();
  58. // ....................................................................
  59. /**
  60. * Constructor
  61. *
  62. * Create a new menumaintainer.
  63. * @param string $id Unique database menu identifier
  64. * @param object $webpage Webpage object that this menu is being created for
  65. * @param string $stylsheet Name of stylesheet file to reference for menu styles
  66. */
  67. function rowmenu($id="main", $webpage=false, $stylesheet="") {
  68. $this->treemenu($id, $webpage, $stylesheet);
  69. } // rowmenu
  70. // ....................................................................
  71. /**
  72. * Set backgrounds colours
  73. * Sets the background colours for each menu level. Provide either a
  74. * delimited list of colours in a string in #nnnnnn format, or an
  75. * array of same. The first colour is for LEVEL 0, second LEVEL 1 etc.
  76. * @param mixed $bgcolours List or array of background colours.
  77. */
  78. function set_background_colours($bgcolours, $delim=",") {
  79. if (!is_array($bgcolours)) {
  80. $bgcolours = explode($delim, $bgcolours);
  81. }
  82. $this->background_colours = $bgcolours;
  83. } // set_background_colours
  84. // ....................................................................
  85. /**
  86. * Set the separator string.
  87. * Sets the string which separates menu options as listed hozizontally
  88. * across. This defaults to SEP_BAR ("&nbsp;| ").
  89. * @param string $sep The separator string to use between menu options
  90. */
  91. function set_separator($sep) {
  92. $this->separator = $sep;
  93. } // set_separator
  94. // ....................................................................
  95. /**
  96. * Process any menu navigation.
  97. * This means we take note of any $_mid value which signifies a menu
  98. * option of that ID is currently being focussed on and alter the menu
  99. * configuration accordingly. We also look at the current page and
  100. * compare that to the menu id 'action' to determine where we are and
  101. * what we should be doing.
  102. */
  103. function process_navigation() {
  104. global $_mid, $RESPONSE;
  105. if ($this->exists) {
  106. if (isset($_mid) && $this->menu->menuop_exists($_mid)) {
  107. $this->menu->current_menu_option = $_mid;
  108. debugbr(">> setting current menu option id=$_mid");
  109. $selmop = $this->menu->menuop($_mid);
  110. if ($selmop !== false) {
  111. // Expand if a submenu-heading..
  112. if ($selmop->is_submenuheading()) {
  113. $selmop->expanded = true;
  114. }
  115. foreach ($this->menu->menu_ops as $mopid => $mop) {
  116. if ($mopid != $_mid && $mop->level >= $selmop->level && $mop->expanded) {
  117. $mop->expanded = false;
  118. $this->menu->menu_ops[$mopid] = $mop;
  119. }
  120. }
  121. $this->menu->menu_ops[$_mid] = $selmop;
  122. }
  123. // Save the updated menu instance object..
  124. $this->save_to_session();
  125. }
  126. }
  127. } // process_navigation
  128. // ....................................................................
  129. /**
  130. * Render the menu as HTML.
  131. * @return string The HTML
  132. */
  133. function html() {
  134. debug_trace($this);
  135. global $LIBDIR, $RESPONSE;
  136. global $_mid;
  137.  
  138. // Initialise content..
  139. $s = "";
  140.  
  141. // Menu layout table..
  142. $Tvw = new table($this->menuid . "_menu", "menu");
  143. $Tvw->setwidth("");
  144.  
  145. // MENU ITEM DETAIL..
  146. if ($this->menu->menuop_count() > 0) {
  147. $parent_id = 0;
  148. for ($level=0; $level <= $this->menu->level_depth; $level++) {
  149. $Tvw->tr();
  150. $menurow_items = array();
  151. $next_parent_id = false;
  152. foreach ($this->menu->menu_ops as $mopid => $mop) {
  153. if ($mop->parent == $parent_id /* && $mop->level == $level */ ) {
  154. if ($mop->expanded) {
  155. $next_parent_id = $mopid;
  156. }
  157. $action = $mop->action;
  158. $label = $mop->label;
  159. if ($action == "") {
  160. // Link to current page for refresh..
  161. $action = $RESPONSE->requested;
  162. if ($RESPONSE->requested_query != "") {
  163. $action .= "?$RESPONSE->requested_query";
  164. }
  165. $heading = true;
  166. }
  167. $menuoption = !$heading;
  168.  
  169. // Add selected menu option id to url..
  170. $action = href_addparm($action, "_mid", $mopid);
  171.  
  172. // Make sure our menu gets refreshed and not stuck in a static
  173. // state in the web-browser's cache..
  174. $action = href_addparm($action, "cachecontrol", "dynamic");
  175.  
  176. // To click or not to click, only if not current webpage..
  177. $req = preg_replace("/^[\\/]/", "", $RESPONSE->requested);
  178. $act = preg_replace("/^[\\/]/", "", $mop->action);
  179.  
  180. if ($mop->action != "" && preg_match("/$act/i", $req)) {
  181. $menuop = "<span id=\"hlmenuitem\">$label</span>";
  182. }
  183. else {
  184. $menuop_link = new anchor($action, $label);
  185. if ($heading && $mop->expanded) {
  186. $menuop_link->setid("hlmenuitem");
  187. }
  188. $menuop = $menuop_link->render();
  189. }
  190. $menurow_items[] = $menuop;
  191. }
  192. } // foreach
  193.  
  194. // Add the menu options row to the menu..
  195. $Tvw->td( implode($this->separator, $menurow_items) );
  196. if (isset($this->background_colours[$level])) {
  197. $Tvw->td_css("background-color:" . $this->background_colours[$level]);
  198. }
  199.  
  200. // If we didn't find a new parent option, we're done..
  201. if ($next_parent_id === false) {
  202. break;
  203. }
  204. else {
  205. $parent_id = $next_parent_id;
  206. }
  207. } // for
  208. }
  209. else {
  210. $Tvw->tr();
  211. $Tvw->td( "&nbsp;" );
  212. }
  213.  
  214. // Render the menu viewer table..
  215. $s .= $Tvw->render();
  216. debug_trace();
  217. return $s;
  218. } // html
  219.  
  220.  
  221.  
  222. } // rowmenu class
  223. // ----------------------------------------------------------------------
  224.  
  225. ?>

Documentation generated by phpDocumentor 1.3.0RC3