Removing the PHP4 constructors
[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 * Adds a global link to the array; these cannot be removed once added
93 *
94 * @access public
95 *
96 * @param string Link text
97 * @param string HREF of the URL
98 */
99 function add_top_link($text, $href)
100 {
101 $this->toplinks["$href"] = $text;
102 }
103
104 // ###################################################################
105 /**
106 * Adds to the structure array. The following is the global structure
107 * of the array, but you can specify any entry point. When you add onto
108 * the structure, it will go at the bottom
109 * array(
110 * '<tab>unique_key' => array(
111 * '<section>unique_key' => array(
112 * '<link>unique_key' => array('text', 'url')
113 * )
114 * )
115 * )
116 *
117 * Note that the portion in brackets is called the "scope"
118 *
119 * @access public
120 *
121 * @param string Scope to add to
122 * @param string Unique key for the scope
123 * @param string Parent key to add to
124 * @param string Text to display (usually localized)
125 * @param string URL to go to when text is clicked
126 */
127 function add_component($scope, $key, $parent, $text, $url)
128 {
129 if ($scope == 'tab')
130 {
131 $this->tabs["$key"] = array($text, $url);
132 }
133 else if ($scope == 'section')
134 {
135 $this->sections["$parent"]["$key"] = $text;
136 }
137 else if ($scope == 'link')
138 {
139 $this->links["$parent"]["$key"] = array($text, $url);
140 }
141 }
142
143 // ###################################################################
144 /**
145 * Sets the focus for either a tab or link
146 *
147 * @access public
148 *
149 * @param string Scope operator
150 * @param string Unique key in scope
151 * @param string Parent operator (links only)
152 */
153 function set_focus($scope, $key, $parent)
154 {
155 if ($scope == 'tab')
156 {
157 if (isset($this->tabs["$key"]))
158 {
159 $this->focus["$scope"] = $key;
160 }
161 else
162 {
163 trigger_error('Invalid key for scope', E_USER_WARNING);
164 }
165 }
166 else if ($scope == 'link')
167 {
168 if (isset($this->links["$parent"]["$key"]))
169 {
170 $this->focus["$scope"] = $key;
171 }
172 else
173 {
174 trigger_error('Invalid key for scope', E_USER_WARNING);
175 }
176 }
177 else
178 {
179 trigger_error('Printer_Navigation::set_focus() only allows setting of focus for tab and link scopes', E_USER_ERROR);
180 }
181 }
182
183 // ###################################################################
184 /**
185 * Generates the header HTML that is called in ISSO.Printer->page_start()
186 * to setup the navigation frame
187 *
188 * @access public
189 *
190 * @return string Generated HTML content
191 */
192 function generate_header_html()
193 {
194 $output = '<!-- navigation start -->' . "\n\n";
195
196 // -------------------------------------------------------------------
197
198 $output2 = array();
199 foreach ($this->toplinks AS $href => $text)
200 {
201 $output2[] = '<a href="' . $href . '">' . $text . '</a>';
202 }
203
204 $output .= "\n" . '<div id="toplinks">';
205 $output .= "\n\t" . '<div>' . $this->registry->get('application') . ' ' . $this->registry->modules['printer']->get('realm') . '</div>';
206 $output .= "\n\t" . '<div id="toplinks-links">' . implode(' &bull; ', $output2) . '</div>';
207 $output .= "\n" . '</div>';
208
209 // -------------------------------------------------------------------
210
211 $output .= "\n\n" . '<div id="wrapper">';
212
213 // -------------------------------------------------------------------
214
215 $output .= "\n" . '<div id="tabbar">';
216 foreach ($this->tabs AS $key => $content)
217 {
218 $link = "\n\t" . '<a href="' . $content[1] . '"';
219 if ($this->focus['tab'] == $key)
220 {
221 $link .= ' id="focustab"';
222 }
223
224 $link .= '><span>' . $content[0] . '</span></a>';
225
226 $output .= $link;
227 }
228 $output .= "\n" . '</div>';
229
230 // -------------------------------------------------------------------
231
232 $output .= "\n\n" . '<table id="contentbody" cellspacing="0" cellpadding="0" border="0">';
233 $output .= "\n" . '<tr>';
234
235 // -------------------------------------------------------------------
236
237 $output .= "\n" . '<td id="menu">';
238 foreach ((array)$this->sections[ $this->focus['tab'] ] AS $key => $text)
239 {
240 $output .= "\n" . '<ul>';
241 $output .= "\n\t" . '<li class="header"><span>' . $text . '</span></li>';
242 foreach ((array)$this->links["$key"] AS $key2 => $content)
243 {
244 $output .= "\n\t" . '<li' . ($this->focus['link'] == $key2 ? ' class="focus"' : '') . '><a href="' . $content[1] . '"><span>' . $content[0] . '</span></a></li>';
245 }
246 $output .= "\n" . '</ul>' . "\n";
247 }
248 $output .= "\n" . '</td>';
249
250 // -------------------------------------------------------------------
251
252 $output .= "\n" . '<td id="mainbody">';
253 $output .= "\n\n" . '<!-- main content body -->' . "\n";
254
255 return $output;
256 }
257
258 // ###################################################################
259 /**
260 * Generates the HTML that is inserted in ISSO.Printer->page_end() that
261 * closes all of the navigation HTML stuff
262 *
263 * @access public
264 *
265 * @return string Generated HTML content
266 */
267 function generate_footer_html()
268 {
269 $output = '';
270
271 $output .= "\n" . '<!-- / main content body -->' . "\n";
272
273 $output .= "\n" . '</td>';
274 $output .= "\n" . '</tr>';
275
276 $output .= "\n\n" . '</table>';
277
278 $output .= "\n\n" . '</div>';
279
280 return $output;
281 }
282 }
283
284 /*=====================================================================*\
285 || ###################################################################
286 || # $HeadURL$
287 || # $Id$
288 || ###################################################################
289 \*=====================================================================*/
290 ?>