{extends file="layout.html"}
{block name=title}LMS: {$layout.pagetitle|striphtml}{/block}
{block name=module_content}
<!--// $Id$ //-->
<H1>{$layout.pagetitle}</H1>
<FORM method="get" action="?m=netdevlist" name="choosefilter">

{$lastonline_limit=ConfigHelper::getConfig('phpui.lastonline_limit')}

<INPUT type="hidden" NAME="m" VALUE="netdevlist">
<TABLE class="lmsbox lms-ui-background-cycle">
    <THEAD>
	<TR {tip text="Click on column name to change sorting order"}>
		<TD width="95%">
			{icon name="netdev"}
			<A href="?m=netdevlist&o=name{if $listdata.direction == "asc" && $listdata.order == "name"},desc{/if}"><B>{trans("Name:")}</B></A> {if $listdata.order == "name"}<IMG src="img/{if $listdata.direction == "desc"}asc{else}desc{/if}_order.gif" alt="">{/if}
			<br>
			{icon name="type"}
			<a href="?m=netdevlist&o=type{if $listdata.direction == "asc" && $listdata.order == "type"},desc{/if}">{trans("Type")}</a> {if $listdata.order == "type"}<IMG src="img/{if $listdata.direction == "desc"}asc{else}desc{/if}_order.gif" alt="">{/if}
			{icon name="producer"}
			<A href="?m=netdevlist&o=producer{if $listdata.direction == "asc" && $listdata.order == "producer"},desc{/if}">{trans("Manufacturer:")}</A> {if $listdata.order == "producer"}<IMG src="img/{if $listdata.direction == "desc"}asc{else}desc{/if}_order.gif" alt="">{/if} /
			{icon name="model"}
			<A href="?m=netdevlist&o=model{if $listdata.direction == "asc" && $listdata.order == "model"},desc{/if}">{trans("Model:")}</A> {if $listdata.order == "model"}<IMG src="img/{if $listdata.direction == "desc"}asc{else}desc{/if}_order.gif" alt="">{/if}
		</TD>
		<td width="1%" class="nobr valign-top">
		    {icon name="location"}
			<A href="?m=netdevlist&amp;o=location{if $listdata.direction == "asc" && $listdata.order == "location"},desc{/if}">{trans("Location")}</A>
			{if $listdata.order == "location"}<IMG src="img/{if $listdata.direction == "desc"}asc{else}desc{/if}_order.gif" alt="">{/if}
		</td>
		<TD width="1%" class="nobr align-left valign-top">
			{icon name="netnode"}
			<A href="?m=netdevlist&amp;o=netnode{if $listdata.direction == "asc" && $listdata.order == "netnode"},desc{/if}">{trans("Network node")}</A> {if $listdata.order == "netnode"}<IMG src="img/{if $listdata.direction == "desc"}asc{else}desc{/if}_order.gif" alt="">{/if}<br>
			{icon name="customer"}
			<A href="?m=netdevlist&amp;o=customername{if $listdata.direction == "asc" && $listdata.order == "customername"},desc{/if}">{trans("Customer")}</A> {if $listdata.order == "customername"}<IMG src="img/{if $listdata.direction == "desc"}asc{else}desc{/if}_order.gif" alt="">{/if}
		</TD>
		<TD width="1%" class="text-right valign-top nobr">
			{icon name="id"} <A href="?m=netdevlist&amp;o=id{if $listdata.direction == "asc" && $listdata.order == "id"},desc{/if}">ID</A> {if $listdata.order == "id"}<IMG src="img/{if $listdata.direction == "desc"}asc{else}desc{/if}_order.gif" alt="">{/if}
		</TD>
		<TD width="1%" NOWRAP>
			{icon name="port"}<A href="?m=netdevlist&amp;o=ports{if $listdata.direction == "asc" && $listdata.order == "ports"},desc{/if}">{trans("Number of ports:")}</A> {if $listdata.order == "ports"}<IMG src="img/{if $listdata.direction == "desc"}asc{else}desc{/if}_order.gif" alt="">{/if}
			(<A href="?m=netdevlist&amp;o=takenports{if $listdata.direction == "asc" && $listdata.order == "takenports"},desc{/if}">{trans("Ports used:")}</A>{if $listdata.order == "takenports"}<IMG src="img/{if $listdata.direction == "desc"}asc{else}desc{/if}_order.gif" alt="">{/if})<BR>
			{icon name="serial"}<A href="?m=netdevlist&amp;o=serialnumber{if $listdata.direction == "asc" && $listdata.order == "serialnumber"},desc{/if}">{trans("Serial number")}</A> {if $listdata.order == "serialnumber"}<IMG src="img/{if $listdata.direction == "desc"}asc{else}desc{/if}_order.gif" alt="">{/if}
		</TD>
		<td width="1%" class="text-right nobr bold">
			{trans("Total:")} {$listdata.total|default:"0"}
		</td>
	</TR>
	<TR>
		<TD colspan="6">
			<div class="lms-ui-filter-container">
				<div class="lms-ui-filter-definition">
					{icon name="filter"}
					<label>
						{trans("Status")}
						<select size="1" name="s" onchange="document.choosefilter.submit();">
							<option value="-1"{if $listdata.status == -1} selected{/if}>{trans("— all —")}</option>
							{foreach $_NETELEMENTSTATUSES as $idx => $status}
								<option value="{$idx}"{if $listdata.status == $idx} selected{/if}>{$status}</option>
							{/foreach}
							<option value="100"{if $listdata.status == 100} selected{/if}>{trans("TERYT not specified")}</option>
							<option value="101"{if $listdata.status == 101} selected{/if}>{trans("online")}</option>
							<option value="102"{if $listdata.status == 102} selected{/if}>{trans("no connections")}</option>
						</select>
					</label>
					<label>
						{trans("Project")}
						<select size="1" name="p" onchange="document.choosefilter.submit();">
							<option value="-1"{if $listdata.invprojectid == -1} selected{/if}>{trans("— all —")}</option>
							<option value="-2"{if $listdata.invprojectid == -2} selected{/if}>— {trans("without project")} —</option>
							{foreach $NNprojects as $project}
								<option value="{$project.id}"{if ($listdata.invprojectid == $project.id)} selected{/if}>{$project.name|escape}</option>
							{/foreach}
						</select>
					</label>
					<label>
						{trans("Network node")}
						<select name="n" onchange="document.choosefilter.submit();"
							{tip class="lms-ui-advanced-select-test" text="Select network node (optional)" trigger="netnodeid"}>
							<option value="-1"{if $listdata.netnode == -1} selected{/if}>{trans("— all —")}</option>
							<option value="-2"{if $listdata.netnode == -2} selected{/if}>{trans("— none —")}</option>
							{foreach $netnodes as $netnode}
								<option value="{$netnode.id}"{if $listdata.netnode == $netnode.id} selected{/if}>{$netnode.name}</option>
							{/foreach}
						</select>
					</label>
					<label>
						{trans("Type")}
						{networkDeviceTypes elemname="type" selected=$listdata.type onchange="document.choosefilter.submit();"}
					</label>
					<label>
						{trans("Producer")}
						<select size="1" name="producer" onchange="document.choosefilter.submit();">
							<option value="-1"{if $listdata.producer == -1} selected{/if}>{trans("— all —")}</option>
							<option value="-2"{if $listdata.producer == -2} selected{/if}>{trans("— none —")}</option>
							{foreach $producers as $producer}
								<option value="{$producer}"{if $listdata.producer == $producer} selected{/if}>{$producer}</option>
							{/foreach}
						</select>
					</label>
					<label>
						{trans("Model")}
						<select size="1" name="model" onchange="document.choosefilter.submit();">
							<option value="-1"{if $listdata.model == -1} selected{/if}>{trans("— all —")}</option>
							<option value="-2"{if $listdata.model == -2} selected{/if}>{trans("— none —")}</option>
							{foreach $models as $model}
								<option value="{$model}"{if $listdata.model == $model} selected{/if}>{$model}</option>
							{/foreach}
						</select>
					</label>
					<label>
						{trans("Existing links")}
						&nbsp;
						<select size="1" name="linktechnology" class="lms-ui-advanced-select-test show-group-labels">
							<option value="-1"{if $listdata.linktechnology == -1} selected{/if}>{trans("— any —")}</option>
							<option value="-2"{if $listdata.linktechnology == -2} selected{/if}>{trans("— without technology —")}</option>
							<option value="-3"{if $listdata.linktechnology == -3} selected{/if}>{trans("<!netlink>— none —")}</option>
							{foreach $_LINKTYPES as $linktype => $linktypelabel}
								<optgroup label="{$linktypelabel}">
									{foreach $_LINKTECHNOLOGIES[$linktype] as $linktechnologyidx => $linktechnology}
										<option value="{$linktechnologyidx}"{if $listdata.linktechnology == $linktechnologyidx} selected{/if}>{$linktechnology}</option>
									{/foreach}
								</optgroup>
							{/foreach}
						</select>
					</label>
				</div>
			</div>
		</TD>
	</TR>
	{if $pagination->getTotal() != 0}
	<TR>
		<TD class="lms-ui-pagination" COLSPAN="6">
			{include file="pagination.html"}
		</TD>
	</TR>
	{/if}
    </THEAD>
    <TBODY>
	{foreach $netdevlist as $netdev}
	<TR class="highlight" data-target-url="?m=netdevinfo&id={$netdev.id}" data-name="{$netdev.name}" data-id="{$netdev.id}">
		<TD class="valign-top">
			{if $netdev.lastonline}
				{if ($smarty.now-$netdev.lastonline) > $lastonline_limit}
					<i class="lms-ui-icon-netdevoff" {tip a=$netdev.lastonlinedate text="Last online: \$a"}></i>
				{else}
					<i class="lms-ui-icon-netdevon" {tip a="on-line" text="Last online: \$a"}></i>
				{/if}
			{else}
				<i class="lms-ui-icon-netdevunk"></i>
			{/if}
			<A href="?m=netdevinfo&amp;id={$netdev.id}" name="{$netdev.id}"
					title="{$netdev.description|replace:"\n":"<br>"|default:trans("— no description —")}">
				<B>{$netdev.name}</B></A>
			<br>
			{if $netdev.producer}
				{icon name="type"}
				{$netdev.producer} {if $netdev.model}/ {$netdev.model}{/if}
				{if !empty($netdev.devtype)}
					({strip}
						{trans($netdev.devtypename)}
						&nbsp;-&nbsp;
						{if empty($netdev.devtypepassive)}{trans("<!netdevmodeltype>active")}{else}{trans("<!netdevmodeltype>passive")}{/if}
					{/strip})
				{/if}
			{else}
				<br>
			{/if}
		</TD>
		<TD class="nobr valign-top">
			{if $netdev.location}
				{icon name="location" label=$netdev.location}
				{if $netdev.borough_name}
					<div class="blend">
						({$netdev.state_name} / {$netdev.district_name} / {$_BOROUGHTYPES[$netdev.borough_type]} {$netdev.borough_name})
					</div>
				{/if}
			{elseif $netdev.netnodeid && $netnodes[$netdev.netnodeid].location}
				{$netnodeid=$netdev.netnodeid}
				{$netnodes[$netnodeid].location} {trans("(from network node)")}
				{if $netnodes[$netnodeid].location_borough_name}
					<div class="blend">
						({$netnodes[$netnodeid].location_state_name} / {$netnodes[$netnodeid].location_district_name} / {$_BOROUGHTYPES[$netnodes[$netnodeid].location_borough_type]} {$netnodes[$netnodeid].location_borough_name})
					</div>
				{/if}
			{/if}
			{if $netdev.ownerid}
				<div>{button type="link" icon="customer" label=$netdev.customername href="?m=customerinfo&id={$netdev.ownerid}"}</div>
			{/if}
		</TD>
		<TD class="nobr valign-top">
			{if $netdev.netnode}<IMG src="img/netnode.png" alt=""><a href="?m=netnodeinfo&amp;id={$netdev.netnodeid}"> {$netdev.netnode}</a>{/if}
			{if $netdev.customerid}<IMG src="img/customer.png" alt=""><a href="?m=customerinfo&amp;id={$netdev.customerid}"> {$netdev.customerid}</a>{/if}
		</TD>
		<TD class="text-right valign-top">
			({$netdev.id|string_format:"%04d"})
		</TD>
		<TD class="nobr">
			{icon name="port" label="{$netdev.ports} ({$netdev.takenports})"}<br>
			{icon name="serialnumber" label=$netdev.serialnumber}
		</TD>
		<TD class="lms-ui-buttons text-right nobr">
			{if $netdev.filecontainers}
				{foreach $netdev.filecontainers as $filecontainer}
					{if $filecontainer.files}
						{button class="models-toggle-file-list" type="link" icon="attachment" tip="Show file list" resourceid={$filecontainer.id} label="{$filecontainer.description|default:'---'}"}
					{/if}
					<div id="listfiles-{$filecontainer.id}" style="display: none;" class="files">
						{foreach $filecontainer.files as $file}
							{documentview id="{$filecontainer.id}-{$file.id}" type=$file.contenttype name=$file.filename
								url="?m=attachments&attachmentaction=viewfile&type=messageid&id={$netdev.filecontainerid}&fileid={$file.id}" external=true
								text="{$file.filename} <i class=\"lms-ui-icon-view{if preg_match('/pdf/',$file.contenttype)} pdf{elseif preg_match('/csv|excel|spreadsheet/',$file.contenttype)} xls{/if}\"></i>"}
							<br>
						{/foreach}
					</div>
				{/foreach}
			{/if}

			{foreach $netdev.customlinks as $link}
				<a {if isset($link.url)} href="{$link.url}" {/if} rel="external"
						{if isset($link.onclick)} onclick="{$link.onclick}"{/if}
						{if isset($link.class)} class="{$link.class}"{/if}
				>
					{if isset($link.icon)}
						<img src="{$link.icon}" alt="{$link.label}" {$link.tip}>
					{else}
						{$link.label}
					{/if}
				</a>
				{if isset($link.extra)}{$link.extra}{/if}
			{/foreach}
			{buttons}
				{button type="link" icon="delete" class="delete-netdev" tip="Delete" href="?m=netdevdel&id={$netdev.id}&is_sure=1"}
				{button type="link" icon="edit" tip="Edit" href="?m=netdevedit&id={$netdev.id}"}
				{button type="link" icon="clone" tip="Clone" href="?m=netdevadd&id={$netdev.id}&clone=1"}
				{button type="link" icon="info" tip="Info" href="?m=netdevinfo&id={$netdev.id}"}
			{/buttons}
		</TD>
	</TR>
	{if $netdevlist[netdevlist.index_next].ownerid == $netdev.ownerid && $listdata.order == "owner"}{cycle print=false}{/if}
	{foreachelse}
	<tr>
		<td colspan="6" class="empty-table">
			{trans("There are no devices in your database.")}
		</td>
	</tr>
	{/foreach}
    </TBODY>
	<TFOOT>
	{if $pagination->getTotal() != 0}
	<TR>
		<TD class="lms-ui-pagination" COLSPAN="6">
			{include file="pagination.html"}
		</TD>
	</TR>
	{/if}
	<TR>
		<td colspan="6" class="text-right bold">
			{trans("Total:")} {$listdata.total|default:"0"}
		</td>
	</TR>
	</TFOOT>
</TABLE>
</FORM>
<script>
	$('.delete-netdev').click(function() {
		var name = $(this).closest('tr').attr('data-name');
		confirmDialog($t("Are you sure, you want to remove device '$a' from database?", name), this).done(function() {
			location.href = $(this).attr('href');
		});
		return false;
	});

	$(function () {
		$('.models-toggle-file-list').click(function () {
			var containerid = parseInt($(this).attr('data-resourceid'));
			var elem = $('#listfiles-' + containerid);
			elem.toggle();
		});

		$('[name="linktechnology"]').change(function() {
			document.choosefilter.submit();
		});
	});

</script>
{/block}
