Subversion Repositories travelsized

Rev

Rev 70 | Blame | Compare with Previous | Last modification | View Log | RSS feed

<?php
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * This file is part of Travelsized CMS
 *              A content management system with modules, based on wiki syntax
 *
 * Author: Dan Jensen <admin@leinir.dk>
 * Copyright 2003/2004
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * The GNU General Public License is available at: http://www.gnu.org/copyleft/
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */


/**
 * Tab widget class
 */

class Tab {
        var $title = "Tab";
        var $url;
        var $current = false;
}
/**
 * TabBar widget class
 */

class TabBar {
        var $tabs = array();
       
        function addTab($title, $url = "", $current = false) {
                $tab = new Tab;
                $tab->title = $title;
                if ($url != "") $tab->url = $url;
                $tab->current = $current;
                $this->tabs[$title] = $tab;
        }
       
        function removeTab($title) {
                unset($this->tabs[$title]);
        }
       
        function renameTab($oldTitle, $newTitle) {
                $this->tabs[$newTitle] = $this->tabs[$oldTitle];
                $this->tabs[$newTitle]->title = $newTitle;
                unset($this->tabs[$oldTitle]);
        }
        function setCurrent($title) {
                foreach($this->tabs as $key => $value) {
                        $this->tabs[$key]->current = false;
                }
                $this->tabs[$title]->current = true;
        }
       
        function renderTabBar() {
                $numberoftabs = count($this->tabs);
                $tabbar = "
                        <div class=\"tabbar\"><span class=\"tabbar_left\">&nbsp;</span>"
;
                foreach($this->tabs as $key => $value) {
                        if(!$value->current) {
                        $tabbar .= "<span class=\"tabbar_tab_left\">&nbsp;</span><a href=\"{$value->url}\" class=\"tabbar_tab\"><span class=\"tabbar_tab\">{$value->title}</span></a><span class=\"tabbar_tab_right\">&nbsp;</span>";
                        } else {
                        $tabbar .= "<span class=\"tabbar_tab_left_current\">&nbsp;</span><span class=\"tabbar_tab_current\">{$value->title}</span><span class=\"tabbar_tab_right_current\">&nbsp;</span>";
                        }
                }
                $tabbar .= "<span class=\"tabbar_right\">&nbsp;</span></div>";
                return $tabbar;
        }
}

class CommandButton
{
        var $title;
        var $command;
        var $url;
        var $icon;
       
        function render()
        {
                if( $this->icon == null )
                        $icon = "";
                else
                        $icon = "<img style=\"vertical-align: middle;\" src=\"" . $this->icon . "\" alt=\"" . $this->title . "\" />";
                return "<a class=\"command\" title=\"" . $this->title . "\" href=\"" . $this->url . "\">[$icon" . $this->command . "]</a>";
        }
}

class CommandSeparator
{
        function render()
        {
                return " | ";
        }
}

class TabWidget {
        var $tabbar;
        var $contents = "";
        var $commands;
       
        function TabWidget () {
                $this->tabbar = new TabBar;
        }
        function addCommand($command, $title, $url, $icon = null) {
                $this->commands[$command] = new CommandButton;
                $this->commands[$command]->command = $command;
                $this->commands[$command]->title = $title;
                $this->commands[$command]->url = $url;
                $this->commands[$command]->icon = $icon;
        }
       
        function addCommandSeparator()
        {
                $this->commands[] = new CommandSeparator;
        }
       
        function renderTabWidget() {
                $tabwidget = $this->tabbar->renderTabBar() . "<div class=\"tabwidget\"><div class=\"wikirightalign\">";
                if (is_array($this->commands)) {
                        foreach($this->commands as $key => $value) {
                                $tabwidget .= $value->render();
                        }
                } else {
                        $tabwidget .= "<small style=\"font-size: 1px;\">&nbsp;</small>";
                }
                $tabwidget .= "</div><div class=\"tabwidget_content\">" . $this->contents . "</div></div>";
                return $tabwidget;
        }
}
?>