<?php
// FIX PARENT LISTS

require "./global.php";

$query = $db->query("SELECT fid FROM ".TABLE_PREFIX."forums");
while($row = $db->fetch_array($query))
{
	$newparentlist = addslashes(makeparentlist($row['fid']));
	$db->query("UPDATE ".TABLE_PREFIX."forums SET parentlist='$newparentlist' WHERE fid='$row[fid]' LIMIT 1");
}

function makeparentlist($fid, $navsep=",") {
	global $pforumcache, $db;
	if(!$pforumcache) {
		$query = $db->query("SELECT name, fid, pid FROM ".TABLE_PREFIX."forums ORDER BY disporder, pid");
		while($forum = $db->fetch_array($query)){
			$pforumcache[$forum[fid]][$forum[pid]] = $forum;
		}
	}
	reset($pforumcache);
	reset($pforumcache[$fid]);
	while(list($key, $forum) = each($pforumcache[$fid])) {
		if($fid == $forum[fid]) {
			if($pforumcache[$forum[pid]]){
				$navigation = makeparentlist($forum[pid], $navsep) . $navigation;
			}
			if($navigation) {
				$navigation .= $navsep;
			}
			$navigation .= "$forum[fid]";
		}
	}
	return $navigation;
}
?>