Location: PHPKode > projects > WaveWatcher > wavewatcher3/html/selnodes.php
<?
    require_once("../classes/network.php");
require_once("../classes/user.php");
session_start();                                                                                //Start session

$user = new User();
$network = new Network();
    $error = FALSE;
    $user_id = 0;
	//If the user hasn't logged in then we should send him to the loginpage.
	if (!$user->IsLoggedIn())
		header("Location: index.php");
    
	// Are we entering the page with posted variables (from allusers.php)
    if (IsSet($id))
    {
        if (!$user->IsAdmin())
            header("Location: selnodes.php");

        if ($id != $user->GetUserID())
            $user_id = substr($id,2);
    }

	// Posted variables, update table nodes_users
    if ($HTTP_POST_VARS)
    {
        $nodes = array();
        $i = 0;
        $update = FALSE;

        foreach ($HTTP_POST_VARS as $value)
        {
            if ($value == "Update")
                $update = TRUE;
            elseif ($value > 0)
            {
                $nodes[$i] = $value;
                $i++;
            }
        }

        if ($update)
			if (!$user->SetUserNodes($nodes, $user_id))
				$error = TRUE;
		
    }

    $name = $user->GetUserName($user_id);


	function GetNetworkCssClass($status)
	{
		if($status == 0)
			return "td_network";
		return "td_network_alarm";
	}

	function GetNodeCssClass($status)
	{
		if($status == 0)
			return "a_node_up";
		else if($status == 1)
			return "a_node_down";
		else if($status == 2)
			return "a_node_unknown";
	}

	// Check which web browser
	function GetBrowser()
	{
		 if((ereg("Nav", getenv("HTTP_USER_AGENT"))) || 
		    (ereg("Gold", getenv("HTTP_USER_AGENT"))) || 
		    (ereg("X11", getenv("HTTP_USER_AGENT"))) ||
		    (ereg("Mozilla", getenv("HTTP_USER_AGENT"))) || 
		    (ereg("Netscape", getenv("HTTP_USER_AGENT"))) AND 
		    (!ereg("MSIE", getenv("HTTP_USER_AGENT")))) 
				return "Netscape";
		elseif(ereg("MSIE", getenv("HTTP_USER_AGENT")))
				return "MSIE";
		
		return "Other";
	}

	// Prints treeview
	function PrintTreeView($user, $user_id, $netscape = false)
	{
		// Get user's nodes
		$selnodes = $user->GetUserNodes($user_id);

		//Start printing tree
		if (!$netscape)
		{
			print "var TREE_NODES = [";
			PrintNetworks($user_id, $user, $selnodes);
			print "['";
			print "<input type=\"Submit\" name=\"Update\" value=\"Update\">";
			print "', null, null]";
			print "];\n";
		}
		else
		{
			PrintNetworks($user_id, $user, $selnodes, true);
			print "<input type=\"Submit\" name=\"Update\" value=\"Update\">";
		}
	}

	// Adds networks to treeview
	function PrintNetworks($user_id, $user, $selnodes, $netscape = false)
	{
		$net = new Network();
		$network = $net->GetNetworks();
		$formprinted = false;

		if ($netscape)
		{
			while (List($network_id, $network_name) = $net->FetchRow($network))
			{
				print "<table border=\"0\" width=\"495px\" bgcolor=\"#d7d7d7\" cellpadding=\"0\" cellspacing=\"0\">";
				print "<tr>";
				print "<td width=\"495px\" class=\"$css_class\">$network_name</td>";
				print "</tr>";
				print "</table>";
				PrintNodes($user_id, $net, $network_id, $selnodes, true);
			}
		}
		else
		{
			while (List($network_id, $network_name) = $net->FetchRow($network))
			{
				print "['";
				print "<table border=\"0\" width=\"495px\" bgcolor=\"#d7d7d7\" cellpadding=\"0\" cellspacing=\"0\">";
				print "<tr>";
				print "<td width=\"495px\" class=\"$css_class\">$network_name</td>";
				print "</tr>";
				print "</table>";
				print "', null, null,";
				PrintNodes($user_id, $net, $network_id, $selnodes);
				print "],\n";
			}
		}
	}

	// Prints all nodes under network $network_id
	function PrintNodes($user_id, $net, $network_id, $selnodes, $netscape = false)
	{
		
		$bgcolor = "bgcolor=#eaeaea";
		$nodes = $net->GetNodes(0, $network_id);

		if ($netscape)
		{
			while (List($node_id, $parent_node_id, $node_name, $node_pass, $node_ip, $location, $monitor, $log, $signal, $alarm, $node_type_name, $network_name) = $net->FetchRow($nodes))
			{
				$css_class = GetNodeCssClass($status);

				in_array($node_id, $selnodes) ? $checked="checked" : $checked="";
				
				print "<table border=0 width=479 $bgcolor cellpadding=0 cellspacing=0>";
				print "<tr>";
				print "<td width=20px align=left><input type=checkbox name=node$node_id value=$node_id $checked></td>";
				print "<td width=116px>$node_name</td>";
				print "<td width=100px><b>$node_ip</b></td>";
				print "<td width=100px>$node_type_name</td>";
				print "<td width=143px>$location</td>";
				print "</tr>";
				print "</table>";
			}
		}
		else
		{
			while (List($node_id, $parent_node_id, $node_name, $node_pass, $node_ip, $location, $monitor, $log, $signal, $alarm, $node_type_name, $network_name) = $net->FetchRow($nodes))
			{
				$css_class = GetNodeCssClass($status);

				in_array($node_id, $selnodes) ? $checked="checked" : $checked="";
				
				print "['";
				print "<table border=0 width=479 $bgcolor cellpadding=0 cellspacing=0>";
				print "<tr>";
				print "<td width=20px align=left><input type=checkbox name=node$node_id value=$node_id $checked></td>";
				print "<td width=116px>$node_name</td>";
				print "<td width=100px><b>$node_ip</b></td>";
				print "<td width=100px>$node_type_name</td>";
				print "<td width=143px>$location</td>";
				print "</tr>";
				print "</table>";
				print "', null, null";		
				print "],\n";
			}
		}
	}

	// Shows profile menu
	function ShowMenu($user,$name,$user_id)
    {
        if ($user->IsAdmin())
        {
            if ($user_id == 0)
                print "\n<td height=19>[ your nodes ]</td>\n";
            else
                print "\n<td height=19>[ <a href=selnodes.php?id=id0>your nodes</a> ]</td>\n";

            print "<td height=19>[ <a href=profile.php?id=0>your details</a> ]</td>\n";
			print "<td>[ <a href=prefs.php>preferences</a> ]</td>";

            print "</tr>\n</table>\n<table align=center>\n<tr>\n";

            if ($user_id != 0)
            {
                print "<td height=19>[ $name's nodes ]</td>\n";
                print "<td height=19>[ <a href=profile.php?id=$user_id>$name's details</a> ]</td></tr>\n</table>\n<table align=center>\n<tr>\n";
            }

            print "<td height=19>[ <a href=allusers.php>users</a> ]</td>\n";
        }
        else
        {
            print "\n<td height=19>[ <a href=profile.php>your details</a> ]</td>\n";
            print "<td height=19>[ your nodes ]</td>\n";
			print "<td>[ <a href=prefs.php>preferences</a> ]</td>";
        }
    } 
?>

<html>
    <head>
		<link href="css/style1.css" rel="styleSheet" type="text/css"> 
        <title>WaveWatcher</title>
		<link href="css/tree.css" rel="styleSheet" type="text/css">
		<link href="css/monitor.css" rel="styleSheet" type="text/css">
		<script language="JavaScript" src="js/tooltip.js"></script>
		<script language="JavaScript" src="js/selnodes_format.js"></script>
		<script language="JavaScript" src="js/nostree.js"></script>

    </head>
    <body bgcolor="#ffffff">
<?include("menuinclude.php");?>
		<br><br>
		<table align="center">
			<tr>
				<? ShowMenu($user,$name,$user_id) ?>
			</tr>
		</table>
		<br>
		<form method=post>
		Nodes to monitor for user <b><i><?= $name ?>.</i></b><br><br>
			<!-- Generate Tree -->

			<? 
				if (GetBrowser() == 'Netscape')
				{
					PrintTreeView($user, $user_id, true);
				}
				else
				{
					print "<script language=\"JavaScript\">\n";
					
					PrintTreeView($user, $user_id);
					
					print "// Create FolderView\n";
					print "var treeName = \"Tree\"\n";
					print "new NosTree (treeName, TREE_NODES, TREE_FORMAT);\n";
					print "</script>\n";
				}
			?>
		</form>
	</body>
</html>














Return current item: WaveWatcher