<?

	/* 
	** get list of child pathways
	*/ 
	$Query = "SELECT ID, Name, Description, Icon ";
	$Query .= "FROM pathway ";
	$Query .= "WHERE Parent=$pathway ";
	if(!$UserInfo["Login"])
	{
		$Query .= "AND Private='N' ";
	}
	$Query .= "ORDER BY DisplayOrder, Name "; 

	$DatabaseResult = mysql_query($Query, $DatabaseLink);
	
	$numRows = mysql_NumRows($DatabaseResult);

	if($numRows > 0)
	{
		print("<B>Pathways to Other Nodes</B>");
		print("<TABLE BORDER=\"0\" CELLSPACING=\"0\" CELLPADDING=\"10\">\n");

		$current_Column = 1;
		
		while($DatabaseRow = mysql_fetch_row($DatabaseResult))
		{
			$door_ID = $DatabaseRow[0];
			$door_Title = $DatabaseRow[1];
			$door_Description = $DatabaseRow[2];
			$door_Icon = $DatabaseRow[3];
	
			if ($current_Column == 1)
			{
				print("<TR ALIGN=\"left\" VALIGN=\"top\">\n");
			}
			
			print("<TD><A HREF=\"".ScreenURL("view")."&pathway=$door_ID\">");
			if ($door_Icon)
			{
				print("<IMG SRC=\"$Icon_URL$door_Icon\">");
			}
			print("<FONT FACE=\"helvetica\">$door_Title</FONT></A>\n");
			print("<BR>\n");
			print("<FONT FACE=\"helvetica\" SIZE=2>$door_Description</FONT></TD>\n");
	
			if ($current_Column == $pathway_Layout)
			{
				print("</TR>\n");
				
				$current_Column = 1;
			}
			else
			{
				// print out a blank cell for the gutter column
				print("<TD><IMG SRC=\"images/clear.gif\" WIDTH=\"" . PATHWAY_GUTTER . "\" HEIGHT=\"1\" ALT=\"\" BORDER=\"0\"></TD>\n");
				
				$current_Column++;
			}
		
		}
		
		// make extra table cell if we didn't fill a whole row
		
		if ($current_Column <= $pathway_Layout && $current_Column > 1)
		{
			print("<TD COLSPAN=\"" . (2 * $pathway_Layout - 2 * $current_Column +1) . "\">&nbsp;</TD>\n");
		}

		print("</TABLE>\n");
	}

	/* 
	** get list of child nodes 
	*/
	$Query = "SELECT n.ID, n.Name, n.Description, c.Name, (to_days(now()) - to_days(Created)), n.Icon, n.Parent ";
	$Query .= "FROM node n, content c ";
	$Query .= "WHERE n.Content = c.ID ";
	$Query .= "AND n.Parent=$pathway ";
	
	switch($order_by)
	{
		case 'name':
			$Query .= "ORDER BY n.Name, n.LinkCount DESC, n.DisplayOrder DESC ";
			break;
		case 'popularity':
			$Query .= "ORDER BY n.LinkCount DESC, n.DisplayOrder DESC, n.Name ";
			break;
		case 'age':
			$Query .= "ORDER BY n.Created DESC, n.DisplayOrder DESC, n.Name ";
			break;
		default:
			$Query .= "ORDER BY n.DisplayOrder DESC, n.Name, n.LinkCount DESC "; 
	}

		
	$DatabaseResult = mysql_query($Query, $DatabaseLink);
	
	$numRows = mysql_NumRows($DatabaseResult);

	if($numRows > 0)
	{
		print("<B>Nodes at this Level</B><BR>\n");
		
		print("Order by:<BR>\n");
		
		if ($order_by != "display_order")
		{	
			print("<A HREF=\"".ScreenURL("view")."&pathway=$pathway&order_by=display_order\">Display Order</A> | \n");
		}
		else
		{
			print("Display Order | \n");
		}
		
		if ($order_by != "name")
		{
			print("<A HREF=\"".ScreenURL("view")."&pathway=$pathway&order_by=name\">Name</A> | \n");
		}
		else
		{
			print("Name | \n");
		}
		
		if ($order_by != "popularity")
		{
			print("<A HREF=\"".ScreenURL("view")."&pathway=$pathway&order_by=popularity\">Popularity</A> | \n");
		}
		else
		{
			print("Popularity | \n");
		}
		
		if ($order_by != "age")
		{
			print("<A HREF=\"".ScreenURL("view")."&pathway=$pathway&order_by=age\">Newest First</A>\n");
		}
		else
		{
			print("Newest First\n");
		}
		
		print("<BR><BR>\n");
		
		
		include("$Application_Root/modules/include/display_nodes");
	}
	else
	{
		print("No nodes at this level");
	}
	


?>
