CSS cleanup for the navigation links
[isso.git] / printer_navigation.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Iris Studios Shared Object Framework [#]issoversion[#]
5 || # Copyright ©2002-[#]year[#] Iris Studios, Inc.
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 Iris Studios, Inc.
38 * @copyright Copyright ©2002 - [#]year[#], Iris Studios, Inc.
39 * @version $Revision$
40 * @package ISSO
41 *
42 */
43 class Printer_Navigation
44 {
45 /**
46 * Framework registry object
47 * @var object
48 * @access private
49 */
50 var $registry = null;
51
52 /**
53 * Global links that are used for admin home, logout, etc.
54 * @var array
55 * @access private
56 */
57 var $toplinks = array();
58
59 /**
60 * Navigational tabs: array(text, url)
61 * @var array
62 * @access private
63 */
64 var $tabs = array();
65
66 /**
67 * Sections: text
68 * @var array
69 * @access private
70 */
71 var $sections = array();
72
73 /**
74 * Links: array(text, url)
75 * @var array
76 * @access private
77 */
78 var $links = array();
79
80 /**
81 * Array of scopes to set focus to key
82 * @var array
83 * @access private
84 */
85 var $focus = array('tab' => null, 'link' => null);
86
87 // ###################################################################
88 /**
89 * Constructor
90 */
91 function __construct(&$registry)
92 {
93 $this->registry =& $registry;
94 }
95
96 // ###################################################################
97 /**
98 * (PHP 4) Constructor
99 */
100 function Printer_Navigation(&$registry)
101 {
102 $this->__construct($registry);
103 }
104
105 // ###################################################################
106 /**
107 * Adds a global link to the array; these cannot be removed once added
108 *
109 * @access public
110 *
111 * @param string Link text
112 * @param string HREF of the URL
113 */
114 function add_top_link($text, $href)
115 {
116 $this->toplinks["$href"] = $text;
117 }
118
119 // ###################################################################
120 /**
121 * Adds to the structure array. The following is the global structure
122 * of the array, but you can specify any entry point. When you add onto
123 * the structure, it will go at the bottom
124 * array(
125 * '<tab>unique_key' => array(
126 * '<section>unique_key' => array(
127 * '<link>unique_key' => array('text', 'url')
128 * )
129 * )
130 * )
131 *
132 * Note that the portion in brackets is called the "scope"
133 *
134 * @access public
135 *
136 * @param string Scope to add to
137 * @param string Unique key for the scope
138 * @param string Parent key to add to
139 * @param string Text to display (usually localized)
140 * @param string URL to go to when text is clicked
141 */
142 function add_component($scope, $key, $parent, $text, $url)
143 {
144 if ($scope == 'tab')
145 {
146 $this->tabs["$key"] = array($text, $url);
147 }
148 else if ($scope == 'section')
149 {
150 $this->sections["$parent"]["$key"] = $text;
151 }
152 else if ($scope == 'link')
153 {
154 $this->links["$parent"]["$key"] = array($text, $url);
155 }
156 }
157
158 // ###################################################################
159 /**
160 * Sets the focus for either a tab or link
161 *
162 * @access public
163 *
164 * @param string Scope operator
165 * @param string Unique key in scope
166 */
167 function set_focus($scope, $key)
168 {
169 if ($scope == 'tab')
170 {
171 $array = 'tabs';
172 }
173 else if ($scope == 'link')
174 {
175 $array = 'links';
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 if (isset($this->{$array}["$key"]))
183 {
184 $this->focus["$scope"] = $key;
185 }
186 }
187
188 // ###################################################################
189 /**
190 * Generates the header HTML that is called in ISSO.Printer->page_start()
191 * to setup the navigation frame
192 *
193 * @access public
194 *
195 * @return string Generated HTML content
196 */
197 function generate_header_html()
198 {
199 $output = '<!-- navigation start -->' . "\n\n";
200
201 // -------------------------------------------------------------------
202
203 $output2 = array();
204 foreach ($this->toplinks AS $href => $text)
205 {
206 $output2[] = '<a href="' . $href . '" class="nav_toplink">' . $text . '</a>';
207 }
208
209 $output .= "\n" . '<div id="toplinks">';
210 $output .= "\n\t" . '<div>' . $this->registry->get('application') . ' ' . $this->registry->modules['printer']->get('realm') . '</div>';
211 $output .= "\n\t" . '<div id="toplinks-links">' . implode(' &bull; ', $output2) . '</div>';
212 $output .= "\n" . '</div>';
213
214 // -------------------------------------------------------------------
215
216 $output .= '<div id="wrapper">';
217
218 // -------------------------------------------------------------------
219
220 $output .= '<div id="tabbar">';
221 foreach ($this->tabs AS $key => $content)
222 {
223 $link = "\n\t" . '<a href="' . $content[1] . '" class="tab';
224 if ($this->focus['tab'] == $key)
225 {
226 $link .= ' focus';
227 }
228
229 $link .= '">' . $content[0] . '</a>';
230
231 $output .= $link;
232 }
233 $output .= "\n" . '</div>';
234
235 // -------------------------------------------------------------------
236
237 $output .= "\n" . '<table id="contentbody" cellspacing="0" cellpadding="0" border="0">';
238 $output .= "\n" . '<tr>';
239
240 $output .= '<td id="menu"><ul>';
241 foreach ((array)$this->sections[ $this->focus['tab'] ] AS $key => $text)
242 {
243 $output .= '<li><strong>' . $text . '</strong><ul>';
244 foreach ((array)$this->links["$key"] AS $key2 => $content)
245 {
246 $link = '<li><a href="' . $content[1] . '" class="link">' . $content[0] . '</a></li>';
247 if ($this->focus['link'] == $key)
248 {
249 $output .= "<em>$link</em>";
250 }
251 else
252 {
253 $output .= $link;
254 }
255 }
256 $output .= '</ul>';
257 }
258 $output .= '</ul></td>';
259
260 $output .= "\n" . '<td id="mainbody">';
261
262 return $output;
263 }
264
265 // ###################################################################
266 /**
267 * Generates the HTML that is inserted in ISSO.Printer->page_end() that
268 * closes all of the navigation HTML stuff
269 *
270 * @access public
271 *
272 * @return string Generated HTML content
273 */
274 function generate_footer_html()
275 {
276 $output = '';
277
278 $output .= "\n" . '</td>';
279 $output .= "\n" . '</tr>';
280
281 $output .= "\n\n" . '</table>';
282
283 $output .= "\n\n" . '</div>';
284
285 return $output;
286 }
287 }
288
289 /*=====================================================================*\
290 || ###################################################################
291 || # $HeadURL$
292 || # $Id$
293 || ###################################################################
294 \*=====================================================================*/
295 ?>