{if $no_user_101}
    <script>
    jconfirm('{$lang.modules.asterisk.not_found_101}', function () {
            $('#deactivate_on_server').val('0');
            $('#deactivate_form').submit();
        });
    </script>
{/if}

{if $sip_reg_error == "user already registered"}
    <script>
        $(function () {
            $('#sipout_reg_form').dialog({ modal:true, width:560 });
            $('#sip_reg_error').html('{$lang.modules.asterisk.email_or_phone_registered}');
        });
    </script>
{/if}

{if $sip_reg_error == "sip data mismatch"}
    <script>
        $(function () {
            $('.sip_form').show();
            $('.sip_form input').css({ 'color':'red', 'font-weight':'bold' });
        });
    </script>
{/if}

{if $sip_reg_error == "extensions mismatch"}
    <script>
        $(function () {
            $('#add_settings_save').show();
            $('#add_settings_save input').css({ 'color':'red', 'font-weight':'bold' });
        });
    </script>
{/if}

{if $one_sip_err and $num_sip}
    <script>
        $(function () {
            generate_sip_form({if $num_sip == -1}0{else}{$num_sip}{/if});
            {if $num_sip == -1}
            $('#sip_type3').prop('checked', true);
            switch_sip_type(3);
            {/if}
        });
    </script>
{/if}

{if $bad_forward_phones}
    <script>
        $(function () {
            display_add_settings();
        });
    </script>
{/if}

<div align=center>
    <div style="font-size: 14px;"><b>{$lang.Module_settings}</b><span class='help_bt' h_id='Telephony'></div>
    <br>
    {if $one_server.id}
        <table {* width=1000 *} border=0 cellpadding=3 cellspacing=0>

            {if $error}
                <tr>
                    <td align=center colspan=2 style="text-align:center; color:red;">
                        {if $error==400}
                            {$lang.modules.asterisk.table_exists}
                        {elseif $error==401}
                            {$lang.modules.asterisk.select_table}
                        {elseif $error==402}
                            {$lang.modules.asterisk.fields_required}
                        {elseif $error==404}
                            {$lang.modules.asterisk.SIP_server_error} ({$connect_error}).<br>{$lang.modules.asterisk.data_not_updated}
                        {else}
                            {$error}
                        {/if}
                        <br><br>
                    </td>
                </tr>
            {/if}

            <!-- SIP АККАУНТЫ -->

            <form action="edit_modules.php?module=asterisk" method="post" enctype="multipart/form-data">
                <input type="hidden" name="sips" value="1"/>

                <tr><td colspan="2" align="center" style="text-align: center;"><b>{$lang.modules.asterisk.SIP_accounts}</b></td></tr>

                {if $wait_message}
                    <tr>
                        <td colspan="2" style="text-align: center; color: orange" id="sip_wait">
                            {$lang.modules.asterisk.changes_few_minutes}
                        </td>
                    </tr>
                {/if}

                <tr>
                    <td colspan="2" style="text-align: center; color: red" id="sip_alert">
                        {if $one_sip_err == 2}
                            {$lang.modules.asterisk.SIP_not_connect}
                        {elseif $num_sip == -1}
                            {$lang.modules.asterisk.Error_adding_SIP}
                        {elseif $one_sip_err}
                            {$lang.modules.asterisk.Error_updating_SIP}
                        {elseif $sip_reg_error == 'sip data mismatch'}
                            {$lang.modules.asterisk.SIP_data_mismatch}
                        {elseif $sip_reg_error == 'extensions mismatch'}
                            {$lang.modules.asterisk.SIP_data_mismatch}
                        {elseif $sip_reg_error != 'user already registered'}
                            {$sip_reg_error}
                        {/if}
                    </td>
                </tr>

                {if $all_sips|count_cb > 1}
                    <tr>
                        <td align=right width=45%>{$lang.modules.asterisk.default_server}:</td>
                        <td>
                            <select class="form-control form-control-160" name="by_default" id="by_default" onchange="$('.sip_form').fadeIn()">
                                {foreach from=$all_sips item=one_sip}
                                    <option value="{$one_sip.id}" {if $one_sip.by_default}selected{/if}>{$one_sip.sip_s1}</option>
                                {/foreach}
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <td align=center colspan=2 style="padding-bottom:7px">
                            {$lang.modules.asterisk.server_for_callout}:
                            <input type=checkbox name="sel_outgoing" value=1 {if $one_server.sel_outgoing}checked{/if} onchange="$('.sip_form').fadeIn()">
                        </td>
                    </tr>
                {/if}

                {foreach from=$all_sips item=one_sip}
                    <tr>
                        <td align=right width=45%>
                            <img src="images/phone_status_{$one_sip.sip_status_color}.png" title="{$one_sip.sip_status} (нажмите для обновления)"
                                 style="cursor:pointer" onclick="refresh_sip_status({$one_sip.sip_number})">
                            {if $one_sip.sip_phone}{$one_sip.sip_phone}{else}{$one_sip.sip_s1}{/if} (SIP-{$one_sip.id}):
                        </td>
                        <td>
                            <a href="#" onclick="generate_sip_form({$one_sip.id}); return false;">{$lang.modules.asterisk.edit}</a>
                            <a href="#" onclick="generate_sip_form_delete({$one_sip.id}, {$one_sip.sip_number}); return false;">{$lang.modules.asterisk.delete}</a>
                            {if $one_sip.sip_domain == "vpbx.sipout.net"}
                                &nbsp;
                            <a href="https://vpbx.sipout.net/ui" onclick="go_sipout_lk({$one_sip.sip_s2}); return false;">{$lang.modules.asterisk.personal_account}</a>
                                &nbsp;
                                <b>{$one_sip.sip_balance}</b>
                            {/if}
                        </td>
                    </tr>
                    <tr class="sip{$one_sip.id}_form" style="display: none;">
                        <td align=right width=45%>{$lang.modules.asterisk.number}<span class="help_bt" h_id="telephony_SIPnumber"></span>:</td>
                        <td>
                            <input class="form-control form-control-160" type=text
                                   name="sip{if $one_sip.id > 1}{$one_sip.id}{/if}_s1" value="{$one_sip.sip_s1}">
                        </td>
                    </tr>
                    <tr class="sip{$one_sip.id}_form" style="display: none;">
                        <td align=right width=45%>{$lang.modules.asterisk.user}<span class="help_bt" h_id="telephony_SIPuser"></span>:</td>
                        <td>
                            <input class="form-control form-control-160" type=text
                                   name="sip{if $one_sip.id > 1}{$one_sip.id}{/if}_user" value="{$one_sip.sip_user}">
                        </td>
                    </tr>
                    <tr class="sip{$one_sip.id}_form" style="display: none;">
                        <td align=right width=45%>{$lang.modules.asterisk.password}<span class="help_bt" h_id="telephony_SIPpassword"></span>:</td>
                        <td>
                            <input class="form-control form-control-160" type=password
                                   name="sip{if $one_sip.id > 1}{$one_sip.id}{/if}_password" value="{$one_sip.sip_password}">
                        </td>
                    </tr>
                    <tr class="sip{$one_sip.id}_form" style="display: none;">
                        <td align=right width=45%>{$lang.modules.asterisk.domain}<span class="help_bt" h_id="telephony_SIPdomen"></span>:</td>
                        <td>
                            <input class="form-control form-control-160" type=text
                                   name="sip{if $one_sip.id > 1}{$one_sip.id}{/if}_domain" value="{$one_sip.sip_domain}">
                        </td>
                    </tr>
                    <tr class="sip{$one_sip.id}_form" style="display: none;">
                        <td align=right width=45%>{$lang.modules.asterisk.host}<span class="help_bt" h_id="telephony_SIPhost"></span>:</td>
                        <td>
                            <input class="form-control form-control-160" type=text
                                   name="sip{if $one_sip.id > 1}{$one_sip.id}{/if}_host" value="{$one_sip.sip_host}">
                            <input type=hidden name="sip{if $one_sip.id > 1}{$one_sip.id}{/if}_trunkname" value="{$main_server}">
                        </td>
                    </tr>
                    <tr class="sip{$one_sip.id}_form" style="display: none;">
                        <td align=right width=45%>{$lang.modules.asterisk.autocorrecting}<span class="help_bt" h_id="telephony_SIPreplace"></span>:</td>
                        <td>
                            <input class="form-control form-control-160 sip_replace" type=text
                                   name="sip{if $one_sip.id > 1}{$one_sip.id}{/if}_replace"
                                   value="{$one_sip.sip_replace}">
                        </td>
                    </tr>
                {/foreach}
                {if  !$trial}
                {if $all_sips|count_cb < $max_count_sips}
                    <tr>
                        <td align=center colspan=2>
                            <a href="#" onclick="generate_sip_form(0);return false;">{$lang.modules.asterisk.add}</a>
                        </td>
                    </tr>
                    <tr class="sip0_form" style="display: none;">
                        <td align=left colspan=2 style="padding-left:450px">
                            <input type=radio name="sip{$new_sip_id}_type" value=1
                                onclick="switch_sip_type(1)" id="sip_type1"> {$lang.modules.asterisk.SipOut_account}<br>
                            <input type=radio name="sip{$new_sip_id}_type" value=2
                                onclick="switch_sip_type(2)" id="sip_type2"> {$lang.modules.asterisk.other_account}
                               (<a href="https://clientbase.ru/help/for_admin_16/sravnitelnaya_tablica_provajderov_telefonii_protes/" target="_blank">{$lang.modules.asterisk.list_recommended}</a>)<br>
                            <input type=radio name="sip{$new_sip_id}_type" value=3
                                onclick="switch_sip_type(3)" id="sip_type3"> {$lang.modules.asterisk.extended}
                        </td>
                    </tr>
                    <tr class="sip_form_extended" style="display: none;">
                        <td align=right width=45%>{$lang.modules.asterisk.number}<span class="help_bt" h_id="telephony_SIPnumber"></span>:</td>
                        <td>
                            <input class="form-control form-control-160" type=text name="sip{$new_sip_id}_s1"
                                   value="{$add_sip.sip_s1}">
                        </td>
                    </tr>
                    <tr class="sip0_form" style="display: none;">
                        <td align=right width=45%>{$lang.modules.asterisk.user}<span class="help_bt" h_id="telephony_SIPuser"></span>:</td>
                        <td>
                            <input class="form-control form-control-160" type=text name="sip{$new_sip_id}_user"
                                   value="{$add_sip.sip_user}">
                        </td>
                    </tr>
                    <tr class="sip0_form" style="display: none;">
                        <td align=right width=45%>{$lang.modules.asterisk.password}<span class="help_bt" h_id="telephony_SIPpassword"></span>:</td>
                        <td>
                            <input class="form-control form-control-160" type=password name="sip{$new_sip_id}_password"
                                   value="{$add_sip.sip_password}">
                        </td>
                    </tr>
                    <tr class="sip_form_another sip_form_extended" style="display: none;">
                        <td align=right width=45%>{$lang.modules.asterisk.domain}<span class="help_bt" h_id="telephony_SIPdomen"></span>:</td>
                        <td>
                            <input class="form-control form-control-160" type=text name="sip{$new_sip_id}_domain"
                                   value="{$add_sip.sip_domain}">
                        </td>
                    </tr>
                    <tr class="sip_form_extended" style="display: none;">
                        <td align=right width=45%>{$lang.modules.asterisk.host}<span class="help_bt" h_id="telephony_SIPhost"></span>:</td>
                        <td>
                            <input class="form-control form-control-160" type=text name="sip{$new_sip_id}_host"
                                   value="{$add_sip.sip_host}">
                            <input type=hidden name="sip{$new_sip_id}_trunkname" value="{$main_server}">
                        </td>
                    </tr>
                    <tr class="sip_form_extended" style="display: none;">
                        <td align=right width=45%>{$lang.modules.asterisk.autocorrecting}<span class="help_bt" h_id="telephony_SIPreplace"></span>:</td>
                        <td>
                            <input class="form-control form-control-160 sip_replace" type=text name="sip{$new_sip_id}_replace"
                                   value="{$add_sip.sip_replace}">
                        </td>
                    </tr>
                    <tr class="sip0_form sip_reg" style="display: none;">
                        <td align=center colspan=2 style="padding-top: 7px;">
                            <a href="" onclick="$('#sipout_reg_form').dialog({ modal:true, width:560 }); return false;">{$lang.modules.asterisk.registration}</a>
                        </td>
                    </tr>
                {/if}
                {/if}
                <tr class="{foreach from=$all_sips item=one_sip}sip{$one_sip.id}_form {/foreach}sip0_form sip_form" style="display: none;">
                    <td colspan=2 align=center style="text-align: center;">
                        <br>
                        <input type="hidden" name="new_sip" value="{if $new_sip_id}{$new_sip_id}{else}1{/if}">
                        <input type="hidden" name="max_count_sips" value="{$max_count_sips}">
                        <input type="hidden" name="save" value="1">
                        <input type="hidden" name="csrf" value="{$csrf}">
                        <input class="btn btn-default btn-sm" type="submit"
                               onclick="{if $cant_edit_telephony}alert_add_user(); return false;{else}return check_sips();{/if}"
                               value="{$lang.Save}">
                    </td>
                </tr>

            </form>

            <!-- ТАБЛИЦЫ ДЛЯ ЗВОНКОВ -->

            {if $all_sips}

                <tr><td colspan="2"><br/></td></tr>

                <tr><td colspan="2" align="center" style="text-align: center;"><b>{$lang.modules.asterisk.call_tables}</b></td></tr>

                {foreach from=$f_tables item=one_table}
                    <form action="edit_modules.php?module=asterisk" method="post" enctype="multipart/form-data">
                        <input type="hidden" name="one_table" value="{$one_table.mid}"/>

                        <tr>
                            <td align=right width=45%>{$one_table.name_table}</td>
                            <td>
                                <a href="#" onclick="generate_f_tables_addit_form_edit({$one_table.mid});return false;">{$lang.modules.asterisk.edit}</a> |
                                <a href="#" onclick="generate_f_tables_form_delete({$one_table.mid});return false;">{$lang.modules.asterisk.delete}</a>
                            </td>
                        </tr>

                        <tr class="addit_form_edit_{$one_table.mid}" style="display:none;">
                            <td align=right width=45%>{$lang.modules.asterisk.priority}<span class="help_bt" h_id="telephony_priority"></span>:</td>
                            <td>
                                <select class="form-control form-control-160" name="priority">
                                    <option value="0" {if $one_table.priority==0}selected{/if}>{$lang.modules.asterisk.higher}</option>
                                    <option value="1" {if $one_table.priority==1}selected{/if}>{$lang.modules.asterisk.average}</option>
                                    <option value="2" {if $one_table.priority==2}selected{/if}>{$lang.modules.asterisk.low}</option>
                                </select>
                            </td>
                        </tr>

                        <tr class="addit_form_edit_{$one_table.mid}" style="display:none;">
                            <td align=right width=45%>{$lang.modules.asterisk.Field_phone}<span class="help_bt" h_id="telephony_phone"></span>:</td>
                            <td>{$one_table.phone_field}</td>
                        </tr>
                        <tr class="addit_form_edit_{$one_table.mid}" style="display:none;">
                            <td align=right width=45%>{$lang.modules.asterisk.Field_name}<span class="help_bt" h_id="telephony_name"></span>:</td>
                            <td>{$one_table.name_field}</td>
                        </tr>

                        <tr class="addit_form_edit_{$one_table.mid}" style="display:none;">
                            <td colspan="2" align="center" style="text-align: center;">
                                {$lang.modules.asterisk.display_3_fields}<span class="help_bt" h_id="telephony_add_fields"></span>:
                            </td>
                        </tr>
                        <tr class="addit_form_edit_{$one_table.mid}" style="display:none;">
                            <td align=right width=45%>{$lang.modules.asterisk.additional_field_1}:</td>
                            <td>{$one_table.addit_1_sel}</td>
                        </tr>
                        <tr class="addit_form_edit_{$one_table.mid}" style="display:none;">
                            <td align=right width=45%>{$lang.modules.asterisk.additional_field_2}:</td>
                            <td>{$one_table.addit_2_sel}</td>
                        </tr>
                        <tr class="addit_form_edit_{$one_table.mid}" style="display:none;">
                            <td align=right width=45%>{$lang.modules.asterisk.additional_field_3}:</td>
                            <td>{$one_table.addit_3_sel}</td>
                        </tr>

                        <tr class="addit_form_edit_{$one_table.mid}" style="display: none;">
                            <td colspan=2 align=center style="text-align: center;">
                                <input type="hidden" name="save" value="1">
                                <input type="hidden" name="csrf" value="{$csrf}">
                                <input class="btn btn-default btn-sm" type="submit" value="{$lang.Save}">
                            </td>
                        </tr>

                    </form>
                {/foreach}

                <form action="edit_modules.php?module=asterisk" method="post" enctype="multipart/form-data">
                    <input type="hidden" name="tables" value="1"/>
                    {if !$trial_table}
                    <tr>
                        <td colspan="2" align="center" style="text-align: center;">
                            <a href="#" onclick="generate_f_tables_form();return false;">{$lang.modules.asterisk.add}</a>
                        </td>
                    </tr>
                    {/if}
                    <tr class="f_tables_form" {if !$set_f_tables}style="display: none;"{/if}>
                        <td align=right width=45%>{$lang.modules.asterisk.table}:</td>
                        <td>
                            {$f_tables_arr}
                        </td>
                    </tr>
                    <tr class="f_tables_form" {if !$set_f_tables}style="display: none;"{/if}>
                        <td align=right width=45%>{$lang.modules.asterisk.Field_phone}:</td>
                        <td>
                            {$f_fields_arr_phone}
                        </td>
                    </tr>
                    <tr class="f_tables_form" {if !$set_f_tables}style="display: none;"{/if}>
                        <td align=right width=45%>{$lang.modules.asterisk.Field_name}:</td>
                        <td>
                            {$f_fields_arr_name}
                        </td>
                    </tr>


                    <tr class="f_tables_form f_tables_form_2" {if !$set_f_tables}style="display: none;"{/if}>
                        <td colspan=2 align=center style="text-align: center;">
                            <br>
                            <input type="hidden" name="save" value="1">
                            <input type="hidden" name="csrf" value="{$csrf}">
                            <input class="btn btn-default btn-sm" type="submit"
                                   {if $cant_edit_telephony}onclick="alert_add_user(); return false;"{/if}
                                   value="{$lang.Add}">
                        </td>
                    </tr>

                </form>
            {/if}

            <!-- ТАБЛИЦА ЗАПИСЕЙ РАЗГОВОРОВ -->

            {if $all_sips && $record_table}
                <form action="edit_modules.php?module=asterisk" method="post" enctype="multipart/form-data">
                    <input type="hidden" name="records" value="1"/>

                    <tr><td colspan="2"><br/></td></tr>

                    <tr><td colspan="2" align="center" style="text-align: center;"><b>{$lang.modules.asterisk.Call_records_table}</b></td></tr>

                    <tr>
                        <td colspan="2" align="center" style="text-align: center;">
                            <a href="fields.php?table={$record_table.id}" target="_blanc">{$record_table.name}</a>
                        </td>
                    </tr>

                </form>
            {/if}

            <!-- ПОЛЬЗОВАТЕЛИ -->

            <tbody id="users_block" {if ($all_sips && $record_table) || $as_users|count_cb > 1 }{else}style="display:none"{/if}>

            <form action="edit_modules.php?module=asterisk" method="post" enctype="multipart/form-data">
                <input type="hidden" name="users" value="1"/>

                <tr><td colspan="2"><br/></td></tr>

                    <tr><td colspan="2" align="center" style="text-align: center;"><b>{$lang.modules.asterisk.users}</b></td></tr>

                {if $one_number_err}
                    <tr>
                        <td colspan=2 align=center style="text-align: center; color: red">
                                {$lang.modules.asterisk.user_number} {$one_number_err} {$lang.modules.asterisk.already_exists}.
                            <br/><br/>
                        </td>
                    </tr>
                {/if}

                {if $ask_user_error}
                    <tr>
                        <td colspan=2 align=center style="text-align: center; color: red">
                            {if $ask_user_error==1}
                                    {$lang.modules.asterisk.user_number_missing}.
                            {else}
                                    {$lang.modules.asterisk.user_password_missing}.
                            {/if}
                            <br/><br/>
                        </td>
                    </tr>
                {/if}

                {foreach from=$as_users item=one_user}
                    <tr>
                        <td align=right width=45%>{$one_user.info.fio}</td>
                        <td>
                            ({$one_user.login})
                                <a href="#" onclick="generate_user_form_edit({$one_user.id});return false;">{$lang.modules.asterisk.edit}</a>
                            {if $one_user.login!=101}
                                    <a href="#" onclick="generate_user_form_delete({$one_user.id});return false;">{$lang.modules.asterisk.delete}</a>
                            {/if}
                        </td>
                    </tr>
                    <tr class="user_form_edit_{$one_user.id}" style="display: none;">
                            <td align=right width=45%>{$lang.modules.asterisk.user}:</td>
                        <input type=hidden name="user_id[]" value="{$one_user.id}">
                        <td>
                            <select class="form-control form-control-160" name="user_name_edit_{$one_user.id}">
                                <option value="{$one_user.info.id}">{$one_user.info.fio}</option>
                                {foreach from=$se_users item=one_user2}
                                    <option value="{$one_user2.id}">{$one_user2.fio}</option>
                                {/foreach}
                            </select>
                        </td>
                    </tr>
                    <tr class="user_form_edit_{$one_user.id}" style="display: none;">
                            <td align=right width=45%>{$lang.modules.asterisk.login}:</td>
                        <td>{$main_server}_{$one_user.login}</td>
                    </tr>
                    <tr class="user_form_edit_{$one_user.id}" style="display: none;">
                            <td align=right width=45%>{$lang.modules.asterisk.password}:</td>
                        <td>
                            <input class="form-control form-control-160" type=text
                                       name="user_password_edit_{$one_user.id}" value="{$one_user.password}" size=20>
                        </td>
                    </tr>
                    <tr class="user_form_edit_{$one_user.id}" style="display: none;">
                            <td align=right width=45%>{$lang.modules.asterisk.number}:</td>
                        <td>
                            {if $one_user.login!=101}
                                <input class="form-control form-control-160" type=text
                                       name="user_phone_edit_{$one_user.id}" value="{$one_user.login}">
                            {else}
                                101 <input type=hidden name="user_phone_edit_{$one_user.id}" value="{$one_user.login}">
                            {/if}
                        </td>
                    </tr>
                    <tr class="user_form_edit_{$one_user.id}" style="display: none;">
                            <td align=right width=45%>{$lang.modules.asterisk.receive_call}:</td>
                        <td>
                            <input type=checkbox name="user_incoming_edit_{$one_user.id}" {if $one_user.from_browser}checked{/if}>
                        </td>
                    </tr>
                    <tr class="user_form_edit_{$one_user.id}" style="display: none;">
                            <td align=right width=45%>{$lang.modules.asterisk.browser_calls}:</td>
                        <td>
                            <input type=checkbox name="user_browser_caller_{$one_user.id}" {if $one_user.browser_caller}checked{/if} value="1">
                        </td>
                    </tr>
                {/foreach}

                {if !empty($se_users)}
                    <tr>
                        <td colspan="2" align="center" style="text-align: center;">
                                <a href="#" onclick="generate_user_form();return false;">{$lang.modules.asterisk.add}</a>
                            <input type="hidden" name="add_user" id="add_user_active" value=0>
                        </td>
                    </tr>
                    <tr class="user_form" style="display: none;">
                            <td align=right width=45%>{$lang.modules.asterisk.user}:</td>
                        <td>
                            <select class="form-control form-control-160" name="user_name" id="user_name">
                                {foreach from=$se_users item=one_user}
                                    <option value="{$one_user.id}">{$one_user.fio}</option>
                                {/foreach}
                            </select>
                        </td>
                    </tr>
                    <tr class="user_form" style="display: none;">
                            <td align=right width=45%>{$lang.modules.asterisk.password}:</td>
                        <td>
                            <input class="form-control form-control-160" type=text name="user_password" value="{$new_pass}">
                        </td>
                    </tr>
                    <tr class="user_form" style="display: none;">
                            <td align=right width=45%>{$lang.modules.asterisk.number}:</td>
                        <td>
                            <input class="form-control form-control-160" type=text name="user_phone" value="">
                        </td>
                    </tr>
                    <tr class="user_form" style="display: none;">
                            <td align=right width=45%>{$lang.modules.asterisk.receive_call}:</td>
                            <td><input type=checkbox name="user_incoming" size=20></td>
                    </tr>
                    <tr class="user_form" style="display: none;">
                            <td align=right width=45%>{$lang.modules.asterisk.browser_calls}:</td>
                            <td><input type=checkbox name="browser_caller" value="1" size=20 checked></td>
                    </tr>
                {/if}

                <tr class="user_form user_form_2" style="display:none;">
                    <td colspan=2 align=center style="text-align: center;">
                        <br>
                        <input type="hidden" name="save" value="1">
                        <input type="hidden" name="csrf" value="{$csrf}">
                        <input class="btn btn-default btn-sm" type="submit" value="{$lang.Save}">
                    </td>
                </tr>

            </form>

            </tbody>

            <!-- ДОПОЛНИТЕЛЬНЫЕ НАСТРОЙКИ -->

            {if $all_sips && $record_table}
                <form action="edit_modules.php?module=asterisk" method="post" enctype="multipart/form-data">
                    <input type="hidden" name="server_id" value="{if !$one_server.id}-1{else}{$one_server.id}{/if}"/>

                    <tr><td colspan="2"><br/></td></tr>

                    <tr>
                        <td colspan="2" align="center" style="text-align: center;">
                            <a href="" onclick="display_add_settings(); return false;"><b>{$lang.modules.asterisk.additional_settings}</b></a>
                        </td>
                    </tr>

                    <tr class="add_settings" style="display: none;"><td colspan="2"><br/></td></tr>

                    <tr class="add_settings" style="display: none;">
                        <td align=right width=45%>{$lang.modules.asterisk.greeting}<span class="help_bt" h_id="greeting"></span>:</td>
                        <td>
                            {if $one_server.hello_audio}
                                {$one_server.hello_audio}
                                <a href="modules/asterisk/{$one_server.hello_audio}">{$lang.modules.asterisk.download}</a>
                                &nbsp;
                                <a href="edit_modules.php?module=asterisk&server_id={$one_server.id}&remove=hello_audio">{$lang.modules.asterisk.delete}</a>
                            {else}
                                <input type=file name="hello_audio" accept="audio/mp3" />
                            {/if}
                        </td>
                    </tr>
                    <tr class="add_settings" style="display: none;" id="inter_code_tr">
                        <td align=right width=45%>{$lang.modules.asterisk.Default_prefix}<span class="help_bt" h_id="inter_code"></span>:</td>
                        <td><input class="form-control form-control-160" type=text name="inter_code"
                                   value="{if $one_server.inter_code!=0}{$one_server.inter_code}{/if}"></td>
                    </tr>
                    <tr class="add_settings" style="display: none;" id="inter_code_tr">
                        <td align=right width=45%>{$lang.modules.asterisk.output_prefix}<span class="help_bt" h_id="inter_prefix"></span>:</td>
                        <td><input class="form-control form-control-160" type=text name="inter_prefix"
                                   value="{$one_server.inter_prefix}"></td>
                    </tr>
                    <tr class="add_settings" style="display: none;">
                        <td align=right width=45%>{$lang.modules.asterisk.ban_calls}<span class="help_bt" h_id="max_phone_numbers"></span>:</td>
                        <td><input class="form-control form-control-160" type=text name="max_phone_numbers"
                                   value="{if $one_server.max_phone_numbers!=0}{$one_server.max_phone_numbers}{/if}"></td>
                    </tr>
                    <tr class="add_settings" style="display: none;">
                        <td align=right width=45%>{$lang.modules.asterisk.length_local_number}<span class="help_bt" h_id="loc_numbers_lenght"></span>:</td>
                        <td><input class="form-control form-control-160" type=text name="loc_numbers_lenght"
                                   value="{if $one_server.loc_numbers_lenght!=0}{$one_server.loc_numbers_lenght}{/if}"></td>
                    </tr>
                    <tr class="add_settings" style="display: none;" id="inter_code_tr">
                        <td align=right width=45%>{$lang.modules.asterisk.additional_rules}<span class="help_bt" h_id="addit_rules"></span>:</td>
                        <td><input class="form-control form-control-160" type=text name="addit_rules"
                                   value="{$one_server.addit_rules}">
                        </td>
                    </tr>
                    <tr class="add_settings" style="display: none;">
                        <td align=right width=45%>{$lang.modules.asterisk.permitted_directions}<span class="help_bt" h_id="asterisk_perm_dir"></span>:</td>
                        <td>
                            <input type=checkbox name="perm_dir[lat]" value=1 {if $one_server.perm_dir.lat}checked{/if}>{strip}
                            {/strip}<span class="help_bt" h_id="perm_dir_lat" style="margin-top:-5px"></span>
                            {$lang.modules.asterisk.Latvia} <br>
                            <input type=checkbox name="perm_dir[est]" value=1 {if $one_server.perm_dir.est}checked{/if}>{strip}
                            {/strip}<span class="help_bt" h_id="perm_dir_est" style="margin-top:-5px"></span>
                            {$lang.modules.asterisk.Estonia} <br>
                            <input type=checkbox name="perm_dir[bel]" value=1 {if $one_server.perm_dir.bel}checked{/if}>{strip}
                            {/strip}<span class="help_bt" h_id="perm_dir_bel" style="margin-top:-5px"></span>
                            {$lang.modules.asterisk.Belarus} <br>
                            <input type=checkbox name="perm_dir[ukr]" value=1 {if $one_server.perm_dir.ukr}checked{/if}>{strip}
                            {/strip}<span class="help_bt" h_id="perm_dir_ukr" style="margin-top:-5px"></span>
                            {$lang.modules.asterisk.Ukraine} <br>
                            <input type=checkbox name="perm_dir[kaz]" value=1 {if $one_server.perm_dir.kaz}checked{/if}>{strip}
                            {/strip}<span class="help_bt" h_id="perm_dir_kaz" style="margin-top:-5px"></span>
                            {$lang.modules.asterisk.Kazakhstan} <br>
                            <input type=checkbox name="perm_dir[rus]" value=1 {if $one_server.perm_dir.rus}checked{/if} onclick="$('#inter_code_tr').toggle(this.checked)">{strip}
                            {/strip}<span class="help_bt" h_id="perm_dir_rus" style="margin-top:-5px"></span>
                            {$lang.modules.asterisk.Russia} <br>
                            <input type=checkbox name="perm_dir[all]" value=1 {if $trial}disabled{/if} {if $one_server.perm_dir.all}checked{/if} onclick="all_dir_switch(this.checked)">{strip}
                            {/strip}<span class="help_bt" h_id="perm_dir_all" style="margin-top:-5px"></span>
                            <b>{$lang.modules.asterisk.all}</b><span id="all_dir_users" {if !$one_server.perm_dir.all}style="display: none;"{/if}>, {$lang.modules.asterisk.only_for}:<br>
                                {foreach from=$as_users item=one_user}
                                    <span style="margin-left: 40px"><input type=checkbox name="all_dir_users[]" value="{$one_user.login}" {if $one_user.all_dir}checked{/if}> {$one_user.info.fio}</span><br>
                                {/foreach}
                                <div style="margin: 5px 0 0 42px">
                                <input class="form-control form-control-160" type=text name="capacity"
                                       value="{$one_server.capacity}" size=1> {$lang.modules.asterisk.simultaneous_call}
                            </div>
                            </span>
                        </td>
                    </tr>
                    <tr class="add_settings" style="display: none;" id="forward_phone">
                        <td align=right width=45%>{$lang.modules.asterisk.call_forwarding}<span class="help_bt" h_id="forward_phone"></span>:</td>
                        <td>
                            <input class="form-control form-control-160" type=text name="forward_phone"
                                   id="forward_phone" value="{$one_server.forward_phone}">
                            <!-- img src="images/phone_icon1.png" title="Позвонить" style="cursor:pointer; margin: 0 0 -2px 2px;"
                                 onclick="module_asterisk_call{if $user.browser_caller}_window{/if}($('#forward_phone').val())" width="16" -->
                            {if $bad_forward_phones}
                                <span style="text-align: center; color: red">
                                    <br>{if $bad_forward_phones|strpos:','}{$lang.modules.asterisk.incorrect_phone_numbers}{else}{$lang.modules.asterisk.incorrect_phone_number}{/if}: 111, 222{$bad_forward_phones}
                                </span>
                            {/if}
                        </td>
                    </tr>
                    <tr class="add_settings" style="display: none;">
                        <td align=right width=45%>{$lang.modules.asterisk.call_completion}<span class="help_bt" h_id="forward_timeout"></span>:</td>
                        <td>
                            <input class="form-control" type=text name="forward_timeout" style="width:20px"
                                   value="{if $one_server.forward_timeout!=0}{$one_server.forward_timeout}{else}15{/if}"> сек
                        </td>
                    </tr>
                    {if $record_table}
                        <tr class="add_settings" style="display: none;">
                            <td align=right width=45%>{$lang.modules.asterisk.delete_30_days}<span class="help_bt" h_id="record_limit"></span>:</td>
                            <td>
                                <select name="record_limit" class="form-control" style="width:20px">
                                    <option value=""></option>
                                    <option value="1" {if $one_server.city_code == 1}selected{/if}>1</option>
                                    <option value="3" {if $one_server.city_code == 3}selected{/if}>3</option>
                                    <option value="6" {if $one_server.city_code == 6}selected{/if}>6</option>
                                    <option value="12" {if $one_server.city_code == 12}selected{/if}>12</option>
                                </select>
                                {$lang.months}
                            </td>
                        </tr>
                    {/if}
                    <tr class="add_settings" style="display: none;">
                        <td align=right width=45% style="vertical-align:top; padding-top:7px;">
                            {$lang.modules.asterisk.program_address}<span class="help_bt" h_id="asterisk_client_host"></span>:
                        </td>
                        <td style="padding-top:5px;">
                            {if $memcache_work}
                                <input class="form-control form-control-160" type=text name="client_host"
                                       id="client_host" value="{$one_server.client_host}">
                                {if !$one_server.client_host}
                                    <br><a href="" onclick="$('#client_host').val('{$config.site_url}'); return false;">{$lang.modules.asterisk.fill_in_automatically}</a>
                                {/if}
                            {elseif $memcache_connect}
                                <span style="color:red">{$lang.modules.asterisk.Memcache_error}</span>
                            {elseif $memcache_exist}
                                <span style="color:red">{$lang.modules.asterisk.Memcache_failed}</span>
                            {else}
                                <span style="color:red">{$lang.modules.asterisk.no_Memcache}</span>
                            {/if}
                        </td>
                    </tr>
                    <tr class="add_settings" style="display: none;">
                        <td align=right width=45%>{$lang.modules.asterisk.Automatically_add_group_users}<span class="help_bt" h_id="auto_add_phone_users"></span>:</td>
                        <td>
                            {foreach from=$a_groups item=one_group key=a_group_id}
                                <input type="checkbox"
                                       name="auto_add_ip_user[]"
                                       id="auto_add_ip_user{$a_group_id}"
                                       value="{$a_group_id}"
                                       {if $one_group.auto_add_ip_user}checked{/if}>
                                <label for="auto_add_ip_user{$a_group_id}">{$one_group.name}</label><br>
                            {/foreach}
                        </td>
                    </tr>
                    <tr class="add_settings" style="display: none;">
                        <td align=right width=45%>{$lang.modules.asterisk.hide_numbers_phones}<span class="help_bt" h_id="hide_phones_for_groups"></span>:</td>
                        <td>
                            {foreach from=$a_groups item=one_group key=a_group_id}
                                <input type="checkbox"
                                       name="hide_phones_for_groups[]"
                                       id="hide_phones_for_group{$a_group_id}"
                                       value="{$a_group_id}"
                                       {if $one_group.hide_phones_for_group}checked{/if}>
                                <label for="hide_phones_for_group{$a_group_id}">{$one_group.name}</label><br>
                            {/foreach}
                        </td>
                    </tr>
                    <tr class="add_settings" style="display: none;">
                        <td align=right width=45%>{$lang.modules.asterisk.how_hide_numbers}:<span class="help_bt" h_id="hide_phones_type"></span>:</td>
                        <td>
                            <input type="radio"
                                   name="hide_phones_type"
                                   id="hide_phones_type1"
                                   value="-1"
                                   onclick="$('#hide_phones_count_chars1, #hide_phones_count_chars2').val('')"
                                   {if $one_server.hide_phones_type == -1}checked{/if}>
                            <label for="hide_phones_type1">{$lang.modules.asterisk.in_full}</label><br>

                            <input type="radio"
                                   name="hide_phones_type"
                                   id="hide_phones_type2"
                                   value="0"
                                   onclick="$('#hide_phones_count_chars1, #hide_phones_count_chars2').val('')"
                                   {if $one_server.hide_phones_type == 0}checked{/if}>
                            <label for="hide_phones_type2">{$lang.modules.asterisk.replace_by_asterisk}</label><br>

                            <input type="radio"
                                   name="hide_phones_type"
                                   id="hide_phones_type3"
                                   value="1"
                                   onclick="$('#hide_phones_count_chars1').val($('#hide_phones_count_chars').val()); $('#hide_phones_count_chars2').val('')"
                                   {if $one_server.hide_phones_type == 1}checked{/if}>
                            <input class="form-control form-control-160" type="text"
                                   id="hide_phones_count_chars1"
                                   value="{if $one_server.hide_phones_type == 1 && $one_server.hide_phones_count_chars}{$one_server.hide_phones_count_chars}{/if}"
                                   onclick="$('#hide_phones_type3').prop('checked', true); this.value = $('#hide_phones_count_chars').val(); $('#hide_phones_count_chars2').val('')"
                                   onchange="$('#hide_phones_count_chars').val(this.value)"
                                   style="width:20px; height:15px;">
                            <label for="hide_phones_type3">{$lang.modules.asterisk.first_symbols}</label><br>

                            <input type="radio"
                                   name="hide_phones_type"
                                   id="hide_phones_type4"
                                   value="2"
                                   onclick="$('#hide_phones_count_chars2').val($('#hide_phones_count_chars').val()); $('#hide_phones_count_chars1').val('')"
                                   {if $one_server.hide_phones_type == 2}checked{/if}>
                            <input class="form-control form-control-160" type="text"
                                   id="hide_phones_count_chars2"
                                   value="{if $one_server.hide_phones_type == 2 && $one_server.hide_phones_count_chars}{$one_server.hide_phones_count_chars}{/if}"
                                   onclick="$('#hide_phones_type4').prop('checked', true); this.value = $('#hide_phones_count_chars').val(); $('#hide_phones_count_chars1').val('')"
                                   onchange="$('#hide_phones_count_chars').val(this.value)"
                                   style="width:20px; height:15px;">
                            <label for="hide_phones_type4">{$lang.modules.asterisk.last_symbols}</label>

                            <input type="hidden"
                                   name="hide_phones_count_chars"
                                   id="hide_phones_count_chars"
                                   value="{if $one_server.hide_phones_count_chars}{$one_server.hide_phones_count_chars}{/if}">
                        </td>
                    </tr>
                    {if $browser_caller_on}
                        <tr class="add_settings" style="display: none;">
                        <td align=right width=45%>{$lang.modules.asterisk.Disable_reminder}<span class="help_bt" h_id="disable_phone_window_reminder"></span>:</td>
                            <td>
                                <input type="checkbox"
                                       name="disable_reminder"
                                       value=1
                                       {if $one_server.disable_reminder}checked{/if}>
                            </td>
                        </tr>
                    {/if}
                    <tr class="add_settings" style="display: none;">
                        <td align=right width=45%>{$lang.modules.asterisk.allow_direct_call}<span class="help_bt" h_id="allow_direct_call"></span>:</td>
                        <td>
                            <input type="checkbox"
                                   name="allow_direct_call"
                                   value=1
                                   {if $one_server.allow_direct_call}checked{/if}>
                        </td>
                    </tr>
                    <tr class="add_settings" style="display: none;" id="add_settings_save">
                        <td colspan=2 align=center style="text-align: center;">
                            <br>
                            <input type="hidden" name="save" value="1">
                            <input type="hidden" name="csrf" value="{$csrf}">
                            <input class="btn btn-default btn-sm" type="submit"
                                   {if $cant_edit_telephony}onclick="alert_add_user(); return false;"{/if}
                                   value="{$lang.Save}">
                        </td>
                    </tr>

                </form>
            {/if}
            {*<tr class="add_settings">
                <td align=right width=45%>Не оповещать о необходимости активного окна модуля телефонии<span class="help_bt" h_id="disable_notify_asterisk"></span>:</td>
                <td>
                    <input type="checkbox"
                           name="disable_notify_asterisk"
                           value={if $asterisk_settings.disable_notify_asterisk}1{else}0{/if}
                           {if $asterisk_settings.disable_notify_asterisk}checked{/if} onclick="change_checkbox_value(event);">
                </td>
            </tr>
            <tr>
                <td colspan="2" align="center">
                    <input class="btn btn-default btn-sm" type="button" value="Сохранить" onclick="update_asterisk_settings();">
                </td>
            </tr>*}
        </table>
        <br>
        <form action="edit_modules.php?module=asterisk" method="post" id="deactivate_form" class="hidden">
            <input type="hidden" name="save" value="1">
            <input type="hidden" name="csrf" value="{$csrf}">
            <input type="hidden" name="deactivate" value="1">
            <input type="hidden" name="deactivate_on_server" id="deactivate_on_server" value="1">
            <input class="btn btn-default btn-sm" type="button" value="{$lang.modules.asterisk.off_module}" onclick="deactivate_asterisk();">
        </form>
        <br>
        {if $trial_check}
          <div style="margin:20px auto;font-size:13px"> {$lang.modules.asterisk.trial_version}</div>
        {/if}
    {else}
        {$lang.modules.asterisk.module_status}: {$lang.modules.asterisk.switched_off}.
        <br>
        <br>
        {if $error==404}
            <div align="center" style="text-align:center; color:red;">
                    {$lang.modules.asterisk.SIP_server_error}
                <br><br>
            </div>
        {/if}
        <form action="edit_modules.php?module=asterisk" method="post" id="activate_form" class="hidden">
            <input type="hidden" name="save" value="1">
            <input type="hidden" name="csrf" value="{$csrf}">
            <input type="hidden" name="activate" value="1">
            <input type="hidden" name="server_name" value="Clientbase" id="server_name">
            <input class="btn btn-default btn-sm" type="button" value="{$lang.modules.asterisk.Enable_module}" onclick="activate_asterisk();"><br><br>
            <div align="center"><a href="" onclick="$('#additional').toggle(); return false;">{$lang.Additional}</a></div>
            <div id="additional" style="display:none">
                <br>{$lang.modules.asterisk.Server}<span class="help_bt" h_id="asterisk_server"></span>
                <input type="text" name="server" value="sip.{$config.clientbase_domain}" class="form-control form-control-160"
                       onchange="$('#server_name').val(this.value ? 'Alternate' : 'Clientbase')">
            </div>
        </form>
    {/if}
</div>

<form action="edit_modules.php?module=asterisk" method="post" id="asterisk_delete_form">
    <input type="hidden" name="save" value="1">
    <input type="hidden" name="csrf" value="{$csrf}">
    <input type="hidden" name="delete" value="" id="asterisk_delete_form_user">
</form>

<form action="edit_modules.php?module=asterisk" method="post" id="asterisk_delete_form_s">
    <input type="hidden" name="save" value="1">
    <input type="hidden" name="csrf" value="{$csrf}">
    <input type="hidden" name="sip_to_delete" value="" id="asterisk_delete_form_sip_id">
    <input type="hidden" name="sipnumber" value="" id="asterisk_delete_form_sip_count">
</form>

<form action="edit_modules.php?module=asterisk" method="post" id="asterisk_delete_form_f">
    <input type="hidden" name="save" value="1">
    <input type="hidden" name="csrf" value="{$csrf}">
    <input type="hidden" name="f_tables_to_delete" value="" id="asterisk_delete_form_f_tables">
</form>

<form action="edit_modules.php?module=asterisk" method="post" id="asterisk_refresh_sip_form">
    <input type="hidden" name="csrf" value="{$csrf}">
    <input type="hidden" name="sip_to_refresh" id="sip_to_refresh">
</form>

<form action="https://vpbx.sipout.net/ui" method="post" id="sipout_lk" target="_blanc">
    <input type="hidden" name="ac" id="sipout_login">
    <input type="hidden" name="pw" id="sipout_password">
    <input type="hidden" name="phone" id="sipout_phone">
</form>

<div align=center id="sipout_reg_form" style="display: none;">
    <form action="edit_modules.php?module=asterisk" method="post" enctype="multipart/form-data">
        <table border=0 cellpadding=3 cellspacing=0 width=100%>
            <tr><td colspan="2" align="center" style="text-align: center;"><b>{$lang.modules.asterisk.SipOut_check_in}</b></td></tr>

            <tr><td colspan="2" style="text-align: center; color: red" id="sip_reg_error"></td></tr>

            <tr><td colspan="2"></td></tr>

            <tr>
                <td align=right width=50%>{$lang.modules.asterisk.user_type}:</td>
                <td>
                    <select class="form-control form-control-160" name="org_type" onchange="switch_reg_type(this.value)">
                        <option value="private">{$lang.modules.asterisk.private_person}</option>
                        <option value="org">{$lang.modules.asterisk.organization}</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td align=right width=50%>{$lang.modules.asterisk.phone}:</td>
                <td><input class="form-control form-control-160" type=text name="phone" value="{$sip_reg.phone}"></td>
            </tr>
            <tr>
                <td align=right width=50%>{$lang.modules.asterisk.email}</td>
                <td><input class="form-control form-control-160" type=text name="email" value="{$sip_reg.email}"></td>
            </tr>
            <tr>
                <td align=right width=50%>{$lang.modules.asterisk.city}:</td>
                <td><input class="form-control form-control-160" type=text name="city" value="{$sip_reg.city}"></td>
            </tr>

            <tr class="sip_reg_private">
                <td align=right width=50%>{$lang.modules.asterisk.Surname}:</td>
                <td><input class="form-control form-control-160" type=text name="surname" value="{$sip_reg.surname}"></td>
            </tr>
            <tr class="sip_reg_private">
                <td align=right width=50%>{$lang.modules.asterisk.name}:</td>
                <td><input class="form-control form-control-160" type=text name="name" value="{$sip_reg.name}"></td>
            </tr>
            <tr class="sip_reg_private">
                <td align=right width=50%>{$lang.modules.asterisk.middle_name}:</td>
                <td><input class="form-control form-control-160" type=text name="middle_name" value="{$sip_reg.middle_name}"></td>
            </tr>
            <tr class="sip_reg_private">
                <td align=right width=50%>{$lang.modules.asterisk.Registration_address}:</td>
                <td><input class="form-control form-control-160" type=text name="adr_reg" value="{$sip_reg.adr_reg}"></td>
            </tr>
            <tr class="sip_reg_private">
                <td align=right width=50%>{$lang.modules.asterisk.actual_address}:</td>
                <td><input class="form-control form-control-160" type=text name="adr_live" value="{$sip_reg.adr_live}"></td>
            </tr>
            <tr class="sip_reg_private">
                <td align=right width=50%>{$lang.modules.asterisk.passport_series}:</td>
                <td><input class="form-control form-control-160" type=text name="pasp_serie" value="{$sip_reg.pasp_serie}"></td>
            </tr>
            <tr class="sip_reg_private">
                <td align=right width=50%>{$lang.modules.asterisk.passport_number}:</td>
                <td><input class="form-control form-control-160" type=text name="pasp_num" value="{$sip_reg.pasp_num}"></td>
            </tr>
            <tr class="sip_reg_private">
                <td align=right width=50%>{$lang.modules.asterisk.Passport_issued_by}:</td>
                <td><input class="form-control form-control-160" type=text name="pasp_issued" value="{$sip_reg.pasp_issued}"></td>
            </tr>
            <tr class="sip_reg_private">
                <td align=right width=50%>{$lang.modules.asterisk.Date_issue_passport}:</td>
                <td><input class="form-control form-control-160" type=text name="pasp_date" value="{$sip_reg.pasp_date}"></td>
            </tr>

            <tr class="sip_reg_org" style="display: none;">
                <td align=right width=50%>{$lang.modules.asterisk.Name_organization}:</td>
                <td><input class="form-control form-control-160" type=text name="org_name" value="{$sip_reg.org_name}"></td>
            </tr>
            <tr class="sip_reg_org" style="display: none;">
                <td align=right width=50%>{$lang.modules.asterisk.Organizational_legal_form}:</td>
                <td><input class="form-control form-control-160" type=text name="opf" value="{$sip_reg.opf}"></td>
            </tr>
            <tr class="sip_reg_org" style="display: none;">
                <td align=right width=50%>{$lang.modules.asterisk.Legal_address}:</td>
                <td><input class="form-control form-control-160" type=text name="law_addr" value="{$sip_reg.law_addr}"></td>
            </tr>
            <tr class="sip_reg_org" style="display: none;">
                <td align=right width=50%>{$lang.modules.asterisk.Organization_PPC}:</td>
                <td><input class="form-control form-control-160" type=text name="kpp" value="{$sip_reg.kpp}"></td>
            </tr>
            <tr class="sip_reg_org" style="display: none;">
                <td align=right width=50%>{$lang.modules.asterisk.TIN_organization}:</td>
                <td><input class="form-control form-control-160" type=text name="inn" value="{$sip_reg.inn}"></td>
            </tr>
            <tr class="sip_reg_org" style="display: none;">
                <td align=right width=50%>{$lang.modules.asterisk.Organization_OGRN}:</td>
                <td><input class="form-control form-control-160" type=text name="ogrn" value="{$sip_reg.ogrn}"></td>
            </tr>
            <tr class="sip_reg_org" style="display: none;">
                <td align=right width=50%>{$lang.modules.asterisk.Name_bank}:</td>
                <td><input class="form-control form-control-160" type=text name="bank_name" value="{$sip_reg.bank_name}"></td>
            </tr>
            <tr class="sip_reg_org" style="display: none;">
                <td align=right width=50%>{$lang.modules.asterisk.Bank_BIC}:</td>
                <td><input class="form-control form-control-160" type=text name="bik" value="{$sip_reg.bik}"></td>
            </tr>
            <tr class="sip_reg_org" style="display: none;">
                <td align=right width=50%>{$lang.modules.asterisk.Personal_account}:</td>
                <td><input class="form-control form-control-160" type=text name="bank_rs" value="{$sip_reg.bank_rs}"></td>
            </tr>
            <tr class="sip_reg_org" style="display: none;">
                <td align=right width=50%>{$lang.modules.asterisk.Location}:</td>
                <td><input class="form-control form-control-160" type=text name="placement" value="{$sip_reg.placement}"></td>
            </tr>
            <tr class="sip_reg_org" style="display: none;">
                <td align=right width=50%>{$lang.modules.asterisk.location_at}:</td>
                <td><input class="form-control form-control-160" type=text name="at_place" value="{$sip_reg.at_place}"></td>
            </tr>

            <tr><td colspan="2"></td></tr>

            <tr>
                <td colspan=2 align=center style="text-align: center;">
                    <input type="hidden" name="sipout_reg" value="1"/>
                    <input type="hidden" name="sip_num" value="{$new_sip_id}">
                    <input type="hidden" name="save" value="1">
                    <input type="hidden" name="csrf" value="{$csrf}">
                    <input class="btn btn-default btn-sm" type="submit" value="{$lang.Save}">
                </td>
            </tr>

            <tr><td colspan="2"></td></tr>
            <tr><td colspan="2"></td></tr>

        </table>
    </form>
</div>

<script>
    function generate_f_tables_addit_form_edit(id) {
        if ($('.addit_form_edit_' + id).css('display') == 'none') {
            $('.addit_form_edit_' + id).fadeIn();
            $('.addit_form_2').fadeIn();
        }
        else {
            $('.addit_form_edit_' + id).fadeOut();
            $('.addit_form_2').fadeOut();
        }
    }
    function generate_sip_form(id) {
        {if !$full_version}
        jalert('{$lang.modules.asterisk.upgrade_sip_version}.');
        {else}
        if ($('.sip'+id+'_form').css('display') == 'none') {
            $('.sip'+id+'_form').fadeIn();
            $('.sip'+id+'_form input').addClass('sip_fields');
            $('.sip_replace').removeClass('sip_fields');
            $('.sip'+id+'_form').css('background-color', '#fff');
            if (id == 0) switch_sip_type(1);
        }
        else {
            $('.sip'+id+'_form').fadeOut();
            $('.sip'+id+'_form input').removeClass('sip_fields');
            $('#sip_alert').html('');
            if (id == 0) switch_sip_type(0);
        }
        {/if}
    }

    function generate_user_form() {
        if ($('.user_form').css('display') == 'none') {
            $('.user_form').fadeIn();
            $('#add_user_active').val(1);
        }
        else {
            $('.user_form').fadeOut();
            $('#add_user_active').val(0);
        }
    }

    function generate_f_tables_form() {
        if ($('.f_tables_form').css('display') == 'none') {
            $('.f_tables_form').fadeIn();
        }
        else {
            $('.f_tables_form').fadeOut();
        }
    }

    function generate_fields_form() {
        if ($('.fields_form').css('display') == 'none') {
            $('.fields_form').fadeIn();
        }
        else {
            $('.fields_form').fadeOut();
        }
    }

    function generate_user_form_edit(id) {
        if ($('.user_form_edit_' + id).css('display') == 'none') {
            $('.user_form_edit_' + id).fadeIn();
            $('.user_form_2').fadeIn();
        }
        else {
            $('.user_form_edit_' + id).fadeOut();
            $('.user_form_2').fadeOut();
        }
    }

    function generate_f_tables_form_edit(id) {
        if ($('.f_tables_form_edit_' + id).css('display') == 'none') {
            $('.f_tables_form_edit_' + id).fadeIn();
            $('.f_tables_form_2').fadeIn();
        }
        else {
            $('.f_tables_form_edit_' + id).fadeOut();
            $('.f_tables_form_2').fadeOut();
        }
    }

    function generate_user_form_delete(id) {
        jconfirm('{$lang.modules.asterisk.remove_user_module}', function () {
            $('#asterisk_delete_form_user').val(id);
            $('#asterisk_delete_form').submit();
        });
    }

    function generate_f_tables_form_delete(id) {
        jconfirm('{$lang.modules.asterisk.remove_table_module}', function () {
            $('#asterisk_delete_form_f_tables').val(id);
            $('#asterisk_delete_form_f').submit();
        });
    }

    function generate_sip_form_delete(id, count) {
        {if $cant_edit_telephony}
        alert_add_user();
        {else}
        jconfirm('{$lang.modules.asterisk.remove_sip_module}', function () {
            $('#asterisk_delete_form_sip_id').val(id);
            $('#asterisk_delete_form_sip_count').val(count);
            $('#asterisk_delete_form_s').submit();
        });
        {/if}

    }

    function refresh_sip_status(sip_num) {
        $('*').css('cursor', 'progress');
        $('#sip_to_refresh').val(sip_num);
        $('#asterisk_refresh_sip_form').submit();
    }

    function deactivate_asterisk() {
        {if $cant_edit_telephony}
        alert_add_user();
        {else}
        jconfirm('{$lang.modules.asterisk.deactivate_phone_module}', function () {
            $('#deactivate_form').submit();
        });
        {/if}
    }

    function activate_asterisk() {
        {if !$full_version}
        jalert('{$lang.modules.asterisk.upgrade_telephony_version}');
        {else}
        jconfirm('{$lang.modules.asterisk.activate_telephony_module}', function () {
            $('#activate_form').submit();
        });
        {/if}
    }

    function update_audio_record() {
        location.href = "modules/asterisk/asterisk_functions.php?sel=save&type=record&main=" + asterisk_number;
    }

    function check_sips() {
        var check = true;
        $('.sip_fields').parents('tr').css('background-color', '#fff');
        $('.sip_fields').each(function (indx, elem) {
            if (!elem.value) {
                $(elem).parents('tr').css('background-color', 'var(--color-misty-rose)');
                check = false;
            }
        });
        if (!check) {
            $('#sip_wait').hide();
            $('#sip_alert').html('{$lang.modules.asterisk.fields_not_filled}');
        } else if (
                ($('[name=sip_user]').val() == $('[name=sip2_user]').val() && $('[name=sip_domain]').val() == ($('[name=sip2_domain]').val() ? $('[name=sip2_domain]').val() : 'vpbx.sipout.net')) ||
                ($('[name=sip_user]').val() == $('[name=sip3_user]').val() && $('[name=sip_domain]').val() == ($('[name=sip2_domain]').val() ? $('[name=sip2_domain]').val() : 'vpbx.sipout.net')) ||
                ($('[name=sip2_user]').val() && $('[name=sip2_user]').val() == $('[name=sip3_user]').val() && $('[name=sip2_domain]').val() == ($('[name=sip3_domain]').val() ? $('[name=sip3_domain]').val() : 'vpbx.sipout.net'))
            ) {
            $('#sip_wait').hide();
            $('#sip_alert').html('{$lang.modules.asterisk.double_sip}');
            check = false;
        }
        return check;
    }

    function switch_sip_type(type) {
        if (type == 1) {
            $('#sip_type1').prop('checked', true);
            $('.sip_form_extended').hide();
            $('.sip_form_extended input').removeClass('sip_fields');
            $('.sip_reg').show();
        } else if (type == 2) {
            $('.sip_form_extended').hide();
            $('.sip_form_extended input').removeClass('sip_fields');
            $('.sip_form_another').show();
            $('.sip_form_another input').addClass('sip_fields');
            $('.sip_form_another').css('background-color', '#fff');
            $('.sip_reg').hide();
        } else if (type == 3) {
            $('.sip_form_extended').show();
            $('.sip_form_extended input').addClass('sip_fields');
            $('.sip_replace').removeClass('sip_fields');
            $('.sip_form_extended').css('background-color', '#fff');
            $('.sip_reg').hide();
        } else {
            $('.sip_form_extended').fadeOut();
            $('.sip_form_extended input').removeClass('sip_fields');
        }
    }

    function switch_reg_type(type) {
        if (type == 'private') {
            $('.sip_reg_private').show();
            $('.sip_reg_org').hide();
        } else if (type == 'org') {
            $('.sip_reg_org').show();
            $('.sip_reg_private').hide();
        }
    }

    function display_add_settings() {
        if ($('.add_settings').css('display') == 'none') {
            $('.add_settings').fadeIn();
        } else {
            $('.add_settings').fadeOut();
        }
    }

    function alert_add_user() {
        jconfirm('{$lang.modules.asterisk.will_you_add_user}',
            function () {
                $('#users_block').show();
                $('#user_name').val({$user.id});
                generate_user_form();
            }
        );
    }

    function go_sipout_lk(login, password, phone) {
        $('#sipout_login').val(login);
        $('#sipout_password').val(password);
        $('#sipout_phone').val(phone);
        $('#sipout_lk').submit();
    }

    function all_dir_switch(checked) {
        if (checked) {
            jalert('{$lang.modules.asterisk.Enabling_the_all}');
        }
        $('#all_dir_users').toggle(checked);
    }

    function update_asterisk_settings() {
        let requestData = $('input[name=disable_notify_asterisk]').val();
        $.ajax({
            url: 'modules/asterisk/updateSettings.php',
            type: 'post',
            {literal}data: `disable_notify_asterisk=${requestData}&csrf=${csrf}`,{/literal}
            success: function (resp) {
            }
        });
    }

    function change_checkbox_value(e) {
        let checkBox = $(e.target);
        checkBox.prop('checked') ? checkBox.val('1') : checkBox.val('0');
    }

</script>
