<!--// $Id$ //-->
{$show_timetable_event_notes = ConfigHelper::checkConfig('customers.show_timetable_event_notes')}

{css}
{js}

{if !$show_timetable_event_notes}
<style>

	#eventspanel .title {
		width: 30em;
	}
	#eventspanel .description {
		width: 30em;
	}
	#eventspanel .note {
		width: 0em;
	}

</style>
{/if}
<script>

	$(function() {
		$('[name="customer-events-from-date"]').change(function() {
			location.href = '?m={$layout.module}&id={$objectid}&events-from-date=' +
				$(this).val();
		});

		$('.clear-event-filter').click(function() {
			location.href = '?m={$layout.module}&id={$objectid}&clear-event-filter=1'
			return false;
		});

		$('#show-in-timetable').click(function() {
			var from_date = $('[name="customer-events-from-date"]').val();
			if (from_date != '') {
				var date = from_date.split('/');
				location.href = $(this).attr('href') + '&day=' + date[2] + '&month=' + date[1] + '&year=' + date[0];
			} else {
				location.href = $(this).attr('href');
			}
			return false;
		});
	});

</script>

{tab_container id="customerevents" label="Customer Timetable"}

	{tab_header content_id="eventspanel"}
		{tab_header_cell icon="lms-ui-icon-calendar"}
			<strong>{trans("Customer Timetable")}</strong>
			{if $limit > 0}
				&nbsp;({t a=$limit}last $a events{/t})
			{/if}
			<label>
				{trans("from")}
				<input type="text" name="customer-events-from-date" size="10" maxlength="10" placeholder="{trans("yyyy/mm/dd")}"
					{tip class="lms-ui-date" text="Enter date in 'yyyy/mm/dd' format (empty field means 1970/01/01) or click to choose it from calendar"}
					value="{$events_from_date}">
			</label>
			{button type="link" class="clear-event-filter" icon="delete" href="#" tip="Clear filter"}
		{/tab_header_cell}
		{tab_header_cell}
			<a href="?m=eventadd&customerid={$customerinfo.id}">
				{trans("New Event")}
				{icon name="next" class="fa-fw"}
			</a>
			<a id="show-in-timetable" href="?m=eventlist&u={$customerinfo.id}">
				{trans("Show in timetable")}
				{icon name="next" class="fa-fw"}
			</a>
			<a href="?m={$layout.module}&id={if $nodeinfo.id}{$nodeinfo.id}{else}{$customerinfo.id}{/if}&allevents={if $allevents}0{else}1{/if}">
				{if $allevents}{trans("Hide closed")}{else}{trans("Show closed")}{/if}
				{icon name="next" class="fa-fw"}
			</a>
		{/tab_header_cell}
	{/tab_header}

	{tab_contents id="eventspanel"}
		{tab_table}
			<div class="lms-ui-tab-table-row header">
				<div class="lms-ui-tab-table-column type">
					<strong>{trans("Type:")}</strong>
					<br>{trans("Ticket ID:")}
				</div>
				<div class="lms-ui-tab-table-wrapper col-4">
					<div class="lms-ui-tab-table-column creation-date">
						<strong>{trans("Date:")}</strong>
					</div>
					<div class="lms-ui-tab-table-wrapper title-description col-3">
						<div class="lms-ui-tab-table-column title">
							{trans("Title:")}
						</div>
						<div class="lms-ui-tab-table-column description">
							{trans("Description:")}
						</div>
						<div class="lms-ui-tab-table-column note">
							{if $show_timetable_event_notes}
								{trans("Note")}
							{/if}
						</div>
					</div>
				</div>

				<div class="lms-ui-tab-table-column buttons">
					&nbsp;
				</div>
			</div>

			{section name=eventlist loop=$eventlist max=$limit}
			{$event=$eventlist[eventlist]}
				<div class="lms-ui-tab-table-row{if $event.closed} blend{/if}" data-target-url="?m=eventinfo&id={$event.id}">
					<div class="lms-ui-tab-table-column type" style="{if !$event.closed}{if isset($_EVENTTYPES[$event.type])} {$_EVENTTYPES[$event.type].style}{/if}{/if}">
						{trans($_EVENTTYPES[$event.type].label)}
						{if $event.ticketid}
							<br><A href="?m=rtticketview&id={$event.ticketid}">#{$event.ticketid}</A>
						{/if}
					</div>
					<div class="lms-ui-tab-table-wrapper col-4">
						<div class="lms-ui-tab-table-column creation-date">
							{$event.date|date_format:"Y-m-d"}
							{if $event.endtime == 86400}
								{if $event.enddate > $event.date}- {$event.enddate|date_format:"Y-m-d"}{/if}
								{trans("whole day")}
							{else}
								{($event.date + $event.begintime)|date_format:"H:i"}
								{if $event.begintime != $event.endtime}
									- {($event.enddate + $event.endtime)|date_format:"H:i"}
								{/if}
							{/if}
						</div>
						<div class="lms-ui-tab-table-wrapper title-description col-3">
							<div class="lms-ui-tab-table-column title">
								{$event.title|escape}
							</div>
							<div class="lms-ui-tab-table-column description">
								{$event.description|default:"-"}
							</div>
							<div class="lms-ui-tab-table-column note">
								{if $show_timetable_event_notes}
									{$event.note|escape|replace:"\n":"<BR>"}
								{/if}
							</div>
						</div>
					</div>
					<div class="lms-ui-tab-table-column buttons">
						{if $event.closed}
							{button type="link" icon="close" href="?m=eventedit&id={$event.id}&action=open"
								tip="Open"}
						{else}
							{button type="link" icon="open" href="?m=eventedit&id={$event.id}&action=close"
								tip="Close"}
						{/if}
						{button type="link" class="delete-event" href="?m=eventdel&id={$event.id}" icon="delete"
							tip="Delete"}
						{button type="link" icon="edit" href="?m=eventedit&id={$event.id}" tip="Edit"}
					</div>
				</div>
			{sectionelse}
				<div class="lms-ui-tab-empty-table">
					{if $allevents}
						{trans("There are no events in timetable.")}
					{else}
						{trans("There are no open events in timetable.")}
					{/if}
				</div>
			{/section}
		{/tab_table}
	{/tab_contents}
{/tab_container}