diff --git a/lib/weblib.php b/lib/weblib.php index db90114b39b..a0f4e37e7a1 100644 --- a/lib/weblib.php +++ b/lib/weblib.php @@ -3848,5 +3848,145 @@ function print_maintenance_message () { } + +/// Some code to print tabs + +/// A class for tabs +class tabobject { + var $id; + var $link; + var $text; + + /// A constructor just because I like constructors + function tabobject ($id, $link='', $text='') { + $this->id = $id; + $this->link = $link; + $this->text = $text; + } + + + /// a method to look after the messy business of setting up a tab cell + /// with all the appropriate classes and things + function createtab ($selected=false, $inactive=false, $last=false) { + $str = ''; + $astr = ''; + $cstr = ''; + + /// The text and anchor for this tab + if ($inactive) { + $astr .= $this->text; + } else { + $astr .= ''.$this->text.''; + } + + /// There's an IE bug with background images in tags + /// so we put a div around so that we can add a background image + $astr = ''; + + /// Set the class for inactive cells + if ($inactive) { + $cstr .= ' inactive'; + + /// Set the class for the selected cell + } else if ($selected) { + $cstr .= ' selected'; + } + + + /// Are we on the last tab in this row? + if ($last) { + $cstr .= ' last'; + $astr = ''.$astr.''; + } + + /// Lets set up the tab cell + $str .= 'tabselectedtofront) and ($selected !== NULL) ) { + $found = false; + $frontrows = array(); + $rearrows = array(); + foreach ($tabrows as $row) { + if ($found) { + $rearrows[] = $row; + } else { + foreach ($row as $tab) { + if ($found) { + continue; + } + $found = ($selected == $tab->id); + } + $frontrows[] = $row; + } + } + $tabrows = array_merge($rearrows,$frontrows); + } + +/// $inactive must be an array + if (!is_array($inactive)) { + $inactive = array(); + } + +/// A table to encapsulate the tabs + $str = ''; + +/// Cycle through the tab rows + foreach ($tabrows as $row) { + + $str .= ''; + $str .= '
'; + $str .= ''; + $str .= ''; + + $numberoftabs = count($row); + $currenttab = 0; + $cstr = ''; + $astr = ''; + + + /// Cycle through the tabs + foreach ($row as $tab) { + $currenttab++; + + $str .= $tab->createtab( ($selected == $tab->id), + (in_array($tab->id, $inactive)), + ($currenttab == $numberoftabs) ); + } + + $str .= ''; + $str .= '
'; + $str .= '
'; + } + + return $str; + +} + + // vim:autoindent:expandtab:shiftwidth=4:tabstop=4:tw=140: ?>