<style>
TABLE {
	width: 100%;
	border: solid 1px #000;
}
TD {
	vertical-align: top;
	border: solid 1px #000;
}
</style>
<script>
function confirmUser(user, date, time)
{
	var post = { user: user, date: date, time: time };
	post.{{ security.getTokenKey() }} = '{{ security.getToken() }}';

	var posting = $.post('/calendar/confirm', post);
	posting.done(function( data ) {
			if(data.Error)
			{
				$('#Error').show();
				$('#Error').html(data.Error);
			}
			else
			{
				window.location.href = '/calendar/report';
			}
		});

	return true;
}
</script>
<table>
<tr>
	<th>Понеделник</th>
	<th>Вторник</th>
	<th>Сряда</th>
	<th>Четвъртък</th>
	<th>Петък</th>
	<th>Събота</th>
	<th>Неделя</th>
{% for i in 0..100 %}
	{% if i % 7 == 0 and date('Y-m-d', strtotime(startDate ~ ' +' ~ i ~ ' days')) > endDate %}
</tr>
		<?php break; ?>
	{% endif %}
	{% if i % 7 == 0 %}
</tr><tr>
	{% endif %}
	<td>
		<u><b>{{ date('Y-m-d', strtotime(startDate ~ ' +' ~ i ~ ' days')) }}</b></u><br>
		{% if in_array(date('Y-m-d', strtotime(startDate ~ ' +' ~ i ~ ' days')), array_keys(dates)) %}
			{% set hour = '' %}
			{% for candidate in dates[date('Y-m-d', strtotime(startDate ~ ' +' ~ i ~ ' days'))] %}
				{% if hour != date('H:i', strtotime(candidate.DateTime ~ ' +' ~ i ~ ' days')) %}
					<b>{{ date('H:i', strtotime(candidate.DateTime ~ ' +' ~ i ~ ' days')) }}</b><br>
					{% set hour = date('H:i', strtotime(candidate.DateTime ~ ' +' ~ i ~ ' days')) %}
				{% endif %}
				{{ candidate.Confirmed ? '<b>' : '' }}{{ candidate.User.Name }}{{ candidate.Confirmed ? '</b>' : (userId == 3 and strtotime(candidate.DateTime) > strtotime('today') ? '&nbsp;<a href="#" onclick="confirmUser('~candidate.UserId~', '~"'"~date('Y-m-d', strtotime(startDate ~ ' +' ~ i ~ ' days'))~"'"~', '~"'"~date('H:i', strtotime(candidate.DateTime ~ ' +' ~ i ~ ' days'))~"'"~'); return false;">v</a>' : '') }}<br>
			{% endfor %}
		{% endif %}
	</td>
{% endfor %}
</table>

<table>
<tr>
	<th>
	Име
	</th>
	<th>
	Заявени
	</th>
	<th>
	Потвърдени
	</th>
</tr>
{% for name, person in people %}
<tr>
	<td>
		{{ name }}
	</td>
	<td>
		{{ person['Requested'] | default(0) + person['Initial'] | default(0) }}
	</td>
	<td>
		{{ person['Initial'] | default(0) }}
	</td>
</tr>
{% endfor %}
</table>