{include file="./index_top.tpl"}
{if $tariff_limits.mp_off}
<div align=center><br>{$lang.Not_supported_cur_tariff}</div>
{else}
<style>
.shop_info {
    width: 14px;
    height: 14px;
    display: inline-block;
    vertical-align: middle;
    background: url(images/help.gif) no-repeat;
    margin-left: 2px;
}
</style>
<script>
function check_addon(file_name) {
    var addons = { {foreach from=$cur_addons item=one_addon}{if !$one_addon.inactive}'{$one_addon.name}':1,{/if}{/foreach} };
    var addon_name = file_name.substring(file_name.lastIndexOf('\\') + 1, file_name.indexOf('.'));
    if (addons[addon_name]) {
        jconfirm('{$lang.Update_addon_alert_1}' + addon_name + '{$lang.Update_addon_alert_2}',
            function () {
                $('#imp_form').submit();
            },
            function() {
                return false;
            }
        );
    } else {
        $('#imp_form').submit();
    }
}

function check_links() {
    var warning = false;
    $('.sel_links').each(function(indx, element) {
        if ($(element).val() == '0') {
            warning = true;
        }
    });
    if (warning) {
        jconfirm('{$lang.Not_set_links_alert}',
            function() {
                $('#sel_links_form').submit();
            },
            function() {
                return false;
            }
        );
    } else {
        $('#sel_links_form').submit();
    }
}

$(function () {
    $('.sel_links').each(function(indx, element) {
        if ($(element).val() == '0') {
            $(element).css('color', '#aaa');
        }
    });
{if $test_addon}
    jconfirm('{if $test_addon === 'free_version'}{$lang.Try_free_version_alert}{else}{$lang.Try_free_alert}{/if}', function() { location.href = '?addon={$test_addon}&test&install' }, null, '{$lang.Addon_installing} &quot;{$shop_addons[$test_addon].name}&quot;');
{/if}
{foreach from=$addon_groups item=addon_group key=group_id}
    var find_group{$group_id} = 0;
    {if $old_sel_groups}
    {foreach from=$old_sel_groups[$group_id] item=old_group_id}
        add_sel_groups({$group_id}, '{$addon_group.name}', null, {$old_group_id});
        find_group{$group_id} = 1;
    {/foreach}
    {else}
    {foreach from=$sel_groups item=group_name key=sel_group_id}
        {if $group_name == $addon_group.name}
            add_sel_groups({$group_id}, '{$addon_group.name}');
            find_group{$group_id} = 1;
        {/if}
    {/foreach}
    {/if}
    add_sel_groups({$group_id}, find_group{$group_id} ? '' : '{$lang.create}');
{/foreach}

    init_chosen();
})

function gen_sel_settings() {
    var options = '';
    $('.sel_reports').each(function(indx, element) {
        if (element.checked) {
            options += '<option value="' + element.value + '">' + $(element).attr('data-text') + '</option>';
        }
    });
    if (options) {
        $('select.select_report').css('font-style', '');
        $('select.select_report').prop('disabled', 0);
        $('select.select_report').html('<option value=""></option>' + options);
    } else {
        $('select.select_report').css('font-style', 'italic');
        $('select.select_report').prop('disabled', 1);
        $('select.select_report').html('<option value="">{$lang.select_report}</option>');
    }
    init_chosen();
}

function add_sel_groups(group_id, group_name, cur_select, old_group_id) {
    var select = '<div><select name="sel_groups[' + group_id  + '][]" class="form-control sel_group" style="display:block; margin-bottom: 2px" onchange="add_sel_groups(' + group_id  + ', \'\', this)">' +
        '<option value="0"></option>' +
        (group_id > 1 ? '<option value="-1" style="font-style:italic" ' + (group_name == '{$lang.create}' ? 'selected' : '') + '>{$lang.create}</option>' : '') +
        {foreach from=$sel_groups item=group_name key=sel_group_id}
            '<option value="{$sel_group_id}" ' + ((!old_group_id && group_name == '{$group_name}') || old_group_id == {$sel_group_id} ? 'selected' : '') + '>{$group_name}</option>' +
        {/foreach}
        '</select></div>';
    if (!cur_select || ($(cur_select).val() != 0 && $(cur_select).val() != -1 && !$(cur_select).parent().next().html())) {
        $('#sel_group_' + group_id).append(select);
    } else if (($(cur_select).val() == 0 || $(cur_select).val() == -1) && $(cur_select).parent().next().html()) {
        if($(cur_select).parent().next().find('select').eq(0).val() != 0 && $(cur_select).parent().next().find('select').eq(0).val() != -1){
            $(cur_select).parent().remove();
        }
        else {
            $(cur_select).parent().next().remove();
        }
    }
    init_chosen();
}

// всплывающая справка по полю (при выборе внешних полей связи)
var help_viewed = false;
var h_init = false;
var v_init = false;
function viewHelpAddon(elemId) {
    if (h_init) clearTimeout(h_init);
    if (help_viewed) return;
    help_viewed = true;
    document.getElementById("f_tooltip_" + elemId).style.display = "block";
}
function hideHelpAddonInit(elemId) {
    if (v_init) clearTimeout(v_init);
    str_to = "hideHelpAddon('" + elemId + "')";
    h_init = setTimeout(str_to, 100);
}
function hideHelpAddon(elemId) {
    help_viewed = false;
    document.getElementById("f_tooltip_" + elemId).style.display = "none"
}

$(document).ready(function() {
    $('#shop_addons').find('a[iframe-href]').each(function(i, item) {
        var onclick_text = $(item).attr('onclick');
        var reformClick = onclick_text.replace('width="560"', 'width="1100"');
        reformClick = reformClick.replace('height="315"', 'height="720"');

        $(item).attr('onclick', reformClick);
    });
});

function toggle_addons_settings() {
    $('#addons_list').toggle();
    $('#addons_more').toggle();
}
</script>

<style>
    select, input {
        box-sizing: border-box !important;
    }
</style>
<div align=center>
    {if $user.group_id == 1 || ($user.sub_admin_rights.addons && $user.sub_admin_rights.modules)}
        <br>
        <div style="font-size:13px">
            {$lang.Addons} / <a href="edit_modules.php">{$lang.Modules_short}</a>
            {if $configuration_has} / <a href="edit_configuration.php">{$lang.Configuration}</a>{/if}
        </div>
    {/if}
    <br>
    <div style="display:flex; align-items:center; justify-content:center;">
        {$lang.Addons}<span class='help_bt' h_id='Addons'></span>
        {if !$progress_bar && !$addon_groups}<a class="settings" style="margin-left:5px" title="{$lang.Settings}" onclick="toggle_addons_settings(); return false;"></a>{/if}
    </div>
    <br>
    {if $progress_bar}
        <div id="backup_status" style="font-size: 13px; text-align: center">
            <img src="images/indicator.gif" style="vertical-align: middle"> {$progress_text}<br><br>
        </div>
        <div id="backup_process" style="width: 200px; text-align: left; border: 1px solid black; margin: 3px auto 40px">
            <div id="backup_bar" style="height: 18px; width: {$percent}%; background: #85C51F"></div>
            <div id="backup_progress" style="position: absolute; margin-top: -18px; text-align: center; width: 200px; font-size: 13px;">{$percent} %</div>
        </div>
        <br>
    {elseif $link_fields || $addon_groups}
        <h4>{$lang.Addons_settings} &quot;{$addon_name}&quot;</h4><br>
        <form action="edit_transfer.php" method="post" id="sel_links_form">
            <input type="hidden" name="csrf" value="{$csrf}">
            <input type="hidden" name="import_continue" value=1>
            <table id="sel_links_table">
                {if $link_fields}
                    <tr><td colspan=2 align=center>{$lang.Select_or_confirm_links}:<br><br></td></tr>
                    {foreach from=$link_fields item=link_info key=impr_field_id}
                    <tr>
                        <td align=right>
                            <b>{$link_info.impr_table}.{$link_info.impr_field}</b>
                            {if $link_info.impr_help}
                                <div style="position: relative; display: inline;">
                                    <img src="images/help.gif"
                                         class="question"
                                         onclick="viewHelpAddon('f{$impr_field_id}')"
                                         onmouseover="v_init = setTimeout('viewHelpAddon(\'f{$impr_field_id}\')', 500)"
                                         onmouseout="hideHelpAddonInit('f{$impr_field_id}')">
                                    <div class="field_tooltip"
                                         align="left"
                                         id="f_tooltip_f{$impr_field_id}"
                                         onmouseover="viewHelpAddon('f{$impr_field_id}')"
                                         onmouseout="hideHelpAddonInit('f{$impr_field_id}')">
                                        <b>{$link_info.impr_field}</b><div>{$link_info.impr_help}</div>
                                    </div>
                                </div>
                            {/if}
                            <b>:</b>&nbsp;
                        </td>
                        <td>
                            <select name="sel_links[{$impr_field_id}]" id="sel_links_{$impr_field_id}" class="form-control sel_links">
                                {if $sel_fields}<option value="0" style="display:none">( {$link_info.link_table}.{$link_info.link_field} )</option>{/if}
                                <option value="-1" style="font-style:italic;">{ {$lang.create_table} }</option>
                                {foreach from=$sel_fields item=one_field key=field_id}
                                    <option value="{$field_id}" {if $one_field == "{$link_info.link_table}.{$link_info.link_field}"}selected{/if}>{$one_field}</option>
                                {/foreach}
                            </select>
                        </td>
                    </tr>
                    {/foreach}
                {/if}
                {if $addon_groups}
                    <tr><td colspan=2 align=center><br>{$lang.Match_access_group}:<br><br></td></tr>
                    {foreach from=$addon_groups item=addon_group key=group_id}
                    <tr>
                        <td align=right style="vertical-align: top; padding: 5px 0 7px;">
                            <b>{$addon_group.name}</b>
                            {if $addon_group.help}
                                <div style="position: relative; display: inline;">
                                    <img src="images/help.gif"
                                         class="question"
                                         onclick="viewHelpAddon('g{$group_id}')"
                                         onmouseover="v_init = setTimeout('viewHelpAddon(\'g{$group_id}\')', 500)"
                                         onmouseout="hideHelpAddonInit('g{$group_id}')">
                                    <div class="field_tooltip"
                                         align="left"
                                         id="f_tooltip_g{$group_id}"
                                         onmouseover="viewHelpAddon('g{$group_id}')"
                                         onmouseout="hideHelpAddonInit('g{$group_id}')">
                                        <b>{$addon_group.name}</b><div>{$addon_group.help}</div>
                                    </div>
                                </div>
                            {/if}
                            <b>:</b>&nbsp;
                        </td>
                        <td style="padding: 0 0 5px;" id='sel_group_{$group_id}'></td>
                    </tr>
                    {/foreach}
                {/if}
            </table>
            <br>
            <input type="button" value="{$lang.Cancel}" onclick="location.href='edit_transfer.php'" class="btn btn-default"> &nbsp;
            <input type="button" value="{$lang.Apply}" onclick="$('.btn').prop('disabled', true); $('body').css('cursor', 'wait'); check_links();" class="btn btn-default">
        </form>
        <br>
    {else}
        <div id="addons_list"
          {if $settings_message || $export_message || $import_message}
            style="display:none"
          {else}
            style="
              display: grid;
              grid-template-columns: .75fr 1fr auto;
              width: 100%;
            "
          {/if}>
          <div></div>
          <div style="justify-self: baseline;">
            <table cellpadding=3>
                {foreach from=$all_addons item=one_addon key=id}
                {if $one_addon.installed || $one_addon.public}
                <tr id="addon{$id}_row">
                    <td>
                        <a href="edit_transfer.php?{if $one_addon.shop_id}addon={$one_addon.shop_id}&{/if}reset"
                           {if !$one_addon.installed}class="disabled"{/if} title="{$lang.Addons_settings}" id="addon{$id}_link"
                           {if !$one_addon.shop_id}onclick="$('#reload_form_div').toggle(); return false;"{/if}>{$one_addon.name}</a>
                        <!--a href="{$one_addon.link}" {if !$one_addon.link}class="disabled"{/if} id="addon{$id}_link">{$one_addon.name}</a-->
                        <!--a href="https://clientbase.ru/market/library_tables/?addit&config={$one_addon.shop_id}" target="_blanc"><span class="shop_info" title="перейти в магазин"></span></a-->
                    </td>
                    <td style="display: flex; width: 60px;">
                        <div class="switch-btn {if $one_addon.installed}switch-on{/if}" id="switch-btn_{$id}"><div></div></div>
                        <script>
                            $('#switch-btn_{$id}').click(function () {
                                var $this = $(this);
                                if ($this.hasClass('switch-on')) {
                                    jconfirm('{$lang.Delete_addon_confirm} "{$one_addon.name}"?<br><br>' +
                                    '<span style="color:red"><b>{$lang.Attention}!</b></span> {$lang.Delete_addon_confirm2}',
                                    function () {
                                        $this.toggleClass('switch-on');
                                        $this.trigger('off.switch');
                                    });
                                } else {
                                    jconfirm('{if $one_addon.price < 0}{$lang.Addon}{else}{$lang.Instal_addon_confirm}{/if} ' +
                                        '"{if $one_addon.public}<a href="https://clientbase.ru/market/library_tables/?addit&config={$one_addon.shop_id}" target="_blanc" style="color:blue">{/if}{$one_addon.name}{if $one_addon.public}</a>{/if}"' +
                                        '{if $one_addon.price < 0}{$lang.Need_license_for_install_addon}{else}?' +
                                        '{if $one_addon.discount == 100 && !$one_addon.expired}<br><br>{$lang.Cost_rent}: <s>{$one_addon.rent_sum_no_discount|round} {$lang.lk_cur_mount}</s> 0 {$lang.lk_cur_mount} ({$lang.for_tariff} {$tariff_name}){else}' +
                                        '{if $one_addon.rent_sum}<br><br>{$lang.Instal_addon_confirm_2} ' +
                                        '{if $one_addon.rent_sum > 0}' +
                                        '{if $one_addon.expired}{$lang.from2} {else} {/if}{$one_addon.rent_sum|round} {$lang.lk_cur_mount} ' +
                                        '{if $one_addon.expired}{$lang.Instal_addon_confirm_33}{else}{$lang.Instal_addon_confirm_31}{/if}<br><br>{$lang.Cost_rent} {$lang.PRO_line} - {if !$one_addon.expired}<s>{$one_addon.rent_sum|round} {$lang.lk_cur_mount}</s> {/if}0 {$lang.lk_cur_mount}' +
                                        '{elseif $one_addon.rent_sum < 0}{$lang.Instal_addon_confirm_32}{/if}{/if}{/if}{/if}',
                                        function () {
                                            {if $one_addon.price >= 0}$this.toggleClass('switch-on');
                                            $this.trigger('on.switch');{else}return false;{/if}
                                        }
                                    );
                                }
                            });
                            $('#switch-btn_{$id}').on('on.switch', function () {
                                // Посылаем запрос на установку дополнения
                                $.ajax({
                                    url: '{$config.site_url}/edit_transfer.php?ajax&addon={$one_addon.shop_id}&install',
                                    beforeSend: function() {
                                        makePreloader();
                                    },
                                    success: function (resp) {
                                        resp = resp.trim();
                                        if (resp.substr(0, 22) == '<script>location.href=') {
                                            location.href = resp.substr(23, -10);
                                        } else if (resp && resp.substr(0, 8) != '<script>') {
                                            destroyPreloader();
                                            jalert(resp);
                                            $('#switch-btn_{$id}').toggleClass('switch-on');
                                        } else {
                                            location.href = 'edit_transfer.php?set';
                                        }
                                    }
                                });
                            });
                            $('#switch-btn_{$id}').on('off.switch', function () {
                                // Посылаем запрос на удаление дополнения
                                $.ajax({
                                    url: '{$config.site_url}/edit_transfer.php?ajax',
                                    type: 'post',
                                    data: 'csrf={$csrf}&addon={$one_addon.id}&delete',
                                    beforeSend: function() {
                                        makePreloader();
                                    },
                                    success: function (resp) {
                                        resp = resp.trim();
                                        if (resp && resp.substr(0, 8) != '<script>') {
                                            destroyPreloader();
                                            jalert(resp);
                                            $('#switch-btn_{$id}').toggleClass('switch-on');
                                        } else {
                                            destroyPreloader();
                                            $('#addon{$id}_{if $one_addon.shop_id && $one_addon.public}info{else}row{/if}').hide();
                                            $('#addon{$id}_link').toggleClass('disabled');
                                            $('#active_cat_{$one_addon.cat_id}').parent().hide();
                                            $('#total_rent_sum').html($('#total_rent_sum').html() - {$one_addon.rent_sum|round});
                                        }
                                    }
                                });
                            });
                        </script>
                    </td>
                    <td id="addon{$id}_info">
                        {if $one_addon.new}
                            <a class='href_post' href="edit_transfer.php?addon={$one_addon.shop_id}&import"
                               onclick="return href_post=jconfirm('{$lang.Update_addon_confirm_1} &quot;{$one_addon.name}&quot;?<br><br>{$lang.Update_addon_confirm_2}', this);">
                                {$lang.update}
                            </a>
                        {elseif $one_addon.rented}
                            <img alt="{$lang.Locked}" title="{$lang.Locked}" src="images/locked.png" border=0 style="cursor:pointer; margin-right:5px;" 
                                 onclick="jalert('{$lang.Locked_addon_message1}<br><br>{$lang.Cost_of_addon} {$one_addon.price} {$lang.cur_3}. {$lang.Locked_addon_message2}')">
                            <span style="color:gray">
                                {if $one_addon.discount}<s>{$one_addon.rent_sum_no_discount|round} {$lang.lk_cur_mount}</s>{/if}
                                {$one_addon.rent_sum|round} {$lang.lk_cur_mount}
                            </span>
                        {elseif $one_addon.tested}
                            <img alt="{$lang.Locked}" title="{$lang.Locked}" src="images/locked.png" border=0 style="cursor:pointer; margin-right:5px;" 
                                 onclick="jalert('{$lang.Locked_addon_message1}<br><br>{$lang.Cost_of_addon} {$one_addon.price} {$lang.cur_3}. {$lang.Locked_addon_message2}')">
                            <span style="color:gray">{$lang.free} {$lang.until} {$one_addon.expire}</span>
                        {elseif $one_addon.installed && ($one_addon.bought || !$one_addon.paid)}
                            <a class='href_post' href="edit_transfer.php?addon={$one_addon.id}&unlock" onclick="return href_post=jconfirm('{$lang.Addon_unlock_alert}', this);">
                                <img alt="{$lang.Unlock}" title="{$lang.Unlock}" src="images/unlock.png" border=0>
                            </a>
                        {/if}
                    </td>
                </tr>
                {/if}
                {/foreach}
                {if $total_rent_sum}
                <tr>
                    <td><b>{$lang.Total}:</b></td><td></td><td><span id="total_rent_sum">{$total_rent_sum|round}</span> {$lang.lk_cur_mount}</td>
                </tr>
                {/if}
            </table>
            <div id="reload_form_div" style="display:none; margin-top:20px; text-align:left;">
                <form action="edit_transfer.php" method="post" enctype="multipart/form-data" id="reload_form">
                    {$lang.Upload_file}:
                    <input type=file name="upload_file" onchange="makePreloader(); $('#reload_form').submit()" class="jfilestyle" data-input="false">
                    <input type=hidden name="csrf" value="{$csrf}">
                    <input type=hidden name="reset" value=1>
                </form>
            </div>
          </div>
            <br>
        </div>
        <div id="addons_more" {if !$settings_message && !$export_message && !$import_message}style="display:none"{/if}>
            <div id="addons_settings" {if $export_message || $import_message}style="display:none"{/if}>
                <div style="font-size:13px;">
                    <b>{$lang.Settings}</b> /
                    {if $all_cats}<a href="" onclick="$('#exp_conf').show(); $('#addons_settings').hide(); return false;">{$lang.Create}</a> /{/if}
                    <a href="" onclick="$('#imp_conf').show(); $('#addons_settings').hide(); return false;">{$lang.Upload}</a> /
                    <a href="" onclick="$('#base_links').show(); $('#addons_settings').hide(); return false;">{$lang.Relations}</a>
                    <div style="{if !$settings_message}display:none{/if}; color:green; margin:15px 0 -5px;" id="settings_message">{$settings_message}</div>
                </div>
                <br>
                <form action="edit_transfer.php" method="post">
                    <input type=hidden name="csrf" value="{$csrf}">
                    <div style="padding:3px">
                        <input type=checkbox name="autoupdate_addons" {if $config.autoupdate_addons}checked{/if}> {$lang.Auto_update_addons}
                        <span class='help_bt' h_id='autoupdate_addons'></span><br><br>
                        {if $config.type == 'SAAS'}
                        <input type=checkbox name="no_autodelete_addons" {if $config.no_autodelete_addons}checked{/if}> {$lang.No_auto_delete_addons}
                        <span class='help_bt' h_id='no_autodelete_addons'></span><br><br>
                        {/if}
                        <div style="padding:3px"><input class="btn btn-default btn-sm" type="submit" name="settings" value="{$lang.Save}"></div>
                    </div>
                </form>
            </div>
            <div id="exp_conf" {if !$export_message}style="display:none"{/if}>
                <div style="font-size:13px;">
                    <a href="" onclick="$('#addons_settings').show(); $('#exp_conf').hide(); return false;">{$lang.Settings}</a> /
                    {if $all_cats}<b>{$lang.Create}</b> /{/if}
                    <a href="" onclick="$('#imp_conf').show(); $('#exp_conf').hide(); return false;">{$lang.Upload}</a> /
                    <a href="" onclick="$('#base_links').show(); $('#exp_conf').hide(); return false;">{$lang.Relations}</a>
                    <div style="{if !$export_message}display:none{/if}; color:{$export_message_color}; margin:15px 0 -5px;" id="export_message">{$export_message}</div>
                </div>
                <br>
                <form action="edit_transfer.php" method="post">
                    <input type=hidden name="csrf" value="{$csrf}">
                    <div style="padding:3px">
                        {$lang.File_name}: <input class="form-control form-control-160" type=text name="file_name" id="file_name" size=17 value="{$config.application}">.add.zip<br><br>
                        <table class="edit_transfer_table_checked">
                            <tr>
                                <td>
                                    {foreach from=$all_cats item=one_cat}
                                        <div style="display: flex; align-items: center; margin-top: 5px;">
                                        <img src="images/none.gif"
                                             id="img_{$one_cat.id}"
                                             class="{foreach from=$sub_cats.{$one_cat.id} item=par_table}img_subcats_{$par_table} {/foreach}
                                                    {foreach from=$sub_ccats.{$one_cat.id} item=par_cat}img_subccats_{$par_cat} {/foreach}
                                                    {foreach from=$ev_cats.{$one_cat.id} item=par_calnd}img_evcats_{$par_calnd} {/foreach}"
                                             style="margin-top:-5px;margin-right:4px;"
                                             onclick="$('#cat_block_{$one_cat.id}').css('display',$('#cat_block_{$one_cat.id}').css('display')=='none'?'block':'none');
                                                      this.src='images/'+$('#cat_block_{$one_cat.id}').css('display')+'.gif';">
                                        <input type=checkbox
                                               style="margin-left:-3px; margin-right: 4px;"
                                               name="sel_cat[{$one_cat.id}][new_cat]" value=1
                                               onclick="$('.sel_tabs_{$one_cat.id}').prop('checked',this.checked);
                                                        if (this.checked) {
                                                            $('#cat_block_{$one_cat.id}').css('display','block');
                                                            $('#img_{$one_cat.id}').attr('src','images/block.gif');
                                                            if ($('.sel_subctabs_{$one_cat.id}').length > 0) {
                                                                jconfirm('{$lang.On_subtables_other_cat}',
                                                                    function () {
                                                                        $('.sel_subctabs_{$one_cat.id}').prop('checked',true);
                                                                        $('.sel_subccats_{$one_cat.id}').css('display','block');
                                                                        $('.img_subccats_{$one_cat.id}').attr('src','images/block.gif');
                                                                    }
                                                                );
                                                            }
                                                            if ($('#file_name').val() == '{$config.application}') $('#file_name').val('{$one_cat.name}');
                                                        } else {
                                                            $('.sel_data_{$one_cat.id}').prop('checked',false);
                                                            if ($('#file_name').val() == '{$one_cat.name}') $('#file_name').val('{$config.application}');
                                                        }
                                                        gen_sel_settings();
                                                        ">
                                        {$one_cat.name}</div>
                                        <div id="cat_block_{$one_cat.id}"
                                             class="{foreach from=$sub_cats.{$one_cat.id} item=par_table}sel_subcats_{$par_table} {/foreach}
                                                    {foreach from=$sub_ccats.{$one_cat.id} item=par_cat}sel_subccats_{$par_cat} {/foreach}
                                                    {foreach from=$ev_cats.{$one_cat.id} item=par_calnd}sel_evcats_{$par_calnd} {/foreach}"
                                             style="display:none">
                                            {foreach from=$one_cat.tables item=one_table}
                                                <div style="display: flex; align-items: center; margin-top: 5px;">
                                                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                                <input type=checkbox
                                                       id="sel_tab_{$one_table.id}"
                                                       class="sel_tabs_{$one_cat.id}
                                                             {foreach from=$sub_tables.{$one_table.id} item=par_table}sel_subtabs_{$par_table} {/foreach}
                                                             {foreach from=$sub_ctables.{$one_table.id} item=par_cat}sel_subctabs_{$par_cat} {/foreach}
                                                             {foreach from=$ev_tables.{$one_table.id} item=par_calnd}sel_evtabs_{$par_calnd} {/foreach}"
                                                       name="sel_cat[{$one_cat.id}][tables][]"
                                                       value="{$one_table.id}"
                                                       style="margin-right: 4px;"
                                                       onclick="if (this.checked) {
                                                                    if ($('.sel_subtabs_{$one_table.id}').length > 0) {
                                                                        jconfirm('{$lang.On_subtables_for_table}',
                                                                            function () {
                                                                                $('.sel_subtabs_{$one_table.id}').prop('checked',true);
                                                                                $('.sel_subcats_{$one_table.id}').css('display','block');
                                                                                $('.img_subcats_{$one_table.id}').attr('src','images/block.gif');
                                                                            }
                                                                        );
                                                                    }
                                                                    if ($('#file_name').val() == '{$config.application}') $('#file_name').val('{$one_table.name_table}');
                                                                } else {
                                                                    $('#table_data_{$one_table.id}').prop('checked',0);
                                                                    if ($('#file_name').val() == '{$one_table.name_table}') $('#file_name').val('{$config.application}');
                                                                }">
                                                {$one_table.name_table}&nbsp;
                                                <input type=checkbox
                                                       id="table_data_{$one_table.id}"
                                                       class="sel_data_{$one_cat.id}
                                                             {foreach from=$sub_tables.{$one_table.id} item=par_table}sel_subdata_{$par_table} {/foreach}"
                                                       name="table_data[]"
                                                       value="{$one_table.id}"
                                                       onclick="if (this.checked) {
                                                                    if ($('.sel_subtabs_{$one_table.id}').length > 0) {
                                                                        jconfirm('{$lang.On_subtables_for_table}',
                                                                            function () {
                                                                                $('.sel_subtabs_{$one_table.id}').prop('checked',true);
                                                                                $('.sel_subdata_{$one_table.id}').prop('checked',true);
                                                                                $('.sel_subcats_{$one_table.id}').css('display','block');
                                                                                $('.img_subcats_{$one_table.id}').attr('src','images/block.gif');
                                                                            }
                                                                        );
                                                                    }
                                                                    $('#sel_tab_{$one_table.id}').prop('checked',1);
                                                                }">
                                                <i>{$lang.data2}</i>
                                                </div>
                                            {/foreach}
                                            {foreach from=$one_cat.reports item=one_report}

                                                <div style="display: flex; align-items: center; margin-top: 5px;">
                                                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                                <input type=checkbox
                                                       class="sel_tabs_{$one_cat.id} sel_reports"
                                                       style="margin-right: 4px;"
                                                       name="sel_cat[{$one_cat.id}][reports][]"
                                                       value="{$one_report.id}"
                                                       onclick="if (this.checked) {
                                                                    if ($('#file_name').val() == '{$config.application}') $('#file_name').val('{$one_report.name}');
                                                                } else {
                                                                    if ($('#file_name').val() == '{$one_report.name}') $('#file_name').val('{$config.application}');
                                                                }
                                                                gen_sel_settings();"
                                                       data-text="{$one_report.name}">
                                                {$one_report.name}
                                                </div>
                                            {/foreach}
                                            {foreach from=$one_cat.calendars item=one_calendar}
                                                <div style="display: flex; align-items: center; margin-top: 5px;">
                                                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                                <input type=checkbox
                                                       class="sel_tabs_{$one_cat.id}"
                                                       name="sel_cat[{$one_cat.id}][calendars][]"
                                                       style="margin-right: 4px;"
                                                       value="{$one_calendar.id}"
                                                       onclick="if (this.checked) {
                                                                    if ($('.sel_evtabs_{$one_calendar.id}').length > 0) {
                                                                        jconfirm('{$lang.On_subtables_for_calend}',
                                                                            function () {
                                                                                $('.sel_evtabs_{$one_calendar.id}').prop('checked',true);
                                                                                $('.sel_evcats_{$one_calendar.id}').css('display','block');
                                                                                $('.img_evcats_{$one_calendar.id}').attr('src','images/block.gif');
                                                                            }
                                                                        );
                                                                    }
                                                                    if ($('#file_name').val() == '{$config.application}') $('#file_name').val('{$one_calendar.name}');
                                                                } else {
                                                                    $('#table_data_{$one_calendar.id}').prop('checked',0);
                                                                    if ($('#file_name').val() == '{$one_calendar.name}') $('#file_name').val('{$config.application}');
                                                                }">
                                                {$one_calendar.name}
                                                </div>
                                            {/foreach}
                                        </div>
                                    {/foreach}
                                </td>
                            </tr>
                        </table>
                        <br>
                        <div><a href="" onclick="$('#additional_settings').toggle(); return false;">{$lang.Additional}</a></div>
                        <div id="additional_settings" style="display:none">
                            <br>
                            <table>
                                <tr>
                                    <td align=right width=50%>{$lang.Addons_settings}<span class='help_bt' h_id='addons_settings_report'></span>:</td>
                                    <td>
                                        <select class="form-control form-control-160 select_report" name="addons_settings_report" style="font-style:italic" disabled>
                                            <option value="">{$lang.select_report}</option>
                                        </select>
                                    </td>
                                </tr>
                                <tr>
                                    <td align=right>{$lang.Install_addon_code}<span class='help_bt' h_id='addons_install_code'></span>:</td>
                                    <td>
                                        <select class="form-control form-control-160 select_report" name="addons_install_code" style="font-style:italic" disabled>
                                            <option value="">{$lang.select_report}</option>
                                        </select>
                                    </td>
                                </tr>
                                <tr>
                                    <td align=right>{$lang.Uninstall_addon_code}<span class='help_bt' h_id='addons_uninstall_code'></span>:</td>
                                    <td>
                                        <select class="form-control form-control-160 select_report" name="addons_uninstall_code" style="font-style:italic" disabled>
                                            <option value="">{$lang.select_report}</option>
                                        </select>
                                    </td>
                                </tr>
                            </table>
                        </div>
                        <br>
                        <div style="padding:3px"><input class="btn btn-default btn-sm" type="submit" name="export" value="{$lang.Generate}" onclick="$('#export_message').hide()"></div>
                    </div>
                </form>
            </div>
            <div id="imp_conf" {if !$import_message}style="display:none"{/if}>
                <div style="font-size:13px;">
                    <a href="" onclick="$('#addons_settings').show(); $('#imp_conf').hide(); return false;">{$lang.Settings}</a> /
                    {if $all_cats}<a href="" onclick="$('#exp_conf').show(); $('#imp_conf').hide(); return false;">{$lang.Create}</a> /{/if}
                    <b>{$lang.Upload}</b> /
                    <a href="" onclick="$('#base_links').show(); $('#imp_conf').hide(); return false;">{$lang.Relations}</a>
                    <div style="{if !$import_message}display:none{/if}; color:{$import_message_color}; margin:15px 0 -5px;" id="import_message">{$import_message}</div>
                </div>
                <br>
                <form action="edit_transfer.php" method="post" enctype="multipart/form-data" id="imp_form">
                    <input type=hidden name="csrf" value="{$csrf}">
                    <input type=hidden name="import" value=1>
                    <div style="padding:3px">
                        {$lang.Upload_file}:
                        <input type=file name="upload_file" id="upload_file" size=25 onchange="$('#import_message').hide()" class="jfilestyle" data-input="false">
                        <div style="color:gray; font-style:italic; margin:10px">{$lang.max_filesize}: {$config.maxfilesize}B</div>
                        <div style="padding:3px"><input class="btn btn-default btn-sm" type=button value="{$lang.Upload}" onclick="check_addon($('#upload_file').val())"></div>
                    </div>
                </form>
            </div>
            <div id="base_links" style="display:none">
                <div style="font-size:13px;">
                    <a href="" onclick="$('#addons_settings').show(); $('#base_links').hide(); return false;">{$lang.Settings}</a> /
                    {if $all_cats}<a href="" onclick="$('#exp_conf').show(); $('#base_links').hide(); return false;">{$lang.Create}</a> /{/if}
                    <a href="" onclick="$('#imp_conf').show(); $('#base_links').hide(); return false;">{$lang.Upload}</a> /
                    <b>{$lang.Relations}</b>
                </div>
                <br>
                <form action="edit_transfer.php" method="post">
                    <input type=hidden name="csrf" value="{$csrf}">
                    <div style="padding:3px">
                        <table>
                            {foreach from=$base_names item=base_name key=id}
                            <tr>
                                <td align=right>
                                    <b>{$base_name.name_table}.{$base_name.name_field}:</b>
                                </td>
                                <td>
                                    <select name="base_names[{$id}]" class="form-control form-control-300">
                                        <option value="0"></option>
                                        {foreach from=$sel_fields item=one_field key=field_id}
                                            <option value="{$field_id}"
                                                {if ($base_name.field_id != 0 && $field_id == $base_name.field_id) ||
                                                    ($base_name.field_id == 0 && $one_field == "`$base_name.name_table`.`$base_name.name_field`")}selected{/if}
                                            >{$one_field}</option>
                                        {/foreach}
                                    </select>
                                </td>
                            </tr>
                            {/foreach}
                        </table>
                    </div>
                    <br>
                    <input class="btn btn-default btn-sm" type="submit" value="{$lang.Save}">
                </form>
            </div>
            <br>
            <a href="edit_transfer.php" onclick="toggle_addons_settings(); return false;">{$lang.Return}</a>
        </div>
    {/if}
</div>
<script>
    function makePreloader() {
        const overlay = `<div class='overlay'><div>`;
        const preloader = `<div class="preloader__block" style="z-index: 10000000;">
                                        <div class="preloader">
                                            <div class="lds-css ng-scope">
                                                <div style="width:100%;height:100%" class="lds-ellipsis">
                                                    <div>
                                                        <div></div>
                                                    </div>
                                                    <div>
                                                        <div></div>
                                                    </div>
                                                    <div>
                                                        <div></div>
                                                    </div>
                                                    <div>
                                                        <div></div>
                                                    </div>
                                                    <div>
                                                        <div></div>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>`;
        $('body').append(overlay);
        $('body').append(preloader);
    }

    function destroyPreloader() {
        $('.overlay').hide();
        $('.preloader__block').hide();
    }
</script>
{/if}