Location: PHPKode > projects > OpenDataCenter Network Management System > include/mainview_page/network/view.php
<?php
// ----------------------------------------------------------------------
// Copyright (C) 2007 by GREGORY LE BRAS
// ----------------------------------------------------------------------
// LICENSE
//
// This file is part of ODCNMS - Open DataCenter Network Management System
// 
// ODCNMS is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
// 
// Foobar is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with Foobar; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
// ----------------------------------------------------------------------
// Original Author of file: GREGORY LE BRAS - http://www.odcnms.org/
// ----------------------------------------------------------------------
?>
<?php
$request=mysql_query("SELECT * FROM $name_table_network WHERE id=\"$id\"") or die ("ERROR!");

while($tmp_request=mysql_fetch_array($request))
{
$network_name = $tmp_request['name'];
$cidr = find_net($tmp_request['address'],$tmp_request['mask']);
?>
<table class="subtitle" width="100%" cellspacing="0" cellpadding="0">
	<tr>
		<td width="84%"><h4><img src="images/network.gif" alt="Network" align="top"> <?php echo $tmp_request['name']; ?></h4></td>
		<td width="8%" style="text-align:right">[ <a href="index.php?include=mainview&page=network&action=edit&id=<?php echo $id; ?>"><?php echo TXT_EDIT; ?></a> ]</td>
		<td width="8%" style="text-align:right">[ <a href="index.php?include=mainview&page=network&action=delete&id=<?php echo $id; ?>"><?php echo TXT_DELETE; ?></a> ]</td>
	<tr>
</table>
<table class="list" width="100%" cellspacing="2" cellpadding="3">
	<tr class="list_title">
		<td width="100%" style="font-weight:normal;"><b><?php echo TXT_ADDRESS; ?>:</b> <?php echo $tmp_request['address']; ?></td>
	</tr>
	<tr class="list_title">
		<td width="100%" style="font-weight:normal;"><b><?php echo TXT_MASK; ?>:</b> <?php echo $tmp_request['mask']; echo " (".$cidr['cidr'].")";?></td>
	</tr>	
	<tr class="list_title">
		<td width="100%" style="font-weight:normal;"><b><?php echo TXT_DESCRIPTION; ?>:</b> <?php echo $tmp_request['description']; ?></td>
	</tr>
</table>

<table class="subtitle" width="100%" cellspacing="0" cellpadding="0">
	<tr>
		<td width="70%"><h4><img src="images/subnetwork.gif" alt="Subnet" align="top"> <?php echo TXT_ALL; ?> "<?php echo $network_name; ?>" <?php echo TXT_SUBNETS; ?></h4></td>
		<td width="30%" style="text-align:right">[ <a href="index.php?include=mainview&page=subnet&action=manually_add&network_ident2=<?php echo $id; ?>">Manually <?php echo TXT_ADD; ?></a> ] [ <a href="index.php?include=mainview&page=subnet&action=automatically_add&network_ident=<?php echo $id; ?>">Automatically <?php echo TXT_ADD; ?></a> ]</td>
	<tr>
</table>
<table class="list" width="100%" cellspacing="2" cellpadding="3">
<tr class="list_title" style="font-weight: bold;background-color: #ededed;">
	<td style="padding:2px;"><?php echo TXT_NAME; ?></td>
	<td style="padding:2px;"><?php echo TXT_ADDRESS; ?> /CIDR</td>
	<td style="padding:2px;"><?php echo TXT_CUSTOMERS; ?></td>
	<td style="padding:2px;"><?php echo TXT_VLAN; ?></td>
	<td style="padding:2px;"><?php echo TXT_STATUS; ?></td>
	<td style="padding:2px;"><?php echo TXT_DESCRIPTION; ?></td>
	<td style="padding:2px;"><?php echo TXT_ACTION; ?></td>
</tr>
<?php
$list1 = "list1"; 
$list2 = "list2"; 
$line_count = 0; 
$subnet_count = 0; 
$vlan_array = array();

$request=mysql_query("select * FROM $name_table_subnet WHERE network_id=$id ORDER BY id ASC") or die ("ERROR!");

while($tmp_request=mysql_fetch_array($request))
{
$line_color = ($line_count % 2) ? $list1 : $list2;

$cidr = find_net($tmp_request['address'],$tmp_request['mask']);

?>
<tr class="<?php echo "$line_color"; ?>">
<td width="15%"><?php print("<a href=\"index.php?include=mainview&page=subnet&action=view&id=$tmp_request[id]\">$tmp_request[name]</a>"); ?></td>
<td width="10%"><?php echo $tmp_request['address']." ".$cidr['cidr'];?></td>
<td width="15%"><select><?php 
$request2=mysql_query("select * FROM $name_table_link_customer_subnet WHERE subnet_id=$tmp_request[id]") or die ("ERROR!");

while($tmp_request2=mysql_fetch_array($request2))
{
	$request3=mysql_query("select id,name FROM $name_table_customer WHERE id=$tmp_request2[customer_id]") or die ("ERROR!");

	while($tmp_request3=mysql_fetch_array($request3))
	{
		echo "<option value=\"$tmp_request3[id]\">$tmp_request3[name]</option>";
	}
}
?></select></td>
<td width="10%"><?php 

$request2=mysql_query("select * FROM $name_table_link_subnet_vlan WHERE subnet_id=$tmp_request[id]") or die ("ERROR!");

while($tmp_request2=mysql_fetch_array($request2))
{
	$request3=mysql_query("select id,name FROM $name_table_vlan WHERE id=$tmp_request2[vlan_id]") or die ("ERROR!");

	while($tmp_request3=mysql_fetch_array($request3))
	{
		array_push($vlan_array,"$tmp_request3[id]");
		echo "<a href=\"$tmp_request3[id]\">$tmp_request3[name]</a>";
	}
}
?></td>
<td width="8%" align="center"><?php			
switch ($tmp_request['status'])
{
	case '0':
	echo "<p style='margin:0px;background:#0000ff;color:#fff'>";
	echo TXT_ASSIGNED;
	echo "</p>";
	break;
	
	case '1':
	echo "<p style='margin:0px;background:#00ff00;color:#fff'>";
	echo TXT_UNUSED;
	echo "</p>";
	break;

	case '2':
	echo "<p style='margin:0px;background:#ff0000;color:#fff'>";
	echo TXT_RESERVED;
	echo "</p>";
	break;
	
}
?></td>
<td width="20%"><?php echo $tmp_request['description']; ?></td>
<td width="12%">[ <?php print("<a href=\"index.php?include=mainview&page=subnet&action=edit&id=$tmp_request[id]\">");
echo TXT_EDIT; echo "</a>"; ?> ] [ <?php print("<a href=\"index.php?include=mainview&page=subnet&action=delete&id=$tmp_request[id]\">"); echo TXT_DELETE; echo "</a>"; ?> ]</td></tr>
<?php
$line_count++;
$subnet_count++;
}
echo "</table>";
?>

<table class="subtitle" width="100%" cellspacing="0" cellpadding="0">
	<tr>
		<td width="90%"><h4><img src="images/vlan.gif" alt="vlan" align="top"> <?php echo TXT_ALL; ?> "<?php echo $network_name; ?>" <?php echo TXT_VLANS; ?></h4></td>
		<td width="10%" style="text-align:right">[ <a href="index.php?include=mainview&page=vlan&action=add"><?php echo TXT_ADD; ?></a> ]</td>
	<tr>
</table>
<table class="sortable list" id="sortable" width="100%" cellspacing="2" cellpadding="3">
	<tr class="list_title">
		<td width="20%" valign="top"><?php echo TXT_NAME; ?></td>
		<td width="20%" valign="top"><?php echo TXT_NUMBER; ?></td>
		<td width="48%" valign="top"><?php echo TXT_DESCRIPTION; ?></td>
		<td width="12%" valign="top" class="unsortable"><?php echo TXT_ACTION; ?></td>
	</tr>
<?php
	$list1 = "list1"; 
	$list2 = "list2"; 
	$line_count = 0; 
	$vlan_count = 0; 
	
	if (!empty($vlan_array))
	{
		$result_vlan = array_unique ($vlan_array);
		foreach ($result_vlan as $key => $arrayvalue)
		{
			$request6=mysql_query("SELECT * FROM $name_table_vlan WHERE id=\"$arrayvalue\"") or die ("ERROR!");
			while($tmp_request6=mysql_fetch_array($request6))
			{
				$line_color = ($line_count % 2) ? $list1 : $list2;
				echo "<tr class=\"$line_color\">
				<td width=\"20%\" valign=\"top\"><a href=\"index.php?include=mainview&page=vlan&action=view&id=$tmp_request6[id]\">$tmp_request6[name]</a></td>
				<td width=\"20%\" valign=\"top\">$tmp_request6[number]</td>
				<td width=\"48%\" valign=\"top\">$tmp_request6[description]</td>
				<td width=\"12%\" valign=\"top\">[ <a href=\"index.php?include=mainview&page=vlan&action=edit&id=$tmp_request6[id]\">";
				echo TXT_EDIT;
				echo "</a> ] [ <a href=\"index.php?include=mainview&page=vlan&action=delete&id=$tmp_request6[id]\">";
				echo TXT_DELETE;
				echo "</a> ]</td>
				</tr>";
				$line_count++;
				$vlan_count++;
			}
		}
	}
?>	
</table>


<table class="subtitle" width="100%" cellspacing="0" cellpadding="0">
	<tr>
		<td width="90%"><h4><img src="images/location.gif" alt="Location" align="top"> <?php echo TXT_ALL; ?> "<?php echo $network_name; ?>" <?php echo TXT_LOCATIONS; ?></h4></td>
		<td width="10%" style="text-align:right">[ <a href="index.php?include=mainview&page=location&action=add"><?php echo TXT_ADD; ?></a> ]</td>
	<tr>
</table>
<table class="sortable list" id="sortable" width="100%" cellspacing="2" cellpadding="3">
	<tr class="list_title">
		<td width="28%" valign="top"><?php echo TXT_NAME; ?></td>
		<td width="60%" valign="top"><?php echo TXT_DESCRIPTION; ?></td>
		<td width="12%" valign="top" class="unsortable"><?php echo TXT_ACTION; ?></td>
	</tr>
<?php
	$list1 = "list1"; 
	$list2 = "list2"; 
	$line_count = 0; 
	$location_count = 0; 
	
	$location_array = array();
	
	$request4=mysql_query("SELECT id FROM $name_table_subnet WHERE network_id=\"$id\"") or die ("ERROR!");
	while($tmp_request4=mysql_fetch_array($request4))
	{
		$request5=mysql_query("SELECT id FROM $name_table_ip_address WHERE subnet_id=\"$tmp_request4[id]\"") or die ("ERROR!");
		while($tmp_request5=mysql_fetch_array($request5))
		{
			$request6=mysql_query("SELECT rack_id FROM $name_table_device WHERE ip_address_id=\"$tmp_request5[id]\"") or die ("ERROR!");
			while($tmp_request6=mysql_fetch_array($request6))
			{
				$request7=mysql_query("SELECT location_id FROM $name_table_rack WHERE id=\"$tmp_request6[rack_id]\"") or die ("ERROR!");
				while($tmp_request7=mysql_fetch_array($request7))
				{
					array_push ($location_array, "$tmp_request7[location_id]");
				}
			}
		}
	}
	$result = array_unique ($location_array);
	foreach ($result as $key => $arrayvalue)
	{
		$request8=mysql_query("SELECT id,name,description FROM $name_table_location WHERE id=\"$arrayvalue\"") or die ("ERROR!");
		while($tmp_request8=mysql_fetch_array($request8))
		{
			$line_color = ($line_count % 2) ? $list1 : $list2;
			echo "<tr class=\"$line_color\">
			<td width=\"28%\" valign=\"top\"><a href=\"index.php?include=mainview&page=location&action=view&id=$tmp_request8[id]\">$tmp_request8[name]</a></td>
			<td width=\"60%\" valign=\"top\">$tmp_request8[description]</td>
			<td width=\"12%\" valign=\"top\">[ <a href=\"index.php?include=mainview&page=location&action=edit&id=$tmp_request8[id]\">";
			echo TXT_EDIT;
			echo "</a> ] [ <a href=\"index.php?include=mainview&page=location&action=delete&id=$tmp_request8[id]\">";
			echo TXT_DELETE;
			echo "</a> ]</td>
			</tr>";
			$line_count++;
			$location_count++;
		}
	}
?>	
</table>

<table class="subtitle" width="100%" cellspacing="0" cellpadding="0">
	<tr>
		<td width="90%"><h4><img src="images/customer.gif" alt="Customer" align="top"> <?php echo TXT_ALL; ?> "<?php echo $network_name; ?>" <?php echo TXT_CUSTOMERS; ?></h4></td>
		<td width="10%" style="text-align:right">[ <a href="index.php?include=mainview&page=customer&action=add"><?php echo TXT_ADD; ?></a> ]</td>
	<tr>
</table>
<table class="sortable list" id="sortable" width="100%" cellspacing="2" cellpadding="3">
	<tr class="list_title">
		<td width="28%" valign="top"><?php echo TXT_NAME; ?></td>
		<td width="60%" valign="top"><?php echo TXT_DESCRIPTION; ?></td>
		<td width="12%" valign="top" class="unsortable"><?php echo TXT_ACTION; ?></td>
	</tr>
<?php
	$list1 = "list1"; 
	$list2 = "list2"; 
	$line_count = 0; 
	$customer_count = 0; 
	
	$customerarray = array();
	
	$request4=mysql_query("SELECT id FROM $name_table_subnet WHERE network_id=\"$id\"") or die ("ERROR!");
	while($tmp_request4=mysql_fetch_array($request4))
	{
		$request5=mysql_query("SELECT customer_id FROM $name_table_link_customer_subnet WHERE subnet_id=\"$tmp_request4[id]\"") or die ("ERROR!");
		while($tmp_request5=mysql_fetch_array($request5))
		{
			$request6=mysql_query("SELECT id FROM $name_table_customer WHERE id=\"$tmp_request5[customer_id]\"") or die ("ERROR!");
			while($tmp_request6=mysql_fetch_array($request6))
			{
				array_push ($customerarray, "$tmp_request6[id]");
			}
		}
	}
	$result = array_unique ($customerarray);
	foreach ($result as $key => $arrayvalue)
	{
		$request6=mysql_query("SELECT id,name,description FROM $name_table_customer WHERE id=\"$arrayvalue\"") or die ("ERROR!");
		while($tmp_request6=mysql_fetch_array($request6))
		{
			$line_color = ($line_count % 2) ? $list1 : $list2;
			echo "<tr class=\"$line_color\">
			<td width=\"28%\" valign=\"top\"><a href=\"index.php?include=mainview&page=customer&action=view&id=$tmp_request6[id]\">$tmp_request6[name]</a></td>
			<td width=\"60%\" valign=\"top\">$tmp_request6[description]</td>
			<td width=\"12%\" valign=\"top\">[ <a href=\"index.php?include=mainview&page=customer&action=edit&id=$tmp_request6[id]\">";
			echo TXT_EDIT;
			echo "</a> ] [ <a href=\"index.php?include=mainview&page=customer&action=delete&id=$tmp_request6[id]\">";
			echo TXT_DELETE;
			echo "</a> ]</td>
			</tr>";
			$line_count++;
			$customer_count++;
		}
	}
?>	
</table>

<table class="subtitle" width="100%" cellspacing="0" cellpadding="0">
	<tr>
		<td width="90%"><h4><img src="images/device.gif" alt="Device" align="top"> <?php echo TXT_ALL; ?> "<?php echo $network_name; ?>" <?php echo TXT_DEVICES; ?></h4></td>
		<td width="10%" style="text-align:right">[ <a href="index.php?include=mainview&page=device&action=add"><?php echo TXT_ADD; ?></a> ]</td>
	<tr>
</table>
<table class="sortable list" id="sortable" width="100%" cellspacing="2" cellpadding="3">
	<tr class="list_title">
		<td valign="top"><?php echo TXT_NAME; ?></td>
		<td valign="top"><?php echo TXT_ADDRESS; ?></td>
		<td valign="top"><?php echo TXT_MANUFACTURER; ?></td>
		<td valign="top"><?php echo TXT_CATEGORY; ?></td>
		<td valign="top"><?php echo TXT_MODEL; ?></td>
		<td valign="top"><?php echo TXT_LOCATION; ?></td>
		<td valign="top"><?php echo TXT_RACK; ?></td>
		<td valign="top"><?php echo TXT_DESCRIPTION; ?></td>
		<td class="unsortable" width="12%" valign="top"><?php echo TXT_ACTION; ?></td>
	</tr>
<?php
	$list1 = "list1"; 
	$list2 = "list2"; 
	$line_count = 0; 
	$device_count = 0; 
	
	$device_array = array();
	
	$request2=mysql_query("SELECT id FROM $name_table_subnet WHERE network_id=\"$id\"") or die ("ERROR!");
	while($tmp_request2=mysql_fetch_array($request2))
	{
		$request_ip=mysql_query("SELECT id FROM $name_table_ip_address WHERE subnet_id=\"$tmp_request2[id]\"") or die ("ERROR!");
		while($tmp_request_ip=mysql_fetch_array($request_ip))
		{
			$request_device=mysql_query("SELECT * FROM $name_table_device WHERE ip_address_id=\"$tmp_request_ip[id]\"") or die ("ERROR!");
			while($tmp_request_device=mysql_fetch_array($request_device))
			{
				array_push ($device_array, "$tmp_request_device[id]");
			}
			
			$request_link_device_ip_address=mysql_query("SELECT device_id FROM $name_table_link_device_ip_address WHERE ip_address_id=$tmp_request_ip[id]") or die ("ERROR!");

			while($tmp_request_device_ip_address=mysql_fetch_array($request_link_device_ip_address))
			{
				array_push ($device_array, "$tmp_request_device_ip_address[device_id]");
			}
		}
	}
	
	$result = array_unique ($device_array);
	foreach ($result as $key => $arrayvalue)
	{

	$request3=mysql_query("SELECT * FROM $name_table_device WHERE id=$arrayvalue") or die ("ERROR!");

	while($tmp_request3=mysql_fetch_array($request3))
	{
					$line_color = ($line_count % 2) ? $list1 : $list2;
			?>
			<tr class="<?php echo "$line_color"; ?>">
				<td valign="top"><?php print("<a href=\"index.php?include=mainview&page=device&action=view&id=$tmp_request3[id]\">$tmp_request3[name]</a>"); ?></td>
				<td valign="top"><?php 
				$request4=mysql_query("SELECT id,ip FROM $name_table_ip_address WHERE id=$tmp_request3[ip_address_id]") or die ("ERROR!");
				
				while($tmp_request4=mysql_fetch_array($request4))
				{
					echo "<a href=\"index.php?include=mainview&page=ip_address&action=view&id=$tmp_request4[id]\">".$tmp_request4['ip']."</a>";
				}
				?></td>
				<td valign="top"><?php 
				$request5=mysql_query("SELECT id,name,manufacturer_id FROM $name_table_model WHERE id=$tmp_request3[model_id]") or die ("ERROR!");
				
				while($tmp_request5=mysql_fetch_array($request5))
				{
					$request6=mysql_query("SELECT id,name FROM $name_table_manufacturer WHERE id=$tmp_request5[manufacturer_id]") or die ("ERROR!");
					
					while($tmp_request6=mysql_fetch_array($request6))
					{
						echo "<a href=\"index.php?include=mainview&page=manufacturer&action=view&id=$tmp_request6[id]\">".$tmp_request6['name']."</a>";
					}
				}
				?></td>
				<td valign="top"><?php 
				$request7=mysql_query("SELECT id,name,category_id FROM $name_table_model WHERE id=$tmp_request3[model_id]") or die ("ERROR!");
				
				while($tmp_request7=mysql_fetch_array($request7))
				{
					$request8=mysql_query("SELECT id,name FROM $name_table_category WHERE id=$tmp_request7[category_id]") or die ("ERROR!");
					
					while($tmp_request8=mysql_fetch_array($request8))
					{
						echo "<a href=\"index.php?include=mainview&page=category&action=view&id=$tmp_request8[id]\">".$tmp_request8['name']."</a>";
					}
				}			
				?></td>
				<td valign="top"><?php 
				$request9=mysql_query("SELECT id,name FROM $name_table_model WHERE id=$tmp_request3[model_id]") or die ("ERROR!");
				
				while($tmp_request9=mysql_fetch_array($request9))
				{
					echo "<a href=\"index.php?include=mainview&page=model&action=view&id=$tmp_request9[id]\">".$tmp_request9['name']."</a>";
				}
				?></td>
				<td valign="top"><?php 
				$request10=mysql_query("SELECT id,name,location_id FROM $name_table_rack WHERE id=$tmp_request3[rack_id]") or die ("ERROR!");
				
				while($tmp_request10=mysql_fetch_array($request10))
				{
					$request11=mysql_query("SELECT id,name FROM $name_table_location WHERE id=$tmp_request10[location_id]") or die ("ERROR!");
					
					while($tmp_request11=mysql_fetch_array($request11))
					{
						echo "<a href=\"index.php?include=mainview&page=location&action=view&id=$tmp_request11[id]\">".$tmp_request11['name']."</a>";
					}
				}
				?></td>
				<td valign="top"><?php 
				$request12=mysql_query("SELECT id,name FROM $name_table_rack WHERE id=$tmp_request3[rack_id]") or die ("ERROR!");
				
				while($tmp_request12=mysql_fetch_array($request12))
				{
					echo "<a href=\"index.php?include=mainview&page=rack&action=view&id=$tmp_request12[id]\">".$tmp_request12['name']."</a>";
				}

				?></td>
				<td valign="top"><?php echo $tmp_request3['description']; ?></td>
				<td valign="top">[ <?php print("<a href=\"index.php?include=mainview&page=device&action=edit&id=$tmp_request3[id]\">");
				echo TXT_EDIT;
				echo "</a>"; ?> ] [ <?php print("<a href=\"index.php?include=mainview&page=device&action=delete&id=$tmp_request3[id]\">");
				echo TXT_DELETE;
				echo "</a>"; ?> ]</td>	
			</tr>
			<?php
				$device_count++;
			}
		}
?>	
</table>

<table class="subtitle" width="100%" cellspacing="0" cellpadding="0">
	<tr>
		<td width="100%"><h4><img src="images/stats.gif" alt="Stats" align="top"> <?php echo TXT_STATS; ?></h4></td>
	<tr>
</table>
<table class="list" width="100%" cellspacing="2" cellpadding="3">
	<tr class="list_title">
		<td width="100%" style="font-weight:normal;"><img src="images/subnetwork.gif" alt="subnet" align="top"> <b><?php echo TXT_SUBNET; ?> :</b>
		<?php echo "$subnet_count";?> <?php echo TXT_SUBNETS; ?></td>
	</tr>
	<tr class="list_title">
		<td width="100%" style="font-weight:normal;"><img src="images/vlan.gif" alt="vlan" align="top"> <b><?php echo TXT_VLAN; ?> :</b>
		<?php echo "$vlan_count";?>	<?php echo TXT_VLANS; ?></td>
	</tr>
	<tr class="list_title">
		<td width="100%" style="font-weight:normal;"><img src="images/location.gif" alt="location" align="top"> <b><?php echo TXT_LOCATION; ?> :</b>
		<?php echo "$location_count";?>	<?php echo TXT_LOCATIONS; ?></td>
	</tr>
	<tr class="list_title">
		<td width="100%" style="font-weight:normal;"><img src="images/customer.gif" alt="Customer" align="top"> <b><?php echo TXT_CUSTOMER; ?> :</b>
		<?php echo "$customer_count";?>	<?php echo TXT_CUSTOMERS; ?></td>
	</tr>
	<tr class="list_title">
		<td width="100%" style="font-weight:normal;"><img src="images/device.gif" alt="Device" align="top"> <b><?php echo TXT_DEVICE; ?> :</b>
		<?php echo "$device_count";?> <?php echo TXT_DEVICES; ?></td>
	</tr>		
</table>

<br><center><a href="javascript:history.go(-1);"><?php echo TXT_BACK; ?></a></center>
<?php
}
?>
Return current item: OpenDataCenter Network Management System