Switch to actual public/private/protected indicators instead of @access ones
[isso.git] / printer_navigation.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Blue Static ISSO Framework [#]issoversion[#]
5 || # Copyright ©2002-[#]year[#] Blue Static
6 || #
7 || # This program is free software; you can redistribute it and/or modify
8 || # it under the terms of the GNU General Public License as published by
9 || # the Free Software Foundation; version [#]gpl[#] of the License.
10 || #
11 || # This program is distributed in the hope that it will be useful, but
12 || # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 || # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 || # more details.
15 || #
16 || # You should have received a copy of the GNU General Public License along
17 || # with this program; if not, write to the Free Software Foundation, Inc.,
18 || # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 || ###################################################################
20 \*=====================================================================*/
21
22 /**
23 * Printer - Navigation Generator
24 * printer_navigation.php
25 *
26 * @package ISSO
27 */
28
29 /**
30 * Printer - Navigation Generator
31 *
32 * This framework works in conjunction with ISSO.Printer to generate a page header
33 * and sidebar to be used for navigation. You set the navigation array and then can
34 * specify a given key to highlight elements. Elements are broken into three types:
35 * tabs (top of the page), groups (blocks of link actions), and links
36 *
37 * @author Blue Static
38 * @copyright Copyright ©2002 - [#]year[#], Blue Static
39 * @version $Revision$
40 * @package ISSO
41 *
42 */
43 class Printer_Navigation
44 {
45 /**
46 * Framework registry object
47 * @var object
48 */
49 private $registry = null;
50
51 /**
52 * Global links that are used for admin home, logout, etc.
53 * @var array
54 */
55 private $toplinks = array();
56
57 /**
58 * Navigational tabs: array(text, url)
59 * @var array
60 */
61 private $tabs = array();
62
63 /**
64 * Sections: text
65 * @var array
66 */
67 private $sections = array();
68
69 /**
70 * Links: array(text, url)
71 * @var array
72 */
73 private $links = array();
74
75 /**
76 * Array of scopes to set focus to key
77 * @var array
78 */
79 private $focus = array('tab' => null, 'link' => null);
80
81 // ###################################################################
82 /**
83 * Constructor
84 */
85 function __construct(&$registry)
86 {
87 $this->registry =& $registry;
88 }
89
90 // ###################################################################
91 /**
92 * (PHP 4) Constructor
93 */
94 function Printer_Navigation(&$registry)
95 {
96 $this->__construct($registry);
97 }
98
99 // ###################################################################
100 /**
101 * Adds a global link to the array; these cannot be removed once added
102 *
103 * @access public
104 *
105 * @param string Link text
106 * @param string HREF of the URL
107 */
108 function add_top_link($text, $href)
109 {
110 $this->toplinks["$href"] = $text;
111 }
112
113 // ###################################################################
114 /**
115 * Adds to the structure array. The following is the global structure
116 * of the array, but you can specify any entry point. When you add onto
117 * the structure, it will go at the bottom
118 * array(
119 * '<tab>unique_key' => array(
120 * '<section>unique_key' => array(
121 * '<link>unique_key' => array('text', 'url')
122 * )
123 * )
124 * )
125 *
126 * Note that the portion in brackets is called the "scope"
127 *
128 * @access public
129 *
130 * @param string Scope to add to
131 * @param string Unique key for the scope
132 * @param string Parent key to add to
133 * @param string Text to display (usually localized)
134 * @param string URL to go to when text is clicked
135 */
136 function add_component($scope, $key, $parent, $text, $url)
137 {
138 if ($scope == 'tab')
139 {
140 $this->tabs["$key"] = array($text, $url);
141 }
142 else if ($scope == 'section')
143 {
144 $this->sections["$parent"]["$key"] = $text;
145 }
146 else if ($scope == 'link')
147 {
148 $this->links["$parent"]["$key"] = array($text, $url);
149 }
150 }
151
152 // ###################################################################
153 /**
154 * Sets the focus for either a tab or link
155 *
156 * @access public
157 *
158 * @param string Scope operator
159 * @param string Unique key in scope
160 * @param string Parent operator (links only)
161 */
162 function set_focus($scope, $key, $parent)
163 {
164 if ($scope == 'tab')
165 {
166 if (isset($this->tabs["$key"]))
167 {
168 $this->focus["$scope"] = $key;
169 }
170 else
171 {
172 trigger_error('Invalid key for scope', E_USER_WARNING);
173 }
174 }
175 else if ($scope == 'link')
176 {
177 if (isset($this->links["$parent"]["$key"]))
178 {
179 $this->focus["$scope"] = $key;
180 }
181 else
182 {
183 trigger_error('Invalid key for scope', E_USER_WARNING);
184 }
185 }
186 else
187 {
188 trigger_error('Printer_Navigation::set_focus() only allows setting of focus for tab and link scopes', E_USER_ERROR);
189 }
190 }
191
192 // ###################################################################
193 /**
194 * Generates the header HTML that is called in ISSO.Printer->page_start()
195 * to setup the navigation frame
196 *
197 * @access public
198 *
199 * @return string Generated HTML content
200 */
201 function generate_header_html()
202 {
203 $output = '<!-- navigation start -->' . "\n\n";
204
205 // -------------------------------------------------------------------
206
207 $output2 = array();
208 foreach ($this->toplinks AS $href => $text)
209 {
210 $output2[] = '<a href="' . $href . '">' . $text . '</a>';
211 }
212
213 $output .= "\n" . '<div id="toplinks">';
214 $output .= "\n\t" . '<div>' . $this->registry->get('application') . ' ' . $this->registry->modules['printer']->get('realm') . '</div>';
215 $output .= "\n\t" . '<div id="toplinks-links">' . implode(' &bull; ', $output2) . '</div>';
216 $output .= "\n" . '</div>';
217
218 // -------------------------------------------------------------------
219
220 $output .= "\n\n" . '<div id="wrapper">';
221
222 // -------------------------------------------------------------------
223
224 $output .= "\n" . '<div id="tabbar">';
225 foreach ($this->tabs AS $key => $content)
226 {
227 $link = "\n\t" . '<a href="' . $content[1] . '"';
228 if ($this->focus['tab'] == $key)
229 {
230 $link .= ' id="focustab"';
231 }
232
233 $link .= '><span>' . $content[0] . '</span></a>';
234
235 $output .= $link;
236 }
237 $output .= "\n" . '</div>';
238
239 // -------------------------------------------------------------------
240
241 $output .= "\n\n" . '<table id="contentbody" cellspacing="0" cellpadding="0" border="0">';
242 $output .= "\n" . '<tr>';
243
244 // -------------------------------------------------------------------
245
246 $output .= "\n" . '<td id="menu">';
247 foreach ((array)$this->sections[ $this->focus['tab'] ] AS $key => $text)
248 {
249 $output .= "\n" . '<ul>';
250 $output .= "\n\t" . '<li class="header"><span>' . $text . '</span></li>';
251 foreach ((array)$this->links["$key"] AS $key2 => $content)
252 {
253 $output .= "\n\t" . '<li' . ($this->focus['link'] == $key2 ? ' class="focus"' : '') . '><a href="' . $content[1] . '"><span>' . $content[0] . '</span></a></li>';
254 }
255 $output .= "\n" . '</ul>' . "\n";
256 }
257 $output .= "\n" . '</td>';
258
259 // -------------------------------------------------------------------
260
261 $output .= "\n" . '<td id="mainbody">';
262 $output .= "\n\n" . '<!-- main content body -->' . "\n";
263
264 return $output;
265 }
266
267 // ###################################################################
268 /**
269 * Generates the HTML that is inserted in ISSO.Printer->page_end() that
270 * closes all of the navigation HTML stuff
271 *
272 * @access public
273 *
274 * @return string Generated HTML content
275 */
276 function generate_footer_html()
277 {
278 $output = '';
279
280 $output .= "\n" . '<!-- / main content body -->' . "\n";
281
282 $output .= "\n" . '</td>';
283 $output .= "\n" . '</tr>';
284
285 $output .= "\n\n" . '</table>';
286
287 $output .= "\n\n" . '</div>';
288
289 return $output;
290 }
291 }
292
293 /*=====================================================================*\
294 || ###################################################################
295 || # $HeadURL$
296 || # $Id$
297 || ###################################################################
298 \*=====================================================================*/
299 ?>