<?php

function T_TELBOX_NEIGHBOUR_IN_SELECT() {
	global $thiss,$result;

	$add_info = '';
	$field_name = 'T_TELBOX_NEIGHBOUR_IN';
	$select_list = array();

	$sql_where = '';
	if (!empty($_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD']['T_NETWORK_SERVER'])) {
		$sql_where = " and T_NETWORK_SERVER='{$_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD']['T_NETWORK_SERVER']}' ";
		$add_info .= ' <em>' . "Tylko telboxy z T_NETWORK_SERVER='{$_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD']['T_NETWORK_SERVER']}'" . '</em>';
	}

	$sql = "select T_TELBOX_NAME, T_TELBOX_TYPE
		from TELBOXES
		where A_STATUS in('NORMAL','WAITING','WARNING')
			and A_ADM_COMPANY like '{$_SESSION['ADM_COMPANY']}'
			{$sql_where}
		order by T_TELBOX_NAME
	";
	ZAP_SQL($sql);

	while ($r = mysql_fetch_object($result)) {
		$select_list [$r->T_TELBOX_NAME] = "" . $r->T_TELBOX_NAME . " (" . $r->T_TELBOX_TYPE . ")";
	}

	if (empty($_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD']['T_NETWORK_SERVER'])) {
		$sql = "select T_NETWORK_SERVER, S_ADDRESS_STREET
			from NETWORKS_SERVERS
			where A_STATUS='NORMAL'
				and A_ADM_COMPANY like '{$_SESSION['ADM_COMPANY']}'
			order by T_NETWORK_SERVER
		";
		ZAP_SQL($sql);

		while ($r = mysql_fetch_object($result)) {
			$select_list [$r->T_NETWORK_SERVER] = "" . $r->T_NETWORK_SERVER . " (" . $r->S_ADDRESS_STREET . ")";
		}
	}

	echo '<select name="' . $field_name . '">';
		echo ' <option value="">' . " " . '</option>';
		if (!empty($_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD'][$field_name]) && !array_key_exists($_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD'][$field_name], $select_list)) {
			echo ' <option value="' . $_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD'][$field_name] . '">' . $_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD'][$field_name] . '</option>';
		}
		foreach ($select_list as $key => $val) {
			$sel = ($_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD'][$field_name] == $key)? ' selected="selected"' : '';
			echo '<option value="' . $key . '"' . $sel . '>' . $val . '</option>';
		}
		if (!empty($_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD']['T_NETWORK_SERVER']) && !array_key_exists($_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD']['T_NETWORK_SERVER'], $select_list)) {
			echo ' <option value="' . $_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD']['T_NETWORK_SERVER'] . '">' . $_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD']['T_NETWORK_SERVER'] . '</option>';
		}
	echo '</select>';
	echo ' ' . $add_info;
}
