{include file="./index_top.tpl"}
<style>
    td .form-control {
        box-sizing: border-box !important;
    }
    textarea.form-control {
        min-width:806px;
        max-width:806px;
    }
    select.form-control {
        width:808px;
    }
    input[type=file] {
        display:inline !important;
    }
</style>

<script type="text/javascript" src="themes/clientbase/js/print-template-script.js"></script>

<script type="text/javascript" src="mybic.js?{$revision}"></script>
<script language="JavaScript" type="text/javascript">
    // значения для системной подсказки
    var help_section = 'Settings';
    var help_sub_section = '{if $mode eq "sms"}SMS{elseif $mode eq "msg"}Messenger{elseif $mode eq "send"}Mailer{elseif $mode eq "print"}Templates{/if}';

    var ta;
    var rtf_type = {if $type_form==3}true{else}false{/if};
    var new_rec = {if $form_id==-1 or $form_id==-2}true{else}false{/if};
    var free_template = {if $form_id==-2}true{else}false{/if} ;
    function check_all(type, obj) {
        {if $parent}
            par = 1;
        {else}
            par = 0;
        {/if}

        if ($(obj).attr("o_value") == "2") {
            $(obj).attr("src", "images/check_on_m.png");
            $(obj).attr("o_value", "1");
            on_off = "on";
        }
        else if ($(obj).attr("o_value") == "1") {
            $(obj).attr("src", "images/check_off_m.png");
            $(obj).attr("o_value", "0");
            on_off = "off";
        }
        else if (par) {
            $(obj).attr("src", "images/check_dis_off_m.png");
            $(obj).attr("o_value", "2");
            on_off = "dis_on";
        }
        else {
            $(obj).attr("src", "images/check_on_m.png");
            $(obj).attr("o_value", "1");
            on_off = "on";
        }

        $('[id^="par_' + type + '_"]').each(function () {
            $(this).attr("src", "images/check_" + on_off + "_m.png");
            if ($(this).attr("o_value") == 3 && on_off == "dis_on")  $(this).attr("src", "images/check_dis_off_m.png");
        });
        $('[id^="check_' + type + '_"]').each(function () {
            if (on_off == 'on') {
                $(this).val('1');
            }
            else if (on_off == 'dis_on') {
                if ($(this).attr('o_value') == '2') $(this).val('2');
                if ($(this).attr('o_value') == '3') $(this).val('3');
            }
            else {
                $(this).val('0');
            }
            if ($(this).val() != $(this).attr('data-o_value')) {
                $(this).parent().css('backgroundColor', 'rgb(255, 255, 153)');
            }
            else {
                $(this).parent().css('backgroundColor', 'transparent');
            }
        });
    }
    function insert_var(ins_var) {
        ins_text = document.getElementById(ins_var).value;
        {literal}
        if (ins_text.substr(0, 8) == '{foreach') ins_text = ins_text + '\r\n{/foreach}\r\n';
        {/literal}
        if ((typeof CKEDITOR != "undefined") && (typeof CKEDITOR.instances.body_form != "undefined")) {
            if (CKEDITOR.instances.body_form.mode != 'source') {

                {literal}
                /** Регулярки нужны потому что переменные с { и }, не вставляются должным образом
                 *  Поэтому меняем их на спец символы*/
                CKEDITOR.instances.body_form.insertHtml(ins_text.replace(/\{+/g, '&#123;').replace(/\}+/g, '&#125;'));
                {/literal}
            } else {
                var ta_s = document.getElementsByTagName('textarea');
                ta = ta_s[3];
                if (document.selection) {
                    ta.focus();
                    document.selection.createRange().text = ins_text;
                } else {
                    ta.value = ta.value.substr(0, ta.selectionStart) + ins_text + ta.value.substr(ta.selectionEnd);
                }
            }
        } else { // old textarea
            if (document.selection) {
                ta.focus();
                document.selection.createRange().text = ins_text;
            } else {
                ta.value = ta.value.substr(0, ta.selectionStart) + ins_text + ta.value.substr(ta.selectionEnd);
            }
        }
    }

    function switch_type(type) {
        if (type == -1) {
            document.getElementById('type12').style.display = 'none';
            document.getElementById('type3').style.display = 'none';
            document.getElementById('type-1').style.display = '';
        } else if (type < 3) {
            document.getElementById('type12').style.display = '';
            document.getElementById('type3').style.display = 'none';
            document.getElementById('type-1').style.display = 'none';
        } else {
            document.getElementById('type12').style.display = 'none';
            document.getElementById('type3').style.display = '';
            document.getElementById('type-1').style.display = 'none';
        }
        if (type == 1 || type == 2) {
            location.href = "?table={$table_id}&mode={$mode}{if !$cur_cat}&admin{/if}&form={$form_id}&edit&cust_type_form=" + type + "{if $smarty.get.back_url}&back_url={$smarty.get.back_url}{/if}";
        } else if (type == 6 || type == 7) {
            document.getElementById('xls_vars').style.display = '';
        } else {
            document.getElementById('xls_vars').style.display = 'none';
        }
    }

    function check_ext(type, file_name) {
        type = parseInt(type);
        if (type === 2) {
            type = parseInt(document.getElementById("type_form").value);
        }
        switch (type) {
            case 3:
                ext = 'rtf';
                break
            case 4:
                ext = 'odt';
                break
            case 5:
                ext = 'docx';
                break
            case 6:
                ext = 'xls';
                break
            case 7:
                ext = 'xlsx';
                break
            default:
                ext = "";
                break
        }
        pos = file_name.lastIndexOf('.');
        str_ext = file_name.substr(pos + 1);
        if (ext === str_ext) {
            return true;
        }
        else {
            return false;
        }

    }


    function check_form(type) {
        var status_string  = new Array();
        status_string['3'] = "rtf";
        status_string['4'] = "odt";
        status_string['5'] = "docx";
        status_string['6'] = "xls";
        status_string['7'] = "xlsx";
        if (document.getElementById('name_form') && !document.getElementById('name_form').value.replace(/ /g, '')) {
            jalert('{$lang.alert_template_name}');
            return false;
        }
        if (document.getElementById('to_mail') && document.getElementById('to_mail').value == "0") {
            jalert('{$lang.alert_template_to_mail}');
            return false;
        }
        if (document.getElementById('to_phone') && document.getElementById('to_phone').value == "0") {
            jalert('{$lang.alert_template_to_phone}');
            return false;
        }
        if (document.getElementById('from_phone') && document.getElementById('from_phone').value == "") {
            jalert('{$lang.alert_template_from_phone}');
            return false;
        }
        if (type && document.getElementById('body_file')) {
            if (check_ext(type, document.getElementById('body_file').value) == false && document.getElementById('body_file').value.length) {
                jalert('{$lang.incorrect_type_file_mes} .' + status_string[type]);
                return false
            }
        }
        return true;
    }
    var ajaxObject = new XMLHTTP("forms.php?table={$table_id}&mode={$mode}&form={$form_id}&edit");
    var last_test_id = -1;

    function test_var(test_id) {
        if (last_test_id == -1) {
            var new_eval = encodeURIComponent(document.getElementById('var_' + test_id).value);
            ajaxObject.format = 0;
            ajaxObject.method = "POST";
            ajaxObject.failed_requests = 0;
            ajaxObject.net_down_func = NetworkDown;
            ajaxObject.call("var_test_id=" + test_id + "&new_eval=" + new_eval + "&csrf={$csrf}", ComResp);
            last_test_id = test_id;
            document.getElementById('refresh_' + test_id).src = "images/b_refresh_animate.gif";
        }
        ;
    }
    ;

    function NetworkDown(status) { // Ошибки игнорируем
        document.getElementById('refresh_' + last_test_id).src = "images/b_refresh.png";
        last_test_id = -1;
        return;
    }
    ;

    function ComResp(resp) {
        document.getElementById('refresh_res_' + last_test_id).innerHTML = "'" + resp + "'";
        document.getElementById('refresh_' + last_test_id).src = "images/b_refresh.png";
        last_test_id = -1;
    }

    function switch_sender(type) {
        if (type == 1) {
            document.getElementById('from_mail_tr1').style.display = '';
            document.getElementById('from_name_tr1').style.display = '';
            document.getElementById('from_mail_tr2').style.display = 'none';
            document.getElementById('from_name_tr2').style.display = 'none';
            document.getElementById('from_mail').value = '';
            document.getElementById('from_name').value = '';
        } else if (type == 2) {
            document.getElementById('from_mail_tr1').style.display = 'none';
            document.getElementById('from_name_tr1').style.display = 'none';
            document.getElementById('from_mail_tr2').style.display = 'none';
            document.getElementById('from_name_tr2').style.display = 'none';
            document.getElementById('from_mail').value = '*cur_user*';
            document.getElementById('from_name').value = '';
        } else if (type == 3) {
            document.getElementById('from_mail_tr1').style.display = 'none';
            document.getElementById('from_name_tr1').style.display = 'none';
            document.getElementById('from_mail_tr2').style.display = '';
            document.getElementById('from_name_tr2').style.display = '';
            document.getElementById('from_mail').value = document.getElementById('sel_from_mail').value;
            document.getElementById('from_name').value = document.getElementById('sel_from_name').value;
        }
    }

    function switch_color(color1, sub) {
        if (color1 == 'FFFF0000') {
            $('#sub_color_' + sub).css('background-color', '#FF0000');
        }
        else if (color1 == 'FFFFFF00') {
            $('#sub_color_' + sub).css('background-color', '#FFFF00');
        }
        else if (color1 == 'FF00FF00') {
            $('#sub_color_' + sub).css('background-color', '#00FF00');
        }
    }

    $(function () {
        $('.sub_color').each(function () {
            color = $(this).prev('#color_sub').val();
            color = '#' + color.substr(2);
            $(this).css({
                'width': '18px',
                'height': '18px',
                'float': 'right',
                'border': 'solid 1px black'
            }).css('background-color', color);
        });
        sel_signature();
    });

    function sel_signature() {
        if (document.getElementById('alt_signature_box')) {
            if (isNaN(document.getElementById('from_phone').value))
                document.getElementById('alt_signature_box').style.display = '';
            else
                document.getElementById('alt_signature_box').style.display = 'none';
        }
    }

    function sel_channel(channel) {
        var type = $('#channel option[value=' + channel + ']').attr('data-type');
        $('#phone_row').toggle(type == 'whatsapp' || type == 'telegram');
        $('#nickname_row').toggle(type == 'instagram' || type == 'telegram');
    }
</script>
<br>
<div align=center>
    {if $no_save_mode}<img src="images/lock.svg" style="width:20px; padding-right:5px;" title="{$lang.Element_no_edit_msg}">{/if}
    {if $form_id eq -1}{$lang.Create_template}{else}{$lang.Edit_template} "{$name_form}"{/if}{if !$cur_cat} {$lang.of_table} "{$name_table}"{/if}
    {if $form_id != -1 && !$blocked}
        <div style="left: 10px; top: 2px; float: none;"
            onclick="switchOnObject('{$form_id}')"
            class="switch-btn {if !$disabled}switch-on{/if}"
            id="switch-on-btn_{$form_id}"></div>
        <script>
            let ajaxObj = new XMLHTTP("forms.php");
            ajaxObj.format = 0;
            ajaxObj.method = "POST";
            function switchOnObject(form_id) {
                $('#switch-on-btn_'+form_id).toggleClass('switch-on');
                $('#switch-on-btn_'+form_id).trigger('on.switch');
                ajaxObj.call('table={$table_id}&form='+form_id+'&sel=disable&enbl='+($('#switch-on-btn_'+form_id).hasClass('switch-on')?1:0)+'&csrf={$csrf}',()=>{});
            }
        </script>
    {/if}
</div>
<br>
<form action="forms.php?table={$table_id}{if $filter_id}&filter={$filter_id}{/if}&mode={$mode}&edit{if !$cur_cat}&admin{/if}&form={$form_id}{if $ajax_edit}&ajax_edit{/if}"
      method="post" enctype="multipart/form-data" id="edit_form">

    {if $mode != 'print' || $form_id != -1}<input type="hidden" name="type_form" value="{if $mode=='print'||$mode=='send'}{$type_form}{else}1{/if}">{/if}
    <table align=center border=0 cellpadding=3 width=1000>
        {if $error}
            <tr>
                <td colspan=2 align=center>
                    <span id="edit_config__info-maessage" style="color:red">{$error}</span><br><br>
                </td>
            </tr>
        {/if}
        {if $message}
            <tr>
                <td colspan=2 align=center>
                    <span id="edit_config__info-maessage" style="color:green">{$message}</span><br><br>
                </td>
            </tr>
        {/if}
        {if $blocked}
            <tr>
                <td colspan=2 align=center>
                    <a href="forms.php?table={$table_id}&mode={$mode}&admin">{$lang.Return}</a>
                </td>
            </tr>
        {else}
        {if $form_id != -2}
            <tr>
                <td align=right width=25%>{$lang.Template_name}<span class='help_bt' h_id='Template_name'></span>:</td>
                <td><input class="form-control" type=text name=name_form id=name_form value="{$name_form|escape:'html'}" size=50></td>
            </tr>
          {if $mode == "print"}
            <tr>
              <td align=right>{$lang.Template_format}<span class='help_bt' h_id='Template_format'></span>:</td>

              <td>
                {if $form_id == -1}
                    <select class="form-control dont_use_chosen" name="type_form" id="type_form" onchange="switch_type(this.value)">
                        <option value=1 {if $type_form == 1}selected{/if}>{$lang.simple_text} / xml</option>
                        <option value=2 {if $type_form == 2}selected{/if}>html / pdf</option>
                        <option value=3 {if $type_form == 3}selected{/if}>rtf (WordPad)</option>
                        <option value=4 {if $type_form == 4}selected{/if}>odt (OpenOffice)</option>
                        <option value=5 {if $type_form == 5}selected{/if}>docx (Ms Word 2007)</option>
                        {if $user.group_id != 777}
                          <option value=6 {if $type_form == 6}selected{/if}>xls (Excel)</option>
                          <option value=7 {if $type_form == 7}selected{/if}>xlsx (Excel версии от 2007) - альфа</option>
                        {/if}
                        <option value=-1 {if $type_form == -1}selected{/if}>{$lang.combined}</option>
                    </select>
                {else}
                    {if $type_form == 1}{$lang.simple_text} / xml{/if}
                    {if $type_form == 2}html / pdf{/if}
                    {if $type_form == 3}rtf (WordPad){/if}
                    {if $type_form == 4}odt (OpenOffice){/if}
                    {if $type_form == 5}docx (MS Word 2007){/if}
                    {if $type_form == 6}xls (MS Excel){/if}
                    {if $type_form == 7}xlsx (MS Excel 2007){/if}
                    {if $type_form ==- 1}{$lang.combined}{/if}
                {/if}
              </td>
            </tr>
          {/if}
        {/if}
        {if $mode eq "print"}
            <tbody id="type12" {if $type_form != 1 && $type_form != 2}style="display:none"{/if}>
            {if $type_form == 1}
                <tr>
                    <td align=right>{$lang.Template_header_1}<span class='help_bt' h_id='Template_header'></span>:</td>
                    <td><textarea name="head_form" class="form-control" style="height:100px" onfocus="ta=this;">{$head_form}</textarea></td>
                </tr>
                <tr>
                    <td align=right>{$lang.Template_body}<span class='help_bt' h_id='Template_body'></span>:</td>
                    <td><textarea name="body_form" class="form-control" style="height:300px" onfocus="ta=this;">{$body_form}</textarea></td>
                </tr>
                <tr>
                    <td align=right>{$lang.Template_bottom_1}<span class='help_bt' h_id='Template_bottom'></span>:</td>
                    <td><textarea name="foot_form" class="form-control" style="height:100px" onfocus="ta=this;">{$foot_form}</textarea></td>
                </tr>
                <tr>
                    <td align=right>{$lang.insert_field}<span class='help_bt' h_id='insert_field'></span>:</td>
                    <td>
                        <select class="form-control" id="ins_field" style="width:500px">{$sel_field}</select>
                        <input type=button class="btn btn-default btn-sm" value="OK" onclick="insert_var('ins_field')">
                    </td>
                </tr>
                <tr>
                    <td align=right width=25%>{$lang.Save_in_file}<span class='help_bt' h_id='Document_name'></span>:</td>
                    <td>
                        <input type="checkbox" name="save_file" {if $doc_name}checked{/if} onclick="$('#doc_name').toggle(this.checked)">
                        <input class="form-control" type="text" name="doc_name" id="doc_name" value="{$doc_name|htmlspecialchars}" style="width:789px; {if !$doc_name}display:none{/if}">
                    </td>
                </tr>
            {elseif $type_form == 2}
                <tr>
                    <td align=right>{$lang.Template_header_2}<span class='help_bt' h_id='Template_header'></span>:</td>
                    <td><textarea name="head_form" class="form-control" style="height:100px" onfocus="ta=this;">{$head_form}</textarea></td>
                </tr>
                <tr>
                    <td align=right>{$lang.Template_body}<span class='help_bt' h_id='Template_body'></span>:</td>
                    <td>{$fck_editor}</td>
                </tr>
                <tr>
                    <td align=right>{$lang.insert_field}<span class='help_bt' h_id='insert_field'></span>:</td>
                    <td>
                        <select class="form-control" id="ins_field" style="width:500px">{$sel_field}</select>
                        <input type=button class="btn btn-default btn-sm" value="OK" onclick="insert_var('ins_field')">
                    </td>
                </tr>
                <tr>
                    <td align=right>{$lang.insert_image}<span class='help_bt' h_id='insert_image'></span>:</td>
                    <td>
                        {if $sel_image}
                            <select class="form-control" id="ins_image" style="width:500px">{$sel_image}</select>
                            <input type=button class="btn btn-default btn-sm" value="OK" onclick="insert_var('ins_image')">
                            <a href="" class="red_link"
                               onclick="return jconfirm('{$lang.Delete_file} '+document.getElementById(document.getElementById('ins_image').value).innerHTML+'?', function () { document.getElementById('del_image').value=document.getElementById(document.getElementById('ins_image').value).innerHTML; document.getElementById('edit_form').submit(); });">{$lang.delete}</a>
                            <br>
                        {/if}
                        <input type=hidden name=inl_images value='{$inl_images}'>
                        <input type=file name=inl_image id=inl_image onchange="$(this).next().show()">
                        <input type="submit" name=add_image value="{$lang.Upload}" style="display:none"
                               onClick="if (!check_form( $('#type_form').val() ) ) return false;">
                        <input type=hidden name=del_image id=del_image>
                    </td>
                </tr>
                <tr>
                    <td align=right>{$lang.Template_bottom_2}<span class='help_bt' h_id='Template_bottom'></span>:</td>
                    <td><textarea name="foot_form" class="form-control" style="height:100px" onfocus="ta=this;">{$foot_form}</textarea></td>
                </tr>
                <tr>
                    <td align=right valign=top style="padding-top:12px">{$lang.pagebreak}<span class='help_bt'
                                                                                               h_id='pagebreak'></span>:
                    </td>
                    <td><input type=checkbox name=pagebreak value=1
                               {if $pagebreak}checked{/if} {if $user.group_id!=1}disabled{/if}>
                    </td>
                </tr>
                <tr>
                    <td align=right valign=top style="padding-top:12px">{$lang.export_to_pdf}<span class='help_bt' h_id='export_to_pdf'></span>:
                    </td>
                    <td align=left valign=top>
                        <table>
                            <tr>
                                <td><input type=checkbox name=pdf_import value=1
                                           {if $pdf_import}checked{/if} {if $user.group_id!=1}disabled{/if}
                                           style="margin-left: -3px;{if $pdf_import}vertical-align: top;{/if}"
                                           {literal}onclick="if (this.checked) {$('.pdf_settings').css('display',''); $(this).css('vertical-align','top');} else {$('.pdf_settings').css('display','none');$(this).css('vertical-align','middle');}"{/literal}>
                                </td>
                                <td style="height:28px">
                                    <table class="pdf_settings" {if !$pdf_import}style="display:none"{/if}>
                                        <tr>
                                            <td align="right" style="width:155px">{$lang.Orientation}:</td>
                                            <td><select class="form-control" style="width:200px" name=orientation>
                                                    <option value="">{$lang.portrait}</option>
                                                    <option value="-L"
                                                            {if $orientation=="-L"}selected{/if}>{$lang.landscape}</option>
                                                </select></td>
                                            <td style="padding-left:30px">{$lang.Margins}:</td>
                                            <td style="padding-left:5px">{$lang.top}</td>
                                            <td><input type=text name=margin_top class="form-control"
                                                       value="{if $form_id>0}{$margin_top}{else}15{/if}"
                                                       style="width:40px;"></td>
                                            <td style="padding-left:7px">{$lang.bottom}</td>
                                            <td><input type=text name=margin_bottom class="form-control"
                                                       value="{if $form_id>0}{$margin_bottom}{else}15{/if}"
                                                       style="width:40px;"></td>
                                            <td style="padding-left:7px">{$lang.left}</td>
                                            <td><input type=text name=margin_left class="form-control"
                                                       value="{if $form_id>0}{$margin_left}{else}15{/if}"
                                                       style="width:40px;"></td>
                                            <td style="padding-left:7px">{$lang.right}</td>
                                            <td><input type=text name=margin_right class="form-control"
                                                       value="{if $form_id>0}{$margin_right}{else}15{/if}"
                                                       style="width:40px;"></td>
                                        </tr>
                                    </table>
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
                <tr class="pdf_settings" {if !$pdf_import}style="display:none"{/if}>
                    <td align="right" style="width:155px">{$lang.File_name}<span class='help_bt' h_id='Document_name'></span>:
                    </td>
                    <td><input type=text name=doc_name value="{$doc_name|htmlspecialchars}" size=50 class="form-control"></td>
                </tr>
                <tr class="pdf_settings" {if !$pdf_import}style="display:none"{/if}>
                    <td align="right" style="width:155px">{$lang.Page_header}<span class='help_bt' h_id='Page_header'></span>:
                    </td>
                    <td><textarea name="head_page" class="form-control" style="height:30px">{$head_page|htmlspecialchars}</textarea></td>
                </tr>
                <tr class="pdf_settings" {if !$pdf_import}style="display:none"{/if}>
                    <td align="right" style="width:155px">{$lang.Page_footer}<span class='help_bt' h_id='Page_footer'></span>:
                    </td>
                    <td><textarea name="foot_page" class="form-control" style="height:30px">{$foot_page|htmlspecialchars}</textarea></td>
                </tr>
            {/if}
            </tbody>
            <tbody id="type3" {if $type_form < 3}style="display:none"{/if}>
            {if $form_id > 0}
                {if $type_form > 2}
                    <tr>
                        <td align=right width=25%>{$lang.File_name}<span class='help_bt'
                                                                             h_id='Document_name'></span>:
                        </td>
                        <td><input class="form-control" type=text name=doc_name value="{$doc_name|htmlspecialchars}" size=50></td>
                    </tr>
                {/if}
                {if $type_form==3 || $type_form==6 || $type_form==7}
                    <tr>
                        <td></td>
                        <td><a class='href_post'
                               href="forms.php?table={$table_id}&form={$form_id}&open_file">{$lang.Download_file}</a>
                        </td>
                    </tr>
                {elseif $type_form == 4 or $type_form == 5}
                    <tr>
                        <td></td>
                        <td>{$lang.download_template_edit}</td>
                    </tr>
                    <tr>
                        <td></td>
                        <td><a class='href_post'
                               href="forms.php?table={$table_id}&form={$form_id}&template_doc_file">{$lang.Download_file}</a>
                        </td>
                    </tr>
                {/if}
                <tr>
                    <td></td>
                    <td colspan="3">{$lang.alert_reload_file}</td>
                </tr>
            {/if}
            <tr>
                <td align=right>{$lang.Upload_file}<span class='help_bt' h_id='Upload_file'></span>:</td>
                <td>
                    <input type=file name=body_file id=body_file onchange="$(this).next().show()">
                    <input type="submit" name=load_body value="{$lang.Upload}" style="display:none"
                           onClick="if (!check_form( $('#type_form').val() ) ) return false;">
                </td>
            </tr>

            {if $type_form eq 5}
                <tr>
                    <td><br></td>
                </tr>
                <tr>
                    <td align="right" valign="top">{$lang.template_vars}<span class='help_bt'
                                                                              h_id='template_vars'></span>:
                    </td>
                    <td>
                        <div class="form-control form-print-variable cb-scroll" style="height:300px; overflow-y: auto;   background-color: #eee;">
                        {foreach from=$form_fields item=one_field}
                            <div class="form-print-variable__block">
                                <span class="form-print-variable__value">{$one_field}</span>
                                <button class="form-print-variable__btn" title="Скопировать"  onclick="copyToClipboard(this, event)">
                                    <img class="form-print-variable__img" src="images/icon_copy.svg">
                                </button>
                            </div>
                        {/foreach}
                        </div>
                    </td>
                </tr>
            {/if}

            {if $type_form eq 6 || $type_form eq 7 || $form_id == -1}
                <tr id="xls_vars" {if $form_id == -1}style="display:none"{/if}>
                    <td align="right" valign="top">{$lang.template_vars}<span class='help_bt'
                                                                              h_id='template_vars'></span>:
                    </td>
                    <td>
                        <div class="form-control form-print-variable cb-scroll" style="height:300px; overflow-y: auto;   background-color: #eee;">
                        {foreach from=$form_fields_xls item=one_field}
                            <div class="form-print-variable__block">
                                <span class="form-print-variable__value">{ldelim}{$one_field}{rdelim}</span>
                                <button class="form-print-variable__btn" title="Скопировать"  onclick="copyToClipboard(this, event)">
                                    <img class="form-print-variable__img" src="images/icon_copy.svg">
                                </button>
                            </div>
                        {/foreach}
                        </div>
                    </td>
                </tr>
            {/if}

            {if $type_form eq 6}
                <tr>
                    <td align=right>{$lang.Orientation}<span class='help_bt' h_id='xls_page_orientation'></span>:</td>
                    <td>
                        <select class="form-control" name=orientation>
                            <option value="">{$lang.portrait}</option>
                            <option value="-L" {if $orientation=="-L"}selected{/if}>{$lang.landscape}</option>
                        </select>
                    </td>
                </tr>
                
                <tr>
                    <td align=right>{$lang.Page_size}<span class='help_bt' h_id='xls_page_type'></span>:</td>
                    <td>
                        <select class="form-control" name=page_size>
                            <option value=""></option>
                            <option value="1" {if $page_size=="1"}selected{/if}>{$lang.xls_page_type_Letter}</option>
                            <option value="2"
                                    {if $page_size=="2"}selected{/if}>{$lang.xls_page_type_Letter_small}</option>
                            <option value="3" {if $page_size=="3"}selected{/if}>{$lang.xls_page_type_Tabloid}</option>
                            <option value="4" {if $page_size=="4"}selected{/if}>{$lang.xls_page_type_Ledger}</option>
                            <option value="5" {if $page_size=="5"}selected{/if}>{$lang.xls_page_type_Legal}</option>
                            <option value="6" {if $page_size=="6"}selected{/if}>{$lang.xls_page_type_Statement}</option>
                            <option value="7" {if $page_size=="7"}selected{/if}>{$lang.xls_page_type_Executive}</option>
                            <option value="8" {if $page_size=="8"}selected{/if}>{$lang.xls_page_type_A3}</option>
                            <option value="9" {if $page_size=="9"}selected{/if}>{$lang.xls_page_type_A4}</option>
                            <option value="10"
                                    {if $page_size=="10"}selected{/if}>{$lang.xls_page_type_A4_small}</option>
                            <option value="11" {if $page_size=="11"}selected{/if}>{$lang.xls_page_type_A5}</option>
                            <option value="12" {if $page_size=="12"}selected{/if}>{$lang.xls_page_type_B4_JIS}</option>
                            <option value="13" {if $page_size=="13"}selected{/if}>{$lang.xls_page_type_B5_JIS}</option>
                            <option value="14" {if $page_size=="14"}selected{/if}>{$lang.xls_page_type_Folio}</option>
                            <option value="15" {if $page_size=="15"}selected{/if}>{$lang.xls_page_type_Quarto}</option>
                            <option value="16" {if $page_size=="16"}selected{/if}>{$lang.xls_page_type_10x14}</option>
                            <option value="17" {if $page_size=="17"}selected{/if}>{$lang.xls_page_type_11x17}</option>
                            <option value="18" {if $page_size=="18"}selected{/if}>{$lang.xls_page_type_Note}</option>
                            <option value="19"
                                    {if $page_size=="19"}selected{/if}>{$lang.xls_page_type_Envelope_9}</option>
                            <option value="20"
                                    {if $page_size=="20"}selected{/if}>{$lang.xls_page_type_Envelope_10}</option>
                            <option value="21"
                                    {if $page_size=="21"}selected{/if}>{$lang.xls_page_type_Envelope_11}</option>
                            <option value="22"
                                    {if $page_size=="22"}selected{/if}>{$lang.xls_page_type_Envelope_12}</option>
                            <option value="23"
                                    {if $page_size=="23"}selected{/if}>{$lang.xls_page_type_Envelope_14}</option>
                            <option value="24" {if $page_size=="24"}selected{/if}>{$lang.xls_page_type_C}</option>
                            <option value="25" {if $page_size=="25"}selected{/if}>{$lang.xls_page_type_D}</option>
                            <option value="26" {if $page_size=="26"}selected{/if}>{$lang.xls_page_type_E}</option>
                            <option value="27"
                                    {if $page_size=="27"}selected{/if}>{$lang.xls_page_type_Envelope_DL}</option>
                            <option value="28"
                                    {if $page_size=="28"}selected{/if}>{$lang.xls_page_type_Envelope_C5}</option>
                            <option value="29"
                                    {if $page_size=="29"}selected{/if}>{$lang.xls_page_type_Envelope_C3}</option>
                            <option value="30"
                                    {if $page_size=="30"}selected{/if}>{$lang.xls_page_type_Envelope_C4}</option>
                            <option value="31"
                                    {if $page_size=="31"}selected{/if}>{$lang.xls_page_type_Envelope_C6}</option>
                            <option value="32"
                                    {if $page_size=="32"}selected{/if}>{$lang.xls_page_type_Envelope_C6_C5}</option>
                            <option value="33" {if $page_size=="33"}selected{/if}>{$lang.xls_page_type_B4_ISO}</option>
                            <option value="34" {if $page_size=="34"}selected{/if}>{$lang.xls_page_type_B5_ISO}</option>
                            <option value="35" {if $page_size=="35"}selected{/if}>{$lang.xls_page_type_B6_ISO}</option>
                            <option value="36"
                                    {if $page_size=="36"}selected{/if}>{$lang.xls_page_type_Envelope_Italy}</option>
                            <option value="37"
                                    {if $page_size=="37"}selected{/if}>{$lang.xls_page_type_Envelope_Monarch}</option>
                            <option value="38"
                                    {if $page_size=="38"}selected{/if}>{$lang.xls_page_type_6_3_4_Envelope}</option>
                            <option value="39"
                                    {if $page_size=="39"}selected{/if}>{$lang.xls_page_type_US_Standard_Fanfold}</option>
                            <option value="40"
                                    {if $page_size=="40"}selected{/if}>{$lang.xls_page_type_German_Standard_Fanfold}</option>
                            <option value="41"
                                    {if $page_size=="41"}selected{/if}>{$lang.xls_page_type_German_Legal_Fanfold}</option>
                            <option value="42" {if $page_size=="42"}selected{/if}>{$lang.xls_page_type_B2_ISO}</option>
                            <option value="43"
                                    {if $page_size=="43"}selected{/if}>{$lang.xls_page_type_Japanese_Postcard}</option>
                            <option value="44" {if $page_size=="44"}selected{/if}>{$lang.xls_page_type_9x11}</option>
                            <option value="45" {if $page_size=="45"}selected{/if}>{$lang.xls_page_type_10x11}</option>
                            <option value="46" {if $page_size=="46"}selected{/if}>{$lang.xls_page_type_15x11}</option>
                            <option value="47"
                                    {if $page_size=="47"}selected{/if}>{$lang.xls_page_type_Envelope_Invite}</option>
                            <option value="50"
                                    {if $page_size=="50"}selected{/if}>{$lang.xls_page_type_Letter_Extra}</option>
                            <option value="51"
                                    {if $page_size=="51"}selected{/if}>{$lang.xls_page_type_Legal_Extra}</option>
                            <option value="52"
                                    {if $page_size=="52"}selected{/if}>{$lang.xls_page_type_Tabloid_Extra}</option>
                            <option value="53"
                                    {if $page_size=="53"}selected{/if}>{$lang.xls_page_type_A4_Extra}</option>
                            <option value="54"
                                    {if $page_size=="54"}selected{/if}>{$lang.xls_page_type_Letter_Transverse}</option>
                            <option value="55"
                                    {if $page_size=="55"}selected{/if}>{$lang.xls_page_type_A4_Transverse}</option>
                            <option value="56"
                                    {if $page_size=="56"}selected{/if}>{$lang.xls_page_type_Letter_Extra_Transverse}</option>
                            <option value="57"
                                    {if $page_size=="57"}selected{/if}>{$lang.xls_page_type_Super_A_A4}</option>
                            <option value="58"
                                    {if $page_size=="58"}selected{/if}>{$lang.xls_page_type_Super_B_A3}</option>
                            <option value="59"
                                    {if $page_size=="59"}selected{/if}>{$lang.xls_page_type_Letter_Plus}</option>
                            <option value="60" {if $page_size=="60"}selected{/if}>{$lang.xls_page_type_A4_Plus}</option>
                            <option value="61"
                                    {if $page_size=="61"}selected{/if}>{$lang.xls_page_type_A5_Transverse}</option>
                            <option value="62"
                                    {if $page_size=="62"}selected{/if}>{$lang.xls_page_type_B5_JIS_Transverse}</option>
                            <option value="63"
                                    {if $page_size=="63"}selected{/if}>{$lang.xls_page_type_A3_Extra}</option>
                            <option value="64"
                                    {if $page_size=="64"}selected{/if}>{$lang.xls_page_type_A5_Extra}</option>
                            <option value="65"
                                    {if $page_size=="65"}selected{/if}>{$lang.xls_page_type_B5_ISO_Extra}</option>
                            <option value="66" {if $page_size=="66"}selected{/if}>{$lang.xls_page_type_A2}</option>
                            <option value="67"
                                    {if $page_size=="67"}selected{/if}>{$lang.xls_page_type_A3_Transverse}</option>
                            <option value="68"
                                    {if $page_size=="68"}selected{/if}>{$lang.xls_page_type_A3_Extra_Transverse}</option>
                            <option value="69"
                                    {if $page_size=="69"}selected{/if}>{$lang.xls_page_type_Double_Japanese_Postcard}</option>
                            <option value="70" {if $page_size=="70"}selected{/if}>{$lang.xls_page_type_A6}</option>
                            <option value="75"
                                    {if $page_size=="75"}selected{/if}>{$lang.xls_page_type_Letter_Rotated}</option>
                            <option value="76"
                                    {if $page_size=="76"}selected{/if}>{$lang.xls_page_type_A3_Rotated}</option>
                            <option value="77"
                                    {if $page_size=="77"}selected{/if}>{$lang.xls_page_type_A4_Rotated}</option>
                            <option value="78"
                                    {if $page_size=="78"}selected{/if}>{$lang.xls_page_type_A5_Rotated}</option>
                            <option value="79"
                                    {if $page_size=="79"}selected{/if}>{$lang.xls_page_type_B4_JIS_Rotated}</option>
                            <option value="80"
                                    {if $page_size=="80"}selected{/if}>{$lang.xls_page_type_B5_JIS_Rotated}</option>
                            <option value="81"
                                    {if $page_size=="81"}selected{/if}>{$lang.xls_page_type_Japanese_Postcard_Rotated}</option>
                            <option value="82"
                                    {if $page_size=="82"}selected{/if}>{$lang.xls_page_type_Double_Japanese_Postcard_Rotated}</option>
                            <option value="83"
                                    {if $page_size=="83"}selected{/if}>{$lang.xls_page_type_A6_Rotated}</option>
                            <option value="88" {if $page_size=="88"}selected{/if}>{$lang.xls_page_type_B6_JIS}</option>
                            <option value="89"
                                    {if $page_size=="89"}selected{/if}>{$lang.xls_page_type_B6_JIS_Rotated}</option>
                            <option value="90" {if $page_size=="90"}selected{/if}>{$lang.xls_page_type_12x11}</option>
                        </select>
                    </td>
                </tr>

            {/if}

            {if $type_form eq 6 || $type_form eq 7}
                <tr>
                    <td align=right nowrap>{$lang.Line_breaks}<span class='help_bt' h_id='xls_page_break'></span>:</td>
                    <td>
                        <input type="checkbox" name=page_break {if $page_break=="1"}checked{/if}/>
                    </td>
                </tr>      
                <tr>
                    <td><br></td>
                </tr>                      
            {/if}

            {if $form_id > 0}
                {if $type_form!=6 and $type_form!=7 and $user.group_id==1}
                <tr>
                    <td align="right">
                        {$lang.template_clac_vars}<span class='help_bt' h_id='template_clac_vars'></span>:
                    </td>
                    <td>
                        {if $form_vars}
                            <table>
                                <tr>
                                    <td></td>
                                    <td>{$lang.Name}</td>
                                    <td>{$lang.Computation}</td>
                                    <td></td>
                                    <td>{$lang.Result}</td>
                                </tr>
                                {foreach from=$form_vars item=one_var}
                                    <tr>
                                        <td><a class='href_post'
                                               href="forms.php?table={$table_id}{if $filter_id}&filter={$filter_id}{/if}&mode={$mode}{if !$cur_cat}&admin{/if}&form={$form_id}&del_var={$one_var.id}{$back_url_prm}"
                                               {if $one_var.name}onclick="return href_post=jconfirm('{$lang.alert_delete_form_var}', this);"{/if}
                                               title="{$lang.delete}"><img src="images/b_drop.png"></a></td>
                                        <td><input class="form-control" type="text" name="var_name[{$one_var.id}]" value="{$one_var.name}">
                                        </td>
                                        <td><textarea name="var_eval[{$one_var.id}]"
                                                      id="var_{$one_var.id}">{$one_var.eval}</textarea></td>
                                        <td><a href="" onclick="test_var({$one_var.id});return false;"
                                               title="{$lang.refresh_from_eval}{$back_url_prm}"><img
                                                        src="images/b_refresh.png" id="refresh_{$one_var.id}"></a></td>
                                        <td id="refresh_res_{$one_var.id}" align="center">'{$one_var.eval_res}'</td>
                                    </tr>
                                {/foreach}
                            </table>
                        {/if}
                        <a class='href_post'
                           href="forms.php?table={$table_id}{if $filter_id}&filter={$filter_id}{/if}&mode={$mode}{if !$cur_cat}&admin{/if}&form={$form_id}&add_var=1{$back_url_prm}">{$lang.Add_var}</a>
                    </td>
                {/if}
                </tr>
            {/if}
            </tbody>

            <tbody id="type-1" {if $type_form!=-1}style="display:none"{/if}>
            {if $type_form == -1}
            <tr>
                <td align=right width=25%>{$lang.File_name}<span class='help_bt'
                                                                     h_id='Document_name'></span>:
                 </td>
                <td><input class="form-control" type=text name=doc_name value="{$doc_name|htmlspecialchars}" size=50></td>
            </tr>
            <tr>
            {/if}
                <td align="right" valign="top">{$lang.Select_templates}<span class='help_bt'
                                                                             h_id='select_templates_for_combo'></span>:
                </td>
                <td>
                    {if $comb_forms}
                        <table class='sortableTable'>
                            {foreach from=$comb_forms item=one_form}
                                <tr>
                                    <td><span class="draggableImg">&nbsp;</span></td>
                                    <td align="right">{$one_form.name_form}:</td>
                                    <td><input class="form-control" type=text name=comb_forms[{$one_form.id}] value='{$one_form.count}'
                                               style="text-align:right; width:30px"> {$lang.pcs}</td>
                                </tr>
                            {/foreach}
                        </table>
                    {else}
                        <span style="color:gray"><i>{$lang.No_pdf_templates}</i></span>
                    {/if}
                </td>
            </tr>
            </tbody>

            <tr>
                <td></td>
                <td>
                    {if $admin_mode && ($user.group_id == 1 || $user.sub_admin_rights.set_rights.tables[$table_id] == 2)}<a href="" id="config_access_rules" style="width: 110px;display: inline-block">{$lang.Access_rules}</a>{/if}
                    {if $config.protect_of_elements && $user.id == 1}<a href="" id="protect_switch" style="width: 60px;display: inline-block">{$lang.Protect}</a>{/if}
                    {if $form_id > 0}<a href="edit_log.php?st_date=00&f_text=forms.php?table%3D{$table_id}%26form%3D{$form_id}%26mode%3D{$mode}%26admin%26edit>" target="_blank" style="padding-left:10px">{$lang.Log}</a>{/if}
                </td>
            </tr>
        {elseif $mode eq "send"}
            <tbody id="type12">
            <tr>
                <td align=right>{$lang.Mail_subject}<span class='help_bt' h_id='Mail_subject'></span>:</td>
                <td><input class="form-control" type=text name=subj_mail value='{$subj_mail}' size=100 onfocus="ta=this;"></td>
            </tr>
            <tr>
                <td align=right>{$lang.Mail_body}<span class='help_bt' h_id='Mail_body'></span>:</td>
                <td>{$fck_editor}</td>
            </tr>
            {if $form_id != -2}
                <tr>
                    <td align=right>{$lang.insert_field}<span class='help_bt' h_id='insert_field'></span>:</td>
                    <td>
                        <select class="form-control" id="ins_field" style="width:500px">{$sel_field}</select>
                        <input type=button class="btn btn-default btn-sm" value="OK" onclick="insert_var('ins_field')">
                    </td>
                </tr>
            {/if}
            {if $type_form==2 and $form_id != -2}
                <tr>
                    <td align=right>{$lang.insert_image}<span class='help_bt' h_id='insert_image'></span>:</td>
                    <td>
                        {if $sel_image}
                            <select class="form-control" id="ins_image" style="width:500px">{$sel_image}</select>
                            <input type=button class="btn btn-default btn-sm" value="OK" onclick="insert_var('ins_image')">
                            <a href="" class="red_link"
                               onclick="return jconfirm('{$lang.Delete_file} '+document.getElementById(document.getElementById('ins_image').value).innerHTML+'?', function () { document.getElementById('del_image').value=document.getElementById(document.getElementById('ins_image').value).innerHTML; document.getElementById('edit_form').submit(); });">{$lang.delete}</a>
                            <br>
                        {/if}
                        <input type=hidden name=inl_images value='{$inl_images}'>
                        <input type=file name=inl_image id=inl_image onchange="$(this).next().show()">
                        <input type="submit" name=add_image value="{$lang.Upload}" style="display:none"
                               onClick="if (!check_form( $('#type_form').val() ) ) return false;">
                        <input type=hidden name=del_image id=del_image>
                    </td>
                </tr>
            {/if}
            <tr>
                <td></td>
            </tr>
            <tr>
                <td align=right>{$lang.dst_address}<span class='help_bt' h_id='dst_address'></span>:</td>
                <td><select class="form-control" name=to_mail id=to_mail
                            onclick="if (this.value==document.getElementById('log_mail').value && this.value!=0) { jalert('{$lang.alert_dst_field}'); this.value=0; }">{$to_mail}</select>
                </td>
            </tr>
            <tr>
                <td align=right>{$lang.Sender}<span class='help_bt' h_id='Sender'></span>:</td>
                <td>
                    <table>
                        <tr>
                            <td><input type=radio name="sender" onclick="switch_sender(1)"
                                       {if $from_mail != "*cur_user*" && !$from_mail|is_numeric}checked{/if}></td>
                            <td>{$lang.fixed}</td>
                        </tr>
                        <tr>
                            <td><input type=radio name="sender" onclick="switch_sender(2)"
                                       {if $from_mail == "*cur_user*"}checked{/if}></td>
                            <td>{$lang.current_user}</td>
                        </tr>
                        <tr>
                            <td><input type=radio name="sender" onclick="switch_sender(3)"
                                       {if $from_mail|is_numeric}checked{/if}></td>
                            <td>{$lang.from_field}</td>
                        </tr>
                    </table>
                </td>
            </tr>
            <tr id="from_mail_tr1" {if $from_mail == "*cur_user*" || $from_mail|is_numeric}style="display:none"{/if}>
                <td align=right>{$lang.mail_from}<span class='help_bt' h_id='mail_from'></span>:</td>
                <td><input class="form-control" type=text name="from_mail" id="from_mail" value="{$from_mail}"></td>
            </tr>
            <tr id="from_name_tr1" {if $from_mail == "*cur_user*" || $from_mail|is_numeric}style="display:none"{/if}>
                <td align=right>{$lang.my_name_in_mail}<span class='help_bt' h_id='my_name_in_mail'></span>:</td>
                <td><input class="form-control" type=text name="from_name" id="from_name" value="{$from_name|htmlspecialchars}"></td>
            </tr>
            <tr id="from_mail_tr2" {if $from_mail == "*cur_user*" || !$from_mail|is_numeric}style="display:none"{/if}>
                <td align=right>{$lang.mail_from}<span class='help_bt' h_id='mail_from'></span>:</td>
                <td><select class="form-control" onchange="$('#from_mail').val(this.value)" id="sel_from_mail">{$sel_from_mail}</select></td>
            </tr>
            <tr id="from_name_tr2" {if $from_mail == "*cur_user*" || !$from_mail|is_numeric}style="display:none"{/if}>
                <td align=right>{$lang.my_name_in_mail}<span class='help_bt' h_id='my_name_in_mail'></span>:</td>
                <td><select class="form-control" onchange="$('#from_name').val(this.value)" id="sel_from_name">{$sel_from_name}</select></td>
            </tr>
            {if $config.mail_list_id}
                <tr>
                    <td align=right nowrap>{$lang.List_id_field}<span class='help_bt' h_id='list_id_field'></span>:</td>
                    <td>
                        <select class="form-control" name="listid_field">{$listid_select}></select>
                    </td>
                </tr>
            {/if}
            {if $form_id != -2}
            <tr>
                <td></td>
                <td>
                    <a href="#" id="open_add_set" style="width: 110px;display: inline-block">{$lang.Additional}</a>
                    {if $admin_mode && ($user.group_id == 1 || $user.sub_admin_rights.set_rights.tables[$table_id] == 2)}<a href="" id="config_access_rules" style="width: 110px;display: inline-block">{$lang.Access_rules}</a>{/if}
                    {if $config.protect_of_elements && $user.id == 1}<a href="" id="protect_switch" style="width: 60px;display: inline-block">{$lang.Protect}</a>{/if}
                    {if $form_id > 0}<a href="edit_log.php?st_date=00&f_text=forms.php?table%3D{$table_id}%26form%3D{$form_id}%26mode%3D{$mode}%26admin%26edit>" target="_blank" style="padding-left:10px">{$lang.Log}</a>{/if}
                </td>
            </tr>
            </tbody>
            <tbody id="additional_settings" style="display: none;">
                <tr>
                    <td align=right>{$lang.Attachments}<span class='help_bt' h_id='Attachments'></span>:</td>
                    <td>
                        <input type=hidden name=att_files value='{$att_files}'>
                        {foreach from=$arr_files item=file}
                            <a href="open_file.php?table={$table_id}&form={$form_id}&file={$file.url}">{$file.name}</a>
                            <a href="" class="red_link"
                               onclick="return jconfirm('{$lang.Delete_file} {$file.name}?', function () { document.getElementById('del_file').value='{$file.name}'; document.getElementById('edit_form').submit(); });">{$lang.delete}</a>
                            <br>
                        {/foreach}
                        <input type=file name=att_file id=att_file onchange="$(this).next().show()">
                        <input type="submit" name=add_file value="{$lang.Add}" style="display:none"
                               onClick="if (!check_form( $('#type_form').val() ) ) return false;">
                        <input type=hidden name=del_file id=del_file>
                    </td>
                </tr>
                {if $arr_fields}
                <tr>
                    <td align=right>{$lang.from_field}<span class='help_bt' h_id='from_field'></span>:</td>
                    <td>
                        {foreach from=$arr_fields item=field}
                            <input type=checkbox name="att_fields[]" value="{$field.id}"
                                   {if $field.checked}checked{/if}>
                            {$field.name}
                        {/foreach}
                    </td>
                </tr>
                {/if}
                {if $sel_form}
                <tr>
                    <td align=right>{$lang.Nested_templates}<span class='help_bt' h_id='Nested_templates'></span>:</td>
                    <td>
                        <input type=hidden name=att_forms value='{$att_forms}'>
                        {foreach from=$arr_forms item=form}
                            <a class='href_post'
                               href="forms.php?table={$table_id}{if $filter_id}&filter={$filter_id}{/if}&mode=print{if !$cur_cat}&admin{/if}&form={$form.id}&edit{$back_url_prm}">{$form.name_form}</a>
                            <a href="" class="red_link"
                               onclick="return jconfirm('{$lang.Delete_template} {$form.name_form}?', function () { document.getElementById('del_form').value='{$form.id}'; document.getElementById('edit_form').submit(); });">{$lang.delete}</a>
                            <br>
                        {/foreach}
                        <select class="form-control" name=att_form style="width:500px">{$sel_form}></select>
                        <input type="submit" name=add_form value="{$lang.Add}" class="btn btn-default btn-sm"
                               {literal}onClick="if (!document.getElementById('att_form').value) {jalert('{$lang.select_file}');return false;}"{/literal}>
                        <input type=hidden name=del_form id=del_form>
                    </td>
                </tr>
                {/if}
                <tr>
                    <td align=right>{$lang.mailer_log}<span class='help_bt' h_id='mailer_log'></span>:</td>
                    <td><select class="form-control" name=log_mail
                                onclick="if (this.value==document.getElementById('to_mail').value && this.value!=0) { jalert('{$lang.alert_log_field}'); this.value=0; }"
                                id=log_mail>{$log_mail}></select></td>
                </tr>
                <tr>
                    <td align=right>{$lang.logs_sub}<span class='help_bt' h_id='sub_log'></span>:</td>
                    <td>
                        <input type=checkbox name="logs_sub" value="1" {if $log_sub or $form_id == -1}checked{/if}>
                    </td>
                </tr>
                <tr>
                    <td align=right>{$lang.send_start_timestamp}<span class='help_bt'
                                                                      h_id='send_start_timestamp'></span>:
                    </td>
                    <td>
                        <select class="form-control" name="scheduled">
                            <option value="0">{$lang.start_now}</option>
                            <option value="1" {if $scheduled eq "1"} selected {/if}>{$lang.delayed}</option>
                        </select>
                    </td>
                </tr>
                {if $user.sub_admin!=1}
                    <tr>
                        <td align=right><span class="help_long">{$lang.send_by_cron_using_filter}<span class='help_bt'
                                                                               h_id='send_by_cron_using_filter'></span>:</span>
                        </td>
                        <td>
                            <select class="form-control" name=period_use_filter
                                    onchange="if (this.options[this.selectedIndex].value>0) document.getElementById('edit_cron_job_span').style.display='inline'; else document.getElementById('edit_cron_job_span').style.display='none';">
                                <option value="-1">{$lang.dont_send_mails}</option>
                                {$conf_filter_select}
                            </select>
        <span {if $cron_filter_id <= 0}style="display:none;"{/if} id="edit_cron_job_span"><a href=""
                                                                                             onClick="document.getElementById('edit_cron_mode').value = 1; if (check_form()) document.getElementById('edit_form').submit(); return false;">{$lang.Edit_cron_job}</a><span>
                        </td>
                    </tr>
                {/if}
                <tr>
                    <td align=right>{$lang.use_unsubscribe_option}<span class='help_bt'
                                                                        h_id='use_unsubscribe_option'></span>:
                    </td>
                    <td>

                        {if $config.type eq "LOCAL" and not $full_version}
                            {$lang.activate_for_unsubscribe}
                        {else}
                            <select class="form-control" name="unsubscribe">
                                <option value="1">{$lang.Yes}</option>
                                <option value="0" {if $unsubscribe eq "0"} selected {/if}>{$lang.No}</option>
                            </select>
                        {/if}

                    </td>
                </tr>
                <tr>
                    <td align=right><span class="help_long">{$lang.Mail_no_duplic}<span class='help_bt' h_id='Mail_no_duplic'></span>:</span></td>
                    <td>
                        <input name="mail_no_duplic" type="checkbox" value="on"
                               {if $mail_no_duplic}checked="checked"{/if} />
                    </td>
                </tr>
                <tr>
                    <td align=right>{$lang.encoding_letters}<span class='help_bt' h_id='encoding_letters'></span>:</td>
                    <td>
                        <select class="form-control" name="encoding_letters">
                            <option value="">{$lang.Default}</option>
                            {foreach from=$charsets item=one_charset_name key=one_charset_value}
                                <option value="{$one_charset_value}"{if $encoding_letters eq $one_charset_value} selected="selected"{/if}>{$one_charset_name}</option>
                            {/foreach}
                        </select>
                    </td>
                </tr>
            {/if}
            </tbody>
            <tbody id="type3"></tbody>
            <tbody id="type-1"></tbody>
        {elseif $mode eq "sms"}
            <tbody id="type12">
            <tr>
                <td align=right>{$lang.Message_body}<span class='help_bt' h_id='Message_body'></span>:</td>
                <td><textarea name="body_form" class="form-control" style="height:300px" onfocus="ta=this;">{$body_form}</textarea></td>
            </tr>
            {if $form_id!=-2}
                <tr>
                    <td align=right>{$lang.insert_field}<span class='help_bt' h_id='insert_field'></span>:</td>
                    <td>
                        <select class="form-control" id="ins_field" style="width:500px">{$sel_field}</select>
                        <input type=button class="btn btn-default btn-sm" value="OK" onclick="insert_var('ins_field')">
                    </td>
                </tr>
            {/if}
            <tr>
                <td></td>
            </tr>
            <tr>
                <td align=right>{$lang.dst_phone}<span class='help_bt' h_id='dst_phone'></span>:</td>
                <td><select class="form-control" name=to_mail id=to_phone>{$to_mail}</select></td>
            </tr>
            <tr>
                <td align=right>{$lang.phone_from}<span class='help_bt' h_id='phone_from'></span>:</td>
                <td>
                    {if $sel_signature}
                        <select class="form-control" name=from_mail id=from_phone onchange="sel_signature()">{$sel_signature}</select>
                        &nbsp;
                        <a href="edit_modules.php?module=sms&id=2" target="_blanc">{$lang.modules.sms.add_sign}</a>
                    {else}
                        <input class="form-control" type=text name=from_mail id=from_phone value='{$from_mail}' size=30>
                    {/if}
                </td>
            </tr>
            {* if $sel_alt_signature}
            <tr id="alt_signature_box">
              <td align=right>{$lang.alt_signature}<span class='help_bt' h_id='alt_signature'></span>:</td>
              <td>
                <select name=alt_signature>{$sel_alt_signature}</select> &nbsp; <a href="edit_modules.php?module=sms&id=1" target="_blanc">{$lang.modules.sms.add_sign}</a>
              </td>
            </tr>
            {/if *}
            <tr>
                <td align=right>{$lang.mailer_log}<span class='help_bt' h_id='mailer_log'></span>:</td>
                <td><select class="form-control" name=log_mail
                            onclick="if (this.value==document.getElementById('to_phone').value) { jalert('{$lang.alert_log_field}'); this.value=0; }">{$log_mail}
                        ></select></td>
            </tr>
            <tr>
                <td align=right>{$lang.logs_sub}<span class='help_bt' h_id='sub_log'></span>:</td>
                <td>
                    <input type=checkbox name="logs_sub" value="1" {if $log_sub or $form_id == -1}checked{/if}>
                </td>
            </tr>
            {if $form_id != -2}
                <tr>
                    <td align=right>{$lang.send_start_timestamp}<span class='help_bt'
                                                                      h_id='send_start_timestamp'></span>:
                    </td>
                    <td>
                        <select name="scheduled">
                            <option value="0">{$lang.start_now}</option>
                            <option value="1" {if $scheduled eq "1"} selected {/if}>{$lang.delayed}</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td align=right><span class="help_long">{$lang.send_by_cron_using_filter}<span class='help_bt'
                                                                           h_id='send_by_cron_using_filter'></span>:</span>
                    </td>
                    <td>
                        <select class="form-control" name=period_use_filter
                                onchange="if (this.options[this.selectedIndex].value>0) document.getElementById('edit_cron_job_span').style.display='inline'; else document.getElementById('edit_cron_job_span').style.display='none';">
                            <option value="-1">{$lang.dont_send_mails}</option>
                            {$conf_filter_select}
                        </select>
        <span {if $cron_filter_id <= 0}style="display:none;"{/if} id="edit_cron_job_span"><a href=""
                                                                                             onClick="document.getElementById('edit_cron_mode').value = 1; if (check_form()) document.getElementById('edit_form').submit(); return false;">{$lang.Edit_cron_job}</a><span>
                    </td>
                </tr>
            {/if}
            </tbody>
            <tbody id="type3"></tbody>
            <tbody id="type-1"></tbody>
        {elseif $mode eq "msg"}
            <tbody id="type12">
            <tr>
                <td align=right>{$lang.Message_body}<span class='help_bt' h_id='Message_body'></span>:</td>
                <td><textarea name="body_form" class="form-control" style="height:300px" onfocus="ta=this;">{$body_form}</textarea></td>
            </tr>
                <tr>
                    <td align=right>{$lang.insert_field}<span class='help_bt' h_id='insert_field'></span>:</td>
                    <td>
                        <select class="form-control" id="ins_field" style="width:500px">{$sel_field}</select>
                        <input type=button class="btn btn-default btn-sm" value="OK" onclick="insert_var('ins_field')">
                    </td>
                </tr>
            <tr>
                <td></td>
            </tr>
            <tr>
                <td align=right>{$lang.Channel}<span class='help_bt' h_id='mess_channel'></span>:</td>
                <td><select class="form-control" name="channel" id="channel" onchange="sel_channel(this.value)">{$sel_channel}</select></td>
            </tr>
            <tr id="phone_row" {if $chat_type == 'instagram'}style="display:none"{/if}>
                <td align=right>{$lang.Phone}<span class='help_bt' h_id='mess_phone'></span>:</td>
                <td><select class="form-control" name="to_mail">{$to_mail}</select></td>
            </tr>
            <tr id="nickname_row" {if $chat_type == 'whatsapp'}style="display:none"{/if}>
                <td align=right>{$lang.Nickname}<span class='help_bt' h_id='mess_nickname'></span>:</td>
                <td><select class="form-control" name="nickname">{$nickname}</select></td>
            </tr>
            <tr>
                <td></td>
                <td>
                    <a href="#" id="open_add_set" style="width: 110px;display: inline-block">{$lang.Additional}</a>
                    {if $admin_mode && ($user.group_id == 1 || $user.sub_admin_rights.set_rights.tables[$table_id] == 2)}<a href="" id="config_access_rules" style="width: 110px;display: inline-block">{$lang.Access_rules}</a>{/if}
                    {if $config.protect_of_elements && $user.id == 1}<a href="" id="protect_switch" style="width: 60px;display: inline-block">{$lang.Protect}</a>{/if}
                    {if $form_id > 0}<a href="edit_log.php?st_date=00&f_text=forms.php?table%3D{$table_id}%26form%3D{$form_id}%26mode%3D{$mode}%26admin%26edit>" target="_blank" style="padding-left:10px">{$lang.Log}</a>{/if}
                </td>
            </tr>
            </tbody>
            <tbody id="additional_settings" style="display: none;">
            <tr>
                <td align=right>{$lang.Attachments}<span class='help_bt' h_id='Attachments'></span>:</td>
                <td>
                    <input type=hidden name=att_files value='{$att_files}'>
                    {foreach from=$arr_files item=file}
                        <a href="open_file.php?table={$table_id}&form={$form_id}&file={$file.url}">{$file.name}</a>
                        <a href="" class="red_link"
                           onclick="return jconfirm('{$lang.Delete_file} {$file.name}?', function () { document.getElementById('del_file').value='{$file.name}'; document.getElementById('edit_form').submit(); });">{$lang.delete}</a>
                        <br>
                    {/foreach}
                    <input type=file name=att_file id=att_file onchange="$(this).next().show()">
                    <input type="submit" name=add_file value="{$lang.Add}" style="display:none"
                           onClick="if (!check_form( $('#type_form').val() ) ) return false;">
                    <input type=hidden name=del_file id=del_file>
                </td>
            </tr>
            {if $arr_fields}
            <tr>
                <td align=right>{$lang.from_field}<span class='help_bt' h_id='from_field'></span>:</td>
                <td>
                    {foreach from=$arr_fields item=field}
                        <input type=checkbox name="att_fields[]" value="{$field.id}"
                               {if $field.checked}checked{/if}>
                        {$field.name}
                    {/foreach}
                </td>
            </tr>
            {/if}
            <tr>
                <td align=right>{$lang.Nested_templates}<span class='help_bt' h_id='Nested_templates'></span>:</td>
                <td>
                    <input type=hidden name=att_forms value='{$att_forms}'>
                    {foreach from=$arr_forms item=form}
                        <a class='href_post'
                           href="forms.php?table={$table_id}{if $filter_id}&filter={$filter_id}{/if}&mode=print{if !$cur_cat}&admin{/if}&form={$form.id}&edit{$back_url_prm}">{$form.name_form}</a>
                        <a href="" class="red_link"
                           onclick="return jconfirm('{$lang.Delete_template} {$form.name_form}?', function () { document.getElementById('del_form').value='{$form.id}'; document.getElementById('edit_form').submit(); });">{$lang.delete}</a>
                        <br>
                    {/foreach}
                    <select class="form-control" name=att_form style="width:500px">{$sel_form}></select>
                    <input type="submit" name=add_form value="{$lang.Add}" class="btn btn-default btn-sm"
                           {literal}onClick="if (!document.getElementById('att_form').value) {jalert('{$lang.select_file}');return false;}"{/literal}>
                    <input type=hidden name=del_form id=del_form>
                </td>
            </tr>
            <tr>
                <td align=right>{$lang.mailer_log}<span class='help_bt' h_id='mailer_log'></span>:</td>
                <td>
                    <select class="form-control" name=log_mail
                            onclick="if (this.value==document.getElementById('to_mail').value && this.value!=0) { jalert('{$lang.alert_log_field}'); this.value=0; }"
                            id=log_mail>{$log_mail}</select>
                </td>
            </tr>
            <tr>
                <td align=right>{$lang.logs_sub}<span class='help_bt' h_id='sub_log'></span>:</td>
                <td>
                    <input type=checkbox name="logs_sub" value="1" {if $log_sub or $form_id == -1}checked{/if}>
                </td>
            </tr>
            <tr>
                <td align=right style="vertical-align:top; padding-top:9px;"><span class="help_long">{$lang.send_by_cron_using_filter}<span class='help_bt'
                                                                       h_id='send_by_cron_using_filter'></span>:</span>
                </td>
                <td>
                    <select class="form-control dont_use_chosen" name="period_use_filter" onchange="$('#edit_cron_job_span').toggle(this.value>0)">
                        <option value="-1">{$lang.dont_send_mails}</option>
                        {$conf_filter_select}
                    </select>
                    <span {if $cron_filter_id <= 0}style="display:none"{/if} id="edit_cron_job_span">
                        <a href="" onClick="document.getElementById('edit_cron_mode').value = 1; if (check_form()) document.getElementById('edit_form').submit(); return false;">
                            {$lang.Edit_cron_job}
                        </a>
                    </span>
                </td>
            </tr>
            </tbody>
            <tbody id="type3"></tbody>
            <tbody id="type-1"></tbody>
        {/if}
        {if $admin_mode && ($user.group_id == 1 || $user.sub_admin_rights.set_rights.tables[$table_id] == 2)}
            {if $mode=="sms"}
                <tr>
                <td align="right"></td>
                <td>
                    <a href="" id="config_access_rules" style="width: 110px;display: inline-block">{$lang.Access_rules}</a>
                    {if $config.protect_of_elements && $user.id == 1}<a href="" id="protect_switch" style="width: 60px;display: inline-block">{$lang.Protect}</a>{/if}
                    {if $form_id > 0}<a href="edit_log.php?st_date=00&f_text=forms.php?table%3D{$table_id}%26form%3D{$form_id}%26mode%3D{$mode}%26admin%26edit>" target="_blank" style="padding-left:10px">{$lang.Log}</a>{/if}
                </td>
                </tr>
            {/if}
            <tr class="config_access_rules_window access_window_header">
                <td align=right></td>
                <td>
                    <span class="access_param_wrapper">{$lang.Rights_in}</span>
                    <!--span class="access_param_wrapper">{$lang.Edit3}</span>
                    <span class="access_param_wrapper">{$lang.Delete}</span-->
                </td>
            </tr>
            <tr class="config_access_rules_window access_window_header">
                <td align=right></td>
                <td>
                    <div style="float: left;margin:0 34px; width: 60px; padding-top: 8px; padding-bottom: 6px; text-align: center;">
                        <img style="margin-top:4px;{if $acc_blocked}cursor:not-allowed;{/if}" id="all_read" src="images/check_off_m.png" 
                            {if !$acc_blocked}onclick="check_all('read', this)"{/if} o_value="{if $parent}2{else}0{/if}">
                    </div>
                    <!--div style="float: left;margin:0 34px; width: 60px; padding-top: 8px; padding-bottom: 6px; text-align: center;">
                        <img style="margin-top:4px;{if $acc_blocked}cursor:not-allowed;{/if}" id="all_edit" src="images/check_off_m.png" 
                            {if !$acc_blocked}onclick="check_all('edit', this)"{/if} o_value="{if $parent}2{else}0{/if}">
                    </div>
                    <div style="float: left;margin:0 34px; width: 60px; padding-top: 8px; padding-bottom: 6px; text-align: center;">
                        <img style="margin-top:4px;{if $acc_blocked}cursor:not-allowed;{/if}" id="all_del" src="images/check_off_m.png" 
                            {if !$acc_blocked}onclick="check_all('del', this)" {/if} o_value="{if $parent}2{else}0{/if}">
                    </div-->
                </td>
            </tr>
            {foreach from=$access_data key=gid item=acc}
                <tr class="config_access_rules_window access_window_eyes {if !$acc_blocked}access_checkbox_wrapper{/if}">
                    <td style="padding: 0" align=right>{$acc.name}:</td>
                    <td>
                        <div style="float: left; margin:0 34px; width: 60px; padding-top: 8px; padding-bottom: 6px; text-align: center;">
                            <input id="check_read_" name="ob_access[{$gid}][read_acc]" value="{$acc.access.read_acc}"
                                   data-type="read_acc" data-gid="{$gid}" {if $acc.pid}data-parent="{$acc.parent}" data-pid='{$acc.pid.read_acc}'{/if} 
                                   data-o_value="{$acc.access.read_acc}" type="hidden">
                            <img id="par_read_" {if $acc_blocked}style="cursor:not-allowed"{/if}
                                 src="images/check_{if $acc.access.read_acc==2}dis_on{elseif $acc.access.read_acc==3}dis_off{elseif $acc.access.read_acc}on{else}off{/if}_m.png">
                        </div>
                        <!--div style="float: left; margin:0 34px; width: 60px; padding-top: 8px; padding-bottom: 6px; text-align: center;">
                            <input id="check_edit_" name="ob_access[{$gid}][edit_acc]" value="{$acc.access.edit_acc}" 
                                   data-type="edit_acc" data-gid="{$gid}" {if $acc.pid}data-parent="{$acc.parent}" data-pid='{$acc.pid.edit_acc}'{/if} 
                                   data-o_value="{$acc.access.edit_acc}" type="hidden">
                            <img id="par_edit_" {if $acc_blocked}style="cursor:not-allowed"{/if}
                                 src="images/check_{if $acc.access.edit_acc==2}dis_on{elseif $acc.access.edit_acc==3}dis_off{elseif $acc.access.edit_acc}on{else}off{/if}_m.png">
                        </div>
                        <div style="float: left; margin:0 34px; width: 60px; padding-top: 8px; padding-bottom: 6px; text-align: center;">
                            <input id="check_del_" name="ob_access[{$gid}][del_acc]" value="{$acc.access.del_acc}" 
                                   data-type="del_acc" data-gid="{$gid}" {if $acc.pid}data-parent="{$acc.parent}" data-pid='{$acc.pid.del_acc}'{/if} 
                                   data-o_value="{$acc.access.del_acc}" type="hidden">
                            <img id="par_del_" {if $acc_blocked}style="cursor:not-allowed"{/if}
                                 src="images/check_{if $acc.access.del_acc ==2}dis_on{elseif $acc.access.del_acc ==3}dis_off{elseif $acc.access.del_acc}on{else}off{/if}_m.png">
                        </div-->
                    </td>
                </tr>
            {/foreach}
            {if $config.protect_of_elements && $user.id == 1}
            <tbody id="protect_block" style="display:none">
                <tr>
                    <td align="right">{$lang.Protected}<span class='help_bt' h_id='Protect_of_element'></span>:</td>
                    <td>
                        <input type="checkbox" name="protected" {if $protected}checked{/if} onclick="$('[id^=pr_]').prop('disabled', !this.checked)">
                        <span class="access_param_wrapper">{$lang.View2}<span class='help_bt' h_id='protect_of_view'></span></span>
                        <span class="access_param_wrapper">{$lang.Edit3}<span class='help_bt' h_id='protect_of_edit'></span></span>
                        {if $config.access_protect_mode == 2}
                        <span class="access_param_wrapper">{$lang.Access}<span class='help_bt' h_id='protect_of_access'></span></span>
                        {/if}
                    </td>
                </tr>
                <tr>
                    <td align="right"></td>
                    <td>
                        <div style="float: left; margin:0 34px; width: 60px; padding: 8px 0 6px 15px; text-align: center;">
                            <input type="checkbox" id="pr_view_all" {if !$protected}disabled{/if}
                                   onclick="$('[id^=pr_view]').prop('checked', this.checked); if (!this.checked) $('[id^=pr_edit]').prop('checked', 0);">
                        </div>
                        <div style="float: left; margin:0 34px; width: 60px; padding: 8px 0 6px 0; text-align: center;">
                            <input type="checkbox" id="pr_edit_all" {if !$protected}disabled{/if}
                                   onclick="$('[id^=pr_edit]').prop('checked', this.checked); if ( this.checked) $('[id^=pr_view]').prop('checked', 1);">
                        </div>
                        {if $config.access_protect_mode == 2}
                        <div style="float: left; margin:0 34px; width: 60px; padding: 8px 0 6px 0; text-align: center;">
                            <input type="checkbox" id="pr_acc_all" {if !$protected}disabled{/if}
                                   onclick="$('[id^=pr_acc]').prop('checked', this.checked);">
                        </div>
                        {/if}
                    </td>
                </tr>
                {foreach from=$protect key=gid item=acc}
                    <tr>
                        <td align="right" style="padding-top: 11px;">{$acc.name}:</td>
                        <td style="display: flex; flex-wrap: nowrap;">
                            <div style="float: left; margin:0 34px; width: 60px; padding: 8px 0 6px 15px; text-align: center;">
                                <input type="checkbox" name="protect_rights[{$gid}][view]" id="pr_view{$gid}" value="1"
                                       {if $acc.view}checked{/if} {if !$protected}disabled{/if}
                                       onclick="if (!this.checked) $('#pr_edit{$gid}').prop('checked', 0)">
                            </div>
                            <div style="float: left; margin:0 34px; width: 60px; padding: 8px 0 6px 0; text-align: center;">
                                <input type="checkbox" name="protect_rights[{$gid}][edit]" id="pr_edit{$gid}" value="1"
                                       {if $acc.edit}checked{/if} {if !$protected}disabled{/if}
                                       onclick="if ( this.checked) $('#pr_view{$gid}').prop('checked', 1)">
                            </div>
                            {if $config.access_protect_mode == 2}
                            <div style="float: left; margin:0 34px; width: 60px; padding: 8px 0 6px 0; text-align: center;">
                                <input type="checkbox" name="protect_rights[{$gid}][acc]" id="pr_acc{$gid}" value="1"
                                       {if $acc.acc}checked{/if} {if !$protected}disabled{/if}>
                            </div>
                            <div style="float: left; margin:0 34px; width: 60px; padding: 8px 0 6px 0; text-align: center;">
                                <a href="edit_protect.php?group={$gid}&cat={$cat_id}&table={$table_id}&menu=templates&type={$mode}" target="_blanc">{$lang.Go}</a>
                            </div>
                            {/if}
                        </td>
                    </tr>
                {/foreach}
                <tr><td></td></tr>
                <tr>
                    <td align=right>{$lang.Comment}<span class='help_bt' h_id='protect_comment'></span>:</td>
                    <td><textarea class="form-control form-control-250" name="protect_comment" rows=5>{$protect_comment}</textarea></td>
                </tr>
            </tbody>
            {/if}
        {/if}
        <tr>
            <td colspan=4 align=center>
                <br>
                <input type="hidden" name="edit_cron_mode" id="edit_cron_mode"/>
                <input class="btn btn-default btn-sm" value="{$lang.Save}" type="{if $no_save_mode}submit{else}button{/if}" 
                       {if !$no_save_mode}onClick="if (!check_form( $('#type_form').val() ) ) return false; else return check_vars();"{/if}
                       {if $no_save_mode == 2}disabled title="{$lang.Element_no_edit_msg}"{/if}>
                <br/><br/>
                <a href="forms.php?table={$table_id}{if $filter_id}&filter={$filter_id}{/if}&mode={$mode}{if !$cur_cat}&admin{/if}{if $archive}&archive{/if}{if $ajax_edit}&form={$form_id}&view{/if}{$back_url_prm}">{$lang.Return}</a>
            </td>
        <tr>
        {/if}{*blocked*}
    </table>
    <input type=hidden name="reopen_flag" id="reopen_flag" value=0>
    <input type=hidden name=csrf value='{$csrf}'>
    <input type=hidden name=back_url value='{$base64_back_url}'>
    <input type=hidden name="save" value="1">
</form><br>
<div id="white_div"
     style="position:fixed;width:100%;height:100%;background-color:white;display:none;top:0px;left:0px;z-index:999"></div>
<script>
    {if $user.group_id==1}
    function set_fields_acc(body) {
        $.ajax({
            type: "POST",
            url: "forms.php",
            data: { act: 'set_fields_acc', csrf: '{$csrf}', body: body, table_id: {$table_id}, form_id: {$form_id} },
            success: function (msg) {
            }
        });
        document.getElementById('edit_form').submit();
    }
    {/if}
    function select_fields_acc(body) {
        $('#white_div').css('display', '');
        $.ajax({
            type: "POST",
            url: "forms.php",
            data: { act: 'select_fields_acc', csrf: '{$csrf}', body: body, table_id: {$table_id}, form_id: {$form_id} },
            success: function (msg) {
                if (msg && msg.indexOf('<!DOCTYPE HTML PUBLIC') == -1) {
                    $('#white_div').css('display', 'none');
                    {if $user.group_id==1}
                    jconfirm("{$lang.Next_fields_using_non_access} <br/>" + msg + "<br/>{$lang.Set_access}",
                            function () {
                                set_fields_acc(body);
                            }, function () {
                                document.getElementById('edit_form').submit();
                            });
                    {else}
                    jalert("{$lang.Forms_using_non_access_fields}");
                    {/if}
                }
                else {
                    document.getElementById('edit_form').submit();
                }
            }
        });
    }
    function check_fields_acc() {
        document.getElementById('edit_cron_mode').value = 0;
        if (!check_form()) return false;

        if (CKEDITOR.instances.body_form) {
            var body = CKEDITOR.instances.body_form.getSnapshot();
        } else {
            var body = $('textarea[name=body_form]').val();
        }
        select_fields_acc(body);

        return false;
    }
    $("[name='pdf_import']").on('change', function () {
        var self = $(this),
                access = $(".config_access_rules_window .access_disabled");
        if (self.is(":checked"))
            access.removeClass('access_manage_off').prop("disabled", 0).parent().find('img').attr('src', 'images/check_off_m.png');
        else
            access.addClass('access_manage_off').val('0').prop("disabled", 1).parent().css('background-color', '').find('img').attr('src', 'images/check_dis_off_m.png');
    });
    function check_vars() {
        if (CKEDITOR.instances.body_form) {
            var body = CKEDITOR.instances.body_form.getSnapshot();
        } else {
            var body = $('textarea[name=body_form]').val();
        }
        $.ajax({
            type: "POST",
            url: "forms.php",
            data: { act: 'check_vars', csrf: '{$csrf}', body: body, table: {$table_id}, form: {$form_id} },
            success: function (msg) {
                if (msg) {
                    $('#white_div').css('display', 'none');
                    jconfirm("{$lang.Bad_templ_vars_alert1}: " + msg + ". {$lang.Bad_templ_vars_alert2}.",
                        function () {
                            check_fields_acc();
                        },
                        null
                    );
                }
                else {
                    check_fields_acc();
                }
            }
        });
        return false;
    }
    init_chosen();
</script>
<script src="include/js/configuration.js?{$revision}"></script>
<script src="themes/clientbase/js/edit-form.js?{$revision}"></script>
