{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=netnodelist" name="choosefilter" id="choosefilter">
	<input type="hidden" name="m" value="netnodelist">
	<input type="hidden" name="page" value="1">
</form>

<table class="lmsbox lms-ui-background-cycle">
	<colgrpup>
		<col style="width: 25%;">
		<col style="width: 10%;">
		<col style="width: 18%;">
		<col style="width: 10%;">
		<col style="width: 10%;">
		<col style="width: 17%;">
		<col style="width: 10%;">
	</colgrpup>
	<thead>
		<tr {tip text="Click on column name to change sorting order"}>
			<td>
				<img src="img/netnode.png">
				<a href="?m=netnodelist&o=name{if $listdata.direction == "asc" && $listdata.order == "name"},desc{/if}">
					<strong>{trans("Name:")}</strong>
				</a>
				{if $listdata.order == "name"}
					<img src="img/{if $listdata.direction == "desc"}asc{else}desc{/if}_order.gif">
				{/if}
				<br>
				<img src="img/producer.gif">
				<a href="?m=netnodelist&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">
				{/if} /
				<a href="?m=netnodelist&o=status{if $listdata.direction == "asc" && $listdata.order == "status"},desc{/if}">
					{trans("Status:")}
				</a>
				{if $listdata.order == "status"}
					<img src="img/{if $listdata.direction == "desc"}asc{else}desc{/if}_order.gif">
				{/if}
			</td>
			<td class="text-center">
				<a href="?m=netnodelist&o=netdevcount{if $listdata.direction == "asc" && $listdata.order == "netdevcount"},desc{/if}">
					{trans("Network Devices")}
				</a>
				{if $listdata.order == "netdevcount"}
					<img src="img/{if $listdata.direction == "desc"}asc{else}desc{/if}_order.gif">
				{/if}
			</td>
			<td class="text-center">
				<a href="?m=netnodelist&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">
				{/if}
			</td>
			<td class="text-center">
				<a href="?m=netnodelist&o=invprojectid{if $listdata.direction == "asc" && $listdata.order == "invprojectid"},desc{/if}">
					{trans("Project:")}
				</a>
				{if $listdata.order == "invprojectid"}
					<img src="img/{if $listdata.direction == "desc"}asc{else}desc{/if}_order.gif">
				{/if}
			</td>
			<td class="text-center">
				<a href="?m=netnodelist&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">
				{/if}
			</td>
			<td class="text-center">
				<a href="?m=netnodelist&o=lastinspectiontime{if $listdata.direction == "asc" && $listdata.order == "lastinspectiontime"},desc{/if}">
					{trans("Last inspection:")}
				</a>
				{if $listdata.order == "lastinspectiontime"}
					<img src="img/{if $listdata.direction == "desc"}asc{else}desc{/if}_order.gif">
				{/if}
			</td>
			<td class="nobr">
			</td>
		</tr>
		<tr>
			<td colspan="3">
				<strong>{trans("Filter:")}</strong>
				{if $divisions}
					<label>
						{trans("Division:")}
						<select size="1" name="d" form="choosefilter" onchange="document.choosefilter.submit();">
							<option value="-1"{if $listdata.divisionid == -1} selected{/if} >{trans("— all —")}</option>
							{foreach $divisions as $division}
								<option value="{$division.id}"{if $listdata.divisionid == $division.id} selected{/if} >{$division.label|escape}</option>
							{/foreach}
						</select>
					</label>
				{/if}
				<label>
					{trans("Type:")}
					<input type="hidden" name="t" value="-1" form="choosefilter">
					<select size="1" name="t[]" form="choosefilter" onchange="document.choosefilter.submit();"
						multiple class="lms-ui-multiselect" data-default-value="{trans("— all —")}">
						<option value="-1"{if is_array($listdata.type) && in_array(-1, $listdata.type)} selected{/if} data-exclusive>{trans("— all —")}</option>
						{foreach $_NETELEMENTTYPES as $idx => $type}
							<option VALUE="{$idx}"{if is_array($listdata.type) && in_array($idx, $listdata.type)} selected{/if}>{$type}</option>
						{/foreach}
					</select>
				</label>
				<label>
					{trans("Status")}:
					<select size="1" name="s" form="choosefilter" 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}
					</select>
				</label>
				<label>
					{trans("Project:")}
					<input type="hidden" name="p" value="-1" form="choosefilter">
					<select size="1" name="p[]" form="choosefilter" onchange="document.choosefilter.submit();"
						multiple class="lms-ui-multiselect" data-default-value="{trans("— all —")}">
						<option value="-2"{if is_array($listdata.invprojectid) && in_array(-2, $listdata.invprojectid)} selected{/if} data-exclusive>— {trans("without project")} —</option>
						{foreach $NNprojects as $project}
							<option value="{$project.id}"{if is_array($listdata.invprojectid) && in_array($project.id, $listdata.invprojectid)} selected{/if}
								>{$project.name|escape}</option>
						{/foreach}
					</select>
				</label>
				<label>
					{trans("Ownership:")}
					<select size="1" name="w" form="choosefilter" onchange="document.choosefilter.submit();">
						<option value="-1"{if !$listdata.ownership == -1} selected{/if}>{trans("— all —")}</option>
						{foreach $_NETELEMENTOWNERSHIPS as $idx => $ownership}
							<option value="{$idx}"{if $listdata.ownership == $idx} selected{/if}>{$ownership}</option>
						{/foreach}
					</select>
				</label>
				<label>
					{trans("Flags")}
					<select size="1" name="flags" form="choosefilter" onchange="document.choosefilter.submit();">
						<option value="">{trans("— all —")}</option>
						{foreach $_NETWORK_NODE_FLAGS as $flag => $label}
							<option value="{$flag}"{if $flag == $listdata.flags} selected{/if}>{$label}</option>
						{/foreach}
					</select>
				</label>
				<label>
					{trans("Services")}
					<select size="1" name="services" form="choosefilter" onchange="document.choosefilter.submit();">
						<option value="">{trans("— all —")}</option>
						{foreach $_NETWORK_NODE_SERVICES as $service => $label}
							<option value="{$service}"{if $service == $listdata.services} selected{/if}>{$label}</option>
						{/foreach}
					</select>
				</label>
			</td>
			<td class="text-right" colspan="4">
				{button icon="add" label="Add network node" onclick="location.href = '?m=netnodeadd';"}
			</td>
		</tr>
		{if $pagination->getTotal() != 0}
			<tr>
				<td class="lms-ui-pagination" colspan="7">
					{include file="pagination.html"}
				</td>
			</tr>
		{/if}
	</thead>
	<tbody>
		{foreach $nlist as $item}
			<tr class="highlight" data-target-url="?m=netnodeinfo&id={$item.id}" data-name="{$item.name}">
				<td class="valign-top">
					<img src="img/netnode.png" ALT=""> <a name="{$item.id}"><span class="bold">{$item.name}</span></A><BR>
					<img src="img/producer.gif" ALT=""> {$_NETELEMENTTYPES[$item.type]} / {$_NETELEMENTSTATUSES[$item.status]}
				</td>
				<td class="text-center">
					{$item.netdevcount}
				</td>
				<td class="nobr">
					{$item.location}
					{if $item.location_borough_name}
						<div class="blend">
							({$item.location_state_name} / {$item.location_district_name} / {$_BOROUGHTYPES[$item.location_borough_type]} {$item.location_borough_name})
						</div>
					{/if}
				</td>
				<td class="text-center">
					{if ($item.invprojectid==1)}{trans("— none —")}{else}{$item.project|escape}{/if}
				</td>
				<td class="nobr text-center">
					({$item.id|string_format:"%04d"})
				</td>
				<td class="text-center">{$item.lastinspectiontime|date_format:"Y-m-d"}</td>
				<td class="lms-ui-buttons text-right nobr">
					{if $item.filecontainers}
						{foreach $item.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={$item.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}
					{button type="link" icon="delete" class="delete-netnode" tip="Delete" href="?m=netnodedel&id={$item.id}"}
					{button type="link" icon="edit" tip="Edit" href="?m=netnodeedit&id={$item.id}"}
					{button type="link" icon="info" tip="Info" href="?m=netnodeinfo&id={$item.id}"}
				</td>
			</tr>
		{foreachelse}
			<tr>
				<td colspan="7" class="empty-table">
					{trans("There are no device nodes 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>
				<td class="lms-ui-pagination text-right bold">
					{trans("Total:")} {$listdata.total|default:"0"}
				</td>
			</tr>
		{/if}
	</tfoot>
</table>
<script>

	$(function() {
		$('.delete-netnode').click(function() {
			var name = $(this).closest('tr').attr('data-name');
			confirmDialog($t("Are you sure, you want to remove net device node '$a' from database?", name), this).done(function() {
				location.href = $(this).attr('href');
			});
			return false;
		});

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

</script>
{/block}
