PHP Classes

File: treemenu2.php3

Recommend this page to a friend!
  Classes of BrettsBSD.net   treemenu2.php3   treemenu2.php3   Download  
File: treemenu2.php3
Role: ???
Content type: text/plain
Description: See description below
Class: treemenu2.php3
Author: By
Last change:
Date: 23 years ago
Size: 4,115 bytes
 

Contents

Class file image Download
<? /* This is a modification on Sword Su's code. You can now collapse menus with out having to click on another. I also refined the html a bit. I am currently working on an easy way to implement nested menus. */ echo '<font face="arial">'; class submenu { var $urls; var $desps; var $cot; var $id; //easily modify you menu symbols, can also use image tags var $openSymbol = '(+)'; var $closedSymbol = '(--)'; var $itemBranch = '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp|---'; 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; while($i<$this->cot) { if ($i==0) { global $PHP_SELF; echo '<b><a href="'.$PHP_SELF.'?action=close&id=">'.$this->closedSymbol.$this->desps[0].'</a></b><br>'; } else { echo $this->itemBranch.'<a href="'.$this->urls[$i].'">'.$this->desps[$i].'</a><br>'; } $i++; } } function close() { global $PHP_SELF; if (! $this->id){ } else { echo '<b><a href="'.$PHP_SELF.'?action=open&id='.$this->id.'">'.$this->openSymbol.$this->desps[0].'</a></b><br>'; } } } 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++; } } function hide() { $tmp = new submenu; $tmp->close(); } } $sm_1=new submenu; $sm_1->create('1'); $sm_1->add('','Menu1'); $sm_1->add('http://www.whu.edu.cn','Item1'); $sm_1->add('http://www.whnet.edu.cn','Item2'); $sm_1->add('http://www.pku.edu.cn','Item3'); $sm_1->add('http://www.tsinghua.edu.cn','Item4'); $sm_2=new submenu; $sm_2->create('2'); $sm_2->add('','Menu2'); $sm_2->add('http://www.whu.edu.cn','Item1'); $sm_2->add('http://www.whnet.edu.cn','Item2'); $sm_2->add('http://www.pku.edu.cn','Item3'); $sm_2->add('http://www.tsinghua.edu.cn','Item4'); $sm_3=new submenu; $sm_3->create('3'); $sm_3->add('','Menu3'); $sm_3->add('http://www.whu.edu.cn','Item1'); $sm_3->add('http://www.whnet.edu.cn','Item2'); $sm_3->add('http://www.pku.edu.cn','Item3'); $sm_3->add('http://www.tsinghua.edu.cn','Item4'); $sm_4=new submenu; $sm_4->create('4'); $sm_4->add('','Menu4'); $sm_4->add('http://www.whu.edu.cn','Item1'); $sm_4->add('http://www.whnet.edu.cn','Item2'); $sm_4->add('http://www.pku.edu.cn','Item3'); $sm_4->add('http://www.tsinghua.edu.cn','Item4'); $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(); } if ($action=='close') { $m_1->id=$id; $m_1->hide(); $m_1->show(); } echo '</font>'; ?>