]> src.bluestatic.org Git - isso.git/blob - PrinterNavigation.php
Cleaing up error reporting and error triggering in Api.php
[isso.git] / PrinterNavigation.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Blue Static ISSO Framework
5 || # Copyright (c)2002-2007 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 2 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 (PrinterNavigation.php)
24 *
25 * @package ISSO
26 */
27
28 /**
29 * Printer: Navigation Generator
30 *
31 * This framework works in conjunction with BSPrinter to generate a page header
32 * and sidebar to be used for navigation. You set the navigation array and then can
33 * specify a given key to highlight elements. Elements are broken into three types:
34 * tabs (top of the page), groups (blocks of link actions), and links
35 *
36 * @author Blue Static
37 * @copyright Copyright (c)2002 - 2007, Blue Static
38 * @package ISSO
39 *
40 */
41 class BSPrinterNavigation
42 {
43 /**
44 * Global links that are used for admin home, logout, etc.
45 * @var array
46 */
47 private $toplinks = array();
48
49 /**
50 * Navigational tabs: array(text, url)
51 * @var array
52 */
53 private $tabs = array();
54
55 /**
56 * Sections: text
57 * @var array
58 */
59 private $sections = array();
60
61 /**
62 * Links: array(text, url)
63 * @var array
64 */
65 private $links = array();
66
67 /**
68 * Array of scopes to set focus to key
69 * @var array
70 */
71 private $focus = array('tab' => null, 'link' => null);
72
73 // ###################################################################
74 /**
75 * Adds a global link to the array; these cannot be removed once added
76 *
77 * @param string Link text
78 * @param string HREF of the URL
79 */
80 public function addTopLink($text, $href)
81 {
82 $this->toplinks["$href"] = $text;
83 }
84
85 // ###################################################################
86 /**
87 * Adds to the structure array. The following is the global structure
88 * of the array, but you can specify any entry point. When you add onto
89 * the structure, it will go at the bottom
90 * array(
91 * '<tab>unique_key' => array(
92 * '<section>unique_key' => array(
93 * '<link>unique_key' => array('text', 'url')
94 * )
95 * )
96 * )
97 *
98 * Note that the portion in brackets is called the "scope"
99 *
100 * @param string Scope to add to
101 * @param string Unique key for the scope
102 * @param string Parent key to add to
103 * @param string Text to display (usually localized)
104 * @param string URL to go to when text is clicked
105 */
106 public function addComponent($scope, $key, $parent, $text, $url)
107 {
108 if ($scope == 'tab')
109 {
110 $this->tabs["$key"] = array($text, $url);
111 }
112 else if ($scope == 'section')
113 {
114 $this->sections["$parent"]["$key"] = $text;
115 }
116 else if ($scope == 'link')
117 {
118 $this->links["$parent"]["$key"] = array($text, $url);
119 }
120 }
121
122 // ###################################################################
123 /**
124 * Sets the focus for either a tab or link
125 *
126 * @param string Scope operator
127 * @param string Unique key in scope
128 * @param string Parent operator (links only)
129 */
130 public function setFocus($scope, $key, $parent)
131 {
132 if ($scope == 'tab')
133 {
134 if (isset($this->tabs["$key"]))
135 {
136 $this->focus["$scope"] = $key;
137 }
138 else
139 {
140 trigger_error('Invalid key for scope');
141 }
142 }
143 else if ($scope == 'link')
144 {
145 if (isset($this->links["$parent"]["$key"]))
146 {
147 $this->focus["$scope"] = $key;
148 }
149 else
150 {
151 trigger_error('Invalid key for scope');
152 }
153 }
154 else
155 {
156 trigger_error('BSPrinterNavigation::setFocus() only allows setting of focus for tab and link scopes');
157 }
158 }
159
160 // ###################################################################
161 /**
162 * Generates the header HTML that is called in BSPrinterRootElementPage
163 * to setup the navigation frame
164 *
165 * @return string Generated HTML content
166 */
167 public function constructHeaderHtml()
168 {
169 $output = '<!-- navigation start -->' . "\n\n";
170
171 // -------------------------------------------------------------------
172
173 $output2 = array();
174 foreach ($this->toplinks AS $href => $text)
175 {
176 $output2[] = '<a href="' . $href . '">' . $text . '</a>';
177 }
178
179 $output .= "\n" . '<div id="toplinks">';
180 $output .= "\n\t" . '<div>' . BSApp::GetApplicaiton . ' ' . BSPrinter::GetRealm() . '</div>';
181 $output .= "\n\t" . '<div id="toplinks-links">' . implode(' &bull; ', $output2) . '</div>';
182 $output .= "\n" . '</div>';
183
184 // -------------------------------------------------------------------
185
186 $output .= "\n\n" . '<div id="wrapper">';
187
188 // -------------------------------------------------------------------
189
190 $output .= "\n" . '<div id="tabbar">';
191 foreach ($this->tabs AS $key => $content)
192 {
193 $link = "\n\t" . '<a href="' . $content[1] . '"';
194 if ($this->focus['tab'] == $key)
195 {
196 $link .= ' id="focustab"';
197 }
198
199 $link .= '><span>' . $content[0] . '</span></a>';
200
201 $output .= $link;
202 }
203 $output .= "\n" . '</div>';
204
205 // -------------------------------------------------------------------
206
207 $output .= "\n\n" . '<table id="contentbody" cellspacing="0" cellpadding="0" border="0">';
208 $output .= "\n" . '<tr>';
209
210 // -------------------------------------------------------------------
211
212 $output .= "\n" . '<td id="menu">';
213 foreach ((array)$this->sections[ $this->focus['tab'] ] AS $key => $text)
214 {
215 $output .= "\n" . '<ul>';
216 $output .= "\n\t" . '<li class="header"><span>' . $text . '</span></li>';
217 foreach ((array)$this->links["$key"] AS $key2 => $content)
218 {
219 $output .= "\n\t" . '<li' . ($this->focus['link'] == $key2 ? ' class="focus"' : '') . '><a href="' . $content[1] . '"><span>' . $content[0] . '</span></a></li>';
220 }
221 $output .= "\n" . '</ul>' . "\n";
222 }
223 $output .= "\n" . '</td>';
224
225 // -------------------------------------------------------------------
226
227 $output .= "\n" . '<td id="mainbody">';
228 $output .= "\n\n" . '<!-- main content body -->' . "\n";
229
230 return $output;
231 }
232
233 // ###################################################################
234 /**
235 * Generates the HTML that is inserted in BSPrinterRootElementPage that
236 * closes all of the navigation HTML stuff
237 *
238 * @return string Generated HTML content
239 */
240 public function constructFooterHtml()
241 {
242 $output = '';
243
244 $output .= "\n" . '<!-- / main content body -->' . "\n";
245
246 $output .= "\n" . '</td>';
247 $output .= "\n" . '</tr>';
248
249 $output .= "\n\n" . '</table>';
250
251 $output .= "\n\n" . '</div>';
252
253 return $output;
254 }
255 }
256
257 ?>