{extends file="layout.html"}
{block name=title}LMS: {$layout.pagetitle|striphtml}{/block}
{block name=module_content}
<!--// $Id$ //-->
<style>
	@media screen and (max-width: 500px) {
		.lms-ui-filter-container {
			flex-wrap: wrap;
		}

		thead tr {
			display: flex;
			flex-direction: column;
		}
		thead td.text-right {
			text-align: left;
		}
		thead td:last-child {
			text-align: right;
		}
		thead img {
			display: none;
		}

		tbody tr {
			display: flex;
			flex-direction: column;
		}
		tbody td.text-right{
			text-align: left;
			padding-left: 0.3em;
		}
		tbody td:not(:first-child) img {
			display: none;
		}
		tbody td:first-child img:first-child {
			display: none;
		}

		tfoot tr {
			display: flex;
			justify-content: space-between;
		}
		tfoot td{
			flex-grow: 1
		}

		table.lmsbox>tfoot>tr:first-child, table.lmsbox>thead>tr:first-child {
			border-top: 0px;
		}

		.lms-ui-filter-definition label {
			text-align: left;
		}
	}

	.node-lock-icon {
		margin-left: 0.4em;
	}

</style>

<H1>{$layout.pagetitle}</H1>

{$lastonline_limit = ConfigHelper::getConfig('phpui.lastonline_limit')}
<FORM method="get" action="?m={$layout.module}" name="choosefilter">
<p style="display: none;">
<INPUT type="submit" class="hiddenbtn">
<INPUT type="hidden" NAME="m" VALUE="nodelist">
</p>
<TABLE class="lmsbox lms-ui-background-cycle">
	<COLGROUP>
		<COL style="width: 96%;">
		<COL style="width: 1%;">
		<COL style="width: 1%;">
		<COL style="width: 1%;">
		<COL style="width: 1%;">
	</COLGROUP>
	<THEAD>
	{block name="nodelist-list-header"}
	<TR {tip text="Click on column name to change sorting order"}>
		<td scope="col">
			<span class="nobr">
				{icon name="node"}
				<A href="?m=nodelist&o=name{if $filter.direction == "asc" && $filter.order == "name"},desc{/if}">{trans("Name:")}</A>{if $filter.order == "name"} <IMG SRC="img/{if $filter.direction == "desc"}asc{else}desc{/if}_order.gif" alt="">{/if}
			</span>
			<br>
			<span class="nobr lighter">
				{icon name="customer"}
				<A href="?m=nodelist&o=owner{if $filter.direction == "asc" && $filter.order == "owner"},desc{/if}">{trans("Customer:")}</A>{if $filter.order == "owner"} <IMG SRC="img/{if $filter.direction == "desc"}asc{else}desc{/if}_order.gif" alt="">{/if}
			</span>
		</td>
		<td scope="col">
		<SPAN class="nobr"><A href="?m=nodelist&amp;o=location{if $filter.direction == "asc" && $filter.order == "location"},desc{/if}">{trans("Location:")}</A>{if $filter.order == "location"} <IMG SRC="img/{if $filter.direction == "desc"}asc{else}desc{/if}_order.gif" alt="">{/if}</SPAN>
		</td>
		<td scope="col" class="text-right lighter nobr">
			<img src="img/empty.gif" alt="" width="1" height="16"><A href="?m=nodelist&amp;o=id{if $filter.direction == "asc" && $filter.order == "id"},desc{/if}">{trans("Node ID:")}</A>{if $filter.order == "id"} <IMG SRC="img/{if $filter.direction == "desc"}asc{else}desc{/if}_order.gif" alt="">{/if}<BR>
			<img src="img/empty.gif" alt="" width="1" height="16"><A href="?m=nodelist&amp;o=ownerid{if $filter.direction == "asc" && $filter.order == "ownerid"},desc{/if}">{trans("Customer ID:")}</A>{if $filter.order == "ownerid"} <IMG SRC="img/{if $filter.direction == "desc"}asc{else}desc{/if}_order.gif" alt="">{/if}
		</td>
		<td scope="col" class="lighter nobr">
			{icon name="ipnetwork"}
			{trans("Network:")} /
			<a href="?m=nodelist&o=ip{if $filter.direction == "asc" && $filter.order == "ip"},desc{/if}">{trans("IP address:")}</a>
			{if $filter.order == "ip"} <img src="img/{if $filter.direction == "desc"}asc{else}desc{/if}_order.gif" alt="">{/if}
			<a href="?m=nodelist&o=ip_pub{if $filter.direction == "asc" && $filter.order == "ip_pub"},desc{/if}">({trans("Pub. IP address:")})</a>
			{if $filter.order == "ip_pub"}<img src="img/{if $filter.direction == "desc"}asc{else}desc{/if}_order.gif" alt="">{/if}
			<br>
			{icon name="mac"}
			<a href="?m=nodelist&o=mac{if $filter.direction == "asc" && $filter.order == "mac"},desc{/if}">{trans("MAC address:")}</a>
			{if $filter.order == "mac"} <img src="img/{if $filter.direction == "desc"}asc{else}desc{/if}_order.gif" alt="">{/if}
		</td>
		<td scope="col" class="text-right nobr">
			{t a=$pagination->getTotal()}Total: $a{/t}
		</td>
	</TR>
	<TR>
		<TD colspan="5">
			<div class="lms-ui-filter-container">
			<div class="lms-ui-filter-definition">

				<SPAN class="bold">{trans("Filter:")}</SPAN>&nbsp;
				<label for="s"><SPAN class="nobr">{trans("Status:")}
				<SELECT SIZE="1" NAME="s" ONCHANGE="document.choosefilter.submit();">
					<OPTION VALUE="0"{if $filter.status == 0} SELECTED{/if}>{trans("— all —")}</OPTION>
					<OPTION VALUE="1"{if $filter.status == 1} SELECTED{/if}>{trans("connected<!plural:item>")}</OPTION>
					<OPTION VALUE="2"{if $filter.status == 2} SELECTED{/if}>{trans("disconnected<!plural:item>")}</OPTION>
					<OPTION VALUE="3"{if $filter.status == 3} SELECTED{/if}>{trans("online")}</OPTION>
					<OPTION VALUE="4"{if $filter.status == 4} SELECTED{/if}>{trans("without tariff")}</OPTION>
					<OPTION VALUE="5"{if $filter.status == 5} SELECTED{/if}>{trans("without explicit TERYT")}</OPTION>
					<OPTION VALUE="11"{if $filter.status == 11} SELECTED{/if}>{trans("without TERYT")}</OPTION>
					<OPTION VALUE="6"{if $filter.status == 6} SELECTED{/if}>{trans("Net Device not specified")}</OPTION>
					<option value="9"{if $filter.status == 9} selected{/if}>{trans("without radio sector")}</option>
					<OPTION VALUE="7"{if $filter.status == 7} SELECTED{/if}>{trans("with warning")}</OPTION>
					<option value="10"{if $filter.status == 10} selected{/if}>{trans("with locks")}</option>
					<OPTION value="8"{if $filter.status == 8} selected{/if}>{trans("without GPS coords")}</OPTION>
				</SELECT></SPAN>
				</label>

				{if !empty($networks) && count($networks) > 1}
					<label for="n" class="nobr"><SPAN>{trans("Network:")}</SPAN>
					<SELECT SIZE="1" NAME="n" ONCHANGE="document.choosefilter.submit();">
						<OPTION value="0" {if !$filter.network} SELECTED {/if}>{trans("— all networks —")}</OPTION>
						{section name=networks loop=$networks}
						<OPTION value="{$networks[networks].id}" {if $filter.network == $networks[networks].id} SELECTED {/if}>{$networks[networks].name|truncate:30:"&hellip;":true}</OPTION>
						{/section}
					</SELECT>
					</label>
				{else}
					<input type="hidden" name="n" value="0">
				{/if}

				{if !empty($nodegroups) && count($nodegroups)}
					<label for="ng"><SPAN class="nobr">{trans("Group:")}</SPAN>
					<SELECT SIZE="1" NAME="ng" ONCHANGE="document.choosefilter.submit();">
						<OPTION value="" {if !$filter.nodegroup} SELECTED {/if}>{trans("— all groups —")}</OPTION>
						<option value="-1"{if $filter.nodegroup == -1} selected{/if}>— {trans("without group")} —</option>
						{foreach from=$nodegroups item=nodegroup}
						<OPTION value="{$nodegroup.id}" {if $filter.nodegroup == $nodegroup.id} SELECTED {/if}>{$nodegroup.name|truncate:30:"&hellip;":true}</OPTION>
						{/foreach}
					</SELECT>
					</label>
				{else}
					<input type="hidden" name="ng" value="">
				{/if}

				{if !empty($customergroups) && count($customergroups)}
					<label for="g"><SPAN class="nobr">{trans("Customers Group:")}</SPAN>
					<SELECT SIZE="1" NAME="g" ONCHANGE="document.choosefilter.submit();">
						<OPTION value="" {if !$filter.customergroup} SELECTED {/if}>{trans("— all groups —")}</OPTION>
						{section name=customergroups loop=$customergroups}
						<OPTION value="{$customergroups[customergroups].id}" {if $filter.customergroup == $customergroups[customergroups].id} SELECTED {/if}>{$customergroups[customergroups].name|truncate:30:"&hellip;":true}</OPTION>
						{/section}
					</SELECT>
					</label>
				{else}
					<input type="hidden" name="g" value="">
				{/if}

				{if !empty($NNprojects)}
					<label for="p"><SPAN class="nobr">{trans("Project:")}</SPAN>
					<SELECT SIZE="1" NAME="p" ONCHANGE="document.choosefilter.submit();">
						<OPTION VALUE="-1"{if $filter.search.project == -1} selected{/if}>{trans("— all —")}</OPTION>
						<OPTION VALUE="-2"{if $filter.search.project == -2} selected{/if}>— {trans("without project")} —</OPTION>
						{foreach $NNprojects as $project}
							<OPTION value="{$project.id}"{if $filter.search.project == $project.id} selected{/if}>{$project.name|escape}</OPTION>
						{/foreach}
					</SELECT>
					</label>
				{else}
					<input type="hidden" name="p" value="-1">
				{/if}
			</div>
			{persistent_filter}
			</div>
		</TD>
	</TR>
	{if $pagination->getTotal() != 0}
	<TR>
		<TD class="lms-ui-pagination" colspan="5">
			{include file="pagination.html"}
		</TD>
	</TR>
	{/if}
	{/block}
	</THEAD>
	<TFOOT>
	{block name="nodelist-list-footer"}
	{if $pagination->getTotal() != 0}
	<TR>
		<TD class="lms-ui-pagination" colspan="5">
			{include file="pagination.html"}
		</TD>
	</TR>
	{/if}
	<TR>
		<TD colspan="4" class="text-right bold">
			{trans("Total:")}<BR>
			{trans("Connected<!nodes>:")}<BR>
			{trans("Disconnected:")}
		</TD>
		<TD colspan="1" class="text-left bold">
			{if $filter.total}{$filter.total}{else}0{/if}<BR>
			{if $filter.totalon}{$filter.totalon}{else}0{/if}<BR>
			{if $filter.totaloff}{$filter.totaloff}{else}0{/if}
		</TD>
	</TR>
	{/block}
	</TFOOT>
	<TBODY>
	{block name="nodelist-list-body"}
	{foreach $nodelist as $node}
	<TR class="highlight {if ! $node.access} blend{/if}" data-target-url="?m=nodeinfo&id={$node.id}" data-name="{$node.name}">
		<TD class="nobr">
			<span class="bold">
			<A name="{$node.id}">
			{if $node.lastonline}
				{if ($smarty.now-$node.lastonline) > $lastonline_limit}
					{capture assign="lastonline"}{t a=$node.lastonlinedate}Last online: $a{/t}{/capture}
					{icon name="nodeoff" tip=$lastonline}
				{else}
					{capture assign="lastonline"}{t a="on-line"}Last online: $a{/t}{/capture}
					{icon name="nodeon" tip=$lastonline}
				{/if}
			{else}
				{icon name="nodeunk"}
			{/if}
			{if $node.info}
			    {icon name="info" tip=$node.info|escape}
			{/if}
			{$node.name|escape}</A>{if $node.locked}{icon name="lock" tip="<!node>lock is active" class="node-lock-icon"}{/if}</span>
			<br>
			<span class="nobr{if ! $node.access} blend{/if}">
				{icon name="customer"}
				<a href="?m=customerinfo&id={$node.ownerid}"
					class="lms-ui-hint-rollover"
					data-url="?m=customerinfoshort&id={$node.ownerid}">
					{$node.owner|trunescape:40}
				</a>
			</span>
		</TD>
		<TD class="nobr">
		{$node.location}{if $node.borough_name}<br><span class="blend">({$node.state_name} / {$node.district_name} / {$_BOROUGHTYPES[$node.borough_type]} {$node.borough_name})</span>{/if}
		</TD>
		<TD class="text-right">
			({$node.id|string_format:"%04d"})<BR>
			<SPAN class="blend">({$node.ownerid|string_format:"%04d"})</span>
		</TD>
		<TD class="nobr">
			{icon name="ipnetwork"}
			{$node.netname} / {$node.ip} {if $node.ip_pub != "0.0.0.0"}({$node.ip_pub}){/if}
			<br>
			{icon name="mac"}
			{$node.mac|replace:",":"</span><br><span class=\"nobr\"><i class=\"lms-ui-icon-mac fa-fw\"></i>"}
		</TD>
		<TD class="lms-ui-buttons nobr">
			{if $node.access}
				{button type="link" icon="connected" tip="Disconnect" href="?m=nodeset&id={$node.id}"}
			{else}
				{button type="link" icon="disconnected" tip="Disconnect" href="?m=nodeset&id={$node.id}"}
			{/if}
			{if $node.warning}
				{button type="link" icon="warnon" tip="Disable notice" href="?m=nodewarn&id={$node.id}"}
			{else}
				{button type="link" icon="warnoff" tip="Enable notice" href="?m=nodewarn&id={$node.id}"}
			{/if}
			{button type="link" icon="delete" class="delete-node" href="?m=nodedel&id={$node.id}"}
			{button type="link" icon="edit" href="?m=nodeedit&id={$node.id}"}
			{button type="link" icon="info" href="?m=nodeinfo&id={$node.id}"}
		</TD>
	</TR>
	{if $nodelist[nodelist.index_next].ownerid == $node.ownerid && $filter.order == "owner"}{cycle print=false}{/if}
	{foreachelse}
	<tr>
		<td colspan="5" class="empty-table">
			{trans("No such nodes in database.")}
		</td>
	</tr>
	{/foreach}
	{/block}
	</TBODY>
</TABLE>
</FORM>
<script>
	$('.delete-node').click(function() {
		var name = $(this).closest('tr').attr('data-name');
		confirmDialog($t("Are you sure, you want to remove node '$a' from database?", name), this).done(function() {
			location.href = $(this).attr('href');
		});
		return false;
	});
</script>
{/block}
