--- txplib_db.php 2008-06-05 07:32:02.828125000 +0100 +++ txplib_db_tree_mod.php 2008-06-05 07:27:20.687500000 +0100 @@ -326,7 +326,7 @@ } // ------------------------------------------------------------- - function getTree($root, $type, $where='1=1') + function getTree($root, $type, $where='1=1', $tbl='txp_category') { $root = doSlash($root); @@ -334,7 +334,7 @@ $rs = safe_row( "lft as l, rgt as r", - "txp_category", + $tbl, "name='$root' and type = '$type'" ); @@ -346,7 +346,7 @@ $rs = safe_rows_start( "id, name, lft, rgt, parent, title", - "txp_category", + $tbl, "lft between $l and $r and type = '$type' and name != 'root' and $where order by lft asc" ); @@ -371,12 +371,12 @@ } // ------------------------------------------------------------- - function getTreePath($target, $type) + function getTreePath($target, $type, $tbl='txp_category') { $rs = safe_row( "lft as l, rgt as r", - "txp_category", + $tbl, "name='".doSlash($target)."' and type = '".doSlash($type)."'" ); if (!$rs) return array(); @@ -384,7 +384,7 @@ $rs = safe_rows_start( "*", - "txp_category", + $tbl, "lft <= $l and rgt >= $r and type = '".doSlash($type)."' order by lft asc" ); @@ -412,7 +412,7 @@ } // ------------------------------------------------------------- - function rebuild_tree($parent, $left, $type) + function rebuild_tree($parent, $left, $type, $tbl='txp_category') { $left = assert_int($left); $right = $left+1; @@ -420,11 +420,11 @@ $parent = doSlash($parent); $type = doSlash($type); - $result = safe_column("name", "txp_category", + $result = safe_column("name", $tbl, "parent='$parent' and type='$type' order by name"); foreach($result as $row) { - $right = rebuild_tree($row, $right, $type); + $right = rebuild_tree($row, $right, $type, $tbl); } safe_update( @@ -436,13 +436,13 @@ } //------------------------------------------------------------- - function rebuild_tree_full($type) + function rebuild_tree_full($type, $tbl='txp_category') { # fix circular references, otherwise rebuild_tree() could get stuck in a loop - safe_update('txp_category', "parent=''", "type='".doSlash($type)."' and name='root'"); - safe_update('txp_category', "parent='root'", "type='".doSlash($type)."' and parent=name"); + safe_update($tbl, "parent=''", "type='".doSlash($type)."' and name='root'"); + safe_update($tbl, "parent='root'", "type='".doSlash($type)."' and parent=name"); - rebuild_tree('root', 1, $type); + rebuild_tree('root', 1, $type, $tbl); } //-------------------------------------------------------------