{! admin/util/minimal-grid !}
{! admin/util/search !}

<div class="e-row-variable" style="margin-bottom: 20px">
	<div class="e-col-50 e-no-padding">
		<a href="/user/add">{"Add"}</a>
		&nbsp;|&nbsp;
		<a href="/user/import">{"Import"}</a>
		&nbsp;|&nbsp;
		<a href="/user/export">{"Export"}</a>
		{% if User::require_acl ('user/roles') %}
		&nbsp;|&nbsp;
		<a href="/user/roles">{"Roles"}</a>
		{% end %}
		{% if User::require_acl ('settings') %}
		&nbsp;|&nbsp;
		<a href="/user/settings">{"Settings"}</a>
		&nbsp;|&nbsp;
		<a href="/admin/extended?extends=User&name=Accounts">{"Custom Fields"}</a>
		{% end %}
	</div>
	<div class="e-col-50 e-no-padding" style="text-align: right">
		<form method="get" id="search-form">
			<input type="text" name="q" id="search-query" size="40" value="{{q|quotes}}" />
			<button>{"Search"}</button>
			{% if q != '' %}
			<button onclick="window.location.href = '/user/admin'; return false">{"Clear"}</button>
			{% end %}
		</form>
	</div>
</div>

<div class="e-row-variable">
	<div class="e-col-50 e-no-padding">
		{! navigation/pager?style=results&url=[url]&total=[total]&count=[count]&limit=[limit] !}
	</div>
	<div class="e-col-50 e-no-padding" style="text-align: right">
		{% if total > $data->limit %}
		{! navigation/pager?style=numbers&url=[url]&total=[total]&count=[count]&limit=[limit] !}
		{% end %}
	</div>
</div>

<table width="100%">
	<tr>
		<th width="18%">{"Name"}</th>
		<th width="13%">{"Phone"}</th>
		<th width="20%">{"Email"}</th>
		<th width="16%">{"Company"}</th>
		<th width="15%">{"Title"}</th>
		<th width="8%">
			<select class="search-option" data-prefix="type">
				<option value="">{"Role"}</option>
				{% foreach User::allowed_roles () as _role %}
				<option value="{{_role}}">{{_role|ucfirst}}</option>
				{% end %}
			</select>
		</th>
		<th width="10%">&nbsp;</th>
	</tr>
{% foreach users %}
	<tr>
		<td class="title"><a href="/user/details?id={{ loop_value->id }}">{{ loop_value->name }}</a></td>
		<td>{{ loop_value->phone }}</td>
		<td><a href="mailto:{{ loop_value->email }}">{{ loop_value->email }}</a></td>
		<td><a href="#" class="search-for" data-search="company:&quot;{{ loop_value->company }}&quot;">{{ loop_value->company }}</td>
		<td>{{ loop_value->title }}</td>
		<td><a href="#" class="search-for" data-search="type:{{ loop_value->type}}">{{ loop_value->type|ucfirst }}</a></td>
		<td class="edit">
			<a href="/user/edit?id={{ loop_value->id }}">{"Edit"}</a>
			{% if User::val ('id') != $data->loop_value->id %}
			|
			<a href="/user/delete?id={{ loop_value->id }}" onclick="return confirm ('{"Are you sure you want to delete this user?"}');">{"Delete"}</a>
			{% end %}
			</td>
	</tr>
{% end %}
</table>

{% if total > $data->limit %}
{! navigation/pager?style=numbers&url=[url]&total=[total]&count=[count]&limit=[limit] !}
{% end %}

<script>
$(function () {
	$.search_init ({
		form: '#search-form',
		query: '#search-query',
		links: '.search-for',
		options: '.search-option'
	});
});
</script>
