All pastes #899656 Raw Edit

Unnamed

public text v1 · immutable
·published 2008-02-11 10:07 UTC
rendered paste body
function getLevels($id)
{
	global $db;
	$result = array($id);	
	$qString = "select parent_id from topics where id=".(int)$id;
	$qResult = pg_query($db, $qString);
	$checkId = pg_fetch_assoc($qResult);
	pg_free_result($qResult);
	$checkId = (int)$checkId['id'];
	if($checkId)
	{
		$result = array_merge($result,getLevels($checkId));
	}

	return $result;
}

function getGroups($parent_id = 0, $lvl = 0,$currentGroup = 0, $currentTopic = 0, $currentComment = 0, $limitLvl = 0)
{
	global $db;
	
	$params = array(
	'comment',
	'topic',
	'group'
	);

	$qString = "select id, name, description from topics where parent_id='.$parent_id.' order by pos asc";
	$qResult = pg_query($db,$qString);
	$switch($lvl)
	{
		case 0:
			$currentValue = $currentGroup;
		break;
		case 1:
			$currentValue = $currentTopic;
		break;
		case 2:
			$currentValue = $currentComment;
		break;
	}
	while($row = pg_fetch_assoc($qResult))
	{
		if($currentValue == $row['id'])
		{
			$cssStl = 'text-decorations: underline;';
		}
		else
		{

			$cssStl = 'text-decorations: none;';
		}
		$idChain = getLevels($row['id']);
		if(count($idChain)<4)
		{
			for($i = 0; $i < (4-count($idChain)); $i++)
			{
				$idChain = array_merge(array(0),$idChain);
			}
		}
		$url = '';
		foreach($idChain as $cnt => $id)
		{
			if($id)
			{
				$url .= '&'.$params[$cnt].='='.$id;
			}
			
		}
		$aLink1 = '<a href="index.php?module=topic'.$url.'" style="'.$cssStl.'">';
		$aLink2 = '</a>';
		$topicsList .= '
		<tr>	
			<td>'.$aLink1.'<b>'.$row['name'].'</b>'.$aLink2.'</td>
			<td><pre>'.$row['description'].'</pre></td>
		</tr>
		<tr>
			<td colspan="2">'.getGroups($row['id'], $lvl+1, $currentGroup, $currentTopic, $currentComment).'</td>
		</tr>
		';
	}
	$topicsList = '<table>'.$topicsList.'</table>';
	return $topicsList;
}