树行列表类及其应用
时间:2006-05-11 来源:TX
一:class.tree.php类;在开发后台管理系统时,我是用树行列表类来实现的;在frame框架里,左边放这个列表,右边显示相应的 连接(个人觉得非常好用)
class.tree.php
class Tree {
var $tree_basefrm = "_top";
var $tree_gbase;
// internal data
var $tree_path;
var $tree_count = 1;
var $usetextlinks = true;
var $startallopen = false;
var $tree_ftv2folderclosed;
var $tree_ftv2folderopen;
var $tree_ftv2doc;
function Tree ($t_path = "class.tree")
{
$this->tree_path = $t_path;
}
function set_frame ($t_frame)
// (c) Gildas LE NADAN, 10 march 2000
// This method should be called before method open_tree
// if you want to change the default target frame
{
$this->tree_basefrm = $t_frame;
}
function set_textlinks ($tlval)
{
$this->usetextlinks = $tlval;
}
function set_startallopen ($saaval)
{
$this->startallopen = $saaval;
}
function open_tree ($t_text, $t_url, $t_imgopen = "", $t_imgclosed = "", $t_frame="",
$t_gbase="ftv2")
//add $t_imgopen and $t_imgclosed tow parameters
// by gh email:
[email protected]
{
$this->tree_gbase = $t_gbase;
$this->tree_ftv2folderclosed = "$this->tree_gbase/ftv2folderclosed.gif";
$this->tree_ftv2folderopen = "$this->tree_gbase/ftv2folderopen.gif";
$this->tree_ftv2doc = "$this->tree_gbase/ftv2doc.gif";
$tree_ftv2blank = "$this->tree_gbase/ftv2blank.gif";
$tree_ftv2lastnode = "$this->tree_gbase/ftv2lastnode.gif";
$tree_ftv2link = "$this->tree_gbase/ftv2link.gif";
$tree_ftv2mlastnode = "$this->tree_gbase/ftv2mlastnode.gif";
$tree_ftv2mnode = "$this->tree_gbase/ftv2mnode.gif";
$tree_ftv2node = "$this->tree_gbase/ftv2node.gif";
$tree_ftv2plastnode = "$this->tree_gbase/ftv2plastnode.gif";
$tree_ftv2pnode = "$this->tree_gbase/ftv2pnode.gif";
$tree_ftv2vertline = "$this->tree_gbase/ftv2vertline.gif";
if($t_frame) {
$this->tree_basefrm = $t_frame;
}
echo "\n";
if ($this->usetextlinks) echo "var USETEXTLINKS = 1;\n";
else echo "var USETEXTLINKS = 0;\n";
if ($this->startallopen) echo "var STARTALLOPEN = 1;\n";
else echo "var STARTALLOPEN = 0;\n";
?>
classPath = tree_path\";\n"; ?>
ftv2blank = ;
ftv2doc = tree_ftv2doc\""; ?>;
ftv2folderclosed = tree_ftv2folderclosed\""; ?>;
ftv2folderopen = tree_ftv2folderopen\""; ?>;
ftv2lastnode = ;
ftv2link = ;
ftv2mlastnode = ;
ftv2mnode = ;
ftv2node = ;
ftv2plastnode = ;
ftv2pnode = ;
ftv2vertline = ;
basefrm = tree_basefrm\""; ?>;
tree_path/ua.js\""; ?> type="text/javascript">
tree_path/ftiens4.js\""; ?> type="text/javascript">
$jsvn = "foldersTree";
//begin: add by gh email:
[email protected]
if (!strlen($t_imgopen))
$t_imgopen = $this->tree_ftv2folderopen;
if (!strlen($t_imgclosed))
$t_imgclosed = $this->tree_ftv2folderclosed;
//end: add by gh
echo "$jsvn = gFld(\"$t_text\", \"$t_url\", \"$t_imgopen\", \"$t_imgclosed\");\n";
return ($jsvn);
}
function add_folder ($t_parent, $t_text, $t_url,
$t_imgopen = "", $t_imgclosed = "")
{
$jsvn = "aux".$this->tree_count;
$this->tree_count++;
if (!strlen($t_imgopen))
$t_imgopen = $this->tree_ftv2folderopen;
if (!strlen($t_imgclosed))
$t_imgclosed = $this->tree_ftv2folderclosed;
echo "$jsvn = insFld($t_parent, gFld (\"$t_text\", ";
echo "\"$t_url\", \"$t_imgopen\", \"$t_imgclosed\"));\n";
return ($jsvn);
}
function add_document ($t_parent, $t_text, $t_url, $t_img = "")
{
if (!strlen($t_img)) $t_img = $this->tree_ftv2doc;
echo "insDoc($t_parent, gLnk ($t_parent, \"$t_text\", ";
echo "\"$t_url\", \"$t_img\"));\n";
}
function close_tree ( )
{
echo "\ninitializeDocument();\n";
}
}
?>
二:该类的应用left.php
set_frame("main_content");
//Start with all folders open
$tree->set_startallopen(0);
$root = $tree->open_tree("$strRoot","mainpage.php","gohome.gif","gohome.gif");
$nodeLog = $tree->add_folder
($root, "日志管理","","closed.gif","open.gif");
$nodeLog1 = $tree->add_document
($nodeLog, "日志浏览" ,"loglist.php","view_log.gif");
$nodeExit = $tree->add_document
($root, "退出","logoff.php","left_exit.jpg");
$tree->close_tree();
?>
class.tree.php
class Tree {
var $tree_basefrm = "_top";
var $tree_gbase;
// internal data
var $tree_path;
var $tree_count = 1;
var $usetextlinks = true;
var $startallopen = false;
var $tree_ftv2folderclosed;
var $tree_ftv2folderopen;
var $tree_ftv2doc;
function Tree ($t_path = "class.tree")
{
$this->tree_path = $t_path;
}
function set_frame ($t_frame)
// (c) Gildas LE NADAN, 10 march 2000
// This method should be called before method open_tree
// if you want to change the default target frame
{
$this->tree_basefrm = $t_frame;
}
function set_textlinks ($tlval)
{
$this->usetextlinks = $tlval;
}
function set_startallopen ($saaval)
{
$this->startallopen = $saaval;
}
function open_tree ($t_text, $t_url, $t_imgopen = "", $t_imgclosed = "", $t_frame="",
$t_gbase="ftv2")
//add $t_imgopen and $t_imgclosed tow parameters
// by gh email:
[email protected]
{
$this->tree_gbase = $t_gbase;
$this->tree_ftv2folderclosed = "$this->tree_gbase/ftv2folderclosed.gif";
$this->tree_ftv2folderopen = "$this->tree_gbase/ftv2folderopen.gif";
$this->tree_ftv2doc = "$this->tree_gbase/ftv2doc.gif";
$tree_ftv2blank = "$this->tree_gbase/ftv2blank.gif";
$tree_ftv2lastnode = "$this->tree_gbase/ftv2lastnode.gif";
$tree_ftv2link = "$this->tree_gbase/ftv2link.gif";
$tree_ftv2mlastnode = "$this->tree_gbase/ftv2mlastnode.gif";
$tree_ftv2mnode = "$this->tree_gbase/ftv2mnode.gif";
$tree_ftv2node = "$this->tree_gbase/ftv2node.gif";
$tree_ftv2plastnode = "$this->tree_gbase/ftv2plastnode.gif";
$tree_ftv2pnode = "$this->tree_gbase/ftv2pnode.gif";
$tree_ftv2vertline = "$this->tree_gbase/ftv2vertline.gif";
if($t_frame) {
$this->tree_basefrm = $t_frame;
}
echo "\n";
if ($this->usetextlinks) echo "var USETEXTLINKS = 1;\n";
else echo "var USETEXTLINKS = 0;\n";
if ($this->startallopen) echo "var STARTALLOPEN = 1;\n";
else echo "var STARTALLOPEN = 0;\n";
?>
classPath = tree_path\";\n"; ?>
ftv2blank = ;
ftv2doc = tree_ftv2doc\""; ?>;
ftv2folderclosed = tree_ftv2folderclosed\""; ?>;
ftv2folderopen = tree_ftv2folderopen\""; ?>;
ftv2lastnode = ;
ftv2link = ;
ftv2mlastnode = ;
ftv2mnode = ;
ftv2node = ;
ftv2plastnode = ;
ftv2pnode = ;
ftv2vertline = ;
basefrm = tree_basefrm\""; ?>;
tree_path/ua.js\""; ?> type="text/javascript">
tree_path/ftiens4.js\""; ?> type="text/javascript">
$jsvn = "foldersTree";
//begin: add by gh email:
[email protected]
if (!strlen($t_imgopen))
$t_imgopen = $this->tree_ftv2folderopen;
if (!strlen($t_imgclosed))
$t_imgclosed = $this->tree_ftv2folderclosed;
//end: add by gh
echo "$jsvn = gFld(\"$t_text\", \"$t_url\", \"$t_imgopen\", \"$t_imgclosed\");\n";
return ($jsvn);
}
function add_folder ($t_parent, $t_text, $t_url,
$t_imgopen = "", $t_imgclosed = "")
{
$jsvn = "aux".$this->tree_count;
$this->tree_count++;
if (!strlen($t_imgopen))
$t_imgopen = $this->tree_ftv2folderopen;
if (!strlen($t_imgclosed))
$t_imgclosed = $this->tree_ftv2folderclosed;
echo "$jsvn = insFld($t_parent, gFld (\"$t_text\", ";
echo "\"$t_url\", \"$t_imgopen\", \"$t_imgclosed\"));\n";
return ($jsvn);
}
function add_document ($t_parent, $t_text, $t_url, $t_img = "")
{
if (!strlen($t_img)) $t_img = $this->tree_ftv2doc;
echo "insDoc($t_parent, gLnk ($t_parent, \"$t_text\", ";
echo "\"$t_url\", \"$t_img\"));\n";
}
function close_tree ( )
{
echo "\ninitializeDocument();\n";
}
}
?>
二:该类的应用left.php
set_frame("main_content");
//Start with all folders open
$tree->set_startallopen(0);
$root = $tree->open_tree("$strRoot","mainpage.php","gohome.gif","gohome.gif");
$nodeLog = $tree->add_folder
($root, "日志管理","","closed.gif","open.gif");
$nodeLog1 = $tree->add_document
($nodeLog, "日志浏览" ,"loglist.php","view_log.gif");
$nodeExit = $tree->add_document
($root, "退出","logoff.php","left_exit.jpg");
$tree->close_tree();
?>
相关阅读 更多 +