/[cvs]/nfo/php/libs/com.newsblob.phphtmllib/widgets/TabWidget.inc
ViewVC logotype

Contents of /nfo/php/libs/com.newsblob.phphtmllib/widgets/TabWidget.inc

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (show annotations)
Thu May 6 16:57:34 2004 UTC (20 years, 2 months ago) by jonen
Branch: MAIN
CVS Tags: HEAD
 updated all to v2.4.1 - Apr 01, 2004

1 <?php
2 /**
3 * Holds the TabWidget and Tablist
4 *
5 * $Id: TabWidget.inc,v 1.6 2004/02/03 23:46:23 hemna Exp $
6 *
7 * @author Walter A. Boring IV <waboring@buildabetterweb.com>
8 * @package phpHtmlLib
9 *
10 * @copyright LGPL - See LICENCE
11 *
12 */
13
14 /**
15 * Some defines
16 */
17 define("TABLIST_SELECTED", "tab_selected");
18 define("TABLIST_SUB_SELECTED", "subtab_selected");
19
20
21 /**
22 * This class implements the Qualys Tab object.
23 *
24 * @author Walter A. Boring IV
25 * @package phpHtmlLib
26 */
27 class TabWidget extends BaseWidget {
28
29 /**
30 * Is this tab selected or not?
31 */
32 var $_selected = false;
33
34 /**
35 * The tab number in the list of tabs.
36 */
37 var $_number = 0;
38
39 /**
40 * The constructor
41 *
42 * {@source }
43 *
44 * @param string the title for the Tab
45 */
46 function TabWidget($title) {
47 $this->set_title($title);
48 }
49
50
51 /**
52 * This is the function where you
53 * can build the content for the Tab itself.
54 *
55 * The alternative is to use the add() method.
56 *
57 * {@source }
58 * @return Container object
59 */
60 function content() {
61 return null;
62 }
63
64 /**
65 * This method creates the name of the tab
66 *
67 * @param string - the tab display string
68 * @return string - the tab name
69 */
70 function name($title) {
71 $name = strtolower($title);
72 $len = strlen($name);
73
74 for ($i=0; $i<$len;$i++) {
75 if ((ord($name[$i])<97 || ord($name[$i])>122) &&
76 (ord($name[$i])<48 || ord($name[$i])>57))
77 $name[$i] = "_";
78 }
79 return $name;
80 }
81
82
83 /**
84 * This method builds the query string
85 * 'tab_selected=<name>' for you
86 * to place in a url
87 *
88 * @param string - the tab title
89 * @param boolean - is this a subtab?
90 * @return string - the query var assigned to tab name
91 */
92 function queryvar($title, $subtab_flag=false) {
93 if ($subtab_flag) {
94 $prefix = TABLIST_SUB_SELECTED."=";
95 } else {
96 $prefix = TABLIST_SELECTED."=";
97 }
98 return $prefix.TabWidget::name($title);
99 }
100 }
101
102
103 /**
104 * This class implements a set of multiple tabs holding
105 * data objects
106 *
107 *
108 * @author Suren Markossian
109 * @author Walter A. Boring IV
110 */
111 class TabList extends BaseWidget {
112
113 /**
114 * The number of tabs
115 */
116 var $_tab_num=0;
117
118 /**
119 * The selected tab
120 * from the list
121 */
122 var $_tab_elected=null;
123
124 /**
125 * array of tabs that have been added
126 */
127 var $_tabs = array();
128
129 /**
130 * the TR object for the tabs
131 */
132 var $_tab_row = null;
133
134 /**
135 * This holds a list of
136 * name=>value vars that the
137 * caller/child wants to propogate
138 * automatically.
139 *
140 */
141 var $_save_vars = array();
142
143 /**
144 * Flag to let us know we are a subtab
145 * list or not
146 */
147 var $_subtab_flag = false;
148
149
150 /**
151 * The outer wrapper for the ui.
152 * So we can build top level and
153 * sublevels
154 */
155 var $_ui_wrapper = null;
156
157 /**
158 * valid selected tab?
159 */
160 var $_valid_tab = false;
161
162
163 /**
164 * The constructor.
165 *
166 * @param the title of the tablist.
167 */
168 function TabList($title) {
169 $this->title = $title;
170 }
171
172 /**
173 * The render method
174 *
175 * @param int the html indentation level
176 * @param int the html debug level
177 * @return string the output html
178 */
179 function render( $indent_level=0, $output_debug=0 ) {
180 if ($this->_subtab_flag) {
181 //we need to build a subtab list
182 $this->_build_subtab_ui();
183 } else {
184 //ok build the outer UI for the top tabs
185 $this->_build_top_tab_ui();
186 }
187
188 return $this->_ui_wrapper->render($indent_level, $output_debug=0);
189
190 }
191
192 /**
193 * This public method adds a new tab to the table
194 * @param title string - tab title
195 * @param data object - data container for this tab
196 */
197 function add(&$tab_obj) {
198
199 if (is_subclass_of($tab_obj, "tabwidget")) {
200 //render a normal tab with its content.
201 $this->_tabs[] =& $tab_obj;
202 } else if (is_subclass_of($tab_obj, "tablist") ||
203 get_class($tab_obj) == 'tablist') {
204 $tab_obj->_set_subtab_flag(TRUE);
205 $this->_tabs[] =& $tab_obj;
206 } else {
207 trigger_error(__CLASS__."::".__FUNCTION__."() - called with an invalid object (".
208 get_parent_class($tab_obj).
209 "). must be either a TabWidget or a TabList(subtab).",
210 E_USER_ERROR);
211 }
212 }
213
214
215 /**
216 * Return the title
217 */
218 function get_title() {
219 return $this->title;
220 }
221
222 /**
223 * This function sets the save variables
224 * that the user/child wants to automatically
225 * propogate
226 *
227 * @param array - name=>value pairs of the data
228 * that they want to propogate
229 */
230 function set_save_vars( $vars ) {
231 $this->_save_vars = $vars;
232 }
233
234 /**
235 * this function builds a partial
236 * query string with the
237 * $this->_save_vars
238 *
239 * @return string
240 */
241 function _build_save_vars() {
242 $query_string = "";
243 foreach( $this->_save_vars as $name => $value ) {
244 $query_string .= $name."=".$value."&";
245 }
246 return $query_string;
247 }
248
249
250 /**
251 * this private function builds the url
252 * for the main tab script and adss the
253 * needed query string params
254 *
255 * @param string - the tab name
256 * @param string - the subtab name
257 *
258 * @return string url
259 */
260 function _build_url($tab_name, $subtab_name=null) {
261 $url = $_SERVER["SCRIPT_NAME"]."?".TABLIST_SELECTED."=".$tab_name."&";
262 if ($subtab_name !== null) {
263 $url .= TABLIST_SUB_SELECTED."=".$subtab_name."&";
264 }
265 $url .= $this->_build_save_vars();
266 return $url;
267 }
268
269 /**
270 * This method is used to set the
271 * subtab bit
272 *
273 * @param boolean
274 */
275 function _set_subtab_flag($flag) {
276 $this->_subtab_flag = $flag;
277 }
278
279 /**
280 * This method creates the name of the tab
281 *
282 * @param string - the tab display string
283 * @return string - the tab name
284 */
285 function name($title) {
286 return TabWidget::name($title);
287 }
288
289
290 /**
291 * This method builds the query string
292 * 'tab_selected=<name>' for you
293 * to place in a url
294 *
295 * @param string - the tab title
296 * @return string - the query var assigned to tab name
297 */
298 function queryvar($title) {
299 return TabWidget::queryvar($title);
300 }
301
302
303 /**
304 * This method builds the outer wrapper UI
305 * for the top level tab list.
306 *
307 * @return none
308 */
309 function _build_top_tab_ui() {
310 // initialize selected tab number
311 if (isset($_REQUEST[TABLIST_SELECTED]))
312 $this->_tab_selected = $_REQUEST[TABLIST_SELECTED];
313
314 $this->_tab_row = new TRtag();
315
316 $this->_ui_wrapper = html_table();
317 $this->_ui_wrapper->set_class('tablist');
318
319 $this->tab_num = count( $this->_tabs );
320 // create data row and add data to it
321 $tr = new TRtag();
322 $colspan = 2*$this->tab_num+1;
323 $data_td = new TDtag(array("class"=>"tab_data","colspan"=>$colspan));
324
325 foreach( $this->_tabs as $tab_obj ) {
326 $title = $tab_obj->get_title();
327 $tab_name = $this->name($title);
328 $this->_build_tab($title, $tab_name);
329
330 // separator between two tabs
331 $this->_add_tab_spacer();
332
333 if ($tab_name==$this->_tab_selected) {
334 if (is_subclass_of($tab_obj, "tablist") ||
335 get_class($tab_obj) == 'tablist') {
336 $this->_valid_tab = TRUE;
337 $data_td->add_reference( $tab_obj );
338 } else {
339 $this->_valid_tab = TRUE;
340 $data_td->add_reference( $tab_obj->content() );
341 }
342 }
343 }
344
345 if (!$this->_valid_tab) {
346 //someone hacked the selected tab
347 $data_td->add( $this->_invalid_tab() );
348 }
349
350 $this->_add_tab_spacer(TRUE);
351 $this->_ui_wrapper->add_row($this->_tab_row);
352 $tr->add($data_td);
353 $this->_ui_wrapper->add_row($tr);
354 }
355
356
357 /**
358 * This method builds the outer wrapper UI
359 * for the subtab
360 *
361 * @return none
362 */
363 function _build_subtab_ui() {
364
365 // initialize selected tab number
366 if (isset($_REQUEST[TABLIST_SUB_SELECTED]))
367 $this->_tab_selected = $_REQUEST[TABLIST_SUB_SELECTED];
368
369 $this->_ui_wrapper = html_table("100%");
370
371 $this->_tab_row = new TRtag();
372
373 $tr = new TRtag();
374
375 $tab_name = $this->name($this->get_title());
376 $data_td = new TDtag(array("class"=>"subtab_data"));
377
378 foreach( $this->_tabs as $tab_obj ) {
379 $title = $tab_obj->get_title();
380 $subtab_name = $this->name($title);
381 $this->_build_subtab($title, $tab_name, $subtab_name);
382
383 if ($subtab_name==$this->_tab_selected) {
384 if (is_subclass_of($tab_obj, "tablist") ||
385 get_class($tab_obj) == 'tablist') {
386 $this->_valid_tab = TRUE;
387 $data_td->add_reference( $tab_obj );
388 } else {
389 $this->_valid_tab = TRUE;
390 $data_td->add_reference( $tab_obj->content() );
391 }
392 }
393 }
394
395 if (!$this->_valid_tab) {
396 //someone hacked the selected tab
397 $data_td->add( $this->_invalid_tab() );
398 }
399
400 //add last spacer to cram everything left.
401 $this->_tab_row->add( new TDtag(array("width" => "95%",
402 "class" => "subtab"), _HTML_SPACE));
403 $this->_ui_wrapper->add_row($this->_tab_row);
404 $tr->add($data_td);
405 $this->_ui_wrapper->add_row($tr);
406 }
407
408
409 /**
410 * This method is used to build a top level
411 * tab
412 *
413 * @param string - the tab title
414 *
415 */
416 function _build_tab($title, $tab_name) {
417
418 if ($this->_tab_selected == null ||
419 empty($this->_tab_selected)) {
420 $this->_tab_selected = $tab_name;
421 }
422
423 if ($tab_name==$this->_tab_selected) {
424 $class = "tab_selected";
425 $link_class = "tab_link_selected";
426 } else {
427 $class = "tab_default";
428 $link_class = "tab_link_default";
429 }
430
431
432 // create link for this tab pointing to the same page with the tab number
433 $url = $this->_build_url($tab_name);
434
435 // the actual tab
436 $onclick = "window.location='" . $url."';return false;";
437 $td = new TDtag(array(
438 "class"=>$class,
439 "valign" => "top",
440 "width"=>"10%",
441 "nowrap",
442 "onclick"=> $onclick));
443
444 $td->push(html_a($url, $title, $link_class));
445 $td->set_collapse();
446 $this->_tab_row->add($td);
447 }
448
449 /**
450 * This method builds a single subtab
451 *
452 * @param string the title
453 * @param string the tab name
454 */
455 function _build_subtab($title, $tab_name, $subtab_name) {
456
457 if ($this->_tab_selected == null ||
458 empty($this->_tab_selected)) {
459 $this->_tab_selected = $subtab_name;
460 }
461
462 if ($subtab_name==$this->_tab_selected) {
463 $class = "subtab";
464 $link_class = "subtab_link_selected";
465 } else {
466 $class = "subtab";
467 $link_class = "subtab_link_default";
468 }
469
470 $url = $this->_build_url($tab_name, $subtab_name);
471
472 $td = html_td($class);
473
474 $td->set_collapse();
475 $td->add( html_a($url, $title, $link_class));
476
477 $this->_tab_row->add( $td );
478 }
479
480
481 /**
482 * This method adds a new spacer in between
483 * the tabs.
484 *
485 * @param boolean - is this the last spacer?
486 */
487 function _add_tab_spacer($last_spacer=false) {
488
489 $attributes = array();
490
491 if ($last_spacer) {
492 $width = 100 - ($this->tab_num*10) . "%";
493
494 $attributes["class"] = "tab_spacer_last";
495 $attributes["align"] = "center";
496 $attributes["width"] = $width;
497
498 } else {
499 $attributes["class"] = "tab_spacer";
500 $attributes["align"] = "left";
501 }
502
503
504 $td = new TDtag($attributes);
505 $td->add(_HTML_SPACE);
506 $td->set_collapse();
507 $this->_tab_row->add($td);
508 }
509
510 /**
511 * This method builds a message for an invalid
512 * selected tab/subtab
513 *
514 * @return Container
515 */
516 function _invalid_tab() {
517 return "Invalid Selected Tab";
518 }
519 }
520
521
522 /**
523 * This class defines the css used by the
524 * FooterNav Object.
525 *
526 * @author Walter A. Boring IV <waboring@buildabetterweb.com>
527 * @package phpHtmlLib
528 */
529 class TabListCSS extends CSSBuilder {
530
531 function user_setup() {
532 $this->add_entry(".tablist", "",
533 array(
534 "margin" => "0px",
535 "padding" => "0px",
536 "font-famiy" => "sans-serif",
537 "font-size" => "12px",
538 ) );
539
540 $this->add_entry(".tablist", ".tab_selected",
541 array(
542 "font-weight" => "bold",
543 "padding" => "2px 4px 2px 4px",
544 "color" => "#FFFFFF",
545 "background-color" => "#999999",
546 "border-right" => "1px solid #828282",
547 "border-top" => "1px solid #828282"
548 ) );
549
550 $this->add_entry(".tablist", ".tab_default",
551 array(
552 "padding" => "2px 4px 2px 4px",
553 "color" => "#FFFFFF",
554 "background-color" => "#e1e1e1",
555 "border-left" => "1px solid #828282",
556 "border-right" => "1px solid #828282",
557 "border-top" => "1px solid #828282",
558 "border-bottom" => "1px solid #828282"
559 ));
560
561 $this->add_entry(".tablist", ".tab_spacer",
562 array(
563 "margin" => "0px",
564 "padding" => "0px",
565 "background-color" => "#ffffff",
566 "border-bottom" => "1px solid #828282",
567 ));
568
569 $this->add_entry(".tablist", ".tab_spacer_last",
570 array(
571 "margin" => "0px",
572 "padding" => "0px",
573 "background-color" => "#ffffff",
574 "border-bottom" => "1px solid #828282"
575 ));
576
577
578 $this->add_entry(".tablist", ".tab_data",
579 array(
580 "margin" => "0px",
581 "background-color" => "#ffffff",
582 "border-left" => "1px solid #828282",
583 "border-right" => "1px solid #828282",
584 "border-bottom" => "1px solid #828282"
585 ));
586
587
588 $this->add_entry(".tablist", ".subtab",
589 array(
590 "margin" => "0px",
591 "padding" => "2px 10px 2px 2px",
592 "background-color" => "#999999",
593 "white-space" => "nowrap"
594 ));
595
596
597 /**
598 * The href links
599 */
600 $this->add_entry(".tablist", ".tab_link_selected",
601 array(
602 "text-decoration" => "none",
603 "color" => "#ffffff",
604 "font-weight" => "bold"
605 ));
606
607 $this->add_entry(".tablist", ".tab_link_selected:hover",
608 array(
609 "text-decoration" => "none",
610 "color" => "#efefef",
611 "font-weight" => "bold"
612 ));
613
614 $this->add_entry(".tablist", ".tab_link_default",
615 array(
616 "text-decoration" => "none",
617 "color" => "#828282",
618 ));
619 $this->add_entry(".tablist", ".tab_link_default:hover",
620 array(
621 "text-decoration" => "none",
622 "color" => "#ffffff",
623 ));
624
625
626 $this->add_entry(".tablist", ".subtab_link_selected",
627 array(
628 "text-decoration" => "none",
629 "color" => "#ffffff",
630 "font-weight" => "bold"
631 ));
632
633 $this->add_entry(".tablist", ".subtab_link_selected:hover",
634 array(
635 "text-decoration" => "none",
636 "color" => "#efefef",
637 "font-weight" => "bold"
638 ));
639
640 $this->add_entry(".tablist", ".subtab_link_default",
641 array(
642 "text-decoration" => "underline",
643 "color" => "#e1e1e1",
644 ));
645 $this->add_entry(".tablist", ".subtab_link_default:hover",
646 array(
647 "text-decoration" => "none",
648 "color" => "#ffffff",
649 ));
650
651 }
652 }
653
654 ?>

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed