histogram: Make histograms crash less
[ninja.git] / application / controllers / toolbar.php
bloba2bf0a720ab5193f37a7bfd31d9781d0feb1486c
1 <?php
3 /**
4 * Ninja Toolbar Management
7 */
9 class Toolbar_Controller {
11 public $title = false;
12 public $subtitle = false;
13 public function __construct ( $title = false, $subtitle = false ) {
15 $this->title = ( gettype( $title ) == "string" ) ? $title: false;
16 $this->subtitle = ( gettype( $subtitle ) == "string" ) ? $subtitle: false;
20 private $should_render_buttons = false;
21 public function should_render_buttons($should_render_buttons = true) {
22 $this->should_render_buttons = $should_render_buttons;
25 private $buttons = array();
26 public function button ( $title, $attr = false ) {
27 $this->should_render_buttons(true);
28 if ( !$attr ) $attr = array();
30 $this->buttons[ ] = array(
31 "name" => $title,
32 "attr" => $attr
37 private $tabs = array();
38 public function tab ( $title, $attr = false ) {
40 if ( !$attr ) $attr = array();
42 $this->tabs[ ] = array(
43 "name" => $title,
44 "attr" => $attr
49 private $info = array();
50 public function info ( $html ) {
52 if ( gettype( $html ) == "string" ) {
53 $this->info[ ] = $html;
54 return true;
57 return false;
61 private function get_button_html () {
63 $h = "";
65 foreach ( $this->buttons as $b ) {
66 $a = array();
67 foreach ( $b[ "attr" ] as $k => $v )
68 $a[] = "$k=\"$v\"";
69 $h .= "<a " . implode( " ", $a ) . ">" . $b[ "name" ] . "</a>";
72 return $h;
76 public function render () {
78 print '<div class="main-toolbar">';
80 if ( gettype( $this->title ) == "string" ) {
81 print '<div class="main-toolbar-title">' . $this->title . '</div>';
84 if ( gettype( $this->subtitle ) == "string" ) {
85 print '<div class="main-toolbar-subtitle">' . $this->subtitle . '</div>';
86 } else {
87 print '<div class="main-toolbar-subtitle"></div>';
90 if ( count( $this->info ) > 0 ) {
91 print '<div class="main-toolbar-info">';
92 foreach ( $this->info as $html ) print $html;
93 print '</div>';
96 if ($this->should_render_buttons) {
97 print '<div class="main-toolbar-buttons">';
98 print $this->get_button_html();
99 print '</div>';
102 print '<div class="clear"></div>';
103 print '</div>';