<?php

/*
** SellaNMS
** $Id: connectionlister_template.php,v 1.12 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);

if ($data['router']) {
	$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_element.id = '%d' AND 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", $data['router']);

//	$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, 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 dst_interface_name WHERE src_element.id = '%d' AND 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 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 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", $data['router']);

	$result = mysql_query($sql, $db);
?>
	<TABLE WIDTH="100%" CELLSPACING="1" CELLPADDING="0" BORDER="0">
		<TR>
			<TD CLASS="tbltitle" COLSPAN="5">
				Connections: <?php printf("%d\n", mysql_affected_rows($db)); ?>
			</TD>
		</TR>
		<TR CLASS="tblhdr">
			<TD NOWRAP>&nbsp;Admin&nbsp;</TD>
			<TD NOWRAP>&nbsp;Oper&nbsp;</TD>
			<TD NOWRAP>&nbsp;Local Interface&nbsp;&nbsp;</TD>
			<TD NOWRAP>&nbsp;Remote Element&nbsp;&nbsp;</TD>
			<TD WIDTH="100%" NOWRAP>&nbsp;Remote Interface&nbsp;&nbsp;</TD>
		</TR>

<?php while ($row = mysql_fetch_array($result)) { ?>
		<TR CLASS="tblentry">
			<!-- FIXME: The up/down/etc translation should be done by snmp discovery. -->
			<TD>&nbsp;<?php printf('%s', ($row['src_if_admin'] == 1) ? 'up' : 'down'); ?>&nbsp;</TD>
			<TD>&nbsp;<?php printf('%s', ($row['src_if_oper'] == 1) ? 'up' : 'down'); ?>&nbsp;</TD>
			<TD>&nbsp;<?php printf('<A TARGET="interfaceviewer" HREF="sella_nms-interfaceviewer.php?interface=%d&rand=%d">%s</A>', $row['src_if_id'], rand(0, getrandmax()), $row['src_if']); ?>&nbsp;</TD>
			<TD>&nbsp;<?php printf('<A TARGET="browserbody" HREF="sella_nms-browserbody.php?function=Display&router=%d&rand=%d">%s</A>', $row['dst_el_id'], rand(0, getrandmax()), $row['dst_el']); ?>&nbsp;</TD>
			<TD>&nbsp;<?php printf('<A TARGET="browserbody" HREF="sella_nms-browserbody.php?function=Display&router=%d&interface=%d&rand=%d">%s</A>', $row['dst_el_id'], $row['dst_if_id'], rand(0, getrandmax()), $row['dst_if']); ?>&nbsp;&nbsp;&nbsp;</TD>
		</TR>
<?php } ?>

	</TABLE>
<?php } ?>

<?php
/*
** Local Variables:
** c-basic-offset: 3
** tab-width: 3
** End:
** vim600: fdm=marker
** vim: noet ts=3 sw=3
*/
?>
