{include file="./index_top.tpl"}
<script language="JavaScript" type="text/javascript">
    function turnSync(syncId, syncStat) {
        document.getElementById("checkSync" + syncId).innerHTML = "<img src=\"images/indicator.gif\" alt=\"\" />";

        $.ajax({
            type: "POST",
            url: "edit_sync.php",
            data: "csrf={$csrf}&sync_id=" + syncId + "&cur_status=" + syncStat,
            success: function (msg) {
                document.getElementById("checkSync" + syncId).innerHTML = msg;
            }
        });
    }

    $(document).ready(function () {
        $.ajax({
            type: "POST",
            url: "edit_sync.php",
            data: "csrf={$csrf}&check_sync=1",
            success: function (msg) {
                $(".checkSync").html("<img src=\"images/well.gif\" alt=\"\" title=\"{$lang.Sync}{$lang.sync_correct}\" />");
                eval(msg);
            }
        });
    });
</script>
<div align=center>
    <br>
    {if $table_id}
        {$lang.Sync_settings} {$lang.of_table} "{$table_name}"<span class='help_bt' h_id='Sync_settings'></span><br><br>
        {include file="./conf_nav.tpl"}
        <table border="0" cellpadding="5">
            {foreach from=$all_syncs item=one_sync}
                <tr>
                    <td>
                        <a class='href_post' href='edit_sync.php?deleted_table={$table_id}&sync_id={$one_sync.sync_id}&redirect=1'
                           onclick="return href_post=jconfirm('{$lang.Del_sync_confirm}', this)">
                            <img alt="{$lang.Delete}"
                                title="{$lang.Del_sync}"
                                src="images/b_drop.png"
                                border="0"/>
                        </a>
                    </td>
                    <td style="padding:5px">
                        <a href='edit_sync.php?table={$table_id}&sel=fields&sync_id={$one_sync.sync_id}'><b>{$one_sync.sync_name}</b></a>
                    </td>
                </tr>
            {foreachelse}
                <tr><td>{$lang.Not_remote_available}</td></tr>
            {/foreach}
        </table>
        <br>
        {if $new_syncs && $all_modules.pro_tariff}
            <input class="btn btn-default btn-sm" type="button" value="{$lang.Add_sync}" onclick="$(this).hide(); $('#add_sync_block').show()">
            <div id="add_sync_block" style="display:none">
                <select id="add_sync" class="form-control form-control-160">
                    {foreach from=$new_syncs item=one_sync}
                        <option value="{$one_sync.sync_id}'">{$one_sync.sync_name}</option>
                    {/foreach}
                </select>
                <input class="btn btn-default btn-sm" type="button" value="{$lang.Add}" onclick="location.href='edit_sync.php?table={$table_id}&sel=fields&sync_id='+$('#add_sync').val()">
            </div>
            <br><br>
        {/if}
        <a href="edit_tabrep.php?cat={$cat_id}">{$lang.return_to_tables}</a> | <a href="fields.php?table={$table_id}" target="_blank">{$lang.view_table}</a><br><br>
    {else}
        {$lang.Sync_settings}<span class='help_bt' h_id='Sync_settings'></span>{if $all_syncs}<br><br>{/if}
        <table border="0" cellpadding="5">
            {foreach from=$all_syncs item=one_sync}
                <tr>
                    <td>
                        <input type="checkbox" onclick="turnSync({$one_sync.sync_id}, (this.checked?1:0))"
                               value="{$one_sync.sync_id}" {if $one_sync.sync_status eq 1}checked{/if}
                               id="sync_{$one_sync.sync_id}"/>
                    </td>
                    <td>
                        <a class='href_post' href='edit_sync.php?sel=del&sync_id={$one_sync.sync_id}'
                           onclick="return href_post=jconfirm('{$lang.Del_sync_confirm}', this)"><img alt="{$lang.Delete}"
                                                                                                      title="{$lang.Del_sync}"
                                                                                                      src="images/b_drop.png"
                                                                                                      border="0"/></a>
                    </td>
                    <td>
                        <a href='edit_sync.php?sync_id={$one_sync.sync_id}'><b>{$one_sync.sync_name}</b></a>
                    </td>
                    <td>
                        <a href='edit_sync.php?sel=fields&sync_id={$one_sync.sync_id}'>{$lang.Sync_fields}</a>
                    </td>
                    <td style="font-style: oblique; color: #f00" id="checkSync{$one_sync.sync_id}"
                        {if $one_sync.sync_status eq 1}class="checkSync"{/if}>{if $one_sync.sync_status eq 1}
                            <img src="images/indicator.gif" alt=""/>
                        {/if}</td>
                </tr>
            {/foreach}
        </table>
        <br>
        {if $config.sync_disable}
            {$lang.sync_disable_message}
        {else}
            <input class="btn btn-default btn-sm" type="button" value="{$lang.Add_sync}" onclick="location.href='edit_sync.php?sync_id=-1'"
                {if !$all_modules.pro_tariff}disabled title="{$lang.Pro_tariff_func_message}"{/if}>
        {/if}
        <br><br>
        <a href="edit_add.php">{$lang.return_to_add_settings}</a><br><br>
    {/if}
</div>