日期:2011-02-20  浏览次数:20605 次

<?
class Tree {
var $data = array();
var $tpl = '<table cellpadding=0 cellspacing=0 border=0 style="font-size:9pt">$块</table>';
var $block = '<tr onClick="tree_onclick()" bs=$标识><td background="$连线">$主图标</td><td>$副图标 $文字</td></tr><tr style="display:$可见"><td background="$连线"></td><td value="$编号">$子树</td></tr>';

var $images = array( // 节点图片
array("images/tree_L.gif","images/tree_T.gif","images/icon-page.gif"),
array("images/OpenFolder_L.gif","images/OpenFolder_T.gif","images/FolderClose.gif","images/FolderOpen.gif"),
array("images/CloseFolder_L.gif","images/CloseFolder_T.gif","images/FolderClose.gif","images/FolderOpen.gif"),
array("none","images/tree_I.gif"),
);

var $bond = array("","数据加载中...");
var $all = false; // 是否产生一棵子树

/**
* Tree 构造函数
*/
function Tree() {
}
/**
* table 方法
* 功能 产生以表格方式组织的数据
* 说明 主要用于调试
*/
function table($format="",$head="") {
if(count($this->data) <= 0) return $this->out = "";
$out = "<table $format><tr>";
if($head == "") {
foreach($this->data as $v) break;
$head = array_keys($v);
}
foreach($head as $v)
$out .= "<th>$v</th>";
$out .= "</tr>";
foreach($this->data as $value) {
$out .= "<tr>";
foreach($head as $k)
$out .= "<td>$value[$k]</td>";
$out .= "</tr>";
}
return $this->out = "$out</table>";
}
/**
* node_all 方法
* 功能 根据模板构造全部数据
*/
function node_all($id, $key=array("id","pid","text","link")) {
$this->all = true;
return $this->node($id,$key);
}
/**
* index 方法
* 功能 索引树
*/
function index($start=0, $key=array("id","pid")) {
$fun = create_function('$a,$b'
,"if(\$a[$key[1]] == \$b[$key[1]]) return 0;"
."return \$a[$key[1]] > \$b[$key[1]]?1:-1;");
$out = array();
foreach($this->data as $k=>$v) {
if($v[$key[1]] == $start)
$out[] = $v;
else
$this->insert($v,&$out,$key);
}
return $this->data = $out;
}
/**
* insert 方法
* 功能 插入节点
*/
function insert($value,$array="",$key=array("id","pid")) {
if($array == "") $array =& $this->data;
if(count($array) <= 0) {
$array[] = $value;
return true;
}
$k = $m = $n = 0;
$ar = array();
foreach($array as $t) {
$k++;
if($t[$key[0]] == $value[$key[1]]) $m = $k;
if($t[$key[1]] == $value[$key[1]] || in_array($t[$key[1]],$ar)) {
$n = $k;
$ar[] = $t[$key[0]];
}
}
$k = max($m,$n);
if($k == 0) return false;
$array = array_merge(array_slice($array,0,$k),array($value),array_slice($array,$k));
return true;
}
/**
* update 方法
* 功能 修改节点
*/
function update() {
}
/**
* delete 方法
* 功能 删除节点
*/
function delete() {
}
/**
* move 方法
* 功能 移动节点
*/
function move() {
}
/**
* display 方法