Location: PHPKode > scripts > Tree menu > tree-menu/treemenu.php3
<?

class submenu { /* ×Ӳ˵¥Àà */

  var $urls; /* Á´½ÓµØÖ·Êý×é */
  var $desps; /* Á´½ÓÃèÊöÊý×é */
  var $cot; /* Á´½á¸öÊý */
  var $id; /* ×Ӳ˵¥±êʶ */

  function create($id) { /* ¹¹Ô캯Êý */
    $this->cot=0; 
	$this->id=$id;
  }

  function add($url, $desp) { /* Ôö¼ÓÒ»ÏîÁ´½Ó */
    $this->urls[$this->cot]=$url;
    $this->desps[$this->cot]=$desp;	
    $this->cot++;
  }
  
  function open() { /* ´ò¿ª×Ӳ˵¥ */
  $i=0;
  echo '<table width="15%" border="0" align="center">';
  while($i<=$this->cot) {
    if ($i==0) { /* ±íÍ· */
   	  echo '<tr><th align="center" bgcolor="#34ABC0"><font color="White">';
 	  echo $this->desps[0];
	  echo '</font></th></tr>';
	}
	else {
      echo '<tr><td align="center" ><font size="-1">';
	  echo '<a href="'.$this->urls[$i].'">'.$this->desps[$i].'</a>';
	  echo '</font></td></tr>';
    }
    $i++;
  }
  echo '</table>';
  }
  
  function close() { /* ¹Ø±Õ×Ӳ˵¥ */
    echo '<table width="15%" border="0" align="center">';
    echo '<tr><th align="center" bgcolor="#34ABC0"><font color="White">';
    echo '<a href="?action=open&id='.$this->id.'">'.$this->desps[0].'</a>';
	echo '</font></th></tr>';  
    echo '</table>';	
  }

}

class menu { /* ²Ëµ¥Àà */

  var $submenus; /* ×Ӳ˵¥¶ÔÏóÊý×é */
  var $cot; /* ×Ӳ˵¥¸öÊý */
  var $id; /* µ±Ç°µÄ×Ӳ˵¥±êʶ */
  
  function create() { /* ¹¹Ô캯Êý */
    $this->cot=0;
	$this->id=2;
  }
  
  function add($submenu) { /* Ôö¼Ó×Ӳ˵¥¶ÔÏó */
    $this->submenus[$this->cot]=new submenu;
	$this->submenus[$this->cot]=$submenu;
	$this->cot++;
  }
  
  function show() { /* ÏÔʾ²Ëµ¥ */
    $i=0;
	$tmp = new submenu;
	while ($i<$this->cot) {
	  $tmp=$this->submenus[$i];
	  if ($tmp->id==(string)$this->id) {
  	    $tmp->open();
	  }
	  else {
	    $tmp->close();
	  }
	  $i++;
	}
  }
 
} 

$sm_1=new submenu;
$sm_1->create('1');
$sm_1->add('','½ÌÓý1');
$sm_1->add('http://www.whu.edu.cn','Î人´óѧ');
$sm_1->add('http://www.whnet.edu.cn','»ªÖÐÀí¹¤´óѧ');
$sm_1->add('http://www.pku.edu.cn','±±¾©´óѧ');
$sm_1->add('http://www.tsinghua.edu.cn','Ç廪´óѧ'); 

$sm_2=new submenu;
$sm_2->create('2');
$sm_2->add('','½ÌÓý2');
$sm_2->add('http://www.whu.edu.cn','Î人´óѧ');
$sm_2->add('http://www.whnet.edu.cn','»ªÖÐÀí¹¤´óѧ');
$sm_2->add('http://www.pku.edu.cn','±±¾©´óѧ');
$sm_2->add('http://www.tsinghua.edu.cn','Ç廪´óѧ');

$sm_3=new submenu;
$sm_3->create('3');
$sm_3->add('','½ÌÓý3');
$sm_3->add('http://www.whu.edu.cn','Î人´óѧ');
$sm_3->add('http://www.whnet.edu.cn','»ªÖÐÀí¹¤´óѧ');
$sm_3->add('http://www.pku.edu.cn','±±¾©´óѧ');
$sm_3->add('http://www.tsinghua.edu.cn','Ç廪´óѧ');

$sm_4=new submenu;
$sm_4->create('4');
$sm_4->add('','½ÌÓý4');
$sm_4->add('http://www.whu.edu.cn','Î人´óѧ');
$sm_4->add('http://www.whnet.edu.cn','»ªÖÐÀí¹¤´óѧ');
$sm_4->add('http://www.pku.edu.cn','±±¾©´óѧ');
$sm_4->add('http://www.tsinghua.edu.cn','Ç廪´óѧ');

$m_1=new menu;
$m_1->create();
$m_1->add($sm_1);
$m_1->add($sm_2);
$m_1->add($sm_3);
$m_1->add($sm_4);

if ($action=='') {
  $m_1->show();
}

if ($action=='open') {
  $m_1->id=$id;
  $m_1->show();
}

?>
Return current item: Tree menu