{extends file="layout.html"}
{block name=title}LMS: {$layout.pagetitle|striphtml}{/block}
{block name=module_content}
<!--// $Id$ //-->
<H1>{$layout.pagetitle}</H1>
<table class="lmsbox lms-ui-background-cycle">
	<colgroup>
		<col style="width: 1%;">
		<col style="width: 1%;">
		<col style="width: 1%;">
		<col style="width: 95%;">
		<col style="width: 1%;">
		<col style="width: 1%;">
	</colgroup>
	<thead>
		<tr>
			<td class="nobr">
				{icon name="division"}
				<strong>{trans("Name:")}</strong>
			</td>
			<td class="text-right">
				<strong>{trans("ID:")}</strong>
			</td>
			<td class="text-left nobr">
				{trans("Text label:")}
			</td>
			<td class="text-left nobr">
				{trans("Long name:")}
			</td>
			<td class="text-right nobr">
				{trans("Natural person")}
			</td>
			<td class="text-right nobr">
				{trans("Customers:")}
			</td>
			<td class="text-right nobr">
				{button type="link-button" icon="add" label="Add division" href="?m=divisionadd"}
			</td>
		</tr>
		{if $pagination->getTotal() != 0}
			<tr>
				<td class="lms-ui-pagination" colspan="7">
					{include file="pagination.html"}
				</td>
			</tr>
		{/if}
	</thead>
	<tbody>
		{foreach $divisionlist as $division}
			<tr class="{if $division.status} blend{/if}" data-name="{$division.shortname|escape}">
				<td class="nobr" data-target-url="?m=divisionedit&id={$division.id}">
					{icon name="division"}
					<strong>{$division.shortname|escape}</strong>
				</td>
				<td class="text-right nobr" data-target-url="?m=divisionedit&id={$division.id}">
					({$division.id|string_format:"%04d"})
				</td>
				<td class="text-left">
					{$division.label|escape|default:"-"}
				</td>
				<td class="text-left" data-target-url="?m=divisionedit&id={$division.id}">
					{$division.name|escape}
				</td>
				<td class="text-center nobr">
					{if $division.naturalperson}
						{capture assign="fullname"}
							{$division.firstname} {$division.lastname}
							<br>
							{t a=$division.birthdate|date_format:"Y-m-d"}Birth date: $a{/t}
						{/capture}
						{icon name="checked" tip=$fullname}
					{/if}
				</td>
				<td class="text-right" data-target-url="?m=divisionedit&id={$division.id}">
					{$division.cnt|default:0}
				</td>
				<td class="lms-ui-buttons text-right nobr">
					{button type="link" icon="lock" tip="{if $division.status}{trans("Unlock")}{else}{trans("Lock")}{/if}" href="?m=divisionedit&amp;id={$division.id}&amp;changestatus=1"}
					{if isset($division.unblock_delete)}
						{button type="link" icon="delete" tip="Delete" class="delete-division" href="?m=divisiondel&id={$division.id}"}
					{else}
						{button type="link" icon="delete" tip="Some users are assigned to this division!" disabled=true}
					{/if}
					{button type="link" icon="clone" tip="Clone" class="clone-division" href="?m=divisionclone&id={$division.id}"}
					{button type="link" icon="edit" tip="Edit" href="?m=divisionedit&id={$division.id}"}
				</td>
			</tr>
		{foreachelse}
			<tr>
				<td colspan="7" class="empty-table">
					{trans("No such divisions in database.")}
				</td>
			</tr>
		{/foreach}
	</tbody>
	<tfoot>
		{if $pagination->getTotal() != 0}
			<tr>
				<td class="lms-ui-pagination division-context" colspan="7">
					{include file="pagination.html"}
				</td>
			</tr>
		{/if}
	</tfoot>
</table>

<script>

	$(function() {
		$('.division-context').on( 'lms:division_selection', function() {
			location.reload();
		});

		$('.delete-division').click(function() {
			var name = $(this).closest('tr').attr('data-name');
			confirmDialog($t("Are you sure, you want to delete division '$a'?", name), this).done(function() {
				location.href = $(this).attr('href');
			});
			return false;
		});
		$('.clone-division').click(function() {
			var name = $(this).closest('tr').attr('data-name');
			confirmDialog($t("Are you sure, you want to clone division '$a'?", name), this).done(function() {
				location.href = $(this).attr('href');
			});
			return false;
		});
	});

</script>

{/block}
