<?php
/**
 * This file implements displaying of an Icons legend.
 *
 * This file is part of the evoCore framework - {@link http://evocore.net/}
 * See also {@link http://sourceforge.net/projects/evocms/}.
 *
 * @copyright (c)2003-2006 by Francois PLANQUE - {@link http://fplanque.net/}
 *
 * {@internal License choice
 * - If you have received this file as part of a package, please find the license.txt file in
 *   the same folder or the closest folder above for complete license terms.
 * - If you have received this file individually (e-g: from http://cvs.sourceforge.net/viewcvs.py/evocms/)
 *   then you must choose one of the following licenses before using the file:
 *   - GNU General Public License 2 (GPL) - http://www.opensource.org/licenses/gpl-license.php
 *   - Mozilla Public License 1.1 (MPL) - http://www.opensource.org/licenses/mozilla1.1.php
 * }}
 *
 * {@internal Open Source relicensing agreement:
 * PROGIDISTRI grants Francois PLANQUE the right to license
 * PROGIDISTRI's contributions to this file and the b2evolution project
 * under any OSI approved OSS license (http://www.opensource.org/licenses/).
 * }}
 *
 * @package evocore
 *
 * @author fplanque: Francois PLANQUE.
 * @author mbruneau: Marc BRUNEAU / PROGIDISTRI
 *
 * @version $Id: _iconlegend.class.php,v 1.2.4.1 2006/11/30 22:00:32 fplanque Exp $
 */
if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );


/**
 * Display icon legend
 *
 * @package evocore
 */
class IconLegend
{

	var $icons = array();

	/**
	 * Constructor
	 * @return IconLegend
	 */
	function IconLegend()
	{
	}

	/**
	 * Add an icon with his legend to the icons array
	 *
	 * @param string name of the icon
	 */
	function add_icon( $icon )
	{
		if( !in_array( $icon, $this->icons ) )
		{
			$this->icons[] = $icon;
		}
	}

	/**
	 * Display the icon legend
	 */
	function display_legend()
	{
		global $map_iconfiles;

		if( !empty( $this->icons ) )
		{	// There are some icons to display
			$r = '<div id="icon_legend">';

			// Loop on all map array of filenames for icons to display icons list in the same order:
			foreach( $map_iconfiles as $icon=>$value )
			{
				if( in_array( $icon, $this->icons ) )
				{	// The icon is used in the page, so display its legend:
					$r .= '<span class="legend_element">'
								.get_icon( $icon ) . ' ';

					if( isset( $map_iconfiles[$icon]['legend'] ) )
					{ // Icon has a legend:
						$r .= $map_iconfiles[$icon]['legend'] . ' ';
					}
					else
					{ // Icon has no legend so we use the alt:
						$r .= $map_iconfiles[$icon]['alt'] . ' ';
					}

					$r .= '</span>';
				}
			}

			$r .= '</div>';
			// Display icon legende:
			echo $r;
		}
	}

	/**
	 * Reset icons array
	 */
	function reset()
	{
		$this->icons[] = array();
	}
}
?>