<!--// $Id$ //-->

<style>

	.cell-flex {
		display: flex;
		flex-wrap: wrap;
	}

	.cell-flex > *:not(:first-child) {
		margin-left: 0.5em;
	}

</style>

<table class="lmsbox{if $devicepanel} lms-ui-tab-container lms-ui-sortable{/if}" id="netdevinfobox"
	{if $devicepanel} data-label="{trans("Network Device")}"{/if}>
    <colgroup>
		<col style="width: 1%;">
		<col style="width: 99%;">
	</colgroup>
	<thead>
		<tr{if $devicepanel} class="hand lmsbox-titlebar" data-lmsbox-content="devicepanel"{/if}>
			<td>
				{icon name="netdev"}
			</td>
			<td>
				<strong>{$netdev.name} (#{$netdev.id})</strong>
			</td>
		</tr>
	</thead>
	<tbody>
		<tr{if $devicepanel} id="devicepanel" style="display:none;"{/if}>
			<td colspan="2" class="container">
				<table class="lmsbox-inner">
					<colgroup>
						<col style="width: 50%;">
						<col style="width: 50%;">
					</colgroup>
					<tr>
						<td class="valign-top">
							<table class="lmsbox-inner">
								<colgroup>
									<col style="width: 1%;">
									<col style="width: 1%;">
									<col style="width: 98%;">
								</colgroup>
								{if !empty($netdev.division)}
									<tr>
										<td>
											{icon name="division"}
										</td>
										<td class="nobr">
											<strong>{trans("Division")}</strong>
										</td>
										<td>
											<a href="?m=divisionedit&id={$netdev.divisionid}">{$netdev.division|escape} (#{$netdev.divisionid})</a>
										</td>
									</tr>
								{/if}
								{if !empty($netdev.ownerid)}
									<tr>
										<td>
											{icon name="customer"}
										</td>
										<td>
											<strong>{trans("Owner")}</strong>
										</td>
										<td>
											<a href="?m=customerinfo&id={$netdev.ownerid}">
												{$netdev.owner} (#{$netdev.ownerid})
											</a>
										</td>
									</tr>
								{/if}
								<tr>
									<td>
										{icon name="status"}
									</TD>
									<td>
										<strong>{trans("Status")}</strong>
									</td>
									<td>
										{$_NETELEMENTSTATUSES[$netdev.status]}
									</td>
								</tr>
								{if $netdev.producer}
									<tr>
										<td>
											{icon name="hardware"}
										</td>
										<td>
											<strong>{trans("Producer")}</strong>
										</td>
										<td>
											{$netdev.producer}
										</td>
									</tr>
								{/if}
								{if $netdev.type}
									<tr>
										<td>
											{icon name="hardware"}
										</td>
										<td>
											<strong>{trans("Hardware type")}</strong>
										</td>
										<td>
											{$netdev.type}
										</td>
									</tr>
								{/if}
								{if $netdev.model}
									<tr>
										<td>
											{icon name="hardware"}
										</td>
										<td>
											<strong>{trans("Model")}</strong>
										</td>
										<td>
											{$netdev.model}
											{if !empty($netdev.devtypename)}{strip}
												(
												{trans($netdev.devtypename)}
												&nbsp;-&nbsp;
												{if empty($netdev.devtypepassive)}{trans("<!netdevmodeltype>active")}{else}{trans("<!netdevmodeltype>passive")}{/if}
												)
											{/strip}{/if}
										</td>
									</tr>
								{/if}
								{if $netdev.serialnumber}
									<tr>
										<td>
											{icon name="sn"}
										</td>
										<td class="nobr">
											<strong>{trans("Serial number")}</strong>
										</td>
										<td>
											{$netdev.serialnumber}
										</td>
									</tr>
								{/if}
								<tr>
									<td>
										{icon name="port"}
									</td>
									<td class="nobr">
										<strong>{trans("Number of ports")}</strong>
									</td>
									<td>
										{$netdev.ports}
									</td>
								</tr>
								<tr>
									<td>
										{icon name="port-connected"}
									</td>
									<td class="nobr">
										<strong>{trans("Ports used")}</strong>
									</td>
									<td>
										{$netdev.takenports}
									</td>
								</tr>
								{if $netdev.location || ($netdev.netnodeid && $netdev.netnode.location)}
									<tr>
										<td>
											{icon name="home"}
										</td>
										<td class="nobr">
											<strong>{trans("Location")}</strong>
										</td>
										<td>
											{if $netdev.location}
												{if $netdev.location_name}{$netdev.location_name}, {/if}{$netdev.location}
												{if $netdev.borough_name}
													({$netdev.state_name} / {$netdev.district_name} / {$_BOROUGHTYPES[$netdev.borough_type]} {$netdev.borough_name})
												{/if}
												{if !empty($netdev.ownerid) && empty($netdev.address_id)}
													<span class="lms-ui-alert bold">{trans("<!node-location>(implicit)")}</span>
												{/if}
											{else}
												{$netdev.netnode.location}
												{if $netdev.netnode.location_borough_name}
													({$netdev.netnode.location_state_name} / {$netdev.netnode.location_district_name} / {$_BOROUGHTYPES[$netdev.netnode.location_borough_type]} {$netdev.netnode.location_borough_name})
												{/if}
												{trans("(from network node)")}
											{/if}
										</td>
									</tr>
								{/if}
								{if $netdev.longitude || $netdev.latitude || ($netdev.netnodeid && ($netdev.netnode.longitude || $netdev.netnode.latitude))}
									<tr>
										<td>
											{icon name="location"}
										</td>
										<td class="nobr">
											<strong>{trans("GPS longitude")}</strong>
										</td>
										<td>
											{if empty($netdev.longitude)}
												<input id="longitude" type="hidden" value="{$netdev.netnode.longitude}">
												{$netdev.netnode.longitude}
												{trans("(from network node)")}
												{$longitude = $netdev.netnode.longitude}
											{else}
												<input id="longitude" type="hidden" value="{$netdev.longitude}">
												{$netdev.longitude}
												{$longitude = $netdev.longitude}
											{/if}
										</td>
									</tr>
									<tr>
										<td>
											{icon name="location"}
										</td>
										<td class="nobr">
											<strong>{trans("GPS latitude")}</strong>
										</td>
										<td>
											{if empty($netdev.latitude)}
												<input id="longitude" type="hidden" value="{$netdev.netnode.latitude}">
												{$netdev.netnode.latitude}
												{trans("(from network node)")}
												{$latitude = $netdev.netnode.latitude}
											{else}
												<input id="latitude" type="hidden" value="{$netdev.latitude}">
												{$netdev.latitude}
												{$latitude = $netdev.latitude}
											{/if}
										</td>
									</tr>
									<tr>
										<td colspan="2">
										</td>
										<td class="cell-flex">
											{show_on_map_button
												netdevid=$netdev.id
												label=true}
											{show_on_map_button
												type="default"
												latitude=$latitude
												longitude=$longitude
												label=true
											}
											{show_on_map_button
												type="geoportal"
												latitude=$latitude
												longitude=$longitude
												label=true
											}
											{show_on_map_button
												type="netstork"
												latitude=$latitude
												longitude=$longitude
												label=true
											}
										</td>
									</tr>
								{/if}
								{if ConfigHelper::checkConfig('phpui.radius')}
									{if $netdev.shortname}
										<tr>
											<td>
												{icon name="radius"}
											</td>
											<td class="nobr">
												<strong>{trans("Shortname")}</strong>
											</td>
											<td>
												{$netdev.shortname}
											</td>
										</tr>
									{/if}
									{if $netdev.nastype}
										<tr>
											<td>
												{icon name="radius"}
											</td>
											<td class="nobr">
												<strong>{trans("Type")}</strong>
											</td>
											<td>
												{$netdev.nastypename}
											</td>
										</tr>
									{/if}
									{if $netdev.clients}
										<tr>
											<td>
												{icon name="radius"}
											</td>
											<td class="nobr">
												<strong>{trans("Max clients")}</strong>
											</td>
											<td>
												{$netdev.clients}
											</td>
										</tr>
									{/if}
									{if $netdev.login}
										<tr>
											<td>
												{icon name="radius"}
											</td>
											<td class="nobr">
												<strong>{trans("<!radius>Login")}</strong>
											</td>
											<td>
												{$netdev.login}
											</td>
										</tr>
									{/if}
									{if $netdev.secret}
										<tr>
											<td>
												{icon name="radius"}
											</td>
											<td class="nobr">
												<strong>{trans("Secret")}</strong>
											</td>
											<td>
												{if ConfigHelper::checkConfig('phpui.protect_passwords')}
													{button class="lms-ui-button-clipboard" data_clipboard_text="{$netdev.secret}"
														icon="copy" label="Copy"}
												{else}
													{$netdev.secret}
												{/if}
											</td>
										</tr>
									{/if}
									{if $netdev.community}
										<tr>
											<td>
												{icon name="radius"}
											</td>
											<td class="nobr">
												<strong>{trans("Community")}</strong>
											</td>
											<td>
												{$netdev.community}
											</td>
										</tr>
									{/if}
								{/if}
								{if $netdev.channelid}
									<tr>
										<td>
											<img src="img/channel.gif">
										</td>
										<td class="nobr">
											<strong>{trans("Channel")}</strong>
										</td>
										<td>
											<a href="?m=ewxchinfo&id={$netdev.channelid}">
												{$netdev.channel}
												(#{$netdev.channelid})
											</a>
										</td>
									</tr>
								{/if}
							</table>
						</td>
						<td class="valign-top">
							<table class="lmsbox-inner">
								<colgroup>
									<col style="width: 1%;">
									<col style="width: 1%;">
									<col style="width: 98%;">
								</colgroup>
								{if $netdev.purchasetime}
									<tr>
										<td>
											{icon name="calendar"}
										</td>
										<td class="nobr">
											<strong>{trans("Purchase date")}</strong>
										</td>
										<td>
											{$netdev.purchasetime|date_format:"Y-m-d"}
										</td>
									</tr>
								{/if}
								<tr>
									<td>
										{icon name="warranty"}
									</td>
									<td class="nobr">
										<strong>{trans("Warranty")}</strong>
									</td>
									<td>
										{if !$netdev.guaranteeperiod}
											{trans("no guarantee")}
										{elseif $netdev.guaranteeperiod == -1}
											{trans("lifetime")}
										{else}
											{assign var=periodid value=$netdev.guaranteeperiod}
											{$_GUARANTEEPERIODS.$periodid}
												({if $netdev.guaranteetime-$smarty.now < 0}{trans("expired<!guarantee>")}{else}{$netdev.guaranteetime|date_format:"Y-m-d"}{/if})
										{/if}
									</td>
								</tr>
								{if $netdev.description}
								<tr>
									<td>
										{icon name="description"}
									</td>
									<td colspan="2">
										<table style="width: 100%;">
											<tr>
												<td class="fall superlight lms-ui-autolinker">
													{$netdev.description|escape|replace:"\n":"<BR>"}
												</td>
											</tr>
										</table>
									</td>
								</tr>
								{/if}
								<tr>
									<td>
										{icon name="invproject"}
									</td>
									<td class="nobr">
										<strong>{trans("Investment project")}</strong>
									</td>
									<td>
										{$netdev.projectname}
									</td>
								</tr>
								{if $netdev.netnodeid}
									<tr>
										<td>
											{icon name="netdev"}
										</td>
										<td class="nobr">
											<strong>{trans("Network Node")}</strong>
										</td>
										<td>
											<a href="?m=netnodeinfo&id={$netdev.netnodeid}">
												<strong>{$netdev.netnode.name}</strong>
											</a>
										</td>
									</tr>
								{/if}
							</table>
						</td>
					</tr>
				</table>
{if !$devicepanel}
			</td>
		</tr>
		<tr>
			<td colspan="2" class="lms-ui-box-buttons">
{/if}
				<div class="lms-ui-box-button-container">
					{block name="netdevinfobox-buttons"}
						{button icon="clone" id="clone-netdev" onclick="location.href = '?m=netdevadd&id={$netdev.id}&clone=1';" label="Clone"}
						{button icon="edit" id="edit-netdev" onclick="location.href = '?m=netdevedit&id={$netdev.id}';" label="Edit" accesskey="E"}
						{button icon="delete" id="delete-netdev" label="Delete" data_name="{$netdev.name}"}
					{/block}
				</div>
				{if !empty($targetnetdevs)}
					<div class="lms-ui-box-button-container">
						{button icon="convert" id="replace-netdev" label="Replace"}
						<select id="target-netdev" class="lms-ui-advanced-select-test">
							<option value="">{trans("— select target network device —")}</option>
							{foreach $targetnetdevs as $targetnetdev}
								<option value="{$targetnetdev.id}" title="{$targetnetdev.producer} / {$targetnetdev.model}"
									{if $netdev.ports > $targetnetdev.ports}disabled{/if}
									>{$targetnetdev.name}{if !empty($targetnetdev.location)} ({$targetnetdev.location}){/if}</option>
							{/foreach}
						</select>
					</div>
					{/if}
			</td>
		</tr>
	</tbody>
</table>
{if $devicepanel}
<script>

	if (getCookie('devicepanel') == '1') {
		$('#devicepanel').show();
	}

</script>
{/if}
<script>

	$(function() {
		$('#delete-netdev').click(function () {
			var name = $(this).attr('data-name');
			confirmDialog($t("Are you sure, you want to remove device '$a' from database?", name), this).done(function () {
				location.href = '?m=netdevdel&id={$netdev.id}&is_sure=1';
			});
			return false;
		});

		$('#replace-netdev').click(function() {
			var targetNetDev = parseInt($('#target-netdev').val());
			if (targetNetDev) {
				location.href = '?m=netdevedit&action=replace&id={$netdev.id}&netdev=' + targetNetDev;
			}
		});
	});

</script>
