Location: PHPKode > scripts > GonxTabs > gonxtabs/libs/gonxtabs.class.php
<?php

/**
 * gonxtabs class : Tabs Class Management.
 * 
 * @package 
 * @author Ben Yacoub Hatem <hide@address.com>
 * @copyright Copyright (c) 2004
 * @version $Id$ - 04/03/2004 14:17:23 - tabs.class.php
 * @access public
 **/
class gonxtabs{
	/**
     * Constructor
     * @access protected
     */
	function gonxtabs(){

	}
	
	/**
	 *
	 * @access public
	 * @return void 
	 **/
	function version(){
		return "1.0.2";
	}
	
	
	/**
	 *
	 * @access public
	 * @return void 
	 **/
	function init(){
		global $tabs,$GonxAdmin;
		if (session_is_registered('gonxtabs') and !isset($_GET["tabs"])) {
		    $tabs = $_SESSION["gonxtabs"];
		} elseif (!isset($_GET["tabs"])) {
			if (isset($_SESSION["gonxtabs"])) {
			    $tabs = $_SESSION["gonxtabs"];
			} else {
				$tabs = $GonxAdmin["theme"];
			}	    
		} elseif (isset($_GET["tabs"])) {
			if (is_file("themes/".$_GET["tabs"]."/".$_GET["tabs"].".class.php")) {
				if (!session_is_registered('gonxtabs')) {
				    session_register('gonxtabs');
				}
				$_SESSION["gonxtabs"] = $_GET["tabs"];
			}
		}
		return $tabs;
	}
	
	/**
	 *
	 * @access public
	 * @return void 
	 **/
	function chg_menu(){
		global $go,$tabs;
		$d = dir("./themes");
		$theme_menu = "";
		while (false !== ($entry = $d->read())) {
		   if ($entry!="." and $entry!=".." and is_dir("./themes/".$entry)) {
		   		if ($tabs == $entry) {
		   		    $sel = "selected";
		   		}else $sel="";
		       $theme_menu .= "\t<option value=$entry $sel>$entry</option>\n";
		   }
		}
		$theme_menu = "<select OnChange=\"location.href='?go=$go&tabs='+ChgTheme.options[selectedIndex].value\" name=\"ChgTheme\" class=tab-s>\n\n$theme_menu</select>\n\n";
		$d->close();
		return $theme_menu;
	}
	
	
	/**
	 * tabs::create() : Create tabs
	 * 
	 * @param $menus	Array of tabs
	 * @param $go		Selected tab
	 * @return Tabs in HTML format
	 **/
	function create($menus,$go,$tablewidth="100%"){
		global $GonxAdmin;
		$theme_menu = gonxtabs::chg_menu();
		
		$result = "\n<!-- GonxTabs Menu -->
<table cellSpacing=\"0\" cellPadding=\"0\" width=\"$tablewidth\" background=\"image.php?img=stab_bg_gif\" border=\"0\">
  <tr height=\"24\">
    <td width=\"40\">
    <img height=\"24\" src=\"image.php?img=stab_bg_gif\" width=\"40\"></td>
    <td align=\"left\" width=\"$tablewidth\">
	<table cellSpacing=\"0\" cellPadding=\"0\" border=\"0\">
      <tr height=\"24\">
        <td>&nbsp;</td>\n";
		
		$mk = array_keys($menus);
		$i = 1;
		foreach($menus as $k=>$v){
			if ($k==$go) {
				$m{$i} = "stab_sb_gif";
				$t{$i} = "class=\"tab-s\"";
			} else {
				$m{$i} = "stab_ub_gif";
				$t{$i} = "class=\"tab-g\"";
			}

			if (($i-1)>=0 and $mk[$i-1]==$go) {
			    $mx{$i} = "stab_mus_gif";
			} elseif (($i-2)>=0 and $mk[$i-2]==$go) {
			    $mx{$i} = "stab_msu_gif";
			} else {
			    $mx{$i} = "stab_muu_gif";
			}
				

			// First Tab
			if ($i==1) {
				$mx{$i} = "stab_bs_gif";
				$width = 1;
			} else {
				$width = 14;
			}
			
			if (ereg("^http://",$k)) {
			    $lien = "$k";
			} else {
				$lien = "?go=$k";
			}
			if (ereg("^javascript:",$k)) {
			    $onclick = " onClick=\"window.close()\"";
				$lien = "#";
			} else $onclick="";
			
			$result .="         <td vAlign=\"center\" noWrap background=\"image.php?img=".$m{$i}."\">
        <img src=\"image.php?img=".$mx{$i}."\" align=\"absMiddle\" width=\"$width\" height=\"24\"></td>
        <td vAlign=\"center\" noWrap background=\"image.php?img=".$m{$i}."\">
        &nbsp;&nbsp;<a ".$t{$i}." accessKey=\"$i\" href=\"$lien\" $onclick>$v</a></td>\n\n";


			$i++;
		}

		// Latest tab
		if ($go==$mk[sizeof($menus)-1]) {
		    $result .= "        <td>
        <img src=\"image.php?img=stab_es_gif\" width=\"10\" height=\"24\"></td>\n";
		} else {
		    $result .= "        <td>
        <img src=\"image.php?img=stab_eu_gif\" width=\"10\" height=\"24\"></td>\n";
		}

		$result .= "      </tr>
    </table>
	    </td>
    <td align=right>&nbsp;$theme_menu</td>
  </tr>
</table>
<!-- /GonxTabs Menu -->\n\n";
		return $result;
	}
	
	/**
	 * gonxtabs::block()	create a block of content
	 * 
	 * @param string $content
	 * @param string $tablewidth
	 * @return 
	 **/
	function block($content = "",$tablewidth="100%"){
		global $GonxAdmin;
		
$res =  "\n<!-- GonxTabs Content -->\n<br/>
		    <table cellpadding='0' cellspacing='0' border='0' class=gonxbox width='$tablewidth'>
		      <tr>
		        <td><img src=\"image.php?img=corner_tl_gif\" border=\"0\" height=\"5\" width=\"5\" /></td>
		        <td><img src=\"image.php?img=bar_t_gif\" border=\"0\" height=\"5\" width=\"100%\" /></td>
		        <td><img src=\"image.php?img=corner_tr_gif\" border=\"0\" height=\"5\" width=\"5\" /></td>
		      </tr>
		      <tr>
		        <td width='5' height='100%'><img src=\"image.php?img=bar_l_gif\" border=\"0\" height=\"100%\" width=\"5\" /></td>
		        <td>
		          <table cellpadding='2' cellspacing='3' border='0' width='100%' height='100%'>
		            <tr> 
		             <td>$content</td>
		            </tr>
		          </table>
		        </td>
		        <td width='5' height='100%'><img src=\"image.php?img=bar_r_gif\" border=\"0\" height=\"100%\" width=\"5\" /></td>
		      </tr>
		      <tr>
		        <td><img src=\"image.php?img=corner_bl_gif\" border=\"0\" height=\"5\" width=\"5\" /></td>
		        <td><img src=\"image.php?img=bar_b_gif\" border=\"0\" height=\"5\" width=\"100%\" /></td>
		        <td><img src=\"image.php?img=corner_br_gif\" border=\"0\" height=\"5\" width=\"5\" /></td>
		      </tr>
		    </table>
<br/>
		    <table cellpadding='0' cellspacing='0' border='0' bgColor ='white' width='$tablewidth'>
		      <tr>
		        <td align=center><span class=blue>&nbsp;&nbsp;<font size=1>Author : Ben Yacoub Hatem<br>
				Copyright © <a href=\"http://www.phptunisie.net/\" target=_blank class=blue>PHP Tunisie</a> 2004-2005</font></span>
				</td>
		      </tr>
		    </table>
<!-- /GonxTabs Content -->
</body>
</html>";
		return $res;
	}	
}

?>
Return current item: GonxTabs