{include file="./index_top.tpl"}
<script>
    let ajaxObj = new XMLHTTP("edit_format.php");
    ajaxObj.format = 0;
    ajaxObj.method = "POST";
    function switchOnObjectFormat(format_id) {
        $('#switch-on-btn_'+format_id).toggleClass('switch-on');
        $('#switch-on-btn_'+format_id).trigger('on.switch');
        ajaxObj.call('format_id='+format_id+'&sel=disable&enbl='+($('#switch-on-btn_'+format_id).hasClass('switch-on')?1:0)+'&csrf={$csrf}',()=>{});
    }
</script>
<div align=center>
    <br>{$lang.formats_of_table} "{$name_table}"<span class='help_bt' h_id='Format'></span><br><br>
    {include file="./conf_nav.tpl"}
    <p style="font-size:14px;">
        {if $archive}<a style="font-size:14px;" href="edit_format.php?table={$table_id}">{/if}
            {$lang.active}
        {if $archive}</a>{/if}
        /
        {if !$archive}
            {if $has_archive}
                <a style="font-size:14px;" href="edit_format.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_format.php?table={$table_id}" method="post">
        <table class='sortableTable'>
            {foreach from=$all_format item=one_format}
                {if $user.group_id==1 || $user.sub_admin_rights.tables.{$table_id}>=2 || $one_format.owner_id==$user.group_id}
                {if $config.display_protected_elements || $one_format.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_format.owner_id==$user.group_id}
                            {if !$one_format.blocked}
                            {if !$archive}
                                <a class='href_post'
                                    href="edit_format.php?table={$table_id}&format={$one_format.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_format.php?table={$table_id}&format={$one_format.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_format.owner_id==$user.group_id}
                            {if !$one_format.blocked}
                                <a class='href_post'
                                   href="edit_format.php?table={$table_id}&format={$one_format.id}&delete{if $back_url}&back_url={$base64_back_url}{/if}"
                                   onClick="return href_post=jconfirm('{$lang.alert_delete_format}', this);"><img
                                        alt="{$lang.delete}" title="{$lang.Delete_format}" src="images/b_drop.png"
                                        border=0></a>
                            {/if}
                            {/if}
                        </td>
                        {if !$archive}
                            <td>{if $one_format.blocked != 2 && !$add_blocked && ($all_modules.pro_tariff || $one_format.construct)}<a class='href_post'
                                href="edit_format.php?table={$table_id}&format={$one_format.id}&amp;copy{if $back_url}&back_url={$base64_current_url}{/if}"
                                onClick="if (copy_name=prompt('{$lang.Copy_as}','{$one_format.name} {$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_format}" src="images/b_copy.png" border=0></a>{/if}
                            </td>
                            <td>
                                {if !$one_format.blocked}
                                <div style="left: 0; top: 2px; margin: 0 5px;"
                                    onclick="switchOnObjectFormat('{$one_format.id}')"
                                    class="switch-btn {if !$one_format.disabled}switch-on{/if}"
                                    id="switch-on-btn_{$one_format.id}"><div></div></div>
                                {/if}
                            </td>
                            <td><input type=text size=1 name=num[{$one_format.id}] value={$one_format.num} class="edit-format__format-num"></td>
                        {/if}
                        <td>{if ($user.group_id==1 || $user.sub_admin_rights.tables.{$table_id}>=2 || $one_format.owner_id==$user.group_id) && $one_format.blocked != 2}
                                <a
                                class="cb_field_title__link {if $one_format.blocked}gray_link{/if}"
                                href="edit_format.php?table={$table_id}&format={$one_format.id}{if $back_url}&back_url={$smarty.get.back_url}{/if}">
                                <b>{$one_format.name}</b></a>{else}<b style="color:gray;">{$one_format.name}</b>{/if}
                        </td>
                        <td style="padding-left: 30px;">
                            {if $one_format.construct}<span style="color: grey; font-style: italic;">{$lang.construct}</span>{/if}
                        </td>
                        {if $one_format.protected}<td><img src="images/lock.svg" style="width:13px" title="{$one_format.protect_comment}"></td>{/if}
                    </tr>
                {/if}
                {/if}
                {foreachelse}
                <tr>
                    <td>{$lang.No_formats}</td>
                </tr>
            {/foreach}
        </table>
        <br>
        {*if $all_format}<input class="btn btn-default btn-sm" type=submit value="{$lang.Refresh_range}"> {/if*}
        <input type=hidden name=csrf value='{$csrf}'>
        <input type=hidden name=back_url value='{$base64_back_url}'>
        {if !$archive && !$add_blocked}<input class="btn btn-default btn-sm" type=button value="{$lang.Add_format}"
               onClick="location.href='edit_format.php?table={$table_id}&format=-1{if $back_url}&back_url={$smarty.get.back_url}{/if}';">{/if}
    </form>
    <br>
    <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>
