<?php
	require ("/var/www/html/uclit/ct_tree_lite.php");
	include ("/var/www/html/uclit/protected/connections/db_login.php");

	//Login Aware start
	$username=$_SESSION['username'];
	
	if ($username) 
	{
		$dbConn = mysql_select_db($database_login, $loginConn) or die("Couldn't select database");
		$login_query = "select allowed_nodes from users where username='$username'";
		//echo $query;
		$login_result = mysql_query($login_query);
	 	$nodes = mysql_result($login_result,0,"allowed_nodes");
		$allowed_nodes = split("\+",$nodes);
	}
	
	//LOGIN Aware end
	include ("/var/www/html/uclit/protected/connections/db_menu.php");
	$dbConn = mysql_select_db($database_menu, $menuConn) or die("Couldn't select database");


	Function ReadLevel($id,$level=0)
	{
		global $allowed_nodes;
		global $username;
		//echo "first: $allowed_nodes[0]";
		
		$str = "";
		/* Prepare and execute the SQL query statement */
		$query = "SELECT nodeId, parentId, title, url FROM nodes where parentId=".$id;
		$result = mysql_query($query);
		
		/* Loop on results */
		while(list($nodeId, $parentId, $title, $url) = mysql_fetch_row($result))
		{
			//echo "parentid: $parentId - nodeid: $nodeId<br>";
			if ((($parentId == 0) && (in_array($nodeId, $allowed_nodes))) || ((in_array($parentId, $allowed_nodes)))) 
			{
			$subitems=ReadLevel($nodeId,$level+1,$url);
			$str.=CreateItem(	$nodeId, 		// Id of the node, used for identification
								$title,	        // Name of the node (may be some html code), will be displayed 
								$url,          // URL 
								$url,           // URL target
								$subitems==""?"clsItem":"clsFolder", // CSS 
								$subitems,      // subitems string
								$level			// level of the item 
												// for proper offset
							); 
			}
		}	
	return ($str); 
	}
?>
<html>
<head>
<script language="JavaScript" src="/uclit/css.js"></script>
<script language="JavaScript" type="text/JavaScript" src="sorttable.js"></script>
<link rel='stylesheet' type='text/css' href='/uclit/new_intranet_print.css' media='print' />
<?php echo Preface() ?>
<title>Library Technology Terminal</title>
</head>
<body>
  <div class="skipLinks">
    skip to: <a href="#content">page content</a> | 
	<a href="/pageNav">links on this page</a> | 
	<a href="#globalNav">site navigation</a> | 
	<a href="#siteInfo">footer (site information)</a>
  </div>
  <div id="wrapper"> 
    <div id="headwrap">
	  <div id="headerleft">
	    <img src="/uclit/images/header2.jpg" alt="University Libraries" width="371" height="74" />
	  </div>
	  <div id="headright"></div>
    </div>
	<!-- end header -->
	<div id="utility">
      <a href="/cgi-bin/Calcium40.cgi?Op=ShowIt&CalendarName=ULMain" target="_blank">Main Calendar</a> | <a href="/cgi-bin/Calcium40.cgi?Op=ShowIt&CalendarName=Room_scheduler">Room Scheduler</a> | <a href="/resources/phonebook/index.html">Staff
      Directory</a> | <a href="/departments/libit/help/show_addhelp.php">Help Calls</a> | <a href="/news/submit_news.php">Add Item to Home Page</a>	 
	</div>
    <div id="content">
	  <div id="login">
<?php
	if ($username) 
	{
		echo "&nbsp; &nbsp; &nbsp; <font size=1>Logged in as <b>$username</b> </font><a href='/uclit/protected/common/login/logout.php'><font size=1>[ logoff ]</font></a>
		      &nbsp; <a href='/uclit/protected/common/login/changepwd.php'><font size=1>[ change password ]</font></a>"; 
	}
	else 
	{
		echo "&nbsp; &nbsp; &nbsp; <a href='/uclit/protected/common/login/login.php'><font size=1>[ login ]</font></a>";
	}
?>	
	  </div>
	  <div id="pageMenu">
	    <div id="menu">
		  <?php if ($username) echo ReadLevel(0); ?> 
	    </div>
	  </div>
	  <!-- end menu -->
      <div class='story'>