{block name=eventlistfilter}
{$hide_disabled_users = ConfigHelper::checkConfig('timetable.hide_disabled_users', ConfigHelper::checkConfig('phpui.timetable_hide_disabled_users'))}
{$hide_deleted_users = ConfigHelper::checkConfig('timetable.hide_deleted_users', ConfigHelper::checkConfig('phpui.timetable_hide_deleted_users'))}
	<TR>
		<TD colspan="6" class="text-center nobr no-print">
			<A href="?m=eventlist&day=1&month={if $filter.month == 1}12{else}{math equation="x-1" x=$filter.month}{/if}&amp;year={if $filter.month == 1}{math equation="x-1" x=$filter.year}{else}{$filter.year}{/if}">&laquo;&laquo;&laquo;&nbsp;</A>
			{section name=days loop=$days.day}
				{if !$days.dow[days]}<span class="light">{/if}
				<A href="?m=eventlist&day={$days.day[days]}&month={$filter.month}&year={$filter.year}">&nbsp;{if $days.sel[days]}
				<B>*{/if}{$days.day[days]|string_format:"%d"}{if $days.sel[days]}*</B>{/if}
				</A>{if !$days.dow[days]}</span>{/if}
			{/section}
			<A href="?m=eventlist&day=1&month={if $filter.month == 12}1{else}{math equation="x+1" x=$filter.month}{/if}&amp;year={if $filter.month == 12}{math equation="x+1" x=$filter.year}{else}{$filter.year}{/if}">&raquo;&raquo;&raquo;&nbsp;</A>
		</TD>
	</TR>
	<TR>
		<TD colspan="6" class="nobr no-print">
			<div class="lms-ui-filter-container">
				<div class="lms-ui-filter-definition">
					<FORM method="POST" action="?m=eventlist" name="filter" id="filter">
						<INPUT type="submit" class="hiddenbtn"> <INPUT type="HIDDEN" name="m" value="eventlist">
						<SELECT name="type[]" onchange="document.filter.submit();" class="lms-ui-multiselect lms-ui-multiselect-filter" multiple data-default-value="{trans("Events types")}">
							{foreach Localisation::arraySort($_EVENTTYPES, 'label') as $id => $eventtype}
								<OPTION value="{$id}"{if is_array($filter.type) && in_array($id, $filter.type)} selected{/if}>{$eventtype.label}</OPTION>
							{/foreach}
						</SELECT>

						<select name="g[]" multiple
							class="lms-ui-advanced-select-test auto-width"
							data-placeholder="{trans("User groups")}">
							<option value="">{trans("- any -")}</option>
							{foreach $usergroups as $usergroup}
								<option value="{$usergroup.id}" data-users="{$usergroup.users}"
									{if !empty($filter.usergroups) && in_array($usergroup.id, $filter.usergroups)} selected{/if}
									>{$usergroup.name|escape}</option>
							{/foreach}
						</select>

						{user_selection
							elemname="a[]"
							placeholder="Users"
							multiple=true
							selected=$filter.userid
							visible=$visible_users
							hide_disabled=$hide_disabled_users
							hide_deleted=$hide_deleted_users
						}

						<label>
							<input type="hidden" name="userand" value="0">
							{if $filter.userand}{trans("and")}{else}{trans("or")}{/if}
							<input type="checkbox" name="userand" value="1" onchange="document.filter.submit();"{if isset($filter.userand) && $filter.userand} checked{/if}{tip text="Use logical conjunction AND instead of OR in user selection"}>
						</label>

						<select name="divisionid[]" onchange="document.filter.submit();" multiple
							class="lms-ui-multiselect"
							data-default-value="{trans("— any —")}"
							{tip text="Divisions"}>
							{foreach $divisions as $division}
								{if !$division.status}
									<option value="{$division.id}"
										{if !empty($filter.divisionid) && in_array($division.id, $filter.divisionid)} selected{/if}
										>{$division.label|escape}</option>
								{/if}
							{/foreach}
						</select>

						<SELECT name="privacy" onchange="document.filter.submit();" {tip text="Select privacy flag"}>
							<OPTION value="0"{if $filter.privacy == "0"} selected{/if}>{trans("— all —")}</OPTION>
							<OPTION value="1"{if $filter.privacy == "1"} selected{/if}>{trans("public")}</OPTION>
							<OPTION value="2"{if $filter.privacy == "2"} selected{/if}>{trans("private")}</OPTION>
						</SELECT>
						{customerlist form="filter" customers=$customers selected=$filter.customerid selectname="u" inputname="u" customOnChange="document.filter.submit();" version=2}
						{button label="Today" onclick="location.href='?m=eventlist&day={$smarty.now|date_format:"d"}&month={$smarty.now|date_format:"m"}&year={$smarty.now|date_format:"Y"}';"}
						<input type="text" name="date" class="lms-ui-date" value="{if $filter.year}{sprintf("%04d/%02d/%02d", $filter.year, $filter.month, $filter.day)}{/if}" onchange="document.filter.submit();">
						<SELECT name="closed" onchange="document.filter.submit();" {tip text="Select status"}>
							<OPTION value="" {if $filter.closed == ""} selected{/if}>{trans("— all —")}</OPTION>
							<OPTION value="0"{if $filter.closed == "0"} selected{/if}>{trans("opened<!plural:event>")}</OPTION>
							<OPTION value="1"{if $filter.closed == "1"} selected{/if}>{trans("closed<!plural:event>")}</OPTION>
						</SELECT>
					</FORM>
				</div>
				{persistent_filter}
			</div>
		</TD>
	</TR>

	<script>

		$(function() {
			$('[name="g[]"]').change(function() {
				var that = $(this);
				var userInGroups = [];
				var users = that.find('option:selected').attr('data-users');
				if (typeof(users) !== 'undefined') {
					userInGroups = that.find('option:selected').attr('data-users').split(',');
				}
				userInGroups = [...new Set(userInGroups)];
				$('[name="a[]"] option').each(function() {
					$(this).toggle(!userInGroups.length || !that.val().length || userInGroups.indexOf($(this).val()) !== -1);
					$(this).prop('selected', $(this).prop('selected') && (!userInGroups.length || userInGroups.indexOf($(this).val()) !== -1));
				});
				updateAdvancedSelectsTest('[name="a[]"]');
			});
		});

	</script>
{/block}
