Execute('SELECT * FROM nav ORDER BY id');
while(!$res->EOF) {
$this->entries[$res->fields[0]] = new NavEntry($res->fields[1], $res->fields[2], $res->fields[3]);
$res->MoveNext();
}
foreach($this->entries as $entry)
if($entry->parent != 0)
$this->entries[$entry->parent]->Add($entry);
}
function ParseEntries() {
$ret = '
';
foreach($this->entries as $entry)
if($entry->parent == 0)
$ret .= $entry->Parse();
$ret .= '
';
return $ret;
}
}
class NavEntry {
var $parent, $text, $link;
var $children = array();
function NavEntry($parent, $text, $link) {
$this->parent = $parent;
$this->text = $text;
$this->link = $link;
}
function Add($entry) {
array_push($this->children, $entry);
}
function Parse() {
$ccount = 0;
$ret = '';
$a = $GLOBALS['links']->ParseNavLink($this->text, $this->link);
$ret .= $a;
if(count($this->children) > 0) {
$ret .= '';
foreach($this->children as $child) {
$cret = $child->Parse();
if($cret) {
$ret .= $cret;
$ccount++;
}
}
$ret .= '
';
}
if(!$ccount && $a == $this->text)
return '';
return $ret . '';
}
}
$GLOBALS['nav'] = new Nav;
?>