{extends file="layout.html"}
{block name=title}LMS: {$layout.pagetitle|striphtml}{/block}
{block name=module_content}
<!--// $Id$ //-->
{$xajax}
<script>

	function PrintList()
	{
		document.nodesearch.action = "?m=nodesearch&search=1&print=1";
		document.nodesearch.target = "_BLANK";
		document.nodesearch.submit();
	}

	function Search()
	{
		document.nodesearch.action = "?m=nodesearch&search=1";
		document.nodesearch.target = "";
		document.nodesearch.submit();
	}

</script>
<H1>{$layout.pagetitle}</H1>
<FORM method="post" action="?m=nodesearch&amp;search" id="nodesearch" name="nodesearch">
<P style="display: none;">
<INPUT type="submit" class="hiddenbtn">
<INPUT TYPE="hidden" NAME="m" VALUE="nodesearch">
</p>
<TABLE class="lmsbox">
	<COLGROUP>
		<COL style="width: 1%;">
		<COL style="width: 99%;">
	</COLGROUP>
	<THEAD>
	<TR>
		<TD colspan="2" class="bold">
			{trans("Find nodes matching the following search criteria:")}
		</TD>
	</TR>
	</THEAD>
	<TBODY>
	<TR>
		<TD class="bold nobr">
			<IMG src="img/node.gif" width="16" alt=""> {trans("Node name:")}
		</TD>
		<TD>
			<INPUT TYPE="text" NAME="search[name]" value="{$nodesearch.name}" {tip text="Enter node name or it's fragment"}>
		</TD>
	</TR>
	<TR>
		<TD class="bold nobr">
			{icon name="login"} {trans("<!node>Login")}
		</TD>
		<TD>
			<INPUT TYPE="text" NAME="search[login]" value="{$nodesearch.login}" {tip text="Enter node login or it's fragment"}>
		</TD>
	</TR>
	<TR>
		<TD class="bold nobr">
			<IMG src="img/mac.gif" width="16" alt=""> {trans("MAC address:")}
		</TD>
		<TD>
			<INPUT TYPE="text" NAME="search[mac]" value="{$nodesearch.mac}" {tip text="Enter MAC address or it's fragment"}>
		</TD>
	</TR>
	<TR>
		<TD class="bold nobr">
			<IMG src="img/ip.gif" width="16" alt=""> {trans("IP address:")}
		</TD>
		<TD>
			<INPUT TYPE="text" NAME="search[ipaddr]" value="{$nodesearch.ipaddr}" {tip text="Enter IP address or it's fragment"}>
		</TD>
	</TR>
	<TR>
		<TD class="bold nobr">
			<IMG src="img/home.gif" width="16" alt=""> {trans("Location:")}
		</TD>
		<TD>
			<INPUT TYPE="text" NAME="search[location]" value="{$nodesearch.location}" {tip text="Enter node location"}>
		</TD>
	</TR>
	<tr>
		<td class="nobr">
			{icon name="home"}
			<strong>{trans("<!nodesearch>Address origin")}</strong>
		</td>
		<td>
			<select name="search[address-origin]">
				<option value="">{trans("— ignore —")}</option>
				<option value="1"{if $nodesearch['address-origin'] == 1} selected{/if}
					>{trans("<!nodesearch>with explicit address")}</option>
				<option value="2"{if $nodesearch['address-origin'] == 2} selected{/if}
					>{trans("<!nodesearch>with implicit address")}</option>
			</select>
		</td>
	</tr>
	<tr>
		<td class="bold nobr">
			<img src="img/access.gif">
			{trans("Status:")}
		</td>
		<td>
			<select size="1" name="search[status]">
				<option value="0"{if $nodesearch.status == 0} selected{/if}>{trans("— all —")}</option>
				<option value="1"{if $nodesearch.status == 1} selected{/if}>{trans("connected<!plural:item>")}</option>
				<option value="2"{if $nodesearch.status == 2} selected{/if}>{trans("disconnected<!plural:item>")}</option>
				<option value="3"{if $nodesearch.status == 3} selected{/if}>{trans("<!node>online")}</option>
				<option value="12"{if $nodesearch.status == 12} selected{/if}>{trans("<!node>offline")}</option>
				<option value="4"{if $nodesearch.status == 4} selected{/if}>{trans("no assignments")}</option>
				<option value="13"{if $nodesearch.status == 13} selected{/if}>{trans("no active or future assignments")}</option>
				<option value="5"{if $nodesearch.status == 5} selected{/if}>{trans("without explicit TERYT")}</option>
				<option value="11"{if $nodesearch.status == 11} selected{/if}>{trans("without TERYT")}</option>
				<option value="6"{if $nodesearch.status == 6} selected{/if}>{trans("Net Device not specified")}</option>
				<option value="9"{if $nodesearch.status == 9} selected{/if}>{trans("without radio sector")}</option>
				<option value="7"{if $nodesearch.status == 7} selected{/if}>{trans("with warning")}</option>
				<option value="10"{if $nodesearch.status == 10} selected{/if}>{trans("with locks")}</option>
				<option value="8"{if $nodesearch.status == 8} selected{/if}>{trans("without GPS coords")}</option>
			</select>
		</td>
	</tr>
{if !empty($states)}
	<tr id="state">
		<td class="bold nobr">
			<IMG src="img/home.gif" width="16" alt=""> {trans("State")}:
		</td>
		<td>
			<select id="state_sel" name="search[state]" onchange="change_selection(this)" {tip text="Select state"}>
				<option value="0"></option>
				{foreach from=$states item=item}
				<option value="{$item.id}"{if $item.id == $nodesearch.state} selected{/if}>{$item.name}</option>
				{/foreach}
			</select>
		</td>
	</tr>
	<tr id="district"{if empty($districts)} style="display: none;"{/if}>
		<td class="bold nobr">
			<IMG src="img/home.gif" width="16" alt=""> {trans("District")}:
		</td>
		<td>
			<select id="district_sel" name="search[district]" onchange="change_selection(this)" {tip text="Select district"} style="width: 20%;">
				{if !$data.districtid}
				<option value="0"></option>
				{/if}
				{foreach from=$districts item=item}
				<option value="{$item.id}"{if $item.id == $nodesearch.district} selected{/if}>{$item.name}</option>
				{/foreach}
			</select>
		</td>
	</tr>
	<tr id="borough"{if empty($boroughs)} style="display: none;"{/if}>
		<td class="bold nobr">
			<IMG src="img/home.gif" width="16" alt=""> {trans("Commune")}:
		</td>
		<td>
			<select id="borough_sel" name="search[borough]" {tip text="Select commune"} style="width: 20%;">
				{if !$data.boroughid}
				<option value="0"></option>
				{/if}
				{foreach from=$boroughs item=item}
				<option value="{$item.id}"{if $item.id == $nodesearch.borough} selected{/if}>{$item.name}</option>
				{/foreach}
			</select>
		</td>
	</tr>
{/if}
	<TR>
		<TD class="bold nobr">
			<IMG src="img/info1.gif" width="16" alt=""> {trans("Description:")}
		</TD>
		<TD>
			<INPUT TYPE="text" NAME="search[info]" value="{$nodesearch.info}" {tip text="Enter additional information"}>
		</TD>
	</TR>
	<TR>
		<td class="bold nobr">
			<img src="img/netdev.gif"> {trans("Device:")}
		</td>
		<td>
			<input type="text" name="search[netdev]" id="netdev" value="{$nodesearch.netdev}" {tip text="Enter network device name or ip address"}>
		</td>
	</TR>
	<tr>
		<td class="nobr">
			{icon name="modified-date"}
			<strong>{trans("Created")}</strong>
		</td>
		<td>
			{date_period_preset from="#createdfrom" to="#createdto" time=true}
			{trans("from")}
			<input type="text" name="search[createdfrom]" id="createdfrom" value="{$nodesearch.createdfrom}"
				{tip class="calendar-time" text="Enter date in YYYY/MM/DD hh:mm format (empty field means ignore) or click to choose it from calendar"}>
			{trans("to")}
			<input type="text" name="search[createdto]" id="createdto" value="{$nodesearch.createdto}"
				{tip class="calendar-time" text="Enter date in YYYY/MM/DD hh:mm format (empty field means ignore) or click to choose it from calendar"}>
		</td>
	</tr>
	<tr>
		<td class="nobr">
			{icon name="modified-date"}
			<strong>{trans("Modified")}</strong>
		</td>
		<td>
			{date_period_preset from="#modifiedfrom" to="#modifiedto" time=true}
			{trans("from")}
			<input type="text" name="search[modifiedfrom]" id="modifiedfrom" value="{$nodesearch.modifiedfrom}"
				{tip class="calendar-time" text="Enter date in YYYY/MM/DD hh:mm format (empty field means ignore) or click to choose it from calendar"}>
			{trans("to")}
			<input type="text" name="search[modifiedto]" id="modifiedto" value="{$nodesearch.modifiedto}"
				{tip class="calendar-time" text="Enter date in YYYY/MM/DD hh:mm format (empty field means ignore) or click to choose it from calendar"}>
		</td>
	</tr>
	<tr>
		<td class="nobr">
			{icon name="calendar"}
			<strong>{trans("Last online earlier than")}</strong>
		</td>
		<td>
			<input type="text" name="search[lastonlinebefore]" id="lastonlinebefore" value="{$nodesearch.lastonlinebefore}"
				{tip class="calendar-time" text="Enter date in YYYY/MM/DD hh:mm format (empty field means ignore) or click to choose it from calendar"}>
		</td>
	</tr>
	<tr>
		<td class="nobr">
			{icon name="calendar"}
			<strong>{trans("Last online later than")}</strong>
		</td>
		<td>
			<input type="text" name="search[lastonlineafter]" id="lastonlineafter" value="{$nodesearch.lastonlineafter}"
				{tip class="calendar-time" text="Enter date in YYYY/MM/DD hh:mm format (empty field means ignore) or click to choose it from calendar"}>
		</td>
	</tr>
	<tr>
		<td class="nobr valign-top">
			{icon name="netdev"}
			<strong>{trans("Type")}</strong>
			<label>
				<input class="radio light" type="radio" value="AND" name="search[authtypek]"{if $nodesearch.authtypek != 'OR'} checked{/if}>
				{trans("and")}
			</label>
			<label>
				<input class="radio light" type="radio" value="OR" name="search[authtypek]"{if $nodesearch.authtypek == 'OR'} checked{/if}>
				{trans("or")}
			</label>
		</td>
		<td>
			{foreach $_SESSIONTYPES as $idx => $sessiontype}
				<label {tip text="`$sessiontype.tip`"}>
					<input type="checkbox" name="search[authtype][{$idx}]" value="{$idx}"
						   id="authtype{$idx}" {tip trigger="authtype`$idx`"}
							{if ($nodeinfo.authtype & $idx) == $idx} checked{/if}>
					{$sessiontype.label}
				</label>
				{if !$sessiontype@last}
					<br>
				{/if}
			{/foreach}
		</td>
	</tr>
	<tr>
		<td class="nobr">
			{icon name="qualification-operator"}
			<strong>{trans("Qualification operator")}</strong>
		</td>
		<td>
			<label>
				<input class="radio light" type="radio" value="AND" name="k"{if $k!='OR'} checked{/if}>
				{trans("and")}
			</label>
			<label>
				<input class="radio light" type="radio" value="OR" name="k"{if $k=='OR'} checked{/if}>
				{trans("or")}
			</label>
		</td>
	</tr>
	<TR>
		<td class="lms-ui-box-buttons" colspan="2">
			{button icon="search" label="Search" onclick="Search()"}
			{button icon="print" label="Print" onclick="PrintList()"}
		</td>
	</TR>
	</TBODY>
</TABLE>
</FORM>
<script>

	function change_selection(elem)
	{
		var district = document.getElementById('district'),
			borough = document.getElementById('borough');

		if (elem.name == 'search[state]') {
			district.style.display = 'none';
			borough.style.display = 'none';
		}
		else if (elem.name == 'search[district]')
			borough.style.display = 'none';

		if (elem.value != 0)
			xajax_select_location(elem.name, elem.value);
	}

	function update_selection(type, data, selected)
	{
		var i, len, elem = document.getElementById(type),
			select = document.getElementById(type+'_sel');

		select.options.length = 0;
		select.options[0] = new Option('', 0);
		for (i=0, len=data.length; i<len; i++) {
			select.options[select.options.length] = new Option(data[i].name, data[i].id);
		}

		if (i > 0)
			elem.style.display = '';
		select.value = selected ? selected : 0;
		select.focus();
	}

	$(function() {
		$('form[name="nodesearch"] [name="search[name]"]').focus();

		new AutoSuggest(document.getElementById('nodesearch'),document.getElementById('netdev'),'?m=nodesearch&ajax=1&mode=netdev&what=',0);
	});

</script>
{/block}
