<link rel="stylesheet" href="{$config.site_root}/modules/api/css/style.css" type="text/css">
<div class="my_api_settings">
    <div class="top">    {$lang.modules.api.My_settings} <span class="help_bt" h_id="setting_top_api"></span></div>
    <div align="center" class="f13">
        <a href="?module=api">{$lang['modules']['api']['activate']}</a> /
        {$lang['modules']['api']['forms']} /
        <a href="?module=api&path=config">{$lang['Settings']}</a>
    </div>
    {if $users}
        <form>
            <table class="for_table">
                <tr>
                    <td align="right" style="text-align: right">
                        {$lang.log_ras_name} <span class="help_bt" h_id="api_template_name"></span>:
                    </td>
                    <td align="left">
                        <input name="name_form" required
                               value="{if $form.name_form}{$form.name_form}{else}{$lang.Template} {$name_template}{/if}"
                               class="form-control form-control-160">
                    </td>
                </tr>
                <tr>
                    <td align="right" style="text-align: right">
                        {$lang.modules.api.select} <span class="help_bt" h_id="api_select_user"></span>:
                    </td>
                    <td align="left">
                        <select name="user" class="form-control form-control-160" id="user" required
                                onchange="links_show('table',this.options[this.selectedIndex].value)">
                            <option></option>
                            {foreach from=$users item=row}
                                <option {if $form.user == $row.id} selected
                                                                   {/if}value="{$row.login}">{$row.fio}</option>
                            {/foreach}
                        </select>
                    </td>
                </tr>
                <tr>
                    <td align="right" style="text-align: right">
                        {$lang.Sync_select_table} <span class="help_bt" h_id="api_select_table"></span>:
                    </td>
                    <td align="left">
                        <select name="table" id="table" required class="form-control form-control-160"
                                onchange="links_show('filter',this.options[this.selectedIndex].value)">
                            <option></option>
                            {if $form}
                                {foreach from=$table item="row"}
                                    <option value="{$row.id}" {if $form.table_id == $row.id} selected {/if}>{$row.name_table}</option>
                                {/foreach}
                            {/if}
                        </select>
                    </td>
                </tr>
                <tr>
                    <td align="right" style="text-align: right">
                        {$lang.modules.api.select_filter} <span class="help_bt" h_id="api_select_filter"></span>:
                    </td>
                    <td align="left">
                        <select name="filter" id="filter" class="form-control form-control-160">
                            <option></option>
                            {if $form}
                                {foreach from=$filter item="row"}
                                    <option value="{$row.id}" {if $form.filter_id == $row.id} selected {/if}>{$row.name}</option>
                                {/foreach}
                            {/if}
                        </select>
                    </td>
                </tr>
                <tr>
                    <td align="right" style="text-align: right">
                        {$lang.modules.api.select_limit} <span class="help_bt" h_id="api_select_limit"></span>:
                    </td>
                    <td align="left">
                        <input name="limit" id="limit"
                               required {if $form} value="{$form.limits}" {else} value="100"  {/if}
                               class="form-control form-control-160">
                    </td>
                </tr>
                <tr>
                    <td align="right" style="text-align: right">
                        {$lang.modules.api.select_view} <span class="help_bt" h_id="api_select_view"></span>:
                    </td>
                    <td align="left">
                        <input name="view" id="view" required {if $form} value="{$form.views}" {else} value="50"  {/if}
                               class="form-control form-control-160">
                    </td>
                </tr>
                <tbody id="full_version" style="display:{if $form} contents {else} none {/if}">
                <tr>
                    <td align="right" style="text-align: right">{$lang.View_line}
                        <span class="help_bt" h_id="api_new_line"></span>:
                    </td>
                    <td align="left">
                        <input name="show" type="checkbox" {if $form.shows || !$form}checked {/if}id="show">
                    </td>
                </tr>
                <tr>
                    <td align="right" style="text-align: right">
                        {$lang.Add_record} <span class="help_bt" h_id="api_add"></span>:
                    </td>
                    <td align="left">
                        <input name="add" type="checkbox" {if $form.adds || !$form}checked{/if} id="add">
                    </td>
                </tr>
                <tr>
                    <td align="right" style="text-align: right">
                        {$lang.Edit} <span class="help_bt" h_id="api_edit"></span>:
                    </td>
                    <td align="left">
                        <input name="edit" id="edit" type="checkbox" {if $form.edits || !$form}checked{/if}>
                    </td>
                </tr>
                <tr>
                    <td align="right" style="text-align: right">
                        {$lang.Fast_search} <span class="help_bt" h_id="api_search"></span>:
                    </td>
                    <td align="left">
                        <input name="search" id="search" type="checkbox" {if $form.searchs || !$form}checked{/if}>
                    </td>
                </tr>
                </tbody>
            </table>
            <div class="btn btn-default btn-sm"
                 onclick="generate_code('{$config.site_root}')">{$lang.modules.api.generate}</div>
            <input type="hidden" name="module" value="api">
            {if $form} <input type="hidden" name="id" value="{$form.id}">{/if}
            <input type="hidden" name="path" value="add">
            <input type="hidden" name="save_forms" value="save">
            <input type=hidden name="csrf" value="{$csrf}">
            <input type="submit" class="btn btn-default btn-sm" value="{$lang.Save}">
            <button class="btn btn-default btn-sm" type="button"
                    onclick="window.location='{$config.site_root}/edit_modules.php?module=api&path=forms';">{$lang.Cancel}</button>
            <br/>
        </form>
        <textarea class="form-control" readonly name="code" id="code"
                  style="width:500px;height: 100px;margin:40px auto"></textarea>
        <br/>
        <div class="btn btn-default btn-sm" style="display:none;margin-bottom: 37px;" id="button_view"
             onclick="view_code('{$config.site_root}')">{$lang.modules.api.view}</div>
        <br/>
        <iframe scroling="auto" align="center" id="frame_api"></iframe>
    {else}
        <br/>
        <div>{$lang.modules.api.no_user}</div>
    {/if}
</div>
<script type="text/javascript" src="{$config.site_root}/modules/api/js/script.js"></script>
{if $form}
    <script type="text/javascript">
        version_form();
        generate_code();
        view_code('{$config.site_root}');
    </script>
{/if}
