<TABLE BORDER="0" CELLSPACING="1" CELLPADDING="0" WIDTH="100%">

<?php

/*
** SellaNMS
** $Id: topology_template.php,v 1.11 2005/08/22 02:25:41 sella Exp $
** Copyright (c) 2001 Digital Genesis Software, LLC. All Rights Reserved.
** Released under the GPL Version 2 License.
** http://www.digitalgenesis.com
*/

require_once('../config/config.php');
require_once('../libs/dgsutil/cgi.php');
require_once('../libs/util.php');

$data = getFormData();

$db = mysql_connect($config['databaseServer'], $config['databaseUsername'], $config['databasePassword']);
mysql_select_db($config['databaseName'], $db);
	$sql = sprintf("SELECT DISTINCT src_element.id AS src_el_id, src_interface.id AS src_if_id, dst_element.id AS dst_el_id, dst_interface.id AS dst_if_id, src_element_name.value AS src_el, src_interface_name.value AS src_if, src_interface_admin.value AS src_if_admin, src_interface_oper.value AS src_if_oper, dst_element_name.value AS dst_el, dst_interface_name.value AS dst_if FROM connection_point AS src LEFT JOIN connection_point AS dst ON ( src.connection = dst.connection ), element AS src_element, element AS dst_element, interface AS src_interface, interface AS dst_interface, ip AS src_ip, ip AS dst_ip, element_data AS src_element_name, element_data AS dst_element_name, interface_data AS src_interface_name, interface_data AS src_interface_admin, interface_data AS src_interface_oper, interface_data AS dst_interface_name WHERE src.point != dst.point AND src_ip.id = src.point AND dst_ip.id = dst.point AND src_interface.id = src_ip.interface AND dst_interface.id = dst_ip.interface AND src_element.id = src_interface.element AND dst_element.id = dst_interface.element AND src_element_name.element = src_element.id AND dst_element_name.element = dst_element.id AND src_interface_name.interface = src_interface.id AND src_interface_admin.interface = src_interface.id AND src_interface_oper.interface = src_interface.id AND dst_interface_name.interface = dst_interface.id AND src_element_name.variable = '.1.3.6.1.2.1.1.5.0' AND src_interface_name.variable = '.1.3.6.1.2.1.2.2.1.2' AND src_interface_admin.variable = '.1.3.6.1.2.1.2.2.1.7' AND src_interface_oper.variable = '.1.3.6.1.2.1.2.2.1.8' AND dst_element_name.variable = '.1.3.6.1.2.1.1.5.0' AND dst_interface_name.variable = '.1.3.6.1.2.1.2.2.1.2' ORDER BY src_el, src_el_id, src_if, dst_el, dst_el_id, dst_if");

$src_el_id = false;
$result = mysql_query($sql, $db);
if (mysql_num_rows($result) < 1) {
?>
	<TR CLASS="tbltitle">
		<TD >No Connections</TD>
	</TR>
<?php

} else {
	while ($row = mysql_fetch_array($result)) {
		if ($row['src_el_id'] != $src_el_id) {
			if ($src_el_id) {
?>
	<TR>
		<TD COLSPAN="5">&nbsp;</TD>
	</TR>
<?php 
			}
			$src_el_id = $row['src_el_id'];
?>
	<TR CLASS="tbltitle">
		<TD NOWRAP COLSPAN="5"><?php printf('Element: %s', strlen($row['src_el']) ? $row['src_el'] : "Unnamed"); ?></TD>
	</TR>
	<TR CLASS="tblhdr">
		<TD NOWRAP>&nbsp;Admin&nbsp;</TD>
		<TD NOWRAP>&nbsp;Oper&nbsp;</TD>
		<TD NOWRAP>&nbsp;Interface&nbsp;</TD>
		<TD NOWRAP COLSPAN="2">&nbsp;Connected Element&nbsp;</TD>
	</TR>

<?php
		}		
?>
	<TR VALIGN="top" CLASS="tblentry">
		<!-- FIXME: The up/down/etc translation should be done by the discovery module. -->
		<TD NOWRAP>&nbsp;<?php printf('%s', ($row['src_if_admin'] == 1) ? 'up' : 'down'); ?>&nbsp;</TD>
		<TD NOWRAP>&nbsp;<?php printf('%s', ($row['src_if_oper'] == 1) ? 'up' : 'down'); ?>&nbsp;</TD>
		<TD NOWRAP>&nbsp;<?php printf('%s', strlen($row['src_if']) ? $row['src_if'] : "Unknown"); ?>&nbsp;</TD>
		<TD NOWRAP>&nbsp;<?php printf('%s', strlen($row['dst_el']) ? $row['dst_el'] : "Unnamed"); ?>&nbsp;</TD>
		<TD NOWRAP WIDTH="100%">&nbsp;<?php printf('%s', strlen($row['dst_if']) ? $row['dst_if'] : "Unknown" ); ?>&nbsp;</TD>
	</TR>
<?php
	}
}
?>

</TABLE>
