{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: 97%;">
		<COL style="width: 1%;">
		<COL style="width: 1%;">
		<COL style="width: 1%;">
	</COLGROUP>
	<THEAD>
	<TR>
		<TD scope="col" class="nobr">
			{icon name="customergroup"}&nbsp;{trans("Name:")}
			<br>
			<span class="lighter">{icon name="optional-info"}&nbsp;{trans("Description:")}</span>
		</TD>
		<TD scope="col" class="text-right lighter">
			{trans("ID:")}
		</TD>
		<TD scope="col" class="text-right lighter">
			{trans("Members:")}
		</TD>
		<TD scope="col" class="text-right nobr">
			{button icon="customergroup" label="Add group" href="?m=customergroupadd"}
			<br>
			{t a=$listdata.total|default:"0"}Total: $a{/t}
		</TD>
	</TR>
	</THEAD>
	<TFOOT>
	<TR>
		<TD colspan="4" class="text-right bold nobr">
			{icon name="info"}&nbsp;{trans("Total:")}
			{$listdata.totalcount|default:"0"}
		</TD>
	</TR>
	</TFOOT>
	<TBODY>
	{foreach $customergrouplist as $customergroup}
	<TR class="highlight" data-target-url="?m=customergroupinfo&id={$customergroup.id}" data-name="{$customergroup.name}">
		<TD>
			{icon name="customergroup"}&nbsp;<span class="bold">{$customergroup.name}</span><BR>
			{if $customergroup.description}{icon name="optional-info"}&nbsp;{$customergroup.description|escape|replace:"\n":"<BR>"}{/if}
		</TD>
		<TD class="text-right">
			({$customergroup.id|string_format:"%04d"})
		</TD>
		<TD class="text-right">
			{$customergroup.customerscount}
		</TD>
		<TD class="lms-ui-buttons text-right nobr">
			{if $customergroup.customerscount}
				{button type="link" class="delete-group-alert" icon="delete" tip="Delete"}
			{else}
				{button type="link" class="delete-group" icon="delete" tip="Delete" data_customer_group_id=$customergroup.id}
			{/if}
			{button type="link" icon="edit" tip="Edit" href="?m=customergroupedit&id={$customergroup.id}"}
			{button type="link" icon="info" tip="Info" href="?m=customergroupinfo&id={$customergroup.id}"}
		</TD>
	</TR>
	{foreachelse}
	<tr>
		<td colspan="4" class="empty-table">
			{trans("There are no such groups in database.")}
		</td>
	</tr>
	{/foreach}
	</TBODY>
</TABLE>
	<script>
		$('.delete-group').click(function() {
			var name = $(this).closest('tr').attr('data-name');
			confirmDialog($t("Are you sure, you want to remove group '$a'?", name), this).done(function() {
				location.href = '?m=customergroupdel&id=' + $(this).attr('data-customer-group-id');
			});
			return false;
		});
		$('.delete-group-alert').click(function() {
			var name = $(this).closest('tr').attr('data-name');
			alertDialog($t("Group '$a' has members and cannot be deleted!", name), this);
				return;
		});
	</script>
{/block}
