{extends file="layout.html"}
{block name=title}LMS: {$layout.pagetitle|striphtml}{/block}
{block name=module_content}
<!--// $Id$ //-->
{if $layout.module=="accountsearch"}{assign var=suffix value="&s=1"}{/if}
<H1>{$layout.pagetitle}</H1>
<TABLE class="lmsbox">
    <COLGROUP>
        <COL style="width: 96%;">
        <COL style="width: 1%;">
        <COL style="width: 1%;">
        <COL style="width: 1%;">
        <COL style="width: 1%;">
    </COLGROUP>
    <THEAD>
	<TR>
		<TH scope="col">
                        <SPAN class="nobr">
			<IMG src="img/account.gif" alt=""> <A href="?m={$layout.module}{$suffix}&amp;o=login{if $listdata.direction == "asc" && $listdata.order == "login"},desc{/if}"><B>{trans("Login<!account>")}</B></A> {if $listdata.order == "login"}<IMG src="img/{if $listdata.direction == "desc"}asc{else}desc{/if}_order.gif" alt="">{/if}
			@
                        <A href="?m={$layout.module}{$suffix}&amp;o=domain{if $listdata.direction == "asc" && $listdata.order == "domain"},desc{/if}">{trans("Domain:")}</A> {if $listdata.order == "domain"}<IMG src="img/{if $listdata.direction == "desc"}asc{else}desc{/if}_order.gif" alt="">{/if}</SPAN><BR>
                        <SPAN class="nobr lighter"><IMG src="img/customer.gif" ALT=""> <A href="?m={$layout.module}{$suffix}&amp;o=customername{if $listdata.direction == "asc" && $listdata.order == "customername"},desc{/if}">{trans("Owner:")}</A> {if $listdata.order == "customername"}<IMG src="img/{if $listdata.direction == "desc"}asc{else}desc{/if}_order.gif" alt="">{/if}</SPAN>
		</TH>
		<TH scope="col" class="text-right">
                        <SPAN class="nobr lighter"><A href="?m={$layout.module}{$suffix}&amp;o=id{if $listdata.direction == "asc" && $listdata.order == "id"},desc{/if}">{trans("ID:")}</A> {if $listdata.order == "id"}<IMG src="img/{if $listdata.direction == "desc"}asc{else}desc{/if}_order.gif" alt="">{/if}</SPAN>
		</TH>
		<TH scope="col" class="text-right lighter">
                        <SPAN class="nobr">{trans("Type (sh/mail/www/ftp/sql/cloud):")}</SPAN><BR>
                        <SPAN class="nobr">{trans("Quota (sh/mail/www/ftp/sql/cloud):")}</SPAN>
		</TH>
		<TH scope="col" class="text-right lighter">
                        <SPAN class="nobr"><A href="?m={$layout.module}{$suffix}&amp;o=lastlogin{if $listdata.direction == "asc" && $listdata.order == "lastlogin"},desc{/if}">{trans("Last login:")}</A>{if $listdata.order == "lastlogin"} <IMG src="img/{if $listdata.direction == "desc"}asc{else}desc{/if}_order.gif" alt="">{/if}</SPAN><BR>
                        <SPAN class="nobr"><A href="?m={$layout.module}{$suffix}&amp;o=expdate{if $listdata.direction == "asc" && $listdata.order == "expdate"},desc{/if}">{trans("Expiration date:")}</A>{if $listdata.order == "expdate"} <IMG src="img/{if $listdata.direction == "desc"}asc{else}desc{/if}_order.gif" alt="">{/if}</SPAN>
		</TH>
		<TH scope="col" class="text-right">
                        <SPAN class="nobr">{t a=$listdata.total}Total: $a{/t}</SPAN>
		</TH>
	</TR>
	<TR>
	        <TD colspan="4" class="nobr">
                                <FORM method="GET" action="?m={$layout.module}" name="filter">
                                        <INPUT type="submit" class="hiddenbtn">
                                        <INPUT type="HIDDEN" name="m" value="{$layout.module}">
                                        {if $suffix}<INPUT type="HIDDEN" name="s" value="1">{/if}
                                        <INPUT type="HIDDEN" name="page" value="1">
                                        <SPAN class="bold">{trans("Filter:")}</SPAN> {trans("Owner:")}
                                        <SELECT size="1" name="u" OnChange="document.filter.submit();">
                                                <OPTION value=""{if $listdata.customer == ""} SELECTED{/if}>{trans("— all owners —")}</OPTION>
                                                <OPTION value="0"{if $listdata.customer == "0"} SELECTED{/if}>{trans("SYSTEM ACCOUNT")}</OPTION>
                                                {foreach from=$customerlist item=customer}
                                                <OPTION value="{$customer.id}"{if $customer.id == $listdata.customer} SELECTED{/if}>{$customer.customername|truncate:35:"&hellip;":true}</OPTION>
                                                {/foreach}
                                        </SELECT>
                                        {trans("Type:")}
                                        <SELECT size="1" name="t" ONCHANGE="document.filter.submit();">
											<OPTION value="0"{if !$listdata.type} SELECTED {/if}>{trans("— all —")}</OPTION>
											{foreach $_ACCOUNTTYPES as $typeidx => $type}
											<OPTION value="{$typeidx}"{if $listdata.type == $typeidx} selected{/if}>{$type.label}</OPTION>
											{/foreach}
                                        </SELECT>
                                        {trans("Status:")}
                                        <SELECT size="1" name="k" OnChange="document.filter.submit();">
                                                <OPTION value="0"{if !$listdata.kind} SELECTED {/if}>{trans("— all —")}</OPTION>
                                                <OPTION value="1"{if $listdata.kind == 1} SELECTED {/if}>{trans("expired")}</OPTION>
                                                <OPTION value="2"{if $listdata.kind == 2} SELECTED {/if}>{trans("active")}</OPTION>
                                        </SELECT>
                                        {trans("Domain:")}
                                        <SELECT size="1" name="d" OnChange="document.filter.submit();">
                                                <OPTION value=""{if $listdata.domain == ""} SELECTED{/if}>{trans("— all —")}</OPTION>
                                                {section name=domainlist loop=$domainlist}
                                                <OPTION value="{$domainlist[domainlist].id}"{if $domainlist[domainlist].id == $listdata.domain} SELECTED{/if}>{$domainlist[domainlist].name}</OPTION>
                                                {/section}
                                        </SELECT>
                                </FORM>
                </TD>
                <TD class="text-right nobr">
                                <A href="?m=accountadd{if $listdata.customer}&cid={$listdata.customer}{/if}{if $listdata.domain}&did={$listdata.domain}{/if}">{trans("New Account")} <IMG src="img/save.gif" alt=""></A>
		</TD>
	</TR>
	{if $listdata.total != 0}
	<TR>
		<TD class="lms-ui-pagination" COLSPAN="5">
			{include file="scroller.html" loop=$accountlist adlink=$suffix}
		</TD>
	</TR>
	{/if}
    </THEAD>
    <TBODY>
	{foreach $_ACCOUNTTYPES as $typeidx => $type}
	{$totalquota[$typeidx]=0}
	{/foreach}
	{cycle values="light,lucid" print=false}
	{section name=accountlist loop=$accountlist start=$start max=$pagelimit}
	<TR class="highlight {cycle}{if $accountlist[accountlist].expdate != 0 && $accountlist[accountlist].expdate < $smarty.now} blend{/if}" data-name="{$accountlist[accountlist].login}@{$accountlist[accountlist].domain}">
		<TD OnClick="return self.location.href='?m=accountinfo&id={$accountlist[accountlist].id}';">
                        <SPAN class="nobr bold"><IMG src="img/account.gif" alt=""> {$accountlist[accountlist].login}@{$accountlist[accountlist].domain}</SPAN>
			{if $accountlist[accountlist].ownerid}
			<BR><IMG src="img/customer.gif" alt="">
			<A href="?m=customerinfo&id={$accountlist[accountlist].ownerid}">
			{$accountlist[accountlist].customername|truncate:40:"&hellip;":true} ({$accountlist[accountlist].ownerid|string_format:"%04d"})
			</A>
			{/if}
		</TD>
		<TD OnClick="return self.location.href='?m=accountinfo&id={$accountlist[accountlist].id}';">
			({$accountlist[accountlist].id|string_format:"%04d"})
		</TD>
		<TD class="text-right" OnClick="return self.location.href='?m=accountinfo&id={$accountlist[accountlist].id}';">
			{foreach $_ACCOUNTTYPES as $typeidx => $type}
			{if ($accountlist[accountlist].type & $typeidx) == $typeidx}*{else}-{/if}
			{if !$type@last}/{/if}
			{/foreach}
			<BR>
			{foreach $_ACCOUNTTYPES as $typeidx => $type}
			{$idx='quota_'|cat:$type.alias}
			{$accountlist[accountlist][$idx]}
			{$totalquota[$typeidx]=$totalquota[$typeidx]+$accountlist[accountlist][$idx]}
			{if !$type@last}/{/if}
			{/foreach}
		</TD>
		<TD class="text-right" OnClick="return self.location.href='?m=accountinfo&id={$accountlist[accountlist].id}';">
			<SPAN class="nobr">{if $accountlist[accountlist].lastlogin}{$accountlist[accountlist].lastlogin|date_format:"Y-m-d H:i"}{/if}</SPAN><BR>
			<SPAN class="nobr">{if $accountlist[accountlist].expdate}{$accountlist[accountlist].expdate|date_format:"Y-m-d"}{/if}</SPAN>
		</TD>
		<TD class="text-right">
			{assign var=account value="`$accountlist[accountlist].login`@`$accountlist[accountlist].domain`"}
			<SPAN class="nobr">
			<A href="?m=accountpasswd&id={$accountlist[accountlist].id}"><IMG src="img/pass.gif" alt="{trans("Change password")}" title="{trans("Change password")}"></A>
			<A href="?m=aliasadd&accountid={$accountlist[accountlist].id}"><IMG src="img/alias.gif" alt="{trans("Create alias")}" title="{trans("Create alias")}"></A>
			<A class="delete-account" href="?m=accountdel&id={$accountlist[accountlist].id}"><IMG src="img/delete.gif" title="{trans("Delete")}" alt="{trans("Delete")}"></A>
			<A href="?m=accountedit&id={$accountlist[accountlist].id}"><IMG src="img/edit.gif" alt="{trans("Edit")}" title="{trans("Edit")}"></A>
			<A href="?m=accountinfo&id={$accountlist[accountlist].id}"><IMG src="img/info.gif" alt="{trans("Info")}" title="{trans("Info")}"></A>
                        </SPAN>
		</TD>
	</TR>
	{sectionelse}
	<tr>
		<td colspan="5" class="empty-table">
			{trans("No such accounts in database.")} {trans('Click $a to create.', '<a href="?m=accountadd">'|cat: trans("here")|cat: '</a>')}
		</td>
	</tr>
	{/section}
    </TBODY>
    <TFOOT>
	{if $listdata.total != 0}
	<TR>
		<TD class="lms-ui-pagination" COLSPAN="5">
			{include file="scroller.html" loop=$accountlist adlink=$suffix}
		</TD>
	</TR>
	{/if}
	<TR>
		<TD colspan="3" class="text-right bold nobr">
			{trans("Total:")}
			{foreach $_ACCOUNTTYPES as $typeidx => $type}
			{$totalquota[$typeidx]}
			{if !$type@last}/{/if}
			{/foreach}
		</TD>
		<TD colspan="2" class="text-right nobr">
                        <A href="?m=accountadd{if $listdata.customer}&cid={$listdata.customer}{/if}{if $listdata.domain}&did={$listdata.domain}{/if}">{trans("New Account")} <IMG src="img/save.gif" alt=""></A>
		</TD>
	</TR>
    </TFOOT>
</TABLE>
	<script>
		$('.delete-account').click(function() {
			var name = $(this).closest('tr').attr('data-name');
			confirmDialog($t("Are you sure, you want to delete account '$a' and all assigned to them aliases?", name), this).done(function() {
				location.href = $(this).attr('href');
			});
			return false;
		});
	</script>
{/block}
