Use a <table> to get the two-columns becase CSS makes IE unhappy
[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 .= implode(' &bull; ', $output2);
210
211 // -------------------------------------------------------------------
212
213 $output .= '<div id="tabbar">';
214 foreach ($this->tabs AS $key => $content)
215 {
216 $link = "\n\t" . '<a href="' . $content[1] . '" class="tab';
217 if ($this->focus['tab'] == $key)
218 {
219 $link .= ' focus';
220 }
221
222 $link .= '">' . $content[0] . '</a>';
223
224 $output .= $link;
225 }
226 $output .= "\n" . '</div>';
227
228 // -------------------------------------------------------------------
229
230 $output .= "\n" . '<table id="contentbody" cellspacing="0" cellpadding="0" border="0">';
231 $output .= "\n" . '<tr>';
232
233 $output .= '<td id="menu"><ul>';
234 foreach ((array)$this->sections[ $this->focus['tab'] ] AS $key => $text)
235 {
236 $output .= '<li><strong>' . $text . '</strong><ul>';
237 foreach ((array)$this->links["$key"] AS $key2 => $content)
238 {
239 $link = '<li><a href="' . $content[1] . '" class="link">' . $content[0] . '</a></li>';
240 if ($this->focus['link'] == $key)
241 {
242 $output .= "<em>$link</em>";
243 }
244 else
245 {
246 $output .= $link;
247 }
248 }
249 $output .= '</ul>';
250 }
251 $output .= '</ul></td>';
252
253 $output .= "\n" . '<td id="mainbody">';
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" . '</td>';
272 $output .= "\n" . '</tr>';
273
274 $output .= "\n\n" . '</table>';
275
276 return $output;
277 }
278 }
279
280 /*=====================================================================*\
281 || ###################################################################
282 || # $HeadURL$
283 || # $Id$
284 || ###################################################################
285 \*=====================================================================*/
286 ?>