<?php
// Class vB_YUI written by King Kovifor.
// Copryight 2008+
// Cannot be redistributed without permission of author.
// Written for use in Tabbed Forum Home.

class tfh_vB_YUI
{
	var $tabs = array();
	var $count = 0;
	var $vb;
	var $usergroup;
	var $name = 'myTabs';
	
	function tfh_vB_YUI(&$registry, $usergroup, $variable)
	{
		$this->vb =& $registry;
		$this->usergroup =& $usergroup;
		$this->name =& $variable;
	}

	function add_tab($title, $useDataSrc = false, $content, $active = false, $cacheData = false, $limitTo)
	{		
		if(!is_array($limitTo))
		{
			if(!$limitTo == 'all')
			{
				$limitTo = array($limitTo);
			}
		}
		
		$dataContent = ($useDataSrc ? 'dataSrc' : 'content');
		$active = ($active == 'true' ? 'true' : 'false');
		$cacheData = ($cacheData == 'true' ? 'true' : 'false');
		
		$array = array('title' => $title, 'contentT' => $dataContent, 'content' => $content, 'active' => $active, 'cacheData' => $cacheData, 'limitTo' => $limitTo);
				
		$this->tabs[++$this->count] = $array;
	}
	
	function javascript_code($container, $verify_usergroup = true)
	{
		$this->code .= "var " . $this->name . " = new YAHOO.widget.TabView();";
       		
		foreach($this->tabs as $tab)
		{
			if($verify_usergroup)
			{
				if($tab['limitTo'] == 'all')
				{
					$this->code .= "YAHOO.plugin.Dispatcher.delegate(new YAHOO.widget.Tab({label: '" . mysql_escape_string($tab['title']) . "', " . $tab['contentT'] . ": '" . $tab['content'] . "', active: " . $tab['active'] .", cacheData: " . $tab['cacheData'] ."}), " . $this->name . ");";
				}
				else
				{
					$tab['limitTo'] = explode(",", $tab['limitTo']);
					if(in_array($this->usergroup, $tab['limitTo']))
					{
						$this->code .= "YAHOO.plugin.Dispatcher.delegate(new YAHOO.widget.Tab({label: '" . mysql_escape_string($tab['title']) . "', " . $tab['contentT'] . ": '" . $tab['content'] . "', active: " . $tab['active'] .", cacheData: " . $tab['cacheData'] ."}), " . $this->name . ");";
					}
				}
			}
			else
			{
				$this->code .= "YAHOO.plugin.Dispatcher.delegate(new YAHOO.widget.Tab({label: '" . mysql_escape_string($tab['title']) . "', " . $tab['contentT'] . ": '" . $tab['content'] . "', active: " . $tab['active'] .", cacheData: " . $tab['cacheData'] ."}), " . $this->name . ");";
			}
		}
		$this->code .= $this->name . '.appendTo("' . $container .'");';
		return $this->code;
	}
}

?>