Location: PHPKode > projects > Bugdar > upload/framework/printer_navigation.php
<?php
/*=====================================================================*\
|| ###################################################################
|| # Blue Static ISSO Framework
|| # Copyright ©2002-[#]year[#] Blue Static
|| #
|| # 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; version [#]gpl[#] of the License.
|| #
|| # This program is distributed in the hope that it will be useful, but
|| # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|| # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|| # more details.
|| #
|| # You should have received a copy of the GNU General Public License along
|| # with this program; if not, write to the Free Software Foundation, Inc.,
|| # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|| ###################################################################
\*=====================================================================*/

/**
* Printer - Navigation Generator
* printer_navigation.php
*
* @package	ISSO
*/

/**
* Printer - Navigation Generator
*
* This framework works in conjunction with ISSO.Printer to generate a page header
* and sidebar to be used for navigation. You set the navigation array and then can
* specify a given key to highlight elements. Elements are broken into three types:
* tabs (top of the page), groups (blocks of link actions), and links
*
* @author		Blue Static
* @copyright	Copyright ©2002 - [#]year[#], Blue Static
* @version		$Revision$
* @package		ISSO
* 
*/
class Printer_Navigation
{
	/**
	* Framework registry object
	* @var	object
	* @access	private
	*/
	var $registry = null;
	
	/**
	* Global links that are used for admin home, logout, etc.
	* @var	array
	* @access	private
	*/
	var $toplinks = array();
	
	/**
	* Navigational tabs: array(text, url)
	* @var	array
	* @access	private
	*/
	var $tabs = array();
	
	/**
	* Sections: text
	* @var	array
	* @access	private
	*/
	var $sections = array();
	
	/**
	* Links: array(text, url)
	* @var	array
	* @access	private
	*/
	var $links = array();
	
	/**
	* Array of scopes to set focus to key
	* @var	array
	* @access	private
	*/
	var $focus = array('tab' => null, 'link' => null);
	
	// ###################################################################
	/**
	* Constructor
	*/
	function __construct(&$registry)
	{
		$this->registry =& $registry;
	}
	
	// ###################################################################
	/**
	* (PHP 4) Constructor
	*/
	function Printer_Navigation(&$registry)
	{
		$this->__construct($registry);
	}
	
	// ###################################################################
	/**
	* Adds a global link to the array; these cannot be removed once added
	*
	* @access	public
	*
	* @param	string	Link text
	* @param	string	HREF of the URL
	*/
	function add_top_link($text, $href)
	{
		$this->toplinks["$href"] = $text;
	}
	
	// ###################################################################
	/**
	* Adds to the structure array. The following is the global structure 
	* of the array, but you can specify any entry point. When you add onto
	* the structure, it will go at the bottom
	* array(
	*	'<tab>unique_key'	=> array(
	*		'<section>unique_key'	=> array(
	*			'<link>unique_key'	=> array('text', 'url')
	*		)
	*	)
	* )
	*
	* Note that the portion in brackets is called the "scope"
	*
	* @access	public
	*
	* @param	string	Scope to add to
	* @param	string	Unique key for the scope
	* @param	string	Parent key to add to
	* @param	string	Text to display (usually localized)
	* @param	string	URL to go to when text is clicked
	*/
	function add_component($scope, $key, $parent, $text, $url)
	{
		if ($scope == 'tab')
		{
			$this->tabs["$key"] = array($text, $url);
		}
		else if ($scope == 'section')
		{
			$this->sections["$parent"]["$key"] = $text;
		}
		else if ($scope == 'link')
		{
			$this->links["$parent"]["$key"] = array($text, $url);
		}
	}
	
	// ###################################################################
	/**
	* Sets the focus for either a tab or link
	*
	* @access	public
	*
	* @param	string	Scope operator
	* @param	string	Unique key in scope
	* @param	string	Parent operator (links only)
	*/
	function set_focus($scope, $key, $parent)
	{
		if ($scope == 'tab')
		{
			if (isset($this->tabs["$key"]))
			{
				$this->focus["$scope"] = $key;
			}
			else
			{
				trigger_error('Invalid key for scope', E_USER_WARNING);
			}
		}
		else if ($scope == 'link')
		{
			if (isset($this->links["$parent"]["$key"]))
			{
				$this->focus["$scope"] = $key;
			}
			else
			{
				trigger_error('Invalid key for scope', E_USER_WARNING);
			}
		}
		else
		{
			trigger_error('Printer_Navigation::set_focus() only allows setting of focus for tab and link scopes', E_USER_ERROR);
		}
	}
	
	// ###################################################################
	/**
	* Generates the header HTML that is called in ISSO.Printer->page_start()
	* to setup the navigation frame
	*
	* @access	public
	*
	* @return	string	Generated HTML content
	*/
	function generate_header_html()
	{
		$output = '<!-- navigation start -->' . "\n\n";
		
		// -------------------------------------------------------------------
		
		$output2 = array();
		foreach ($this->toplinks AS $href => $text)
		{
			$output2[] = '<a href="' . $href . '">' . $text . '</a>';
		}
		
		$language = $this->registry->modules['printer']->getLanguageInformation();
		
		$output .= "\n" . '<div id="toplinks" style="float: ' . ($language['direction'] == 'rtl' ? 'left' : 'right') . '">';
		$output .= "\n\t" . '<div>' . $this->registry->getApplication() . ' ' . $this->registry->modules['printer']->getRealm() . '</div>';
		$output .= "\n\t" . '<div id="toplinks-links">' . implode(' &bull; ', $output2) . '</div>';
		$output .= "\n" . '</div>';
		
		// -------------------------------------------------------------------
		
		$output .= "\n\n" . '<div id="wrapper">';
		
		// -------------------------------------------------------------------
		
		$output .= "\n" . '<div id="tabbar">';
		foreach ($this->tabs AS $key => $content)
		{
			$link = "\n\t" . '<a href="' . $content[1] . '"';
			if ($this->focus['tab'] == $key)
			{
				$link .= ' id="focustab"';
			}
			
			$link .= '><span>' . $content[0] . '</span></a>';
			
			$output .= $link;
		}
		$output .= "\n" . '</div>';
		
		// -------------------------------------------------------------------
		
		$output .= "\n\n" . '<table id="contentbody" cellspacing="0" cellpadding="0" border="0">';
		$output .= "\n" . '<tr>';
		
		// -------------------------------------------------------------------
		
		$output .= "\n" . '<td id="menu">';
		foreach ((array)$this->sections[ $this->focus['tab'] ] AS $key => $text)
		{
			$output .= "\n" . '<ul>';
			$output .= "\n\t" . '<li class="header"><span>' . $text . '</span></li>';
			foreach ((array)$this->links["$key"] AS $key2 => $content)
			{
				$output .= "\n\t" . '<li' . ($this->focus['link'] == $key2 ? ' class="focus"' : '') . '><a href="' . $content[1] . '"><span>' . $content[0] . '</span></a></li>';
			}
			$output .= "\n" . '</ul>' . "\n";
		}
		$output .= "\n" . '</td>';
		
		// -------------------------------------------------------------------
		
		$output .= "\n" . '<td id="mainbody">';
		$output .= "\n\n" . '<!-- main content body -->' . "\n";
		
		return $output;
	}
	
	// ###################################################################
	/**
	* Generates the HTML that is inserted in ISSO.Printer->page_end() that
	* closes all of the navigation HTML stuff
	*
	* @access	public
	*
	* @return	string	Generated HTML content
	*/
	function generate_footer_html()
	{
		$output = '';
		
		$output .= "\n" . '<!-- / main content body -->' . "\n";
		
		$output .= "\n" . '</td>';
		$output .= "\n" . '</tr>';
		
		$output .= "\n\n" . '</table>';
		
		$output .= "\n\n" . '</div>';
		
		return $output;
	}
}

/*=====================================================================*\
|| ###################################################################
|| # $HeadURL$
|| # $Id$
|| ###################################################################
\*=====================================================================*/
?>
Return current item: Bugdar