{extends file="layout.html"}
{block name=title}LMS: {$layout.pagetitle|striphtml}{/block}
{block name=module_content}
<!-- $Id$ -->
{$xajax}
<h1>{$layout.pagetitle}</h1>
<form method="POST" name="search" id="search" action="?m=rtsearch">
	<input type="submit" class="hiddenbtn">
</form>
<table class="lmsbox">
	<colgroup>
		<col style="width: 1%;">
		<col style="width: 99%;">
	</colgroup>
	<thead>
		<tr>
			<td class="nobr" colspan="2">
				<strong>{trans("Display tickets matching the following criteria")}:</strong>
			</td>
		</tr>
	</thead>
	<tbody>
		<tr>
			<td class="bold nobr">
				{icon name="subject" label="Subject"}
			</td>
			<td>
				<input type="search" size="50" name="search[subject]" value="{$search.subject}"
					form="search" {tip text="Enter subject"}>
			</td>
		</tr>
		<tr>
			<td class="bold nobr">
				{icon name="message" label="<!rt>Content"}
			</td>
			<td>
				<input type="search" size="50" name="search[body][pattern]" value="{$search.body.pattern}"
					form="search" {tip text="Enter body fragment"}>
				<label>
					<input type="checkbox" name="search[body][regexp]" value="1"
						form="search" {if isset($search.body.regexp)} checked{/if}>
					{trans("treat as regular expression")}
				</label>
			</td>
		</tr>
		<tr>
			<td class="bold nobr">
				{icon name="requestor" label="Requestor"}
			</td>
			<td>
				<table width="100%" cellpadding="1">
					<colgroup>
						<col style="width: 1%;">
						<col style="width: 99%;">
					</colgroup>
					<tr>
						<td colspan="2" class="nobr">
							{customerlist form="search" customers=$customerlist selected=$search.customerid version=2 form="search"
								selectname="search[customerid]" inputname="search[custid]" firstoption="— all customers —"
								selecttip="select customer from list or enter his data if is not a customer"
								inputtip="select customer from list or enter his data if is not a customer"}
						</td>
					</tr>
					<tr>
						<td class="nobr">
							{trans("First/last or Company name")}
						</td>
						<td>
							<input type="text" name="search[name]" value="{$search.name}" form="search"
								{tip text="Select customer from list or enter his data if is not a customer"}>
						</td>
					</tr>
					<tr>
						<td>
							{trans("E-mail")}
						</td>
						<td>
							<input type="email" name="search[email]" value="{$search.email}" form="search"
								{tip text="Select customer from list or enter his data if is not a customer"}>
						</td>
					</tr>
					<tr>
						<td>
							{trans("Phone")}
						</td>
						<td>
							<input type="tel" name="search[phone]" value="{$search.phone}" form="search"
								{tip text="Select customer from list or enter his data if is not a customer"}>
						</td>
					</tr>
				</table>
			</td>
		</tr>
		<tr>
			<td class="bold nobr">
				{icon name="home" label="Address"}
			</td>
			<td class="nobr">
				<input type="text" name="search[address]" value="{$search.address}" form="search">
				<strong>{trans("City")}</strong>
				<input type="text" name="search[city]" value="{$search.city}" form="search">
				<strong>{trans("Postcode")}</strong>
				<input type="text" name="search[zip]" value="{$search.zip}" size="10" form="search">
			</td>
		</tr>
		<tr>
			<td class="bold nobr">
				{icon name="owner" label="Owner"}
			</td>
			<td>
				<select size="1" name="search[owner]" form="search"
					{tip text="Select user/owner of the ticket"}>
					<option value="all">{trans("— all owners —")}</option>
					{foreach $userlist as $item}
						<option value="{$item.id}"{if $item.id == $search.owner} selected{/if}>{$item.rname|escape}</option>
					{/foreach}
				</select>
			</td>
		</tr>
		<tr>
			<td class="bold nobr">
				{icon name="queue" label="Queue"}
			</td>
			<td>
				<select size="1" name="search[queue][]" form="search"
					{tip text="Select queue" class="lms-ui-multiselect" trigger="queue"} multiple data-default-value="{trans("— all —")}">
					{foreach $queuelist as $item}
						<option value="{$item.id}"
							{if is_array($search.queue) && in_array($item.id, $search.queue)} selected{/if}>{$item.name}</option>
					{/foreach}
				</select>
			</td>
		</tr>
		<tr>
			<td class="bold nobr">
				{icon name="delete" label="Status"}
			</td>
			<td>
				<select size="1" name="search[state]" form="search"
					{tip text="Select ticket status"}>
					<option value=""{if $search.state == ""} selected{/if}>{trans("— all —")}</option>
					<option value="-1"{if $search.state == "-1"} selected{/if}>{trans("not resolved")}</option>
					{foreach $_RT_STATES as $idx => $s}
						<option value="{$idx}"
							{if is_array($queuedata.state) && in_array($idx, $queuedata.state)} selected{/if}>{$s.label}</option>
					{/foreach}
				</select>
			</td>
		</tr>
		<tr>
			<td class="bold nobr">
				{icon name="service" label="Service type"}
			</td>
			<td>
				<select size="1" name="search[service]" form="search"
					{tip text="Select ticket service" }>
					<option value=""{if $search.state == ""} selected{/if}>{trans("— all —")}</option>
					{foreach $_SERVICETYPES as $key => $ts}
						<option value="{$key}"
							{if is_array($queuedata.service) && in_array($key, $queuedata.service)} selected{/if}>{$ts}</option>
					{/foreach}
				</select>
			</td>
		</tr>
		<tr>
			<td class="bold nobr">
				{icon name="helpdesk" label="Ticket type"}
			</td>
			<td>
				<select size="1" name="search[type]" form="search"
					{tip text="Select ticket type" }>
					<option value=""{if $search.type == ""} selected{/if}>{trans("— all —")}</option>
					{foreach Localisation::arraySort($_RT_TYPES, 'label') as $key => $tt}
						<option value="{$key}"
							{if is_array($queuedata.type) && in_array($key, $queuedata.type)} selected{/if}>{$tt.label}</option>
					{/foreach}
				</select>
			</td>
		</tr>
		<tr>
			<td class="bold nobr">
				{icon name="source" label="Source"}
			</td>
			<td>
				<select size="1" name="search[source]" form="search"
						{tip text="Select ticket source"}>
					<option value=""{if $search.source == ""} selected{/if}>{trans("— all —")}</option>
					{foreach Localisation::arraySort($_RT_SOURCES) as $idx => $source}
						<option value="{$idx}"
							{if is_array($queuedata.source) && in_array($idx, $queuedata.source)} selected{/if}>{$source}</option>
					{/foreach}
				</select>
			</td>
		</tr>
		<tr>
			<td class="bold nobr">
				{icon name="priority" label="Priority"}
			</td>
			<td>
				<select size="1" name="search[priority]" form="search"
					{tip text="Select ticket priority"}>
					<option value=""{if $search.priority == ""} selected{/if}>{trans("— all —")}</option>
					{foreach $_RT_PRIORITIES as $idx => $priority}
						<option value="{$idx}"
							{if is_array($queuedata.priority) && in_array($idx, $queuedata.priority)} selected{/if}>{$priority}</option>
					{/foreach}
					<option value="-101"
						{if is_array($queuedata.priority) && in_array('-101', $queuedata.priority)} selected{/if}>{trans("undefined")}</option>
				</select>
			</td>
		</tr>
		<tr>
			<td class="bold nobr">
				{icon name="uptime" label="Min. Uptime"}
			</td>
			<td>
				<select size="1" name="search[uptime]" form="search"
					{tip text="Select ticket uptime"}>
					<option value=""{if $search.uptime == ""} selected{/if}>{trans("— all —")}</option>
					<option value="604800"{if $search.uptime == "604800"} selected{/if}>{trans("7 days")}</option>
					<option value="2592000"{if $search.uptime == "2592000"} selected{/if}>{trans("30 days")}</option>
					<option value="31536000"{if $search.uptime == "31536000"} selected{/if}>{trans("365 days")}</option>
				</select>
			</td>
		</tr>
		<tr>
			<td class="bold nobr valign-top">
				{icon name="categories" label="Categories"}
			</td>
			<td class="nobr">
				{include file="rt/rtcategoryselection.html" name_prefix="search[categories]" categories=$categories
					form="search"}
			</td>
		</tr>
		{if ConfigHelper::checkPrivilege('helpdesk_advanced_operations')}
			<tr>
				<td class="bold nobr">
					{icon name="delete" label="<!rt>Removed"}
				</td>
				<td>
					<select size="1" name="search[removed]" form="search"
						{tip text="Select ticket status"}>
						<option value=""{if $search.remove == ""} selected{/if}>{trans("— all —")}</option>
						<option value="-1"{if $search.remove == "-1"} selected{/if}>{trans("Not removed")}</option>
						<option value="1"{if $search.remove == "1"} selected{/if}>{trans("Removed")}</option>
					</select>
				</td>
			</tr>
		{/if}
		<tr>
			<td class="bold nobr">
				{icon name="netnode" label="Network node"}
			</td>
			<td class="nobr">
				<select name="search[netnodeid]" form="search"
					{tip text="Select network node (optional)" trigger="netnodeid"}
					onchange="xajax_netnode_changed($(this).val(), $('#netdevid').val())">
					<option value="">{trans("— none —")}</option>
					{foreach $netnodelist as $idx => $n}
						<option value="{$idx}">{$n.name} ({$n.id})</option>
					{/foreach}
				</select>
			</td>
		</tr>
		<tr>
			<td class="bold nobr">
				{icon name="netdevice" label="Device"}
			</td>
			<td class="nobr" id="rtnetdevs">
				{include file="rt/rtnetdevs.html" form="search"}
			</td>
		</tr>
		<tr>
			<td class="bold nobr">
				{icon name="verifier" label="Verifier"}
			</td>
			<td>
				<select size="1" name="search[verifierid]" form="search"
					{tip text="Select user/owner of the ticket"}>
					<option value="0">{trans("— all owners —")}</option>
					{foreach $userlist as $item}
						<option value="{$item.id}"{if $item.id == $search.verifierid} selected{/if}>{$item.rname|escape}</option>
					{/foreach}
				</select>
			</td>
		</tr>
		<tr>
			<td class="bold">
				{icon name="deadline" label="Deadline expired"}
			</td>
			<td>
				<input type="checkbox" name="search[expired]" value="1" form="searhc"
					{tip text="Check if ticket is expired" trigger="expired"}>
			</td>
		</tr>
		<tr>
			<td class="lms-ui-box-buttons" colspan="2">
				{button icon="search" label="Search" type="submit" form="search" accesskey="s"}
			</td>
		</tr>
	</tbody>
</table>

<script>

	$(function() {
		$('[name="search[subject]"]').focus();
	});

</script>
{/block}
