{include file="./index_top.tpl"}
<script>
    let ajaxObj = new XMLHTTP("edit_subtable.php");
    ajaxObj.format = 0;
    ajaxObj.method = "POST";
    function switchOnObjectSubtable(subtable_id) {
        $('#switch-on-btn_'+subtable_id).toggleClass('switch-on');
        $('#switch-on-btn_'+subtable_id).trigger('on.switch');
        ajaxObj.call('subtable_id='+subtable_id+'&sel=disable&enbl='+($('#switch-on-btn_'+subtable_id).hasClass('switch-on')?1:0)+'&csrf={$csrf}',()=>{});
    }
</script>
<div align=center>
    <br>{$lang.subtables_of_table} "{$name_table}"<span class='help_bt' h_id='Subtables'></span><br><br>
    {include file="./conf_nav.tpl"}
    <p style="font-size:14px;">
        {if $archive}<a style="font-size:14px;" href="edit_subtable.php?table={$table_id}">{/if}
            {$lang.active}
        {if $archive}</a>{/if}
        /
        {if !$archive}
            {if $has_archive}
                <a style="font-size:14px;" href="edit_subtable.php?table={$table_id}&archive">
            {else}
                <span style="color:gray" title="{$lang.Empty_archive}">
            {/if}
        {/if}
            {$lang.archive}
        {if !$archive}{if $has_archive}</a>{else}</span>{/if}{/if}
    </p>
    <form action="edit_subtable.php?table={$table_id}" method="post">
        <table class='sortableTable'>
            {if $error}
                <tr>
                    <td style="color:red" colspan="7" align="center">{$error}<br><br></td>
                </tr>
            {/if}
            {foreach from=$all_subtables item=one_subtable}
                {if $user.group_id==1 || $user.sub_admin_rights.tables.{$table_id}>=2 || $one_subtable.owner_id==$user.group_id}
                {if $config.display_protected_elements || $one_subtable.blocked != 2}
                <tr>
                    <td><span class="draggableImg">&nbsp;</span></td>
                    <td>
                        {if $user.group_id==1 || $user.sub_admin_rights.tables.{$table_id}==2 || $one_subtable.owner_id==$user.group_id}
                        {if !$one_subtable.blocked}
                        {if !$archive}
                            <a class='href_post'
                                href="edit_subtable.php?table={$table_id}&subtable={$one_subtable.id}&sel=archive"><img
                                        alt="{$lang.into_archive}" title="{$lang.send_in_archive}"
                                        src="images/b_archive.png" border=0></a>
                        {else}
                            <a class='href_post'
                                href="edit_subtable.php?table={$table_id}&subtable={$one_subtable.id}&sel=restore"><img
                                        alt="{$lang.restore}" title="{$lang.restore_from_archive}"
                                        src="images/b_restore.png" border=0></a>
                        {/if}
                        {/if}
                        {/if}
                    </td>
                    <td>{if ($user.group_id==1 || ($user.sub_admin_rights.tables.{$table_id}==2 && $user.sub_admin_rights.allow_del) || $one_subtable.owner_id==$user.group_id) && !$one_subtable.blocked}
                        <a class='href_post'
                           href="edit_subtable.php?table={$table_id}&subtable={$one_subtable.id}&delete{if $back_url}&back_url={$base64_back_url}{/if}"
                           onClick="return href_post=jconfirm('{$lang.delete_subtable1}{$one_subtable.name}{$lang.delete_subtable2}{$one_subtable.link_table_name}{$lang.delete_subtable3}', this);"><img
                                    alt="{$lang.Delete}" title="{$lang.Delete_subtable}" src="images/b_drop.png"
                                    border=0></a>{/if}</td>
                    {if !$archive}
                        <td>{if $one_subtable.blocked != 2 && !$add_blocked}<a class='href_post'
                               href="edit_subtable.php?table={$table_id}&subtable={$one_subtable.id}&amp;copy{$back_url_prm}"
                               onClick="if (copy_name=prompt('{$lang.Copy_as}','{$one_subtable.name|escape:'html'} {$lang['(copy)']}')) {ldelim}this.href=this.href+'&amp;copy='+copy_name; href_post=true;{rdelim} else href_post=false;"><img
                                        alt="{$lang.copy}" title="{$lang.Copy_subtable}" src="images/b_copy.png"
                                        border=0></a>{/if}</td>
                        <td>
                            {if !$one_subtable.blocked}
                            <div style="left: 0; top: 2px; margin: 0 5px;"
                                onclick="switchOnObjectSubtable('{$one_subtable.id}')"
                                class="switch-btn {if !$one_subtable.disabled}switch-on{/if}"
                                id="switch-on-btn_{$one_subtable.id}"><div></div></div>
                            {/if}
                        </td>
                        <td><input class="edit-subtable__table-num" type=text size=1 name=num[{$one_subtable.id}] value={$one_subtable.num}></td>
                    {/if}
                    <td>
                        {if ($user.group_id==1 || $user.sub_admin_rights.tables.{$table_id}==2 || $one_subtable.owner_id==$user.group_id) && $one_subtable.blocked != 2}
                            <a class="cb_field_title__link {if $one_subtable.blocked}gray_link{/if}" href="edit_subtable.php?table={$table_id}&subtable={$one_subtable.id}{if $back_url}&back_url={$base64_back_url}{/if}">
                                <b>{$one_subtable.name}</b>
                            </a>
                        {else}
                            <b style="color:gray;">{$one_subtable.name}</b>
                        {/if}
                    </td>
                    {if $one_subtable.protected}<td><img src="images/lock.svg" style="width:13px" title="{$one_subtable.protect_comment}"></td>{/if}
                </tr>
                {/if}
                {/if}
                {foreachelse}
                {if !$error}
                    <tr>
                    <td>{$lang.no_subtables}</td></tr>{/if}
            {/foreach}
        </table>
        <br>
        <input type=hidden name=back_url value="{$base64_back_url}">
        <input type=hidden name=csrf value="{$csrf}">
        {*if $all_subtables}<input class="btn btn-default btn-sm" id="subtables__refresh_subtable" type=submit value="{$lang.Refresh_range}">{/if*}
        {if !$archive && !$add_blocked}<input class="btn btn-default btn-sm" id='subtables__add_subtable' type=button value="{$lang.Add_subtable}"
               onClick="location.href='edit_subtable.php?table={$table_id}&subtable=-1{if $back_url}&back_url={$base64_back_url}{/if}';">{/if}
    </form>
    <br><a href="{if $back_url}{$back_url}{else}edit_tabrep.php?cat={$cat_id}{/if}">{$lang.return_to_tables}</a> | <a href="fields.php?table={$table_id}" target="_blank">{$lang.view_table}</a><br><br>
</div>

<script src="themes/clientbase/js/cut_title_field.js"></script>
