{include file="./index_top.tpl"}
<script>
    // значения для системной подсказки
    var help_section = 'Settings';
    var help_sub_section = 'Users';

    function add_user() {
        {if $tab=='users_list' && $limit_users}
        jalert('{$lang.users_limit_alert_p1} {$config.max_users} {$lang.users_limit_alert_p2}.');
        {elseif $tab=='clients_list' && $limit_clients}
        jalert('{$lang.clients_limit_alert}');
        {else}
        location.href = "edit_user.php?{if $tab=='clients_list'}tab=clients_list&{/if}sel=add_user&user_id=-1";
        {/if}
    }
</script>
<div align=center>
    <br>
    {if $tab=='users_list'}
        {$lang.Users_list}
        <span class='help_bt' h_id='Users_list'></span>
    {elseif $tab=='clients_list'}
        {$lang.Clients_list}
        <span class='help_bt' h_id='Clients_list'></span>
    {elseif $tab=='block_list'}
        {$lang.Locked_list}
        <span class='help_bt' h_id='Locked_list'></span>
    {/if}
    {if $archive}({$lang.archive}){/if}
    <br><br>
    <p>
    <form action="edit_user.php{$query_string}" method="post" id="edit_user_form">
        {$lang.Sort_by}:&nbsp;
        <select class="form-control form-control-160" name="sort" id="userSortSelect">
            <option value="0" {if $config.user_sort_method==0} selected{/if}>{$lang.date_added}</option>
            <option value="1" {if $config.user_sort_method==1} selected{/if}>{$lang.user_Name}</option>
            <option value="2" {if $config.user_sort_method==2} selected{/if}>{$lang.access_group}</option>
        </select>
        <input name="csrf" type="hidden" value="{$csrf}"/>
    </form>
    </p>
    <script>
        $("#userSortSelect").on("change", function () {
            $("#edit_user_form").submit();
        });
    </script>
    <table class="" border=0 cellpadding=3>
        {foreach from=$all_users item=one_user}
            <tr>
                {if $one_user.id eq 1 || ($user.group_id!=1 && $one_user.group_id==1) || $one_user.id==$user.id || ($user.group_id!=1 && $one_user.sub_admin==1 && !$user.sub_admin_rights.access_subadmin) || ($one_user.group_id == 777 && !$all_modules.client_group) }
                    <td></td>
                {elseif !$archive}
                    <td><a class='href_post'
                           href="edit_user.php?{if $tab=='clients_list'}tab=clients_list&{/if}sel=archive_user&user_id={$one_user.id}"><img
                                alt="{$lang.into_archive}" title="{$lang.send_in_archive}" src="images/b_archive.png"
                                border=0></a></td>
                {else}
                    <td><a class='href_post'
                           href="edit_user.php?{if $tab=='clients_list'}tab=clients_list&{/if}archive&sel=restore_user&user_id={$one_user.id}"><img
                                alt="{$lang.restore}" title="{$lang.restore_from_archive}" src="images/b_restore.png"
                                border=0></a></td>{/if}
                <td>{if $one_user.id eq 1 || ($user.group_id!=1 && $one_user.group_id==1) || $one_user.id==$user.id || ($user.group_id!=1 && $one_user.sub_admin==1 && !$user.sub_admin_rights.access_subadmin)}{else}
                        <a class='href_post'
                           href="edit_user.php?{if $tab=='clients_list'}tab=clients_list&{/if}{if $archive}archive&{/if}sel=delete_user&user_id={$one_user.id}"
                           onclick='{if $one_user.ast_user}jalert("{$lang.user_no_delete_asterisk_alert}");href_post=false;{else}return href_post=jconfirm("{$lang.user_delete_alert}", this);{/if}'>
                        <img alt="{$lang.delete}" title="{$lang.delete_user}" src="images/b_drop.png" border=0></a>{/if}
                </td>
                <td>{if $one_user.arc!=2 && ($one_user.group_id!=777 || $all_modules.client_group)}{if $user.group_id==1 || ($one_user.group_id!=1 && ($one_user.sub_admin!=1 || $user.sub_admin_rights.access_subadmin)) || ($one_user.id==$user.id && $user.sub_admin==1)}
                    <a href="edit_user.php?{if $tab=='clients_list'}tab=clients_list&{/if}{if $archive}archive&{/if}sel=edit_user&user_id={$one_user.id}">{else}
                        <span style="color:gray" title='Вы не можете редактировать Администраторов.'>{/if}{else}<span
                                    style="color:gray"
                                    title='{if $tab=="users_list"}{$lang.users_limit_used_p1} {$config.max_users} {$lang.users_limit_used_p2}.{else}{$lang.clients_limit_alert}{/if}'>{/if}<b>{$one_user.fio}</b>{if $one_user.arc!=2}
                    </a>{else}</span>{/if}</td>
                <td>
                <td>
                    <span style="color:gray">{$one_user.login}</span>
                </td>
                <td>
                    <span style="color: grey; font-style: italic;">{if $user.sub_admin_rights.access==1 || $user.group_id==1}
                            <a href="edit_group.php?group={$one_user.group_id}"
                               class="sel_user_group">{$one_user.group}</a>{else}{$one_user.group}{/if}</span></td>
            </tr>
        {/foreach}
    </table>
    {if !$archive}
    {if $tab=='users_list'}
        <p style="margin: 15px">{$lang.Total_users}: {$users_count} ({$lang.Tariff_plan_user}: {if $config.max_users == 99999}{$lang.lk_unlimited}{else}{$config.max_users}{/if})</p>
        {if $clients_list}
            <a href='edit_user.php?tab=clients_list{if $archive}&archive{/if}'><b>{$lang.Clients_list}</b></a>
            <span class='help_bt' h_id='Clients_list'></span>
            <br>
        {/if}
    {elseif $tab=='clients_list'}
        <p style="margin: 15px">{$lang.Total_clients}: {$users_count} {if $locked_count}(<a href="edit_user.php?tab=block_list">{$lang.Locked}: {$locked_count}</a>){/if}</p>
        <a href='edit_user.php{if $archive}?archive{/if}'><b>{$lang.Users_list}</b></a>
        <span class='help_bt' h_id='Users_list'></span>
        <br>
    {/if}
    {/if}
    <br>{if !$archive && ($tab=='users_list' || $all_modules.client_group)}<input class="btn btn-default" type=button value="{$lang.add_new_user}" onClick='add_user()'><br><br>{/if}
    {if $tab=='block_list'}
        <a href="edit_user.php?tab=clients_list"><b>{$lang.Return}</b></a>
    {elseif !$archive}
        <a href="edit_user.php?{if $tab=='clients_list'}tab=clients_list&{/if}archive"><b>{$lang.Open_arhive}</b></a>
        <span class='help_bt' h_id='Open_arhive'></span>
    {else}
        <a href="edit_user.php{if $tab=='clients_list'}?tab=clients_list{/if}"><b>{$lang.close_arhive}</b></a>
        <span class='help_bt' h_id='close_arhive'></span>
    {/if}
    <br><br><br><br>
</div>