* @copyright 2001-2006 VIKO team and contributors * @license http://www.gnu.org/licenses/gpl.html GPL 2.0 */ /** * Uses the {@link Configuration} class to access configuration */ require_once 'Configuration.php'; /** * VIKO page * * Possible usage: * *
 * $page = new VIKO();
 * $page->setTitle("VIKO Hello");
 * $page->setContent("Hello, world of VIKO!");
 * echo $page->toHTML();
 * 
*/ class VIKO { /**#@+ * @access private * @var string */ /** * Title following the VIKO logo */ var $_environment_title=""; /** * Title of the page */ var $_title="--noname--"; /** * Contents of the page (in HTML format) */ var $_content="--empty--"; /** * The Identifier of active VIKO module */ var $_module_id="front-page"; /** * Stylesheets associated with the page */ var $_stylesheets = ""; /**#@-*/ /** * Navigation menu * * @access private * @var array */ var $_nav = array(); /** * Constructs new VIKO instance */ function VIKO() { $this->_environment_title = _("learning environment"); $this->addStylesheet("/css/layout.css"); } /** * Sets the general VIKO environment, based on user group * * For example, if the user group is "STUDENT", the VIKO header will say: * "VIKO student environment". * * @access public * @param string $user_group the group of the user. * only 4 values are allowed: STUDENT, TEACHER, SCHOOLADMIN and ADMIN. * If the parameter is unspecified, no special title will be generated. */ function setEnvironment( $user_group="" ) { switch ($user_group) { case "": $this->_environment_title = _("learning environment"); break; case "STUDENT": $this->_environment_title = _("student environment"); break; case "TEACHER": $this->_environment_title = _("teacher environment"); break; case "SCHOOLADMIN": $this->_environment_title = _("school administrator environment"); break; case "ADMIN": $this->_environment_title = _("administrator environment"); break; default: trigger_error("Unknown user group '$user_group'", E_USER_ERROR); } } /** * Sets the title of VIKO page * * @access public * @param string $title title of the page. */ function setTitle( $title ) { $this->_title = $title; } /** * Sets the Identifier of current VIKO module * * The {@link $module_id} will be used as a value for the 'id' attribute * of the 'body' element. For example: * *
     * $viko->setModuleID("about");
     * // will also output a body tag like: <body id="about">
     * echo $viko->toHTML();
     * 
* * @access public * @param string $module_id ID of module */ function setModuleID( $module_id ) { $this->_module_id = $module_id; } /** * Adds a stylesheet to VIKO page * * @access public * @param string $uri address of the CSS file * @param string $media CSS media type (or list of types, separated by commas) * @param string $rel either "stylesheet" or "alternate stylesheet" */ function addStylesheet( $uri, $media="all", $rel="stylesheet") { $this->_stylesheets .= << EOHTML; } /** * Adds a multiple stylesheets to VIKO page * * @access public * @param string $stylesheets array containing stylesheets */ function addStylesheetList( $stylesheets ) { foreach ( $stylesheets as $sheet ) { $uri = $sheet['uri']; $media = ( isset($sheet['media']) ) ? $sheet['media'] : 'all'; $rel = ( isset($sheet['rel']) ) ? $sheet['rel'] : 'stylesheet'; $this->addStylesheet( $uri, $media, $rel ); } } /** * Sets the contents of VIKO page * * @access public * @param string $content content of the page. */ function setContent( $content ) { $this->_content = $content; } /** * Appends item (link) to VIKO menu * * @param string $uri address of the link * @param string $label label of the link * @param string $description description (displays as HTML title-text) */ function addMenuItem( $uri, $label, $description ) { $this->_nav[] = array( 'uri'=>$uri, 'label'=>$label, 'description'=>$description, 'state'=>'normal' ); } /** * Marks menu item as selected * * @param string $uri URI of menu item to select */ function selectMenuItem( $uri ) { $this->_changeMenuItemState( $uri, 'selected' ); } /** * Marks menu item as highlighted * * @param string $uri URI of menu item to highlight */ function highlightMenuItem( $uri ) { $this->_changeMenuItemState( $uri, 'highlighted' ); } /** * Changes the state of menu item * * 'normal', 'selected' and 'highlighted' are allowed values for state. * * @access private * @param string $uri URI of menu item to change * @param string $state the value to assign to the menu item state */ function _changeMenuItemState( $uri, $state ) { // find the menu item with specified title, and change it's state for ( $i=0; $i < count($this->_nav); $i++ ) { if ( $this->_nav[$i]['uri'] == $uri ) { $this->_nav[$i]['state'] = $state; return; } } } /** * Converts $this->_nav array to unordered list. * * @access private * @return string generated HTML */ function _menuToHTML() { $html='"; return $html; } /** * Creates langage menu, highlighting current locale * * @access private * @return string HTML ul */ function _languageMenu() { $lang_menu = array( "et_EE" => "Eesti", "ru_RU" => "Русский", "en_US" => "English", ); $html = ''; return $html; } /** * Outputs VIKO page in HTML * * @return string HTML document */ function toHTML() { $lang = preg_replace('/^([a-z]{2})_([A-Z]+)$/', '\1', Configuration::getLocale()); $copyright = _("Tallinn University %year1%-%year2%"); $copyright = str_replace("%year1%", "2001", $copyright); $copyright = str_replace("%year2%", "2006", $copyright); $lang_menu = $this->_languageMenu(); $menu = ( count($this->_nav) > 0 ) ? $this->_menuToHTML() : ""; return << {$this->_title} {$this->_stylesheets}
{$lang_menu}

VIKO {$this->_environment_title}

{$menu}
{$this->_content}

EOHTML; } } ?>