1 |
<?php |
2 |
/** |
3 |
* This contains the InfoTable widget |
4 |
* |
5 |
* $Id: NavTable.inc,v 1.15 2002/10/23 22:18:51 hemna Exp $ |
6 |
* |
7 |
* @author Walter A. Boring IV <waboring@buildabetterweb.com> |
8 |
* @package phpHtmlLib |
9 |
* |
10 |
*/ |
11 |
|
12 |
/** |
13 |
* must have the BaseWidget |
14 |
*/ |
15 |
require_once( $phphtmllib."/widgets/BaseWidget.inc"); |
16 |
|
17 |
/** |
18 |
* This builds a navigational table |
19 |
* widget that has a title, any # |
20 |
* of subtitles and then navigational |
21 |
* links. |
22 |
* @author Walter A. Boring IV <waboring@buildabetterweb.com> |
23 |
* @package phpHtmlLib |
24 |
*/ |
25 |
class NavTable extends BaseWidget { |
26 |
|
27 |
|
28 |
/** |
29 |
* The name of the css file for this class |
30 |
* |
31 |
* @access private |
32 |
* @var string |
33 |
*/ |
34 |
var $_css_file = "NavTable.php"; |
35 |
|
36 |
/** |
37 |
* Array to hold the css customizable |
38 |
* colors for themeing. |
39 |
* Each widget will have its own set of |
40 |
* customizable css colors with defaults. |
41 |
* the user can programatically modify the |
42 |
* colors by setting them in this array. |
43 |
* |
44 |
* @access private |
45 |
* @var array |
46 |
*/ |
47 |
var $_css_entities = array("title"=> "#666699", |
48 |
"titlefont" => "#FFFFFF", |
49 |
"subtitle" => "#9999CC", |
50 |
"subtitlefont" => "#0000CC"); |
51 |
|
52 |
|
53 |
/** |
54 |
* the constructor for this class. |
55 |
* @param string $title - the title for the widget. |
56 |
* @param string $subtitle - the subtitle if any. |
57 |
* @param mixed $width - the width of the widget. |
58 |
* can be a % or an int. |
59 |
*/ |
60 |
function NavTable( $title, $subtitle=NULL, $width="100%") { |
61 |
|
62 |
$this->set_title( $title ); |
63 |
$this->set_subtitle( $subtitle ); |
64 |
$this->set_width( $width ); |
65 |
} |
66 |
|
67 |
|
68 |
function set_subtitle( $subtitle ) { |
69 |
$this->subtitle = $subtitle; |
70 |
} |
71 |
|
72 |
//functions for adding/updating data |
73 |
|
74 |
/** |
75 |
* this function adds an entry to the navtable. |
76 |
* It automatically adds the link based on $url, |
77 |
* with $text as the viewable text. |
78 |
* |
79 |
* @param string - the url for the link |
80 |
* @param string - the link text |
81 |
* @param string - the link title text |
82 |
* @param string - the link target |
83 |
*/ |
84 |
function add($url, $text, $title=NULL, $target=NULL) { |
85 |
array_push($this->data, array("type"=>"url", |
86 |
"url"=>$url, |
87 |
"text"=>$text, |
88 |
"target"=>$target, |
89 |
"title"=>$title)); |
90 |
} |
91 |
|
92 |
/** |
93 |
* depricated version of add() |
94 |
* |
95 |
* @deprecated - use add() instead |
96 |
*/ |
97 |
function push($url, $text, $title=NULL, $target=NULL) { |
98 |
$this->add($url, $text, $title, $target); |
99 |
} |
100 |
|
101 |
/** |
102 |
* This lets you add a blank line |
103 |
* between 2 links |
104 |
* |
105 |
* @param int - the # of blank lines to insert |
106 |
*/ |
107 |
function add_blank( $num = 1 ) { |
108 |
for ($x=1; $x<=$num; $x++) |
109 |
array_push($this->data, array( "type"=>"blank" )); |
110 |
} |
111 |
|
112 |
/** |
113 |
* depricated version of add_blank() |
114 |
* |
115 |
* @deprecated - use add_blank() instead |
116 |
*/ |
117 |
function push_blank( $num=1 ) { |
118 |
$this->add_blank( $num ); |
119 |
} |
120 |
|
121 |
/** |
122 |
* this adds a text item in the nav |
123 |
* |
124 |
* @param string - the text to display |
125 |
*/ |
126 |
function add_text( $text ) { |
127 |
array_push($this->data, array( "type"=>"text", "text"=>$text )); |
128 |
} |
129 |
|
130 |
/** |
131 |
* depricated version of add_text() |
132 |
* |
133 |
* @deprecated - use add_text() instead |
134 |
*/ |
135 |
function push_text( $text ) { |
136 |
$this->add_text( $text ); |
137 |
} |
138 |
|
139 |
/** |
140 |
* This adds a new heading in the nav. |
141 |
* It will look just like the sub title area |
142 |
* |
143 |
* @param string - the text in the heading |
144 |
*/ |
145 |
function add_heading( $title ) { |
146 |
array_push($this->data, array( "type" => "heading", "title" => $title )); |
147 |
} |
148 |
|
149 |
/** |
150 |
* depricated version of add_heading() |
151 |
* |
152 |
* @deprecated - use add_heading() instead |
153 |
*/ |
154 |
function push_heading( $title ) { |
155 |
$this->add_headring( $title ); |
156 |
} |
157 |
|
158 |
|
159 |
//****************************************** |
160 |
//* rendering area |
161 |
//****************************************** |
162 |
|
163 |
|
164 |
/** |
165 |
* renders a title table for the widget. |
166 |
* @access private |
167 |
*/ |
168 |
function render_title_table() { |
169 |
$table = html_table($this->width,0 ,0 ,0); |
170 |
|
171 |
//ok lets render the title table. |
172 |
$img = html_img("/phphtmllib/widgets/images/spacer.gif", 10, 15); |
173 |
|
174 |
$td = html_td("barleft", "left", $img ); |
175 |
$td->set_collapse(); |
176 |
$td2 = html_td("title", "", $this->title); |
177 |
$td2->set_collapse(); |
178 |
$td3 = html_td("barright", "right", $img); |
179 |
$td3->set_collapse(); |
180 |
|
181 |
$table->add_row( $td, $td2, $td3 ); |
182 |
return $table; |
183 |
} |
184 |
|
185 |
/** |
186 |
* this function builds the subtitle td |
187 |
* to hold the...subtitle! |
188 |
* |
189 |
* @return TDtag object |
190 |
*/ |
191 |
function _build_subtitle() { |
192 |
$td = html_td("subtitle", "", $this->subtitle); |
193 |
$td->set_tag_attribute("colspan", 2); |
194 |
$td->set_collapse(); |
195 |
return $td; |
196 |
} |
197 |
|
198 |
/** |
199 |
* render a blank tr |
200 |
* @access private |
201 |
*/ |
202 |
function _render_blank_tr() { |
203 |
$tr = new TRtag; |
204 |
$space = " "; |
205 |
|
206 |
$td = new TDtag( array( "style" => "width:1%;", "class" => "navtablediv"), $space ); |
207 |
$td2 = new TDtag( array( "style" => "width:99%;", "class" => "navtablediv"), $space ); |
208 |
|
209 |
$tr->add( $td, $td2 ); |
210 |
$tr->set_collapse(); |
211 |
|
212 |
return $tr; |
213 |
} |
214 |
|
215 |
/** |
216 |
* render a url row. |
217 |
* @param array() - the item to render. |
218 |
*/ |
219 |
function _render_url( $val ) { |
220 |
$tr = new TRtag; |
221 |
$bullet = "• "; |
222 |
|
223 |
$tr->add( html_td("bullet", "", $bullet) ); |
224 |
|
225 |
$url_td = new TDtag( array("class" => "link") ); |
226 |
|
227 |
$attributes = array("href" => $val["url"]); |
228 |
if ($val["target"] != NULL) { |
229 |
$target = $val["target"]; |
230 |
} else { |
231 |
$target = ""; |
232 |
} |
233 |
$url = html_a( $val["url"], $val["text"], NULL, $target, $val["title"]); |
234 |
|
235 |
$url_td->add( $url ); |
236 |
$tr->add( $url_td ); |
237 |
$tr->set_collapse(); |
238 |
|
239 |
return $tr; |
240 |
} |
241 |
|
242 |
/** |
243 |
* render a text row. |
244 |
* @param array() - the item to render. |
245 |
*/ |
246 |
function _render_text( $val ) { |
247 |
$tr = new TRtag; |
248 |
$bullet = "• "; |
249 |
|
250 |
$td = html_td("bullet", "", $bullet); |
251 |
$text_td = html_td("link", "", $val["text"] ); |
252 |
|
253 |
$tr->add( $td, $text_td ); |
254 |
$tr->set_collapse(); |
255 |
|
256 |
return $tr; |
257 |
} |
258 |
|
259 |
|
260 |
/** |
261 |
* Render the Navtable and its content. |
262 |
* |
263 |
* @param int - the indentation level for |
264 |
* the container. |
265 |
* @param int - the output debug flag to |
266 |
* maintain compatibility w/ the API. |
267 |
* |
268 |
* @return string the raw html output. |
269 |
*/ |
270 |
function render( $indent_level=1, $output_debug=0 ) { |
271 |
|
272 |
$span = html_div(); |
273 |
$span->set_class("navtable"); |
274 |
|
275 |
$html = ""; |
276 |
|
277 |
//render the title area first. |
278 |
$title = $this->render_title_table(); |
279 |
$span->add( $title ); |
280 |
|
281 |
$table = html_table($this->width, 0, 0, 2); |
282 |
$table->set_class("content"); |
283 |
|
284 |
if ($this->subtitle) { |
285 |
$table->add_row( $this->_build_subtitle() ); |
286 |
} |
287 |
|
288 |
foreach ($this->data as $key=>$val) { |
289 |
switch ($val["type"]) { |
290 |
case "blank": |
291 |
$table->add_row( $this->_render_blank_tr() ); |
292 |
break; |
293 |
|
294 |
case "url": |
295 |
$table->add_row( $this->_render_url( $val ) ); |
296 |
break; |
297 |
|
298 |
case "text": |
299 |
$table->add_row( $this->_render_text( $val ) ); |
300 |
break; |
301 |
|
302 |
case "heading": |
303 |
//dunno if we can do this. |
304 |
break; |
305 |
} |
306 |
} |
307 |
|
308 |
$span->add( $table ); |
309 |
|
310 |
return $span->render( $indent_level, $output_debug); |
311 |
} |
312 |
} |
313 |
|
314 |
/** |
315 |
* This class defines the css used by the |
316 |
* FooterNav Object. |
317 |
* |
318 |
* @author Walter A. Boring IV <waboring@buildabetterweb.com> |
319 |
* @package phpHtmlLib |
320 |
*/ |
321 |
class NavTableCSS extends CSSBuilder { |
322 |
|
323 |
function user_setup() { |
324 |
$this->add_entry(".navtable", NULL, |
325 |
array("font-family" => "arial,verdana,helvetica") ); |
326 |
|
327 |
$this->add_entry(".navtable", ".title", |
328 |
array("font-size" => "10pt", |
329 |
"font-weight" => "bold", |
330 |
"text-align" => "center", |
331 |
"color" => "#FFFFFF", |
332 |
"background-color" => "#999999", |
333 |
"width" => "98%") ); |
334 |
|
335 |
$this->add_entry(".navtable", ".barleft", |
336 |
array("background-image" => "url('/phphtmllib/widgets/images/top-left-corner.gif')", |
337 |
"background-repeat" => "no-repeat", |
338 |
"background-color" => "#999999", |
339 |
"width" => "1%")); |
340 |
|
341 |
$this->add_entry(".navtable", ".barright", |
342 |
array("background-image" => "url('/phphtmllib/widgets/images/top-right-corner.gif')", |
343 |
"background-repeat" => "no-repeat", |
344 |
"background-color" => "#999999", |
345 |
"width" => "1%")); |
346 |
|
347 |
$this->add_entry(".navtable", ".content", |
348 |
array("border" => "1px solid #777777;", |
349 |
"background-color" => "#FFFFFF") ); |
350 |
|
351 |
$this->add_entry(".navtable", ".subtitle", |
352 |
array("font-size" => "8pt", |
353 |
"font-weight" => "bold", |
354 |
"text-align" => "center", |
355 |
"color" => "#777777", |
356 |
"background-color" => "#eeeeee") ); |
357 |
|
358 |
$this->add_entry(".navtable", ".bullet", |
359 |
array("width" => "1%", |
360 |
"font-size" => "10pt", |
361 |
"padding-left" => "5px")); |
362 |
|
363 |
$this->add_entry(".navtable", ".link", |
364 |
array("width" => "99%", |
365 |
"font-size" => "10pt", |
366 |
"line-height" => "11pt")); |
367 |
|
368 |
$this->add_entry(".navtable", "a:active,a:link,a:visited", |
369 |
array("font-weight" => "bold", |
370 |
"color" => "#505dd8") ); |
371 |
$this->add_entry(".navtable", "a:hover", |
372 |
array("color" => "#505dd8", |
373 |
"background-color" => "#eeeeee", |
374 |
"text-decoration" => "none") ); |
375 |
} |
376 |
} |
377 |
|
378 |
?> |